pci.c 24 KB

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