fsl_pci.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * MPC83xx/85xx/86xx PCI/PCIE support routing.
  3. *
  4. * Copyright 2007-2012 Freescale Semiconductor, Inc.
  5. * Copyright 2008-2009 MontaVista Software, Inc.
  6. *
  7. * Initial author: Xianghua Xiao <x.xiao@freescale.com>
  8. * Recode: ZHANG WEI <wei.zhang@freescale.com>
  9. * Rewrite the routing for Frescale PCI and PCI Express
  10. * Roy Zang <tie-fei.zang@freescale.com>
  11. * MPC83xx PCI-Express support:
  12. * Tony Li <tony.li@freescale.com>
  13. * Anton Vorontsov <avorontsov@ru.mvista.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/pci.h>
  22. #include <linux/delay.h>
  23. #include <linux/string.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/bootmem.h>
  27. #include <linux/memblock.h>
  28. #include <linux/log2.h>
  29. #include <linux/slab.h>
  30. #include <linux/suspend.h>
  31. #include <linux/syscore_ops.h>
  32. #include <linux/uaccess.h>
  33. #include <asm/io.h>
  34. #include <asm/prom.h>
  35. #include <asm/pci-bridge.h>
  36. #include <asm/ppc-pci.h>
  37. #include <asm/machdep.h>
  38. #include <asm/disassemble.h>
  39. #include <asm/ppc-opcode.h>
  40. #include <sysdev/fsl_soc.h>
  41. #include <sysdev/fsl_pci.h>
  42. static int fsl_pcie_bus_fixup, is_mpc83xx_pci;
  43. static void quirk_fsl_pcie_early(struct pci_dev *dev)
  44. {
  45. u8 hdr_type;
  46. /* if we aren't a PCIe don't bother */
  47. if (!pci_is_pcie(dev))
  48. return;
  49. /* if we aren't in host mode don't bother */
  50. pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type);
  51. if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE)
  52. return;
  53. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  54. fsl_pcie_bus_fixup = 1;
  55. return;
  56. }
  57. static int fsl_indirect_read_config(struct pci_bus *, unsigned int,
  58. int, int, u32 *);
  59. static int fsl_pcie_check_link(struct pci_controller *hose)
  60. {
  61. u32 val = 0;
  62. if (hose->indirect_type & PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK) {
  63. if (hose->ops->read == fsl_indirect_read_config) {
  64. struct pci_bus bus;
  65. bus.number = hose->first_busno;
  66. bus.sysdata = hose;
  67. bus.ops = hose->ops;
  68. indirect_read_config(&bus, 0, PCIE_LTSSM, 4, &val);
  69. } else
  70. early_read_config_dword(hose, 0, 0, PCIE_LTSSM, &val);
  71. if (val < PCIE_LTSSM_L0)
  72. return 1;
  73. } else {
  74. struct ccsr_pci __iomem *pci = hose->private_data;
  75. /* for PCIe IP rev 3.0 or greater use CSR0 for link state */
  76. val = (in_be32(&pci->pex_csr0) & PEX_CSR0_LTSSM_MASK)
  77. >> PEX_CSR0_LTSSM_SHIFT;
  78. if (val != PEX_CSR0_LTSSM_L0)
  79. return 1;
  80. }
  81. return 0;
  82. }
  83. static int fsl_indirect_read_config(struct pci_bus *bus, unsigned int devfn,
  84. int offset, int len, u32 *val)
  85. {
  86. struct pci_controller *hose = pci_bus_to_host(bus);
  87. if (fsl_pcie_check_link(hose))
  88. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  89. else
  90. hose->indirect_type &= ~PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  91. return indirect_read_config(bus, devfn, offset, len, val);
  92. }
  93. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  94. static struct pci_ops fsl_indirect_pcie_ops =
  95. {
  96. .read = fsl_indirect_read_config,
  97. .write = indirect_write_config,
  98. };
  99. #define MAX_PHYS_ADDR_BITS 40
  100. static u64 pci64_dma_offset = 1ull << MAX_PHYS_ADDR_BITS;
  101. static int fsl_pci_dma_set_mask(struct device *dev, u64 dma_mask)
  102. {
  103. if (!dev->dma_mask || !dma_supported(dev, dma_mask))
  104. return -EIO;
  105. /*
  106. * Fixup PCI devices that are able to DMA to above the physical
  107. * address width of the SoC such that we can address any internal
  108. * SoC address from across PCI if needed
  109. */
  110. if ((dev_is_pci(dev)) &&
  111. dma_mask >= DMA_BIT_MASK(MAX_PHYS_ADDR_BITS)) {
  112. set_dma_ops(dev, &dma_direct_ops);
  113. set_dma_offset(dev, pci64_dma_offset);
  114. }
  115. *dev->dma_mask = dma_mask;
  116. return 0;
  117. }
  118. static int setup_one_atmu(struct ccsr_pci __iomem *pci,
  119. unsigned int index, const struct resource *res,
  120. resource_size_t offset)
  121. {
  122. resource_size_t pci_addr = res->start - offset;
  123. resource_size_t phys_addr = res->start;
  124. resource_size_t size = resource_size(res);
  125. u32 flags = 0x80044000; /* enable & mem R/W */
  126. unsigned int i;
  127. pr_debug("PCI MEM resource start 0x%016llx, size 0x%016llx.\n",
  128. (u64)res->start, (u64)size);
  129. if (res->flags & IORESOURCE_PREFETCH)
  130. flags |= 0x10000000; /* enable relaxed ordering */
  131. for (i = 0; size > 0; i++) {
  132. unsigned int bits = min(ilog2(size),
  133. __ffs(pci_addr | phys_addr));
  134. if (index + i >= 5)
  135. return -1;
  136. out_be32(&pci->pow[index + i].potar, pci_addr >> 12);
  137. out_be32(&pci->pow[index + i].potear, (u64)pci_addr >> 44);
  138. out_be32(&pci->pow[index + i].powbar, phys_addr >> 12);
  139. out_be32(&pci->pow[index + i].powar, flags | (bits - 1));
  140. pci_addr += (resource_size_t)1U << bits;
  141. phys_addr += (resource_size_t)1U << bits;
  142. size -= (resource_size_t)1U << bits;
  143. }
  144. return i;
  145. }
  146. /* atmu setup for fsl pci/pcie controller */
  147. static void setup_pci_atmu(struct pci_controller *hose)
  148. {
  149. struct ccsr_pci __iomem *pci = hose->private_data;
  150. int i, j, n, mem_log, win_idx = 3, start_idx = 1, end_idx = 4;
  151. u64 mem, sz, paddr_hi = 0;
  152. u64 offset = 0, paddr_lo = ULLONG_MAX;
  153. u32 pcicsrbar = 0, pcicsrbar_sz;
  154. u32 piwar = PIWAR_EN | PIWAR_PF | PIWAR_TGI_LOCAL |
  155. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP;
  156. const char *name = hose->dn->full_name;
  157. const u64 *reg;
  158. int len;
  159. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  160. if (in_be32(&pci->block_rev1) >= PCIE_IP_REV_2_2) {
  161. win_idx = 2;
  162. start_idx = 0;
  163. end_idx = 3;
  164. }
  165. }
  166. /* Disable all windows (except powar0 since it's ignored) */
  167. for(i = 1; i < 5; i++)
  168. out_be32(&pci->pow[i].powar, 0);
  169. for (i = start_idx; i < end_idx; i++)
  170. out_be32(&pci->piw[i].piwar, 0);
  171. /* Setup outbound MEM window */
  172. for(i = 0, j = 1; i < 3; i++) {
  173. if (!(hose->mem_resources[i].flags & IORESOURCE_MEM))
  174. continue;
  175. paddr_lo = min(paddr_lo, (u64)hose->mem_resources[i].start);
  176. paddr_hi = max(paddr_hi, (u64)hose->mem_resources[i].end);
  177. /* We assume all memory resources have the same offset */
  178. offset = hose->mem_offset[i];
  179. n = setup_one_atmu(pci, j, &hose->mem_resources[i], offset);
  180. if (n < 0 || j >= 5) {
  181. pr_err("Ran out of outbound PCI ATMUs for resource %d!\n", i);
  182. hose->mem_resources[i].flags |= IORESOURCE_DISABLED;
  183. } else
  184. j += n;
  185. }
  186. /* Setup outbound IO window */
  187. if (hose->io_resource.flags & IORESOURCE_IO) {
  188. if (j >= 5) {
  189. pr_err("Ran out of outbound PCI ATMUs for IO resource\n");
  190. } else {
  191. pr_debug("PCI IO resource start 0x%016llx, size 0x%016llx, "
  192. "phy base 0x%016llx.\n",
  193. (u64)hose->io_resource.start,
  194. (u64)resource_size(&hose->io_resource),
  195. (u64)hose->io_base_phys);
  196. out_be32(&pci->pow[j].potar, (hose->io_resource.start >> 12));
  197. out_be32(&pci->pow[j].potear, 0);
  198. out_be32(&pci->pow[j].powbar, (hose->io_base_phys >> 12));
  199. /* Enable, IO R/W */
  200. out_be32(&pci->pow[j].powar, 0x80088000
  201. | (ilog2(hose->io_resource.end
  202. - hose->io_resource.start + 1) - 1));
  203. }
  204. }
  205. /* convert to pci address space */
  206. paddr_hi -= offset;
  207. paddr_lo -= offset;
  208. if (paddr_hi == paddr_lo) {
  209. pr_err("%s: No outbound window space\n", name);
  210. return;
  211. }
  212. if (paddr_lo == 0) {
  213. pr_err("%s: No space for inbound window\n", name);
  214. return;
  215. }
  216. /* setup PCSRBAR/PEXCSRBAR */
  217. early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, 0xffffffff);
  218. early_read_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, &pcicsrbar_sz);
  219. pcicsrbar_sz = ~pcicsrbar_sz + 1;
  220. if (paddr_hi < (0x100000000ull - pcicsrbar_sz) ||
  221. (paddr_lo > 0x100000000ull))
  222. pcicsrbar = 0x100000000ull - pcicsrbar_sz;
  223. else
  224. pcicsrbar = (paddr_lo - pcicsrbar_sz) & -pcicsrbar_sz;
  225. early_write_config_dword(hose, 0, 0, PCI_BASE_ADDRESS_0, pcicsrbar);
  226. paddr_lo = min(paddr_lo, (u64)pcicsrbar);
  227. pr_info("%s: PCICSRBAR @ 0x%x\n", name, pcicsrbar);
  228. /* Setup inbound mem window */
  229. mem = memblock_end_of_DRAM();
  230. /*
  231. * The msi-address-64 property, if it exists, indicates the physical
  232. * address of the MSIIR register. Normally, this register is located
  233. * inside CCSR, so the ATMU that covers all of CCSR is used. But if
  234. * this property exists, then we normally need to create a new ATMU
  235. * for it. For now, however, we cheat. The only entity that creates
  236. * this property is the Freescale hypervisor, and the address is
  237. * specified in the partition configuration. Typically, the address
  238. * is located in the page immediately after the end of DDR. If so, we
  239. * can avoid allocating a new ATMU by extending the DDR ATMU by one
  240. * page.
  241. */
  242. reg = of_get_property(hose->dn, "msi-address-64", &len);
  243. if (reg && (len == sizeof(u64))) {
  244. u64 address = be64_to_cpup(reg);
  245. if ((address >= mem) && (address < (mem + PAGE_SIZE))) {
  246. pr_info("%s: extending DDR ATMU to cover MSIIR", name);
  247. mem += PAGE_SIZE;
  248. } else {
  249. /* TODO: Create a new ATMU for MSIIR */
  250. pr_warn("%s: msi-address-64 address of %llx is "
  251. "unsupported\n", name, address);
  252. }
  253. }
  254. sz = min(mem, paddr_lo);
  255. mem_log = ilog2(sz);
  256. /* PCIe can overmap inbound & outbound since RX & TX are separated */
  257. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  258. /* Size window to exact size if power-of-two or one size up */
  259. if ((1ull << mem_log) != mem) {
  260. mem_log++;
  261. if ((1ull << mem_log) > mem)
  262. pr_info("%s: Setting PCI inbound window "
  263. "greater than memory size\n", name);
  264. }
  265. piwar |= ((mem_log - 1) & PIWAR_SZ_MASK);
  266. /* Setup inbound memory window */
  267. out_be32(&pci->piw[win_idx].pitar, 0x00000000);
  268. out_be32(&pci->piw[win_idx].piwbar, 0x00000000);
  269. out_be32(&pci->piw[win_idx].piwar, piwar);
  270. win_idx--;
  271. hose->dma_window_base_cur = 0x00000000;
  272. hose->dma_window_size = (resource_size_t)sz;
  273. /*
  274. * if we have >4G of memory setup second PCI inbound window to
  275. * let devices that are 64-bit address capable to work w/o
  276. * SWIOTLB and access the full range of memory
  277. */
  278. if (sz != mem) {
  279. mem_log = ilog2(mem);
  280. /* Size window up if we dont fit in exact power-of-2 */
  281. if ((1ull << mem_log) != mem)
  282. mem_log++;
  283. piwar = (piwar & ~PIWAR_SZ_MASK) | (mem_log - 1);
  284. /* Setup inbound memory window */
  285. out_be32(&pci->piw[win_idx].pitar, 0x00000000);
  286. out_be32(&pci->piw[win_idx].piwbear,
  287. pci64_dma_offset >> 44);
  288. out_be32(&pci->piw[win_idx].piwbar,
  289. pci64_dma_offset >> 12);
  290. out_be32(&pci->piw[win_idx].piwar, piwar);
  291. /*
  292. * install our own dma_set_mask handler to fixup dma_ops
  293. * and dma_offset
  294. */
  295. ppc_md.dma_set_mask = fsl_pci_dma_set_mask;
  296. pr_info("%s: Setup 64-bit PCI DMA window\n", name);
  297. }
  298. } else {
  299. u64 paddr = 0;
  300. /* Setup inbound memory window */
  301. out_be32(&pci->piw[win_idx].pitar, paddr >> 12);
  302. out_be32(&pci->piw[win_idx].piwbar, paddr >> 12);
  303. out_be32(&pci->piw[win_idx].piwar, (piwar | (mem_log - 1)));
  304. win_idx--;
  305. paddr += 1ull << mem_log;
  306. sz -= 1ull << mem_log;
  307. if (sz) {
  308. mem_log = ilog2(sz);
  309. piwar |= (mem_log - 1);
  310. out_be32(&pci->piw[win_idx].pitar, paddr >> 12);
  311. out_be32(&pci->piw[win_idx].piwbar, paddr >> 12);
  312. out_be32(&pci->piw[win_idx].piwar, piwar);
  313. win_idx--;
  314. paddr += 1ull << mem_log;
  315. }
  316. hose->dma_window_base_cur = 0x00000000;
  317. hose->dma_window_size = (resource_size_t)paddr;
  318. }
  319. if (hose->dma_window_size < mem) {
  320. #ifdef CONFIG_SWIOTLB
  321. ppc_swiotlb_enable = 1;
  322. #else
  323. pr_err("%s: ERROR: Memory size exceeds PCI ATMU ability to "
  324. "map - enable CONFIG_SWIOTLB to avoid dma errors.\n",
  325. name);
  326. #endif
  327. /* adjusting outbound windows could reclaim space in mem map */
  328. if (paddr_hi < 0xffffffffull)
  329. pr_warning("%s: WARNING: Outbound window cfg leaves "
  330. "gaps in memory map. Adjusting the memory map "
  331. "could reduce unnecessary bounce buffering.\n",
  332. name);
  333. pr_info("%s: DMA window size is 0x%llx\n", name,
  334. (u64)hose->dma_window_size);
  335. }
  336. }
  337. static void __init setup_pci_cmd(struct pci_controller *hose)
  338. {
  339. u16 cmd;
  340. int cap_x;
  341. early_read_config_word(hose, 0, 0, PCI_COMMAND, &cmd);
  342. cmd |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  343. | PCI_COMMAND_IO;
  344. early_write_config_word(hose, 0, 0, PCI_COMMAND, cmd);
  345. cap_x = early_find_capability(hose, 0, 0, PCI_CAP_ID_PCIX);
  346. if (cap_x) {
  347. int pci_x_cmd = cap_x + PCI_X_CMD;
  348. cmd = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  349. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  350. early_write_config_word(hose, 0, 0, pci_x_cmd, cmd);
  351. } else {
  352. early_write_config_byte(hose, 0, 0, PCI_LATENCY_TIMER, 0x80);
  353. }
  354. }
  355. void fsl_pcibios_fixup_bus(struct pci_bus *bus)
  356. {
  357. struct pci_controller *hose = pci_bus_to_host(bus);
  358. int i, is_pcie = 0, no_link;
  359. /* The root complex bridge comes up with bogus resources,
  360. * we copy the PHB ones in.
  361. *
  362. * With the current generic PCI code, the PHB bus no longer
  363. * has bus->resource[0..4] set, so things are a bit more
  364. * tricky.
  365. */
  366. if (fsl_pcie_bus_fixup)
  367. is_pcie = early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP);
  368. no_link = !!(hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK);
  369. if (bus->parent == hose->bus && (is_pcie || no_link)) {
  370. for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; ++i) {
  371. struct resource *res = bus->resource[i];
  372. struct resource *par;
  373. if (!res)
  374. continue;
  375. if (i == 0)
  376. par = &hose->io_resource;
  377. else if (i < 4)
  378. par = &hose->mem_resources[i-1];
  379. else par = NULL;
  380. res->start = par ? par->start : 0;
  381. res->end = par ? par->end : 0;
  382. res->flags = par ? par->flags : 0;
  383. }
  384. }
  385. }
  386. int fsl_add_bridge(struct platform_device *pdev, int is_primary)
  387. {
  388. int len;
  389. struct pci_controller *hose;
  390. struct resource rsrc;
  391. const int *bus_range;
  392. u8 hdr_type, progif;
  393. struct device_node *dev;
  394. struct ccsr_pci __iomem *pci;
  395. dev = pdev->dev.of_node;
  396. if (!of_device_is_available(dev)) {
  397. pr_warning("%s: disabled\n", dev->full_name);
  398. return -ENODEV;
  399. }
  400. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  401. /* Fetch host bridge registers address */
  402. if (of_address_to_resource(dev, 0, &rsrc)) {
  403. printk(KERN_WARNING "Can't get pci register base!");
  404. return -ENOMEM;
  405. }
  406. /* Get bus range if any */
  407. bus_range = of_get_property(dev, "bus-range", &len);
  408. if (bus_range == NULL || len < 2 * sizeof(int))
  409. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  410. " bus 0\n", dev->full_name);
  411. pci_add_flags(PCI_REASSIGN_ALL_BUS);
  412. hose = pcibios_alloc_controller(dev);
  413. if (!hose)
  414. return -ENOMEM;
  415. /* set platform device as the parent */
  416. hose->parent = &pdev->dev;
  417. hose->first_busno = bus_range ? bus_range[0] : 0x0;
  418. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  419. pr_debug("PCI memory map start 0x%016llx, size 0x%016llx\n",
  420. (u64)rsrc.start, (u64)resource_size(&rsrc));
  421. pci = hose->private_data = ioremap(rsrc.start, resource_size(&rsrc));
  422. if (!hose->private_data)
  423. goto no_bridge;
  424. setup_indirect_pci(hose, rsrc.start, rsrc.start + 0x4,
  425. PPC_INDIRECT_TYPE_BIG_ENDIAN);
  426. if (in_be32(&pci->block_rev1) < PCIE_IP_REV_3_0)
  427. hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
  428. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  429. /* use fsl_indirect_read_config for PCIe */
  430. hose->ops = &fsl_indirect_pcie_ops;
  431. /* For PCIE read HEADER_TYPE to identify controler mode */
  432. early_read_config_byte(hose, 0, 0, PCI_HEADER_TYPE, &hdr_type);
  433. if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE)
  434. goto no_bridge;
  435. } else {
  436. /* For PCI read PROG to identify controller mode */
  437. early_read_config_byte(hose, 0, 0, PCI_CLASS_PROG, &progif);
  438. if ((progif & 1) &&
  439. !of_property_read_bool(dev, "fsl,pci-agent-force-enum"))
  440. goto no_bridge;
  441. }
  442. setup_pci_cmd(hose);
  443. /* check PCI express link status */
  444. if (early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP)) {
  445. hose->indirect_type |= PPC_INDIRECT_TYPE_EXT_REG |
  446. PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS;
  447. if (fsl_pcie_check_link(hose))
  448. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  449. }
  450. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
  451. "Firmware bus number: %d->%d\n",
  452. (unsigned long long)rsrc.start, hose->first_busno,
  453. hose->last_busno);
  454. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  455. hose, hose->cfg_addr, hose->cfg_data);
  456. /* Interpret the "ranges" property */
  457. /* This also maps the I/O region and sets isa_io/mem_base */
  458. pci_process_bridge_OF_ranges(hose, dev, is_primary);
  459. /* Setup PEX window registers */
  460. setup_pci_atmu(hose);
  461. return 0;
  462. no_bridge:
  463. iounmap(hose->private_data);
  464. /* unmap cfg_data & cfg_addr separately if not on same page */
  465. if (((unsigned long)hose->cfg_data & PAGE_MASK) !=
  466. ((unsigned long)hose->cfg_addr & PAGE_MASK))
  467. iounmap(hose->cfg_data);
  468. iounmap(hose->cfg_addr);
  469. pcibios_free_controller(hose);
  470. return -ENODEV;
  471. }
  472. #endif /* CONFIG_FSL_SOC_BOOKE || CONFIG_PPC_86xx */
  473. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID,
  474. quirk_fsl_pcie_early);
  475. #if defined(CONFIG_PPC_83xx) || defined(CONFIG_PPC_MPC512x)
  476. struct mpc83xx_pcie_priv {
  477. void __iomem *cfg_type0;
  478. void __iomem *cfg_type1;
  479. u32 dev_base;
  480. };
  481. struct pex_inbound_window {
  482. u32 ar;
  483. u32 tar;
  484. u32 barl;
  485. u32 barh;
  486. };
  487. /*
  488. * With the convention of u-boot, the PCIE outbound window 0 serves
  489. * as configuration transactions outbound.
  490. */
  491. #define PEX_OUTWIN0_BAR 0xCA4
  492. #define PEX_OUTWIN0_TAL 0xCA8
  493. #define PEX_OUTWIN0_TAH 0xCAC
  494. #define PEX_RC_INWIN_BASE 0xE60
  495. #define PEX_RCIWARn_EN 0x1
  496. static int mpc83xx_pcie_exclude_device(struct pci_bus *bus, unsigned int devfn)
  497. {
  498. struct pci_controller *hose = pci_bus_to_host(bus);
  499. if (hose->indirect_type & PPC_INDIRECT_TYPE_NO_PCIE_LINK)
  500. return PCIBIOS_DEVICE_NOT_FOUND;
  501. /*
  502. * Workaround for the HW bug: for Type 0 configure transactions the
  503. * PCI-E controller does not check the device number bits and just
  504. * assumes that the device number bits are 0.
  505. */
  506. if (bus->number == hose->first_busno ||
  507. bus->primary == hose->first_busno) {
  508. if (devfn & 0xf8)
  509. return PCIBIOS_DEVICE_NOT_FOUND;
  510. }
  511. if (ppc_md.pci_exclude_device) {
  512. if (ppc_md.pci_exclude_device(hose, bus->number, devfn))
  513. return PCIBIOS_DEVICE_NOT_FOUND;
  514. }
  515. return PCIBIOS_SUCCESSFUL;
  516. }
  517. static void __iomem *mpc83xx_pcie_remap_cfg(struct pci_bus *bus,
  518. unsigned int devfn, int offset)
  519. {
  520. struct pci_controller *hose = pci_bus_to_host(bus);
  521. struct mpc83xx_pcie_priv *pcie = hose->dn->data;
  522. u32 dev_base = bus->number << 24 | devfn << 16;
  523. int ret;
  524. ret = mpc83xx_pcie_exclude_device(bus, devfn);
  525. if (ret)
  526. return NULL;
  527. offset &= 0xfff;
  528. /* Type 0 */
  529. if (bus->number == hose->first_busno)
  530. return pcie->cfg_type0 + offset;
  531. if (pcie->dev_base == dev_base)
  532. goto mapped;
  533. out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, dev_base);
  534. pcie->dev_base = dev_base;
  535. mapped:
  536. return pcie->cfg_type1 + offset;
  537. }
  538. static int mpc83xx_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
  539. int offset, int len, u32 *val)
  540. {
  541. void __iomem *cfg_addr;
  542. cfg_addr = mpc83xx_pcie_remap_cfg(bus, devfn, offset);
  543. if (!cfg_addr)
  544. return PCIBIOS_DEVICE_NOT_FOUND;
  545. switch (len) {
  546. case 1:
  547. *val = in_8(cfg_addr);
  548. break;
  549. case 2:
  550. *val = in_le16(cfg_addr);
  551. break;
  552. default:
  553. *val = in_le32(cfg_addr);
  554. break;
  555. }
  556. return PCIBIOS_SUCCESSFUL;
  557. }
  558. static int mpc83xx_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
  559. int offset, int len, u32 val)
  560. {
  561. struct pci_controller *hose = pci_bus_to_host(bus);
  562. void __iomem *cfg_addr;
  563. cfg_addr = mpc83xx_pcie_remap_cfg(bus, devfn, offset);
  564. if (!cfg_addr)
  565. return PCIBIOS_DEVICE_NOT_FOUND;
  566. /* PPC_INDIRECT_TYPE_SURPRESS_PRIMARY_BUS */
  567. if (offset == PCI_PRIMARY_BUS && bus->number == hose->first_busno)
  568. val &= 0xffffff00;
  569. switch (len) {
  570. case 1:
  571. out_8(cfg_addr, val);
  572. break;
  573. case 2:
  574. out_le16(cfg_addr, val);
  575. break;
  576. default:
  577. out_le32(cfg_addr, val);
  578. break;
  579. }
  580. return PCIBIOS_SUCCESSFUL;
  581. }
  582. static struct pci_ops mpc83xx_pcie_ops = {
  583. .read = mpc83xx_pcie_read_config,
  584. .write = mpc83xx_pcie_write_config,
  585. };
  586. static int __init mpc83xx_pcie_setup(struct pci_controller *hose,
  587. struct resource *reg)
  588. {
  589. struct mpc83xx_pcie_priv *pcie;
  590. u32 cfg_bar;
  591. int ret = -ENOMEM;
  592. pcie = zalloc_maybe_bootmem(sizeof(*pcie), GFP_KERNEL);
  593. if (!pcie)
  594. return ret;
  595. pcie->cfg_type0 = ioremap(reg->start, resource_size(reg));
  596. if (!pcie->cfg_type0)
  597. goto err0;
  598. cfg_bar = in_le32(pcie->cfg_type0 + PEX_OUTWIN0_BAR);
  599. if (!cfg_bar) {
  600. /* PCI-E isn't configured. */
  601. ret = -ENODEV;
  602. goto err1;
  603. }
  604. pcie->cfg_type1 = ioremap(cfg_bar, 0x1000);
  605. if (!pcie->cfg_type1)
  606. goto err1;
  607. WARN_ON(hose->dn->data);
  608. hose->dn->data = pcie;
  609. hose->ops = &mpc83xx_pcie_ops;
  610. hose->indirect_type |= PPC_INDIRECT_TYPE_FSL_CFG_REG_LINK;
  611. out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAH, 0);
  612. out_le32(pcie->cfg_type0 + PEX_OUTWIN0_TAL, 0);
  613. if (fsl_pcie_check_link(hose))
  614. hose->indirect_type |= PPC_INDIRECT_TYPE_NO_PCIE_LINK;
  615. return 0;
  616. err1:
  617. iounmap(pcie->cfg_type0);
  618. err0:
  619. kfree(pcie);
  620. return ret;
  621. }
  622. int __init mpc83xx_add_bridge(struct device_node *dev)
  623. {
  624. int ret;
  625. int len;
  626. struct pci_controller *hose;
  627. struct resource rsrc_reg;
  628. struct resource rsrc_cfg;
  629. const int *bus_range;
  630. int primary;
  631. is_mpc83xx_pci = 1;
  632. if (!of_device_is_available(dev)) {
  633. pr_warning("%s: disabled by the firmware.\n",
  634. dev->full_name);
  635. return -ENODEV;
  636. }
  637. pr_debug("Adding PCI host bridge %s\n", dev->full_name);
  638. /* Fetch host bridge registers address */
  639. if (of_address_to_resource(dev, 0, &rsrc_reg)) {
  640. printk(KERN_WARNING "Can't get pci register base!\n");
  641. return -ENOMEM;
  642. }
  643. memset(&rsrc_cfg, 0, sizeof(rsrc_cfg));
  644. if (of_address_to_resource(dev, 1, &rsrc_cfg)) {
  645. printk(KERN_WARNING
  646. "No pci config register base in dev tree, "
  647. "using default\n");
  648. /*
  649. * MPC83xx supports up to two host controllers
  650. * one at 0x8500 has config space registers at 0x8300
  651. * one at 0x8600 has config space registers at 0x8380
  652. */
  653. if ((rsrc_reg.start & 0xfffff) == 0x8500)
  654. rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8300;
  655. else if ((rsrc_reg.start & 0xfffff) == 0x8600)
  656. rsrc_cfg.start = (rsrc_reg.start & 0xfff00000) + 0x8380;
  657. }
  658. /*
  659. * Controller at offset 0x8500 is primary
  660. */
  661. if ((rsrc_reg.start & 0xfffff) == 0x8500)
  662. primary = 1;
  663. else
  664. primary = 0;
  665. /* Get bus range if any */
  666. bus_range = of_get_property(dev, "bus-range", &len);
  667. if (bus_range == NULL || len < 2 * sizeof(int)) {
  668. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  669. " bus 0\n", dev->full_name);
  670. }
  671. pci_add_flags(PCI_REASSIGN_ALL_BUS);
  672. hose = pcibios_alloc_controller(dev);
  673. if (!hose)
  674. return -ENOMEM;
  675. hose->first_busno = bus_range ? bus_range[0] : 0;
  676. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  677. if (of_device_is_compatible(dev, "fsl,mpc8314-pcie")) {
  678. ret = mpc83xx_pcie_setup(hose, &rsrc_reg);
  679. if (ret)
  680. goto err0;
  681. } else {
  682. setup_indirect_pci(hose, rsrc_cfg.start,
  683. rsrc_cfg.start + 4, 0);
  684. }
  685. printk(KERN_INFO "Found FSL PCI host bridge at 0x%016llx. "
  686. "Firmware bus number: %d->%d\n",
  687. (unsigned long long)rsrc_reg.start, hose->first_busno,
  688. hose->last_busno);
  689. pr_debug(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  690. hose, hose->cfg_addr, hose->cfg_data);
  691. /* Interpret the "ranges" property */
  692. /* This also maps the I/O region and sets isa_io/mem_base */
  693. pci_process_bridge_OF_ranges(hose, dev, primary);
  694. return 0;
  695. err0:
  696. pcibios_free_controller(hose);
  697. return ret;
  698. }
  699. #endif /* CONFIG_PPC_83xx */
  700. u64 fsl_pci_immrbar_base(struct pci_controller *hose)
  701. {
  702. #ifdef CONFIG_PPC_83xx
  703. if (is_mpc83xx_pci) {
  704. struct mpc83xx_pcie_priv *pcie = hose->dn->data;
  705. struct pex_inbound_window *in;
  706. int i;
  707. /* Walk the Root Complex Inbound windows to match IMMR base */
  708. in = pcie->cfg_type0 + PEX_RC_INWIN_BASE;
  709. for (i = 0; i < 4; i++) {
  710. /* not enabled, skip */
  711. if (!(in_le32(&in[i].ar) & PEX_RCIWARn_EN))
  712. continue;
  713. if (get_immrbase() == in_le32(&in[i].tar))
  714. return (u64)in_le32(&in[i].barh) << 32 |
  715. in_le32(&in[i].barl);
  716. }
  717. printk(KERN_WARNING "could not find PCI BAR matching IMMR\n");
  718. }
  719. #endif
  720. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  721. if (!is_mpc83xx_pci) {
  722. u32 base;
  723. pci_bus_read_config_dword(hose->bus,
  724. PCI_DEVFN(0, 0), PCI_BASE_ADDRESS_0, &base);
  725. /*
  726. * For PEXCSRBAR, bit 3-0 indicate prefetchable and
  727. * address type. So when getting base address, these
  728. * bits should be masked
  729. */
  730. base &= PCI_BASE_ADDRESS_MEM_MASK;
  731. return base;
  732. }
  733. #endif
  734. return 0;
  735. }
  736. #ifdef CONFIG_E500
  737. static int mcheck_handle_load(struct pt_regs *regs, u32 inst)
  738. {
  739. unsigned int rd, ra, rb, d;
  740. rd = get_rt(inst);
  741. ra = get_ra(inst);
  742. rb = get_rb(inst);
  743. d = get_d(inst);
  744. switch (get_op(inst)) {
  745. case 31:
  746. switch (get_xop(inst)) {
  747. case OP_31_XOP_LWZX:
  748. case OP_31_XOP_LWBRX:
  749. regs->gpr[rd] = 0xffffffff;
  750. break;
  751. case OP_31_XOP_LWZUX:
  752. regs->gpr[rd] = 0xffffffff;
  753. regs->gpr[ra] += regs->gpr[rb];
  754. break;
  755. case OP_31_XOP_LBZX:
  756. regs->gpr[rd] = 0xff;
  757. break;
  758. case OP_31_XOP_LBZUX:
  759. regs->gpr[rd] = 0xff;
  760. regs->gpr[ra] += regs->gpr[rb];
  761. break;
  762. case OP_31_XOP_LHZX:
  763. case OP_31_XOP_LHBRX:
  764. regs->gpr[rd] = 0xffff;
  765. break;
  766. case OP_31_XOP_LHZUX:
  767. regs->gpr[rd] = 0xffff;
  768. regs->gpr[ra] += regs->gpr[rb];
  769. break;
  770. case OP_31_XOP_LHAX:
  771. regs->gpr[rd] = ~0UL;
  772. break;
  773. case OP_31_XOP_LHAUX:
  774. regs->gpr[rd] = ~0UL;
  775. regs->gpr[ra] += regs->gpr[rb];
  776. break;
  777. default:
  778. return 0;
  779. }
  780. break;
  781. case OP_LWZ:
  782. regs->gpr[rd] = 0xffffffff;
  783. break;
  784. case OP_LWZU:
  785. regs->gpr[rd] = 0xffffffff;
  786. regs->gpr[ra] += (s16)d;
  787. break;
  788. case OP_LBZ:
  789. regs->gpr[rd] = 0xff;
  790. break;
  791. case OP_LBZU:
  792. regs->gpr[rd] = 0xff;
  793. regs->gpr[ra] += (s16)d;
  794. break;
  795. case OP_LHZ:
  796. regs->gpr[rd] = 0xffff;
  797. break;
  798. case OP_LHZU:
  799. regs->gpr[rd] = 0xffff;
  800. regs->gpr[ra] += (s16)d;
  801. break;
  802. case OP_LHA:
  803. regs->gpr[rd] = ~0UL;
  804. break;
  805. case OP_LHAU:
  806. regs->gpr[rd] = ~0UL;
  807. regs->gpr[ra] += (s16)d;
  808. break;
  809. default:
  810. return 0;
  811. }
  812. return 1;
  813. }
  814. static int is_in_pci_mem_space(phys_addr_t addr)
  815. {
  816. struct pci_controller *hose;
  817. struct resource *res;
  818. int i;
  819. list_for_each_entry(hose, &hose_list, list_node) {
  820. if (!(hose->indirect_type & PPC_INDIRECT_TYPE_EXT_REG))
  821. continue;
  822. for (i = 0; i < 3; i++) {
  823. res = &hose->mem_resources[i];
  824. if ((res->flags & IORESOURCE_MEM) &&
  825. addr >= res->start && addr <= res->end)
  826. return 1;
  827. }
  828. }
  829. return 0;
  830. }
  831. int fsl_pci_mcheck_exception(struct pt_regs *regs)
  832. {
  833. u32 inst;
  834. int ret;
  835. phys_addr_t addr = 0;
  836. /* Let KVM/QEMU deal with the exception */
  837. if (regs->msr & MSR_GS)
  838. return 0;
  839. #ifdef CONFIG_PHYS_64BIT
  840. addr = mfspr(SPRN_MCARU);
  841. addr <<= 32;
  842. #endif
  843. addr += mfspr(SPRN_MCAR);
  844. if (is_in_pci_mem_space(addr)) {
  845. if (user_mode(regs)) {
  846. pagefault_disable();
  847. ret = get_user(regs->nip, &inst);
  848. pagefault_enable();
  849. } else {
  850. ret = probe_kernel_address(regs->nip, inst);
  851. }
  852. if (mcheck_handle_load(regs, inst)) {
  853. regs->nip += 4;
  854. return 1;
  855. }
  856. }
  857. return 0;
  858. }
  859. #endif
  860. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  861. static const struct of_device_id pci_ids[] = {
  862. { .compatible = "fsl,mpc8540-pci", },
  863. { .compatible = "fsl,mpc8548-pcie", },
  864. { .compatible = "fsl,mpc8610-pci", },
  865. { .compatible = "fsl,mpc8641-pcie", },
  866. { .compatible = "fsl,qoriq-pcie", },
  867. { .compatible = "fsl,qoriq-pcie-v2.1", },
  868. { .compatible = "fsl,qoriq-pcie-v2.2", },
  869. { .compatible = "fsl,qoriq-pcie-v2.3", },
  870. { .compatible = "fsl,qoriq-pcie-v2.4", },
  871. { .compatible = "fsl,qoriq-pcie-v3.0", },
  872. /*
  873. * The following entries are for compatibility with older device
  874. * trees.
  875. */
  876. { .compatible = "fsl,p1022-pcie", },
  877. { .compatible = "fsl,p4080-pcie", },
  878. {},
  879. };
  880. struct device_node *fsl_pci_primary;
  881. void fsl_pci_assign_primary(void)
  882. {
  883. struct device_node *np;
  884. /* Callers can specify the primary bus using other means. */
  885. if (fsl_pci_primary)
  886. return;
  887. /* If a PCI host bridge contains an ISA node, it's primary. */
  888. np = of_find_node_by_type(NULL, "isa");
  889. while ((fsl_pci_primary = of_get_parent(np))) {
  890. of_node_put(np);
  891. np = fsl_pci_primary;
  892. if (of_match_node(pci_ids, np) && of_device_is_available(np))
  893. return;
  894. }
  895. /*
  896. * If there's no PCI host bridge with ISA, arbitrarily
  897. * designate one as primary. This can go away once
  898. * various bugs with primary-less systems are fixed.
  899. */
  900. for_each_matching_node(np, pci_ids) {
  901. if (of_device_is_available(np)) {
  902. fsl_pci_primary = np;
  903. of_node_put(np);
  904. return;
  905. }
  906. }
  907. }
  908. #ifdef CONFIG_PM_SLEEP
  909. static irqreturn_t fsl_pci_pme_handle(int irq, void *dev_id)
  910. {
  911. struct pci_controller *hose = dev_id;
  912. struct ccsr_pci __iomem *pci = hose->private_data;
  913. u32 dr;
  914. dr = in_be32(&pci->pex_pme_mes_dr);
  915. if (!dr)
  916. return IRQ_NONE;
  917. out_be32(&pci->pex_pme_mes_dr, dr);
  918. return IRQ_HANDLED;
  919. }
  920. static int fsl_pci_pme_probe(struct pci_controller *hose)
  921. {
  922. struct ccsr_pci __iomem *pci;
  923. struct pci_dev *dev;
  924. int pme_irq;
  925. int res;
  926. u16 pms;
  927. /* Get hose's pci_dev */
  928. dev = list_first_entry(&hose->bus->devices, typeof(*dev), bus_list);
  929. /* PME Disable */
  930. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pms);
  931. pms &= ~PCI_PM_CTRL_PME_ENABLE;
  932. pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pms);
  933. pme_irq = irq_of_parse_and_map(hose->dn, 0);
  934. if (!pme_irq) {
  935. dev_err(&dev->dev, "Failed to map PME interrupt.\n");
  936. return -ENXIO;
  937. }
  938. res = devm_request_irq(hose->parent, pme_irq,
  939. fsl_pci_pme_handle,
  940. IRQF_SHARED,
  941. "[PCI] PME", hose);
  942. if (res < 0) {
  943. dev_err(&dev->dev, "Unable to requiest irq %d for PME\n", pme_irq);
  944. irq_dispose_mapping(pme_irq);
  945. return -ENODEV;
  946. }
  947. pci = hose->private_data;
  948. /* Enable PTOD, ENL23D & EXL23D */
  949. clrbits32(&pci->pex_pme_mes_disr,
  950. PME_DISR_EN_PTOD | PME_DISR_EN_ENL23D | PME_DISR_EN_EXL23D);
  951. out_be32(&pci->pex_pme_mes_ier, 0);
  952. setbits32(&pci->pex_pme_mes_ier,
  953. PME_DISR_EN_PTOD | PME_DISR_EN_ENL23D | PME_DISR_EN_EXL23D);
  954. /* PME Enable */
  955. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pms);
  956. pms |= PCI_PM_CTRL_PME_ENABLE;
  957. pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pms);
  958. return 0;
  959. }
  960. static void send_pme_turnoff_message(struct pci_controller *hose)
  961. {
  962. struct ccsr_pci __iomem *pci = hose->private_data;
  963. u32 dr;
  964. int i;
  965. /* Send PME_Turn_Off Message Request */
  966. setbits32(&pci->pex_pmcr, PEX_PMCR_PTOMR);
  967. /* Wait trun off done */
  968. for (i = 0; i < 150; i++) {
  969. dr = in_be32(&pci->pex_pme_mes_dr);
  970. if (dr) {
  971. out_be32(&pci->pex_pme_mes_dr, dr);
  972. break;
  973. }
  974. udelay(1000);
  975. }
  976. }
  977. static void fsl_pci_syscore_do_suspend(struct pci_controller *hose)
  978. {
  979. send_pme_turnoff_message(hose);
  980. }
  981. static int fsl_pci_syscore_suspend(void)
  982. {
  983. struct pci_controller *hose, *tmp;
  984. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  985. fsl_pci_syscore_do_suspend(hose);
  986. return 0;
  987. }
  988. static void fsl_pci_syscore_do_resume(struct pci_controller *hose)
  989. {
  990. struct ccsr_pci __iomem *pci = hose->private_data;
  991. u32 dr;
  992. int i;
  993. /* Send Exit L2 State Message */
  994. setbits32(&pci->pex_pmcr, PEX_PMCR_EXL2S);
  995. /* Wait exit done */
  996. for (i = 0; i < 150; i++) {
  997. dr = in_be32(&pci->pex_pme_mes_dr);
  998. if (dr) {
  999. out_be32(&pci->pex_pme_mes_dr, dr);
  1000. break;
  1001. }
  1002. udelay(1000);
  1003. }
  1004. setup_pci_atmu(hose);
  1005. }
  1006. static void fsl_pci_syscore_resume(void)
  1007. {
  1008. struct pci_controller *hose, *tmp;
  1009. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  1010. fsl_pci_syscore_do_resume(hose);
  1011. }
  1012. static struct syscore_ops pci_syscore_pm_ops = {
  1013. .suspend = fsl_pci_syscore_suspend,
  1014. .resume = fsl_pci_syscore_resume,
  1015. };
  1016. #endif
  1017. void fsl_pcibios_fixup_phb(struct pci_controller *phb)
  1018. {
  1019. #ifdef CONFIG_PM_SLEEP
  1020. fsl_pci_pme_probe(phb);
  1021. #endif
  1022. }
  1023. static int fsl_pci_probe(struct platform_device *pdev)
  1024. {
  1025. struct device_node *node;
  1026. int ret;
  1027. node = pdev->dev.of_node;
  1028. ret = fsl_add_bridge(pdev, fsl_pci_primary == node);
  1029. mpc85xx_pci_err_probe(pdev);
  1030. return 0;
  1031. }
  1032. static struct platform_driver fsl_pci_driver = {
  1033. .driver = {
  1034. .name = "fsl-pci",
  1035. .of_match_table = pci_ids,
  1036. },
  1037. .probe = fsl_pci_probe,
  1038. };
  1039. static int __init fsl_pci_init(void)
  1040. {
  1041. #ifdef CONFIG_PM_SLEEP
  1042. register_syscore_ops(&pci_syscore_pm_ops);
  1043. #endif
  1044. return platform_driver_register(&fsl_pci_driver);
  1045. }
  1046. arch_initcall(fsl_pci_init);
  1047. #endif