pci.c 33 KB

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