18c2ecf20Sopenharmony_ciRISC-V Hart-Level Interrupt Controller (HLIC)
28c2ecf20Sopenharmony_ci---------------------------------------------
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciRISC-V cores include Control Status Registers (CSRs) which are local to each
58c2ecf20Sopenharmony_ciCPU core (HART in RISC-V terminology) and can be read or written by software.
68c2ecf20Sopenharmony_ciSome of these CSRs are used to control local interrupts connected to the core.
78c2ecf20Sopenharmony_ciEvery interrupt is ultimately routed through a hart's HLIC before it
88c2ecf20Sopenharmony_ciinterrupts that hart.
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciThe RISC-V supervisor ISA manual specifies three interrupt sources that are
118c2ecf20Sopenharmony_ciattached to every HLIC: software interrupts, the timer interrupt, and external
128c2ecf20Sopenharmony_ciinterrupts.  Software interrupts are used to send IPIs between cores.  The
138c2ecf20Sopenharmony_citimer interrupt comes from an architecturally mandated real-time timer that is
148c2ecf20Sopenharmony_cicontrolled via Supervisor Binary Interface (SBI) calls and CSR reads.  External
158c2ecf20Sopenharmony_ciinterrupts connect all other device interrupts to the HLIC, which are routed
168c2ecf20Sopenharmony_civia the platform-level interrupt controller (PLIC).
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciAll RISC-V systems that conform to the supervisor ISA specification are
198c2ecf20Sopenharmony_cirequired to have a HLIC with these three interrupt sources present.  Since the
208c2ecf20Sopenharmony_ciinterrupt map is defined by the ISA it's not listed in the HLIC's device tree
218c2ecf20Sopenharmony_cientry, though external interrupt controllers (like the PLIC, for example) will
228c2ecf20Sopenharmony_cineed to define how their interrupts map to the relevant HLICs.  This means
238c2ecf20Sopenharmony_cia PLIC interrupt property will typically list the HLICs for all present HARTs
248c2ecf20Sopenharmony_ciin the system.
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciRequired properties:
278c2ecf20Sopenharmony_ci- compatible : "riscv,cpu-intc"
288c2ecf20Sopenharmony_ci- #interrupt-cells : should be <1>.  The interrupt sources are defined by the
298c2ecf20Sopenharmony_ci  RISC-V supervisor ISA manual, with only the following three interrupts being
308c2ecf20Sopenharmony_ci  defined for supervisor mode:
318c2ecf20Sopenharmony_ci    - Source 1 is the supervisor software interrupt, which can be sent by an SBI
328c2ecf20Sopenharmony_ci      call and is reserved for use by software.
338c2ecf20Sopenharmony_ci    - Source 5 is the supervisor timer interrupt, which can be configured by
348c2ecf20Sopenharmony_ci      SBI calls and implements a one-shot timer.
358c2ecf20Sopenharmony_ci    - Source 9 is the supervisor external interrupt, which chains to all other
368c2ecf20Sopenharmony_ci      device interrupts.
378c2ecf20Sopenharmony_ci- interrupt-controller : Identifies the node as an interrupt controller
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciFurthermore, this interrupt-controller MUST be embedded inside the cpu
408c2ecf20Sopenharmony_cidefinition of the hart whose CSRs control these local interrupts.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciAn example device tree entry for a HLIC is show below.
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	cpu1: cpu@1 {
458c2ecf20Sopenharmony_ci		compatible = "riscv";
468c2ecf20Sopenharmony_ci		...
478c2ecf20Sopenharmony_ci		cpu1-intc: interrupt-controller {
488c2ecf20Sopenharmony_ci			#interrupt-cells = <1>;
498c2ecf20Sopenharmony_ci			compatible = "sifive,fu540-c000-cpu-intc", "riscv,cpu-intc";
508c2ecf20Sopenharmony_ci			interrupt-controller;
518c2ecf20Sopenharmony_ci		};
528c2ecf20Sopenharmony_ci	};
53