qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hw/mem/cxl_type3: reset dvsecs in ct3d_reset()
@ 2024-04-09  7:58 Li Zhijian via
  2024-04-11 10:18 ` Jonathan Cameron via
  0 siblings, 1 reply; 4+ messages in thread
From: Li Zhijian via @ 2024-04-09  7:58 UTC (permalink / raw)
  To: Jonathan Cameron, Fan Ni, qemu-devel; +Cc: linux-cxl, Dan Williams, Li Zhijian

After the kernel commit
0cab68720598 ("cxl/pci: Fix disabling memory if DVSEC CXL Range does not match a CFMWS window")
CXL type3 devices cannot be enabled again after the reboot because the
control register(see 8.1.3.2 in CXL specifiction 2.0 for more details) was
not reset.

These registers could be changed by the firmware or OS, let them have
their initial value in reboot so that the OS can read their clean status.

Fixes: e1706ea83da0 ("hw/cxl/device: Add a memory device (8.2.8.5)")
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
---
root_port, usp and dsp have the same issue, if this patch get approved,
I will send another patch to fix them later.

V2:
   Add fixes tag.
   Reset all dvsecs registers instead of CTRL only
---
 hw/mem/cxl_type3.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c
index b0a7e9f11b64..4f09d0b8fedc 100644
--- a/hw/mem/cxl_type3.c
+++ b/hw/mem/cxl_type3.c
@@ -30,6 +30,7 @@
 #include "hw/pci/msix.h"
 
 #define DWORD_BYTE 4
+#define CT3D_CAP_SN_OFFSET PCI_CONFIG_SPACE_SIZE
 
 /* Default CDAT entries for a memory region */
 enum {
@@ -284,6 +285,10 @@ static void build_dvsecs(CXLType3Dev *ct3d)
              range2_size_hi = 0, range2_size_lo = 0,
              range2_base_hi = 0, range2_base_lo = 0;
 
+    cxl_cstate->dvsec_offset = CT3D_CAP_SN_OFFSET;
+    if (ct3d->sn != UI64_NULL) {
+        cxl_cstate->dvsec_offset += PCI_EXT_CAP_DSN_SIZEOF;
+    }
     /*
      * Volatile memory is mapped as (0x0)
      * Persistent memory is mapped at (volatile->size)
@@ -664,10 +669,7 @@ static void ct3_realize(PCIDevice *pci_dev, Error **errp)
 
     pcie_endpoint_cap_init(pci_dev, 0x80);
     if (ct3d->sn != UI64_NULL) {
-        pcie_dev_ser_num_init(pci_dev, 0x100, ct3d->sn);
-        cxl_cstate->dvsec_offset = 0x100 + 0x0c;
-    } else {
-        cxl_cstate->dvsec_offset = 0x100;
+        pcie_dev_ser_num_init(pci_dev, CT3D_CAP_SN_OFFSET, ct3d->sn);
     }
 
     ct3d->cxl_cstate.pdev = pci_dev;
@@ -907,6 +909,7 @@ static void ct3d_reset(DeviceState *dev)
 
     cxl_component_register_init_common(reg_state, write_msk, CXL2_TYPE3_DEVICE);
     cxl_device_register_init_t3(ct3d);
+    build_dvsecs(ct3d);
 
     /*
      * Bring up an endpoint to target with MCTP over VDM.
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-02 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09  7:58 [PATCH v2] hw/mem/cxl_type3: reset dvsecs in ct3d_reset() Li Zhijian via
2024-04-11 10:18 ` Jonathan Cameron via
2024-04-26  3:36   ` Zhijian Li (Fujitsu) via
2024-08-02 16:40     ` Jonathan Cameron via

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).