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