pci.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /* PCI.c - PCI functions */
  2. /* Copyright - Galileo technology. */
  3. #include <common.h>
  4. #include <pci.h>
  5. #include <galileo/pci.h>
  6. static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
  7. #ifdef CONFIG_ZUMA_V2
  8. {0,0,0,0,0,0,0,29, [8 ... PCI_MAX_DEVICES-1]=0},
  9. {0,0,0,0,0,0,0,28, [8 ... PCI_MAX_DEVICES-1]=0}
  10. #else /* EVB??? This is a guess */
  11. {0,0,0,0,0,0,0,27,27, [9 ... PCI_MAX_DEVICES-1]=0},
  12. {0,0,0,0,0,0,0,29,29, [9 ... PCI_MAX_DEVICES-1]=0}
  13. #endif
  14. };
  15. static const unsigned int pci_p2p_configuration_reg[]={
  16. PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION};
  17. static const unsigned int pci_configuration_address[]={
  18. PCI_0CONFIGURATION_ADDRESS, PCI_1CONFIGURATION_ADDRESS};
  19. static const unsigned int pci_configuration_data[]={
  20. PCI_0CONFIGURATION_DATA_VIRTUAL_REGISTER,
  21. PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER};
  22. static const unsigned int pci_error_cause_reg[]={
  23. PCI_0ERROR_CAUSE, PCI_1ERROR_CAUSE};
  24. static const unsigned int pci_arbiter_control[]={
  25. PCI_0ARBITER_CONTROL, PCI_1ARBITER_CONTROL};
  26. static const unsigned int pci_snoop_control_base_0_low[]={
  27. PCI_0SNOOP_CONTROL_BASE_0_LOW, PCI_1SNOOP_CONTROL_BASE_0_LOW};
  28. static const unsigned int pci_snoop_control_top_0[]={
  29. PCI_0SNOOP_CONTROL_TOP_0, PCI_1SNOOP_CONTROL_TOP_0};
  30. static const unsigned int pci_access_control_base_0_low[]={
  31. PCI_0ACCESS_CONTROL_BASE_0_LOW, PCI_1ACCESS_CONTROL_BASE_0_LOW};
  32. static const unsigned int pci_access_control_top_0[]={
  33. PCI_0ACCESS_CONTROL_TOP_0, PCI_1ACCESS_CONTROL_TOP_0};
  34. static const unsigned int pci_scs_bank_size[2][4] = {
  35. {PCI_0SCS_0_BANK_SIZE, PCI_0SCS_1_BANK_SIZE,
  36. PCI_0SCS_2_BANK_SIZE, PCI_0SCS_3_BANK_SIZE},
  37. {PCI_1SCS_0_BANK_SIZE, PCI_1SCS_1_BANK_SIZE,
  38. PCI_1SCS_2_BANK_SIZE, PCI_1SCS_3_BANK_SIZE}};
  39. static const unsigned int pci_p2p_configuration[] = {
  40. PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION};
  41. static unsigned int local_buses[] = { 0, 0};
  42. /********************************************************************
  43. * pciWriteConfigReg - Write to a PCI configuration register
  44. * - Make sure the GT is configured as a master before writing
  45. * to another device on the PCI.
  46. * - The function takes care of Big/Little endian conversion.
  47. *
  48. *
  49. * Inputs: unsigned int regOffset: The register offset as it apears in the GT spec
  50. * (or any other PCI device spec)
  51. * pciDevNum: The device number needs to be addressed.
  52. *
  53. * Configuration Address 0xCF8:
  54. *
  55. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  56. * |congif|Reserved| Bus |Device|Function|Register|00|
  57. * |Enable| |Number|Number| Number | Number | | <=field Name
  58. *
  59. *********************************************************************/
  60. void pciWriteConfigReg(PCI_HOST host, unsigned int regOffset,unsigned int pciDevNum,unsigned int data)
  61. {
  62. volatile unsigned int DataForAddrReg;
  63. unsigned int functionNum;
  64. unsigned int busNum = PCI_BUS(pciDevNum);
  65. unsigned int addr;
  66. if(pciDevNum > 32) /* illegal device Number */
  67. return;
  68. if(pciDevNum == SELF) /* configure our configuration space. */
  69. {
  70. pciDevNum = (GTREGREAD(pci_p2p_configuration_reg[host]) >> 24) & 0x1f;
  71. busNum = GTREGREAD(pci_p2p_configuration_reg[host]) & 0xff0000;
  72. }
  73. functionNum = regOffset & 0x00000700;
  74. pciDevNum = pciDevNum << 11;
  75. regOffset = regOffset & 0xfc;
  76. DataForAddrReg = ( regOffset | pciDevNum | functionNum | busNum) | BIT31;
  77. GT_REG_WRITE(pci_configuration_address[host],DataForAddrReg);
  78. GT_REG_READ(pci_configuration_address[host], &addr);
  79. if (addr != DataForAddrReg) return;
  80. GT_REG_WRITE(pci_configuration_data[host],data);
  81. }
  82. /********************************************************************
  83. * pciReadConfigReg - Read from a PCI0 configuration register
  84. * - Make sure the GT is configured as a master before reading
  85. * from another device on the PCI.
  86. * - The function takes care of Big/Little endian conversion.
  87. * INPUTS: regOffset: The register offset as it apears in the GT spec (or PCI
  88. * spec)
  89. * pciDevNum: The device number needs to be addressed.
  90. * RETURNS: data , if the data == 0xffffffff check the master abort bit in the
  91. * cause register to make sure the data is valid
  92. *
  93. * Configuration Address 0xCF8:
  94. *
  95. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  96. * |congif|Reserved| Bus |Device|Function|Register|00|
  97. * |Enable| |Number|Number| Number | Number | | <=field Name
  98. *
  99. *********************************************************************/
  100. unsigned int pciReadConfigReg (PCI_HOST host, unsigned int regOffset,unsigned int pciDevNum)
  101. {
  102. volatile unsigned int DataForAddrReg;
  103. unsigned int data;
  104. unsigned int functionNum;
  105. unsigned int busNum = PCI_BUS(pciDevNum);
  106. if(pciDevNum > 32) /* illegal device Number */
  107. return 0xffffffff;
  108. if(pciDevNum == SELF) /* configure our configuration space. */
  109. {
  110. pciDevNum = (GTREGREAD(pci_p2p_configuration_reg[host]) >> 24) & 0x1f;
  111. busNum = GTREGREAD(pci_p2p_configuration_reg[host]) & 0xff0000;
  112. }
  113. functionNum = regOffset & 0x00000700;
  114. pciDevNum = pciDevNum << 11;
  115. regOffset = regOffset & 0xfc;
  116. DataForAddrReg = (regOffset | pciDevNum | functionNum | busNum) | BIT31 ;
  117. GT_REG_WRITE(pci_configuration_address[host],DataForAddrReg);
  118. GT_REG_READ(pci_configuration_address[host], &data);
  119. if (data != DataForAddrReg)
  120. return 0xffffffff;
  121. GT_REG_READ(pci_configuration_data[host], &data);
  122. return data;
  123. }
  124. /********************************************************************
  125. * pciOverBridgeWriteConfigReg - Write to a PCI configuration register where
  126. * the agent is placed on another Bus. For more
  127. * information read P2P in the PCI spec.
  128. *
  129. * Inputs: unsigned int regOffset - The register offset as it apears in the
  130. * GT spec (or any other PCI device spec).
  131. * unsigned int pciDevNum - The device number needs to be addressed.
  132. * unsigned int busNum - On which bus does the Target agent connect
  133. * to.
  134. * unsigned int data - data to be written.
  135. *
  136. * Configuration Address 0xCF8:
  137. *
  138. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  139. * |congif|Reserved| Bus |Device|Function|Register|01|
  140. * |Enable| |Number|Number| Number | Number | | <=field Name
  141. *
  142. * The configuration Address is configure as type-I (bits[1:0] = '01') due to
  143. * PCI spec referring to P2P.
  144. *
  145. *********************************************************************/
  146. void pciOverBridgeWriteConfigReg(PCI_HOST host,
  147. unsigned int regOffset,
  148. unsigned int pciDevNum,
  149. unsigned int busNum,unsigned int data)
  150. {
  151. unsigned int DataForReg;
  152. unsigned int functionNum;
  153. functionNum = regOffset & 0x00000700;
  154. pciDevNum = pciDevNum << 11;
  155. regOffset = regOffset & 0xff;
  156. busNum = busNum << 16;
  157. if(pciDevNum == SELF) /* This board */
  158. {
  159. DataForReg = ( regOffset | pciDevNum | functionNum) | BIT0;
  160. }
  161. else
  162. {
  163. DataForReg = ( regOffset | pciDevNum | functionNum | busNum) |
  164. BIT31 | BIT0;
  165. }
  166. GT_REG_WRITE(pci_configuration_address[host],DataForReg);
  167. if(pciDevNum == SELF) /* This board */
  168. {
  169. GT_REG_WRITE(pci_configuration_data[host],data);
  170. }
  171. else /* configuration Transaction over the pci. */
  172. {
  173. /* The PCI is working in LE Mode So it swap the Data. */
  174. GT_REG_WRITE(pci_configuration_data[host],WORD_SWAP(data));
  175. }
  176. }
  177. /********************************************************************
  178. * pciOverBridgeReadConfigReg - Read from a PCIn configuration register where
  179. * the agent target locate on another PCI bus.
  180. * - Make sure the GT is configured as a master
  181. * before reading from another device on the PCI.
  182. * - The function takes care of Big/Little endian
  183. * conversion.
  184. * INPUTS: regOffset: The register offset as it apears in the GT spec (or PCI
  185. * spec). (configuration register offset.)
  186. * pciDevNum: The device number needs to be addressed.
  187. * busNum: the Bus number where the agent is place.
  188. * RETURNS: data , if the data == 0xffffffff check the master abort bit in the
  189. * cause register to make sure the data is valid
  190. *
  191. * Configuration Address 0xCF8:
  192. *
  193. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  194. * |congif|Reserved| Bus |Device|Function|Register|01|
  195. * |Enable| |Number|Number| Number | Number | | <=field Name
  196. *
  197. *********************************************************************/
  198. unsigned int pciOverBridgeReadConfigReg(PCI_HOST host,
  199. unsigned int regOffset,
  200. unsigned int pciDevNum,
  201. unsigned int busNum)
  202. {
  203. unsigned int DataForReg;
  204. unsigned int data;
  205. unsigned int functionNum;
  206. functionNum = regOffset & 0x00000700;
  207. pciDevNum = pciDevNum << 11;
  208. regOffset = regOffset & 0xff;
  209. busNum = busNum << 16;
  210. if (pciDevNum == SELF) /* This board */
  211. {
  212. DataForReg = (regOffset | pciDevNum | functionNum) | BIT31 ;
  213. }
  214. else /* agent on another bus */
  215. {
  216. DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
  217. BIT0 | BIT31 ;
  218. }
  219. GT_REG_WRITE(pci_configuration_address[host],DataForReg);
  220. if (pciDevNum == SELF) /* This board */
  221. {
  222. GT_REG_READ(pci_configuration_data[host], &data);
  223. return data;
  224. }
  225. else /* The PCI is working in LE Mode So it swap the Data. */
  226. {
  227. GT_REG_READ(pci_configuration_data[host], &data);
  228. return WORD_SWAP(data);
  229. }
  230. }
  231. /********************************************************************
  232. * pciGetRegOffset - Gets the register offset for this region config.
  233. *
  234. * INPUT: Bus, Region - The bus and region we ask for its base address.
  235. * OUTPUT: N/A
  236. * RETURNS: PCI register base address
  237. *********************************************************************/
  238. static unsigned int pciGetRegOffset(PCI_HOST host, PCI_REGION region)
  239. {
  240. switch (host)
  241. {
  242. case PCI_HOST0:
  243. switch(region) {
  244. case PCI_IO: return PCI_0I_O_LOW_DECODE_ADDRESS;
  245. case PCI_REGION0: return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
  246. case PCI_REGION1: return PCI_0MEMORY1_LOW_DECODE_ADDRESS;
  247. case PCI_REGION2: return PCI_0MEMORY2_LOW_DECODE_ADDRESS;
  248. case PCI_REGION3: return PCI_0MEMORY3_LOW_DECODE_ADDRESS;
  249. }
  250. case PCI_HOST1:
  251. switch(region) {
  252. case PCI_IO: return PCI_1I_O_LOW_DECODE_ADDRESS;
  253. case PCI_REGION0: return PCI_1MEMORY0_LOW_DECODE_ADDRESS;
  254. case PCI_REGION1: return PCI_1MEMORY1_LOW_DECODE_ADDRESS;
  255. case PCI_REGION2: return PCI_1MEMORY2_LOW_DECODE_ADDRESS;
  256. case PCI_REGION3: return PCI_1MEMORY3_LOW_DECODE_ADDRESS;
  257. }
  258. }
  259. return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
  260. }
  261. static unsigned int pciGetRemapOffset(PCI_HOST host, PCI_REGION region)
  262. {
  263. switch (host)
  264. {
  265. case PCI_HOST0:
  266. switch(region) {
  267. case PCI_IO: return PCI_0I_O_ADDRESS_REMAP;
  268. case PCI_REGION0: return PCI_0MEMORY0_ADDRESS_REMAP;
  269. case PCI_REGION1: return PCI_0MEMORY1_ADDRESS_REMAP;
  270. case PCI_REGION2: return PCI_0MEMORY2_ADDRESS_REMAP;
  271. case PCI_REGION3: return PCI_0MEMORY3_ADDRESS_REMAP;
  272. }
  273. case PCI_HOST1:
  274. switch(region) {
  275. case PCI_IO: return PCI_1I_O_ADDRESS_REMAP;
  276. case PCI_REGION0: return PCI_1MEMORY0_ADDRESS_REMAP;
  277. case PCI_REGION1: return PCI_1MEMORY1_ADDRESS_REMAP;
  278. case PCI_REGION2: return PCI_1MEMORY2_ADDRESS_REMAP;
  279. case PCI_REGION3: return PCI_1MEMORY3_ADDRESS_REMAP;
  280. }
  281. }
  282. return PCI_0MEMORY0_ADDRESS_REMAP;
  283. }
  284. bool pciMapSpace(PCI_HOST host, PCI_REGION region, unsigned int remapBase, unsigned int bankBase,unsigned int bankLength)
  285. {
  286. unsigned int low=0xfff;
  287. unsigned int high=0x0;
  288. unsigned int regOffset=pciGetRegOffset(host, region);
  289. unsigned int remapOffset=pciGetRemapOffset(host, region);
  290. if(bankLength!=0) {
  291. low = (bankBase >> 20) & 0xfff;
  292. high=((bankBase+bankLength)>>20)-1;
  293. }
  294. GT_REG_WRITE(regOffset, low | (1<<24)); /* no swapping */
  295. GT_REG_WRITE(regOffset+8, high);
  296. if(bankLength!=0) { /* must do AFTER writing maps */
  297. GT_REG_WRITE(remapOffset, remapBase>>20); /* sorry, 32 bits only.
  298. dont support upper 32
  299. in this driver */
  300. }
  301. return true;
  302. }
  303. unsigned int pciGetSpaceBase(PCI_HOST host, PCI_REGION region)
  304. {
  305. unsigned int low;
  306. unsigned int regOffset=pciGetRegOffset(host, region);
  307. GT_REG_READ(regOffset,&low);
  308. return (low&0xfff)<<20;
  309. }
  310. unsigned int pciGetSpaceSize(PCI_HOST host, PCI_REGION region)
  311. {
  312. unsigned int low,high;
  313. unsigned int regOffset=pciGetRegOffset(host, region);
  314. GT_REG_READ(regOffset,&low);
  315. GT_REG_READ(regOffset+8,&high);
  316. high&=0xfff;
  317. low&=0xfff;
  318. if(high<=low) return 0;
  319. return (high+1-low)<<20;
  320. }
  321. /********************************************************************
  322. * pciMapMemoryBank - Maps PCI_host memory bank "bank" for the slave.
  323. *
  324. * Inputs: base and size of PCI SCS
  325. *********************************************************************/
  326. void pciMapMemoryBank(PCI_HOST host, MEMORY_BANK bank, unsigned int pciDramBase,unsigned int pciDramSize)
  327. {
  328. pciDramBase = pciDramBase & 0xfffff000;
  329. pciDramBase = pciDramBase | (pciReadConfigReg(host,
  330. PCI_SCS_0_BASE_ADDRESS + 4*bank,SELF) & 0x00000fff);
  331. pciWriteConfigReg(host,PCI_SCS_0_BASE_ADDRESS + 4*bank,SELF,pciDramBase);
  332. if(pciDramSize == 0)
  333. pciDramSize ++;
  334. GT_REG_WRITE(pci_scs_bank_size[host][bank], pciDramSize-1);
  335. }
  336. /********************************************************************
  337. * pciSetRegionFeatures - This function modifys one of the 8 regions with
  338. * feature bits given as an input.
  339. * - Be advised to check the spec before modifying them.
  340. * Inputs: PCI_PROTECT_REGION region - one of the eight regions.
  341. * unsigned int features - See file: pci.h there are defintion for those
  342. * region features.
  343. * unsigned int baseAddress - The region base Address.
  344. * unsigned int topAddress - The region top Address.
  345. * Returns: false if one of the parameters is erroneous true otherwise.
  346. *********************************************************************/
  347. bool pciSetRegionFeatures(PCI_HOST host, PCI_ACCESS_REGIONS region,unsigned int features,
  348. unsigned int baseAddress,unsigned int regionLength)
  349. {
  350. unsigned int accessLow;
  351. unsigned int accessHigh;
  352. unsigned int accessTop = baseAddress + regionLength;
  353. if(regionLength == 0) /* close the region. */
  354. {
  355. pciDisableAccessRegion(host, region);
  356. return true;
  357. }
  358. /* base Address is store is bits [11:0] */
  359. accessLow = (baseAddress & 0xfff00000) >> 20;
  360. /* All the features are update according to the defines in pci.h (to be on
  361. the safe side we disable bits: [11:0] */
  362. accessLow = accessLow | (features & 0xfffff000);
  363. /* write to the Low Access Region register */
  364. GT_REG_WRITE( pci_access_control_base_0_low[host] + 0x10*region,accessLow);
  365. accessHigh = (accessTop & 0xfff00000) >> 20;
  366. /* write to the High Access Region register */
  367. GT_REG_WRITE(pci_access_control_top_0[host] + 0x10*region,accessHigh - 1);
  368. return true;
  369. }
  370. /********************************************************************
  371. * pciDisableAccessRegion - Disable The given Region by writing MAX size
  372. * to its low Address and MIN size to its high Address.
  373. *
  374. * Inputs: PCI_ACCESS_REGIONS region - The region we to be Disabled.
  375. * Returns: N/A.
  376. *********************************************************************/
  377. void pciDisableAccessRegion(PCI_HOST host, PCI_ACCESS_REGIONS region)
  378. {
  379. /* writing back the registers default values. */
  380. GT_REG_WRITE(pci_access_control_base_0_low[host] + 0x10*region,0x01001fff);
  381. GT_REG_WRITE(pci_access_control_top_0[host] + 0x10*region,0);
  382. }
  383. /********************************************************************
  384. * pciArbiterEnable - Enables PCI-0`s Arbitration mechanism.
  385. *
  386. * Inputs: N/A
  387. * Returns: true.
  388. *********************************************************************/
  389. bool pciArbiterEnable(PCI_HOST host)
  390. {
  391. unsigned int regData;
  392. GT_REG_READ(pci_arbiter_control[host],&regData);
  393. GT_REG_WRITE(pci_arbiter_control[host],regData | BIT31);
  394. return true;
  395. }
  396. /********************************************************************
  397. * pciArbiterDisable - Disable PCI-0`s Arbitration mechanism.
  398. *
  399. * Inputs: N/A
  400. * Returns: true
  401. *********************************************************************/
  402. bool pciArbiterDisable(PCI_HOST host)
  403. {
  404. unsigned int regData;
  405. GT_REG_READ(pci_arbiter_control[host],&regData);
  406. GT_REG_WRITE(pci_arbiter_control[host],regData & 0x7fffffff);
  407. return true;
  408. }
  409. /********************************************************************
  410. * pciParkingDisable - Park on last option disable, with this function you can
  411. * disable the park on last mechanism for each agent.
  412. * disabling this option for all agents results parking
  413. * on the internal master.
  414. *
  415. * Inputs: PCI_AGENT_PARK internalAgent - parking Disable for internal agent.
  416. * PCI_AGENT_PARK externalAgent0 - parking Disable for external#0 agent.
  417. * PCI_AGENT_PARK externalAgent1 - parking Disable for external#1 agent.
  418. * PCI_AGENT_PARK externalAgent2 - parking Disable for external#2 agent.
  419. * PCI_AGENT_PARK externalAgent3 - parking Disable for external#3 agent.
  420. * PCI_AGENT_PARK externalAgent4 - parking Disable for external#4 agent.
  421. * PCI_AGENT_PARK externalAgent5 - parking Disable for external#5 agent.
  422. * Returns: true
  423. *********************************************************************/
  424. bool pciParkingDisable(PCI_HOST host, PCI_AGENT_PARK internalAgent,
  425. PCI_AGENT_PARK externalAgent0,
  426. PCI_AGENT_PARK externalAgent1,
  427. PCI_AGENT_PARK externalAgent2,
  428. PCI_AGENT_PARK externalAgent3,
  429. PCI_AGENT_PARK externalAgent4,
  430. PCI_AGENT_PARK externalAgent5)
  431. {
  432. unsigned int regData;
  433. unsigned int writeData;
  434. GT_REG_READ(pci_arbiter_control[host],&regData);
  435. writeData = (internalAgent << 14) + (externalAgent0 << 15) + \
  436. (externalAgent1 << 16) + (externalAgent2 << 17) + \
  437. (externalAgent3 << 18) + (externalAgent4 << 19) + \
  438. (externalAgent5 << 20);
  439. regData = (regData & ~(0x7f<<14)) | writeData;
  440. GT_REG_WRITE(pci_arbiter_control[host],regData);
  441. return true;
  442. }
  443. /********************************************************************
  444. * pciSetRegionSnoopMode - This function modifys one of the 4 regions which
  445. * supports Cache Coherency in the PCI_n interface.
  446. * Inputs: region - One of the four regions.
  447. * snoopType - There is four optional Types:
  448. * 1. No Snoop.
  449. * 2. Snoop to WT region.
  450. * 3. Snoop to WB region.
  451. * 4. Snoop & Invalidate to WB region.
  452. * baseAddress - Base Address of this region.
  453. * regionLength - Region length.
  454. * Returns: false if one of the parameters is wrong otherwise return true.
  455. *********************************************************************/
  456. bool pciSetRegionSnoopMode(PCI_HOST host, PCI_SNOOP_REGION region,PCI_SNOOP_TYPE snoopType,
  457. unsigned int baseAddress,
  458. unsigned int regionLength)
  459. {
  460. unsigned int snoopXbaseAddress;
  461. unsigned int snoopXtopAddress;
  462. unsigned int data;
  463. unsigned int snoopHigh = baseAddress + regionLength;
  464. if( (region > PCI_SNOOP_REGION3) || (snoopType > PCI_SNOOP_WB) )
  465. return false;
  466. snoopXbaseAddress = pci_snoop_control_base_0_low[host] + 0x10 * region;
  467. snoopXtopAddress = pci_snoop_control_top_0[host] + 0x10 * region;
  468. if(regionLength == 0) /* closing the region */
  469. {
  470. GT_REG_WRITE(snoopXbaseAddress,0x0000ffff);
  471. GT_REG_WRITE(snoopXtopAddress,0);
  472. return true;
  473. }
  474. baseAddress = baseAddress & 0xfff00000; /* Granularity of 1MByte */
  475. data = (baseAddress >> 20) | snoopType << 12;
  476. GT_REG_WRITE(snoopXbaseAddress,data);
  477. snoopHigh = (snoopHigh & 0xfff00000) >> 20;
  478. GT_REG_WRITE(snoopXtopAddress,snoopHigh - 1);
  479. return true;
  480. }
  481. /*
  482. *
  483. */
  484. static int gt_read_config_dword(struct pci_controller *hose,
  485. pci_dev_t dev,
  486. int offset, u32* value)
  487. {
  488. int bus = PCI_BUS(dev);
  489. if ((bus == local_buses[0]) || (bus == local_buses[1])){
  490. *value = pciReadConfigReg((PCI_HOST) hose->cfg_addr, offset,
  491. PCI_DEV(dev));
  492. } else {
  493. *value = pciOverBridgeReadConfigReg((PCI_HOST) hose->cfg_addr,
  494. offset, PCI_DEV(dev), bus);
  495. }
  496. return 0;
  497. }
  498. static int gt_write_config_dword(struct pci_controller *hose,
  499. pci_dev_t dev,
  500. int offset, u32 value)
  501. {
  502. int bus = PCI_BUS(dev);
  503. if ((bus == local_buses[0]) || (bus == local_buses[1])){
  504. pciWriteConfigReg((PCI_HOST)hose->cfg_addr, offset,
  505. PCI_DEV(dev), value);
  506. } else {
  507. pciOverBridgeWriteConfigReg((PCI_HOST)hose->cfg_addr, offset,
  508. PCI_DEV(dev), value, bus);
  509. }
  510. return 0;
  511. }
  512. /*
  513. *
  514. */
  515. static void gt_setup_ide(struct pci_controller *hose,
  516. pci_dev_t dev, struct pci_config_table *entry)
  517. {
  518. static const int ide_bar[]={8,4,8,4,0,0};
  519. u32 bar_response, bar_value;
  520. int bar;
  521. for (bar=0; bar<6; bar++)
  522. {
  523. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar*4, 0x0);
  524. pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + bar*4, &bar_response);
  525. pciauto_region_allocate(bar_response & PCI_BASE_ADDRESS_SPACE_IO ?
  526. hose->pci_io : hose->pci_mem, ide_bar[bar], &bar_value);
  527. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + bar*4, bar_value);
  528. }
  529. }
  530. static void gt_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  531. {
  532. unsigned char pin, irq;
  533. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
  534. if(pin == 1) { /* only allow INT A */
  535. irq = pci_irq_swizzle[(PCI_HOST)hose->cfg_addr][PCI_DEV(dev)];
  536. if(irq)
  537. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  538. }
  539. }
  540. struct pci_config_table gt_config_table[] = {
  541. { PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE,
  542. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_ide},
  543. { }
  544. };
  545. struct pci_controller pci0_hose = {
  546. fixup_irq: gt_fixup_irq,
  547. config_table: gt_config_table,
  548. };
  549. struct pci_controller pci1_hose = {
  550. fixup_irq: gt_fixup_irq,
  551. config_table: gt_config_table,
  552. };
  553. void
  554. pci_init_board(void)
  555. {
  556. unsigned int command;
  557. pci0_hose.first_busno = 0;
  558. pci0_hose.last_busno = 0xff;
  559. local_buses[0] = pci0_hose.first_busno;
  560. /* PCI memory space */
  561. pci_set_region(pci0_hose.regions + 0,
  562. CFG_PCI0_0_MEM_SPACE,
  563. CFG_PCI0_0_MEM_SPACE,
  564. CFG_PCI0_MEM_SIZE,
  565. PCI_REGION_MEM);
  566. /* PCI I/O space */
  567. pci_set_region(pci0_hose.regions + 1,
  568. CFG_PCI0_IO_SPACE_PCI,
  569. CFG_PCI0_IO_SPACE,
  570. CFG_PCI0_IO_SIZE,
  571. PCI_REGION_IO);
  572. pci_set_ops(&pci0_hose,
  573. pci_hose_read_config_byte_via_dword,
  574. pci_hose_read_config_word_via_dword,
  575. gt_read_config_dword,
  576. pci_hose_write_config_byte_via_dword,
  577. pci_hose_write_config_word_via_dword,
  578. gt_write_config_dword);
  579. pci0_hose.region_count = 2;
  580. pci0_hose.cfg_addr = (unsigned int*) PCI_HOST0;
  581. pci_register_hose(&pci0_hose);
  582. pciArbiterEnable(PCI_HOST0);
  583. pciParkingDisable(PCI_HOST0,1,1,1,1,1,1,1);
  584. command = pciReadConfigReg(PCI_HOST0, PCI_COMMAND, SELF);
  585. command |= PCI_COMMAND_MASTER;
  586. pciWriteConfigReg(PCI_HOST0, PCI_COMMAND, SELF, command);
  587. pci0_hose.last_busno = pci_hose_scan(&pci0_hose);
  588. command = pciReadConfigReg(PCI_HOST0, PCI_COMMAND, SELF);
  589. command |= PCI_COMMAND_MEMORY;
  590. pciWriteConfigReg(PCI_HOST0, PCI_COMMAND, SELF, command);
  591. pci1_hose.first_busno = pci0_hose.last_busno + 1;
  592. pci1_hose.last_busno = 0xff;
  593. pci1_hose.current_busno = pci0_hose.current_busno;
  594. local_buses[1] = pci1_hose.first_busno;
  595. /* PCI memory space */
  596. pci_set_region(pci1_hose.regions + 0,
  597. CFG_PCI1_0_MEM_SPACE,
  598. CFG_PCI1_0_MEM_SPACE,
  599. CFG_PCI1_MEM_SIZE,
  600. PCI_REGION_MEM);
  601. /* PCI I/O space */
  602. pci_set_region(pci1_hose.regions + 1,
  603. CFG_PCI1_IO_SPACE_PCI,
  604. CFG_PCI1_IO_SPACE,
  605. CFG_PCI1_IO_SIZE,
  606. PCI_REGION_IO);
  607. pci_set_ops(&pci1_hose,
  608. pci_hose_read_config_byte_via_dword,
  609. pci_hose_read_config_word_via_dword,
  610. gt_read_config_dword,
  611. pci_hose_write_config_byte_via_dword,
  612. pci_hose_write_config_word_via_dword,
  613. gt_write_config_dword);
  614. pci1_hose.region_count = 2;
  615. pci1_hose.cfg_addr = (unsigned int*) PCI_HOST1;
  616. pci_register_hose(&pci1_hose);
  617. pciArbiterEnable(PCI_HOST1);
  618. pciParkingDisable(PCI_HOST1,1,1,1,1,1,1,1);
  619. command = pciReadConfigReg(PCI_HOST1, PCI_COMMAND, SELF);
  620. command |= PCI_COMMAND_MASTER;
  621. pciWriteConfigReg(PCI_HOST1, PCI_COMMAND, SELF, command);
  622. pci1_hose.last_busno = pci_hose_scan(&pci1_hose);
  623. command = pciReadConfigReg(PCI_HOST1, PCI_COMMAND, SELF);
  624. command |= PCI_COMMAND_MEMORY;
  625. pciWriteConfigReg(PCI_HOST1, PCI_COMMAND, SELF, command);
  626. }