From: Bibo Mao Date: Mon, 12 Jan 2026 06:58:01 +0000 (+0800) Subject: hw/loongarch/virt: Add property highmem-mmio-size with virt machine X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a8d5e95d70ab1bdbc2a39065e9864f4201e519f;p=thirdparty%2Fqemu.git hw/loongarch/virt: Add property highmem-mmio-size with virt machine The default high mmio size of GPEX PCIE host controller is 64G bytes on virt machine. If it does not meet requirements with some pass-throught HW devices in future, it can be adjust dynamically, here adds property highmem-mmio-size to set high mmio size. Signed-off-by: Bibo Mao Reviewed-by: Song Gao --- diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 78e9dd66d1..2580ab37b6 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -7,6 +7,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/datadir.h" +#include "qemu/cutils.h" #include "qapi/error.h" #include "exec/target_page.h" #include "hw/core/boards.h" @@ -106,6 +107,43 @@ static void virt_set_highmem_mmio(Object *obj, bool value, Error **errp) lvms->highmem_mmio = value; } +static void virt_get_highmem_mmio_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(obj); + uint64_t size = lvms->gpex.mmio64.size; + + visit_type_size(v, name, &size, errp); +} + +static void virt_set_highmem_mmio_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(obj); + uint64_t size; + + if (!visit_type_size(v, name, &size, errp)) { + return; + } + + if (!is_power_of_2(size)) { + error_setg(errp, "highmem-mmio-size is not a power of 2"); + return; + } + + if (size < DEFAULT_HIGH_PCIE_MMIO_SIZE) { + char *sz = size_to_str(DEFAULT_HIGH_PCIE_MMIO_SIZE); + error_setg(errp, "highmem-mmio-size cannot be set to a lower value " + "than the default (%s)", sz); + g_free(sz); + return; + } + + lvms->gpex.mmio64.size = size; +} + static PFlashCFI01 *virt_flash_create1(LoongArchVirtMachineState *lvms, const char *name, const char *alias_prop_name) @@ -1473,6 +1511,13 @@ static void virt_class_init(ObjectClass *oc, const void *data) object_class_property_set_description(oc, "highmem-mmio", "Set on/off to enable/disable high " "memory region for PCI MMIO"); + object_class_property_add(oc, "highmem-mmio-size", "size", + virt_get_highmem_mmio_size, + virt_set_highmem_mmio_size, + NULL, NULL); + object_class_property_set_description(oc, "highmem-mmio-size", + "Set the high memory region size " + "for PCI MMIO"); } static const TypeInfo virt_machine_types[] = {