pci.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. /* PCI.c - PCI functions */
  25. #include <common.h>
  26. #include <pci.h>
  27. #include "../include/pci.h"
  28. #undef DEBUG
  29. #undef IDE_SET_NATIVE_MODE
  30. static unsigned int local_buses[] = { 0, 0 };
  31. static const unsigned char pci_irq_swizzle[2][PCI_MAX_DEVICES] = {
  32. {0, 0, 0, 0, 0, 0, 0, 27, 27, [9 ... PCI_MAX_DEVICES - 1] = 0 },
  33. {0, 0, 0, 0, 0, 0, 0, 29, 29, [9 ... PCI_MAX_DEVICES - 1] = 0 },
  34. };
  35. #ifdef DEBUG
  36. static const unsigned int pci_bus_list[] = { PCI_0_MODE, PCI_1_MODE };
  37. static void gt_pci_bus_mode_display (PCI_HOST host)
  38. {
  39. unsigned int mode;
  40. mode = (GTREGREAD (pci_bus_list[host]) & (BIT4 | BIT5)) >> 4;
  41. switch (mode) {
  42. case 0:
  43. printf ("PCI %d bus mode: Conventional PCI\n", host);
  44. break;
  45. case 1:
  46. printf ("PCI %d bus mode: 66 Mhz PCIX\n", host);
  47. break;
  48. case 2:
  49. printf ("PCI %d bus mode: 100 Mhz PCIX\n", host);
  50. break;
  51. case 3:
  52. printf ("PCI %d bus mode: 133 Mhz PCIX\n", host);
  53. break;
  54. default:
  55. printf ("Unknown BUS %d\n", mode);
  56. }
  57. }
  58. #endif
  59. static const unsigned int pci_p2p_configuration_reg[] = {
  60. PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION
  61. };
  62. static const unsigned int pci_configuration_address[] = {
  63. PCI_0CONFIGURATION_ADDRESS, PCI_1CONFIGURATION_ADDRESS
  64. };
  65. static const unsigned int pci_configuration_data[] = {
  66. PCI_0CONFIGURATION_DATA_VIRTUAL_REGISTER,
  67. PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER
  68. };
  69. static const unsigned int pci_error_cause_reg[] = {
  70. PCI_0ERROR_CAUSE, PCI_1ERROR_CAUSE
  71. };
  72. static const unsigned int pci_arbiter_control[] = {
  73. PCI_0ARBITER_CONTROL, PCI_1ARBITER_CONTROL
  74. };
  75. static const unsigned int pci_address_space_en[] = {
  76. PCI_0_BASE_ADDR_REG_ENABLE, PCI_1_BASE_ADDR_REG_ENABLE
  77. };
  78. static const unsigned int pci_snoop_control_base_0_low[] = {
  79. PCI_0SNOOP_CONTROL_BASE_0_LOW, PCI_1SNOOP_CONTROL_BASE_0_LOW
  80. };
  81. static const unsigned int pci_snoop_control_top_0[] = {
  82. PCI_0SNOOP_CONTROL_TOP_0, PCI_1SNOOP_CONTROL_TOP_0
  83. };
  84. static const unsigned int pci_access_control_base_0_low[] = {
  85. PCI_0ACCESS_CONTROL_BASE_0_LOW, PCI_1ACCESS_CONTROL_BASE_0_LOW
  86. };
  87. static const unsigned int pci_access_control_top_0[] = {
  88. PCI_0ACCESS_CONTROL_TOP_0, PCI_1ACCESS_CONTROL_TOP_0
  89. };
  90. static const unsigned int pci_scs_bank_size[2][4] = {
  91. {PCI_0SCS_0_BANK_SIZE, PCI_0SCS_1_BANK_SIZE,
  92. PCI_0SCS_2_BANK_SIZE, PCI_0SCS_3_BANK_SIZE},
  93. {PCI_1SCS_0_BANK_SIZE, PCI_1SCS_1_BANK_SIZE,
  94. PCI_1SCS_2_BANK_SIZE, PCI_1SCS_3_BANK_SIZE}
  95. };
  96. static const unsigned int pci_p2p_configuration[] = {
  97. PCI_0P2P_CONFIGURATION, PCI_1P2P_CONFIGURATION
  98. };
  99. /********************************************************************
  100. * pciWriteConfigReg - Write to a PCI configuration register
  101. * - Make sure the GT is configured as a master before writing
  102. * to another device on the PCI.
  103. * - The function takes care of Big/Little endian conversion.
  104. *
  105. *
  106. * Inputs: unsigned int regOffset: The register offset as it apears in the GT spec
  107. * (or any other PCI device spec)
  108. * pciDevNum: The device number needs to be addressed.
  109. *
  110. * Configuration Address 0xCF8:
  111. *
  112. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  113. * |congif|Reserved| Bus |Device|Function|Register|00|
  114. * |Enable| |Number|Number| Number | Number | | <=field Name
  115. *
  116. *********************************************************************/
  117. void pciWriteConfigReg (PCI_HOST host, unsigned int regOffset,
  118. unsigned int pciDevNum, unsigned int data)
  119. {
  120. volatile unsigned int DataForAddrReg;
  121. unsigned int functionNum;
  122. unsigned int busNum = 0;
  123. unsigned int addr;
  124. if (pciDevNum > 32) /* illegal device Number */
  125. return;
  126. if (pciDevNum == SELF) { /* configure our configuration space. */
  127. pciDevNum =
  128. (GTREGREAD (pci_p2p_configuration_reg[host]) >> 24) &
  129. 0x1f;
  130. busNum = GTREGREAD (pci_p2p_configuration_reg[host]) &
  131. 0xff0000;
  132. }
  133. functionNum = regOffset & 0x00000700;
  134. pciDevNum = pciDevNum << 11;
  135. regOffset = regOffset & 0xfc;
  136. DataForAddrReg =
  137. (regOffset | pciDevNum | functionNum | busNum) | BIT31;
  138. GT_REG_WRITE (pci_configuration_address[host], DataForAddrReg);
  139. GT_REG_READ (pci_configuration_address[host], &addr);
  140. if (addr != DataForAddrReg)
  141. return;
  142. GT_REG_WRITE (pci_configuration_data[host], data);
  143. }
  144. /********************************************************************
  145. * pciReadConfigReg - Read from a PCI0 configuration register
  146. * - Make sure the GT is configured as a master before reading
  147. * from another device on the PCI.
  148. * - The function takes care of Big/Little endian conversion.
  149. * INPUTS: regOffset: The register offset as it apears in the GT spec (or PCI
  150. * spec)
  151. * pciDevNum: The device number needs to be addressed.
  152. * RETURNS: data , if the data == 0xffffffff check the master abort bit in the
  153. * cause register to make sure the data is valid
  154. *
  155. * Configuration Address 0xCF8:
  156. *
  157. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  158. * |congif|Reserved| Bus |Device|Function|Register|00|
  159. * |Enable| |Number|Number| Number | Number | | <=field Name
  160. *
  161. *********************************************************************/
  162. unsigned int pciReadConfigReg (PCI_HOST host, unsigned int regOffset,
  163. unsigned int pciDevNum)
  164. {
  165. volatile unsigned int DataForAddrReg;
  166. unsigned int data;
  167. unsigned int functionNum;
  168. unsigned int busNum = 0;
  169. if (pciDevNum > 32) /* illegal device Number */
  170. return 0xffffffff;
  171. if (pciDevNum == SELF) { /* configure our configuration space. */
  172. pciDevNum =
  173. (GTREGREAD (pci_p2p_configuration_reg[host]) >> 24) &
  174. 0x1f;
  175. busNum = GTREGREAD (pci_p2p_configuration_reg[host]) &
  176. 0xff0000;
  177. }
  178. functionNum = regOffset & 0x00000700;
  179. pciDevNum = pciDevNum << 11;
  180. regOffset = regOffset & 0xfc;
  181. DataForAddrReg =
  182. (regOffset | pciDevNum | functionNum | busNum) | BIT31;
  183. GT_REG_WRITE (pci_configuration_address[host], DataForAddrReg);
  184. GT_REG_READ (pci_configuration_address[host], &data);
  185. if (data != DataForAddrReg)
  186. return 0xffffffff;
  187. GT_REG_READ (pci_configuration_data[host], &data);
  188. return data;
  189. }
  190. /********************************************************************
  191. * pciOverBridgeWriteConfigReg - Write to a PCI configuration register where
  192. * the agent is placed on another Bus. For more
  193. * information read P2P in the PCI spec.
  194. *
  195. * Inputs: unsigned int regOffset - The register offset as it apears in the
  196. * GT spec (or any other PCI device spec).
  197. * unsigned int pciDevNum - The device number needs to be addressed.
  198. * unsigned int busNum - On which bus does the Target agent connect
  199. * to.
  200. * unsigned int data - data to be written.
  201. *
  202. * Configuration Address 0xCF8:
  203. *
  204. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  205. * |congif|Reserved| Bus |Device|Function|Register|01|
  206. * |Enable| |Number|Number| Number | Number | | <=field Name
  207. *
  208. * The configuration Address is configure as type-I (bits[1:0] = '01') due to
  209. * PCI spec referring to P2P.
  210. *
  211. *********************************************************************/
  212. void pciOverBridgeWriteConfigReg (PCI_HOST host,
  213. unsigned int regOffset,
  214. unsigned int pciDevNum,
  215. unsigned int busNum, unsigned int data)
  216. {
  217. unsigned int DataForReg;
  218. unsigned int functionNum;
  219. functionNum = regOffset & 0x00000700;
  220. pciDevNum = pciDevNum << 11;
  221. regOffset = regOffset & 0xff;
  222. busNum = busNum << 16;
  223. if (pciDevNum == SELF) { /* This board */
  224. DataForReg = (regOffset | pciDevNum | functionNum) | BIT0;
  225. } else {
  226. DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
  227. BIT31 | BIT0;
  228. }
  229. GT_REG_WRITE (pci_configuration_address[host], DataForReg);
  230. GT_REG_WRITE (pci_configuration_data[host], data);
  231. }
  232. /********************************************************************
  233. * pciOverBridgeReadConfigReg - Read from a PCIn configuration register where
  234. * the agent target locate on another PCI bus.
  235. * - Make sure the GT is configured as a master
  236. * before reading from another device on the PCI.
  237. * - The function takes care of Big/Little endian
  238. * conversion.
  239. * INPUTS: regOffset: The register offset as it apears in the GT spec (or PCI
  240. * spec). (configuration register offset.)
  241. * pciDevNum: The device number needs to be addressed.
  242. * busNum: the Bus number where the agent is place.
  243. * RETURNS: data , if the data == 0xffffffff check the master abort bit in the
  244. * cause register to make sure the data is valid
  245. *
  246. * Configuration Address 0xCF8:
  247. *
  248. * 31 30 24 23 16 15 11 10 8 7 2 0 <=bit Number
  249. * |congif|Reserved| Bus |Device|Function|Register|01|
  250. * |Enable| |Number|Number| Number | Number | | <=field Name
  251. *
  252. *********************************************************************/
  253. unsigned int pciOverBridgeReadConfigReg (PCI_HOST host,
  254. unsigned int regOffset,
  255. unsigned int pciDevNum,
  256. unsigned int busNum)
  257. {
  258. unsigned int DataForReg;
  259. unsigned int data;
  260. unsigned int functionNum;
  261. functionNum = regOffset & 0x00000700;
  262. pciDevNum = pciDevNum << 11;
  263. regOffset = regOffset & 0xff;
  264. busNum = busNum << 16;
  265. if (pciDevNum == SELF) { /* This board */
  266. DataForReg = (regOffset | pciDevNum | functionNum) | BIT31;
  267. } else { /* agent on another bus */
  268. DataForReg = (regOffset | pciDevNum | functionNum | busNum) |
  269. BIT0 | BIT31;
  270. }
  271. GT_REG_WRITE (pci_configuration_address[host], DataForReg);
  272. GT_REG_READ (pci_configuration_data[host], &data);
  273. return data;
  274. }
  275. /********************************************************************
  276. * pciGetRegOffset - Gets the register offset for this region config.
  277. *
  278. * INPUT: Bus, Region - The bus and region we ask for its base address.
  279. * OUTPUT: N/A
  280. * RETURNS: PCI register base address
  281. *********************************************************************/
  282. static unsigned int pciGetRegOffset (PCI_HOST host, PCI_REGION region)
  283. {
  284. switch (host) {
  285. case PCI_HOST0:
  286. switch (region) {
  287. case PCI_IO:
  288. return PCI_0I_O_LOW_DECODE_ADDRESS;
  289. case PCI_REGION0:
  290. return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
  291. case PCI_REGION1:
  292. return PCI_0MEMORY1_LOW_DECODE_ADDRESS;
  293. case PCI_REGION2:
  294. return PCI_0MEMORY2_LOW_DECODE_ADDRESS;
  295. case PCI_REGION3:
  296. return PCI_0MEMORY3_LOW_DECODE_ADDRESS;
  297. }
  298. case PCI_HOST1:
  299. switch (region) {
  300. case PCI_IO:
  301. return PCI_1I_O_LOW_DECODE_ADDRESS;
  302. case PCI_REGION0:
  303. return PCI_1MEMORY0_LOW_DECODE_ADDRESS;
  304. case PCI_REGION1:
  305. return PCI_1MEMORY1_LOW_DECODE_ADDRESS;
  306. case PCI_REGION2:
  307. return PCI_1MEMORY2_LOW_DECODE_ADDRESS;
  308. case PCI_REGION3:
  309. return PCI_1MEMORY3_LOW_DECODE_ADDRESS;
  310. }
  311. }
  312. return PCI_0MEMORY0_LOW_DECODE_ADDRESS;
  313. }
  314. static unsigned int pciGetRemapOffset (PCI_HOST host, PCI_REGION region)
  315. {
  316. switch (host) {
  317. case PCI_HOST0:
  318. switch (region) {
  319. case PCI_IO:
  320. return PCI_0I_O_ADDRESS_REMAP;
  321. case PCI_REGION0:
  322. return PCI_0MEMORY0_ADDRESS_REMAP;
  323. case PCI_REGION1:
  324. return PCI_0MEMORY1_ADDRESS_REMAP;
  325. case PCI_REGION2:
  326. return PCI_0MEMORY2_ADDRESS_REMAP;
  327. case PCI_REGION3:
  328. return PCI_0MEMORY3_ADDRESS_REMAP;
  329. }
  330. case PCI_HOST1:
  331. switch (region) {
  332. case PCI_IO:
  333. return PCI_1I_O_ADDRESS_REMAP;
  334. case PCI_REGION0:
  335. return PCI_1MEMORY0_ADDRESS_REMAP;
  336. case PCI_REGION1:
  337. return PCI_1MEMORY1_ADDRESS_REMAP;
  338. case PCI_REGION2:
  339. return PCI_1MEMORY2_ADDRESS_REMAP;
  340. case PCI_REGION3:
  341. return PCI_1MEMORY3_ADDRESS_REMAP;
  342. }
  343. }
  344. return PCI_0MEMORY0_ADDRESS_REMAP;
  345. }
  346. /********************************************************************
  347. * pciGetBaseAddress - Gets the base address of a PCI.
  348. * - If the PCI size is 0 then this base address has no meaning!!!
  349. *
  350. *
  351. * INPUT: Bus, Region - The bus and region we ask for its base address.
  352. * OUTPUT: N/A
  353. * RETURNS: PCI base address.
  354. *********************************************************************/
  355. unsigned int pciGetBaseAddress (PCI_HOST host, PCI_REGION region)
  356. {
  357. unsigned int regBase;
  358. unsigned int regEnd;
  359. unsigned int regOffset = pciGetRegOffset (host, region);
  360. GT_REG_READ (regOffset, &regBase);
  361. GT_REG_READ (regOffset + 8, &regEnd);
  362. if (regEnd <= regBase)
  363. return 0xffffffff; /* ERROR !!! */
  364. regBase = regBase << 16;
  365. return regBase;
  366. }
  367. bool pciMapSpace (PCI_HOST host, PCI_REGION region, unsigned int remapBase,
  368. unsigned int bankBase, unsigned int bankLength)
  369. {
  370. unsigned int low = 0xfff;
  371. unsigned int high = 0x0;
  372. unsigned int regOffset = pciGetRegOffset (host, region);
  373. unsigned int remapOffset = pciGetRemapOffset (host, region);
  374. if (bankLength != 0) {
  375. low = (bankBase >> 16) & 0xffff;
  376. high = ((bankBase + bankLength) >> 16) - 1;
  377. }
  378. GT_REG_WRITE (regOffset, low | (1 << 24)); /* no swapping */
  379. GT_REG_WRITE (regOffset + 8, high);
  380. if (bankLength != 0) { /* must do AFTER writing maps */
  381. GT_REG_WRITE (remapOffset, remapBase >> 16); /* sorry, 32 bits only.
  382. dont support upper 32
  383. in this driver */
  384. }
  385. return true;
  386. }
  387. unsigned int pciGetSpaceBase (PCI_HOST host, PCI_REGION region)
  388. {
  389. unsigned int low;
  390. unsigned int regOffset = pciGetRegOffset (host, region);
  391. GT_REG_READ (regOffset, &low);
  392. return (low & 0xffff) << 16;
  393. }
  394. unsigned int pciGetSpaceSize (PCI_HOST host, PCI_REGION region)
  395. {
  396. unsigned int low, high;
  397. unsigned int regOffset = pciGetRegOffset (host, region);
  398. GT_REG_READ (regOffset, &low);
  399. GT_REG_READ (regOffset + 8, &high);
  400. return ((high & 0xffff) + 1) << 16;
  401. }
  402. /* ronen - 7/Dec/03*/
  403. /********************************************************************
  404. * gtPciDisable/EnableInternalBAR - This function enable/disable PCI BARS.
  405. * Inputs: one of the PCI BAR
  406. *********************************************************************/
  407. void gtPciEnableInternalBAR (PCI_HOST host, PCI_INTERNAL_BAR pciBAR)
  408. {
  409. RESET_REG_BITS (pci_address_space_en[host], BIT0 << pciBAR);
  410. }
  411. void gtPciDisableInternalBAR (PCI_HOST host, PCI_INTERNAL_BAR pciBAR)
  412. {
  413. SET_REG_BITS (pci_address_space_en[host], BIT0 << pciBAR);
  414. }
  415. /********************************************************************
  416. * pciMapMemoryBank - Maps PCI_host memory bank "bank" for the slave.
  417. *
  418. * Inputs: base and size of PCI SCS
  419. *********************************************************************/
  420. void pciMapMemoryBank (PCI_HOST host, MEMORY_BANK bank,
  421. unsigned int pciDramBase, unsigned int pciDramSize)
  422. {
  423. /*ronen different function for 3rd bank. */
  424. unsigned int offset = (bank < 2) ? bank * 8 : 0x100 + (bank - 2) * 8;
  425. pciDramBase = pciDramBase & 0xfffff000;
  426. pciDramBase = pciDramBase | (pciReadConfigReg (host,
  427. PCI_SCS_0_BASE_ADDRESS
  428. + offset,
  429. SELF) & 0x00000fff);
  430. pciWriteConfigReg (host, PCI_SCS_0_BASE_ADDRESS + offset, SELF,
  431. pciDramBase);
  432. if (pciDramSize == 0)
  433. pciDramSize++;
  434. GT_REG_WRITE (pci_scs_bank_size[host][bank], pciDramSize - 1);
  435. gtPciEnableInternalBAR (host, bank);
  436. }
  437. /********************************************************************
  438. * pciSetRegionFeatures - This function modifys one of the 8 regions with
  439. * feature bits given as an input.
  440. * - Be advised to check the spec before modifying them.
  441. * Inputs: PCI_PROTECT_REGION region - one of the eight regions.
  442. * unsigned int features - See file: pci.h there are defintion for those
  443. * region features.
  444. * unsigned int baseAddress - The region base Address.
  445. * unsigned int topAddress - The region top Address.
  446. * Returns: false if one of the parameters is erroneous true otherwise.
  447. *********************************************************************/
  448. bool pciSetRegionFeatures (PCI_HOST host, PCI_ACCESS_REGIONS region,
  449. unsigned int features, unsigned int baseAddress,
  450. unsigned int regionLength)
  451. {
  452. unsigned int accessLow;
  453. unsigned int accessHigh;
  454. unsigned int accessTop = baseAddress + regionLength;
  455. if (regionLength == 0) { /* close the region. */
  456. pciDisableAccessRegion (host, region);
  457. return true;
  458. }
  459. /* base Address is store is bits [11:0] */
  460. accessLow = (baseAddress & 0xfff00000) >> 20;
  461. /* All the features are update according to the defines in pci.h (to be on
  462. the safe side we disable bits: [11:0] */
  463. accessLow = accessLow | (features & 0xfffff000);
  464. /* write to the Low Access Region register */
  465. GT_REG_WRITE (pci_access_control_base_0_low[host] + 0x10 * region,
  466. accessLow);
  467. accessHigh = (accessTop & 0xfff00000) >> 20;
  468. /* write to the High Access Region register */
  469. GT_REG_WRITE (pci_access_control_top_0[host] + 0x10 * region,
  470. accessHigh - 1);
  471. return true;
  472. }
  473. /********************************************************************
  474. * pciDisableAccessRegion - Disable The given Region by writing MAX size
  475. * to its low Address and MIN size to its high Address.
  476. *
  477. * Inputs: PCI_ACCESS_REGIONS region - The region we to be Disabled.
  478. * Returns: N/A.
  479. *********************************************************************/
  480. void pciDisableAccessRegion (PCI_HOST host, PCI_ACCESS_REGIONS region)
  481. {
  482. /* writing back the registers default values. */
  483. GT_REG_WRITE (pci_access_control_base_0_low[host] + 0x10 * region,
  484. 0x01001fff);
  485. GT_REG_WRITE (pci_access_control_top_0[host] + 0x10 * region, 0);
  486. }
  487. /********************************************************************
  488. * pciArbiterEnable - Enables PCI-0`s Arbitration mechanism.
  489. *
  490. * Inputs: N/A
  491. * Returns: true.
  492. *********************************************************************/
  493. bool pciArbiterEnable (PCI_HOST host)
  494. {
  495. unsigned int regData;
  496. GT_REG_READ (pci_arbiter_control[host], &regData);
  497. GT_REG_WRITE (pci_arbiter_control[host], regData | BIT31);
  498. return true;
  499. }
  500. /********************************************************************
  501. * pciArbiterDisable - Disable PCI-0`s Arbitration mechanism.
  502. *
  503. * Inputs: N/A
  504. * Returns: true
  505. *********************************************************************/
  506. bool pciArbiterDisable (PCI_HOST host)
  507. {
  508. unsigned int regData;
  509. GT_REG_READ (pci_arbiter_control[host], &regData);
  510. GT_REG_WRITE (pci_arbiter_control[host], regData & 0x7fffffff);
  511. return true;
  512. }
  513. /********************************************************************
  514. * pciSetArbiterAgentsPriority - Priority setup for the PCI agents (Hi or Low)
  515. *
  516. * Inputs: PCI_AGENT_PRIO internalAgent - priotity for internal agent.
  517. * PCI_AGENT_PRIO externalAgent0 - priotity for external#0 agent.
  518. * PCI_AGENT_PRIO externalAgent1 - priotity for external#1 agent.
  519. * PCI_AGENT_PRIO externalAgent2 - priotity for external#2 agent.
  520. * PCI_AGENT_PRIO externalAgent3 - priotity for external#3 agent.
  521. * PCI_AGENT_PRIO externalAgent4 - priotity for external#4 agent.
  522. * PCI_AGENT_PRIO externalAgent5 - priotity for external#5 agent.
  523. * Returns: true
  524. *********************************************************************/
  525. bool pciSetArbiterAgentsPriority (PCI_HOST host, PCI_AGENT_PRIO internalAgent,
  526. PCI_AGENT_PRIO externalAgent0,
  527. PCI_AGENT_PRIO externalAgent1,
  528. PCI_AGENT_PRIO externalAgent2,
  529. PCI_AGENT_PRIO externalAgent3,
  530. PCI_AGENT_PRIO externalAgent4,
  531. PCI_AGENT_PRIO externalAgent5)
  532. {
  533. unsigned int regData;
  534. unsigned int writeData;
  535. GT_REG_READ (pci_arbiter_control[host], &regData);
  536. writeData = (internalAgent << 7) + (externalAgent0 << 8) +
  537. (externalAgent1 << 9) + (externalAgent2 << 10) +
  538. (externalAgent3 << 11) + (externalAgent4 << 12) +
  539. (externalAgent5 << 13);
  540. regData = (regData & 0xffffc07f) | writeData;
  541. GT_REG_WRITE (pci_arbiter_control[host], regData & regData);
  542. return true;
  543. }
  544. /********************************************************************
  545. * pciParkingDisable - Park on last option disable, with this function you can
  546. * disable the park on last mechanism for each agent.
  547. * disabling this option for all agents results parking
  548. * on the internal master.
  549. *
  550. * Inputs: PCI_AGENT_PARK internalAgent - parking Disable for internal agent.
  551. * PCI_AGENT_PARK externalAgent0 - parking Disable for external#0 agent.
  552. * PCI_AGENT_PARK externalAgent1 - parking Disable for external#1 agent.
  553. * PCI_AGENT_PARK externalAgent2 - parking Disable for external#2 agent.
  554. * PCI_AGENT_PARK externalAgent3 - parking Disable for external#3 agent.
  555. * PCI_AGENT_PARK externalAgent4 - parking Disable for external#4 agent.
  556. * PCI_AGENT_PARK externalAgent5 - parking Disable for external#5 agent.
  557. * Returns: true
  558. *********************************************************************/
  559. bool pciParkingDisable (PCI_HOST host, PCI_AGENT_PARK internalAgent,
  560. PCI_AGENT_PARK externalAgent0,
  561. PCI_AGENT_PARK externalAgent1,
  562. PCI_AGENT_PARK externalAgent2,
  563. PCI_AGENT_PARK externalAgent3,
  564. PCI_AGENT_PARK externalAgent4,
  565. PCI_AGENT_PARK externalAgent5)
  566. {
  567. unsigned int regData;
  568. unsigned int writeData;
  569. GT_REG_READ (pci_arbiter_control[host], &regData);
  570. writeData = (internalAgent << 14) + (externalAgent0 << 15) +
  571. (externalAgent1 << 16) + (externalAgent2 << 17) +
  572. (externalAgent3 << 18) + (externalAgent4 << 19) +
  573. (externalAgent5 << 20);
  574. regData = (regData & ~(0x7f << 14)) | writeData;
  575. GT_REG_WRITE (pci_arbiter_control[host], regData);
  576. return true;
  577. }
  578. /********************************************************************
  579. * pciEnableBrokenAgentDetection - A master is said to be broken if it fails to
  580. * respond to grant assertion within a window specified in
  581. * the input value: 'brokenValue'.
  582. *
  583. * Inputs: unsigned char brokenValue - A value which limits the Master to hold the
  584. * grant without asserting frame.
  585. * Returns: Error for illegal broken value otherwise true.
  586. *********************************************************************/
  587. bool pciEnableBrokenAgentDetection (PCI_HOST host, unsigned char brokenValue)
  588. {
  589. unsigned int data;
  590. unsigned int regData;
  591. if (brokenValue > 0xf)
  592. return false; /* brokenValue must be 4 bit */
  593. data = brokenValue << 3;
  594. GT_REG_READ (pci_arbiter_control[host], &regData);
  595. regData = (regData & 0xffffff87) | data;
  596. GT_REG_WRITE (pci_arbiter_control[host], regData | BIT1);
  597. return true;
  598. }
  599. /********************************************************************
  600. * pciDisableBrokenAgentDetection - This function disable the Broken agent
  601. * Detection mechanism.
  602. * NOTE: This operation may cause a dead lock on the
  603. * pci0 arbitration.
  604. *
  605. * Inputs: N/A
  606. * Returns: true.
  607. *********************************************************************/
  608. bool pciDisableBrokenAgentDetection (PCI_HOST host)
  609. {
  610. unsigned int regData;
  611. GT_REG_READ (pci_arbiter_control[host], &regData);
  612. regData = regData & 0xfffffffd;
  613. GT_REG_WRITE (pci_arbiter_control[host], regData);
  614. return true;
  615. }
  616. /********************************************************************
  617. * pciP2PConfig - This function set the PCI_n P2P configurate.
  618. * For more information on the P2P read PCI spec.
  619. *
  620. * Inputs: unsigned int SecondBusLow - Secondery PCI interface Bus Range Lower
  621. * Boundry.
  622. * unsigned int SecondBusHigh - Secondry PCI interface Bus Range upper
  623. * Boundry.
  624. * unsigned int busNum - The CPI bus number to which the PCI interface
  625. * is connected.
  626. * unsigned int devNum - The PCI interface's device number.
  627. *
  628. * Returns: true.
  629. *********************************************************************/
  630. bool pciP2PConfig (PCI_HOST host, unsigned int SecondBusLow,
  631. unsigned int SecondBusHigh,
  632. unsigned int busNum, unsigned int devNum)
  633. {
  634. unsigned int regData;
  635. regData = (SecondBusLow & 0xff) | ((SecondBusHigh & 0xff) << 8) |
  636. ((busNum & 0xff) << 16) | ((devNum & 0x1f) << 24);
  637. GT_REG_WRITE (pci_p2p_configuration[host], regData);
  638. return true;
  639. }
  640. /********************************************************************
  641. * pciSetRegionSnoopMode - This function modifys one of the 4 regions which
  642. * supports Cache Coherency in the PCI_n interface.
  643. * Inputs: region - One of the four regions.
  644. * snoopType - There is four optional Types:
  645. * 1. No Snoop.
  646. * 2. Snoop to WT region.
  647. * 3. Snoop to WB region.
  648. * 4. Snoop & Invalidate to WB region.
  649. * baseAddress - Base Address of this region.
  650. * regionLength - Region length.
  651. * Returns: false if one of the parameters is wrong otherwise return true.
  652. *********************************************************************/
  653. bool pciSetRegionSnoopMode (PCI_HOST host, PCI_SNOOP_REGION region,
  654. PCI_SNOOP_TYPE snoopType,
  655. unsigned int baseAddress,
  656. unsigned int regionLength)
  657. {
  658. unsigned int snoopXbaseAddress;
  659. unsigned int snoopXtopAddress;
  660. unsigned int data;
  661. unsigned int snoopHigh = baseAddress + regionLength;
  662. if ((region > PCI_SNOOP_REGION3) || (snoopType > PCI_SNOOP_WB))
  663. return false;
  664. snoopXbaseAddress =
  665. pci_snoop_control_base_0_low[host] + 0x10 * region;
  666. snoopXtopAddress = pci_snoop_control_top_0[host] + 0x10 * region;
  667. if (regionLength == 0) { /* closing the region */
  668. GT_REG_WRITE (snoopXbaseAddress, 0x0000ffff);
  669. GT_REG_WRITE (snoopXtopAddress, 0);
  670. return true;
  671. }
  672. baseAddress = baseAddress & 0xfff00000; /* Granularity of 1MByte */
  673. data = (baseAddress >> 20) | snoopType << 12;
  674. GT_REG_WRITE (snoopXbaseAddress, data);
  675. snoopHigh = (snoopHigh & 0xfff00000) >> 20;
  676. GT_REG_WRITE (snoopXtopAddress, snoopHigh - 1);
  677. return true;
  678. }
  679. static int gt_read_config_dword (struct pci_controller *hose,
  680. pci_dev_t dev, int offset, u32 * value)
  681. {
  682. int bus = PCI_BUS (dev);
  683. if ((bus == local_buses[0]) || (bus == local_buses[1])) {
  684. *value = pciReadConfigReg ((PCI_HOST) hose->cfg_addr, offset,
  685. PCI_DEV (dev));
  686. } else {
  687. *value = pciOverBridgeReadConfigReg ((PCI_HOST) hose->
  688. cfg_addr, offset,
  689. PCI_DEV (dev), bus);
  690. }
  691. return 0;
  692. }
  693. static int gt_write_config_dword (struct pci_controller *hose,
  694. pci_dev_t dev, int offset, u32 value)
  695. {
  696. int bus = PCI_BUS (dev);
  697. if ((bus == local_buses[0]) || (bus == local_buses[1])) {
  698. pciWriteConfigReg ((PCI_HOST) hose->cfg_addr, offset,
  699. PCI_DEV (dev), value);
  700. } else {
  701. pciOverBridgeWriteConfigReg ((PCI_HOST) hose->cfg_addr,
  702. offset, PCI_DEV (dev), bus,
  703. value);
  704. }
  705. return 0;
  706. }
  707. static void gt_setup_ide (struct pci_controller *hose,
  708. pci_dev_t dev, struct pci_config_table *entry)
  709. {
  710. static const int ide_bar[] = { 8, 4, 8, 4, 0, 0 };
  711. u32 bar_response, bar_value;
  712. int bar;
  713. for (bar = 0; bar < 6; bar++) {
  714. /*ronen different function for 3rd bank. */
  715. unsigned int offset =
  716. (bar < 2) ? bar * 8 : 0x100 + (bar - 2) * 8;
  717. pci_write_config_dword (dev, PCI_BASE_ADDRESS_0 + offset,
  718. 0x0);
  719. pci_read_config_dword (dev, PCI_BASE_ADDRESS_0 + offset,
  720. &bar_response);
  721. pciauto_region_allocate (bar_response &
  722. PCI_BASE_ADDRESS_SPACE_IO ? hose->
  723. pci_io : hose->pci_mem, ide_bar[bar],
  724. &bar_value);
  725. pci_write_config_dword (dev, PCI_BASE_ADDRESS_0 + bar * 4,
  726. bar_value);
  727. }
  728. }
  729. /* TODO BJW: Change this for DB64360. This was pulled from the EV64260 */
  730. /* and is curently not called *. */
  731. #if 0
  732. static void gt_fixup_irq (struct pci_controller *hose, pci_dev_t dev)
  733. {
  734. unsigned char pin, irq;
  735. pci_read_config_byte (dev, PCI_INTERRUPT_PIN, &pin);
  736. if (pin == 1) { /* only allow INT A */
  737. irq = pci_irq_swizzle[(PCI_HOST) hose->
  738. cfg_addr][PCI_DEV (dev)];
  739. if (irq)
  740. pci_write_config_byte (dev, PCI_INTERRUPT_LINE, irq);
  741. }
  742. }
  743. #endif
  744. struct pci_config_table gt_config_table[] = {
  745. {PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE,
  746. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, gt_setup_ide},
  747. {}
  748. };
  749. struct pci_controller pci0_hose = {
  750. /* fixup_irq: gt_fixup_irq, */
  751. config_table:gt_config_table,
  752. };
  753. struct pci_controller pci1_hose = {
  754. /* fixup_irq: gt_fixup_irq, */
  755. config_table:gt_config_table,
  756. };
  757. void pci_init_board (void)
  758. {
  759. unsigned int command;
  760. #ifdef DEBUG
  761. gt_pci_bus_mode_display (PCI_HOST0);
  762. #endif
  763. pci0_hose.first_busno = 0;
  764. pci0_hose.last_busno = 0xff;
  765. local_buses[0] = pci0_hose.first_busno;
  766. /* PCI memory space */
  767. pci_set_region (pci0_hose.regions + 0,
  768. CONFIG_SYS_PCI0_0_MEM_SPACE,
  769. CONFIG_SYS_PCI0_0_MEM_SPACE,
  770. CONFIG_SYS_PCI0_MEM_SIZE, PCI_REGION_MEM);
  771. /* PCI I/O space */
  772. pci_set_region (pci0_hose.regions + 1,
  773. CONFIG_SYS_PCI0_IO_SPACE_PCI,
  774. CONFIG_SYS_PCI0_IO_SPACE, CONFIG_SYS_PCI0_IO_SIZE, PCI_REGION_IO);
  775. pci_set_ops (&pci0_hose,
  776. pci_hose_read_config_byte_via_dword,
  777. pci_hose_read_config_word_via_dword,
  778. gt_read_config_dword,
  779. pci_hose_write_config_byte_via_dword,
  780. pci_hose_write_config_word_via_dword,
  781. gt_write_config_dword);
  782. pci0_hose.region_count = 2;
  783. pci0_hose.cfg_addr = (unsigned int *) PCI_HOST0;
  784. pci_register_hose (&pci0_hose);
  785. pciArbiterEnable (PCI_HOST0);
  786. pciParkingDisable (PCI_HOST0, 1, 1, 1, 1, 1, 1, 1);
  787. command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF);
  788. command |= PCI_COMMAND_MASTER;
  789. pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command);
  790. command = pciReadConfigReg (PCI_HOST0, PCI_COMMAND, SELF);
  791. command |= PCI_COMMAND_MEMORY;
  792. pciWriteConfigReg (PCI_HOST0, PCI_COMMAND, SELF, command);
  793. pci0_hose.last_busno = pci_hose_scan (&pci0_hose);
  794. #ifdef DEBUG
  795. gt_pci_bus_mode_display (PCI_HOST1);
  796. #endif
  797. pci1_hose.first_busno = pci0_hose.last_busno + 1;
  798. pci1_hose.last_busno = 0xff;
  799. pci1_hose.current_busno = pci1_hose.first_busno;
  800. local_buses[1] = pci1_hose.first_busno;
  801. /* PCI memory space */
  802. pci_set_region (pci1_hose.regions + 0,
  803. CONFIG_SYS_PCI1_0_MEM_SPACE,
  804. CONFIG_SYS_PCI1_0_MEM_SPACE,
  805. CONFIG_SYS_PCI1_MEM_SIZE, PCI_REGION_MEM);
  806. /* PCI I/O space */
  807. pci_set_region (pci1_hose.regions + 1,
  808. CONFIG_SYS_PCI1_IO_SPACE_PCI,
  809. CONFIG_SYS_PCI1_IO_SPACE, CONFIG_SYS_PCI1_IO_SIZE, PCI_REGION_IO);
  810. pci_set_ops (&pci1_hose,
  811. pci_hose_read_config_byte_via_dword,
  812. pci_hose_read_config_word_via_dword,
  813. gt_read_config_dword,
  814. pci_hose_write_config_byte_via_dword,
  815. pci_hose_write_config_word_via_dword,
  816. gt_write_config_dword);
  817. pci1_hose.region_count = 2;
  818. pci1_hose.cfg_addr = (unsigned int *) PCI_HOST1;
  819. pci_register_hose (&pci1_hose);
  820. pciArbiterEnable (PCI_HOST1);
  821. pciParkingDisable (PCI_HOST1, 1, 1, 1, 1, 1, 1, 1);
  822. command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF);
  823. command |= PCI_COMMAND_MASTER;
  824. pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);
  825. pci1_hose.last_busno = pci_hose_scan (&pci1_hose);
  826. command = pciReadConfigReg (PCI_HOST1, PCI_COMMAND, SELF);
  827. command |= PCI_COMMAND_MEMORY;
  828. pciWriteConfigReg (PCI_HOST1, PCI_COMMAND, SELF, command);
  829. }