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