Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
riscv_aplic.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
15
16#ifndef ZEPHYR_INCLUDE_DRIVERS_INTERRUPT_CONTROLLER_RISCV_APLIC_H_
17#define ZEPHYR_INCLUDE_DRIVERS_INTERRUPT_CONTROLLER_RISCV_APLIC_H_
18
19#include <zephyr/device.h>
20#include <zephyr/types.h>
21
28#define APLIC_DOMAINCFG 0x0000
30#define APLIC_SOURCECFG_BASE 0x0004
32#define APLIC_SETIP_BASE 0x1C00
34#define APLIC_SETIPNUM 0x1CDC
36#define APLIC_CLRIP_BASE 0x1D00
38#define APLIC_CLRIPNUM 0x1DDC
40#define APLIC_SETIE_BASE 0x1E00
42#define APLIC_SETIENUM 0x1EDC
44#define APLIC_CLRIE_BASE 0x1F00
46#define APLIC_CLRIENUM 0x1FDC
48#define APLIC_MSIADDRCFG 0x1BC0
50#define APLIC_MSIADDRCFGH 0x1BC4
52#define APLIC_SMSIADDRCFG 0x1BC8
54#define APLIC_SMSIADDRCFGH 0x1BCC
56#define APLIC_GENMSI 0x3000
58#define APLIC_TARGET_BASE 0x3004
60#define APLIC_IDC_BASE 0x4000
62
69#define APLIC_DOMAINCFG_IE BIT(8)
71#define APLIC_DOMAINCFG_DM BIT(2)
73#define APLIC_DOMAINCFG_BE BIT(0)
75
83#define APLIC_MSIADDRCFGH_L_BIT 31
85#define APLIC_MSIADDRCFGH_HHXS_SHIFT 24
87#define APLIC_MSIADDRCFGH_HHXS_MASK 0x1F
89#define APLIC_MSIADDRCFGH_LHXS_SHIFT 20
91#define APLIC_MSIADDRCFGH_LHXS_MASK 0x7
93#define APLIC_MSIADDRCFGH_HHXW_SHIFT 16
95#define APLIC_MSIADDRCFGH_HHXW_MASK 0x7
97#define APLIC_MSIADDRCFGH_LHXW_SHIFT 12
99#define APLIC_MSIADDRCFGH_LHXW_MASK 0xF
101#define APLIC_MSIADDRCFGH_BAPPN_MASK 0xFFF
103
110#define APLIC_SOURCECFG_D_BIT 10
112#define APLIC_SOURCECFG_SM_MASK 0x7
114#define APLIC_SM_INACTIVE 0x0
116#define APLIC_SM_DETACHED 0x1
118#define APLIC_SM_EDGE_RISE 0x4
120#define APLIC_SM_EDGE_FALL 0x5
122#define APLIC_SM_LEVEL_HIGH 0x6
124#define APLIC_SM_LEVEL_LOW 0x7
126
133#define APLIC_TARGET_HART_SHIFT 18
135#define APLIC_TARGET_HART_MASK 0x3FFF
137#define APLIC_TARGET_MSI_DEL BIT(11)
139#define APLIC_TARGET_EIID_MASK 0x7FF
141
148#define APLIC_GENMSI_HART_SHIFT 18
150#define APLIC_GENMSI_HART_MASK 0x3FFF
152#define APLIC_GENMSI_CONTEXT_SHIFT 13
154#define APLIC_GENMSI_CONTEXT_MASK 0x1F
156#define APLIC_GENMSI_BUSY BIT(12)
158#define APLIC_GENMSI_MMSI_MODE BIT(11)
160#define APLIC_GENMSI_EIID_MASK 0x7FF
162
170#define APLIC_IDC_IDELIVERY_OFFSET 0x0
172#define APLIC_IDC_IFORCE_OFFSET 0x4
174#define APLIC_IDC_ITHRESHOLD_OFFSET 0x8
176#define APLIC_IDC_TOPI_OFFSET 0x18
178#define APLIC_IDC_CLAIMI_OFFSET 0x1C
180#define APLIC_IDC_STRUCT_SIZE 0x20
182
189#define APLIC_IDC_IDELIVERY_ENABLE BIT(0)
191
198#define APLIC_IDC_IFORCE_SET 1
200
207#define APLIC_IDC_ITHRESHOLD 0
209
216#define APLIC_IPRIO_MASK 0xFF
218#define APLIC_INTERRUPT_IDENTITY_SHIFT 16
220#define APLIC_INTERRUPT_IDENTITY_MASK (BIT_MASK(10) << APLIC_INTERRUPT_IDENTITY_SHIFT)
222
229static inline uint32_t aplic_sourcecfg_off(unsigned int src)
230{
231 return APLIC_SOURCECFG_BASE + (src - 1U) * 4U;
232}
233
240static inline uint32_t aplic_target_off(unsigned int src)
241{
242 return APLIC_TARGET_BASE + (src - 1U) * 4U;
243}
244
252static inline const struct device *riscv_aplic_get_dev(void)
253{
254 return DEVICE_DT_GET_ANY(riscv_aplic);
255}
256
266int riscv_aplic_domain_enable(const struct device *dev, bool enable);
267
278int riscv_aplic_config_src(const struct device *dev, unsigned int src, unsigned int sm);
279
290int riscv_aplic_enable_src(const struct device *dev, unsigned int src, bool enable);
291
292#if defined(CONFIG_RISCV_APLIC_MSI) || defined(__DOXYGEN__)
304int riscv_aplic_msi_route(const struct device *dev, unsigned int src, uint32_t hart, uint32_t eiid);
305
318 uint32_t hart_id, uint32_t context);
319#endif /* CONFIG_RISCV_APLIC_MSI */
320
330
338static inline void riscv_aplic_enable_source(unsigned int src)
339{
341}
342
350static inline void riscv_aplic_disable_source(unsigned int src)
351{
353}
354
355#if defined(CONFIG_RISCV_APLIC_MSI) || defined(__DOXYGEN__)
368#endif /* CONFIG_RISCV_APLIC_MSI */
369
370#if defined(CONFIG_RISCV_APLIC_DIRECT) || defined(__DOXYGEN__)
377static inline uint32_t aplic_idelivery_off(unsigned int cpu)
378{
380}
381
388static inline uint32_t aplic_ithreshold_off(unsigned int cpu)
389{
391}
392
399static inline uint32_t aplic_iforce_off(unsigned int cpu)
400{
402}
403
410static inline uint32_t aplic_topi_off(unsigned int cpu)
411{
413}
414
421static inline uint32_t aplic_claimi_off(unsigned int cpu)
422{
424}
425#endif /* CONFIG_RISCV_APLIC_DIRECT */
426
427#endif
#define DEVICE_DT_GET_ANY(compat)
Get a device reference from a devicetree compatible.
Definition device.h:346
int riscv_aplic_msi_route(const struct device *dev, unsigned int src, uint32_t hart, uint32_t eiid)
Configure MSI routing for an interrupt source.
static uint32_t aplic_target_off(unsigned int src)
Calculate target register offset for a source.
Definition riscv_aplic.h:240
#define APLIC_IDC_ITHRESHOLD_OFFSET
WLRL register indicating the minimum priority for an interrupt to be signaled.
Definition riscv_aplic.h:174
static uint32_t aplic_ithreshold_off(unsigned int cpu)
Calculate ithreshold register offset for a given CPU.
Definition riscv_aplic.h:388
int riscv_aplic_domain_enable(const struct device *dev, bool enable)
Enable or disable the APLIC domain.
#define APLIC_IDC_IFORCE_OFFSET
WARL register for testing (1=interrupt asserted by force).
Definition riscv_aplic.h:172
#define APLIC_IDC_STRUCT_SIZE
Per AIA spec, each IDC structure is 32 bytes.
Definition riscv_aplic.h:180
static uint32_t aplic_sourcecfg_off(unsigned int src)
Calculate sourcecfg register offset for a source.
Definition riscv_aplic.h:229
static const struct device * riscv_aplic_get_dev(void)
Get the APLIC device instance.
Definition riscv_aplic.h:252
static uint32_t aplic_topi_off(unsigned int cpu)
Calculate topi register offset for a given CPU.
Definition riscv_aplic.h:410
#define APLIC_IDC_CLAIMI_OFFSET
Read-only register identical to TOPI, with the affect of clearing the pending bit.
Definition riscv_aplic.h:178
#define APLIC_IDC_TOPI_OFFSET
Read-only register indicating the current highest-priority interrupt pending.
Definition riscv_aplic.h:176
static void riscv_aplic_enable_source(unsigned int src)
Enable an interrupt source (convenience wrapper).
Definition riscv_aplic.h:338
#define APLIC_SOURCECFG_BASE
Source configuration registers base offset.
Definition riscv_aplic.h:30
static uint32_t aplic_idelivery_off(unsigned int cpu)
Calculate idelivery register offset for a given CPU.
Definition riscv_aplic.h:377
static void riscv_aplic_msi_inject_genmsi(uint32_t hart, uint32_t eiid)
Inject MSI using GENMSI (convenience wrapper).
Definition riscv_aplic.h:364
int riscv_aplic_msi_inject_software_interrupt(const struct device *dev, uint32_t eiid, uint32_t hart_id, uint32_t context)
Inject a software-triggered MSI.
static void riscv_aplic_disable_source(unsigned int src)
Disable an interrupt source (convenience wrapper).
Definition riscv_aplic.h:350
static uint32_t aplic_iforce_off(unsigned int cpu)
Calculate iforce register offset for a given CPU.
Definition riscv_aplic.h:399
#define APLIC_IDC_BASE
Interrupt Domain Control (IDC) region base offset.
Definition riscv_aplic.h:60
uint32_t riscv_aplic_get_num_sources(const struct device *dev)
Get the number of interrupt sources.
int riscv_aplic_enable_src(const struct device *dev, unsigned int src, bool enable)
Enable or disable an interrupt source.
static uint32_t aplic_claimi_off(unsigned int cpu)
Calculate claimi register offset for a given CPU.
Definition riscv_aplic.h:421
#define APLIC_TARGET_BASE
Target registers base offset.
Definition riscv_aplic.h:58
int riscv_aplic_config_src(const struct device *dev, unsigned int src, unsigned int sm)
Configure an interrupt source mode.
#define APLIC_IDC_IDELIVERY_OFFSET
WARL register to specify interrupt delivery (0=disabled, 1=enabled).
Definition riscv_aplic.h:170
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513