ppc4xx_pci.c 60 KB

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