cxl/type3: minimum MHD cci support
RFC 1/1 cxl/type3: minimum MHD cci support
Implement the MHD GET_INFO cci command and add a shared memory region to the type3 device to host the information.
Add a helper program to initialize this shared memory region.
For now, limit the number of LD's to the number of heads. Later, this limitation will need to be lifted for MH-MLDs.
Intended use case:
1. Create the shared memory region
2. Format the shared memory region
3. Launch QEMU with is_mhd=true,mhd_head=N,mhd_shmid=$shmid
shmid=ipcmk -M 4096 | grep -o -E '[0-9]+' | head -1cxl_mhd_init 4 $shmid
qemu-system-x86_64 \
-nographic \
-accel kvm \
-drive file=./mhd.qcow2,format=qcow2,index=0,media=disk,id=hd \
-m 4G,slots=4,maxmem=8G \
-smp 4 \
-machine type=q35,cxl=on,hmat=on \
-device pxb-cxl,id=cxl.0,bus=pcie.0,bus_nr=52 \
-device cxl-rp,id=rp0,bus=cxl.0,chassis=0,port=0,slot=0 \
-object memory-backend-file,id=mem0,mem-path=/tmp/mem0,size=4G,share=true \
-device cxl-type3,bus=rp0,volatile-memdev=mem0,id=cxl-mem0,sn=66666,is_mhd=true,mhd_head=0,mhd_shmid=$shmid \
-M cxl-fmw.0.targets.0=cxl.0,cxl-fmw.0.size=4G
Comments:
base repo: https://gitlab.com/jic23/qemu
base branch: cxl-2023-07-17
Originally I wanted to add this as a separate CCI, but I realized this wouldn't work as intended because that would require a separate pci/cxl device in /dev/ to tunnel messages though. This is not how this will present on real devices, so I went away from that.
Next I wanted to simply *dynamically* add the command to the existing CCI in the type3 device, but these are statically defined in cxl-mailbox.
I settled for simply adding the cci command to the type 3 device by default, and checking for whether is_mhd is set in the command.
Ultimately, for MHD, they are likely to have a bunch of vendor specific commands associated with them *and* a bunch of vendor specific state. It would be nice to able to have something like "cci_add_command_set()" to the cci-mailbox, and an interface to override certain type3 functions such as read/write (but this is an exercise for a later patch set).
--- hw/cxl/cxl-mailbox-utils.c | 53 +++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 50 +++++++++++++++++++++++++++++ include/hw/cxl/cxl_device.h | 12 +++++++ tools/cxl/cxl_mhd_init.c | 63 +++++++++++++++++++++++++++++++++++++ tools/cxl/meson.build | 3 ++ tools/meson.build | 1 + 6 files changed, 182 insertions(+) create mode 100644 tools/cxl/cxl_mhd_init.c create mode 100644 tools/cxl/meson.build
hw/cxl/cxl-mailbox-utils.c +53 -0
@@ -84,6 +84,8 @@ enum {#define GET_PHYSICAL_PORT_STATE 0x1 TUNNEL = 0x53,#define MANAGEMENT_COMMAND 0x0 + MHD = 0x55, +#define GET_MHD_INFO 0x0 };/* CCI Message Format CXL r3.0 Figure 7-19 */
@@ -1155,6 +1157,56 @@ static CXLRetCode cmd_media_clear_poison(const struct cxl_cmd *cmd,return CXL_MBOX_SUCCESS ; } +static CXLRetCode cmd_mhd_get_info (const struct cxl_cmd *cmd, +uint8_t *payload_in, +size_t len_in, +uint8_t *payload_out, +size_t *len_out, +CXLCCI *cci) +{ +CXLType3Dev *ct3d =CXL_TYPE3 (cci->d); +struct { +uint8_t start_ld; +uint8_t ldmap_len; + } QEMU_PACKED *input = (void *)payload_in; + +struct { +uint8_t nr_lds; +uint8_t nr_heads; +uint16_t resv1; +uint8_t start_ld; +uint8_t ldmap_len; +uint16_t resv2; +uint8_t ldmap[]; + } QEMU_PACKED *output = (void *)payload_out; + +uint8_t start_ld = input->start_ld; +uint8_t ldmap_len = input->ldmap_len; +uint8_t i; + +if (!ct3d->is_mhd) { +return CXL_MBOX_UNSUPPORTED ; + } + +if (start_ld >= ct3d->mhd_state->nr_lds) { +return CXL_MBOX_INVALID_INPUT ; + } + + output->nr_lds = ct3d->mhd_state->nr_lds; + output->nr_heads = ct3d->mhd_state->nr_heads; + output->resv1 =0 ; + output->start_ld = start_ld; + output->resv2 =0 ; + +for (i =0 ; i < ldmap_len && (start_ld + i) < output->nr_lds; i++) { + output->ldmap[i] = ct3d->mhd_state->ldmap[start_ld + i]; + } + output->ldmap_len = i; + + *len_out =sizeof (*output) + output->ldmap_len; +return CXL_MBOX_SUCCESS ; +} +#define IMMEDIATE_CONFIG_CHANGE (1 << 1)#define IMMEDIATE_DATA_CHANGE (1 << 2)#define IMMEDIATE_POLICY_CHANGE (1 << 3)
@@ -1195,6 +1247,7 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = { cmd_media_inject_poison, 8, 0 }, [MEDIA_AND_POISON][CLEAR_POISON] = { "MEDIA_AND_POISON_CLEAR_POISON", cmd_media_clear_poison, 72, 0 }, + [MHD][GET_MHD_INFO] = {"GET_MULTI_HEADED_INFO", cmd_mhd_get_info, 2, 0}, }; static const struct cxl_cmd cxl_cmd_set_sw[256][256] = {
hw/mem/cxl_type3.c +50 -0
80 lines not on this page · raw message
include/hw/cxl/cxl_device.h +12 -0
@@ -406,6 +406,12 @@ typedef struct CXLPoison { typedef QLIST_HEAD(, CXLPoison) CXLPoisonList;#define CXL_POISON_LIST_LIMIT 256 +struct CXLMHD_SharedState { +uint8_t nr_heads; +uint8_t nr_lds; +uint8_t ldmap[]; +}; +struct CXLType3Dev {/* Private */ PCIDevice parent_obj;
@@ -440,6 +446,12 @@ struct CXLType3Dev {unsigned int poison_list_cnt;bool poison_list_overflowed;uint64_t poison_list_overflow_ts; + +/* Multi-headed Device */ +bool is_mhd; +uint32_t mhd_head; +uint32_t mhd_shmid; +struct CXLMHD_SharedState *mhd_state; };#define TYPE_CXL_TYPE3 "cxl-type3"
tools/cxl/cxl_mhd_init.c new file +63 -0
63 lines not on this page · raw message
tools/cxl/meson.build new file +3 -0
@@ -0,0 +1,3 @@ +executable('cxl_mhd_init', files('cxl_mhd_init.c'), + install: true, + install_dir: get_option('libexecdir'))
tools/meson.build +1 -0
@@ -0,0 +1 @@ +subdir('cxl')
Signature · 1 line
2.39.1