Modify CCI cmd sets to be mutable
cover Modify CCI cmd sets to be mutable
This is on top of the proposed CCI changes by Jonathan.
Base repo: https://gitlab.com/jic23/qemu
Base branch: cxl-2023-07-17
A proposal to make the CCI cmd sets full members of their device, and copy the const struct entries instead of referencing them. This would allow child devices to inherit the parent device default behavior, but with the flexibility to override without changing the core device.
This also enables the base device to receive the commands via the same /dev/cxl/XXXX device, simplifying testing.
An example of how one might override/add commands (paraphrased):
instantiating:
-device cxl-type3,bus=rp0,volatile-memdev=mem0,id=cxl-mem0 -device cxl-my-cmds,target=cxl-mem0
simple code:
static const struct cxl_cmd cxl_cmd_set_my_cmds[256][256] = {
[MY_CMDS][GET_INFO] = { "SPECIAL_GET_INFO",
cmd_my_cmds_get_info, 0, 0 },}static void cxl_my_cmds_realize(DeviceState *d, Error **errp)
{
CXL_MyCmds_State *s = CXL_MyCmds(d);
if (object_dynamic_cast(OBJECT(s->target), TYPE_CXL_TYPE3)) {
CXLType3Dev *ct3d = CXL_TYPE3(s->target);
s->type = cxl_type3;
s->cci = &ct3d->cci;
cxl_add_cci_commands(&ct3d->cci, cxl_cmd_set_my_cmds, 512);
return;
}
error_setg(errp, "Unhandled target type for CXL MHDSLD");
}#define TYPE_CXL_Niagara "cxl-my-cmds"
static const TypeInfo cxl_my_cmds_info = {
.name = TYPE_CXL_MyCmds,
.parent = TYPE_CXL_TYPE3,
.class_size = sizeof(struct CXL_MyCmdsClass),
.class_init = cxl_my_cmds_class_init,
.instance_size = sizeof(CXL_MyCmds_State),
.interfaces = (InterfaceInfo[]) {
{ INTERFACE_CXL_DEVICE },
{ INTERFACE_PCIE_DEVICE },
{}
},
};
---
Gregory Price (2):
cxl/mailbox: change CCI cmd set structure to be a member, not a
refernce
cxl/mailbox: interface to add CCI commands to an existing CCI
hw/cxl/cxl-mailbox-utils.c | 37 +++++++++++++++++++++++++++++++++---- include/hw/cxl/cxl_device.h | 4 +++- 2 files changed, 36 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.1
RFC 1/2 cxl/mailbox: change CCI cmd set structure to be a member, not a refernce
This allows devices to have fully customized CCIs, along with complex devices where wrapper devices can override or add additional CCI commands without having to replicate full command structures or pollute a base device with every command that might ever be used.
--- hw/cxl/cxl-mailbox-utils.c | 18 ++++++++++++++---- include/hw/cxl/cxl_device.h | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-)
hw/cxl/cxl-mailbox-utils.c +14 -4
@@ -1373,9 +1373,19 @@ void cxl_init_cci(CXLCCI *cci, size_t payload_max) bg_timercb, cci); } +static void cxl_copy_cci_commands (CXLCCI *cci,const struct cxl_cmd (*cxl_cmds)[256 ]) { +for (int set =0 ; set <256 ; set++) { +for (int cmd =0 ; cmd <256 ; cmd++) { +if (cxl_cmds[set][cmd].handler) { + cci->cxl_cmd_set[set][cmd] = cxl_cmds[set][cmd]; + } + } + } +} +void cxl_initialize_mailbox_swcci (CXLCCI *cci,DeviceState *intf,DeviceState *d,size_t payload_max) { - cci->cxl_cmd_set = cxl_cmd_set_sw; +cxl_copy_cci_commands (cci, cxl_cmd_set_sw); cci->d = d; cci->intf = intf;cxl_init_cci (cci, payload_max);
@@ -1383,7 +1393,7 @@ void cxl_initialize_mailbox_swcci(CXLCCI *cci, DeviceState *intf, DeviceState *dvoid cxl_initialize_mailbox_t3 (CXLCCI *cci,DeviceState *d,size_t payload_max) { - cci->cxl_cmd_set = cxl_cmd_set; +cxl_copy_cci_commands (cci, cxl_cmd_set); cci->d = d;/* No separation for PCI MB as protocol handled in PCI device */
@@ -1398,7 +1408,7 @@ static const struct cxl_cmd cxl_cmd_set_t3_mctp[256][256] = {void cxl_initialize_t3_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf,size_t payload_max) { - cci->cxl_cmd_set = cxl_cmd_set_t3_mctp; +cxl_copy_cci_commands (cci, cxl_cmd_set_t3_mctp); cci->d = d; cci->intf = intf;cxl_init_cci (cci, payload_max);
@@ -1414,7 +1424,7 @@ static const struct cxl_cmd cxl_cmd_set_usp_mctp[256][256] = {void cxl_initialize_usp_mctpcci (CXLCCI *cci,DeviceState *d,DeviceState *intf,size_t payload_max) { - cci->cxl_cmd_set = cxl_cmd_set_usp_mctp; +cxl_copy_cci_commands (cci, cxl_cmd_set_usp_mctp); cci->d = d; cci->intf = intf;cxl_init_cci (cci, payload_max);
include/hw/cxl/cxl_device.h +1 -1
@@ -163,7 +163,7 @@ typedef struct CXLEventLog { } CXLEventLog; typedef struct CXLCCI { - const struct cxl_cmd (*cxl_cmd_set)[256]; + struct cxl_cmd cxl_cmd_set[256][256]; struct cel_log { uint16_t opcode; uint16_t effect;
Signature · 1 line
2.39.1
RFC 2/2 cxl/mailbox: interface to add CCI commands to an existing CCI
In reply to Gregory PriceThis enables wrapper devices to customize the base device's CCI (for example, with custom commands outside the specification) without the need to change the base device.
The also enabled the base device to dispatch those commands without requiring additional driver support.
--- hw/cxl/cxl-mailbox-utils.c | 19 +++++++++++++++++++ include/hw/cxl/cxl_device.h | 2 ++ 2 files changed, 21 insertions(+)
hw/cxl/cxl-mailbox-utils.c +19 -0
@@ -1383,6 +1383,25 @@ static void cxl_copy_cci_commands(CXLCCI *cci, const struct cxl_cmd (*cxl_cmds)[ } } +void cxl_add_cci_commands (CXLCCI *cci,const struct cxl_cmd (*cxl_cmd_set)[256 ],size_t payload_max) +{ + cci->payload_max = payload_max > cci->payload_max ? payload_max : cci->payload_max; +for (int set =0 ; set <256 ; set++) { +for (int cmd =0 ; cmd <256 ; cmd++) { +if (cxl_cmd_set[set][cmd].handler) { +const struct cxl_cmd *c = &cxl_cmd_set[set][cmd]; + cci->cxl_cmd_set[set][cmd] = *c; +struct cel_log *log = + &cci->cel_log[cci->cel_size]; + + log->opcode = (set <<8 ) | cmd; + log->effect = c->effect; + cci->cel_size++; + } + } + } +} +void cxl_initialize_mailbox_swcci (CXLCCI *cci,DeviceState *intf,DeviceState *d,size_t payload_max) {cxl_copy_cci_commands (cci, cxl_cmd_set_sw);
include/hw/cxl/cxl_device.h +2 -0
@@ -297,6 +297,8 @@ void cxl_initialize_mailbox_t3(CXLCCI *cci, DeviceState *d, size_t payload_max);void cxl_initialize_mailbox_swcci (CXLCCI *cci,DeviceState *intf,DeviceState *d,size_t payload_max);void cxl_init_cci (CXLCCI *cci,size_t payload_max); +void cxl_add_cci_commands (CXLCCI *cci,const struct cxl_cmd (*cxl_cmd_set)[256 ], +size_t payload_max); int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd, size_t len_in, uint8_t *pl_in, size_t *len_out, uint8_t *pl_out,
Signature · 1 line
2.39.1