hw/cxl: Support emulating 4 HDM decoders throughout topology
cover hw/cxl: Support emulating 4 HDM decoders throughout topology
For initial CXL emulation / kernel driver bring up a single Host-managed Device Memory (HDM) decoder instance was sufficient as it let us test the basic region creation code etc. More complex testing appropriate today requires a more realistic configuration with multiple decoders.
The Linux kernel will use separate decoders for each memory type (and shortly per DCD region) and for each interleave set within a memory type or DCD region. 4 decoders are sufficient for most test cases today but we may need to grow these further in future.
This patch set already allowed us to identify one kernel bug which is now fixed.
https://lore.kernel.org/linux-cxl/168696507968.3590522.14484000711718573626.stgit@dwillia2-xfh.jf.intel.com/
Note that, whilst I'm proposing this series for upstream (based on priorities of what we have out of tree) it hasn't previously been posted so needs review. (I failed to send it out previously)
Based on: [PATCH 0/4] hw/cxl: Minor CXL emulation fixes and cleanup Based on: [PATCH v2 0/3] hw/cxl: Add dummy ACPI QTG DSM
Based on: Message ID: [email protected] Based on: Message ID: [email protected]
Jonathan Cameron (2):
hw/cxl: Add utility functions decoder interleave ways and target
count.
hw/cxl: Support 4 HDM decoders at all levels of topology
include/hw/cxl/cxl_component.h | 21 ++++++++ hw/cxl/cxl-component-utils.c | 43 +++++++++++---- hw/cxl/cxl-host.c | 65 +++++++++++++++-------- hw/mem/cxl_type3.c | 97 +++++++++++++++++++++++----------- 4 files changed, 164 insertions(+), 62 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/2 hw/cxl: Add utility functions decoder interleave ways and target count.
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)
include/hw/cxl/cxl_component.h +14 -0
@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; } +static inline int cxl_decoder_count_dec (int enc_cnt) +{ +switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +} +uint8_t cxl_interleave_ways_enc (int iw,Error **errp); +int cxl_interleave_ways_dec (uint8_t iw_enc,Error **errp);uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp);static inline hwaddr cxl_decode_ig (int ig)
hw/cxl/cxl-component-utils.c +17 -0
@@ -392,6 +392,23 @@ uint8_t cxl_interleave_ways_enc(int iw, Error **errp) } } +int cxl_interleave_ways_dec (uint8_t iw_enc,Error **errp) +{ +switch (iw_enc) { +case 0x0 :return 1 ; +case 0x1 :return 2 ; +case 0x2 :return 4 ; +case 0x3 :return 8 ; +case 0x4 :return 16 ; +case 0x8 :return 3 ; +case 0x9 :return 6 ; +case 0xa :return 12 ; +default : +error_setg (errp,"Encoded interleave ways: %d not supported" , iw_enc); +return 0 ; + } +} +uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp) {switch (gran) {
Signature · 1 line
2.39.2
Re: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 20 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)include/hw/cxl/cxl_component.h +2
-0@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; } +static inline int cxl_decoder_count_dec (int enc_cnt) +{
include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 252
Quoted 10 lines
include/hw/cxl/cxl_component.h +10
-0+switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +}
Why inline?
Alternatively:
unsigned cxl_decoder_count_dec(unsigned enc_cnt)
{
return enc_cnt <= 5 ? 2 * enc_cnt : 0;
}Re: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 19 lines · On Mon, 4 Sep 2023 20:26:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 18 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)include/hw/cxl/cxl_component.h +0
-0@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; }
Quoted 15 lines
include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 252
Quoted 12 lines
include/hw/cxl/cxl_component.h +12
-0+static inline int cxl_decoder_count_dec (int enc_cnt) +{ +switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +}Why inline?
Bad habit.
Quoted 5 lines
Alternatively:
unsigned cxl_decoder_count_dec(unsigned enc_cnt) { return enc_cnt <= 5 ? 2 * enc_cnt : 0;
It gets a little more fiddly than the code I'm proposing implies. For Switches and Host Bridges larger values are defined (we just don't emulate them yet and may never do so) and those don't have a sensible mapping.
I guess there is no harm in adding the full decode however which will make it more obvious why it was a switch statement.
Quoted 3 lines
}
Re: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 38 lines · On Tue, 5 Sep 2023 15:56:39 +0100 Jonathan Cameron via <[email protected]>…
Quoted 19 lines · On Mon, 4 Sep 2023 20:26:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 18 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)include/hw/cxl/cxl_component.h +0
-0@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; }Quoted 15 lines
include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 252
Quoted 12 lines
include/hw/cxl/cxl_component.h +12
-0+static inline int cxl_decoder_count_dec (int enc_cnt) +{ +switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +}Why inline?
Quoted 1 line
Bad habit.
Nope. I'm being slow. This is in a header so if I don't mark it inline I get a bunch of defined but not used warnings.
Obviously I could move the implementation of this and the matching encoding routines out of the header. I haven't done so for now.
Quoted 22 lines
Quoted 7 lines
Alternatively:
unsigned cxl_decoder_count_dec(unsigned enc_cnt) { return enc_cnt <= 5 ? 2 * enc_cnt : 0;It gets a little more fiddly than the code I'm proposing implies. For Switches and Host Bridges larger values are defined (we just don't emulate them yet and may never do so) and those don't have a sensible mapping.
I guess there is no harm in adding the full decode however which will make it more obvious why it was a switch statement.
Quoted 3 lines
}
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 41 lines · Jonathan Cameron
Quoted 38 lines · On Tue, 5 Sep 2023 15:56:39 +0100 Jonathan Cameron via <[email protected]>…
Quoted 34 lines · On Mon, 4 Sep 2023 20:26:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 20 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)include/hw/cxl/cxl_component.h +2
-0@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; } +static inline int cxl_decoder_count_dec (int enc_cnt) +{include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 252
Quoted 10 lines
include/hw/cxl/cxl_component.h +10
-0+switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +}Why inline?
Quoted 6 lines
Quoted 1 line
Bad habit.
Nope. I'm being slow. This is in a header so if I don't mark it inline I get a bunch of defined but not used warnings.
Obviously I could move the implementation of this and the matching encoding routines out of the header. I haven't done so for now.
Inlined function in hw/ are hardly justifiable. They make the headers and debugging sessions harder to read in my experience. Compilers are becoming clever and clever, and we have LTO, so I rather privilege code maintainability. My 2 cents :)
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Alternatively:
unsigned cxl_decoder_count_dec(unsigned enc_cnt) { return enc_cnt <= 5 ? 2 * enc_cnt : 0;
Quoted 7 lines
Quoted 7 lines
It gets a little more fiddly than the code I'm proposing implies. For Switches and Host Bridges larger values are defined (we just don't emulate them yet and may never do so) and those don't have a sensible mapping.
I guess there is no harm in adding the full decode however which will make it more obvious why it was a switch statement.
Right, no problem.
Preferably having this tiny function not inlined:
Re: [PATCH 1/2] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 65 lines · On Tue, 5 Sep 2023 18:55:23 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 41 lines · Jonathan Cameron
Quoted 38 lines · On Tue, 5 Sep 2023 15:56:39 +0100 Jonathan Cameron via <[email protected]>…
Quoted 34 lines · On Mon, 4 Sep 2023 20:26:59 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 20 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 14 ++++++++++++++ hw/cxl/cxl-component-utils.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+)include/hw/cxl/cxl_component.h +2
-0@@ -238,7 +238,21 @@ static inline int cxl_decoder_count_enc(int count)return 0 ; } +static inline int cxl_decoder_count_dec (int enc_cnt) +{include/hw/cxl/cxl_component.h static inline int cxl_decoder_count_enc(int count) · line 252
Quoted 10 lines
include/hw/cxl/cxl_component.h +10
-0+switch (enc_cnt) { +case 0 :return 1 ; +case 1 :return 2 ; +case 2 :return 4 ; +case 3 :return 6 ; +case 4 :return 8 ; +case 5 :return 10 ; + } +return 0 ; +}Why inline?
Quoted 6 lines
Quoted 1 line
Bad habit.
Nope. I'm being slow. This is in a header so if I don't mark it inline I get a bunch of defined but not used warnings.
Obviously I could move the implementation of this and the matching encoding routines out of the header. I haven't done so for now.
Inlined function in hw/ are hardly justifiable. They make the headers and debugging sessions harder to read in my experience. Compilers are becoming clever and clever, and we have LTO, so I rather privilege code maintainability. My 2 cents :)
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Alternatively:
unsigned cxl_decoder_count_dec(unsigned enc_cnt) { return enc_cnt <= 5 ? 2 * enc_cnt : 0;It gets a little more fiddly than the code I'm proposing implies. For Switches and Host Bridges larger values are defined (we just don't emulate them yet and may never do so) and those don't have a sensible mapping.
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
I guess there is no harm in adding the full decode however which will make it more obvious why it was a switch statement.
Right, no problem.
Preferably having this tiny function not inlined
I'll push this and the enc() version down into the cxl-component-utils.c as a precursor patch.
Quoted 4 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks, but the changes to do make these non inline, and include the larger decode and encode values are big enough I won't pick up the RB - too much changing (that I might mess up ;)
Jonathan
PATCH 2/2 hw/cxl: Support 4 HDM decoders at all levels of topology
In reply to Jonathan CameronSupport these decoders in CXL host bridges (pxb-cxl), CXL Switch USP and CXL Type 3 end points.
---
Note there is a fix in here for a wrong increment that had no impact when there was only one HDM decoder.
include/hw/cxl/cxl_component.h | 7 +++ hw/cxl/cxl-component-utils.c | 26 +++++---- hw/cxl/cxl-host.c | 65 +++++++++++++++-------- hw/mem/cxl_type3.c | 97 +++++++++++++++++++++++----------- 4 files changed, 133 insertions(+), 62 deletions(-)
include/hw/cxl/cxl_component.h +7 -0
@@ -135,6 +135,10 @@ REG32(CXL_RAS_ERR_HEADER0, CXL_RAS_REGISTERS_OFFSET + 0x18) REG32(CXL_HDM_DECODER##n##_TARGET_LIST_LO, \ CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x24) \ REG32(CXL_HDM_DECODER##n##_TARGET_LIST_HI, \ + CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x28) \ + REG32(CXL_HDM_DECODER##n##_DPA_SKIP_LO, \ + CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x24) \ + REG32(CXL_HDM_DECODER##n##_DPA_SKIP_HI, \ CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x28)REG32 (CXL_HDM_DECODER_CAPABILITY ,CXL_HDM_REGISTERS_OFFSET )
@@ -148,6 +152,9 @@ REG32(CXL_HDM_DECODER_GLOBAL_CONTROL, CXL_HDM_REGISTERS_OFFSET + 4) FIELD(CXL_HDM_DECODER_GLOBAL_CONTROL, HDM_DECODER_ENABLE, 1, 1)HDM_DECODER_INIT (0 ); +HDM_DECODER_INIT (1 ); +HDM_DECODER_INIT (2 ); +HDM_DECODER_INIT (3 );/* 8.2.5.13 - CXL Extended Security Capability Structure (Root complex only) */ #define EXTSEC_ENTRY_MAX 256
hw/cxl/cxl-component-utils.c +16 -10
@@ -42,6 +42,9 @@ static void dumb_hdm_handler(CXLComponentState *cxl_cstate, hwaddr offset,switch (offset) {case A_CXL_HDM_DECODER0_CTRL : +case A_CXL_HDM_DECODER1_CTRL : +case A_CXL_HDM_DECODER2_CTRL : +case A_CXL_HDM_DECODER3_CTRL : should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); should_uncommit = !should_commit;break ;
@@ -81,7 +84,7 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value, }if (offset >=A_CXL_HDM_DECODER_CAPABILITY && - offset <=A_CXL_HDM_DECODER0_TARGET_LIST_HI ) { + offset <=A_CXL_HDM_DECODER3_TARGET_LIST_HI ) {dumb_hdm_handler (cxl_cstate, offset, value); }else { cregs->cache_mem_registers[offset /sizeof (*cregs->cache_mem_registers)] = value;
@@ -161,7 +164,7 @@ static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk)static void hdm_init_common (uint32_t *reg_state,uint32_t *write_msk,enum reg_type type) { -int decoder_count =1 ; +int decoder_count =4 ;int i; ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, DECODER_COUNT,
@@ -174,19 +177,22 @@ static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, HDM_DECODER_ENABLE, 0); write_msk[R_CXL_HDM_DECODER_GLOBAL_CONTROL ] =0x3 ;for (i =0 ; i < decoder_count; i++) { - write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 ] =0x13ff ; + write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 /4 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 /4 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 /4 ] =0x13ff ;if (type ==CXL2_DEVICE || type ==CXL2_TYPE3_DEVICE || type ==CXL2_LOGICAL_DEVICE ) { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xf0000000 ; }else { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xffffffff ; } - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 /4 ] = +0xffffffff ; } }
hw/cxl/cxl-host.c +44 -21
77 lines not on this page · raw message
hw/mem/cxl_type3.c +66 -31
136 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH 2/2] hw/cxl: Support 4 HDM decoders at all levels of topology
Hi Jonathan,
Few style comments inlined.
Quoted 30 lines · Jonathan Cameron
Support these decoders in CXL host bridges (pxb-cxl), CXL Switch USP and CXL Type 3 end points.
Signed-off-by Jonathan Cameron <[email protected]>---
Note there is a fix in here for a wrong increment that had no impact when there was only one HDM decoder.include/hw/cxl/cxl_component.h | 7 +++ hw/cxl/cxl-component-utils.c | 26 +++++---- hw/cxl/cxl-host.c | 65 +++++++++++++++-------- hw/mem/cxl_type3.c | 97 +++++++++++++++++++++++----------- 4 files changed, 133 insertions(+), 62 deletions(-)include/hw/cxl/cxl_component.h +4
-0@@ -135,6 +135,10 @@ REG32(CXL_RAS_ERR_HEADER0, CXL_RAS_REGISTERS_OFFSET + 0x18) REG32(CXL_HDM_DECODER##n##_TARGET_LIST_LO, \ CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x24) \ REG32(CXL_HDM_DECODER##n##_TARGET_LIST_HI, \ + CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x28) \ + REG32(CXL_HDM_DECODER##n##_DPA_SKIP_LO, \ + CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x24) \ + REG32(CXL_HDM_DECODER##n##_DPA_SKIP_HI, \ CXL_HDM_REGISTERS_OFFSET + (0x20 * n) + 0x28)REG32 (CXL_HDM_DECODER_CAPABILITY ,CXL_HDM_REGISTERS_OFFSET )
include/hw/cxl/cxl_component.h REG32(CXL_HDM_DECODER_GLOBAL_CONTROL, CXL_HDM_REGISTERS_OFFSET + 4) · line 157
Quoted 6 lines
include/hw/cxl/cxl_component.h +3
-0@@ -148,6 +152,9 @@ REG32(CXL_HDM_DECODER_GLOBAL_CONTROL, CXL_HDM_REGISTERS_OFFSET + 4) FIELD(CXL_HDM_DECODER_GLOBAL_CONTROL, HDM_DECODER_ENABLE, 1, 1)HDM_DECODER_INIT (0 ); +HDM_DECODER_INIT (1 ); +HDM_DECODER_INIT (2 ); +HDM_DECODER_INIT (3 );
#define HDM_DECODER_COUNT 4
Quoted 26 lines
include/hw/cxl/cxl_component.h +0
-0/* 8.2.5.13 - CXL Extended Security Capability Structure (Root complex only) */ #define EXTSEC_ENTRY_MAX 256hw/cxl/cxl-component-utils.c +4
-1@@ -42,6 +42,9 @@ static void dumb_hdm_handler(CXLComponentState *cxl_cstate, hwaddr offset,switch (offset) {case A_CXL_HDM_DECODER0_CTRL : +case A_CXL_HDM_DECODER1_CTRL : +case A_CXL_HDM_DECODER2_CTRL : +case A_CXL_HDM_DECODER3_CTRL : should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); should_uncommit = !should_commit;break ;@@ -81,7 +84,7 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value, }if (offset >=A_CXL_HDM_DECODER_CAPABILITY && - offset <=A_CXL_HDM_DECODER0_TARGET_LIST_HI ) { + offset <=A_CXL_HDM_DECODER3_TARGET_LIST_HI ) {dumb_hdm_handler (cxl_cstate, offset, value); }else { cregs->cache_mem_registers[offset /sizeof (*cregs->cache_mem_registers)] = value;
hw/cxl/cxl-component-utils.c static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk) · line 167
Quoted 5 lines
hw/cxl/cxl-component-utils.c +1
-1@@ -161,7 +164,7 @@ static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk)static void hdm_init_common (uint32_t *reg_state,uint32_t *write_msk,enum reg_type type) { -int decoder_count =1 ; +int decoder_count =4 ;
unsigned decoder_count = HDM_DECODER_COUNT;
hw/cxl/cxl-component-utils.c static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, · line 179
Quoted 7 lines
hw/cxl/cxl-component-utils.c +0
-0int i; ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, DECODER_COUNT,@@ -174,19 +177,22 @@ static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, HDM_DECODER_ENABLE, 0); write_msk[R_CXL_HDM_DECODER_GLOBAL_CONTROL ] =0x3 ;for (i =0 ; i < decoder_count; i++) {
Alternatively:
for (i = 0; i < decoder_count; i++, write_msk += 8) {
write_msk[R_CXL_HDM_DECODER0_BASE_LO] = 0xf0000000;hw/cxl/cxl-component-utils.c static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, · line 180
Quoted 6 lines
hw/cxl/cxl-component-utils.c +1
-5- write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 ] =0x13ff ; + write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 /4 ] =0xf0000000 ;
(this 0x20 / 4 bugs me a bit).
Quoted 42 lines
hw/cxl/cxl-component-utils.c +10
-3+ write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 /4 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 /4 ] =0x13ff ;if (type ==CXL2_DEVICE || type ==CXL2_TYPE3_DEVICE || type ==CXL2_LOGICAL_DEVICE ) { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xf0000000 ; }else { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xffffffff ; } - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 /4 ] = +0xffffffff ; } }hw/cxl/cxl-host.c +0
-9@@ -97,33 +97,56 @@ void cxl_fmws_link_targets(CXLState *cxl_state, Error **errp) } } -/* TODO: support, multiple hdm decoders */ static bool cxl_hdm_find_target (uint32_t *cache_mem,hwaddr addr,uint8_t *target) { -uint32_t ctrl; -uint32_t ig_enc; -uint32_t iw_enc; -uint32_t target_idx; - - ctrl = cache_mem[R_CXL_HDM_DECODER0_CTRL ]; -if (!FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED )) { -return false;
hw/cxl/cxl-host.c void cxl_fmws_link_targets(CXLState *cxl_state, Error **errp) · line 107
Quoted 10 lines
hw/cxl/cxl-host.c +5
-5- } - - ig_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IG ); - iw_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IW ); - target_idx = (addr /cxl_decode_ig (ig_enc)) % (1 << iw_enc); +bool found = false; +int i; +uint32_t cap; + + cap =ldl_le_p (cache_mem +R_CXL_HDM_DECODER_CAPABILITY );
unsigned count = cxl_decoder_count_dec(FIELD_EX32(cap,
CXL_HDM_DECODER_CAPABILITY,
DECODER_COUNT));for (i = 0; i < count; ...)
Quoted 196 lines
hw/cxl/cxl-host.c +39
-7+for (i =0 ; + i <cxl_decoder_count_dec (FIELD_EX32 (cap,CXL_HDM_DECODER_CAPABILITY , +DECODER_COUNT )); + i++) { +uint32_t ctrl, ig_enc, iw_enc, target_idx; +uint32_t low, high; +uint64_t base, size; + + low =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_BASE_LO + i *0x20 /4 ); + high =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_BASE_HI + i *0x20 /4 ); + base = (low &0xf0000000 ) | ((uint64_t )high <<32 ); + low =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 /4 ); + high =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 /4 ); + size = (low &0xf0000000 ) | ((uint64_t )high <<32 ); +if (addr < base || addr >= base + size) { +continue ; + } -if (target_idx <4 ) { - *target =extract32 (cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_LO ], - target_idx *8 ,8 ); - }else { - *target =extract32 (cache_mem[R_CXL_HDM_DECODER0_TARGET_LIST_HI ], - (target_idx -4 ) *8 ,8 ); + ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + i *0x20 /4 ); +if (!FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED )) { +return false; + } + found = true; + ig_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IG ); + iw_enc =FIELD_EX32 (ctrl,CXL_HDM_DECODER0_CTRL ,IW ); + target_idx = (addr /cxl_decode_ig (ig_enc)) % (1 << iw_enc); + +if (target_idx <4 ) { +uint32_t val =ldl_le_p (cache_mem + +R_CXL_HDM_DECODER0_TARGET_LIST_LO + + i *0x20 /4 ); + *target =extract32 (val, target_idx *8 ,8 ); + }else { +uint32_t val =ldl_le_p (cache_mem + +R_CXL_HDM_DECODER0_TARGET_LIST_HI + + i *0x20 /4 ); + *target =extract32 (val, (target_idx -4 ) *8 ,8 ); + } +break ; } -return true; +return found; }static PCIDevice *cxl_cfmws_find_device (CXLFixedWindow *fw,hwaddr addr)hw/mem/cxl_type3.c +66
-31@@ -381,14 +381,12 @@ static void hdm_decoder_commit(CXLType3Dev *ct3d, int which)uint32_t *cache_mem = cregs->cache_mem_registers;uint32_t ctrl; -assert (which ==0 ); - - ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL ); + ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + which *0x20 /4 );/* TODO: Sanity checks that the decoder is possible */ ctrl =FIELD_DP32 (ctrl,CXL_HDM_DECODER0_CTRL ,ERR ,0 ); ctrl =FIELD_DP32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED ,1 ); -stl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL , ctrl); +stl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + which *0x20 /4 , ctrl); }static void hdm_decoder_uncommit (CXLType3Dev *ct3d,int which)@@ -397,14 +395,12 @@ static void hdm_decoder_uncommit(CXLType3Dev *ct3d, int which)uint32_t *cache_mem = cregs->cache_mem_registers;uint32_t ctrl; -assert (which ==0 ); - - ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL ); + ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + which *0x20 /4 ); ctrl =FIELD_DP32 (ctrl,CXL_HDM_DECODER0_CTRL ,ERR ,0 ); ctrl =FIELD_DP32 (ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED ,0 ); -stl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL , ctrl); +stl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + which *0x20 /4 , ctrl); }static int ct3d_qmp_uncor_err_to_cxl (CxlUncorErrorType qmp_err)@@ -487,6 +483,21 @@ static void ct3d_reg_write(void *opaque, hwaddr offset, uint64_t value, should_uncommit = !should_commit; which_hdm =0 ;break ; +case A_CXL_HDM_DECODER1_CTRL : + should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); + should_uncommit = !should_commit; + which_hdm =1 ; +break ; +case A_CXL_HDM_DECODER2_CTRL : + should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); + should_uncommit = !should_commit; + which_hdm =2 ; +break ; +case A_CXL_HDM_DECODER3_CTRL : + should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); + should_uncommit = !should_commit; + which_hdm =3 ; +break ;case A_CXL_RAS_UNC_ERR_STATUS : {uint32_t capctrl =ldl_le_p (cache_mem +R_CXL_RAS_ERR_CAP_CTRL );@@ -758,36 +769,60 @@ static void ct3_exit(PCIDevice *pci_dev) } } -/* TODO: Support multiple HDM decoders and DPA skip */ static bool cxl_type3_dpa (CXLType3Dev *ct3d,hwaddr host_addr,uint64_t *dpa) {uint32_t *cache_mem = ct3d->cxl_cstate.crb.cache_mem_registers; -uint64_t decoder_base, decoder_size, hpa_offset; -uint32_t hdm0_ctrl; -int ig, iw; +uint32_t cap; +uint64_t dpa_base =0 ; +int i; - decoder_base = (((uint64_t )cache_mem[R_CXL_HDM_DECODER0_BASE_HI ] <<32 ) | - cache_mem[R_CXL_HDM_DECODER0_BASE_LO ]); -if ((uint64_t )host_addr < decoder_base) { -return false; - } + cap =ldl_le_p (cache_mem +R_CXL_HDM_DECODER_CAPABILITY ); +for (i =0 ; i <cxl_decoder_count_dec (FIELD_EX32 (cap, +CXL_HDM_DECODER_CAPABILITY , +DECODER_COUNT )); + i++) { +uint64_t decoder_base, decoder_size, hpa_offset, skip; +uint32_t hdm_ctrl, low, high; +int ig, iw; + + low =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_BASE_LO + i *0x20 /4 ); + high =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_BASE_HI + i *0x20 /4 ); + decoder_base = ((uint64_t )high <<32 ) | (low &0xf0000000 ); + + low =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 /4 ); + high =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 /4 ); + decoder_size = ((uint64_t )high <<32 ) | (low &0xf0000000 ); + + low =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_DPA_SKIP_LO + + i *0x20 /4 ); + high =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_DPA_SKIP_HI + + i *0x20 /4 ); + skip = ((uint64_t )high <<32 ) | (low &0xf0000000 ); + dpa_base += skip; + + hpa_offset = (uint64_t )host_addr - decoder_base; + + hdm_ctrl =ldl_le_p (cache_mem +R_CXL_HDM_DECODER0_CTRL + i *0x20 /4 ); + iw =FIELD_EX32 (hdm_ctrl,CXL_HDM_DECODER0_CTRL ,IW ); + ig =FIELD_EX32 (hdm_ctrl,CXL_HDM_DECODER0_CTRL ,IG ); +if (!FIELD_EX32 (hdm_ctrl,CXL_HDM_DECODER0_CTRL ,COMMITTED )) { +return false; + } +if (((uint64_t )host_addr < decoder_base) || + (hpa_offset >= decoder_size)) { + dpa_base += decoder_size / +cxl_interleave_ways_dec (iw, &error_fatal); +continue ; + } - hpa_offset = (uint64_t )host_addr - decoder_base; + *dpa = dpa_base + + ((MAKE_64BIT_MASK (0 ,8 + ig) & hpa_offset) | + ((MAKE_64BIT_MASK (8 + ig + iw,64 -8 - ig - iw) & hpa_offset) + >> iw)); - decoder_size = ((uint64_t )cache_mem[R_CXL_HDM_DECODER0_SIZE_HI ] <<32 ) | - cache_mem[R_CXL_HDM_DECODER0_SIZE_LO ]; -if (hpa_offset >= decoder_size) { -return false; +return true; } - - hdm0_ctrl = cache_mem[R_CXL_HDM_DECODER0_CTRL ]; - iw =FIELD_EX32 (hdm0_ctrl,CXL_HDM_DECODER0_CTRL ,IW ); - ig =FIELD_EX32 (hdm0_ctrl,CXL_HDM_DECODER0_CTRL ,IG ); - - *dpa = (MAKE_64BIT_MASK (0 ,8 + ig) & hpa_offset) | - ((MAKE_64BIT_MASK (8 + ig + iw,64 -8 - ig - iw) & hpa_offset) >> iw); - -return true; +return false; } static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d,
Re: [PATCH 2/2] hw/cxl: Support 4 HDM decoders at all levels of topology
Quoted 10 lines · On Mon, 4 Sep 2023 20:36:02 +0200 Philippe Mathieu-Daudé <[email protected]>…
Hi Jonathan,
Few style comments inlined.
Quoted 5 lines · Jonathan Cameron
Support these decoders in CXL host bridges (pxb-cxl), CXL Switch USP and CXL Type 3 end points.
Signed-off-by Jonathan Cameron <[email protected]>---
Hi Philippe,
Thanks for the particularly quick reviews!
...
Quoted 42 lines
Quoted 24 lines
hw/cxl/cxl-component-utils.c +4
-1@@ -42,6 +42,9 @@ static void dumb_hdm_handler(CXLComponentState *cxl_cstate, hwaddr offset,switch (offset) {case A_CXL_HDM_DECODER0_CTRL : +case A_CXL_HDM_DECODER1_CTRL : +case A_CXL_HDM_DECODER2_CTRL : +case A_CXL_HDM_DECODER3_CTRL : should_commit =FIELD_EX32 (value,CXL_HDM_DECODER0_CTRL ,COMMIT ); should_uncommit = !should_commit;break ;@@ -81,7 +84,7 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value, }if (offset >=A_CXL_HDM_DECODER_CAPABILITY && - offset <=A_CXL_HDM_DECODER0_TARGET_LIST_HI ) { + offset <=A_CXL_HDM_DECODER3_TARGET_LIST_HI ) {dumb_hdm_handler (cxl_cstate, offset, value); }else { cregs->cache_mem_registers[offset /sizeof (*cregs->cache_mem_registers)] = value;hw/cxl/cxl-component-utils.c static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk) · line 167
Quoted 5 lines
hw/cxl/cxl-component-utils.c +1
-1@@ -161,7 +164,7 @@ static void ras_init_common(uint32_t *reg_state, uint32_t *write_msk)static void hdm_init_common (uint32_t *reg_state,uint32_t *write_msk,enum reg_type type) { -int decoder_count =1 ; +int decoder_count =4 ;unsigned decoder_count = HDM_DECODER_COUNT;hw/cxl/cxl-component-utils.c static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, · line 179
Quoted 7 lines
hw/cxl/cxl-component-utils.c +0
-0int i; ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, DECODER_COUNT,@@ -174,19 +177,22 @@ static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, HDM_DECODER_ENABLE, 0); write_msk[R_CXL_HDM_DECODER_GLOBAL_CONTROL ] =0x3 ;for (i =0 ; i < decoder_count; i++) {Alternatively:
Quoted 2 lines
for (i = 0; i < decoder_count; i++, write_msk += 8) {
write_msk[R_CXL_HDM_DECODER0_BASE_LO] = 0xf0000000;That's a bit nasty and fragile given we are offsetting the base register than indexing into it (so applying a later offset).
Quoted 9 lines
hw/cxl/cxl-component-utils.c static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk, · line 180
Quoted 7 lines
hw/cxl/cxl-component-utils.c +1
-5- write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 ] =0xf0000000 ; - write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 ] =0xffffffff ; - write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 ] =0x13ff ; + write_msk[R_CXL_HDM_DECODER0_BASE_LO + i *0x20 /4 ] =0xf0000000 ;(this
0x20/ 4 bugs me a bit).
Instead, I've gone with a local variable which leaves me room for deriving this based on the step between the registers for decoders 0 and 1.
hdm_inc = R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_LO;
I haven't added a define for this because it would probably have to be long enough that it will cause line length problems :(
So it is replicated in a few different places which isn't ideal but definitely better than the 0x20 / 4
Quoted 22 lines
Quoted 21 lines
hw/cxl/cxl-component-utils.c +10
-3+ write_msk[R_CXL_HDM_DECODER0_BASE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i *0x20 /4 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i *0x20 /4 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_CTRL + i *0x20 /4 ] =0x13ff ;if (type ==CXL2_DEVICE || type ==CXL2_TYPE3_DEVICE || type ==CXL2_LOGICAL_DEVICE ) { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xf0000000 ; }else { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 /4 ] = +0xffffffff ; } - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 /4 ] = +0xffffffff ; } }