1 // SPDX-License-Identifier: GPL-2.0+
5 * U-Boot syscon driver for Andes's Platform Level Interrupt Controller (PLIC).
6 * The PLIC block holds memory-mapped claim and pending registers
7 * associated with software interrupt.
12 #include <asm/global_data.h>
13 #include <dm/device-internal.h>
15 #include <dm/uclass-internal.h>
19 #include <asm/syscon.h>
21 #include <linux/err.h>
23 /* pending register */
24 #define PENDING_REG(base, hart) ((ulong)(base) + 0x1000 + ((hart) / 4) * 4)
26 #define ENABLE_REG(base, hart) ((ulong)(base) + 0x2000 + (hart) * 0x80)
28 #define CLAIM_REG(base, hart) ((ulong)(base) + 0x200004 + (hart) * 0x1000)
30 #define ENABLE_HART_IPI (0x80808080)
31 #define SEND_IPI_TO_HART(hart) (0x80 >> (hart))
33 DECLARE_GLOBAL_DATA_PTR;
35 static int enable_ipi(int hart)
39 en = ENABLE_HART_IPI >> hart;
40 writel(en, (void __iomem *)ENABLE_REG(gd->arch.plic, hart));
45 int riscv_init_ipi(void)
48 long *base = syscon_get_first_range(RISCV_SYSCON_PLIC);
57 ret = uclass_find_first_device(UCLASS_CPU, &dev);
63 ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
64 const char *device_type;
66 device_type = ofnode_read_string(node, "device_type");
70 if (strcmp(device_type, "cpu"))
73 /* skip if hart is marked as not available */
74 if (!ofnode_is_available(node))
77 /* read hart ID of CPU */
78 ret = ofnode_read_u32(node, "reg", ®);
86 int riscv_send_ipi(int hart)
88 unsigned int ipi = (SEND_IPI_TO_HART(hart) << (8 * gd->arch.boot_hart));
90 writel(ipi, (void __iomem *)PENDING_REG(gd->arch.plic,
96 int riscv_clear_ipi(int hart)
100 source_id = readl((void __iomem *)CLAIM_REG(gd->arch.plic, hart));
101 writel(source_id, (void __iomem *)CLAIM_REG(gd->arch.plic, hart));
106 int riscv_get_ipi(int hart, int *pending)
108 *pending = readl((void __iomem *)PENDING_REG(gd->arch.plic,
109 gd->arch.boot_hart));
110 *pending = !!(*pending & SEND_IPI_TO_HART(hart));
115 static const struct udevice_id andes_plic_ids[] = {
116 { .compatible = "riscv,plic1", .data = RISCV_SYSCON_PLIC },
120 U_BOOT_DRIVER(andes_plic) = {
121 .name = "andes_plic",
123 .of_match = andes_plic_ids,
124 .flags = DM_FLAG_PRE_RELOC,