core.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. typedef enum _bool{false,true} bool;
  83. /* Little to Big endian conversion macros */
  84. #ifdef LE /* Little Endian */
  85. #define SHORT_SWAP(X) (X)
  86. #define WORD_SWAP(X) (X)
  87. #define LONG_SWAP(X) ((l64)(X))
  88. #else /* Big Endian */
  89. #define SHORT_SWAP(X) ((X <<8 ) | (X >> 8))
  90. #define WORD_SWAP(X) (((X)&0xff)<<24)+ \
  91. (((X)&0xff00)<<8)+ \
  92. (((X)&0xff0000)>>8)+ \
  93. (((X)&0xff000000)>>24)
  94. #define LONG_SWAP(X) ( (l64) (((X)&0xffULL)<<56)+ \
  95. (((X)&0xff00ULL)<<40)+ \
  96. (((X)&0xff0000ULL)<<24)+ \
  97. (((X)&0xff000000ULL)<<8)+ \
  98. (((X)&0xff00000000ULL)>>8)+ \
  99. (((X)&0xff0000000000ULL)>>24)+ \
  100. (((X)&0xff000000000000ULL)>>40)+ \
  101. (((X)&0xff00000000000000ULL)>>56))
  102. #endif
  103. #ifndef NULL
  104. #define NULL 0
  105. #endif
  106. /* Those two definitions were defined to be compatible with MIPS */
  107. #define NONE_CACHEABLE 0x00000000
  108. #define CACHEABLE 0x00000000
  109. /* 750 cache line */
  110. #define CACHE_LINE_SIZE 32
  111. #define CACHELINE_MASK_BITS (CACHE_LINE_SIZE - 1)
  112. #define CACHELINE_ROUNDUP(A) (((A)+CACHELINE_MASK_BITS) & ~CACHELINE_MASK_BITS)
  113. /* Read/Write to/from GT`s internal registers */
  114. #define GT_REG_READ(offset, pData) \
  115. *pData = ( *((volatile unsigned int *)(NONE_CACHEABLE | \
  116. INTERNAL_REG_BASE_ADDR | (offset))) ) ; \
  117. *pData = WORD_SWAP(*pData)
  118. #define GTREGREAD(offset) \
  119. (WORD_SWAP( *((volatile unsigned int *)(NONE_CACHEABLE | \
  120. INTERNAL_REG_BASE_ADDR | (offset))) ))
  121. #define GT_REG_WRITE(offset, data) \
  122. *((unsigned int *)( INTERNAL_REG_BASE_ADDR | (offset))) = \
  123. WORD_SWAP(data)
  124. /* Write 32/16/8 bit */
  125. #define WRITE_CHAR(address, data) \
  126. *((unsigned char *)(address)) = data
  127. #define WRITE_SHORT(address, data) \
  128. *((unsigned short *)(address)) = data
  129. #define WRITE_WORD(address, data) \
  130. *((unsigned int *)(address)) = data
  131. #define GT_WRITE_CHAR(address, data) WRITE_CHAR(address, data)
  132. /* Write 32/16/8 bit NonCacheable */
  133. /*
  134. #define GT_WRITE_CHAR(address, data) \
  135. (*((unsigned char *)NONE_CACHEABLE(address))) = data
  136. #define GT_WRITE_SHORT(address, data) \
  137. (*((unsigned short *)NONE_CACHEABLE(address))) = data
  138. #define GT_WRITE_WORD(address, data) \
  139. (*((unsigned int *)NONE_CACHEABLE(address))) = data
  140. */
  141. /*#define GT_WRITE_CHAR(address, data) ((*((volatile unsigned char *)NONE_CACHEABLE((address)))) = ((unsigned char)(data)))1 */
  142. /*#define GT_WRITE_SHORT(address, data) ((*((volatile unsigned short *)NONE_CACHEABLE((address)))) = ((unsigned short)(data)))1 */
  143. /*#define GT_WRITE_WORD(address, data) ((*((volatile unsigned int *)NONE_CACHEABLE((address)))) = ((unsigned int)(data)))1 */
  144. /* Read 32/16/8 bits - returns data in variable. */
  145. #define READ_CHAR(address, pData) \
  146. *pData = *((volatile unsigned char *)(address))
  147. #define READ_SHORT(address, pData) \
  148. *pData = *((volatile unsigned short *)(address))
  149. #define READ_WORD(address, pData) \
  150. *pData = *((volatile unsigned int *)(address))
  151. /* Read 32/16/8 bit - returns data direct. */
  152. #define READCHAR(address) \
  153. *((volatile unsigned char *)((address) | NONE_CACHEABLE))
  154. #define READSHORT(address) \
  155. *((volatile unsigned short *)((address) | NONE_CACHEABLE))
  156. #define READWORD(address) \
  157. *((volatile unsigned int *)((address) | NONE_CACHEABLE))
  158. /* Those two Macros were defined to be compatible with MIPS */
  159. #define VIRTUAL_TO_PHY(x) (((unsigned int)x) & 0xffffffff)
  160. #define PHY_TO_VIRTUAL(x) (((unsigned int)x) | NONE_CACHEABLE)
  161. /* SET_REG_BITS(regOffset,bits) -
  162. gets register offset and bits: a 32bit value. It set to logic '1' in the
  163. internal register the bits which given as an input example:
  164. SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  165. '1' in register 0x840 while the other bits stays as is. */
  166. #define SET_REG_BITS(regOffset,bits) \
  167. *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR | \
  168. regOffset) |= (unsigned int)WORD_SWAP(bits)
  169. /* RESET_REG_BITS(regOffset,bits) -
  170. gets register offset and bits: a 32bit value. It set to logic '0' in the
  171. internal register the bits which given as an input example:
  172. RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  173. '0' in register 0x840 while the other bits stays as is. */
  174. #define RESET_REG_BITS(regOffset,bits) \
  175. *(unsigned int*)(NONE_CACHEABLE | INTERNAL_REG_BASE_ADDR \
  176. | regOffset) &= ~( (unsigned int)WORD_SWAP(bits) )
  177. /* gets register offset and bits: a 32bit value. It set to logic '1' in the
  178. internal register the bits which given as an input example:
  179. GT_SET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to logic
  180. '1' in register 0x840 while the other bits stays as is. */
  181. /*#define GT_SET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) | (regOffset)))) |= ((unsigned int)WORD_SWAP(bits)))1 */
  182. /*#define GT_SET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)1 */
  183. #define GT_SET_REG_BITS(regOffset,bits) SET_REG_BITS(regOffset,bits)
  184. /* gets register offset and bits: a 32bit value. It set to logic '0' in the
  185. internal register the bits which given as an input example:
  186. GT_RESET_REG_BITS(0x840,BIT3 | BIT24 | BIT30) - set bits: 3,24 and 30 to
  187. logic '0' in register 0x840 while the other bits stays as is. */
  188. /*#define GT_RESET_REG_BITS(regOffset,bits) ((*((volatile unsigned int*)(NONE_CACHEABLE(INTERNAL_REG_BASE_ADDR) | (regOffset)))) &= ~((unsigned int)WORD_SWAP(bits)))1 */
  189. #define GT_RESET_REG_BITS(regOffset,bits) RESET_REG_BITS(regOffset,bits)
  190. #define DEBUG_LED0_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x8000,0)
  191. #define DEBUG_LED1_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0xc000,0)
  192. #define DEBUG_LED2_ON() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x10000,0)
  193. #define DEBUG_LED0_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x14000,0)
  194. #define DEBUG_LED1_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x18000,0)
  195. #define DEBUG_LED2_OFF() WRITE_CHAR(memoryGetDeviceBaseAddress(DEVICE1) | 0x1c000,0)
  196. #endif /* __INCcoreh */