162306a36Sopenharmony_ciRISC-V Hart-Level Interrupt Controller (HLIC)
262306a36Sopenharmony_ci---------------------------------------------
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciRISC-V cores include Control Status Registers (CSRs) which are local to each
562306a36Sopenharmony_ciCPU core (HART in RISC-V terminology) and can be read or written by software.
662306a36Sopenharmony_ciSome of these CSRs are used to control local interrupts connected to the core.
762306a36Sopenharmony_ciEvery interrupt is ultimately routed through a hart's HLIC before it
862306a36Sopenharmony_ciinterrupts that hart.
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciThe RISC-V supervisor ISA manual specifies three interrupt sources that are
1162306a36Sopenharmony_ciattached to every HLIC: software interrupts, the timer interrupt, and external
1262306a36Sopenharmony_ciinterrupts.  Software interrupts are used to send IPIs between cores.  The
1362306a36Sopenharmony_citimer interrupt comes from an architecturally mandated real-time timer that is
1462306a36Sopenharmony_cicontrolled via Supervisor Binary Interface (SBI) calls and CSR reads.  External
1562306a36Sopenharmony_ciinterrupts connect all other device interrupts to the HLIC, which are routed
1662306a36Sopenharmony_civia the platform-level interrupt controller (PLIC).
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciAll RISC-V systems that conform to the supervisor ISA specification are
1962306a36Sopenharmony_cirequired to have a HLIC with these three interrupt sources present.  Since the
2062306a36Sopenharmony_ciinterrupt map is defined by the ISA it's not listed in the HLIC's device tree
2162306a36Sopenharmony_cientry, though external interrupt controllers (like the PLIC, for example) will
2262306a36Sopenharmony_cineed to define how their interrupts map to the relevant HLICs.  This means
2362306a36Sopenharmony_cia PLIC interrupt property will typically list the HLICs for all present HARTs
2462306a36Sopenharmony_ciin the system.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciRequired properties:
2762306a36Sopenharmony_ci- compatible : "riscv,cpu-intc"
2862306a36Sopenharmony_ci- #interrupt-cells : should be <1>.  The interrupt sources are defined by the
2962306a36Sopenharmony_ci  RISC-V supervisor ISA manual, with only the following three interrupts being
3062306a36Sopenharmony_ci  defined for supervisor mode:
3162306a36Sopenharmony_ci    - Source 1 is the supervisor software interrupt, which can be sent by an SBI
3262306a36Sopenharmony_ci      call and is reserved for use by software.
3362306a36Sopenharmony_ci    - Source 5 is the supervisor timer interrupt, which can be configured by
3462306a36Sopenharmony_ci      SBI calls and implements a one-shot timer.
3562306a36Sopenharmony_ci    - Source 9 is the supervisor external interrupt, which chains to all other
3662306a36Sopenharmony_ci      device interrupts.
3762306a36Sopenharmony_ci- interrupt-controller : Identifies the node as an interrupt controller
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciFurthermore, this interrupt-controller MUST be embedded inside the cpu
4062306a36Sopenharmony_cidefinition of the hart whose CSRs control these local interrupts.
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciAn example device tree entry for a HLIC is show below.
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	cpu1: cpu@1 {
4562306a36Sopenharmony_ci		compatible = "riscv";
4662306a36Sopenharmony_ci		...
4762306a36Sopenharmony_ci		cpu1-intc: interrupt-controller {
4862306a36Sopenharmony_ci			#interrupt-cells = <1>;
4962306a36Sopenharmony_ci			compatible = "sifive,fu540-c000-cpu-intc", "riscv,cpu-intc";
5062306a36Sopenharmony_ci			interrupt-controller;
5162306a36Sopenharmony_ci		};
5262306a36Sopenharmony_ci	};
53