Add hexagon l2vic device
v2 cover Add hexagon l2vic device
This is a follow-up to the previous system emulation series which introduced hex-l2vic. The device implementation has been reworked and should address the feedback from previous threads.
Changes since v1:
- refactored l2vic_{read,write} to use a table
- changed arch tests to use QemuBaseTest.scratch_file
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Brian Cain (6):
target/hexagon: initialize deferred sreg-write temps to current value target/hexagon: fix PC not advancing for non-COF TB-ending packets bitops.h: Add find_first_bit32()
hw/hexagon: connect l2vic device
tests/qtest: add L2VIC qtest
tests/functional/hexagon: add arch_tests functional test
Sid Manning (1):
hw/intc: Add l2vic interrupt controller
MAINTAINERS | 5 + docs/devel/hexagon-l2vic.rst | 55 ++ docs/devel/index-internals.rst | 1 + include/hw/hexagon/hexagon.h | 1 + include/hw/hexagon/hexagon_globalreg.h | 4 + include/hw/intc/hex-l2vic.h | 87 ++++ include/qemu/bitops.h | 30 +- target/hexagon/cpu.h | 2 + target/hexagon/translate.h | 3 + hw/hexagon/hexagon_dsp.c | 20 + hw/hexagon/hexagon_globalreg.c | 41 +- hw/hexagon/virt.c | 22 + hw/intc/hex-l2vic.c | 532 ++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/genptr.c | 14 +- target/hexagon/op_helper.c | 21 +- target/hexagon/translate.c | 56 ++- tests/qtest/l2vic-test.c | 242 +++++++++ hw/hexagon/Kconfig | 1 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 2 + hw/intc/trace-events | 4 + tests/functional/hexagon/meson.build | 5 + tests/functional/hexagon/test_arch_tests.py | 63 +++ tests/functional/meson.build | 1 + tests/qtest/meson.build | 2 +- 26 files changed, 1187 insertions(+), 32 deletions(-) create mode 100644 docs/devel/hexagon-l2vic.rst create mode 100644 include/hw/intc/hex-l2vic.h create mode 100644 hw/intc/hex-l2vic.c create mode 100644 tests/qtest/l2vic-test.c create mode 100644 tests/functional/hexagon/meson.build create mode 100755 tests/functional/hexagon/test_arch_tests.py
Signature · 1 line
2.34.1
PATCH v2 1/7 target/hexagon: initialize deferred sreg-write temps to current value
Unconditionally allocate and initialize the temp to the sreg's current value for every logged sreg write, rather than only allocating when need_commit is set or the register is SSR.
Without this, reading a deferred sreg write within the same packet before it is committed can observe an uninitialized temp instead of the register's pre-packet value.
--- target/hexagon/translate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/hexagon/translate.c +3 -2
@@ -615,9 +615,10 @@ static void gen_start_packet(DisasContext *ctx) }for (i =0 ; i < ctx->sreg_log_idx; i++) {int reg_num = ctx->sreg_log[i]; -if (reg_num <HEX_SREG_GLB_START && - (ctx->need_commit || reg_num ==HEX_SREG_SSR )) { +if (reg_num <HEX_SREG_GLB_START ) { ctx->t_sreg_new_value[reg_num] =tcg_temp_new (); +tcg_gen_mov_tl (ctx->t_sreg_new_value[reg_num], + hex_t_sreg[reg_num]); } }for (i =0 ; i <NUM_GREGS ; i++) {
Signature · 1 line
2.34.1
Re: [PATCH v2 1/7] target/hexagon: initialize deferred sreg-write temps to current value
Quoted 8 lines · Brian Cain
Unconditionally allocate and initialize the temp to the sreg's current value for every logged sreg write, rather than only allocating when
need_commitis set or the register is SSR.Without this, reading a deferred sreg write within the same packet before it is committed can observe an uninitialized temp instead of the register's pre-packet value.
Do you have an example where this happens? I searched the code and only found references to t_sreg_new_value guarded by ctx->need_commit except gen_sreg_writes which should have an early exit if ctx->need_commit is set (similar to gen_reg_writes).
The special handling of SSR could be cleaned up. Consider making writes to SSR set ctx->need_commit.
Also, consider creating a function similar to get_result_gpr to centralize all the checking (e.g., in gen_log_sreg_write).
Quoted 28 lines
Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>--- target/hexagon/translate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/hexagon/translate.c +3
-3@@ -615,9 +615,10 @@ static void gen_start_packet(DisasContext *ctx) }for (i =0 ; i < ctx->sreg_log_idx; i++) {int reg_num = ctx->sreg_log[i]; -if (reg_num <HEX_SREG_GLB_START && - (ctx->need_commit || reg_num ==HEX_SREG_SSR )) { +if (reg_num <HEX_SREG_GLB_START ) { ctx->t_sreg_new_value[reg_num] =tcg_temp_new (); +tcg_gen_mov_tl (ctx->t_sreg_new_value[reg_num], + hex_t_sreg[reg_num]); } }for (i =0 ; i <NUM_GREGS ; i++) { --2.34.1
PATCH v2 2/7 target/hexagon: fix PC not advancing for non-COF TB-ending packets
In reply to Brian CainAdd hex_next_PC, a global mirroring CPUHexagonState::next_PC, and ctx->need_next_pc, so that gen_write_new_pc_addr() can write the branch target through hex_next_PC instead of hex_gpr[HEX_REG_PC] when a later unconditional write of PC is expected. gen_end_tb() then commits hex_next_PC into hex_gpr[HEX_REG_PC] at the end of the packet.
Previously, non-COF instructions that still end a TB did not advance the PC, since next_PC's value was never written back into the PC register.
--- target/hexagon/translate.h | 3 +++ target/hexagon/genptr.c | 14 ++++++++--- target/hexagon/translate.c | 51 ++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 19 deletions(-)
target/hexagon/translate.h +3 -0
@@ -40,6 +40,7 @@ typedef struct DisasContext {int reg_log_idx;DECLARE_BITMAP (regs_written,TOTAL_PER_THREAD_REGS );DECLARE_BITMAP (predicated_regs,TOTAL_PER_THREAD_REGS ); +bool pkt_ends_tb;bool implicit_usr_write;#ifndef CONFIG_USER_ONLY int greg_log[GREG_WRITES_MAX ];
@@ -75,6 +76,7 @@ typedef struct DisasContext {DECLARE_BITMAP (insn_qregs_read,NUM_QREGS );bool pre_commit;bool need_commit; +bool need_next_pc;TCGCond branch_cond;target_ulong branch_dest;bool is_tight_loop;
@@ -310,6 +312,7 @@ extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];extern TCGv hex_pred[NUM_PREGS ];extern TCGv hex_slot_cancelled;extern TCGv hex_new_value_usr; +extern TCGv hex_next_PC;extern TCGv hex_store_addr[STORES_MAX ];extern TCGv_i32 hex_store_width[STORES_MAX ];extern TCGv hex_store_val32[STORES_MAX ];
target/hexagon/genptr.c +11 -3
@@ -613,14 +613,22 @@ static void gen_write_new_pc_addr(DisasContext *ctx, TCGv addr,tcg_gen_brcondi_tl (cond, pred,1 , pred_false); } +/* +* If gen_end_tb() will unconditionally overwrite PC with hex_next_PC +* (because this packet has a predicated COF that may not execute), +* write the branch target there instead of directly into the PC +* global, or the overwrite in gen_end_tb() would clobber it. +*/ +TCGv pc_wr = ctx->need_next_pc ? hex_next_PC : hex_gpr[HEX_REG_PC ]; +if (ctx->pkt.pkt_has_multi_cof) {/* If there are multiple branches in a packet, ignore the second one */ -tcg_gen_movcond_tl (TCG_COND_NE , hex_gpr[HEX_REG_PC ], +tcg_gen_movcond_tl (TCG_COND_NE , pc_wr, ctx->branch_taken,tcg_constant_tl (0 ), - hex_gpr[HEX_REG_PC ], addr); + pc_wr, addr);tcg_gen_movi_tl (ctx->branch_taken,1 ); }else { -tcg_gen_mov_tl (hex_gpr[HEX_REG_PC ], addr); +tcg_gen_mov_tl (pc_wr, addr); }if (cond !=TCG_COND_ALWAYS ) {
target/hexagon/translate.c +35 -16
93 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 2/7] target/hexagon: fix PC not advancing for non-COF TB-ending packets
Quoted 20 lines · Brian Cain
Add
hex_next_PC, a global mirroringCPUHexagonState::next_PC, andctx->need_next_pc, so thatgen_write_new_pc_addr()can write the branch target throughhex_next_PCinstead of hex_gpr[HEX_REG_PC] when a later unconditional write of PC is expected.gen_end_tb()then commitshex_next_PCinto hex_gpr[HEX_REG_PC] at the end of the packet.Previously, non-COF instructions that still end a TB did not advance the PC, since next_PC's value was never written back into the PC register.
Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>--- target/hexagon/translate.h | 3 +++ target/hexagon/genptr.c | 14 ++++++++--- target/hexagon/translate.c | 51 ++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 19 deletions(-)
target/hexagon/translate.c void hexagon_translate_init(void) · line 1349
Quoted 6 lines
target/hexagon/translate.c +2
-0@@ -1327,6 +1344,8 @@ void hexagon_translate_init(void) } hex_new_value_usr =tcg_global_mem_new (tcg_env, offsetof(CPUHexagonState , new_value_usr),"new_value_usr" ); + hex_next_PC =tcg_global_mem_new (tcg_env, + offsetof(CPUHexagonState , next_PC),"next_PC" );
This only lives within the context of a single packet, so it shouldn't be global.
Put it into DisasContext and make it a tmp similar to new_value.
Re: [PATCH v2 2/7] target/hexagon: fix PC not advancing for non-COF TB-ending packets
Quoted 33 lines · Taylor Simpson
On Wed, Jul 15, 2026 at 12:57 PM Brian Cain <[email protected]> wrote:
Add
hex_next_PC, a global mirroringCPUHexagonState::next_PC, andctx->need_next_pc, so thatgen_write_new_pc_addr()can write the branch target throughhex_next_PCinstead of hex_gpr[HEX_REG_PC] when a later unconditional write of PC is expected.gen_end_tb()then commitshex_next_PCinto hex_gpr[HEX_REG_PC] at the end of the packet.Previously, non-COF instructions that still end a TB did not advance the
PC, since next_PC's value was never written back into the PC register.Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>---
target/hexagon/translate.h | 3 +++ target/hexagon/genptr.c | 14 ++++++++---target/hexagon/translate.c| 51
++++++++++++++++++++++++++------------
3 files changed, 49 insertions(+), 19 deletions(-)@@ -1327,6 +1344,8 @@ void
hexagon_translate_init(void)}
hex_new_value_usr =tcg_global_mem_new(tcg_env, offsetof(CPUHexagonState, new_value_usr), "new_value_usr"); +hex_next_PC= tcg_global_mem_new(tcg_env,
+offsetof(CPUHexagonState, next_PC), "next_PC");
Quoted 3 lines
This only lives within the context of a single packet, so it shouldn't be global.
Put it into DisasContext and make it a tmp similar to
new_value.
Taylor - this patch was included for the sake of testing the l2vic series, but landed recently - https://lore.kernel.org/qemu-devel/20260720100107.GA816167@fedora/
So I'll send a new independent series with updates suggested for "target/hexagon: fix PC not advancing for non-COF TB-ending packets" and "target/hexagon: initialize deferred sreg-write temps to current value".
-Brian
PATCH v2 3/7 bitops.h: Add find_first_bit32()
In reply to Brian Cainset_bit32()/test_bit32()/etc already let devices operate on guest-visible uint32_t register arrays without depending on the host's 'unsigned long' size. find_first_bit() has no such equivalent, which pushes callers towards casting a uint32_t array to 'unsigned long *'.
Add find_first_bit32(), implemented the same way as find_first_bit().
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
include/qemu/bitops.h +26 -4
@@ -43,10 +43,9 @@* be some guest-visible register view of the bit array. * * We do not currently implement uint32_t versions of find_last_bit(), -* find_next_bit(), find_next_zero_bit(), find_first_bit() or -* find_first_zero_bit(), because we haven't yet needed them. If you -* need them you should implement them similarly to the 'unsigned long' -* versions. +* find_next_bit(), find_next_zero_bit() or find_first_zero_bit(), +* because we haven't yet needed them. If you need them you should +* implement them similarly to the 'unsigned long' versions. * * You can declare a bitmap to be used with these functions via the * DECLARE_BITMAP and DECLARE_BITMAP32 macros in bitmap.h.
@@ -382,6 +381,29 @@ static inline int test_bit32(long nr, const uint32_t *addr)return 1U & (addr[BIT32_WORD (nr)] >> (nr &31 )); } +/** +* find_first_bit32 - find the first set bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first set bit, +* or @size if there is no set bit in the bitmap. +*/ +static inline uint32_t find_first_bit32 (const uint32_t *addr,uint32_t size) +{ +uint32_t result; + +for (result =0 ; result < size; result +=32 ) { +uint32_t tmp = *addr++; +if (tmp) { + result +=ctz32 (tmp); +return result < size ? result : size; + } + } +/* Not found */ +return size; +} +/** * DOC: Miscellaneous bit operations on single values *
Signature · 1 line
2.34.1
Re: [PATCH v2 3/7] bitops.h: Add find_first_bit32()
Hi Brian,
some random thoughts...
Quoted 10 lines · Brian Cain
set_bit32()/test_bit32()/etc already let devices operate on guest-visible
uint32_tregister arrays without depending on the host's 'unsigned long' size.find_first_bit()has no such equivalent, which pushes callers towards casting auint32_tarray to 'unsigned long *'.Add
find_first_bit32(), implemented the same way asfind_first_bit().Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>
Quoted 8 lines
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)+/**
+ *find_first_bit32- find the first set bit in a memory region
+ * @addr: The address to start the search at
s/addr/ptr/?
Quoted 1 line
+ * @size: The maximum size to search
Pre-existing, it is not clear this is expressed in bits. Neither if we expect it to be a multiple of 32, or @addr to be 32-bit aligbed.
Maybe rename as @last_searched_bit?
Quoted 2 lines
+ *
+ * Returns the bit number of the first set bit,
"Returns the index of the first bit,"?
Quoted 3 lines
+ * or @size if there is no set bit in the bitmap.
+ */
+static inlineuint32_tfind_first_bit32(const uint32_t *addr, uint32_t size)
Could we simply return a plain unsigned? Also take a size_t?
Quoted 13 lines
include/qemu/bitops.h +13
-0+{ +uint32_t result; + +for (result =0 ; result < size; result +=32 ) { +uint32_t tmp = *addr++; +if (tmp) { + result +=ctz32 (tmp); +return result < size ? result : size; + } + } +/* Not found */ +return size; +}
Re: [PATCH v2 3/7] bitops.h: Add find_first_bit32()
Quoted 25 lines · Philippe Mathieu-Daudé
Hi Brian,
some random thoughts...
Quoted 10 lines · Brian Cain
set_bit32()/test_bit32()/etc already let devices operate on guest-visible
uint32_tregister arrays without depending on the host's 'unsigned long' size.find_first_bit()has no such equivalent, which pushes callers towards casting auint32_tarray to 'unsigned long *'.Add
find_first_bit32(), implemented the same way asfind_first_bit().Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>Quoted 8 lines
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)+/**
+ *find_first_bit32- find the first set bit in a memory region
+ * @addr: The address to start the search at
Quoted 8 lines
s/addr/ptr/?
Quoted 1 line
+ * @size: The maximum size to search
Pre-existing, it is not clear this is expressed in bits. Neither if we expect it to be a multiple of 32, or @addr to be 32-bit aligbed.
Maybe rename as @last_searched_bit?
Could we please stop bikeshedding this function? It's a simple copy of the existing find_first_bit() but with the type changed from 'unsigned long' to 'uint32_t'. The comments and parameter names on that existing function have been fine for years, and having the new function pick different names and comment phrasing seems unnecessary and obscures the parallels between the two functions.
thanks
-- PMM
Re: [PATCH v2 3/7] bitops.h: Add find_first_bit32()
Quoted 36 lines · Peter Maydell
Quoted 25 lines · Philippe Mathieu-Daudé
Hi Brian,
some random thoughts...
Quoted 10 lines · Brian Cain
set_bit32()/test_bit32()/etc already let devices operate on guest-visible
uint32_tregister arrays without depending on the host's 'unsigned long' size.find_first_bit()has no such equivalent, which pushes callers towards casting auint32_tarray to 'unsigned long *'.Add
find_first_bit32(), implemented the same way asfind_first_bit().Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>Quoted 8 lines
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)+/**
+ *find_first_bit32- find the first set bit in a memory region
+ * @addr: The address to start the search atQuoted 8 lines
s/addr/ptr/?
Quoted 1 line
+ * @size: The maximum size to search
Pre-existing, it is not clear this is expressed in bits. Neither if we expect it to be a multiple of 32, or @addr to be 32-bit aligbed.
Maybe rename as @last_searched_bit?
Quoted 7 lines
Could we please stop bikeshedding this function? It's a simple copy of the existing
find_first_bit()but with the type changed from 'unsigned long' to 'uint32_t'. The comments and parameter names on that existing function have been fine for years, and having the new function pick different names and comment phrasing seems unnecessary and obscures the parallels between the two functions.
Argument renaming of course implies renaming the other companion methods. You taught me to add public APIs with good descriptions when possible, I thought your advice was worth to other contributors. I'm not considering this review comment as bikeshedding. Anyway, thanks for your review and advice. I don't object if Brian keeps the current names or rename as @a, @b, @foo, @bar.
Thanks.
Re: [PATCH v2 3/7] bitops.h: Add find_first_bit32()
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Peter Maydell
Quoted 25 lines · Philippe Mathieu-Daudé
Hi Brian,
some random thoughts...
Quoted 10 lines · Brian Cain
set_bit32()/test_bit32()/etc already let devices operate on guest-visible
uint32_tregister arrays without depending on the host's 'unsigned long' size.find_first_bit()has no such equivalent, which pushes callers towards casting auint32_tarray to 'unsigned long *'.Add
find_first_bit32(), implemented the same way asfind_first_bit().Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>Quoted 8 lines
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)+/**
+ *find_first_bit32- find the first set bit in a memory region
+ * @addr: The address to start the search atQuoted 8 lines
s/addr/ptr/?
Quoted 1 line
+ * @size: The maximum size to search
Pre-existing, it is not clear this is expressed in bits. Neither if we expect it to be a multiple of 32, or @addr to be 32-bit aligbed.
Maybe rename as @last_searched_bit?
Quoted 7 lines
Could we please stop bikeshedding this function? It's a simple copy of the existing
find_first_bit()but with the type changed from 'unsigned long' to 'uint32_t'. The comments and parameter names on that existing function have been fine for years, and having the new function pick different names and comment phrasing seems unnecessary and obscures the parallels between the two functions.
Quoted 6 lines
Argument renaming of course implies renaming the other companion methods. You taught me to add public APIs with good descriptions when possible, I thought your advice was worth to other contributors. I'm not considering this review comment as bikeshedding. Anyway, thanks for your review and advice. I don't object if Brian keeps the current names or rename as @a, @b, @foo, @bar.
Sorry for being a bit grumpy -- it's just that this is the second time around of somebody suggesting a change here to something that's already present in the existing function this is patterned off (and which we borrowed from the Linux kernel originally).
-- PMM
Re: [PATCH v2 3/7] bitops.h: Add find_first_bit32()
Quoted 55 lines · Peter Maydell
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Peter Maydell
Quoted 25 lines · Philippe Mathieu-Daudé
Hi Brian,
some random thoughts...
Quoted 10 lines · Brian Cain
set_bit32()/test_bit32()/etc already let devices operate on guest-visible
uint32_tregister arrays without depending on the host's 'unsigned long' size.find_first_bit()has no such equivalent, which pushes callers towards casting auint32_tarray to 'unsigned long *'.Add
find_first_bit32(), implemented the same way asfind_first_bit().Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>Quoted 8 lines
--- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)+/**
+ *find_first_bit32- find the first set bit in a memory region
+ * @addr: The address to start the search atQuoted 8 lines
s/addr/ptr/?
Quoted 1 line
+ * @size: The maximum size to search
Pre-existing, it is not clear this is expressed in bits. Neither if we expect it to be a multiple of 32, or @addr to be 32-bit aligbed.
Maybe rename as @last_searched_bit?
Quoted 7 lines
Could we please stop bikeshedding this function? It's a simple copy of the existing
find_first_bit()but with the type changed from 'unsigned long' to 'uint32_t'. The comments and parameter names on that existing function have been fine for years, and having the new function pick different names and comment phrasing seems unnecessary and obscures the parallels between the two functions.Quoted 6 lines
Argument renaming of course implies renaming the other companion methods. You taught me to add public APIs with good descriptions when possible, I thought your advice was worth to other contributors. I'm not considering this review comment as bikeshedding. Anyway, thanks for your review and advice. I don't object if Brian keeps the current names or rename as @a, @b, @foo, @bar.
Quoted 5 lines
Sorry for being a bit grumpy -- it's just that this is the second time around of somebody suggesting a change here to something that's already present in the existing function this is patterned off (and which we borrowed from the Linux kernel originally).
Ah, I missed the previous suggestion and didn't know about the historical origin. Thanks Peter.
PATCH v2 4/7 hw/intc: Add l2vic interrupt controller
In reply to Brian CainFrom: Sid Manning <[email protected]>
The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. This device model implements the register interface, interrupt steering, and edge/level type handling needed by the sysemu machine models.
--- MAINTAINERS | 3 + docs/devel/hexagon-l2vic.rst | 55 ++++ docs/devel/index-internals.rst | 1 + include/hw/intc/hex-l2vic.h | 87 ++++++ target/hexagon/cpu.h | 2 + hw/intc/hex-l2vic.c | 532 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/op_helper.c | 21 +- hw/hexagon/Kconfig | 1 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 2 + hw/intc/trace-events | 4 + 12 files changed, 712 insertions(+), 1 deletion(-) create mode 100644 docs/devel/hexagon-l2vic.rst create mode 100644 include/hw/intc/hex-l2vic.h create mode 100644 hw/intc/hex-l2vic.c
MAINTAINERS +3 -0
@@ -250,6 +250,8 @@ M: Brian Cain <[email protected]> R: Pierrick Bouvier <[email protected]> S: Supported F: target/hexagon/ +F: hw/intc/hex-l2vic.c +F: include/hw/intc/hex-l2vic.h X: target/hexagon/idef-parser/ X: target/hexagon/gen_idef_parser_funcs.py F: linux-user/hexagon/
@@ -262,6 +264,7 @@ F: gdbstub/gdb-xml/hexagon*.xml F: docs/system/target-hexagon.rst F: docs/system/hexagon/ F: docs/devel/hexagon-sys.rst +F: docs/devel/hexagon-l2vic.rst T: git https://github.com/qualcomm/qemu.git hex-next Hexagon idef-parser
docs/devel/hexagon-l2vic.rst new file +55 -0
55 lines not on this page · raw message
docs/devel/index-internals.rst +1 -0
@@ -15,6 +15,7 @@ Details about QEMU's various subsystems including how to add features to them. clocks ebpf_rss hexagon-sys + hexagon-l2vic migration/index multi-process reset
include/hw/intc/hex-l2vic.h new file +87 -0
87 lines not on this page · raw message
target/hexagon/cpu.h +2 -0
@@ -39,6 +39,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;#include "qemu/bitmap.h" #include "target/hexagon/reg_fields.h" +#include "hw/intc/hex-l2vic.h" #define NUM_PREGS 4#define TOTAL_PER_THREAD_REGS 64
@@ -198,6 +199,7 @@ struct ArchCPU {uint32_t boot_addr;HexagonGlobalRegState *globalregs;uint32_t htid; +HexL2VicInterface *l2vic;#endif };
hw/intc/hex-l2vic.c new file +532 -0
532 lines not on this page · raw message
target/hexagon/cpu.c +2 -0
@@ -65,6 +65,8 @@ static const Property hexagon_cpu_properties[] = {DEFINE_PROP_LINK ("tlb" , HexagonCPU, tlb,TYPE_HEXAGON_TLB , HexagonTLBState *),DEFINE_PROP_UINT32 ("exec-start-addr" , HexagonCPU, boot_addr,0xffffffff ), +DEFINE_PROP_LINK ("l2vic" , HexagonCPU, l2vic, + TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *),DEFINE_PROP_LINK ("global-regs" , HexagonCPU, globalregs, TYPE_HEXAGON_GLOBALREG, HexagonGlobalRegState *), DEFINE_PROP_UINT32("htid", HexagonCPU, htid, 0),
target/hexagon/op_helper.c +20 -1
@@ -40,6 +40,7 @@#include "hw/hexagon/hexagon_globalreg.h" #include "hex_mmu.h" #include "hw/hexagon/hexagon_tlb.h" +#include "hw/intc/hex-l2vic.h" #include "hex_interrupts.h" #include "hexswi.h" #endif
@@ -1557,7 +1558,25 @@ void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,void HELPER (ciad )(CPUHexagonState *env,uint32_t mask) { -g_assert_not_reached (); +uint32_t ipendad; +uint32_t iad; +HexagonCPU *cpu; + +BQL_LOCK_GUARD (); + cpu =env_archcpu (env); + ipendad = cpu->globalregs ? +hexagon_globalreg_read (cpu->globalregs,HEX_SREG_IPENDAD , + env->threadId) :0 ; + iad =fGET_FIELD (ipendad,IPENDAD_IAD ); +fSET_FIELD (ipendad,IPENDAD_IAD , iad & ~(mask)); +if (cpu->globalregs) { +hexagon_globalreg_write (cpu->globalregs,HEX_SREG_IPENDAD , + ipendad, env->threadId); + } +if (cpu->l2vic) { +l2vic_clear_interrupt (cpu->l2vic); + } +hex_interrupt_update (env); }void HELPER (siad )(CPUHexagonState *env,uint32_t mask)
hw/hexagon/Kconfig +1 -0
@@ -2,6 +2,7 @@ config HEX_DSP bool default y depends on HEXAGON + select HEX_L2VIC config HEX_VIRT bool
hw/intc/Kconfig +3 -0
@@ -8,6 +8,9 @@ config I8259 config PL190 bool +config HEX_L2VIC + bool + config IOAPIC bool select I8259
hw/intc/meson.build +2 -0
@@ -74,6 +74,8 @@ specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('xics_spapr.c', 'spapr_xi specific_ss.add(when: 'CONFIG_XIVE', if_true: files('xive.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XIVE'], if_true: files('spapr_xive_kvm.c')) + +specific_ss.add(when: 'CONFIG_HEX_L2VIC', if_true: files('hex-l2vic.c')) specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongson_ipi_common.c')) specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.c'))
hw/intc/trace-events +4 -0
@@ -337,6 +337,10 @@ sh_intc_register(const char *s, int id, unsigned short v, int c, int m) "%s %u - sh_intc_read(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " -> 0x%lx" sh_intc_write(unsigned size, uint64_t offset, unsigned long val) "size %u 0x%" PRIx64 " <- 0x%lx" sh_intc_set(int id, int enable) "setting interrupt group %d to %d" +# hex-l2vic.c +hex_l2vic_reg_write(unsigned int addr, uint32_t value) "addr: 0x%03x value: 0x%08"PRIx32 +hex_l2vic_reg_read(unsigned int addr, uint32_t value) "addr: 0x%03x value: 0x%08"PRIx32 +hex_l2vic_delivered(int irq, int vid) "l2vic: delivered %d (vid %d)" # loongson_ipi.c loongson_ipi_read(unsigned size, uint64_t addr, uint64_t val) "size: %u addr: 0x%"PRIx64 "val: 0x%"PRIx64
Signature · 1 line
2.34.1
Re: [PATCH v2 4/7] hw/intc: Add l2vic interrupt controller
Quoted 20 lines · Brian Cain
From: Sid Manning <[email protected]>
The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. This device model implements the register interface, interrupt steering, and edge/level type handling needed by the sysemu machine models.
Co-authored-by Matheus Tavares Bernardino <[email protected]>Co-authored-by Damien Hedde <[email protected]>Signed-off-by Brian Cain <[email protected]>--- MAINTAINERS | 3 + docs/devel/hexagon-l2vic.rst | 55 ++++ docs/devel/index-internals.rst | 1 + include/hw/intc/hex-l2vic.h | 87 ++++++ target/hexagon/cpu.h | 2 + hw/intc/hex-l2vic.c | 532 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/op_helper.c | 21 +-
Quoted 9 lines
hw/hexagon/Kconfig | 1 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 2 + hw/intc/trace-events | 4 + 12 files changed, 712 insertions(+), 1 deletion(-) create mode 100644 docs/devel/hexagon-l2vic.rst create mode 100644 include/hw/intc/hex-l2vic.h create mode 100644 hw/intc/hex-l2vic.c
Re: [PATCH v2 4/7] hw/intc: Add l2vic interrupt controller
In reply to Brian CainHi Brian,
+Peter for commit 3d7680fb18c ("bitops.h: Define bit operations on 'uint32_t' arrays").
Quoted 282 lines · Brian Cain
From: Sid Manning <[email protected]>
The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. This device model implements the register interface, interrupt steering, and edge/level type handling needed by the sysemu machine models.
Co-authored-by Matheus Tavares Bernardino <[email protected]>Co-authored-by Damien Hedde <[email protected]>Signed-off-by Brian Cain <[email protected]>--- MAINTAINERS | 3 + docs/devel/hexagon-l2vic.rst | 55 ++++ docs/devel/index-internals.rst | 1 + include/hw/intc/hex-l2vic.h | 87 ++++++ target/hexagon/cpu.h | 2 + hw/intc/hex-l2vic.c | 532 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/op_helper.c | 21 +- hw/hexagon/Kconfig | 1 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 2 + hw/intc/trace-events | 4 + 12 files changed, 712 insertions(+), 1 deletion(-)create mode 100644
docs/devel/hexagon-l2vic.rst
create mode 100644include/hw/intc/hex-l2vic.h
create mode 100644hw/intc/hex-l2vic.cMAINTAINERS +3
-0@@ -250,6 +250,8 @@ M: Brian Cain <[email protected]> R: Pierrick Bouvier <[email protected]> S: Supported F: target/hexagon/ +F: hw/intc/hex-l2vic.c +F: include/hw/intc/hex-l2vic.h X: target/hexagon/idef-parser/ X: target/hexagon/gen_idef_parser_funcs.py F: linux-user/hexagon/@@ -262,6 +264,7 @@ F: gdbstub/gdb-xml/hexagon*.xml F: docs/system/target-hexagon.rst F: docs/system/hexagon/ F: docs/devel/hexagon-sys.rst +F: docs/devel/hexagon-l2vic.rst T: git https://github.com/qualcomm/qemu.git hex-next Hexagon idef-parserdocs/devel/hexagon-l2vic.rst new file +55
-0@@ -0,0 +1,55 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Hexagon L2 Vectored Interrupt Controller +======================================== + + +.. code-block:: none + + +-------------+ +----------------------+ + | l2vic | | hexagon core | + | | | | + IRQ in ---->| | | | + IRQ in ---->| VID0 -|----------------->| irq2 | + ... ---->| | | | | + IRQ in ---->| | | v | + | ... | | <int steering> | + | | | / | | \ | + IRQ in ---->| | | t0 t1 t2 t3 ...| + IRQ in ---->| VIDN -| | | + ... ---->| | | | + IRQ in ---->| | | Global SREG File | + | | | | + | State | | | + | [ ] <--|==================|==> [ VID ] | + | [ ] <--|==================|==> [ VID1 ] | + | | | | + +-------------+ +----------------------+ + +L2VIC/Core Integration +---------------------- + +* hexagon core supports 8 external interrupt sources +* l2vic supports 1024 input interrupts mapped among 4 output interrupts +* l2vic has four output signals: { VID0, VID1, VID2, VID3 } +* l2vic device has a bank of registers per-VID that can be used to query + the status or assert new interrupts. +* Interrupts are 'steered' to threads based on { thread priority, 'EX' state, + thread interrupt mask, thread interrupt enable, global interrupt enable, + etc. }. +* Any hardware thread could conceivably handle any input interrupt, dependent + on state. +* The system register transfer instruction can read the VID0-VID3 values from + the l2vic when reading from hexagon core system registers "VID" and "VID1". +* When l2vic VID0 has multiple active interrupts, it pulses the VID0 output + IRQ and stores the IRQ number for the VID0 register field. Only after this + interrupt is cleared can the l2vic pulse the VID0 output IRQ again and provide + the next interrupt number on the VID0 register. +* The ``ciad`` instruction clears the l2vic input interrupt and un-disables the + core interrupt. If some/an l2vic VID0 interrupt is pending when this occurs, + the next interrupt should fire and any subsequent reads of the VID register + should reflect the newly raised interrupt. +* In QEMU, on an external interrupt or an unmasked-pending interrupt, + all vCPUs are triggered (has_work==true) and each will grab the IO lock + while considering the steering logic to determine whether they're the thread + that must handle the interrupt.docs/devel/index-internals.rst +1
-0@@ -15,6 +15,7 @@ Details about QEMU's various subsystems including how to add features to them. clocks ebpf_rss hexagon-sys + hexagon-l2vic migration/index multi-process resetinclude/hw/intc/hex-l2vic.h new file +87
-0@@ -0,0 +1,87 @@ +/* +* QEMU L2VIC Interrupt Controller +* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_INTC_HEX_L2VIC_H +#define HW_INTC_HEX_L2VIC_H + +#include "qom/object.h" + +#define L2VIC_VID_GRP_0 0x0/* Read */ +#define L2VIC_VID_GRP_1 0x4/* Read */ +#define L2VIC_VID_GRP_2 0x8/* Read */ +#define L2VIC_VID_GRP_3 0xC/* Read */ +#define L2VIC_INT_ENABLEn 0x100/* Read/Write */ +#define L2VIC_INT_ENABLE_CLEARn 0x180/* Write */ +#define L2VIC_INT_ENABLE_SETn 0x200/* Write */ +#define L2VIC_INT_TYPEn 0x280/* Read/Write */ +#define L2VIC_INT_STATUSn 0x380/* Read */ +#define L2VIC_INT_CLEARn 0x400/* Write */ +#define L2VIC_SOFT_INTn 0x480/* Write */ +#define L2VIC_INT_PENDINGn 0x500/* Read */ +#define L2VIC_INT_GRPn_0 0x600/* Read/Write */ +#define L2VIC_INT_GRPn_1 0x680/* Read/Write */ +#define L2VIC_INT_GRPn_2 0x700/* Read/Write */ +#define L2VIC_INT_GRPn_3 0x780/* Read/Write */ + +#define L2VIC_INTERRUPT_MAX 1024 +/* +* Note about l2vic groups: +* Each interrupt to L2VIC can be configured to associate with one of +* four groups. +* Group 0 interrupts go to IRQ2 via VID 0 (SSR: 0xC2, the default) +* Group 1 interrupts go to IRQ3 via VID 1 (SSR: 0xC3) +* Group 2 interrupts go to IRQ4 via VID 2 (SSR: 0xC4) +* Group 3 interrupts go to IRQ5 via VID 3 (SSR: 0xC5) +*/ + +#define TYPE_HEX_L2VIC "hex-l2vic" +/* +* L2VIC Interface for CPU/GlobalReg interaction +*/ +#define TYPE_HEX_L2VIC_INTERFACE "hex-l2vic-if" + +typedef struct HexL2VicInterface HexL2VicInterface ; + +typedef struct HexL2VicInterfaceClass { +InterfaceClass parent_class; + +/* Read VID register for given group */ +uint32_t (*read_vid)(HexL2VicInterface *l2vic,uint32_t group); + +/* Update VID register value */ +void (*update_vid)(HexL2VicInterface *l2vic,uint32_t group, +uint32_t value); + +/* Clear interrupt using CIAD instruction */ +void (*clear_interrupt)(HexL2VicInterface *l2vic); +}HexL2VicInterfaceClass ; + +DECLARE_OBJ_CHECKERS (HexL2VicInterface, HexL2VicInterfaceClass, +HEX_L2VIC_INTERFACE ,TYPE_HEX_L2VIC_INTERFACE ); + +/* Convenience functions for interface users */ +static inline uint32_t l2vic_read_vid (HexL2VicInterface *l2vic, +uint32_t group) +{ +HexL2VicInterfaceClass *k =HEX_L2VIC_INTERFACE_GET_CLASS (l2vic); +return k->read_vid (l2vic, group); +} + +static inline void l2vic_update_vid (HexL2VicInterface *l2vic,uint32_t group, +uint32_t value) +{ +HexL2VicInterfaceClass *k =HEX_L2VIC_INTERFACE_GET_CLASS (l2vic); + k->update_vid (l2vic, group, value); +} + +static inline void l2vic_clear_interrupt (HexL2VicInterface *l2vic) +{ +HexL2VicInterfaceClass *k =HEX_L2VIC_INTERFACE_GET_CLASS (l2vic); + k->clear_interrupt (l2vic); +} + +#endif /* HW_INTC_HEX_L2VIC_H */ target/hexagon/cpu.h +2
-0@@ -39,6 +39,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState;#include "qemu/bitmap.h" #include "target/hexagon/reg_fields.h" +#include "hw/intc/hex-l2vic.h" #define NUM_PREGS 4#define TOTAL_PER_THREAD_REGS 64@@ -198,6 +199,7 @@ struct ArchCPU {uint32_t boot_addr;HexagonGlobalRegState *globalregs;uint32_t htid; +HexL2VicInterface *l2vic;#endif };hw/intc/hex-l2vic.c new file +40
-0@@ -0,0 +1,532 @@ +/* +* QEMU L2VIC Interrupt Controller +* +* Arm PrimeCell PL190 Vector Interrupt Controller was used as a reference. +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "hw/core/irq.h" +#include "hw/core/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/lockable.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bitmap.h" +#include "qemu/bitops.h" +#include "hw/intc/hex-l2vic.h" +#include "trace.h" + +static void bitmap32_write_word (uint32_t *bitmap,int word_offset,uint32_t val) +{ + bitmap[word_offset] = val; +} + +static void bitmap32_clear_word (uint32_t *bitmap,int word_offset, +uint32_t mask) +{ + bitmap[word_offset] &= ~mask; +} + +static void bitmap32_set_word (uint32_t *bitmap,int word_offset,uint32_t mask) +{ + bitmap[word_offset] |= mask; +} + +static uint32_t bitmap32_read_word (uint32_t *bitmap,int word_offset) +{ +return bitmap[word_offset]; +}
hw/intc/hex-l2vic.c line 50
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ +OBJECT_DECLARE_SIMPLE_TYPE(HexL2VICState, HEX_L2VIC) + +#define SLICE_MAX (L2VIC_INTERRUPT_MAX / 32) +#define L2VIC_REG_RANGE_SIZE 0x80 + +typedef struct HexL2VICState { + SysBusDevice parent_obj; + + QemuMutex active;
Can you describe what is protected by this mutex?
hw/intc/hex-l2vic.c line 60
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+MemoryRegion iomem; +MemoryRegion fast_iomem; +/* +* offset 0:vid group 0 etc, 10 bits in each group +* are used: +*/ +uint32_t vid_group[4 ]; +uint32_t vid0; +/* Enable interrupt source */ + DECLARE_BITMAP32(int_enable, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16);
This bitmap alignment here is dubious. I suppose it relates to my other comment on find_first_bit32(). If the callee requires alignment, then the QEMU_ALIGNED() attribute should be used at the definition IMO, not here. Peter, WDYT?
hw/intc/hex-l2vic.c line 64
Quoted 4 lines
hw/intc/hex-l2vic.c new file +4
-0+/* Present for debugging, not used */ + DECLARE_BITMAP32(int_pending, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); +/* Which enabled interrupt is active */ + DECLARE_BITMAP32(int_status, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16);
Apparently int_status is mutex-protected.
Quoted 142 lines
hw/intc/hex-l2vic.c new file +142
-0+/* Edge or Level interrupt */ + DECLARE_BITMAP32(int_type, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); +/* L2 interrupt group 0-3 0x600-0x7FF */ + DECLARE_BITMAP32(int_group_n0, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); + DECLARE_BITMAP32(int_group_n1, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); + DECLARE_BITMAP32(int_group_n2, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); + DECLARE_BITMAP32(int_group_n3, L2VIC_INTERRUPT_MAX) QEMU_ALIGNED(16); +qemu_irq irq[8 ]; +} HexL2VICState; + +typedef enum { +L2VIC_OP_WRITE , +L2VIC_OP_CLEAR , +L2VIC_OP_SET , +}L2VicWriteOp ; + +typedef struct { +hwaddr base; +size_t state_offset; +L2VicWriteOp write_op; +bool write_only; +}L2VicRegRange ; + +static const L2VicRegRange l2vic_reg_ranges[] = { + { L2VIC_INT_ENABLEn, offsetof(HexL2VICState , int_enable), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_ENABLE_CLEARn, offsetof(HexL2VICState , int_enable), +L2VIC_OP_CLEAR , true }, + { L2VIC_INT_ENABLE_SETn, offsetof(HexL2VICState , int_enable), +L2VIC_OP_SET , true }, + { L2VIC_INT_TYPEn, offsetof(HexL2VICState , int_type), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_STATUSn, offsetof(HexL2VICState , int_status), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_CLEARn, offsetof(HexL2VICState , int_status), +L2VIC_OP_CLEAR , true }, + { L2VIC_SOFT_INTn, offsetof(HexL2VICState , int_enable), +L2VIC_OP_SET , true }, + { L2VIC_INT_PENDINGn, offsetof(HexL2VICState , int_pending), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_GRPn_0, offsetof(HexL2VICState , int_group_n0), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_GRPn_1, offsetof(HexL2VICState , int_group_n1), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_GRPn_2, offsetof(HexL2VICState , int_group_n2), +L2VIC_OP_WRITE , false }, + { L2VIC_INT_GRPn_3, offsetof(HexL2VICState , int_group_n3), +L2VIC_OP_WRITE , false }, +}; + +static uint32_t *l2vic_state_bitmap (HexL2VICState *s,size_t state_offset) +{ +return (uint32_t *)((char *)s + state_offset); +} + +static bool l2vic_reg_read_range (HexL2VICState *s,hwaddr offset, +uint64_t *value) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (l2vic_reg_ranges); i++) { +const L2VicRegRange *r = &l2vic_reg_ranges[i]; + +if (offset >= r->base && + offset < r->base +L2VIC_REG_RANGE_SIZE ) { +if (r->write_only) { + *value =0 ; + }else { +uint32_t *bitmap =l2vic_state_bitmap (s, r->state_offset); + *value =bitmap32_read_word (bitmap, + (offset - r->base) >>2 ); + } +return true; + } + } +return false; +} + +static bool l2vic_reg_write_range (HexL2VICState *s,hwaddr offset, +uint32_t val) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (l2vic_reg_ranges); i++) { +const L2VicRegRange *r = &l2vic_reg_ranges[i]; + +if (offset >= r->base && + offset < r->base +L2VIC_REG_RANGE_SIZE ) { +uint32_t *bitmap =l2vic_state_bitmap (s, r->state_offset); +int word = (offset - r->base) >>2 ; + +switch (r->write_op) { +case L2VIC_OP_WRITE : +bitmap32_write_word (bitmap, word, val); +break ; +case L2VIC_OP_CLEAR : +bitmap32_clear_word (bitmap, word, val); +break ; +case L2VIC_OP_SET : +bitmap32_set_word (bitmap, word, val); +break ; +default : +g_assert_not_reached (); + } +return true; + } + } +return false; +} + +/* +* Find out if this irq is associated with a group other than +* the default group +*/ +static uint32_t *get_int_group (HexL2VICState *s,int irq) +{ +int n = irq &0x1f ; +if (n <8 ) { +return s->int_group_n0; + } +if (n <16 ) { +return s->int_group_n1; + } +if (n <24 ) { +return s->int_group_n2; + } +return s->int_group_n3; +} + +static int find_slice (int irq) +{ +return irq /32 ; +} + +static int get_vid (HexL2VICState *s,int irq) +{ +uint32_t *group =get_int_group (s, irq); +uint32_t slice = group[find_slice (irq)]; +/* Mask with 0x7 to remove the GRP:EN bit */ +uint32_t val = slice >> ((irq &0x7 ) *4 ); +if (val &0x8 ) { +return val &0x7 ;
hw/intc/hex-l2vic.c line 216
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ }else { +return 0 ; + } +} + +static inline bool vid_active (HexL2VICState *s) +{ +/* scan all 1024 bits in int_status array */ +const uint32_t size =L2VIC_INTERRUPT_MAX ; +const uint32_t active_irq =find_first_bit32 (s->int_status, size);
Is int_status protected here?
Quoted 7 lines
hw/intc/hex-l2vic.c new file +7
-0+return active_irq != size; +} + +static bool l2vic_update (HexL2VICState *s,int irq) +{ +bool pending; +bool enable;
hw/intc/hex-l2vic.c line 233
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ +if (vid_active (s)) { +return true; + } + + pending =test_bit32 (irq, s->int_pending); + enable =test_bit32 (irq, s->int_enable); +if (pending && enable) { +int vid =get_vid (s, irq); +set_bit32 (irq, s->int_status);
Is int_status protected here? Do we want to use the set_bit32_atomic() alternative?
Quoted 25 lines
hw/intc/hex-l2vic.c new file +25
-0+clear_bit32 (irq, s->int_pending); +/* +* Only auto-disable for edge-triggered interrupts (type=1). +* Level-triggered interrupts (type=0, the default) keep their +* enable bit set across deliveries -- the firmware enables once +* and expects the interrupt to remain enabled. +*/ +if (test_bit32 (irq, s->int_type)) { +clear_bit32 (irq, s->int_enable); + } + s->vid0 = irq; + s->vid_group[vid] = irq; + +qemu_irq_pulse (s->irq[vid +2 ]); +trace_hex_l2vic_delivered (irq, vid); +return true; + } +return false; +} + +static void l2vic_update_all (HexL2VICState *s) +{ +for (int i =0 ; i <L2VIC_INTERRUPT_MAX ; i++) { +if (l2vic_update (s, i)) { +/* once vid is active, no-one else can set it until ciad */
hw/intc/hex-l2vic.c line 268
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+return ; + } + } +} + +static void l2vic_set_irq (void *opaque,int irq,int level) +{ +HexL2VICState *s = (HexL2VICState *)opaque; + +QEMU_LOCK_GUARD (&s->active);
Ah, here you protect int_pending, described as "Present for debugging, not used".
hw/intc/hex-l2vic.c line 280
Quoted 12 lines
hw/intc/hex-l2vic.c new file +12
-0+if (level) { +set_bit32 (irq, s->int_pending); + } +l2vic_update (s, irq); +} + +static void l2vic_write (void *opaque,hwaddr offset,uint64_t val, +unsigned size) +{ +HexL2VICState *s = (HexL2VICState *)opaque; + +QEMU_LOCK_GUARD (&s->active);
Here you protect the whole device via MMIO access.
Quoted 18 lines
hw/intc/hex-l2vic.c new file +18
-0+trace_hex_l2vic_reg_write ((unsigned )offset, (uint32_t )val); + +if (!l2vic_reg_write_range (s, offset, val)) { +qemu_log_mask (LOG_UNIMP , +"%s: offset 0x%" HWADDR_PRIx" unimplemented\n" , + __func__, offset); + } + +/* SOFT_INT also sets pending for edge-triggered interrupts */ +if (offset >= L2VIC_SOFT_INTn && + offset < L2VIC_SOFT_INTn +L2VIC_REG_RANGE_SIZE && val) { +int irq =ctz32 ((uint32_t )val); + irq += ((offset - L2VIC_SOFT_INTn) >>2 ) *32 ; + +if (test_bit32 (irq, s->int_type)) { +set_bit32 (irq, s->int_pending); + } + }
hw/intc/hex-l2vic.c line 308
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ +l2vic_update_all (s); +} + +static uint64_t l2vic_read (void *opaque,hwaddr offset,unsigned size) +{ +uint64_t value; +HexL2VICState *s = (HexL2VICState *)opaque; + +QEMU_LOCK_GUARD (&s->active);
Yet another whole device via MMIO access guard. What are the other uses you want to protect?
Quoted 59 lines
hw/intc/hex-l2vic.c new file +59
-0+ +if (offset <=L2VIC_VID_GRP_3 ) { + value = s->vid_group[offset >>2 ]; + }else if (!l2vic_reg_read_range (s, offset, &value)) { + value =0 ; +qemu_log_mask (LOG_GUEST_ERROR , +"L2VIC: %s: offset 0x%" HWADDR_PRIx"\n" , __func__, + offset); + } + +trace_hex_l2vic_reg_read ((unsigned )offset, (uint32_t )value); +return value; +} + +static const MemoryRegionOps l2vic_ops = { + .read = l2vic_read, + .write = l2vic_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid.min_access_size =4 , + .valid.max_access_size =4 , + .valid.unaligned = false, +}; + +#define FASTL2VIC_ENABLE 0x0 +#define FASTL2VIC_DISABLE 0x1 +#define FASTL2VIC_INT 0x2 + +static void fastl2vic_write (void *opaque,hwaddr offset,uint64_t val, +unsigned size) +{ +if (offset ==0 ) { +uint32_t cmd = (val >>16 ) &0x3 ; +uint32_t irq = val &0x3ff ; +uint32_t slice = (irq /32 ) *4 ; + val =1 << (irq %32 ); + +if (cmd ==FASTL2VIC_ENABLE ) { +l2vic_write (opaque, L2VIC_INT_ENABLE_SETn + slice, val, size); + }else if (cmd ==FASTL2VIC_DISABLE ) { +l2vic_write (opaque, L2VIC_INT_ENABLE_CLEARn + slice, val, size); + }else if (cmd ==FASTL2VIC_INT ) { +l2vic_write (opaque, L2VIC_SOFT_INTn + slice, val, size); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: invalid write cmd %" PRId32"\n" , + __func__, cmd); + } +return ; + } +qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid write offset 0x%08" HWADDR_PRIx +"\n" , __func__, offset); +} + +static const MemoryRegionOps fastl2vic_ops = { + .write = fastl2vic_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid.min_access_size =4 , + .valid.max_access_size =4 , + .valid.unaligned = false,
hw/intc/hex-l2vic.c line 377
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+}; + +/* L2VIC Interface Implementation */ +static uint32_t l2vic_interface_read_vid_impl (HexL2VicInterface *iface, +uint32_t group) +{ +HexL2VICState *s =HEX_L2VIC (iface); +uint32_t result =0 ; + +QEMU_LOCK_GUARD (&s->active);
Ah, another whole device via MMIO access guard.
Quoted 27 lines
hw/intc/hex-l2vic.c new file +27
-0+if (group ==0 ) { +/* VID register: VID1 (bits 16-31), VID0 (bits 0-15) */ + result =deposit32 (result,0 ,16 , s->vid_group[0 ]); + result =deposit32 (result,16 ,16 , s->vid_group[1 ]); + }else if (group ==1 ) { +/* VID1 register: VID3 (bits 16-31), VID2 (bits 0-15) */ + result =deposit32 (result,0 ,16 , s->vid_group[2 ]); + result =deposit32 (result,16 ,16 , s->vid_group[3 ]); + } +return result; +} + +static void l2vic_interface_update_vid_impl (HexL2VicInterface *iface, +uint32_t group,uint32_t value) +{ +HexL2VICState *s =HEX_L2VIC (iface); + +QEMU_LOCK_GUARD (&s->active); + +if (group ==0 ) { +/* VID register: unpack VID0 and VID1 */ + s->vid_group[0 ] =extract32 (value,0 ,16 ); + s->vid_group[1 ] =extract32 (value,16 ,16 ); + }else if (group ==1 ) { +/* VID1 register: unpack VID2 and VID3 */ + s->vid_group[2 ] =extract32 (value,0 ,16 ); + s->vid_group[3 ] =extract32 (value,16 ,16 );
hw/intc/hex-l2vic.c line 414
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ } + +l2vic_update_all (s); +} + +static void l2vic_interface_clear_interrupt_impl (HexL2VicInterface *iface) +{ +HexL2VICState *s =HEX_L2VIC (iface); + +QEMU_LOCK_GUARD (&s->active);
OK, this is apparently a non-MMIO call via the HexL2VicInterfaceClass. Is that why we need this mutex? So far I can not see any consumer of this interface in this series.
Quoted 108 lines
hw/intc/hex-l2vic.c new file +108
-0+if (s->vid0 <L2VIC_INTERRUPT_MAX ) { +clear_bit32 (s->vid0, s->int_status); + } +l2vic_update_all (s); +} + +static void l2vic_reset_hold(Object *obj, ResetType type G_GNUC_UNUSED) +{ +HexL2VICState *s =HEX_L2VIC (obj); + +QEMU_LOCK_GUARD (&s->active); +memset (s->int_enable,0 ,sizeof (s->int_enable)); +memset (s->int_pending,0 ,sizeof (s->int_pending)); +memset (s->int_status,0 ,sizeof (s->int_status)); +memset (s->int_type,0 ,sizeof (s->int_type)); +memset (s->int_group_n0,0 ,sizeof (s->int_group_n0)); +memset (s->int_group_n1,0 ,sizeof (s->int_group_n1)); +memset (s->int_group_n2,0 ,sizeof (s->int_group_n2)); +memset (s->int_group_n3,0 ,sizeof (s->int_group_n3)); +memset (s->vid_group,0 ,sizeof (s->vid_group)); + s->vid0 =0 ; + +l2vic_update_all (s); +} + +static void reset_irq_handler (void *opaque,int irq,int level) +{ +Object *obj =OBJECT (opaque); + +if (level) { +l2vic_reset_hold (obj,RESET_TYPE_COLD ); + } +} + +static void l2vic_init (Object *obj) +{ +DeviceState *dev =DEVICE (obj); +HexL2VICState *s =HEX_L2VIC (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); +int i; + +memory_region_init_io (&s->iomem, obj, &l2vic_ops, s,"l2vic" ,0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +memory_region_init_io (&s->fast_iomem, obj, &fastl2vic_ops, s,"fast" , +0x10000 ); +sysbus_init_mmio (sbd, &s->fast_iomem); + +qdev_init_gpio_in (dev, l2vic_set_irq,L2VIC_INTERRUPT_MAX ); +qdev_init_gpio_in_named (dev, reset_irq_handler,"reset" ,1 ); +for (i =0 ; i <8 ; i++) { +sysbus_init_irq (sbd, &s->irq[i]); + } +qemu_mutex_init (&s->active); +} + +static const VMStateDescription vmstate_l2vic = { + .name ="l2vic" , + .version_id =1 , + .minimum_version_id =1 , + .fields = + (VMStateField []){ +VMSTATE_UINT32_ARRAY (vid_group, HexL2VICState,4 ), +VMSTATE_UINT32 (vid0, HexL2VICState), +VMSTATE_UINT32_ARRAY (int_enable, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_type, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_status, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_pending, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_group_n0, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_group_n1, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_group_n2, HexL2VICState,SLICE_MAX ), +VMSTATE_UINT32_ARRAY (int_group_n3, HexL2VICState,SLICE_MAX ), +VMSTATE_END_OF_LIST () } +}; + +static void l2vic_interface_class_init (ObjectClass *klass,const void *data) +{ +HexL2VicInterfaceClass *k =HEX_L2VIC_INTERFACE_CLASS (klass); + + k->read_vid = l2vic_interface_read_vid_impl; + k->update_vid = l2vic_interface_update_vid_impl; + k->clear_interrupt = l2vic_interface_clear_interrupt_impl; +} + +static void l2vic_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); + + dc->vmsd = &vmstate_l2vic; + rc->phases.hold = l2vic_reset_hold; +} + +static const TypeInfo l2vic_interface_info = { + .name =TYPE_HEX_L2VIC_INTERFACE , + .parent =TYPE_INTERFACE , + .class_size =sizeof (HexL2VicInterfaceClass), + .class_init = l2vic_interface_class_init, +}; + +static const TypeInfo l2vic_info = { + .name =TYPE_HEX_L2VIC , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (HexL2VICState), + .instance_init = l2vic_init, + .class_init = l2vic_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_HEX_L2VIC_INTERFACE }, + { }
hw/intc/hex-l2vic.c line 532
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ }, +}; + +static void l2vic_register_types (void ) +{ +type_register_static (&l2vic_interface_info); +type_register_static (&l2vic_info); +} + +type_init (l2vic_register_types)
Prefer DEFINE_TYPES() for multiple TypeInfo.
Re: [PATCH v2 4/7] hw/intc: Add l2vic interrupt controller
Quoted 334 lines · Philippe Mathieu-Daudé
Hi Brian,
+Peter for commit
3d7680fb18c("bitops.h: Define bit operations on 'uint32_t' arrays").Quoted 304 lines · Brian Cain
From: Sid Manning <[email protected]>
The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. This device model implements the register interface, interrupt steering, and edge/level type handling needed by the sysemu machine models.
Co-authored-by Matheus Tavares Bernardino <[email protected]>Co-authored-by Damien Hedde <[email protected]>Signed-off-by Brian Cain <[email protected]>---
MAINTAINERS | 3 + docs/devel/hexagon-l2vic.rst | 55 ++++docs/devel/index-internals.rst| 1 + include/hw/intc/hex-l2vic.h | 87 ++++++ target/hexagon/cpu.h | 2 +
hw/intc/hex-l2vic.c | 532 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/op_helper.c | 21 +-
hw/hexagon/Kconfig | 1 +
hw/intc/Kconfig | 3 +
hw/intc/meson.build | 2 + hw/intc/trace-events | 4 +12 files changed, 712 insertions(+), 1 deletion(-)create mode 100644
docs/devel/hexagon-l2vic.rst
create mode 100644include/hw/intc/hex-l2vic.h
create mode 100644hw/intc/hex-l2vic.cMAINTAINERS +0
-0@@ -250,6 +250,8 @@ M: Brian Cain <[email protected]>R: Pierrick Bouvier <[email protected]>
S: Supported
F: target/hexagon/MAINTAINERS +2
-0+F: hw/intc/hex-l2vic.c +F: include/hw/intc/hex-l2vic.hX: target/hexagon/idef-parser/
X:target/hexagon/gen_idef_parser_funcs.py
F: linux-user/hexagon/MAINTAINERS +0
-0@@ -262,6 +264,7 @@ F: gdbstub/gdb-xml/hexagon*.xmlF:
docs/system/target-hexagon.rst
F: docs/system/hexagon/
F:docs/devel/hexagon-sys.rst
+F:docs/devel/hexagon-l2vic.rst
T: git https://github.com/qualcomm/qemu.git hex-next Hexagon idef-parserdocs/devel/hexagon-l2vic.rst new file +10
-0@@ -0,0 +1,55 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Hexagon L2 Vectored Interrupt Controller +======================================== + + +.. code-block:: none + + +-------------+ +----------------------+ + | l2vic | | hexagoncore |
+ | | | |
+ IRQ in ---->| | | |
+ IRQ in ---->| VID0 -|----------------->|
irq2 |
+ ... ---->| | | | | + IRQ in ---->| | | v | + | ... | | <int steering> |
+ | | | / | | \ | + IRQ in ---->| | | t0 t1 t2 t3 ...| + IRQ in ---->| VIDN -| | |
+ ... ---->| | | |
+ IRQ in ---->| | | Global SREG File |+ | | | | + | State | | | + | [ ] <--|==================|==> [ VID] |
+ | [ ] <--|==================|==> [ VID1 ] |
+ | | | | + +-------------+ +----------------------+docs/devel/hexagon-l2vic.rst new file +8
-0+ +L2VIC/Core Integration +---------------------- + +* hexagon core supports 8 external interrupt sources +* l2vic supports 1024 input interrupts mapped among 4 output interrupts +* l2vic has four output signals: { VID0, VID1, VID2, VID3 } +* l2vic device has a bank of registers per-VID that can be used toquery
+ the status or assert new interrupts.
+* Interrupts are 'steered' to threads based on { thread priority, 'EX' state,
+ thread interrupt mask, thread interrupt enable, global interrupt enable,
+ etc. }.
+* Any hardware thread could conceivably handle any input interrupt, dependent
+ on state.
+* The system register transfer instruction can read the VID0-VID3 values from
+ the l2vic when reading from hexagon core system registers "VID" and "VID1".
+* When l2vic VID0 has multiple active interrupts, it pulses the VID0 output
+ IRQ and stores the IRQ number for the VID0 register field. Only after this
+ interrupt is cleared can the l2vic pulse the VID0 output IRQ again and provide
+ the next interrupt number on the VID0 register.
+* The ``ciad`` instruction clears the l2vic input interrupt and un-disables the
+ core interrupt. If some/an l2vic VID0 interrupt is pending when this occurs,
+ the next interrupt should fire and any subsequent reads of the VID register
+ should reflect the newly raised interrupt.
+* In QEMU, on an external interrupt or an unmasked-pending interrupt, + all vCPUs are triggered (has_work==true) and each will grab the IO lock
+ while considering the steering logic to determine whether they're the thread
+ that must handle the interrupt.docs/devel/index-internals.rst +0
-0@@ -15,6 +15,7 @@ Details about QEMU's various subsystems includinghow to add features to them.
clocks
ebpf_rss
hexagon-sys
+ hexagon-l2vic
migration/index
multi-process
resetinclude/hw/intc/hex-l2vic.h new file +74
-0@@ -0,0 +1,87 @@ +/* +* QEMU L2VIC Interrupt Controller +* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_INTC_HEX_L2VIC_H +#define HW_INTC_HEX_L2VIC_H + +#include "qom/object.h" + +#define L2VIC_VID_GRP_0 0x0/* Read */ +#define L2VIC_VID_GRP_1 0x4/* Read */ +#define L2VIC_VID_GRP_2 0x8/* Read */ +#define L2VIC_VID_GRP_3 0xC/* Read */ +#define L2VIC_INT_ENABLEn 0x100/* Read/Write */ +#define L2VIC_INT_ENABLE_CLEARn 0x180/* Write */ +#define L2VIC_INT_ENABLE_SETn 0x200/* Write */ +#define L2VIC_INT_TYPEn 0x280/* Read/Write */ +#define L2VIC_INT_STATUSn 0x380/* Read */ +#define L2VIC_INT_CLEARn 0x400/* Write */ +#define L2VIC_SOFT_INTn 0x480/* Write */ +#define L2VIC_INT_PENDINGn 0x500/* Read */ +#define L2VIC_INT_GRPn_0 0x600/* Read/Write */ +#define L2VIC_INT_GRPn_1 0x680/* Read/Write */ +#define L2VIC_INT_GRPn_2 0x700/* Read/Write */ +#define L2VIC_INT_GRPn_3 0x780/* Read/Write */ + +#define L2VIC_INTERRUPT_MAX 1024 +/* +* Note about l2vic groups: +* Each interrupt to L2VIC can be configured to associate with one of +* four groups. +* Group 0 interrupts go to IRQ2 via VID 0 (SSR: 0xC2, the default) +* Group 1 interrupts go to IRQ3 via VID 1 (SSR: 0xC3) +* Group 2 interrupts go to IRQ4 via VID 2 (SSR: 0xC4) +* Group 3 interrupts go to IRQ5 via VID 3 (SSR: 0xC5) +*/ + +#define TYPE_HEX_L2VIC "hex-l2vic" +/* +* L2VIC Interface for CPU/GlobalReg interaction +*/ +#define TYPE_HEX_L2VIC_INTERFACE "hex-l2vic-if" + +typedef struct HexL2VicInterface HexL2VicInterface ; + +typedef struct HexL2VicInterfaceClass { + InterfaceClass parent_class; + + /* Read VID register for given group */ + uint32_t (*read_vid)(HexL2VicInterface *l2vic, uint32_t group); + + /* Update VID register value */ + void (*update_vid)(HexL2VicInterface *l2vic, uint32_t group, + uint32_t value); + + /* Clear interrupt using CIAD instruction */ + void (*clear_interrupt)(HexL2VicInterface *l2vic); +}HexL2VicInterfaceClass ; + +DECLARE_OBJ_CHECKERS (HexL2VicInterface, HexL2VicInterfaceClass, + HEX_L2VIC_INTERFACE, TYPE_HEX_L2VIC_INTERFACE); + +/* Convenience functions for interface users */ +static inline uint32_t l2vic_read_vid (HexL2VicInterface *l2vic, + uint32_t group) +{ + HexL2VicInterfaceClass *k = HEX_L2VIC_INTERFACE_GET_CLASS(l2vic); + return k->read_vid(l2vic, group); +} + +static inline void l2vic_update_vid(HexL2VicInterface *l2vic,
uint32_tgroup,
+uint32_tvalue)include/hw/intc/hex-l2vic.h new file +12
-0+{ + HexL2VicInterfaceClass *k = HEX_L2VIC_INTERFACE_GET_CLASS(l2vic); + k->update_vid(l2vic, group, value); +} + +static inline void l2vic_clear_interrupt (HexL2VicInterface *l2vic) +{ + HexL2VicInterfaceClass *k = HEX_L2VIC_INTERFACE_GET_CLASS(l2vic); + k->clear_interrupt(l2vic); +} + +#endif /* HW_INTC_HEX_L2VIC_H */ target/hexagon/cpu.h +2
-0@@ -39,6 +39,7 @@ typedef struct HexagonGlobalRegState HexagonGlobalRegState; #include "qemu/bitmap.h" #include "target/hexagon/reg_fields.h" +#include "hw/intc/hex-l2vic.h" #define NUM_PREGS 4 #define TOTAL_PER_THREAD_REGS 64@@ -198,6 +199,7 @@ struct ArchCPU { uint32_t boot_addr; HexagonGlobalRegState *globalregs; uint32_t htid; + HexL2VicInterface *l2vic; #endif };diff --git
a/hw/intc/hex-l2vic.cb/hw/intc/hex-l2vic.cnew file mode 100644
index 00000000000..6b2dc6bb091hw/intc/hex-l2vic.c new file +4
-0@@ -0,0 +1,532 @@ +/* +* QEMU L2VIC Interrupt Controller +* +* Arm PrimeCell PL190 Vector Interrupt Controller was used as a reference.
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */hw/intc/hex-l2vic.c new file +14
-0+ +#include "qemu/osdep.h" +#include "hw/core/irq.h" +#include "hw/core/sysbus.h" +#include "migration/vmstate.h" +#include "qemu/lockable.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bitmap.h" +#include "qemu/bitops.h" +#include "hw/intc/hex-l2vic.h" +#include "trace.h" + +static void bitmap32_write_word(uint32_t *bitmap, int word_offset,
uint32_tval)hw/intc/hex-l2vic.c new file +11
-0+{ + bitmap[word_offset] = val; +} + +static void bitmap32_clear_word (uint32_t *bitmap,int word_offset, + uint32_t mask) +{ + bitmap[word_offset] &= ~mask; +} + +static void bitmap32_set_word(uint32_t *bitmap, int word_offset,
uint32_tmask)hw/intc/hex-l2vic.c new file +8
-0+{ + bitmap[word_offset] |= mask; +} + +static uint32_t bitmap32_read_word (uint32_t *bitmap,int word_offset) +{ + return bitmap[word_offset]; +}hw/intc/hex-l2vic.c line 50
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ +OBJECT_DECLARE_SIMPLE_TYPE(HexL2VICState, HEX_L2VIC) + +#define SLICE_MAX (L2VIC_INTERRUPT_MAX / 32) +#define L2VIC_REG_RANGE_SIZE 0x80 + +typedef struct HexL2VICState { + SysBusDevice parent_obj; + + QemuMutex active;Can you describe what is protected by this mutex?
Quoted 10 lines
+ MemoryRegion iomem;
+ MemoryRegionfast_iomem;
+ /*
+ * offset 0:vid group 0 etc, 10 bits in each group
+ * are used:
+ */
+uint32_tvid_group[4];
+uint32_tvid0;
+ /* Enable interrupt source */
+DECLARE_BITMAP32(int_enable, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
Quoted 4 lines
This bitmap alignment here is dubious. I suppose it relates to my other comment on
find_first_bit32(). If the callee requires alignment, then theQEMU_ALIGNED()attribute should be used at the definition IMO, not here. Peter, WDYT?
You are correct: QEMU_ALIGNED does not belong here. In prior reviews, it was suggested that we use bitmaps and other QEMU idioms. And in making that change we no longer require the alignment because we no longer do direct pointer derefs within these.
I will drop the alignment.
Quoted 389 lines
Quoted 6 lines
+ /* Present for debugging, not used */
+DECLARE_BITMAP32(int_pending, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
+ /* Which enabled interrupt is active */
+DECLARE_BITMAP32(int_status, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);Apparently
int_statusis mutex-protected.Quoted 148 lines
+ /* Edge or Level interrupt */
+DECLARE_BITMAP32(int_type, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16); + /* L2 interrupt group 0-3 0x600-0x7FF */
+DECLARE_BITMAP32(int_group_n0, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
+DECLARE_BITMAP32(int_group_n1, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
+DECLARE_BITMAP32(int_group_n2, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
+DECLARE_BITMAP32(int_group_n3, L2VIC_INTERRUPT_MAX)QEMU_ALIGNED(16);
+qemu_irqirq[8];hw/intc/hex-l2vic.c new file +43
-0+} HexL2VICState; + +typedef enum { + L2VIC_OP_WRITE, + L2VIC_OP_CLEAR, + L2VIC_OP_SET, +}L2VicWriteOp ; + +typedef struct { + hwaddr base; + size_t state_offset; + L2VicWriteOp write_op; + bool write_only; +}L2VicRegRange ; + +static const L2VicRegRange l2vic_reg_ranges[] = { + { L2VIC_INT_ENABLEn, offsetof(HexL2VICState, int_enable), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_ENABLE_CLEARn, offsetof(HexL2VICState, int_enable), + L2VIC_OP_CLEAR, true }, + { L2VIC_INT_ENABLE_SETn, offsetof(HexL2VICState, int_enable), + L2VIC_OP_SET, true }, + { L2VIC_INT_TYPEn, offsetof(HexL2VICState, int_type), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_STATUSn, offsetof(HexL2VICState, int_status), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_CLEARn, offsetof(HexL2VICState, int_status), + L2VIC_OP_CLEAR, true }, + { L2VIC_SOFT_INTn, offsetof(HexL2VICState, int_enable), + L2VIC_OP_SET, true }, + { L2VIC_INT_PENDINGn, offsetof(HexL2VICState, int_pending), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_GRPn_0, offsetof(HexL2VICState, int_group_n0), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_GRPn_1, offsetof(HexL2VICState, int_group_n1), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_GRPn_2, offsetof(HexL2VICState, int_group_n2), + L2VIC_OP_WRITE, false }, + { L2VIC_INT_GRPn_3, offsetof(HexL2VICState, int_group_n3), + L2VIC_OP_WRITE, false }, +}; + +static uint32_t *l2vic_state_bitmap(HexL2VICState *s, size_t
state_offset)hw/intc/hex-l2vic.c new file +18
-0+{ + return (uint32_t *)((char *)s + state_offset); +} + +static bool l2vic_reg_read_range (HexL2VICState *s,hwaddr offset, + uint64_t *value) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(l2vic_reg_ranges); i++) { + const L2VicRegRange *r = &l2vic_reg_ranges[i]; + + if (offset >= r->base && + offset < r->base + L2VIC_REG_RANGE_SIZE) { + if (r->write_only) { + *value = 0; + } else { + uint32_t *bitmap = l2vic_state_bitmap(s,
r->state_offset);
+ *value = bitmap32_read_word(bitmap,
+ (offset -r->base) >> 2); + }
+ return true;
+ }
+ }
+ return false;hw/intc/hex-l2vic.c new file +66
-0+} + +static bool l2vic_reg_write_range (HexL2VICState *s,hwaddr offset, + uint32_t val) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(l2vic_reg_ranges); i++) { + const L2VicRegRange *r = &l2vic_reg_ranges[i]; + + if (offset >= r->base && + offset < r->base + L2VIC_REG_RANGE_SIZE) { + uint32_t *bitmap = l2vic_state_bitmap(s, r->state_offset); + int word = (offset - r->base) >> 2; + + switch (r->write_op) { + case L2VIC_OP_WRITE: + bitmap32_write_word(bitmap, word, val); + break; + case L2VIC_OP_CLEAR: + bitmap32_clear_word(bitmap, word, val); + break; + case L2VIC_OP_SET: + bitmap32_set_word(bitmap, word, val); + break; + default: + g_assert_not_reached(); + } + return true; + } + } + return false; +} + +/* +* Find out if this irq is associated with a group other than +* the default group +*/ +static uint32_t *get_int_group (HexL2VICState *s,int irq) +{ + int n = irq & 0x1f; + if (n < 8) { + return s->int_group_n0; + } + if (n < 16) { + return s->int_group_n1; + } + if (n < 24) { + return s->int_group_n2; + } + return s->int_group_n3; +} + +static int find_slice (int irq) +{ + return irq / 32; +} + +static int get_vid (HexL2VICState *s,int irq) +{ + uint32_t *group = get_int_group(s, irq); + uint32_t slice = group[find_slice(irq)]; + /* Mask with 0x7 to remove the GRP:EN bit */ + uint32_t val = slice >> ((irq & 0x7) * 4); + if (val & 0x8) { + return val & 0x7;hw/intc/hex-l2vic.c line 216
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ } else { + return 0; + } +} + +static inline bool vid_active (HexL2VICState *s) +{ + /* scan all 1024 bits in int_status array */ + const uint32_t size = L2VIC_INTERRUPT_MAX; + const uint32_t active_irq = find_first_bit32(s->int_status, size);Is
int_statusprotected here?Quoted 7 lines
+ return
active_irq!= size;hw/intc/hex-l2vic.c new file +6
-0+} + +static bool l2vic_update (HexL2VICState *s,int irq) +{ + bool pending; + bool enable;hw/intc/hex-l2vic.c line 233
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ + if (vid_active(s)) { + return true; + } + + pending = test_bit32(irq, s->int_pending); + enable = test_bit32(irq, s->int_enable); + if (pending && enable) { + int vid = get_vid(s, irq); + set_bit32(irq, s->int_status);Is
int_statusprotected here? Do we want to use theset_bit32_atomic()alternative?Quoted 26 lines
+
clear_bit32(irq, s->int_pending);
+ /*
+ * Only auto-disable for edge-triggered interrupts (type=1). + * Level-triggered interrupts (type=0, the default) keep their + * enable bit set across deliveries -- the firmware enables once
+ * and expects the interrupt to remain enabled.
+ */
+ if (test_bit32(irq, s->int_type)) {
+clear_bit32(irq, s->int_enable);
+ }
+s->vid0= irq;
+ s->vid_group[vid] = irq;hw/intc/hex-l2vic.c new file +13
-0+ + qemu_irq_pulse(s->irq[vid + 2]); + trace_hex_l2vic_delivered(irq, vid); + return true; + } + return false; +} + +static void l2vic_update_all (HexL2VICState *s) +{ + for (int i = 0; i < L2VIC_INTERRUPT_MAX; i++) { + if (l2vic_update(s, i)) { + /* once vid is active, no-one else can set it until ciad */hw/intc/hex-l2vic.c line 268
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ return; + } + } +} + +static void l2vic_set_irq (void *opaque,int irq,int level) +{ + HexL2VICState *s = (HexL2VICState *)opaque; + + QEMU_LOCK_GUARD(&s->active);Ah, here you protect
int_pending, described as "Present for debugging, not used".hw/intc/hex-l2vic.c line 280
Quoted 12 lines
+ if (level) {
+set_bit32(irq, s->int_pending);
+ }
+l2vic_update(s, irq);hw/intc/hex-l2vic.c new file +8
-0+} + +static void l2vic_write (void *opaque,hwaddr offset,uint64_t val, + unsigned size) +{ + HexL2VICState *s = (HexL2VICState *)opaque; + + QEMU_LOCK_GUARD(&s->active);Here you protect the whole device via MMIO access.
Quoted 18 lines
+
trace_hex_l2vic_reg_write((unsigned)offset, (uint32_t)val);hw/intc/hex-l2vic.c new file +17
-0+ + if (!l2vic_reg_write_range(s, offset, val)) { + qemu_log_mask(LOG_UNIMP, + "%s: offset 0x%" HWADDR_PRIx " unimplemented\n", + __func__, offset); + } + + /* SOFT_INT also sets pending for edge-triggered interrupts */ + if (offset >= L2VIC_SOFT_INTn && + offset < L2VIC_SOFT_INTn + L2VIC_REG_RANGE_SIZE && val) { + int irq = ctz32((uint32_t)val); + irq += ((offset - L2VIC_SOFT_INTn) >> 2) * 32; + + if (test_bit32(irq, s->int_type)) { + set_bit32(irq, s->int_pending); + } + }hw/intc/hex-l2vic.c line 308
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+ + l2vic_update_all(s); +} + +static uint64_t l2vic_read (void *opaque,hwaddr offset,unsigned size) +{ + uint64_t value; + HexL2VICState *s = (HexL2VICState *)opaque; + + QEMU_LOCK_GUARD(&s->active);Yet another whole device via MMIO access guard. What are the other uses you want to protect?
Quoted 63 lines
+
+ if (offset <=L2VIC_VID_GRP_3) {
+ value = s->vid_group[offset >> 2];
+ } else if (!l2vic_reg_read_range(s, offset, &value)) { + value = 0;
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "L2VIC: %s: offset 0x%"HWADDR_PRIx"\n",__func__,
+ offset);
+ }hw/intc/hex-l2vic.c new file +29
-0+ + trace_hex_l2vic_reg_read((unsigned)offset, (uint32_t)value); + return value; +} + +static const MemoryRegionOps l2vic_ops = { + .read = l2vic_read, + .write = l2vic_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid.min_access_size = 4, + .valid.max_access_size = 4, + .valid.unaligned = false, +}; + +#define FASTL2VIC_ENABLE 0x0 +#define FASTL2VIC_DISABLE 0x1 +#define FASTL2VIC_INT 0x2 + +static void fastl2vic_write (void *opaque,hwaddr offset,uint64_t val, + unsigned size) +{ + if (offset == 0) { + uint32_t cmd = (val >> 16) & 0x3; + uint32_t irq = val & 0x3ff; + uint32_t slice = (irq / 32) * 4; + val = 1 << (irq % 32); + + if (cmd == FASTL2VIC_ENABLE) { + l2vic_write(opaque, L2VIC_INT_ENABLE_SETn + slice, val,size);
+ } else if (cmd ==FASTL2VIC_DISABLE) {
+l2vic_write(opaque, L2VIC_INT_ENABLE_CLEARn + slice, val, size);
+ } else if (cmd ==FASTL2VIC_INT) {
+l2vic_write(opaque, L2VIC_SOFT_INTn + slice, val, size); + } else {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: invalid write cmd %" PRId32 "\n", +__func__, cmd);
+ }
+ return;
+ }
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid write offset 0x%08"HWADDR_PRIx
+ "\n",__func__, offset);hw/intc/hex-l2vic.c new file +8
-0+} + +static const MemoryRegionOps fastl2vic_ops = { + .write = fastl2vic_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid.min_access_size = 4, + .valid.max_access_size = 4, + .valid.unaligned = false,hw/intc/hex-l2vic.c line 377
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+}; + +/* L2VIC Interface Implementation */ +static uint32_t l2vic_interface_read_vid_impl (HexL2VicInterface *iface, + uint32_t group) +{ + HexL2VICState *s = HEX_L2VIC(iface); + uint32_t result = 0; + + QEMU_LOCK_GUARD(&s->active);Ah, another whole device via MMIO access guard.
Quoted 35 lines
+ if (group == 0) {
+ /* VID register: VID1 (bits 16-31), VID0 (bits 0-15) */ + result =deposit32(result, 0, 16, s->vid_group[0]); + result =deposit32(result, 16, 16, s->vid_group[1]); + } else if (group == 1) {
+ /* VID1 register: VID3 (bits 16-31), VID2 (bits 0-15) */ + result =deposit32(result, 0, 16, s->vid_group[2]); + result =deposit32(result, 16, 16, s->vid_group[3]); + }
+ return result;hw/intc/hex-l2vic.c new file +4
-0+} + +static void l2vic_interface_update_vid_impl (HexL2VicInterface *iface, + uint32_t group, uint32_tvalue)
hw/intc/hex-l2vic.c new file +19
-0+{ + HexL2VICState *s = HEX_L2VIC(iface); + + QEMU_LOCK_GUARD(&s->active); + + if (group == 0) { + /* VID register: unpack VID0 and VID1 */ + s->vid_group[0] = extract32(value, 0, 16); + s->vid_group[1] = extract32(value, 16, 16); + } else if (group == 1) { + /* VID1 register: unpack VID2 and VID3 */ + s->vid_group[2] = extract32(value, 0, 16); + s->vid_group[3] = extract32(value, 16, 16); + } + + l2vic_update_all(s); +} + +static void l2vic_interface_clear_interrupt_impl(HexL2VicInterface*iface)
Quoted 8 lines
hw/intc/hex-l2vic.c line 377
Quoted 4 lines
hw/intc/hex-l2vic.c new file +4
-0+{ + HexL2VICState *s = HEX_L2VIC(iface); + + QEMU_LOCK_GUARD(&s->active);OK, this is apparently a non-MMIO call via the HexL2VicInterfaceClass. Is that why we need this mutex? So far I can not see any consumer of this interface in this series.
I will clarify the use of this mutex.
Quoted 121 lines
Quoted 121 lines
+ if (
s->vid0<L2VIC_INTERRUPT_MAX) {
+clear_bit32(s->vid0, s->int_status);
+ }
+l2vic_update_all(s);hw/intc/hex-l2vic.c new file +38
-0+} + +static void l2vic_reset_hold(Object *obj, ResetType type G_GNUC_UNUSED) +{ + HexL2VICState *s = HEX_L2VIC(obj); + + QEMU_LOCK_GUARD(&s->active); + memset(s->int_enable, 0, sizeof(s->int_enable)); + memset(s->int_pending, 0, sizeof(s->int_pending)); + memset(s->int_status, 0, sizeof(s->int_status)); + memset(s->int_type, 0, sizeof(s->int_type)); + memset(s->int_group_n0, 0, sizeof(s->int_group_n0)); + memset(s->int_group_n1, 0, sizeof(s->int_group_n1)); + memset(s->int_group_n2, 0, sizeof(s->int_group_n2)); + memset(s->int_group_n3, 0, sizeof(s->int_group_n3)); + memset(s->vid_group, 0, sizeof(s->vid_group)); + s->vid0 = 0; + + l2vic_update_all(s); +} + +static void reset_irq_handler (void *opaque,int irq,int level) +{ + Object *obj = OBJECT(opaque); + + if (level) { + l2vic_reset_hold(obj, RESET_TYPE_COLD); + } +} + +static void l2vic_init (Object *obj) +{ + DeviceState *dev = DEVICE(obj); + HexL2VICState *s = HEX_L2VIC(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + int i; + + memory_region_init_io(&s->iomem, obj, &l2vic_ops, s, "l2vic",
0x1000);
+sysbus_init_mmio(sbd, &s->iomem);
+ memory_region_init_io(&s->fast_iomem, obj,&fastl2vic_ops, s, "fast",
+0x10000);
+sysbus_init_mmio(sbd, &s->fast_iomem);hw/intc/hex-l2vic.c new file +21
-0+ + qdev_init_gpio_in(dev, l2vic_set_irq, L2VIC_INTERRUPT_MAX); + qdev_init_gpio_in_named(dev, reset_irq_handler, "reset", 1); + for (i = 0; i < 8; i++) { + sysbus_init_irq(sbd, &s->irq[i]); + } + qemu_mutex_init(&s->active); +} + +static const VMStateDescription vmstate_l2vic = { + .name = "l2vic", + .version_id = 1, + .minimum_version_id = 1, + .fields = + (VMStateField[]){ + VMSTATE_UINT32_ARRAY(vid_group, HexL2VICState, 4), + VMSTATE_UINT32(vid0, HexL2VICState), + VMSTATE_UINT32_ARRAY(int_enable, HexL2VICState, SLICE_MAX), + VMSTATE_UINT32_ARRAY(int_type, HexL2VICState, SLICE_MAX), + VMSTATE_UINT32_ARRAY(int_status, HexL2VICState, SLICE_MAX), + VMSTATE_UINT32_ARRAY(int_pending, HexL2VICState,
SLICE_MAX),
+VMSTATE_UINT32_ARRAY(int_group_n0, HexL2VICState, SLICE_MAX),
+VMSTATE_UINT32_ARRAY(int_group_n1, HexL2VICState, SLICE_MAX),
+VMSTATE_UINT32_ARRAY(int_group_n2, HexL2VICState, SLICE_MAX),
+VMSTATE_UINT32_ARRAY(int_group_n3, HexL2VICState, SLICE_MAX),
+VMSTATE_END_OF_LIST()}hw/intc/hex-l2vic.c new file +3
-0+}; + +static void l2vic_interface_class_init(ObjectClass *klass, constvoid *data)
hw/intc/hex-l2vic.c new file +37
-0+{ + HexL2VicInterfaceClass *k = HEX_L2VIC_INTERFACE_CLASS(klass); + + k->read_vid = l2vic_interface_read_vid_impl; + k->update_vid = l2vic_interface_update_vid_impl; + k->clear_interrupt = l2vic_interface_clear_interrupt_impl; +} + +static void l2vic_class_init (ObjectClass *klass,const void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); + + dc->vmsd = &vmstate_l2vic; + rc->phases.hold = l2vic_reset_hold; +} + +static const TypeInfo l2vic_interface_info = { + .name = TYPE_HEX_L2VIC_INTERFACE, + .parent = TYPE_INTERFACE, + .class_size = sizeof(HexL2VicInterfaceClass), + .class_init = l2vic_interface_class_init, +}; + +static const TypeInfo l2vic_info = { + .name = TYPE_HEX_L2VIC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(HexL2VICState), + .instance_init = l2vic_init, + .class_init = l2vic_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_HEX_L2VIC_INTERFACE }, + { } + }, +}; + +static void l2vic_register_types (void )
Quoted 8 lines
hw/intc/hex-l2vic.c line 532
Quoted 6 lines
hw/intc/hex-l2vic.c new file +6
-0+{ + type_register_static(&l2vic_interface_info); + type_register_static(&l2vic_info); +} + +type_init (l2vic_register_types)Prefer
DEFINE_TYPES()for multiple TypeInfo.
I will make that change.
Re: [PATCH v2 4/7] hw/intc: Add l2vic interrupt controller
In reply to Brian CainQuoted 37 lines · Brian Cain
From: Sid Manning <[email protected]>
The Hexagon DSP requires an L2VIC to route up to 1024 external interrupt sources through 4 VID output groups into the core's 8 interrupt inputs. This device model implements the register interface, interrupt steering, and edge/level type handling needed by the sysemu machine models.
Co-authored-by Matheus Tavares Bernardino <[email protected]>Co-authored-by Damien Hedde <[email protected]>Signed-off-by Brian Cain <[email protected]>--- MAINTAINERS | 3 + docs/devel/hexagon-l2vic.rst | 55 ++++ docs/devel/index-internals.rst | 1 + include/hw/intc/hex-l2vic.h | 87 ++++++ target/hexagon/cpu.h | 2 + hw/intc/hex-l2vic.c | 532 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.c | 2 + target/hexagon/op_helper.c | 21 +- hw/hexagon/Kconfig | 1 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 2 + hw/intc/trace-events | 4 + 12 files changed, 712 insertions(+), 1 deletion(-)create mode 100644
docs/devel/hexagon-l2vic.rst
create mode 100644include/hw/intc/hex-l2vic.h
create mode 100644hw/intc/hex-l2vic.chw/intc/hex-l2vic.c new file +7
-0+/* +* Find out if this irq is associated with a group other than +* the default group +*/ +static uint32_t *get_int_group (HexL2VICState *s,int irq) +{ +int n = irq &0x1f ;
hw/intc/hex-l2vic.c line 191
Quoted 10 lines
hw/intc/hex-l2vic.c new file +10
-0+if (n <8 ) { +return s->int_group_n0; + } +if (n <16 ) { +return s->int_group_n1; + } +if (n <24 ) { +return s->int_group_n2; + } +return s->int_group_n3;
Declaring int_group_n[4], this could be:
return s->int_group_n[extract32(irq, 3, 2)];
Quoted 1 line
+}
PATCH v2 5/7 hw/hexagon: connect l2vic device
In reply to Brian CainInstantiate the L2VIC device in both machine models, map its slow and MMIO regions, and link it to each CPU via the "l2vic" property.
--- include/hw/hexagon/hexagon.h | 1 + include/hw/hexagon/hexagon_globalreg.h | 4 +++ hw/hexagon/hexagon_dsp.c | 20 +++++++++++++ hw/hexagon/hexagon_globalreg.c | 41 ++++++++++++++++++++++---- hw/hexagon/virt.c | 22 ++++++++++++++ 5 files changed, 83 insertions(+), 5 deletions(-)
include/hw/hexagon/hexagon.h +1 -0
@@ -156,6 +156,7 @@ struct HexagonCommonMachineState {MemoryRegion ram;MemoryRegion cfgtable_rom; + DeviceState *l2vic_dev; };#endif
include/hw/hexagon/hexagon_globalreg.h +4 -0
@@ -10,6 +10,7 @@#include "hw/core/qdev.h" #include "hw/core/sysbus.h" +#include "hw/intc/hex-l2vic.h" #include "qom/object.h" #include "target/hexagon/cpu.h"
@@ -22,6 +23,9 @@ struct HexagonGlobalRegState {/* Array of system registers */ uint32_t regs[NUM_SREGS ]; +/* L2VIC interface used to back the VID/VID1 registers */ +HexL2VicInterface *l2vic; +/* Global performance cycle counter base */ uint64_t g_pcycle_base;
hw/hexagon/hexagon_dsp.c +20 -0
@@ -16,6 +16,7 @@#include "hw/hexagon/hexagon.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_tlb.h" +#include "hw/intc/hex-l2vic.h" #include "hw/core/loader.h" #include "qapi/error.h" #include "qemu/error-report.h"
@@ -111,6 +112,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,MemoryRegion *address_space;DeviceState *glob_regs_dev;DeviceState *tlb_dev; +DeviceState *cpu0 =NULL ;memset (&hexagon_binfo,0 ,sizeof (hexagon_binfo));if (machine->kernel_filename) {
@@ -131,11 +133,21 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev, machine->ram_size, &error_fatal);memory_region_add_subregion (address_space,0x0 , &hms->ram); + hms->l2vic_dev =qdev_new (TYPE_HEX_L2VIC ); +object_property_add_child (OBJECT (machine),"l2vic" , +OBJECT (hms->l2vic_dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (hms->l2vic_dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (hms->l2vic_dev),0 , m_cfg->l2vic_base); +sysbus_mmio_map (SYS_BUS_DEVICE (hms->l2vic_dev),1 , + m_cfg->cfgtable.fastl2vic_base <<16 ); + glob_regs_dev =qdev_new (TYPE_HEXAGON_GLOBALREG );object_property_add_child (OBJECT (machine),"global-regs" ,OBJECT (glob_regs_dev));qdev_prop_set_uint64 (glob_regs_dev,"config-table-addr" , m_cfg->cfgbase);qdev_prop_set_uint32 (glob_regs_dev,"dsp-rev" , rev); +object_property_set_link (OBJECT (glob_regs_dev),"l2vic" , +OBJECT (hms->l2vic_dev), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (glob_regs_dev), &error_fatal); tlb_dev =qdev_new (TYPE_HEXAGON_TLB );
@@ -154,15 +166,23 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,*/ qdev_prop_set_bit (DEVICE (cpu),"start-powered-off" , (i !=0 ));if (i ==0 ) { + cpu0 =DEVICE (cpu);hexagon_init_bootstrap (dms, cpu); }object_property_set_link (OBJECT (cpu),"global-regs" ,OBJECT (glob_regs_dev), &error_fatal);object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); +object_property_set_link (OBJECT (cpu),"l2vic" , +OBJECT (hms->l2vic_dev), &error_fatal);qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); } +for (int i =0 ; i <8 ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (hms->l2vic_dev), i, +qdev_get_gpio_in (cpu0, i)); + } +rom_add_blob_fixed_as ("config_table.rom" , &m_cfg->cfgtable,sizeof (m_cfg->cfgtable), m_cfg->cfgbase, &address_space_memory);
hw/hexagon/hexagon_globalreg.c +36 -5
90 lines not on this page · raw message
hw/hexagon/virt.c +22 -0
@@ -15,6 +15,7 @@#include "hw/hexagon/hexagon.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_tlb.h" +#include "hw/intc/hex-l2vic.h" #include "hw/core/loader.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-clock.h"
@@ -268,10 +269,22 @@ static void virt_init(MachineState *ms) &vms->parent_obj.cfgtable_rom);fdt_add_hvx (vms, m_cfg); + vms->parent_obj.l2vic_dev =qdev_new (TYPE_HEX_L2VIC ); +object_property_add_child (OBJECT (ms),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev), + &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev),0 , + m_cfg->l2vic_base); +sysbus_mmio_map (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev),1 , + m_cfg->cfgtable.fastl2vic_base <<16 ); + gsregs_dev =qdev_new (TYPE_HEXAGON_GLOBALREG );object_property_add_child (OBJECT (ms),"global-regs" ,OBJECT (gsregs_dev));qdev_prop_set_uint64 (gsregs_dev,"config-table-addr" , m_cfg->cfgbase);qdev_prop_set_uint32 (gsregs_dev,"dsp-rev" , v68_rev); +object_property_set_link (OBJECT (gsregs_dev),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (gsregs_dev), &error_fatal); tlb_dev =qdev_new (TYPE_HEXAGON_TLB );
@@ -301,9 +314,18 @@ static void virt_init(MachineState *ms) OBJECT(gsregs_dev), &error_fatal);object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); +object_property_set_link (OBJECT (cpu),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev), + &error_fatal);qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); } + +for (int i =0 ; i <8 ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev), i, +qdev_get_gpio_in (cpu0, i)); + } +fdt_add_cpu_nodes (vms); clk_phandle =fdt_add_clocks (vms);fdt_add_uart (vms,VIRT_UART0 , clk_phandle);
Signature · 1 line
2.34.1
Re: [PATCH v2 5/7] hw/hexagon: connect l2vic device
Quoted 2 lines · Brian Cain
Instantiate the L2VIC device in both machine models, map its slow and MMIO regions, and link it to each CPU via the "l2vic" property.
"slow and MMIO" description is not clear to me.
Quoted 16 lines
Reviewed-by Pierrick Bouvier <[email protected]>Signed-off-by Brian Cain <[email protected]>--- include/hw/hexagon/hexagon.h | 1 + include/hw/hexagon/hexagon_globalreg.h | 4 +++ hw/hexagon/hexagon_dsp.c | 20 +++++++++++++ hw/hexagon/hexagon_globalreg.c | 41 ++++++++++++++++++++++---- hw/hexagon/virt.c | 22 ++++++++++++++ 5 files changed, 83 insertions(+), 5 deletions(-)include/hw/hexagon/hexagon.h +0
-0
include/hw/hexagon/hexagon.h struct HexagonCommonMachineState { · line 159
Quoted 4 lines
include/hw/hexagon/hexagon.h +1
-0@@ -156,6 +156,7 @@ struct HexagonCommonMachineState {MemoryRegion ram;MemoryRegion cfgtable_rom; +DeviceState *l2vic_dev;
s/_dev//
Quoted 68 lines
include/hw/hexagon/hexagon.h +0
-0};#endif include/hw/hexagon/hexagon_globalreg.h +4
-0@@ -10,6 +10,7 @@#include "hw/core/qdev.h" #include "hw/core/sysbus.h" +#include "hw/intc/hex-l2vic.h" #include "qom/object.h" #include "target/hexagon/cpu.h" @@ -22,6 +23,9 @@ struct HexagonGlobalRegState {/* Array of system registers */ uint32_t regs[NUM_SREGS ]; +/* L2VIC interface used to back the VID/VID1 registers */ +HexL2VicInterface *l2vic; +/* Global performance cycle counter base */ uint64_t g_pcycle_base;hw/hexagon/hexagon_dsp.c +12
-0@@ -16,6 +16,7 @@#include "hw/hexagon/hexagon.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_tlb.h" +#include "hw/intc/hex-l2vic.h" #include "hw/core/loader.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -111,6 +112,7 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,MemoryRegion *address_space;DeviceState *glob_regs_dev;DeviceState *tlb_dev; +DeviceState *cpu0 =NULL ;memset (&hexagon_binfo,0 ,sizeof (hexagon_binfo));if (machine->kernel_filename) {@@ -131,11 +133,21 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev, machine->ram_size, &error_fatal);memory_region_add_subregion (address_space,0x0 , &hms->ram); + hms->l2vic_dev =qdev_new (TYPE_HEX_L2VIC ); +object_property_add_child (OBJECT (machine),"l2vic" , +OBJECT (hms->l2vic_dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (hms->l2vic_dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (hms->l2vic_dev),0 , m_cfg->l2vic_base); +sysbus_mmio_map (SYS_BUS_DEVICE (hms->l2vic_dev),1 , + m_cfg->cfgtable.fastl2vic_base <<16 ); + glob_regs_dev =qdev_new (TYPE_HEXAGON_GLOBALREG );object_property_add_child (OBJECT (machine),"global-regs" ,OBJECT (glob_regs_dev));qdev_prop_set_uint64 (glob_regs_dev,"config-table-addr" , m_cfg->cfgbase);qdev_prop_set_uint32 (glob_regs_dev,"dsp-rev" , rev); +object_property_set_link (OBJECT (glob_regs_dev),"l2vic" , +OBJECT (hms->l2vic_dev), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (glob_regs_dev), &error_fatal); tlb_dev =qdev_new (TYPE_HEXAGON_TLB );
hw/hexagon/hexagon_dsp.c static void hexagon_common_init(MachineState *machine, Rev_t rev, · line 169
Quoted 4 lines
hw/hexagon/hexagon_dsp.c +1
-0@@ -154,15 +166,23 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,*/ qdev_prop_set_bit (DEVICE (cpu),"start-powered-off" , (i !=0 ));if (i ==0 ) { + cpu0 =DEVICE (cpu);
Alternatively call sysbus_connect_irq() here.
Quoted 37 lines
hw/hexagon/hexagon_dsp.c +7
-0hexagon_init_bootstrap (dms, cpu); }object_property_set_link (OBJECT (cpu),"global-regs" ,OBJECT (glob_regs_dev), &error_fatal);object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); +object_property_set_link (OBJECT (cpu),"l2vic" , +OBJECT (hms->l2vic_dev), &error_fatal);qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); } +for (int i =0 ; i <8 ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (hms->l2vic_dev), i, +qdev_get_gpio_in (cpu0, i)); + } +rom_add_blob_fixed_as ("config_table.rom" , &m_cfg->cfgtable,sizeof (m_cfg->cfgtable), m_cfg->cfgbase, &address_space_memory);hw/hexagon/hexagon_globalreg.c +3
-0@@ -11,6 +11,7 @@#include "hw/core/qdev-properties.h" #include "hw/core/sysbus.h" #include "hw/core/resettable.h" +#include "hw/intc/hex-l2vic.h" #include "migration/vmstate.h" #include "qom/object.h" #include "target/hexagon/cpu.h" @@ -135,6 +136,32 @@ static inline uint32_t apply_write_mask(uint32_t new_val, uint32_t cur_val,return new_val; } +static inline bool is_vid_reg (uint32_t reg) +{
hw/hexagon/hexagon_globalreg.c static inline uint32_t apply_write_mask(uint32_t new_val, uint32_t cur_val, · line 150
Quoted 10 lines
hw/hexagon/hexagon_globalreg.c +10
-0+return reg ==HEX_SREG_VID || reg ==HEX_SREG_VID1 ; +} + +/* +* HEX_SREG_VID/VID1 are backed by the L2VIC's VID group registers +* rather than the plain regs[] array, when an L2VIC is wired up. +*/ +static uint32_t get_reg_value (HexagonGlobalRegState *s,uint32_t reg) +{ +if (is_vid_reg (reg) && s->l2vic) {
Do we still want an optional l2vic? Otherwise we should make it unconditional, checking the link is set in hexagon_globalreg_realize().
hw/hexagon/hexagon_globalreg.c static inline uint32_t apply_write_mask(uint32_t new_val, uint32_t cur_val, · line 159
Quoted 9 lines
hw/hexagon/hexagon_globalreg.c +9
-0+return l2vic_read_vid (s->l2vic, reg ==HEX_SREG_VID ?0 :1 ); + } +return s->regs[reg]; +} + +static void set_reg_value (HexagonGlobalRegState *s,uint32_t reg, +uint32_t value) +{ + s->regs[reg] = value;
IIUC HEX_SREG_VID,1 are read-only and shouldn't be updated, is that right?
Quoted 18 lines
hw/hexagon/hexagon_globalreg.c +6
-1+if (is_vid_reg (reg) && s->l2vic) { +l2vic_update_vid (s->l2vic, reg ==HEX_SREG_VID ?0 :1 , value); + } +} +uint32_t hexagon_globalreg_read (HexagonGlobalRegState *s,uint32_t reg,uint32_t htid) {@@ -146,7 +173,7 @@ uint32_t hexagon_globalreg_read(HexagonGlobalRegState *s, uint32_t reg,g_assert (reg <NUM_SREGS );g_assert (reg >=HEX_SREG_GLB_START ); - value = s->regs[reg]; + value =get_reg_value (s, reg);trace_hexagon_globalreg_read (htid,get_sreg_name (reg), value);return value;
hw/hexagon/hexagon_globalreg.c void hexagon_globalreg_write(HexagonGlobalRegState *s, uint32_t reg, · line 190
Quoted 5 lines
hw/hexagon/hexagon_globalreg.c +1
-1@@ -160,7 +187,7 @@ void hexagon_globalreg_write(HexagonGlobalRegState *s, uint32_t reg, }g_assert (reg <NUM_SREGS );g_assert (reg >=HEX_SREG_GLB_START ); - s->regs[reg] = value; +set_reg_value (s, reg, value);
A preliminary patch with extracting get_reg_value/set_reg_value stubs would reduce this diff.
Quoted 96 lines
hw/hexagon/hexagon_globalreg.c +7
-3trace_hexagon_globalreg_write (htid,get_sreg_name (reg), value); }@@ -168,6 +195,7 @@ uint32_t hexagon_globalreg_masked_value(HexagonGlobalRegState *s, uint32_t reg, uint32_t value) {uint32_t reg_mask; +uint32_t cur_val;if (!s) {return value;@@ -175,9 +203,10 @@ uint32_t hexagon_globalreg_masked_value(HexagonGlobalRegState *s, uint32_t reg,g_assert (reg <NUM_SREGS );g_assert (reg >=HEX_SREG_GLB_START ); reg_mask = global_sreg_immut_masks[reg]; + cur_val =get_reg_value (s, reg);return reg_mask ==IMMUTABLE ? - s->regs[reg] : -apply_write_mask (value, s->regs[reg], reg_mask); + cur_val : +apply_write_mask (value, cur_val, reg_mask); } void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg,@@ -186,7 +215,7 @@ void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg,if (!s) {return ; } - s->regs[reg] =hexagon_globalreg_masked_value (s, reg, value); +set_reg_value (s, reg,hexagon_globalreg_masked_value (s, reg, value)); }uint64_t hexagon_globalreg_get_pcycle_base (HexagonGlobalRegState *s)@@ -275,6 +304,8 @@ static const VMStateDescription vmstate_hexagon_globalreg = { };static const Property hexagon_globalreg_properties[] = { +DEFINE_PROP_LINK ("l2vic" , HexagonGlobalRegState, l2vic, + TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *),DEFINE_PROP_UINT32 ("boot-evb" , HexagonGlobalRegState, boot_evb,0x0 ),DEFINE_PROP_UINT64 ("config-table-addr" , HexagonGlobalRegState, config_table_addr,0xffffffffULL ),hw/hexagon/virt.c +22
-0@@ -15,6 +15,7 @@#include "hw/hexagon/hexagon.h" #include "hw/hexagon/hexagon_globalreg.h" #include "hw/hexagon/hexagon_tlb.h" +#include "hw/intc/hex-l2vic.h" #include "hw/core/loader.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-clock.h" @@ -268,10 +269,22 @@ static void virt_init(MachineState *ms) &vms->parent_obj.cfgtable_rom);fdt_add_hvx (vms, m_cfg); + vms->parent_obj.l2vic_dev =qdev_new (TYPE_HEX_L2VIC ); +object_property_add_child (OBJECT (ms),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev), + &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev),0 , + m_cfg->l2vic_base); +sysbus_mmio_map (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev),1 , + m_cfg->cfgtable.fastl2vic_base <<16 ); + gsregs_dev =qdev_new (TYPE_HEXAGON_GLOBALREG );object_property_add_child (OBJECT (ms),"global-regs" ,OBJECT (gsregs_dev));qdev_prop_set_uint64 (gsregs_dev,"config-table-addr" , m_cfg->cfgbase);qdev_prop_set_uint32 (gsregs_dev,"dsp-rev" , v68_rev); +object_property_set_link (OBJECT (gsregs_dev),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (gsregs_dev), &error_fatal); tlb_dev =qdev_new (TYPE_HEXAGON_TLB );@@ -301,9 +314,18 @@ static void virt_init(MachineState *ms) OBJECT(gsregs_dev), &error_fatal);object_property_set_link (OBJECT (cpu),"tlb" ,OBJECT (tlb_dev), &error_fatal); +object_property_set_link (OBJECT (cpu),"l2vic" , +OBJECT (vms->parent_obj.l2vic_dev), + &error_fatal);qdev_realize_and_unref (DEVICE (cpu),NULL , &error_fatal); } + +for (int i =0 ; i <8 ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (vms->parent_obj.l2vic_dev), i, +qdev_get_gpio_in (cpu0, i)); + } +fdt_add_cpu_nodes (vms); clk_phandle =fdt_add_clocks (vms);fdt_add_uart (vms,VIRT_UART0 , clk_phandle);
PATCH v2 6/7 tests/qtest: add L2VIC qtest
In reply to Brian CainAdd a qtest exercising the L2VIC interrupt controller's basic register access and interrupt enable/disable behavior.
--- MAINTAINERS | 1 + tests/qtest/l2vic-test.c | 242 +++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/l2vic-test.c
MAINTAINERS +1 -0
@@ -252,6 +252,7 @@ S: Supported F: target/hexagon/ F: hw/intc/hex-l2vic.c F: include/hw/intc/hex-l2vic.h +F: tests/qtest/l2vic-test.c X: target/hexagon/idef-parser/ X: target/hexagon/gen_idef_parser_funcs.py F: linux-user/hexagon/
tests/qtest/l2vic-test.c new file +242 -0
242 lines not on this page · raw message
tests/qtest/meson.build +1 -1
@@ -299,7 +299,7 @@ qtests_riscv64 = ['riscv-csr-test'] + \ ['iommu-riscv-test'] : []) + \ (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : []) -qtests_hexagon = ['boot-serial-test'] +qtests_hexagon = ['boot-serial-test', 'l2vic-test'] qos_test_ss = ss.source_set() qos_test_ss.add(
Signature · 1 line
2.34.1
PATCH v2 7/7 tests/functional/hexagon: add arch_tests functional test
In reply to Brian CainAdd new test cases from hexagon-arch-tests to exercise exceptions, guest mode, interrupt steering, etc.
--- MAINTAINERS | 1 + tests/functional/hexagon/meson.build | 5 ++ tests/functional/hexagon/test_arch_tests.py | 63 +++++++++++++++++++++ tests/functional/meson.build | 1 + 4 files changed, 70 insertions(+) create mode 100644 tests/functional/hexagon/meson.build create mode 100755 tests/functional/hexagon/test_arch_tests.py
MAINTAINERS +1 -0
@@ -1361,6 +1361,7 @@ F: hw/hexagon/ F: include/hw/hexagon/ F: configs/devices/hexagon-softmmu/default.mak F: docs/system/hexagon/ +F: tests/functional/hexagon/ F: docs/devel/hexagon-sys.rst LoongArch Machines
tests/functional/hexagon/meson.build new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +tests_hexagon_system_thorough = [ + 'arch_tests', +]
tests/functional/hexagon/test_arch_tests.py new file +63 -0
63 lines not on this page · raw message
tests/functional/meson.build +1 -0
@@ -14,6 +14,7 @@ subdir('aarch64') subdir('alpha') subdir('arm') subdir('avr') +subdir('hexagon') subdir('hppa') subdir('i386') subdir('loongarch64')
Signature · 1 line
2.34.1