ppc4xx_pci.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  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 <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 "ppc4xx_pci.h"
  31. static int dma_offset_set;
  32. /* Move that to a useable header */
  33. extern unsigned long total_memory;
  34. #define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
  35. #define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
  36. #ifdef CONFIG_RESOURCES_64BIT
  37. #define RES_TO_U32_LOW(val) U64_TO_U32_LOW(val)
  38. #define RES_TO_U32_HIGH(val) U64_TO_U32_HIGH(val)
  39. #else
  40. #define RES_TO_U32_LOW(val) (val)
  41. #define RES_TO_U32_HIGH(val) (0)
  42. #endif
  43. static inline int ppc440spe_revA(void)
  44. {
  45. /* Catch both 440SPe variants, with and without RAID6 support */
  46. if ((mfspr(SPRN_PVR) & 0xffefffff) == 0x53421890)
  47. return 1;
  48. else
  49. return 0;
  50. }
  51. static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev)
  52. {
  53. struct pci_controller *hose;
  54. int i;
  55. if (dev->devfn != 0 || dev->bus->self != NULL)
  56. return;
  57. hose = pci_bus_to_host(dev->bus);
  58. if (hose == NULL)
  59. return;
  60. if (!of_device_is_compatible(hose->dn, "ibm,plb-pciex") &&
  61. !of_device_is_compatible(hose->dn, "ibm,plb-pcix") &&
  62. !of_device_is_compatible(hose->dn, "ibm,plb-pci"))
  63. return;
  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. res->end = size = 0x80000000;
  87. res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
  88. /* Get dma-ranges property */
  89. ranges = of_get_property(hose->dn, "dma-ranges", &rlen);
  90. if (ranges == NULL)
  91. goto out;
  92. /* Walk it */
  93. while ((rlen -= np * 4) >= 0) {
  94. u32 pci_space = ranges[0];
  95. u64 pci_addr = of_read_number(ranges + 1, 2);
  96. u64 cpu_addr = of_translate_dma_address(hose->dn, ranges + 3);
  97. size = of_read_number(ranges + pna + 3, 2);
  98. ranges += np;
  99. if (cpu_addr == OF_BAD_ADDR || size == 0)
  100. continue;
  101. /* We only care about memory */
  102. if ((pci_space & 0x03000000) != 0x02000000)
  103. continue;
  104. /* We currently only support memory at 0, and pci_addr
  105. * within 32 bits space
  106. */
  107. if (cpu_addr != 0 || pci_addr > 0xffffffff) {
  108. printk(KERN_WARNING "%s: Ignored unsupported dma range"
  109. " 0x%016llx...0x%016llx -> 0x%016llx\n",
  110. hose->dn->full_name,
  111. pci_addr, pci_addr + size - 1, cpu_addr);
  112. continue;
  113. }
  114. /* Check if not prefetchable */
  115. if (!(pci_space & 0x40000000))
  116. res->flags &= ~IORESOURCE_PREFETCH;
  117. /* Use that */
  118. res->start = pci_addr;
  119. #ifndef CONFIG_RESOURCES_64BIT
  120. /* Beware of 32 bits resources */
  121. if ((pci_addr + size) > 0x100000000ull)
  122. res->end = 0xffffffff;
  123. else
  124. #endif
  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 "%s: dma-ranges(s) mismatch\n",
  131. hose->dn->full_name);
  132. return -ENXIO;
  133. }
  134. /* Check that we can fit all of memory as we don't support
  135. * DMA bounce buffers
  136. */
  137. if (size < total_memory) {
  138. printk(KERN_ERR "%s: dma-ranges too small "
  139. "(size=%llx total_memory=%lx)\n",
  140. hose->dn->full_name, size, total_memory);
  141. return -ENXIO;
  142. }
  143. /* Check we are a power of 2 size and that base is a multiple of size*/
  144. if (!is_power_of_2(size) ||
  145. (res->start & (size - 1)) != 0) {
  146. printk(KERN_ERR "%s: dma-ranges unaligned\n",
  147. hose->dn->full_name);
  148. return -ENXIO;
  149. }
  150. /* Check that we are fully contained within 32 bits space */
  151. if (res->end > 0xffffffff) {
  152. printk(KERN_ERR "%s: dma-ranges outside of 32 bits space\n",
  153. hose->dn->full_name);
  154. return -ENXIO;
  155. }
  156. out:
  157. dma_offset_set = 1;
  158. pci_dram_offset = res->start;
  159. printk(KERN_INFO "4xx PCI DMA offset set to 0x%08lx\n",
  160. pci_dram_offset);
  161. return 0;
  162. }
  163. /*
  164. * 4xx PCI 2.x part
  165. */
  166. static void __init ppc4xx_configure_pci_PMMs(struct pci_controller *hose,
  167. void __iomem *reg)
  168. {
  169. u32 la, ma, pcila, pciha;
  170. int i, j;
  171. /* Setup outbound memory windows */
  172. for (i = j = 0; i < 3; i++) {
  173. struct resource *res = &hose->mem_resources[i];
  174. /* we only care about memory windows */
  175. if (!(res->flags & IORESOURCE_MEM))
  176. continue;
  177. if (j > 2) {
  178. printk(KERN_WARNING "%s: Too many ranges\n",
  179. hose->dn->full_name);
  180. break;
  181. }
  182. /* Calculate register values */
  183. la = res->start;
  184. pciha = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
  185. pcila = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
  186. ma = res->end + 1 - res->start;
  187. if (!is_power_of_2(ma) || ma < 0x1000 || ma > 0xffffffffu) {
  188. printk(KERN_WARNING "%s: Resource out of range\n",
  189. hose->dn->full_name);
  190. continue;
  191. }
  192. ma = (0xffffffffu << ilog2(ma)) | 0x1;
  193. if (res->flags & IORESOURCE_PREFETCH)
  194. ma |= 0x2;
  195. /* Program register values */
  196. writel(la, reg + PCIL0_PMM0LA + (0x10 * j));
  197. writel(pcila, reg + PCIL0_PMM0PCILA + (0x10 * j));
  198. writel(pciha, reg + PCIL0_PMM0PCIHA + (0x10 * j));
  199. writel(ma, reg + PCIL0_PMM0MA + (0x10 * j));
  200. j++;
  201. }
  202. }
  203. static void __init ppc4xx_configure_pci_PTMs(struct pci_controller *hose,
  204. void __iomem *reg,
  205. const struct resource *res)
  206. {
  207. resource_size_t size = res->end - res->start + 1;
  208. u32 sa;
  209. /* Calculate window size */
  210. sa = (0xffffffffu << ilog2(size)) | 1;
  211. sa |= 0x1;
  212. /* RAM is always at 0 local for now */
  213. writel(0, reg + PCIL0_PTM1LA);
  214. writel(sa, reg + PCIL0_PTM1MS);
  215. /* Map on PCI side */
  216. early_write_config_dword(hose, hose->first_busno, 0,
  217. PCI_BASE_ADDRESS_1, res->start);
  218. early_write_config_dword(hose, hose->first_busno, 0,
  219. PCI_BASE_ADDRESS_2, 0x00000000);
  220. early_write_config_word(hose, hose->first_busno, 0,
  221. PCI_COMMAND, 0x0006);
  222. }
  223. static void __init ppc4xx_probe_pci_bridge(struct device_node *np)
  224. {
  225. /* NYI */
  226. struct resource rsrc_cfg;
  227. struct resource rsrc_reg;
  228. struct resource dma_window;
  229. struct pci_controller *hose = NULL;
  230. void __iomem *reg = NULL;
  231. const int *bus_range;
  232. int primary = 0;
  233. /* Fetch config space registers address */
  234. if (of_address_to_resource(np, 0, &rsrc_cfg)) {
  235. printk(KERN_ERR "%s:Can't get PCI config register base !",
  236. np->full_name);
  237. return;
  238. }
  239. /* Fetch host bridge internal registers address */
  240. if (of_address_to_resource(np, 3, &rsrc_reg)) {
  241. printk(KERN_ERR "%s: Can't get PCI internal register base !",
  242. np->full_name);
  243. return;
  244. }
  245. /* Check if primary bridge */
  246. if (of_get_property(np, "primary", NULL))
  247. primary = 1;
  248. /* Get bus range if any */
  249. bus_range = of_get_property(np, "bus-range", NULL);
  250. /* Map registers */
  251. reg = ioremap(rsrc_reg.start, rsrc_reg.end + 1 - rsrc_reg.start);
  252. if (reg == NULL) {
  253. printk(KERN_ERR "%s: Can't map registers !", np->full_name);
  254. goto fail;
  255. }
  256. /* Allocate the host controller data structure */
  257. hose = pcibios_alloc_controller(np);
  258. if (!hose)
  259. goto fail;
  260. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  261. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  262. /* Setup config space */
  263. setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
  264. /* Disable all windows */
  265. writel(0, reg + PCIL0_PMM0MA);
  266. writel(0, reg + PCIL0_PMM1MA);
  267. writel(0, reg + PCIL0_PMM2MA);
  268. writel(0, reg + PCIL0_PTM1MS);
  269. writel(0, reg + PCIL0_PTM2MS);
  270. /* Parse outbound mapping resources */
  271. pci_process_bridge_OF_ranges(hose, np, primary);
  272. /* Parse inbound mapping resources */
  273. if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
  274. goto fail;
  275. /* Configure outbound ranges POMs */
  276. ppc4xx_configure_pci_PMMs(hose, reg);
  277. /* Configure inbound ranges PIMs */
  278. ppc4xx_configure_pci_PTMs(hose, reg, &dma_window);
  279. /* We don't need the registers anymore */
  280. iounmap(reg);
  281. return;
  282. fail:
  283. if (hose)
  284. pcibios_free_controller(hose);
  285. if (reg)
  286. iounmap(reg);
  287. }
  288. /*
  289. * 4xx PCI-X part
  290. */
  291. static void __init ppc4xx_configure_pcix_POMs(struct pci_controller *hose,
  292. void __iomem *reg)
  293. {
  294. u32 lah, lal, pciah, pcial, sa;
  295. int i, j;
  296. /* Setup outbound memory windows */
  297. for (i = j = 0; i < 3; i++) {
  298. struct resource *res = &hose->mem_resources[i];
  299. /* we only care about memory windows */
  300. if (!(res->flags & IORESOURCE_MEM))
  301. continue;
  302. if (j > 1) {
  303. printk(KERN_WARNING "%s: Too many ranges\n",
  304. hose->dn->full_name);
  305. break;
  306. }
  307. /* Calculate register values */
  308. lah = RES_TO_U32_HIGH(res->start);
  309. lal = RES_TO_U32_LOW(res->start);
  310. pciah = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
  311. pcial = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
  312. sa = res->end + 1 - res->start;
  313. if (!is_power_of_2(sa) || sa < 0x100000 ||
  314. sa > 0xffffffffu) {
  315. printk(KERN_WARNING "%s: Resource out of range\n",
  316. hose->dn->full_name);
  317. continue;
  318. }
  319. sa = (0xffffffffu << ilog2(sa)) | 0x1;
  320. /* Program register values */
  321. if (j == 0) {
  322. writel(lah, reg + PCIX0_POM0LAH);
  323. writel(lal, reg + PCIX0_POM0LAL);
  324. writel(pciah, reg + PCIX0_POM0PCIAH);
  325. writel(pcial, reg + PCIX0_POM0PCIAL);
  326. writel(sa, reg + PCIX0_POM0SA);
  327. } else {
  328. writel(lah, reg + PCIX0_POM1LAH);
  329. writel(lal, reg + PCIX0_POM1LAL);
  330. writel(pciah, reg + PCIX0_POM1PCIAH);
  331. writel(pcial, reg + PCIX0_POM1PCIAL);
  332. writel(sa, reg + PCIX0_POM1SA);
  333. }
  334. j++;
  335. }
  336. }
  337. static void __init ppc4xx_configure_pcix_PIMs(struct pci_controller *hose,
  338. void __iomem *reg,
  339. const struct resource *res,
  340. int big_pim,
  341. int enable_msi_hole)
  342. {
  343. resource_size_t size = res->end - res->start + 1;
  344. u32 sa;
  345. /* RAM is always at 0 */
  346. writel(0x00000000, reg + PCIX0_PIM0LAH);
  347. writel(0x00000000, reg + PCIX0_PIM0LAL);
  348. /* Calculate window size */
  349. sa = (0xffffffffu << ilog2(size)) | 1;
  350. sa |= 0x1;
  351. if (res->flags & IORESOURCE_PREFETCH)
  352. sa |= 0x2;
  353. if (enable_msi_hole)
  354. sa |= 0x4;
  355. writel(sa, reg + PCIX0_PIM0SA);
  356. if (big_pim)
  357. writel(0xffffffff, reg + PCIX0_PIM0SAH);
  358. /* Map on PCI side */
  359. writel(0x00000000, reg + PCIX0_BAR0H);
  360. writel(res->start, reg + PCIX0_BAR0L);
  361. writew(0x0006, reg + PCIX0_COMMAND);
  362. }
  363. static void __init ppc4xx_probe_pcix_bridge(struct device_node *np)
  364. {
  365. struct resource rsrc_cfg;
  366. struct resource rsrc_reg;
  367. struct resource dma_window;
  368. struct pci_controller *hose = NULL;
  369. void __iomem *reg = NULL;
  370. const int *bus_range;
  371. int big_pim = 0, msi = 0, primary = 0;
  372. /* Fetch config space registers address */
  373. if (of_address_to_resource(np, 0, &rsrc_cfg)) {
  374. printk(KERN_ERR "%s:Can't get PCI-X config register base !",
  375. np->full_name);
  376. return;
  377. }
  378. /* Fetch host bridge internal registers address */
  379. if (of_address_to_resource(np, 3, &rsrc_reg)) {
  380. printk(KERN_ERR "%s: Can't get PCI-X internal register base !",
  381. np->full_name);
  382. return;
  383. }
  384. /* Check if it supports large PIMs (440GX) */
  385. if (of_get_property(np, "large-inbound-windows", NULL))
  386. big_pim = 1;
  387. /* Check if we should enable MSIs inbound hole */
  388. if (of_get_property(np, "enable-msi-hole", NULL))
  389. msi = 1;
  390. /* Check if primary bridge */
  391. if (of_get_property(np, "primary", NULL))
  392. primary = 1;
  393. /* Get bus range if any */
  394. bus_range = of_get_property(np, "bus-range", NULL);
  395. /* Map registers */
  396. reg = ioremap(rsrc_reg.start, rsrc_reg.end + 1 - rsrc_reg.start);
  397. if (reg == NULL) {
  398. printk(KERN_ERR "%s: Can't map registers !", np->full_name);
  399. goto fail;
  400. }
  401. /* Allocate the host controller data structure */
  402. hose = pcibios_alloc_controller(np);
  403. if (!hose)
  404. goto fail;
  405. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  406. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  407. /* Setup config space */
  408. setup_indirect_pci(hose, rsrc_cfg.start, rsrc_cfg.start + 0x4, 0);
  409. /* Disable all windows */
  410. writel(0, reg + PCIX0_POM0SA);
  411. writel(0, reg + PCIX0_POM1SA);
  412. writel(0, reg + PCIX0_POM2SA);
  413. writel(0, reg + PCIX0_PIM0SA);
  414. writel(0, reg + PCIX0_PIM1SA);
  415. writel(0, reg + PCIX0_PIM2SA);
  416. if (big_pim) {
  417. writel(0, reg + PCIX0_PIM0SAH);
  418. writel(0, reg + PCIX0_PIM2SAH);
  419. }
  420. /* Parse outbound mapping resources */
  421. pci_process_bridge_OF_ranges(hose, np, primary);
  422. /* Parse inbound mapping resources */
  423. if (ppc4xx_parse_dma_ranges(hose, reg, &dma_window) != 0)
  424. goto fail;
  425. /* Configure outbound ranges POMs */
  426. ppc4xx_configure_pcix_POMs(hose, reg);
  427. /* Configure inbound ranges PIMs */
  428. ppc4xx_configure_pcix_PIMs(hose, reg, &dma_window, big_pim, msi);
  429. /* We don't need the registers anymore */
  430. iounmap(reg);
  431. return;
  432. fail:
  433. if (hose)
  434. pcibios_free_controller(hose);
  435. if (reg)
  436. iounmap(reg);
  437. }
  438. #ifdef CONFIG_PPC4xx_PCI_EXPRESS
  439. /*
  440. * 4xx PCI-Express part
  441. *
  442. * We support 3 parts currently based on the compatible property:
  443. *
  444. * ibm,plb-pciex-440spe
  445. * ibm,plb-pciex-405ex
  446. * ibm,plb-pciex-460ex
  447. *
  448. * Anything else will be rejected for now as they are all subtly
  449. * different unfortunately.
  450. *
  451. */
  452. #define MAX_PCIE_BUS_MAPPED 0x40
  453. struct ppc4xx_pciex_port
  454. {
  455. struct pci_controller *hose;
  456. struct device_node *node;
  457. unsigned int index;
  458. int endpoint;
  459. int link;
  460. int has_ibpre;
  461. unsigned int sdr_base;
  462. dcr_host_t dcrs;
  463. struct resource cfg_space;
  464. struct resource utl_regs;
  465. void __iomem *utl_base;
  466. };
  467. static struct ppc4xx_pciex_port *ppc4xx_pciex_ports;
  468. static unsigned int ppc4xx_pciex_port_count;
  469. struct ppc4xx_pciex_hwops
  470. {
  471. int (*core_init)(struct device_node *np);
  472. int (*port_init_hw)(struct ppc4xx_pciex_port *port);
  473. int (*setup_utl)(struct ppc4xx_pciex_port *port);
  474. };
  475. static struct ppc4xx_pciex_hwops *ppc4xx_pciex_hwops;
  476. #ifdef CONFIG_44x
  477. /* Check various reset bits of the 440SPe PCIe core */
  478. static int __init ppc440spe_pciex_check_reset(struct device_node *np)
  479. {
  480. u32 valPE0, valPE1, valPE2;
  481. int err = 0;
  482. /* SDR0_PEGPLLLCT1 reset */
  483. if (!(mfdcri(SDR0, PESDR0_PLLLCT1) & 0x01000000)) {
  484. /*
  485. * the PCIe core was probably already initialised
  486. * by firmware - let's re-reset RCSSET regs
  487. *
  488. * -- Shouldn't we also re-reset the whole thing ? -- BenH
  489. */
  490. pr_debug("PCIE: SDR0_PLLLCT1 already reset.\n");
  491. mtdcri(SDR0, PESDR0_440SPE_RCSSET, 0x01010000);
  492. mtdcri(SDR0, PESDR1_440SPE_RCSSET, 0x01010000);
  493. mtdcri(SDR0, PESDR2_440SPE_RCSSET, 0x01010000);
  494. }
  495. valPE0 = mfdcri(SDR0, PESDR0_440SPE_RCSSET);
  496. valPE1 = mfdcri(SDR0, PESDR1_440SPE_RCSSET);
  497. valPE2 = mfdcri(SDR0, PESDR2_440SPE_RCSSET);
  498. /* SDR0_PExRCSSET rstgu */
  499. if (!(valPE0 & 0x01000000) ||
  500. !(valPE1 & 0x01000000) ||
  501. !(valPE2 & 0x01000000)) {
  502. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstgu error\n");
  503. err = -1;
  504. }
  505. /* SDR0_PExRCSSET rstdl */
  506. if (!(valPE0 & 0x00010000) ||
  507. !(valPE1 & 0x00010000) ||
  508. !(valPE2 & 0x00010000)) {
  509. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstdl error\n");
  510. err = -1;
  511. }
  512. /* SDR0_PExRCSSET rstpyn */
  513. if ((valPE0 & 0x00001000) ||
  514. (valPE1 & 0x00001000) ||
  515. (valPE2 & 0x00001000)) {
  516. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rstpyn error\n");
  517. err = -1;
  518. }
  519. /* SDR0_PExRCSSET hldplb */
  520. if ((valPE0 & 0x10000000) ||
  521. (valPE1 & 0x10000000) ||
  522. (valPE2 & 0x10000000)) {
  523. printk(KERN_INFO "PCIE: SDR0_PExRCSSET hldplb error\n");
  524. err = -1;
  525. }
  526. /* SDR0_PExRCSSET rdy */
  527. if ((valPE0 & 0x00100000) ||
  528. (valPE1 & 0x00100000) ||
  529. (valPE2 & 0x00100000)) {
  530. printk(KERN_INFO "PCIE: SDR0_PExRCSSET rdy error\n");
  531. err = -1;
  532. }
  533. /* SDR0_PExRCSSET shutdown */
  534. if ((valPE0 & 0x00000100) ||
  535. (valPE1 & 0x00000100) ||
  536. (valPE2 & 0x00000100)) {
  537. printk(KERN_INFO "PCIE: SDR0_PExRCSSET shutdown error\n");
  538. err = -1;
  539. }
  540. return err;
  541. }
  542. /* Global PCIe core initializations for 440SPe core */
  543. static int __init ppc440spe_pciex_core_init(struct device_node *np)
  544. {
  545. int time_out = 20;
  546. /* Set PLL clock receiver to LVPECL */
  547. dcri_clrset(SDR0, PESDR0_PLLLCT1, 0, 1 << 28);
  548. /* Shouldn't we do all the calibration stuff etc... here ? */
  549. if (ppc440spe_pciex_check_reset(np))
  550. return -ENXIO;
  551. if (!(mfdcri(SDR0, PESDR0_PLLLCT2) & 0x10000)) {
  552. printk(KERN_INFO "PCIE: PESDR_PLLCT2 resistance calibration "
  553. "failed (0x%08x)\n",
  554. mfdcri(SDR0, PESDR0_PLLLCT2));
  555. return -1;
  556. }
  557. /* De-assert reset of PCIe PLL, wait for lock */
  558. dcri_clrset(SDR0, PESDR0_PLLLCT1, 1 << 24, 0);
  559. udelay(3);
  560. while (time_out) {
  561. if (!(mfdcri(SDR0, PESDR0_PLLLCT3) & 0x10000000)) {
  562. time_out--;
  563. udelay(1);
  564. } else
  565. break;
  566. }
  567. if (!time_out) {
  568. printk(KERN_INFO "PCIE: VCO output not locked\n");
  569. return -1;
  570. }
  571. pr_debug("PCIE initialization OK\n");
  572. return 3;
  573. }
  574. static int ppc440spe_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  575. {
  576. u32 val = 1 << 24;
  577. if (port->endpoint)
  578. val = PTYPE_LEGACY_ENDPOINT << 20;
  579. else
  580. val = PTYPE_ROOT_PORT << 20;
  581. if (port->index == 0)
  582. val |= LNKW_X8 << 12;
  583. else
  584. val |= LNKW_X4 << 12;
  585. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
  586. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x20222222);
  587. if (ppc440spe_revA())
  588. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x11000000);
  589. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL0SET1, 0x35000000);
  590. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL1SET1, 0x35000000);
  591. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL2SET1, 0x35000000);
  592. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL3SET1, 0x35000000);
  593. if (port->index == 0) {
  594. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL4SET1,
  595. 0x35000000);
  596. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL5SET1,
  597. 0x35000000);
  598. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL6SET1,
  599. 0x35000000);
  600. mtdcri(SDR0, port->sdr_base + PESDRn_440SPE_HSSL7SET1,
  601. 0x35000000);
  602. }
  603. dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET,
  604. (1 << 24) | (1 << 16), 1 << 12);
  605. return 0;
  606. }
  607. static int ppc440speA_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  608. {
  609. return ppc440spe_pciex_init_port_hw(port);
  610. }
  611. static int ppc440speB_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  612. {
  613. int rc = ppc440spe_pciex_init_port_hw(port);
  614. port->has_ibpre = 1;
  615. return rc;
  616. }
  617. static int ppc440speA_pciex_init_utl(struct ppc4xx_pciex_port *port)
  618. {
  619. /* XXX Check what that value means... I hate magic */
  620. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x68782800);
  621. /*
  622. * Set buffer allocations and then assert VRB and TXE.
  623. */
  624. out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
  625. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  626. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x10000000);
  627. out_be32(port->utl_base + PEUTL_PBBSZ, 0x53000000);
  628. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x08000000);
  629. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x10000000);
  630. out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
  631. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  632. return 0;
  633. }
  634. static int ppc440speB_pciex_init_utl(struct ppc4xx_pciex_port *port)
  635. {
  636. /* Report CRS to the operating system */
  637. out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
  638. return 0;
  639. }
  640. static struct ppc4xx_pciex_hwops ppc440speA_pcie_hwops __initdata =
  641. {
  642. .core_init = ppc440spe_pciex_core_init,
  643. .port_init_hw = ppc440speA_pciex_init_port_hw,
  644. .setup_utl = ppc440speA_pciex_init_utl,
  645. };
  646. static struct ppc4xx_pciex_hwops ppc440speB_pcie_hwops __initdata =
  647. {
  648. .core_init = ppc440spe_pciex_core_init,
  649. .port_init_hw = ppc440speB_pciex_init_port_hw,
  650. .setup_utl = ppc440speB_pciex_init_utl,
  651. };
  652. static int __init ppc460ex_pciex_core_init(struct device_node *np)
  653. {
  654. /* Nothing to do, return 2 ports */
  655. return 2;
  656. }
  657. static int ppc460ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  658. {
  659. u32 val;
  660. u32 utlset1;
  661. if (port->endpoint)
  662. val = PTYPE_LEGACY_ENDPOINT << 20;
  663. else
  664. val = PTYPE_ROOT_PORT << 20;
  665. if (port->index == 0) {
  666. val |= LNKW_X1 << 12;
  667. utlset1 = 0x20000000;
  668. } else {
  669. val |= LNKW_X4 << 12;
  670. utlset1 = 0x20101101;
  671. }
  672. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET, val);
  673. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, utlset1);
  674. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01210000);
  675. switch (port->index) {
  676. case 0:
  677. mtdcri(SDR0, PESDR0_460EX_L0CDRCTL, 0x00003230);
  678. mtdcri(SDR0, PESDR0_460EX_L0DRV, 0x00000136);
  679. mtdcri(SDR0, PESDR0_460EX_L0CLK, 0x00000006);
  680. mtdcri(SDR0, PESDR0_460EX_PHY_CTL_RST,0x10000000);
  681. break;
  682. case 1:
  683. mtdcri(SDR0, PESDR1_460EX_L0CDRCTL, 0x00003230);
  684. mtdcri(SDR0, PESDR1_460EX_L1CDRCTL, 0x00003230);
  685. mtdcri(SDR0, PESDR1_460EX_L2CDRCTL, 0x00003230);
  686. mtdcri(SDR0, PESDR1_460EX_L3CDRCTL, 0x00003230);
  687. mtdcri(SDR0, PESDR1_460EX_L0DRV, 0x00000136);
  688. mtdcri(SDR0, PESDR1_460EX_L1DRV, 0x00000136);
  689. mtdcri(SDR0, PESDR1_460EX_L2DRV, 0x00000136);
  690. mtdcri(SDR0, PESDR1_460EX_L3DRV, 0x00000136);
  691. mtdcri(SDR0, PESDR1_460EX_L0CLK, 0x00000006);
  692. mtdcri(SDR0, PESDR1_460EX_L1CLK, 0x00000006);
  693. mtdcri(SDR0, PESDR1_460EX_L2CLK, 0x00000006);
  694. mtdcri(SDR0, PESDR1_460EX_L3CLK, 0x00000006);
  695. mtdcri(SDR0, PESDR1_460EX_PHY_CTL_RST,0x10000000);
  696. break;
  697. }
  698. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  699. mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) |
  700. (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
  701. /* Poll for PHY reset */
  702. /* XXX FIXME add timeout */
  703. switch (port->index) {
  704. case 0:
  705. while (!(mfdcri(SDR0, PESDR0_460EX_RSTSTA) & 0x1))
  706. udelay(10);
  707. break;
  708. case 1:
  709. while (!(mfdcri(SDR0, PESDR1_460EX_RSTSTA) & 0x1))
  710. udelay(10);
  711. break;
  712. }
  713. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET,
  714. (mfdcri(SDR0, port->sdr_base + PESDRn_RCSSET) &
  715. ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
  716. PESDRx_RCSSET_RSTPYN);
  717. port->has_ibpre = 1;
  718. return 0;
  719. }
  720. static int ppc460ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
  721. {
  722. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
  723. /*
  724. * Set buffer allocations and then assert VRB and TXE.
  725. */
  726. out_be32(port->utl_base + PEUTL_PBCTL, 0x0800000c);
  727. out_be32(port->utl_base + PEUTL_OUTTR, 0x08000000);
  728. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  729. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
  730. out_be32(port->utl_base + PEUTL_PBBSZ, 0x00000000);
  731. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
  732. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
  733. out_be32(port->utl_base + PEUTL_RCIRQEN,0x00f00000);
  734. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  735. return 0;
  736. }
  737. static struct ppc4xx_pciex_hwops ppc460ex_pcie_hwops __initdata =
  738. {
  739. .core_init = ppc460ex_pciex_core_init,
  740. .port_init_hw = ppc460ex_pciex_init_port_hw,
  741. .setup_utl = ppc460ex_pciex_init_utl,
  742. };
  743. #endif /* CONFIG_44x */
  744. #ifdef CONFIG_40x
  745. static int __init ppc405ex_pciex_core_init(struct device_node *np)
  746. {
  747. /* Nothing to do, return 2 ports */
  748. return 2;
  749. }
  750. static void ppc405ex_pcie_phy_reset(struct ppc4xx_pciex_port *port)
  751. {
  752. /* Assert the PE0_PHY reset */
  753. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01010000);
  754. msleep(1);
  755. /* deassert the PE0_hotreset */
  756. if (port->endpoint)
  757. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01111000);
  758. else
  759. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x01101000);
  760. /* poll for phy !reset */
  761. /* XXX FIXME add timeout */
  762. while (!(mfdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSTA) & 0x00001000))
  763. ;
  764. /* deassert the PE0_gpl_utl_reset */
  765. mtdcri(SDR0, port->sdr_base + PESDRn_RCSSET, 0x00101000);
  766. }
  767. static int ppc405ex_pciex_init_port_hw(struct ppc4xx_pciex_port *port)
  768. {
  769. u32 val;
  770. if (port->endpoint)
  771. val = PTYPE_LEGACY_ENDPOINT;
  772. else
  773. val = PTYPE_ROOT_PORT;
  774. mtdcri(SDR0, port->sdr_base + PESDRn_DLPSET,
  775. 1 << 24 | val << 20 | LNKW_X1 << 12);
  776. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET1, 0x00000000);
  777. mtdcri(SDR0, port->sdr_base + PESDRn_UTLSET2, 0x01010000);
  778. mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET1, 0x720F0000);
  779. mtdcri(SDR0, port->sdr_base + PESDRn_405EX_PHYSET2, 0x70600003);
  780. /*
  781. * Only reset the PHY when no link is currently established.
  782. * This is for the Atheros PCIe board which has problems to establish
  783. * the link (again) after this PHY reset. All other currently tested
  784. * PCIe boards don't show this problem.
  785. * This has to be re-tested and fixed in a later release!
  786. */
  787. val = mfdcri(SDR0, port->sdr_base + PESDRn_LOOP);
  788. if (!(val & 0x00001000))
  789. ppc405ex_pcie_phy_reset(port);
  790. dcr_write(port->dcrs, DCRO_PEGPL_CFG, 0x10000000); /* guarded on */
  791. port->has_ibpre = 1;
  792. return 0;
  793. }
  794. static int ppc405ex_pciex_init_utl(struct ppc4xx_pciex_port *port)
  795. {
  796. dcr_write(port->dcrs, DCRO_PEGPL_SPECIAL, 0x0);
  797. /*
  798. * Set buffer allocations and then assert VRB and TXE.
  799. */
  800. out_be32(port->utl_base + PEUTL_OUTTR, 0x02000000);
  801. out_be32(port->utl_base + PEUTL_INTR, 0x02000000);
  802. out_be32(port->utl_base + PEUTL_OPDBSZ, 0x04000000);
  803. out_be32(port->utl_base + PEUTL_PBBSZ, 0x21000000);
  804. out_be32(port->utl_base + PEUTL_IPHBSZ, 0x02000000);
  805. out_be32(port->utl_base + PEUTL_IPDBSZ, 0x04000000);
  806. out_be32(port->utl_base + PEUTL_RCIRQEN, 0x00f00000);
  807. out_be32(port->utl_base + PEUTL_PCTL, 0x80800066);
  808. out_be32(port->utl_base + PEUTL_PBCTL, 0x08000000);
  809. return 0;
  810. }
  811. static struct ppc4xx_pciex_hwops ppc405ex_pcie_hwops __initdata =
  812. {
  813. .core_init = ppc405ex_pciex_core_init,
  814. .port_init_hw = ppc405ex_pciex_init_port_hw,
  815. .setup_utl = ppc405ex_pciex_init_utl,
  816. };
  817. #endif /* CONFIG_40x */
  818. /* Check that the core has been initied and if not, do it */
  819. static int __init ppc4xx_pciex_check_core_init(struct device_node *np)
  820. {
  821. static int core_init;
  822. int count = -ENODEV;
  823. if (core_init++)
  824. return 0;
  825. #ifdef CONFIG_44x
  826. if (of_device_is_compatible(np, "ibm,plb-pciex-440spe")) {
  827. if (ppc440spe_revA())
  828. ppc4xx_pciex_hwops = &ppc440speA_pcie_hwops;
  829. else
  830. ppc4xx_pciex_hwops = &ppc440speB_pcie_hwops;
  831. }
  832. if (of_device_is_compatible(np, "ibm,plb-pciex-460ex"))
  833. ppc4xx_pciex_hwops = &ppc460ex_pcie_hwops;
  834. #endif /* CONFIG_44x */
  835. #ifdef CONFIG_40x
  836. if (of_device_is_compatible(np, "ibm,plb-pciex-405ex"))
  837. ppc4xx_pciex_hwops = &ppc405ex_pcie_hwops;
  838. #endif
  839. if (ppc4xx_pciex_hwops == NULL) {
  840. printk(KERN_WARNING "PCIE: unknown host type %s\n",
  841. np->full_name);
  842. return -ENODEV;
  843. }
  844. count = ppc4xx_pciex_hwops->core_init(np);
  845. if (count > 0) {
  846. ppc4xx_pciex_ports =
  847. kzalloc(count * sizeof(struct ppc4xx_pciex_port),
  848. GFP_KERNEL);
  849. if (ppc4xx_pciex_ports) {
  850. ppc4xx_pciex_port_count = count;
  851. return 0;
  852. }
  853. printk(KERN_WARNING "PCIE: failed to allocate ports array\n");
  854. return -ENOMEM;
  855. }
  856. return -ENODEV;
  857. }
  858. static void __init ppc4xx_pciex_port_init_mapping(struct ppc4xx_pciex_port *port)
  859. {
  860. /* We map PCI Express configuration based on the reg property */
  861. dcr_write(port->dcrs, DCRO_PEGPL_CFGBAH,
  862. RES_TO_U32_HIGH(port->cfg_space.start));
  863. dcr_write(port->dcrs, DCRO_PEGPL_CFGBAL,
  864. RES_TO_U32_LOW(port->cfg_space.start));
  865. /* XXX FIXME: Use size from reg property. For now, map 512M */
  866. dcr_write(port->dcrs, DCRO_PEGPL_CFGMSK, 0xe0000001);
  867. /* We map UTL registers based on the reg property */
  868. dcr_write(port->dcrs, DCRO_PEGPL_REGBAH,
  869. RES_TO_U32_HIGH(port->utl_regs.start));
  870. dcr_write(port->dcrs, DCRO_PEGPL_REGBAL,
  871. RES_TO_U32_LOW(port->utl_regs.start));
  872. /* XXX FIXME: Use size from reg property */
  873. dcr_write(port->dcrs, DCRO_PEGPL_REGMSK, 0x00007001);
  874. /* Disable all other outbound windows */
  875. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, 0);
  876. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, 0);
  877. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0);
  878. dcr_write(port->dcrs, DCRO_PEGPL_MSGMSK, 0);
  879. }
  880. static int __init ppc4xx_pciex_wait_on_sdr(struct ppc4xx_pciex_port *port,
  881. unsigned int sdr_offset,
  882. unsigned int mask,
  883. unsigned int value,
  884. int timeout_ms)
  885. {
  886. u32 val;
  887. while(timeout_ms--) {
  888. val = mfdcri(SDR0, port->sdr_base + sdr_offset);
  889. if ((val & mask) == value) {
  890. pr_debug("PCIE%d: Wait on SDR %x success with tm %d (%08x)\n",
  891. port->index, sdr_offset, timeout_ms, val);
  892. return 0;
  893. }
  894. msleep(1);
  895. }
  896. return -1;
  897. }
  898. static int __init ppc4xx_pciex_port_init(struct ppc4xx_pciex_port *port)
  899. {
  900. int rc = 0;
  901. /* Init HW */
  902. if (ppc4xx_pciex_hwops->port_init_hw)
  903. rc = ppc4xx_pciex_hwops->port_init_hw(port);
  904. if (rc != 0)
  905. return rc;
  906. printk(KERN_INFO "PCIE%d: Checking link...\n",
  907. port->index);
  908. /* Wait for reset to complete */
  909. if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS, 1 << 20, 0, 10)) {
  910. printk(KERN_WARNING "PCIE%d: PGRST failed\n",
  911. port->index);
  912. return -1;
  913. }
  914. /* Check for card presence detect if supported, if not, just wait for
  915. * link unconditionally.
  916. *
  917. * note that we don't fail if there is no link, we just filter out
  918. * config space accesses. That way, it will be easier to implement
  919. * hotplug later on.
  920. */
  921. if (!port->has_ibpre ||
  922. !ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
  923. 1 << 28, 1 << 28, 100)) {
  924. printk(KERN_INFO
  925. "PCIE%d: Device detected, waiting for link...\n",
  926. port->index);
  927. if (ppc4xx_pciex_wait_on_sdr(port, PESDRn_LOOP,
  928. 0x1000, 0x1000, 2000))
  929. printk(KERN_WARNING
  930. "PCIE%d: Link up failed\n", port->index);
  931. else {
  932. printk(KERN_INFO
  933. "PCIE%d: link is up !\n", port->index);
  934. port->link = 1;
  935. }
  936. } else
  937. printk(KERN_INFO "PCIE%d: No device detected.\n", port->index);
  938. /*
  939. * Initialize mapping: disable all regions and configure
  940. * CFG and REG regions based on resources in the device tree
  941. */
  942. ppc4xx_pciex_port_init_mapping(port);
  943. /*
  944. * Map UTL
  945. */
  946. port->utl_base = ioremap(port->utl_regs.start, 0x100);
  947. BUG_ON(port->utl_base == NULL);
  948. /*
  949. * Setup UTL registers --BenH.
  950. */
  951. if (ppc4xx_pciex_hwops->setup_utl)
  952. ppc4xx_pciex_hwops->setup_utl(port);
  953. /*
  954. * Check for VC0 active and assert RDY.
  955. */
  956. if (port->link &&
  957. ppc4xx_pciex_wait_on_sdr(port, PESDRn_RCSSTS,
  958. 1 << 16, 1 << 16, 5000)) {
  959. printk(KERN_INFO "PCIE%d: VC0 not active\n", port->index);
  960. port->link = 0;
  961. }
  962. dcri_clrset(SDR0, port->sdr_base + PESDRn_RCSSET, 0, 1 << 20);
  963. msleep(100);
  964. return 0;
  965. }
  966. static int ppc4xx_pciex_validate_bdf(struct ppc4xx_pciex_port *port,
  967. struct pci_bus *bus,
  968. unsigned int devfn)
  969. {
  970. static int message;
  971. /* Endpoint can not generate upstream(remote) config cycles */
  972. if (port->endpoint && bus->number != port->hose->first_busno)
  973. return PCIBIOS_DEVICE_NOT_FOUND;
  974. /* Check we are within the mapped range */
  975. if (bus->number > port->hose->last_busno) {
  976. if (!message) {
  977. printk(KERN_WARNING "Warning! Probing bus %u"
  978. " out of range !\n", bus->number);
  979. message++;
  980. }
  981. return PCIBIOS_DEVICE_NOT_FOUND;
  982. }
  983. /* The root complex has only one device / function */
  984. if (bus->number == port->hose->first_busno && devfn != 0)
  985. return PCIBIOS_DEVICE_NOT_FOUND;
  986. /* The other side of the RC has only one device as well */
  987. if (bus->number == (port->hose->first_busno + 1) &&
  988. PCI_SLOT(devfn) != 0)
  989. return PCIBIOS_DEVICE_NOT_FOUND;
  990. /* Check if we have a link */
  991. if ((bus->number != port->hose->first_busno) && !port->link)
  992. return PCIBIOS_DEVICE_NOT_FOUND;
  993. return 0;
  994. }
  995. static void __iomem *ppc4xx_pciex_get_config_base(struct ppc4xx_pciex_port *port,
  996. struct pci_bus *bus,
  997. unsigned int devfn)
  998. {
  999. int relbus;
  1000. /* Remove the casts when we finally remove the stupid volatile
  1001. * in struct pci_controller
  1002. */
  1003. if (bus->number == port->hose->first_busno)
  1004. return (void __iomem *)port->hose->cfg_addr;
  1005. relbus = bus->number - (port->hose->first_busno + 1);
  1006. return (void __iomem *)port->hose->cfg_data +
  1007. ((relbus << 20) | (devfn << 12));
  1008. }
  1009. static int ppc4xx_pciex_read_config(struct pci_bus *bus, unsigned int devfn,
  1010. int offset, int len, u32 *val)
  1011. {
  1012. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  1013. struct ppc4xx_pciex_port *port =
  1014. &ppc4xx_pciex_ports[hose->indirect_type];
  1015. void __iomem *addr;
  1016. u32 gpl_cfg;
  1017. BUG_ON(hose != port->hose);
  1018. if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
  1019. return PCIBIOS_DEVICE_NOT_FOUND;
  1020. addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
  1021. /*
  1022. * Reading from configuration space of non-existing device can
  1023. * generate transaction errors. For the read duration we suppress
  1024. * assertion of machine check exceptions to avoid those.
  1025. */
  1026. gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
  1027. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
  1028. /* Make sure no CRS is recorded */
  1029. out_be32(port->utl_base + PEUTL_RCSTA, 0x00040000);
  1030. switch (len) {
  1031. case 1:
  1032. *val = in_8((u8 *)(addr + offset));
  1033. break;
  1034. case 2:
  1035. *val = in_le16((u16 *)(addr + offset));
  1036. break;
  1037. default:
  1038. *val = in_le32((u32 *)(addr + offset));
  1039. break;
  1040. }
  1041. pr_debug("pcie-config-read: bus=%3d [%3d..%3d] devfn=0x%04x"
  1042. " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
  1043. bus->number, hose->first_busno, hose->last_busno,
  1044. devfn, offset, len, addr + offset, *val);
  1045. /* Check for CRS (440SPe rev B does that for us but heh ..) */
  1046. if (in_be32(port->utl_base + PEUTL_RCSTA) & 0x00040000) {
  1047. pr_debug("Got CRS !\n");
  1048. if (len != 4 || offset != 0)
  1049. return PCIBIOS_DEVICE_NOT_FOUND;
  1050. *val = 0xffff0001;
  1051. }
  1052. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
  1053. return PCIBIOS_SUCCESSFUL;
  1054. }
  1055. static int ppc4xx_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
  1056. int offset, int len, u32 val)
  1057. {
  1058. struct pci_controller *hose = (struct pci_controller *) bus->sysdata;
  1059. struct ppc4xx_pciex_port *port =
  1060. &ppc4xx_pciex_ports[hose->indirect_type];
  1061. void __iomem *addr;
  1062. u32 gpl_cfg;
  1063. if (ppc4xx_pciex_validate_bdf(port, bus, devfn) != 0)
  1064. return PCIBIOS_DEVICE_NOT_FOUND;
  1065. addr = ppc4xx_pciex_get_config_base(port, bus, devfn);
  1066. /*
  1067. * Reading from configuration space of non-existing device can
  1068. * generate transaction errors. For the read duration we suppress
  1069. * assertion of machine check exceptions to avoid those.
  1070. */
  1071. gpl_cfg = dcr_read(port->dcrs, DCRO_PEGPL_CFG);
  1072. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg | GPL_DMER_MASK_DISA);
  1073. pr_debug("pcie-config-write: bus=%3d [%3d..%3d] devfn=0x%04x"
  1074. " offset=0x%04x len=%d, addr=0x%p val=0x%08x\n",
  1075. bus->number, hose->first_busno, hose->last_busno,
  1076. devfn, offset, len, addr + offset, val);
  1077. switch (len) {
  1078. case 1:
  1079. out_8((u8 *)(addr + offset), val);
  1080. break;
  1081. case 2:
  1082. out_le16((u16 *)(addr + offset), val);
  1083. break;
  1084. default:
  1085. out_le32((u32 *)(addr + offset), val);
  1086. break;
  1087. }
  1088. dcr_write(port->dcrs, DCRO_PEGPL_CFG, gpl_cfg);
  1089. return PCIBIOS_SUCCESSFUL;
  1090. }
  1091. static struct pci_ops ppc4xx_pciex_pci_ops =
  1092. {
  1093. .read = ppc4xx_pciex_read_config,
  1094. .write = ppc4xx_pciex_write_config,
  1095. };
  1096. static void __init ppc4xx_configure_pciex_POMs(struct ppc4xx_pciex_port *port,
  1097. struct pci_controller *hose,
  1098. void __iomem *mbase)
  1099. {
  1100. u32 lah, lal, pciah, pcial, sa;
  1101. int i, j;
  1102. /* Setup outbound memory windows */
  1103. for (i = j = 0; i < 3; i++) {
  1104. struct resource *res = &hose->mem_resources[i];
  1105. /* we only care about memory windows */
  1106. if (!(res->flags & IORESOURCE_MEM))
  1107. continue;
  1108. if (j > 1) {
  1109. printk(KERN_WARNING "%s: Too many ranges\n",
  1110. port->node->full_name);
  1111. break;
  1112. }
  1113. /* Calculate register values */
  1114. lah = RES_TO_U32_HIGH(res->start);
  1115. lal = RES_TO_U32_LOW(res->start);
  1116. pciah = RES_TO_U32_HIGH(res->start - hose->pci_mem_offset);
  1117. pcial = RES_TO_U32_LOW(res->start - hose->pci_mem_offset);
  1118. sa = res->end + 1 - res->start;
  1119. if (!is_power_of_2(sa) || sa < 0x100000 ||
  1120. sa > 0xffffffffu) {
  1121. printk(KERN_WARNING "%s: Resource out of range\n",
  1122. port->node->full_name);
  1123. continue;
  1124. }
  1125. sa = (0xffffffffu << ilog2(sa)) | 0x1;
  1126. /* Program register values */
  1127. switch (j) {
  1128. case 0:
  1129. out_le32(mbase + PECFG_POM0LAH, pciah);
  1130. out_le32(mbase + PECFG_POM0LAL, pcial);
  1131. dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAH, lah);
  1132. dcr_write(port->dcrs, DCRO_PEGPL_OMR1BAL, lal);
  1133. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKH, 0x7fffffff);
  1134. dcr_write(port->dcrs, DCRO_PEGPL_OMR1MSKL, sa | 3);
  1135. break;
  1136. case 1:
  1137. out_le32(mbase + PECFG_POM1LAH, pciah);
  1138. out_le32(mbase + PECFG_POM1LAL, pcial);
  1139. dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAH, lah);
  1140. dcr_write(port->dcrs, DCRO_PEGPL_OMR2BAL, lal);
  1141. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKH, 0x7fffffff);
  1142. dcr_write(port->dcrs, DCRO_PEGPL_OMR2MSKL, sa | 3);
  1143. break;
  1144. }
  1145. j++;
  1146. }
  1147. /* Configure IO, always 64K starting at 0 */
  1148. if (hose->io_resource.flags & IORESOURCE_IO) {
  1149. lah = RES_TO_U32_HIGH(hose->io_base_phys);
  1150. lal = RES_TO_U32_LOW(hose->io_base_phys);
  1151. out_le32(mbase + PECFG_POM2LAH, 0);
  1152. out_le32(mbase + PECFG_POM2LAL, 0);
  1153. dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAH, lah);
  1154. dcr_write(port->dcrs, DCRO_PEGPL_OMR3BAL, lal);
  1155. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKH, 0x7fffffff);
  1156. dcr_write(port->dcrs, DCRO_PEGPL_OMR3MSKL, 0xffff0000 | 3);
  1157. }
  1158. }
  1159. static void __init ppc4xx_configure_pciex_PIMs(struct ppc4xx_pciex_port *port,
  1160. struct pci_controller *hose,
  1161. void __iomem *mbase,
  1162. struct resource *res)
  1163. {
  1164. resource_size_t size = res->end - res->start + 1;
  1165. u64 sa;
  1166. if (port->endpoint) {
  1167. resource_size_t ep_addr = 0;
  1168. resource_size_t ep_size = 32 << 20;
  1169. /* Currently we map a fixed 64MByte window to PLB address
  1170. * 0 (SDRAM). This should probably be configurable via a dts
  1171. * property.
  1172. */
  1173. /* Calculate window size */
  1174. sa = (0xffffffffffffffffull << ilog2(ep_size));;
  1175. /* Setup BAR0 */
  1176. out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
  1177. out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa) |
  1178. PCI_BASE_ADDRESS_MEM_TYPE_64);
  1179. /* Disable BAR1 & BAR2 */
  1180. out_le32(mbase + PECFG_BAR1MPA, 0);
  1181. out_le32(mbase + PECFG_BAR2HMPA, 0);
  1182. out_le32(mbase + PECFG_BAR2LMPA, 0);
  1183. out_le32(mbase + PECFG_PIM01SAH, RES_TO_U32_HIGH(sa));
  1184. out_le32(mbase + PECFG_PIM01SAL, RES_TO_U32_LOW(sa));
  1185. out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(ep_addr));
  1186. out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(ep_addr));
  1187. } else {
  1188. /* Calculate window size */
  1189. sa = (0xffffffffffffffffull << ilog2(size));;
  1190. if (res->flags & IORESOURCE_PREFETCH)
  1191. sa |= 0x8;
  1192. out_le32(mbase + PECFG_BAR0HMPA, RES_TO_U32_HIGH(sa));
  1193. out_le32(mbase + PECFG_BAR0LMPA, RES_TO_U32_LOW(sa));
  1194. /* The setup of the split looks weird to me ... let's see
  1195. * if it works
  1196. */
  1197. out_le32(mbase + PECFG_PIM0LAL, 0x00000000);
  1198. out_le32(mbase + PECFG_PIM0LAH, 0x00000000);
  1199. out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
  1200. out_le32(mbase + PECFG_PIM1LAH, 0x00000000);
  1201. out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
  1202. out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
  1203. out_le32(mbase + PCI_BASE_ADDRESS_0, RES_TO_U32_LOW(res->start));
  1204. out_le32(mbase + PCI_BASE_ADDRESS_1, RES_TO_U32_HIGH(res->start));
  1205. }
  1206. /* Enable inbound mapping */
  1207. out_le32(mbase + PECFG_PIMEN, 0x1);
  1208. /* Enable I/O, Mem, and Busmaster cycles */
  1209. out_le16(mbase + PCI_COMMAND,
  1210. in_le16(mbase + PCI_COMMAND) |
  1211. PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  1212. }
  1213. static void __init ppc4xx_pciex_port_setup_hose(struct ppc4xx_pciex_port *port)
  1214. {
  1215. struct resource dma_window;
  1216. struct pci_controller *hose = NULL;
  1217. const int *bus_range;
  1218. int primary = 0, busses;
  1219. void __iomem *mbase = NULL, *cfg_data = NULL;
  1220. const u32 *pval;
  1221. u32 val;
  1222. /* Check if primary bridge */
  1223. if (of_get_property(port->node, "primary", NULL))
  1224. primary = 1;
  1225. /* Get bus range if any */
  1226. bus_range = of_get_property(port->node, "bus-range", NULL);
  1227. /* Allocate the host controller data structure */
  1228. hose = pcibios_alloc_controller(port->node);
  1229. if (!hose)
  1230. goto fail;
  1231. /* We stick the port number in "indirect_type" so the config space
  1232. * ops can retrieve the port data structure easily
  1233. */
  1234. hose->indirect_type = port->index;
  1235. /* Get bus range */
  1236. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  1237. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  1238. /* Because of how big mapping the config space is (1M per bus), we
  1239. * limit how many busses we support. In the long run, we could replace
  1240. * that with something akin to kmap_atomic instead. We set aside 1 bus
  1241. * for the host itself too.
  1242. */
  1243. busses = hose->last_busno - hose->first_busno; /* This is off by 1 */
  1244. if (busses > MAX_PCIE_BUS_MAPPED) {
  1245. busses = MAX_PCIE_BUS_MAPPED;
  1246. hose->last_busno = hose->first_busno + busses;
  1247. }
  1248. if (!port->endpoint) {
  1249. /* Only map the external config space in cfg_data for
  1250. * PCIe root-complexes. External space is 1M per bus
  1251. */
  1252. cfg_data = ioremap(port->cfg_space.start +
  1253. (hose->first_busno + 1) * 0x100000,
  1254. busses * 0x100000);
  1255. if (cfg_data == NULL) {
  1256. printk(KERN_ERR "%s: Can't map external config space !",
  1257. port->node->full_name);
  1258. goto fail;
  1259. }
  1260. hose->cfg_data = cfg_data;
  1261. }
  1262. /* Always map the host config space in cfg_addr.
  1263. * Internal space is 4K
  1264. */
  1265. mbase = ioremap(port->cfg_space.start + 0x10000000, 0x1000);
  1266. if (mbase == NULL) {
  1267. printk(KERN_ERR "%s: Can't map internal config space !",
  1268. port->node->full_name);
  1269. goto fail;
  1270. }
  1271. hose->cfg_addr = mbase;
  1272. pr_debug("PCIE %s, bus %d..%d\n", port->node->full_name,
  1273. hose->first_busno, hose->last_busno);
  1274. pr_debug(" config space mapped at: root @0x%p, other @0x%p\n",
  1275. hose->cfg_addr, hose->cfg_data);
  1276. /* Setup config space */
  1277. hose->ops = &ppc4xx_pciex_pci_ops;
  1278. port->hose = hose;
  1279. mbase = (void __iomem *)hose->cfg_addr;
  1280. if (!port->endpoint) {
  1281. /*
  1282. * Set bus numbers on our root port
  1283. */
  1284. out_8(mbase + PCI_PRIMARY_BUS, hose->first_busno);
  1285. out_8(mbase + PCI_SECONDARY_BUS, hose->first_busno + 1);
  1286. out_8(mbase + PCI_SUBORDINATE_BUS, hose->last_busno);
  1287. }
  1288. /*
  1289. * OMRs are already reset, also disable PIMs
  1290. */
  1291. out_le32(mbase + PECFG_PIMEN, 0);
  1292. /* Parse outbound mapping resources */
  1293. pci_process_bridge_OF_ranges(hose, port->node, primary);
  1294. /* Parse inbound mapping resources */
  1295. if (ppc4xx_parse_dma_ranges(hose, mbase, &dma_window) != 0)
  1296. goto fail;
  1297. /* Configure outbound ranges POMs */
  1298. ppc4xx_configure_pciex_POMs(port, hose, mbase);
  1299. /* Configure inbound ranges PIMs */
  1300. ppc4xx_configure_pciex_PIMs(port, hose, mbase, &dma_window);
  1301. /* The root complex doesn't show up if we don't set some vendor
  1302. * and device IDs into it. The defaults below are the same bogus
  1303. * one that the initial code in arch/ppc had. This can be
  1304. * overwritten by setting the "vendor-id/device-id" properties
  1305. * in the pciex node.
  1306. */
  1307. /* Get the (optional) vendor-/device-id from the device-tree */
  1308. pval = of_get_property(port->node, "vendor-id", NULL);
  1309. if (pval) {
  1310. val = *pval;
  1311. } else {
  1312. if (!port->endpoint)
  1313. val = 0xaaa0 + port->index;
  1314. else
  1315. val = 0xeee0 + port->index;
  1316. }
  1317. out_le16(mbase + 0x200, val);
  1318. pval = of_get_property(port->node, "device-id", NULL);
  1319. if (pval) {
  1320. val = *pval;
  1321. } else {
  1322. if (!port->endpoint)
  1323. val = 0xbed0 + port->index;
  1324. else
  1325. val = 0xfed0 + port->index;
  1326. }
  1327. out_le16(mbase + 0x202, val);
  1328. if (!port->endpoint) {
  1329. /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
  1330. out_le32(mbase + 0x208, 0x06040001);
  1331. printk(KERN_INFO "PCIE%d: successfully set as root-complex\n",
  1332. port->index);
  1333. } else {
  1334. /* Set Class Code to Processor/PPC */
  1335. out_le32(mbase + 0x208, 0x0b200001);
  1336. printk(KERN_INFO "PCIE%d: successfully set as endpoint\n",
  1337. port->index);
  1338. }
  1339. return;
  1340. fail:
  1341. if (hose)
  1342. pcibios_free_controller(hose);
  1343. if (cfg_data)
  1344. iounmap(cfg_data);
  1345. if (mbase)
  1346. iounmap(mbase);
  1347. }
  1348. static void __init ppc4xx_probe_pciex_bridge(struct device_node *np)
  1349. {
  1350. struct ppc4xx_pciex_port *port;
  1351. const u32 *pval;
  1352. int portno;
  1353. unsigned int dcrs;
  1354. const char *val;
  1355. /* First, proceed to core initialization as we assume there's
  1356. * only one PCIe core in the system
  1357. */
  1358. if (ppc4xx_pciex_check_core_init(np))
  1359. return;
  1360. /* Get the port number from the device-tree */
  1361. pval = of_get_property(np, "port", NULL);
  1362. if (pval == NULL) {
  1363. printk(KERN_ERR "PCIE: Can't find port number for %s\n",
  1364. np->full_name);
  1365. return;
  1366. }
  1367. portno = *pval;
  1368. if (portno >= ppc4xx_pciex_port_count) {
  1369. printk(KERN_ERR "PCIE: port number out of range for %s\n",
  1370. np->full_name);
  1371. return;
  1372. }
  1373. port = &ppc4xx_pciex_ports[portno];
  1374. port->index = portno;
  1375. port->node = of_node_get(np);
  1376. pval = of_get_property(np, "sdr-base", NULL);
  1377. if (pval == NULL) {
  1378. printk(KERN_ERR "PCIE: missing sdr-base for %s\n",
  1379. np->full_name);
  1380. return;
  1381. }
  1382. port->sdr_base = *pval;
  1383. /* Check if device_type property is set to "pci" or "pci-endpoint".
  1384. * Resulting from this setup this PCIe port will be configured
  1385. * as root-complex or as endpoint.
  1386. */
  1387. val = of_get_property(port->node, "device_type", NULL);
  1388. if (!strcmp(val, "pci-endpoint")) {
  1389. port->endpoint = 1;
  1390. } else if (!strcmp(val, "pci")) {
  1391. port->endpoint = 0;
  1392. } else {
  1393. printk(KERN_ERR "PCIE: missing or incorrect device_type for %s\n",
  1394. np->full_name);
  1395. return;
  1396. }
  1397. /* Fetch config space registers address */
  1398. if (of_address_to_resource(np, 0, &port->cfg_space)) {
  1399. printk(KERN_ERR "%s: Can't get PCI-E config space !",
  1400. np->full_name);
  1401. return;
  1402. }
  1403. /* Fetch host bridge internal registers address */
  1404. if (of_address_to_resource(np, 1, &port->utl_regs)) {
  1405. printk(KERN_ERR "%s: Can't get UTL register base !",
  1406. np->full_name);
  1407. return;
  1408. }
  1409. /* Map DCRs */
  1410. dcrs = dcr_resource_start(np, 0);
  1411. if (dcrs == 0) {
  1412. printk(KERN_ERR "%s: Can't get DCR register base !",
  1413. np->full_name);
  1414. return;
  1415. }
  1416. port->dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0));
  1417. /* Initialize the port specific registers */
  1418. if (ppc4xx_pciex_port_init(port)) {
  1419. printk(KERN_WARNING "PCIE%d: Port init failed\n", port->index);
  1420. return;
  1421. }
  1422. /* Setup the linux hose data structure */
  1423. ppc4xx_pciex_port_setup_hose(port);
  1424. }
  1425. #endif /* CONFIG_PPC4xx_PCI_EXPRESS */
  1426. static int __init ppc4xx_pci_find_bridges(void)
  1427. {
  1428. struct device_node *np;
  1429. #ifdef CONFIG_PPC4xx_PCI_EXPRESS
  1430. for_each_compatible_node(np, NULL, "ibm,plb-pciex")
  1431. ppc4xx_probe_pciex_bridge(np);
  1432. #endif
  1433. for_each_compatible_node(np, NULL, "ibm,plb-pcix")
  1434. ppc4xx_probe_pcix_bridge(np);
  1435. for_each_compatible_node(np, NULL, "ibm,plb-pci")
  1436. ppc4xx_probe_pci_bridge(np);
  1437. return 0;
  1438. }
  1439. arch_initcall(ppc4xx_pci_find_bridges);