pcie-xilinx.c 16 KB

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