ppc4xx_pci.c 60 KB

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