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