ppc4xx_pci.c 60 KB

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