pcie-altera.c 16 KB

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