pcie-altera.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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) >> 12) & 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 INTX_NUM 4
  75. #define DWORD_MASK 3
  76. struct altera_pcie {
  77. struct platform_device *pdev;
  78. void __iomem *cra_base; /* DT Cra */
  79. int irq;
  80. u8 root_bus_nr;
  81. struct irq_domain *irq_domain;
  82. struct resource bus_range;
  83. struct list_head resources;
  84. };
  85. struct tlp_rp_regpair_t {
  86. u32 ctrl;
  87. u32 reg0;
  88. u32 reg1;
  89. };
  90. static inline void cra_writel(struct altera_pcie *pcie, const u32 value,
  91. const u32 reg)
  92. {
  93. writel_relaxed(value, pcie->cra_base + reg);
  94. }
  95. static inline u32 cra_readl(struct altera_pcie *pcie, const u32 reg)
  96. {
  97. return readl_relaxed(pcie->cra_base + reg);
  98. }
  99. static bool altera_pcie_link_is_up(struct altera_pcie *pcie)
  100. {
  101. return !!((cra_readl(pcie, RP_LTSSM) & RP_LTSSM_MASK) == LTSSM_L0);
  102. }
  103. /*
  104. * Altera PCIe port uses BAR0 of RC's configuration space as the translation
  105. * from PCI bus to native BUS. Entire DDR region is mapped into PCIe space
  106. * using these registers, so it can be reached by DMA from EP devices.
  107. * This BAR0 will also access to MSI vector when receiving MSI/MSIX interrupt
  108. * from EP devices, eventually trigger interrupt to GIC. The BAR0 of bridge
  109. * should be hidden during enumeration to avoid the sizing and resource
  110. * allocation by PCIe core.
  111. */
  112. static bool altera_pcie_hide_rc_bar(struct pci_bus *bus, unsigned int devfn,
  113. int offset)
  114. {
  115. if (pci_is_root_bus(bus) && (devfn == 0) &&
  116. (offset == PCI_BASE_ADDRESS_0))
  117. return true;
  118. return false;
  119. }
  120. static void tlp_write_tx(struct altera_pcie *pcie,
  121. struct tlp_rp_regpair_t *tlp_rp_regdata)
  122. {
  123. cra_writel(pcie, tlp_rp_regdata->reg0, RP_TX_REG0);
  124. cra_writel(pcie, tlp_rp_regdata->reg1, RP_TX_REG1);
  125. cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
  126. }
  127. static bool altera_pcie_valid_device(struct altera_pcie *pcie,
  128. struct pci_bus *bus, int dev)
  129. {
  130. /* If there is no link, then there is no device */
  131. if (bus->number != pcie->root_bus_nr) {
  132. if (!altera_pcie_link_is_up(pcie))
  133. return false;
  134. }
  135. /* access only one slot on each root port */
  136. if (bus->number == pcie->root_bus_nr && dev > 0)
  137. return false;
  138. return true;
  139. }
  140. static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
  141. {
  142. int i;
  143. bool sop = 0;
  144. u32 ctrl;
  145. u32 reg0, reg1;
  146. u32 comp_status = 1;
  147. /*
  148. * Minimum 2 loops to read TLP headers and 1 loop to read data
  149. * payload.
  150. */
  151. for (i = 0; i < TLP_LOOP; i++) {
  152. ctrl = cra_readl(pcie, RP_RXCPL_STATUS);
  153. if ((ctrl & RP_RXCPL_SOP) || (ctrl & RP_RXCPL_EOP) || sop) {
  154. reg0 = cra_readl(pcie, RP_RXCPL_REG0);
  155. reg1 = cra_readl(pcie, RP_RXCPL_REG1);
  156. if (ctrl & RP_RXCPL_SOP) {
  157. sop = true;
  158. comp_status = TLP_COMP_STATUS(reg1);
  159. }
  160. if (ctrl & RP_RXCPL_EOP) {
  161. if (comp_status)
  162. return PCIBIOS_DEVICE_NOT_FOUND;
  163. if (value)
  164. *value = reg0;
  165. return PCIBIOS_SUCCESSFUL;
  166. }
  167. }
  168. udelay(5);
  169. }
  170. return PCIBIOS_DEVICE_NOT_FOUND;
  171. }
  172. static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
  173. u32 data, bool align)
  174. {
  175. struct tlp_rp_regpair_t tlp_rp_regdata;
  176. tlp_rp_regdata.reg0 = headers[0];
  177. tlp_rp_regdata.reg1 = headers[1];
  178. tlp_rp_regdata.ctrl = RP_TX_SOP;
  179. tlp_write_tx(pcie, &tlp_rp_regdata);
  180. if (align) {
  181. tlp_rp_regdata.reg0 = headers[2];
  182. tlp_rp_regdata.reg1 = 0;
  183. tlp_rp_regdata.ctrl = 0;
  184. tlp_write_tx(pcie, &tlp_rp_regdata);
  185. tlp_rp_regdata.reg0 = data;
  186. tlp_rp_regdata.reg1 = 0;
  187. } else {
  188. tlp_rp_regdata.reg0 = headers[2];
  189. tlp_rp_regdata.reg1 = data;
  190. }
  191. tlp_rp_regdata.ctrl = RP_TX_EOP;
  192. tlp_write_tx(pcie, &tlp_rp_regdata);
  193. }
  194. static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
  195. int where, u8 byte_en, u32 *value)
  196. {
  197. u32 headers[TLP_HDR_SIZE];
  198. headers[0] = TLP_CFGRD_DW0(pcie, bus);
  199. headers[1] = TLP_CFG_DW1(pcie, TLP_READ_TAG, byte_en);
  200. headers[2] = TLP_CFG_DW2(bus, devfn, where);
  201. tlp_write_packet(pcie, headers, 0, false);
  202. return tlp_read_packet(pcie, value);
  203. }
  204. static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
  205. int where, u8 byte_en, u32 value)
  206. {
  207. u32 headers[TLP_HDR_SIZE];
  208. int ret;
  209. headers[0] = TLP_CFGWR_DW0(pcie, bus);
  210. headers[1] = TLP_CFG_DW1(pcie, TLP_WRITE_TAG, byte_en);
  211. headers[2] = TLP_CFG_DW2(bus, devfn, where);
  212. /* check alignment to Qword */
  213. if ((where & 0x7) == 0)
  214. tlp_write_packet(pcie, headers, value, true);
  215. else
  216. tlp_write_packet(pcie, headers, value, false);
  217. ret = tlp_read_packet(pcie, NULL);
  218. if (ret != PCIBIOS_SUCCESSFUL)
  219. return ret;
  220. /*
  221. * Monitor changes to PCI_PRIMARY_BUS register on root port
  222. * and update local copy of root bus number accordingly.
  223. */
  224. if ((bus == pcie->root_bus_nr) && (where == PCI_PRIMARY_BUS))
  225. pcie->root_bus_nr = (u8)(value);
  226. return PCIBIOS_SUCCESSFUL;
  227. }
  228. static int _altera_pcie_cfg_read(struct altera_pcie *pcie, u8 busno,
  229. unsigned int devfn, int where, int size,
  230. u32 *value)
  231. {
  232. int ret;
  233. u32 data;
  234. u8 byte_en;
  235. switch (size) {
  236. case 1:
  237. byte_en = 1 << (where & 3);
  238. break;
  239. case 2:
  240. byte_en = 3 << (where & 3);
  241. break;
  242. default:
  243. byte_en = 0xf;
  244. break;
  245. }
  246. ret = tlp_cfg_dword_read(pcie, busno, devfn,
  247. (where & ~DWORD_MASK), byte_en, &data);
  248. if (ret != PCIBIOS_SUCCESSFUL)
  249. return ret;
  250. switch (size) {
  251. case 1:
  252. *value = (data >> (8 * (where & 0x3))) & 0xff;
  253. break;
  254. case 2:
  255. *value = (data >> (8 * (where & 0x2))) & 0xffff;
  256. break;
  257. default:
  258. *value = data;
  259. break;
  260. }
  261. return PCIBIOS_SUCCESSFUL;
  262. }
  263. static int _altera_pcie_cfg_write(struct altera_pcie *pcie, u8 busno,
  264. unsigned int devfn, int where, int size,
  265. u32 value)
  266. {
  267. u32 data32;
  268. u32 shift = 8 * (where & 3);
  269. u8 byte_en;
  270. switch (size) {
  271. case 1:
  272. data32 = (value & 0xff) << shift;
  273. byte_en = 1 << (where & 3);
  274. break;
  275. case 2:
  276. data32 = (value & 0xffff) << shift;
  277. byte_en = 3 << (where & 3);
  278. break;
  279. default:
  280. data32 = value;
  281. byte_en = 0xf;
  282. break;
  283. }
  284. return tlp_cfg_dword_write(pcie, busno, devfn, (where & ~DWORD_MASK),
  285. byte_en, data32);
  286. }
  287. static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn,
  288. int where, int size, u32 *value)
  289. {
  290. struct altera_pcie *pcie = bus->sysdata;
  291. if (altera_pcie_hide_rc_bar(bus, devfn, where))
  292. return PCIBIOS_BAD_REGISTER_NUMBER;
  293. if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) {
  294. *value = 0xffffffff;
  295. return PCIBIOS_DEVICE_NOT_FOUND;
  296. }
  297. return _altera_pcie_cfg_read(pcie, bus->number, devfn, where, size,
  298. value);
  299. }
  300. static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn,
  301. int where, int size, u32 value)
  302. {
  303. struct altera_pcie *pcie = bus->sysdata;
  304. if (altera_pcie_hide_rc_bar(bus, devfn, where))
  305. return PCIBIOS_BAD_REGISTER_NUMBER;
  306. if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn)))
  307. return PCIBIOS_DEVICE_NOT_FOUND;
  308. return _altera_pcie_cfg_write(pcie, bus->number, devfn, where, size,
  309. value);
  310. }
  311. static struct pci_ops altera_pcie_ops = {
  312. .read = altera_pcie_cfg_read,
  313. .write = altera_pcie_cfg_write,
  314. };
  315. static int altera_read_cap_word(struct altera_pcie *pcie, u8 busno,
  316. unsigned int devfn, int offset, u16 *value)
  317. {
  318. u32 data;
  319. int ret;
  320. ret = _altera_pcie_cfg_read(pcie, busno, devfn,
  321. PCIE_CAP_OFFSET + offset, sizeof(*value),
  322. &data);
  323. *value = data;
  324. return ret;
  325. }
  326. static int altera_write_cap_word(struct altera_pcie *pcie, u8 busno,
  327. unsigned int devfn, int offset, u16 value)
  328. {
  329. return _altera_pcie_cfg_write(pcie, busno, devfn,
  330. PCIE_CAP_OFFSET + offset, sizeof(value),
  331. value);
  332. }
  333. static void altera_wait_link_retrain(struct altera_pcie *pcie)
  334. {
  335. struct device *dev = &pcie->pdev->dev;
  336. u16 reg16;
  337. unsigned long start_jiffies;
  338. /* Wait for link training end. */
  339. start_jiffies = jiffies;
  340. for (;;) {
  341. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  342. PCI_EXP_LNKSTA, &reg16);
  343. if (!(reg16 & PCI_EXP_LNKSTA_LT))
  344. break;
  345. if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) {
  346. dev_err(dev, "link retrain timeout\n");
  347. break;
  348. }
  349. udelay(100);
  350. }
  351. /* Wait for link is up */
  352. start_jiffies = jiffies;
  353. for (;;) {
  354. if (altera_pcie_link_is_up(pcie))
  355. break;
  356. if (time_after(jiffies, start_jiffies + LINK_UP_TIMEOUT)) {
  357. dev_err(dev, "link up timeout\n");
  358. break;
  359. }
  360. udelay(100);
  361. }
  362. }
  363. static void altera_pcie_retrain(struct altera_pcie *pcie)
  364. {
  365. u16 linkcap, linkstat, linkctl;
  366. if (!altera_pcie_link_is_up(pcie))
  367. return;
  368. /*
  369. * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but
  370. * current speed is 2.5 GB/s.
  371. */
  372. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKCAP,
  373. &linkcap);
  374. if ((linkcap & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB)
  375. return;
  376. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKSTA,
  377. &linkstat);
  378. if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) {
  379. altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  380. PCI_EXP_LNKCTL, &linkctl);
  381. linkctl |= PCI_EXP_LNKCTL_RL;
  382. altera_write_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
  383. PCI_EXP_LNKCTL, linkctl);
  384. altera_wait_link_retrain(pcie);
  385. }
  386. }
  387. static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
  388. irq_hw_number_t hwirq)
  389. {
  390. irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
  391. irq_set_chip_data(irq, domain->host_data);
  392. return 0;
  393. }
  394. static const struct irq_domain_ops intx_domain_ops = {
  395. .map = altera_pcie_intx_map,
  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, INTX_NUM) {
  411. /* clear interrupts */
  412. cra_writel(pcie, 1 << bit, P2A_INT_STATUS);
  413. virq = irq_find_mapping(pcie->irq_domain, bit + 1);
  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, INTX_NUM + 1,
  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. dev_err(dev, "failed to map cra memory\n");
  470. return PTR_ERR(pcie->cra_base);
  471. }
  472. /* setup IRQ */
  473. pcie->irq = platform_get_irq(pdev, 0);
  474. if (pcie->irq <= 0) {
  475. dev_err(dev, "failed to get IRQ: %d\n", pcie->irq);
  476. return -EINVAL;
  477. }
  478. irq_set_chained_handler_and_data(pcie->irq, altera_pcie_isr, pcie);
  479. return 0;
  480. }
  481. static void altera_pcie_host_init(struct altera_pcie *pcie)
  482. {
  483. altera_pcie_retrain(pcie);
  484. }
  485. static int altera_pcie_probe(struct platform_device *pdev)
  486. {
  487. struct device *dev = &pdev->dev;
  488. struct altera_pcie *pcie;
  489. struct pci_bus *bus;
  490. struct pci_bus *child;
  491. int ret;
  492. pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
  493. if (!pcie)
  494. return -ENOMEM;
  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. bus = pci_scan_root_bus(dev, pcie->root_bus_nr, &altera_pcie_ops,
  518. pcie, &pcie->resources);
  519. if (!bus)
  520. return -ENOMEM;
  521. pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
  522. pci_assign_unassigned_bus_resources(bus);
  523. /* Configure PCI Express setting. */
  524. list_for_each_entry(child, &bus->children, node)
  525. pcie_bus_configure_settings(child);
  526. pci_bus_add_devices(bus);
  527. return ret;
  528. }
  529. static const struct of_device_id altera_pcie_of_match[] = {
  530. { .compatible = "altr,pcie-root-port-1.0", },
  531. {},
  532. };
  533. static struct platform_driver altera_pcie_driver = {
  534. .probe = altera_pcie_probe,
  535. .driver = {
  536. .name = "altera-pcie",
  537. .of_match_table = altera_pcie_of_match,
  538. .suppress_bind_attrs = true,
  539. },
  540. };
  541. static int altera_pcie_init(void)
  542. {
  543. return platform_driver_register(&altera_pcie_driver);
  544. }
  545. device_initcall(altera_pcie_init);