[PATCH v3 13/25] hw/acpi: Use memory_region_get_address()

Philippe Mathieu-Daudé posted 25 patches 2 weeks, 3 days ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Richard Henderson <richard.henderson@linaro.org>, Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>, Jesper Devantier <foss@defmacro.it>, Bernhard Beschow <shentey@gmail.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, "Cédric Le Goater" <clg@kaod.org>, Peter Maydell <peter.maydell@linaro.org>, Steven Lee <steven_lee@aspeedtech.com>, Troy Lee <leetroy@gmail.com>, Jamin Lin <jamin_lin@aspeedtech.com>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Peter Xu <peterx@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Fabiano Rosas <farosas@suse.de>
[PATCH v3 13/25] hw/acpi: Use memory_region_get_address()
Posted by Philippe Mathieu-Daudé 2 weeks, 3 days ago
MemoryRegion::addr is private data of MemoryRegion, use
memory_region_get_address() to access it.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/acpi/cxl.c                  | 8 ++++++--
 hw/i386/acpi-build.c           | 8 +++++---
 hw/loongarch/virt-acpi-build.c | 4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/cxl.c b/hw/acpi/cxl.c
index 77c99dfb184..92c032851cc 100644
--- a/hw/acpi/cxl.c
+++ b/hw/acpi/cxl.c
@@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     PXBDev *pxb = PXB_DEV(cxl);
     SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
     MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
+    hwaddr container_base_addr = memory_region_get_address(mr->container);
 
     /* Type */
     build_append_int_noprefix(table_data, 0, 1);
@@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base - subregion within a container that is in PA space */
-    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
+    build_append_int_noprefix(table_data,
+                              container_base_addr
+                              + memory_region_get_address(mr), 8);
 
     /* Length */
     build_append_int_noprefix(table_data, memory_region_size(mr), 8);
@@ -154,7 +157,8 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base HPA */
-    build_append_int_noprefix(table_data, fw->mr.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&fw->mr), 8);
 
     /* Window Size */
     build_append_int_noprefix(table_data, fw->size, 8);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 9446a9f862c..201fdbb39f0 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1039,7 +1039,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
             /* Handle the ranges for the PXB expanders */
             if (pci_bus_is_cxl(bus)) {
                 MemoryRegion *mr = &pcms->cxl_devices_state.host_mr;
-                uint64_t base = mr->addr;
+                hwaddr base = memory_region_get_address(mr);
 
                 cxl_present = true;
                 crs_range_insert(crs_range_set.mem_ranges, base,
@@ -1822,7 +1822,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
     /* Capability offset */
     build_append_int_noprefix(table_data, s->pci->capab_offset, 2);
     /* IOMMU base address */
-    build_append_int_noprefix(table_data, s->mr_mmio.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&s->mr_mmio), 8);
     /* PCI Segment Group */
     build_append_int_noprefix(table_data, 0, 2);
     /* IOMMU info */
@@ -1857,7 +1858,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
     /* Capability offset */
     build_append_int_noprefix(table_data, s->pci->capab_offset, 2);
     /* IOMMU base address */
-    build_append_int_noprefix(table_data, s->mr_mmio.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&s->mr_mmio), 8);
     /* PCI Segment Group */
     build_append_int_noprefix(table_data, 0, 2);
     /* IOMMU info */
diff --git a/hw/loongarch/virt-acpi-build.c b/hw/loongarch/virt-acpi-build.c
index 3694c9827f0..101d083ae6a 100644
--- a/hw/loongarch/virt-acpi-build.c
+++ b/hw/loongarch/virt-acpi-build.c
@@ -409,11 +409,11 @@ static void build_flash_aml(Aml *scope, LoongArchVirtMachineState *lvms)
     hwaddr flash1_size;
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[0]);
-    flash0_base = flash_mem->addr;
+    flash0_base = memory_region_get_address(flash_mem);
     flash0_size = memory_region_size(flash_mem);
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[1]);
-    flash1_base = flash_mem->addr;
+    flash1_base = memory_region_get_address(flash_mem);
     flash1_size = memory_region_size(flash_mem);
 
     dev = aml_device("FLS0");
-- 
2.51.0


Re: [PATCH v3 13/25] hw/acpi: Use memory_region_get_address()
Posted by Jonathan Cameron via 2 weeks, 2 days ago
On Tue, 28 Oct 2025 19:12:47 +0100
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> MemoryRegion::addr is private data of MemoryRegion, use
> memory_region_get_address() to access it.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/acpi/cxl.c                  | 8 ++++++--

Acked-by: Jonathan Cameron <jonathan.cameron@huawei.com> #for CXL

>  hw/i386/acpi-build.c           | 8 +++++---
>  hw/loongarch/virt-acpi-build.c | 4 ++--
>  3 files changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/acpi/cxl.c b/hw/acpi/cxl.c
> index 77c99dfb184..92c032851cc 100644
> --- a/hw/acpi/cxl.c
> +++ b/hw/acpi/cxl.c
> @@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
>      PXBDev *pxb = PXB_DEV(cxl);
>      SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
>      MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
> +    hwaddr container_base_addr = memory_region_get_address(mr->container);
>  
>      /* Type */
>      build_append_int_noprefix(table_data, 0, 1);
> @@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
>      build_append_int_noprefix(table_data, 0, 4);
>  
>      /* Base - subregion within a container that is in PA space */
> -    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
> +    build_append_int_noprefix(table_data,
> +                              container_base_addr
> +                              + memory_region_get_address(mr), 8);
>  
>      /* Length */
>      build_append_int_noprefix(table_data, memory_region_size(mr), 8);
> @@ -154,7 +157,8 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)
>      build_append_int_noprefix(table_data, 0, 4);
>  
>      /* Base HPA */
> -    build_append_int_noprefix(table_data, fw->mr.addr, 8);
> +    build_append_int_noprefix(table_data,
> +                              memory_region_get_address(&fw->mr), 8);
>  
>      /* Window Size */
>      build_append_int_noprefix(table_data, fw->size, 8);
Re: [PATCH v3 13/25] hw/acpi: Use memory_region_get_address()
Posted by Richard Henderson 2 weeks, 2 days ago
On 10/28/25 19:12, Philippe Mathieu-Daudé wrote:
> +++ b/hw/acpi/cxl.c
> @@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
>       PXBDev *pxb = PXB_DEV(cxl);
>       SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
>       MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
> +    hwaddr container_base_addr = memory_region_get_address(mr->container);
>   
>       /* Type */
>       build_append_int_noprefix(table_data, 0, 1);
> @@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
>       build_append_int_noprefix(table_data, 0, 4);
>   
>       /* Base - subregion within a container that is in PA space */
> -    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
> +    build_append_int_noprefix(table_data,
> +                              container_base_addr
> +                              + memory_region_get_address(mr), 8);

Why the single-use variable, instead of expanding here, like what you're replacing?


r~