core.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* Core.h - Basic core logic functions and definitions */
  2. /* Copyright Galileo Technology. */
  3. /*
  4. DESCRIPTION
  5. This header file contains simple read/write macros for addressing
  6. the SDRAM, devices, GT`s internal registers and PCI (using the PCI`s address
  7. space). The macros take care of Big/Little endian conversions.
  8. */
  9. #ifndef __INCcoreh
  10. #define __INCcoreh
  11. #include "mv_gen_reg.h"
  12. extern unsigned int INTERNAL_REG_BASE_ADDR;
  13. /****************************************/
  14. /* GENERAL Definitions */
  15. /****************************************/
  16. #define NO_BIT 0x00000000
  17. #define BIT0 0x00000001
  18. #define BIT1 0x00000002
  19. #define BIT2 0x00000004
  20. #define BIT3 0x00000008
  21. #define BIT4 0x00000010
  22. #define BIT5 0x00000020
  23. #define BIT6 0x00000040
  24. #define BIT7 0x00000080
  25. #define BIT8 0x00000100
  26. #define BIT9 0x00000200
  27. #define BIT10 0x00000400
  28. #define BIT11 0x00000800
  29. #define BIT12 0x00001000
  30. #define BIT13 0x00002000
  31. #define BIT14 0x00004000
  32. #define BIT15 0x00008000
  33. #define BIT16 0x00010000
  34. #define BIT17 0x00020000
  35. #define BIT18 0x00040000
  36. #define BIT19 0x00080000
  37. #define BIT20 0x00100000
  38. #define BIT21 0x00200000
  39. #define BIT22 0x00400000
  40. #define BIT23 0x00800000
  41. #define BIT24 0x01000000
  42. #define BIT25 0x02000000
  43. #define BIT26 0x04000000
  44. #define BIT27 0x08000000
  45. #define BIT28 0x10000000
  46. #define BIT29 0x20000000
  47. #define BIT30 0x40000000
  48. #define BIT31 0x80000000
  49. #define _1K 0x00000400
  50. #define _2K 0x00000800
  51. #define _4K 0x00001000
  52. #define _8K 0x00002000
  53. #define _16K 0x00004000
  54. #define _32K 0x00008000
  55. #define _64K 0x00010000
  56. #define _128K 0x00020000
  57. #define _256K 0x00040000
  58. #define _512K 0x00080000
  59. #define _1M 0x00100000
  60. #define _2M 0x00200000
  61. #define _3M 0x00300000
  62. #define _4M 0x00400000
  63. #define _5M 0x00500000
  64. #define _6M 0x00600000
  65. #define _7M 0x00700000
  66. #define _8M 0x00800000
  67. #define _9M 0x00900000
  68. #define _10M 0x00a00000
  69. #define _11M 0x00b00000
  70. #define _12M 0x00c00000
  71. #define _13M 0x00d00000
  72. #define _14M 0x00e00000
  73. #define _15M 0x00f00000
  74. #define _16M 0x01000000
  75. #define _32M 0x02000000
  76. #define _64M 0x04000000
  77. #define _128M 0x08000000
  78. #define _256M 0x10000000
  79. #define _512M 0x20000000
  80. #define _1G 0x40000000
  81. #define _2G 0x80000000
  82. /* Little to Big endian conversion macros */
  83. #ifdef LE /* Little Endian */
  84. #define SHORT_SWAP(X) (X)
  85. #define WORD_SWAP(X) (X)
  86. #define LONG_SWAP(X) ((l64)(X))
  87. #else /* Big Endian */
  88. #define SHORT_SWAP(X) ((X <<8 ) | (X >> 8))
  89. #define WORD_SWAP(X) (((X)&0xff)<<24)+ \
  90. (((X)&0xff00)<<8)+ \
  91. (((X)&0xff0000)>>8)+ \
  92. (((X)&0xff000000)>>24)
  93. #define LONG_SWAP(X) ( (l64) (((X)&0xffULL)<<56)+ \
  94. (((X)&0xff00ULL)<<40)+ \
  95. (((X)&0xff0000ULL)<<24)+ \
  96. (((X)&0xff000000ULL)<<8)+ \
  97. (((X)&0xff00000000ULL)>>8)+ \
  98. (((X)&0xff0000000000ULL)>>24)+ \
  99. (((X)&0xff000000000000ULL)>>40)+ \
  100. (((X)&0xff00000000000000ULL)>>56))
  101. #endif
  102. #ifndef NULL
  103. #define NULL 0
  104. #endif
  105. /* Those two definitions were defined to be compatible with MIPS */
  106. #define NONE_CACHEABLE 0x00000000
  107. #define CACHEABLE 0x00000000
  108. /* 750 cache line */
  109. #define CACHE_LINE_SIZE 32
  110. #define CACHELINE_MASK_BITS (CACHE_LINE_SIZE - 1)
  111. #define CACHELINE_ROUNDUP(A) (((A)+CACHELINE_MASK_BITS) & ~CACHELINE_MASK_BITS)
  112. /* Read/Write to/from GT`s internal registers */
  113. #define GT_REG_READ(offset, pData) \
  114. *pData = ( *((volatile unsigned int *)(NONE_CACHEABLE | \
  115. INTERNAL_REG_BASE_ADDR | (offset))) ) ; \
  116. *pData = WORD_SWAP(*pData)
  117. #define GTREGREAD(offset) \
  118. (WORD_SWAP( *((volatile unsigned int *)(NONE_CACHEABLE | \
  119. INTERNAL_REG_BASE_ADDR | (offset))) ))
  120. #define GT_REG_WRITE(offset, data) \
  121. *((unsigned int *)( INTERNAL_REG_BASE_ADDR | (offset))) = \
  122. WORD_SWAP(data)
  123. /* Write 32/16/8 bit */
  124. #define WRITE_CHAR(address, data) \
  125. *((unsigned char *)(address)) = data
  126. #define WRITE_SHORT(address, data) \
  127. *((unsigned short *)(address)) = data
  128. #define WRITE_WORD(address, data) \
  129. *((unsigned int *)(address)) = data
  130. #define GT_WRITE_CHAR(address, data) WRITE_CHAR(address, data)
  131. /* Write 32/16/8 bit NonCacheable */
  132. /*
  133. #define GT_WRITE_CHAR(address, data) \
  134. (*((unsigned char *)NONE_CACHEABLE(address))) = data
  135. #define GT_WRITE_SHORT(address, data) \
  136. (*((unsigned short *)NONE_CACHEABLE(address))) = data
  137. #define GT_WRITE_WORD(address, data) \
  138. (*((unsigned int *)NONE_CACHEABLE(address))) = data
  139. */
  140. /*#define GT_WRITE_CHAR(address, data) ((*((volatile unsigned char *)NONE_CACHEABLE((address)))) = ((unsigned char)(data)))1 */
  141. /*#define GT_WRITE_SHORT(address, data) ((*((volatile unsigned short *)NONE_CACHEABLE((address)))) = ((unsigned short)(data)))1 */
  142. /*#define GT_WRITE_WORD(address, data) ((*((volatile unsigned int *)NONE_CACHEABLE((address)))) = ((unsigned int)(data)))1 */
  143. /* Read 32/16/8 bits - returns data in variable. */
  144. #define READ_CHAR(address, pData) \
  145. *pData = *((volatile unsigned char *)(address))
  146. #define READ_SHORT(address, pData) \
  147. *pData = *((volatile unsigned short *)(address))
  148. #define READ_WORD(address, pData) \
  149. *pData = *((volatile unsigned int *)(address))
  150. /* Read 32/16/8 bit - returns data direct. */
  151. #define READCHAR(address) \
  152. *((volatile unsigned char *)((address) | NONE_CACHEABLE))
  153. #define READSHORT(address) \
  154. *((volatile unsigned short *)((address) | NONE_CACHEABLE))
  155. #define READWORD(address) \
  156. *((volatile unsigned int *)((address) | NONE_CACHEABLE))
  157. /* Those two Macros were defined to be compatible with MIPS */
  158. #define VIRTUAL_TO_PHY(x) (((unsigned int)x) & 0xffffffff)
  159. #define PHY_TO_VIRTUAL(x) (((unsigned int)x) | NONE_CACHEABLE)
  160. /* SET_REG_BITS(regOffset,bits) -
  161. gets register offset and bits: a 32bit value. It set to logic '1' in the
  162. internal register the bits which given as an input example:
  163. SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  164. '1' in register 0x840 while the other bits stays as is. */
  165. #define SET_REG_BITS(regOffset,bits) \
  166. *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR | \
  167. regOffset) |= (unsigned int)WORD_SWAP(bits)
  168. /* RESET_REG_BITS(regOffset,bits) -
  169. gets register offset and bits: a 32bit value. It set to logic '0' in the
  170. internal register the bits which given as an input example:
  171. RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  172. '0' in register 0x840 while the other bits stays as is. */
  173. #define RESET_REG_BITS(regOffset,bits) \
  174. *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR \
  175. | regOffset) &= ~( (unsigned int)WORD_SWAP(bits) )
  176. /* gets register offset and bits: a 32bit value. It set to logic '1' in the
  177. internal register the bits which given as an input example:
  178. GT_SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  179. '1' in register 0x840 while the other bits stays as is. */
  180. /*#define GT_SET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) | (regOffset)))) |= ((unsigned int)WORD_SWAP(bits)))1 */
  181. /*#define GT_SET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)1 */
  182. #define GT_SET_REG_BITS(regOffset,bits) SET_REG_BITS(regOffset,bits)
  183. /* gets register offset and bits: a 32bit value. It set to logic '0' in the
  184. internal register the bits which given as an input example:
  185. GT_RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to
  186. logic '0' in register 0x840 while the other bits stays as is. */
  187. /*#define GT_RESET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) | (regOffset)))) &= ~((unsigned int)WORD_SWAP(bits)))1 */
  188. #define GT_RESET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)
  189. #define DEBUG_LED0_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x8000,0)
  190. #define DEBUG_LED1_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0xc000,0)
  191. #define DEBUG_LED2_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x10000,0)
  192. #define DEBUG_LED0_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x14000,0)
  193. #define DEBUG_LED1_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x18000,0)
  194. #define DEBUG_LED2_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x1c000,0)
  195. #endif /* __INCcoreh */