fsl_pci.c 34 KB

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