core.h 8.3 KB

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