fsl_pci.c 32 KB

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