From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, atar4qemu@gmail.com
Subject: [PATCH v4 71/80] sparc/sun4m: use memdev for RAM
Date: Fri, 31 Jan 2020 16:09:41 +0100 [thread overview]
Message-ID: <1580483390-131164-72-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1580483390-131164-1-git-send-email-imammedo@redhat.com>
memory_region_allocate_system_memory() API is going away, so
replace it with memdev allocated MemoryRegion. The later is
initialized by generic code, so board only needs to opt in
to memdev scheme by providing
MachineClass::default_ram_id
and using MachineState::ram instead of manually initializing
RAM memory region.
Patch moves ram size check into sun4m_hw_init() and drops
ram_init() moving remainder to sun4m_hw_init() as well,
as it was the only place that called it.
Also it rewrites impl. of RamDevice a little bit, which
could serve as an example of frontend device for RAM backend.
(Caveats are:
1. it doesn't check for memdev backend being mapped
since it's been usurped by generic machine to handle
majority of machines which don't have RAM frontend device
2. it still lacks 'addr' property and still has hardcoded
sysbus_mmio_map() in board init. If done right, board should
set 'addr' property and bus/machine plug handler should map
it during device realize time.
)
Further improvements were left as exercise for the future,
since frontends are out scope of RAM conversion to memdev.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v4:
* 'machine: introduce memory-backend property' patch changed
'memory-backend' property from link to backend id to allow for
delayed initialization. Take that in account and add resolving
machine->ram_memdev_id into backend pointer before setting link
on RamDevice.
CC: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
CC: atar4qemu@gmail.com
---
hw/sparc/sun4m.c | 74 ++++++++++++++++++++++++++++----------------------------
1 file changed, 37 insertions(+), 37 deletions(-)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 25e96db..f5bf95f 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -777,63 +777,42 @@ static const TypeInfo prom_info = {
typedef struct RamDevice {
SysBusDevice parent_obj;
-
- MemoryRegion ram;
- uint64_t size;
+ HostMemoryBackend *memdev;
} RamDevice;
/* System RAM */
static void ram_realize(DeviceState *dev, Error **errp)
{
RamDevice *d = SUN4M_RAM(dev);
- SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+ MemoryRegion *ram = host_memory_backend_get_memory(d->memdev);
- memory_region_allocate_system_memory(&d->ram, OBJECT(d), "sun4m.ram",
- d->size);
- sysbus_init_mmio(sbd, &d->ram);
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), ram);
}
-static void ram_init(hwaddr addr, ram_addr_t RAM_size,
- uint64_t max_mem)
+static void ram_initfn(Object *obj)
{
- DeviceState *dev;
- SysBusDevice *s;
- RamDevice *d;
-
- /* allocate RAM */
- if ((uint64_t)RAM_size > max_mem) {
- error_report("Too much memory for this machine: %" PRId64 ","
- " maximum %" PRId64,
- RAM_size / MiB, max_mem / MiB);
- exit(1);
- }
- dev = qdev_create(NULL, "memory");
- s = SYS_BUS_DEVICE(dev);
-
- d = SUN4M_RAM(dev);
- d->size = RAM_size;
- qdev_init_nofail(dev);
-
- sysbus_mmio_map(s, 0, addr);
+ RamDevice *d = SUN4M_RAM(obj);
+ object_property_add_link(obj, "memdev", TYPE_MEMORY_BACKEND,
+ (Object **)&d->memdev,
+ object_property_allow_set_link,
+ OBJ_PROP_LINK_STRONG, &error_abort);
+ object_property_set_description(obj, "memdev", "Set RAM backend"
+ "Valid value is ID of a hostmem backend",
+ &error_abort);
}
-static Property ram_properties[] = {
- DEFINE_PROP_UINT64("size", RamDevice, size, 0),
- DEFINE_PROP_END_OF_LIST(),
-};
-
static void ram_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
dc->realize = ram_realize;
- device_class_set_props(dc, ram_properties);
}
static const TypeInfo ram_info = {
.name = TYPE_SUN4M_MEMORY,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(RamDevice),
+ .instance_init = ram_initfn,
.class_init = ram_class_init,
};
@@ -879,6 +858,15 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
SysBusDevice *s;
unsigned int smp_cpus = machine->smp.cpus;
unsigned int max_cpus = machine->smp.max_cpus;
+ Object *ram_memdev = object_resolve_path_type(machine->ram_memdev_id,
+ TYPE_MEMORY_BACKEND, NULL);
+
+ if (machine->ram_size > hwdef->max_mem) {
+ error_report("Too much memory for this machine: %" PRId64 ","
+ " maximum %" PRId64,
+ machine->ram_size / MiB, hwdef->max_mem / MiB);
+ exit(1);
+ }
/* init CPUs */
for(i = 0; i < smp_cpus; i++) {
@@ -888,9 +876,12 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
for (i = smp_cpus; i < MAX_CPUS; i++)
cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
+ /* Create and map RAM frontend */
+ dev = qdev_create(NULL, "memory");
+ object_property_set_link(OBJECT(dev), ram_memdev, "memdev", &error_fatal);
+ qdev_init_nofail(dev);
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0);
- /* set up devices */
- ram_init(0, machine->ram_size, hwdef->max_mem);
/* models without ECC don't trap when missing ram is accessed */
if (!hwdef->ecc_base) {
empty_slot_init(machine->ram_size, hwdef->max_mem - machine->ram_size);
@@ -1078,7 +1069,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
- fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+ fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_WIDTH, graphic_width);
@@ -1415,6 +1406,7 @@ static void ss5_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss5_type = {
@@ -1434,6 +1426,7 @@ static void ss10_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss10_type = {
@@ -1453,6 +1446,7 @@ static void ss600mp_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss600mp_type = {
@@ -1472,6 +1466,7 @@ static void ss20_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss20_type = {
@@ -1490,6 +1485,7 @@ static void voyager_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo voyager_type = {
@@ -1508,6 +1504,7 @@ static void ss_lx_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss_lx_type = {
@@ -1526,6 +1523,7 @@ static void ss4_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo ss4_type = {
@@ -1544,6 +1542,7 @@ static void scls_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo scls_type = {
@@ -1562,6 +1561,7 @@ static void sbook_class_init(ObjectClass *oc, void *data)
mc->default_boot_order = "c";
mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
mc->default_display = "tcx";
+ mc->default_ram_id = "sun4m.ram";
}
static const TypeInfo sbook_type = {
--
2.7.4
next prev parent reply other threads:[~2020-01-31 16:01 UTC|newest]
Thread overview: 102+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-31 15:08 [PATCH v4 00/80] refactor main RAM allocation to use hostmem backend Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 01/80] numa: remove deprecated -mem-path fallback to anonymous RAM Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 02/80] machine: introduce memory-backend property Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 03/80] machine: alias -mem-path and -mem-prealloc into memory-foo backend Igor Mammedov
2020-02-03 9:04 ` Michael S. Tsirkin
2020-02-03 9:27 ` Igor Mammedov
2020-02-03 9:42 ` Michael S. Tsirkin
2020-02-03 10:40 ` Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 04/80] machine: introduce convenience MachineState::ram Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 05/80] initialize MachineState::ram in NUMA case Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 06/80] vl.c: move -m parsing after memory backends has been processed Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 07/80] vl.c: ensure that ram_size matches size of machine.memory-backend Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 08/80] alpha/dp264: use memdev for RAM Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 09/80] arm/aspeed: actually check RAM size Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 10/80] arm/aspeed: use memdev for RAM Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 11/80] arm/collie: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 12/80] arm/cubieboard: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 13/80] arm/digic_boards: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 14/80] arm/highbank: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 15/80] arm/imx25_pdk: drop RAM size fixup Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 16/80] arm/imx25_pdk: use memdev for RAM Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 17/80] arm/integratorcp: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 18/80] arm/kzm: drop RAM size fixup Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 19/80] arm/kzm: use memdev for RAM Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 20/80] arm/mcimx6ul-evk: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 21/80] arm/mcimx7d-sabre: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 22/80] arm/mps2-tz: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 23/80] arm/mps2: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 24/80] arm/musicpal: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 25/80] arm/nseries: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 26/80] arm/omap_sx1: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 27/80] arm/palm: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 28/80] arm/raspi: " Igor Mammedov
2020-01-31 15:08 ` [PATCH v4 29/80] arm/sabrelite: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 30/80] arm/sbsa-ref: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 31/80] arm/versatilepb: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 32/80] arm/vexpress: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 33/80] arm/virt: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 34/80] arm/xilinx_zynq: drop RAM size fixup Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 35/80] arm/xilinx_zynq: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 36/80] arm/xlnx-versal-virt: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 37/80] arm/xlnx-zcu102: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 38/80] s390x/s390-virtio-ccw: " Igor Mammedov
2020-02-05 20:11 ` Halil Pasic
2020-02-06 13:15 ` Igor Mammedov
2020-02-10 19:33 ` Halil Pasic
2020-01-31 15:09 ` [PATCH v4 39/80] null-machine: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 40/80] cris/axis_dev88: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 41/80] hppa: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 42/80] x86/microvm: " Igor Mammedov
2020-02-03 8:58 ` Michael S. Tsirkin
2020-01-31 15:09 ` [PATCH v4 43/80] x86/pc: " Igor Mammedov
2020-02-03 9:07 ` Michael S. Tsirkin
2020-02-03 9:45 ` Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 44/80] lm32/lm32_boards: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 45/80] lm32/milkymist: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 46/80] m68k/an5206: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 47/80] m68k/q800: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 48/80] m68k/mcf5208: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 49/80] m68k/next-cube: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 50/80] mips/boston: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 51/80] mips/mips_fulong2e: drop RAM size fixup Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 52/80] mips/mips_fulong2e: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 53/80] mips/mips_jazz: " Igor Mammedov
2020-02-09 16:41 ` Philippe Mathieu-Daudé
2020-02-10 15:06 ` [PATCH v5 81/80] mips/mips_jazz: add max ram size check Igor Mammedov
2020-02-10 17:04 ` Philippe Mathieu-Daudé
2020-01-31 15:09 ` [PATCH v4 54/80] mips/mips_malta: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 55/80] mips/mips_mipssim: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 56/80] mips/mips_r4k: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 57/80] ppc/e500: drop RAM size fixup Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 58/80] ppc/e500: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 59/80] ppc/mac_newworld: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 60/80] ppc/mac_oldworld: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 61/80] ppc/pnv: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 62/80] ppc/ppc405_boards: add RAM size checks Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 63/80] ppc/ppc405_boards: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 64/80] ppc/{ppc440_bamboo, sam460ex}: drop RAM size fixup Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 65/80] ppc/{ppc440_bamboo, sam460ex}: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 66/80] ppc/prep: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 67/80] ppc/spapr: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 68/80] ppc/virtex_ml507: remove unused arguments Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 69/80] ppc/virtex_ml507: use memdev for RAM Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 70/80] sparc/leon3: " Igor Mammedov
2020-01-31 15:09 ` Igor Mammedov [this message]
2020-01-31 15:09 ` [PATCH v4 72/80] sparc/niagara: " Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 73/80] remove no longer used memory_region_allocate_system_memory() Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize() Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 75/80] exec: drop bogus mem_path from qemu_ram_alloc_from_fd() Igor Mammedov
2020-02-07 14:42 ` Marc-André Lureau
2020-01-31 15:09 ` [PATCH v4 76/80] make mem_path local variable Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 77/80] hostmem: introduce "prealloc-threads" property Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 78/80] hostmem: fix strict bind policy Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 79/80] tests/numa-test: make top level args dynamic and g_autofree(cli) cleanups Igor Mammedov
2020-01-31 15:09 ` [PATCH v4 80/80] tests:numa-test: use explicit memdev to specify node RAM Igor Mammedov
2020-01-31 16:16 ` [PATCH v4 00/80] refactor main RAM allocation to use hostmem backend no-reply
2020-01-31 16:28 ` no-reply
2020-02-03 9:49 ` Igor Mammedov
2020-02-04 15:08 ` Igor Mammedov
2020-02-04 15:39 ` Igor Mammedov
2020-02-04 22:05 ` Paolo Bonzini
2020-02-05 13:20 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1580483390-131164-72-git-send-email-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=atar4qemu@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).