hw/{cxl,i386,arm}: PoC: Emulated MCTP over I2C for CXL Fabric / Device management
cover hw/{cxl,i386,arm}: PoC: Emulated MCTP over I2C for CXL Fabric / Device management
Not intended for merge in anything like current form!
CC list is a bit random and I'll admit I added a few people just to make them groan.
Depends on patches 1 and 2 from.
[PATCH v2 0/3] hw/{i2c, nvme}: mctp endpoint, nvme management interface model.
Based-on: Message-ID: [email protected] Arm parts also need the out of tree ARM64 cxl patches. Generally working with the kernel CXL stack requires event emulation.
A git tree with this near the top and all prereqs is available at:
http://gitlab.com/jic23/qemu cxl-2023-05-25
Just over a year ago (yikes) I posted [RFC PATCH 0/2] CXL FMAPI interface over MCTP/I2C
https://lore.kernel.org/linux-cxl/[email protected]/
Since that time I've had a number of questions about how to build on that PoC to enable control of actual CXL devices.
The fundamental problem at that stage was the PoC only worked with device tree bindings and the rest of CXL software assumes ACPI (adding DT support for CXL in general is a long term project). So this series attempts to 'solve' that.
Currently I'm only aware of one emulated I2C controller with the right characteristics to be able to support MCTP over I2C - aspeed-i2c. So lets add that to the main architectures we care about for CXL:
- ARM64 (on top of my out of tree support github.com/jic23/qemu)
- X86 - yup I just added an aspeed-i2c controller to pc :)
The actual emulated device has been rebased on Klaus Jensen's work for the nvme-mi which massively reduces the amount of boilerplate / state machine handling that needs to be done in this emulation. (great work btw Klaius!)
So how to use this:
For ACPI you need the kernel patches from:
https://lore.kernel.org/linux-cxl/[email protected]/T/#u
To make the aspeed i2c controller play nicely with PRP0001 based ACPI description.
Example qemu command line - stripped back to include only relevant bits
qemu-system-x86_64 -M q35,cxl=on -m 4g,maxmem=8G,slots=8 -cpu max -smp 4 \
...
-object memory-backend-file,id=cxl-mem1,share=on,mem-path=/tmp/cxltest.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-mem2,share=on,mem-path=/tmp/cxltest2.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-mem3,share=on,mem-path=/tmp/cxltest3.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa1,share=on,mem-path=/tmp/lsa.raw,size=1M,align=1M \
-object memory-backend-file,id=cxl-lsa2,share=on,mem-path=/tmp/lsa2.raw,size=1M,align=1M \
-object memory-backend-file,id=cxl-lsa3,share=on,mem-path=/tmp/lsa3.raw,size=1M,align=1M \
-object memory-backend-file,id=cxl-mem5,share=on,mem-path=/tmp/cxltest5.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-mem6,share=on,mem-path=/tmp/cxltest6.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-mem7,share=on,mem-path=/tmp/cxltest7.raw,size=256M,align=256M \
-object memory-backend-file,id=cxl-lsa5,share=on,mem-path=/tmp/lsa5.raw,size=1M,align=1M \
-object memory-backend-file,id=cxl-lsa6,share=on,mem-path=/tmp/lsa6.raw,size=1M,align=1M \
-object memory-backend-file,id=cxl-lsa7,share=on,mem-path=/tmp/lsa7.raw,size=1M,align=1M \
-device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
-device cxl-rp,port=0,bus=cxl.1,id=root_port0,chassis=0,slot=2 \
-device cxl-rp,port=1,bus=cxl.1,id=root_port2,chassis=0,slot=3 \
-device cxl-upstream,port=33,bus=root_port0,id=us0,multifunction=on,addr=0.0,sn=12345678 \
-device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \
-device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \
-device cxl-downstream,port=2,bus=us0,id=swport2,chassis=0,slot=6 \
-device cxl-type3,bus=swport0,persistent-memdev=cxl-mem1,id=cxl-pmem0,lsa=cxl-lsa1,sn=3 \
-device cxl-type3,bus=swport1,persistent-memdev=cxl-mem2,id=cxl-pmem1,lsa=cxl-lsa2,sn=4 \
-device cxl-type3,bus=swport2,persistent-memdev=cxl-mem3,id=cxl-pmem2,lsa=cxl-lsa3,sn=5 \
-machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=1k \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=4,target=us0 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=5,target=cxl-pmem0 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=6,target=cxl-pmem1 \
-device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=7,target=cxl-pmem2 \
Install the MCTP daemon from:
https://github.com/CodeConstruct/mctp
Bring up and enumerate the MCTP EPs:
# Bring up the link
mctp link set mctpi2c0 up
# Assign an address to the aspeed-i2c controller
mctp addr add 50 dev mctpi2c0
# Assign a neetwork ID to the link (11)
mctp link set mctpi2c0 net 11
# Start the daemon that uses dbus for configuration.
systemctl start mctpd.service
# Assign EIDs to the EPs
busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeConstruct.MCTP AssignEndpoint say mctpi2c0 1 0x4 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeConstruct.MCTP AssignEndpoint say mctpi2c0 1 0x5 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeConstruct.MCTP AssignEndpoint say mctpi2c0 1 0x6 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeConstruct.MCTP AssignEndpoint say mctpi2c0 1 0x7
# Check it worked by dumping some state.
busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/8 xyz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/9 xyz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/10 xyz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/11 xyz.openbmc_project.MCTP.Endpoint
Use the following test program to poke them
./test 8 etc (address will be printed out during configuration above, but usually starts at 8)
From 14ac4ad4eb97bd0536c332f08c639f980c280b93 Mon Sep 17 00:00:00 2001
From: Jonathan Cameron <[email protected]>
Date: Thu, 25 May 2023 11:36:36 +0100
Subject: [PATCH] Trivial MCTP CXL CCI test prog
--- cxl_fmapi.h | 72 +++++++++++ mctp.h | 68 ++++++++++ test.c | 361 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 501 insertions(+) create mode 100644 cxl_fmapi.h create mode 100644 mctp.h create mode 100644 test.c
cxl_fmapi.h new file +72 -0
@@ -0,0 +1,72 @@ + +#include <stdint.h> + +#define CXL_CCI_CMD_SET_INFO 0x0 +#define CXL_IDENTIFY 0x0 +#define CXL_FM_API_CMD_SET_PHYSICAL_SWITCH 0x51 +#define CXL_IDENTIFY_SWITCH_DEVICE 0x00 +#define CXL_GET_PHYSICAL_PORT_STATE 0x01 + +struct cxl_fmapi_header { +#define CXL_MCTP_CATEGORY_REQ 0 +#define CXL_MCTP_CATEGORY_RESP 1 +uint8_t category; +uint8_t tag; +uint8_t rsv1; +uint8_t command; +uint8_t command_set; +uint8_t pl_length[3 ];/* 20 bit little endian, BO bit at bit 23 */ +uint16_t return_code; +uint16_t vendor_ext_status; +} __attribute__ ((packed)); + +struct cxl_cci_infostat_identify_resp_pl { +uint16_t vendor_id; +uint16_t device_id; +uint16_t subsys_vendor_id; +uint16_t subsys_id; +uint8_t serial_num[8 ]; +uint8_t max_msg; +uint8_t component_type; +} __attribute__((packed)); + +struct cxl_fmapi_ident_switch_dev_resp_pl { +uint8_t ingres_port_id; +uint8_t rsv1; +uint8_t num_physical_ports; +uint8_t num_vcs; +uint8_t active_port_bitmask[32 ]; +uint8_t active_vcs_bitmask[32 ]; +uint16_t num_total_vppb; +uint16_t num_active_vppb; +} __attribute__((packed)); + +struct cxl_fmapi_get_phys_port_state_req_pl { +uint8_t num_ports;/* CHECK. may get too large for MCTP message size */ +uint8_t ports[]; +} __attribute__((packed)); + +struct cxl_fmapi_port_state_info_block { +uint8_t port_id; +uint8_t config_state; +uint8_t connected_device_cxl_version; +uint8_t rsv1; +uint8_t connected_device_type; +uint8_t port_cxl_version_bitmask; +uint8_t max_link_width; +uint8_t negotiated_link_width; +uint8_t supported_link_speeds_vector; +uint8_t max_link_speed; +uint8_t current_link_speed; +uint8_t ltssm_state; +uint8_t first_lane_num; +uint16_t link_state; +uint8_t supported_ld_count; +} __attribute__((packed)); + +struct cxl_fmapi_get_phys_port_state_resp_pl { +uint8_t num_ports; +uint8_t rsv1[3 ]; +struct cxl_fmapi_port_state_info_block ports[]; +} __attribute__((packed)); +
mctp.h new file +68 -0
68 lines not on this page · raw message
test.c new file +361 -0
361 lines not on this page · raw message
Signature · 35 lines
2.39.2
Jonathan Cameron (6):
hw/acpi/aml-build: add function for i2c slave device serial bus
description
HACK: arm/virt: Add aspeed-i2c controller and MCTP EP to enable MCTP
testing
HACK: hw/arm/virt: Add ACPI support for aspeed-i2c / mctp
HACK: hw/i386/pc: Add Aspeed i2c controller + MCTP with ACPI tables
misc/i2c_mctp_cxl: Initial device emulation
docs: cxl: Add example commandline for MCTP CXL CCIs
docs/system/devices/cxl.rst | 27 +++
include/hw/acpi/aml-build.h | 1 +
include/hw/arm/virt.h | 2 +
include/hw/cxl/cxl_fmapi.h | 102 ++++++++++
include/hw/i386/pc.h | 1 +
hw/acpi/aml-build.c | 17 ++
hw/arm/virt-acpi-build.c | 60 ++++++
hw/arm/virt.c | 92 ++++++++-
hw/cxl/i2c_mctp_cxl.c | 369 ++++++++++++++++++++++++++++++++++++
hw/i386/acpi-build.c | 65 +++++++
hw/i386/pc.c | 20 +-
hw/arm/Kconfig | 2 +
hw/cxl/Kconfig | 3 +
hw/cxl/meson.build | 1 +
hw/i2c/meson.build | 2 +-
hw/i386/Kconfig | 2 +
hw/misc/meson.build | 1 +
17 files changed, 762 insertions(+), 5 deletions(-)
create mode 100644 include/hw/cxl/cxl_fmapi.h
create mode 100644 hw/cxl/i2c_mctp_cxl.c
--
2.39.2RFC PATCH 1/6 hw/acpi/aml-build: add function for i2c slave device serial bus description
--- include/hw/acpi/aml-build.h | 1 + hw/acpi/aml-build.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/hw/acpi/aml-build.h +1 -0
@@ -382,6 +382,7 @@ Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel);Aml *aml_sleep (uint64_t msec);Aml *aml_i2c_serial_bus_device (uint16_t address,const char *resource_source); +Aml *aml_i2c_slv_serial_bus_device (uint16_t address,const char *resource_source);/* Block AML object primitives */ Aml *aml_scope (const char *name_format, ...)G_GNUC_PRINTF (1 ,2 );
hw/acpi/aml-build.c +17 -0
@@ -2478,3 +2478,20 @@ Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source)return var; } + +/* ACPI 5.0: 6.4.3.8.2.1 I2C Serial Bus Connection Resource Descriptor */ +Aml *aml_i2c_slv_serial_bus_device (uint16_t address,const char *resource_source) +{ +uint16_t resource_source_len =strlen (resource_source) +1 ; +Aml *var =aml_serial_bus_device (AML_SERIAL_BUS_TYPE_I2C ,1 ,0 ,1 , +6 , resource_source_len); + +/* Connection Speed. Just set to 100K for now, it doesn't really matter. */ +build_append_int_noprefix (var->buf,100000 ,4 ); +build_append_int_noprefix (var->buf, address,sizeof (address)); + +/* This is a string, not a name, so just copy it directly in. */ +g_array_append_vals (var->buf, resource_source, resource_source_len); + +return var; +}
Signature · 1 line
2.39.2
RFC PATCH 2/6 HACK: arm/virt: Add aspeed-i2c controller and MCTP EP to enable MCTP testing
In reply to Jonathan CameronAs the only I2C emulation in QEMU that supports being both a master and a slave, suitable for MCTP over i2c is aspeed-i2c add this controller to the arm virt model and hook up our new i2c_mctp_cxl_fmapi device.
The current Linux driver for aspeed-i2c has a hard requirement on a reset controller. Throw down the simplest reset controller I could find so as to avoid need to make any changes to the kernel code.
Patch also builds appropriate device tree.
--- include/hw/arm/virt.h | 2 + hw/arm/virt.c | 92 +++++++++++++++++++++++++++++++++++++++++-- hw/arm/Kconfig | 1 + 3 files changed, 92 insertions(+), 3 deletions(-)
include/hw/arm/virt.h +2 -0
@@ -72,6 +72,8 @@ enum {VIRT_SMMU ,VIRT_UART ,VIRT_MMIO , +VIRT_I2C , +VIRT_RESET_FAKE ,VIRT_RTC ,VIRT_FW_CFG , VIRT_PCIE,
hw/arm/virt.c +89 -3
122 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -32,6 +32,7 @@ config ARM_VIRT select VIRTIO_MEM_SUPPORTED select ACPI_CXL select ACPI_HMAT + select I2C_MCTP_CXL_FMAPI config CHEETAH bool
Signature · 1 line
2.39.2
RFC PATCH 3/6 HACK: hw/arm/virt: Add ACPI support for aspeed-i2c / mctp
In reply to Jonathan CameronEnable this for FM-API testing for CXL devices via MCTP over I2C
Example DSDT block:
Device (MCTP)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x03)
{
Package (0x02)
{
"compatible",
"aspeed,ast2600-i2c-bus"
},
Package (0x02)
{
"bus-frequency",
0x00061A80
},
Package (0x02)
{
"mctp-controller",
One
}
}
})
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
Memory32Fixed (ReadWrite,
0x0B000080, // Address Base
0x00000080, // Address Length
)
Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive, ,, )
{
0x0000002A,
}
})
}
Device (MCTS)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
I2cSerialBusV2 (0x0050, DeviceInitiated, 0x000186A0,
AddressingMode7Bit, "\\_SB.MCTP",
0x00, ResourceProducer, , Exclusive,
)
})
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x01)
{
Package (0x02)
{
"compatible",
"mctp-i2c-controller"
}
}
})
}Tests not updated given I'm not currently proposing this for upstream.
--- hw/arm/virt-acpi-build.c | 60 ++++++++++++++++++++++++++++++++++++++++ hw/i2c/meson.build | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +60 -0
@@ -77,6 +77,65 @@ static void acpi_dsdt_add_cpus(Aml *scope, VirtMachineState *vms) } } +static void acpi_dsdt_add_mctp (Aml *scope,VirtMachineState *vms) +{ +uint32_t interrupt = vms->irqmap[VIRT_I2C ] +ARM_SPI_BASE ; +Aml *main_dev =aml_device ("MCTP" ); +Aml *sub_dev =aml_device ("MCTS" ); +Aml *dsd_pkg =aml_package (2 ); +Aml *props_pkg =aml_package (3 ); +Aml *pkg =aml_package (2 ); +Aml *crs =aml_resource_template (); + +aml_append (main_dev,aml_name_decl ("_HID" ,aml_string ("PRP0001" ))); + +aml_append (pkg,aml_string ("compatible" )); +aml_append (pkg,aml_string ("aspeed,ast2600-i2c-bus" )); +aml_append (props_pkg, pkg); + + pkg =aml_package (2 ); +aml_append (pkg,aml_string ("bus-frequency" )); +aml_append (pkg,aml_int (400000 )); +aml_append (props_pkg, pkg); + + pkg =aml_package (2 ); +aml_append (pkg,aml_string ("mctp-controller" )); +aml_append (pkg,aml_int (1 )); +aml_append (props_pkg, pkg); + +aml_append (dsd_pkg,aml_touuid ("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301" )); +aml_append (dsd_pkg, props_pkg); +aml_append (main_dev,aml_name_decl ("_DSD" , dsd_pkg)); + +aml_append (crs,aml_memory32_fixed (vms->memmap[VIRT_I2C ].base +0x80 , +0x80 ,AML_READ_WRITE )); +aml_append (crs, +aml_interrupt (AML_CONSUMER ,AML_LEVEL ,AML_ACTIVE_HIGH , +AML_EXCLUSIVE , &interrupt,1 )); +aml_append (main_dev,aml_name_decl ("_CRS" , crs)); + +aml_append (sub_dev,aml_name_decl ("_HID" ,aml_string ("PRP0001" ))); + + dsd_pkg =aml_package (2 ); +aml_append (dsd_pkg,aml_touuid ("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301" )); + + props_pkg =aml_package (1 ); + + pkg =aml_package (2 ); +aml_append (pkg,aml_string ("compatible" )); +aml_append (pkg,aml_string ("mctp-i2c-controller" )); +aml_append (props_pkg, pkg); +aml_append (dsd_pkg, props_pkg); + + crs =aml_resource_template (); +aml_append (crs,aml_i2c_slv_serial_bus_device (0x50 ,"\\_SB.MCTP" )); +aml_append (sub_dev,aml_name_decl ("_CRS" , crs)); +aml_append (sub_dev,aml_name_decl ("_DSD" , dsd_pkg)); + +aml_append (scope, main_dev); +aml_append (scope, sub_dev); +} +static void acpi_dsdt_add_uart (Aml *scope,const MemMapEntry *uart_memmap,uint32_t uart_irq) {
@@ -887,6 +946,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)*/ scope =aml_scope ("\\_SB" );acpi_dsdt_add_cpus (scope, vms); +acpi_dsdt_add_mctp (scope, vms);acpi_dsdt_add_uart (scope, &memmap[VIRT_UART ], (irqmap[VIRT_UART ] +ARM_SPI_BASE ));if (vmc->acpi_expose_flash) {
hw/i2c/meson.build +1 -1
@@ -4,7 +4,7 @@ i2c_ss.add(when: 'CONFIG_MCTP_I2C', if_true: files('mctp.c')) i2c_ss.add(when: 'CONFIG_SMBUS', if_true: files('smbus_slave.c', 'smbus_master.c')) i2c_ss.add(when: 'CONFIG_ACPI_SMBUS', if_true: files('pm_smbus.c')) i2c_ss.add(when: 'CONFIG_ACPI_ICH9', if_true: files('smbus_ich9.c')) -i2c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i2c.c')) +i2c_ss.add(when: 'CONFIG_I2C', if_true: files('aspeed_i2c.c')) i2c_ss.add(when: 'CONFIG_BITBANG_I2C', if_true: files('bitbang_i2c.c')) i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c'))
Signature · 1 line
2.39.2
RFC PATCH 4/6 HACK: hw/i386/pc: Add Aspeed i2c controller + MCTP with ACPI tables
In reply to Jonathan CameronCXL devices provide a standard Fabric Management API - FM-API. See CXL specification r3.0 from https://www.computeexpresslink.org
In many real setups that will be used by a separate host from the one actually using the CXL devices (BMC or similar) but it is helpful to be able to use the main CXL emulation and the Fabric Management emulation on a single host. This 'hack' enables that (with minor kernel driver changes).
There are many many things wrong with how this is done but for now it enables use of this aspeed controller with ACPI FW on an x86 host. That is useful for testing MCTP over I2C.
If anyone has either:
1) Docs for an I2C controller with MCTP support that might actually appear on an x86 host.
2) A nice solution for how wrap this up in a device whilst minimising kernel changes.
3) A guide / reference example to how to do the interrupt 'right' (I'm an ARM focused developer so got lost in the x86 interrupt
stuff).
then let me know.
For now this works and I will carry it out of tree on gitlab.com/jic23/qemu.
DSDT blob - as this is a hack I haven't included test updates
Scope (_SB)
{
Device (MCTP)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x03)
{
Package (0x02)
{
"compatible",
"aspeed,ast2600-i2c-bus"
},
Package (0x02)
{
"bus-frequency",
0x00061A80
},
Package (0x02)
{
"mctp-controller",
One
}
}
})
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
0x0000000000000000, // Granularity
0x00000004800FC080, // Range Minimum
0x00000004800FC0FF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000000000000080, // Length
,, , AddressRangeMemory, TypeStatic)
Interrupt (ResourceConsumer, Level, ActiveHigh, Shared, ,, )
{
0x00000007,
}
})
}
Device (MCTS)
{
Name (_HID, "PRP0001") // _HID: Hardware ID
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
I2cSerialBusV2 (0x0050, DeviceInitiated, 0x000186A0,
AddressingMode7Bit, "\\_SB.MCTP",
0x00, ResourceProducer, , Exclusive,
)
})
Name (_DSD, Package (0x02) // _DSD: Device-Specific Data
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x01)
{
Package (0x02)
{
"compatible",
"mctp-i2c-controller"
}
}
})
}
}To add devices to the bus use something like:
-device i2c_mctp_cxl_switch,bus=aspeed.i2c.bus.0,address=4,target=us0
--- include/hw/i386/pc.h | 1 + hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ hw/i386/pc.c | 20 +++++++++++++- hw/i386/Kconfig | 1 + 4 files changed, 86 insertions(+), 1 deletion(-)
include/hw/i386/pc.h +1 -0
@@ -56,6 +56,7 @@ typedef struct PCMachineState {SGXEPCState sgx_epc;CXLState cxl_devices_state; +hwaddr i2c_base; } PCMachineState;#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
hw/i386/acpi-build.c +65 -0
77 lines not on this page · raw message
hw/i386/pc.c +19 -1
@@ -95,6 +95,7 @@#include "hw/i386/kvm/xen_gnttab.h" #include "hw/i386/kvm/xen_xenstore.h" #include "hw/mem/memory-device.h" +#include "hw/i2c/aspeed_i2c.h" #include "sysemu/replay.h" #include "target/i386/cpu.h" #include "e820_memory_layout.h"
@@ -1083,6 +1084,8 @@ void pc_memory_init(PCMachineState *pcms,memory_region_init (mr,OBJECT (machine),"cxl_host_reg" , cxl_size);memory_region_add_subregion (system_memory, cxl_base, mr); cxl_resv_end = cxl_base + cxl_size; + pcms->i2c_base = cxl_resv_end -0x4000 ; +if (pcms->cxl_devices_state.fixed_windows) {hwaddr cxl_fmw_base;GList *it;
@@ -1166,7 +1169,7 @@ uint64_t pc_pci_hole64_start(void)ram_addr_t size =0 ;if (pcms->cxl_devices_state.is_enabled) { - hole64_start =pc_get_cxl_range_end (pcms); + hole64_start =pc_get_cxl_range_end (pcms) +0x4000 ; }else if (pcmc->has_reserved_memory && (ms->ram_size < ms->maxram_size)) {pc_get_device_memory_range (pcms, &hole64_start, &size);if (!pcmc->broken_reserved_end) {
@@ -1360,6 +1363,21 @@ void pc_basic_device_init(struct PCMachineState *pcms,/* Super I/O */ pc_superio_init (isa_bus, create_fdctrl, pcms->i8042_enabled, pcms->vmport !=ON_OFF_AUTO_ON ); + + { +AspeedI2CState *aspeed_i2c; +struct DeviceState *dev; + + dev =qdev_new ("aspeed.i2c-ast2600" ); + aspeed_i2c =ASPEED_I2C (dev); +object_property_set_link (OBJECT (dev),"dram" , +OBJECT (MACHINE (pcms)->ram), &error_fatal); +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , pcms->i2c_base); +/* Hack ;) - Steal unused interrupt 7 */ +sysbus_connect_irq (SYS_BUS_DEVICE (&aspeed_i2c->busses[0 ]),0 , + x86ms->gsi[7 ]); + } }void pc_nic_init (PCMachineClass *pcmc,ISABus *isa_bus,PCIBus *pci_bus)
hw/i386/Kconfig +1 -0
@@ -45,6 +45,7 @@ config PC select ACPI_VMGENID select VIRTIO_PMEM_SUPPORTED select VIRTIO_MEM_SUPPORTED + select I2C_MCTP_CXL_FMAPI config PC_PCI bool
Signature · 1 line
2.39.2
RFC PATCH 5/6 misc/i2c_mctp_cxl: Initial device emulation
In reply to Jonathan CameronThe CCI and Fabric Manager APIs are used to configure CXL switches and devices. DMTF has defined an MCTP binding specification to carry these messages. The end goal of this work is to hook this up to emulated CXL switches and devices to allow control of the configuration.
--- include/hw/cxl/cxl_fmapi.h | 102 ++++++++++ hw/cxl/i2c_mctp_cxl.c | 369 +++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 3 +- hw/cxl/Kconfig | 3 + hw/cxl/meson.build | 1 + hw/i386/Kconfig | 3 +- hw/misc/meson.build | 1 + 7 files changed, 480 insertions(+), 2 deletions(-)
include/hw/cxl/cxl_fmapi.h new file +102 -0
@@ -0,0 +1,102 @@ +/* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* CXL Fabric Manager API definitions +* +* Copyright (c) 2023 Huawei Technologies. +* +* Refs to: Compute Express Link (CXL) Specification revision 3.0 Version 1.0 +* from www.computeexpresslink.org +* +* FM-API commands can be carried over various transports (MCTP, switch-CCI etc) +* so define the payloads in a common header. +*/ + +#ifndef CXL_FMAPI_H +#define CXL_FMAPI_H + +#include "qemu/osdep.h" + +/* +* TODO: Confirm which commands sent via FM-API binding and which via Type 3 CCI +* binding. For now I'm assuming only stuff in the FM-API table goes via +* FM-API. +*/ + +/* +* CXL r3.0 Table 8-36 Generic Component Command Opcodes +*/ + +/* CXL r3.0 8.2.9.1.1 Identify (Opcode 0001h) */ +#define CXL_CCI_CMD_SET_INFOSTAT 0x00 +#define CXL_CCI_INFOSTAT_IDENTIFY 0x01 + +struct cxl_cci_infostat_identify_resp_pl { +uint16_t vendor_id; +uint16_t device_id; +uint16_t subsystem_vendor_id; +uint16_t subsystem_id; +uint8_t serial_num[8 ]; +uint8_t max_msg; +uint8_t component_type; +}; + +/* +* CXL r3.0 7.6.7 Fabric Management Application Programming Interface +*/ +#define CXL_FMAPI_CMD_SET_PHYSICAL_SWITCH 0x51 +#define CXL_FMAPI_PHYSICAL_SWITCH_IDENTIFY_SWITCH 0x00 +#define CXL_FMAPI_GET_PHYSICAL_PORT_STATE 0x01 + +/* +* CXL r3.0 7.6.7.1.1 Identify Switch Device (Opcode 5100h) +*/ +struct cxl_fmapi_ident_switch_dev_resp_pl { +uint8_t ingres_port_id; +uint8_t rsv1; +uint8_t num_physical_ports; +uint8_t num_vcs; +uint8_t active_port_bitmask[32 ]; +uint8_t active_vcs_bitmask[32 ]; +uint16_t num_total_vppb; +uint16_t num_active_vppb; +uint8_t num_hdm_decoders; +}QEMU_PACKED ; + +/* +* CXL r3.0 7.6.7.1.2 Get Physical Port State (Opcode 5101h) +*/ + +/* CXL r3.0 Table 7-18 Get Physical Port State Request Payload */ +struct cxl_fmapi_get_phys_port_state_req_pl { +uint8_t num_ports;/* CHECK. may get too large for MCTP message size */ +uint8_t ports[]; +}QEMU_PACKED ; + +/* CXL r3.0 Table 7-20 Get Physical Port State Port Information Block Format */ +struct cxl_fmapi_port_state_info_block { +uint8_t port_id; +uint8_t config_state; +uint8_t connected_device_cxl_version; +uint8_t rsv1; +uint8_t connected_device_type; +uint8_t port_cxl_version_bitmask; +uint8_t max_link_width; +uint8_t negotiated_link_width; +uint8_t supported_link_speeds_vector; +uint8_t max_link_speed; +uint8_t current_link_speed; +uint8_t ltssm_state; +uint8_t first_lane_num; +uint16_t link_state; +uint8_t supported_ld_count; +}QEMU_PACKED ; + +/* CXL r3.0 Table 7-19 Get Physical Port State Response Payload */ +struct cxl_fmapi_get_phys_port_state_resp_pl { +uint8_t num_ports; +uint8_t rsv1[3 ]; +struct cxl_fmapi_port_state_info_block ports[]; +}QEMU_PACKED ; + +#endif /* CXL_FMAPI_H */
hw/cxl/i2c_mctp_cxl.c new file +369 -0
369 lines not on this page · raw message
hw/arm/Kconfig +2 -1
@@ -32,7 +32,8 @@ config ARM_VIRT select VIRTIO_MEM_SUPPORTED select ACPI_CXL select ACPI_HMAT - select I2C_MCTP_CXL_FMAPI + select MCTP_I2C + select I2C_MCTP_CXL config CHEETAH bool
hw/cxl/Kconfig +3 -0
@@ -1,3 +1,6 @@ config CXL bool default y if PCI_EXPRESS + +config I2C_MCTP_CXL + bool
hw/cxl/meson.build +1 -0
@@ -12,5 +12,6 @@ softmmu_ss.add(when: 'CONFIG_CXL', if_false: files( 'cxl-host-stubs.c', )) +softmmu_ss.add(when: 'CONFIG_I2C_MCTP_CXL', if_true: files('i2c_mctp_cxl.c')) softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('cxl-host-stubs.c'))
hw/i386/Kconfig +2 -1
@@ -45,7 +45,8 @@ config PC select ACPI_VMGENID select VIRTIO_PMEM_SUPPORTED select VIRTIO_MEM_SUPPORTED - select I2C_MCTP_CXL_FMAPI + select MCTP_I2C + select I2C_MCTP_CXL config PC_PCI bool
hw/misc/meson.build +1 -0
@@ -128,6 +128,7 @@ softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_rng.c')) softmmu_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_ahb_apb_pnp.c')) + softmmu_ss.add(when: 'CONFIG_I2C', if_true: files('i2c-echo.c')) specific_ss.add(when: 'CONFIG_AVR_POWER', if_true: files('avr_power.c'))
Signature · 1 line
2.39.2
RFC PATCH 6/6 docs: cxl: Add example commandline for MCTP CXL CCIs
In reply to Jonathan CameronA lot more needed here on what these are for and what can be done with them.
--- docs/system/devices/cxl.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
docs/system/devices/cxl.rst +27 -0
@@ -406,6 +406,33 @@ OS management of CXL memory devices as described here. * CONFIG_CXL_PORT * CONFIG_CXL_REGION + +CCI access via MCTP over I2C +---------------------------- + +TODO: Add some more info here on what this actually is. + +Both CXL switches and CXL Type 3 devices support configuration via +MCTP access to Component Command Interfaces (CCIs) on the devices. + +Example configuration: + + -device cxl-upstream,port=33,bus=root_port0,id=us0,multifunction=on,addr=0.0,sn=12345678 \ + -device cxl-downstream,port=0,bus=us0,id=swport0,chassis=0,slot=4 \ + -device cxl-downstream,port=1,bus=us0,id=swport1,chassis=0,slot=5 \ + -device cxl-downstream,port=2,bus=us0,id=swport2,chassis=0,slot=6 \ + -device cxl-type3,bus=swport0,persistent-memdev=cxl-mem1,id=cxl-pmem0,lsa=cxl-lsa1,sn=3 \ + -device cxl-type3,bus=swport1,persistent-memdev=cxl-mem2,id=cxl-pmem1,lsa=cxl-lsa2,sn=4 \ + -device cxl-type3,bus=swport2,persistent-memdev=cxl-mem3,id=cxl-pmem2,lsa=cxl-lsa3,sn=5 \ + -machine cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G,cxl-fmw.0.interleave-granularity=1k \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=4,target=us0 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=5,target=cxl-pmem0 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=6,target=cxl-pmem1 \ + -device i2c_mctp_cxl,bus=aspeed.i2c.bus.0,address=7,target=cxl-pmem2 + +Communication with the MCTP CCI can then be established using standard MCTP configuration +tools. + References ----------
Signature · 1 line
2.39.2