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