pci.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  1. /*
  2. * PCI / PCI-X / PCI-Express support for 4xx parts
  3. *
  4. * Copyright 2007 Ben. Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
  5. *
  6. * Most PCI Express code is coming from Stefan Roese implementation for
  7. * arch/ppc in the Denx tree, slightly reworked by me.
  8. *
  9. * Copyright 2007 DENX Software Engineering, Stefan Roese <sr@denx.de>
  10. *
  11. * Some of that comes itself from a previous implementation for 440SPE only
  12. * by Roland Dreier:
  13. *
  14. * Copyright (c) 2005 Cisco Systems. All rights reserved.
  15. * Roland Dreier <rolandd@cisco.com>
  16. *
  17. */
  18. #undef DEBUG
  19. #include <linux/kernel.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/of.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <asm/io.h>
  26. #include <asm/pci-bridge.h>
  27. #include <asm/machdep.h>
  28. #include <asm/dcr.h>
  29. #include <asm/dcr-regs.h>
  30. #include <mm/mmu_decl.h>
  31. #include "pci.h"
  32. static int dma_offset_set;
  33. #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
  34. #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
  35. #define RES_TO_U32_LOW(val) \
  36. ((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_LOW(val) : (val))
  37. #define RES_TO_U32_HIGH(val) \
  38. ((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_HIGH(val) : (0))
  39. static inline int ppc440spe_revA(void)
  40. {
  41. /* Catch both 440SPe variants, with and without RAID6 support */
  42. if ((mfspr(SPRN_PVR) & 0xffefffff) == 0x53421890)
  43. return 1;
  44. else
  45. return 0;
  46. }
  47. static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev)
  48. {
  49. struct pci_controller *hose;
  50. int i;
  51. if (dev->devfn != 0 || dev->bus->self != NULL)
  52. return;
  53. hose = pci_bus_to_host(dev->bus);
  54. if (hose == NULL)
  55. return;
  56. if (!of_device_is_compatible(hose->dn, "ibm,plb-pciex") &&
  57. !of_device_is_compatible(hose->dn, "ibm,plb-pcix") &&
  58. !of_device_is_compatible(hose->dn, "ibm,plb-pci"))
  59. return;
  60. if (of_device_is_compatible(hose->dn, "ibm,plb440epx-pci") ||
  61. of_device_is_compatible(hose->dn, "ibm,plb440grx-pci")) {
  62. hose->indirect_type |= PPC_INDIRECT_TYPE_BROKEN_MRM;
  63. }
  64. /* Hide the PCI host BARs from the kernel as their content doesn't
  65. * fit well in the resource management
  66. */
  67. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  68. dev->resource[i].start = dev->resource[i].end = 0;
  69. dev->resource[i].flags = 0;
  70. }
  71. printk(KERN_INFO "PCI: Hiding 4xx host bridge resources %s\n",
  72. pci_name(dev));
  73. }
  74. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, fixup_ppc4xx_pci_bridge);
  75. static int __init ppc4xx_parse_dma_ranges(struct pci_controller *hose,
  76. void __iomem *reg,
  77. struct resource *res)
  78. {
  79. u64 size;
  80. const u32 *ranges;
  81. int rlen;
  82. int pna = of_n_addr_cells(hose->dn);
  83. int np = pna + 5;
  84. /* Default */
  85. res->start = 0;
  86. size = 0x80000000;
  87. res->end = size - 1;
  88. res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  89. /* Get dma-ranges property */
  90. ranges = of_get_property(hose->dn, "dma-ranges", &rlen);
  91. if (ranges == NULL)
  92. goto out;
  93. /* Walk it */
  94. while ((rlen -= np * 4) >= 0) {
  95. u32 pci_space = ranges[0];
  96. u64 pci_addr = of_read_number(ranges + 1, 2);
  97. u64 cpu_addr = of_translate_dma_address(hose->dn, ranges + 3);
  98. size = of_read_number(ranges + pna + 3, 2);
  99. ranges += np;
  100. if (cpu_addr == OF_BAD_ADDR || size == 0)
  101. continue;
  102. /* We only care about memory */
  103. if ((pci_space & 0x03000000) != 0x02000000)
  104. continue;
  105. /* We currently only support memory at 0, and pci_addr
  106. * within 32 bits space
  107. */
  108. if (cpu_addr != 0 || pci_addr > 0xffffffff) {
  109. printk(KERN_WARNING "%pOF: Ignored unsupported dma range"
  110. " 0x%016llx...0x%016llx -> 0x%016llx\n",
  111. hose->dn,
  112. pci_addr, pci_addr + size - 1, cpu_addr);
  113. continue;
  114. }
  115. /* Check if not prefetchable */
  116. if (!(pci_space & 0x40000000))
  117. res->flags &= ~IORESOURCE_PREFETCH;
  118. /* Use that */
  119. res->start = pci_addr;
  120. /* Beware of 32 bits resources */
  121. if (sizeof(resource_size_t) == sizeof(u32) &&
  122. (pci_addr + size) > 0x100000000ull)
  123. res->end = 0xffffffff;
  124. else
  125. res->end = res->start + size - 1;
  126. break;
  127. }
  128. /* We only support one global DMA offset */
  129. if (dma_offset_set && pci_dram_offset != res->start) {
  130. printk(KERN_ERR "%pOF: dma-ranges(s) mismatch\n", hose->dn);
  131. return -ENXIO;
  132. }
  133. /* Check that we can fit all of memory as we don't support
  134. * DMA bounce buffers
  135. */
  136. if (size < total_memory) {
  137. printk(KERN_ERR "%pOF: dma-ranges too small "
  138. "(size=%llx total_memory=%llx)\n",
  139. hose->dn, size, (u64)total_memory);
  140. return -ENXIO;
  141. }
  142. /* Check we are a power of 2 size and that base is a multiple of size*/
  143. if ((size & (size - 1)) != 0 ||
  144. (res->start & (size - 1)) != 0) {
  145. printk(KERN_ERR "%pOF: dma-ranges unaligned\n", hose->dn);
  146. return -ENXIO;
  147. }
  148. /* Check that we are fully contained within 32 bits space if we are not
  149. * running on a 460sx or 476fpe which have 64 bit bus addresses.
  150. */
  151. if (res->end > 0xffffffff &&
  152. !(of_device_is_compatible(hose->dn, "ibm,plb-pciex-460sx")
  153. || of_device_is_compatible(hose->dn, "ibm,plb-pciex-476fpe"))) {
  154. printk(KERN_ERR "%pOF: dma-ranges outside of 32 bits space\n",
  155. hose->dn);
  156. return -ENXIO;
  157. }
  158. out:
  159. dma_offset_set = 1;
  160. pci_dram_offset = res->start;
  161. hose->dma_window_base_cur = res->start;
  162. hose->dma_window_size = resource_size(res);
  163. printk(KERN_INFO "4xx PCI DMA offset set to 0x%08lx\n",
  164. pci_dram_offset);
  165. printk(KERN_INFO "4xx PCI DMA window base to 0x%016llx\n",
  166. (unsigned long long)hose->dma_window_base_cur);
  167. printk(KERN_INFO "DMA window size 0x%016llx\n",
  168. (unsigned long long)hose->dma_window_size);
  169. return 0;
  170. }
  171. /*
  172. * 4xx PCI 2.x part
  173. */
  174. static int __init ppc4xx_setup_one_pci_PMM(struct pci_controller *hose,
  175. void __iomem *reg,
  176. u64 plb_addr,
  177. u64 pci_addr,
  178. u64 size,
  179. unsigned int flags,
  180. int index)
  181. {
  182. u32 ma, pcila, pciha;
  183. /* Hack warning ! The "old" PCI 2.x cell only let us configure the low
  184. * 32-bit of incoming PLB addresses. The top 4 bits of the 36-bit
  185. * address are actually hard wired to a value that appears to depend
  186. * on the specific SoC. For example, it's 0 on 440EP and 1 on 440EPx.
  187. *
  188. * The trick here is we just crop those top bits and ignore them when
  189. * programming the chip. That means the device-tree has to be right
  190. * for the specific part used (we don't print a warning if it's wrong
  191. * but on the other hand, you'll crash quickly enough), but at least
  192. * this code should work whatever the hard coded value is
  193. */
  194. plb_addr &= 0xffffffffull;
  195. /* Note: Due to the above hack, the test below doesn't actually test
  196. * if you address is above 4G, but it tests that address and
  197. * (address + size) are both contained in the same 4G
  198. */
  199. if ((plb_addr + size) > 0xffffffffull || !is_power_of_2(size) ||
  200. size < 0x1000 || (plb_addr & (size - 1)) != 0) {
  201. printk(KERN_WARNING "%pOF: Resource out of range\n", hose->dn);
  202. return -1;
  203. }
  204. ma = (0xffffffffu << ilog2(size)) | 1;
  205. if (flags & IORESOURCE_PREFETCH)
  206. ma |= 2;
  207. pciha = RES_TO_U32_HIGH(pci_addr);
  208. pcila = RES_TO_U32_LOW(pci_addr);
  209. writel(plb_addr, reg + PCIL0_PMM0LA + (0x10 * index));
  210. writel(pcila, reg + PCIL0_PMM0PCILA + (0x10 * index));
  211. writel(pciha, reg + PCIL0_PMM0PCIHA + (0x10 * index));
  212. writel(ma, reg + PCIL0_PMM0MA + (0x10 * index));
  213. return 0;
  214. }
  215. static void __init ppc4xx_configure_pci_PMMs(struct pci_controller *hose,
  216. void __iomem *reg)
  217. {
  218. int i, j, found_isa_hole = 0;
  219. /* Setup outbound memory windows */
  220. for (i = j = 0; i < 3; i++) {
  221. struct resource *res = &hose->mem_resources[i];
  222. resource_size_t offset = hose->mem_offset[i];
  223. /* we only care about memory windows */
  224. if (!(res->flags & IORESOURCE_MEM))
  225. continue;
  226. if (j > 2) {
  227. printk(KERN_WARNING "%pOF: Too many ranges\n", hose->dn);
  228. break;
  229. }
  230. /* Configure the resource */
  231. if (ppc4xx_setup_one_pci_PMM(hose, reg,
  232. res->start,
  233. res->start - offset,
  234. resource_size(res),
  235. res->flags,
  236. j) == 0) {
  237. j++;
  238. /* If the resource PCI address is 0 then we have our
  239. * ISA memory hole
  240. */
  241. if (res->start == offset)
  242. found_isa_hole = 1;
  243. }
  244. }
  245. /* Handle ISA memory hole if not already covered */
  246. if (j <= 2 && !found_isa_hole && hose->isa_mem_size)
  247. if (ppc4xx_setup_one_pci_PMM(hose, reg, hose->isa_mem_phys, 0,
  248. hose->isa_mem_size, 0, j) == 0)
  249. printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
  250. hose->dn);
  251. }
  252. static void __init ppc4xx_configure_pci_PTMs(struct pci_controller *hose,
  253. void __iomem *reg,
  254. const struct resource *res)
  255. {
  256. resource_size_t size = resource_size(res);
  257. u32 sa;
  258. /* Calculate window size */
  259. sa = (0xffffffffu << ilog2(size)) | 1;
  260. sa |= 0x1;
  261. /* RAM is always at 0 local for now */
  262. writel(0, reg + PCIL0_PTM1LA);
  263. writel(sa, reg + PCIL0_PTM1MS);
  264. /* Map on PCI side */
  265. early_write_config_dword(hose, hose->first_busno, 0,
  266. PCI_BASE_ADDRESS_1, res->start);
  267. early_write_config_dword(hose, hose->first_busno, 0,
  268. PCI_BASE_ADDRESS_2, 0x00000000);
  269. early_write_config_word(hose, hose->first_busno, 0,
  270. PCI_COMMAND, 0x0006);
  271. }
  272. static void __init ppc4xx_probe_pci_bridge(struct device_node *np)
  273. {
  274. /* NYI */
  275. struct resource rsrc_cfg;
  276. struct resource rsrc_reg;
  277. struct resource dma_window;
  278. struct pci_controller *hose = NULL;
  279. void __iomem *reg = NULL;
  280. const int *bus_range;
  281. int primary = 0;
  282. /* Check if device is enabled */
  283. if (!of_device_is_available(np)) {
  284. printk(KERN_INFO "%pOF: Port disabled via device-tree\n", np);
  285. return;
  286. }
  287. /* Fetch config space registers address */
  288. if (of_address_to_resource(np, 0, &rsrc_cfg)) {
  289. printk(KERN_ERR "%pOF: Can't get PCI config register base !",
  290. np);
  291. return;
  292. }
  293. /* Fetch host bridge internal registers address */
  294. if (of_address_to_resource(np, 3, &rsrc_reg)) {
  295. printk(KERN_ERR "%pOF: Can't get PCI internal register base !",
  296. np);
  297. return;
  298. }
  299. /* Check if primary bridge */
  300. if (of_get_property(np, "primary", NULL))
  301. primary = 1;
  302. /* Get bus range if any */
  303. bus_range = of_get_property(np, "bus-range", NULL);
  304. /* Map registers */
  305. reg = ioremap(rsrc_reg.start, resource_size(&rsrc_reg));
  306. if (reg == NULL) {
  307. printk(KERN_ERR "%pOF: Can't map registers !", np);
  308. goto fail;
  309. }
  310. /* Allocate the host controller data structure */
  311. hose = pcibios_alloc_controller(np);
  312. if (!hose)
  313. goto fail;
  314. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  315. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  316. /* Setup config space */
  317. setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
  318. /* Disable all windows */
  319. writel(0, reg + PCIL0_PMM0MA);
  320. writel(0, reg + PCIL0_PMM1MA);
  321. writel(0, reg + PCIL0_PMM2MA);
  322. writel(0, reg + PCIL0_PTM1MS);
  323. writel(0, reg + PCIL0_PTM2MS);
  324. /* Parse outbound mapping resources */
  325. pci_process_bridge_OF_ranges(hose, np, primary);
  326. /* Parse inbound mapping resources */
  327. if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
  328. goto fail;
  329. /* Configure outbound ranges POMs */
  330. ppc4xx_configure_pci_PMMs(hose, reg);
  331. /* Configure inbound ranges PIMs */
  332. ppc4xx_configure_pci_PTMs(hose, reg, &dma_window);
  333. /* We don't need the registers anymore */
  334. iounmap(reg);
  335. return;
  336. fail:
  337. if (hose)
  338. pcibios_free_controller(hose);
  339. if (reg)
  340. iounmap(reg);
  341. }
  342. /*
  343. * 4xx PCI-X part
  344. */
  345. static int __init ppc4xx_setup_one_pcix_POM(struct pci_controller *hose,
  346. void __iomem *reg,
  347. u64 plb_addr,
  348. u64 pci_addr,
  349. u64 size,
  350. unsigned int flags,
  351. int index)
  352. {
  353. u32 lah, lal, pciah, pcial, sa;
  354. if (!is_power_of_2(size) || size < 0x1000 ||
  355. (plb_addr & (size - 1)) != 0) {
  356. printk(KERN_WARNING "%pOF: Resource out of range\n",
  357. hose->dn);
  358. return -1;
  359. }
  360. /* Calculate register values */
  361. lah = RES_TO_U32_HIGH(plb_addr);
  362. lal = RES_TO_U32_LOW(plb_addr);
  363. pciah = RES_TO_U32_HIGH(pci_addr);
  364. pcial = RES_TO_U32_LOW(pci_addr);
  365. sa = (0xffffffffu << ilog2(size)) | 0x1;
  366. /* Program register values */
  367. if (index == 0) {
  368. writel(lah, reg + PCIX0_POM0LAH);
  369. writel(lal, reg + PCIX0_POM0LAL);
  370. writel(pciah, reg + PCIX0_POM0PCIAH);
  371. writel(pcial, reg + PCIX0_POM0PCIAL);
  372. writel(sa, reg + PCIX0_POM0SA);
  373. } else {
  374. writel(lah, reg + PCIX0_POM1LAH);
  375. writel(lal, reg + PCIX0_POM1LAL);
  376. writel(pciah, reg + PCIX0_POM1PCIAH);
  377. writel(pcial, reg + PCIX0_POM1PCIAL);
  378. writel(sa, reg + PCIX0_POM1SA);
  379. }
  380. return 0;
  381. }
  382. static void __init ppc4xx_configure_pcix_POMs(struct pci_controller *hose,
  383. void __iomem *reg)
  384. {
  385. int i, j, found_isa_hole = 0;
  386. /* Setup outbound memory windows */
  387. for (i = j = 0; i < 3; i++) {
  388. struct resource *res = &hose->mem_resources[i];
  389. resource_size_t offset = hose->mem_offset[i];
  390. /* we only care about memory windows */
  391. if (!(res->flags & IORESOURCE_MEM))
  392. continue;
  393. if (j > 1) {
  394. printk(KERN_WARNING "%pOF: Too many ranges\n", hose->dn);
  395. break;
  396. }
  397. /* Configure the resource */
  398. if (ppc4xx_setup_one_pcix_POM(hose, reg,
  399. res->start,
  400. res->start - offset,
  401. resource_size(res),
  402. res->flags,
  403. j) == 0) {
  404. j++;
  405. /* If the resource PCI address is 0 then we have our
  406. * ISA memory hole
  407. */
  408. if (res->start == offset)
  409. found_isa_hole = 1;
  410. }
  411. }
  412. /* Handle ISA memory hole if not already covered */
  413. if (j <= 1 && !found_isa_hole && hose->isa_mem_size)
  414. if (ppc4xx_setup_one_pcix_POM(hose, reg, hose->isa_mem_phys, 0,
  415. hose->isa_mem_size, 0, j) == 0)
  416. printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
  417. hose->dn);
  418. }
  419. static void __init ppc4xx_configure_pcix_PIMs(struct pci_controller *hose,
  420. void __iomem *reg,
  421. const struct resource *res,
  422. int big_pim,
  423. int enable_msi_hole)
  424. {
  425. resource_size_t size = resource_size(res);
  426. u32 sa;
  427. /* RAM is always at 0 */
  428. writel(0x00000000, reg + PCIX0_PIM0LAH);
  429. writel(0x00000000, reg + PCIX0_PIM0LAL);
  430. /* Calculate window size */
  431. sa = (0xffffffffu << ilog2(size)) | 1;
  432. sa |= 0x1;
  433. if (res->flags & IORESOURCE_PREFETCH)
  434. sa |= 0x2;
  435. if (enable_msi_hole)
  436. sa |= 0x4;
  437. writel(sa, reg + PCIX0_PIM0SA);
  438. if (big_pim)
  439. writel(0xffffffff, reg + PCIX0_PIM0SAH);
  440. /* Map on PCI side */
  441. writel(0x00000000, reg + PCIX0_BAR0H);
  442. writel(res->start, reg + PCIX0_BAR0L);
  443. writew(0x0006, reg + PCIX0_COMMAND);
  444. }
  445. static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
  446. {
  447. struct resource rsrc_cfg;
  448. struct resource rsrc_reg;
  449. struct resource dma_window;
  450. struct pci_controller *hose = NULL;
  451. void __iomem *reg = NULL;
  452. const int *bus_range;
  453. int big_pim = 0, msi = 0, primary = 0;
  454. /* Fetch config space registers address */
  455. if (of_address_to_resource(np, 0, &rsrc_cfg)) {
  456. printk(KERN_ERR "%pOF: Can't get PCI-X config register base !",
  457. np);
  458. return;
  459. }
  460. /* Fetch host bridge internal registers address */
  461. if (of_address_to_resource(np, 3, &rsrc_reg)) {
  462. printk(KERN_ERR "%pOF: Can't get PCI-X internal register base !",
  463. np);
  464. return;
  465. }
  466. /* Check if it supports large PIMs (440GX) */
  467. if (of_get_property(np, "large-inbound-windows", NULL))
  468. big_pim = 1;
  469. /* Check if we should enable MSIs inbound hole */
  470. if (of_get_property(np, "enable-msi-hole", NULL))
  471. msi = 1;
  472. /* Check if primary bridge */
  473. if (of_get_property(np, "primary", NULL))
  474. primary = 1;
  475. /* Get bus range if any */
  476. bus_range = of_get_property(np, "bus-range", NULL);
  477. /* Map registers */
  478. reg = ioremap(rsrc_reg.start, resource_size(&rsrc_reg));
  479. if (reg == NULL) {
  480. printk(KERN_ERR "%pOF: Can't map registers !", np);
  481. goto fail;
  482. }
  483. /* Allocate the host controller data structure */
  484. hose = pcibios_alloc_controller(np);
  485. if (!hose)
  486. goto fail;
  487. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  488. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  489. /* Setup config space */
  490. setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4,
  491. PPC_INDIRECT_TYPE_SET_CFG_TYPE);
  492. /* Disable all windows */
  493. writel(0, reg + PCIX0_POM0SA);
  494. writel(0, reg + PCIX0_POM1SA);
  495. writel(0, reg + PCIX0_POM2SA);
  496. writel(0, reg + PCIX0_PIM0SA);
  497. writel(0, reg + PCIX0_PIM1SA);
  498. writel(0, reg + PCIX0_PIM2SA);
  499. if (big_pim) {
  500. writel(0, reg + PCIX0_PIM0SAH);
  501. writel(0, reg + PCIX0_PIM2SAH);
  502. }
  503. /* Parse outbound mapping resources */
  504. pci_process_bridge_OF_ranges(hose, np, primary);
  505. /* Parse inbound mapping resources */
  506. if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
  507. goto fail;
  508. /* Configure outbound ranges POMs */
  509. ppc4xx_configure_pcix_POMs(hose, reg);
  510. /* Configure inbound ranges PIMs */
  511. ppc4xx_configure_pcix_PIMs(hose, reg, &dma_window, big_pim, msi);
  512. /* We don't need the registers anymore */
  513. iounmap(reg);
  514. return;
  515. fail:
  516. if (hose)
  517. pcibios_free_controller(hose);
  518. if (reg)
  519. iounmap(reg);
  520. }
  521. #ifdef CONFIG_PPC4xx_PCI_EXPRESS
  522. /*
  523. * 4xx PCI-Express part
  524. *
  525. * We support 3 parts currently based on the compatible property:
  526. *
  527. * ibm,plb-pciex-440spe
  528. * ibm,plb-pciex-405ex
  529. * ibm,plb-pciex-460ex
  530. *
  531. * Anything else will be rejected for now as they are all subtly
  532. * different unfortunately.
  533. *
  534. */
  535. #define MAX_PCIE_BUS_MAPPED 0x40
  536. struct ppc4xx_pciex_port
  537. {
  538. struct pci_controller *hose;
  539. struct device_node *node;
  540. unsigned int index;
  541. int endpoint;
  542. int link;
  543. int has_ibpre;
  544. unsigned int sdr_base;
  545. dcr_host_t dcrs;
  546. struct resource cfg_space;
  547. struct resource utl_regs;
  548. void __iomem *utl_base;
  549. };
  550. static struct ppc4xx_pciex_port *ppc4xx_pciex_ports;
  551. static unsigned int ppc4xx_pciex_port_count;
  552. struct ppc4xx_pciex_hwops
  553. {
  554. bool want_sdr;
  555. int (*core_init)(struct device_node *np);
  556. int (*port_init_hw)(struct ppc4xx_pciex_port *port);
  557. int (*setup_utl)(struct ppc4xx_pciex_port *port);
  558. void (*check_link)(struct ppc4xx_pciex_port *port);
  559. };
  560. static struct ppc4xx_pciex_hwops *ppc4xx_pciex_hwops;
  561. static int __init ppc4xx_pciex_wait_on_sdr(struct ppc4xx_pciex_port *port,
  562. unsigned int sdr_offset,
  563. unsigned int mask,
  564. unsigned int value,
  565. int timeout_ms)
  566. {
  567. u32 val;
  568. while(timeout_ms--) {
  569. val = mfdcri(SDR0, port->sdr_base + sdr_offset);
  570. if ((val & mask) == value) {
  571. pr_debug("PCIE%d: Wait on SDR %x success with tm %d (%08x)\n",
  572. port->index, sdr_offset, timeout_ms, val);
  573. return 0;
  574. }
  575. msleep(1);
  576. }
  577. return -1;
  578. }
  579. static int __init ppc4xx_pciex_port_reset_sdr(struct ppc4xx_pciex_port *port)
  580. {
  581. /* Wait for reset to complete */
  582. if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS, 1 << 20, 0, 10)) {
  583. printk(KERN_WARNING "PCIE%d: PGRST failed\n",
  584. port->index);
  585. return -1;
  586. }
  587. return 0;
  588. }
  589. static void __init ppc4xx_pciex_check_link_sdr(struct ppc4xx_pciex_port *port)
  590. {
  591. printk(KERN_INFO "PCIE%d: Checking link...\n", port->index);
  592. /* Check for card presence detect if supported, if not, just wait for
  593. * link unconditionally.
  594. *
  595. * note that we don't fail if there is no link, we just filter out
  596. * config space accesses. That way, it will be easier to implement
  597. * hotplug later on.
  598. */
  599. if (!port->has_ibpre ||
  600. !ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
  601. 1 << 28, 1 << 28, 100)) {
  602. printk(KERN_INFO
  603. "PCIE%d: Device detected, waiting for link...\n",
  604. port->index);
  605. if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
  606. 0x1000, 0x1000, 2000))
  607. printk(KERN_WARNING
  608. "PCIE%d: Link up failed\n", port->index);
  609. else {
  610. printk(KERN_INFO
  611. "PCIE%d: link is up !\n", port->index);
  612. port->link = 1;
  613. }
  614. } else
  615. printk(KERN_INFO "PCIE%d: No device detected.\n", port->index);
  616. }
  617. #ifdef CONFIG_44x
  618. /* Check various reset bits of the 440SPe PCIe core */
  619. static int __init ppc440spe_pciex_check_reset(struct device_node *np)
  620. {
  621. u32 valPE0, valPE1, valPE2;
  622. int err = 0;
  623. /* SDR0_PEGPLLLCT1 reset */
  624. if (!(mfdcri(SDR0, PESDR0_PLLLCT1) & 0x01000000)) {
  625. /*
  626. * the PCIe core was probably already initialised
  627. * by firmware - let's re-reset RCSSET regs
  628. *
  629. * -- Shouldn't we also re-reset the whole thing ? -- BenH
  630. */
  631. pr_debug("PCIE: SDR0_PLLLCT1 already reset.\n");
  632. mtdcri(SDR0, PESDR0_440SPE_RCSSET, 0x01010000);
  633. mtdcri(SDR0, PESDR1_440SPE_RCSSET, 0x01010000);
  634. mtdcri(SDR0, PESDR2_440SPE_RCSSET, 0x01010000);
  635. }
  636. valPE0 = mfdcri(SDR0, PESDR0_440SPE_RCSSET);
  637. valPE1 = mfdcri(SDR0, PESDR1_440SPE_RCSSET);
  638. valPE2 = mfdcri(SDR0, PESDR2_440SPE_RCSSET);
  639. /* SDR0_PExRCSSET rstgu */
  640. if (!(valPE0 & 0x01000000) ||
  641. !(valPE1 & 0x01000000) ||
  642. !(valPE2 & 0x01000000)) {
  643. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstgu error\n");
  644. err = -1;
  645. }
  646. /* SDR0_PExRCSSET rstdl */
  647. if (!(valPE0 & 0x00010000) ||
  648. !(valPE1 & 0x00010000) ||
  649. !(valPE2 & 0x00010000)) {
  650. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstdl error\n");
  651. err = -1;
  652. }
  653. /* SDR0_PExRCSSET rstpyn */
  654. if ((valPE0 & 0x00001000) ||
  655. (valPE1 & 0x00001000) ||
  656. (valPE2 & 0x00001000)) {
  657. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstpyn error\n");
  658. err = -1;
  659. }
  660. /* SDR0_PExRCSSET hldplb */
  661. if ((valPE0 & 0x10000000) ||
  662. (valPE1 & 0x10000000) ||
  663. (valPE2 & 0x10000000)) {
  664. printk(KERN_INFO "PCIE: SDR0_PExRCSSET hldplb error\n");
  665. err = -1;
  666. }
  667. /* SDR0_PExRCSSET rdy */
  668. if ((valPE0 & 0x00100000) ||
  669. (valPE1 & 0x00100000) ||
  670. (valPE2 & 0x00100000)) {
  671. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rdy error\n");
  672. err = -1;
  673. }
  674. /* SDR0_PExRCSSET shutdown */
  675. if ((valPE0 & 0x00000100) ||
  676. (valPE1 & 0x00000100) ||
  677. (valPE2 & 0x00000100)) {
  678. printk(KERN_INFO "PCIE: SDR0_PExRCSSET shutdown error\n");
  679. err = -1;
  680. }
  681. return err;
  682. }
  683. /* Global PCIe core initializations for 440SPe core */
  684. static int __init ppc440spe_pciex_core_init(struct device_node *np)
  685. {
  686. int time_out = 20;
  687. /* Set PLL clock receiver to LVPECL */
  688. dcri_clrset(SDR0, PESDR0_PLLLCT1, 0, 1 << 28);
  689. /* Shouldn't we do all the calibration stuff etc... here ? */
  690. if (ppc440spe_pciex_check_reset(np))
  691. return -ENXIO;
  692. if (!(mfdcri(SDR0, PESDR0_PLLLCT2) & 0x10000)) {
  693. printk(KERN_INFO "PCIE: PESDR_PLLCT2 resistance calibration "
  694. "failed (0x%08x)\n",
  695. mfdcri(SDR0, PESDR0_PLLLCT2));
  696. return -1;
  697. }
  698. /* De-assert reset of PCIe PLL, wait for lock */
  699. dcri_clrset(SDR0, PESDR0_PLLLCT1, 1 << 24, 0);
  700. udelay(3);
  701. while (time_out) {
  702. if (!(mfdcri(SDR0, PESDR0_PLLLCT3) & 0x10000000)) {
  703. time_out--;
  704. udelay(1);
  705. } else
  706. break;
  707. }
  708. if (!time_out) {
  709. printk(KERN_INFO "PCIE: VCO output not locked\n");
  710. return -1;
  711. }
  712. pr_debug("PCIE initialization OK\n");
  713. return 3;
  714. }
  715. static int __init ppc440spe_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  716. {
  717. u32 val = 1 << 24;
  718. if (port->endpoint)
  719. val = PTYPE_LEGACY_ENDPOINT << 20;
  720. else
  721. val = PTYPE_ROOT_PORT << 20;
  722. if (port->index == 0)
  723. val |= LNKW_X8 << 12;
  724. else
  725. val |= LNKW_X4 << 12;
  726. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
  727. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x20222222);
  728. if (ppc440spe_revA())
  729. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x11000000);
  730. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL0SET1, 0x35000000);
  731. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL1SET1, 0x35000000);
  732. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL2SET1, 0x35000000);
  733. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL3SET1, 0x35000000);
  734. if (port->index == 0) {
  735. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL4SET1,
  736. 0x35000000);
  737. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL5SET1,
  738. 0x35000000);
  739. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL6SET1,
  740. 0x35000000);
  741. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL7SET1,
  742. 0x35000000);
  743. }
  744. dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
  745. (1 << 24) | (1 << 16), 1 << 12);
  746. return ppc4xx_pciex_port_reset_sdr(port);
  747. }
  748. static int __init ppc440speA_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  749. {
  750. return ppc440spe_pciex_init_port_hw(port);
  751. }
  752. static int __init ppc440speB_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  753. {
  754. int rc = ppc440spe_pciex_init_port_hw(port);
  755. port->has_ibpre = 1;
  756. return rc;
  757. }
  758. static int ppc440speA_pciex_init_utl(struct ppc4xx_pciex_port *port)
  759. {
  760. /* XXX Check what that value means... I hate magic */
  761. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x68782800);
  762. /*
  763. * Set buffer allocations and then assert VRB and TXE.
  764. */
  765. out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
  766. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  767. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x10000000);
  768. out_be32(port->utl_base + PEUTL_PBBSZ, 0x53000000);
  769. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x08000000);
  770. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x10000000);
  771. out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
  772. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  773. return 0;
  774. }
  775. static int ppc440speB_pciex_init_utl(struct ppc4xx_pciex_port *port)
  776. {
  777. /* Report CRS to the operating system */
  778. out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
  779. return 0;
  780. }
  781. static struct ppc4xx_pciex_hwops ppc440speA_pcie_hwops __initdata =
  782. {
  783. .want_sdr = true,
  784. .core_init = ppc440spe_pciex_core_init,
  785. .port_init_hw = ppc440speA_pciex_init_port_hw,
  786. .setup_utl = ppc440speA_pciex_init_utl,
  787. .check_link = ppc4xx_pciex_check_link_sdr,
  788. };
  789. static struct ppc4xx_pciex_hwops ppc440speB_pcie_hwops __initdata =
  790. {
  791. .want_sdr = true,
  792. .core_init = ppc440spe_pciex_core_init,
  793. .port_init_hw = ppc440speB_pciex_init_port_hw,
  794. .setup_utl = ppc440speB_pciex_init_utl,
  795. .check_link = ppc4xx_pciex_check_link_sdr,
  796. };
  797. static int __init ppc460ex_pciex_core_init(struct device_node *np)
  798. {
  799. /* Nothing to do, return 2 ports */
  800. return 2;
  801. }
  802. static int __init ppc460ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  803. {
  804. u32 val;
  805. u32 utlset1;
  806. if (port->endpoint)
  807. val = PTYPE_LEGACY_ENDPOINT << 20;
  808. else
  809. val = PTYPE_ROOT_PORT << 20;
  810. if (port->index == 0) {
  811. val |= LNKW_X1 << 12;
  812. utlset1 = 0x20000000;
  813. } else {
  814. val |= LNKW_X4 << 12;
  815. utlset1 = 0x20101101;
  816. }
  817. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
  818. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, utlset1);
  819. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01210000);
  820. switch (port->index) {
  821. case 0:
  822. mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
  823. mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000130);
  824. mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
  825. mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST,0x10000000);
  826. break;
  827. case 1:
  828. mtdcri(SDR0, PESDR1_460EX_L0CDRCTL, 0x00003230);
  829. mtdcri(SDR0, PESDR1_460EX_L1CDRCTL, 0x00003230);
  830. mtdcri(SDR0, PESDR1_460EX_L2CDRCTL, 0x00003230);
  831. mtdcri(SDR0, PESDR1_460EX_L3CDRCTL, 0x00003230);
  832. mtdcri(SDR0, PESDR1_460EX_L0DRV, 0x00000130);
  833. mtdcri(SDR0, PESDR1_460EX_L1DRV, 0x00000130);
  834. mtdcri(SDR0, PESDR1_460EX_L2DRV, 0x00000130);
  835. mtdcri(SDR0, PESDR1_460EX_L3DRV, 0x00000130);
  836. mtdcri(SDR0, PESDR1_460EX_L0CLK, 0x00000006);
  837. mtdcri(SDR0, PESDR1_460EX_L1CLK, 0x00000006);
  838. mtdcri(SDR0, PESDR1_460EX_L2CLK, 0x00000006);
  839. mtdcri(SDR0, PESDR1_460EX_L3CLK, 0x00000006);
  840. mtdcri(SDR0, PESDR1_460EX_PHY_CTL_RST,0x10000000);
  841. break;
  842. }
  843. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  844. mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
  845. (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
  846. /* Poll for PHY reset */
  847. /* XXX FIXME add timeout */
  848. switch (port->index) {
  849. case 0:
  850. while (!(mfdcri(SDR0, PESDR0_460EX_RSTSTA) & 0x1))
  851. udelay(10);
  852. break;
  853. case 1:
  854. while (!(mfdcri(SDR0, PESDR1_460EX_RSTSTA) & 0x1))
  855. udelay(10);
  856. break;
  857. }
  858. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  859. (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
  860. ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
  861. PESDRx_RCSSET_RSTPYN);
  862. port->has_ibpre = 1;
  863. return ppc4xx_pciex_port_reset_sdr(port);
  864. }
  865. static int ppc460ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
  866. {
  867. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
  868. /*
  869. * Set buffer allocations and then assert VRB and TXE.
  870. */
  871. out_be32(port->utl_base + PEUTL_PBCTL, 0x0800000c);
  872. out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
  873. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  874. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
  875. out_be32(port->utl_base + PEUTL_PBBSZ, 0x00000000);
  876. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
  877. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
  878. out_be32(port->utl_base + PEUTL_RCIRQEN,0x00f00000);
  879. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  880. return 0;
  881. }
  882. static struct ppc4xx_pciex_hwops ppc460ex_pcie_hwops __initdata =
  883. {
  884. .want_sdr = true,
  885. .core_init = ppc460ex_pciex_core_init,
  886. .port_init_hw = ppc460ex_pciex_init_port_hw,
  887. .setup_utl = ppc460ex_pciex_init_utl,
  888. .check_link = ppc4xx_pciex_check_link_sdr,
  889. };
  890. static int __init apm821xx_pciex_core_init(struct device_node *np)
  891. {
  892. /* Return the number of pcie port */
  893. return 1;
  894. }
  895. static int __init apm821xx_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  896. {
  897. u32 val;
  898. /*
  899. * Do a software reset on PCIe ports.
  900. * This code is to fix the issue that pci drivers doesn't re-assign
  901. * bus number for PCIE devices after Uboot
  902. * scanned and configured all the buses (eg. PCIE NIC IntelPro/1000
  903. * PT quad port, SAS LSI 1064E)
  904. */
  905. mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x0);
  906. mdelay(10);
  907. if (port->endpoint)
  908. val = PTYPE_LEGACY_ENDPOINT << 20;
  909. else
  910. val = PTYPE_ROOT_PORT << 20;
  911. val |= LNKW_X1 << 12;
  912. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
  913. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
  914. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
  915. mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
  916. mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000130);
  917. mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
  918. mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x10000000);
  919. mdelay(50);
  920. mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST, 0x30000000);
  921. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  922. mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
  923. (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
  924. /* Poll for PHY reset */
  925. val = PESDR0_460EX_RSTSTA - port->sdr_base;
  926. if (ppc4xx_pciex_wait_on_sdr(port, val, 0x1, 1, 100)) {
  927. printk(KERN_WARNING "%s: PCIE: Can't reset PHY\n", __func__);
  928. return -EBUSY;
  929. } else {
  930. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  931. (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
  932. ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
  933. PESDRx_RCSSET_RSTPYN);
  934. port->has_ibpre = 1;
  935. return 0;
  936. }
  937. }
  938. static struct ppc4xx_pciex_hwops apm821xx_pcie_hwops __initdata = {
  939. .want_sdr = true,
  940. .core_init = apm821xx_pciex_core_init,
  941. .port_init_hw = apm821xx_pciex_init_port_hw,
  942. .setup_utl = ppc460ex_pciex_init_utl,
  943. .check_link = ppc4xx_pciex_check_link_sdr,
  944. };
  945. static int __init ppc460sx_pciex_core_init(struct device_node *np)
  946. {
  947. /* HSS drive amplitude */
  948. mtdcri(SDR0, PESDR0_460SX_HSSL0DAMP, 0xB9843211);
  949. mtdcri(SDR0, PESDR0_460SX_HSSL1DAMP, 0xB9843211);
  950. mtdcri(SDR0, PESDR0_460SX_HSSL2DAMP, 0xB9843211);
  951. mtdcri(SDR0, PESDR0_460SX_HSSL3DAMP, 0xB9843211);
  952. mtdcri(SDR0, PESDR0_460SX_HSSL4DAMP, 0xB9843211);
  953. mtdcri(SDR0, PESDR0_460SX_HSSL5DAMP, 0xB9843211);
  954. mtdcri(SDR0, PESDR0_460SX_HSSL6DAMP, 0xB9843211);
  955. mtdcri(SDR0, PESDR0_460SX_HSSL7DAMP, 0xB9843211);
  956. mtdcri(SDR0, PESDR1_460SX_HSSL0DAMP, 0xB9843211);
  957. mtdcri(SDR0, PESDR1_460SX_HSSL1DAMP, 0xB9843211);
  958. mtdcri(SDR0, PESDR1_460SX_HSSL2DAMP, 0xB9843211);
  959. mtdcri(SDR0, PESDR1_460SX_HSSL3DAMP, 0xB9843211);
  960. mtdcri(SDR0, PESDR2_460SX_HSSL0DAMP, 0xB9843211);
  961. mtdcri(SDR0, PESDR2_460SX_HSSL1DAMP, 0xB9843211);
  962. mtdcri(SDR0, PESDR2_460SX_HSSL2DAMP, 0xB9843211);
  963. mtdcri(SDR0, PESDR2_460SX_HSSL3DAMP, 0xB9843211);
  964. /* HSS TX pre-emphasis */
  965. mtdcri(SDR0, PESDR0_460SX_HSSL0COEFA, 0xDCB98987);
  966. mtdcri(SDR0, PESDR0_460SX_HSSL1COEFA, 0xDCB98987);
  967. mtdcri(SDR0, PESDR0_460SX_HSSL2COEFA, 0xDCB98987);
  968. mtdcri(SDR0, PESDR0_460SX_HSSL3COEFA, 0xDCB98987);
  969. mtdcri(SDR0, PESDR0_460SX_HSSL4COEFA, 0xDCB98987);
  970. mtdcri(SDR0, PESDR0_460SX_HSSL5COEFA, 0xDCB98987);
  971. mtdcri(SDR0, PESDR0_460SX_HSSL6COEFA, 0xDCB98987);
  972. mtdcri(SDR0, PESDR0_460SX_HSSL7COEFA, 0xDCB98987);
  973. mtdcri(SDR0, PESDR1_460SX_HSSL0COEFA, 0xDCB98987);
  974. mtdcri(SDR0, PESDR1_460SX_HSSL1COEFA, 0xDCB98987);
  975. mtdcri(SDR0, PESDR1_460SX_HSSL2COEFA, 0xDCB98987);
  976. mtdcri(SDR0, PESDR1_460SX_HSSL3COEFA, 0xDCB98987);
  977. mtdcri(SDR0, PESDR2_460SX_HSSL0COEFA, 0xDCB98987);
  978. mtdcri(SDR0, PESDR2_460SX_HSSL1COEFA, 0xDCB98987);
  979. mtdcri(SDR0, PESDR2_460SX_HSSL2COEFA, 0xDCB98987);
  980. mtdcri(SDR0, PESDR2_460SX_HSSL3COEFA, 0xDCB98987);
  981. /* HSS TX calibration control */
  982. mtdcri(SDR0, PESDR0_460SX_HSSL1CALDRV, 0x22222222);
  983. mtdcri(SDR0, PESDR1_460SX_HSSL1CALDRV, 0x22220000);
  984. mtdcri(SDR0, PESDR2_460SX_HSSL1CALDRV, 0x22220000);
  985. /* HSS TX slew control */
  986. mtdcri(SDR0, PESDR0_460SX_HSSSLEW, 0xFFFFFFFF);
  987. mtdcri(SDR0, PESDR1_460SX_HSSSLEW, 0xFFFF0000);
  988. mtdcri(SDR0, PESDR2_460SX_HSSSLEW, 0xFFFF0000);
  989. /* Set HSS PRBS enabled */
  990. mtdcri(SDR0, PESDR0_460SX_HSSCTLSET, 0x00001130);
  991. mtdcri(SDR0, PESDR2_460SX_HSSCTLSET, 0x00001130);
  992. udelay(100);
  993. /* De-assert PLLRESET */
  994. dcri_clrset(SDR0, PESDR0_PLLLCT2, 0x00000100, 0);
  995. /* Reset DL, UTL, GPL before configuration */
  996. mtdcri(SDR0, PESDR0_460SX_RCSSET,
  997. PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
  998. mtdcri(SDR0, PESDR1_460SX_RCSSET,
  999. PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
  1000. mtdcri(SDR0, PESDR2_460SX_RCSSET,
  1001. PESDRx_RCSSET_RSTDL | PESDRx_RCSSET_RSTGU);
  1002. udelay(100);
  1003. /*
  1004. * If bifurcation is not enabled, u-boot would have disabled the
  1005. * third PCIe port
  1006. */
  1007. if (((mfdcri(SDR0, PESDR1_460SX_HSSCTLSET) & 0x00000001) ==
  1008. 0x00000001)) {
  1009. printk(KERN_INFO "PCI: PCIE bifurcation setup successfully.\n");
  1010. printk(KERN_INFO "PCI: Total 3 PCIE ports are present\n");
  1011. return 3;
  1012. }
  1013. printk(KERN_INFO "PCI: Total 2 PCIE ports are present\n");
  1014. return 2;
  1015. }
  1016. static int __init ppc460sx_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  1017. {
  1018. if (port->endpoint)
  1019. dcri_clrset(SDR0, port->sdr_base + PESDRn_UTLSET2,
  1020. 0x01000000, 0);
  1021. else
  1022. dcri_clrset(SDR0, port->sdr_base + PESDRn_UTLSET2,
  1023. 0, 0x01000000);
  1024. dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
  1025. (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL),
  1026. PESDRx_RCSSET_RSTPYN);
  1027. port->has_ibpre = 1;
  1028. return ppc4xx_pciex_port_reset_sdr(port);
  1029. }
  1030. static int ppc460sx_pciex_init_utl(struct ppc4xx_pciex_port *port)
  1031. {
  1032. /* Max 128 Bytes */
  1033. out_be32 (port->utl_base + PEUTL_PBBSZ, 0x00000000);
  1034. /* Assert VRB and TXE - per datasheet turn off addr validation */
  1035. out_be32(port->utl_base + PEUTL_PCTL, 0x80800000);
  1036. return 0;
  1037. }
  1038. static void __init ppc460sx_pciex_check_link(struct ppc4xx_pciex_port *port)
  1039. {
  1040. void __iomem *mbase;
  1041. int attempt = 50;
  1042. port->link = 0;
  1043. mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
  1044. if (mbase == NULL) {
  1045. printk(KERN_ERR "%pOF: Can't map internal config space !",
  1046. port->node);
  1047. return;
  1048. }
  1049. while (attempt && (0 == (in_le32(mbase + PECFG_460SX_DLLSTA)
  1050. & PECFG_460SX_DLLSTA_LINKUP))) {
  1051. attempt--;
  1052. mdelay(10);
  1053. }
  1054. if (attempt)
  1055. port->link = 1;
  1056. iounmap(mbase);
  1057. }
  1058. static struct ppc4xx_pciex_hwops ppc460sx_pcie_hwops __initdata = {
  1059. .want_sdr = true,
  1060. .core_init = ppc460sx_pciex_core_init,
  1061. .port_init_hw = ppc460sx_pciex_init_port_hw,
  1062. .setup_utl = ppc460sx_pciex_init_utl,
  1063. .check_link = ppc460sx_pciex_check_link,
  1064. };
  1065. #endif /* CONFIG_44x */
  1066. #ifdef CONFIG_40x
  1067. static int __init ppc405ex_pciex_core_init(struct device_node *np)
  1068. {
  1069. /* Nothing to do, return 2 ports */
  1070. return 2;
  1071. }
  1072. static void ppc405ex_pcie_phy_reset(struct ppc4xx_pciex_port *port)
  1073. {
  1074. /* Assert the PE0_PHY reset */
  1075. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01010000);
  1076. msleep(1);
  1077. /* deassert the PE0_hotreset */
  1078. if (port->endpoint)
  1079. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01111000);
  1080. else
  1081. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01101000);
  1082. /* poll for phy !reset */
  1083. /* XXX FIXME add timeout */
  1084. while (!(mfdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSTA) & 0x00001000))
  1085. ;
  1086. /* deassert the PE0_gpl_utl_reset */
  1087. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x00101000);
  1088. }
  1089. static int __init ppc405ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  1090. {
  1091. u32 val;
  1092. if (port->endpoint)
  1093. val = PTYPE_LEGACY_ENDPOINT;
  1094. else
  1095. val = PTYPE_ROOT_PORT;
  1096. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET,
  1097. 1 << 24 | val << 20 | LNKW_X1 << 12);
  1098. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
  1099. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
  1100. mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET1, 0x720F0000);
  1101. mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET2, 0x70600003);
  1102. /*
  1103. * Only reset the PHY when no link is currently established.
  1104. * This is for the Atheros PCIe board which has problems to establish
  1105. * the link (again) after this PHY reset. All other currently tested
  1106. * PCIe boards don't show this problem.
  1107. * This has to be re-tested and fixed in a later release!
  1108. */
  1109. val = mfdcri(SDR0, port->sdr_base + PESDRn_LOOP);
  1110. if (!(val & 0x00001000))
  1111. ppc405ex_pcie_phy_reset(port);
  1112. dcr_write(port->dcrs, DCRO_PEGPL_CFG, 0x10000000); /* guarded on */
  1113. port->has_ibpre = 1;
  1114. return ppc4xx_pciex_port_reset_sdr(port);
  1115. }
  1116. static int ppc405ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
  1117. {
  1118. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
  1119. /*
  1120. * Set buffer allocations and then assert VRB and TXE.
  1121. */
  1122. out_be32(port->utl_base + PEUTL_OUTTR, 0x02000000);
  1123. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  1124. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
  1125. out_be32(port->utl_base + PEUTL_PBBSZ, 0x21000000);
  1126. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
  1127. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
  1128. out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
  1129. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  1130. out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
  1131. return 0;
  1132. }
  1133. static struct ppc4xx_pciex_hwops ppc405ex_pcie_hwops __initdata =
  1134. {
  1135. .want_sdr = true,
  1136. .core_init = ppc405ex_pciex_core_init,
  1137. .port_init_hw = ppc405ex_pciex_init_port_hw,
  1138. .setup_utl = ppc405ex_pciex_init_utl,
  1139. .check_link = ppc4xx_pciex_check_link_sdr,
  1140. };
  1141. #endif /* CONFIG_40x */
  1142. #ifdef CONFIG_476FPE
  1143. static int __init ppc_476fpe_pciex_core_init(struct device_node *np)
  1144. {
  1145. return 4;
  1146. }
  1147. static void __init ppc_476fpe_pciex_check_link(struct ppc4xx_pciex_port *port)
  1148. {
  1149. u32 timeout_ms = 20;
  1150. u32 val = 0, mask = (PECFG_TLDLP_LNKUP|PECFG_TLDLP_PRESENT);
  1151. void __iomem *mbase = ioremap(port->cfg_space.start + 0x10000000,
  1152. 0x1000);
  1153. printk(KERN_INFO "PCIE%d: Checking link...\n", port->index);
  1154. if (mbase == NULL) {
  1155. printk(KERN_WARNING "PCIE%d: failed to get cfg space\n",
  1156. port->index);
  1157. return;
  1158. }
  1159. while (timeout_ms--) {
  1160. val = in_le32(mbase + PECFG_TLDLP);
  1161. if ((val & mask) == mask)
  1162. break;
  1163. msleep(10);
  1164. }
  1165. if (val & PECFG_TLDLP_PRESENT) {
  1166. printk(KERN_INFO "PCIE%d: link is up !\n", port->index);
  1167. port->link = 1;
  1168. } else
  1169. printk(KERN_WARNING "PCIE%d: Link up failed\n", port->index);
  1170. iounmap(mbase);
  1171. return;
  1172. }
  1173. static struct ppc4xx_pciex_hwops ppc_476fpe_pcie_hwops __initdata =
  1174. {
  1175. .core_init = ppc_476fpe_pciex_core_init,
  1176. .check_link = ppc_476fpe_pciex_check_link,
  1177. };
  1178. #endif /* CONFIG_476FPE */
  1179. /* Check that the core has been initied and if not, do it */
  1180. static int __init ppc4xx_pciex_check_core_init(struct device_node *np)
  1181. {
  1182. static int core_init;
  1183. int count = -ENODEV;
  1184. if (core_init++)
  1185. return 0;
  1186. #ifdef CONFIG_44x
  1187. if (of_device_is_compatible(np, "ibm,plb-pciex-440spe")) {
  1188. if (ppc440spe_revA())
  1189. ppc4xx_pciex_hwops = &ppc440speA_pcie_hwops;
  1190. else
  1191. ppc4xx_pciex_hwops = &ppc440speB_pcie_hwops;
  1192. }
  1193. if (of_device_is_compatible(np, "ibm,plb-pciex-460ex"))
  1194. ppc4xx_pciex_hwops = &ppc460ex_pcie_hwops;
  1195. if (of_device_is_compatible(np, "ibm,plb-pciex-460sx"))
  1196. ppc4xx_pciex_hwops = &ppc460sx_pcie_hwops;
  1197. if (of_device_is_compatible(np, "ibm,plb-pciex-apm821xx"))
  1198. ppc4xx_pciex_hwops = &apm821xx_pcie_hwops;
  1199. #endif /* CONFIG_44x */
  1200. #ifdef CONFIG_40x
  1201. if (of_device_is_compatible(np, "ibm,plb-pciex-405ex"))
  1202. ppc4xx_pciex_hwops = &ppc405ex_pcie_hwops;
  1203. #endif
  1204. #ifdef CONFIG_476FPE
  1205. if (of_device_is_compatible(np, "ibm,plb-pciex-476fpe")
  1206. || of_device_is_compatible(np, "ibm,plb-pciex-476gtr"))
  1207. ppc4xx_pciex_hwops = &ppc_476fpe_pcie_hwops;
  1208. #endif
  1209. if (ppc4xx_pciex_hwops == NULL) {
  1210. printk(KERN_WARNING "PCIE: unknown host type %pOF\n", np);
  1211. return -ENODEV;
  1212. }
  1213. count = ppc4xx_pciex_hwops->core_init(np);
  1214. if (count > 0) {
  1215. ppc4xx_pciex_ports =
  1216. kzalloc(count * sizeof(struct ppc4xx_pciex_port),
  1217. GFP_KERNEL);
  1218. if (ppc4xx_pciex_ports) {
  1219. ppc4xx_pciex_port_count = count;
  1220. return 0;
  1221. }
  1222. printk(KERN_WARNING "PCIE: failed to allocate ports array\n");
  1223. return -ENOMEM;
  1224. }
  1225. return -ENODEV;
  1226. }
  1227. static void __init ppc4xx_pciex_port_init_mapping(struct ppc4xx_pciex_port *port)
  1228. {
  1229. /* We map PCI Express configuration based on the reg property */
  1230. dcr_write(port->dcrs, DCRO_PEGPL_CFGBAH,
  1231. RES_TO_U32_HIGH(port->cfg_space.start));
  1232. dcr_write(port->dcrs, DCRO_PEGPL_CFGBAL,
  1233. RES_TO_U32_LOW(port->cfg_space.start));
  1234. /* XXX FIXME: Use size from reg property. For now, map 512M */
  1235. dcr_write(port->dcrs, DCRO_PEGPL_CFGMSK, 0xe0000001);
  1236. /* We map UTL registers based on the reg property */
  1237. dcr_write(port->dcrs, DCRO_PEGPL_REGBAH,
  1238. RES_TO_U32_HIGH(port->utl_regs.start));
  1239. dcr_write(port->dcrs, DCRO_PEGPL_REGBAL,
  1240. RES_TO_U32_LOW(port->utl_regs.start));
  1241. /* XXX FIXME: Use size from reg property */
  1242. dcr_write(port->dcrs, DCRO_PEGPL_REGMSK, 0x00007001);
  1243. /* Disable all other outbound windows */
  1244. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, 0);
  1245. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, 0);
  1246. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0);
  1247. dcr_write(port->dcrs, DCRO_PEGPL_MSGMSK, 0);
  1248. }
  1249. static int __init ppc4xx_pciex_port_init(struct ppc4xx_pciex_port *port)
  1250. {
  1251. int rc = 0;
  1252. /* Init HW */
  1253. if (ppc4xx_pciex_hwops->port_init_hw)
  1254. rc = ppc4xx_pciex_hwops->port_init_hw(port);
  1255. if (rc != 0)
  1256. return rc;
  1257. /*
  1258. * Initialize mapping: disable all regions and configure
  1259. * CFG and REG regions based on resources in the device tree
  1260. */
  1261. ppc4xx_pciex_port_init_mapping(port);
  1262. if (ppc4xx_pciex_hwops->check_link)
  1263. ppc4xx_pciex_hwops->check_link(port);
  1264. /*
  1265. * Map UTL
  1266. */
  1267. port->utl_base = ioremap(port->utl_regs.start, 0x100);
  1268. BUG_ON(port->utl_base == NULL);
  1269. /*
  1270. * Setup UTL registers --BenH.
  1271. */
  1272. if (ppc4xx_pciex_hwops->setup_utl)
  1273. ppc4xx_pciex_hwops->setup_utl(port);
  1274. /*
  1275. * Check for VC0 active or PLL Locked and assert RDY.
  1276. */
  1277. if (port->sdr_base) {
  1278. if (of_device_is_compatible(port->node,
  1279. "ibm,plb-pciex-460sx")){
  1280. if (port->link && ppc4xx_pciex_wait_on_sdr(port,
  1281. PESDRn_RCSSTS,
  1282. 1 << 12, 1 << 12, 5000)) {
  1283. printk(KERN_INFO "PCIE%d: PLL not locked\n",
  1284. port->index);
  1285. port->link = 0;
  1286. }
  1287. } else if (port->link &&
  1288. ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS,
  1289. 1 << 16, 1 << 16, 5000)) {
  1290. printk(KERN_INFO "PCIE%d: VC0 not active\n",
  1291. port->index);
  1292. port->link = 0;
  1293. }
  1294. dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET, 0, 1 << 20);
  1295. }
  1296. msleep(100);
  1297. return 0;
  1298. }
  1299. static int ppc4xx_pciex_validate_bdf(struct ppc4xx_pciex_port *port,
  1300. struct pci_bus *bus,
  1301. unsigned int devfn)
  1302. {
  1303. static int message;
  1304. /* Endpoint can not generate upstream(remote) config cycles */
  1305. if (port->endpoint && bus->number != port->hose->first_busno)
  1306. return PCIBIOS_DEVICE_NOT_FOUND;
  1307. /* Check we are within the mapped range */
  1308. if (bus->number > port->hose->last_busno) {
  1309. if (!message) {
  1310. printk(KERN_WARNING "Warning! Probing bus %u"
  1311. " out of range !\n", bus->number);
  1312. message++;
  1313. }
  1314. return PCIBIOS_DEVICE_NOT_FOUND;
  1315. }
  1316. /* The root complex has only one device / function */
  1317. if (bus->number == port->hose->first_busno && devfn != 0)
  1318. return PCIBIOS_DEVICE_NOT_FOUND;
  1319. /* The other side of the RC has only one device as well */
  1320. if (bus->number == (port->hose->first_busno + 1) &&
  1321. PCI_SLOT(devfn) != 0)
  1322. return PCIBIOS_DEVICE_NOT_FOUND;
  1323. /* Check if we have a link */
  1324. if ((bus->number != port->hose->first_busno) && !port->link)
  1325. return PCIBIOS_DEVICE_NOT_FOUND;
  1326. return 0;
  1327. }
  1328. static void __iomem *ppc4xx_pciex_get_config_base(struct ppc4xx_pciex_port *port,
  1329. struct pci_bus *bus,
  1330. unsigned int devfn)
  1331. {
  1332. int relbus;
  1333. /* Remove the casts when we finally remove the stupid volatile
  1334. * in struct pci_controller
  1335. */
  1336. if (bus->number == port->hose->first_busno)
  1337. return (void __iomem *)port->hose->cfg_addr;
  1338. relbus = bus->number - (port->hose->first_busno + 1);
  1339. return (void __iomem *)port->hose->cfg_data +
  1340. ((relbus << 20) | (devfn << 12));
  1341. }
  1342. static int ppc4xx_pciex_read_config(struct pci_bus *bus, unsigned int devfn,
  1343. int offset, int len, u32 *val)
  1344. {
  1345. struct pci_controller *hose = pci_bus_to_host(bus);
  1346. struct ppc4xx_pciex_port *port =
  1347. &ppc4xx_pciex_ports[hose->indirect_type];
  1348. void __iomem *addr;
  1349. u32 gpl_cfg;
  1350. BUG_ON(hose != port->hose);
  1351. if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
  1352. return PCIBIOS_DEVICE_NOT_FOUND;
  1353. addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
  1354. /*
  1355. * Reading from configuration space of non-existing device can
  1356. * generate transaction errors. For the read duration we suppress
  1357. * assertion of machine check exceptions to avoid those.
  1358. */
  1359. gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
  1360. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
  1361. /* Make sure no CRS is recorded */
  1362. out_be32(port->utl_base + PEUTL_RCSTA, 0x00040000);
  1363. switch (len) {
  1364. case 1:
  1365. *val = in_8((u8 *)(addr + offset));
  1366. break;
  1367. case 2:
  1368. *val = in_le16((u16 *)(addr + offset));
  1369. break;
  1370. default:
  1371. *val = in_le32((u32 *)(addr + offset));
  1372. break;
  1373. }
  1374. pr_debug("pcie-config-read: bus=%3d [%3d..%3d] devfn=0x%04x"
  1375. " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
  1376. bus->number, hose->first_busno, hose->last_busno,
  1377. devfn, offset, len, addr + offset, *val);
  1378. /* Check for CRS (440SPe rev B does that for us but heh ..) */
  1379. if (in_be32(port->utl_base + PEUTL_RCSTA) & 0x00040000) {
  1380. pr_debug("Got CRS !\n");
  1381. if (len != 4 || offset != 0)
  1382. return PCIBIOS_DEVICE_NOT_FOUND;
  1383. *val = 0xffff0001;
  1384. }
  1385. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
  1386. return PCIBIOS_SUCCESSFUL;
  1387. }
  1388. static int ppc4xx_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
  1389. int offset, int len, u32 val)
  1390. {
  1391. struct pci_controller *hose = pci_bus_to_host(bus);
  1392. struct ppc4xx_pciex_port *port =
  1393. &ppc4xx_pciex_ports[hose->indirect_type];
  1394. void __iomem *addr;
  1395. u32 gpl_cfg;
  1396. if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
  1397. return PCIBIOS_DEVICE_NOT_FOUND;
  1398. addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
  1399. /*
  1400. * Reading from configuration space of non-existing device can
  1401. * generate transaction errors. For the read duration we suppress
  1402. * assertion of machine check exceptions to avoid those.
  1403. */
  1404. gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
  1405. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
  1406. pr_debug("pcie-config-write: bus=%3d [%3d..%3d] devfn=0x%04x"
  1407. " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
  1408. bus->number, hose->first_busno, hose->last_busno,
  1409. devfn, offset, len, addr + offset, val);
  1410. switch (len) {
  1411. case 1:
  1412. out_8((u8 *)(addr + offset), val);
  1413. break;
  1414. case 2:
  1415. out_le16((u16 *)(addr + offset), val);
  1416. break;
  1417. default:
  1418. out_le32((u32 *)(addr + offset), val);
  1419. break;
  1420. }
  1421. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
  1422. return PCIBIOS_SUCCESSFUL;
  1423. }
  1424. static struct pci_ops ppc4xx_pciex_pci_ops =
  1425. {
  1426. .read = ppc4xx_pciex_read_config,
  1427. .write = ppc4xx_pciex_write_config,
  1428. };
  1429. static int __init ppc4xx_setup_one_pciex_POM(struct ppc4xx_pciex_port *port,
  1430. struct pci_controller *hose,
  1431. void __iomem *mbase,
  1432. u64 plb_addr,
  1433. u64 pci_addr,
  1434. u64 size,
  1435. unsigned int flags,
  1436. int index)
  1437. {
  1438. u32 lah, lal, pciah, pcial, sa;
  1439. if (!is_power_of_2(size) ||
  1440. (index < 2 && size < 0x100000) ||
  1441. (index == 2 && size < 0x100) ||
  1442. (plb_addr & (size - 1)) != 0) {
  1443. printk(KERN_WARNING "%pOF: Resource out of range\n", hose->dn);
  1444. return -1;
  1445. }
  1446. /* Calculate register values */
  1447. lah = RES_TO_U32_HIGH(plb_addr);
  1448. lal = RES_TO_U32_LOW(plb_addr);
  1449. pciah = RES_TO_U32_HIGH(pci_addr);
  1450. pcial = RES_TO_U32_LOW(pci_addr);
  1451. sa = (0xffffffffu << ilog2(size)) | 0x1;
  1452. /* Program register values */
  1453. switch (index) {
  1454. case 0:
  1455. out_le32(mbase + PECFG_POM0LAH, pciah);
  1456. out_le32(mbase + PECFG_POM0LAL, pcial);
  1457. dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAH, lah);
  1458. dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAL, lal);
  1459. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKH, 0x7fffffff);
  1460. /*Enabled and single region */
  1461. if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx"))
  1462. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
  1463. sa | DCRO_PEGPL_460SX_OMR1MSKL_UOT
  1464. | DCRO_PEGPL_OMRxMSKL_VAL);
  1465. else if (of_device_is_compatible(
  1466. port->node, "ibm,plb-pciex-476fpe") ||
  1467. of_device_is_compatible(
  1468. port->node, "ibm,plb-pciex-476gtr"))
  1469. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
  1470. sa | DCRO_PEGPL_476FPE_OMR1MSKL_UOT
  1471. | DCRO_PEGPL_OMRxMSKL_VAL);
  1472. else
  1473. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL,
  1474. sa | DCRO_PEGPL_OMR1MSKL_UOT
  1475. | DCRO_PEGPL_OMRxMSKL_VAL);
  1476. break;
  1477. case 1:
  1478. out_le32(mbase + PECFG_POM1LAH, pciah);
  1479. out_le32(mbase + PECFG_POM1LAL, pcial);
  1480. dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAH, lah);
  1481. dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAL, lal);
  1482. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKH, 0x7fffffff);
  1483. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL,
  1484. sa | DCRO_PEGPL_OMRxMSKL_VAL);
  1485. break;
  1486. case 2:
  1487. out_le32(mbase + PECFG_POM2LAH, pciah);
  1488. out_le32(mbase + PECFG_POM2LAL, pcial);
  1489. dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAH, lah);
  1490. dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAL, lal);
  1491. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKH, 0x7fffffff);
  1492. /* Note that 3 here means enabled | IO space !!! */
  1493. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL,
  1494. sa | DCRO_PEGPL_OMR3MSKL_IO
  1495. | DCRO_PEGPL_OMRxMSKL_VAL);
  1496. break;
  1497. }
  1498. return 0;
  1499. }
  1500. static void __init ppc4xx_configure_pciex_POMs(struct ppc4xx_pciex_port *port,
  1501. struct pci_controller *hose,
  1502. void __iomem *mbase)
  1503. {
  1504. int i, j, found_isa_hole = 0;
  1505. /* Setup outbound memory windows */
  1506. for (i = j = 0; i < 3; i++) {
  1507. struct resource *res = &hose->mem_resources[i];
  1508. resource_size_t offset = hose->mem_offset[i];
  1509. /* we only care about memory windows */
  1510. if (!(res->flags & IORESOURCE_MEM))
  1511. continue;
  1512. if (j > 1) {
  1513. printk(KERN_WARNING "%pOF: Too many ranges\n",
  1514. port->node);
  1515. break;
  1516. }
  1517. /* Configure the resource */
  1518. if (ppc4xx_setup_one_pciex_POM(port, hose, mbase,
  1519. res->start,
  1520. res->start - offset,
  1521. resource_size(res),
  1522. res->flags,
  1523. j) == 0) {
  1524. j++;
  1525. /* If the resource PCI address is 0 then we have our
  1526. * ISA memory hole
  1527. */
  1528. if (res->start == offset)
  1529. found_isa_hole = 1;
  1530. }
  1531. }
  1532. /* Handle ISA memory hole if not already covered */
  1533. if (j <= 1 && !found_isa_hole && hose->isa_mem_size)
  1534. if (ppc4xx_setup_one_pciex_POM(port, hose, mbase,
  1535. hose->isa_mem_phys, 0,
  1536. hose->isa_mem_size, 0, j) == 0)
  1537. printk(KERN_INFO "%pOF: Legacy ISA memory support enabled\n",
  1538. hose->dn);
  1539. /* Configure IO, always 64K starting at 0. We hard wire it to 64K !
  1540. * Note also that it -has- to be region index 2 on this HW
  1541. */
  1542. if (hose->io_resource.flags & IORESOURCE_IO)
  1543. ppc4xx_setup_one_pciex_POM(port, hose, mbase,
  1544. hose->io_base_phys, 0,
  1545. 0x10000, IORESOURCE_IO, 2);
  1546. }
  1547. static void __init ppc4xx_configure_pciex_PIMs(struct ppc4xx_pciex_port *port,
  1548. struct pci_controller *hose,
  1549. void __iomem *mbase,
  1550. struct resource *res)
  1551. {
  1552. resource_size_t size = resource_size(res);
  1553. u64 sa;
  1554. if (port->endpoint) {
  1555. resource_size_t ep_addr = 0;
  1556. resource_size_t ep_size = 32 << 20;
  1557. /* Currently we map a fixed 64MByte window to PLB address
  1558. * 0 (SDRAM). This should probably be configurable via a dts
  1559. * property.
  1560. */
  1561. /* Calculate window size */
  1562. sa = (0xffffffffffffffffull << ilog2(ep_size));
  1563. /* Setup BAR0 */
  1564. out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
  1565. out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa) |
  1566. PCI_BASE_ADDRESS_MEM_TYPE_64);
  1567. /* Disable BAR1 & BAR2 */
  1568. out_le32(mbase + PECFG_BAR1MPA, 0);
  1569. out_le32(mbase + PECFG_BAR2HMPA, 0);
  1570. out_le32(mbase + PECFG_BAR2LMPA, 0);
  1571. out_le32(mbase + PECFG_PIM01SAH, RES_TO_U32_HIGH(sa));
  1572. out_le32(mbase + PECFG_PIM01SAL, RES_TO_U32_LOW(sa));
  1573. out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(ep_addr));
  1574. out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(ep_addr));
  1575. } else {
  1576. /* Calculate window size */
  1577. sa = (0xffffffffffffffffull << ilog2(size));
  1578. if (res->flags & IORESOURCE_PREFETCH)
  1579. sa |= PCI_BASE_ADDRESS_MEM_PREFETCH;
  1580. if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx") ||
  1581. of_device_is_compatible(
  1582. port->node, "ibm,plb-pciex-476fpe") ||
  1583. of_device_is_compatible(
  1584. port->node, "ibm,plb-pciex-476gtr"))
  1585. sa |= PCI_BASE_ADDRESS_MEM_TYPE_64;
  1586. out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
  1587. out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
  1588. /* The setup of the split looks weird to me ... let's see
  1589. * if it works
  1590. */
  1591. out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
  1592. out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
  1593. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  1594. out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
  1595. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  1596. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  1597. out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
  1598. out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
  1599. }
  1600. /* Enable inbound mapping */
  1601. out_le32(mbase + PECFG_PIMEN, 0x1);
  1602. /* Enable I/O, Mem, and Busmaster cycles */
  1603. out_le16(mbase + PCI_COMMAND,
  1604. in_le16(mbase + PCI_COMMAND) |
  1605. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  1606. }
  1607. static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
  1608. {
  1609. struct resource dma_window;
  1610. struct pci_controller *hose = NULL;
  1611. const int *bus_range;
  1612. int primary = 0, busses;
  1613. void __iomem *mbase = NULL, *cfg_data = NULL;
  1614. const u32 *pval;
  1615. u32 val;
  1616. /* Check if primary bridge */
  1617. if (of_get_property(port->node, "primary", NULL))
  1618. primary = 1;
  1619. /* Get bus range if any */
  1620. bus_range = of_get_property(port->node, "bus-range", NULL);
  1621. /* Allocate the host controller data structure */
  1622. hose = pcibios_alloc_controller(port->node);
  1623. if (!hose)
  1624. goto fail;
  1625. /* We stick the port number in "indirect_type" so the config space
  1626. * ops can retrieve the port data structure easily
  1627. */
  1628. hose->indirect_type = port->index;
  1629. /* Get bus range */
  1630. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  1631. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  1632. /* Because of how big mapping the config space is (1M per bus), we
  1633. * limit how many busses we support. In the long run, we could replace
  1634. * that with something akin to kmap_atomic instead. We set aside 1 bus
  1635. * for the host itself too.
  1636. */
  1637. busses = hose->last_busno - hose->first_busno; /* This is off by 1 */
  1638. if (busses > MAX_PCIE_BUS_MAPPED) {
  1639. busses = MAX_PCIE_BUS_MAPPED;
  1640. hose->last_busno = hose->first_busno + busses;
  1641. }
  1642. if (!port->endpoint) {
  1643. /* Only map the external config space in cfg_data for
  1644. * PCIe root-complexes. External space is 1M per bus
  1645. */
  1646. cfg_data = ioremap(port->cfg_space.start +
  1647. (hose->first_busno + 1) * 0x100000,
  1648. busses * 0x100000);
  1649. if (cfg_data == NULL) {
  1650. printk(KERN_ERR "%pOF: Can't map external config space !",
  1651. port->node);
  1652. goto fail;
  1653. }
  1654. hose->cfg_data = cfg_data;
  1655. }
  1656. /* Always map the host config space in cfg_addr.
  1657. * Internal space is 4K
  1658. */
  1659. mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
  1660. if (mbase == NULL) {
  1661. printk(KERN_ERR "%pOF: Can't map internal config space !",
  1662. port->node);
  1663. goto fail;
  1664. }
  1665. hose->cfg_addr = mbase;
  1666. pr_debug("PCIE %pOF, bus %d..%d\n", port->node,
  1667. hose->first_busno, hose->last_busno);
  1668. pr_debug(" config space mapped at: root @0x%p, other @0x%p\n",
  1669. hose->cfg_addr, hose->cfg_data);
  1670. /* Setup config space */
  1671. hose->ops = &ppc4xx_pciex_pci_ops;
  1672. port->hose = hose;
  1673. mbase = (void __iomem *)hose->cfg_addr;
  1674. if (!port->endpoint) {
  1675. /*
  1676. * Set bus numbers on our root port
  1677. */
  1678. out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
  1679. out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
  1680. out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
  1681. }
  1682. /*
  1683. * OMRs are already reset, also disable PIMs
  1684. */
  1685. out_le32(mbase + PECFG_PIMEN, 0);
  1686. /* Parse outbound mapping resources */
  1687. pci_process_bridge_OF_ranges(hose, port->node, primary);
  1688. /* Parse inbound mapping resources */
  1689. if (ppc4xx_parse_dma_ranges(hose, mbase, &dma_window) != 0)
  1690. goto fail;
  1691. /* Configure outbound ranges POMs */
  1692. ppc4xx_configure_pciex_POMs(port, hose, mbase);
  1693. /* Configure inbound ranges PIMs */
  1694. ppc4xx_configure_pciex_PIMs(port, hose, mbase, &dma_window);
  1695. /* The root complex doesn't show up if we don't set some vendor
  1696. * and device IDs into it. The defaults below are the same bogus
  1697. * one that the initial code in arch/ppc had. This can be
  1698. * overwritten by setting the "vendor-id/device-id" properties
  1699. * in the pciex node.
  1700. */
  1701. /* Get the (optional) vendor-/device-id from the device-tree */
  1702. pval = of_get_property(port->node, "vendor-id", NULL);
  1703. if (pval) {
  1704. val = *pval;
  1705. } else {
  1706. if (!port->endpoint)
  1707. val = 0xaaa0 + port->index;
  1708. else
  1709. val = 0xeee0 + port->index;
  1710. }
  1711. out_le16(mbase + 0x200, val);
  1712. pval = of_get_property(port->node, "device-id", NULL);
  1713. if (pval) {
  1714. val = *pval;
  1715. } else {
  1716. if (!port->endpoint)
  1717. val = 0xbed0 + port->index;
  1718. else
  1719. val = 0xfed0 + port->index;
  1720. }
  1721. out_le16(mbase + 0x202, val);
  1722. /* Enable Bus master, memory, and io space */
  1723. if (of_device_is_compatible(port->node, "ibm,plb-pciex-460sx"))
  1724. out_le16(mbase + 0x204, 0x7);
  1725. if (!port->endpoint) {
  1726. /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
  1727. out_le32(mbase + 0x208, 0x06040001);
  1728. printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
  1729. port->index);
  1730. } else {
  1731. /* Set Class Code to Processor/PPC */
  1732. out_le32(mbase + 0x208, 0x0b200001);
  1733. printk(KERN_INFO "PCIE%d: successfully set as endpoint\n",
  1734. port->index);
  1735. }
  1736. return;
  1737. fail:
  1738. if (hose)
  1739. pcibios_free_controller(hose);
  1740. if (cfg_data)
  1741. iounmap(cfg_data);
  1742. if (mbase)
  1743. iounmap(mbase);
  1744. }
  1745. static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
  1746. {
  1747. struct ppc4xx_pciex_port *port;
  1748. const u32 *pval;
  1749. int portno;
  1750. unsigned int dcrs;
  1751. const char *val;
  1752. /* First, proceed to core initialization as we assume there's
  1753. * only one PCIe core in the system
  1754. */
  1755. if (ppc4xx_pciex_check_core_init(np))
  1756. return;
  1757. /* Get the port number from the device-tree */
  1758. pval = of_get_property(np, "port", NULL);
  1759. if (pval == NULL) {
  1760. printk(KERN_ERR "PCIE: Can't find port number for %pOF\n", np);
  1761. return;
  1762. }
  1763. portno = *pval;
  1764. if (portno >= ppc4xx_pciex_port_count) {
  1765. printk(KERN_ERR "PCIE: port number out of range for %pOF\n",
  1766. np);
  1767. return;
  1768. }
  1769. port = &ppc4xx_pciex_ports[portno];
  1770. port->index = portno;
  1771. /*
  1772. * Check if device is enabled
  1773. */
  1774. if (!of_device_is_available(np)) {
  1775. printk(KERN_INFO "PCIE%d: Port disabled via device-tree\n", port->index);
  1776. return;
  1777. }
  1778. port->node = of_node_get(np);
  1779. if (ppc4xx_pciex_hwops->want_sdr) {
  1780. pval = of_get_property(np, "sdr-base", NULL);
  1781. if (pval == NULL) {
  1782. printk(KERN_ERR "PCIE: missing sdr-base for %pOF\n",
  1783. np);
  1784. return;
  1785. }
  1786. port->sdr_base = *pval;
  1787. }
  1788. /* Check if device_type property is set to "pci" or "pci-endpoint".
  1789. * Resulting from this setup this PCIe port will be configured
  1790. * as root-complex or as endpoint.
  1791. */
  1792. val = of_get_property(port->node, "device_type", NULL);
  1793. if (!strcmp(val, "pci-endpoint")) {
  1794. port->endpoint = 1;
  1795. } else if (!strcmp(val, "pci")) {
  1796. port->endpoint = 0;
  1797. } else {
  1798. printk(KERN_ERR "PCIE: missing or incorrect device_type for %pOF\n",
  1799. np);
  1800. return;
  1801. }
  1802. /* Fetch config space registers address */
  1803. if (of_address_to_resource(np, 0, &port->cfg_space)) {
  1804. printk(KERN_ERR "%pOF: Can't get PCI-E config space !", np);
  1805. return;
  1806. }
  1807. /* Fetch host bridge internal registers address */
  1808. if (of_address_to_resource(np, 1, &port->utl_regs)) {
  1809. printk(KERN_ERR "%pOF: Can't get UTL register base !", np);
  1810. return;
  1811. }
  1812. /* Map DCRs */
  1813. dcrs = dcr_resource_start(np, 0);
  1814. if (dcrs == 0) {
  1815. printk(KERN_ERR "%pOF: Can't get DCR register base !", np);
  1816. return;
  1817. }
  1818. port->dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0));
  1819. /* Initialize the port specific registers */
  1820. if (ppc4xx_pciex_port_init(port)) {
  1821. printk(KERN_WARNING "PCIE%d: Port init failed\n", port->index);
  1822. return;
  1823. }
  1824. /* Setup the linux hose data structure */
  1825. ppc4xx_pciex_port_setup_hose(port);
  1826. }
  1827. #endif /* CONFIG_PPC4xx_PCI_EXPRESS */
  1828. static int __init ppc4xx_pci_find_bridges(void)
  1829. {
  1830. struct device_node *np;
  1831. pci_add_flags(PCI_ENABLE_PROC_DOMAINS | PCI_COMPAT_DOMAIN_0);
  1832. #ifdef CONFIG_PPC4xx_PCI_EXPRESS
  1833. for_each_compatible_node(np, NULL, "ibm,plb-pciex")
  1834. ppc4xx_probe_pciex_bridge(np);
  1835. #endif
  1836. for_each_compatible_node(np, NULL, "ibm,plb-pcix")
  1837. ppc4xx_probe_pcix_bridge(np);
  1838. for_each_compatible_node(np, NULL, "ibm,plb-pci")
  1839. ppc4xx_probe_pci_bridge(np);
  1840. return 0;
  1841. }
  1842. arch_initcall(ppc4xx_pci_find_bridges);