ppc4xx_pci.c 46 KB

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