pci.c 33 KB

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