@samitouri / QOSamiQemu / commits / ea24be6cdd

hw/cxl: Use HPA in cxl_cfmws_find_device() rather than offset in window.

This function will shortly be used to help find if there is a route to a device, serving an HPA, under a particular fixed memory window. Rather than having that new use case subtract the base address in the caller, only to add it again in cxl_cfmws_find_device(), push the responsibility for calculating the HPA to the caller. This also reduces the inconsistency in the meaning of the hwaddr addr parameter between this function and the calls made within it that access the HDM decoders that operating on HPA. Reviewed-by: Li Zhijian <lizhijian@fujitsu.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Reviewed-by: Gregory Price <gourry@gourry.net> Tested-by: Gregory Price <gourry@gourry.net> Signed-off-by: Alireza Sanaee <alireza.sanaee@huawei.com> Message-ID: <20260318171918.146-2-alireza.sanaee@huawei.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Alireza Sanaee committed Feb 4, 2026 at 15:00 UTC ea24be6cdd9def87b354869ed9c76049d44bb902
1 file changed +2 -5
hw/cxl/cxl-host.c
+2 -5
@@ -168,9 +168,6 @@ static PCIDevice *cxl_cfmws_find_device(CXLFixedWindow *fw, hwaddr addr)
168 bool target_found;
169 PCIDevice *rp, *d;
170
171 - /* Address is relative to memory region. Convert to HPA */
172 - addr += fw->base;
173 -
171 rb_index = (addr / cxl_decode_ig(fw->enc_int_gran)) % fw->num_targets;
172 hb = PCI_HOST_BRIDGE(fw->target_hbs[rb_index]->cxl_host_bridge);
173 if (!hb || !hb->bus || !pci_bus_is_cxl(hb->bus)) {
@@ -254,7 +251,7 @@ static MemTxResult cxl_read_cfmws(void *opaque, hwaddr addr, uint64_t *data,
251 CXLFixedWindow *fw = opaque;
252 PCIDevice *d;
253
257 - d = cxl_cfmws_find_device(fw, addr);
254 + d = cxl_cfmws_find_device(fw, addr + fw->base);
255 if (d == NULL) {
256 *data = 0;
257 /* Reads to invalid address return poison */
@@ -271,7 +268,7 @@ static MemTxResult cxl_write_cfmws(void *opaque, hwaddr addr,
268 CXLFixedWindow *fw = opaque;
269 PCIDevice *d;
270
274 - d = cxl_cfmws_find_device(fw, addr);
271 + d = cxl_cfmws_find_device(fw, addr + fw->base);
272 if (d == NULL) {
273 /* Writes to invalid address are silent */
274 return MEMTX_OK;