pci-keystone-dw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. * DesignWare application register space functions for Keystone PCI controller
  3. *
  4. * Copyright (C) 2013-2014 Texas Instruments., Ltd.
  5. * http://www.ti.com
  6. *
  7. * Author: Murali Karicheri <m-karicheri2@ti.com>
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/irq.h>
  15. #include <linux/irqdomain.h>
  16. #include <linux/irqreturn.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_pci.h>
  20. #include <linux/pci.h>
  21. #include <linux/platform_device.h>
  22. #include "pcie-designware.h"
  23. #include "pci-keystone.h"
  24. /* Application register defines */
  25. #define LTSSM_EN_VAL 1
  26. #define LTSSM_STATE_MASK 0x1f
  27. #define LTSSM_STATE_L0 0x11
  28. #define DBI_CS2_EN_VAL 0x20
  29. #define OB_XLAT_EN_VAL 2
  30. /* Application registers */
  31. #define CMD_STATUS 0x004
  32. #define CFG_SETUP 0x008
  33. #define OB_SIZE 0x030
  34. #define CFG_PCIM_WIN_SZ_IDX 3
  35. #define CFG_PCIM_WIN_CNT 32
  36. #define SPACE0_REMOTE_CFG_OFFSET 0x1000
  37. #define OB_OFFSET_INDEX(n) (0x200 + (8 * n))
  38. #define OB_OFFSET_HI(n) (0x204 + (8 * n))
  39. /* IRQ register defines */
  40. #define IRQ_EOI 0x050
  41. #define IRQ_STATUS 0x184
  42. #define IRQ_ENABLE_SET 0x188
  43. #define IRQ_ENABLE_CLR 0x18c
  44. #define MSI_IRQ 0x054
  45. #define MSI0_IRQ_STATUS 0x104
  46. #define MSI0_IRQ_ENABLE_SET 0x108
  47. #define MSI0_IRQ_ENABLE_CLR 0x10c
  48. #define IRQ_STATUS 0x184
  49. #define MSI_IRQ_OFFSET 4
  50. /* Error IRQ bits */
  51. #define ERR_AER BIT(5) /* ECRC error */
  52. #define ERR_AXI BIT(4) /* AXI tag lookup fatal error */
  53. #define ERR_CORR BIT(3) /* Correctable error */
  54. #define ERR_NONFATAL BIT(2) /* Non-fatal error */
  55. #define ERR_FATAL BIT(1) /* Fatal error */
  56. #define ERR_SYS BIT(0) /* System (fatal, non-fatal, or correctable) */
  57. #define ERR_IRQ_ALL (ERR_AER | ERR_AXI | ERR_CORR | \
  58. ERR_NONFATAL | ERR_FATAL | ERR_SYS)
  59. #define ERR_FATAL_IRQ (ERR_FATAL | ERR_AXI)
  60. #define ERR_IRQ_STATUS_RAW 0x1c0
  61. #define ERR_IRQ_STATUS 0x1c4
  62. #define ERR_IRQ_ENABLE_SET 0x1c8
  63. #define ERR_IRQ_ENABLE_CLR 0x1cc
  64. /* Config space registers */
  65. #define DEBUG0 0x728
  66. #define to_keystone_pcie(x) dev_get_drvdata((x)->dev)
  67. static inline void update_reg_offset_bit_pos(u32 offset, u32 *reg_offset,
  68. u32 *bit_pos)
  69. {
  70. *reg_offset = offset % 8;
  71. *bit_pos = offset >> 3;
  72. }
  73. phys_addr_t ks_dw_pcie_get_msi_addr(struct pcie_port *pp)
  74. {
  75. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  76. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  77. return ks_pcie->app.start + MSI_IRQ;
  78. }
  79. static u32 ks_dw_app_readl(struct keystone_pcie *ks_pcie, u32 offset)
  80. {
  81. return readl(ks_pcie->va_app_base + offset);
  82. }
  83. static void ks_dw_app_writel(struct keystone_pcie *ks_pcie, u32 offset, u32 val)
  84. {
  85. writel(val, ks_pcie->va_app_base + offset);
  86. }
  87. void ks_dw_pcie_handle_msi_irq(struct keystone_pcie *ks_pcie, int offset)
  88. {
  89. struct dw_pcie *pci = ks_pcie->pci;
  90. struct pcie_port *pp = &pci->pp;
  91. struct device *dev = pci->dev;
  92. u32 pending, vector;
  93. int src, virq;
  94. pending = ks_dw_app_readl(ks_pcie, MSI0_IRQ_STATUS + (offset << 4));
  95. /*
  96. * MSI0 status bit 0-3 shows vectors 0, 8, 16, 24, MSI1 status bit
  97. * shows 1, 9, 17, 25 and so forth
  98. */
  99. for (src = 0; src < 4; src++) {
  100. if (BIT(src) & pending) {
  101. vector = offset + (src << 3);
  102. virq = irq_linear_revmap(pp->irq_domain, vector);
  103. dev_dbg(dev, "irq: bit %d, vector %d, virq %d\n",
  104. src, vector, virq);
  105. generic_handle_irq(virq);
  106. }
  107. }
  108. }
  109. static void ks_dw_pcie_msi_irq_ack(struct irq_data *d)
  110. {
  111. u32 offset, reg_offset, bit_pos;
  112. struct keystone_pcie *ks_pcie;
  113. struct msi_desc *msi;
  114. struct pcie_port *pp;
  115. struct dw_pcie *pci;
  116. msi = irq_data_get_msi_desc(d);
  117. pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
  118. pci = to_dw_pcie_from_pp(pp);
  119. ks_pcie = to_keystone_pcie(pci);
  120. offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
  121. update_reg_offset_bit_pos(offset, &reg_offset, &bit_pos);
  122. ks_dw_app_writel(ks_pcie, MSI0_IRQ_STATUS + (reg_offset << 4),
  123. BIT(bit_pos));
  124. ks_dw_app_writel(ks_pcie, IRQ_EOI, reg_offset + MSI_IRQ_OFFSET);
  125. }
  126. void ks_dw_pcie_msi_set_irq(struct pcie_port *pp, int irq)
  127. {
  128. u32 reg_offset, bit_pos;
  129. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  130. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  131. update_reg_offset_bit_pos(irq, &reg_offset, &bit_pos);
  132. ks_dw_app_writel(ks_pcie, MSI0_IRQ_ENABLE_SET + (reg_offset << 4),
  133. BIT(bit_pos));
  134. }
  135. void ks_dw_pcie_msi_clear_irq(struct pcie_port *pp, int irq)
  136. {
  137. u32 reg_offset, bit_pos;
  138. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  139. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  140. update_reg_offset_bit_pos(irq, &reg_offset, &bit_pos);
  141. ks_dw_app_writel(ks_pcie, MSI0_IRQ_ENABLE_CLR + (reg_offset << 4),
  142. BIT(bit_pos));
  143. }
  144. static void ks_dw_pcie_msi_irq_mask(struct irq_data *d)
  145. {
  146. struct keystone_pcie *ks_pcie;
  147. struct msi_desc *msi;
  148. struct pcie_port *pp;
  149. struct dw_pcie *pci;
  150. u32 offset;
  151. msi = irq_data_get_msi_desc(d);
  152. pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
  153. pci = to_dw_pcie_from_pp(pp);
  154. ks_pcie = to_keystone_pcie(pci);
  155. offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
  156. /* Mask the end point if PVM implemented */
  157. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  158. if (msi->msi_attrib.maskbit)
  159. pci_msi_mask_irq(d);
  160. }
  161. ks_dw_pcie_msi_clear_irq(pp, offset);
  162. }
  163. static void ks_dw_pcie_msi_irq_unmask(struct irq_data *d)
  164. {
  165. struct keystone_pcie *ks_pcie;
  166. struct msi_desc *msi;
  167. struct pcie_port *pp;
  168. struct dw_pcie *pci;
  169. u32 offset;
  170. msi = irq_data_get_msi_desc(d);
  171. pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
  172. pci = to_dw_pcie_from_pp(pp);
  173. ks_pcie = to_keystone_pcie(pci);
  174. offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
  175. /* Mask the end point if PVM implemented */
  176. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  177. if (msi->msi_attrib.maskbit)
  178. pci_msi_unmask_irq(d);
  179. }
  180. ks_dw_pcie_msi_set_irq(pp, offset);
  181. }
  182. static struct irq_chip ks_dw_pcie_msi_irq_chip = {
  183. .name = "Keystone-PCIe-MSI-IRQ",
  184. .irq_ack = ks_dw_pcie_msi_irq_ack,
  185. .irq_mask = ks_dw_pcie_msi_irq_mask,
  186. .irq_unmask = ks_dw_pcie_msi_irq_unmask,
  187. };
  188. static int ks_dw_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
  189. irq_hw_number_t hwirq)
  190. {
  191. irq_set_chip_and_handler(irq, &ks_dw_pcie_msi_irq_chip,
  192. handle_level_irq);
  193. irq_set_chip_data(irq, domain->host_data);
  194. return 0;
  195. }
  196. static const struct irq_domain_ops ks_dw_pcie_msi_domain_ops = {
  197. .map = ks_dw_pcie_msi_map,
  198. };
  199. int ks_dw_pcie_msi_host_init(struct pcie_port *pp, struct msi_controller *chip)
  200. {
  201. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  202. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  203. struct device *dev = pci->dev;
  204. int i;
  205. pp->irq_domain = irq_domain_add_linear(ks_pcie->msi_intc_np,
  206. MAX_MSI_IRQS,
  207. &ks_dw_pcie_msi_domain_ops,
  208. chip);
  209. if (!pp->irq_domain) {
  210. dev_err(dev, "irq domain init failed\n");
  211. return -ENXIO;
  212. }
  213. for (i = 0; i < MAX_MSI_IRQS; i++)
  214. irq_create_mapping(pp->irq_domain, i);
  215. return 0;
  216. }
  217. void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie)
  218. {
  219. int i;
  220. for (i = 0; i < MAX_LEGACY_IRQS; i++)
  221. ks_dw_app_writel(ks_pcie, IRQ_ENABLE_SET + (i << 4), 0x1);
  222. }
  223. void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset)
  224. {
  225. struct dw_pcie *pci = ks_pcie->pci;
  226. struct device *dev = pci->dev;
  227. u32 pending;
  228. int virq;
  229. pending = ks_dw_app_readl(ks_pcie, IRQ_STATUS + (offset << 4));
  230. if (BIT(0) & pending) {
  231. virq = irq_linear_revmap(ks_pcie->legacy_irq_domain, offset);
  232. dev_dbg(dev, ": irq: irq_offset %d, virq %d\n", offset, virq);
  233. generic_handle_irq(virq);
  234. }
  235. /* EOI the INTx interrupt */
  236. ks_dw_app_writel(ks_pcie, IRQ_EOI, offset);
  237. }
  238. void ks_dw_pcie_enable_error_irq(struct keystone_pcie *ks_pcie)
  239. {
  240. ks_dw_app_writel(ks_pcie, ERR_IRQ_ENABLE_SET, ERR_IRQ_ALL);
  241. }
  242. irqreturn_t ks_dw_pcie_handle_error_irq(struct keystone_pcie *ks_pcie)
  243. {
  244. u32 status;
  245. status = ks_dw_app_readl(ks_pcie, ERR_IRQ_STATUS_RAW) & ERR_IRQ_ALL;
  246. if (!status)
  247. return IRQ_NONE;
  248. if (status & ERR_FATAL_IRQ)
  249. dev_err(ks_pcie->pci->dev, "fatal error (status %#010x)\n",
  250. status);
  251. /* Ack the IRQ; status bits are RW1C */
  252. ks_dw_app_writel(ks_pcie, ERR_IRQ_STATUS, status);
  253. return IRQ_HANDLED;
  254. }
  255. static void ks_dw_pcie_ack_legacy_irq(struct irq_data *d)
  256. {
  257. }
  258. static void ks_dw_pcie_mask_legacy_irq(struct irq_data *d)
  259. {
  260. }
  261. static void ks_dw_pcie_unmask_legacy_irq(struct irq_data *d)
  262. {
  263. }
  264. static struct irq_chip ks_dw_pcie_legacy_irq_chip = {
  265. .name = "Keystone-PCI-Legacy-IRQ",
  266. .irq_ack = ks_dw_pcie_ack_legacy_irq,
  267. .irq_mask = ks_dw_pcie_mask_legacy_irq,
  268. .irq_unmask = ks_dw_pcie_unmask_legacy_irq,
  269. };
  270. static int ks_dw_pcie_init_legacy_irq_map(struct irq_domain *d,
  271. unsigned int irq, irq_hw_number_t hw_irq)
  272. {
  273. irq_set_chip_and_handler(irq, &ks_dw_pcie_legacy_irq_chip,
  274. handle_level_irq);
  275. irq_set_chip_data(irq, d->host_data);
  276. return 0;
  277. }
  278. static const struct irq_domain_ops ks_dw_pcie_legacy_irq_domain_ops = {
  279. .map = ks_dw_pcie_init_legacy_irq_map,
  280. .xlate = irq_domain_xlate_onetwocell,
  281. };
  282. /**
  283. * ks_dw_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask
  284. * registers
  285. *
  286. * Since modification of dbi_cs2 involves different clock domain, read the
  287. * status back to ensure the transition is complete.
  288. */
  289. static void ks_dw_pcie_set_dbi_mode(struct keystone_pcie *ks_pcie)
  290. {
  291. u32 val;
  292. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  293. ks_dw_app_writel(ks_pcie, CMD_STATUS, DBI_CS2_EN_VAL | val);
  294. do {
  295. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  296. } while (!(val & DBI_CS2_EN_VAL));
  297. }
  298. /**
  299. * ks_dw_pcie_clear_dbi_mode() - Disable DBI mode
  300. *
  301. * Since modification of dbi_cs2 involves different clock domain, read the
  302. * status back to ensure the transition is complete.
  303. */
  304. static void ks_dw_pcie_clear_dbi_mode(struct keystone_pcie *ks_pcie)
  305. {
  306. u32 val;
  307. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  308. ks_dw_app_writel(ks_pcie, CMD_STATUS, ~DBI_CS2_EN_VAL & val);
  309. do {
  310. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  311. } while (val & DBI_CS2_EN_VAL);
  312. }
  313. void ks_dw_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
  314. {
  315. struct dw_pcie *pci = ks_pcie->pci;
  316. struct pcie_port *pp = &pci->pp;
  317. u32 start = pp->mem->start, end = pp->mem->end;
  318. int i, tr_size;
  319. u32 val;
  320. /* Disable BARs for inbound access */
  321. ks_dw_pcie_set_dbi_mode(ks_pcie);
  322. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
  323. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0);
  324. ks_dw_pcie_clear_dbi_mode(ks_pcie);
  325. /* Set outbound translation size per window division */
  326. ks_dw_app_writel(ks_pcie, OB_SIZE, CFG_PCIM_WIN_SZ_IDX & 0x7);
  327. tr_size = (1 << (CFG_PCIM_WIN_SZ_IDX & 0x7)) * SZ_1M;
  328. /* Using Direct 1:1 mapping of RC <-> PCI memory space */
  329. for (i = 0; (i < CFG_PCIM_WIN_CNT) && (start < end); i++) {
  330. ks_dw_app_writel(ks_pcie, OB_OFFSET_INDEX(i), start | 1);
  331. ks_dw_app_writel(ks_pcie, OB_OFFSET_HI(i), 0);
  332. start += tr_size;
  333. }
  334. /* Enable OB translation */
  335. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  336. ks_dw_app_writel(ks_pcie, CMD_STATUS, OB_XLAT_EN_VAL | val);
  337. }
  338. /**
  339. * ks_pcie_cfg_setup() - Set up configuration space address for a device
  340. *
  341. * @ks_pcie: ptr to keystone_pcie structure
  342. * @bus: Bus number the device is residing on
  343. * @devfn: device, function number info
  344. *
  345. * Forms and returns the address of configuration space mapped in PCIESS
  346. * address space 0. Also configures CFG_SETUP for remote configuration space
  347. * access.
  348. *
  349. * The address space has two regions to access configuration - local and remote.
  350. * We access local region for bus 0 (as RC is attached on bus 0) and remote
  351. * region for others with TYPE 1 access when bus > 1. As for device on bus = 1,
  352. * we will do TYPE 0 access as it will be on our secondary bus (logical).
  353. * CFG_SETUP is needed only for remote configuration access.
  354. */
  355. static void __iomem *ks_pcie_cfg_setup(struct keystone_pcie *ks_pcie, u8 bus,
  356. unsigned int devfn)
  357. {
  358. u8 device = PCI_SLOT(devfn), function = PCI_FUNC(devfn);
  359. struct dw_pcie *pci = ks_pcie->pci;
  360. struct pcie_port *pp = &pci->pp;
  361. u32 regval;
  362. if (bus == 0)
  363. return pci->dbi_base;
  364. regval = (bus << 16) | (device << 8) | function;
  365. /*
  366. * Since Bus#1 will be a virtual bus, we need to have TYPE0
  367. * access only.
  368. * TYPE 1
  369. */
  370. if (bus != 1)
  371. regval |= BIT(24);
  372. ks_dw_app_writel(ks_pcie, CFG_SETUP, regval);
  373. return pp->va_cfg0_base;
  374. }
  375. int ks_dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  376. unsigned int devfn, int where, int size, u32 *val)
  377. {
  378. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  379. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  380. u8 bus_num = bus->number;
  381. void __iomem *addr;
  382. addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
  383. return dw_pcie_read(addr + where, size, val);
  384. }
  385. int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  386. unsigned int devfn, int where, int size, u32 val)
  387. {
  388. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  389. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  390. u8 bus_num = bus->number;
  391. void __iomem *addr;
  392. addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
  393. return dw_pcie_write(addr + where, size, val);
  394. }
  395. /**
  396. * ks_dw_pcie_v3_65_scan_bus() - keystone scan_bus post initialization
  397. *
  398. * This sets BAR0 to enable inbound access for MSI_IRQ register
  399. */
  400. void ks_dw_pcie_v3_65_scan_bus(struct pcie_port *pp)
  401. {
  402. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  403. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  404. /* Configure and set up BAR0 */
  405. ks_dw_pcie_set_dbi_mode(ks_pcie);
  406. /* Enable BAR0 */
  407. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 1);
  408. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, SZ_4K - 1);
  409. ks_dw_pcie_clear_dbi_mode(ks_pcie);
  410. /*
  411. * For BAR0, just setting bus address for inbound writes (MSI) should
  412. * be sufficient. Use physical address to avoid any conflicts.
  413. */
  414. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, ks_pcie->app.start);
  415. }
  416. /**
  417. * ks_dw_pcie_link_up() - Check if link up
  418. */
  419. int ks_dw_pcie_link_up(struct dw_pcie *pci)
  420. {
  421. u32 val;
  422. val = dw_pcie_readl_dbi(pci, DEBUG0);
  423. return (val & LTSSM_STATE_MASK) == LTSSM_STATE_L0;
  424. }
  425. void ks_dw_pcie_initiate_link_train(struct keystone_pcie *ks_pcie)
  426. {
  427. u32 val;
  428. /* Disable Link training */
  429. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  430. val &= ~LTSSM_EN_VAL;
  431. ks_dw_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
  432. /* Initiate Link Training */
  433. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  434. ks_dw_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
  435. }
  436. /**
  437. * ks_dw_pcie_host_init() - initialize host for v3_65 dw hardware
  438. *
  439. * Ioremap the register resources, initialize legacy irq domain
  440. * and call dw_pcie_v3_65_host_init() API to initialize the Keystone
  441. * PCI host controller.
  442. */
  443. int __init ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
  444. struct device_node *msi_intc_np)
  445. {
  446. struct dw_pcie *pci = ks_pcie->pci;
  447. struct pcie_port *pp = &pci->pp;
  448. struct device *dev = pci->dev;
  449. struct platform_device *pdev = to_platform_device(dev);
  450. struct resource *res;
  451. /* Index 0 is the config reg. space address */
  452. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  453. pci->dbi_base = devm_pci_remap_cfg_resource(dev, res);
  454. if (IS_ERR(pci->dbi_base))
  455. return PTR_ERR(pci->dbi_base);
  456. /*
  457. * We set these same and is used in pcie rd/wr_other_conf
  458. * functions
  459. */
  460. pp->va_cfg0_base = pci->dbi_base + SPACE0_REMOTE_CFG_OFFSET;
  461. pp->va_cfg1_base = pp->va_cfg0_base;
  462. /* Index 1 is the application reg. space address */
  463. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  464. ks_pcie->va_app_base = devm_ioremap_resource(dev, res);
  465. if (IS_ERR(ks_pcie->va_app_base))
  466. return PTR_ERR(ks_pcie->va_app_base);
  467. ks_pcie->app = *res;
  468. /* Create legacy IRQ domain */
  469. ks_pcie->legacy_irq_domain =
  470. irq_domain_add_linear(ks_pcie->legacy_intc_np,
  471. MAX_LEGACY_IRQS,
  472. &ks_dw_pcie_legacy_irq_domain_ops,
  473. NULL);
  474. if (!ks_pcie->legacy_irq_domain) {
  475. dev_err(dev, "Failed to add irq domain for legacy irqs\n");
  476. return -EINVAL;
  477. }
  478. return dw_pcie_host_init(pp);
  479. }