summaryrefslogtreecommitdiff
path: root/lib/utils/irqchip
AgeCommit message (Collapse)AuthorFilesLines
2025-02-19lib: utils/irqchip: Match against more specific compatible strings firstAlex Studer1-1/+7
The T-HEAD C90x PLIC has some special quirks, such as the S-mode delegation bit. OpenSBI currently handles this by checking the compatible string in the device tree. However, this matching is done in the order of the fdt_match array. So if a device tree contains both strings, for example: compatible = "thead,c900-plic", "riscv,plic0"; Then OpenSBI will match against the generic "riscv,plic0" string, since that appears first in the fdt_match array. This means it will fail to set the S-mode delegation bit, and Linux will fail to boot. In some cases, it is not possible to change the compatible string to just the T-HEAD PLIC, as older versions of Linux only recognize the RISC-V compatible string. This patch fixes that by moving the RISC-V string to the end, ensuring that the more specific options get matched first. Signed-off-by: Alex Studer <alex@studer.dev> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12lib: utils/irqchip: Use fdt_driver for initializationSamuel Holland5-36/+9
The irqchip driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_irqchip_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-24lib: utils: Fix irqchip registration for PLIC and APLICAnup Patel2-11/+3
Currently, the same irqchip instance is registered for multiple PLIC and APLIC instances which causes the sbi_list_for_each_entry() loop in the sbi_irqchip_init() to hang at boot-time. To address the above issue, register a separate irqchip instance for each PLIC and APLIC instance. Fixes: 2dd6eaf68055 ("lib: sbi_irqchip: Call driver warm_init from SBI core") Reported-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Himanshu Chauhan <hchauhan@ventanamicro.com>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland1-3/+2
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: sbi_irqchip: Set the IRQ handler when registering a chipSamuel Holland1-3/+1
In addition to saving some code size, this moves the decision about setting the top-level external interrupt handler to the irqchip core, not the specific driver, which would be needed to support chained interrupt handlers. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28platform: Drop irqchip warm init and exit hooksSamuel Holland4-61/+1
Now that driver lifecycle is managed from within the SBI irqchip core, platforms need only to initialize the driver once during cold init. Remove the remaining platform hooks that are no longer used. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: sbi_irqchip: Call driver warm_init from SBI coreSamuel Holland5-11/+7
Currently, each platform keeps track of which irqchip driver is in use and calls its warm init function. Since the generic platform may use multiple irqchip drivers, it has logic to track an array of drivers. The code is simplified and made common across platforms by treating warm init and exit as properties of the driver, not the platform. Then the platform's only role is to select and prepare a driver during cold boot. For now, only add a .warm_init hook, since none of the existing drivers need an .exit hook. It could be added in the future if needed. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: sbi_irqchip: Register devices during cold initSamuel Holland3-0/+20
Have the SBI irqchip core keep track of registered irqchip devices. This is useful for any callbacks the irqchip driver may have, such as for warm initialization, the external interrupt handler function, and any future support for handling external interrupts (beyond IPIs) in M-mode. This improves on the tracking done in fdt_irqchip.c, as it tracks device instances, not just drivers, so callbacks can target a specific device. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/irqchip: Move per-hart data from fdt_plic to plicSamuel Holland2-52/+46
The per-hart PLIC pointer is not really specific to FDT platforms. Move it into the main driver and drop the extra wrapper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/irqchip: plic: Common PM save/restoreSamuel Holland2-71/+95
Move the PLIC save/restore functions inside the driver, so they can be reused on any platform that needs them. The memory needed to store the PLIC context is also allocated by the driver. The PM data cannot be completely encapsulated, as some platforms (including Allwinner D1) need to program the IRQ enable status to a sideband interrupt controller for wakeup capability. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/irqchip: plic: Provide a hartindex to context mapSamuel Holland2-50/+26
This removes platform-specific arguments to plic_warm_irqchip_init(), which makes the driver independent from the platform after cold init, and allows for further refactoring. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/irqchip: plic: Move delegation to base PLIC driverSamuel Holland2-13/+14
This needs to be in the base PLIC driver as part of the power management save/restore flow. This is also in preparation for moving the PLIC information in the scratch area to the base PLIC driver. After that change, the FDT PLIC layer will be unable to look up the `struct plic_data` after cold boot. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/irqchip: plic: Allow enabling IRQs by defaultSamuel Holland1-6/+11
Unlike other platforms, Ariane and OpenPiton enable all IRQs by default. This was described in commit b44e844880d0 ("Add support for Ariane FPGA SoC") as "due to some issue of the design." Add this workaround behind a flag in plic_warm_irqchip_init(), so every platform can use the same warm init function. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-10-25lib: utils/irqchip: Use sbi_domain_root_add_memrange() for APLICAnup Patel1-7/+4
The sbi_domain_root_add_memrange() should be preferred for creating multiple memregions over a range. Update APLIC driver to use sbi_domain_root_add_memrange() instead of explicitly registering memregions. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2024-10-25lib: utils/irqchip: Use sbi_domain_root_add_memrange() for IMSICAnup Patel1-8/+6
The sbi_domain_root_add_memrange() should be preferred for creating multiple memregions over a range. Update IMSIC driver to use sbi_domain_root_add_memrange() instead of explicitly registering memregions. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2024-09-25lib: utils/irqchip: Look up IMSIC data by hart indexSamuel Holland1-5/+5
This avoids needing to map a hartid to a hart index. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: Delete redundant `ulong`Zhang RunMin1-1/+1
In `csr_read_allowed` and `csr_write_allowed` macros, has already converted second param to `ulong`. So delete redundant `ulong` where uses csr_read/write_allowed macros. Signed-off-by: Zhang RunMin <runmin.zhang@ingenic.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: utils/irqchip: Constify FDT pointers in parsing functionsSamuel Holland4-8/+8
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-04Makefile: change to using .carray.c for carray filesBen Dooks1-1/+1
We would like to clean any files generated by the carray scripts by just searching for the filename as the current make system turns f.carray into f.o. Change to make the make system turn f.carray into f.carray.o note, command to go through .mk files changing the .o in the .mk files is: find . -type f -name "*.carray" | xargs -t -I fname /bin/bash -x -c ' fn=`basename -s .carray fname`; echo "$fn"; sed -i `dirname fname `/objects.mk -e s/"$fn".o/"$fn".carray.o/g' Link: https://patchwork.ozlabs.org/project/opensbi/patch/20240401213438.590209-2-ivan.orlov0322@gmail.com/ Reported-by: Ivan Orlov <ivan.orlov0322@gmail.com> Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-06-13lib: utils/irqchip: Skip initialize irqchip when dt is not enabledXiang W1-0/+3
When the dt node has a status property and the value is not ok or okay, skip initializing irqchip. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-05-23lib: utils/irqchip: Add sanity checks in imsic_get_data() and ↵Cyan Yang1-0/+6
imsic_get_target_file() Add extra sanity checks to prevent the caller getting the invalid result from imsic_get_data() or imsic_get_target_file() when imsic is not initialized correctly. Signed-off-by: Cyan Yang <cyan.yang@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-05-16lib: utils/irqchip: Check before initializing imsicCheng Yang1-0/+8
The current mlevel imsic check is only for the platform, which may cause hart without imsic in the platform to trigger an illegal instruction exception when initializing imsic. For example, the platform contains a management hart that only supports wired interrupts. This patch will check if each hart supports Smaia extension before doing imsic initialization to avoid triggering illegal instruction exceptions. Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-19lib: sbi: Remove regs paramter of sbi_irqchip_process()Anup Patel1-1/+1
The irqchip handlers will typically not need pointer to trap registers so remove regs parameter of sbi_irqchip_process(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Clément Léger <cleger@rivosinc.com>
2023-12-19lib: utils/irqchip: Add shared MMIO region for PLIC in root domainAnup Patel1-1/+5
On platforms with Smepmp, the MMIO regions accessed by M-mode need to be explicitly marked with M-mode only read/write or shared (both (M-mode and S-mode) read/write permission. If the above is not done then runtime PLIC access from M-mode on platforms with Smepmp will result in access fault when further results in CPU hotplug not working. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-11-26lib: sbi: Allow relaxed MMIO writes in device ipi_send() callbackAnup Patel1-2/+2
Currently, we have a smp_wmb() between atomic_raw_set_bit() and ipi_send() device callback whereas the MMIO writes done by the device ipi_send() callback will also include a barrier. We can avoid unnecessary/redundant barriers described above by allowing relaxed MMIO writes in device ipi_send() callback. To achieve this, we simply use wmb() instead of smp_wmb() before calling device ipi_send(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reported-by: Bo Gan <ganboing@gmail.com>
2023-11-24lib: utils/irqchip: Avoid redundant writes to APLIC CLRIE registerAnup Patel1-1/+1
Each APLIC CLRIE register allows disabling 32 interrupt sources at a time by writing -1 so no need to write CLRIE register separately for each interrupt source. Fixes: 99792653de29 ("lib: utils/irqchip: Add APLIC initialization library") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2023-09-24lib: sbi: Prefer hartindex over hartid in IPI frameworkAnup Patel1-2/+2
Let us prefer hartindex over hartid in IPI framework which in-turn forces IPI users to also prefer hartindex. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-06-06lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointerAnup Patel2-17/+70
Instead of using a global array indexed by hartid, we should use scratch space to save per-HART IMSIC pointer and IMSIC file number. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05lib: utils/irqchip: Don't check hartid in imsic_update_hartid_table()Anup Patel1-3/+0
The imsic_map_hartid_to_data() already checks hartid before using so we don't need to check in imsic_update_hartid_table(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05lib: utils/irqchip: Use scratch space to save per-HART PLIC pointerAnup Patel1-22/+66
Instead of using a global array indexed by hartid, we should use scratch space to save per-HART PLIC pointer and PLIC context numbers. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-06-05lib: utils/irqchip: Use heap in PLIC, APLIC and IMSIC driversAnup Patel3-46/+42
Let's use heap allocation in PLIC, APLIC, and IMSIC irqchip drivers instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-01-09lib: utils: Add M-mode {R/W} flags to the MMIO regionsHimanshu Chauhan2-2/+8
Add the M-mode readable/writable flags to mmio regions of various drivers. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Tested-by: Anup Patel <anup@brainfault.org>
2022-12-17lib: utils/irqchip: plic: Ensure no out-of-bound access in context ↵Bin Meng2-8/+15
save/restore helpers Currently the context save/restore helpers writes/reads the provided array using an index whose maximum value is determined by PLIC, which potentially may disagree with the caller to these helpers. Add a parameter to ask the caller to provide the size limit of the array to ensure no out-of-bound access happens. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-12-17lib: utils/irqchip: plic: Fix the off-by-one error in context save/restore ↵Bin Meng1-2/+2
helpers plic->num_src holds the number of interrupt sources without interrupt source 0 but the interrupt enable register includes a bit for the interrupt source 0 in the first word. Fixes: 415ecf28f7ad ("lib: irqchip/plic: Add context save/restore helpers") Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org>
2022-12-17lib: utils/irqchip: plic: Fix the off-by-one error in plic_context_init()Bin Meng1-1/+1
The number of interrupt enable register in words was once correct, but was wrongly changed to have an off-by-one error since commit 8c362e7d065e ("lib: irqchip/plic: Factor out a context init function"). Fixes: 8c362e7d065e ("lib: irqchip/plic: Factor out a context init function") Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org>
2022-12-17lib: utils/irqchip: plic: Ensure no out-of-bound access in priority ↵Bin Meng2-8/+9
save/restore helpers Currently the priority save/restore helpers writes/reads the provided array using an index whose maximum value is determined by PLIC, which potentially may disagree with the caller to these helpers. Add a parameter to ask the caller to provide the size limit of the array to ensure no out-of-bound access happens. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-12-17lib: utils/irqchip: plic: Fix the off-by-one error in priority save/restore ↵Bin Meng1-2/+2
helpers Interrupt source 0 is reserved. Hence the irq should start from 1. Fixes: 2b79b694a805 ("lib: irqchip/plic: Add priority save/restore helpers") Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-12-12lib: utils/irqchip: Add compatible string for Andestech NCEPLIC100Lad Prabhakar1-1/+2
Add compatible string for Andestech NCEPLIC100 found on Renesas RZ/Five SoC which is equipped with AX45MP AndesCore. While at it drop the comma after the sentinel as it does not make sense to have a comma after a sentinel, as any new elements must be added before the sentinel. dts example (Single-core AX45MP): soc: soc { .... plic: interrupt-controller@12c00000 { compatible = "renesas,r9a07g043-plic", "andestech,nceplic100"; #interrupt-cells = <2>; #address-cells = <0>; riscv,ndev = <511>; interrupt-controller; reg = <0x0 0x12c00000 0 0x400000>; clocks = <&cpg CPG_MOD R9A07G043_NCEPLIC_ACLK>; power-domains = <&cpg>; resets = <&cpg R9A07G043_NCEPLIC_ARESETN>; interrupts-extended = <&cpu0_intc 11 &cpu0_intc 9>; }; .... }; Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Bin Meng <bmeng@tinylab.org>
2022-12-09lib: fix irqchip_plic_update_hartid_tableHeinrich Schuchardt1-1/+1
After determining cpu_offset we have to check this value. Addresses-Coverity-ID: 1529706 ("Logically dead code") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-08lib: utils/fdt: Use kconfig for enabling/disablingAnup Patel1-0/+1
We update FDT support makefile to use kconfig for enabling/disabling. To avoid compilation errors, we also enable FDT for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/irqchip: Use kconfig for enabling/disabling driversAnup Patel2-11/+51
We update irqchip drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate irqchip drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-06-22lib: irqchip/plic: fix typo in plic_warm_irqchip_initJan Remes1-1/+1
The second invocation of plic_context_init() incorrectly calls the function with m_cntx_id instead of s_cntx_id. This breaks systems which only have 1 external interrupt per hart. Fixes: 8c362e7 ("lib: irqchip/plic: Factor out a context init function") Signed-off-by: Jan Remes <jan.remes@codasip.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org>
2022-06-21lib: utils: Remove CSRs that set/clear an IMSIC interrupt file bitsAnup Patel1-6/+45
Based on architecture review committee feedback, the [m|s|vs]seteienum, [m|s|vs]clreienum, [m|s|vs]seteipnum, and [m|s|vs]clreipnum CSRs are removed in the latest AIA draft v0.3.0 specification. (Refer, https://github.com/riscv/riscv-aia/releases/tag/0.3.0-draft.31) These CSRs were mostly for software convenience and software can always use [m|s|vs]iselect and [m|s|vs]ireg CSRs to update the IMSIC interrupt file bits. We update the IMSIC programming as-per above to match the latest AIA draft specification. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-06-13lib: utils/irqchip: Add wrapper for T-HEAD PLIC delegationSamuel Holland1-0/+7
The delegation bit is lost along with the rest of the PLIC state when the CPU power domain in the Allwinner D1 is powered down, so the PLIC needs to be re-delegated to S-mode during the hart resume path. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-06-13lib: utils/irqchip: Add FDT wrappers for PLIC save/restore functionsSamuel Holland1-0/+32
These functions save/restore the state of the PLIC associated with the current hart. The context save/restore functions only manipulate a single context, since most likely the M-mode context is unused and does not need to be saved. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-06-13lib: irqchip/plic: Add priority save/restore helpersSamuel Holland1-0/+19
These can be used by platform code to save the PLIC priority state, if it would otherwise be lost during non-retentive suspend. The platform is responsible for allocating all necessary storage. As a space optimization, store the saved priority values as 8-bit integers, since that is large enough to hold any priority value on the relevant platforms. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-06-13lib: irqchip/plic: Add context save/restore helpersSamuel Holland1-3/+48
These can be used by platform code to save the PLIC context state, if it would otherwise be lost during non-retentive suspend. The platform is responsible for allocating all necessary storage. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-06-13lib: irqchip/plic: Factor out a context init functionSamuel Holland1-26/+29
This simplifies both the callers and the callees by removing duplicated code and consolidating the error handling. It also fixes two bugs in the process: 1) ie_words was one too large when plic->num_src was a multiple of 32. 2) plic_set_ie takes a 32-bit mask, not a Boolean value, so the FPGA platforms previously only enabled one out of every 32 interrupts. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-06-13lib: irqchip/plic: Constify plic_data pointersSamuel Holland1-5/+6
None of the functions modify the passed-in plic_data, so mark it const. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel@sholland.org>
2022-05-13lib: utils/irqchip: fix typo when checking for CPU nodeJan Remes1-1/+1
Fix typo in irqchip_imsic_update_hartid_table() when checking for CPU node. Signed-off-by: Jan Remes <jan.remes@codasip.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>