hw/cxl: Support emulating 4 HDM decoders throughout topology
v2 cover hw/cxl: Support emulating 4 HDM decoders throughout topology
v2:
- New patch to push previously static inline functions out of cxl_component.h
- Add the CXL r3.0 expanded set of decoder counts - making it more obviously why a switch function makes sense.
- Use computed difference in HDM1 and HDM0 decoder registers sets instead of 0x20 / 4.
- Style changes suggested by Philippe.
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 (3):
hw/cxl: Push cxl_decoder_count_enc() and cxl_decode_ig() into .c 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 | 30 +++++----- hw/cxl/cxl-component-utils.c | 92 ++++++++++++++++++++++++++---- hw/cxl/cxl-host.c | 65 ++++++++++++++------- hw/mem/cxl_type3.c | 100 +++++++++++++++++++++++---------- 4 files changed, 209 insertions(+), 78 deletions(-)
Signature · 1 line
2.39.2
PATCH v2 1/3 hw/cxl: Push cxl_decoder_count_enc() and cxl_decode_ig() into .c
There is no strong justification for keeping these in the header so push them down into the associated cxl-component-utils.c file.
--- include/hw/cxl/cxl_component.h | 18 ++---------------- hw/cxl/cxl-component-utils.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-)
include/hw/cxl/cxl_component.h +2 -16
@@ -225,26 +225,12 @@ void cxl_component_create_dvsec(CXLComponentState *cxl_cstate, enum reg_type cxl_dev_type, uint16_t length, uint16_t type, uint8_t rev, uint8_t *body); -static inline int cxl_decoder_count_enc (int count) -{ -switch (count) { -case 1 :return 0 ; -case 2 :return 1 ; -case 4 :return 2 ; -case 6 :return 3 ; -case 8 :return 4 ; -case 10 :return 5 ; - } -return 0 ; -} +int cxl_decoder_count_enc (int count);uint8_t cxl_interleave_ways_enc (int iw,Error **errp);uint8_t cxl_interleave_granularity_enc (uint64_t gran,Error **errp); -static inline hwaddr cxl_decode_ig (int ig) -{ -return 1ULL << (ig +8 ); -} +hwaddr cxl_decode_ig (int ig);CXLComponentState *cxl_get_hb_cstate (PCIHostState *hb);bool cxl_get_hb_passthrough (PCIHostState *hb);
hw/cxl/cxl-component-utils.c +18 -0
@@ -13,6 +13,24 @@#include "hw/pci/pci.h" #include "hw/cxl/cxl.h" +int cxl_decoder_count_enc (int count) +{ +switch (count) { +case 1 :return 0 ; +case 2 :return 1 ; +case 4 :return 2 ; +case 6 :return 3 ; +case 8 :return 4 ; +case 10 :return 5 ; + } +return 0 ; +} + +hwaddr cxl_decode_ig (int ig) +{ +return 1ULL << (ig +8 ); +} +static uint64_t cxl_cache_mem_read_reg (void *opaque,hwaddr offset,unsigned size) {
Signature · 1 line
2.39.2
Re: [PATCH v2 1/3] hw/cxl: Push cxl_decoder_count_enc() and cxl_decode_ig() into .c
Quoted 9 lines · Jonathan Cameron
There is no strong justification for keeping these in the header so push them down into the associated
cxl-component-utils.cfile.Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Jonathan Cameron <[email protected]>--- include/hw/cxl/cxl_component.h | 18 ++---------------- hw/cxl/cxl-component-utils.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-)
PATCH v2 2/3 hw/cxl: Add utility functions decoder interleave ways and target count.
In reply to Jonathan CameronAs an encoded version of these key configuration parameters is available in a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Whilst here update the _enc() function to include additional values as defined in the CXL 3.0 specification. Whilst they are not currently used in the emulation, they may be in future and it is easier to compare with the specification if all values are covered.
---
v2: Thanks to Philippe Mathieu-Daudé
- Expand both enc() and dec() functions to include full set of values defined in CXL r3.0
- Pushed implementation down into the .c file.
--- include/hw/cxl/cxl_component.h | 2 ++ hw/cxl/cxl-component-utils.c | 59 ++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-)
include/hw/cxl/cxl_component.h +2 -0
@@ -226,8 +226,10 @@ void cxl_component_create_dvsec(CXLComponentState *cxl_cstate, uint16_t type, uint8_t rev, uint8_t *body);int cxl_decoder_count_enc (int count); +int cxl_decoder_count_dec (int enc_cnt);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);hwaddr cxl_decode_ig (int ig);
hw/cxl/cxl-component-utils.c +53 -6
74 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v2 2/3] hw/cxl: Add utility functions decoder interleave ways and target count.
Quoted 15 lines · Jonathan Cameron
As an encoded version of these key configuration parameters is available in a register, provide functions to extract it again so as to avoid the need for duplicating the storage.
Whilst here update the
_enc()function to include additional values as defined in the CXL 3.0 specification. Whilst they are not currently used in the emulation, they may be in future and it is easier to compare with the specification if all values are covered.Signed-off-by Jonathan Cameron <[email protected]>---
v2: Thanks to Philippe Mathieu-Daudé
- Expand bothenc()anddec()functions to include full set of values defined in CXL r3.0
- Pushed implementation down into the .c file.
Quoted 4 lines
--- include/hw/cxl/cxl_component.h | 2 ++ hw/cxl/cxl-component-utils.c | 59 ++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-)
Hoping the values match the "CXL r3.0 Section 8.2.4.19.1 CXL HDM Decoder Capability Register":
PATCH v2 3/3 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.
--- include/hw/cxl/cxl_component.h | 10 ++++ hw/cxl/cxl-component-utils.c | 27 +++++---- hw/cxl/cxl-host.c | 65 ++++++++++++++------- hw/mem/cxl_type3.c | 100 +++++++++++++++++++++++---------- 4 files changed, 140 insertions(+), 62 deletions(-)
include/hw/cxl/cxl_component.h +10 -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 )
@@ -147,7 +151,13 @@ REG32(CXL_HDM_DECODER_GLOBAL_CONTROL, CXL_HDM_REGISTERS_OFFSET + 4) FIELD(CXL_HDM_DECODER_GLOBAL_CONTROL, POISON_ON_ERR_EN, 0, 1)FIELD (CXL_HDM_DECODER_GLOBAL_CONTROL ,HDM_DECODER_ENABLE ,1 ,1 ) +/* Support 4 decoders at all levels of topology */ +#define CXL_HDM_DECODER_COUNT 4 +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 +17 -10
@@ -90,6 +90,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 ;
@@ -129,7 +132,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;
@@ -209,7 +212,8 @@ 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 =CXL_HDM_DECODER_COUNT ; +int hdm_inc =R_CXL_HDM_DECODER1_BASE_LO -R_CXL_HDM_DECODER0_BASE_LO ;int i; ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, DECODER_COUNT,
@@ -222,19 +226,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 * hdm_inc] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_BASE_HI + i * hdm_inc] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_SIZE_LO + i * hdm_inc] =0xf0000000 ; + write_msk[R_CXL_HDM_DECODER0_SIZE_HI + i * hdm_inc] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_CTRL + i * hdm_inc] =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 * hdm_inc] = +0xf0000000 ; }else { - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i * hdm_inc] = +0xffffffff ; } - write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i *0x20 ] =0xffffffff ; + write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_HI + i * hdm_inc] = +0xffffffff ; } }
hw/cxl/cxl-host.c +44 -21
77 lines not on this page · raw message
hw/mem/cxl_type3.c +69 -31
145 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v2 3/3] hw/cxl: Support 4 HDM decoders at all levels of topology
Quoted 10 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]>--- include/hw/cxl/cxl_component.h | 10 ++++ hw/cxl/cxl-component-utils.c | 27 +++++---- hw/cxl/cxl-host.c | 65 ++++++++++++++------- hw/mem/cxl_type3.c | 100 +++++++++++++++++++++++---------- 4 files changed, 140 insertions(+), 62 deletions(-)
If you ever have to respin, please split the 'hdm_inc' introduction in a preliminary patch, to reduce the number of changes and the probability of missing a bug.
Re: [PATCH v2 3/3] hw/cxl: Support 4 HDM decoders at all levels of topology
Quoted 12 lines · On Thu, 7 Sep 2023 14:41:16 +0200 Philippe Mathieu-Daudé <[email protected]>…
Quoted 10 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]>--- include/hw/cxl/cxl_component.h | 10 ++++ hw/cxl/cxl-component-utils.c | 27 +++++---- hw/cxl/cxl-host.c | 65 ++++++++++++++------- hw/mem/cxl_type3.c | 100 +++++++++++++++++++++++---------- 4 files changed, 140 insertions(+), 62 deletions(-)
Quoted 4 lines
If you ever have to respin, please split the '
hdm_inc' introduction in a preliminary patch, to reduce the number of changes and the probability of missing a bug.
I didn't do this originally because it's a bit interleaved with the other changes. I can make this separable by adding the register definitions for HDM decoder 1 and a note that it's only used for offset calcs.
I've also pushed it into various other functions that before the other changes in here don't attempt to deal with multiple hdm decoders at all.
Didn't end up looking too bad.
Whilst changing this, I noticed a bug where in one place the encoded version of the hdm count was being used undecoded. So all good in the end :)
Jonathan