pci-keystone-dw.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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 msi_desc *msi;
  147. struct pcie_port *pp;
  148. u32 offset;
  149. msi = irq_data_get_msi_desc(d);
  150. pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
  151. offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
  152. /* Mask the end point if PVM implemented */
  153. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  154. if (msi->msi_attrib.maskbit)
  155. pci_msi_mask_irq(d);
  156. }
  157. ks_dw_pcie_msi_clear_irq(pp, offset);
  158. }
  159. static void ks_dw_pcie_msi_irq_unmask(struct irq_data *d)
  160. {
  161. struct msi_desc *msi;
  162. struct pcie_port *pp;
  163. u32 offset;
  164. msi = irq_data_get_msi_desc(d);
  165. pp = (struct pcie_port *) msi_desc_to_pci_sysdata(msi);
  166. offset = d->irq - irq_linear_revmap(pp->irq_domain, 0);
  167. /* Mask the end point if PVM implemented */
  168. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  169. if (msi->msi_attrib.maskbit)
  170. pci_msi_unmask_irq(d);
  171. }
  172. ks_dw_pcie_msi_set_irq(pp, offset);
  173. }
  174. static struct irq_chip ks_dw_pcie_msi_irq_chip = {
  175. .name = "Keystone-PCIe-MSI-IRQ",
  176. .irq_ack = ks_dw_pcie_msi_irq_ack,
  177. .irq_mask = ks_dw_pcie_msi_irq_mask,
  178. .irq_unmask = ks_dw_pcie_msi_irq_unmask,
  179. };
  180. static int ks_dw_pcie_msi_map(struct irq_domain *domain, unsigned int irq,
  181. irq_hw_number_t hwirq)
  182. {
  183. irq_set_chip_and_handler(irq, &ks_dw_pcie_msi_irq_chip,
  184. handle_level_irq);
  185. irq_set_chip_data(irq, domain->host_data);
  186. return 0;
  187. }
  188. static const struct irq_domain_ops ks_dw_pcie_msi_domain_ops = {
  189. .map = ks_dw_pcie_msi_map,
  190. };
  191. int ks_dw_pcie_msi_host_init(struct pcie_port *pp, struct msi_controller *chip)
  192. {
  193. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  194. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  195. struct device *dev = pci->dev;
  196. int i;
  197. pp->irq_domain = irq_domain_add_linear(ks_pcie->msi_intc_np,
  198. MAX_MSI_IRQS,
  199. &ks_dw_pcie_msi_domain_ops,
  200. chip);
  201. if (!pp->irq_domain) {
  202. dev_err(dev, "irq domain init failed\n");
  203. return -ENXIO;
  204. }
  205. for (i = 0; i < MAX_MSI_IRQS; i++)
  206. irq_create_mapping(pp->irq_domain, i);
  207. return 0;
  208. }
  209. void ks_dw_pcie_enable_legacy_irqs(struct keystone_pcie *ks_pcie)
  210. {
  211. int i;
  212. for (i = 0; i < PCI_NUM_INTX; i++)
  213. ks_dw_app_writel(ks_pcie, IRQ_ENABLE_SET + (i << 4), 0x1);
  214. }
  215. void ks_dw_pcie_handle_legacy_irq(struct keystone_pcie *ks_pcie, int offset)
  216. {
  217. struct dw_pcie *pci = ks_pcie->pci;
  218. struct device *dev = pci->dev;
  219. u32 pending;
  220. int virq;
  221. pending = ks_dw_app_readl(ks_pcie, IRQ_STATUS + (offset << 4));
  222. if (BIT(0) & pending) {
  223. virq = irq_linear_revmap(ks_pcie->legacy_irq_domain, offset);
  224. dev_dbg(dev, ": irq: irq_offset %d, virq %d\n", offset, virq);
  225. generic_handle_irq(virq);
  226. }
  227. /* EOI the INTx interrupt */
  228. ks_dw_app_writel(ks_pcie, IRQ_EOI, offset);
  229. }
  230. void ks_dw_pcie_enable_error_irq(struct keystone_pcie *ks_pcie)
  231. {
  232. ks_dw_app_writel(ks_pcie, ERR_IRQ_ENABLE_SET, ERR_IRQ_ALL);
  233. }
  234. irqreturn_t ks_dw_pcie_handle_error_irq(struct keystone_pcie *ks_pcie)
  235. {
  236. u32 status;
  237. status = ks_dw_app_readl(ks_pcie, ERR_IRQ_STATUS_RAW) & ERR_IRQ_ALL;
  238. if (!status)
  239. return IRQ_NONE;
  240. if (status & ERR_FATAL_IRQ)
  241. dev_err(ks_pcie->pci->dev, "fatal error (status %#010x)\n",
  242. status);
  243. /* Ack the IRQ; status bits are RW1C */
  244. ks_dw_app_writel(ks_pcie, ERR_IRQ_STATUS, status);
  245. return IRQ_HANDLED;
  246. }
  247. static void ks_dw_pcie_ack_legacy_irq(struct irq_data *d)
  248. {
  249. }
  250. static void ks_dw_pcie_mask_legacy_irq(struct irq_data *d)
  251. {
  252. }
  253. static void ks_dw_pcie_unmask_legacy_irq(struct irq_data *d)
  254. {
  255. }
  256. static struct irq_chip ks_dw_pcie_legacy_irq_chip = {
  257. .name = "Keystone-PCI-Legacy-IRQ",
  258. .irq_ack = ks_dw_pcie_ack_legacy_irq,
  259. .irq_mask = ks_dw_pcie_mask_legacy_irq,
  260. .irq_unmask = ks_dw_pcie_unmask_legacy_irq,
  261. };
  262. static int ks_dw_pcie_init_legacy_irq_map(struct irq_domain *d,
  263. unsigned int irq, irq_hw_number_t hw_irq)
  264. {
  265. irq_set_chip_and_handler(irq, &ks_dw_pcie_legacy_irq_chip,
  266. handle_level_irq);
  267. irq_set_chip_data(irq, d->host_data);
  268. return 0;
  269. }
  270. static const struct irq_domain_ops ks_dw_pcie_legacy_irq_domain_ops = {
  271. .map = ks_dw_pcie_init_legacy_irq_map,
  272. .xlate = irq_domain_xlate_onetwocell,
  273. };
  274. /**
  275. * ks_dw_pcie_set_dbi_mode() - Set DBI mode to access overlaid BAR mask
  276. * registers
  277. *
  278. * Since modification of dbi_cs2 involves different clock domain, read the
  279. * status back to ensure the transition is complete.
  280. */
  281. static void ks_dw_pcie_set_dbi_mode(struct keystone_pcie *ks_pcie)
  282. {
  283. u32 val;
  284. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  285. ks_dw_app_writel(ks_pcie, CMD_STATUS, DBI_CS2_EN_VAL | val);
  286. do {
  287. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  288. } while (!(val & DBI_CS2_EN_VAL));
  289. }
  290. /**
  291. * ks_dw_pcie_clear_dbi_mode() - Disable DBI mode
  292. *
  293. * Since modification of dbi_cs2 involves different clock domain, read the
  294. * status back to ensure the transition is complete.
  295. */
  296. static void ks_dw_pcie_clear_dbi_mode(struct keystone_pcie *ks_pcie)
  297. {
  298. u32 val;
  299. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  300. ks_dw_app_writel(ks_pcie, CMD_STATUS, ~DBI_CS2_EN_VAL & val);
  301. do {
  302. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  303. } while (val & DBI_CS2_EN_VAL);
  304. }
  305. void ks_dw_pcie_setup_rc_app_regs(struct keystone_pcie *ks_pcie)
  306. {
  307. struct dw_pcie *pci = ks_pcie->pci;
  308. struct pcie_port *pp = &pci->pp;
  309. u32 start = pp->mem->start, end = pp->mem->end;
  310. int i, tr_size;
  311. u32 val;
  312. /* Disable BARs for inbound access */
  313. ks_dw_pcie_set_dbi_mode(ks_pcie);
  314. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 0);
  315. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_1, 0);
  316. ks_dw_pcie_clear_dbi_mode(ks_pcie);
  317. /* Set outbound translation size per window division */
  318. ks_dw_app_writel(ks_pcie, OB_SIZE, CFG_PCIM_WIN_SZ_IDX & 0x7);
  319. tr_size = (1 << (CFG_PCIM_WIN_SZ_IDX & 0x7)) * SZ_1M;
  320. /* Using Direct 1:1 mapping of RC <-> PCI memory space */
  321. for (i = 0; (i < CFG_PCIM_WIN_CNT) && (start < end); i++) {
  322. ks_dw_app_writel(ks_pcie, OB_OFFSET_INDEX(i), start | 1);
  323. ks_dw_app_writel(ks_pcie, OB_OFFSET_HI(i), 0);
  324. start += tr_size;
  325. }
  326. /* Enable OB translation */
  327. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  328. ks_dw_app_writel(ks_pcie, CMD_STATUS, OB_XLAT_EN_VAL | val);
  329. }
  330. /**
  331. * ks_pcie_cfg_setup() - Set up configuration space address for a device
  332. *
  333. * @ks_pcie: ptr to keystone_pcie structure
  334. * @bus: Bus number the device is residing on
  335. * @devfn: device, function number info
  336. *
  337. * Forms and returns the address of configuration space mapped in PCIESS
  338. * address space 0. Also configures CFG_SETUP for remote configuration space
  339. * access.
  340. *
  341. * The address space has two regions to access configuration - local and remote.
  342. * We access local region for bus 0 (as RC is attached on bus 0) and remote
  343. * region for others with TYPE 1 access when bus > 1. As for device on bus = 1,
  344. * we will do TYPE 0 access as it will be on our secondary bus (logical).
  345. * CFG_SETUP is needed only for remote configuration access.
  346. */
  347. static void __iomem *ks_pcie_cfg_setup(struct keystone_pcie *ks_pcie, u8 bus,
  348. unsigned int devfn)
  349. {
  350. u8 device = PCI_SLOT(devfn), function = PCI_FUNC(devfn);
  351. struct dw_pcie *pci = ks_pcie->pci;
  352. struct pcie_port *pp = &pci->pp;
  353. u32 regval;
  354. if (bus == 0)
  355. return pci->dbi_base;
  356. regval = (bus << 16) | (device << 8) | function;
  357. /*
  358. * Since Bus#1 will be a virtual bus, we need to have TYPE0
  359. * access only.
  360. * TYPE 1
  361. */
  362. if (bus != 1)
  363. regval |= BIT(24);
  364. ks_dw_app_writel(ks_pcie, CFG_SETUP, regval);
  365. return pp->va_cfg0_base;
  366. }
  367. int ks_dw_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  368. unsigned int devfn, int where, int size, u32 *val)
  369. {
  370. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  371. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  372. u8 bus_num = bus->number;
  373. void __iomem *addr;
  374. addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
  375. return dw_pcie_read(addr + where, size, val);
  376. }
  377. int ks_dw_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
  378. unsigned int devfn, int where, int size, u32 val)
  379. {
  380. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  381. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  382. u8 bus_num = bus->number;
  383. void __iomem *addr;
  384. addr = ks_pcie_cfg_setup(ks_pcie, bus_num, devfn);
  385. return dw_pcie_write(addr + where, size, val);
  386. }
  387. /**
  388. * ks_dw_pcie_v3_65_scan_bus() - keystone scan_bus post initialization
  389. *
  390. * This sets BAR0 to enable inbound access for MSI_IRQ register
  391. */
  392. void ks_dw_pcie_v3_65_scan_bus(struct pcie_port *pp)
  393. {
  394. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  395. struct keystone_pcie *ks_pcie = to_keystone_pcie(pci);
  396. /* Configure and set up BAR0 */
  397. ks_dw_pcie_set_dbi_mode(ks_pcie);
  398. /* Enable BAR0 */
  399. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, 1);
  400. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, SZ_4K - 1);
  401. ks_dw_pcie_clear_dbi_mode(ks_pcie);
  402. /*
  403. * For BAR0, just setting bus address for inbound writes (MSI) should
  404. * be sufficient. Use physical address to avoid any conflicts.
  405. */
  406. dw_pcie_writel_dbi(pci, PCI_BASE_ADDRESS_0, ks_pcie->app.start);
  407. }
  408. /**
  409. * ks_dw_pcie_link_up() - Check if link up
  410. */
  411. int ks_dw_pcie_link_up(struct dw_pcie *pci)
  412. {
  413. u32 val;
  414. val = dw_pcie_readl_dbi(pci, DEBUG0);
  415. return (val & LTSSM_STATE_MASK) == LTSSM_STATE_L0;
  416. }
  417. void ks_dw_pcie_initiate_link_train(struct keystone_pcie *ks_pcie)
  418. {
  419. u32 val;
  420. /* Disable Link training */
  421. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  422. val &= ~LTSSM_EN_VAL;
  423. ks_dw_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
  424. /* Initiate Link Training */
  425. val = ks_dw_app_readl(ks_pcie, CMD_STATUS);
  426. ks_dw_app_writel(ks_pcie, CMD_STATUS, LTSSM_EN_VAL | val);
  427. }
  428. /**
  429. * ks_dw_pcie_host_init() - initialize host for v3_65 dw hardware
  430. *
  431. * Ioremap the register resources, initialize legacy irq domain
  432. * and call dw_pcie_v3_65_host_init() API to initialize the Keystone
  433. * PCI host controller.
  434. */
  435. int __init ks_dw_pcie_host_init(struct keystone_pcie *ks_pcie,
  436. struct device_node *msi_intc_np)
  437. {
  438. struct dw_pcie *pci = ks_pcie->pci;
  439. struct pcie_port *pp = &pci->pp;
  440. struct device *dev = pci->dev;
  441. struct platform_device *pdev = to_platform_device(dev);
  442. struct resource *res;
  443. /* Index 0 is the config reg. space address */
  444. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  445. pci->dbi_base = devm_pci_remap_cfg_resource(dev, res);
  446. if (IS_ERR(pci->dbi_base))
  447. return PTR_ERR(pci->dbi_base);
  448. /*
  449. * We set these same and is used in pcie rd/wr_other_conf
  450. * functions
  451. */
  452. pp->va_cfg0_base = pci->dbi_base + SPACE0_REMOTE_CFG_OFFSET;
  453. pp->va_cfg1_base = pp->va_cfg0_base;
  454. /* Index 1 is the application reg. space address */
  455. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  456. ks_pcie->va_app_base = devm_ioremap_resource(dev, res);
  457. if (IS_ERR(ks_pcie->va_app_base))
  458. return PTR_ERR(ks_pcie->va_app_base);
  459. ks_pcie->app = *res;
  460. /* Create legacy IRQ domain */
  461. ks_pcie->legacy_irq_domain =
  462. irq_domain_add_linear(ks_pcie->legacy_intc_np,
  463. PCI_NUM_INTX,
  464. &ks_dw_pcie_legacy_irq_domain_ops,
  465. NULL);
  466. if (!ks_pcie->legacy_irq_domain) {
  467. dev_err(dev, "Failed to add irq domain for legacy irqs\n");
  468. return -EINVAL;
  469. }
  470. return dw_pcie_host_init(pp);
  471. }