fsl_pci.c 33 KB

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