pci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* PCI.h - PCI functions header file */
  2. /* Copyright - Galileo technology. */
  3. #ifndef __INCpcih
  4. #define __INCpcih
  5. /* includes */
  6. #include"core.h"
  7. #include"memory.h"
  8. /* According to PCI REV 2.1 MAX agents allowed on the bus are -21- */
  9. #define PCI_MAX_DEVICES 22
  10. /* Macros */
  11. /* The next Macros configurate the initiator board (SELF) or any any agent on
  12. the PCI to become: MASTER, response to MEMORY transactions , response to
  13. IO transactions or TWO both MEMORY_IO transactions. Those configuration
  14. are for both PCI0 and PCI1. */
  15. #define PCI_MEMORY_ENABLE(host, deviceNumber) pciWriteConfigReg(host, \
  16. PCI_STATUS_AND_COMMAND,deviceNumber,MEMORY_ENABLE | \
  17. pciReadConfigReg(host, PCI_STATUS_AND_COMMAND,deviceNumber) )
  18. #define PCI_IO_ENABLE(host, deviceNumber) pciWriteConfigReg(host, \
  19. PCI_STATUS_AND_COMMAND,deviceNumber,I_O_ENABLE | \
  20. pciReadConfigReg(host, PCI_STATUS_AND_COMMAND,deviceNumber) )
  21. #define PCI_SLAVE_ENABLE(host, deviceNumber) pciWriteConfigReg(host, \
  22. PCI_STATUS_AND_COMMAND,deviceNumber,MEMORY_ENABLE | I_O_ENABLE | \
  23. pciReadConfigReg(host, PCI_STATUS_AND_COMMAND,deviceNumber) )
  24. #define PCI_DISABLE(host, deviceNumber) pciWriteConfigReg(host, \
  25. PCI_STATUS_AND_COMMAND,deviceNumber,0xfffffff8 & \
  26. pciReadConfigReg(host, PCI_STATUS_AND_COMMAND,deviceNumber))
  27. #define PCI_MASTER_ENABLE(host,deviceNumber) pciWriteConfigReg(host, \
  28. PCI_STATUS_AND_COMMAND,deviceNumber,MASTER_ENABLE | \
  29. pciReadConfigReg(host,PCI_STATUS_AND_COMMAND,deviceNumber) )
  30. #define PCI_MASTER_DISABLE(deviceNumber) pciWriteConfigReg(host, \
  31. PCI_STATUS_AND_COMMAND,deviceNumber,~MASTER_ENABLE & \
  32. pciReadConfigReg(host,PCI_STATUS_AND_COMMAND,deviceNumber) )
  33. #define MASTER_ENABLE BIT2
  34. #define MEMORY_ENABLE BIT1
  35. #define I_O_ENABLE BIT0
  36. #define SELF 32
  37. /* Agent on the PCI bus may have up to 6 BARS. */
  38. #define BAR0 0x10
  39. #define BAR1 0x14
  40. #define BAR2 0x18
  41. #define BAR3 0x1c
  42. #define BAR4 0x20
  43. #define BAR5 0x24
  44. #define BAR_SEL_MEM_IO BIT0
  45. #define BAR_MEM_TYPE_32_BIT NO_BIT
  46. #define BAR_MEM_TYPE_BELOW_1M BIT1
  47. #define BAR_MEM_TYPE_64_BIT BIT2
  48. #define BAR_MEM_TYPE_RESERVED (BIT1 | BIT2)
  49. #define BAR_MEM_TYPE_MASK (BIT1 | BIT2)
  50. #define BAR_PREFETCHABLE BIT3
  51. #define BAR_CONFIG_MASK (BIT0 | BIT1 | BIT2 | BIT3)
  52. /* Defines for the access regions. */
  53. #define PREFETCH_ENABLE BIT12
  54. #define PREFETCH_DISABLE NO_BIT
  55. #define DELAYED_READ_ENABLE BIT13
  56. /* #define CACHING_ENABLE BIT14 */
  57. /* aggressive prefetch: PCI slave prefetch two burst in advance*/
  58. #define AGGRESSIVE_PREFETCH BIT16
  59. /* read line aggresive prefetch: PCI slave prefetch two burst in advance*/
  60. #define READ_LINE_AGGRESSIVE_PREFETCH BIT17
  61. /* read multiple aggresive prefetch: PCI slave prefetch two burst in advance*/
  62. #define READ_MULTI_AGGRESSIVE_PREFETCH BIT18
  63. #define MAX_BURST_4 NO_BIT
  64. #define MAX_BURST_8 BIT20 /* Bits[21:20] = 01 */
  65. #define MAX_BURST_16 BIT21 /* Bits[21:20] = 10 */
  66. #define PCI_BYTE_SWAP NO_BIT /* Bits[25:24] = 00 */
  67. #define PCI_NO_SWAP BIT24 /* Bits[25:24] = 01 */
  68. #define PCI_BYTE_AND_WORD_SWAP BIT25 /* Bits[25:24] = 10 */
  69. #define PCI_WORD_SWAP (BIT24 | BIT25) /* Bits[25:24] = 11 */
  70. #define PCI_ACCESS_PROTECT BIT28
  71. #define PCI_WRITE_PROTECT BIT29
  72. /* typedefs */
  73. typedef enum __pciAccessRegions{REGION0,REGION1,REGION2,REGION3,REGION4,REGION5,
  74. REGION6,REGION7} PCI_ACCESS_REGIONS;
  75. typedef enum __pciAgentPrio{LOW_AGENT_PRIO,HI_AGENT_PRIO} PCI_AGENT_PRIO;
  76. typedef enum __pciAgentPark{PARK_ON_AGENT,DONT_PARK_ON_AGENT} PCI_AGENT_PARK;
  77. typedef enum __pciSnoopType{PCI_NO_SNOOP,PCI_SNOOP_WT,PCI_SNOOP_WB}
  78. PCI_SNOOP_TYPE;
  79. typedef enum __pciSnoopRegion{PCI_SNOOP_REGION0,PCI_SNOOP_REGION1,
  80. PCI_SNOOP_REGION2,PCI_SNOOP_REGION3}
  81. PCI_SNOOP_REGION;
  82. typedef enum __memPciHost{PCI_HOST0,PCI_HOST1} PCI_HOST;
  83. typedef enum __memPciRegion{PCI_REGION0,PCI_REGION1,
  84. PCI_REGION2,PCI_REGION3,
  85. PCI_IO}
  86. PCI_REGION;
  87. /*ronen 7/Dec/03 */
  88. typedef enum __pci_bar_windows{PCI_CS0_BAR, PCI_CS1_BAR, PCI_CS2_BAR,
  89. PCI_CS3_BAR, PCI_DEV_CS0_BAR, PCI_DEV_CS1_BAR,
  90. PCI_DEV_CS2_BAR, PCI_DEV_CS3_BAR, PCI_BOOT_CS_BAR,
  91. PCI_MEM_INT_REG_BAR, PCI_IO_INT_REG_BAR,
  92. PCI_P2P_MEM0_BAR, PCI_P2P_MEM1_BAR,
  93. PCI_P2P_IO_BAR, PCI_CPU_BAR, PCI_INT_SRAM_BAR,
  94. PCI_LAST_BAR} PCI_INTERNAL_BAR;
  95. typedef struct pciBar {
  96. unsigned int detectBase;
  97. unsigned int base;
  98. unsigned int size;
  99. unsigned int type;
  100. } PCI_BAR;
  101. typedef struct pciDevice {
  102. PCI_HOST host;
  103. char type[40];
  104. unsigned int deviceNum;
  105. unsigned int venID;
  106. unsigned int deviceID;
  107. PCI_BAR bar[6];
  108. } PCI_DEVICE;
  109. typedef struct pciSelfBars {
  110. unsigned int SCS0Base;
  111. unsigned int SCS0Size;
  112. unsigned int SCS1Base;
  113. unsigned int SCS1Size;
  114. unsigned int SCS2Base;
  115. unsigned int SCS2Size;
  116. unsigned int SCS3Base;
  117. unsigned int SCS3Size;
  118. unsigned int internalMemBase;
  119. unsigned int internalIOBase;
  120. unsigned int CS0Base;
  121. unsigned int CS0Size;
  122. unsigned int CS1Base;
  123. unsigned int CS1Size;
  124. unsigned int CS2Base;
  125. unsigned int CS2Size;
  126. unsigned int CS3Base;
  127. unsigned int CS3Size;
  128. unsigned int CSBootBase;
  129. unsigned int CSBootSize;
  130. unsigned int P2PMem0Base;
  131. unsigned int P2PMem0Size;
  132. unsigned int P2PMem1Base;
  133. unsigned int P2PMem1Size;
  134. unsigned int P2PIOBase;
  135. unsigned int P2PIOSize;
  136. unsigned int CPUBase;
  137. unsigned int CPUSize;
  138. } PCI_SELF_BARS;
  139. /* read/write configuration registers on local PCI bus. */
  140. void pciWriteConfigReg(PCI_HOST host, unsigned int regOffset,
  141. unsigned int pciDevNum, unsigned int data);
  142. unsigned int pciReadConfigReg (PCI_HOST host, unsigned int regOffset,
  143. unsigned int pciDevNum);
  144. /* read/write configuration registers on another PCI bus. */
  145. void pciOverBridgeWriteConfigReg(PCI_HOST host,
  146. unsigned int regOffset,
  147. unsigned int pciDevNum,
  148. unsigned int busNum,unsigned int data);
  149. unsigned int pciOverBridgeReadConfigReg(PCI_HOST host,
  150. unsigned int regOffset,
  151. unsigned int pciDevNum,
  152. unsigned int busNum);
  153. /* Performs full scane on both PCI and returns all detail possible on the
  154. agents which exist on the bus. */
  155. void pciScanDevices(PCI_HOST host, PCI_DEVICE *pci0Detect,
  156. unsigned int numberOfElment);
  157. /* Master`s memory space */
  158. bool pciMapSpace(PCI_HOST host, PCI_REGION region,
  159. unsigned int remapBase,
  160. unsigned int deviceBase,
  161. unsigned int deviceLength);
  162. unsigned int pciGetSpaceBase(PCI_HOST host, PCI_REGION region);
  163. unsigned int pciGetSpaceSize(PCI_HOST host, PCI_REGION region);
  164. /* Slave`s memory space */
  165. void pciMapMemoryBank(PCI_HOST host, MEMORY_BANK bank,
  166. unsigned int pci0Dram0Base, unsigned int pci0Dram0Size);
  167. #if 0 /* GARBAGE routines - dont use till they get cleaned up */
  168. void pci0ScanSelfBars(PCI_SELF_BARS *pci0SelfBars);
  169. void pci1ScanSelfBars(PCI_SELF_BARS *pci1SelfBars);
  170. void pci0MapInternalRegSpace(unsigned int pci0InternalBase);
  171. void pci1MapInternalRegSpace(unsigned int pci1InternalBase);
  172. void pci0MapInternalRegIOSpace(unsigned int pci0InternalBase);
  173. void pci1MapInternalRegIOSpace(unsigned int pci1InternalBase);
  174. void pci0MapDevice0MemorySpace(unsigned int pci0Dev0Base,
  175. unsigned int pci0Dev0Length);
  176. void pci1MapDevice0MemorySpace(unsigned int pci1Dev0Base,
  177. unsigned int pci1Dev0Length);
  178. void pci0MapDevice1MemorySpace(unsigned int pci0Dev1Base,
  179. unsigned int pci0Dev1Length);
  180. void pci1MapDevice1MemorySpace(unsigned int pci1Dev1Base,
  181. unsigned int pci1Dev1Length);
  182. void pci0MapDevice2MemorySpace(unsigned int pci0Dev2Base,
  183. unsigned int pci0Dev2Length);
  184. void pci1MapDevice2MemorySpace(unsigned int pci1Dev2Base,
  185. unsigned int pci1Dev2Length);
  186. void pci0MapDevice3MemorySpace(unsigned int pci0Dev3Base,
  187. unsigned int pci0Dev3Length);
  188. void pci1MapDevice3MemorySpace(unsigned int pci1Dev3Base,
  189. unsigned int pci1Dev3Length);
  190. void pci0MapBootDeviceMemorySpace(unsigned int pci0DevBootBase,
  191. unsigned int pci0DevBootLength);
  192. void pci1MapBootDeviceMemorySpace(unsigned int pci1DevBootBase,
  193. unsigned int pci1DevBootLength);
  194. void pci0MapP2pMem0Space(unsigned int pci0P2pMem0Base,
  195. unsigned int pci0P2pMem0Length);
  196. void pci1MapP2pMem0Space(unsigned int pci1P2pMem0Base,
  197. unsigned int pci1P2pMem0Length);
  198. void pci0MapP2pMem1Space(unsigned int pci0P2pMem1Base,
  199. unsigned int pci0P2pMem1Length);
  200. void pci1MapP2pMem1Space(unsigned int pci1P2pMem1Base,
  201. unsigned int pci1P2pMem1Length);
  202. void pci0MapP2pIoSpace(unsigned int pci0P2pIoBase,
  203. unsigned int pci0P2pIoLength);
  204. void pci1MapP2pIoSpace(unsigned int pci1P2pIoBase,
  205. unsigned int pci1P2pIoLength);
  206. void pci0MapCPUspace(unsigned int pci0CpuBase, unsigned int pci0CpuLengs);
  207. void pci1MapCPUspace(unsigned int pci1CpuBase, unsigned int pci1CpuLengs);
  208. #endif
  209. /* PCI region options */
  210. bool pciSetRegionFeatures(PCI_HOST host, PCI_ACCESS_REGIONS region,
  211. unsigned int features, unsigned int baseAddress,
  212. unsigned int regionLength);
  213. void pciDisableAccessRegion(PCI_HOST host, PCI_ACCESS_REGIONS region);
  214. /* PCI arbiter */
  215. bool pciArbiterEnable(PCI_HOST host);
  216. bool pciArbiterDisable(PCI_HOST host);
  217. bool pciSetArbiterAgentsPriority(PCI_HOST host, PCI_AGENT_PRIO internalAgent,
  218. PCI_AGENT_PRIO externalAgent0,
  219. PCI_AGENT_PRIO externalAgent1,
  220. PCI_AGENT_PRIO externalAgent2,
  221. PCI_AGENT_PRIO externalAgent3,
  222. PCI_AGENT_PRIO externalAgent4,
  223. PCI_AGENT_PRIO externalAgent5);
  224. bool pciSetArbiterAgentsPriority(PCI_HOST host, PCI_AGENT_PRIO internalAgent,
  225. PCI_AGENT_PRIO externalAgent0,
  226. PCI_AGENT_PRIO externalAgent1,
  227. PCI_AGENT_PRIO externalAgent2,
  228. PCI_AGENT_PRIO externalAgent3,
  229. PCI_AGENT_PRIO externalAgent4,
  230. PCI_AGENT_PRIO externalAgent5);
  231. bool pciParkingDisable(PCI_HOST host, PCI_AGENT_PARK internalAgent,
  232. PCI_AGENT_PARK externalAgent0,
  233. PCI_AGENT_PARK externalAgent1,
  234. PCI_AGENT_PARK externalAgent2,
  235. PCI_AGENT_PARK externalAgent3,
  236. PCI_AGENT_PARK externalAgent4,
  237. PCI_AGENT_PARK externalAgent5);
  238. bool pciEnableBrokenAgentDetection(PCI_HOST host, unsigned char brokenValue);
  239. bool pciEnableBrokenAgentDetection(PCI_HOST host, unsigned char brokenValue);
  240. /* PCI-to-PCI (P2P) */
  241. bool pciP2PConfig(PCI_HOST host,
  242. unsigned int SecondBusLow,unsigned int SecondBusHigh,
  243. unsigned int busNum,unsigned int devNum);
  244. /* PCI Cache-coherency */
  245. bool pciSetRegionSnoopMode(PCI_HOST host, PCI_SNOOP_REGION region,
  246. PCI_SNOOP_TYPE snoopType,
  247. unsigned int baseAddress,
  248. unsigned int regionLength);
  249. PCI_DEVICE * pciFindDevice(unsigned short ven, unsigned short dev);
  250. #endif /* __INCpcih */