irqchip/rpmi: Expose APLIC/IMSIC interfaces for platform use
cover irqchip/rpmi: Expose APLIC/IMSIC interfaces for platform use
This series exposes existing APLIC and IMSIC internal definitions and adds minimal extension points so that platform code can perform custom interrupt configuration without modifying the generic irqchip drivers.
The motivation is that a platform which uses AIA may need to:
- Configure APLIC source/target registers directly for M-mode interrupt routing
- Iterate registered APLIC devices for platform-specific initialization
- Handle M-mode external interrupts beyond IPI in the IMSIC driver
Furthermore, a platform using RPMI PERFORMANCE service group may need to:
- Use RPMI performance domain attribute flags for RPMI PERFORMANCE PERF_DOMAIN and FAST_CHANNEL attribute control
Patch 1 moves APLIC register defines from aplic.c to the public aplic.h header (pure move, no functional change).
Patch 2 adds aplic_get_list() to allow platform code to iterate registered APLIC devices.
Patch 3 routes non-IPI IMSIC interrupts through the sbi_irqchip handler framework and adds hwirq_unmask/hwirq_mask callbacks so that sbi_irqchip_register_handler() works end-to-end with IMSIC. Patch 4 adds missing RPMI performance flag defines and a struct field.
All changes are additive and preserve existing behavior for platforms that do not use the new interfaces.
David E. Garcia Porras (4):
lib: utils: irqchip: aplic: Move register defines to public header
lib: utils: irqchip: aplic: Add aplic_get_list() accessor
lib: utils: irqchip: imsic: Dispatch non-IPI interrupts via irqchip
framework
include: mailbox: rpmi_msgprot: Add RPMI performance domain flag
defines
include/sbi_utils/irqchip/aplic.h | 103 ++++++++++++++++++++++ include/sbi_utils/mailbox/rpmi_msgprot.h | 18 ++++ lib/utils/irqchip/aplic.c | 106 ++--------------------- lib/utils/irqchip/imsic.c | 15 +++- 4 files changed, 139 insertions(+), 103 deletions(-)
--
2.43.0
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/4 lib: utils: irqchip: aplic: Move register defines to public header
The APLIC register-level defines (DOMAINCFG, SOURCECFG, TARGET, SETIE, CLRIE, IDC, MSICFG, etc.) are currently defined locally in aplic.c and not accessible to platform code. Platform implementations that need direct APLIC register access for custom interrupt configuration (e.g. MSI-mode source/target setup) have no way to use the canonical defines.
Move these defines from aplic.c to the public aplic.h header so that platform code can configure APLIC registers without duplicating magic numbers. The defines match the RISC-V AIA specification. No functional change.
--- include/sbi_utils/irqchip/aplic.h | 101 ++++++++++++++++++++++++++++++ lib/utils/irqchip/aplic.c | 101 ------------------------------ 2 files changed, 101 insertions(+), 101 deletions(-)
include/sbi_utils/irqchip/aplic.h +101 -0
@@ -14,6 +14,107 @@#include <sbi/sbi_types.h> #include <sbi/sbi_irqchip.h> +#define APLIC_MAX_IDC (1UL << 14) +#define APLIC_MAX_SOURCE 1024 + +#define APLIC_DOMAINCFG 0x0000 +#define APLIC_DOMAINCFG_IE (1 << 8) +#define APLIC_DOMAINCFG_DM (1 << 2) +#define APLIC_DOMAINCFG_BE (1 << 0) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_D (1 << 10) +#define APLIC_SOURCECFG_CHILDIDX_MASK 0x000003ff +#define APLIC_SOURCECFG_SM_MASK 0x00000007 +#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_MMSICFGADDR 0x1bc0 +#define APLIC_MMSICFGADDRH 0x1bc4 +#define APLIC_SMSICFGADDR 0x1bc8 +#define APLIC_SMSICFGADDRH 0x1bcc + +#define APLIC_xMSICFGADDRH_L (1UL << 31) +#define APLIC_xMSICFGADDRH_HHXS_MASK 0x1f +#define APLIC_xMSICFGADDRH_HHXS_SHIFT 24 +#define APLIC_xMSICFGADDRH_LHXS_MASK 0x7 +#define APLIC_xMSICFGADDRH_LHXS_SHIFT 20 +#define APLIC_xMSICFGADDRH_HHXW_MASK 0x7 +#define APLIC_xMSICFGADDRH_HHXW_SHIFT 16 +#define APLIC_xMSICFGADDRH_LHXW_MASK 0xf +#define APLIC_xMSICFGADDRH_LHXW_SHIFT 12 +#define APLIC_xMSICFGADDRH_BAPPN_MASK 0xfff + +#define APLIC_xMSICFGADDR_PPN_SHIFT 12 + +#define APLIC_xMSICFGADDR_PPN_HART (__lhxs) \ + ((1UL << (__lhxs)) - 1) + +#define APLIC_xMSICFGADDR_PPN_LHX_MASK (__lhxw) \ + ((1UL << (__lhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_LHX_SHIFT (__lhxs) \ + ((__lhxs)) +#define APLIC_xMSICFGADDR_PPN_LHX (__lhxw, __lhxs) \ + (APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) << \ + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs)) + +#define APLIC_xMSICFGADDR_PPN_HHX_MASK (__hhxw) \ + ((1UL << (__hhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_HHX_SHIFT (__hhxs) \ + ((__hhxs) + APLIC_xMSICFGADDR_PPN_SHIFT) +#define APLIC_xMSICFGADDR_PPN_HHX (__hhxw, __hhxs) \ + (APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) << \ + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs)) + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 +#define APLIC_SETIPNUM_BE 0x2004 + +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_HART_IDX_MASK 0x3fff +#define APLIC_TARGET_GUEST_IDX_SHIFT 12 +#define APLIC_TARGET_GUEST_IDX_MASK 0x3f +#define APLIC_TARGET_IPRIO_MASK 0xff +#define APLIC_TARGET_EIID_MASK 0x7ff + +#define APLIC_IDC_BASE 0x4000 +#define APLIC_IDC_SIZE 32 + +#define APLIC_IDC_IDELIVERY 0x00 + +#define APLIC_IDC_IFORCE 0x04 + +#define APLIC_IDC_ITHRESHOLD 0x08 + +#define APLIC_IDC_TOPI 0x18 +#define APLIC_IDC_TOPI_ID_SHIFT 16 +#define APLIC_IDC_TOPI_ID_MASK 0x3ff +#define APLIC_IDC_TOPI_PRIO_MASK 0xff + +#define APLIC_IDC_CLAIMI 0x1c + +#define APLIC_DEFAULT_PRIORITY 1 +#define APLIC_DISABLE_IDELIVERY 0 +#define APLIC_ENABLE_IDELIVERY 1 +#define APLIC_DISABLE_ITHRESHOLD 1 +#define APLIC_ENABLE_ITHRESHOLD 0 +#define APLIC_MAX_DELEGATE 16struct aplic_msicfg_data {
lib/utils/irqchip/aplic.c +0 -101
107 lines not on this page · raw message
Signature · 7 lines
2.43.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 2/4 lib: utils: irqchip: aplic: Add aplic_get_list() accessor
In reply to David E. Garcia PorrasThe internal aplic_list is static, preventing platform code from iterating over registered APLIC devices for custom configuration (e.g. enabling domain-level interrupts in MSI delivery mode).
Add aplic_get_list() to return a pointer to the list head, allowing platform code to walk registered APLIC devices without breaking encapsulation by extern-ing the static list directly.
--- include/sbi_utils/irqchip/aplic.h | 2 ++ lib/utils/irqchip/aplic.c | 5 +++++ 2 files changed, 7 insertions(+)
include/sbi_utils/irqchip/aplic.h +2 -0
@@ -152,6 +152,8 @@ struct aplic_data {int aplic_cold_irqchip_init (struct aplic_data *aplic); +struct sbi_dlist *aplic_get_list (void ); +void aplic_reinit_all (void );#endif
lib/utils/irqchip/aplic.c +5 -0
@@ -90,6 +90,11 @@ static void aplic_init(struct aplic_data *aplic) } } +struct sbi_dlist *aplic_get_list (void ) +{ +return &aplic_list; +} +void aplic_reinit_all (void ) {struct aplic_data *aplic;
Signature · 7 lines
2.43.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 3/4 lib: utils: irqchip: imsic: Dispatch non-IPI interrupts via irqchip framework
In reply to David E. Garcia PorrasCurrently imsic_process_hwirqs() only handles the IPI interrupt (IMSIC_IPI_ID) and logs all other external interrupts as unhandled. Platforms using IMSIC in MSI delivery mode (APLIC wired to IMSIC) have no way to handle M-mode external interrupts through the existing sbi_irqchip handler registration framework.
Route non-IPI interrupts through sbi_irqchip_process_hwirq() so that handlers registered via sbi_irqchip_register_handler() are invoked. Also implement hwirq_unmask and hwirq_mask callbacks using the existing imsic_local_eix_update() helper, enabling sbi_irqchip_register_handler() to automatically enable interrupt identities when a handler is registered.
--- lib/utils/irqchip/imsic.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
lib/utils/irqchip/imsic.c +13 -2
@@ -159,8 +159,7 @@ static int imsic_process_hwirqs(struct sbi_irqchip_device *chip)sbi_ipi_process ();break ;default : -sbi_printf ("%s: unhandled IRQ%d\n" , - __func__, (u32 )mirq); +sbi_irqchip_process_hwirq (chip, mirq);break ; } }
@@ -353,10 +352,22 @@ static int imsic_hwirq_setup(struct sbi_irqchip_device *chip, u32 hwirq)return 0 ; } +static void imsic_hwirq_unmask (struct sbi_irqchip_device *chip,u32 hwirq) +{ +imsic_local_eix_update (hwirq,1 , false, true); +} + +static void imsic_hwirq_mask (struct sbi_irqchip_device *chip,u32 hwirq) +{ +imsic_local_eix_update (hwirq,1 , false, false); +} +static struct sbi_irqchip_device imsic_device = { .warm_init = imsic_warm_irqchip_init, .process_hwirqs = imsic_process_hwirqs, .hwirq_setup = imsic_hwirq_setup, + .hwirq_unmask = imsic_hwirq_unmask, + .hwirq_mask = imsic_hwirq_mask, };int imsic_cold_irqchip_init (struct imsic_data *imsic)
Signature · 7 lines
2.43.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 4/4 include: mailbox: rpmi_msgprot: Add RPMI performance domain flag defines
In reply to David E. Garcia PorrasAdd bit-field defines for the RPMI performance domain attributes flags and fast-channel attributes flags as specified in the RPMI specification. These are needed by platform implementations that provide RPMI performance services (e.g. DVFS controllers).
Also add the missing db_write_value field to rpmi_perf_get_fast_chn_attr_resp to match the RPMI spec layout.
--- include/sbi_utils/mailbox/rpmi_msgprot.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/sbi_utils/mailbox/rpmi_msgprot.h +18 -0
@@ -830,6 +830,23 @@ struct rpmi_dpwr_get_state_resp {u32 state; }; +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_MASK (7U << 0) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP_POS 0 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP_POS 1 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP_POS 2 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP_POS) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP_POS) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP_POS) + +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_MASK (7U << 0) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP_POS 0 +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS 1 +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP (1U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_MASK (3U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_8 (0U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_16 (1U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_32 (2U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +/** RPMI Performance ServiceGroup Service IDs */ enum rpmi_performance_service_id {RPMI_PERF_SRV_ENABLE_NOTIFICATION =0x01 ,
@@ -941,6 +958,7 @@ struct rpmi_perf_get_fast_chn_attr_resp {u32 region_size;u32 db_addr_low;u32 db_addr_high; +u32 db_write_value;u32 db_id_low;u32 db_id_high;u32 db_perserved_low;
Signature · 7 lines
2.43.0 -- opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Re: [PATCH 4/4] include: mailbox: rpmi_msgprot: Add RPMI performance domain flag defines
Quoted 43 lines · David E. Garcia Porras
Add bit-field defines for the RPMI performance domain attributes flags and fast-channel attributes flags as specified in the RPMI specification. These are needed by platform implementations that provide RPMI performance services (e.g. DVFS controllers).
Also add the missing
db_write_valuefield torpmi_perf_get_fast_chn_attr_respto match the RPMI spec layout.Signed-off-by David E. Garcia Porras <[email protected]>--- include/sbi_utils/mailbox/rpmi_msgprot.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)include/sbi_utils/mailbox/rpmi_msgprot.h +17
-0@@ -830,6 +830,23 @@ struct rpmi_dpwr_get_state_resp {u32 state; }; +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_MASK (7U << 0) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP_POS 0 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP_POS 1 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP_POS 2 +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_FASTCHANNEL_SUPP_POS) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LVL_CHG_SUPP_POS) +#define RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP (1U << RPMI_PERF_DOMAIN_ATTRS_FLAGS_PERF_LIMIT_CHG_SUPP_POS) + +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_MASK (7U << 0) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP_POS 0 +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS 1 +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP (1U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_SUPP_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_MASK (3U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_8 (0U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_16 (1U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +#define RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_32 (2U << RPMI_PERF_FASTCHAN_ATTRS_FLAGS_DB_WIDTH_POS) +/** RPMI Performance ServiceGroup Service IDs */ enum rpmi_performance_service_id {RPMI_PERF_SRV_ENABLE_NOTIFICATION =0x01 ,
include/sbi_utils/mailbox/rpmi_msgprot.h struct rpmi_perf_get_fast_chn_attr_resp { · line 964
Quoted 7 lines
include/sbi_utils/mailbox/rpmi_msgprot.h +1
-0@@ -941,6 +958,7 @@ struct rpmi_perf_get_fast_chn_attr_resp {u32 region_size;u32 db_addr_low;u32 db_addr_high; +u32 db_write_value;u32 db_id_low;u32 db_id_high;u32 db_perserved_low;
The db_id_low, db_id_high, and db_preserved_low are also not aligned with the RPMI spec hence should be remove.
Quoted 8 lines
--
2.43.0--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Overall, this patch looks good. I have taken care of the above comment at the time of merging.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi
Hi David,
Quoted 5 lines · David E. Garcia Porras
This series exposes existing APLIC and IMSIC internal definitions and adds minimal extension points so that platform code can perform custom interrupt configuration without modifying the generic irqchip drivers.
Quoted 10 lines
The motivation is that a platform which uses AIA may need to
- Configure APLIC source/target registers directly for M-mode interrupt routing
- Iterate registered APLIC devices for platform-specific initialization
- Handle M-mode external interrupts beyond IPI in the IMSIC driver
Furthermore, a platform using RPMI PERFORMANCE service group may need to:
- Use RPMI performance domain attribute flags for RPMI PERFORMANCEPERF_DOMAINandFAST_CHANNELattribute control
Platform specific code should be doing minimal AIA configuration and we will soon have more functionally complete IMSIC and APLIC drivers. The idea is that platforms should be able to create desired interrupt routing to domains using only DT-based domain configuration and generic AIA, MPXY, and RPMI drivers.
Quoted 5 lines
Patch 1 moves APLIC register defines from
aplic.cto the publicaplic.hheader (pure move, no functional change). Patch 2 addsaplic_get_list()to allow platform code to iterate registered APLIC devices.
Based on above, both PATCH1 and PATCH2 are not needed. If a platform specific code still needs direct APLIC configuration then better to have these patches as part of the series which adds that platform support in OpenSBI.
Quoted 3 lines
Patch 3 routes non-IPI IMSIC interrupts through the
sbi_irqchiphandler framework and adds hwirq_unmask/hwirq_mask callbacks so thatsbi_irqchip_register_handler()works end-to-end with IMSIC.
The PATCH3 is really incomplete because IMSIC driver needs to implement lot more sbi_irqchip operations for a complete MSI controller functionality. We (Qualcomm) will be posting a complete IMSIC driver which will also include a complete APLIC driver supporting both MSI-mode and Direct-mode in the next few days so stay tuned.
Quoted 1 line
Patch 4 adds missing RPMI performance flag defines and a struct field.
The PATCH4 of this series looks good to me and should be merged.
Quoted 18 lines
All changes are additive and preserve existing behavior for platforms that do not use the new interfaces.
David E. Garcia Porras (4):
lib: utils: irqchip: aplic: Move register defines to public header
lib: utils: irqchip: aplic: Addaplic_get_list()accessor
lib: utils: irqchip: imsic: Dispatch non-IPI interrupts via irqchip
framework
include: mailbox:rpmi_msgprot: Add RPMI performance domain flag
definesinclude/sbi_utils/irqchip/aplic.h | 103 ++++++++++++++++++++++ include/sbi_utils/mailbox/rpmi_msgprot.h | 18 ++++ lib/utils/irqchip/aplic.c | 106 ++--------------------- lib/utils/irqchip/imsic.c | 15 +++- 4 files changed, 139 insertions(+), 103 deletions(-)
Quoted 8 lines
--
2.43.0--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Regards,
Anup
Signature · 3 lines
opensbi mailing list [email protected] http://lists.infradead.org/mailman/listinfo/opensbi