[PATCH v2 07/39] xen/riscv: add missing APLIC register offsets, masks to asm/aplic.h
Oleksii Kurochko <[email protected]>
| Newsgroups | gmane.comp.emulators.xen.devel |
|---|---|
| Message-ID | <b3e0c1a662403ea2aa84a1943223ad0885733d0f.1787838835.git.oleksii.kurochko@gmail.com> |
These definitions are required for correct decoding of APLIC MMIO accesses and target configuration, and will be used by both the physical and virtual APLIC implementations. While adding them, rearrange the header in the style of x86's asm/msr-index.h: a register's offset is immediately followed by the definitions of that register's fields, with the blocks sorted by offset. This makes the relation between a register and its fields obvious from the layout alone, so no comment is needed to express it. No functional change is intended by this patch; it only centralises hardware definitions that were previously missing. Co-developed-by: Romain Caritey <[email protected]> Signed-off-by: Oleksii Kurochko <[email protected]> --- Changes in v2: - Rearrange the whole header the way x86's asm/msr-index.h is laid out: put each register offset first and the definitions of its fields immediately after it (indented by an extra space), sorted by offset. - Describe the convention in a comment at the top of the definitions, mirroring the one in asm/msr-index.h. - Reflow APLIC_SIZE() to fit the new alignment column. - Fix the comment for declaration of member target in aplic_regs[]. It should be 0x3004. - s/APLIC_REG_OFFSET_MASK/APLIC_CTRL_REGION_OFFSET_MASK --- --- xen/arch/riscv/include/asm/aplic.h | 90 ++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 17 deletions(-) diff --git a/xen/arch/riscv/include/asm/aplic.h b/xen/arch/riscv/include/asm/aplic.h index 07318aaac25d..a2af55d54fc0 100644 --- a/xen/arch/riscv/include/asm/aplic.h +++ b/xen/arch/riscv/include/asm/aplic.h @@ -15,32 +15,88 @@ #include <asm/imsic.h> +/* + * APLIC register offsets and, immediately following each of them, the + * definitions of the fields of the respective register: + * + * #define APLIC_$NAME 0x$OFFSET + * #define APLIC_$NAME_$FIELD1 ... + * #define APLIC_$NAME_$FIELD1_$VAL ... + * #define APLIC_$NAME_$FIELD2 ... + * + * Blocks of related constants are sorted by register offset. + */ + +#define APLIC_CTRL_REGION_OFFSET_MASK 0x3fff + +#define APLIC_DOMAINCFG 0x0000 /* * domaincfg read-only fields (AIA spec): * - bits [31:24] -> read-only 0x80 * - bit 7 -> read-only 0 */ -#define APLIC_DOMAINCFG_RO (0x80U << 24) -#define APLIC_DOMAINCFG_IE BIT(8, U) -#define APLIC_DOMAINCFG_DM BIT(2, U) -#define APLIC_DOMAINCFG_BE BIT(0, U) +#define APLIC_DOMAINCFG_RO (0x80U << 24) +#define APLIC_DOMAINCFG_IE BIT(8, U) +#define APLIC_DOMAINCFG_DM BIT(2, U) +#define APLIC_DOMAINCFG_BE BIT(0, U) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_LAST 0x0ffc +/* + * sourcecfg[] register fields: + * - bit 10 (D) selects the layout of the remaining bits; + * - D = 1: bits [9:0] hold the Child Index, i.e. the source is delegated + * to a child domain (unsupported by Xen); + * - D = 0: bits [2:0] hold the source mode SM (WARL). + */ +#define APLIC_SOURCECFG_D BIT(10, U) +#define APLIC_SOURCECFG_SM GENMASK(2, 0) +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +/* Bits 0x2 and 0x3 are reserved */ +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 + +#define APLIC_SMSICFGADDR 0x1bc8 +#define APLIC_SMSICFGADDRH 0x1bcc + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIP_LAST 0x1c7c +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIP_LAST 0x1d7c +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIE_LAST 0x1e7c +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIE_LAST 0x1f7c +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 -#define APLIC_SOURCECFG_SM_INACTIVE 0x0 -#define APLIC_SOURCECFG_SM_DETACH 0x1 -#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 -#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 -#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 -#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 +#define APLIC_GENMSI 0x3000 -#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_LAST 0x3ffc +#define APLIC_TARGET_HART_IDX GENMASK(31, 18) +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_GUEST_IDX GENMASK(17, 12) +/* Bit 11 is reserved and reads as zero */ +#define APLIC_TARGET_EIID GENMASK(10, 0) -#define APLIC_IDC_SIZE 32 +#define APLIC_IDC_SIZE 32 -#define APLIC_MIN_SIZE 0x4000 -#define APLIC_SIZE_ALIGN(x) ROUNDUP(x, APLIC_MIN_SIZE) +#define APLIC_MIN_SIZE 0x4000 +#define APLIC_SIZE_ALIGN(x) ROUNDUP(x, APLIC_MIN_SIZE) -#define APLIC_SIZE(nr_cpus) (APLIC_MIN_SIZE + \ - APLIC_SIZE_ALIGN(APLIC_IDC_SIZE * (nr_cpus))) +#define APLIC_SIZE(nr_cpus) \ + (APLIC_MIN_SIZE + APLIC_SIZE_ALIGN(APLIC_IDC_SIZE * (nr_cpus))) struct aplic_regs { uint32_t domaincfg; /* 0x0000 */ @@ -82,7 +138,7 @@ struct aplic_regs { uint8_t _reserved11[4088]; /* 0x2008 */ uint32_t genmsi; /* 0x3000 */ - uint32_t target[1023]; /* 0x3008 */ + uint32_t target[1023]; /* 0x3004 */ }; #endif /* ASM_RISCV_APLIC_H */ -- 2.55.0