pcie-xilinx.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * PCIe host controller driver for Xilinx AXI PCIe Bridge
  4. *
  5. * Copyright (c) 2012 - 2014 Xilinx, Inc.
  6. *
  7. * Based on the Tegra PCIe driver
  8. *
  9. * Bits taken from Synopsys DesignWare Host controller driver and
  10. * ARM PCI Host generic driver.
  11. */
  12. #include <linux/interrupt.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqdomain.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/msi.h>
  18. #include <linux/of_address.h>
  19. #include <linux/of_pci.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/of_irq.h>
  22. #include <linux/pci.h>
  23. #include <linux/pci-ecam.h>
  24. #include <linux/platform_device.h>
  25. #include "../pci.h"
  26. /* Register definitions */
  27. #define XILINX_PCIE_REG_BIR 0x00000130
  28. #define XILINX_PCIE_REG_IDR 0x00000138
  29. #define XILINX_PCIE_REG_IMR 0x0000013c
  30. #define XILINX_PCIE_REG_PSCR 0x00000144
  31. #define XILINX_PCIE_REG_RPSC 0x00000148
  32. #define XILINX_PCIE_REG_MSIBASE1 0x0000014c
  33. #define XILINX_PCIE_REG_MSIBASE2 0x00000150
  34. #define XILINX_PCIE_REG_RPEFR 0x00000154
  35. #define XILINX_PCIE_REG_RPIFR1 0x00000158
  36. #define XILINX_PCIE_REG_RPIFR2 0x0000015c
  37. /* Interrupt registers definitions */
  38. #define XILINX_PCIE_INTR_LINK_DOWN BIT(0)
  39. #define XILINX_PCIE_INTR_ECRC_ERR BIT(1)
  40. #define XILINX_PCIE_INTR_STR_ERR BIT(2)
  41. #define XILINX_PCIE_INTR_HOT_RESET BIT(3)
  42. #define XILINX_PCIE_INTR_CFG_TIMEOUT BIT(8)
  43. #define XILINX_PCIE_INTR_CORRECTABLE BIT(9)
  44. #define XILINX_PCIE_INTR_NONFATAL BIT(10)
  45. #define XILINX_PCIE_INTR_FATAL BIT(11)
  46. #define XILINX_PCIE_INTR_INTX BIT(16)
  47. #define XILINX_PCIE_INTR_MSI BIT(17)
  48. #define XILINX_PCIE_INTR_SLV_UNSUPP BIT(20)
  49. #define XILINX_PCIE_INTR_SLV_UNEXP BIT(21)
  50. #define XILINX_PCIE_INTR_SLV_COMPL BIT(22)
  51. #define XILINX_PCIE_INTR_SLV_ERRP BIT(23)
  52. #define XILINX_PCIE_INTR_SLV_CMPABT BIT(24)
  53. #define XILINX_PCIE_INTR_SLV_ILLBUR BIT(25)
  54. #define XILINX_PCIE_INTR_MST_DECERR BIT(26)
  55. #define XILINX_PCIE_INTR_MST_SLVERR BIT(27)
  56. #define XILINX_PCIE_INTR_MST_ERRP BIT(28)
  57. #define XILINX_PCIE_IMR_ALL_MASK 0x1FF30FED
  58. #define XILINX_PCIE_IMR_ENABLE_MASK 0x1FF30F0D
  59. #define XILINX_PCIE_IDR_ALL_MASK 0xFFFFFFFF
  60. /* Root Port Error FIFO Read Register definitions */
  61. #define XILINX_PCIE_RPEFR_ERR_VALID BIT(18)
  62. #define XILINX_PCIE_RPEFR_REQ_ID GENMASK(15, 0)
  63. #define XILINX_PCIE_RPEFR_ALL_MASK 0xFFFFFFFF
  64. /* Root Port Interrupt FIFO Read Register 1 definitions */
  65. #define XILINX_PCIE_RPIFR1_INTR_VALID BIT(31)
  66. #define XILINX_PCIE_RPIFR1_MSI_INTR BIT(30)
  67. #define XILINX_PCIE_RPIFR1_INTR_MASK GENMASK(28, 27)
  68. #define XILINX_PCIE_RPIFR1_ALL_MASK 0xFFFFFFFF
  69. #define XILINX_PCIE_RPIFR1_INTR_SHIFT 27
  70. /* Bridge Info Register definitions */
  71. #define XILINX_PCIE_BIR_ECAM_SZ_MASK GENMASK(18, 16)
  72. #define XILINX_PCIE_BIR_ECAM_SZ_SHIFT 16
  73. /* Root Port Interrupt FIFO Read Register 2 definitions */
  74. #define XILINX_PCIE_RPIFR2_MSG_DATA GENMASK(15, 0)
  75. /* Root Port Status/control Register definitions */
  76. #define XILINX_PCIE_REG_RPSC_BEN BIT(0)
  77. /* Phy Status/Control Register definitions */
  78. #define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
  79. /* Number of MSI IRQs */
  80. #define XILINX_NUM_MSI_IRQS 128
  81. /**
  82. * struct xilinx_pcie - PCIe port information
  83. * @dev: Device pointer
  84. * @reg_base: IO Mapped Register Base
  85. * @msi_map: Bitmap of allocated MSIs
  86. * @map_lock: Mutex protecting the MSI allocation
  87. * @msi_domain: MSI IRQ domain pointer
  88. * @leg_domain: Legacy IRQ domain pointer
  89. * @resources: Bus Resources
  90. */
  91. struct xilinx_pcie {
  92. struct device *dev;
  93. void __iomem *reg_base;
  94. unsigned long msi_map[BITS_TO_LONGS(XILINX_NUM_MSI_IRQS)];
  95. struct mutex map_lock;
  96. struct irq_domain *msi_domain;
  97. struct irq_domain *leg_domain;
  98. struct list_head resources;
  99. };
  100. static inline u32 pcie_read(struct xilinx_pcie *pcie, u32 reg)
  101. {
  102. return readl(pcie->reg_base + reg);
  103. }
  104. static inline void pcie_write(struct xilinx_pcie *pcie, u32 val, u32 reg)
  105. {
  106. writel(val, pcie->reg_base + reg);
  107. }
  108. static inline bool xilinx_pcie_link_up(struct xilinx_pcie *pcie)
  109. {
  110. return (pcie_read(pcie, XILINX_PCIE_REG_PSCR) &
  111. XILINX_PCIE_REG_PSCR_LNKUP) ? 1 : 0;
  112. }
  113. /**
  114. * xilinx_pcie_clear_err_interrupts - Clear Error Interrupts
  115. * @pcie: PCIe port information
  116. */
  117. static void xilinx_pcie_clear_err_interrupts(struct xilinx_pcie *pcie)
  118. {
  119. struct device *dev = pcie->dev;
  120. unsigned long val = pcie_read(pcie, XILINX_PCIE_REG_RPEFR);
  121. if (val & XILINX_PCIE_RPEFR_ERR_VALID) {
  122. dev_dbg(dev, "Requester ID %lu\n",
  123. val & XILINX_PCIE_RPEFR_REQ_ID);
  124. pcie_write(pcie, XILINX_PCIE_RPEFR_ALL_MASK,
  125. XILINX_PCIE_REG_RPEFR);
  126. }
  127. }
  128. /**
  129. * xilinx_pcie_valid_device - Check if a valid device is present on bus
  130. * @bus: PCI Bus structure
  131. * @devfn: device/function
  132. *
  133. * Return: 'true' on success and 'false' if invalid device is found
  134. */
  135. static bool xilinx_pcie_valid_device(struct pci_bus *bus, unsigned int devfn)
  136. {
  137. struct xilinx_pcie *pcie = bus->sysdata;
  138. /* Check if link is up when trying to access downstream pcie ports */
  139. if (!pci_is_root_bus(bus)) {
  140. if (!xilinx_pcie_link_up(pcie))
  141. return false;
  142. } else if (devfn > 0) {
  143. /* Only one device down on each root port */
  144. return false;
  145. }
  146. return true;
  147. }
  148. /**
  149. * xilinx_pcie_map_bus - Get configuration base
  150. * @bus: PCI Bus structure
  151. * @devfn: Device/function
  152. * @where: Offset from base
  153. *
  154. * Return: Base address of the configuration space needed to be
  155. * accessed.
  156. */
  157. static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
  158. unsigned int devfn, int where)
  159. {
  160. struct xilinx_pcie *pcie = bus->sysdata;
  161. if (!xilinx_pcie_valid_device(bus, devfn))
  162. return NULL;
  163. return pcie->reg_base + PCIE_ECAM_OFFSET(bus->number, devfn, where);
  164. }
  165. /* PCIe operations */
  166. static struct pci_ops xilinx_pcie_ops = {
  167. .map_bus = xilinx_pcie_map_bus,
  168. .read = pci_generic_config_read,
  169. .write = pci_generic_config_write,
  170. };
  171. /* MSI functions */
  172. static void xilinx_msi_top_irq_ack(struct irq_data *d)
  173. {
  174. /*
  175. * xilinx_pcie_intr_handler() will have performed the Ack.
  176. * Eventually, this should be fixed and the Ack be moved in
  177. * the respective callbacks for INTx and MSI.
  178. */
  179. }
  180. static struct irq_chip xilinx_msi_top_chip = {
  181. .name = "PCIe MSI",
  182. .irq_ack = xilinx_msi_top_irq_ack,
  183. };
  184. static int xilinx_msi_set_affinity(struct irq_data *d, const struct cpumask *mask, bool force)
  185. {
  186. return -EINVAL;
  187. }
  188. static void xilinx_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
  189. {
  190. struct xilinx_pcie *pcie = irq_data_get_irq_chip_data(data);
  191. phys_addr_t pa = ALIGN_DOWN(virt_to_phys(pcie), SZ_4K);
  192. msg->address_lo = lower_32_bits(pa);
  193. msg->address_hi = upper_32_bits(pa);
  194. msg->data = data->hwirq;
  195. }
  196. static struct irq_chip xilinx_msi_bottom_chip = {
  197. .name = "Xilinx MSI",
  198. .irq_set_affinity = xilinx_msi_set_affinity,
  199. .irq_compose_msi_msg = xilinx_compose_msi_msg,
  200. };
  201. static int xilinx_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
  202. unsigned int nr_irqs, void *args)
  203. {
  204. struct xilinx_pcie *pcie = domain->host_data;
  205. int hwirq, i;
  206. mutex_lock(&pcie->map_lock);
  207. hwirq = bitmap_find_free_region(pcie->msi_map, XILINX_NUM_MSI_IRQS, order_base_2(nr_irqs));
  208. mutex_unlock(&pcie->map_lock);
  209. if (hwirq < 0)
  210. return -ENOSPC;
  211. for (i = 0; i < nr_irqs; i++)
  212. irq_domain_set_info(domain, virq + i, hwirq + i,
  213. &xilinx_msi_bottom_chip, domain->host_data,
  214. handle_edge_irq, NULL, NULL);
  215. return 0;
  216. }
  217. static void xilinx_msi_domain_free(struct irq_domain *domain, unsigned int virq,
  218. unsigned int nr_irqs)
  219. {
  220. struct irq_data *d = irq_domain_get_irq_data(domain, virq);
  221. struct xilinx_pcie *pcie = domain->host_data;
  222. mutex_lock(&pcie->map_lock);
  223. bitmap_release_region(pcie->msi_map, d->hwirq, order_base_2(nr_irqs));
  224. mutex_unlock(&pcie->map_lock);
  225. }
  226. static const struct irq_domain_ops xilinx_msi_domain_ops = {
  227. .alloc = xilinx_msi_domain_alloc,
  228. .free = xilinx_msi_domain_free,
  229. };
  230. static struct msi_domain_info xilinx_msi_info = {
  231. .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS),
  232. .chip = &xilinx_msi_top_chip,
  233. };
  234. static int xilinx_allocate_msi_domains(struct xilinx_pcie *pcie)
  235. {
  236. struct fwnode_handle *fwnode = dev_fwnode(pcie->dev);
  237. struct irq_domain *parent;
  238. parent = irq_domain_create_linear(fwnode, XILINX_NUM_MSI_IRQS,
  239. &xilinx_msi_domain_ops, pcie);
  240. if (!parent) {
  241. dev_err(pcie->dev, "failed to create IRQ domain\n");
  242. return -ENOMEM;
  243. }
  244. irq_domain_update_bus_token(parent, DOMAIN_BUS_NEXUS);
  245. pcie->msi_domain = pci_msi_create_irq_domain(fwnode, &xilinx_msi_info, parent);
  246. if (!pcie->msi_domain) {
  247. dev_err(pcie->dev, "failed to create MSI domain\n");
  248. irq_domain_remove(parent);
  249. return -ENOMEM;
  250. }
  251. return 0;
  252. }
  253. static void xilinx_free_msi_domains(struct xilinx_pcie *pcie)
  254. {
  255. struct irq_domain *parent = pcie->msi_domain->parent;
  256. irq_domain_remove(pcie->msi_domain);
  257. irq_domain_remove(parent);
  258. }
  259. /* INTx Functions */
  260. /**
  261. * xilinx_pcie_intx_map - Set the handler for the INTx and mark IRQ as valid
  262. * @domain: IRQ domain
  263. * @irq: Virtual IRQ number
  264. * @hwirq: HW interrupt number
  265. *
  266. * Return: Always returns 0.
  267. */
  268. static int xilinx_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
  269. irq_hw_number_t hwirq)
  270. {
  271. irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
  272. irq_set_chip_data(irq, domain->host_data);
  273. return 0;
  274. }
  275. /* INTx IRQ Domain operations */
  276. static const struct irq_domain_ops intx_domain_ops = {
  277. .map = xilinx_pcie_intx_map,
  278. .xlate = pci_irqd_intx_xlate,
  279. };
  280. /* PCIe HW Functions */
  281. /**
  282. * xilinx_pcie_intr_handler - Interrupt Service Handler
  283. * @irq: IRQ number
  284. * @data: PCIe port information
  285. *
  286. * Return: IRQ_HANDLED on success and IRQ_NONE on failure
  287. */
  288. static irqreturn_t xilinx_pcie_intr_handler(int irq, void *data)
  289. {
  290. struct xilinx_pcie *pcie = (struct xilinx_pcie *)data;
  291. struct device *dev = pcie->dev;
  292. u32 val, mask, status;
  293. /* Read interrupt decode and mask registers */
  294. val = pcie_read(pcie, XILINX_PCIE_REG_IDR);
  295. mask = pcie_read(pcie, XILINX_PCIE_REG_IMR);
  296. status = val & mask;
  297. if (!status)
  298. return IRQ_NONE;
  299. if (status & XILINX_PCIE_INTR_LINK_DOWN)
  300. dev_warn(dev, "Link Down\n");
  301. if (status & XILINX_PCIE_INTR_ECRC_ERR)
  302. dev_warn(dev, "ECRC failed\n");
  303. if (status & XILINX_PCIE_INTR_STR_ERR)
  304. dev_warn(dev, "Streaming error\n");
  305. if (status & XILINX_PCIE_INTR_HOT_RESET)
  306. dev_info(dev, "Hot reset\n");
  307. if (status & XILINX_PCIE_INTR_CFG_TIMEOUT)
  308. dev_warn(dev, "ECAM access timeout\n");
  309. if (status & XILINX_PCIE_INTR_CORRECTABLE) {
  310. dev_warn(dev, "Correctable error message\n");
  311. xilinx_pcie_clear_err_interrupts(pcie);
  312. }
  313. if (status & XILINX_PCIE_INTR_NONFATAL) {
  314. dev_warn(dev, "Non fatal error message\n");
  315. xilinx_pcie_clear_err_interrupts(pcie);
  316. }
  317. if (status & XILINX_PCIE_INTR_FATAL) {
  318. dev_warn(dev, "Fatal error message\n");
  319. xilinx_pcie_clear_err_interrupts(pcie);
  320. }
  321. if (status & (XILINX_PCIE_INTR_INTX | XILINX_PCIE_INTR_MSI)) {
  322. struct irq_domain *domain;
  323. val = pcie_read(pcie, XILINX_PCIE_REG_RPIFR1);
  324. /* Check whether interrupt valid */
  325. if (!(val & XILINX_PCIE_RPIFR1_INTR_VALID)) {
  326. dev_warn(dev, "RP Intr FIFO1 read error\n");
  327. goto error;
  328. }
  329. /* Decode the IRQ number */
  330. if (val & XILINX_PCIE_RPIFR1_MSI_INTR) {
  331. val = pcie_read(pcie, XILINX_PCIE_REG_RPIFR2) &
  332. XILINX_PCIE_RPIFR2_MSG_DATA;
  333. domain = pcie->msi_domain->parent;
  334. } else {
  335. val = (val & XILINX_PCIE_RPIFR1_INTR_MASK) >>
  336. XILINX_PCIE_RPIFR1_INTR_SHIFT;
  337. domain = pcie->leg_domain;
  338. }
  339. /* Clear interrupt FIFO register 1 */
  340. pcie_write(pcie, XILINX_PCIE_RPIFR1_ALL_MASK,
  341. XILINX_PCIE_REG_RPIFR1);
  342. generic_handle_domain_irq(domain, val);
  343. }
  344. if (status & XILINX_PCIE_INTR_SLV_UNSUPP)
  345. dev_warn(dev, "Slave unsupported request\n");
  346. if (status & XILINX_PCIE_INTR_SLV_UNEXP)
  347. dev_warn(dev, "Slave unexpected completion\n");
  348. if (status & XILINX_PCIE_INTR_SLV_COMPL)
  349. dev_warn(dev, "Slave completion timeout\n");
  350. if (status & XILINX_PCIE_INTR_SLV_ERRP)
  351. dev_warn(dev, "Slave Error Poison\n");
  352. if (status & XILINX_PCIE_INTR_SLV_CMPABT)
  353. dev_warn(dev, "Slave Completer Abort\n");
  354. if (status & XILINX_PCIE_INTR_SLV_ILLBUR)
  355. dev_warn(dev, "Slave Illegal Burst\n");
  356. if (status & XILINX_PCIE_INTR_MST_DECERR)
  357. dev_warn(dev, "Master decode error\n");
  358. if (status & XILINX_PCIE_INTR_MST_SLVERR)
  359. dev_warn(dev, "Master slave error\n");
  360. if (status & XILINX_PCIE_INTR_MST_ERRP)
  361. dev_warn(dev, "Master error poison\n");
  362. error:
  363. /* Clear the Interrupt Decode register */
  364. pcie_write(pcie, status, XILINX_PCIE_REG_IDR);
  365. return IRQ_HANDLED;
  366. }
  367. /**
  368. * xilinx_pcie_init_irq_domain - Initialize IRQ domain
  369. * @pcie: PCIe port information
  370. *
  371. * Return: '0' on success and error value on failure
  372. */
  373. static int xilinx_pcie_init_irq_domain(struct xilinx_pcie *pcie)
  374. {
  375. struct device *dev = pcie->dev;
  376. struct device_node *pcie_intc_node;
  377. int ret;
  378. /* Setup INTx */
  379. pcie_intc_node = of_get_next_child(dev->of_node, NULL);
  380. if (!pcie_intc_node) {
  381. dev_err(dev, "No PCIe Intc node found\n");
  382. return -ENODEV;
  383. }
  384. pcie->leg_domain = irq_domain_add_linear(pcie_intc_node, PCI_NUM_INTX,
  385. &intx_domain_ops,
  386. pcie);
  387. of_node_put(pcie_intc_node);
  388. if (!pcie->leg_domain) {
  389. dev_err(dev, "Failed to get a INTx IRQ domain\n");
  390. return -ENODEV;
  391. }
  392. /* Setup MSI */
  393. if (IS_ENABLED(CONFIG_PCI_MSI)) {
  394. phys_addr_t pa = ALIGN_DOWN(virt_to_phys(pcie), SZ_4K);
  395. ret = xilinx_allocate_msi_domains(pcie);
  396. if (ret)
  397. return ret;
  398. pcie_write(pcie, upper_32_bits(pa), XILINX_PCIE_REG_MSIBASE1);
  399. pcie_write(pcie, lower_32_bits(pa), XILINX_PCIE_REG_MSIBASE2);
  400. }
  401. return 0;
  402. }
  403. /**
  404. * xilinx_pcie_init_port - Initialize hardware
  405. * @pcie: PCIe port information
  406. */
  407. static void xilinx_pcie_init_port(struct xilinx_pcie *pcie)
  408. {
  409. struct device *dev = pcie->dev;
  410. if (xilinx_pcie_link_up(pcie))
  411. dev_info(dev, "PCIe Link is UP\n");
  412. else
  413. dev_info(dev, "PCIe Link is DOWN\n");
  414. /* Disable all interrupts */
  415. pcie_write(pcie, ~XILINX_PCIE_IDR_ALL_MASK,
  416. XILINX_PCIE_REG_IMR);
  417. /* Clear pending interrupts */
  418. pcie_write(pcie, pcie_read(pcie, XILINX_PCIE_REG_IDR) &
  419. XILINX_PCIE_IMR_ALL_MASK,
  420. XILINX_PCIE_REG_IDR);
  421. /* Enable all interrupts we handle */
  422. pcie_write(pcie, XILINX_PCIE_IMR_ENABLE_MASK, XILINX_PCIE_REG_IMR);
  423. /* Enable the Bridge enable bit */
  424. pcie_write(pcie, pcie_read(pcie, XILINX_PCIE_REG_RPSC) |
  425. XILINX_PCIE_REG_RPSC_BEN,
  426. XILINX_PCIE_REG_RPSC);
  427. }
  428. /**
  429. * xilinx_pcie_parse_dt - Parse Device tree
  430. * @pcie: PCIe port information
  431. *
  432. * Return: '0' on success and error value on failure
  433. */
  434. static int xilinx_pcie_parse_dt(struct xilinx_pcie *pcie)
  435. {
  436. struct device *dev = pcie->dev;
  437. struct device_node *node = dev->of_node;
  438. struct resource regs;
  439. unsigned int irq;
  440. int err;
  441. err = of_address_to_resource(node, 0, &regs);
  442. if (err) {
  443. dev_err(dev, "missing \"reg\" property\n");
  444. return err;
  445. }
  446. pcie->reg_base = devm_pci_remap_cfg_resource(dev, &regs);
  447. if (IS_ERR(pcie->reg_base))
  448. return PTR_ERR(pcie->reg_base);
  449. irq = irq_of_parse_and_map(node, 0);
  450. err = devm_request_irq(dev, irq, xilinx_pcie_intr_handler,
  451. IRQF_SHARED | IRQF_NO_THREAD,
  452. "xilinx-pcie", pcie);
  453. if (err) {
  454. dev_err(dev, "unable to request irq %d\n", irq);
  455. return err;
  456. }
  457. return 0;
  458. }
  459. /**
  460. * xilinx_pcie_probe - Probe function
  461. * @pdev: Platform device pointer
  462. *
  463. * Return: '0' on success and error value on failure
  464. */
  465. static int xilinx_pcie_probe(struct platform_device *pdev)
  466. {
  467. struct device *dev = &pdev->dev;
  468. struct xilinx_pcie *pcie;
  469. struct pci_host_bridge *bridge;
  470. int err;
  471. if (!dev->of_node)
  472. return -ENODEV;
  473. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  474. if (!bridge)
  475. return -ENODEV;
  476. pcie = pci_host_bridge_priv(bridge);
  477. mutex_init(&pcie->map_lock);
  478. pcie->dev = dev;
  479. err = xilinx_pcie_parse_dt(pcie);
  480. if (err) {
  481. dev_err(dev, "Parsing DT failed\n");
  482. return err;
  483. }
  484. xilinx_pcie_init_port(pcie);
  485. err = xilinx_pcie_init_irq_domain(pcie);
  486. if (err) {
  487. dev_err(dev, "Failed creating IRQ Domain\n");
  488. return err;
  489. }
  490. bridge->sysdata = pcie;
  491. bridge->ops = &xilinx_pcie_ops;
  492. err = pci_host_probe(bridge);
  493. if (err)
  494. xilinx_free_msi_domains(pcie);
  495. return err;
  496. }
  497. static const struct of_device_id xilinx_pcie_of_match[] = {
  498. { .compatible = "xlnx,axi-pcie-host-1.00.a", },
  499. {}
  500. };
  501. static struct platform_driver xilinx_pcie_driver = {
  502. .driver = {
  503. .name = "xilinx-pcie",
  504. .of_match_table = xilinx_pcie_of_match,
  505. .suppress_bind_attrs = true,
  506. },
  507. .probe = xilinx_pcie_probe,
  508. };
  509. builtin_platform_driver(xilinx_pcie_driver);