]> git.sur5r.net Git - u-boot/blobdiff - arch/x86/cpu/irq.c
Merge git://git.denx.de/u-boot-sunxi
[u-boot] / arch / x86 / cpu / irq.c
index 74b89ad2ff6c08d4b63fbc4b0244bcf6d13c6d92..f5654eb510d5888b2ae8f077a446fbfbb8817cee 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <asm/irq.h>
 #include <asm/pci.h>
 #include <asm/pirq_routing.h>
+#include <asm/tables.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct irq_router irq_router;
-static struct irq_routing_table *pirq_routing_table;
-
-bool pirq_check_irq_routed(int link, u8 irq)
+bool pirq_check_irq_routed(struct udevice *dev, int link, u8 irq)
 {
+       struct irq_router *priv = dev_get_priv(dev);
        u8 pirq;
-       int base = irq_router.link_base;
+       int base = priv->link_base;
 
-       if (irq_router.config == PIRQ_VIA_PCI)
-               pirq = x86_pci_read_config8(irq_router.bdf,
-                                           LINK_N2V(link, base));
+       if (priv->config == PIRQ_VIA_PCI)
+               dm_pci_read_config8(dev->parent, LINK_N2V(link, base), &pirq);
        else
-               pirq = readb(irq_router.ibase + LINK_N2V(link, base));
+               pirq = readb((uintptr_t)priv->ibase + LINK_N2V(link, base));
 
        pirq &= 0xf;
 
@@ -38,91 +37,96 @@ bool pirq_check_irq_routed(int link, u8 irq)
        return pirq == irq ? true : false;
 }
 
-int pirq_translate_link(int link)
+int pirq_translate_link(struct udevice *dev, int link)
 {
-       return LINK_V2N(link, irq_router.link_base);
+       struct irq_router *priv = dev_get_priv(dev);
+
+       return LINK_V2N(link, priv->link_base);
 }
 
-void pirq_assign_irq(int link, u8 irq)
+void pirq_assign_irq(struct udevice *dev, int link, u8 irq)
 {
-       int base = irq_router.link_base;
+       struct irq_router *priv = dev_get_priv(dev);
+       int base = priv->link_base;
 
        /* IRQ# 0/1/2/8/13 are reserved */
        if (irq < 3 || irq == 8 || irq == 13)
                return;
 
-       if (irq_router.config == PIRQ_VIA_PCI)
-               x86_pci_write_config8(irq_router.bdf,
-                                     LINK_N2V(link, base), irq);
+       if (priv->config == PIRQ_VIA_PCI)
+               dm_pci_write_config8(dev->parent, LINK_N2V(link, base), irq);
        else
-               writeb(irq, irq_router.ibase + LINK_N2V(link, base));
+               writeb(irq, (uintptr_t)priv->ibase + LINK_N2V(link, base));
 }
 
-static inline void fill_irq_info(struct irq_info **slotp, int *entries, u8 bus,
-                                u8 device, u8 func, u8 pin, u8 pirq)
+static struct irq_info *check_dup_entry(struct irq_info *slot_base,
+                                       int entry_num, int bus, int device)
 {
-       struct irq_info *slot = *slotp;
+       struct irq_info *slot = slot_base;
+       int i;
 
-       slot->bus = bus;
-       slot->devfn = (device << 3) | func;
-       slot->irq[pin - 1].link = LINK_N2V(pirq, irq_router.link_base);
-       slot->irq[pin - 1].bitmap = irq_router.irq_mask;
-       (*entries)++;
-       (*slotp)++;
+       for (i = 0; i < entry_num; i++) {
+               if (slot->bus == bus && slot->devfn == (device << 3))
+                       break;
+               slot++;
+       }
+
+       return (i == entry_num) ? NULL : slot;
 }
 
-__weak void cpu_irq_init(void)
+static inline void fill_irq_info(struct irq_router *priv, struct irq_info *slot,
+                                int bus, int device, int pin, int pirq)
 {
-       return;
+       slot->bus = bus;
+       slot->devfn = (device << 3) | 0;
+       slot->irq[pin - 1].link = LINK_N2V(pirq, priv->link_base);
+       slot->irq[pin - 1].bitmap = priv->irq_mask;
 }
 
-static int create_pirq_routing_table(void)
+static int create_pirq_routing_table(struct udevice *dev)
 {
+       struct irq_router *priv = dev_get_priv(dev);
        const void *blob = gd->fdt_blob;
-       struct fdt_pci_addr addr;
        int node;
        int len, count;
        const u32 *cell;
        struct irq_routing_table *rt;
-       struct irq_info *slot;
+       struct irq_info *slot, *slot_base;
        int irq_entries = 0;
        int i;
        int ret;
 
-       node = fdtdec_next_compatible(blob, 0, COMPAT_INTEL_IRQ_ROUTER);
-       if (node < 0) {
-               debug("%s: Cannot find irq router node\n", __func__);
-               return -EINVAL;
-       }
-
-       ret = fdtdec_get_pci_addr(blob, node, FDT_PCI_SPACE_CONFIG,
-                                 "reg", &addr);
-       if (ret)
-               return ret;
+       node = dev_of_offset(dev);
 
        /* extract the bdf from fdt_pci_addr */
-       irq_router.bdf = addr.phys_hi & 0xffff00;
+       priv->bdf = dm_pci_get_bdf(dev->parent);
 
-       ret = fdt_find_string(blob, node, "intel,pirq-config", "pci");
+       ret = fdt_stringlist_search(blob, node, "intel,pirq-config", "pci");
        if (!ret) {
-               irq_router.config = PIRQ_VIA_PCI;
+               priv->config = PIRQ_VIA_PCI;
        } else {
-               ret = fdt_find_string(blob, node, "intel,pirq-config", "ibase");
+               ret = fdt_stringlist_search(blob, node, "intel,pirq-config",
+                                           "ibase");
                if (!ret)
-                       irq_router.config = PIRQ_VIA_IBASE;
+                       priv->config = PIRQ_VIA_IBASE;
                else
                        return -EINVAL;
        }
 
-       ret = fdtdec_get_int_array(blob, node, "intel,pirq-link",
-                                  &irq_router.link_base, 1);
-       if (ret)
+       ret = fdtdec_get_int(blob, node, "intel,pirq-link", -1);
+       if (ret == -1)
                return ret;
+       priv->link_base = ret;
 
-       irq_router.irq_mask = fdtdec_get_int(blob, node,
-                                            "intel,pirq-mask", PIRQ_BITMAP);
+       priv->irq_mask = fdtdec_get_int(blob, node,
+                                       "intel,pirq-mask", PIRQ_BITMAP);
 
-       if (irq_router.config == PIRQ_VIA_IBASE) {
+       if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
+               /* Reserve IRQ9 for SCI */
+               priv->irq_mask &= ~(1 << 9);
+       }
+
+       if (priv->config == PIRQ_VIA_IBASE) {
                int ibase_off;
 
                ibase_off = fdtdec_get_int(blob, node, "intel,ibase-offset", 0);
@@ -139,38 +143,35 @@ static int create_pirq_routing_table(void)
                 *   2) memory range decoding is enabled.
                 * Hence we don't do any santify test here.
                 */
-               irq_router.ibase = x86_pci_read_config32(irq_router.bdf,
-                                                        ibase_off);
-               irq_router.ibase &= ~0xf;
+               dm_pci_read_config32(dev->parent, ibase_off, &priv->ibase);
+               priv->ibase &= ~0xf;
        }
 
-       cell = fdt_getprop(blob, node, "intel,pirq-routing", &len);
-       if (!cell)
-               return -EINVAL;
+       priv->actl_8bit = fdtdec_get_bool(blob, node, "intel,actl-8bit");
+       priv->actl_addr = fdtdec_get_int(blob, node, "intel,actl-addr", 0);
 
-       if ((len % sizeof(struct pirq_routing)) == 0)
-               count = len / sizeof(struct pirq_routing);
-       else
+       cell = fdt_getprop(blob, node, "intel,pirq-routing", &len);
+       if (!cell || len % sizeof(struct pirq_routing))
                return -EINVAL;
+       count = len / sizeof(struct pirq_routing);
 
-       rt = malloc(sizeof(struct irq_routing_table));
+       rt = calloc(1, sizeof(struct irq_routing_table));
        if (!rt)
                return -ENOMEM;
-       memset((char *)rt, 0, sizeof(struct irq_routing_table));
 
        /* Populate the PIRQ table fields */
        rt->signature = PIRQ_SIGNATURE;
        rt->version = PIRQ_VERSION;
-       rt->rtr_bus = 0;
-       rt->rtr_devfn = (PCI_DEV(irq_router.bdf) << 3) |
-                       PCI_FUNC(irq_router.bdf);
+       rt->rtr_bus = PCI_BUS(priv->bdf);
+       rt->rtr_devfn = (PCI_DEV(priv->bdf) << 3) | PCI_FUNC(priv->bdf);
        rt->rtr_vendor = PCI_VENDOR_ID_INTEL;
        rt->rtr_device = PCI_DEVICE_ID_INTEL_ICH7_31;
 
-       slot = rt->slots;
+       slot_base = rt->slots;
 
        /* Now fill in the irq_info entries in the PIRQ table */
-       for (i = 0; i < count; i++) {
+       for (i = 0; i < count;
+            i++, cell += sizeof(struct pirq_routing) / sizeof(u32)) {
                struct pirq_routing pr;
 
                pr.bdf = fdt_addr_to_cpu(cell[0]);
@@ -181,36 +182,108 @@ static int create_pirq_routing_table(void)
                      i, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf),
                      PCI_FUNC(pr.bdf), 'A' + pr.pin - 1,
                      'A' + pr.pirq);
-               fill_irq_info(&slot, &irq_entries, PCI_BUS(pr.bdf),
-                             PCI_DEV(pr.bdf), PCI_FUNC(pr.bdf),
+
+               slot = check_dup_entry(slot_base, irq_entries,
+                                      PCI_BUS(pr.bdf), PCI_DEV(pr.bdf));
+               if (slot) {
+                       debug("found entry for bus %d device %d, ",
+                             PCI_BUS(pr.bdf), PCI_DEV(pr.bdf));
+
+                       if (slot->irq[pr.pin - 1].link) {
+                               debug("skipping\n");
+
+                               /*
+                                * Sanity test on the routed PIRQ pin
+                                *
+                                * If they don't match, show a warning to tell
+                                * there might be something wrong with the PIRQ
+                                * routing information in the device tree.
+                                */
+                               if (slot->irq[pr.pin - 1].link !=
+                                       LINK_N2V(pr.pirq, priv->link_base))
+                                       debug("WARNING: Inconsistent PIRQ routing information\n");
+                               continue;
+                       }
+               } else {
+                       slot = slot_base + irq_entries++;
+               }
+               debug("writing INT%c\n", 'A' + pr.pin - 1);
+               fill_irq_info(priv, slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf),
                              pr.pin, pr.pirq);
-               cell += sizeof(struct pirq_routing) / sizeof(u32);
        }
 
        rt->size = irq_entries * sizeof(struct irq_info) + 32;
 
-       pirq_routing_table = rt;
+       /* Fix up the table checksum */
+       rt->checksum = table_compute_checksum(rt, rt->size);
+
+       gd->arch.pirq_routing_table = rt;
 
        return 0;
 }
 
-void pirq_init(void)
+static void irq_enable_sci(struct udevice *dev)
 {
-       cpu_irq_init();
+       struct irq_router *priv = dev_get_priv(dev);
 
-       if (create_pirq_routing_table()) {
-               debug("Failed to create pirq routing table\n");
+       if (priv->actl_8bit) {
+               /* Bit7 must be turned on to enable ACPI */
+               dm_pci_write_config8(dev->parent, priv->actl_addr, 0x80);
        } else {
-               /* Route PIRQ */
-               pirq_route_irqs(pirq_routing_table->slots,
-                               get_irq_slot_count(pirq_routing_table));
+               /* Write 0 to enable SCI on IRQ9 */
+               if (priv->config == PIRQ_VIA_PCI)
+                       dm_pci_write_config32(dev->parent, priv->actl_addr, 0);
+               else
+                       writel(0, (uintptr_t)priv->ibase + priv->actl_addr);
+       }
+}
+
+int irq_router_common_init(struct udevice *dev)
+{
+       int ret;
+
+       ret = create_pirq_routing_table(dev);
+       if (ret) {
+               debug("Failed to create pirq routing table\n");
+               return ret;
        }
+       /* Route PIRQ */
+       pirq_route_irqs(dev, gd->arch.pirq_routing_table->slots,
+                       get_irq_slot_count(gd->arch.pirq_routing_table));
+
+       if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
+               irq_enable_sci(dev);
+
+       return 0;
 }
 
-u32 write_pirq_routing_table(u32 addr)
+int irq_router_probe(struct udevice *dev)
 {
-       if (!pirq_routing_table)
+       return irq_router_common_init(dev);
+}
+
+ulong write_pirq_routing_table(ulong addr)
+{
+       if (!gd->arch.pirq_routing_table)
                return addr;
 
-       return copy_pirq_routing_table(addr, pirq_routing_table);
+       return copy_pirq_routing_table(addr, gd->arch.pirq_routing_table);
 }
+
+static const struct udevice_id irq_router_ids[] = {
+       { .compatible = "intel,irq-router" },
+       { }
+};
+
+U_BOOT_DRIVER(irq_router_drv) = {
+       .name           = "intel_irq",
+       .id             = UCLASS_IRQ,
+       .of_match       = irq_router_ids,
+       .probe          = irq_router_probe,
+       .priv_auto_alloc_size = sizeof(struct irq_router),
+};
+
+UCLASS_DRIVER(irq) = {
+       .id             = UCLASS_IRQ,
+       .name           = "irq",
+};