Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

irqchip/riscv-aplic: Add support for hart indexes

RISC-V APLIC specification defines "hart index" in:

https://github.com/riscv/riscv-aia

Within a given interrupt domain, each of the domain’s harts has a unique
index number in the range 0 to 2^14 − 1 (= 16,383). The index number a
domain associates with a hart may or may not have any relationship to the
unique hart identifier (“hart ID”) that the RISC-V Privileged Architecture
assigns to the hart. Two different interrupt domains may employ entirely
different index numbers for the same set of harts.

Further, this document says in "4.5 Memory-mapped control region for an
interrupt domain":

The array of IDC structures may include some for potential hart index
numbers that are not actual hart index numbers in the domain. For example,
the first IDC structure is always for hart index 0, but 0 is not
necessarily a valid index number for any hart in the domain.

Support arbitrary hart indices specified in an optional APLIC property
"riscv,hart-indexes" which is specified as an array of u32 elements, one
per interrupt target. If this property is not specified, fallback to use
logical hart indices within the domain.

Signed-off-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/all/20250129091637.1667279-3-vladimir.kondratiev@mobileye.com

authored by

Vladimir Kondratiev and committed by
Thomas Gleixner
b93afe8a c057b6e4

+21 -3
+21 -3
drivers/irqchip/irq-riscv-aplic-direct.c
··· 31 31 }; 32 32 33 33 struct aplic_idc { 34 - unsigned int hart_index; 34 + u32 hart_index; 35 35 void __iomem *regs; 36 36 struct aplic_direct *direct; 37 37 }; ··· 219 219 return 0; 220 220 } 221 221 222 + static int aplic_direct_get_hart_index(struct device *dev, u32 logical_index, 223 + u32 *hart_index) 224 + { 225 + const char *prop_hart_index = "riscv,hart-indexes"; 226 + struct device_node *np = to_of_node(dev->fwnode); 227 + 228 + if (!np || !of_property_present(np, prop_hart_index)) { 229 + *hart_index = logical_index; 230 + return 0; 231 + } 232 + 233 + return of_property_read_u32_index(np, prop_hart_index, logical_index, hart_index); 234 + } 235 + 222 236 int aplic_direct_setup(struct device *dev, void __iomem *regs) 223 237 { 224 238 int i, j, rc, cpu, current_cpu, setup_count = 0; ··· 279 265 cpumask_set_cpu(cpu, &direct->lmask); 280 266 281 267 idc = per_cpu_ptr(&aplic_idcs, cpu); 282 - idc->hart_index = i; 283 - idc->regs = priv->regs + APLIC_IDC_BASE + i * APLIC_IDC_SIZE; 268 + rc = aplic_direct_get_hart_index(dev, i, &idc->hart_index); 269 + if (rc) { 270 + dev_warn(dev, "hart index not found for IDC%d\n", i); 271 + continue; 272 + } 273 + idc->regs = priv->regs + APLIC_IDC_BASE + idc->hart_index * APLIC_IDC_SIZE; 284 274 idc->direct = direct; 285 275 286 276 aplic_idc_set_delivery(idc, true);