pcie-altera.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * Copyright Altera Corporation (C) 2013-2015. All rights reserved
  3. *
  4. * Author: Ley Foon Tan <lftan@altera.com>
  5. * Description: Altera PCIe host controller driver
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/irqchip/chained_irq.h>
  22. #include <linux/init.h>
  23. #include <linux/of_address.h>
  24. #include <linux/of_irq.h>
  25. #include <linux/of_pci.h>
  26. #include <linux/pci.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/slab.h>
  29. #define RP_TX_REG0 0x2000
  30. #define RP_TX_REG1 0x2004
  31. #define RP_TX_CNTRL 0x2008
  32. #define RP_TX_EOP 0x2
  33. #define RP_TX_SOP 0x1
  34. #define RP_RXCPL_STATUS 0x2010
  35. #define RP_RXCPL_EOP 0x2
  36. #define RP_RXCPL_SOP 0x1
  37. #define RP_RXCPL_REG0 0x2014
  38. #define RP_RXCPL_REG1 0x2018
  39. #define P2A_INT_STATUS 0x3060
  40. #define P2A_INT_STS_ALL 0xf
  41. #define P2A_INT_ENABLE 0x3070
  42. #define P2A_INT_ENA_ALL 0xf
  43. #define RP_LTSSM 0x3c64
  44. #define RP_LTSSM_MASK 0x1f
  45. #define LTSSM_L0 0xf
  46. #define PCIE_CAP_OFFSET 0x80
  47. /* TLP configuration type 0 and 1 */
  48. #define TLP_FMTTYPE_CFGRD0 0x04 /* Configuration Read Type 0 */
  49. #define TLP_FMTTYPE_CFGWR0 0x44 /* Configuration Write Type 0 */
  50. #define TLP_FMTTYPE_CFGRD1 0x05 /* Configuration Read Type 1 */
  51. #define TLP_FMTTYPE_CFGWR1 0x45 /* Configuration Write Type 1 */
  52. #define TLP_PAYLOAD_SIZE 0x01
  53. #define TLP_READ_TAG 0x1d
  54. #define TLP_WRITE_TAG 0x10
  55. #define RP_DEVFN 0
  56. #define TLP_REQ_ID(bus, devfn) (((bus) << 8) | (devfn))
  57. #define TLP_CFGRD_DW0(pcie, bus) \
  58. ((((bus == pcie->root_bus_nr) ? TLP_FMTTYPE_CFGRD0 \
  59. : TLP_FMTTYPE_CFGRD1) << 24) | \
  60. TLP_PAYLOAD_SIZE)
  61. #define TLP_CFGWR_DW0(pcie, bus) \
  62. ((((bus == pcie->root_bus_nr) ? TLP_FMTTYPE_CFGWR0 \
  63. : TLP_FMTTYPE_CFGWR1) << 24) | \
  64. TLP_PAYLOAD_SIZE)
  65. #define TLP_CFG_DW1(pcie, tag, be) \
  66. (((TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN)) << 16) | (tag << 8) | (be))
  67. #define TLP_CFG_DW2(bus, devfn, offset) \
  68. (((bus) << 24) | ((devfn) << 16) | (offset))
  69. #define TLP_COMP_STATUS(s) (((s) >> 13) & 7)
  70. #define TLP_HDR_SIZE 3
  71. #define TLP_LOOP 500
  72. #define LINK_UP_TIMEOUT HZ
  73. #define LINK_RETRAIN_TIMEOUT HZ
  74. #define DWORD_MASK 3
  75. struct altera_pcie {
  76. struct platform_device *pdev;
  77. void __iomem *cra_base; /* DT Cra */
  78. int irq;
  79. u8 root_bus_nr;
  80. struct irq_domain *irq_domain;
  81. struct resource bus_range;
  82. struct list_head resources;
  83. };
  84. struct tlp_rp_regpair_t {
  85. u32 ctrl;
  86. u32 reg0;
  87. u32 reg1;
  88. };
  89. static inline void cra_writel(struct altera_pcie *pcie, const u32 value,
  90. const u32 reg)
  91. {
  92. writel_relaxed(value, pcie->cra_base + reg);
  93. }
  94. static inline u32 cra_readl(struct altera_pcie *pcie, const u32 reg)
  95. {
  96. return readl_relaxed(pcie->cra_base + reg);
  97. }
  98. static bool altera_pcie_link_is_up(struct altera_pcie *pcie)
  99. {
  100. return !!((cra_readl(pcie, RP_LTSSM) & RP_LTSSM_MASK) == LTSSM_L0);
  101. }
  102. /*
  103. * Altera PCIe port uses BAR0 of RC's configuration space as the translation
  104. * from PCI bus to native BUS. Entire DDR region is mapped into PCIe space
  105. * using these registers, so it can be reached by DMA from EP devices.
  106. * This BAR0 will also access to MSI vector when receiving MSI/MSIX interrupt
  107. * from EP devices, eventually trigger interrupt to GIC. The BAR0 of bridge
  108. * should be hidden during enumeration to avoid the sizing and resource
  109. * allocation by PCIe core.
  110. */
  111. static bool altera_pcie_hide_rc_bar(struct pci_bus *bus, unsigned int devfn,
  112. int offset)
  113. {
  114. if (pci_is_root_bus(bus) && (devfn == 0) &&
  115. (offset == PCI_BASE_ADDRESS_0))
  116. return true;
  117. return false;
  118. }
  119. static void tlp_write_tx(struct altera_pcie *pcie,
  120. struct tlp_rp_regpair_t *tlp_rp_regdata)
  121. {
  122. cra_writel(pcie, tlp_rp_regdata->reg0, RP_TX_REG0);
  123. cra_writel(pcie, tlp_rp_regdata->reg1, RP_TX_REG1);
  124. cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
  125. }
  126. static bool altera_pcie_valid_device(struct altera_pcie *pcie,
  127. struct pci_bus *bus, int dev)
  128. {
  129. /* If there is no link, then there is no device */
  130. if (bus->number != pcie->root_bus_nr) {
  131. if (!altera_pcie_link_is_up(pcie))
  132. return false;
  133. }
  134. /* access only one slot on each root port */
  135. if (bus->number == pcie->root_bus_nr && dev > 0)
  136. return false;
  137. return true;
  138. }
  139. static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
  140. {
  141. int i;
  142. bool sop = 0;
  143. u32 ctrl;
  144. u32 reg0, reg1;
  145. u32 comp_status = 1;
  146. /*
  147. * Minimum 2 loops to read TLP headers and 1 loop to read data
  148. * payload.
  149. */
  150. for (i = 0; i < TLP_LOOP; i++) {
  151. ctrl = cra_readl(pcie, RP_RXCPL_STATUS);
  152. if ((ctrl & RP_RXCPL_SOP) || (ctrl & RP_RXCPL_EOP) || sop) {
  153. reg0 = cra_readl(pcie, RP_RXCPL_REG0);
  154. reg1 = cra_readl(pcie, RP_RXCPL_REG1);
  155. if (ctrl & RP_RXCPL_SOP) {
  156. sop = true;
  157. comp_status = TLP_COMP_STATUS(reg1);
  158. }
  159. if (ctrl & RP_RXCPL_EOP) {
  160. if (comp_status)
  161. return PCIBIOS_DEVICE_NOT_FOUND;
  162. if (value)
  163. *value = reg0;
  164. return PCIBIOS_SUCCESSFUL;
  165. }
  166. }
  167. udelay(5);
  168. }
  169. return PCIBIOS_DEVICE_NOT_FOUND;
  170. }
  171. static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
  172. u32 data, bool align)
  173. {
  174. struct tlp_rp_regpair_t tlp_rp_regdata;
  175. tlp_rp_regdata.reg0 = headers[0];
  176. tlp_rp_regdata.reg1 = headers[1];
  177. tlp_rp_regdata.ctrl = RP_TX_SOP;
  178. tlp_write_tx(pcie, &tlp_rp_regdata);
  179. if (align) {
  180. tlp_rp_regdata.reg0 = headers[2];
  181. tlp_rp_regdata.reg1 = 0;
  182. tlp_rp_regdata.ctrl = 0;
  183. tlp_write_tx(pcie, &tlp_rp_regdata);
  184. tlp_rp_regdata.reg0 = data;
  185. tlp_rp_regdata.reg1 = 0;
  186. } else {
  187. tlp_rp_regdata.reg0 = headers[2];
  188. tlp_rp_regdata.reg1 = data;
  189. }
  190. tlp_rp_regdata.ctrl = RP_TX_EOP;
  191. tlp_write_tx(pcie, &tlp_rp_regdata);
  192. }
  193. static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
  194. int where, u8 byte_en, u32 *value)
  195. {
  196. u32 headers[TLP_HDR_SIZE];
  197. headers[0] = TLP_CFGRD_DW0(pcie, bus);
  198. headers[1] = TLP_CFG_DW1(pcie, TLP_READ_TAG, byte_en);
  199. headers[2] = TLP_CFG_DW2(bus, devfn, where);
  200. tlp_write_packet(pcie, headers, 0, false);
  201. return tlp_read_packet(pcie, value);
  202. }
  203. static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
  204. int where, u8 byte_en, u32 value)
  205. {
  206. u32 headers[TLP_HDR_SIZE];
  207. int ret;
  208. headers[0] = TLP_CFGWR_DW0(pcie, bus);
  209. headers[1] = TLP_CFG_DW1(pcie, TLP_WRITE_TAG, byte_en);
  210. headers[2] = TLP_CFG_DW2(bus, devfn, where);
  211. /* check alignment to Qword */
  212. if ((where & 0x7) == 0)
  213. tlp_write_packet(pcie, headers, value, true);
  214. else
  215. tlp_write_packet(pcie, headers, value, false);
  216. ret = tlp_read_packet(pcie, NULL);
  217. if (ret != PCIBIOS_SUCCESSFUL)
  218. return ret;
  219. /*
  220. * Monitor changes to PCI_PRIMARY_BUS register on root port
  221. * and update local copy of root bus number accordingly.
  222. */
  223. if ((bus == pcie->root_bus_nr) && (where == PCI_PRIMARY_BUS))
  224. pcie->root_bus_nr = (u8)(value);
  225. return PCIBIOS_SUCCESSFUL;
  226. }
  227. static int _altera_pcie_cfg_read(struct altera_pcie *pcie, u8 busno,
  228. unsigned int devfn, int where, int size,
  229. u32 *value)
  230. {
  231. int ret;
  232. u32 data;
  233. u8 byte_en;
  234. switch (size) {
  235. case 1:
  236. byte_en = 1 << (where & 3);
  237. break;
  238. case 2:
  239. byte_en = 3 << (where & 3);
  240. break;
  241. default:
  242. byte_en = 0xf;
  243. break;
  244. }
  245. ret = tlp_cfg_dword_read(pcie, busno, devfn,
  246. (where & ~DWORD_MASK), byte_en, &data);
  247. if (ret != PCIBIOS_SUCCESSFUL)
  248. return ret;
  249. switch (size) {
  250. case 1:
  251. *value = (data >> (8 * (where & 0x3))) & 0xff;
  252. break;
  253. case 2:
  254. *value = (data >> (8 * (where & 0x2))) & 0xffff;
  255. break;
  256. default:
  257. *value = data;
  258. break;
  259. }
  260. return PCIBIOS_SUCCESSFUL;
  261. }
  262. static int _altera_pcie_cfg_write(struct altera_pcie *pcie, u8 busno,
  263. unsigned int devfn, int where, int size,
  264. u32 value)
  265. {
  266. u32 data32;
  267. u32 shift = 8 * (where & 3);
  268. u8 byte_en;
  269. switch (size) {
  270. case 1:
  271. data32 = (value & 0xff) << shift;
  272. byte_en = 1 << (where & 3);
  273. break;
  274. case 2:
  275. data32 = (value & 0xffff) << shift;
  276. byte_en = 3 << (where & 3);
  277. break;
  278. default:
  279. data32 = value;
  280. byte_en = 0xf;
  281. break;
  282. }
  283. return tlp_cfg_dword_write(pcie, busno, devfn, (where & ~DWORD_MASK),
  284. byte_en, data32);
  285. }
  286. static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn,
  287. int where, int size, u32 *value)
  288. {
  289. struct altera_pcie *pcie = bus->sysdata;
  290. if (altera_pcie_hide_rc_bar(bus, devfn, where))
  291. return PCIBIOS_BAD_REGISTER_NUMBER;
  292. if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) {
  293. *value = 0xffffffff;
  294. return PCIBIOS_DEVICE_NOT_FOUND;
  295. }
  296. return _altera_pcie_cfg_read(pcie, bus->number, devfn, where, size,
  297. value);
  298. }
  299. static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn,
  300. int where, int size, u32 value)
  301. {
  302. struct altera_pcie *pcie = bus->sysdata;
  303. if (altera_pcie_hide_rc_bar(bus, devfn, where))
  304. return PCIBIOS_BAD_REGISTER_NUMBER;
  305. if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn)))
  306. return PCIBIOS_DEVICE_NOT_FOUND;
  307. return _altera_pcie_cfg_write(pcie, bus->number, devfn, where, size,
  308. value);
  309. }
  310. static struct pci_ops altera_pcie_ops = {
  311. .read = altera_pcie_cfg_read,
  312. .write = altera_pcie_cfg_write,
  313. };
  314. static int altera_read_cap_word(struct altera_pcie *pcie, u8 busno,
  315. unsigned int devfn, int offset, u16 *value)
  316. {
  317. u32 data;
  318. int ret;
  319. ret = _altera_pcie_cfg_read(pcie, busno, devfn,
  320. PCIE_CAP_OFFSET + offset, sizeof(*value),
  321. &data);
  322. *value = data;
  323. return ret;
  324. }
  325. static int altera_write_cap_word(struct altera_pcie *pcie, u8 busno,
  326. unsigned int devfn, int offset, u16 value)
  327. {
  328. return _altera_pcie_cfg_write(pcie, busno, devfn,
  329. PCIE_CAP_OFFSET + offset, sizeof(value),
  330. value);
  331. }
  332. static void altera_wait_link_retrain(struct altera_pcie *pcie)
  333. {
  334. struct device *dev = &pcie->pdev->dev;
  335. u16 reg16;
  336. unsigned long start_jiffies;
  337. /* Wait for link training end. */
  338. start_jiffies = jiffies;
  339. for (;;) {
  340. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  341. PCI_EXP_LNKSTA, &reg16);
  342. if (!(reg16 & PCI_EXP_LNKSTA_LT))
  343. break;
  344. if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) {
  345. dev_err(dev, "link retrain timeout\n");
  346. break;
  347. }
  348. udelay(100);
  349. }
  350. /* Wait for link is up */
  351. start_jiffies = jiffies;
  352. for (;;) {
  353. if (altera_pcie_link_is_up(pcie))
  354. break;
  355. if (time_after(jiffies, start_jiffies + LINK_UP_TIMEOUT)) {
  356. dev_err(dev, "link up timeout\n");
  357. break;
  358. }
  359. udelay(100);
  360. }
  361. }
  362. static void altera_pcie_retrain(struct altera_pcie *pcie)
  363. {
  364. u16 linkcap, linkstat, linkctl;
  365. if (!altera_pcie_link_is_up(pcie))
  366. return;
  367. /*
  368. * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but
  369. * current speed is 2.5 GB/s.
  370. */
  371. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKCAP,
  372. &linkcap);
  373. if ((linkcap & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB)
  374. return;
  375. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKSTA,
  376. &linkstat);
  377. if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) {
  378. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  379. PCI_EXP_LNKCTL, &linkctl);
  380. linkctl |= PCI_EXP_LNKCTL_RL;
  381. altera_write_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  382. PCI_EXP_LNKCTL, linkctl);
  383. altera_wait_link_retrain(pcie);
  384. }
  385. }
  386. static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
  387. irq_hw_number_t hwirq)
  388. {
  389. irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
  390. irq_set_chip_data(irq, domain->host_data);
  391. return 0;
  392. }
  393. static const struct irq_domain_ops intx_domain_ops = {
  394. .map = altera_pcie_intx_map,
  395. .xlate = pci_irqd_intx_xlate,
  396. };
  397. static void altera_pcie_isr(struct irq_desc *desc)
  398. {
  399. struct irq_chip *chip = irq_desc_get_chip(desc);
  400. struct altera_pcie *pcie;
  401. struct device *dev;
  402. unsigned long status;
  403. u32 bit;
  404. u32 virq;
  405. chained_irq_enter(chip, desc);
  406. pcie = irq_desc_get_handler_data(desc);
  407. dev = &pcie->pdev->dev;
  408. while ((status = cra_readl(pcie, P2A_INT_STATUS)
  409. & P2A_INT_STS_ALL) != 0) {
  410. for_each_set_bit(bit, &status, PCI_NUM_INTX) {
  411. /* clear interrupts */
  412. cra_writel(pcie, 1 << bit, P2A_INT_STATUS);
  413. virq = irq_find_mapping(pcie->irq_domain, bit);
  414. if (virq)
  415. generic_handle_irq(virq);
  416. else
  417. dev_err(dev, "unexpected IRQ, INT%d\n", bit);
  418. }
  419. }
  420. chained_irq_exit(chip, desc);
  421. }
  422. static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
  423. {
  424. int err, res_valid = 0;
  425. struct device *dev = &pcie->pdev->dev;
  426. struct device_node *np = dev->of_node;
  427. struct resource_entry *win;
  428. err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pcie->resources,
  429. NULL);
  430. if (err)
  431. return err;
  432. err = devm_request_pci_bus_resources(dev, &pcie->resources);
  433. if (err)
  434. goto out_release_res;
  435. resource_list_for_each_entry(win, &pcie->resources) {
  436. struct resource *res = win->res;
  437. if (resource_type(res) == IORESOURCE_MEM)
  438. res_valid |= !(res->flags & IORESOURCE_PREFETCH);
  439. }
  440. if (res_valid)
  441. return 0;
  442. dev_err(dev, "non-prefetchable memory resource required\n");
  443. err = -EINVAL;
  444. out_release_res:
  445. pci_free_resource_list(&pcie->resources);
  446. return err;
  447. }
  448. static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
  449. {
  450. struct device *dev = &pcie->pdev->dev;
  451. struct device_node *node = dev->of_node;
  452. /* Setup INTx */
  453. pcie->irq_domain = irq_domain_add_linear(node, PCI_NUM_INTX,
  454. &intx_domain_ops, pcie);
  455. if (!pcie->irq_domain) {
  456. dev_err(dev, "Failed to get a INTx IRQ domain\n");
  457. return -ENOMEM;
  458. }
  459. return 0;
  460. }
  461. static int altera_pcie_parse_dt(struct altera_pcie *pcie)
  462. {
  463. struct device *dev = &pcie->pdev->dev;
  464. struct platform_device *pdev = pcie->pdev;
  465. struct resource *cra;
  466. cra = platform_get_resource_byname(pdev, IORESOURCE_MEM, "Cra");
  467. pcie->cra_base = devm_ioremap_resource(dev, cra);
  468. if (IS_ERR(pcie->cra_base))
  469. return PTR_ERR(pcie->cra_base);
  470. /* setup IRQ */
  471. pcie->irq = platform_get_irq(pdev, 0);
  472. if (pcie->irq < 0) {
  473. dev_err(dev, "failed to get IRQ: %d\n", pcie->irq);
  474. return pcie->irq;
  475. }
  476. irq_set_chained_handler_and_data(pcie->irq, altera_pcie_isr, pcie);
  477. return 0;
  478. }
  479. static void altera_pcie_host_init(struct altera_pcie *pcie)
  480. {
  481. altera_pcie_retrain(pcie);
  482. }
  483. static int altera_pcie_probe(struct platform_device *pdev)
  484. {
  485. struct device *dev = &pdev->dev;
  486. struct altera_pcie *pcie;
  487. struct pci_bus *bus;
  488. struct pci_bus *child;
  489. struct pci_host_bridge *bridge;
  490. int ret;
  491. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  492. if (!bridge)
  493. return -ENOMEM;
  494. pcie = pci_host_bridge_priv(bridge);
  495. pcie->pdev = pdev;
  496. ret = altera_pcie_parse_dt(pcie);
  497. if (ret) {
  498. dev_err(dev, "Parsing DT failed\n");
  499. return ret;
  500. }
  501. INIT_LIST_HEAD(&pcie->resources);
  502. ret = altera_pcie_parse_request_of_pci_ranges(pcie);
  503. if (ret) {
  504. dev_err(dev, "Failed add resources\n");
  505. return ret;
  506. }
  507. ret = altera_pcie_init_irq_domain(pcie);
  508. if (ret) {
  509. dev_err(dev, "Failed creating IRQ Domain\n");
  510. return ret;
  511. }
  512. /* clear all interrupts */
  513. cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);
  514. /* enable all interrupts */
  515. cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
  516. altera_pcie_host_init(pcie);
  517. list_splice_init(&pcie->resources, &bridge->windows);
  518. bridge->dev.parent = dev;
  519. bridge->sysdata = pcie;
  520. bridge->busnr = pcie->root_bus_nr;
  521. bridge->ops = &altera_pcie_ops;
  522. bridge->map_irq = of_irq_parse_and_map_pci;
  523. bridge->swizzle_irq = pci_common_swizzle;
  524. ret = pci_scan_root_bus_bridge(bridge);
  525. if (ret < 0)
  526. return ret;
  527. bus = bridge->bus;
  528. pci_assign_unassigned_bus_resources(bus);
  529. /* Configure PCI Express setting. */
  530. list_for_each_entry(child, &bus->children, node)
  531. pcie_bus_configure_settings(child);
  532. pci_bus_add_devices(bus);
  533. return ret;
  534. }
  535. static const struct of_device_id altera_pcie_of_match[] = {
  536. { .compatible = "altr,pcie-root-port-1.0", },
  537. {},
  538. };
  539. static struct platform_driver altera_pcie_driver = {
  540. .probe = altera_pcie_probe,
  541. .driver = {
  542. .name = "altera-pcie",
  543. .of_match_table = altera_pcie_of_match,
  544. .suppress_bind_attrs = true,
  545. },
  546. };
  547. builtin_platform_driver(altera_pcie_driver);