[RFC v2 02/15] cxl: introduce cxl_get_hdm_reg_info()
From: mhonap
Date: Tue Dec 09 2025 - 11:52:08 EST
From: Zhi Wang <zhiw@xxxxxxxxxx>
CXL core has the information of what CXL register groups a device has.
When initializing the device, the CXL core probes the register groups
and saves the information. The probing sequence is quite complicated.
vfio-cxl requires the HDM register information to emualte the HDM decoder
registers.
Introduce cxl_get_hdm_reg_info() for vfio-cxl to leverage the HDM
register information in the CXL core. Thus, it doesn't need to implement
its own probing sequence.
Signed-off-by: Zhi Wang <zhiw@xxxxxxxxxx>
Signed-off-by: Manish Honap <mhonap@xxxxxxxxxx>
---
drivers/cxl/core/pci.c | 28 ++++++++++++++++++++++++++++
include/cxl/cxl.h | 4 ++++
2 files changed, 32 insertions(+)
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index a0cda2a8fdba..f998096050cf 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -532,6 +532,34 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm,
}
EXPORT_SYMBOL_NS_GPL(cxl_hdm_decode_init, "CXL");
+int cxl_get_hdm_reg_info(struct cxl_dev_state *cxlds, u64 *count, u64 *offset,
+ u64 *size)
+{
+ struct cxl_component_reg_map *map =
+ &cxlds->reg_map.component_map;
+ struct pci_dev *pdev = to_pci_dev(cxlds->dev);
+ int d = cxlds->cxl_dvsec;
+ u16 cap;
+ int rc;
+
+ if (!map->hdm_decoder.valid) {
+ *count = *offset = *size = 0;
+ return 0;
+ }
+
+ *offset = map->hdm_decoder.offset;
+ *size = map->hdm_decoder.size;
+
+ rc = pci_read_config_word(pdev,
+ d + PCI_DVSEC_CXL_CAP_OFFSET, &cap);
+ if (rc)
+ return rc;
+
+ *count = FIELD_GET(PCI_DVSEC_CXL_HDM_COUNT_MASK, cap);
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_get_hdm_reg_info, "CXL");
+
#define CXL_DOE_TABLE_ACCESS_REQ_CODE 0x000000ff
#define CXL_DOE_TABLE_ACCESS_REQ_CODE_READ 0
#define CXL_DOE_TABLE_ACCESS_TABLE_TYPE 0x0000ff00
diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h
index f18194b9e3e2..d84405afc72e 100644
--- a/include/cxl/cxl.h
+++ b/include/cxl/cxl.h
@@ -289,4 +289,8 @@ int cxl_decoder_detach(struct cxl_region *cxlr,
enum cxl_detach_mode mode);
struct range;
int cxl_get_region_range(struct cxl_region *region, struct range *range);
+
+int cxl_get_hdm_reg_info(struct cxl_dev_state *cxlds, u64 *count, u64 *offset,
+ u64 *size);
+
#endif /* __CXL_CXL_H__ */
--
2.25.1