ppc4xx_pci.c 46 KB

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