Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 18a8e09 | 2016-01-19 21:32:25 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 8 | #include <errno.h> |
| 9 | #include <fdtdec.h> |
| 10 | #include <malloc.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/irq.h> |
| 13 | #include <asm/pci.h> |
| 14 | #include <asm/pirq_routing.h> |
Bin Meng | 3371c0b | 2016-05-11 07:44:57 -0700 | [diff] [blame] | 15 | #include <asm/tables.h> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 19 | /** |
| 20 | * pirq_reg_to_linkno() - Convert a PIRQ routing register offset to link number |
| 21 | * |
| 22 | * @priv: IRQ router driver's priv data |
| 23 | * @reg: PIRQ routing register offset from the base address |
| 24 | * @return: PIRQ link number (0 for PIRQA, 1 for PIRQB, etc) |
| 25 | */ |
| 26 | static inline int pirq_reg_to_linkno(struct irq_router *priv, int reg) |
| 27 | { |
| 28 | int linkno = 0; |
| 29 | |
| 30 | if (priv->has_regmap) { |
| 31 | struct pirq_regmap *map = priv->regmap; |
| 32 | int i; |
| 33 | |
| 34 | for (i = 0; i < priv->link_num; i++) { |
| 35 | if (reg - priv->link_base == map->offset) { |
| 36 | linkno = map->link; |
| 37 | break; |
| 38 | } |
| 39 | map++; |
| 40 | } |
| 41 | } else { |
| 42 | linkno = reg - priv->link_base; |
| 43 | } |
| 44 | |
| 45 | return linkno; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * pirq_linkno_to_reg() - Convert a PIRQ link number to routing register offset |
| 50 | * |
| 51 | * @priv: IRQ router driver's priv data |
| 52 | * @linkno: PIRQ link number (0 for PIRQA, 1 for PIRQB, etc) |
| 53 | * @return: PIRQ routing register offset from the base address |
| 54 | */ |
| 55 | static inline int pirq_linkno_to_reg(struct irq_router *priv, int linkno) |
| 56 | { |
| 57 | int reg = 0; |
| 58 | |
| 59 | if (priv->has_regmap) { |
| 60 | struct pirq_regmap *map = priv->regmap; |
| 61 | int i; |
| 62 | |
| 63 | for (i = 0; i < priv->link_num; i++) { |
| 64 | if (linkno == map->link) { |
| 65 | reg = map->offset + priv->link_base; |
| 66 | break; |
| 67 | } |
| 68 | map++; |
| 69 | } |
| 70 | } else { |
| 71 | reg = linkno + priv->link_base; |
| 72 | } |
| 73 | |
| 74 | return reg; |
| 75 | } |
| 76 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 77 | bool pirq_check_irq_routed(struct udevice *dev, int link, u8 irq) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 78 | { |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 79 | struct irq_router *priv = dev_get_priv(dev); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 80 | u8 pirq; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 81 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 82 | if (priv->config == PIRQ_VIA_PCI) |
Bin Meng | 1defbb1 | 2018-06-03 19:04:23 -0700 | [diff] [blame] | 83 | dm_pci_read_config8(dev->parent, |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 84 | pirq_linkno_to_reg(priv, link), &pirq); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 85 | else |
Bin Meng | 1defbb1 | 2018-06-03 19:04:23 -0700 | [diff] [blame] | 86 | pirq = readb((uintptr_t)priv->ibase + |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 87 | pirq_linkno_to_reg(priv, link)); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 88 | |
| 89 | pirq &= 0xf; |
| 90 | |
| 91 | /* IRQ# 0/1/2/8/13 are reserved */ |
| 92 | if (pirq < 3 || pirq == 8 || pirq == 13) |
| 93 | return false; |
| 94 | |
| 95 | return pirq == irq ? true : false; |
| 96 | } |
| 97 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 98 | int pirq_translate_link(struct udevice *dev, int link) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 99 | { |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 100 | struct irq_router *priv = dev_get_priv(dev); |
| 101 | |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 102 | return pirq_reg_to_linkno(priv, link); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 103 | } |
| 104 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 105 | void pirq_assign_irq(struct udevice *dev, int link, u8 irq) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 106 | { |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 107 | struct irq_router *priv = dev_get_priv(dev); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 108 | |
| 109 | /* IRQ# 0/1/2/8/13 are reserved */ |
| 110 | if (irq < 3 || irq == 8 || irq == 13) |
| 111 | return; |
| 112 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 113 | if (priv->config == PIRQ_VIA_PCI) |
Bin Meng | 1defbb1 | 2018-06-03 19:04:23 -0700 | [diff] [blame] | 114 | dm_pci_write_config8(dev->parent, |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 115 | pirq_linkno_to_reg(priv, link), irq); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 116 | else |
Bin Meng | 1defbb1 | 2018-06-03 19:04:23 -0700 | [diff] [blame] | 117 | writeb(irq, (uintptr_t)priv->ibase + |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 118 | pirq_linkno_to_reg(priv, link)); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 121 | static struct irq_info *check_dup_entry(struct irq_info *slot_base, |
| 122 | int entry_num, int bus, int device) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 123 | { |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 124 | struct irq_info *slot = slot_base; |
| 125 | int i; |
| 126 | |
| 127 | for (i = 0; i < entry_num; i++) { |
| 128 | if (slot->bus == bus && slot->devfn == (device << 3)) |
| 129 | break; |
| 130 | slot++; |
| 131 | } |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 132 | |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 133 | return (i == entry_num) ? NULL : slot; |
| 134 | } |
| 135 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 136 | static inline void fill_irq_info(struct irq_router *priv, struct irq_info *slot, |
| 137 | int bus, int device, int pin, int pirq) |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 138 | { |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 139 | slot->bus = bus; |
Bin Meng | 3a531a3 | 2015-06-23 12:18:46 +0800 | [diff] [blame] | 140 | slot->devfn = (device << 3) | 0; |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 141 | slot->irq[pin - 1].link = pirq_linkno_to_reg(priv, pirq); |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 142 | slot->irq[pin - 1].bitmap = priv->irq_mask; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 143 | } |
| 144 | |
Simon Glass | ddcafd6 | 2016-01-19 21:32:28 -0700 | [diff] [blame] | 145 | static int create_pirq_routing_table(struct udevice *dev) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 146 | { |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 147 | struct irq_router *priv = dev_get_priv(dev); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 148 | const void *blob = gd->fdt_blob; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 149 | int node; |
| 150 | int len, count; |
| 151 | const u32 *cell; |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 152 | struct pirq_regmap *map; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 153 | struct irq_routing_table *rt; |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 154 | struct irq_info *slot, *slot_base; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 155 | int irq_entries = 0; |
| 156 | int i; |
| 157 | int ret; |
| 158 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 159 | node = dev_of_offset(dev); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 160 | |
| 161 | /* extract the bdf from fdt_pci_addr */ |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 162 | priv->bdf = dm_pci_get_bdf(dev->parent); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 163 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 164 | ret = fdt_stringlist_search(blob, node, "intel,pirq-config", "pci"); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 165 | if (!ret) { |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 166 | priv->config = PIRQ_VIA_PCI; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 167 | } else { |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 168 | ret = fdt_stringlist_search(blob, node, "intel,pirq-config", |
| 169 | "ibase"); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 170 | if (!ret) |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 171 | priv->config = PIRQ_VIA_IBASE; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 172 | else |
| 173 | return -EINVAL; |
| 174 | } |
| 175 | |
Bin Meng | c332fca | 2018-06-12 01:26:45 -0700 | [diff] [blame] | 176 | cell = fdt_getprop(blob, node, "intel,pirq-link", &len); |
| 177 | if (!cell || len != 8) |
| 178 | return -EINVAL; |
| 179 | priv->link_base = fdt_addr_to_cpu(cell[0]); |
| 180 | priv->link_num = fdt_addr_to_cpu(cell[1]); |
| 181 | if (priv->link_num > CONFIG_MAX_PIRQ_LINKS) { |
| 182 | debug("Limiting supported PIRQ link number from %d to %d\n", |
| 183 | priv->link_num, CONFIG_MAX_PIRQ_LINKS); |
| 184 | priv->link_num = CONFIG_MAX_PIRQ_LINKS; |
| 185 | } |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 186 | |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 187 | cell = fdt_getprop(blob, node, "intel,pirq-regmap", &len); |
| 188 | if (cell) { |
| 189 | if (len % sizeof(struct pirq_regmap)) |
| 190 | return -EINVAL; |
| 191 | |
| 192 | count = len / sizeof(struct pirq_regmap); |
| 193 | if (count < priv->link_num) { |
| 194 | printf("Number of pirq-regmap entires is wrong\n"); |
| 195 | return -EINVAL; |
| 196 | } |
| 197 | |
| 198 | count = priv->link_num; |
| 199 | priv->regmap = calloc(count, sizeof(struct pirq_regmap)); |
| 200 | if (!priv->regmap) |
| 201 | return -ENOMEM; |
| 202 | |
| 203 | priv->has_regmap = true; |
| 204 | map = priv->regmap; |
| 205 | for (i = 0; i < count; i++) { |
| 206 | map->link = fdt_addr_to_cpu(cell[0]); |
| 207 | map->offset = fdt_addr_to_cpu(cell[1]); |
| 208 | |
| 209 | cell += sizeof(struct pirq_regmap) / sizeof(u32); |
| 210 | map++; |
| 211 | } |
| 212 | } |
| 213 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 214 | priv->irq_mask = fdtdec_get_int(blob, node, |
| 215 | "intel,pirq-mask", PIRQ_BITMAP); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 216 | |
Bin Meng | 61ad371 | 2016-05-07 07:46:13 -0700 | [diff] [blame] | 217 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) { |
| 218 | /* Reserve IRQ9 for SCI */ |
| 219 | priv->irq_mask &= ~(1 << 9); |
| 220 | } |
| 221 | |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 222 | if (priv->config == PIRQ_VIA_IBASE) { |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 223 | int ibase_off; |
| 224 | |
| 225 | ibase_off = fdtdec_get_int(blob, node, "intel,ibase-offset", 0); |
| 226 | if (!ibase_off) |
| 227 | return -EINVAL; |
| 228 | |
| 229 | /* |
| 230 | * Here we assume that the IBASE register has already been |
| 231 | * properly configured by U-Boot before. |
| 232 | * |
| 233 | * By 'valid' we mean: |
| 234 | * 1) a valid memory space carved within system memory space |
| 235 | * assigned to IBASE register block. |
| 236 | * 2) memory range decoding is enabled. |
| 237 | * Hence we don't do any santify test here. |
| 238 | */ |
Bin Meng | bfe20b7 | 2016-02-01 01:40:52 -0800 | [diff] [blame] | 239 | dm_pci_read_config32(dev->parent, ibase_off, &priv->ibase); |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 240 | priv->ibase &= ~0xf; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 241 | } |
| 242 | |
Bin Meng | c3b03ea | 2016-05-07 07:46:14 -0700 | [diff] [blame] | 243 | priv->actl_8bit = fdtdec_get_bool(blob, node, "intel,actl-8bit"); |
| 244 | priv->actl_addr = fdtdec_get_int(blob, node, "intel,actl-addr", 0); |
| 245 | |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 246 | cell = fdt_getprop(blob, node, "intel,pirq-routing", &len); |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 247 | if (!cell || len % sizeof(struct pirq_routing)) |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 248 | return -EINVAL; |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 249 | count = len / sizeof(struct pirq_routing); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 250 | |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 251 | rt = calloc(1, sizeof(struct irq_routing_table)); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 252 | if (!rt) |
| 253 | return -ENOMEM; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 254 | |
| 255 | /* Populate the PIRQ table fields */ |
| 256 | rt->signature = PIRQ_SIGNATURE; |
| 257 | rt->version = PIRQ_VERSION; |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 258 | rt->rtr_bus = PCI_BUS(priv->bdf); |
| 259 | rt->rtr_devfn = (PCI_DEV(priv->bdf) << 3) | PCI_FUNC(priv->bdf); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 260 | rt->rtr_vendor = PCI_VENDOR_ID_INTEL; |
| 261 | rt->rtr_device = PCI_DEVICE_ID_INTEL_ICH7_31; |
| 262 | |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 263 | slot_base = rt->slots; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 264 | |
| 265 | /* Now fill in the irq_info entries in the PIRQ table */ |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 266 | for (i = 0; i < count; |
| 267 | i++, cell += sizeof(struct pirq_routing) / sizeof(u32)) { |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 268 | struct pirq_routing pr; |
| 269 | |
| 270 | pr.bdf = fdt_addr_to_cpu(cell[0]); |
| 271 | pr.pin = fdt_addr_to_cpu(cell[1]); |
| 272 | pr.pirq = fdt_addr_to_cpu(cell[2]); |
| 273 | |
| 274 | debug("irq_info %d: b.d.f %x.%x.%x INT%c PIRQ%c\n", |
| 275 | i, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), |
| 276 | PCI_FUNC(pr.bdf), 'A' + pr.pin - 1, |
| 277 | 'A' + pr.pirq); |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 278 | |
| 279 | slot = check_dup_entry(slot_base, irq_entries, |
| 280 | PCI_BUS(pr.bdf), PCI_DEV(pr.bdf)); |
| 281 | if (slot) { |
| 282 | debug("found entry for bus %d device %d, ", |
| 283 | PCI_BUS(pr.bdf), PCI_DEV(pr.bdf)); |
| 284 | |
| 285 | if (slot->irq[pr.pin - 1].link) { |
| 286 | debug("skipping\n"); |
| 287 | |
| 288 | /* |
| 289 | * Sanity test on the routed PIRQ pin |
| 290 | * |
| 291 | * If they don't match, show a warning to tell |
| 292 | * there might be something wrong with the PIRQ |
| 293 | * routing information in the device tree. |
| 294 | */ |
| 295 | if (slot->irq[pr.pin - 1].link != |
Bin Meng | d803f54 | 2018-06-12 01:26:46 -0700 | [diff] [blame] | 296 | pirq_linkno_to_reg(priv, pr.pirq)) |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 297 | debug("WARNING: Inconsistent PIRQ routing information\n"); |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 298 | continue; |
| 299 | } |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 300 | } else { |
| 301 | slot = slot_base + irq_entries++; |
Bin Meng | 16758a3 | 2015-06-23 12:18:47 +0800 | [diff] [blame] | 302 | } |
Simon Glass | 3b1ed8a | 2015-08-10 07:05:06 -0600 | [diff] [blame] | 303 | debug("writing INT%c\n", 'A' + pr.pin - 1); |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 304 | fill_irq_info(priv, slot, PCI_BUS(pr.bdf), PCI_DEV(pr.bdf), |
| 305 | pr.pin, pr.pirq); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | rt->size = irq_entries * sizeof(struct irq_info) + 32; |
| 309 | |
Bin Meng | 3371c0b | 2016-05-11 07:44:57 -0700 | [diff] [blame] | 310 | /* Fix up the table checksum */ |
| 311 | rt->checksum = table_compute_checksum(rt, rt->size); |
| 312 | |
Simon Glass | f64d6f7 | 2017-01-16 07:04:16 -0700 | [diff] [blame] | 313 | gd->arch.pirq_routing_table = rt; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Bin Meng | c3b03ea | 2016-05-07 07:46:14 -0700 | [diff] [blame] | 318 | static void irq_enable_sci(struct udevice *dev) |
| 319 | { |
| 320 | struct irq_router *priv = dev_get_priv(dev); |
| 321 | |
| 322 | if (priv->actl_8bit) { |
| 323 | /* Bit7 must be turned on to enable ACPI */ |
| 324 | dm_pci_write_config8(dev->parent, priv->actl_addr, 0x80); |
| 325 | } else { |
| 326 | /* Write 0 to enable SCI on IRQ9 */ |
| 327 | if (priv->config == PIRQ_VIA_PCI) |
| 328 | dm_pci_write_config32(dev->parent, priv->actl_addr, 0); |
| 329 | else |
Bin Meng | 95e4a39 | 2017-01-18 03:32:56 -0800 | [diff] [blame] | 330 | writel(0, (uintptr_t)priv->ibase + priv->actl_addr); |
Bin Meng | c3b03ea | 2016-05-07 07:46:14 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Bin Meng | 0c9f594 | 2018-06-03 19:04:22 -0700 | [diff] [blame] | 334 | int irq_router_probe(struct udevice *dev) |
Simon Glass | 18a8e09 | 2016-01-19 21:32:25 -0700 | [diff] [blame] | 335 | { |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 336 | int ret; |
| 337 | |
Simon Glass | ddcafd6 | 2016-01-19 21:32:28 -0700 | [diff] [blame] | 338 | ret = create_pirq_routing_table(dev); |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 339 | if (ret) { |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 340 | debug("Failed to create pirq routing table\n"); |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 341 | return ret; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 342 | } |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 343 | /* Route PIRQ */ |
Simon Glass | f64d6f7 | 2017-01-16 07:04:16 -0700 | [diff] [blame] | 344 | pirq_route_irqs(dev, gd->arch.pirq_routing_table->slots, |
| 345 | get_irq_slot_count(gd->arch.pirq_routing_table)); |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 346 | |
Bin Meng | c3b03ea | 2016-05-07 07:46:14 -0700 | [diff] [blame] | 347 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) |
| 348 | irq_enable_sci(dev); |
| 349 | |
Simon Glass | af1c2d68 | 2015-08-10 07:05:08 -0600 | [diff] [blame] | 350 | return 0; |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 351 | } |
| 352 | |
Simon Glass | 18a8e09 | 2016-01-19 21:32:25 -0700 | [diff] [blame] | 353 | static const struct udevice_id irq_router_ids[] = { |
| 354 | { .compatible = "intel,irq-router" }, |
| 355 | { } |
| 356 | }; |
| 357 | |
| 358 | U_BOOT_DRIVER(irq_router_drv) = { |
| 359 | .name = "intel_irq", |
| 360 | .id = UCLASS_IRQ, |
| 361 | .of_match = irq_router_ids, |
| 362 | .probe = irq_router_probe, |
Bin Meng | a5a2003 | 2016-02-01 01:40:51 -0800 | [diff] [blame] | 363 | .priv_auto_alloc_size = sizeof(struct irq_router), |
Simon Glass | 18a8e09 | 2016-01-19 21:32:25 -0700 | [diff] [blame] | 364 | }; |