core.h 7.4 KB

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