Skip to contentSkip to conversation

CXL: SK hynix Niagara MHSLD Device

PATCH Superseded Gregory Price 4 participants 18 messages Sep 1, 2023 – Sep 12, 2023 Arm/Amlogic Meson SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover CXL: SK hynix Niagara MHSLD Device

v2:
- 5 patch series, first 4 are pull-aheads that can be merged separately
- cci: rebased on 8-30 branch from jic23, dropped cci patches
- mailbox: dropped MHD commands, integrated into niagara (for now)
- mailbox: refactor CCI defines to avoid redefinition in niagara
- type3: cleanup duplicate typecasting
- type3: expose ct3 functions so inheriting devices may access them
- type3: add optional mhd validation function for memory access
- niagara: refactor to make niagara inherit type3 and override behavior
- niagara: refactor command definitions and types into header to make understanding the device a bit easier for users
- style and formatting

This patch set includes an emulation of the SK hynix Niagara MHSLD platform with custom CCI commands that allow for isolation of memory blocks between attached hosts.

This device allows hosts to request memory blocks directly from the device, rather than requiring full the DCD command set. As a matter of simplicity, this is beneficial to for testing and applications of dynamic memory pooling on top of the 1.1 and 2.0 specification.

Note that these CCI commands are not servicable without a proper driver or the kernel allowing raw CXL commands to be passed through the mailbox driver, so users should enable CONFIG_CXL_MEM_RAW_COMMANDS=y on the kernel of their QEMU instance if they wish to test it

Gregory Price (5):
cxl/mailbox: move mailbox effect definitions to a header cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write functions cxl/type3: Expose ct3 functions so that inheriters can call them cxl/type3: add an optional mhd validation function for memory accesses cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

 hw/cxl/Kconfig                          |   4 +
 hw/cxl/cxl-mailbox-utils.c              |  35 +-
 hw/cxl/meson.build                      |   2 +
 hw/cxl/vendor/meson.build               |   1 +
 hw/cxl/vendor/skhynix/.gitignore        |   1 +
 hw/cxl/vendor/skhynix/init_niagara.c    |  99 +++++
 hw/cxl/vendor/skhynix/meson.build       |   1 +
 hw/cxl/vendor/skhynix/skhynix_niagara.c | 516 ++++++++++++++++++++++++
 hw/cxl/vendor/skhynix/skhynix_niagara.h | 169 ++++++++
 hw/mem/cxl_type3.c                      |  33 +-
 include/hw/cxl/cxl_device.h             |   8 +
 include/hw/cxl/cxl_mailbox.h            |  18 +
 12 files changed, 863 insertions(+), 24 deletions(-)
 create mode 100644 hw/cxl/vendor/meson.build
 create mode 100644 hw/cxl/vendor/skhynix/.gitignore
 create mode 100644 hw/cxl/vendor/skhynix/init_niagara.c
 create mode 100644 hw/cxl/vendor/skhynix/meson.build
 create mode 100644 hw/cxl/vendor/skhynix/skhynix_niagara.c
 create mode 100644 hw/cxl/vendor/skhynix/skhynix_niagara.h
 create mode 100644 include/hw/cxl/cxl_mailbox.h
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/5 cxl/mailbox: move mailbox effect definitions to a header

Preparation for allowing devices to define their own CCI commands

---
 hw/cxl/cxl-mailbox-utils.c   | 35 +++++++++++++++++++----------------
 include/hw/cxl/cxl_mailbox.h | 18 ++++++++++++++++++
 2 files changed, 37 insertions(+), 16 deletions(-)
 create mode 100644 include/hw/cxl/cxl_mailbox.h
hw/cxl/cxl-mailbox-utils.c +19 -16
index 4e8651ebe2..edf39a3efb 100644
@@ -12,6 +12,7 @@
 #include "hw/pci/msix.h"
 #include "hw/cxl/cxl.h"
 #include "hw/cxl/cxl_events.h"
+#include "hw/cxl/cxl_mailbox.h"
 #include "hw/pci/pci.h"
 #include "hw/pci-bridge/cxl_upstream_port.h"
 #include "qemu/cutils.h"
@@ -1561,28 +1562,28 @@ static CXLRetCode cmd_dcd_release_dyn_cap(const struct cxl_cmd *cmd,
     return CXL_MBOX_SUCCESS;
 }
 
-#define IMMEDIATE_CONFIG_CHANGE (1 << 1)
-#define IMMEDIATE_DATA_CHANGE (1 << 2)
-#define IMMEDIATE_POLICY_CHANGE (1 << 3)
-#define IMMEDIATE_LOG_CHANGE (1 << 4)
-#define SECURITY_STATE_CHANGE (1 << 5)
-#define BACKGROUND_OPERATION (1 << 6)
+#define CXL_MBOX_IMMEDIATE_CONFIG_CHANGE (1 << 1)
+#define CXL_MBOX_IMMEDIATE_DATA_CHANGE (1 << 2)
+#define CXL_MBOX_IMMEDIATE_POLICY_CHANGE (1 << 3)
+#define CXL_MBOX_IMMEDIATE_LOG_CHANGE (1 << 4)
+#define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5)
+#define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
 
 static const struct cxl_cmd cxl_cmd_set[256][256] = {
     [EVENTS][GET_RECORDS] = { "EVENTS_GET_RECORDS",
         cmd_events_get_records, 1, 0 },
     [EVENTS][CLEAR_RECORDS] = { "EVENTS_CLEAR_RECORDS",
-        cmd_events_clear_records, ~0, IMMEDIATE_LOG_CHANGE },
+        cmd_events_clear_records, ~0, CXL_MBOX_IMMEDIATE_LOG_CHANGE },
     [EVENTS][GET_INTERRUPT_POLICY] = { "EVENTS_GET_INTERRUPT_POLICY",
                                       cmd_events_get_interrupt_policy, 0, 0 },
     [EVENTS][SET_INTERRUPT_POLICY] = { "EVENTS_SET_INTERRUPT_POLICY",
                                       cmd_events_set_interrupt_policy,
-                                      ~0, IMMEDIATE_CONFIG_CHANGE },
+                                      ~0, CXL_MBOX_IMMEDIATE_CONFIG_CHANGE },
     [FIRMWARE_UPDATE][GET_INFO] = { "FIRMWARE_UPDATE_GET_INFO",
         cmd_firmware_update_get_info, 0, 0 },
     [TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
     [TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8,
-                         IMMEDIATE_POLICY_CHANGE },
+                         CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
     [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0, 0 },
     [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
     [IDENTIFY][MEMORY_DEVICE] = { "IDENTIFY_MEMORY_DEVICE",
@@ -1591,9 +1592,11 @@ static const struct cxl_cmd cxl_cmd_set[256][256] = {
         cmd_ccls_get_partition_info, 0, 0 },
     [CCLS][GET_LSA] = { "CCLS_GET_LSA", cmd_ccls_get_lsa, 8, 0 },
     [CCLS][SET_LSA] = { "CCLS_SET_LSA", cmd_ccls_set_lsa,
-        ~0, IMMEDIATE_CONFIG_CHANGE | IMMEDIATE_DATA_CHANGE },
+        ~0, CXL_MBOX_IMMEDIATE_CONFIG_CHANGE | CXL_MBOX_IMMEDIATE_DATA_CHANGE },
     [SANITIZE][OVERWRITE] = { "SANITIZE_OVERWRITE", cmd_sanitize_overwrite, 0,
-        IMMEDIATE_DATA_CHANGE | SECURITY_STATE_CHANGE | BACKGROUND_OPERATION },
+        (CXL_MBOX_IMMEDIATE_DATA_CHANGE |
+         CXL_MBOX_SECURITY_STATE_CHANGE |
+         CXL_MBOX_BACKGROUND_OPERATION)},
     [PERSISTENT_MEM][GET_SECURITY_STATE] = { "GET_SECURITY_STATE",
         cmd_get_security_state, 0, 0 },
     [MEDIA_AND_POISON][GET_POISON_LIST] = { "MEDIA_AND_POISON_GET_POISON_LIST",
@@ -1612,10 +1615,10 @@ static const struct cxl_cmd cxl_cmd_set_dcd[256][256] = {
         8, 0 },
     [DCD_CONFIG][ADD_DYN_CAP_RSP] = {
         "ADD_DCD_DYNAMIC_CAPACITY_RESPONSE", cmd_dcd_add_dyn_cap_rsp,
-        ~0, IMMEDIATE_DATA_CHANGE },
+        ~0, CXL_MBOX_IMMEDIATE_DATA_CHANGE },
     [DCD_CONFIG][RELEASE_DYN_CAP] = {
         "RELEASE_DCD_DYNAMIC_CAPACITY", cmd_dcd_release_dyn_cap,
-        ~0, IMMEDIATE_DATA_CHANGE },
+        ~0, CXL_MBOX_IMMEDIATE_DATA_CHANGE },
 };
 
 static const struct cxl_cmd cxl_cmd_set_sw[256][256] = {
@@ -1628,7 +1631,7 @@ static const struct cxl_cmd cxl_cmd_set_sw[256][256] = {
      */
     [TIMESTAMP][GET] = { "TIMESTAMP_GET", cmd_timestamp_get, 0, 0 },
     [TIMESTAMP][SET] = { "TIMESTAMP_SET", cmd_timestamp_set, 8,
-                         IMMEDIATE_POLICY_CHANGE },
+                         CXL_MBOX_IMMEDIATE_POLICY_CHANGE },
     [LOGS][GET_SUPPORTED] = { "LOGS_GET_SUPPORTED", cmd_logs_get_supported, 0,
                               0 },
     [LOGS][GET_LOG] = { "LOGS_GET_LOG", cmd_logs_get_log, 0x18, 0 },
@@ -1670,7 +1673,7 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
     }
 
     /* Only one bg command at a time */
-    if ((cxl_cmd->effect & BACKGROUND_OPERATION) &&
+    if ((cxl_cmd->effect & CXL_MBOX_BACKGROUND_OPERATION) &&
         cci->bg.runtime > 0) {
         return CXL_MBOX_BUSY;
     }
@@ -1691,7 +1694,7 @@ int cxl_process_cci_message(CXLCCI *cci, uint8_t set, uint8_t cmd,
     }
 
     ret = (*h)(cxl_cmd, pl_in, len_in, pl_out, len_out, cci);
-    if ((cxl_cmd->effect & BACKGROUND_OPERATION) &&
+    if ((cxl_cmd->effect & CXL_MBOX_BACKGROUND_OPERATION) &&
         ret == CXL_MBOX_BG_STARTED) {
         *bg_started = true;
     } else {
include/hw/cxl/cxl_mailbox.h new file +18 -0
new file mode 100644
index 0000000000..beb048052e
@@ -0,0 +1,18 @@
+/*
+ * QEMU CXL Mailbox
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See the
+ * COPYING file in the top-level directory.
+ */
+
+#ifndef CXL_MAILBOX_H
+#define CXL_MAILBOX_H
+
+#define CXL_MBOX_IMMEDIATE_CONFIG_CHANGE (1 << 1)
+#define CXL_MBOX_IMMEDIATE_DATA_CHANGE (1 << 2)
+#define CXL_MBOX_IMMEDIATE_POLICY_CHANGE (1 << 3)
+#define CXL_MBOX_IMMEDIATE_LOG_CHANGE (1 << 4)
+#define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5)
+#define CXL_MBOX_BACKGROUND_OPERATION (1 << 6)
+
+#endif
Signature · 1 line
2.39.1
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH 1/5] cxl/mailbox: move mailbox effect definitions to a header

Quoted 8 lines · Gregory Price

Preparation for allowing devices to define their own CCI commands

---
  hw/cxl/cxl-mailbox-utils.c   | 35 +++++++++++++++++++----------------
  include/hw/cxl/cxl_mailbox.h | 18 ++++++++++++++++++
  2 files changed, 37 insertions(+), 16 deletions(-)

create mode 100644 include/hw/cxl/cxl_mailbox.h

#3 lore raw

PATCH v2 2/5 cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write functions

In reply to Gregory Price

Call CXL_TYPE3 once at top of function to avoid multiple invocations.

---
 hw/mem/cxl_type3.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/mem/cxl_type3.c +6 -4
index fd9d134d46..80d596ee10 100644
@@ -1248,17 +1248,18 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d,
 MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
                            unsigned size, MemTxAttrs attrs)
 {
+    CXLType3Dev *ct3d = CXL_TYPE3(d);
     uint64_t dpa_offset = 0;
     AddressSpace *as = NULL;
     int res;
 
-    res = cxl_type3_hpa_to_as_and_dpa(CXL_TYPE3(d), host_addr, size,
+    res = cxl_type3_hpa_to_as_and_dpa(ct3d, host_addr, size,
                                       &as, &dpa_offset);
     if (res) {
         return MEMTX_ERROR;
     }
 
-    if (sanitize_running(&CXL_TYPE3(d)->cci)) {
+    if (sanitize_running(&ct3d->cci)) {
         qemu_guest_getrandom_nofail(data, size);
         return MEMTX_OK;
     }
@@ -1268,16 +1269,17 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
                             unsigned size, MemTxAttrs attrs)
 {
+    CXLType3Dev *ct3d = CXL_TYPE3(d);
     uint64_t dpa_offset = 0;
     AddressSpace *as = NULL;
     int res;
 
-    res = cxl_type3_hpa_to_as_and_dpa(CXL_TYPE3(d), host_addr, size,
+    res = cxl_type3_hpa_to_as_and_dpa(ct3d, host_addr, size,
                                       &as, &dpa_offset);
     if (res) {
         return MEMTX_ERROR;
     }
-    if (sanitize_running(&CXL_TYPE3(d)->cci)) {
+    if (sanitize_running(&ct3d->cci)) {
         return MEMTX_OK;
     }
     return address_space_write(as, dpa_offset, attrs, &data, size);
Signature · 1 line
2.39.1
#4 lore raw

Re: [PATCH 2/5] cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write functions

Quoted 3 lines · On Thu, 31 Aug 2023 21:29:11 -0400 Gregory Price <[email protected]>…

Call CXL_TYPE3 once at top of function to avoid multiple invocations.

Good cleanup on it's own.

I'll queue this one up on the backend of the sanitize set that introduces the second use in each of these functions.

That series might take a while to land upstream though as the CCI rework is in front of them currently. I'm not sure I want the pain of reording those two series.

Jonathan

Quoted 49 lines
---
 hw/mem/cxl_type3.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/mem/cxl_type3.c +6 -4
index fd9d134d46..80d596ee10 100644
@@ -1248,17 +1248,18 @@ static int cxl_type3_hpa_to_as_and_dpa(CXLType3Dev *ct3d,
 MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
                            unsigned size, MemTxAttrs attrs)
 {
+    CXLType3Dev *ct3d = CXL_TYPE3(d);
     uint64_t dpa_offset = 0;
     AddressSpace *as = NULL;
     int res;
 
-    res = cxl_type3_hpa_to_as_and_dpa(CXL_TYPE3(d), host_addr, size,
+    res = cxl_type3_hpa_to_as_and_dpa(ct3d, host_addr, size,
                                       &as, &dpa_offset);
     if (res) {
         return MEMTX_ERROR;
     }
 
-    if (sanitize_running(&CXL_TYPE3(d)->cci)) {
+    if (sanitize_running(&ct3d->cci)) {
         qemu_guest_getrandom_nofail(data, size);
         return MEMTX_OK;
     }
@@ -1268,16 +1269,17 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
                             unsigned size, MemTxAttrs attrs)
 {
+    CXLType3Dev *ct3d = CXL_TYPE3(d);
     uint64_t dpa_offset = 0;
     AddressSpace *as = NULL;
     int res;
 
-    res = cxl_type3_hpa_to_as_and_dpa(CXL_TYPE3(d), host_addr, size,
+    res = cxl_type3_hpa_to_as_and_dpa(ct3d, host_addr, size,
                                       &as, &dpa_offset);
     if (res) {
         return MEMTX_ERROR;
     }
-    if (sanitize_running(&CXL_TYPE3(d)->cci)) {
+    if (sanitize_running(&ct3d->cci)) {
         return MEMTX_OK;
     }
     return address_space_write(as, dpa_offset, attrs, &data, size);
#6 lore raw

PATCH v2 3/5 cxl/type3: Expose ct3 functions so that inheriters can call them

In reply to Gregory Price

For devices built on top of ct3, we need the init, realize, and exit functions exposed to correctly start up and tear down.

---
 hw/mem/cxl_type3.c          | 8 ++++----
 include/hw/cxl/cxl_device.h | 5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)
hw/mem/cxl_type3.c +4 -4
index 80d596ee10..a8d4a12f3e 100644
@@ -950,7 +950,7 @@ static DOEProtocol doe_spdm_prot[] = {
     { }
 };
 
-static void ct3_realize(PCIDevice *pci_dev, Error **errp)
+void ct3_realize(PCIDevice *pci_dev, Error **errp)
 {
     CXLType3Dev *ct3d = CXL_TYPE3(pci_dev);
     CXLComponentState *cxl_cstate = &ct3d->cxl_cstate;
@@ -1054,7 +1054,7 @@ err_address_space_free:
     return;
 }
 
-static void ct3_exit(PCIDevice *pci_dev)
+void ct3_exit(PCIDevice *pci_dev)
 {
     CXLType3Dev *ct3d = CXL_TYPE3(pci_dev);
     CXLComponentState *cxl_cstate = &ct3d->cxl_cstate;
@@ -1285,7 +1285,7 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     return address_space_write(as, dpa_offset, attrs, &data, size);
 }
 
-static void ct3d_reset(DeviceState *dev)
+void ct3d_reset(DeviceState *dev)
 {
     CXLType3Dev *ct3d = CXL_TYPE3(dev);
     uint32_t *reg_state = ct3d->cxl_cstate.crb.cache_mem_registers;
@@ -2081,7 +2081,7 @@ void qmp_cxl_release_dynamic_capacity(const char *path,
                                      errp);
 }
 
-static void ct3_class_init(ObjectClass *oc, void *data)
+void ct3_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
     PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc);
include/hw/cxl/cxl_device.h +5 -0
index e824c5ade8..4ad38b689c 100644
@@ -524,6 +524,11 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
 MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
                             unsigned size, MemTxAttrs attrs);
 
+void ct3_realize(PCIDevice *pci_dev, Error **errp);
+void ct3_exit(PCIDevice *pci_dev);
+void ct3d_reset(DeviceState *d);
+void ct3_class_init(ObjectClass *oc, void *data);
+
 uint64_t cxl_device_get_timestamp(CXLDeviceState *cxlds);
 
 void cxl_event_init(CXLDeviceState *cxlds, int start_msg_num);
Signature · 1 line
2.39.1
#7 lore raw

Re: [PATCH 3/5] cxl/type3: Expose ct3 functions so that inheriters can call them

Hi Gregory,

Quoted 2 lines · Gregory Price

For devices built on top of ct3, we need the init, realize, and exit functions exposed to correctly start up and tear down.

You shouldn't need this. Your device class can inherit from the CT3 base class by setting its .parent to TYPE_CXL_TYPE3:

static const TypeInfo my_cxl_types[] = {
{
.name = TYPE_MY_CXL_DEVICE_X,
.parent = TYPE_CXL_TYPE3,
.class_init = dev_x_class_init,
},
{
.name = TYPE_MY_CXL_DEVICE_Y,
.parent = TYPE_CXL_TYPE3,
.class_init = dev_y_class_init,
}
};

You can see some documentation about QOM here:
https://qemu-project.gitlab.io/qemu/devel/qom.html
But still you'll have to look at examples in the tree.

Quoted 5 lines
---
  hw/mem/cxl_type3.c          | 8 ++++----
  include/hw/cxl/cxl_device.h | 5 +++++
  2 files changed, 9 insertions(+), 4 deletions(-)
#8 lore raw

Re: [PATCH 3/5] cxl/type3: Expose ct3 functions so that inheriters can call them

Quoted 9 lines · Philippe Mathieu-Daudé

Hi Gregory,

Quoted 2 lines · Gregory Price

For devices built on top of ct3, we need the init, realize, and exit functions exposed to correctly start up and tear down.

You shouldn't need this. Your device class can inherit from the CT3 base class by setting its .parent to TYPE_CXL_TYPE3:

realized this after the fact when testing and patching, forgot to remove it, good eye. Still learning QEMU internals.

Quoted 6 lines

You can see some documentation about QOM here:
https://qemu-project.gitlab.io/qemu/devel/qom.html
But still you'll have to look at examples in the tree.

Thanks!
Gregory

#9 lore raw

PATCH v2 4/5 cxl/type3: add an optional mhd validation function for memory accesses

In reply to Gregory Price

When memory accesses are made, some MHSLD's would validate the address is within the scope of allocated sections. To do this, the base device must call an optional function set by inherited devices.

---
 hw/mem/cxl_type3.c          | 15 +++++++++++++++
 include/hw/cxl/cxl_device.h |  3 +++
 2 files changed, 18 insertions(+)
hw/mem/cxl_type3.c +15 -0
index a8d4a12f3e..8e1565f2fc 100644
@@ -1034,6 +1034,10 @@ void ct3_realize(PCIDevice *pci_dev, Error **errp)
             goto err_release_cdat;
         }
     }
+
+    /* Devices which inherit ct3d should initialize these after ct3_realize */
+    ct3d->mhd_access_valid = NULL;
+
     return;
 
 err_release_cdat:
@@ -1259,6 +1263,11 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
         return MEMTX_ERROR;
     }
 
+    if (ct3d->mhd_access_valid &&
+        !ct3d->mhd_access_valid(d, dpa_offset, size)) {
+        return MEMTX_ERROR;
+    }
+
     if (sanitize_running(&ct3d->cci)) {
         qemu_guest_getrandom_nofail(data, size);
         return MEMTX_OK;
@@ -1279,6 +1288,12 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     if (res) {
         return MEMTX_ERROR;
     }
+
+    if (ct3d->mhd_access_valid &&
+        !ct3d->mhd_access_valid(d, dpa_offset, size)) {
+        return MEMTX_ERROR;
+    }
+
     if (sanitize_running(&ct3d->cci)) {
         return MEMTX_OK;
     }
include/hw/cxl/cxl_device.h +3 -0
index 4ad38b689c..b1b39a9aa0 100644
@@ -489,6 +489,9 @@ struct CXLType3Dev {
         uint8_t num_regions; /* 0-8 regions */
         CXLDCDRegion regions[DCD_MAX_REGION_NUM];
     } dc;
+
+    /* Multi-headed Device */
+    bool (*mhd_access_valid)(PCIDevice *d, uint64_t addr, unsigned int size);
 };
 
 #define TYPE_CXL_TYPE3 "cxl-type3"
Signature · 1 line
2.39.1
#10 lore raw

Re: [PATCH 4/5] cxl/type3: add an optional mhd validation function for memory accesses

Quoted 5 lines · On Thu, 31 Aug 2023 21:29:13 -0400 Gregory Price <[email protected]>…

When memory accesses are made, some MHSLD's would validate the address is within the scope of allocated sections. To do this, the base device must call an optional function set by inherited devices.

This sort of callback addition can be done via class initialization. E.g. get_lsa_size()
https://elixir.bootlin.com/qemu/latest/source/hw/mem/cxl_type3.c#L1494
as the callback is the same for all instances of the class which in next patch is CXLNiagraClass where you already set the PCIClass callbacks in cxl_niagara_class_init()

You can then use something like:
CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
cvc->mhd_access_valid(ct3d, dpa_offset, size);

Jonathan

Quoted 59 lines
---
 hw/mem/cxl_type3.c          | 15 +++++++++++++++
 include/hw/cxl/cxl_device.h |  3 +++
 2 files changed, 18 insertions(+)
hw/mem/cxl_type3.c +15 -0
index a8d4a12f3e..8e1565f2fc 100644
@@ -1034,6 +1034,10 @@ void ct3_realize(PCIDevice *pci_dev, Error **errp)
             goto err_release_cdat;
         }
     }
+
+    /* Devices which inherit ct3d should initialize these after ct3_realize */
+    ct3d->mhd_access_valid = NULL;
+
     return;
 
 err_release_cdat:
@@ -1259,6 +1263,11 @@ MemTxResult cxl_type3_read(PCIDevice *d, hwaddr host_addr, uint64_t *data,
         return MEMTX_ERROR;
     }
 
+    if (ct3d->mhd_access_valid &&
+        !ct3d->mhd_access_valid(d, dpa_offset, size)) {
+        return MEMTX_ERROR;
+    }
+
     if (sanitize_running(&ct3d->cci)) {
         qemu_guest_getrandom_nofail(data, size);
         return MEMTX_OK;
@@ -1279,6 +1288,12 @@ MemTxResult cxl_type3_write(PCIDevice *d, hwaddr host_addr, uint64_t data,
     if (res) {
         return MEMTX_ERROR;
     }
+
+    if (ct3d->mhd_access_valid &&
+        !ct3d->mhd_access_valid(d, dpa_offset, size)) {
+        return MEMTX_ERROR;
+    }
+
     if (sanitize_running(&ct3d->cci)) {
         return MEMTX_OK;
     }
include/hw/cxl/cxl_device.h +3 -0
index 4ad38b689c..b1b39a9aa0 100644
@@ -489,6 +489,9 @@ struct CXLType3Dev {
         uint8_t num_regions; /* 0-8 regions */
         CXLDCDRegion regions[DCD_MAX_REGION_NUM];
     } dc;
+
+    /* Multi-headed Device */
+    bool (*mhd_access_valid)(PCIDevice *d, uint64_t addr, unsigned int size);
 };
 
 #define TYPE_CXL_TYPE3 "cxl-type3"
#11 lore raw

Re: [PATCH 4/5] cxl/type3: add an optional mhd validation function for memory accesses

Quoted 16 lines · Jonathan Cameron
Quoted 5 lines · On Thu, 31 Aug 2023 21:29:13 -0400 Gregory Price <[email protected]>…

When memory accesses are made, some MHSLD's would validate the address is within the scope of allocated sections. To do this, the base device must call an optional function set by inherited devices.

This sort of callback addition can be done via class initialization. E.g. get_lsa_size()
https://elixir.bootlin.com/qemu/latest/source/hw/mem/cxl_type3.c#L1494
as the callback is the same for all instances of the class which in next patch is CXLNiagraClass where you already set the PCIClass callbacks in cxl_niagara_class_init()

Quoted 6 lines

You can then use something like:
CXLType3Class *cvc = CXL_TYPE3_GET_CLASS(ct3d);
cvc->mhd_access_valid(ct3d, dpa_offset, size);

Jonathan

Will make this change along with a few cleanups suggested elsewhere and a few boneheaded mistakes.

~Gregory

#12 lore raw

PATCH v2 5/5 cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

In reply to Gregory Price

Create a new device to emulate the SK hynix Niagara MHSLD platform.

This device has custom CCI commands that allow for applying isolation to each memory block between hosts. This enables an early form of dynamic capacity, whereby the NUMA node maps the entire region, but the host is responsible for asking the device which memory blocks are allocated to it, and therefore may be onlined.

To instantiate:

-device cxl-skh-niagara,cxl-type3,bus=rp0,volatile-memdev=mem0,id=cxl-mem0,sn=66666,mhd-head=0,mhd-shmid=0

The linux kernel will require raw CXL commands enabled to allow for passing through of Niagara CXL commands via the CCI mailbox.

The Niagara MH-SLD has a shared memory region that must be initialized using the 'init_niagara' tool located in the vendor subdirectory

usage: init_niagara <heads> <sections> <section_size> <shmid>

        heads         : number of heads on the device
        sections      : number of sections
        section_size  : size of a section in 128mb increments
        shmid         : shmid produced by ipcmk

Example:
$shmid1=ipcmk -M 131072
./init_niagara 4 32 1 $shmid1

---
 hw/cxl/Kconfig                          |   4 +
 hw/cxl/meson.build                      |   2 +
 hw/cxl/vendor/meson.build               |   1 +
 hw/cxl/vendor/skhynix/.gitignore        |   1 +
 hw/cxl/vendor/skhynix/init_niagara.c    |  99 +++++
 hw/cxl/vendor/skhynix/meson.build       |   1 +
 hw/cxl/vendor/skhynix/skhynix_niagara.c | 516 ++++++++++++++++++++++++
 hw/cxl/vendor/skhynix/skhynix_niagara.h | 169 ++++++++
 8 files changed, 793 insertions(+)
 create mode 100644 hw/cxl/vendor/meson.build
 create mode 100644 hw/cxl/vendor/skhynix/.gitignore
 create mode 100644 hw/cxl/vendor/skhynix/init_niagara.c
 create mode 100644 hw/cxl/vendor/skhynix/meson.build
 create mode 100644 hw/cxl/vendor/skhynix/skhynix_niagara.c
 create mode 100644 hw/cxl/vendor/skhynix/skhynix_niagara.h
hw/cxl/Kconfig +4 -0
index c9b2e46bac..dd6c54b54d 100644
@@ -2,5 +2,9 @@ config CXL
     bool
     default y if PCI_EXPRESS
 
+config CXL_VENDOR
+    bool
+    default y
+
 config I2C_MCTP_CXL
     bool
hw/cxl/meson.build +2 -0
index 1393821fc4..e8c8c1355a 100644
@@ -15,3 +15,5 @@ system_ss.add(when: 'CONFIG_CXL',
 system_ss.add(when: 'CONFIG_I2C_MCTP_CXL', if_true: files('i2c_mctp_cxl.c'))
 
 system_ss.add(when: 'CONFIG_ALL', if_true: files('cxl-host-stubs.c'))
+
+subdir('vendor')
hw/cxl/vendor/meson.build new file +1 -0
new file mode 100644
index 0000000000..12db8991f1
@@ -0,0 +1 @@
+subdir('skhynix')
hw/cxl/vendor/skhynix/.gitignore new file +1 -0
new file mode 100644
index 0000000000..6d96de38ea
@@ -0,0 +1 @@
+init_niagara
hw/cxl/vendor/skhynix/init_niagara.c new file +99 -0

99 lines not on this page · raw message

hw/cxl/vendor/skhynix/meson.build new file +1 -0
new file mode 100644
index 0000000000..4e57db65f1
@@ -0,0 +1 @@
+system_ss.add(when: 'CONFIG_CXL_VENDOR', if_true: files('skhynix_niagara.c',))
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +516 -0

516 lines not on this page · raw message

hw/cxl/vendor/skhynix/skhynix_niagara.h new file +169 -0

169 lines not on this page · raw message

Signature · 1 line
2.39.1
#13 lore raw

Re: [PATCH 5/5] cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

Quoted 19 lines · On Thu, 31 Aug 2023 21:29:14 -0400 Gregory Price <[email protected]>…

Create a new device to emulate the SK hynix Niagara MHSLD platform.

This device has custom CCI commands that allow for applying isolation to each memory block between hosts. This enables an early form of dynamic capacity, whereby the NUMA node maps the entire region, but the host is responsible for asking the device which memory blocks are allocated to it, and therefore may be onlined.

To instantiate:

-device cxl-skh-niagara,cxl-type3,bus=rp0,volatile-memdev=mem0,id=cxl-mem0,sn=66666,mhd-head=0,mhd-shmid=0

The linux kernel will require raw CXL commands enabled to allow for passing through of Niagara CXL commands via the CCI mailbox.

The Niagara MH-SLD has a shared memory region that must be initialized using the 'init_niagara' tool located in the vendor subdirectory

usage: init_niagara <heads> <sections> <section_size> <shmid>

Quoted 9 lines
        heads         : number of heads on the device
        sections      : number of sections
        section_size  : size of a section in 128mb increments
        shmid         : shmid produced by ipcmk

Example:
$shmid1=ipcmk -M 131072
./init_niagara 4 32 1 $shmid1

Hi Gregory,

Some comments inline, but I'm happy to add this to my staging tree in the meantime as it stands (might be a few days until I push a new branch though).

Quoted 3 lines

The SoB chain needs cleaning up. Is this a co-developed situation? If it is use the rules in the kernel documentation as I don't think those are yet clearly stated in QEMU docs (and they are confusing so I won't try to restate them here).

Quoted 13 lines
hw/cxl/vendor/skhynix/meson.build new file +1 -0
new file mode 100644
index 0000000000..4e57db65f1
@@ -0,0 +1 @@
+system_ss.add(when: 'CONFIG_CXL_VENDOR', if_true: files('skhynix_niagara.c',))
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +0 -0
new file mode 100644
index 0000000000..88e53cc6cc

hw/cxl/vendor/skhynix/skhynix_niagara.c line 8

Quoted 8 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +8 -0
@@ -0,0 +1,516 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2023 MemVerge Inc.
+ * Copyright (c) 2023 SK hynix Inc.
+ */
+
+#include <sys/shm.h>

This will need some osdep.h magic. There is some there already but it will need relaxing (unless you want to run only on sparc ;) and we may need to make this device linux host only.

Quoted 14 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +14 -0
+#include "qemu/osdep.h"
+#include "hw/irq.h"
+#include "migration/vmstate.h"
+#include "qapi/error.h"
+#include "hw/cxl/cxl.h"
+#include "hw/cxl/cxl_mailbox.h"
+#include "hw/cxl/cxl_device.h"
+#include "hw/pci/pcie.h"
+#include "hw/pci/pcie_port.h"
+#include "hw/qdev-properties.h"
+#include "skhynix_niagara.h"
+
+#define TYPE_CXL_NIAGARA "cxl-skh-niagara"
+OBJECT_DECLARE_TYPE(CXLNiagaraState, CXLNiagaraClass, CXL_NIAGARA)

...

Quoted 23 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +23 -0
+
+static void niagara_alloc_build_output(NiagaraAllocOutput *output,
+                                       size_t *len_out,
+                                       uint32_t *section_ids,
+                                       uint32_t section_count)
+{
+    uint32_t extents;
+    uint32_t previous;
+    uint32_t i;
+
+    /* Build the output */
+    output->section_count = section_count;
+    extents = 0;
+    previous = 0;
+    for (i = 0; i < section_count; i++) {
+        if (i == 0) {
+            /* start the first extent */
+            output->extents[extents].start_section_id = section_ids[i];
+            output->extents[extents].section_count = 1;
+            extents++;
+        } else if (section_ids[i] == (previous + 1)) {
+            /* increment the current extent */
+            output->extents[extents - 1].section_count++;

hw/cxl/vendor/skhynix/skhynix_niagara.c line 155

Quoted 10 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +10 -0
+        } else {
+            /* start a new extent */
+            output->extents[extents].start_section_id = section_ids[i];
+            output->extents[extents].section_count = 1;
+            extents++;
+        }
+        previous = section_ids[i];
+    }
+    output->extent_count = extents;
+    *len_out = (8 + (16 * extents));

Too many brackets.

Quoted 35 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +34 -0
+    return;
+}
+
 
+static CXLRetCode cmd_niagara_get_section_map(const struct cxl_cmd *cmd,
+                                              uint8_t *payload_in,
+                                              size_t len_in,
+                                              uint8_t *payload_out,
+                                              size_t *len_out,
+                                              CXLCCI *cci)
+{
+    CXLNiagaraState *s = CXL_NIAGARA(cci->d);
+    NiagaraSharedState *nss = s->mhd_state;
+    NiagaraGetSectionMapInput *input = (void *)payload_in;
+    NiagaraGetSectionMapOutput *output = (void *)payload_out;
+    uint32_t *sections = &nss->sections[0];
+    uint8_t query_type = input->query_type;
+    uint32_t i;
+    uint32_t bytes;
+
+    if ((query_type != NIAGARA_GSM_QUERY_FREE) &&
+        (query_type != NIAGARA_GSM_QUERY_ALLOCATED)) {
+        return CXL_MBOX_INVALID_INPUT;
+    }
+
+    output->ttl_section_count = nss->total_sections;
+    output->qry_section_count = 0;
+    bytes = (output->ttl_section_count / 8);
+    if (output->ttl_section_count % 8) {
+        bytes += 1;
+    }
+
+    for (i = 0; i < bytes; i++) {
+        output->bitset[i] = 0x0;
+    }

hw/cxl/vendor/skhynix/skhynix_niagara.c line 374

Quoted 10 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +10 -0
+
+    /* Iterate the the section list and check the bits */
+    for (i = 0; (i < nss->total_sections); i++) {
+        uint32_t section = sections[i];
+
+        if (((query_type == NIAGARA_GSM_QUERY_FREE) && (!section)) ||
+            ((query_type == NIAGARA_GSM_QUERY_ALLOCATED) &&
+             (section & (1 << s->mhd_head)))) {
+            uint32_t byte = i / 8;
+            uint8_t bit = (1 << (i % 8));

Too many brackets

hw/cxl/vendor/skhynix/skhynix_niagara.c line 381

Quoted 7 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +7 -0
+
+            output->bitset[byte] |= bit;
+            output->qry_section_count++;
+        }
+    }
+
+    *len_out = (8 + bytes);

No need for brackets.

Quoted 5 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +5 -0
+    return CXL_MBOX_SUCCESS;
+}
+
+static bool mhdsld_access_valid(PCIDevice *d,
+                                uint64_t dpa_offset,

hw/cxl/vendor/skhynix/skhynix_niagara.c line 396

Quoted 10 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +10 -0
+                                unsigned int size)
+{
+    CXLNiagaraState *s = CXL_NIAGARA(d);
+    NiagaraSharedState *nss = s->mhd_state;
+    uint32_t section = (dpa_offset / NIAGARA_MIN_MEMBLK);
+
+    if (!(nss->sections[section] & (1 << s->mhd_head))) {
+        return false;
+    }
+    return true;
    return nss->sections[section] & (1 << s->mhd_head);
Quoted 1 line

+}

...

hw/cxl/vendor/skhynix/skhynix_niagara.c line 495

Quoted 10 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +10 -0
+
+static void cxl_niagara_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *pc = PCI_DEVICE_CLASS(klass);
+
+    pc->realize = cxl_niagara_realize;
+    pc->exit = cxl_niagara_exit;
+    dc->reset = cxl_niagara_reset;
+    device_class_set_props(dc, cxl_niagara_props);

As mentioned in previous patch, probably want to set your extra callback for verification here as well.

Quoted 13 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +1 -0
+}
hw/cxl/vendor/skhynix/skhynix_niagara.h new file +5 -0
new file mode 100644
index 0000000000..0489102f38
@@ -0,0 +1,169 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2023 MemVerge Inc.
+ * Copyright (c) 2023 SK hynix Inc.

hw/cxl/vendor/skhynix/skhynix_niagara.h line 15

Quoted 10 lines
hw/cxl/vendor/skhynix/skhynix_niagara.h new file +10 -0
+ */
+
+#ifndef CXL_SKH_NIAGARA_H
+#define CXL_SKH_NIAGARA_H
+#include <stdint.h>
+#include "hw/cxl/cxl.h"
+#include "hw/cxl/cxl_mailbox.h"
+#include "hw/cxl/cxl_device.h"
+
+#define NIAGARA_MIN_MEMBLK (1024 * 1024 * 128)

128 * MiB (include/qemu/units.h)

hw/cxl/vendor/skhynix/skhynix_niagara.h line 44

Quoted 4 lines
hw/cxl/vendor/skhynix/skhynix_niagara.h new file +4 -0
+
+enum {
+    NIAGARA_MHD = 0x55,
+        #define GET_MHD_INFO 0x0

Is this standard as it's in the normal space?
If it is then I'd like the implementation pushed down to the type3 implementation (with some callbacks or similar.)

hw/cxl/vendor/skhynix/skhynix_niagara.h line 45

Quoted 1 line
hw/cxl/vendor/skhynix/skhynix_niagara.h new file +1 -0
+    NIAGARA_CMD = 0xC0

These are in the vendor space so having them in this device directly is fine.

Quoted 14 lines
hw/cxl/vendor/skhynix/skhynix_niagara.h new file +14 -0
+        #define GET_SECTION_STATUS 0x0
+        #define SET_SECTION_ALLOC 0x1
+        #define SET_SECTION_RELEASE 0x2
+        #define SET_SECTION_SIZE 0x3
+        /* Future: MOVE_DATA 0x4 */
+        #define GET_SECTION_MAP 0x5
+        /* Future: CLEAR_SECTION 0x99 */
+};
+
+typedef struct NiagaraExtent {
+    uint32_t start_section_id;
+    uint32_t section_count;
+    uint8_t reserved[8];
+} QEMU_PACKED NiagaraExtent;

...

Quoted 5 lines

+/*
+ * Niagara Get Section Map Command
+ * query type:
+ * Free - Map of free sections
+ * Allocted - What sections are allocated for this head

allocated

Quoted 4 lines

+ * Returns a map of the requested type of sections
+ */

hw/cxl/vendor/skhynix/skhynix_niagara.h new file +2 -0
+#define NIAGARA_GSM_QUERY_FREE 0
+#define NIAGARA_GSM_QUERY_ALLOCATED 1

...

#14 lore raw

Re: [PATCH 5/5] cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

Quoted 8 lines · Jonathan Cameron

On Thu, 31 Aug 2023 21:29:14 -0400
Gregory Price <[email protected]> wrote:

Hi Gregory,

Some comments inline, but I'm happy to add this to my staging tree in the meantime as it stands (might be a few days until I push a new branch though).

I'm going to do one a quick v3 today with the feedback and some cleanup in spots i noticed.

Quoted 9 lines
Quoted 3 lines

The SoB chain needs cleaning up. Is this a co-developed situation? If it is use the rules in the kernel documentation as I don't think those are yet clearly stated in QEMU docs (and they are confusing so I won't try to restate them here).

TL;DR: They gave me the command list, I wrote the model. We got approval to release the model, but I wasn't sure how to capture the copyright/SoB list. I suppose the copyright covers SKh, but since I authored the model, it only requires my SoB?

After reading, I'm still not sure how to capture this lol.

Should I just switch the skh folks to Co-developed-by?

Quoted 18 lines
Quoted 18 lines
hw/cxl/vendor/skhynix/meson.build new file +1 -0
new file mode 100644
index 0000000000..4e57db65f1
@@ -0,0 +1 @@
+system_ss.add(when: 'CONFIG_CXL_VENDOR', if_true: files('skhynix_niagara.c',))
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
new file mode 100644
index 0000000000..88e53cc6cc
@@ -0,0 +1,516 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2023 MemVerge Inc.
Quoted 10 lines

hw/cxl/vendor/skhynix/skhynix_niagara.c line 8

Quoted 4 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
+ * Copyright (c) 2023 SK hynix Inc.
+ */
+
+#include <sys/shm.h>

This will need some osdep.h magic. There is some there already but it will need relaxing (unless you want to run only on sparc ;) and we may need to make this device linux host only.

Good point, I had not considered osdep issues. Do you know of any examples of linux-only devices I can use to do a quick patch-up? I can come back around on this issue later.

Quoted 10 lines

hw/cxl/vendor/skhynix/skhynix_niagara.c line 12

Quoted 5 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
+
+enum {
+    NIAGARA_MHD = 0x55,
+        #define GET_MHD_INFO 0x0

Is this standard as it's in the normal space?
If it is then I'd like the implementation pushed down to the type3 implementation (with some callbacks or similar.)

:thinking_face:

maybe a similar pattern to the callback from before? I suppose I could push this down into type3 and add an mhd callback in the class and have niagara fill that in with the callback.

That *feels* right, so i'll go ahead with it.

If I misunderstood anything, let me know

~Gregory

#15 lore raw

Re: [PATCH 5/5] cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

Quoted 23 lines · On Tue, 5 Sep 2023 12:04:29 -0400 Gregory Price <[email protected]>…
Quoted 8 lines · Jonathan Cameron

On Thu, 31 Aug 2023 21:29:14 -0400
Gregory Price <[email protected]> wrote:

Hi Gregory,

Some comments inline, but I'm happy to add this to my staging tree in the meantime as it stands (might be a few days until I push a new branch though).

I'm going to do one a quick v3 today with the feedback and some cleanup in spots i noticed.

Quoted 9 lines
Quoted 3 lines

The SoB chain needs cleaning up. Is this a co-developed situation? If it is use the rules in the kernel documentation as I don't think those are yet clearly stated in QEMU docs (and they are confusing so I won't try to restate them here).

Quoted 4 lines

TL;DR: They gave me the command list, I wrote the model. We got approval to release the model, but I wasn't sure how to capture the copyright/SoB list. I suppose the copyright covers SKh, but since I authored the model, it only requires my SoB?

Yes - I think only your SoB is fine. Maybe some text to explain the other parts.

Quoted 34 lines

After reading, I'm still not sure how to capture this lol.

Should I just switch the skh folks to Co-developed-by?

Quoted 18 lines
Quoted 18 lines
hw/cxl/vendor/skhynix/meson.build new file +1 -0
new file mode 100644
index 0000000000..4e57db65f1
@@ -0,0 +1 @@
+system_ss.add(when: 'CONFIG_CXL_VENDOR', if_true: files('skhynix_niagara.c',))
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
new file mode 100644
index 0000000000..88e53cc6cc
@@ -0,0 +1,516 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2023 MemVerge Inc.
Quoted 10 lines

hw/cxl/vendor/skhynix/skhynix_niagara.c line 8

Quoted 4 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
+ * Copyright (c) 2023 SK hynix Inc.
+ */
+
+#include <sys/shm.h>  

This will need some osdep.h magic. There is some there already but it will need relaxing (unless you want to run only on sparc ;) and we may need to make this device linux host only.

Quoted 3 lines

Good point, I had not considered osdep issues. Do you know of any examples of linux-only devices I can use to do a quick patch-up? I can come back around on this issue later.

No idea.

Quoted 25 lines
Quoted 11 lines

hw/cxl/vendor/skhynix/skhynix_niagara.c line 12

Quoted 6 lines
hw/cxl/vendor/skhynix/skhynix_niagara.c new file +4 -0
+
+enum {
+    NIAGARA_MHD = 0x55,
+        #define GET_MHD_INFO 0x0  

Is this standard as it's in the normal space?
If it is then I'd like the implementation pushed down to the type3 implementation (with some callbacks or similar.)

:thinking_face:

maybe a similar pattern to the callback from before? I suppose I could push this down into type3 and add an mhd callback in the class and have niagara fill that in with the callback.

That *feels* right, so i'll go ahead with it.

If I misunderstood anything, let me know

~Gregory

#16 lore raw
In reply to Gregory Price
Quoted 27 lines · Gregory Price

v2:
- 5 patch series, first 4 are pull-aheads that can be merged separately
- cci: rebased on 8-30 branch from jic23, dropped cci patches
- mailbox: dropped MHD commands, integrated into niagara (for now)
- mailbox: refactor CCI defines to avoid redefinition in niagara
- type3: cleanup duplicate typecasting
- type3: expose ct3 functions so inheriting devices may access them
- type3: add optional mhd validation function for memory access
- niagara: refactor to make niagara inherit type3 and override behavior
- niagara: refactor command definitions and types into header to make understanding the device a bit easier for users
- style and formatting

This patch set includes an emulation of the SK hynix Niagara MHSLD platform with custom CCI commands that allow for isolation of memory blocks between attached hosts.

This device allows hosts to request memory blocks directly from the device, rather than requiring full the DCD command set. As a matter of simplicity, this is beneficial to for testing and applications of dynamic memory pooling on top of the 1.1 and 2.0 specification.

Note that these CCI commands are not servicable without a proper driver or the kernel allowing raw CXL commands to be passed through the mailbox driver, so users should enable CONFIG_CXL_MEM_RAW_COMMANDS=y on the kernel of their QEMU instance if they wish to test it

Quoted 8 lines

Gregory Price (5):
cxl/mailbox: move mailbox effect definitions to a header cxl/type3: Cleanup multiple CXL_TYPE3() calls in read/write functions cxl/type3: Expose ct3 functions so that inheriters can call them cxl/type3: add an optional mhd validation function for memory accesses cxl/vendor: SK hynix Niagara Multi-Headed SLD Device

Being at commit 17780edd81 I can't apply this series:

Applying: cxl/mailbox: move mailbox effect definitions to a header
error: patch failed: hw/cxl/cxl-mailbox-utils.c:12
error: hw/cxl/cxl-mailbox-utils.c: patch does not apply
Patch failed at 0001 cxl/mailbox: move mailbox effect definitions to a header

On what is it based?

Thanks,

Phil.

#17 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Gregory Price

v2:
- 5 patch series, first 4 are pull-aheads that can be merged separately

This patch set includes an emulation of the SK hynix Niagara MHSLD platform with custom CCI commands that allow for isolation of memory blocks between attached hosts.

Being at commit 17780edd81 I can't apply this series:

Quoted 7 lines

Applying: cxl/mailbox: move mailbox effect definitions to a header
error: patch failed: hw/cxl/cxl-mailbox-utils.c:12
error: hw/cxl/cxl-mailbox-utils.c: patch does not apply Patch failed at 0001 cxl/mailbox: move mailbox effect definitions to a header

On what is it based?

This is based on jonathan's branch here:
https://gitlab.com/jic23/qemu/-/tree/cxl-2023-08-30

I try to keep things on top of his working branch to avoid any rebasing issues. I should have included that with the cover letter, my bad.

~Gregory