1 // SPDX-License-Identifier: GPL-2.0
3 * PCIe host bridge driver for Apple system-on-chips.
5 * The HW is ECAM compliant, so once the controller is initialized,
6 * the driver mostly deals MSI mapping and handling of per-port
7 * interrupts (INTx, management and error signals).
9 * Initialization requires enabling power and clocks, along with a
10 * number of register pokes.
13 * Copyright (C) 2021 Google LLC
14 * Copyright (C) 2021 Corellium LLC
21 #include <linux/gpio/consumer.h>
22 #include <linux/kernel.h>
23 #include <linux/iopoll.h>
24 #include <linux/irqchip/chained_irq.h>
25 #include <linux/irqdomain.h>
26 #include <linux/list.h>
27 #include <linux/module.h>
28 #include <linux/msi.h>
29 #include <linux/of_irq.h>
30 #include <linux/pci-ecam.h>
32 #define CORE_RC_PHYIF_CTL 0x00024
33 #define CORE_RC_PHYIF_CTL_RUN BIT(0)
34 #define CORE_RC_PHYIF_STAT 0x00028
35 #define CORE_RC_PHYIF_STAT_REFCLK BIT(4)
36 #define CORE_RC_CTL 0x00050
37 #define CORE_RC_CTL_RUN BIT(0)
38 #define CORE_RC_STAT 0x00058
39 #define CORE_RC_STAT_READY BIT(0)
40 #define CORE_FABRIC_STAT 0x04000
41 #define CORE_FABRIC_STAT_MASK 0x001F001F
42 #define CORE_LANE_CFG(port) (0x84000 + 0x4000 * (port))
43 #define CORE_LANE_CFG_REFCLK0REQ BIT(0)
44 #define CORE_LANE_CFG_REFCLK1REQ BIT(1)
45 #define CORE_LANE_CFG_REFCLK0ACK BIT(2)
46 #define CORE_LANE_CFG_REFCLK1ACK BIT(3)
47 #define CORE_LANE_CFG_REFCLKEN (BIT(9) | BIT(10))
48 #define CORE_LANE_CTL(port) (0x84004 + 0x4000 * (port))
49 #define CORE_LANE_CTL_CFGACC BIT(15)
51 #define PORT_LTSSMCTL 0x00080
52 #define PORT_LTSSMCTL_START BIT(0)
53 #define PORT_INTSTAT 0x00100
54 #define PORT_INT_TUNNEL_ERR 31
55 #define PORT_INT_CPL_TIMEOUT 23
56 #define PORT_INT_RID2SID_MAPERR 22
57 #define PORT_INT_CPL_ABORT 21
58 #define PORT_INT_MSI_BAD_DATA 19
59 #define PORT_INT_MSI_ERR 18
60 #define PORT_INT_REQADDR_GT32 17
61 #define PORT_INT_AF_TIMEOUT 15
62 #define PORT_INT_LINK_DOWN 14
63 #define PORT_INT_LINK_UP 12
64 #define PORT_INT_LINK_BWMGMT 11
65 #define PORT_INT_AER_MASK (15 << 4)
66 #define PORT_INT_PORT_ERR 4
67 #define PORT_INT_INTx(i) i
68 #define PORT_INT_INTx_MASK 15
69 #define PORT_INTMSK 0x00104
70 #define PORT_INTMSKSET 0x00108
71 #define PORT_INTMSKCLR 0x0010c
72 #define PORT_MSICFG 0x00124
73 #define PORT_MSICFG_EN BIT(0)
74 #define PORT_MSICFG_L2MSINUM_SHIFT 4
75 #define PORT_MSIBASE 0x00128
76 #define PORT_MSIBASE_1_SHIFT 16
77 #define PORT_MSIADDR 0x00168
78 #define PORT_LINKSTS 0x00208
79 #define PORT_LINKSTS_UP BIT(0)
80 #define PORT_LINKSTS_BUSY BIT(2)
81 #define PORT_LINKCMDSTS 0x00210
82 #define PORT_OUTS_NPREQS 0x00284
83 #define PORT_OUTS_NPREQS_REQ BIT(24)
84 #define PORT_OUTS_NPREQS_CPL BIT(16)
85 #define PORT_RXWR_FIFO 0x00288
86 #define PORT_RXWR_FIFO_HDR GENMASK(15, 10)
87 #define PORT_RXWR_FIFO_DATA GENMASK(9, 0)
88 #define PORT_RXRD_FIFO 0x0028C
89 #define PORT_RXRD_FIFO_REQ GENMASK(6, 0)
90 #define PORT_OUTS_CPLS 0x00290
91 #define PORT_OUTS_CPLS_SHRD GENMASK(14, 8)
92 #define PORT_OUTS_CPLS_WAIT GENMASK(6, 0)
93 #define PORT_APPCLK 0x00800
94 #define PORT_APPCLK_EN BIT(0)
95 #define PORT_APPCLK_CGDIS BIT(8)
96 #define PORT_STATUS 0x00804
97 #define PORT_STATUS_READY BIT(0)
98 #define PORT_REFCLK 0x00810
99 #define PORT_REFCLK_EN BIT(0)
100 #define PORT_REFCLK_CGDIS BIT(8)
101 #define PORT_PERST 0x00814
102 #define PORT_PERST_OFF BIT(0)
103 #define PORT_RID2SID(i16) (0x00828 + 4 * (i16))
104 #define PORT_RID2SID_VALID BIT(31)
105 #define PORT_RID2SID_SID_SHIFT 16
106 #define PORT_RID2SID_BUS_SHIFT 8
107 #define PORT_RID2SID_DEV_SHIFT 3
108 #define PORT_RID2SID_FUNC_SHIFT 0
109 #define PORT_OUTS_PREQS_HDR 0x00980
110 #define PORT_OUTS_PREQS_HDR_MASK GENMASK(9, 0)
111 #define PORT_OUTS_PREQS_DATA 0x00984
112 #define PORT_OUTS_PREQS_DATA_MASK GENMASK(15, 0)
113 #define PORT_TUNCTRL 0x00988
114 #define PORT_TUNCTRL_PERST_ON BIT(0)
115 #define PORT_TUNCTRL_PERST_ACK_REQ BIT(1)
116 #define PORT_TUNSTAT 0x0098c
117 #define PORT_TUNSTAT_PERST_ON BIT(0)
118 #define PORT_TUNSTAT_PERST_ACK_PEND BIT(1)
119 #define PORT_PREFMEM_ENABLE 0x00994
121 #define MAX_RID2SID 64
124 * The doorbell address is set to 0xfffff000, which by convention
125 * matches what MacOS does, and it is possible to use any other
126 * address (in the bottom 4GB, as the base register is only 32bit).
127 * However, it has to be excluded from the IOVA range, and the DART
128 * driver has to know about it.
130 #define DOORBELL_ADDR CONFIG_PCIE_APPLE_MSI_DOORBELL_ADDR
136 struct irq_domain *domain;
137 unsigned long *bitmap;
138 struct list_head ports;
139 struct completion event;
140 struct irq_fwspec fwspec;
144 struct apple_pcie_port {
145 struct apple_pcie *pcie;
146 struct device_node *np;
148 struct irq_domain *domain;
149 struct list_head entry;
150 DECLARE_BITMAP(sid_map, MAX_RID2SID);
155 static void rmw_set(u32 set, void __iomem *addr)
157 writel_relaxed(readl_relaxed(addr) | set, addr);
160 static void rmw_clear(u32 clr, void __iomem *addr)
162 writel_relaxed(readl_relaxed(addr) & ~clr, addr);
165 static void apple_msi_top_irq_mask(struct irq_data *d)
168 irq_chip_mask_parent(d);
171 static void apple_msi_top_irq_unmask(struct irq_data *d)
173 pci_msi_unmask_irq(d);
174 irq_chip_unmask_parent(d);
177 static struct irq_chip apple_msi_top_chip = {
179 .irq_mask = apple_msi_top_irq_mask,
180 .irq_unmask = apple_msi_top_irq_unmask,
181 .irq_eoi = irq_chip_eoi_parent,
182 .irq_set_affinity = irq_chip_set_affinity_parent,
183 .irq_set_type = irq_chip_set_type_parent,
186 static void apple_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
188 msg->address_hi = upper_32_bits(DOORBELL_ADDR);
189 msg->address_lo = lower_32_bits(DOORBELL_ADDR);
190 msg->data = data->hwirq;
193 static struct irq_chip apple_msi_bottom_chip = {
195 .irq_mask = irq_chip_mask_parent,
196 .irq_unmask = irq_chip_unmask_parent,
197 .irq_eoi = irq_chip_eoi_parent,
198 .irq_set_affinity = irq_chip_set_affinity_parent,
199 .irq_set_type = irq_chip_set_type_parent,
200 .irq_compose_msi_msg = apple_msi_compose_msg,
203 static int apple_msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
204 unsigned int nr_irqs, void *args)
206 struct apple_pcie *pcie = domain->host_data;
207 struct irq_fwspec fwspec = pcie->fwspec;
211 mutex_lock(&pcie->lock);
213 hwirq = bitmap_find_free_region(pcie->bitmap, pcie->nvecs,
214 order_base_2(nr_irqs));
216 mutex_unlock(&pcie->lock);
221 fwspec.param[fwspec.param_count - 2] += hwirq;
223 ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &fwspec);
227 for (i = 0; i < nr_irqs; i++) {
228 irq_domain_set_hwirq_and_chip(domain, virq + i, hwirq + i,
229 &apple_msi_bottom_chip,
236 static void apple_msi_domain_free(struct irq_domain *domain, unsigned int virq,
237 unsigned int nr_irqs)
239 struct irq_data *d = irq_domain_get_irq_data(domain, virq);
240 struct apple_pcie *pcie = domain->host_data;
242 mutex_lock(&pcie->lock);
244 bitmap_release_region(pcie->bitmap, d->hwirq, order_base_2(nr_irqs));
246 mutex_unlock(&pcie->lock);
249 static const struct irq_domain_ops apple_msi_domain_ops = {
250 .alloc = apple_msi_domain_alloc,
251 .free = apple_msi_domain_free,
254 static struct msi_domain_info apple_msi_info = {
255 .flags = (MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
256 MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX),
257 .chip = &apple_msi_top_chip,
260 static void apple_port_irq_mask(struct irq_data *data)
262 struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
264 writel_relaxed(BIT(data->hwirq), port->base + PORT_INTMSKSET);
267 static void apple_port_irq_unmask(struct irq_data *data)
269 struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
271 writel_relaxed(BIT(data->hwirq), port->base + PORT_INTMSKCLR);
274 static bool hwirq_is_intx(unsigned int hwirq)
276 return BIT(hwirq) & PORT_INT_INTx_MASK;
279 static void apple_port_irq_ack(struct irq_data *data)
281 struct apple_pcie_port *port = irq_data_get_irq_chip_data(data);
283 if (!hwirq_is_intx(data->hwirq))
284 writel_relaxed(BIT(data->hwirq), port->base + PORT_INTSTAT);
287 static int apple_port_irq_set_type(struct irq_data *data, unsigned int type)
290 * It doesn't seem that there is any way to configure the
291 * trigger, so assume INTx have to be level (as per the spec),
292 * and the rest is edge (which looks likely).
294 if (hwirq_is_intx(data->hwirq) ^ !!(type & IRQ_TYPE_LEVEL_MASK))
297 irqd_set_trigger_type(data, type);
301 static struct irq_chip apple_port_irqchip = {
303 .irq_ack = apple_port_irq_ack,
304 .irq_mask = apple_port_irq_mask,
305 .irq_unmask = apple_port_irq_unmask,
306 .irq_set_type = apple_port_irq_set_type,
309 static int apple_port_irq_domain_alloc(struct irq_domain *domain,
310 unsigned int virq, unsigned int nr_irqs,
313 struct apple_pcie_port *port = domain->host_data;
314 struct irq_fwspec *fwspec = args;
317 for (i = 0; i < nr_irqs; i++) {
318 irq_flow_handler_t flow = handle_edge_irq;
319 unsigned int type = IRQ_TYPE_EDGE_RISING;
321 if (hwirq_is_intx(fwspec->param[0] + i)) {
322 flow = handle_level_irq;
323 type = IRQ_TYPE_LEVEL_HIGH;
326 irq_domain_set_info(domain, virq + i, fwspec->param[0] + i,
327 &apple_port_irqchip, port, flow,
330 irq_set_irq_type(virq + i, type);
336 static void apple_port_irq_domain_free(struct irq_domain *domain,
337 unsigned int virq, unsigned int nr_irqs)
341 for (i = 0; i < nr_irqs; i++) {
342 struct irq_data *d = irq_domain_get_irq_data(domain, virq + i);
344 irq_set_handler(virq + i, NULL);
345 irq_domain_reset_irq_data(d);
349 static const struct irq_domain_ops apple_port_irq_domain_ops = {
350 .translate = irq_domain_translate_onecell,
351 .alloc = apple_port_irq_domain_alloc,
352 .free = apple_port_irq_domain_free,
355 static void apple_port_irq_handler(struct irq_desc *desc)
357 struct apple_pcie_port *port = irq_desc_get_handler_data(desc);
358 struct irq_chip *chip = irq_desc_get_chip(desc);
362 chained_irq_enter(chip, desc);
364 stat = readl_relaxed(port->base + PORT_INTSTAT);
366 for_each_set_bit(i, &stat, 32)
367 generic_handle_domain_irq(port->domain, i);
369 chained_irq_exit(chip, desc);
372 static int apple_pcie_port_setup_irq(struct apple_pcie_port *port)
374 struct fwnode_handle *fwnode = &port->np->fwnode;
377 /* FIXME: consider moving each interrupt under each port */
378 irq = irq_of_parse_and_map(to_of_node(dev_fwnode(port->pcie->dev)),
383 port->domain = irq_domain_create_linear(fwnode, 32,
384 &apple_port_irq_domain_ops,
389 /* Disable all interrupts */
390 writel_relaxed(~0, port->base + PORT_INTMSKSET);
391 writel_relaxed(~0, port->base + PORT_INTSTAT);
393 irq_set_chained_handler_and_data(irq, apple_port_irq_handler, port);
395 /* Configure MSI base address */
396 BUILD_BUG_ON(upper_32_bits(DOORBELL_ADDR));
397 writel_relaxed(lower_32_bits(DOORBELL_ADDR), port->base + PORT_MSIADDR);
399 /* Enable MSIs, shared between all ports */
400 writel_relaxed(0, port->base + PORT_MSIBASE);
401 writel_relaxed((ilog2(port->pcie->nvecs) << PORT_MSICFG_L2MSINUM_SHIFT) |
402 PORT_MSICFG_EN, port->base + PORT_MSICFG);
407 static irqreturn_t apple_pcie_port_irq(int irq, void *data)
409 struct apple_pcie_port *port = data;
410 unsigned int hwirq = irq_domain_get_irq_data(port->domain, irq)->hwirq;
413 case PORT_INT_LINK_UP:
414 dev_info_ratelimited(port->pcie->dev, "Link up on %pOF\n",
416 complete_all(&port->pcie->event);
418 case PORT_INT_LINK_DOWN:
419 dev_info_ratelimited(port->pcie->dev, "Link down on %pOF\n",
429 static int apple_pcie_port_register_irqs(struct apple_pcie_port *port)
435 { PORT_INT_LINK_UP, "Link up", },
436 { PORT_INT_LINK_DOWN, "Link down", },
440 for (i = 0; i < ARRAY_SIZE(port_irqs); i++) {
441 struct irq_fwspec fwspec = {
442 .fwnode = &port->np->fwnode,
445 [0] = port_irqs[i].hwirq,
451 irq = irq_domain_alloc_irqs(port->domain, 1, NUMA_NO_NODE,
456 ret = request_irq(irq, apple_pcie_port_irq, 0,
457 port_irqs[i].name, port);
464 static int apple_pcie_setup_refclk(struct apple_pcie *pcie,
465 struct apple_pcie_port *port)
470 res = readl_relaxed_poll_timeout(pcie->base + CORE_RC_PHYIF_STAT, stat,
471 stat & CORE_RC_PHYIF_STAT_REFCLK,
476 rmw_set(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
477 rmw_set(CORE_LANE_CFG_REFCLK0REQ, pcie->base + CORE_LANE_CFG(port->idx));
479 res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
480 stat, stat & CORE_LANE_CFG_REFCLK0ACK,
485 rmw_set(CORE_LANE_CFG_REFCLK1REQ, pcie->base + CORE_LANE_CFG(port->idx));
486 res = readl_relaxed_poll_timeout(pcie->base + CORE_LANE_CFG(port->idx),
487 stat, stat & CORE_LANE_CFG_REFCLK1ACK,
493 rmw_clear(CORE_LANE_CTL_CFGACC, pcie->base + CORE_LANE_CTL(port->idx));
495 rmw_set(CORE_LANE_CFG_REFCLKEN, pcie->base + CORE_LANE_CFG(port->idx));
496 rmw_set(PORT_REFCLK_EN, port->base + PORT_REFCLK);
501 static u32 apple_pcie_rid2sid_write(struct apple_pcie_port *port,
504 writel_relaxed(val, port->base + PORT_RID2SID(idx));
505 /* Read back to ensure completion of the write */
506 return readl_relaxed(port->base + PORT_RID2SID(idx));
509 static int apple_pcie_setup_port(struct apple_pcie *pcie,
510 struct device_node *np)
512 struct platform_device *platform = to_platform_device(pcie->dev);
513 struct apple_pcie_port *port;
514 struct gpio_desc *reset;
518 reset = devm_fwnode_gpiod_get(pcie->dev, of_fwnode_handle(np), "reset",
519 GPIOD_OUT_LOW, "PERST#");
521 return PTR_ERR(reset);
523 port = devm_kzalloc(pcie->dev, sizeof(*port), GFP_KERNEL);
527 ret = of_property_read_u32_index(np, "reg", 0, &idx);
531 /* Use the first reg entry to work out the port index */
532 port->idx = idx >> 11;
536 port->base = devm_platform_ioremap_resource(platform, port->idx + 2);
537 if (IS_ERR(port->base))
538 return PTR_ERR(port->base);
540 rmw_set(PORT_APPCLK_EN, port->base + PORT_APPCLK);
542 /* Assert PERST# before setting up the clock */
543 gpiod_set_value(reset, 1);
545 ret = apple_pcie_setup_refclk(pcie, port);
549 /* The minimal Tperst-clk value is 100us (PCIe CEM r5.0, 2.9.2) */
550 usleep_range(100, 200);
552 /* Deassert PERST# */
553 rmw_set(PORT_PERST_OFF, port->base + PORT_PERST);
554 gpiod_set_value(reset, 0);
556 /* Wait for 100ms after PERST# deassertion (PCIe r5.0, 6.6.1) */
559 ret = readl_relaxed_poll_timeout(port->base + PORT_STATUS, stat,
560 stat & PORT_STATUS_READY, 100, 250000);
562 dev_err(pcie->dev, "port %pOF ready wait timeout\n", np);
566 rmw_clear(PORT_REFCLK_CGDIS, port->base + PORT_REFCLK);
567 rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK);
569 ret = apple_pcie_port_setup_irq(port);
573 /* Reset all RID/SID mappings, and check for RAZ/WI registers */
574 for (i = 0; i < MAX_RID2SID; i++) {
575 if (apple_pcie_rid2sid_write(port, i, 0xbad1d) != 0xbad1d)
577 apple_pcie_rid2sid_write(port, i, 0);
580 dev_dbg(pcie->dev, "%pOF: %d RID/SID mapping entries\n", np, i);
582 port->sid_map_sz = i;
584 list_add_tail(&port->entry, &pcie->ports);
585 init_completion(&pcie->event);
587 ret = apple_pcie_port_register_irqs(port);
590 writel_relaxed(PORT_LTSSMCTL_START, port->base + PORT_LTSSMCTL);
592 if (!wait_for_completion_timeout(&pcie->event, HZ / 10))
593 dev_warn(pcie->dev, "%pOF link didn't come up\n", np);
598 static int apple_msi_init(struct apple_pcie *pcie)
600 struct fwnode_handle *fwnode = dev_fwnode(pcie->dev);
601 struct of_phandle_args args = {};
602 struct irq_domain *parent;
605 ret = of_parse_phandle_with_args(to_of_node(fwnode), "msi-ranges",
606 "#interrupt-cells", 0, &args);
610 ret = of_property_read_u32_index(to_of_node(fwnode), "msi-ranges",
611 args.args_count + 1, &pcie->nvecs);
615 of_phandle_args_to_fwspec(args.np, args.args, args.args_count,
618 pcie->bitmap = devm_bitmap_zalloc(pcie->dev, pcie->nvecs, GFP_KERNEL);
622 parent = irq_find_matching_fwspec(&pcie->fwspec, DOMAIN_BUS_WIRED);
624 dev_err(pcie->dev, "failed to find parent domain\n");
628 parent = irq_domain_create_hierarchy(parent, 0, pcie->nvecs, fwnode,
629 &apple_msi_domain_ops, pcie);
631 dev_err(pcie->dev, "failed to create IRQ domain\n");
634 irq_domain_update_bus_token(parent, DOMAIN_BUS_NEXUS);
636 pcie->domain = pci_msi_create_irq_domain(fwnode, &apple_msi_info,
639 dev_err(pcie->dev, "failed to create MSI domain\n");
640 irq_domain_remove(parent);
647 static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
649 struct pci_config_window *cfg = pdev->sysdata;
650 struct apple_pcie *pcie = cfg->priv;
651 struct pci_dev *port_pdev;
652 struct apple_pcie_port *port;
654 /* Find the root port this device is on */
655 port_pdev = pcie_find_root_port(pdev);
657 /* If finding the port itself, nothing to do */
658 if (WARN_ON(!port_pdev) || pdev == port_pdev)
661 list_for_each_entry(port, &pcie->ports, entry) {
662 if (port->idx == PCI_SLOT(port_pdev->devfn))
669 static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev)
671 u32 sid, rid = pci_dev_id(pdev);
672 struct apple_pcie_port *port;
675 port = apple_pcie_get_port(pdev);
679 dev_dbg(&pdev->dev, "added to bus %s, index %d\n",
680 pci_name(pdev->bus->self), port->idx);
682 err = of_map_id(port->pcie->dev->of_node, rid, "iommu-map",
683 "iommu-map-mask", NULL, &sid);
687 mutex_lock(&port->pcie->lock);
689 idx = bitmap_find_free_region(port->sid_map, port->sid_map_sz, 0);
691 apple_pcie_rid2sid_write(port, idx,
693 (sid << PORT_RID2SID_SID_SHIFT) | rid);
695 dev_dbg(&pdev->dev, "mapping RID%x to SID%x (index %d)\n",
699 mutex_unlock(&port->pcie->lock);
701 return idx >= 0 ? 0 : -ENOSPC;
704 static void apple_pcie_disable_device(struct pci_host_bridge *bridge, struct pci_dev *pdev)
706 struct apple_pcie_port *port;
707 u32 rid = pci_dev_id(pdev);
710 port = apple_pcie_get_port(pdev);
714 mutex_lock(&port->pcie->lock);
716 for_each_set_bit(idx, port->sid_map, port->sid_map_sz) {
719 val = readl_relaxed(port->base + PORT_RID2SID(idx));
720 if ((val & 0xffff) == rid) {
721 apple_pcie_rid2sid_write(port, idx, 0);
722 bitmap_release_region(port->sid_map, idx, 0);
723 dev_dbg(&pdev->dev, "Released %x (%d)\n", val, idx);
728 mutex_unlock(&port->pcie->lock);
731 static int apple_pcie_init(struct pci_config_window *cfg)
733 struct device *dev = cfg->parent;
734 struct platform_device *platform = to_platform_device(dev);
735 struct device_node *of_port;
736 struct apple_pcie *pcie;
739 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
745 mutex_init(&pcie->lock);
747 pcie->base = devm_platform_ioremap_resource(platform, 1);
748 if (IS_ERR(pcie->base))
749 return PTR_ERR(pcie->base);
752 INIT_LIST_HEAD(&pcie->ports);
754 ret = apple_msi_init(pcie);
758 for_each_child_of_node(dev->of_node, of_port) {
759 ret = apple_pcie_setup_port(pcie, of_port);
761 dev_err(pcie->dev, "Port %pOF setup fail: %d\n", of_port, ret);
762 of_node_put(of_port);
770 static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
771 .init = apple_pcie_init,
772 .enable_device = apple_pcie_enable_device,
773 .disable_device = apple_pcie_disable_device,
775 .map_bus = pci_ecam_map_bus,
776 .read = pci_generic_config_read,
777 .write = pci_generic_config_write,
781 static const struct of_device_id apple_pcie_of_match[] = {
782 { .compatible = "apple,pcie", .data = &apple_pcie_cfg_ecam_ops },
785 MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
787 static struct platform_driver apple_pcie_driver = {
788 .probe = pci_host_common_probe,
790 .name = "pcie-apple",
791 .of_match_table = apple_pcie_of_match,
792 .suppress_bind_attrs = true,
795 module_platform_driver(apple_pcie_driver);
797 MODULE_DESCRIPTION("Apple PCIe host bridge driver");
798 MODULE_LICENSE("GPL v2");