LoongArch
Single-page view · as markdown
LoongArch Architecture
Peios Kernel / Hardware and drivers / Processor architectures / LoongArch
Booting Linux/LoongArch
Peios Kernel / Hardware and drivers / Processor architectures / LoongArch
Author: Yanteng Si <siyanteng@loongson.cn>
Date: 18 Nov 2022
Information passed from BootLoader to kernel #
LoongArch supports ACPI and FDT. The information that needs to be passed to the kernel includes the memmap, the initrd, the command line, optionally the ACPI/FDT tables, and so on.
The kernel is passed the following arguments on kernel_entry :
a0 = efi_boot:
efi_bootis a flag indicating whether this boot environment is fully UEFI-compliant.a1 = cmdline:
cmdlineis a pointer to the kernel command line.a2 = systemtable:
systemtablepoints to the EFI system table. All pointers involved at this stage are in physical addresses.
Header of Linux/LoongArch kernel images #
Linux/LoongArch kernel images are EFI images. Being PE files, they have a 64-byte header structured like:
u32 MZ_MAGIC /* "MZ", MS-DOS header */
u32 res0 = 0 /* Reserved */
u64 kernel_entry /* Kernel entry point */
u64 _end - _text /* Kernel image effective size */
u64 load_offset /* Kernel image load offset from start of RAM */
u64 res1 = 0 /* Reserved */
u64 res2 = 0 /* Reserved */
u64 res3 = 0 /* Reserved */
u32 LINUX_PE_MAGIC /* Magic number */
u32 pe_header - _head /* Offset to the PE header */
Feature status on loongarch architecture
Peios Kernel / Hardware and drivers / Processor architectures / LoongArch
| Subsystem | Feature | Kconfig | Status | Description |
|---|---|---|---|---|
| core | cBPF-JIT | HAVE_CBPF_JIT | TODO | arch supports cBPF JIT optimizations |
| core | eBPF-JIT | HAVE_EBPF_JIT | ok | arch supports eBPF JIT optimizations |
| core | generic-idle-thread | GENERIC_SMP_IDLE_THREAD | ok | arch makes use of the generic SMP idle thread facility |
| core | jump-labels | HAVE_ARCH_JUMP_LABEL | ok | arch supports live patched, high efficiency branches |
| core | mseal-system-mappings | ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS | ok | arch supports mseal system mappings |
| core | thread-info-in-task | THREAD_INFO_IN_TASK | TODO | arch makes use of the core kernel facility to embed thread_info in task_struct |
| core | tracehook | HAVE_ARCH_TRACEHOOK | ok | arch supports tracehook (ptrace) register handling APIs |
| debug | debug-vm-pgtable | ARCH_HAS_DEBUG_VM_PGTABLE | ok | arch supports pgtable tests for semantics compliance |
| debug | gcov-profile-all | ARCH_HAS_GCOV_PROFILE_ALL | TODO | arch supports whole-kernel GCOV code coverage profiling |
| debug | KASAN | HAVE_ARCH_KASAN | ok | arch supports the KASAN runtime memory checker |
| debug | kcov | ARCH_HAS_KCOV | ok | arch supports kcov for coverage-guided fuzzing |
| debug | kgdb | HAVE_ARCH_KGDB | ok | arch supports the kGDB kernel debugger |
| debug | kmemleak | HAVE_DEBUG_KMEMLEAK | ok | arch supports the kernel memory leak detector |
| debug | kprobes | HAVE_KPROBES | ok | arch supports live patched kernel probe |
| debug | kprobes-on-ftrace | HAVE_KPROBES_ON_FTRACE | ok | arch supports combined kprobes and ftrace live patching |
| debug | kretprobes | HAVE_KRETPROBES | ok | arch supports kernel function-return probes |
| debug | optprobes | HAVE_OPTPROBES | TODO | arch supports live patched optprobes |
| debug | stackprotector | HAVE_STACKPROTECTOR | ok | arch supports compiler driven stack overflow protection |
| debug | uprobes | ARCH_SUPPORTS_UPROBES | ok | arch supports live patched user probes |
| debug | user-ret-profiler | HAVE_USER_RETURN_NOTIFIER | TODO | arch supports user-space return from system call profiler |
| io | dma-contiguous | HAVE_DMA_CONTIGUOUS | ok | arch supports the DMA CMA (continuous memory allocator) |
| locking | cmpxchg-local | HAVE_CMPXCHG_LOCAL | TODO | arch supports the this_cpu_cmpxchg() API |
| locking | lockdep | LOCKDEP_SUPPORT | ok | arch supports the runtime locking correctness debug facility |
| locking | queued-rwlocks | ARCH_USE_QUEUED_RWLOCKS | ok | arch supports queued rwlocks |
| locking | queued-spinlocks | ARCH_USE_QUEUED_SPINLOCKS | ok | arch supports queued spinlocks |
| perf | kprobes-event | HAVE_REGS_AND_STACK_ACCESS_API | ok | arch supports kprobes with perf events |
| perf | perf-regs | HAVE_PERF_REGS | ok | arch supports perf events register access |
| perf | perf-stackdump | HAVE_PERF_USER_STACK_DUMP | ok | arch supports perf events stack dumps |
| sched | membarrier-sync-core | ARCH_HAS_MEMBARRIER_SYNC_CORE | TODO | arch supports core serializing membarrier |
| sched | numa-balancing | ARCH_SUPPORTS_NUMA_BALANCING | ok | arch supports NUMA balancing |
| seccomp | seccomp-filter | HAVE_ARCH_SECCOMP_FILTER | ok | arch supports seccomp filters |
| time | arch-tick-broadcast | ARCH_HAS_TICK_BROADCAST | ok | arch provides tick_broadcast() |
| time | clockevents | !LEGACY_TIMER_TICK | ok | arch support generic clock events |
| time | irq-time-acct | HAVE_IRQ_TIME_ACCOUNTING | ok | arch supports precise IRQ time accounting |
| time | user-context-tracking | HAVE_CONTEXT_TRACKING_USER | ok | arch supports user context tracking for NO_HZ_FULL |
| time | virt-cpuacct | HAVE_VIRT_CPU_ACCOUNTING | ok | arch supports precise virtual CPU time accounting |
| vm | batch-unmap-tlb-flush | ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH | TODO | arch supports deferral of TLB flush until multiple pages are unmapped |
| vm | ELF-ASLR | ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT | ok | arch randomizes the stack, heap and binary images of ELF binaries |
| vm | huge-vmap | HAVE_ARCH_HUGE_VMAP | TODO | arch supports the arch_vmap_pud_supported() and arch_vmap_pmd_supported() VM APIs |
| vm | ioremap_prot | HAVE_IOREMAP_PROT | ok | arch has ioremap_prot() |
| vm | pte_special | ARCH_HAS_PTE_SPECIAL | ok | arch supports the pte_special()/pte_mkspecial() VM APIs |
| vm | THP | HAVE_ARCH_TRANSPARENT_HUGEPAGE | ok | arch supports transparent hugepages |
Introduction to LoongArch
Peios Kernel / Hardware and drivers / Processor architectures / LoongArch
LoongArch is a new RISC ISA, which is a bit like MIPS or RISC-V. There are currently 3 variants: a reduced 32-bit version (LA32R), a standard 32-bit version (LA32S) and a 64-bit version (LA64). There are 4 privilege levels (PLVs) defined in LoongArch: PLV0~PLV3, from high to low. Kernel runs at PLV0 while applications run at PLV3. This document introduces the registers, basic instruction set, virtual memory and some other topics of LoongArch.
Registers #
LoongArch registers include general purpose registers (GPRs), floating point registers (FPRs), vector registers (VRs) and control status registers (CSRs) used in privileged mode (PLV0).
GPRs #
LoongArch has 32 GPRs ( $r0 ~ $r31 ); each one is 32-bit wide in LA32 and 64-bit wide in LA64. $r0 is hard-wired to zero, and the other registers are not architecturally special. (Except $r1, which is hard-wired as the link register of the BL instruction.)
The kernel uses a variant of the LoongArch register convention, as described in the LoongArch ELF psABI spec, in References:
|
Name |
Alias |
Usage |
Preserved across calls |
|---|---|---|---|
|
|
|
Constant zero |
Unused |
|
|
|
Return address |
No |
|
|
|
TLS/Thread pointer |
Unused |
|
|
|
Stack pointer |
Yes |
|
|
|
Argument registers |
No |
|
|
|
Return value |
No |
|
|
|
Temp registers |
No |
|
|
|
Percpu base address |
Unused |
|
|
|
Frame pointer |
Yes |
|
|
|
Static registers |
Yes |
FPRs #
LoongArch has 32 FPRs ( $f0 ~ $f31 ) when FPU is present. Each one is 64-bit wide on the LA64 cores.
The floating-point register convention is the same as described in the LoongArch ELF psABI spec:
|
Name |
Alias |
Usage |
Preserved across calls |
|---|---|---|---|
|
|
|
Argument registers |
No |
|
|
|
Return value |
No |
|
|
|
Temp registers |
No |
|
|
|
Static registers |
Yes |
VRs #
There are currently 2 vector extensions to LoongArch:
-
LSX (Loongson SIMD eXtension) with 128-bit vectors,
-
LASX (Loongson Advanced SIMD eXtension) with 256-bit vectors.
LSX brings $v0 ~ $v31 while LASX brings $x0 ~ $x31 as the vector registers.
The VRs overlap with FPRs: for example, on a core implementing LSX and LASX, the lower 128 bits of $x0 is shared with $v0, and the lower 64 bits of $v0 is shared with $f0; same with all other VRs.
CSRs #
CSRs can only be accessed from privileged mode (PLV0):
|
Address |
Full Name |
Abbrev Name |
|---|---|---|
|
0x0 |
Current Mode Information |
CRMD |
|
0x1 |
Pre-exception Mode Information |
PRMD |
|
0x2 |
Extension Unit Enable |
EUEN |
|
0x3 |
Miscellaneous Control |
MISC |
|
0x4 |
Exception Configuration |
ECFG |
|
0x5 |
Exception Status |
ESTAT |
|
0x6 |
Exception Return Address |
ERA |
|
0x7 |
Bad (Faulting) Virtual Address |
BADV |
|
0x8 |
Bad (Faulting) Instruction Word |
BADI |
|
0xC |
Exception Entrypoint Address |
EENTRY |
|
0x10 |
TLB Index |
TLBIDX |
|
0x11 |
TLB Entry High-order Bits |
TLBEHI |
|
0x12 |
TLB Entry Low-order Bits 0 |
TLBELO0 |
|
0x13 |
TLB Entry Low-order Bits 1 |
TLBELO1 |
|
0x18 |
Address Space Identifier |
ASID |
|
0x19 |
Page Global Directory Address for Lower-half Address Space |
PGDL |
|
0x1A |
Page Global Directory Address for Higher-half Address Space |
PGDH |
|
0x1B |
Page Global Directory Address |
PGD |
|
0x1C |
Page Walk Control for Lower- half Address Space |
PWCL |
|
0x1D |
Page Walk Control for Higher- half Address Space |
PWCH |
|
0x1E |
STLB Page Size |
STLBPS |
|
0x1F |
Reduced Virtual Address Configuration |
RVACFG |
|
0x20 |
CPU Identifier |
CPUID |
|
0x21 |
Privileged Resource Configuration 1 |
PRCFG1 |
|
0x22 |
Privileged Resource Configuration 2 |
PRCFG2 |
|
0x23 |
Privileged Resource Configuration 3 |
PRCFG3 |
|
0x30+n (0≤n≤15) |
Saved Data register |
SAVEn |
|
0x40 |
Timer Identifier |
TID |
|
0x41 |
Timer Configuration |
TCFG |
|
0x42 |
Timer Value |
TVAL |
|
0x43 |
Compensation of Timer Count |
CNTC |
|
0x44 |
Timer Interrupt Clearing |
TICLR |
|
0x60 |
LLBit Control |
LLBCTL |
|
0x80 |
Implementation-specific Control 1 |
IMPCTL1 |
|
0x81 |
Implementation-specific Control 2 |
IMPCTL2 |
|
0x88 |
TLB Refill Exception Entrypoint Address |
TLBRENTRY |
|
0x89 |
TLB Refill Exception BAD (Faulting) Virtual Address |
TLBRBADV |
|
0x8A |
TLB Refill Exception Return Address |
TLBRERA |
|
0x8B |
TLB Refill Exception Saved Data Register |
TLBRSAVE |
|
0x8C |
TLB Refill Exception Entry Low-order Bits 0 |
TLBRELO0 |
|
0x8D |
TLB Refill Exception Entry Low-order Bits 1 |
TLBRELO1 |
|
0x8E |
TLB Refill Exception Entry High-order Bits |
TLBEHI |
|
0x8F |
TLB Refill Exception Pre-exception Mode Information |
TLBRPRMD |
|
0x90 |
Machine Error Control |
MERRCTL |
|
0x91 |
Machine Error Information 1 |
MERRINFO1 |
|
0x92 |
Machine Error Information 2 |
MERRINFO2 |
|
0x93 |
Machine Error Exception Entrypoint Address |
MERRENTRY |
|
0x94 |
Machine Error Exception Return Address |
MERRERA |
|
0x95 |
Machine Error Exception Saved Data Register |
MERRSAVE |
|
0x98 |
Cache TAGs |
CTAG |
|
0x180+n (0≤n≤3) |
Direct Mapping Configuration Window n |
DMWn |
|
0x200+2n (0≤n≤31) |
Performance Monitor Configuration n |
PMCFGn |
|
0x201+2n (0≤n≤31) |
Performance Monitor Overall Counter n |
PMCNTn |
|
0x300 |
Memory Load/Store WatchPoint Overall Control |
MWPC |
|
0x301 |
Memory Load/Store WatchPoint Overall Status |
MWPS |
|
0x310+8n (0≤n≤7) |
Memory Load/Store WatchPoint n Configuration 1 |
MWPnCFG1 |
|
0x311+8n (0≤n≤7) |
Memory Load/Store WatchPoint n Configuration 2 |
MWPnCFG2 |
|
0x312+8n (0≤n≤7) |
Memory Load/Store WatchPoint n Configuration 3 |
MWPnCFG3 |
|
0x313+8n (0≤n≤7) |
Memory Load/Store WatchPoint n Configuration 4 |
MWPnCFG4 |
|
0x380 |
Instruction Fetch WatchPoint Overall Control |
FWPC |
|
0x381 |
Instruction Fetch WatchPoint Overall Status |
FWPS |
|
0x390+8n (0≤n≤7) |
Instruction Fetch WatchPoint n Configuration 1 |
FWPnCFG1 |
|
0x391+8n (0≤n≤7) |
Instruction Fetch WatchPoint n Configuration 2 |
FWPnCFG2 |
|
0x392+8n (0≤n≤7) |
Instruction Fetch WatchPoint n Configuration 3 |
FWPnCFG3 |
|
0x393+8n (0≤n≤7) |
Instruction Fetch WatchPoint n Configuration 4 |
FWPnCFG4 |
|
0x500 |
Debug Register |
DBG |
|
0x501 |
Debug Exception Return Address |
DERA |
|
0x502 |
Debug Exception Saved Data Register |
DSAVE |
ERA, TLBRERA, MERRERA and DERA are sometimes also known as EPC, TLBREPC, MERREPC and DEPC respectively.
Basic Instruction Set #
Instruction formats #
LoongArch instructions are 32 bits wide, belonging to 9 basic instruction formats (and variants of them):
|
Format name |
Composition |
|---|---|
|
2R |
Opcode + Rj + Rd |
|
3R |
Opcode + Rk + Rj + Rd |
|
4R |
Opcode + Ra + Rk + Rj + Rd |
|
2RI8 |
Opcode + I8 + Rj + Rd |
|
2RI12 |
Opcode + I12 + Rj + Rd |
|
2RI14 |
Opcode + I14 + Rj + Rd |
|
2RI16 |
Opcode + I16 + Rj + Rd |
|
1RI21 |
Opcode + I21L + Rj + I21H |
|
I26 |
Opcode + I26L + I26H |
Rd is the destination register operand, while Rj, Rk and Ra ("a" stands for "additional") are the source register operands. I8/I12/I14/I16/I21/I26 are immediate operands of respective width. The longer I21 and I26 are stored in separate higher and lower parts in the instruction word, denoted by the "L" and "H" suffixes.
List of Instructions #
For brevity, only instruction names (mnemonics) are listed here; please see the References for details.
-
Arithmetic Instructions:
ADD.W SUB.W ADDI.W ADD.D SUB.D ADDI.D SLT SLTU SLTI SLTUI AND OR NOR XOR ANDN ORN ANDI ORI XORI MUL.W MULH.W MULH.WU DIV.W DIV.WU MOD.W MOD.WU MUL.D MULH.D MULH.DU DIV.D DIV.DU MOD.D MOD.DU PCADDI PCADDU12I PCADDU18I LU12I.W LU32I.D LU52I.D ADDU16I.D -
Bit-shift Instructions:
SLL.W SRL.W SRA.W ROTR.W SLLI.W SRLI.W SRAI.W ROTRI.W SLL.D SRL.D SRA.D ROTR.D SLLI.D SRLI.D SRAI.D ROTRI.D -
Bit-manipulation Instructions:
EXT.W.B EXT.W.H CLO.W CLO.D SLZ.W CLZ.D CTO.W CTO.D CTZ.W CTZ.D BYTEPICK.W BYTEPICK.D BSTRINS.W BSTRINS.D BSTRPICK.W BSTRPICK.D REVB.2H REVB.4H REVB.2W REVB.D REVH.2W REVH.D BITREV.4B BITREV.8B BITREV.W BITREV.D MASKEQZ MASKNEZ -
Branch Instructions:
BEQ BNE BLT BGE BLTU BGEU BEQZ BNEZ B BL JIRL -
Load/Store Instructions:
LD.B LD.BU LD.H LD.HU LD.W LD.WU LD.D ST.B ST.H ST.W ST.D LDX.B LDX.BU LDX.H LDX.HU LDX.W LDX.WU LDX.D STX.B STX.H STX.W STX.D LDPTR.W LDPTR.D STPTR.W STPTR.D PRELD PRELDX -
Atomic Operation Instructions:
LL.W SC.W LL.D SC.D AMSWAP.W AMSWAP.D AMADD.W AMADD.D AMAND.W AMAND.D AMOR.W AMOR.D AMXOR.W AMXOR.D AMMAX.W AMMAX.D AMMIN.W AMMIN.D -
Barrier Instructions:
IBAR DBAR -
Special Instructions:
SYSCALL BREAK CPUCFG NOP IDLE ERTN(ERET) DBCL(DBGCALL) RDTIMEL.W RDTIMEH.W RDTIME.D ASRTLE.D ASRTGT.D -
Privileged Instructions:
CSRRD CSRWR CSRXCHG IOCSRRD.B IOCSRRD.H IOCSRRD.W IOCSRRD.D IOCSRWR.B IOCSRWR.H IOCSRWR.W IOCSRWR.D CACOP TLBP(TLBSRCH) TLBRD TLBWR TLBFILL TLBCLR TLBFLUSH INVTLB LDDIR LDPTE
Virtual Memory #
LoongArch supports direct-mapped virtual memory and page-mapped virtual memory.
Direct-mapped virtual memory is configured by CSR.DMWn (n=0~3), it has a simple relationship between virtual address (VA) and physical address (PA):
VA = PA + FixedOffset
Page-mapped virtual memory has arbitrary relationship between VA and PA, which is recorded in TLB and page tables. LoongArch's TLB includes a fully-associative MTLB (Multiple Page Size TLB) and set-associative STLB (Single Page Size TLB).
By default, the whole virtual address space of LA32 is configured like this:
|
Name |
Address Range |
Attributes |
|---|---|---|
|
|
|
Page-mapped, Cached, PLV0~3 |
|
|
|
Direct-mapped, Uncached, PLV0 |
|
|
|
Direct-mapped, Cached, PLV0 |
|
|
|
Page-mapped, Cached, PLV0 |
User mode (PLV3) can only access UVRANGE. For direct-mapped KPRANGE0 and KPRANGE1, PA is equal to VA with bit30~31 cleared. For example, the uncached direct-mapped VA of 0x00001000 is 0x80001000, and the cached direct-mapped VA of 0x00001000 is 0xA0001000.
By default, the whole virtual address space of LA64 is configured like this:
|
Name |
Address Range |
Attributes |
|---|---|---|
|
|
|
Page-mapped, Cached, PLV0~3 |
|
|
|
Direct-mapped, Cached / Uncached, PLV0 |
|
|
|
Direct-mapped, Cached / Uncached, PLV0 |
|
|
|
Page-mapped, Cached, PLV0 |
User mode (PLV3) can only access XUVRANGE. For direct-mapped XSPRANGE and XKPRANGE, PA is equal to VA with bits 60~63 cleared, and the cache attribute is configured by bits 60~61 in VA: 0 is for strongly-ordered uncached, 1 is for coherent cached, and 2 is for weakly-ordered uncached.
Currently we only use XKPRANGE for direct mapping and XSPRANGE is reserved.
To put this in action: the strongly-ordered uncached direct-mapped VA (in XKPRANGE) of 0x00000000_00001000 is 0x80000000_00001000, the coherent cached direct-mapped VA (in XKPRANGE) of 0x00000000_00001000 is 0x90000000_00001000, and the weakly-ordered uncached direct-mapped VA (in XKPRANGE) of 0x00000000 _00001000 is 0xA0000000_00001000.
Relationship of Loongson and LoongArch #
LoongArch is a RISC ISA which is different from any other existing ones, while Loongson is a family of processors. Loongson includes 3 series: Loongson-1 is the 32-bit processor series, Loongson-2 is the low-end 64-bit processor series, and Loongson-3 is the high-end 64-bit processor series. Old Loongson is based on MIPS, while New Loongson is based on LoongArch. Take Loongson-3 as an example: Loongson-3A1000/3B1500/3A2000/3A3000/3A4000 are MIPS-compatible, while Loongson- 3A5000 (and future revisions) are all based on LoongArch.
References #
Official web site of Loongson Technology Corp. Ltd.:
Developer web site of Loongson and LoongArch (Software and Documentation):
Documentation of LoongArch ISA:
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-Vol1-v1.10-CN.pdf (in Chinese)
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-Vol1-v1.10-EN.pdf (in English)
Documentation of LoongArch ELF psABI:
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-ELF-ABI-v2.01-CN.pdf (in Chinese)
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/LoongArch-ELF-ABI-v2.01-EN.pdf (in English)
Linux kernel repository of Loongson and LoongArch:
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git
IRQ chip model (hierarchy) of LoongArch
Peios Kernel / Hardware and drivers / Processor architectures / LoongArch
Currently, LoongArch based processors (e.g. Loongson-3A5000) can only work together with LS7A chipsets. The irq chips in LoongArch computers include CPUINTC (CPU Core Interrupt Controller), LIOINTC (Legacy I/O Interrupt Controller), EIOINTC (Extended I/O Interrupt Controller), HTVECINTC (Hyper-Transport Vector Interrupt Controller), PCH-PIC (Main Interrupt Controller in LS7A chipset), PCH-LPC (LPC Interrupt Controller in LS7A chipset) and PCH-MSI (MSI Interrupt Controller).
CPUINTC is a per-core controller (in CPU), LIOINTC/EIOINTC/HTVECINTC are per-package controllers (in CPU), while PCH-PIC/PCH-LPC/PCH-MSI are controllers out of CPU (i.e., in chipsets). These controllers (in other words, irqchips) are linked in a hierarchy, and there are two models of hierarchy (legacy model and extended model).
Legacy IRQ model #
In this model, IPI (Inter-Processor Interrupt) and CPU Local Timer interrupt go to CPUINTC directly, CPU UARTS interrupts go to LIOINTC, while all other devices interrupts go to PCH-PIC/PCH-LPC/PCH-MSI and gathered by HTVECINTC, and then go to LIOINTC, and then CPUINTC:
+-----+ +---------+ +-------+
| IPI | --> | CPUINTC | <-- | Timer |
+-----+ +---------+ +-------+
^
|
+---------+ +-------+
| LIOINTC | <-- | UARTs |
+---------+ +-------+
^
|
+-----------+
| HTVECINTC |
+-----------+
^ ^
| |
+---------+ +---------+
| PCH-PIC | | PCH-MSI |
+---------+ +---------+
^ ^ ^
| | |
+---------+ +---------+ +---------+
| PCH-LPC | | Devices | | Devices |
+---------+ +---------+ +---------+
^
|
+---------+
| Devices |
+---------+
Extended IRQ model #
In this model, IPI (Inter-Processor Interrupt) and CPU Local Timer interrupt go to CPUINTC directly, CPU UARTS interrupts go to LIOINTC, while all other devices interrupts go to PCH-PIC/PCH-LPC/PCH-MSI and gathered by EIOINTC, and then go to to CPUINTC directly:
+-----+ +---------+ +-------+
| IPI | --> | CPUINTC | <-- | Timer |
+-----+ +---------+ +-------+
^ ^
| |
+---------+ +---------+ +-------+
| EIOINTC | | LIOINTC | <-- | UARTs |
+---------+ +---------+ +-------+
^ ^
| |
+---------+ +---------+
| PCH-PIC | | PCH-MSI |
+---------+ +---------+
^ ^ ^
| | |
+---------+ +---------+ +---------+
| PCH-LPC | | Devices | | Devices |
+---------+ +---------+ +---------+
^
|
+---------+
| Devices |
+---------+
Virtual Extended IRQ model #
In this model, IPI (Inter-Processor Interrupt) and CPU Local Timer interrupt go to CPUINTC directly, CPU UARTS interrupts go to PCH-PIC, while all other devices interrupts go to PCH-PIC/PCH-MSI and gathered by V-EIOINTC (Virtual Extended I/O Interrupt Controller), and then go to CPUINTC directly:
+-----+ +-------------------+ +-------+
| IPI |--> | CPUINTC(0-255vcpu)| <-- | Timer |
+-----+ +-------------------+ +-------+
^
|
+-----------+
| V-EIOINTC |
+-----------+
^ ^
| |
+---------+ +---------+
| PCH-PIC | | PCH-MSI |
+---------+ +---------+
^ ^ ^
| | |
+--------+ +---------+ +---------+
| UARTs | | Devices | | Devices |
+--------+ +---------+ +---------+
Description #
V-EIOINTC (Virtual Extended I/O Interrupt Controller) is an extension of EIOINTC, it only works in VM mode which runs in KVM hypervisor. Interrupts can be routed to up to four vCPUs via standard EIOINTC, however with V-EIOINTC interrupts can be routed to up to 256 virtual cpus.
With standard EIOINTC, interrupt routing setting includes two parts: eight bits for CPU selection and four bits for CPU IP (Interrupt Pin) selection. For CPU selection there is four bits for EIOINTC node selection, four bits for EIOINTC CPU selection. Bitmap method is used for CPU selection and CPU IP selection, so interrupt can only route to CPU0 - CPU3 and IP0-IP3 in one EIOINTC node.
With V-EIOINTC it supports to route more CPUs and CPU IP (Interrupt Pin), there are two newly added registers with V-EIOINTC.
EXTIOI_VIRT_FEATURES #
This register is read-only register, which indicates supported features with V-EIOINTC. Feature EXTIOI_HAS_INT_ENCODE and EXTIOI_HAS_CPU_ENCODE is added.
Feature EXTIOI_HAS_INT_ENCODE is part of standard EIOINTC. If it is 1, it indicates that CPU Interrupt Pin selection can be normal method rather than bitmap method, so interrupt can be routed to IP0 - IP15.
Feature EXTIOI_HAS_CPU_ENCODE is extension of V-EIOINTC. If it is 1, it indicates that CPU selection can be normal method rather than bitmap method, so interrupt can be routed to CPU0 - CPU255.
EXTIOI_VIRT_CONFIG #
This register is read-write register, for compatibility interrupt routed uses the default method which is the same with standard EIOINTC. If the bit is set with 1, it indicated HW to use normal method rather than bitmap method.
Advanced Extended IRQ model #
In this model, IPI (Inter-Processor Interrupt) and CPU Local Timer interrupt go to CPUINTC directly, CPU UARTS interrupts go to LIOINTC, PCH-MSI interrupts go to AVECINTC, and then go to CPUINTC directly, while all other devices interrupts go to PCH-PIC/PCH-LPC and gathered by EIOINTC, and then go to CPUINTC directly:
+-----+ +-----------------------+ +-------+
| IPI | --> | CPUINTC | <-- | Timer |
+-----+ +-----------------------+ +-------+
^ ^ ^
| | |
+---------+ +----------+ +---------+ +-------+
| EIOINTC | | AVECINTC | | LIOINTC | <-- | UARTs |
+---------+ +----------+ +---------+ +-------+
^ ^
| |
+---------+ +---------+
| PCH-PIC | | PCH-MSI |
+---------+ +---------+
^ ^ ^
| | |
+---------+ +---------+ +---------+
| Devices | | PCH-LPC | | Devices |
+---------+ +---------+ +---------+
^
|
+---------+
| Devices |
+---------+
ACPI-related definitions #
CPUINTC:
ACPI_MADT_TYPE_CORE_PIC;
struct acpi_madt_core_pic;
enum acpi_madt_core_pic_version;
LIOINTC:
ACPI_MADT_TYPE_LIO_PIC;
struct acpi_madt_lio_pic;
enum acpi_madt_lio_pic_version;
EIOINTC:
ACPI_MADT_TYPE_EIO_PIC;
struct acpi_madt_eio_pic;
enum acpi_madt_eio_pic_version;
HTVECINTC:
ACPI_MADT_TYPE_HT_PIC;
struct acpi_madt_ht_pic;
enum acpi_madt_ht_pic_version;
PCH-PIC:
ACPI_MADT_TYPE_BIO_PIC;
struct acpi_madt_bio_pic;
enum acpi_madt_bio_pic_version;
PCH-MSI:
ACPI_MADT_TYPE_MSI_PIC;
struct acpi_madt_msi_pic;
enum acpi_madt_msi_pic_version;
PCH-LPC:
ACPI_MADT_TYPE_LPC_PIC;
struct acpi_madt_lpc_pic;
enum acpi_madt_lpc_pic_version;
References #
Documentation of Loongson-3A5000:
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/Loongson-3A5000-usermanual-1.02-CN.pdf (in Chinese)
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/Loongson-3A5000-usermanual-1.02-EN.pdf (in English)
Documentation of Loongson's LS7A chipset:
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/Loongson-7A1000-usermanual-2.00-CN.pdf (in Chinese)
https://github.com/loongson/LoongArch-Documentation/releases/latest/download/Loongson-7A1000-usermanual-2.00-EN.pdf (in English)