Skip to contentSkip to conversation

hw/cxl: Add a CXL Type-2 device

RFC In review [email protected] 3 participants 23 messages Nov 6 – Nov 18 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover hw/cxl: Add a CXL Type-2 device

From: Manish Honap <[email protected]>

Hello,

This series adds cxl-type2, an emulated CXL Type-2 device with volatile device memory. It is emulated in such a way that all the Linux checks are satisfied so that CXL passthrough using vfio-pci (vfio-cxl) can be developed and tested in a guest without Type-2 hardware.

This series builds on the Type-2 model from Zhi's series (carried in Cédric's tree) and carries one fix from Shuai's tree. Shuai's tree also set up the decoders through device properties and stubbed CXL Reset; the firmware setup and CXL Reset here are new code.
Carried patches keep their authors, with a note for each change.

The device:
- PCI ID 1b36:0017 and the processing accelerator class 0x1200;
- PCIe DVSEC for CXL Devices with CXL.cache, CXL.mem, one HDM range, cache write-back and invalidate, CXL Reset and Mem Clr; Register Locator and Flex Bus Port DVSECs;
- CXL.cache advertised but not modelled. The device sends no CXL.cache requests, and its memory is host RAM, which is coherent already. A cache write-back and invalidate completes at once. The capability is set because vfio-cxl takes a device as Type-2 only when it reports both CXL.cache and CXL.mem;
- component registers with one HDM decoder;
- slot 0, function 0 below a CXL root port of a pxb-cxl, memory in one fixed memory window selected with fmw-index, cold plug only (no hotplug or unplug), not migratable.

No Linux driver claims the device on its own. cxl_pci does not bind to the accelerator class, and sfc, the other driver that calls the CXL core Type-2 interface, matches only its own devices. A guest binds cxl-type2 to vfio-pci, which hands it to vfio-cxl. Testing the CXL core Type-2 interface without vfio-cxl needs a driver for 1b36:0017 that calls it. There is none yet.

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, and Linux attaches a Type-2 device only to a committed region (devm_cxl_probe_mem()). So QEMU does that step itself. cxl-type2 registers its range with its pxb-cxl at realize (patch 13). At every reset the pxb-cxl commits HDM decoder 0 for it (patch 12), and the device commits its own decoder with Lock On Commit and enables CXL.cache, CXL.mem and HDM decoding (patch 14). A pxb-cxl with a registered range keeps its HDM decoder even with a single root port, where it would otherwise pass accesses through. Type-3 devices, and pxb-cxl without a registered range, are not affected.

A CXL Reset keeps the locked decoder committed, as RWL fields are not affected by CXL Reset once locked (CXL r4.0 Table 8-1). DVSEC Control, the range bases and HDM Decoder Global Control return to their defaults, which leaves Mem_Enable and HDM Decoder Enable at 0. While either is 0 the device drops CXL.mem, so guest accesses to its memory fail until software sets both bits again. The CXL.io part of the reset is not emulated. CONFIG_LOCK makes the RWL DVSEC fields read only until a system reset.

Patches:
- 1-7: Shared CXL code: read-0 ops for the CXL.io range of the
component registers, helpers from Zhi, an HDM decoder count, DVSEC bit names, a device-neutral view for the direct mapping code, PCI IDs;
- 8-17: The device; patch 16 also exports the default component register write handling, so the device can check the enable bits after a write;
- 18: Docs;

Left for later series:
- The CXL device registers with the mailbox, event logs and MSI-X, and the CDAT;
- Direct mapping lifecycle fixes for Type-3 and switch topologies, and Lock On Commit in host bridges and switches;
- Fixes for guest-triggered aborts on 1 and 2 byte mailbox writes and a repeated DOE Go;
- Software-programmed decoders, for Linux-created Type-2 regions;
- A Type-2 device below a CXL switch, and migration.

Testing:
- Build every commit for x86_64 and aarch64, checkpatch for style.
- vfio-cxl selftest (vfio_cxl_type2_test) in an Arm L1 guest on KVM, with the device below a CXL root port and an SMMUv3: 19 of 19 pass

- Not tested: x86_64 L1, a build without CONFIG_CXL_TYPE2_DEVICE.

The Linux vfio-cxl series(v5) this was tested with:
https://lore.kernel.org/r/[email protected]

Sent as RFC to get comments on the series structure and to request 1b36:0017 devid for cxl-type2 device allocation.

References:
[PATCH RFC 0/5] hw/cxl: Type 2 Device RFC
https://lore.kernel.org/linux-cxl/[email protected]/

Type-2 emulation trees:

[1] Zhi Wang
https://github.com/zhiwang-nvidia/qemu/commits/zhi/qemu-type2-emulation-for-review

[2] Cédric Le Goater
https://github.com/legoater/qemu/tree/cxl-type2

[3] Shuai Xue
https://gitee.com/axiqia/qemu-kvm/tree/cxl-type2-test

Manish Honap (12):
hw/cxl: Make HDM decoder initialization count-aware hw/cxl: Define the CXL Device DVSEC capability and control bits hw/cxl: Find the memory of a CXL device through one helper hw/pci: Add PCI IDs for the CXL Type-2 device
hw/mem: Require a CXL root port of a pxb-cxl for cxl-type2 hw/pci-bridge: Add firmware HDM decoder state to pxb-cxl hw/mem: Bind cxl-type2 to a fixed memory window
hw/mem: Commit the cxl-type2 HDM decoder at reset hw/mem: Add CXL.cache with cache write-back and invalidate to
cxl-type2
hw/mem: Implement CXL Reset for cxl-type2
hw/mem: Clear the cxl-type2 volatile memory on a CXL Reset request docs/cxl: Document the CXL Type-2 device

Shuai Xue (1):
hw/cxl: Give the component register .io sub-region read-0 ops

Zhi Wang (5):
hw/cxl: Factor out cxl_host_addr_to_dpa()
hw/cxl: Introduce cxl_component_update_dvsec()
hw/cxl: Introduce CXL type-2 device emulation
hw/cxl: Add the CXL type-2 DVSECs and component registers hw/cxl: Map the CXL type-2 device memory through the fixed windows

 MAINTAINERS                             |   1 +
 docs/specs/pci-ids.rst                  |   2 +
 docs/system/devices/cxl.rst             |  68 +++
 hw/cxl/cxl-component-utils.c            | 227 +++++++++-
 hw/cxl/cxl-host.c                       | 130 ++++--
 hw/mem/Kconfig                          |   5 +
 hw/mem/cxl_type2.c                      | 580 ++++++++++++++++++++++++
 hw/mem/cxl_type2_stubs.c                |  20 +
 hw/mem/cxl_type3.c                      |  68 +--
 hw/mem/meson.build                      |   2 +
 hw/pci-bridge/pci_expander_bridge_cxl.c |  27 +-
 include/hw/cxl/cxl.h                    |   1 +
 include/hw/cxl/cxl_component.h          |  26 ++
 include/hw/cxl/cxl_device.h             |  27 ++
 include/hw/cxl/cxl_pci.h                |  31 ++
 include/hw/pci/pci.h                    |   1 +
 include/hw/pci/pci_bridge.h             |   6 +
 include/hw/pci/pci_ids.h                |   3 +
 18 files changed, 1102 insertions(+), 123 deletions(-)
 create mode 100644 hw/mem/cxl_type2.c
 create mode 100644 hw/mem/cxl_type2_stubs.c

base-commit: f71afb409a87c4ecd0f9d63a5963eb645dfab780

Signature · 1 line
2.53.0
#1 lore raw

RFC 1/18 hw/cxl: Give the component register .io sub-region read-0 ops

From: Shuai Xue <[email protected]>

The .io sub-region of the component register block was created with NULL ops, so a read falling into it (e.g. a vfio passthrough pread of a non-decoder dword of the component BAR) failed the bus transaction. Under TCG this raises a synchronous external abort on Arm guests (ESR DFSC=0x10).

CXL r4.0 Table 8-73 reserves the range, and reserved registers read 0, so attach read-0/write-ignore ops to .io.

[ mhonap: drop the comment above the .io region init ]
---
 hw/cxl/cxl-component-utils.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
hw/cxl/cxl-component-utils.c +18 -2
index a624357978..fc32be77a9 100644
@@ -264,6 +264,23 @@ static const MemoryRegionOps cache_mem_ops = {
     },
 };
 
+/* CXL r4.0 Table 8-73: the CXL.io range is reserved */
+static uint64_t cxl_io_reg_read(void *opaque, hwaddr addr, unsigned size)
+{
+    return 0;
+}
+
+static void cxl_io_reg_write(void *opaque, hwaddr addr, uint64_t val,
+                             unsigned size)
+{
+}
+
+static const MemoryRegionOps cxl_io_reg_ops = {
+    .read = cxl_io_reg_read,
+    .write = cxl_io_reg_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 void cxl_component_register_block_init(Object *obj,
                                        CXLComponentState *cxl_cstate,
                                        const char *type)
@@ -273,8 +290,7 @@ void cxl_component_register_block_init(Object *obj,
     memory_region_init(&cregs->component_registers, obj, type,
                        CXL2_COMPONENT_BLOCK_SIZE);
 
-    /* io registers controls link which we don't care about in QEMU */
-    memory_region_init_io(&cregs->io, obj, NULL, NULL, ".io",
+    memory_region_init_io(&cregs->io, obj, &cxl_io_reg_ops, NULL, ".io",
                           CXL2_COMPONENT_IO_REGION_SIZE);
     memory_region_init_io(&cregs->cache_mem, obj, &cache_mem_ops, cxl_cstate,
                           ".cache_mem", CXL2_COMPONENT_CM_REGION_SIZE);
Signature · 1 line
2.53.0
#2 lore raw

RFC 2/18 hw/cxl: Factor out cxl_host_addr_to_dpa()

In reply to [email protected]

From: Zhi Wang <[email protected]>

cxl_type3_dpa() translates a host address to a DPA when a guest accesses a CXL region. The CXL Type-2 device needs the same translation, so move it to cxl_host_addr_to_dpa().

No functional change.

[ clg: - rebased on upstream (3-way interleave)
- use NULL instead of &error_fatal in cxl_interleave_ways_dec() to match existing upstream callers ]

[ mhonap: commit message updates ]
---
 hw/cxl/cxl-component-utils.c   | 72 ++++++++++++++++++++++++++++++++++
 hw/mem/cxl_type3.c             | 68 +-------------------------------
 include/hw/cxl/cxl_component.h |  3 ++
 3 files changed, 76 insertions(+), 67 deletions(-)
hw/cxl/cxl-component-utils.c +72 -0
index fc32be77a9..5db57f7394 100644
@@ -656,3 +656,75 @@ uint8_t cxl_interleave_granularity_enc(uint64_t gran, Error **errp)
         return 0;
     }
 }
+
+bool cxl_host_addr_to_dpa(CXLComponentState *cxl_cstate, hwaddr host_addr,
+                          uint64_t *dpa)
+{
+    int hdm_inc = R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_LO;
+    uint32_t *cache_mem = cxl_cstate->crb.cache_mem_registers;
+    unsigned int hdm_count;
+    uint32_t cap;
+    uint64_t dpa_base = 0;
+    int i;
+
+    cap = ldl_le_p(cache_mem + R_CXL_HDM_DECODER_CAPABILITY);
+    hdm_count = cxl_decoder_count_dec(FIELD_EX32(cap,
+                                                 CXL_HDM_DECODER_CAPABILITY,
+                                                 DECODER_COUNT));
+
+    for (i = 0; i < hdm_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 * hdm_inc);
+        high = ldl_le_p(cache_mem + R_CXL_HDM_DECODER0_BASE_HI + i * hdm_inc);
+        decoder_base = ((uint64_t)high << 32) | (low & 0xf0000000);
+
+        low = ldl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_LO + i * hdm_inc);
+        high = ldl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_HI + i * hdm_inc);
+        decoder_size = ((uint64_t)high << 32) | (low & 0xf0000000);
+
+        low = ldl_le_p(cache_mem + R_CXL_HDM_DECODER0_DPA_SKIP_LO +
+                       i * hdm_inc);
+        high = ldl_le_p(cache_mem + R_CXL_HDM_DECODER0_DPA_SKIP_HI +
+                        i * hdm_inc);
+        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 * hdm_inc);
+        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)) {
+            int decoded_iw = cxl_interleave_ways_dec(iw, NULL);
+
+            if (decoded_iw == 0) {
+                return false;
+            }
+
+            dpa_base += decoder_size / decoded_iw;
+            continue;
+        }
+
+        if (iw < 8) {
+            *dpa = dpa_base +
+                ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) |
+                 ((MAKE_64BIT_MASK(8 + ig + iw, 64 - 8 - ig - iw) & hpa_offset)
+                  >> iw));
+        } else {
+            *dpa = dpa_base +
+                ((MAKE_64BIT_MASK(0, 8 + ig) & hpa_offset) |
+                 ((((MAKE_64BIT_MASK(ig + iw, 64 - ig - iw) & hpa_offset)
+                   >> (ig + iw)) / 3) << (ig + 8)));
+        }
+
+        return true;
+    }
+    return false;
+}
hw/mem/cxl_type3.c +1 -67

74 lines not on this page · raw message

include/hw/cxl/cxl_component.h +3 -0
index ffc8220220..7929a39b73 100644
@@ -327,6 +327,9 @@ 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);
 
+bool cxl_host_addr_to_dpa(CXLComponentState *cxl_cstate, hwaddr host_addr,
+                          uint64_t *dpa);
+
 hwaddr cxl_decode_ig(int ig);
 
 CXLComponentState *cxl_get_hb_cstate(PCIHostState *hb);
Signature · 1 line
2.53.0
#3 lore raw

RFC 3/18 hw/cxl: Introduce cxl_component_update_dvsec()

In reply to [email protected]

From: Zhi Wang <[email protected]>

cxl_component_create_dvsec() sets the DVSEC registers once, at realize, and nothing resets them. DVSEC Control Mem_Enable then stays 1 across a system reset. The Linux CXL core takes that as HDM decoders set up by firmware, uses whatever the decoders hold, and fails to probe the device.

Add cxl_component_update_dvsec() so that a device can rewrite its DVSEC registers at reset.

[ mhonap: comment and indentation fixes, commit message update ]
---
 hw/cxl/cxl-component-utils.c   | 33 +++++++++++++++++++++++++++------
 include/hw/cxl/cxl_component.h |  3 +++
 2 files changed, 30 insertions(+), 6 deletions(-)
hw/cxl/cxl-component-utils.c +27 -6
index 5db57f7394..bb4c3f541d 100644
@@ -490,9 +490,10 @@ void cxl_component_register_init_common(uint32_t *reg_state,
  * Helper to creates a DVSEC header for a CXL entity. The caller is responsible
  * for tracking the valid offset.
  *
- * This function will build the DVSEC header on behalf of the caller and then
- * copy in the remaining data for the vendor specific bits.
- * It will also set up appropriate write masks.
+ * This function will build the DVSEC header on behalf of the caller and set
+ * up appropriate write masks. With @body it also copies in the remaining
+ * data; otherwise the caller fills it in later with
+ * cxl_component_update_dvsec().
  */
 void cxl_component_create_dvsec(CXLComponentState *cxl,
                                 enum reg_type cxl_dev_type, uint16_t length,
@@ -512,9 +513,12 @@ void cxl_component_create_dvsec(CXLComponentState *cxl,
     pci_set_long(pdev->config + offset + PCIE_DVSEC_HEADER1_OFFSET,
                  (length << 20) | (rev << 16) | CXL_VENDOR_ID);
     pci_set_word(pdev->config + offset + PCIE_DVSEC_ID_OFFSET, type);
-    memcpy(pdev->config + offset + sizeof(DVSECHeader),
-           body + sizeof(DVSECHeader),
-           length - sizeof(DVSECHeader));
+
+    if (body) {
+        memcpy(pdev->config + offset + sizeof(DVSECHeader),
+               body + sizeof(DVSECHeader),
+               length - sizeof(DVSECHeader));
+    }
 
     /* Configure write masks */
     switch (type) {
@@ -606,6 +610,23 @@ void cxl_component_create_dvsec(CXLComponentState *cxl,
     cxl->dvsec_offset += length;
 }
 
+void cxl_component_update_dvsec(CXLComponentState *cxl, uint16_t length,
+                                uint16_t type, uint8_t *body)
+{
+    PCIDevice *pdev = cxl->pdev;
+    struct Range *r;
+
+    assert(type < CXL20_MAX_DVSEC);
+
+    r = &cxl->dvsecs[type];
+
+    assert(range_size(r) == length);
+
+    memcpy(pdev->config + r->lob + sizeof(DVSECHeader),
+           body + sizeof(DVSECHeader),
+           length - sizeof(DVSECHeader));
+}
+
 /* CXL r3.1 Section 8.2.4.20.7 CXL HDM Decoder n Control Register */
 uint8_t cxl_interleave_ways_enc(int iw, Error **errp)
 {
include/hw/cxl/cxl_component.h +3 -0
index 7929a39b73..d6fdb6c1ab 100644
@@ -320,6 +320,9 @@ 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);
 
+void cxl_component_update_dvsec(CXLComponentState *cxl, uint16_t length,
+                                uint16_t type, uint8_t *body);
+
 int cxl_decoder_count_enc(int count);
 int cxl_decoder_count_dec(int enc_cnt);
 
Signature · 1 line
2.53.0
#4 lore raw

RFC 4/18 hw/cxl: Make HDM decoder initialization count-aware

In reply to [email protected]

From: Manish Honap <[email protected]>

cxl_component_register_init_common() always sets up four HDM decoders.

Add cxl_component_register_init_count() for devices with fewer HDM decoders (The CXL Type-2 device added later in this series has only one)

AI-used-for: code (prototype)

---
 hw/cxl/cxl-component-utils.c   | 28 ++++++++++++++++++++--------
 include/hw/cxl/cxl_component.h |  4 ++++
 2 files changed, 24 insertions(+), 8 deletions(-)
hw/cxl/cxl-component-utils.c +20 -8
index bb4c3f541d..f4a7fdb425 100644
@@ -323,11 +323,11 @@ 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, bool bi)
+                            enum reg_type type, bool bi,
+                            unsigned int decoder_count)
 {
-    int decoder_count = CXL_HDM_DECODER_COUNT;
     int hdm_inc = R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_LO;
-    int i;
+    unsigned int i;
 
     ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, DECODER_COUNT,
                      cxl_decoder_count_enc(decoder_count));
@@ -406,13 +406,16 @@ static void bi_decoder_init_common(uint32_t *reg_state, uint32_t *write_msk,
     ARRAY_FIELD_DP32(reg_state, CXL_BI_DECODER_STATUS, COMMIT_TMO_BASE, 0x2);
 }
 
-void cxl_component_register_init_common(uint32_t *reg_state,
-                                        uint32_t *write_msk,
-                                        enum reg_type type,
-                                        bool bi)
+void cxl_component_register_init_count(uint32_t *reg_state,
+                                       uint32_t *write_msk,
+                                       enum reg_type type, bool bi,
+                                       unsigned int decoder_count)
 {
     int caps = 0;
 
+    assert(decoder_count > 0 && decoder_count <= CXL_HDM_DECODER_COUNT);
+    assert(cxl_decoder_count_dec(cxl_decoder_count_enc(decoder_count)) ==
+           decoder_count);
     memset(reg_state, 0, CXL2_COMPONENT_CM_REGION_SIZE);
 
     /* CXL Capability Header Register */
@@ -449,7 +452,7 @@ void cxl_component_register_init_common(uint32_t *reg_state,
     case CXL2_LOGICAL_DEVICE:
         /* + HDM */
         init_cap_reg(HDM, 5, 1);
-        hdm_init_common(reg_state, write_msk, type, bi);
+        hdm_init_common(reg_state, write_msk, type, bi, decoder_count);
         /* fallthrough */
     case CXL2_DOWNSTREAM_PORT:
     case CXL2_DEVICE:
@@ -486,6 +489,15 @@ void cxl_component_register_init_common(uint32_t *reg_state,
 #undef init_cap_reg
 }
 
+void cxl_component_register_init_common(uint32_t *reg_state,
+                                        uint32_t *write_msk,
+                                        enum reg_type type,
+                                        bool bi)
+{
+    cxl_component_register_init_count(reg_state, write_msk, type, bi,
+                                      CXL_HDM_DECODER_COUNT);
+}
+
 /*
  * Helper to creates a DVSEC header for a CXL entity. The caller is responsible
  * for tracking the valid offset.
include/hw/cxl/cxl_component.h +4 -0
index d6fdb6c1ab..3ed8dab92e 100644
@@ -312,6 +312,10 @@ typedef struct cxl_component {
 void cxl_component_register_block_init(Object *obj,
                                        CXLComponentState *cxl_cstate,
                                        const char *type);
+void cxl_component_register_init_count(uint32_t *reg_state,
+                                       uint32_t *write_msk,
+                                       enum reg_type type, bool bi,
+                                       unsigned int decoder_count);
 void cxl_component_register_init_common(uint32_t *reg_state,
                                         uint32_t *write_msk,
                                         enum reg_type type, bool bi);
Signature · 1 line
2.53.0
#5 lore raw

RFC 5/18 hw/cxl: Define the CXL Device DVSEC capability and control bits

In reply to [email protected]

From: Manish Honap <[email protected]>

Name the bits of the PCIe DVSEC for CXL Devices (CXL r4.0 Section 8.1.3) that the CXL Type-2 device added later in this series uses.

standard-headers/linux/pci_regs.h has some of them, but defines them with _BITUL() and __GENMASK(), which it does not include.

AI-used-for: code (prototype)

---
 include/hw/cxl/cxl_pci.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
include/hw/cxl/cxl_pci.h +31 -0
index d0855ed78b..98efa529bc 100644
@@ -96,6 +96,37 @@ typedef struct CXLDVSECDevice {
 } QEMU_PACKED CXLDVSECDevice;
 QEMU_BUILD_BUG_ON(sizeof(CXLDVSECDevice) != PCIE_CXL_DEVICE_DVSEC_LENGTH);
 
+/* CXL r4.0 Section 8.1.3.1: DVSEC CXL Capability */
+#define CXL_DVSEC_CAP_CACHE             0x0001
+#define CXL_DVSEC_CAP_IO                0x0002
+#define CXL_DVSEC_CAP_MEM               0x0004
+#define CXL_DVSEC_CAP_MEM_HWINIT        0x0008
+#define CXL_DVSEC_CAP_HDM_COUNT_SHIFT   4
+#define CXL_DVSEC_CAP_CACHE_WBI         0x0040
+#define CXL_DVSEC_CAP_RST               0x0080
+#define CXL_DVSEC_CAP_RST_TIMEOUT_SHIFT 8
+#define CXL_DVSEC_CAP_RST_TIMEOUT_MASK  0x0700
+#define CXL_DVSEC_CAP_RST_MEM_CLR       0x0800
+
+/* CXL r4.0 Section 8.1.3.2: DVSEC CXL Control */
+#define CXL_DVSEC_CTRL_CACHE_EN         0x0001
+#define CXL_DVSEC_CTRL_IO_EN            0x0002
+#define CXL_DVSEC_CTRL_MEM_EN           0x0004
+
+/* CXL r4.0 Section 8.1.3.4: DVSEC CXL Control2 */
+#define CXL_DVSEC_CTRL2_DISABLE_CACHING 0x0001
+#define CXL_DVSEC_CTRL2_INIT_CACHE_WBI  0x0002
+#define CXL_DVSEC_CTRL2_INIT_CXL_RST    0x0004
+#define CXL_DVSEC_CTRL2_RST_MEM_CLR_EN  0x0008
+
+/* CXL r4.0 Section 8.1.3.5: DVSEC CXL Status2 */
+#define CXL_DVSEC_STATUS2_CACHE_INV     0x0001
+#define CXL_DVSEC_STATUS2_RST_DONE      0x0002
+#define CXL_DVSEC_STATUS2_RST_ERR       0x0004
+
+/* CXL r4.0 Section 8.1.3.6: DVSEC CXL Lock */
+#define CXL_DVSEC_LOCK_CONFIG_LOCK      0x0001
+
 /*
  * CXL r3.1 Section 8.1.5: CXL Extensions DVSEC for Ports
  * DVSEC ID: 3, Revision: 0
Signature · 1 line
2.53.0
#6 lore raw

RFC 6/18 hw/cxl: Find the memory of a CXL device through one helper

In reply to [email protected]

From: Manish Honap <[email protected]>

The direct mapping code takes the memory backends, component registers and mapping slots from CXLType3Dev. Collect them in a CXLMemDevice filled by cxl_mem_device(), and add cxl_fmws_direct_passthrough_remove_all() to drop every mapping of a device. The CXL Type-2 device added later in this series uses both.

No functional change for cxl-type3.

AI-used-for: code (prototype)

---
 hw/cxl/cxl-host.c    | 110 +++++++++++++++++++++++++++++++------------
 include/hw/cxl/cxl.h |   1 +
 2 files changed, 82 insertions(+), 29 deletions(-)
hw/cxl/cxl-host.c +81 -29
index 754f708cce..d9c7599679 100644
@@ -209,6 +209,37 @@ static bool cxl_hdm_find_target(uint32_t *cache_mem, hwaddr addr,
     return found;
 }
 
+/* A CXL device with memory that a fixed memory window can map directly */
+typedef struct CXLMemDevice {
+    PCIDevice *pdev;
+    CXLComponentState *cstate;
+    HostMemoryBackend *hostvmem;
+    HostMemoryBackend *hostpmem;
+    MemoryRegion *direct_mr;
+    CXLFixedWindow **direct_mr_fw;
+} CXLMemDevice;
+
+static bool cxl_mem_device(Object *obj, CXLMemDevice *md)
+{
+    CXLType3Dev *ct3d;
+
+    if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) {
+        return false;
+    }
+    ct3d = CXL_TYPE3(obj);
+    if (md) {
+        *md = (CXLMemDevice) {
+            .pdev = PCI_DEVICE(ct3d),
+            .cstate = &ct3d->cxl_cstate,
+            .hostvmem = ct3d->hostvmem,
+            .hostpmem = ct3d->hostpmem,
+            .direct_mr = ct3d->direct_mr,
+            .direct_mr_fw = ct3d->direct_mr_fw,
+        };
+    }
+    return true;
+}
+
 static PCIDevice *cxl_cfmws_find_device(CXLFixedWindow *fw, hwaddr addr,
                                         bool allow_interleave)
 {
@@ -265,7 +296,7 @@ static PCIDevice *cxl_cfmws_find_device(CXLFixedWindow *fw, hwaddr addr,
         return NULL;
     }
 
-    if (object_dynamic_cast(OBJECT(d), TYPE_CXL_TYPE3)) {
+    if (cxl_mem_device(OBJECT(d), NULL)) {
         return d;
     }
 
@@ -304,7 +335,7 @@ static PCIDevice *cxl_cfmws_find_device(CXLFixedWindow *fw, hwaddr addr,
         return NULL;
     }
 
-    if (!object_dynamic_cast(OBJECT(d), TYPE_CXL_TYPE3)) {
+    if (!cxl_mem_device(OBJECT(d), NULL)) {
         return NULL;
     }
 
@@ -312,7 +343,7 @@ static PCIDevice *cxl_cfmws_find_device(CXLFixedWindow *fw, hwaddr addr,
 }
 
 typedef struct CXLDirectPTState {
-    CXLType3Dev *ct3d;
+    CXLMemDevice md;
     hwaddr decoder_base;
     hwaddr decoder_size;
     hwaddr dpa_base;
@@ -322,15 +353,15 @@ typedef struct CXLDirectPTState {
 static void cxl_fmws_direct_passthrough_setup(CXLDirectPTState *state,
                                               CXLFixedWindow *fw)
 {
-    CXLType3Dev *ct3d = state->ct3d;
+    CXLMemDevice *md = &state->md;
     MemoryRegion *mr = NULL;
     uint64_t vmr_size = 0, pmr_size = 0, offset = 0;
     MemoryRegion *direct_mr;
     g_autofree char *direct_mr_name = NULL;
     unsigned int idx = state->hdm_decoder_idx;
 
-    if (ct3d->hostvmem) {
-        MemoryRegion *vmr = host_memory_backend_get_memory(ct3d->hostvmem);
+    if (md->hostvmem) {
+        MemoryRegion *vmr = host_memory_backend_get_memory(md->hostvmem);
 
         vmr_size = memory_region_size(vmr);
         if (state->dpa_base < vmr_size) {
@@ -338,8 +369,8 @@ static void cxl_fmws_direct_passthrough_setup(CXLDirectPTState *state,
             offset = state->dpa_base;
         }
     }
-    if (!mr && ct3d->hostpmem) {
-        MemoryRegion *pmr = host_memory_backend_get_memory(ct3d->hostpmem);
+    if (!mr && md->hostpmem) {
+        MemoryRegion *pmr = host_memory_backend_get_memory(md->hostpmem);
 
         pmr_size = memory_region_size(pmr);
         if (state->dpa_base - vmr_size < pmr_size) {
@@ -351,37 +382,49 @@ static void cxl_fmws_direct_passthrough_setup(CXLDirectPTState *state,
         return;
     }
 
-    if (ct3d->direct_mr_fw[idx]) {
+    if (md->direct_mr_fw[idx]) {
         return;
     }
 
-    direct_mr = &ct3d->direct_mr[idx];
+    direct_mr = &md->direct_mr[idx];
     direct_mr_name = g_strdup_printf("cxl-direct-mapping-alias-%u", idx);
     if (!direct_mr_name) {
         return;
     }
 
-    memory_region_init_alias(direct_mr, OBJECT(ct3d), direct_mr_name, mr,
+    memory_region_init_alias(direct_mr, OBJECT(md->pdev), direct_mr_name, mr,
                              offset, state->decoder_size);
     memory_region_transaction_begin();
     memory_region_add_subregion(&fw->mr,
                                 state->decoder_base - fw->base, direct_mr);
     memory_region_transaction_commit();
-    ct3d->direct_mr_fw[idx] = fw;
+    md->direct_mr_fw[idx] = fw;
+}
+
+static void cxl_fmws_direct_passthrough_unmap(CXLMemDevice *md,
+                                              unsigned int idx)
+{
+    CXLFixedWindow *owner_fw = md->direct_mr_fw[idx];
+    MemoryRegion *direct_mr = &md->direct_mr[idx];
+
+    memory_region_transaction_begin();
+    memory_region_del_subregion(&owner_fw->mr, direct_mr);
+    object_unparent(OBJECT(direct_mr));
+    memory_region_transaction_commit();
+    md->direct_mr_fw[idx] = NULL;
 }
 
-static void cxl_fmws_direct_passthrough_remove(CXLType3Dev *ct3d,
+static void cxl_fmws_direct_passthrough_remove(CXLMemDevice *md,
                                                uint64_t decoder_base,
                                                unsigned int idx)
 {
-    CXLFixedWindow *owner_fw = ct3d->direct_mr_fw[idx];
-    MemoryRegion *direct_mr = &ct3d->direct_mr[idx];
+    CXLFixedWindow *owner_fw = md->direct_mr_fw[idx];
 
     if (!owner_fw) {
         return;
     }
 
-    if (!memory_region_is_mapped(direct_mr)) {
+    if (!memory_region_is_mapped(&md->direct_mr[idx])) {
         return;
     }
 
@@ -389,11 +432,21 @@ static void cxl_fmws_direct_passthrough_remove(CXLType3Dev *ct3d,
         return;
     }
 
-    memory_region_transaction_begin();
-    memory_region_del_subregion(&owner_fw->mr, direct_mr);
-    object_unparent(OBJECT(direct_mr));
-    memory_region_transaction_commit();
-    ct3d->direct_mr_fw[idx] = NULL;
+    cxl_fmws_direct_passthrough_unmap(md, idx);
+}
+
+void cxl_fmws_direct_passthrough_remove_all(PCIDevice *dev)
+{
+    CXLMemDevice md;
+
+    if (!cxl_mem_device(OBJECT(dev), &md)) {
+        return;
+    }
+    for (unsigned int i = 0; i < CXL_HDM_DECODER_COUNT; i++) {
+        if (md.direct_mr_fw[i]) {
+            cxl_fmws_direct_passthrough_unmap(&md, i);
+        }
+    }
 }
 
 static int cxl_fmws_direct_passthrough(Object *obj, void *opaque)
@@ -421,19 +474,18 @@ static int update_non_interleaved(Object *obj, void *opaque)
 {
     const int hdm_inc = R_CXL_HDM_DECODER1_BASE_LO - R_CXL_HDM_DECODER0_BASE_LO;
     bool commit = *(bool *)opaque;
-    CXLType3Dev *ct3d;
+    CXLMemDevice md;
     uint32_t *cache_mem;
     unsigned int hdm_count, i;
     int interleave_ways_dec;
     uint32_t cap;
     uint64_t dpa_base = 0;
 
-    if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) {
+    if (!cxl_mem_device(obj, &md)) {
         return 0;
     }
 
-    ct3d = CXL_TYPE3(obj);
-    cache_mem = ct3d->cxl_cstate.crb.cache_mem_registers;
+    cache_mem = md.cstate->crb.cache_mem_registers;
     cap = ldl_le_p(cache_mem + R_CXL_HDM_DECODER_CAPABILITY);
     hdm_count = cxl_decoder_count_dec(FIELD_EX32(cap,
                                                  CXL_HDM_DECODER_CAPABILITY,
@@ -447,8 +499,8 @@ static int update_non_interleaved(Object *obj, void *opaque)
         committed = FIELD_EX32(hdm_ctrl, CXL_HDM_DECODER0_CTRL, COMMITTED);
 
         /*
-         * Optimization: Looking for a fully committed path; if the type 3 HDM
-         * decoder is not commmitted, it cannot lie on such a path.
+         * Optimization: Looking for a fully committed path; if the endpoint
+         * HDM decoder is not committed, it cannot lie on such a path.
          */
         if (commit && !committed) {
             return 0;
@@ -473,10 +525,10 @@ static int update_non_interleaved(Object *obj, void *opaque)
 
         if (iw == 0) {
             if (!commit) {
-                cxl_fmws_direct_passthrough_remove(ct3d, decoder_base, i);
+                cxl_fmws_direct_passthrough_remove(&md, decoder_base, i);
             } else {
                 CXLDirectPTState state = {
-                    .ct3d = ct3d,
+                    .md = md,
                     .decoder_base = decoder_base,
                     .decoder_size = decoder_size,
                     .dpa_base = dpa_base,
include/hw/cxl/cxl.h +1 -0
index 7cf3dc622c..e3a3a43236 100644
@@ -84,4 +84,5 @@ typedef struct CXLDownstreamPort CXLDownstreamPort;
 DECLARE_INSTANCE_CHECKER(CXLDownstreamPort, CXL_DSP, TYPE_CXL_DSP)
 
 void cfmws_update_non_interleaved(bool commit);
+void cxl_fmws_direct_passthrough_remove_all(PCIDevice *dev);
 #endif
Signature · 1 line
2.53.0
#7 lore raw

RFC 7/18 hw/pci: Add PCI IDs for the CXL Type-2 device

In reply to [email protected]

From: Manish Honap <[email protected]>

Assign 1b36:0017 to the CXL Type-2 device added later in this series, and add the processing accelerator class code 0x1200.

The CXL memory device class 0x0502 with programming interface 0x10 would bind the guest cxl_pci driver, which treats the device as a Type-3 memory expander.

AI-used-for: code (prototype)

---
 docs/specs/pci-ids.rst   | 2 ++
 include/hw/pci/pci.h     | 1 +
 include/hw/pci/pci_ids.h | 3 +++
 3 files changed, 6 insertions(+)
docs/specs/pci-ids.rst +2 -0
index 74460bb19e..1443830ad1 100644
@@ -109,6 +109,8 @@ PCI devices (other than virtio):
   PCIe Upstream Switch Port (``-device pcie-upstream-port``)
 1b36:0016
   PCIe Downstream Switch Port (``-device pcie-downstream-port``)
+1b36:0017
+  CXL Type-2 device (``-device cxl-type2``)
 
 All these devices are documented in :doc:`index`.
 
include/hw/pci/pci.h +1 -0
index 359331102f..4ca1548771 100644
@@ -123,6 +123,7 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_REDHAT_RISCV_IOMMU 0x0014
 #define PCI_DEVICE_ID_REDHAT_PCIE_USP    0x0015
 #define PCI_DEVICE_ID_REDHAT_PCIE_DSP    0x0016
+#define PCI_DEVICE_ID_REDHAT_CXL_TYPE2   0x0017
 #define PCI_DEVICE_ID_REDHAT_QXL         0x0100
 
 #define FMT_PCIBUS                      PRIx64
include/hw/pci/pci_ids.h +3 -0
index 477609ed62..c35b7b99db 100644
@@ -154,6 +154,9 @@
 #define PCI_CLASS_SP_MANAGEMENT          0x1120
 #define PCI_CLASS_SP_OTHER               0x1180
 
+#define PCI_BASE_CLASS_ACCELERATOR       0x12
+#define PCI_CLASS_ACCELERATOR_PROCESSING 0x1200
+
 #define PCI_CLASS_OTHERS                 0xff
 
 /* Vendors and devices.  Sort key: vendor first, device next. */
Signature · 1 line
2.53.0
#8 lore raw

RFC 8/18 hw/cxl: Introduce CXL type-2 device emulation

In reply to [email protected]

From: Zhi Wang <[email protected]>

Add cxl-type2, a minimal CXL Type-2 device for testing the Linux CXL core Type-2 support and CXL Type-2 passthrough. It does not reuse cxl-type3, as most Type-3 features do not apply to a Type-2 device.

This patch adds the device and its volatile memory backend. The next two add the component registers and guest access to the memory through the fixed memory windows.

[ clg: - use PCI_CLASS_MEMORY_CXL instead of PCI_CLASS_CXL_QEMU_ACCEL
to match cxl_pci driver expectations
- rebased on upstream ]

[ mhonap: - split the original patch in three patches
- rename cxl-accel to cxl-type2
- use the Red Hat ID 1b36:0017 and the processing accelerator class 0x1200, so that cxl_pci does not bind to the device
- require volatile-memdev
- release the memory backend on exit
- refuse migration, the device state is not migrated yet
- drop MSI-X, nothing uses it yet
- license GPL-2.0-or-later
- reword the commit message ]
AI-used-for: code (prototype)

---
 MAINTAINERS                 |   1 +
 hw/mem/Kconfig              |   5 ++
 hw/mem/cxl_type2.c          | 111 ++++++++++++++++++++++++++++++++++++
 hw/mem/meson.build          |   1 +
 include/hw/cxl/cxl_device.h |  14 +++++
 5 files changed, 132 insertions(+)
 create mode 100644 hw/mem/cxl_type2.c
MAINTAINERS +1 -0
index 55463103ff..57a78bc6a9 100644
@@ -3399,6 +3399,7 @@ R: Anisa Su <[email protected]>
 L: [email protected]
 S: Supported
 F: hw/cxl/
+F: hw/mem/cxl_type2.c
 F: hw/mem/cxl_type3.c
 F: include/hw/cxl/
 F: qapi/cxl.json
hw/mem/Kconfig +5 -0
index 39ddb36710..6a5cd2be61 100644
@@ -17,6 +17,11 @@ config CXL_MEM_DEVICE
     default y if CXL
     select MEM_DEVICE
 
+config CXL_TYPE2_DEVICE
+    bool
+    default y if CXL
+    select MEM_DEVICE
+
 config SP_MEM
     bool
     select MEM_DEVICE
hw/mem/cxl_type2.c new file +111 -0

111 lines not on this page · raw message

hw/mem/meson.build +1 -0
index f410d75475..0b2c193a78 100644
@@ -4,6 +4,7 @@ mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c'))
 mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c'))
 mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'))
 mem_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_true: files('cxl_type3.c'))
+mem_ss.add(when: 'CONFIG_CXL_TYPE2_DEVICE', if_true: files('cxl_type2.c'))
 mem_ss.add(when: 'CONFIG_SP_MEM', if_true: files('sp-mem.c'))
 stub_ss.add(files('cxl_type3_stubs.c'))
 
include/hw/cxl/cxl_device.h +14 -0
index 608d05165a..aeccf42855 100644
@@ -830,6 +830,20 @@ struct CSWMBCCIDev {
 #define TYPE_CXL_SWITCH_MAILBOX_CCI "cxl-switch-mailbox-cci"
 OBJECT_DECLARE_TYPE(CSWMBCCIDev, CSWMBCCIClass, CXL_SWITCH_MAILBOX_CCI)
 
+struct CXLType2Dev {
+    /* Private */
+    PCIDevice parent_obj;
+
+    /* Properties */
+    HostMemoryBackend *hostvmem;
+
+    /* State */
+    AddressSpace hostvmem_as;
+};
+
+#define TYPE_CXL_TYPE2 "cxl-type2"
+OBJECT_DECLARE_SIMPLE_TYPE(CXLType2Dev, CXL_TYPE2)
+
 MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
                            unsigned size, MemTxAttrs attrs);
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
Signature · 1 line
2.53.0
#9 lore raw

RFC 9/18 hw/cxl: Add the CXL type-2 DVSECs and component registers

In reply to [email protected]

From: Zhi Wang <[email protected]>

Emulate the component registers of the CXL type-2 device with HDM decoders, and its CXL DVSECs: the PCIe DVSEC for CXL Devices, the Register Locator DVSEC and the Flex Bus Port DVSEC.

The DVSEC values are refreshed on every reset, so that registers such as DVSEC Control return to their defaults across a system reset.

[ clg: rebased on upstream ]

[ mhonap: - second part of the original patch, renamed to cxl-type2
- device DVSEC: CXL.io, CXL.mem, HwInit mode and one HDM range, with the bit names from cxl_pci.h; CXL.cache is added together with the cache flush support later
- device DVSEC Status2 left at 0 and Control2 read-only, the device has no CXL Reset
- CONFIG_LOCK makes the RWL fields read only until reset
- one HDM decoder
- fix "DVS Control" to "DVSEC Control" in the message ]
AI-used-for: code (prototype)

---
 hw/cxl/cxl-component-utils.c   |   2 +
 hw/mem/cxl_type2.c             | 121 +++++++++++++++++++++++++++++++++
 include/hw/cxl/cxl_component.h |   1 +
 include/hw/cxl/cxl_device.h    |   2 +
 4 files changed, 126 insertions(+)
hw/cxl/cxl-component-utils.c +2 -0
index f4a7fdb425..f9bb1684fa 100644
@@ -362,6 +362,7 @@ static void hdm_init_common(uint32_t *reg_state, uint32_t *write_msk,
         write_msk[R_CXL_HDM_DECODER0_CTRL + i * hdm_inc] = 0x13ff;
         if (type == CXL2_DEVICE ||
             type == CXL2_TYPE3_DEVICE ||
+            type == CXL3_TYPE2_DEVICE ||
             type == CXL2_LOGICAL_DEVICE) {
             write_msk[R_CXL_HDM_DECODER0_TARGET_LIST_LO + i * hdm_inc] =
                 0xf0000000;
@@ -449,6 +450,7 @@ void cxl_component_register_init_count(uint32_t *reg_state,
         /* fallthrough */
     case CXL2_UPSTREAM_PORT:
     case CXL2_TYPE3_DEVICE:
+    case CXL3_TYPE2_DEVICE:
     case CXL2_LOGICAL_DEVICE:
         /* + HDM */
         init_cap_reg(HDM, 5, 1);
hw/mem/cxl_type2.c +121 -0

151 lines not on this page · raw message

include/hw/cxl/cxl_component.h +1 -0
index 3ed8dab92e..b38e81d129 100644
@@ -29,6 +29,7 @@ enum reg_type {
     CXL2_UPSTREAM_PORT,
     CXL2_DOWNSTREAM_PORT,
     CXL3_SWITCH_MAILBOX_CCI,
+    CXL3_TYPE2_DEVICE,
 };
 
 /*
include/hw/cxl/cxl_device.h +2 -0
index aeccf42855..9c83421d0f 100644
@@ -839,6 +839,8 @@ struct CXLType2Dev {
 
     /* State */
     AddressSpace hostvmem_as;
+    CXLComponentState cxl_cstate;
+    uint8_t dvsec_wmask[PCIE_CXL_DEVICE_DVSEC_LENGTH];
 };
 
 #define TYPE_CXL_TYPE2 "cxl-type2"
Signature · 1 line
2.53.0
#10 lore raw

RFC 10/18 hw/cxl: Map the CXL type-2 device memory through the fixed windows

In reply to [email protected]

From: Zhi Wang <[email protected]>

Let guest accesses to a CXL fixed memory window reach the volatile memory of a CXL type-2 device. The device decodes the host address with its HDM decoder and accesses its memory backend at the resulting DPA.

A committed, non-interleaved decoder also maps the memory directly into the window, as for cxl-type3.

[ clg: rebased on upstream ]

[ mhonap: - third part of the original patch, renamed to cxl-type2
- add the device to cxl_mem_device() for the direct mapping, and remove its mappings on reset and exit
- stubs for builds without the device ]
AI-used-for: code (prototype)

---
 MAINTAINERS                 |  2 +-
 hw/cxl/cxl-host.c           | 20 +++++++++++++++++++
 hw/mem/cxl_type2.c          | 39 +++++++++++++++++++++++++++++++++++++
 hw/mem/cxl_type2_stubs.c    | 20 +++++++++++++++++++
 hw/mem/meson.build          |  1 +
 include/hw/cxl/cxl_device.h |  7 +++++++
 6 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 hw/mem/cxl_type2_stubs.c
MAINTAINERS +1 -1
index 57a78bc6a9..fba3e29ee1 100644
@@ -3399,7 +3399,7 @@ R: Anisa Su <[email protected]>
 L: [email protected]
 S: Supported
 F: hw/cxl/
-F: hw/mem/cxl_type2.c
+F: hw/mem/cxl_type2*.c
 F: hw/mem/cxl_type3.c
 F: include/hw/cxl/
 F: qapi/cxl.json
hw/cxl/cxl-host.c +20 -0
index d9c7599679..4bbbcda14d 100644
@@ -223,6 +223,20 @@ static bool cxl_mem_device(Object *obj, CXLMemDevice *md)
 {
     CXLType3Dev *ct3d;
 
+    if (object_dynamic_cast(obj, TYPE_CXL_TYPE2)) {
+        CXLType2Dev *ct2d = CXL_TYPE2(obj);
+
+        if (md) {
+            *md = (CXLMemDevice) {
+                .pdev = PCI_DEVICE(ct2d),
+                .cstate = &ct2d->cxl_cstate,
+                .hostvmem = ct2d->hostvmem,
+                .direct_mr = ct2d->direct_mr,
+                .direct_mr_fw = ct2d->direct_mr_fw,
+            };
+        }
+        return true;
+    }
     if (!object_dynamic_cast(obj, TYPE_CXL_TYPE3)) {
         return false;
     }
@@ -577,6 +591,9 @@ static MemTxResult cxl_read_cfmws(void *opaque, hwaddr addr, uint64_t *data,
         return MEMTX_ERROR;
     }
 
+    if (object_dynamic_cast(OBJECT(d), TYPE_CXL_TYPE2)) {
+        return cxl_type2_read(d, addr + fw->base, data, size, attrs);
+    }
     return cxl_type3_read(d, addr + fw->base, data, size, attrs);
 }
 
@@ -593,6 +610,9 @@ static MemTxResult cxl_write_cfmws(void *opaque, hwaddr addr,
         return MEMTX_OK;
     }
 
+    if (object_dynamic_cast(OBJECT(d), TYPE_CXL_TYPE2)) {
+        return cxl_type2_write(d, addr + fw->base, data, size, attrs);
+    }
     return cxl_type3_write(d, addr + fw->base, data, size, attrs);
 }
 
hw/mem/cxl_type2.c +39 -0
index b179d1e884..60f3f04679 100644
@@ -48,6 +48,43 @@ static bool setup_memory(PCIDevice *pci_dev, Error **errp)
     return true;
 }
 
+static int cxl_type2_hpa_to_as_and_dpa(CXLType2Dev *ct2d, hwaddr host_addr,
+                                       AddressSpace **as, uint64_t *dpa)
+{
+    MemoryRegion *vmr = host_memory_backend_get_memory(ct2d->hostvmem);
+
+    if (!cxl_host_addr_to_dpa(&ct2d->cxl_cstate, host_addr, dpa) ||
+        *dpa >= memory_region_size(vmr)) {
+        return -EINVAL;
+    }
+    *as = &ct2d->hostvmem_as;
+    return 0;
+}
+
+MemTxResult cxl_type2_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
+                           unsigned size, MemTxAttrs attrs)
+{
+    AddressSpace *as;
+    uint64_t dpa;
+
+    if (cxl_type2_hpa_to_as_and_dpa(CXL_TYPE2(d), host_addr, &as, &dpa)) {
+        return MEMTX_ERROR;
+    }
+    return address_space_read(as, dpa, attrs, data, size);
+}
+
+MemTxResult cxl_type2_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
+                            unsigned size, MemTxAttrs attrs)
+{
+    AddressSpace *as;
+    uint64_t dpa;
+
+    if (cxl_type2_hpa_to_as_and_dpa(CXL_TYPE2(d), host_addr, &as, &dpa)) {
+        return MEMTX_ERROR;
+    }
+    return address_space_write(as, dpa, attrs, &data, size);
+}
+
 static void update_dvsecs(CXLType2Dev *ct2d)
 {
     CXLComponentState *cxl_cstate = &ct2d->cxl_cstate;
@@ -164,6 +201,7 @@ static void cxl_type2_realize(PCIDevice *pci_dev, Error **errp)
 
 static void cxl_type2_exit(PCIDevice *pci_dev)
 {
+    cxl_fmws_direct_passthrough_remove_all(pci_dev);
     clean_memory(pci_dev);
 }
 
@@ -172,6 +210,7 @@ static void cxl_type2_reset(DeviceState *dev)
     CXLType2Dev *ct2d = CXL_TYPE2(dev);
     CXLComponentState *cxl_cstate = &ct2d->cxl_cstate;
 
+    cxl_fmws_direct_passthrough_remove_all(PCI_DEVICE(dev));
     update_dvsecs(ct2d);
     memcpy(PCI_DEVICE(ct2d)->wmask +
            range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]),
hw/mem/cxl_type2_stubs.c new file +20 -0
new file mode 100644
index 0000000000..8962f55552
@@ -0,0 +1,20 @@
+/*
+ * CXL Type-2 device stubs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/cxl/cxl.h"
+
+MemTxResult cxl_type2_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
+                           unsigned size, MemTxAttrs attrs)
+{
+    return MEMTX_ERROR;
+}
+
+MemTxResult cxl_type2_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
+                            unsigned size, MemTxAttrs attrs)
+{
+    return MEMTX_ERROR;
+}
hw/mem/meson.build +1 -0
index 0b2c193a78..0d20588636 100644
@@ -7,6 +7,7 @@ mem_ss.add(when: 'CONFIG_CXL_MEM_DEVICE', if_true: files('cxl_type3.c'))
 mem_ss.add(when: 'CONFIG_CXL_TYPE2_DEVICE', if_true: files('cxl_type2.c'))
 mem_ss.add(when: 'CONFIG_SP_MEM', if_true: files('sp-mem.c'))
 stub_ss.add(files('cxl_type3_stubs.c'))
+stub_ss.add(files('cxl_type2_stubs.c'))
 
 stub_ss.add(files('memory-device-stubs.c'))
 system_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
include/hw/cxl/cxl_device.h +7 -0
index 9c83421d0f..22ca2f5978 100644
@@ -838,6 +838,8 @@ struct CXLType2Dev {
     HostMemoryBackend *hostvmem;
 
     /* State */
+    MemoryRegion direct_mr[CXL_HDM_DECODER_COUNT];
+    CXLFixedWindow *direct_mr_fw[CXL_HDM_DECODER_COUNT];
     AddressSpace hostvmem_as;
     CXLComponentState cxl_cstate;
     uint8_t dvsec_wmask[PCIE_CXL_DEVICE_DVSEC_LENGTH];
@@ -846,6 +848,11 @@ struct CXLType2Dev {
 #define TYPE_CXL_TYPE2 "cxl-type2"
 OBJECT_DECLARE_SIMPLE_TYPE(CXLType2Dev, CXL_TYPE2)
 
+MemTxResult cxl_type2_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
+                           unsigned size, MemTxAttrs attrs);
+MemTxResult cxl_type2_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
+                            unsigned size, MemTxAttrs attrs);
+
 MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
                            unsigned size, MemTxAttrs attrs);
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
Signature · 1 line
2.53.0
#11 lore raw

RFC 11/18 hw/mem: Require a CXL root port of a pxb-cxl for cxl-type2

In reply to [email protected]

From: Manish Honap <[email protected]>

The firmware decoder setup added later in this series commits only the pxb-cxl and device decoders, and cxl_cfmws_find_device() routes only to devfn 0 below a port. Refuse any other placement.

AI-used-for: code (prototype)

---
 hw/mem/cxl_type2.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
hw/mem/cxl_type2.c +27 -1
index 60f3f04679..ab89d332dc 100644
@@ -11,6 +11,8 @@
 #include "hw/core/qdev-properties.h"
 #include "hw/cxl/cxl.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bridge.h"
+#include "hw/pci/pcie_port.h"
 #include "migration/vmstate.h"
 #include "system/hostmem.h"
 
@@ -22,6 +24,29 @@ static void clean_memory(PCIDevice *pci_dev)
     host_memory_backend_set_mapped(ct2d->hostvmem, false);
 }
 
+/*
+ * The firmware decoder setup covers only the host bridge and the device, and
+ * cxl_cfmws_find_device() routes only to devfn 0 below a port.
+ */
+static bool cxl_type2_check_topology(PCIDevice *pci_dev, Error **errp)
+{
+    PCIDevice *rp = pci_get_bus(pci_dev)->parent_dev;
+    PCIDevice *host = rp ? pci_get_bus(rp)->parent_dev : NULL;
+
+    if (!rp || !pci_is_cxl(rp) ||
+        !object_dynamic_cast(OBJECT(rp), TYPE_PCIE_ROOT_PORT) || !host ||
+        !object_dynamic_cast(OBJECT(host), TYPE_PXB_CXL_DEV)) {
+        error_setg(errp, "cxl-type2 must be directly below a CXL root port "
+                   "of a pxb-cxl");
+        return false;
+    }
+    if (pci_dev->devfn != 0) {
+        error_setg(errp, "cxl-type2 must be at slot 0, function 0");
+        return false;
+    }
+    return true;
+}
+
 static bool setup_memory(PCIDevice *pci_dev, Error **errp)
 {
     CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
@@ -190,7 +215,8 @@ static void setup_cxl_regs(PCIDevice *pci_dev)
 
 static void cxl_type2_realize(PCIDevice *pci_dev, Error **errp)
 {
-    if (!setup_memory(pci_dev, errp)) {
+    if (!cxl_type2_check_topology(pci_dev, errp) ||
+        !setup_memory(pci_dev, errp)) {
         return;
     }
 
Signature · 1 line
2.53.0
#12 lore raw

RFC 12/18 hw/pci-bridge: Add firmware HDM decoder state to pxb-cxl

In reply to [email protected]

From: Manish Honap <[email protected]>

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, so a guest finds no committed region.

Let a cold-plugged device register one range with its pxb-cxl, which then commits HDM decoder 0 for it at every reset. A host bridge with a registered range keeps its decoder instead of passing accesses through. If the device resets first, pxb-cxl retries the direct mapping after the commit.

The CXL Type-2 device registers a range later in this series.

AI-used-for: code (prototype)

---
 hw/cxl/cxl-component-utils.c            | 47 +++++++++++++++++++++++++
 hw/pci-bridge/pci_expander_bridge_cxl.c | 22 ++++++++++--
 include/hw/cxl/cxl_component.h          | 13 +++++++
 include/hw/pci/pci_bridge.h             |  5 +++
 4 files changed, 85 insertions(+), 2 deletions(-)
hw/cxl/cxl-component-utils.c +47 -0
index f9bb1684fa..c61966b202 100644
@@ -9,6 +9,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/pci/pci.h"
 #include "hw/cxl/cxl.h"
@@ -500,6 +501,52 @@ void cxl_component_register_init_common(uint32_t *reg_state,
                                       CXL_HDM_DECODER_COUNT);
 }
 
+/* One range per host bridge; registering the same range again succeeds */
+bool cxl_firmware_hdm_set(CXLFirmwareHDM *fw, const char *owner,
+                          uint64_t base, uint64_t size, uint8_t target,
+                          Error **errp)
+{
+    if (!size || !QEMU_IS_ALIGNED(base, 256 * MiB) ||
+        !QEMU_IS_ALIGNED(size, 256 * MiB)) {
+        error_setg(errp, "firmware HDM range must be 256 MiB aligned");
+        return false;
+    }
+
+    if (fw->valid) {
+        if (fw->base == base && fw->size == size && fw->target == target) {
+            return true;
+        }
+        error_setg(errp, "%s supports one firmware HDM range", owner);
+        return false;
+    }
+
+    *fw = (CXLFirmwareHDM) {
+        .valid = true,
+        .base = base,
+        .size = size,
+        .target = target,
+    };
+    return true;
+}
+
+/*
+ * The caller sets HDM Decoder Enable where it applies. It reads as 0 on host
+ * bridges (CXL r4.0 Section 8.2.4.20.2).
+ */
+void cxl_firmware_hdm_program(const CXLFirmwareHDM *fw, uint32_t *cache_mem)
+{
+    uint32_t ctrl = 0;
+
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_BASE_LO, fw->base & 0xf0000000);
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_BASE_HI, fw->base >> 32);
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_LO, fw->size & 0xf0000000);
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_SIZE_HI, fw->size >> 32);
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_TARGET_LIST_LO, fw->target);
+    ctrl = FIELD_DP32(ctrl, CXL_HDM_DECODER0_CTRL, COMMIT, 1);
+    ctrl = FIELD_DP32(ctrl, CXL_HDM_DECODER0_CTRL, COMMITTED, 1);
+    stl_le_p(cache_mem + R_CXL_HDM_DECODER0_CTRL, ctrl);
+}
+
 /*
  * Helper to creates a DVSEC header for a CXL entity. The caller is responsible
  * for tracking the valid offset.
hw/pci-bridge/pci_expander_bridge_cxl.c +20 -2
index ceb8928f8f..01fd479a9e 100644
@@ -111,9 +111,18 @@ static const TypeInfo cxl_host_info = {
     .class_init    = pxb_cxl_host_class_init,
 };
 
+bool pxb_cxl_register_firmware_hdm(PXBCXLDev *pxb, uint64_t base,
+                                   uint64_t size, uint8_t target,
+                                   Error **errp)
+{
+    return cxl_firmware_hdm_set(&pxb->firmware_hdm, "pxb-cxl", base, size,
+                                target, errp);
+}
+
 static void pxb_cxl_dev_reset(DeviceState *dev)
 {
-    CXLHost *cxl = PXB_CXL_DEV(dev)->cxl_host_bridge;
+    PXBCXLDev *pxb = PXB_CXL_DEV(dev);
+    CXLHost *cxl = pxb->cxl_host_bridge;
     CXLComponentState *cxl_cstate = &cxl->cxl_cstate;
     PCIHostState *hb = PCI_HOST_BRIDGE(cxl);
     uint32_t *reg_state = cxl_cstate->crb.cache_mem_registers;
@@ -121,11 +130,12 @@ static void pxb_cxl_dev_reset(DeviceState *dev)
     int dsp_count = 0;
 
     cxl_component_register_init_common(reg_state, write_msk, CXL2_RC, false);
+    cxl->passthrough = false;
     /*
      * The CXL specification allows for host bridges with no HDM decoders
      * if they only have a single root port.
      */
-    if (!PXB_CXL_DEV(dev)->hdm_for_passthrough) {
+    if (!pxb->hdm_for_passthrough && !pxb->firmware_hdm.valid) {
         dsp_count = pcie_count_ds_ports(hb->bus);
     }
     /* Initial reset will have 0 dsp so wait until > 0 */
@@ -136,6 +146,14 @@ static void pxb_cxl_dev_reset(DeviceState *dev)
     } else {
         ARRAY_FIELD_DP32(reg_state, CXL_HDM_DECODER_CAPABILITY, TARGET_COUNT,
                          8);
+        if (pxb->firmware_hdm.valid) {
+            cxl_firmware_hdm_program(&pxb->firmware_hdm, reg_state);
+            /*
+             * An endpoint that committed before this reset could not map
+             * its memory directly, as this decoder was not committed yet.
+             */
+            cfmws_update_non_interleaved(true);
+        }
     }
 }
 
include/hw/cxl/cxl_component.h +13 -0
index b38e81d129..eb71f1c80a 100644
@@ -328,6 +328,19 @@ void cxl_component_create_dvsec(CXLComponentState *cxl_cstate,
 void cxl_component_update_dvsec(CXLComponentState *cxl, uint16_t length,
                                 uint16_t type, uint8_t *body);
 
+/* The range that firmware routes through HDM decoder 0 to one port */
+typedef struct CXLFirmwareHDM {
+    bool valid;
+    uint64_t base;
+    uint64_t size;
+    uint8_t target;
+} CXLFirmwareHDM;
+
+bool cxl_firmware_hdm_set(CXLFirmwareHDM *fw, const char *owner,
+                          uint64_t base, uint64_t size, uint8_t target,
+                          Error **errp);
+void cxl_firmware_hdm_program(const CXLFirmwareHDM *fw, uint32_t *cache_mem);
+
 int cxl_decoder_count_enc(int count);
 int cxl_decoder_count_dec(int enc_cnt);
 
include/hw/pci/pci_bridge.h +5 -0
index f114f0a651..d0227a4c38 100644
@@ -117,11 +117,16 @@ typedef struct PXBCXLDev {
 
     bool hdm_for_passthrough;
     CXLHost *cxl_host_bridge; /* Pointer to a CXLHost */
+    CXLFirmwareHDM firmware_hdm;
 } PXBCXLDev;
 
 #define TYPE_PXB_CXL_DEV "pxb-cxl"
 OBJECT_DECLARE_SIMPLE_TYPE(PXBCXLDev, PXB_CXL_DEV)
 
+bool pxb_cxl_register_firmware_hdm(PXBCXLDev *pxb, uint64_t base,
+                                   uint64_t size, uint8_t target,
+                                   Error **errp);
+
 int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
                           uint16_t svid, uint16_t ssid,
                           Error **errp);
Signature · 1 line
2.53.0
#13 lore raw

RFC 13/18 hw/mem: Bind cxl-type2 to a fixed memory window

In reply to [email protected]

From: Manish Honap <[email protected]>

fmw-index, 0 by default, selects the fixed memory window that maps the device memory. The window must hold the whole volatile backend, allow device-coherent memory, and have the device's pxb-cxl as its only target. The backend size must be a nonzero multiple of 256 MiB.

The range is registered with the pxb-cxl at realize, one cxl-type2 per pxb-cxl. The pxb-cxl commits its decoder for the range only at reset, so a hotplugged device would find it uncommitted, and an unplugged one could not be plugged back. The device is therefore not hotpluggable.

AI-used-for: code (prototype)

---
 hw/mem/cxl_type2.c                      | 78 +++++++++++++++++++++++++
 hw/pci-bridge/pci_expander_bridge_cxl.c |  5 ++
 include/hw/cxl/cxl_device.h             |  4 ++
 include/hw/pci/pci_bridge.h             |  1 +
 4 files changed, 88 insertions(+)
hw/mem/cxl_type2.c +78 -0
index ab89d332dc..86fcc1a94a 100644
@@ -7,9 +7,11 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/core/qdev-properties.h"
 #include "hw/cxl/cxl.h"
+#include "hw/cxl/cxl_host.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/pcie_port.h"
@@ -30,6 +32,7 @@ static void clean_memory(PCIDevice *pci_dev)
  */
 static bool cxl_type2_check_topology(PCIDevice *pci_dev, Error **errp)
 {
+    CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
     PCIDevice *rp = pci_get_bus(pci_dev)->parent_dev;
     PCIDevice *host = rp ? pci_get_bus(rp)->parent_dev : NULL;
 
@@ -44,9 +47,59 @@ static bool cxl_type2_check_topology(PCIDevice *pci_dev, Error **errp)
         error_setg(errp, "cxl-type2 must be at slot 0, function 0");
         return false;
     }
+
+    ct2d->pxb = PXB_CXL_DEV(host);
+    ct2d->root_port = PCIE_PORT(rp)->port;
+    return true;
+}
+
+/* fw->target_hbs is set only once machine creation is done */
+static bool cxl_type2_resolve_fmw(CXLType2Dev *ct2d, Error **errp)
+{
+    MemoryRegion *mr = host_memory_backend_get_memory(ct2d->hostvmem);
+    GSList *list = cxl_fmws_get_all_sorted();
+    CXLFixedWindow *fw = NULL;
+    unsigned int matches = 0;
+    bool ambiguous = false;
+    Object *target;
+
+    for (GSList *iter = list; iter; iter = iter->next) {
+        if (CXL_FMW(iter->data)->index == ct2d->fmw_index) {
+            fw = CXL_FMW(iter->data);
+            matches++;
+        }
+    }
+    g_slist_free(list);
+
+    if (matches != 1) {
+        error_setg(errp, "cxl-type2 fmw-index %u matched %u CFMWS windows",
+                   ct2d->fmw_index, matches);
+        return false;
+    }
+    if (fw->num_targets != 1) {
+        error_setg(errp, "cxl-type2 requires a single-target CFMWS");
+        return false;
+    }
+    if (!(fw->restrictions & CXL_FMW_DEVICE_COHERENT)) {
+        error_setg(errp, "cxl-type2 CFMWS must allow device-coherent memory");
+        return false;
+    }
+    if (memory_region_size(mr) > fw->size) {
+        error_setg(errp, "cxl-type2 volatile-memdev does not fit in its CFMWS");
+        return false;
+    }
+    target = object_resolve_path_type(fw->targets[0], TYPE_PXB_CXL_DEV,
+                                      &ambiguous);
+    if (!target || ambiguous || target != OBJECT(ct2d->pxb)) {
+        error_setg(errp, "cxl-type2 CFMWS does not target its pxb-cxl");
+        return false;
+    }
+
+    ct2d->fmw = fw;
     return true;
 }
 
+
 static bool setup_memory(PCIDevice *pci_dev, Error **errp)
 {
     CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
@@ -66,6 +119,12 @@ static bool setup_memory(PCIDevice *pci_dev, Error **errp)
                    object_get_canonical_path_component(OBJECT(ct2d->hostvmem)));
         return false;
     }
+    if (!memory_region_size(vmr) ||
+        !QEMU_IS_ALIGNED(memory_region_size(vmr), 256 * MiB)) {
+        error_setg(errp, "volatile-memdev size must be a nonzero multiple of "
+                   "256 MiB");
+        return false;
+    }
     memory_region_set_nonvolatile(vmr, false);
     memory_region_set_enabled(vmr, true);
     host_memory_backend_set_mapped(ct2d->hostvmem, true);
@@ -215,18 +274,34 @@ static void setup_cxl_regs(PCIDevice *pci_dev)
 
 static void cxl_type2_realize(PCIDevice *pci_dev, Error **errp)
 {
+    CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
+    uint64_t size;
+
     if (!cxl_type2_check_topology(pci_dev, errp) ||
         !setup_memory(pci_dev, errp)) {
         return;
     }
+    if (!cxl_type2_resolve_fmw(ct2d, errp)) {
+        clean_memory(pci_dev);
+        return;
+    }
+    size = memory_region_size(host_memory_backend_get_memory(ct2d->hostvmem));
 
     pcie_endpoint_cap_init(pci_dev, 0x80);
 
     setup_cxl_regs(pci_dev);
+
+    if (!pxb_cxl_register_firmware_hdm(ct2d->pxb, ct2d->fmw->base, size,
+                                       ct2d->root_port, errp)) {
+        clean_memory(pci_dev);
+    }
 }
 
 static void cxl_type2_exit(PCIDevice *pci_dev)
 {
+    CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
+
+    pxb_cxl_unregister_firmware_hdm(ct2d->pxb);
     cxl_fmws_direct_passthrough_remove_all(pci_dev);
     clean_memory(pci_dev);
 }
@@ -249,6 +324,7 @@ static void cxl_type2_reset(DeviceState *dev)
 static const Property cxl_type2_props[] = {
     DEFINE_PROP_LINK("volatile-memdev", CXLType2Dev, hostvmem,
                      TYPE_MEMORY_BACKEND, HostMemoryBackend *),
+    DEFINE_PROP_UINT32("fmw-index", CXLType2Dev, fmw_index, 0),
 };
 
 static const VMStateDescription cxl_type2_vmsd = {
@@ -271,6 +347,8 @@ static void cxl_type2_class_init(ObjectClass *oc, const void *data)
     pc->revision = 1;
 
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+    /* pxb-cxl commits its decoder for the device only at reset */
+    dc->hotpluggable = false;
     dc->desc = "CXL Type-2 device";
     dc->vmsd = &cxl_type2_vmsd;
     device_class_set_legacy_reset(dc, cxl_type2_reset);
hw/pci-bridge/pci_expander_bridge_cxl.c +5 -0
index 01fd479a9e..9b0444ce53 100644
@@ -119,6 +119,11 @@ bool pxb_cxl_register_firmware_hdm(PXBCXLDev *pxb, uint64_t base,
                                 target, errp);
 }
 
+void pxb_cxl_unregister_firmware_hdm(PXBCXLDev *pxb)
+{
+    pxb->firmware_hdm = (CXLFirmwareHDM) { 0 };
+}
+
 static void pxb_cxl_dev_reset(DeviceState *dev)
 {
     PXBCXLDev *pxb = PXB_CXL_DEV(dev);
include/hw/cxl/cxl_device.h +4 -0
index 22ca2f5978..b4a33de6e1 100644
@@ -836,8 +836,12 @@ struct CXLType2Dev {
 
     /* Properties */
     HostMemoryBackend *hostvmem;
+    uint32_t fmw_index;
 
     /* State */
+    struct PXBCXLDev *pxb;
+    uint8_t root_port;
+    CXLFixedWindow *fmw;
     MemoryRegion direct_mr[CXL_HDM_DECODER_COUNT];
     CXLFixedWindow *direct_mr_fw[CXL_HDM_DECODER_COUNT];
     AddressSpace hostvmem_as;
include/hw/pci/pci_bridge.h +1 -0
index d0227a4c38..106a3109c8 100644
@@ -126,6 +126,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(PXBCXLDev, PXB_CXL_DEV)
 bool pxb_cxl_register_firmware_hdm(PXBCXLDev *pxb, uint64_t base,
                                    uint64_t size, uint8_t target,
                                    Error **errp);
+void pxb_cxl_unregister_firmware_hdm(PXBCXLDev *pxb);
 
 int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
                           uint16_t svid, uint16_t ssid,
Signature · 1 line
2.53.0
#14 lore raw

RFC 14/18 hw/mem: Commit the cxl-type2 HDM decoder at reset

In reply to [email protected]

From: Manish Honap <[email protected]>

A Linux driver for a CXL Type-2 device attaches to a region that platform firmware committed at boot; devm_cxl_probe_mem() does not create one.

At every reset, do what such firmware does: enable CXL.mem and the HDM decoders, and commit decoder 0 over the volatile memory at the window base with Lock On Commit set. The locked decoder registers are read only until the next reset.

AI-used-for: code (prototype)

---
 hw/mem/cxl_type2.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
hw/mem/cxl_type2.c +42 -0
index 86fcc1a94a..d0fe14afda 100644
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/range.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/core/qdev-properties.h"
@@ -306,6 +307,43 @@ static void cxl_type2_exit(PCIDevice *pci_dev)
     clean_memory(pci_dev);
 }
 
+/* CXL r4.0 Section 8.2.4.20.7: a locked decoder is read only until reset */
+static void cxl_type2_lock_decoder(CXLComponentState *cxl_cstate)
+{
+    uint32_t *write_msk = cxl_cstate->crb.cache_mem_regs_write_mask;
+
+    write_msk[R_CXL_HDM_DECODER0_BASE_LO] = 0;
+    write_msk[R_CXL_HDM_DECODER0_BASE_HI] = 0;
+    write_msk[R_CXL_HDM_DECODER0_SIZE_LO] = 0;
+    write_msk[R_CXL_HDM_DECODER0_SIZE_HI] = 0;
+    write_msk[R_CXL_HDM_DECODER0_CTRL] = 0;
+    write_msk[R_CXL_HDM_DECODER0_DPA_SKIP_LO] = 0;
+    write_msk[R_CXL_HDM_DECODER0_DPA_SKIP_HI] = 0;
+}
+
+static void cxl_type2_firmware_init(CXLType2Dev *ct2d)
+{
+    CXLComponentState *cxl_cstate = &ct2d->cxl_cstate;
+    uint32_t *cache_mem = cxl_cstate->crb.cache_mem_registers;
+    uint16_t ctrl = range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]) +
+                    offsetof(CXLDVSECDevice, ctrl);
+    CXLFirmwareHDM range = {
+        .valid = true,
+        .base = ct2d->fmw->base,
+        .size = memory_region_size(
+            host_memory_backend_get_memory(ct2d->hostvmem)),
+    };
+
+    pci_set_word(PCI_DEVICE(ct2d)->config + ctrl,
+                 CXL_DVSEC_CTRL_IO_EN | CXL_DVSEC_CTRL_MEM_EN);
+    ARRAY_FIELD_DP32(cache_mem, CXL_HDM_DECODER_GLOBAL_CONTROL,
+                     HDM_DECODER_ENABLE, 1);
+    cxl_firmware_hdm_program(&range, cache_mem);
+    ARRAY_FIELD_DP32(cache_mem, CXL_HDM_DECODER0_CTRL, LOCK_ON_COMMIT, 1);
+    cxl_type2_lock_decoder(cxl_cstate);
+    cfmws_update_non_interleaved(true);
+}
+
 static void cxl_type2_reset(DeviceState *dev)
 {
     CXLType2Dev *ct2d = CXL_TYPE2(dev);
@@ -319,6 +357,10 @@ static void cxl_type2_reset(DeviceState *dev)
     cxl_component_register_init_count(cxl_cstate->crb.cache_mem_registers,
                                       cxl_cstate->crb.cache_mem_regs_write_mask,
                                       CXL3_TYPE2_DEVICE, false, 1);
+
+    if (ct2d->fmw) {
+        cxl_type2_firmware_init(ct2d);
+    }
 }
 
 static const Property cxl_type2_props[] = {
Signature · 1 line
2.53.0
#15 lore raw

RFC 15/18 hw/mem: Add CXL.cache with cache write-back and invalidate to cxl-type2

In reply to [email protected]

From: Manish Honap <[email protected]>

Advertise CXL.cache in the Device and Flex Bus Port DVSECs and let firmware set Cache_Enable.

CXL r4.0 Section 8.1.3.1 requires a device that sets Cache_Capable, and is not an RCD, to also set Cache Writeback and Invalidate Capable and implement Disable Caching, Initiate Cache Write Back and Invalidation, and Cache Invalid. The device holds no modified cache lines, so a write back and invalidate completes at once.

AI-used-for: code (prototype)

---
 hw/mem/cxl_type2.c | 66 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 55 insertions(+), 11 deletions(-)
hw/mem/cxl_type2.c +55 -11
index d0fe14afda..54d1b34a4c 100644
@@ -170,6 +170,11 @@ MemTxResult cxl_type2_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     return address_space_write(as, dpa, attrs, &data, size);
 }
 
+static uint16_t cxl_type2_dvsec(CXLType2Dev *ct2d, size_t reg)
+{
+    return range_lob(&ct2d->cxl_cstate.dvsecs[PCIE_CXL_DEVICE_DVSEC]) + reg;
+}
+
 static void update_dvsecs(CXLType2Dev *ct2d)
 {
     CXLComponentState *cxl_cstate = &ct2d->cxl_cstate;
@@ -178,9 +183,9 @@ static void update_dvsecs(CXLType2Dev *ct2d)
     uint8_t *dvsec;
 
     dvsec = (uint8_t *)&(CXLDVSECDevice){
-        .cap = CXL_DVSEC_CAP_IO | CXL_DVSEC_CAP_MEM |
+        .cap = CXL_DVSEC_CAP_CACHE | CXL_DVSEC_CAP_IO | CXL_DVSEC_CAP_MEM |
                CXL_DVSEC_CAP_MEM_HWINIT |
-               1 << CXL_DVSEC_CAP_HDM_COUNT_SHIFT,
+               1 << CXL_DVSEC_CAP_HDM_COUNT_SHIFT | CXL_DVSEC_CAP_CACHE_WBI,
         .ctrl = CXL_DVSEC_CTRL_IO_EN,
         .range1_size_hi = size >> 32,
         .range1_size_lo = (2 << 5) | (2 << 2) | 0x3 | (size & 0xF0000000),
@@ -195,9 +200,9 @@ static void update_dvsecs(CXLType2Dev *ct2d)
                                REG_LOC_DVSEC, dvsec);
 
     dvsec = (uint8_t *)&(CXLDVSECPortFlexBus){
-        .cap                     = 0x26, /* 68B, IO, Mem, non-MLD */
+        .cap                     = 0x27, /* 68B, IO, Cache, Mem, non-MLD */
         .ctrl                    = 0x02, /* IO always enabled */
-        .status                  = 0x26, /* same as capabilities */
+        .status                  = 0x27, /* same as capabilities */
         .rcvd_mod_ts_data_phase1 = 0xef,
     };
     cxl_component_update_dvsec(cxl_cstate, PCIE_CXL3_FLEXBUS_PORT_DVSEC_LENGTH,
@@ -221,10 +226,11 @@ static void build_dvsecs(CXLType2Dev *ct2d)
                                PCIE_CXL3_FLEXBUS_PORT_DVSEC_REVID, NULL);
     update_dvsecs(ct2d);
 
-    /* No CXL.cache and no CXL Reset, so no Control2 bit is writable */
+    /* Disable Caching and Initiate Cache Write Back and Invalidation */
     pci_set_word(PCI_DEVICE(ct2d)->wmask +
-                 range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]) +
-                 offsetof(CXLDVSECDevice, ctrl2), 0);
+                 cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, ctrl2)),
+                 CXL_DVSEC_CTRL2_DISABLE_CACHING |
+                 CXL_DVSEC_CTRL2_INIT_CACHE_WBI);
 
     memcpy(ct2d->dvsec_wmask, PCI_DEVICE(ct2d)->wmask +
            range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]),
@@ -248,11 +254,49 @@ static void cxl_type2_dvsec_lock(CXLType2Dev *ct2d)
     pci_set_quad(wmask + offsetof(CXLDVSECDevice, range2_base_hi), 0);
 }
 
+static void cxl_type2_update_status2(CXLType2Dev *ct2d, uint16_t clear,
+                                     uint16_t set)
+{
+    uint8_t *reg = PCI_DEVICE(ct2d)->config +
+                   cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, status2));
+
+    pci_set_word(reg, (pci_get_word(reg) & ~clear) | set);
+}
+
+/*
+ * CXL r4.0 Section 8.1.3.4: the device holds no modified cache lines, so a
+ * write back and invalidate completes at once.
+ */
+static void cxl_type2_ctrl2_write(CXLType2Dev *ct2d)
+{
+    uint8_t *reg = PCI_DEVICE(ct2d)->config +
+                   cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, ctrl2));
+    uint16_t ctrl2 = pci_get_word(reg);
+
+    if (!(ctrl2 & CXL_DVSEC_CTRL2_DISABLE_CACHING)) {
+        /* Cache Invalid reads as 0 while Disable Caching is 0 */
+        cxl_type2_update_status2(ct2d, CXL_DVSEC_STATUS2_CACHE_INV, 0);
+    }
+    if (ctrl2 & CXL_DVSEC_CTRL2_INIT_CACHE_WBI) {
+        pci_set_word(reg, ctrl2 & ~CXL_DVSEC_CTRL2_INIT_CACHE_WBI);
+        /* Undefined unless Disable Caching is set */
+        if (ctrl2 & CXL_DVSEC_CTRL2_DISABLE_CACHING) {
+            cxl_type2_update_status2(ct2d, 0, CXL_DVSEC_STATUS2_CACHE_INV);
+        }
+    }
+}
+
 static void cxl_type2_config_write(PCIDevice *pci_dev, uint32_t addr,
                                    uint32_t val, int len)
 {
+    CXLType2Dev *ct2d = CXL_TYPE2(pci_dev);
+    uint16_t ctrl2 = cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, ctrl2));
+
     pci_default_write_config(pci_dev, addr, val, len);
-    cxl_type2_dvsec_lock(CXL_TYPE2(pci_dev));
+    cxl_type2_dvsec_lock(ct2d);
+    if (ranges_overlap(addr, len, ctrl2, sizeof(uint16_t))) {
+        cxl_type2_ctrl2_write(ct2d);
+    }
 }
 
 static void setup_cxl_regs(PCIDevice *pci_dev)
@@ -325,8 +369,7 @@ static void cxl_type2_firmware_init(CXLType2Dev *ct2d)
 {
     CXLComponentState *cxl_cstate = &ct2d->cxl_cstate;
     uint32_t *cache_mem = cxl_cstate->crb.cache_mem_registers;
-    uint16_t ctrl = range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]) +
-                    offsetof(CXLDVSECDevice, ctrl);
+    uint16_t ctrl = cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, ctrl));
     CXLFirmwareHDM range = {
         .valid = true,
         .base = ct2d->fmw->base,
@@ -335,7 +378,8 @@ static void cxl_type2_firmware_init(CXLType2Dev *ct2d)
     };
 
     pci_set_word(PCI_DEVICE(ct2d)->config + ctrl,
-                 CXL_DVSEC_CTRL_IO_EN | CXL_DVSEC_CTRL_MEM_EN);
+                 CXL_DVSEC_CTRL_CACHE_EN | CXL_DVSEC_CTRL_IO_EN |
+                 CXL_DVSEC_CTRL_MEM_EN);
     ARRAY_FIELD_DP32(cache_mem, CXL_HDM_DECODER_GLOBAL_CONTROL,
                      HDM_DECODER_ENABLE, 1);
     cxl_firmware_hdm_program(&range, cache_mem);
Signature · 1 line
2.53.0
#16 lore raw

RFC 16/18 hw/mem: Implement CXL Reset for cxl-type2

In reply to [email protected]

From: Manish Honap <[email protected]>

Report CXL Reset Capable and run a CXL Reset when Initiate CXL Reset is set in DVSEC Control2 (CXL r4.0 Section 9.7).

- The locked decoder stays committed, as RWL fields are not affected by CXL Reset once locked (CXL r4.0 Table 8-1).
- Mem_Enable and HDM Decoder Enable return to 0, and while either is 0 the device drops CXL.mem. The direct mapping is disabled and accesses through the window fail until software sets both bits again, which it does when it re-initializes the device after the reset. The bits are also rechecked on every write to DVSEC Control and HDM Decoder Global Control.
- For Global control, default cache_mem write handling is exported as cxl_cache_mem_write_common() and called from a special_ops hook.

The CXL.io part of the reset, which has the scope of an FLR, is not emulated. QEMU runs the whole device reset for an FLR, which would repeat the firmware decoder setup.

AI-used-for: code (prototype)

---
 hw/cxl/cxl-component-utils.c   |  25 +++++---
 hw/mem/cxl_type2.c             | 111 ++++++++++++++++++++++++++++++---
 include/hw/cxl/cxl_component.h |   2 +
 3 files changed, 120 insertions(+), 18 deletions(-)
hw/cxl/cxl-component-utils.c +16 -9
index c61966b202..4886b26c7d 100644
@@ -193,6 +193,21 @@ static void bi_handler(CXLComponentState *cxl_cstate, hwaddr offset,
     stl_le_p((uint8_t *)cache_mem + offset, value);
 }
 
+/* @value has the write mask applied */
+void cxl_cache_mem_write_common(CXLComponentState *cxl_cstate, hwaddr offset,
+                                uint32_t value)
+{
+    if (offset >= A_CXL_HDM_DECODER_CAPABILITY &&
+        offset <= A_CXL_HDM_DECODER3_TARGET_LIST_HI) {
+        dumb_hdm_handler(cxl_cstate, offset, value);
+    } else if (offset == A_CXL_BI_RT_CTRL ||
+               offset == A_CXL_BI_DECODER_CTRL) {
+        bi_handler(cxl_cstate, offset, value);
+    } else {
+        cxl_cstate->crb.cache_mem_registers[offset / 4] = value;
+    }
+}
+
 static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value,
                                     unsigned size)
 {
@@ -213,15 +228,7 @@ static void cxl_cache_mem_write_reg(void *opaque, hwaddr offset, uint64_t value,
             return;
         }
 
-        if (offset >= A_CXL_HDM_DECODER_CAPABILITY &&
-            offset <= A_CXL_HDM_DECODER3_TARGET_LIST_HI) {
-            dumb_hdm_handler(cxl_cstate, offset, value);
-        } else if (offset == A_CXL_BI_RT_CTRL ||
-                   offset == A_CXL_BI_DECODER_CTRL) {
-            bi_handler(cxl_cstate, offset, value);
-        } else {
-            cregs->cache_mem_registers[offset / 4] = value;
-        }
+        cxl_cache_mem_write_common(cxl_cstate, offset, value);
         return;
     }
     case 8:
hw/mem/cxl_type2.c +102 -9

194 lines not on this page · raw message

include/hw/cxl/cxl_component.h +2 -0
index eb71f1c80a..725dc7388d 100644
@@ -313,6 +313,8 @@ typedef struct cxl_component {
 void cxl_component_register_block_init(Object *obj,
                                        CXLComponentState *cxl_cstate,
                                        const char *type);
+void cxl_cache_mem_write_common(CXLComponentState *cxl_cstate, hwaddr offset,
+                                uint32_t value);
 void cxl_component_register_init_count(uint32_t *reg_state,
                                        uint32_t *write_msk,
                                        enum reg_type type, bool bi,
Signature · 1 line
2.53.0
#17 lore raw

RFC 17/18 hw/mem: Clear the cxl-type2 volatile memory on a CXL Reset request

In reply to [email protected]

From: Manish Honap <[email protected]>

Report CXL Reset Mem Clr Capable and zero the volatile backend when Initiate CXL Reset is set with CXL Reset Mem Clr Enable (CXL r4.0 Section 9.7). A failed clear ends the reset with CXL Reset Error.

AI-used-for: code (prototype)

---
 hw/mem/cxl_type2.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
hw/mem/cxl_type2.c +31 -5
index 137758cfd9..2183b0c326 100644
@@ -18,6 +18,7 @@
 #include "hw/pci/pcie_port.h"
 #include "migration/vmstate.h"
 #include "system/hostmem.h"
+#include "system/ramblock.h"
 
 static void clean_memory(PCIDevice *pci_dev)
 {
@@ -215,7 +216,7 @@ static void update_dvsecs(CXLType2Dev *ct2d)
         .cap = CXL_DVSEC_CAP_CACHE | CXL_DVSEC_CAP_IO | CXL_DVSEC_CAP_MEM |
                CXL_DVSEC_CAP_MEM_HWINIT |
                1 << CXL_DVSEC_CAP_HDM_COUNT_SHIFT | CXL_DVSEC_CAP_CACHE_WBI |
-               CXL_DVSEC_CAP_RST,
+               CXL_DVSEC_CAP_RST | CXL_DVSEC_CAP_RST_MEM_CLR,
         .ctrl = CXL_DVSEC_CTRL_IO_EN,
         .range1_size_hi = size >> 32,
         .range1_size_lo = (2 << 5) | (2 << 2) | 0x3 | (size & 0xF0000000),
@@ -260,7 +261,8 @@ static void build_dvsecs(CXLType2Dev *ct2d)
                  cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, ctrl2)),
                  CXL_DVSEC_CTRL2_DISABLE_CACHING |
                  CXL_DVSEC_CTRL2_INIT_CACHE_WBI |
-                 CXL_DVSEC_CTRL2_INIT_CXL_RST);
+                 CXL_DVSEC_CTRL2_INIT_CXL_RST |
+                 CXL_DVSEC_CTRL2_RST_MEM_CLR_EN);
 
     memcpy(ct2d->dvsec_wmask, PCI_DEVICE(ct2d)->wmask +
            range_lob(&cxl_cstate->dvsecs[PCIE_CXL_DEVICE_DVSEC]),
@@ -293,12 +295,31 @@ static void cxl_type2_update_status2(CXLType2Dev *ct2d, uint16_t clear,
     pci_set_word(reg, (pci_get_word(reg) & ~clear) | set);
 }
 
+/*
+ * A discard would change the file behind a private file mapping and undo
+ * the preallocation of a prealloc backend, so those get zeros written.
+ */
+static bool cxl_type2_clear_memory(CXLType2Dev *ct2d)
+{
+    MemoryRegion *vmr = host_memory_backend_get_memory(ct2d->hostvmem);
+    RAMBlock *rb = vmr->ram_block;
+    uint64_t size = memory_region_size(vmr);
+
+    if (rb && !ct2d->hostvmem->prealloc && !ram_block_discard_is_disabled() &&
+        (qemu_ram_get_fd(rb) < 0 || qemu_ram_is_shared(rb)) &&
+        !ram_block_discard_range(rb, 0, size)) {
+        return true;
+    }
+    return address_space_set(&ct2d->hostvmem_as, 0, 0, size,
+                             MEMTXATTRS_UNSPECIFIED) == MEMTX_OK;
+}
+
 /*
  * CXL r4.0 Section 9.7. Fields locked by CONFIG_LOCK or Lock On Commit keep
  * their values. The CXL.io part of the reset, which has the scope of an FLR,
  * is not emulated.
  */
-static void cxl_type2_cxl_reset(CXLType2Dev *ct2d)
+static void cxl_type2_cxl_reset(CXLType2Dev *ct2d, uint16_t ctrl2)
 {
     static const size_t range_bases[] = {
         offsetof(CXLDVSECDevice, range1_base_hi),
@@ -309,6 +330,7 @@ static void cxl_type2_cxl_reset(CXLType2Dev *ct2d)
     uint8_t *config = PCI_DEVICE(ct2d)->config;
     uint32_t *cache_mem = ct2d->cxl_cstate.crb.cache_mem_registers;
     uint16_t lock = cxl_type2_dvsec(ct2d, offsetof(CXLDVSECDevice, lock));
+    bool cleared = true;
 
     cxl_type2_update_status2(ct2d, CXL_DVSEC_STATUS2_RST_DONE |
                              CXL_DVSEC_STATUS2_RST_ERR, 0);
@@ -328,8 +350,12 @@ static void cxl_type2_cxl_reset(CXLType2Dev *ct2d)
 
     cxl_type2_update_mem_active(ct2d);
 
+    if (ctrl2 & CXL_DVSEC_CTRL2_RST_MEM_CLR_EN) {
+        cleared = cxl_type2_clear_memory(ct2d);
+    }
     cxl_type2_update_status2(ct2d, CXL_DVSEC_STATUS2_CACHE_INV,
-                             CXL_DVSEC_STATUS2_RST_DONE);
+                             cleared ? CXL_DVSEC_STATUS2_RST_DONE :
+                             CXL_DVSEC_STATUS2_RST_ERR);
 }
 
 /*
@@ -355,7 +381,7 @@ static void cxl_type2_ctrl2_write(CXLType2Dev *ct2d)
     }
     /* Initiate CXL Reset reads as 0; the reset clears all of Control2 */
     if (ctrl2 & CXL_DVSEC_CTRL2_INIT_CXL_RST) {
-        cxl_type2_cxl_reset(ct2d);
+        cxl_type2_cxl_reset(ct2d, ctrl2);
     }
 }
 
Signature · 1 line
2.53.0
#18 lore raw

RFC 18/18 docs/cxl: Document the CXL Type-2 device

In reply to [email protected]

From: Manish Honap <[email protected]>

Describe cxl-type2, how a guest uses it, its CXL.cache support, where it can be placed, the decoder state it gets at reset, CXL Reset, and example command lines for q35 and virt.

AI-used-for: code (prototype)

---
 docs/system/devices/cxl.rst | 68 +++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
docs/system/devices/cxl.rst +68 -0
index 6bee339cea..b98a066919 100644
@@ -147,6 +147,53 @@ though in these EP devices, the decoder is responsible not for
 routing but for translation of the incoming host physical address (HPA)
 into a Device Physical Address (DPA).
 
+CXL Devices - Type 2
+~~~~~~~~~~~~~~~~~~~~
+``cxl-type2`` is a CXL Type 2 device with volatile device memory. It
+emulates the registers that host software uses to find and set up such
+a device.
+
+The device uses the processing accelerator class code 0x1200, so the
+generic CXL memory device driver does not bind to it, and no other Linux
+driver claims it on its own. A guest uses it through vfio-pci, which
+hands a CXL Type 2 device to the proposed vfio-cxl driver, or through a
+driver of its own that calls the Linux CXL core Type 2 interface. Its
+Device DVSEC reports CXL.cache, CXL.mem, one HDM range, cache write-back
+and invalidate, and CXL Reset with memory clear.
+
+CXL.cache is advertised but not modelled. The device does not send
+CXL.cache requests, and its memory is host RAM. A cache write-back and
+invalidate request completes at once and reports Cache Invalid. The
+capability is set because vfio-cxl takes a device as CXL Type 2 only when
+it reports both CXL.cache and CXL.mem.
+
+The device must be at slot 0, function 0, directly below a CXL root
+port of a pxb-cxl, and cannot be hotplugged or hot-unplugged. A pxb-cxl
+can have one ``cxl-type2`` below it. The size of its ``volatile-memdev``
+must be a multiple of 256 MiB. ``fmw-index``, 0 by default, selects the
+fixed memory window. That window must target only the device's pxb-cxl,
+allow device-coherent memory and hold the whole memory backend.
+
+At every reset QEMU does what platform firmware does at boot. It
+commits the host bridge HDM decoder for the device memory, enables
+CXL.cache and CXL.mem, and commits the device HDM decoder at the window
+base with Lock On Commit set. The locked decoder is read only until the
+next system reset.
+
+The device memory is reachable only while Mem_Enable in DVSEC Control
+and HDM Decoder Enable in HDM Decoder Global Control are both set.
+Otherwise the direct mapping is disabled and accesses through the
+window fail.
+
+Software starts a CXL Reset through DVSEC Control2. The locked decoder
+stays committed. DVSEC Control and the range bases return to their
+defaults unless CONFIG_LOCK is set, and HDM Decoder Global Control
+returns to 0, so the memory is not reachable until software sets
+Mem_Enable and HDM Decoder Enable again.
+A CXL Reset does not repeat the firmware setup, and it leaves the PCI
+Command register and the BARs as they were. With CXL Reset Mem Clr Enable
+set, the reset zeroes the memory backend.
+
 CXL Memory Interleave
 ---------------------
 To understand the interaction of different CXL hardware components which
@@ -332,6 +379,27 @@ The same volatile setup may optionally include an LSA region::
   -device cxl-type3,bus=root_port13,volatile-memdev=vmem0,lsa=cxl-lsa0,id=cxl-vmem0 \
   -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G
 
+A CXL Type 2 device directly attached to a CXL root port. The fixed
+window holds its 256 MiB of memory::
+
+  qemu-system-x86_64 -M q35,cxl=on -m 4G -smp 4 \
+  ...
+  -object memory-backend-ram,id=t2mem0,size=256M \
+  -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
+  -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
+  -device cxl-type2,bus=root_port13,volatile-memdev=t2mem0,id=cxl-t2 \
+  -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=256M
+
+The same device on an Arm virt machine::
+
+  qemu-system-aarch64 -M virt,gic-version=3,cxl=on -m 4G -smp 4 -cpu max \
+  ...
+  -object memory-backend-ram,id=t2mem0,size=256M \
+  -device pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1 \
+  -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \
+  -device cxl-type2,bus=root_port13,volatile-memdev=t2mem0,id=cxl-t2 \
+  -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=256M
+
 A setup suitable for 4 way interleave. Only one fixed window provided, to enable 2 way
 interleave across 2 CXL host bridges.  Each host bridge has 2 CXL Root Ports, with
 the CXL Type3 device directly attached (no switches).::
Signature · 1 line
2.53.0
#19 lore raw
In reply to [email protected]
Quoted 37 lines · On Fri, 6 Nov 2026 09:28:53 +0530 <[email protected]> wrote:

From: Manish Honap <[email protected]>

Hello,

This series adds cxl-type2, an emulated CXL Type-2 device with volatile device memory. It is emulated in such a way that all the Linux checks are satisfied so that CXL passthrough using vfio-pci (vfio-cxl) can be developed and tested in a guest without Type-2 hardware.

This series builds on the Type-2 model from Zhi's series (carried in Cédric's tree) and carries one fix from Shuai's tree. Shuai's tree also set up the decoders through device properties and stubbed CXL Reset; the firmware setup and CXL Reset here are new code.
Carried patches keep their authors, with a note for each change.

The device:
- PCI ID 1b36:0017 and the processing accelerator class 0x1200;
- PCIe DVSEC for CXL Devices with CXL.cache, CXL.mem, one HDM range, cache write-back and invalidate, CXL Reset and Mem Clr; Register Locator and Flex Bus Port DVSECs;
- CXL.cache advertised but not modelled. The device sends no CXL.cache requests, and its memory is host RAM, which is coherent already. A cache write-back and invalidate completes at once. The capability is set because vfio-cxl takes a device as Type-2 only when it reports both CXL.cache and CXL.mem;
- component registers with one HDM decoder;
- slot 0, function 0 below a CXL root port of a pxb-cxl, memory in one fixed memory window selected with fmw-index, cold plug only (no hotplug or unplug), not migratable.

No Linux driver claims the device on its own. cxl_pci does not bind to the accelerator class, and sfc, the other driver that calls the CXL core Type-2 interface, matches only its own devices. A guest binds cxl-type2 to vfio-pci, which hands it to vfio-cxl. Testing the CXL core Type-2 interface without vfio-cxl needs a driver for 1b36:0017 that calls it. There is none yet.

Quoted 3 lines

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, and Linux attaches a Type-2 device only to a committed region (devm_cxl_probe_mem()). So QEMU does that step itself.

Just in case you missed it, Yukiya Takaki is looking at bios programmed flows. https://lore.kernel.org/all/[email protected]/

My immediate thought is follow a similar flow to the one I suggested in that patch. Doing CXL setup in QEMU but the PCI enumeration in the bios doesn't seem like a sustainable model to me. I'd much prefer to see a bios flow with just the QEMU generate tables updated in a similar fashion to how DSDT is updated for PXBs.

Alternative for you (assuming you care more about arm than x86) might be to just use the SBSA model and do the full enumeration in firmware.

Unfortunately I have quite a large backlog so might be a while before I get a chance to take a close look at this series (or the kernel ones!)

Jonathan

#20 lore raw
Quoted 74 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Thursday, November 12, 2026 7:22 AM
To: Manish Honap <[email protected]>
Cc: Alex Williamson <[email protected]>; [email protected]; [email protected]; [email protected]; Zhi Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ankit Agrawal <[email protected]>; Vikram Sethi <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Matt Ochs <[email protected]>; Neo Jia <[email protected]>; Krishnakant Jaju <[email protected]>; [email protected]; [email protected]; Yukiya Takaki <[email protected]>
Subject: Re: [RFC 00/18] hw/cxl: Add a CXL Type-2 device

External email: Use caution opening links or attachments

Quoted 38 lines · On Fri, 6 Nov 2026 09:28:53 +0530 <[email protected]> wrote:

From: Manish Honap <[email protected]>

Hello,

This series adds cxl-type2, an emulated CXL Type-2 device with volatile device memory. It is emulated in such a way that all the Linux checks are satisfied so that CXL passthrough using vfio-pci (vfio-cxl) can be developed and tested in a guest without Type-2 hardware.

This series builds on the Type-2 model from Zhi's series (carried in Cédric's tree) and carries one fix from Shuai's tree. Shuai's tree also set up the decoders through device properties and stubbed CXL Reset; the firmware setup and CXL Reset here are new code. Carried patches keep their authors, with a note for each change.

The device:
- PCI ID 1b36:0017 and the processing accelerator class 0x1200;
- PCIe DVSEC for CXL Devices with CXL.cache, CXL.mem, one HDM range, cache write-back and invalidate, CXL Reset and Mem Clr; Register Locator and Flex Bus Port DVSECs;
- CXL.cache advertised but not modelled. The device sends no CXL.cache requests, and its memory is host RAM, which is coherent already. A cache write-back and invalidate completes at once. The capability is set because vfio-cxl takes a device as Type-2 only when it reports both CXL.cache and CXL.mem;
- component registers with one HDM decoder;
- slot 0, function 0 below a CXL root port of a pxb-cxl, memory in one fixed memory window selected with fmw-index, cold plug only (no hotplug or unplug), not migratable.

No Linux driver claims the device on its own. cxl_pci does not bind to the accelerator class, and sfc, the other driver that calls the CXL core Type-2 interface, matches only its own devices. A guest binds cxl-type2 to vfio-pci, which hands it to vfio-cxl. Testing the CXL core
Type-2 interface without vfio-cxl needs a driver for 1b36:0017 that calls it. There is none yet.

Quoted 3 lines

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, and Linux attaches a Type-2 device only to a committed region (devm_cxl_probe_mem()). So QEMU does that step itself.

Just in case you missed it, Yukiya Takaki is looking at bios programmed flows.
https://lore.kernel.org/all/[email protected]/

My immediate thought is follow a similar flow to the one I suggested in that patch. Doing CXL setup in QEMU but the PCI enumeration in the bios doesn't seem like a sustainable model to me. I'd much prefer to see a bios flow with just the QEMU generate tables updated in a similar fashion to how DSDT is updated for PXBs.

Quoted 8 lines

Alternative for you (assuming you care more about arm than x86) might be to just use the SBSA model and do the full enumeration in firmware.

Unfortunately I have quite a large backlog so might be a while before I get a chance to take a close look at this series (or the kernel ones!)

Jonathan

Thank you Jonathan; I will take a look at the suggested series and SBSA model for this.

#21 lore raw
In reply to [email protected]
Quoted 82 lines · On 2026/11/05 20:58, [email protected] wrote:

From: Manish Honap <[email protected]>

Hello,

This series adds cxl-type2, an emulated CXL Type-2 device with volatile device memory. It is emulated in such a way that all the Linux checks are satisfied so that CXL passthrough using vfio-pci (vfio-cxl) can be developed and tested in a guest without Type-2 hardware.

This series builds on the Type-2 model from Zhi's series (carried in Cédric's tree) and carries one fix from Shuai's tree. Shuai's tree also set up the decoders through device properties and stubbed CXL Reset; the firmware setup and CXL Reset here are new code.
Carried patches keep their authors, with a note for each change.

The device:
- PCI ID 1b36:0017 and the processing accelerator class 0x1200;
- PCIe DVSEC for CXL Devices with CXL.cache, CXL.mem, one HDM range, cache write-back and invalidate, CXL Reset and Mem Clr; Register Locator and Flex Bus Port DVSECs;
- CXL.cache advertised but not modelled. The device sends no CXL.cache requests, and its memory is host RAM, which is coherent already. A cache write-back and invalidate completes at once. The capability is set because vfio-cxl takes a device as Type-2 only when it reports both CXL.cache and CXL.mem;
- component registers with one HDM decoder;
- slot 0, function 0 below a CXL root port of a pxb-cxl, memory in one fixed memory window selected with fmw-index, cold plug only (no hotplug or unplug), not migratable.

No Linux driver claims the device on its own. cxl_pci does not bind to the accelerator class, and sfc, the other driver that calls the CXL core Type-2 interface, matches only its own devices. A guest binds cxl-type2 to vfio-pci, which hands it to vfio-cxl. Testing the CXL core Type-2 interface without vfio-cxl needs a driver for 1b36:0017 that calls it. There is none yet.

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, and Linux attaches a Type-2 device only to a committed region (devm_cxl_probe_mem()). So QEMU does that step itself. cxl-type2 registers its range with its pxb-cxl at realize (patch 13). At every reset the pxb-cxl commits HDM decoder 0 for it (patch 12), and the device commits its own decoder with Lock On Commit and enables CXL.cache, CXL.mem and HDM decoding (patch 14). A pxb-cxl with a registered range keeps its HDM decoder even with a single root port, where it would otherwise pass accesses through. Type-3 devices, and pxb-cxl without a registered range, are not affected.

A CXL Reset keeps the locked decoder committed, as RWL fields are not affected by CXL Reset once locked (CXL r4.0 Table 8-1). DVSEC Control, the range bases and HDM Decoder Global Control return to their defaults, which leaves Mem_Enable and HDM Decoder Enable at 0. While either is 0 the device drops CXL.mem, so guest accesses to its memory fail until software sets both bits again. The CXL.io part of the reset is not emulated. CONFIG_LOCK makes the RWL DVSEC fields read only until a system reset.

Patches:
- 1-7: Shared CXL code: read-0 ops for the CXL.io range of the
component registers, helpers from Zhi, an HDM decoder count, DVSEC bit names, a device-neutral view for the direct mapping code, PCI IDs;
- 8-17: The device; patch 16 also exports the default component register write handling, so the device can check the enable bits after a write;
- 18: Docs;

Left for later series:
- The CXL device registers with the mailbox, event logs and MSI-X, and the CDAT;
- Direct mapping lifecycle fixes for Type-3 and switch topologies, and Lock On Commit in host bridges and switches;
- Fixes for guest-triggered aborts on 1 and 2 byte mailbox writes and a repeated DOE Go;
- Software-programmed decoders, for Linux-created Type-2 regions;
- A Type-2 device below a CXL switch, and migration.

Testing:
- Build every commit for x86_64 and aarch64, checkpatch for style.
- vfio-cxl selftest (vfio_cxl_type2_test) in an Arm L1 guest on KVM, with the device below a CXL root port and an SMMUv3: 19 of 19 pass

Quoted 7 lines

- Not tested: x86_64 L1, a build without CONFIG_CXL_TYPE2_DEVICE.

The Linux vfio-cxl series(v5) this was tested with:
https://lore.kernel.org/r/[email protected]

Sent as RFC to get comments on the series structure and to request 1b36:0017 devid for cxl-type2 device allocation.

Note: that device ID has already been requested for a device called CnuasNIC:

("[PATCH v3 0/6] hw: Add Cnuas virtual devices")
https://lore.kernel.org/qemu-devel/[email protected]/

Regards,
Akihiko Odaki

Quoted 65 lines

References:
[PATCH RFC 0/5] hw/cxl: Type 2 Device RFC
https://lore.kernel.org/linux-cxl/[email protected]/

Type-2 emulation trees:

[1] Zhi Wang
https://github.com/zhiwang-nvidia/qemu/commits/zhi/qemu-type2-emulation-for-review

[2] Cédric Le Goater
https://github.com/legoater/qemu/tree/cxl-type2

[3] Shuai Xue
https://gitee.com/axiqia/qemu-kvm/tree/cxl-type2-test

Manish Honap (12):
hw/cxl: Make HDM decoder initialization count-aware hw/cxl: Define the CXL Device DVSEC capability and control bits hw/cxl: Find the memory of a CXL device through one helper hw/pci: Add PCI IDs for the CXL Type-2 device
hw/mem: Require a CXL root port of a pxb-cxl for cxl-type2 hw/pci-bridge: Add firmware HDM decoder state to pxb-cxl hw/mem: Bind cxl-type2 to a fixed memory window
hw/mem: Commit the cxl-type2 HDM decoder at reset hw/mem: Add CXL.cache with cache write-back and invalidate to
cxl-type2
hw/mem: Implement CXL Reset for cxl-type2
hw/mem: Clear the cxl-type2 volatile memory on a CXL Reset request docs/cxl: Document the CXL Type-2 device

Shuai Xue (1):
hw/cxl: Give the component register .io sub-region read-0 ops

Zhi Wang (5):
hw/cxl: Factor out cxl_host_addr_to_dpa()
hw/cxl: Introduce cxl_component_update_dvsec()
hw/cxl: Introduce CXL type-2 device emulation
hw/cxl: Add the CXL type-2 DVSECs and component registers hw/cxl: Map the CXL type-2 device memory through the fixed windows

  MAINTAINERS                             |   1 +
  docs/specs/pci-ids.rst                  |   2 +
  docs/system/devices/cxl.rst             |  68 +++
  hw/cxl/cxl-component-utils.c            | 227 +++++++++-
  hw/cxl/cxl-host.c                       | 130 ++++--
  hw/mem/Kconfig                          |   5 +
  hw/mem/cxl_type2.c                      | 580 ++++++++++++++++++++++++
  hw/mem/cxl_type2_stubs.c                |  20 +
  hw/mem/cxl_type3.c                      |  68 +--
  hw/mem/meson.build                      |   2 +
  hw/pci-bridge/pci_expander_bridge_cxl.c |  27 +-
  include/hw/cxl/cxl.h                    |   1 +
  include/hw/cxl/cxl_component.h          |  26 ++
  include/hw/cxl/cxl_device.h             |  27 ++
  include/hw/cxl/cxl_pci.h                |  31 ++
  include/hw/pci/pci.h                    |   1 +
  include/hw/pci/pci_bridge.h             |   6 +
  include/hw/pci/pci_ids.h                |   3 +
  18 files changed, 1102 insertions(+), 123 deletions(-)

create mode 100644 hw/mem/cxl_type2.c
create mode 100644 hw/mem/cxl_type2_stubs.c

base-commit: f71afb409a87c4ecd0f9d63a5963eb645dfab780

#22 lore raw
Quoted 110 lines

-----Original Message-----
From: Akihiko Odaki <[email protected]>
Sent: Thursday, November 12, 2026 11:23 PM
To: Manish Honap <[email protected]>; [email protected]; Alex Williamson <[email protected]>; [email protected]; [email protected]; [email protected]; Zhi Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ankit Agrawal <[email protected]>; Vikram Sethi <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Matt Ochs <[email protected]>; Weqaar Janjua <[email protected]>; Gerd Hoffmann <[email protected]>
Cc: Neo Jia <[email protected]>; Krishnakant Jaju <[email protected]>; qemu- [email protected]; [email protected]
Subject: Re: [RFC 00/18] hw/cxl: Add a CXL Type-2 device

External email: Use caution opening links or attachments

Quoted 88 lines · On 2026/11/05 20:58, [email protected] wrote:

From: Manish Honap <[email protected]>

Hello,

This series adds cxl-type2, an emulated CXL Type-2 device with volatile device memory. It is emulated in such a way that all the Linux checks are satisfied so that CXL passthrough using vfio-pci (vfio-cxl) can be developed and tested in a guest without Type-2 hardware.

This series builds on the Type-2 model from Zhi's series (carried in Cédric's tree) and carries one fix from Shuai's tree. Shuai's tree also set up the decoders through device properties and stubbed CXL Reset; the firmware setup and CXL Reset here are new code. Carried patches keep their authors, with a note for each change.

The device:
- PCI ID 1b36:0017 and the processing accelerator class 0x1200;
- PCIe DVSEC for CXL Devices with CXL.cache, CXL.mem, one HDM range, cache write-back and invalidate, CXL Reset and Mem Clr; Register Locator and Flex Bus Port DVSECs;
- CXL.cache advertised but not modelled. The device sends no CXL.cache requests, and its memory is host RAM, which is coherent already. A cache write-back and invalidate completes at once. The capability is set because vfio-cxl takes a device as Type-2 only when it reports both CXL.cache and CXL.mem;
- component registers with one HDM decoder;
- slot 0, function 0 below a CXL root port of a pxb-cxl, memory in one fixed memory window selected with fmw-index, cold plug only (no hotplug or unplug), not migratable.

No Linux driver claims the device on its own. cxl_pci does not bind to the accelerator class, and sfc, the other driver that calls the CXL core Type-2 interface, matches only its own devices. A guest binds cxl-type2 to vfio-pci, which hands it to vfio-cxl. Testing the CXL core
Type-2 interface without vfio-cxl needs a driver for 1b36:0017 that calls it. There is none yet.

QEMU has no firmware that commits the HDM decoders of a CXL route at boot, and Linux attaches a Type-2 device only to a committed region (devm_cxl_probe_mem()). So QEMU does that step itself. cxl-type2 registers its range with its pxb-cxl at realize (patch 13). At every reset the pxb-cxl commits HDM decoder 0 for it (patch 12), and the device commits its own decoder with Lock On Commit and enables CXL.cache, CXL.mem and HDM decoding (patch 14). A pxb-cxl with a registered range keeps its HDM decoder even with a single root port, where it would otherwise pass accesses through. Type-3 devices, and pxb-cxl without a registered range, are not affected.

A CXL Reset keeps the locked decoder committed, as RWL fields are not affected by CXL Reset once locked (CXL r4.0 Table 8-1). DVSEC Control, the range bases and HDM Decoder Global Control return to their defaults, which leaves Mem_Enable and HDM Decoder Enable at 0. While either is 0 the device drops CXL.mem, so guest accesses to its memory fail until software sets both bits again. The CXL.io part of the reset is not emulated. CONFIG_LOCK makes the RWL DVSEC fields read only until a system reset.

Patches:
- 1-7: Shared CXL code: read-0 ops for the CXL.io range of the
component registers, helpers from Zhi, an HDM decoder count, DVSEC bit names, a device-neutral view for the direct mapping code, PCI IDs;
- 8-17: The device; patch 16 also exports the default component register write handling, so the device can check the enable bits after a write;
- 18: Docs;

Left for later series:
- The CXL device registers with the mailbox, event logs and MSI-X, and the CDAT;
- Direct mapping lifecycle fixes for Type-3 and switch topologies, and Lock On Commit in host bridges and switches;
- Fixes for guest-triggered aborts on 1 and 2 byte mailbox writes and a repeated DOE Go;
- Software-programmed decoders, for Linux-created Type-2 regions;
- A Type-2 device below a CXL switch, and migration.

Testing:
- Build every commit for x86_64 and aarch64, checkpatch for style.
- vfio-cxl selftest (vfio_cxl_type2_test) in an Arm L1 guest on KVM, with the device below a CXL root port and an SMMUv3: 19 of 19 pass

- Not tested: x86_64 L1, a build without CONFIG_CXL_TYPE2_DEVICE.

The Linux vfio-cxl series(v5) this was tested with:
https://lore.kernel.org/r/[email protected]

Quoted 9 lines
Quoted 2 lines

Sent as RFC to get comments on the series structure and to request 1b36:0017 devid for cxl-type2 device allocation.

Note: that device ID has already been requested for a device called CnuasNIC:

("[PATCH v3 0/6] hw: Add Cnuas virtual devices") https://lore.kernel.org/qemu-
devel/[email protected]/

Okay, thanks for the heads-up. I will request for new value.

Quoted 71 lines

Regards,
Akihiko Odaki

Quoted 10 lines

References:
[PATCH RFC 0/5] hw/cxl: Type 2 Device RFC
https://lore.kernel.org/linux-cxl/20230517-rfc-type2-dev-v1-0-6eb2e470
[email protected]/

Type-2 emulation trees:

[1] Zhi Wang
https://github.com/zhiwang-nvidia/qemu/commits/zhi/qemu-type2-

emulatio

Quoted 57 lines

n-for-review

[2] Cédric Le Goater
https://github.com/legoater/qemu/tree/cxl-type2

[3] Shuai Xue
https://gitee.com/axiqia/qemu-kvm/tree/cxl-type2-test

Manish Honap (12):
hw/cxl: Make HDM decoder initialization count-aware hw/cxl: Define the CXL Device DVSEC capability and control bits hw/cxl: Find the memory of a CXL device through one helper hw/pci: Add PCI IDs for the CXL Type-2 device
hw/mem: Require a CXL root port of a pxb-cxl for cxl-type2 hw/pci-bridge: Add firmware HDM decoder state to pxb-cxl hw/mem: Bind cxl-type2 to a fixed memory window
hw/mem: Commit the cxl-type2 HDM decoder at reset hw/mem: Add CXL.cache with cache write-back and invalidate to
cxl-type2
hw/mem: Implement CXL Reset for cxl-type2
hw/mem: Clear the cxl-type2 volatile memory on a CXL Reset request docs/cxl: Document the CXL Type-2 device

Shuai Xue (1):
hw/cxl: Give the component register .io sub-region read-0 ops

Zhi Wang (5):
hw/cxl: Factor out cxl_host_addr_to_dpa()
hw/cxl: Introduce cxl_component_update_dvsec()
hw/cxl: Introduce CXL type-2 device emulation
hw/cxl: Add the CXL type-2 DVSECs and component registers hw/cxl: Map the CXL type-2 device memory through the fixed windows

  MAINTAINERS                             |   1 +
  docs/specs/pci-ids.rst                  |   2 +
  docs/system/devices/cxl.rst             |  68 +++
  hw/cxl/cxl-component-utils.c            | 227 +++++++++-
  hw/cxl/cxl-host.c                       | 130 ++++--
  hw/mem/Kconfig                          |   5 +
  hw/mem/cxl_type2.c                      | 580 ++++++++++++++++++++++++
  hw/mem/cxl_type2_stubs.c                |  20 +
  hw/mem/cxl_type3.c                      |  68 +--
  hw/mem/meson.build                      |   2 +
  hw/pci-bridge/pci_expander_bridge_cxl.c |  27 +-
  include/hw/cxl/cxl.h                    |   1 +
  include/hw/cxl/cxl_component.h          |  26 ++
  include/hw/cxl/cxl_device.h             |  27 ++
  include/hw/cxl/cxl_pci.h                |  31 ++
  include/hw/pci/pci.h                    |   1 +
  include/hw/pci/pci_bridge.h             |   6 +
  include/hw/pci/pci_ids.h                |   3 +
  18 files changed, 1102 insertions(+), 123 deletions(-)

create mode 100644 hw/mem/cxl_type2.c
create mode 100644 hw/mem/cxl_type2_stubs.c

base-commit: f71afb409a87c4ecd0f9d63a5963eb645dfab780