pcie-mobiveil-host.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCIe host controller driver for Mobiveil PCIe Host controller
  4. *
  5. * Copyright (c) 2018 Mobiveil Inc.
  6. * Copyright 2019-2020 NXP
  7. *
  8. * Author: Subrahmanya Lingappa <[email protected]>
  9. * Hou Zhiqiang <[email protected]>
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqchip/chained_irq.h>
  15. #include <linux/irqdomain.h>
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/msi.h>
  19. #include <linux/of_address.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/of_pci.h>
  23. #include <linux/pci.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include "pcie-mobiveil.h"
  27. static bool mobiveil_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
  28. {
  29. /* Only one device down on each root port */
  30. if (pci_is_root_bus(bus) && (devfn > 0))
  31. return false;
  32. /*
  33. * Do not read more than one device on the bus directly
  34. * attached to RC
  35. */
  36. if ((bus->primary == to_pci_host_bridge(bus->bridge)->busnr) && (PCI_SLOT(devfn) > 0))
  37. return false;
  38. return true;
  39. }
  40. /*
  41. * mobiveil_pcie_map_bus - routine to get the configuration base of either
  42. * root port or endpoint
  43. */
  44. static void __iomem *mobiveil_pcie_map_bus(struct pci_bus *bus,
  45. unsigned int devfn, int where)
  46. {
  47. struct mobiveil_pcie *pcie = bus->sysdata;
  48. struct mobiveil_root_port *rp = &pcie->rp;
  49. u32 value;
  50. if (!mobiveil_pcie_valid_device(bus, devfn))
  51. return NULL;
  52. /* RC config access */
  53. if (pci_is_root_bus(bus))
  54. return pcie->csr_axi_slave_base + where;
  55. /*
  56. * EP config access (in Config/APIO space)
  57. * Program PEX Address base (31..16 bits) with appropriate value
  58. * (BDF) in PAB_AXI_AMAP_PEX_WIN_L0 Register.
  59. * Relies on pci_lock serialization
  60. */
  61. value = bus->number << PAB_BUS_SHIFT |
  62. PCI_SLOT(devfn) << PAB_DEVICE_SHIFT |
  63. PCI_FUNC(devfn) << PAB_FUNCTION_SHIFT;
  64. mobiveil_csr_writel(pcie, value, PAB_AXI_AMAP_PEX_WIN_L(WIN_NUM_0));
  65. return rp->config_axi_slave_base + where;
  66. }
  67. static struct pci_ops mobiveil_pcie_ops = {
  68. .map_bus = mobiveil_pcie_map_bus,
  69. .read = pci_generic_config_read,
  70. .write = pci_generic_config_write,
  71. };
  72. static void mobiveil_pcie_isr(struct irq_desc *desc)
  73. {
  74. struct irq_chip *chip = irq_desc_get_chip(desc);
  75. struct mobiveil_pcie *pcie = irq_desc_get_handler_data(desc);
  76. struct device *dev = &pcie->pdev->dev;
  77. struct mobiveil_root_port *rp = &pcie->rp;
  78. struct mobiveil_msi *msi = &rp->msi;
  79. u32 msi_data, msi_addr_lo, msi_addr_hi;
  80. u32 intr_status, msi_status;
  81. unsigned long shifted_status;
  82. u32 bit, val, mask;
  83. /*
  84. * The core provides a single interrupt for both INTx/MSI messages.
  85. * So we'll read both INTx and MSI status
  86. */
  87. chained_irq_enter(chip, desc);
  88. /* read INTx status */
  89. val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_STAT);
  90. mask = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  91. intr_status = val & mask;
  92. /* Handle INTx */
  93. if (intr_status & PAB_INTP_INTX_MASK) {
  94. shifted_status = mobiveil_csr_readl(pcie,
  95. PAB_INTP_AMBA_MISC_STAT);
  96. shifted_status &= PAB_INTP_INTX_MASK;
  97. shifted_status >>= PAB_INTX_START;
  98. do {
  99. for_each_set_bit(bit, &shifted_status, PCI_NUM_INTX) {
  100. int ret;
  101. ret = generic_handle_domain_irq(rp->intx_domain,
  102. bit + 1);
  103. if (ret)
  104. dev_err_ratelimited(dev, "unexpected IRQ, INT%d\n",
  105. bit);
  106. /* clear interrupt handled */
  107. mobiveil_csr_writel(pcie,
  108. 1 << (PAB_INTX_START + bit),
  109. PAB_INTP_AMBA_MISC_STAT);
  110. }
  111. shifted_status = mobiveil_csr_readl(pcie,
  112. PAB_INTP_AMBA_MISC_STAT);
  113. shifted_status &= PAB_INTP_INTX_MASK;
  114. shifted_status >>= PAB_INTX_START;
  115. } while (shifted_status != 0);
  116. }
  117. /* read extra MSI status register */
  118. msi_status = readl_relaxed(pcie->apb_csr_base + MSI_STATUS_OFFSET);
  119. /* handle MSI interrupts */
  120. while (msi_status & 1) {
  121. msi_data = readl_relaxed(pcie->apb_csr_base + MSI_DATA_OFFSET);
  122. /*
  123. * MSI_STATUS_OFFSET register gets updated to zero
  124. * once we pop not only the MSI data but also address
  125. * from MSI hardware FIFO. So keeping these following
  126. * two dummy reads.
  127. */
  128. msi_addr_lo = readl_relaxed(pcie->apb_csr_base +
  129. MSI_ADDR_L_OFFSET);
  130. msi_addr_hi = readl_relaxed(pcie->apb_csr_base +
  131. MSI_ADDR_H_OFFSET);
  132. dev_dbg(dev, "MSI registers, data: %08x, addr: %08x:%08x\n",
  133. msi_data, msi_addr_hi, msi_addr_lo);
  134. generic_handle_domain_irq(msi->dev_domain, msi_data);
  135. msi_status = readl_relaxed(pcie->apb_csr_base +
  136. MSI_STATUS_OFFSET);
  137. }
  138. /* Clear the interrupt status */
  139. mobiveil_csr_writel(pcie, intr_status, PAB_INTP_AMBA_MISC_STAT);
  140. chained_irq_exit(chip, desc);
  141. }
  142. static int mobiveil_pcie_parse_dt(struct mobiveil_pcie *pcie)
  143. {
  144. struct device *dev = &pcie->pdev->dev;
  145. struct platform_device *pdev = pcie->pdev;
  146. struct device_node *node = dev->of_node;
  147. struct mobiveil_root_port *rp = &pcie->rp;
  148. struct resource *res;
  149. /* map config resource */
  150. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  151. "config_axi_slave");
  152. rp->config_axi_slave_base = devm_pci_remap_cfg_resource(dev, res);
  153. if (IS_ERR(rp->config_axi_slave_base))
  154. return PTR_ERR(rp->config_axi_slave_base);
  155. rp->ob_io_res = res;
  156. /* map csr resource */
  157. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  158. "csr_axi_slave");
  159. pcie->csr_axi_slave_base = devm_pci_remap_cfg_resource(dev, res);
  160. if (IS_ERR(pcie->csr_axi_slave_base))
  161. return PTR_ERR(pcie->csr_axi_slave_base);
  162. pcie->pcie_reg_base = res->start;
  163. /* read the number of windows requested */
  164. if (of_property_read_u32(node, "apio-wins", &pcie->apio_wins))
  165. pcie->apio_wins = MAX_PIO_WINDOWS;
  166. if (of_property_read_u32(node, "ppio-wins", &pcie->ppio_wins))
  167. pcie->ppio_wins = MAX_PIO_WINDOWS;
  168. return 0;
  169. }
  170. static void mobiveil_pcie_enable_msi(struct mobiveil_pcie *pcie)
  171. {
  172. phys_addr_t msg_addr = pcie->pcie_reg_base;
  173. struct mobiveil_msi *msi = &pcie->rp.msi;
  174. msi->num_of_vectors = PCI_NUM_MSI;
  175. msi->msi_pages_phys = (phys_addr_t)msg_addr;
  176. writel_relaxed(lower_32_bits(msg_addr),
  177. pcie->apb_csr_base + MSI_BASE_LO_OFFSET);
  178. writel_relaxed(upper_32_bits(msg_addr),
  179. pcie->apb_csr_base + MSI_BASE_HI_OFFSET);
  180. writel_relaxed(4096, pcie->apb_csr_base + MSI_SIZE_OFFSET);
  181. writel_relaxed(1, pcie->apb_csr_base + MSI_ENABLE_OFFSET);
  182. }
  183. int mobiveil_host_init(struct mobiveil_pcie *pcie, bool reinit)
  184. {
  185. struct mobiveil_root_port *rp = &pcie->rp;
  186. struct pci_host_bridge *bridge = rp->bridge;
  187. u32 value, pab_ctrl, type;
  188. struct resource_entry *win;
  189. pcie->ib_wins_configured = 0;
  190. pcie->ob_wins_configured = 0;
  191. if (!reinit) {
  192. /* setup bus numbers */
  193. value = mobiveil_csr_readl(pcie, PCI_PRIMARY_BUS);
  194. value &= 0xff000000;
  195. value |= 0x00ff0100;
  196. mobiveil_csr_writel(pcie, value, PCI_PRIMARY_BUS);
  197. }
  198. /*
  199. * program Bus Master Enable Bit in Command Register in PAB Config
  200. * Space
  201. */
  202. value = mobiveil_csr_readl(pcie, PCI_COMMAND);
  203. value |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  204. mobiveil_csr_writel(pcie, value, PCI_COMMAND);
  205. /*
  206. * program PIO Enable Bit to 1 (and PEX PIO Enable to 1) in PAB_CTRL
  207. * register
  208. */
  209. pab_ctrl = mobiveil_csr_readl(pcie, PAB_CTRL);
  210. pab_ctrl |= (1 << AMBA_PIO_ENABLE_SHIFT) | (1 << PEX_PIO_ENABLE_SHIFT);
  211. mobiveil_csr_writel(pcie, pab_ctrl, PAB_CTRL);
  212. /*
  213. * program PIO Enable Bit to 1 and Config Window Enable Bit to 1 in
  214. * PAB_AXI_PIO_CTRL Register
  215. */
  216. value = mobiveil_csr_readl(pcie, PAB_AXI_PIO_CTRL);
  217. value |= APIO_EN_MASK;
  218. mobiveil_csr_writel(pcie, value, PAB_AXI_PIO_CTRL);
  219. /* Enable PCIe PIO master */
  220. value = mobiveil_csr_readl(pcie, PAB_PEX_PIO_CTRL);
  221. value |= 1 << PIO_ENABLE_SHIFT;
  222. mobiveil_csr_writel(pcie, value, PAB_PEX_PIO_CTRL);
  223. /*
  224. * we'll program one outbound window for config reads and
  225. * another default inbound window for all the upstream traffic
  226. * rest of the outbound windows will be configured according to
  227. * the "ranges" field defined in device tree
  228. */
  229. /* config outbound translation window */
  230. program_ob_windows(pcie, WIN_NUM_0, rp->ob_io_res->start, 0,
  231. CFG_WINDOW_TYPE, resource_size(rp->ob_io_res));
  232. /* memory inbound translation window */
  233. program_ib_windows(pcie, WIN_NUM_0, 0, 0, MEM_WINDOW_TYPE, IB_WIN_SIZE);
  234. /* Get the I/O and memory ranges from DT */
  235. resource_list_for_each_entry(win, &bridge->windows) {
  236. if (resource_type(win->res) == IORESOURCE_MEM)
  237. type = MEM_WINDOW_TYPE;
  238. else if (resource_type(win->res) == IORESOURCE_IO)
  239. type = IO_WINDOW_TYPE;
  240. else
  241. continue;
  242. /* configure outbound translation window */
  243. program_ob_windows(pcie, pcie->ob_wins_configured,
  244. win->res->start,
  245. win->res->start - win->offset,
  246. type, resource_size(win->res));
  247. }
  248. /* fixup for PCIe class register */
  249. value = mobiveil_csr_readl(pcie, PAB_INTP_AXI_PIO_CLASS);
  250. value &= 0xff;
  251. value |= PCI_CLASS_BRIDGE_PCI_NORMAL << 8;
  252. mobiveil_csr_writel(pcie, value, PAB_INTP_AXI_PIO_CLASS);
  253. return 0;
  254. }
  255. static void mobiveil_mask_intx_irq(struct irq_data *data)
  256. {
  257. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  258. struct mobiveil_root_port *rp;
  259. unsigned long flags;
  260. u32 mask, shifted_val;
  261. rp = &pcie->rp;
  262. mask = 1 << ((data->hwirq + PAB_INTX_START) - 1);
  263. raw_spin_lock_irqsave(&rp->intx_mask_lock, flags);
  264. shifted_val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  265. shifted_val &= ~mask;
  266. mobiveil_csr_writel(pcie, shifted_val, PAB_INTP_AMBA_MISC_ENB);
  267. raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags);
  268. }
  269. static void mobiveil_unmask_intx_irq(struct irq_data *data)
  270. {
  271. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  272. struct mobiveil_root_port *rp;
  273. unsigned long flags;
  274. u32 shifted_val, mask;
  275. rp = &pcie->rp;
  276. mask = 1 << ((data->hwirq + PAB_INTX_START) - 1);
  277. raw_spin_lock_irqsave(&rp->intx_mask_lock, flags);
  278. shifted_val = mobiveil_csr_readl(pcie, PAB_INTP_AMBA_MISC_ENB);
  279. shifted_val |= mask;
  280. mobiveil_csr_writel(pcie, shifted_val, PAB_INTP_AMBA_MISC_ENB);
  281. raw_spin_unlock_irqrestore(&rp->intx_mask_lock, flags);
  282. }
  283. static struct irq_chip intx_irq_chip = {
  284. .name = "mobiveil_pcie:intx",
  285. .irq_enable = mobiveil_unmask_intx_irq,
  286. .irq_disable = mobiveil_mask_intx_irq,
  287. .irq_mask = mobiveil_mask_intx_irq,
  288. .irq_unmask = mobiveil_unmask_intx_irq,
  289. };
  290. /* routine to setup the INTx related data */
  291. static int mobiveil_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
  292. irq_hw_number_t hwirq)
  293. {
  294. irq_set_chip_and_handler(irq, &intx_irq_chip, handle_level_irq);
  295. irq_set_chip_data(irq, domain->host_data);
  296. return 0;
  297. }
  298. /* INTx domain operations structure */
  299. static const struct irq_domain_ops intx_domain_ops = {
  300. .map = mobiveil_pcie_intx_map,
  301. };
  302. static struct irq_chip mobiveil_msi_irq_chip = {
  303. .name = "Mobiveil PCIe MSI",
  304. .irq_mask = pci_msi_mask_irq,
  305. .irq_unmask = pci_msi_unmask_irq,
  306. };
  307. static struct msi_domain_info mobiveil_msi_domain_info = {
  308. .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
  309. MSI_FLAG_PCI_MSIX),
  310. .chip = &mobiveil_msi_irq_chip,
  311. };
  312. static void mobiveil_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
  313. {
  314. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(data);
  315. phys_addr_t addr = pcie->pcie_reg_base + (data->hwirq * sizeof(int));
  316. msg->address_lo = lower_32_bits(addr);
  317. msg->address_hi = upper_32_bits(addr);
  318. msg->data = data->hwirq;
  319. dev_dbg(&pcie->pdev->dev, "msi#%d address_hi %#x address_lo %#x\n",
  320. (int)data->hwirq, msg->address_hi, msg->address_lo);
  321. }
  322. static int mobiveil_msi_set_affinity(struct irq_data *irq_data,
  323. const struct cpumask *mask, bool force)
  324. {
  325. return -EINVAL;
  326. }
  327. static struct irq_chip mobiveil_msi_bottom_irq_chip = {
  328. .name = "Mobiveil MSI",
  329. .irq_compose_msi_msg = mobiveil_compose_msi_msg,
  330. .irq_set_affinity = mobiveil_msi_set_affinity,
  331. };
  332. static int mobiveil_irq_msi_domain_alloc(struct irq_domain *domain,
  333. unsigned int virq,
  334. unsigned int nr_irqs, void *args)
  335. {
  336. struct mobiveil_pcie *pcie = domain->host_data;
  337. struct mobiveil_msi *msi = &pcie->rp.msi;
  338. unsigned long bit;
  339. WARN_ON(nr_irqs != 1);
  340. mutex_lock(&msi->lock);
  341. bit = find_first_zero_bit(msi->msi_irq_in_use, msi->num_of_vectors);
  342. if (bit >= msi->num_of_vectors) {
  343. mutex_unlock(&msi->lock);
  344. return -ENOSPC;
  345. }
  346. set_bit(bit, msi->msi_irq_in_use);
  347. mutex_unlock(&msi->lock);
  348. irq_domain_set_info(domain, virq, bit, &mobiveil_msi_bottom_irq_chip,
  349. domain->host_data, handle_level_irq, NULL, NULL);
  350. return 0;
  351. }
  352. static void mobiveil_irq_msi_domain_free(struct irq_domain *domain,
  353. unsigned int virq,
  354. unsigned int nr_irqs)
  355. {
  356. struct irq_data *d = irq_domain_get_irq_data(domain, virq);
  357. struct mobiveil_pcie *pcie = irq_data_get_irq_chip_data(d);
  358. struct mobiveil_msi *msi = &pcie->rp.msi;
  359. mutex_lock(&msi->lock);
  360. if (!test_bit(d->hwirq, msi->msi_irq_in_use))
  361. dev_err(&pcie->pdev->dev, "trying to free unused MSI#%lu\n",
  362. d->hwirq);
  363. else
  364. __clear_bit(d->hwirq, msi->msi_irq_in_use);
  365. mutex_unlock(&msi->lock);
  366. }
  367. static const struct irq_domain_ops msi_domain_ops = {
  368. .alloc = mobiveil_irq_msi_domain_alloc,
  369. .free = mobiveil_irq_msi_domain_free,
  370. };
  371. static int mobiveil_allocate_msi_domains(struct mobiveil_pcie *pcie)
  372. {
  373. struct device *dev = &pcie->pdev->dev;
  374. struct fwnode_handle *fwnode = of_node_to_fwnode(dev->of_node);
  375. struct mobiveil_msi *msi = &pcie->rp.msi;
  376. mutex_init(&msi->lock);
  377. msi->dev_domain = irq_domain_add_linear(NULL, msi->num_of_vectors,
  378. &msi_domain_ops, pcie);
  379. if (!msi->dev_domain) {
  380. dev_err(dev, "failed to create IRQ domain\n");
  381. return -ENOMEM;
  382. }
  383. msi->msi_domain = pci_msi_create_irq_domain(fwnode,
  384. &mobiveil_msi_domain_info,
  385. msi->dev_domain);
  386. if (!msi->msi_domain) {
  387. dev_err(dev, "failed to create MSI domain\n");
  388. irq_domain_remove(msi->dev_domain);
  389. return -ENOMEM;
  390. }
  391. return 0;
  392. }
  393. static int mobiveil_pcie_init_irq_domain(struct mobiveil_pcie *pcie)
  394. {
  395. struct device *dev = &pcie->pdev->dev;
  396. struct device_node *node = dev->of_node;
  397. struct mobiveil_root_port *rp = &pcie->rp;
  398. /* setup INTx */
  399. rp->intx_domain = irq_domain_add_linear(node, PCI_NUM_INTX,
  400. &intx_domain_ops, pcie);
  401. if (!rp->intx_domain) {
  402. dev_err(dev, "Failed to get a INTx IRQ domain\n");
  403. return -ENOMEM;
  404. }
  405. raw_spin_lock_init(&rp->intx_mask_lock);
  406. /* setup MSI */
  407. return mobiveil_allocate_msi_domains(pcie);
  408. }
  409. static int mobiveil_pcie_integrated_interrupt_init(struct mobiveil_pcie *pcie)
  410. {
  411. struct platform_device *pdev = pcie->pdev;
  412. struct device *dev = &pdev->dev;
  413. struct mobiveil_root_port *rp = &pcie->rp;
  414. struct resource *res;
  415. int ret;
  416. /* map MSI config resource */
  417. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "apb_csr");
  418. pcie->apb_csr_base = devm_pci_remap_cfg_resource(dev, res);
  419. if (IS_ERR(pcie->apb_csr_base))
  420. return PTR_ERR(pcie->apb_csr_base);
  421. /* setup MSI hardware registers */
  422. mobiveil_pcie_enable_msi(pcie);
  423. rp->irq = platform_get_irq(pdev, 0);
  424. if (rp->irq < 0)
  425. return rp->irq;
  426. /* initialize the IRQ domains */
  427. ret = mobiveil_pcie_init_irq_domain(pcie);
  428. if (ret) {
  429. dev_err(dev, "Failed creating IRQ Domain\n");
  430. return ret;
  431. }
  432. irq_set_chained_handler_and_data(rp->irq, mobiveil_pcie_isr, pcie);
  433. /* Enable interrupts */
  434. mobiveil_csr_writel(pcie, (PAB_INTP_INTX_MASK | PAB_INTP_MSI_MASK),
  435. PAB_INTP_AMBA_MISC_ENB);
  436. return 0;
  437. }
  438. static int mobiveil_pcie_interrupt_init(struct mobiveil_pcie *pcie)
  439. {
  440. struct mobiveil_root_port *rp = &pcie->rp;
  441. if (rp->ops->interrupt_init)
  442. return rp->ops->interrupt_init(pcie);
  443. return mobiveil_pcie_integrated_interrupt_init(pcie);
  444. }
  445. static bool mobiveil_pcie_is_bridge(struct mobiveil_pcie *pcie)
  446. {
  447. u32 header_type;
  448. header_type = mobiveil_csr_readb(pcie, PCI_HEADER_TYPE);
  449. header_type &= 0x7f;
  450. return header_type == PCI_HEADER_TYPE_BRIDGE;
  451. }
  452. int mobiveil_pcie_host_probe(struct mobiveil_pcie *pcie)
  453. {
  454. struct mobiveil_root_port *rp = &pcie->rp;
  455. struct pci_host_bridge *bridge = rp->bridge;
  456. struct device *dev = &pcie->pdev->dev;
  457. int ret;
  458. ret = mobiveil_pcie_parse_dt(pcie);
  459. if (ret) {
  460. dev_err(dev, "Parsing DT failed, ret: %x\n", ret);
  461. return ret;
  462. }
  463. if (!mobiveil_pcie_is_bridge(pcie))
  464. return -ENODEV;
  465. /*
  466. * configure all inbound and outbound windows and prepare the RC for
  467. * config access
  468. */
  469. ret = mobiveil_host_init(pcie, false);
  470. if (ret) {
  471. dev_err(dev, "Failed to initialize host\n");
  472. return ret;
  473. }
  474. ret = mobiveil_pcie_interrupt_init(pcie);
  475. if (ret) {
  476. dev_err(dev, "Interrupt init failed\n");
  477. return ret;
  478. }
  479. /* Initialize bridge */
  480. bridge->sysdata = pcie;
  481. bridge->ops = &mobiveil_pcie_ops;
  482. ret = mobiveil_bringup_link(pcie);
  483. if (ret) {
  484. dev_info(dev, "link bring-up failed\n");
  485. return ret;
  486. }
  487. return pci_host_probe(bridge);
  488. }