refactor main RAM allocation to use hostmem backend
Subsystems (5)
v2 cover refactor main RAM allocation to use hostmem backend
v2:
- fix compile errors on mingw32 host by introducing RAM_ADDR_UFMT [11/86]
- replace "[PATCH 43/86] hppa: drop RAM size fixup" with alternative patches made by Philippe (which effectively do the same thing but other way around)
- ppc440: fix crash and add suggested valid RAM size in error output. s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/ and simplify it by removing not necessary nested loop
- rebase on current master due to new conflicts
Series removes ad hoc RAM allocation API (memory_region_allocate_system_memory) and consolidates it around hostmem backend. It allows to
* resolve conflicts between global -mem-prealloc and hostmem's "policy" option fixing premature allocation before binding policy is applied
* simplify complicated memory allocation routines which had to deal with 2 ways to allocate RAM.
* it allows to reuse hostmem backends of a choice for main RAM without adding extra CLI options to duplicate hostmem features.
Recent case was -mem-shared, to enable vhost-user on targets that don't support hostmem backends [1] (ex: s390)
* move RAM allocation from individual boards into generic machine code and provide them with prepared MemoryRegion.
* clean up deprecated NUMA features which were tied to the old API (see patches)
- "numa: remove deprecated -mem-path fallback to anonymous RAM"
- "numa: remove deprecated implicit RAM distribution between nodes"
- "forbid '-numa node,mem' for 5.0 and newer machine types"
Conversion introduces a new machine.ram-memdev property and wrapper code that aliases global -mem-path and -mem-alloc into automatically created hostmem backend properties (provided ram-memdev was not set explicitly given by user). And then follows bulk of trivial patches that incrementally convert individual boards to using machine.ram-memdev provided MemoryRegion.
Board conversion typically involves:
* providing MachineClass::default_ram_size and MachineClass::default_ram_id so generic code could create default backend if user didn't explicitly provide ram-memdev or -m options
* dropping memory_region_allocate_system_memory() call
* using convenience MachineState::ram MemoryRegion, which points to MemoryRegion allocated by ram-memdev
On top of that for some boards:
* added missing ram_size checks (typically it were boards with fixed ram size)
* ram_size fixups were replaced by checks and hard errors, forcing user to provide correct "-m" values instead of ignoring it and continuing running.
After all boards are converted the old API is removed and memory allocation routines are cleaned up.
git tree for testing:
https://github.com/imammedo/qemu convert_main_ram_to_memdev_v2
previous rev:
https://github.com/imammedo/qemu convert_main_ram_to_memdev_v2
https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg05409.html
Igor Mammedov (83):
numa: remove deprecated -mem-path fallback to anonymous RAM
machine: introduce ram-memdev property
machine: alias -mem-path and -mem-prealloc into memory-foo backend
machine: introduce convenience MachineState::ram initialize MachineState::ram in NUMA case
alpha:dp264: use memdev for RAM
arm:aspeed: convert valid RAM sizes to data
arm:aspeed: actually check RAM size
hw:aspeed: drop warning and bogus ram_size fixup arm:aspeed: use memdev for RAM
arm:collie: use memdev for RAM
arm:cubieboard: use memdev for RAM
arm:digic_boards: use memdev for RAM
arm:highbank: use memdev for RAM
arm:imx25_pdk: drop RAM size fixup
arm:imx25_pdk: use memdev for RAM
arm:integratorcp: use memdev for RAM
arm:kzm: drop RAM size fixup
arm:kzm: use memdev for RAM
arm:mcimx6ul-evk: use memdev for RAM
arm:mcimx7d-sabre: use memdev for RAM
arm:mps2-tz: use memdev for RAM
arm:mps2: use memdev for RAM
arm:musicpal: use memdev for RAM
arm:nseries: use memdev for RAM
arm:omap_sx1: use memdev for RAM
arm:palm: use memdev for RAM
arm:raspi: use memdev for RAM
arm:sabrelite: use memdev for RAM
arm:sbsa-ref: use memdev for RAM
arm:versatilepb: use memdev for RAM
arm:vexpress: use memdev for RAM
arm:virt: use memdev for RAM
arm:xilinx_zynq: drop RAM size fixup
arm:xilinx_zynq: use memdev for RAM arm:xlnx-versal-virt: use memdev for RAM arm:xlnx-zcu102: use memdev for RAM s390x:s390-virtio-ccw: use memdev for RAM
null-machine: use memdev for RAM
cris:axis_dev88: use memdev for RAM
hppa: use memdev for RAM
x86:microvm: use memdev for RAM
x86:pc: use memdev for RAM
lm32:lm32_boards: use memdev for RAM
lm32:milkymist: use memdev for RAM
m68k:an5206: use memdev for RAM
m68k:mcf5208: use memdev for RAM
m68k:next-cube: use memdev for RAM
mips:boston-cube: use memdev for RAM mips:mips_fulong2e: drop RAM size fixup mips:mips_fulong2e: use memdev for RAM
mips:mips_jazz: use memdev for RAM
mips:mips_malta: use memdev for RAM
mips:mips_mipssim: use memdev for RAM
mips:mips_r4k: use memdev for RAM
ppc:e500: drop RAM size fixup
ppc:e500: use memdev for RAM
ppc:mac_newworld: use memdev for RAM
ppc:mac_oldworld: use memdev for RAM
ppc:pnv: use memdev for RAM
ppc:ppc405_boards: add RAM size checks ppc:ppc405_boards: use memdev for RAM ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup ppc:ppc440_bamboo/sam460ex: use memdev for RAM ppc:prep: use memdev for RAM
ppc:spapr: use memdev for RAM
ppc:virtex_ml507: remove unused arguments ppc:virtex_ml507: use memdev for RAM
sparc:leon3: use memdev for RAM
sparc:sun4m: use memdev for RAM
sparc:niagara: use memdev for RAM
remove no longer used memory_region_allocate_system_memory() post conversion default_ram_id cleanup
exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
exec: drop bogus mem_path from qemu_ram_alloc_from_fd() make mem_path local variable
hostmem: introduce "prealloc-threads" property
hostmem: fix strict bind policy
numa: forbid '-numa node,mem' for 5.0 and newer machine types tests:numa-test: make top level args dynamic and g_autofree(cli)
cleanups
tests:numa-test: use explicit memdev to specify node RAM
numa: make exit() usage consistent
numa: remove deprecated implicit RAM distribution between nodes
Philippe Mathieu-Daudé (3):
hw/hppa/machine: Correctly check the firmware is in PDC range hw/hppa/machine: Restrict the total memory size to 3GB hw/hppa/machine: Map the PDC memory region with higher priority
hw/alpha/alpha_sys.h | 2 +- include/exec/cpu-common.h | 2 + include/hw/boards.h | 51 ++++---------- include/hw/misc/aspeed_sdmc.h | 2 + include/hw/ppc/ppc4xx.h | 9 ++- include/sysemu/hostmem.h | 20 +++++- include/sysemu/numa.h | 5 +- include/sysemu/sysemu.h | 2 - backends/hostmem-file.c | 8 --- backends/hostmem-memfd.c | 1 - backends/hostmem-ram.c | 2 - backends/hostmem.c | 53 ++++++++++---- exec.c | 66 ++--------------- hw/alpha/dp264.c | 2 +- hw/alpha/typhoon.c | 8 +-- hw/arm/aspeed.c | 13 +--- hw/arm/collie.c | 15 ++-- hw/arm/cubieboard.c | 25 +++---- hw/arm/digic_boards.c | 35 +++++---- hw/arm/highbank.c | 10 ++- hw/arm/imx25_pdk.c | 13 ++-- hw/arm/integratorcp.c | 9 ++- hw/arm/kzm.c | 13 ++-- hw/arm/mcimx6ul-evk.c | 25 +++---- hw/arm/mcimx7d-sabre.c | 25 +++---- hw/arm/mps2-tz.c | 13 ++-- hw/arm/mps2.c | 13 ++-- hw/arm/musicpal.c | 16 +++-- hw/arm/nseries.c | 31 ++++---- hw/arm/omap_sx1.c | 18 +++-- hw/arm/palm.c | 18 +++-- hw/arm/raspi.c | 32 +++------ hw/arm/sabrelite.c | 23 +++--- hw/arm/sbsa-ref.c | 7 +- hw/arm/versatilepb.c | 7 +- hw/arm/vexpress.c | 14 ++-- hw/arm/virt.c | 9 ++- hw/arm/xilinx_zynq.c | 20 +++--- hw/arm/xlnx-versal-virt.c | 7 +- hw/arm/xlnx-zcu102.c | 7 +- hw/core/machine.c | 37 ++++++++-- hw/core/null-machine.c | 7 +- hw/core/numa.c | 160 +++++++++--------------------------------- hw/cris/axis_dev88.c | 8 +-- hw/hppa/machine.c | 18 ++--- hw/i386/microvm.c | 12 ++-- hw/i386/pc.c | 20 +++--- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/lm32/lm32_boards.c | 36 ++++++---- hw/lm32/milkymist.c | 19 +++-- hw/m68k/an5206.c | 5 +- hw/m68k/mcf5208.c | 5 +- hw/m68k/next-cube.c | 5 +- hw/mips/boston.c | 11 ++- hw/mips/mips_fulong2e.c | 15 ++-- hw/mips/mips_jazz.c | 7 +- hw/mips/mips_malta.c | 10 ++- hw/mips/mips_mipssim.c | 9 +-- hw/mips/mips_r4k.c | 12 ++-- hw/misc/aspeed_sdmc.c | 112 +++++++++++------------------ hw/ppc/e500.c | 17 +++-- hw/ppc/e500plat.c | 1 + hw/ppc/mac_newworld.c | 6 +- hw/ppc/mac_oldworld.c | 6 +- hw/ppc/mpc8544ds.c | 1 + hw/ppc/pnv.c | 8 +-- hw/ppc/ppc405_boards.c | 45 +++++++----- hw/ppc/ppc440_bamboo.c | 12 ++-- hw/ppc/ppc4xx_devs.c | 59 ++++++++-------- hw/ppc/prep.c | 15 ++-- hw/ppc/sam460ex.c | 6 +- hw/ppc/spapr.c | 17 ++--- hw/ppc/virtex_ml507.c | 18 ++--- hw/s390x/s390-virtio-ccw.c | 7 +- hw/sparc/leon3.c | 6 +- hw/sparc/sun4m.c | 73 ++++++++++--------- hw/sparc64/niagara.c | 7 +- qemu-deprecated.texi | 33 --------- qemu-options.hx | 20 +++--- tests/qtest/numa-test.c | 90 ++++++++++++++---------- vl.c | 37 +++++++++- 82 files changed, 727 insertions(+), 920 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/86 numa: remove deprecated -mem-path fallback to anonymous RAM
it was deprecated since 4.0 by commit
cb79224b7 (deprecate -mem-path fallback to anonymous RAM)
Deprecation period ran ont and it's time to remove it so it won't get in a way of switching to using hostmem backend for RAM.
---
CC:[email protected]
CC: [email protected]
--- hw/core/numa.c | 18 +----------------- qemu-deprecated.texi | 9 --------- 2 files changed, 1 insertion(+), 26 deletions(-)
hw/core/numa.c +1 -17
@@ -784,24 +784,8 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner, {if (mem_path) {#ifdef __linux__ -Error *err =NULL ;memory_region_init_ram_from_file (mr, owner, name, ram_size,0 ,0 , - mem_path, &err); -if (err) { -error_report_err (err); -if (mem_prealloc) { -exit (1 ); - } -warn_report ("falling back to regular RAM allocation" ); -error_printf ("This is deprecated. Make sure that -mem-path " -" specified path has sufficient resources to allocate" -" -m specified RAM amount\n" ); -/* Legacy behavior: if allocation failed, fall back to -* regular RAM allocation. -*/ - mem_path =NULL ; -memory_region_init_ram_nomigrate (mr, owner, name, ram_size, &error_fatal); - } + mem_path, &error_fatal);#else fprintf (stderr,"-mem-path not supported on this host\n" );exit (1 );
qemu-deprecated.texi +0 -9
@@ -113,15 +113,6 @@ QEMU using implicit generic or board specific splitting rule. Use @option{memdev} with @var{memory-backend-ram} backend or @option{mem} (if it's supported by used machine type) to define mapping explictly instead. -@subsection -mem-path fallback to RAM (since 4.1) -Currently if guest RAM allocation from file pointed by @option{mem-path} -fails, QEMU falls back to allocating from RAM, which might result -in unpredictable behavior since the backing file specified by the user -is ignored. In the future, users will be responsible for making sure -the backing storage specified with @option{-mem-path} can actually provide -the guest RAM configured with @option{-m} and QEMU will fail to start up if -RAM allocation is unsuccessful. - @subsection RISC-V -bios (since 4.1) QEMU 4.1 introduced support for the -bios option in QEMU for RISC-V for the
Signature · 1 line
2.7.4
PATCH v2 2/86 machine: introduce ram-memdev property
In reply to Igor MammedovProperty will contain link to memory backend that will be used for backing initial RAM.
Follow up commit will alias -mem-path and -mem-prealloc CLI options into memory backend options to make memory handling consistent (using only hostmem backend family for guest RAM allocation).
---
CC: [email protected]
CC: [email protected]
--- include/hw/boards.h | 2 ++ hw/core/machine.c | 9 +++++++++ 2 files changed, 11 insertions(+)
include/hw/boards.h +2 -0
@@ -4,6 +4,7 @@#define HW_BOARDS_H #include "exec/memory.h" +#include "sysemu/hostmem.h" #include "sysemu/blockdev.h" #include "sysemu/accel.h" #include "qapi/qapi-types-machine.h"
@@ -285,6 +286,7 @@ struct MachineState {bool enforce_config_section;bool enable_graphics;char *memory_encryption; +HostMemoryBackend *ram_memdev;DeviceMemoryState *device_memory;ram_addr_t ram_size;
hw/core/machine.c +9 -0
@@ -886,6 +886,15 @@ static void machine_initfn(Object *obj) "Table (HMAT)", NULL); } +object_property_add_link (obj,"ram-memdev" ,TYPE_MEMORY_BACKEND , + (Object **)&ms->ram_memdev, + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG , &error_abort); +object_property_set_description (obj,"ram-memdev" , +"Set RAM backend" +"Valid value is ID of hostmem based backend" , + &error_abort); +/* Register notifier when init is done for sysbus sanity checks */ ms->sysbus_notifier.notify = machine_init_notify;qemu_add_machine_init_done_notifier (&ms->sysbus_notifier);
Signature · 1 line
2.7.4
Re: [PATCH v2 02/86] machine: introduce ram-memdev property
hw/core/machine.c static void machine_initfn(Object *obj) · line 897
Quoted 10 lines · Igor Mammedov
hw/core/machine.c +9
-0+object_property_add_link (obj,"ram-memdev" ,TYPE_MEMORY_BACKEND , + (Object **)&ms->ram_memdev, + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG , &error_abort); +object_property_set_description (obj,"ram-memdev" , +"Set RAM backend" +"Valid value is ID of hostmem based backend" , + &error_abort); +
Obligatory bikeshedding, why not just ram (the MachineState field can remain "ram_memdev"). Or memory-backend matching the QOM type names.
Paolo
Re: [PATCH v2 02/86] machine: introduce ram-memdev property
Quoted 12 lines · On Wed, 15 Jan 2020 16:56:30 +0100 Paolo Bonzini <[email protected]> wrote:
hw/core/machine.c static void machine_initfn(Object *obj) · line 897
Quoted 10 lines · Igor Mammedov
hw/core/machine.c +9
-0+object_property_add_link (obj,"ram-memdev" ,TYPE_MEMORY_BACKEND , + (Object **)&ms->ram_memdev, + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG , &error_abort); +object_property_set_description (obj,"ram-memdev" , +"Set RAM backend" +"Valid value is ID of hostmem based backend" , + &error_abort); +
Quoted 2 lines
Obligatory bikeshedding, why not just ram (the MachineState field can remain "
ram_memdev"). Or memory-backend matching the QOM type names.
I'd say it was inspired by "-numa node,memdev" option for some sort of consistency. But I'm fine with any other name as far as there is consensus.
If I had to choose between 'ram' and 'memory-backend', I'd go for the later.
Quoted 3 lines
Paolo
Re: [PATCH v2 02/86] machine: introduce ram-memdev property
Quoted 15 lines · Igor Mammedov
Quoted 12 lines · On Wed, 15 Jan 2020 16:56:30 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 10 lines · Igor Mammedov
hw/core/machine.c +9
-0+object_property_add_link (obj,"ram-memdev" ,TYPE_MEMORY_BACKEND , + (Object **)&ms->ram_memdev, + object_property_allow_set_link, +OBJ_PROP_LINK_STRONG , &error_abort); +object_property_set_description (obj,"ram-memdev" , +"Set RAM backend" +"Valid value is ID of hostmem based backend" , + &error_abort); +
Quoted 6 lines
Quoted 2 lines
Obligatory bikeshedding, why not just ram (the MachineState field can remain "
ram_memdev"). Or memory-backend matching the QOM type names.I'd say it was inspired by "-numa node,memdev" option for some sort of consistency. But I'm fine with any other name as far as there is consensus.
If I had to choose between 'ram' and 'memory-backend', I'd go for the later.
+1 for "memory-backend".
PATCH v2 3/86 machine: alias -mem-path and -mem-prealloc into memory-foo backend
In reply to Igor MammedovAllow a machine to opt in for hostmem backend based initial RAM even if user used old -mem-path/prealloc options by providing
MachineClass::default_ram_id
Follow up patches will incrementally convert machines to new API, by dropping memory_region_allocate_system_memory() and setting default_ram_id that board used to use before conversion to keep migration stream the same.
---
CC: [email protected]
CC: [email protected]
--- include/hw/boards.h | 5 +++++ include/sysemu/hostmem.h | 16 ++++++++++++++++ backends/hostmem-file.c | 7 ------- backends/hostmem-ram.c | 2 -- vl.c | 25 +++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-)
include/hw/boards.h +5 -0
@@ -170,6 +170,10 @@ typedef struct {* false is returned, an error must be set to show the reason of * the rejection. If the hook is not provided, all hotplug will be * allowed. +* @default_ram_id: +* Specifies inital RAM MemoryRegion name to be used for default backend +* creation if user explicitly hasn't specified backend with "ram-memdev" +* property. */ struct MachineClass {/*< private >*/
@@ -226,6 +230,7 @@ struct MachineClass {bool nvdimm_supported;bool numa_mem_supported;bool auto_enable_numa; +const char *default_ram_id; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);
include/sysemu/hostmem.h +16 -0
@@ -27,6 +27,22 @@#define MEMORY_BACKEND_CLASS (klass) \ OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND) +/* hostmem-ram.c */ +/** +* @TYPE_MEMORY_BACKEND_RAM: +* name of backend that uses mmap on the anonymous RAM +*/ + +#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" + +/* hostmem-file.c */ +/** +* @TYPE_MEMORY_BACKEND_FILE: +* name of backend that uses mmap on a file descriptor +*/ +#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" + +typedef struct HostMemoryBackend HostMemoryBackend ;typedef struct HostMemoryBackendClass HostMemoryBackendClass ;/**
backends/hostmem-file.c +0 -7
@@ -18,13 +18,6 @@#include "sysemu/sysemu.h" #include "qom/object_interfaces.h" -/* hostmem-file.c */ -/** -* @TYPE_MEMORY_BACKEND_FILE: -* name of backend that uses mmap on a file descriptor -*/ -#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" -#define MEMORY_BACKEND_FILE (obj) \ OBJECT_CHECK(HostMemoryBackendFile, (obj), TYPE_MEMORY_BACKEND_FILE)
backends/hostmem-ram.c +0 -2
@@ -16,8 +16,6 @@#include "qemu/module.h" #include "qom/object_interfaces.h" -#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" -static void ram_backend_memory_alloc (HostMemoryBackend *backend,Error **errp) {
vl.c +25 -0
@@ -75,6 +75,7 @@ int main(int argc, char **argv)#include "ui/input.h" #include "sysemu/sysemu.h" #include "sysemu/numa.h" +#include "sysemu/hostmem.h" #include "exec/gdbstub.h" #include "qemu/timer.h" #include "chardev/char.h"
@@ -2820,6 +2821,25 @@ static void configure_accelerators(const char *progname) } } +static void create_default_memdev (MachineState *ms,const char *path, +bool prealloc) +{ +Object *obj; +MachineClass *mc =MACHINE_GET_CLASS (ms); + + obj =object_new (path ?TYPE_MEMORY_BACKEND_FILE :TYPE_MEMORY_BACKEND_RAM ); +if (path) { +object_property_set_str (obj, path,"mem-path" , &error_fatal); + } +object_property_set_bool (obj, prealloc,"prealloc" , &error_fatal); +object_property_set_int (obj, ms->ram_size,"size" , &error_fatal); +object_property_add_child (object_get_objects_root (), mc->default_ram_id, + obj, &error_fatal); +user_creatable_complete (USER_CREATABLE (obj), &error_fatal); +object_unref (obj); +object_property_set_link (OBJECT (ms), obj,"ram-memdev" , &error_fatal); +} +int main (int argc,char **argv,char **envp) {int i;
@@ -4283,6 +4303,11 @@ int main(int argc, char **argv, char **envp) }parse_numa_opts (current_machine); +if (!current_machine->ram_memdev && + machine_class->default_ram_size && + machine_class->default_ram_id) { +create_default_memdev (current_machine, mem_path, mem_prealloc); + }/* do monitor/qmp handling at preconfig state if requested */ main_loop ();
Signature · 1 line
2.7.4
Re: [PATCH v2 03/86] machine: alias -mem-path and -mem-prealloc into memory-foo backend
Quoted 140 lines · Igor Mammedov
Allow a machine to opt in for hostmem backend based initial RAM even if user used old -mem-path/prealloc options by providing
MachineClass::default_ram_id
Follow up patches will incrementally convert machines to new API, by droppingmemory_region_allocate_system_memory()and settingdefault_ram_idthat board used to use before conversion to keep migration stream the same.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]--- include/hw/boards.h | 5 +++++ include/sysemu/hostmem.h | 16 ++++++++++++++++ backends/hostmem-file.c | 7 ------- backends/hostmem-ram.c | 2 -- vl.c | 25 +++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-)include/hw/boards.h +5
-0@@ -170,6 +170,10 @@ typedef struct {* false is returned, an error must be set to show the reason of * the rejection. If the hook is not provided, all hotplug will be * allowed. +* @default_ram_id: +* Specifies inital RAM MemoryRegion name to be used for default backend +* creation if user explicitly hasn't specified backend with "ram-memdev" +* property. */ struct MachineClass {/*< private >*/ @@ -226,6 +230,7 @@ struct MachineClass {bool nvdimm_supported;bool numa_mem_supported;bool auto_enable_numa; +const char *default_ram_id; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);include/sysemu/hostmem.h +16
-0@@ -27,6 +27,22 @@#define MEMORY_BACKEND_CLASS (klass) \ OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND) +/* hostmem-ram.c */ +/** +* @TYPE_MEMORY_BACKEND_RAM: +* name of backend that uses mmap on the anonymous RAM +*/ + +#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" + +/* hostmem-file.c */ +/** +* @TYPE_MEMORY_BACKEND_FILE: +* name of backend that uses mmap on a file descriptor +*/ +#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" + +typedef struct HostMemoryBackend HostMemoryBackend ;typedef struct HostMemoryBackendClass HostMemoryBackendClass ;/** backends/hostmem-file.c +0
-7@@ -18,13 +18,6 @@#include "sysemu/sysemu.h" #include "qom/object_interfaces.h" -/* hostmem-file.c */ -/** -* @TYPE_MEMORY_BACKEND_FILE: -* name of backend that uses mmap on a file descriptor -*/ -#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" -#define MEMORY_BACKEND_FILE (obj) \ OBJECT_CHECK(HostMemoryBackendFile, (obj), TYPE_MEMORY_BACKEND_FILE)backends/hostmem-ram.c +0
-2@@ -16,8 +16,6 @@#include "qemu/module.h" #include "qom/object_interfaces.h" -#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" -static void ram_backend_memory_alloc (HostMemoryBackend *backend,Error **errp) {vl.c +20
-0@@ -75,6 +75,7 @@ int main(int argc, char **argv)#include "ui/input.h" #include "sysemu/sysemu.h" #include "sysemu/numa.h" +#include "sysemu/hostmem.h" #include "exec/gdbstub.h" #include "qemu/timer.h" #include "chardev/char.h" @@ -2820,6 +2821,25 @@ static void configure_accelerators(const char *progname) } } +static void create_default_memdev (MachineState *ms,const char *path, +bool prealloc) +{ +Object *obj; +MachineClass *mc =MACHINE_GET_CLASS (ms); + + obj =object_new (path ?TYPE_MEMORY_BACKEND_FILE :TYPE_MEMORY_BACKEND_RAM ); +if (path) { +object_property_set_str (obj, path,"mem-path" , &error_fatal); + } +object_property_set_bool (obj, prealloc,"prealloc" , &error_fatal); +object_property_set_int (obj, ms->ram_size,"size" , &error_fatal); +object_property_add_child (object_get_objects_root (), mc->default_ram_id, + obj, &error_fatal); +user_creatable_complete (USER_CREATABLE (obj), &error_fatal); +object_unref (obj); +object_property_set_link (OBJECT (ms), obj,"ram-memdev" , &error_fatal); +} +int main (int argc,char **argv,char **envp) {int i;
vl.c int main(int argc, char **argv, char **envp) · line 4308
Quoted 6 lines
vl.c +3
-0@@ -4283,6 +4303,11 @@ int main(int argc, char **argv, char **envp) }parse_numa_opts (current_machine); +if (!current_machine->ram_memdev && + machine_class->default_ram_size && + machine_class->default_ram_id) {
Do we really need for its presence?
Can we instead set it to "ram" if NULL?
Quoted 6 lines
vl.c +2
-0+create_default_memdev (current_machine, mem_path, mem_prealloc); + }/* do monitor/qmp handling at preconfig state if requested */ main_loop ();
Re: [PATCH v2 03/86] machine: alias -mem-path and -mem-prealloc into memory-foo backend
Quoted 144 lines · On Wed, 15 Jan 2020 19:54:18 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 143 lines · Igor Mammedov
Allow a machine to opt in for hostmem backend based initial RAM even if user used old -mem-path/prealloc options by providing
MachineClass::default_ram_id
Follow up patches will incrementally convert machines to new API, by droppingmemory_region_allocate_system_memory()and settingdefault_ram_idthat board used to use before conversion to keep migration stream the same.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]--- include/hw/boards.h | 5 +++++ include/sysemu/hostmem.h | 16 ++++++++++++++++ backends/hostmem-file.c | 7 ------- backends/hostmem-ram.c | 2 -- vl.c | 25 +++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 9 deletions(-)include/hw/boards.h +5
-0@@ -170,6 +170,10 @@ typedef struct {* false is returned, an error must be set to show the reason of * the rejection. If the hook is not provided, all hotplug will be * allowed. +* @default_ram_id: +* Specifies inital RAM MemoryRegion name to be used for default backend +* creation if user explicitly hasn't specified backend with "ram-memdev" +* property. */ struct MachineClass {/*< private >*/ @@ -226,6 +230,7 @@ struct MachineClass {bool nvdimm_supported;bool numa_mem_supported;bool auto_enable_numa; +const char *default_ram_id; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev);include/sysemu/hostmem.h +16
-0@@ -27,6 +27,22 @@#define MEMORY_BACKEND_CLASS (klass) \ OBJECT_CLASS_CHECK(HostMemoryBackendClass, (klass), TYPE_MEMORY_BACKEND) +/* hostmem-ram.c */ +/** +* @TYPE_MEMORY_BACKEND_RAM: +* name of backend that uses mmap on the anonymous RAM +*/ + +#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" + +/* hostmem-file.c */ +/** +* @TYPE_MEMORY_BACKEND_FILE: +* name of backend that uses mmap on a file descriptor +*/ +#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" + +typedef struct HostMemoryBackend HostMemoryBackend ;typedef struct HostMemoryBackendClass HostMemoryBackendClass ;/** backends/hostmem-file.c +0
-7@@ -18,13 +18,6 @@#include "sysemu/sysemu.h" #include "qom/object_interfaces.h" -/* hostmem-file.c */ -/** -* @TYPE_MEMORY_BACKEND_FILE: -* name of backend that uses mmap on a file descriptor -*/ -#define TYPE_MEMORY_BACKEND_FILE "memory-backend-file" -#define MEMORY_BACKEND_FILE (obj) \ OBJECT_CHECK(HostMemoryBackendFile, (obj), TYPE_MEMORY_BACKEND_FILE)backends/hostmem-ram.c +0
-2@@ -16,8 +16,6 @@#include "qemu/module.h" #include "qom/object_interfaces.h" -#define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram" -static void ram_backend_memory_alloc (HostMemoryBackend *backend,Error **errp) {vl.c +20
-0@@ -75,6 +75,7 @@ int main(int argc, char **argv)#include "ui/input.h" #include "sysemu/sysemu.h" #include "sysemu/numa.h" +#include "sysemu/hostmem.h" #include "exec/gdbstub.h" #include "qemu/timer.h" #include "chardev/char.h" @@ -2820,6 +2821,25 @@ static void configure_accelerators(const char *progname) } } +static void create_default_memdev (MachineState *ms,const char *path, +bool prealloc) +{ +Object *obj; +MachineClass *mc =MACHINE_GET_CLASS (ms); + + obj =object_new (path ?TYPE_MEMORY_BACKEND_FILE :TYPE_MEMORY_BACKEND_RAM ); +if (path) { +object_property_set_str (obj, path,"mem-path" , &error_fatal); + } +object_property_set_bool (obj, prealloc,"prealloc" , &error_fatal); +object_property_set_int (obj, ms->ram_size,"size" , &error_fatal); +object_property_add_child (object_get_objects_root (), mc->default_ram_id, + obj, &error_fatal); +user_creatable_complete (USER_CREATABLE (obj), &error_fatal); +object_unref (obj); +object_property_set_link (OBJECT (ms), obj,"ram-memdev" , &error_fatal); +} +int main (int argc,char **argv,char **envp) {int i;@@ -4283,6 +4303,11 @@ int main(int argc, char **argv, char **envp) }parse_numa_opts (current_machine);
Quoted 7 lines
vl.c int main(int argc, char **argv, char **envp) · line 4308
Quoted 3 lines
vl.c +3
-0+if (!current_machine->ram_memdev && + machine_class->default_ram_size && + machine_class->default_ram_id) {Do we really need for its presence?
Can we instead set it to "ram" if NULL?
it helps with incremental conversion,
once all boards are converted, it's cleaned up (see [76/86]).
Quoted 9 lines
Quoted 7 lines
vl.c +2
-0+create_default_memdev (current_machine, mem_path, mem_prealloc); + }/* do monitor/qmp handling at preconfig state if requested */ main_loop ();
PATCH v2 4/86 machine: introduce convenience MachineState::ram
In reply to Igor Mammedovthe new field will be used by boards to get access to main RAM memory region and will help to save boiler plate in boards which often add a field or variable just for this purpose.
Memory region will be equivalent to what currently used memory_region_allocate_system_memory() is returning apart from that it will come from hostmem backend. Followup patches will incrementally switch boards to using RAM from MachineState::ram.
Patch takes care of non-NUMA case and follow up patch will initialize MachineState::ram for NUMA case.
---
CC: [email protected]
CC: [email protected]
--- include/hw/boards.h | 9 ++++++++- hw/core/machine.c | 21 +++++++++++++++++++++ hw/core/numa.c | 14 +------------- 3 files changed, 30 insertions(+), 14 deletions(-)
include/hw/boards.h +8 -1
@@ -73,7 +73,12 @@ void machine_set_cpu_numa_node(MachineState *machine, Error **errp);void machine_class_allow_dynamic_sysbus_dev (MachineClass *mc,const char *type); - +/* +* Checks that backend isn't used, preps it for exclusive usage and +* returns migratable MemoryRegion provided by backend. +*/ +MemoryRegion *machine_consume_memdev (MachineState *machine, +HostMemoryBackend *backend);/** * CPUArchId:
@@ -292,6 +297,8 @@ struct MachineState {bool enable_graphics;char *memory_encryption;HostMemoryBackend *ram_memdev; +/* convenience alias to ram_memdev memory region or numa container */ +MemoryRegion *ram;DeviceMemoryState *device_memory;ram_addr_t ram_size;
hw/core/machine.c +21 -0
@@ -26,6 +26,7 @@#include "sysemu/qtest.h" #include "hw/pci/pci.h" #include "hw/mem/nvdimm.h" +#include "migration/vmstate.h" GlobalProperty hw_compat_4_2[] = { {"virtio-blk-device" ,"x-enable-wce-if-config-wce" ,"off" },
@@ -1041,10 +1042,30 @@ static void machine_numa_finish_cpu_init(MachineState *machine)g_string_free (s, true); } +MemoryRegion *machine_consume_memdev (MachineState *machine, +HostMemoryBackend *backend) +{ +MemoryRegion *ret =host_memory_backend_get_memory (backend); + +if (memory_region_is_mapped (ret)) { +char *path =object_get_canonical_path_component (OBJECT (backend)); +error_report ("memory backend %s can't be used multiple times." , path); +g_free (path); +exit (EXIT_FAILURE ); + } +host_memory_backend_set_mapped (backend, true); +vmstate_register_ram_global (ret); +return ret; +} +void machine_run_board_init (MachineState *machine) {MachineClass *machine_class =MACHINE_GET_CLASS (machine); +if (machine->ram_memdev) { + machine->ram =machine_consume_memdev (machine, machine->ram_memdev); + } +if (machine->numa_state) {numa_complete_configuration (machine);if (machine->numa_state->num_nodes) {
hw/core/numa.c +1 -13
@@ -817,20 +817,8 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,if (!backend) {continue ; } -MemoryRegion *seg =host_memory_backend_get_memory (backend); - -if (memory_region_is_mapped (seg)) { -char *path =object_get_canonical_path_component (OBJECT (backend)); -error_report ("memory backend %s is used multiple times. Each " -"-numa option must use a different memdev value." , - path); -g_free (path); -exit (1 ); - } - -host_memory_backend_set_mapped (backend, true); +MemoryRegion *seg =machine_consume_memdev (ms, backend);memory_region_add_subregion (mr, addr, seg); -vmstate_register_ram_global (seg); addr += size; } }
Signature · 1 line
2.7.4
PATCH v2 5/86 initialize MachineState::ram in NUMA case
In reply to Igor MammedovIn case of NUMA there are 2 cases to consider:
1. '-numa node,memdev', the only one that will be available for 5.0 and newer machine types.
In this case reuse current behavior, with only difference memdevs are put into MachineState::ram container +
a temporary glue to keep memory_region_allocate_system_memory() working until all boards converted.
2. fake NUMA ("-numa node mem" and default RAM splitting) the later has been deprecated and is removed but the former is going to stay available for compat reasons from 4.2 and older machine types (libvirt was heavy user of this)
it takes allocate_system_memory_nonnuma() path, like non-NUMA case and falls under conversion to memdev. So extend non-NUMA MachineState::ram initialization introduced in previous patch to take care of fake NUMA case.
---
CC: [email protected]
CC: [email protected]
--- include/sysemu/numa.h | 1 + hw/core/numa.c | 43 ++++++++++++++++++++++++++++++------------- vl.c | 7 ++++--- 3 files changed, 35 insertions(+), 16 deletions(-)
include/sysemu/numa.h +1 -0
@@ -112,5 +112,6 @@ void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes, int nb_nodes, ram_addr_t size);void numa_cpu_pre_plug (const struct CPUArchId *slot,DeviceState *dev,Error **errp); +bool numa_uses_legacy_mem (void );#endif
hw/core/numa.c +30 -13
75 lines not on this page · raw message
vl.c +4 -3
@@ -4303,9 +4303,10 @@ int main(int argc, char **argv, char **envp) }parse_numa_opts (current_machine); -if (!current_machine->ram_memdev && - machine_class->default_ram_size && - machine_class->default_ram_id) { +if (numa_uses_legacy_mem () && + machine_class->default_ram_size && + machine_class->default_ram_id && + !current_machine->ram_memdev) {create_default_memdev (current_machine, mem_path, mem_prealloc); }/* do monitor/qmp handling at preconfig state if requested */
Signature · 1 line
2.7.4
PATCH v2 6/86 alpha:dp264: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/alpha/alpha_sys.h | 2 +- hw/alpha/dp264.c | 3 ++- hw/alpha/typhoon.c | 8 ++------ 3 files changed, 5 insertions(+), 8 deletions(-)
hw/alpha/alpha_sys.h +1 -1
@@ -11,7 +11,7 @@#include "hw/intc/i8259.h" -PCIBus *typhoon_init (ram_addr_t ,ISABus **,qemu_irq *,AlphaCPU *[4 ], +PCIBus *typhoon_init (MemoryRegion *,ISABus **,qemu_irq *,AlphaCPU *[4 ],pci_map_irq_fn );/* alpha_pci.c. */
hw/alpha/dp264.c +2 -1
@@ -75,7 +75,7 @@ static void clipper_init(MachineState *machine) cpus[0 ]->env.trap_arg2 = smp_cpus;/* Init the chipset. */ - pci_bus =typhoon_init (ram_size, &isa_bus, &rtc_irq, cpus, + pci_bus =typhoon_init (machine->ram, &isa_bus, &rtc_irq, cpus, clipper_pci_map_irq);/* Since we have an SRM-compatible PALcode, use the SRM epoch. */
@@ -183,6 +183,7 @@ static void clipper_machine_init(MachineClass *mc) mc->max_cpus =4 ; mc->is_default =1 ; mc->default_cpu_type =ALPHA_CPU_TYPE_NAME ("ev67" ); + mc->default_ram_id ="ram" ; }DEFINE_MACHINE ("clipper" , clipper_machine_init)
hw/alpha/typhoon.c +2 -6
@@ -58,7 +58,6 @@ typedef struct TyphoonState {TyphoonCchip cchip;TyphoonPchip pchip;MemoryRegion dchip_region; -MemoryRegion ram_region; } TyphoonState;/* Called when one of DRIR or DIM changes. */
@@ -817,8 +816,7 @@ static void typhoon_alarm_timer(void *opaque)cpu_interrupt (CPU (s->cchip.cpu[cpu]),CPU_INTERRUPT_TIMER ); } -PCIBus *typhoon_init (ram_addr_t ram_size,ISABus **isa_bus, -qemu_irq *p_rtc_irq, +PCIBus *typhoon_init (MemoryRegion *ram,ISABus **isa_bus,qemu_irq *p_rtc_irq,AlphaCPU *cpus[4 ],pci_map_irq_fn sys_map_irq) {MemoryRegion *addr_space =get_system_memory ();
@@ -851,9 +849,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,/* Main memory region, 0x00.0000.0000. Real hardware supports 32GB, but the address space hole reserved at this point is 8TB. */ -memory_region_allocate_system_memory (&s->ram_region,OBJECT (s),"ram" , - ram_size); -memory_region_add_subregion (addr_space,0 , &s->ram_region); +memory_region_add_subregion (addr_space,0 , ram);/* TIGbus, 0x801.0000.0000, 1GB. */ /* ??? The TIGbus is used for delivering interrupts, and access to
Signature · 1 line
2.7.4
PATCH v2 7/86 arm:aspeed: convert valid RAM sizes to data
In reply to Igor Mammedovvarious foo_rambits() hardcode mapping of RAM sizes to RAM feature bits, which is hard to reuse and repeats over and over.
Convert maps into GLib's hash tables and perform mapping using common mapping function.
Follow up patch will reuse tables for actually checking ram-size property.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- include/hw/misc/aspeed_sdmc.h | 2 + hw/misc/aspeed_sdmc.c | 116 ++++++++++++++++-------------------------- 2 files changed, 47 insertions(+), 71 deletions(-)
include/hw/misc/aspeed_sdmc.h +2 -0
@@ -39,6 +39,8 @@ typedef struct AspeedSDMCState { typedef struct AspeedSDMCClass { SysBusDeviceClass parent_class; + GHashTable *ram2feat; + int fallback_ram_size; uint64_t max_ram_size; uint32_t (*compute_conf)(AspeedSDMCState *s, uint32_t data); void (*write)(AspeedSDMCState *s, uint32_t reg, uint32_t data);
hw/misc/aspeed_sdmc.c +45 -71
181 lines not on this page · raw message
Signature · 1 line
2.7.4
Joel Stanley
maintainerRe: [PATCH v2 07/86] arm:aspeed: convert valid RAM sizes to data
Quoted 6 lines · Igor Mammedov
various
foo_rambits()hardcode mapping of RAM sizes to RAM feature bits, which is hard to reuse and repeats over and over.Convert maps into GLib's hash tables and perform mapping using common mapping function.
Thanks for the patch.
I find the existing code straight forward to understand, and for this reason I would prefer to leave it as it is. Would you mind dropping this patch from your series?
Quoted 226 lines
Follow up patch will reuse tables for actually checking ram-size property.
Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- include/hw/misc/aspeed_sdmc.h | 2 + hw/misc/aspeed_sdmc.c | 116 ++++++++++++++++-------------------------- 2 files changed, 47 insertions(+), 71 deletions(-)include/hw/misc/aspeed_sdmc.h +2
-0@@ -39,6 +39,8 @@ typedef struct AspeedSDMCState { typedef struct AspeedSDMCClass { SysBusDeviceClass parent_class; + GHashTable *ram2feat; + int fallback_ram_size; uint64_t max_ram_size; uint32_t (*compute_conf)(AspeedSDMCState *s, uint32_t data); void (*write)(AspeedSDMCState *s, uint32_t reg, uint32_t data);hw/misc/aspeed_sdmc.c +45
-72@@ -148,72 +148,6 @@ static const MemoryRegionOps aspeed_sdmc_ops = { .valid.max_access_size = 4, }; -static int ast2400_rambits (AspeedSDMCState *s) -{ -switch (s->ram_size >>20 ) { -case 64 : -return ASPEED_SDMC_DRAM_64MB ; -case 128 : -return ASPEED_SDMC_DRAM_128MB ; -case 256 : -return ASPEED_SDMC_DRAM_256MB ; -case 512 : -return ASPEED_SDMC_DRAM_512MB ; -default : -break ; - } - -/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 256M" , - s->ram_size); - s->ram_size =256 <<20 ; -return ASPEED_SDMC_DRAM_256MB ; -} - -static int ast2500_rambits (AspeedSDMCState *s) -{ -switch (s->ram_size >>20 ) { -case 128 : -return ASPEED_SDMC_AST2500_128MB ; -case 256 : -return ASPEED_SDMC_AST2500_256MB ; -case 512 : -return ASPEED_SDMC_AST2500_512MB ; -case 1024 : -return ASPEED_SDMC_AST2500_1024MB ; -default : -break ; - } - -/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 512M" , - s->ram_size); - s->ram_size =512 <<20 ; -return ASPEED_SDMC_AST2500_512MB ; -} - -static int ast2600_rambits (AspeedSDMCState *s) -{ -switch (s->ram_size >>20 ) { -case 256 : -return ASPEED_SDMC_AST2600_256MB ; -case 512 : -return ASPEED_SDMC_AST2600_512MB ; -case 1024 : -return ASPEED_SDMC_AST2600_1024MB ; -case 2048 : -return ASPEED_SDMC_AST2600_2048MB ; -default : -break ; - } - -/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 1024M" , - s->ram_size); - s->ram_size =1024 <<20 ; -return ASPEED_SDMC_AST2600_1024MB ; -} -static void aspeed_sdmc_reset (DeviceState *dev) {AspeedSDMCState *s =ASPEED_SDMC (dev);@@ -257,11 +191,14 @@ static Property aspeed_sdmc_properties[] = {static void aspeed_sdmc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +AspeedSDMCClass *asc =ASPEED_SDMC_CLASS (klass); + dc->realize = aspeed_sdmc_realize; dc->reset = aspeed_sdmc_reset; dc->desc ="ASPEED SDRAM Memory Controller" ; dc->vmsd = &vmstate_aspeed_sdmc; dc->props = aspeed_sdmc_properties; + asc->ram2feat =g_hash_table_new (g_direct_hash, g_direct_equal); }static const TypeInfo aspeed_sdmc_info = {@@ -273,10 +210,28 @@ static const TypeInfo aspeed_sdmc_info = { .abstract = true, }; +static int aspeed_get_ram_feat (AspeedSDMCState *s) +{ +AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); +int ram_mb = s->ram_size >>20 ; +gpointer val; + +if (g_hash_table_contains (asc->ram2feat,GINT_TO_POINTER (ram_mb))) { + val =g_hash_table_lookup (asc->ram2feat,GINT_TO_POINTER (ram_mb)); +return GPOINTER_TO_INT (val); + } + +warn_report ("Invalid RAM size 0x%" PRIx64". Using default %dM" , + s->ram_size, asc->fallback_ram_size); + s->ram_size = asc->fallback_ram_size <<20 ; + val =g_hash_table_lookup (asc->ram2feat, &asc->fallback_ram_size); +return GPOINTER_TO_INT (val); +} +static uint32_t aspeed_2400_sdmc_compute_conf (AspeedSDMCState *s,uint32_t data) { -uint32_t fixed_conf =ASPEED_SDMC_VGA_COMPAT | -ASPEED_SDMC_DRAM_SIZE (ast2400_rambits (s)); +int ram_f =aspeed_get_ram_feat (s); +uint32_t fixed_conf =ASPEED_SDMC_VGA_COMPAT |ASPEED_SDMC_DRAM_SIZE (ram_f);/* Make sure readonly bits are kept */ data &= ~ASPEED_SDMC_READONLY_MASK ;@@ -298,6 +253,9 @@ static void aspeed_2400_sdmc_write(AspeedSDMCState *s, uint32_t reg, s->regs[reg] = data; } +#define REGISTER_RAM_SIZE (h, k, v) \ + g_hash_table_insert(h->ram2feat, GINT_TO_POINTER(k), GINT_TO_POINTER(v)) +static void aspeed_2400_sdmc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -307,6 +265,11 @@ static void aspeed_2400_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =512 <<20 ; asc->compute_conf = aspeed_2400_sdmc_compute_conf; asc->write = aspeed_2400_sdmc_write; + asc->fallback_ram_size =256 ; +REGISTER_RAM_SIZE (asc,64 ,ASPEED_SDMC_DRAM_64MB ); +REGISTER_RAM_SIZE (asc,128 ,ASPEED_SDMC_DRAM_128MB ); +REGISTER_RAM_SIZE (asc,256 ,ASPEED_SDMC_DRAM_256MB ); +REGISTER_RAM_SIZE (asc,512 ,ASPEED_SDMC_DRAM_512MB ); }static const TypeInfo aspeed_2400_sdmc_info = {@@ -317,10 +280,10 @@ static const TypeInfo aspeed_2400_sdmc_info = {static uint32_t aspeed_2500_sdmc_compute_conf (AspeedSDMCState *s,uint32_t data) { +int ram_f =aspeed_get_ram_feat (s);uint32_t fixed_conf =ASPEED_SDMC_HW_VERSION (1 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | -ASPEED_SDMC_CACHE_INITIAL_DONE | -ASPEED_SDMC_DRAM_SIZE (ast2500_rambits (s)); +ASPEED_SDMC_CACHE_INITIAL_DONE |ASPEED_SDMC_DRAM_SIZE (ram_f);/* Make sure readonly bits are kept */ data &= ~ASPEED_SDMC_AST2500_READONLY_MASK ;@@ -360,6 +323,11 @@ static void aspeed_2500_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =1024 <<20 ; asc->compute_conf = aspeed_2500_sdmc_compute_conf; asc->write = aspeed_2500_sdmc_write; + asc->fallback_ram_size =512 ; +REGISTER_RAM_SIZE (asc,128 ,ASPEED_SDMC_AST2500_128MB ); +REGISTER_RAM_SIZE (asc,256 ,ASPEED_SDMC_AST2500_256MB ); +REGISTER_RAM_SIZE (asc,512 ,ASPEED_SDMC_AST2500_512MB ); +REGISTER_RAM_SIZE (asc,1024 ,ASPEED_SDMC_AST2500_1024MB ); }static const TypeInfo aspeed_2500_sdmc_info = {@@ -370,9 +338,10 @@ static const TypeInfo aspeed_2500_sdmc_info = {static uint32_t aspeed_2600_sdmc_compute_conf (AspeedSDMCState *s,uint32_t data) { +int ram_f =aspeed_get_ram_feat (s);uint32_t fixed_conf =ASPEED_SDMC_HW_VERSION (3 ) |ASPEED_SDMC_VGA_APERTURE (ASPEED_SDMC_VGA_64MB ) | -ASPEED_SDMC_DRAM_SIZE (ast2600_rambits (s)); +ASPEED_SDMC_DRAM_SIZE (ram_f);/* Make sure readonly bits are kept (use ast2500 mask) */ data &= ~ASPEED_SDMC_AST2500_READONLY_MASK ;@@ -413,6 +382,11 @@ static void aspeed_2600_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =2048 <<20 ; asc->compute_conf = aspeed_2600_sdmc_compute_conf; asc->write = aspeed_2600_sdmc_write; + asc->fallback_ram_size =512 ; +REGISTER_RAM_SIZE (asc,256 ,ASPEED_SDMC_AST2600_256MB ); +REGISTER_RAM_SIZE (asc,512 ,ASPEED_SDMC_AST2600_512MB ); +REGISTER_RAM_SIZE (asc,1024 ,ASPEED_SDMC_AST2600_1024MB ); +REGISTER_RAM_SIZE (asc,2048 ,ASPEED_SDMC_AST2600_2048MB ); }static const TypeInfo aspeed_2600_sdmc_info = { --2.7.4
PATCH v2 8/86 arm:aspeed: actually check RAM size
In reply to Igor MammedovIt's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. Well it isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.
So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M
0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container
0000000080000000-00000000800fffff (prio 0, ram): ram
0000000080100000-00000000bfffffff (prio 0, i/o): max_ram
-M ast2500-evb -m 3G
0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container
0000000080000000-000000013fffffff (prio 0, ram): ram
[DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ram)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.
I don't know how hardware is supposed to work so I've kept it as is.
But as for CLI side machine should honor whatever user configured or error out to make user fix CLI.
This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to error_fatal at the moment SOC is realized so user will have to fix RAM size on CLI to start machine.
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/aspeed.c | 9 +-------- hw/misc/aspeed_sdmc.c | 5 +++++ 2 files changed, 6 insertions(+), 8 deletions(-)
hw/arm/aspeed.c +1 -8
@@ -213,14 +213,7 @@ static void aspeed_machine_init(MachineState *machine) "hw-prot-key", &error_abort); }object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , - &error_abort); - -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); + &error_fatal);memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);
hw/misc/aspeed_sdmc.c +5 -0
@@ -165,6 +165,11 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)AspeedSDMCState *s =ASPEED_SDMC (dev);AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); +if (!g_hash_table_contains (asc->ram2feat, +GINT_TO_POINTER (s->ram_size >>20 ))) { +error_setg (errp,"Invalid RAM size 0x%" PRIx64, s->ram_size); +return ; + } s->max_ram_size = asc->max_ram_size; memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_sdmc_ops, s,
Signature · 1 line
2.7.4
Re: [PATCH v2 08/86] arm:aspeed: actually check RAM size
Quoted 21 lines · Igor Mammedov
It's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. Well it isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-00000000800fffff (prio 0, ram): ram 0000000080100000-00000000bfffffff (prio 0, i/o): max_ram -M ast2500-evb -m 3G 0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-000000013fffffff (prio 0, ram): ram [DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ram
Quoted 5 lines
)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.> I don't know how hardware is supposed to work so I've kept it as is.
The HW is hardwired and the modeling is trying to accommodate with the '-m' option, the machine definition and the SDRAM controller limits and register definitions for a given SoC. The result is not that good it seems :/
Quoted 8 lines
But as for CLI side machine should honor whatever user configured or error out to make user fix CLI.
This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to
error_fatalat the moment SOC is realized so user will have to fix RAM size on CLI to start machine.
commit 8e00d1a97d1d ("aspeed/sdmc: Introduce an object class per SoC") moved some calls from the realize handler to reset handler and it broke the checks on the RAM size.
I think we should introduce get/set handlers on the "ram-size" property that would look for a matching size in an AspeedSDMCClass array of valid RAM sizes. The default size of the machine would be a valid default and bogus user defined sizes would be fatal to QEMU.
We could get rid of the code :
/* use a common default */
warn_report("Invalid RAM size 0x%" PRIx64 ". Using default 512M",
s->ram_size);
s->ram_size = 512 << 20;
return ASPEED_SDMC_AST2500_512MB;'max_ram_size' would be the last entry of the AspeedSDMCClass array and, anyhow, we need to check bmc->max_ram is really needed. I am not sure anymore.
Thanks,
C.
Quoted 55 lines
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 9 +-------- hw/misc/aspeed_sdmc.c | 5 +++++ 2 files changed, 6 insertions(+), 8 deletions(-)hw/arm/aspeed.c +1
-8@@ -213,14 +213,7 @@ static void aspeed_machine_init(MachineState *machine) "hw-prot-key", &error_abort); }object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , - &error_abort); - -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); + &error_fatal);memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);hw/misc/aspeed_sdmc.c +5
-0@@ -165,6 +165,11 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)AspeedSDMCState *s =ASPEED_SDMC (dev);AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); +if (!g_hash_table_contains (asc->ram2feat, +GINT_TO_POINTER (s->ram_size >>20 ))) { +error_setg (errp,"Invalid RAM size 0x%" PRIx64, s->ram_size); +return ; + } s->max_ram_size = asc->max_ram_size; memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_sdmc_ops, s,
Re: [PATCH v2 08/86] arm:aspeed: actually check RAM size
Quoted 42 lines · On Thu, 16 Jan 2020 09:41:03 +0100 Cédric Le Goater <[email protected]> wrote:
Quoted 21 lines · Igor Mammedov
It's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. Well it isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-00000000800fffff (prio 0, ram): ram 0000000080100000-00000000bfffffff (prio 0, i/o): max_ram -M ast2500-evb -m 3G 0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-000000013fffffff (prio 0, ram): ram [DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ramQuoted 5 lines
)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.> I don't know how hardware is supposed to work so I've kept it as is.The HW is hardwired and the modeling is trying to accommodate with the '-m' option, the machine definition and the SDRAM controller limits and register definitions for a given SoC. The result is not that good it seems :/
Quoted 8 lines
But as for CLI side machine should honor whatever user configured or error out to make user fix CLI.
This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to
error_fatalat the moment SOC is realized so user will have to fix RAM size on CLI to start machine.
Quoted 8 lines
commit
8e00d1a97d1d("aspeed/sdmc: Introduce an object class per SoC") moved some calls from the realize handler to reset handler and it broke the checks on the RAM size.I think we should introduce get/set handlers on the "ram-size" property that would look for a matching size in an AspeedSDMCClass array of valid RAM sizes. The default size of the machine would be a valid default and bogus user defined sizes would be fatal to QEMU.
That's what I'm after, i.e. board either accepts user asked size or exits with error. So as far as there aren't any fix-ups it should work for the purpose of this series
Quoted 10 lines
We could get rid of the code :
/* use a common default */ warn_report("Invalid RAM size 0x%" PRIx64 ". Using default 512M", s->ram_size); s->ram_size = 512 << 20; return ASPEED_SDMC_AST2500_512MB;
Quoted 3 lines
'
max_ram_size' would be the last entry of the AspeedSDMCClass array and, anyhow, we need to checkbmc->max_ramis really needed. I am not sure anymore.
I'll rework aspeed parts taking in account feedback.
Quoted 62 lines
Thanks,
C.
Quoted 55 lines
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 9 +-------- hw/misc/aspeed_sdmc.c | 5 +++++ 2 files changed, 6 insertions(+), 8 deletions(-)hw/arm/aspeed.c +1
-8@@ -213,14 +213,7 @@ static void aspeed_machine_init(MachineState *machine) "hw-prot-key", &error_abort); }object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , - &error_abort); - -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); + &error_fatal);memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);hw/misc/aspeed_sdmc.c +5
-0@@ -165,6 +165,11 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)AspeedSDMCState *s =ASPEED_SDMC (dev);AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); +if (!g_hash_table_contains (asc->ram2feat, +GINT_TO_POINTER (s->ram_size >>20 ))) { +error_setg (errp,"Invalid RAM size 0x%" PRIx64, s->ram_size); +return ; + } s->max_ram_size = asc->max_ram_size; memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_sdmc_ops, s,
Re: [PATCH v2 08/86] arm:aspeed: actually check RAM size
Quoted 49 lines · Igor Mammedov
Quoted 46 lines · On Thu, 16 Jan 2020 09:41:03 +0100 Cédric Le Goater <[email protected]> wrote:
Quoted 21 lines · Igor Mammedov
It's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. Well it isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-00000000800fffff (prio 0, ram): ram 0000000080100000-00000000bfffffff (prio 0, i/o): max_ram -M ast2500-evb -m 3G 0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-000000013fffffff (prio 0, ram): ram [DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ramQuoted 5 lines
)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.> I don't know how hardware is supposed to work so I've kept it as is.The HW is hardwired and the modeling is trying to accommodate with the '-m' option, the machine definition and the SDRAM controller limits and register definitions for a given SoC. The result is not that good it seems :/
Quoted 8 lines
But as for CLI side machine should honor whatever user configured or error out to make user fix CLI.
This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to
error_fatalat the moment SOC is realized so user will have to fix RAM size on CLI to start machine.commit
8e00d1a97d1d("aspeed/sdmc: Introduce an object class per SoC") moved some calls from the realize handler to reset handler and it broke the checks on the RAM size.
Quoted 7 lines
Quoted 4 lines
I think we should introduce get/set handlers on the "ram-size" property that would look for a matching size in an AspeedSDMCClass array of valid RAM sizes. The default size of the machine would be a valid default and bogus user defined sizes would be fatal to QEMU.
That's what I'm after, i.e. board either accepts user asked size or exits with error.
We should be able to catch bogus values with :
object_property_set_uint(OBJECT(&bmc->soc), ram_size, "ram-size",
&error_abort);in aspeed_machine_init() and let QEMU exit.
Quoted 13 lines
So as far as there aren't any fix-ups it should work for the purpose of this series
Quoted 10 lines
We could get rid of the code :
/* use a common default */ warn_report("Invalid RAM size 0x%" PRIx64 ". Using default 512M", s->ram_size); s->ram_size = 512 << 20; return ASPEED_SDMC_AST2500_512MB;
Quoted 5 lines
Quoted 3 lines
'
max_ram_size' would be the last entry of the AspeedSDMCClass array and, anyhow, we need to checkbmc->max_ramis really needed. I am not sure anymore.I'll rework aspeed parts taking in account feedback.
OK. We will give them a try. I don't think you have to bother with bmc->max_ram for the moment. It doesn't seem to be in your way.
Thanks,
C.
Quoted 58 lines
Quoted 57 lines
Quoted 55 lines
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 9 +-------- hw/misc/aspeed_sdmc.c | 5 +++++ 2 files changed, 6 insertions(+), 8 deletions(-)hw/arm/aspeed.c +1
-8@@ -213,14 +213,7 @@ static void aspeed_machine_init(MachineState *machine) "hw-prot-key", &error_abort); }object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , - &error_abort); - -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); + &error_fatal);memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);hw/misc/aspeed_sdmc.c +5
-0@@ -165,6 +165,11 @@ static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)AspeedSDMCState *s =ASPEED_SDMC (dev);AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); +if (!g_hash_table_contains (asc->ram2feat, +GINT_TO_POINTER (s->ram_size >>20 ))) { +error_setg (errp,"Invalid RAM size 0x%" PRIx64, s->ram_size); +return ; + } s->max_ram_size = asc->max_ram_size; memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_sdmc_ops, s,
PATCH v3 7/84 hw/arm/aspeed: actually check RAM size
In reply to Cédric Le GoaterIt's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. It isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.
So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M
0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container
0000000080000000-00000000800fffff (prio 0, ram): ram
0000000080100000-00000000bfffffff (prio 0, i/o): max_ram
-M ast2500-evb -m 3G
0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container
0000000080000000-000000013fffffff (prio 0, ram): ram
[DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ram)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.
This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to error_fatal at the moment SOC.ram-size is set so user will have to fix RAM size on CLI to start machine.
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
---
v3:
* replace
[PATCH v2 07/86] arm:aspeed: convert valid RAM sizes to data [PATCH v2 08/86] arm:aspeed: actually check RAM size
with a simplified variant that adds ram_size check to sdmc.ram-size property
--- include/hw/misc/aspeed_sdmc.h | 1 + hw/arm/aspeed.c | 13 +++----- hw/misc/aspeed_sdmc.c | 77 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 70 insertions(+), 21 deletions(-)
include/hw/misc/aspeed_sdmc.h +1 -0
@@ -40,6 +40,7 @@ typedef struct AspeedSDMCClass {SysBusDeviceClass parent_class;uint64_t max_ram_size; +const uint64_t *valid_ram_sizes;uint32_t (*compute_conf)(AspeedSDMCState *s,uint32_t data);void (*write)(AspeedSDMCState *s,uint32_t reg,uint32_t data); } AspeedSDMCClass;
hw/arm/aspeed.c +5 -8
@@ -191,8 +191,12 @@ static void aspeed_machine_init(MachineState *machine) sc =ASPEED_SOC_GET_CLASS (&bmc->soc); +/* +* This will error out if isize is not supported by memory controller. +*/ object_property_set_uint (OBJECT (&bmc->soc), ram_size,"ram-size" , - &error_abort); + &error_fatal); +object_property_set_int (OBJECT (&bmc->soc), amc->hw_strap1,"hw-strap1" , &error_abort); object_property_set_int(OBJECT(&bmc->soc), amc->hw_strap2, "hw-strap2",
@@ -215,13 +219,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_abort); -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram); memory_region_add_subregion(get_system_memory(),
hw/misc/aspeed_sdmc.c +64 -13
155 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v3 07/84] hw/arm/aspeed: actually check RAM size
Quoted 31 lines · Igor Mammedov
It's supposed that SOC will check if "-m" provided RAM size is valid by setting "ram-size" property and then board would read back valid (possibly corrected value) to map RAM MemoryReging with valid size. It isn't doing so, since check is called only indirectly from
aspeed_sdmc_reset()->asc->compute_conf()
or much later when guest writes to configuration register.So depending on "-m" value QEMU end-ups with a warning and an invalid MemoryRegion size allocated and mapped. (examples:
-M ast2500-evb -m 1M0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-00000000800fffff (prio 0, ram): ram 0000000080100000-00000000bfffffff (prio 0, i/o): max_ram -M ast2500-evb -m 3G 0000000080000000-000000017ffffffe (prio 0, i/o): aspeed-ram-container 0000000080000000-000000013fffffff (prio 0, ram): ram [DETECTED OVERFLOW!] 0000000140000000-00000000bfffffff (prio 0, i/o): max_ram)
On top of that sdmc falls back and reports to guest "default" size, it thinks machine should have.This patch makes ram-size check actually work and changes behavior from a warning later on during machine reset to
error_fatalat the moment SOC.ram-size is set so user will have to fix RAM size on CLI to start machine.
Quoted 7 lines
It also gets out of the way mutable ram-size logic, so we could consolidate RAM allocation logic around pre-allocated hostmem backend (supplied by user or auto created by generic machine code depending on supplied -m/mem-path/mem-prealloc options.
Signed-off-by Igor Mammedov <[email protected]>
LGTM, some comments below.
Quoted 80 lines
---
v3:
* replace
[PATCH v2 07/86] arm:aspeed: convert valid RAM sizes to data [PATCH v2 08/86] arm:aspeed: actually check RAM size
with a simplified variant that addsram_sizecheck to sdmc.ram-size propertySigned-off-by Igor Mammedov <[email protected]>--- include/hw/misc/aspeed_sdmc.h | 1 + hw/arm/aspeed.c | 13 +++----- hw/misc/aspeed_sdmc.c | 77 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 70 insertions(+), 21 deletions(-)include/hw/misc/aspeed_sdmc.h +1
-0@@ -40,6 +40,7 @@ typedef struct AspeedSDMCClass {SysBusDeviceClass parent_class;uint64_t max_ram_size; +const uint64_t *valid_ram_sizes;uint32_t (*compute_conf)(AspeedSDMCState *s,uint32_t data);void (*write)(AspeedSDMCState *s,uint32_t reg,uint32_t data); } AspeedSDMCClass;hw/arm/aspeed.c +5
-8@@ -191,8 +191,12 @@ static void aspeed_machine_init(MachineState *machine) sc =ASPEED_SOC_GET_CLASS (&bmc->soc); +/* +* This will error out if isize is not supported by memory controller. +*/ object_property_set_uint (OBJECT (&bmc->soc), ram_size,"ram-size" , - &error_abort); + &error_fatal); +object_property_set_int (OBJECT (&bmc->soc), amc->hw_strap1,"hw-strap1" , &error_abort); object_property_set_int(OBJECT(&bmc->soc), amc->hw_strap2, "hw-strap2",@@ -215,13 +219,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_abort); -/* -* Allocate RAM after the memory controller has checked the size -* was valid. If not, a default value is used. -*/ - ram_size =object_property_get_uint (OBJECT (&bmc->soc),"ram-size" , - &error_abort); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size);memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram); memory_region_add_subregion(get_system_memory(),hw/misc/aspeed_sdmc.c +3
-0@@ -17,6 +17,9 @@#include "migration/vmstate.h" #include "qapi/error.h" #include "trace.h" +#include "qemu/units.h" +#include "qemu/cutils.h" +#include "qapi/visitor.h" /* Protection Key Register */ #define R_PROT (0x00 / 4)
hw/misc/aspeed_sdmc.c static int ast2400_rambits(AspeedSDMCState *s) · line 167
Quoted 2 lines
hw/misc/aspeed_sdmc.c +0
-0@@ -163,10 +166,7 @@ static int ast2400_rambits(AspeedSDMCState *s)break ; }
Now that the ramsizes are being checked, I think we can add in the default statement :
g_assert_not_reached();
hw/misc/aspeed_sdmc.c static int ast2400_rambits(AspeedSDMCState *s) · line 170
Quoted 7 lines
hw/misc/aspeed_sdmc.c +1
-4-/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 256M" , - s->ram_size); - s->ram_size =256 <<20 ; +assert (0 );return ASPEED_SDMC_DRAM_256MB ;
and skip the default return value.
A part from that,
Thanks,
C.
Quoted 149 lines
hw/misc/aspeed_sdmc.c +60
-9}@@ -185,10 +185,7 @@ static int ast2500_rambits(AspeedSDMCState *s)break ; } -/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 512M" , - s->ram_size); - s->ram_size =512 <<20 ; +assert (0 );return ASPEED_SDMC_AST2500_512MB ; }@@ -207,10 +204,7 @@ static int ast2600_rambits(AspeedSDMCState *s)break ; } -/* use a common default */ -warn_report ("Invalid RAM size 0x%" PRIx64". Using default 1024M" , - s->ram_size); - s->ram_size =1024 <<20 ; +assert (0 );return ASPEED_SDMC_AST2600_1024MB ; }@@ -225,6 +219,51 @@ static void aspeed_sdmc_reset(DeviceState *dev) s->regs[R_CONF ] = asc->compute_conf (s,0 ); } +static void aspeed_sdmc_get_ram_size (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +AspeedSDMCState *s =ASPEED_SDMC (obj); +int64_t value = s->ram_size; + +visit_type_int (v, name, &value, errp); +} + +static void aspeed_sdmc_set_ram_size (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +int i; +char *sz; +int64_t value; +Error *local_err =NULL ; +AspeedSDMCState *s =ASPEED_SDMC (obj); +AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s); + +visit_type_int (v, name, &value, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +for (i =0 ; asc->valid_ram_sizes[i]; i++) { +if (value == asc->valid_ram_sizes[i]) { + s->ram_size = value; +return ; + } + } + + sz =size_to_str (value); +error_setg (&local_err,"Invalid RAM size %s" , sz); +g_free (sz); +error_propagate (errp, local_err); +} + +static void aspeed_sdmc_initfn (Object *obj) +{ +object_property_add (obj,"ram-size" ,"int" , + aspeed_sdmc_get_ram_size, aspeed_sdmc_set_ram_size, +NULL ,NULL ,NULL ); +} +static void aspeed_sdmc_realize (DeviceState *dev,Error **errp) {SysBusDevice *sbd =SYS_BUS_DEVICE (dev);@@ -249,7 +288,6 @@ static const VMStateDescription vmstate_aspeed_sdmc = { };static Property aspeed_sdmc_properties[] = { -DEFINE_PROP_UINT64 ("ram-size" , AspeedSDMCState, ram_size,0 ),DEFINE_PROP_UINT64 ("max-ram-size" , AspeedSDMCState, max_ram_size,0 ),DEFINE_PROP_END_OF_LIST (), };@@ -268,6 +306,7 @@ static const TypeInfo aspeed_sdmc_info = { .name = TYPE_ASPEED_SDMC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(AspeedSDMCState), + .instance_init = aspeed_sdmc_initfn, .class_init = aspeed_sdmc_class_init, .class_size = sizeof(AspeedSDMCClass), .abstract = true,@@ -298,6 +337,9 @@ static void aspeed_2400_sdmc_write(AspeedSDMCState *s, uint32_t reg, s->regs[reg] = data; } +static const uint64_t +aspeed_2400_ram_sizes[] = {64 * MiB,128 * MiB,256 * MiB,512 * MiB,0 }; +static void aspeed_2400_sdmc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -307,6 +349,7 @@ static void aspeed_2400_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =512 <<20 ; asc->compute_conf = aspeed_2400_sdmc_compute_conf; asc->write = aspeed_2400_sdmc_write; + asc->valid_ram_sizes = aspeed_2400_ram_sizes; }static const TypeInfo aspeed_2400_sdmc_info = {@@ -351,6 +394,9 @@ static void aspeed_2500_sdmc_write(AspeedSDMCState *s, uint32_t reg, s->regs[reg] = data; } +static const uint64_t +aspeed_2500_ram_sizes[] = {128 * MiB,256 * MiB,512 * MiB,1024 * MiB,0 }; +static void aspeed_2500_sdmc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -360,6 +406,7 @@ static void aspeed_2500_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =1024 <<20 ; asc->compute_conf = aspeed_2500_sdmc_compute_conf; asc->write = aspeed_2500_sdmc_write; + asc->valid_ram_sizes = aspeed_2500_ram_sizes; }static const TypeInfo aspeed_2500_sdmc_info = {@@ -404,6 +451,9 @@ static void aspeed_2600_sdmc_write(AspeedSDMCState *s, uint32_t reg, s->regs[reg] = data; } +static const uint64_t +aspeed_2600_ram_sizes[] = {256 * MiB,512 * MiB,1024 * MiB,2048 * MiB,0 }; +static void aspeed_2600_sdmc_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -413,6 +463,7 @@ static void aspeed_2600_sdmc_class_init(ObjectClass *klass, void *data) asc->max_ram_size =2048 <<20 ; asc->compute_conf = aspeed_2600_sdmc_compute_conf; asc->write = aspeed_2600_sdmc_write; + asc->valid_ram_sizes = aspeed_2600_ram_sizes; }static const TypeInfo aspeed_2600_sdmc_info = {
PATCH v2 9/86 hw:aspeed: drop warning and bogus ram_size fixup
In reply to Igor MammedovIt was useless to try fixup ram_size and print warning on guest access to config register to begin with.
Now previous patch made sure that SDMC can not be realized with invalid RAM size, so there is no case where warning and not used ram_size fixup could be triggered.
So remove now dead code.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/misc/aspeed_sdmc.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
hw/misc/aspeed_sdmc.c +1 -10
@@ -219,17 +219,8 @@ static int aspeed_get_ram_feat(AspeedSDMCState *s) {AspeedSDMCClass *asc =ASPEED_SDMC_GET_CLASS (s);int ram_mb = s->ram_size >>20 ; -gpointer val; +gpointer val =g_hash_table_lookup (asc->ram2feat,GINT_TO_POINTER (ram_mb)); -if (g_hash_table_contains (asc->ram2feat,GINT_TO_POINTER (ram_mb))) { - val =g_hash_table_lookup (asc->ram2feat,GINT_TO_POINTER (ram_mb)); -return GPOINTER_TO_INT (val); - } - -warn_report ("Invalid RAM size 0x%" PRIx64". Using default %dM" , - s->ram_size, asc->fallback_ram_size); - s->ram_size = asc->fallback_ram_size <<20 ; - val =g_hash_table_lookup (asc->ram2feat, &asc->fallback_ram_size);return GPOINTER_TO_INT (val); }
Signature · 1 line
2.7.4
PATCH v2 10/86 arm:aspeed: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/aspeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/arm/aspeed.c +2 -3
@@ -35,7 +35,6 @@ static struct arm_boot_info aspeed_board_binfo = {struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram_container; -MemoryRegion ram;MemoryRegion max_ram; };
@@ -184,6 +183,7 @@ static void aspeed_machine_init(MachineState *machine)memory_region_init (&bmc->ram_container,NULL ,"aspeed-ram-container" ,UINT32_MAX ); +memory_region_add_subregion (&bmc->ram_container,0 , machine->ram); object_initialize_child(OBJECT(machine), "soc", &bmc->soc, (sizeof(bmc->soc)), amc->soc_name, &error_abort,
@@ -215,8 +215,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size); -memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_SDRAM ], &bmc->ram_container);
@@ -393,6 +391,7 @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_parallel =1 ; + mc->default_ram_id ="ram" ; }static void aspeed_machine_palmetto_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.7.4
Re: [PATCH v2 10/86] arm:aspeed: use memdev for RAM
Quoted 50 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/aspeed.c +1
-3@@ -35,7 +35,6 @@ static struct arm_boot_info aspeed_board_binfo = {struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram_container; -MemoryRegion ram;MemoryRegion max_ram; };@@ -184,6 +183,7 @@ static void aspeed_machine_init(MachineState *machine)memory_region_init (&bmc->ram_container,NULL ,"aspeed-ram-container" ,UINT32_MAX ); +memory_region_add_subregion (&bmc->ram_container,0 , machine->ram); object_initialize_child(OBJECT(machine), "soc", &bmc->soc, (sizeof(bmc->soc)), amc->soc_name, &error_abort,@@ -215,8 +215,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size); -memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_SDRAM ], &bmc->ram_container);
hw/arm/aspeed.c static void aspeed_machine_class_init(ObjectClass *oc, void *data) · line 397
Quoted 7 lines
hw/arm/aspeed.c +1
-0@@ -393,6 +391,7 @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_parallel =1 ; + mc->default_ram_id ="ram" ; }static void aspeed_machine_palmetto_class_init (ObjectClass *oc,void *data)
Re: [PATCH v2 10/86] arm:aspeed: use memdev for RAM
In reply to Igor MammedovQuoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
We need to check 'max_ram' is still needed. I remember that old firmwares were testing the RAM size by doing write/read checks at the top of the RAM. This was breaking QEMU sometime ago.
C.
Quoted 48 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/aspeed.c +2
-3@@ -35,7 +35,6 @@ static struct arm_boot_info aspeed_board_binfo = {struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram_container; -MemoryRegion ram;MemoryRegion max_ram; };@@ -184,6 +183,7 @@ static void aspeed_machine_init(MachineState *machine)memory_region_init (&bmc->ram_container,NULL ,"aspeed-ram-container" ,UINT32_MAX ); +memory_region_add_subregion (&bmc->ram_container,0 , machine->ram); object_initialize_child(OBJECT(machine), "soc", &bmc->soc, (sizeof(bmc->soc)), amc->soc_name, &error_abort,@@ -215,8 +215,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size); -memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_SDRAM ], &bmc->ram_container);@@ -393,6 +391,7 @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_parallel =1 ; + mc->default_ram_id ="ram" ; }static void aspeed_machine_palmetto_class_init (ObjectClass *oc,void *data)
Re: [PATCH v2 10/86] arm:aspeed: use memdev for RAM
Quoted 9 lines · Cédric Le Goater
Quoted 8 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.
Quoted 8 lines
Quoted 1 line
Signed-off-by Igor Mammedov <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>We need to check '
max_ram' is still needed. I remember that old firmwares were testing the RAM size by doing write/read checks at the top of the RAM. This was breaking QEMU sometime ago.
Do you remember any version we can use to test this? Also add to our acceptance tests.
Quoted 52 lines
C.
Quoted 48 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/aspeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)hw/arm/aspeed.c +2
-3@@ -35,7 +35,6 @@ static struct arm_boot_info aspeed_board_binfo = {struct AspeedBoardState {AspeedSoCState soc;MemoryRegion ram_container; -MemoryRegion ram;MemoryRegion max_ram; };@@ -184,6 +183,7 @@ static void aspeed_machine_init(MachineState *machine)memory_region_init (&bmc->ram_container,NULL ,"aspeed-ram-container" ,UINT32_MAX ); +memory_region_add_subregion (&bmc->ram_container,0 , machine->ram); object_initialize_child(OBJECT(machine), "soc", &bmc->soc, (sizeof(bmc->soc)), amc->soc_name, &error_abort,@@ -215,8 +215,6 @@ static void aspeed_machine_init(MachineState *machine)object_property_set_bool (OBJECT (&bmc->soc), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&bmc->ram,NULL ,"ram" , ram_size); -memory_region_add_subregion (&bmc->ram_container,0 , &bmc->ram);memory_region_add_subregion (get_system_memory (), sc->memmap[ASPEED_SDRAM ], &bmc->ram_container);@@ -393,6 +391,7 @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->no_parallel =1 ; + mc->default_ram_id ="ram" ; }static void aspeed_machine_palmetto_class_init (ObjectClass *oc,void *data)
PATCH v2 11/86 arm:collie: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
- while at it add check for user supplied RAM size and error out if it mismatches board expected value.
- introduce RAM_ADDR_UFMT to avoid build errors on 32-bit hosts when specifying format string for ram_addr_t type
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- include/exec/cpu-common.h | 2 ++ hw/arm/collie.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-)
include/exec/cpu-common.h +2 -0
@@ -33,10 +33,12 @@ enum device_endian {typedef uint64_t ram_addr_t ;# define RAM_ADDR_MAX UINT64_MAX# define RAM_ADDR_FMT "%" PRIx64 +# define RAM_ADDR_UFMT "%" PRIu64#else typedef uintptr_t ram_addr_t ;# define RAM_ADDR_MAX UINTPTR_MAX# define RAM_ADDR_FMT "%" PRIxPTR +# define RAM_ADDR_UFMT "%" PRIuPTR#endif extern ram_addr_t ram_size;
hw/arm/collie.c +10 -5
@@ -20,20 +20,23 @@static struct arm_boot_info collie_binfo = { .loader_start =SA_SDCS0 , - .ram_size =0x20000000 , };static void collie_init (MachineState *machine) {StrongARMState *s;DriveInfo *dinfo; -MemoryRegion *sdram =g_new (MemoryRegion,1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } s =sa1110_init (machine->cpu_type); -memory_region_allocate_system_memory (sdram,NULL ,"strongarm.sdram" , - collie_binfo.ram_size); -memory_region_add_subregion (get_system_memory (),SA_SDCS0 , sdram); +memory_region_add_subregion (get_system_memory (),SA_SDCS0 , machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 ); pflash_cfi01_register(SA_CS0, "collie.fl1", 0x02000000,
@@ -57,6 +60,8 @@ static void collie_machine_init(MachineClass *mc) mc->init = collie_init; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("sa1110" ); + mc->default_ram_size =0x20000000 ; + mc->default_ram_id ="strongarm.sdram" ; }DEFINE_MACHINE ("collie" , collie_machine_init)
Signature · 1 line
2.7.4
PATCH v2 12/86 arm:cubieboard: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
While at it, get rid of no longer needed CubieBoardState wrapper.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/cubieboard.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
hw/arm/cubieboard.c +8 -17
@@ -28,52 +28,42 @@ static struct arm_boot_info cubieboard_binfo = { .board_id = 0x1008, }; -typedef struct CubieBoardState { -AwA10State *a10; -MemoryRegion sdram; -}CubieBoardState ; -static void cubieboard_init (MachineState *machine) { -CubieBoardState *s =g_new (CubieBoardState,1 ); +AwA10State *a10 =AW_A10 (object_new (TYPE_AW_A10 ));Error *err =NULL ; - s->a10 =AW_A10 (object_new (TYPE_AW_A10 )); - -object_property_set_int (OBJECT (&s->a10->emac),1 ,"phy-addr" , &err); +object_property_set_int (OBJECT (&a10->emac),1 ,"phy-addr" , &err);if (err !=NULL ) {error_reportf_err (err,"Couldn't set phy address: " );exit (1 ); } -object_property_set_int (OBJECT (&s->a10->timer),32768 ,"clk0-freq" , &err); +object_property_set_int (OBJECT (&a10->timer),32768 ,"clk0-freq" , &err);if (err !=NULL ) {error_reportf_err (err,"Couldn't set clk0 frequency: " );exit (1 ); } -object_property_set_int (OBJECT (&s->a10->timer),24000000 ,"clk1-freq" , - &err); +object_property_set_int (OBJECT (&a10->timer),24000000 ,"clk1-freq" , &err);if (err !=NULL ) {error_reportf_err (err,"Couldn't set clk1 frequency: " );exit (1 ); } -object_property_set_bool (OBJECT (s->a10), true,"realized" , &err); +object_property_set_bool (OBJECT (a10), true,"realized" , &err);if (err !=NULL ) {error_reportf_err (err,"Couldn't realize Allwinner A10: " );exit (1 ); } -memory_region_allocate_system_memory (&s->sdram,NULL ,"cubieboard.ram" , - machine->ram_size);memory_region_add_subregion (get_system_memory (),AW_A10_SDRAM_BASE , - &s->sdram); + machine->ram);/* TODO create and connect IDE devices for ide_drive_get() */ cubieboard_binfo.ram_size = machine->ram_size; -arm_load_kernel (&s->a10->cpu, machine, &cubieboard_binfo); +arm_load_kernel (&a10->cpu, machine, &cubieboard_binfo); }static void cubieboard_machine_init (MachineClass *mc)
@@ -84,6 +74,7 @@ static void cubieboard_machine_init(MachineClass *mc) mc->block_default_type =IF_IDE ; mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="cubieboard.ram" ; }DEFINE_MACHINE ("cubieboard" , cubieboard_machine_init)
Signature · 1 line
2.7.4
PATCH v2 13/86 arm:digic_boards: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
remove no longer needed DigicBoardState
PS2:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/digic_boards.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
hw/arm/digic_boards.c +18 -18
@@ -35,39 +35,38 @@#include "hw/loader.h" #include "sysemu/sysemu.h" #include "sysemu/qtest.h" +#include "qemu/units.h" #define DIGIC4_ROM0_BASE 0xf0000000#define DIGIC4_ROM1_BASE 0xf8000000#define DIGIC4_ROM_MAX_SIZE 0x08000000 -typedef struct DigicBoardState { -DigicState *digic; -MemoryRegion ram; -}DigicBoardState ; -typedef struct DigicBoard { -hwaddr ram_size; -void (*add_rom0)(DigicBoardState *,hwaddr ,const char *); +void (*add_rom0)(DigicState *,hwaddr ,const char *);const char *rom0_def_filename; -void (*add_rom1)(DigicBoardState *,hwaddr ,const char *); +void (*add_rom1)(DigicState *,hwaddr ,const char *);const char *rom1_def_filename; }DigicBoard ; -static void digic4_board_init (DigicBoard *board) +static void digic4_board_init (MachineState *machine,DigicBoard *board) {Error *err =NULL ; +MachineClass *mc =MACHINE_GET_CLASS (machine); -DigicBoardState *s =g_new (DigicBoardState,1 ); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } - s->digic =DIGIC (object_new (TYPE_DIGIC )); -object_property_set_bool (OBJECT (s->digic), true,"realized" , &err); +DigicState *s =DIGIC (object_new (TYPE_DIGIC )); +object_property_set_bool (OBJECT (s), true,"realized" , &err);if (err !=NULL ) {error_reportf_err (err,"Couldn't realize DIGIC SoC: " );exit (1 ); } -memory_region_allocate_system_memory (&s->ram,NULL ,"ram" , board->ram_size); -memory_region_add_subregion (get_system_memory (),0 , &s->ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);if (board->add_rom0) { board->add_rom0 (s,DIGIC4_ROM0_BASE , board->rom0_def_filename);
@@ -78,7 +77,7 @@ static void digic4_board_init(DigicBoard *board) } } -static void digic_load_rom (DigicBoardState *s,hwaddr addr, +static void digic_load_rom (DigicState *s,hwaddr addr,hwaddr max_size,const char *def_filename) {target_long rom_size;
@@ -118,7 +117,7 @@ static void digic_load_rom(DigicBoardState *s, hwaddr addr,* Samsung K8P3215UQB * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory */ -static void digic4_add_k8p3215uqb_rom (DigicBoardState *s,hwaddr addr, +static void digic4_add_k8p3215uqb_rom (DigicState *s,hwaddr addr,const char *def_filename) {#define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
@@ -135,14 +134,13 @@ static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr, }static DigicBoard digic4_board_canon_a1100 = { - .ram_size =64 *1024 *1024 , .add_rom1 = digic4_add_k8p3215uqb_rom, .rom1_def_filename ="canon-a1100-rom1.bin" , };static void canon_a1100_init (MachineState *machine) { -digic4_board_init (&digic4_board_canon_a1100); +digic4_board_init (machine, &digic4_board_canon_a1100); }static void canon_a1100_machine_init (MachineClass *mc)
@@ -150,6 +148,8 @@ static void canon_a1100_machine_init(MachineClass *mc) mc->desc ="Canon PowerShot A1100 IS" ; mc->init = &canon_a1100_init; mc->ignore_memory_transaction_failures = true; + mc->default_ram_size =64 * MiB; + mc->default_ram_id ="ram" ; }DEFINE_MACHINE ("canon-a1100" , canon_a1100_machine_init)
Signature · 1 line
2.7.4
PATCH v2 14/86 arm:highbank: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/highbank.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/arm/highbank.c +4 -6
@@ -236,7 +236,6 @@ enum cxmachines {*/ static void calxeda_init (MachineState *machine,enum cxmachines machine_id) { -ram_addr_t ram_size = machine->ram_size;DeviceState *dev =NULL ;SysBusDevice *busdev;qemu_irq pic[128 ];
@@ -247,7 +246,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)qemu_irq cpu_virq[4 ];qemu_irq cpu_vfiq[4 ];MemoryRegion *sysram; -MemoryRegion *dram;MemoryRegion *sysmem;char *sysboot_filename;
@@ -290,10 +288,8 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) } sysmem =get_system_memory (); - dram =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (dram,NULL ,"highbank.dram" , ram_size);/* SDRAM at address zero. */ -memory_region_add_subregion (sysmem,0 , dram); +memory_region_add_subregion (sysmem,0 , machine->ram); sysram =g_new (MemoryRegion,1 ); memory_region_init_ram(sysram, NULL, "highbank.sysram", 0x8000,
@@ -387,7 +383,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)/* TODO create and connect IDE devices for ide_drive_get() */ - highbank_binfo.ram_size = ram_size; + highbank_binfo.ram_size = machine->ram_size;/* highbank requires a dtb in order to boot, and the dtb will override * the board ID. The following value is ignored, so set it to -1 to be * clear that the value is meaningless.
@@ -430,6 +426,7 @@ static void highbank_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="highbank.dram" ; }static const TypeInfo highbank_type = {
@@ -448,6 +445,7 @@ static void midway_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="highbank.dram" ; }static const TypeInfo midway_type = {
Signature · 1 line
2.7.4
Re: [PATCH v2 14/86] arm:highbank: use memdev for RAM
Quoted 68 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/highbank.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)hw/arm/highbank.c +3
-6@@ -236,7 +236,6 @@ enum cxmachines {*/ static void calxeda_init (MachineState *machine,enum cxmachines machine_id) { -ram_addr_t ram_size = machine->ram_size;DeviceState *dev =NULL ;SysBusDevice *busdev;qemu_irq pic[128 ];@@ -247,7 +246,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)qemu_irq cpu_virq[4 ];qemu_irq cpu_vfiq[4 ];MemoryRegion *sysram; -MemoryRegion *dram;MemoryRegion *sysmem;char *sysboot_filename;@@ -290,10 +288,8 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) } sysmem =get_system_memory (); - dram =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (dram,NULL ,"highbank.dram" , ram_size);/* SDRAM at address zero. */ -memory_region_add_subregion (sysmem,0 , dram); +memory_region_add_subregion (sysmem,0 , machine->ram); sysram =g_new (MemoryRegion,1 ); memory_region_init_ram(sysram, NULL, "highbank.sysram", 0x8000,@@ -387,7 +383,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)/* TODO create and connect IDE devices for ide_drive_get() */ - highbank_binfo.ram_size = ram_size; + highbank_binfo.ram_size = machine->ram_size;/* highbank requires a dtb in order to boot, and the dtb will override * the board ID. The following value is ignored, so set it to -1 to be * clear that the value is meaningless. @@ -430,6 +426,7 @@ static void highbank_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="highbank.dram" ; }static const TypeInfo highbank_type = {
hw/arm/highbank.c static void midway_class_init(ObjectClass *oc, void *data) · line 451
Quoted 7 lines
hw/arm/highbank.c +1
-0@@ -448,6 +445,7 @@ static void midway_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="highbank.dram" ; }static const TypeInfo midway_type = {
PATCH v2 15/86 arm:imx25_pdk: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/imx25_pdk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/imx25_pdk.c +2 -2
@@ -78,10 +78,10 @@ static void imx25_pdk_init(MachineState *machine)/* We need to initialize our memory */ if (machine->ram_size > (FSL_IMX25_SDRAM0_SIZE +FSL_IMX25_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " +error_report ("RAM size " RAM_ADDR_FMT " above max supported, " "reduced to %x" , machine->ram_size,FSL_IMX25_SDRAM0_SIZE +FSL_IMX25_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX25_SDRAM0_SIZE +FSL_IMX25_SDRAM1_SIZE ; +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "imx25.ram",
Signature · 1 line
2.7.4
PATCH v2 16/86 arm:imx25_pdk: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/imx25_pdk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/arm/imx25_pdk.c +4 -5
@@ -58,7 +58,6 @@typedef struct IMX25PDK {FslIMX25State soc; -MemoryRegion ram;MemoryRegion ram_alias; }IMX25PDK ;
@@ -84,10 +83,8 @@ static void imx25_pdk_init(MachineState *machine)exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (&s->ram,NULL ,"imx25.ram" , - machine->ram_size);memory_region_add_subregion (get_system_memory (),FSL_IMX25_SDRAM0_ADDR , - &s->ram); + machine->ram);/* initialize the alias memory if any */ for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
@@ -107,7 +104,8 @@ static void imx25_pdk_init(MachineState *machine)if (size < ram[i].size) {memory_region_init_alias (&s->ram_alias,NULL ,"ram.alias" , - &s->ram, alias_offset, ram[i].size - size); + machine->ram, + alias_offset, ram[i].size - size);memory_region_add_subregion (get_system_memory (), ram[i].addr + size, &s->ram_alias); }
@@ -135,6 +133,7 @@ static void imx25_pdk_machine_init(MachineClass *mc) mc->desc ="ARM i.MX25 PDK board (ARM926)" ; mc->init = imx25_pdk_init; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="imx25.ram" ; }DEFINE_MACHINE ("imx25-pdk" , imx25_pdk_machine_init)
Signature · 1 line
2.7.4
Re: [PATCH v2 16/86] arm:imx25_pdk: use memdev for RAM
Quoted 53 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/imx25_pdk.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)hw/arm/imx25_pdk.c +3
-5@@ -58,7 +58,6 @@typedef struct IMX25PDK {FslIMX25State soc; -MemoryRegion ram;MemoryRegion ram_alias; }IMX25PDK ;@@ -84,10 +83,8 @@ static void imx25_pdk_init(MachineState *machine)exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (&s->ram,NULL ,"imx25.ram" , - machine->ram_size);memory_region_add_subregion (get_system_memory (),FSL_IMX25_SDRAM0_ADDR , - &s->ram); + machine->ram);/* initialize the alias memory if any */ for (i = 0, ram_size = machine->ram_size, alias_offset = 0;@@ -107,7 +104,8 @@ static void imx25_pdk_init(MachineState *machine)if (size < ram[i].size) {memory_region_init_alias (&s->ram_alias,NULL ,"ram.alias" , - &s->ram, alias_offset, ram[i].size - size); + machine->ram, + alias_offset, ram[i].size - size);memory_region_add_subregion (get_system_memory (), ram[i].addr + size, &s->ram_alias); }
hw/arm/imx25_pdk.c static void imx25_pdk_machine_init(MachineClass *mc) · line 139
Quoted 7 lines
hw/arm/imx25_pdk.c +1
-0@@ -135,6 +133,7 @@ static void imx25_pdk_machine_init(MachineClass *mc) mc->desc ="ARM i.MX25 PDK board (ARM926)" ; mc->init = imx25_pdk_init; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="imx25.ram" ; }DEFINE_MACHINE ("imx25-pdk" , imx25_pdk_machine_init)
PATCH v2 17/86 arm:integratorcp: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/integratorcp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/arm/integratorcp.c +4 -5
@@ -585,7 +585,6 @@ static void integratorcp_init(MachineState *machine)Object *cpuobj;ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *ram_alias =g_new (MemoryRegion,1 );qemu_irq pic[32 ];DeviceState *dev, *sic, *icp;
@@ -605,14 +604,13 @@ static void integratorcp_init(MachineState *machine) cpu =ARM_CPU (cpuobj); -memory_region_allocate_system_memory (ram,NULL ,"integrator.ram" , - ram_size);/* ??? On a real system the first 1Mb is mapped as SSRAM or boot flash. */ /* ??? RAM should repeat to fill physical memory space. */ /* SDRAM at address zero*/ -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* And again at address 0x80000000 */ -memory_region_init_alias (ram_alias,NULL ,"ram.alias" , ram,0 , ram_size); +memory_region_init_alias (ram_alias,NULL ,"ram.alias" , machine->ram, +0 , ram_size);memory_region_add_subregion (address_space_mem,0x80000000 , ram_alias); dev =qdev_create (NULL ,TYPE_INTEGRATOR_CM );
@@ -660,6 +658,7 @@ static void integratorcp_machine_init(MachineClass *mc) mc->init = integratorcp_init; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_id ="integrator.ram" ; }DEFINE_MACHINE ("integratorcp" , integratorcp_machine_init)
Signature · 1 line
2.7.4
PATCH v2 18/86 arm:kzm: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/kzm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/kzm.c +2 -2
@@ -78,10 +78,10 @@ static void kzm_init(MachineState *machine)/* Check the amount of memory is compatible with the SOC */ if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " +error_report ("RAM size " RAM_ADDR_FMT " above max supported, " "reduced to %x" , machine->ram_size,FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ; +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "kzm.ram",
Signature · 1 line
2.7.4
Re: [PATCH v2 18/86] arm:kzm: drop RAM size fixup
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Igor" == Igor Mammedov <[email protected]> writes:
Igor> If user provided non-sense RAM size, board will complain and Igor> continue running with max RAM size supported. Also RAM is going Igor> to be allocated by generic code, so it won't be possible for Igor> board to fix things up for user.
Igor> Make it error message and exit to force user fix CLI, instead of Igor> accepting non-sense CLI values.
I think this comment needs rewording a little. Maybe:
If the user provided too large a RAM size, the code used to complain and trim it to the max size. Now tht RAM is allocated by generic code, that's no longer possible, so generate an error and exit instead.
Igor> /* Check the amount of memory is compatible with the SOC */
Igor> if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +
Igor> FSL_IMX31_SDRAM1_SIZE)) {
Igor> - warn_report("RAM size " RAM_ADDR_FMT " above max supported, " Igor> + error_report("RAM size " RAM_ADDR_FMT " above max supported, "
Igor> "reduced to %x", machine->ram_size,
Igor> FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE);
This needs to be changed so it doesn't say that the RAM size is reduced, just what the maximum is. Maybe:
error_report("RAM size " RAM_ADDR_FMT " above max (%x) supported.", machine->ram_size, FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE);
Peter C
PATCH v3 18/86 arm:kzm: drop RAM size fixup
If the user provided too large a RAM size, the code used to complain and trim it to the max size. Now tht RAM is allocated by generic code, that's no longer possible, so generate an error and exit instead.
---
v3:
* rephrase commit message in nicer way
("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>)
* reword error message and use size_to_str() to pretty print suggested size ("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>)
--- hw/arm/kzm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
hw/arm/kzm.c +5 -4
@@ -25,6 +25,7 @@#include "hw/char/serial.h" #include "sysemu/qtest.h" #include "sysemu/sysemu.h" +#include "qemu/cutils.h" /* Memory map for Kzm Emulation Baseboard: * 0x00000000-0x7fffffff See i.MX31 SOC for support
@@ -78,10 +79,10 @@ static void kzm_init(MachineState *machine)/* Check the amount of memory is compatible with the SOC */ if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " -"reduced to %x" , machine->ram_size, -FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ; +char *sz =size_to_str (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); +error_report ("RAM size more than %s is not supported" , sz); +g_free (sz); +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "kzm.ram",
Signature · 1 line
2.7.4
Re: [PATCH v3 18/86] arm:kzm: drop RAM size fixup
Quoted 33 lines · Igor Mammedov
If the user provided too large a RAM size, the code used to complain and trim it to the max size. Now tht RAM is allocated by generic code, that's no longer possible, so generate an error and exit instead.
Signed-off-by Igor Mammedov <[email protected]>---
v3:
* rephrase commit message in nicer way("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>) * reword error message and use size_to_str() to pretty print suggested size ("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>)--- hw/arm/kzm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/arm/kzm.c +1
-0@@ -25,6 +25,7 @@#include "hw/char/serial.h" #include "sysemu/qtest.h" #include "sysemu/sysemu.h" +#include "qemu/cutils.h" /* Memory map for Kzm Emulation Baseboard: * 0x00000000-0x7fffffff See i.MX31 SOC for support
hw/arm/kzm.c static void kzm_init(MachineState *machine) · line 83
Quoted 9 lines
hw/arm/kzm.c +2
-4@@ -78,10 +79,10 @@ static void kzm_init(MachineState *machine)/* Check the amount of memory is compatible with the SOC */ if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " -"reduced to %x" , machine->ram_size, -FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ; +char *sz =size_to_str (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); +error_report ("RAM size more than %s is not supported" , sz);
Yay! Can you use this pattern the other patches too?
You might want to add:
#define FSL_IMX31_SDRAM_SIZE_MAX \
(FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE)
Quoted 6 lines
hw/arm/kzm.c +2
-0+g_free (sz); +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "kzm.ram",
Re: [PATCH v3 18/86] arm:kzm: drop RAM size fixup
Quoted 35 lines · On Thu, 16 Jan 2020 19:22:08 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 34 lines · Igor Mammedov
If the user provided too large a RAM size, the code used to complain and trim it to the max size. Now tht RAM is allocated by generic code, that's no longer possible, so generate an error and exit instead.
Signed-off-by Igor Mammedov <[email protected]>---
v3:
* rephrase commit message in nicer way("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>) * reword error message and use size_to_str() to pretty print suggested size ("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>)--- hw/arm/kzm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/arm/kzm.c +1
-0@@ -25,6 +25,7 @@#include "hw/char/serial.h" #include "sysemu/qtest.h" #include "sysemu/sysemu.h" +#include "qemu/cutils.h" /* Memory map for Kzm Emulation Baseboard: * 0x00000000-0x7fffffff See i.MX31 SOC for support @@ -78,10 +79,10 @@ static void kzm_init(MachineState *machine)
Quoted 10 lines
hw/arm/kzm.c static void kzm_init(MachineState *machine) · line 83
Quoted 8 lines
hw/arm/kzm.c +2
-4/* Check the amount of memory is compatible with the SOC */ if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " -"reduced to %x" , machine->ram_size, -FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ; +char *sz =size_to_str (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); +error_report ("RAM size more than %s is not supported" , sz);Yay! Can you use this pattern the other patches too?
I plan to, as it's much neater and I can avoid adding RAM_ADDR_FMT
Would your acks still stand or should I drop your Reviewed-bys on changed in such way patches?
Quoted 14 lines
You might want to add:
#define FSL_IMX31_SDRAM_SIZE_MAX \ (FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE)Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 6 lines
hw/arm/kzm.c +2
-0+g_free (sz); +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "kzm.ram",
Re: [PATCH v3 18/86] arm:kzm: drop RAM size fixup
Quoted 49 lines · Igor Mammedov
Quoted 35 lines · On Thu, 16 Jan 2020 19:22:08 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 34 lines · Igor Mammedov
If the user provided too large a RAM size, the code used to complain and trim it to the max size. Now tht RAM is allocated by generic code, that's no longer possible, so generate an error and exit instead.
Signed-off-by Igor Mammedov <[email protected]>---
v3:
* rephrase commit message in nicer way("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>) * reword error message and use size_to_str() to pretty print suggested size ("Chubb, Peter (Data61, Kensington NSW)" <[email protected]>)--- hw/arm/kzm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)hw/arm/kzm.c +1
-0@@ -25,6 +25,7 @@#include "hw/char/serial.h" #include "sysemu/qtest.h" #include "sysemu/sysemu.h" +#include "qemu/cutils.h" /* Memory map for Kzm Emulation Baseboard: * 0x00000000-0x7fffffff See i.MX31 SOC for support @@ -78,10 +79,10 @@ static void kzm_init(MachineState *machine)Quoted 10 lines
hw/arm/kzm.c static void kzm_init(MachineState *machine) · line 83
Quoted 8 lines
hw/arm/kzm.c +2
-4/* Check the amount of memory is compatible with the SOC */ if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE )) { -warn_report ("RAM size " RAM_ADDR_FMT " above max supported, " -"reduced to %x" , machine->ram_size, -FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); - machine->ram_size =FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ; +char *sz =size_to_str (FSL_IMX31_SDRAM0_SIZE +FSL_IMX31_SDRAM1_SIZE ); +error_report ("RAM size more than %s is not supported" , sz);Yay! Can you use this pattern the other patches too?
Quoted 4 lines
I plan to, as it's much neater and I can avoid adding
RAM_ADDR_FMTWould your acks still stand or should I drop your Reviewed-bys on changed in such way patches?
Yes please keep my Reviewed-by tag in the other patches too.
Quoted 15 lines
Quoted 14 lines
You might want to add:
#define FSL_IMX31_SDRAM_SIZE_MAX \ (FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE)Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 6 lines
hw/arm/kzm.c +2
-0+g_free (sz); +exit (EXIT_FAILURE ); } memory_region_allocate_system_memory(&s->ram, NULL, "kzm.ram",
PATCH v2 19/86 arm:kzm: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/kzm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/arm/kzm.c +4 -5
@@ -51,7 +51,6 @@typedef struct IMX31KZM {FslIMX31State soc; -MemoryRegion ram;MemoryRegion ram_alias; }IMX31KZM ;
@@ -84,10 +83,8 @@ static void kzm_init(MachineState *machine)exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (&s->ram,NULL ,"kzm.ram" , - machine->ram_size);memory_region_add_subregion (get_system_memory (),FSL_IMX31_SDRAM0_ADDR , - &s->ram); + machine->ram);/* initialize the alias memory if any */ for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
@@ -107,7 +104,8 @@ static void kzm_init(MachineState *machine)if (size < ram[i].size) {memory_region_init_alias (&s->ram_alias,NULL ,"ram.alias" , - &s->ram, alias_offset, ram[i].size - size); + machine->ram, + alias_offset, ram[i].size - size);memory_region_add_subregion (get_system_memory (), ram[i].addr + size, &s->ram_alias); }
@@ -139,6 +137,7 @@ static void kzm_machine_init(MachineClass *mc) mc->desc ="ARM KZM Emulation Baseboard (ARM1136)" ; mc->init = kzm_init; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="kzm.ram" ; }DEFINE_MACHINE ("kzm" , kzm_machine_init)
Signature · 1 line
2.7.4
Re: [PATCH v2 19/86] arm:kzm: use memdev for RAM
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Igor" == Igor Mammedov <[email protected]> writes:
Igor> memory region.
Igor> Signed-off-by: Igor Mammedov <[email protected]> Igor> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Igor> ---
Igor> CC: [email protected]
You can add:
Igor> CC: [email protected]
Igor> CC: [email protected]
Peter C
PATCH v2 20/86 arm:mcimx6ul-evk: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
remove no longer needed MCIMX6ULEVK
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/mcimx6ul-evk.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
hw/arm/mcimx6ul-evk.c +9 -16
@@ -19,15 +19,10 @@#include "qemu/error-report.h" #include "sysemu/qtest.h" -typedef struct { -FslIMX6ULState soc; -MemoryRegion ram; -}MCIMX6ULEVK ; -static void mcimx6ul_evk_init (MachineState *machine) {static struct arm_boot_info boot_info; -MCIMX6ULEVK *s =g_new0 (MCIMX6ULEVK ,1 ); +FslIMX6ULState *s;int i;if (machine->ram_size >FSL_IMX6UL_MMDC_SIZE ) {
@@ -43,15 +38,12 @@ static void mcimx6ul_evk_init(MachineState *machine) .nb_cpus = machine->smp.cpus, }; -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), -TYPE_FSL_IMX6UL , &error_fatal,NULL ); - -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_fatal); + s =FSL_IMX6UL (object_new (TYPE_FSL_IMX6UL )); +object_property_add_child (OBJECT (machine),"soc" ,OBJECT (s), &error_fatal); +object_property_set_bool (OBJECT (s), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&s->ram,NULL ,"mcimx6ul-evk.ram" , - machine->ram_size); -memory_region_add_subregion (get_system_memory (), -FSL_IMX6UL_MMDC_ADDR , &s->ram); +memory_region_add_subregion (get_system_memory (),FSL_IMX6UL_MMDC_ADDR , + machine->ram);for (i =0 ; i <FSL_IMX6UL_NUM_USDHCS ; i++) {BusState *bus;
@@ -61,7 +53,7 @@ static void mcimx6ul_evk_init(MachineState *machine) di =drive_get_next (IF_SD ); blk = di ?blk_by_legacy_dinfo (di) :NULL ; - bus =qdev_get_child_bus (DEVICE (&s->soc.usdhc[i]),"sd-bus" ); + bus =qdev_get_child_bus (DEVICE (&s->usdhc[i]),"sd-bus" ); carddev =qdev_create (bus,TYPE_SD_CARD );qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal); object_property_set_bool(OBJECT(carddev), true,
@@ -69,7 +61,7 @@ static void mcimx6ul_evk_init(MachineState *machine) }if (!qtest_enabled ()) { -arm_load_kernel (&s->soc.cpu, machine, &boot_info); +arm_load_kernel (&s->cpu, machine, &boot_info); } }
@@ -78,5 +70,6 @@ static void mcimx6ul_evk_machine_init(MachineClass *mc) mc->desc ="Freescale i.MX6UL Evaluation Kit (Cortex A7)" ; mc->init = mcimx6ul_evk_init; mc->max_cpus =FSL_IMX6UL_NUM_CPUS ; + mc->default_ram_id ="mcimx6ul-evk.ram" ; }DEFINE_MACHINE ("mcimx6ul-evk" , mcimx6ul_evk_machine_init)
Signature · 1 line
2.7.4
PATCH v2 21/86 arm:mcimx7d-sabre: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
remove no longer needed MCIMX7Sabre
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/mcimx7d-sabre.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
hw/arm/mcimx7d-sabre.c +9 -16
@@ -21,15 +21,10 @@#include "qemu/error-report.h" #include "sysemu/qtest.h" -typedef struct { -FslIMX7State soc; -MemoryRegion ram; -}MCIMX7Sabre ; -static void mcimx7d_sabre_init (MachineState *machine) {static struct arm_boot_info boot_info; -MCIMX7Sabre *s =g_new0 (MCIMX7Sabre,1 ); +FslIMX7State *s;int i;if (machine->ram_size >FSL_IMX7_MMDC_SIZE ) {
@@ -45,15 +40,12 @@ static void mcimx7d_sabre_init(MachineState *machine) .nb_cpus = machine->smp.cpus, }; -object_initialize_child (OBJECT (machine),"soc" , - &s->soc,sizeof (s->soc), -TYPE_FSL_IMX7 , &error_fatal,NULL ); -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_fatal); + s =FSL_IMX7 (object_new (TYPE_FSL_IMX7 )); +object_property_add_child (OBJECT (machine),"soc" ,OBJECT (s), &error_fatal); +object_property_set_bool (OBJECT (s), true,"realized" , &error_fatal); -memory_region_allocate_system_memory (&s->ram,NULL ,"mcimx7d-sabre.ram" , - machine->ram_size); -memory_region_add_subregion (get_system_memory (), -FSL_IMX7_MMDC_ADDR , &s->ram); +memory_region_add_subregion (get_system_memory (),FSL_IMX7_MMDC_ADDR , + machine->ram);for (i =0 ; i <FSL_IMX7_NUM_USDHCS ; i++) {BusState *bus;
@@ -63,7 +55,7 @@ static void mcimx7d_sabre_init(MachineState *machine) di =drive_get_next (IF_SD ); blk = di ?blk_by_legacy_dinfo (di) :NULL ; - bus =qdev_get_child_bus (DEVICE (&s->soc.usdhc[i]),"sd-bus" ); + bus =qdev_get_child_bus (DEVICE (&s->usdhc[i]),"sd-bus" ); carddev =qdev_create (bus,TYPE_SD_CARD );qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal); object_property_set_bool(OBJECT(carddev), true,
@@ -71,7 +63,7 @@ static void mcimx7d_sabre_init(MachineState *machine) }if (!qtest_enabled ()) { -arm_load_kernel (&s->soc.cpu[0 ], machine, &boot_info); +arm_load_kernel (&s->cpu[0 ], machine, &boot_info); } }
@@ -80,5 +72,6 @@ static void mcimx7d_sabre_machine_init(MachineClass *mc) mc->desc ="Freescale i.MX7 DUAL SABRE (Cortex A7)" ; mc->init = mcimx7d_sabre_init; mc->max_cpus =FSL_IMX7_NUM_CPUS ; + mc->default_ram_id ="mcimx7d-sabre.ram" ; }DEFINE_MACHINE ("mcimx7d-sabre" , mcimx7d_sabre_machine_init)
Signature · 1 line
2.7.4
PATCH v2 22/86 arm:mps2-tz: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/mps2-tz.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/arm/mps2-tz.c +9 -4
@@ -79,7 +79,6 @@ typedef struct {MachineState parent;ARMSSE iotkit; -MemoryRegion psram;MemoryRegion ssram[3 ];MemoryRegion ssram1_m;MPS2SCC scc;
@@ -388,6 +387,12 @@ static void mps2tz_common_init(MachineState *machine)exit (1 ); } +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +sysbus_init_child_obj (OBJECT (machine),"iotkit" , &mms->iotkit,sizeof (mms->iotkit), mmc->armsse_type); iotkitdev =DEVICE (&mms->iotkit);
@@ -458,9 +463,7 @@ static void mps2tz_common_init(MachineState *machine)* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily * call the 16MB our "system memory", as it's the largest lump. */ -memory_region_allocate_system_memory (&mms->psram, -NULL ,"mps.ram" ,16 * MiB); -memory_region_add_subregion (system_memory,0x80000000 , &mms->psram); +memory_region_add_subregion (system_memory,0x80000000 , machine->ram);/* The overflow IRQs for all UARTs are ORed together. * Tx, Rx and "combined" IRQs are sent to the NVIC separately.
@@ -642,6 +645,7 @@ static void mps2tz_class_init(ObjectClass *oc, void *data) mc->init = mps2tz_common_init; iic->check = mps2_tz_idau_check; + mc->default_ram_id ="mps.ram" ; }static void mps2tz_an505_class_init (ObjectClass *oc,void *data)
@@ -657,6 +661,7 @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-m33" ); mmc->scc_id =0x41045050 ; mmc->armsse_type =TYPE_IOTKIT ; + mc->default_ram_size =16 * MiB; }static void mps2tz_an521_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.7.4
PATCH v2 23/86 arm:mps2: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/mps2.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/arm/mps2.c +9 -4
@@ -55,7 +55,6 @@ typedef struct {MachineState parent;ARMv7MState armv7m; -MemoryRegion psram;MemoryRegion ssram1;MemoryRegion ssram1_m;MemoryRegion ssram23;
@@ -118,6 +117,12 @@ static void mps2_common_init(MachineState *machine)exit (1 ); } +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* The FPGA images have an odd combination of different RAMs, * because in hardware they are different implementations and * connected to different buses, giving varying performance/size
@@ -146,9 +151,7 @@ static void mps2_common_init(MachineState *machine)* This is of no use for QEMU so we don't implement it (as if * zbt_boot_ctrl is always zero). */ -memory_region_allocate_system_memory (&mms->psram, -NULL ,"mps.ram" ,16 * MiB); -memory_region_add_subregion (system_memory,0x21000000 , &mms->psram); +memory_region_add_subregion (system_memory,0x21000000 , machine->ram);switch (mmc->fpga_type) {case FPGA_AN385 :
@@ -338,6 +341,8 @@ static void mps2_class_init(ObjectClass *oc, void *data) mc->init = mps2_common_init; mc->max_cpus =1 ; + mc->default_ram_size =16 * MiB; + mc->default_ram_id ="mps.ram" ; }static void mps2_an385_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.7.4
PATCH v2 24/86 arm:musicpal: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/musicpal.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
hw/arm/musicpal.c +11 -5
@@ -1589,16 +1589,20 @@ static void musicpal_init(MachineState *machine)int i;unsigned long flash_size;DriveInfo *dinfo; +MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *sram =g_new (MemoryRegion,1 ); +/* For now we use a fixed - the original - RAM size */ +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } + cpu =ARM_CPU (cpu_create (machine->cpu_type)); -/* For now we use a fixed - the original - RAM size */ -memory_region_allocate_system_memory (ram,NULL ,"musicpal.ram" , -MP_RAM_DEFAULT_SIZE ); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);memory_region_init_ram (sram,NULL ,"musicpal.sram" ,MP_SRAM_SIZE , &error_fatal);
@@ -1714,6 +1718,8 @@ static void musicpal_machine_init(MachineClass *mc) mc->init = musicpal_init; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_size =MP_RAM_DEFAULT_SIZE ; + mc->default_ram_id ="musicpal.ram" ; }DEFINE_MACHINE ("musicpal" , musicpal_machine_init)
Signature · 1 line
2.7.4
PATCH v2 25/86 arm:nseries: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/nseries.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)
hw/arm/nseries.c +18 -13
@@ -47,7 +47,6 @@/* Nokia N8x0 support */ struct n800_s { -MemoryRegion sdram;struct omap_mpu_state_s *mpu;struct rfbi_chip_s blizzard;
@@ -1311,13 +1310,18 @@ static void n8x0_init(MachineState *machine, struct arm_boot_info *binfo, int model) {struct n800_s *s = (struct n800_s *)g_malloc0 (sizeof (*s)); -uint64_t sdram_size = binfo->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine); -memory_region_allocate_system_memory (&s->sdram,NULL ,"omap2.dram" , - sdram_size); -memory_region_add_subregion (get_system_memory (),OMAP2_Q2_BASE , &s->sdram); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } + +memory_region_add_subregion (get_system_memory (),OMAP2_Q2_BASE , + machine->ram); - s->mpu =omap2420_mpu_init (&s->sdram, machine->cpu_type); + s->mpu =omap2420_mpu_init (machine->ram, machine->cpu_type);/* Setup peripherals *
@@ -1383,9 +1387,8 @@ static void n8x0_init(MachineState *machine,* * The code above is for loading the `zImage' file from Nokia * images. */ -load_image_targphys (option_rom[0 ].name, -OMAP2_Q2_BASE +0x400000 , - sdram_size -0x400000 ); +load_image_targphys (option_rom[0 ].name,OMAP2_Q2_BASE +0x400000 , + machine->ram_size -0x400000 );n800_setup_nolo_tags (nolo_tags);cpu_physical_memory_write (OMAP2_SRAM_BASE , nolo_tags,0x10000 );
@@ -1395,16 +1398,12 @@ static void n8x0_init(MachineState *machine,static struct arm_boot_info n800_binfo = { .loader_start =OMAP2_Q2_BASE , -/* Actually two chips of 0x4000000 bytes each */ - .ram_size =0x08000000 , .board_id =0x4f7 , .atag_board = n800_atag_setup, };static struct arm_boot_info n810_binfo = { .loader_start =OMAP2_Q2_BASE , -/* Actually two chips of 0x4000000 bytes each */ - .ram_size =0x08000000 ,/* 0x60c and 0x6bf (WiMAX Edition) have been assigned but are not * used by some older versions of the bootloader and 5555 is used * instead (including versions that shipped with many devices). */
@@ -1431,6 +1430,9 @@ static void n800_class_init(ObjectClass *oc, void *data) mc->default_boot_order ="" ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm1136-r2" ); +/* Actually two chips of 0x4000000 bytes each */ + mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="omap2.dram" ; }static const TypeInfo n800_type = {
@@ -1448,6 +1450,9 @@ static void n810_class_init(ObjectClass *oc, void *data) mc->default_boot_order ="" ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm1136-r2" ); +/* Actually two chips of 0x4000000 bytes each */ + mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="omap2.dram" ; }static const TypeInfo n810_type = {
Signature · 1 line
2.7.4
PATCH v2 26/86 arm:omap_sx1: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/omap_sx1.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
hw/arm/omap_sx1.c +13 -5
@@ -102,8 +102,8 @@ static struct arm_boot_info sx1_binfo = {static void sx1_init (MachineState *machine,const int version) {struct omap_mpu_state_s *mpu; +MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *address_space =get_system_memory (); -MemoryRegion *dram =g_new (MemoryRegion,1 );MemoryRegion *flash =g_new (MemoryRegion,1 );MemoryRegion *cs =g_new (MemoryRegion,4 );static uint32_t cs0val =0x00213090 ;
@@ -115,15 +115,19 @@ static void sx1_init(MachineState *machine, const int version)uint32_t flash_size = flash0_size;int be; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +if (version ==2 ) { flash_size = flash2_size; } -memory_region_allocate_system_memory (dram,NULL ,"omap1.dram" , - sx1_binfo.ram_size); -memory_region_add_subregion (address_space,OMAP_EMIFF_BASE , dram); +memory_region_add_subregion (address_space,OMAP_EMIFF_BASE , machine->ram); - mpu =omap310_mpu_init (dram, machine->cpu_type); + mpu =omap310_mpu_init (machine->ram, machine->cpu_type);/* External Flash (EMIFS) */ memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
@@ -223,6 +227,8 @@ static void sx1_machine_v2_class_init(ObjectClass *oc, void *data) mc->init = sx1_init_v2; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("ti925t" ); + mc->default_ram_size = sdram_size; + mc->default_ram_id ="omap1.dram" ; }static const TypeInfo sx1_machine_v2_type = {
@@ -239,6 +245,8 @@ static void sx1_machine_v1_class_init(ObjectClass *oc, void *data) mc->init = sx1_init_v1; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("ti925t" ); + mc->default_ram_size = sdram_size; + mc->default_ram_id ="omap1.dram" ; }static const TypeInfo sx1_machine_v1_type = {
Signature · 1 line
2.7.4
PATCH v2 27/86 arm:palm: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/arm/palm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
hw/arm/palm.c +12 -6
@@ -181,7 +181,6 @@ static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)static struct arm_boot_info palmte_binfo = { .loader_start =OMAP_EMIFF_BASE , - .ram_size =0x02000000 , .board_id =0x331 , };
@@ -195,15 +194,20 @@ static void palmte_init(MachineState *machine)static uint32_t cs2val =0x0000e1a0 ;static uint32_t cs3val =0xe1a0e1a0 ;int rom_size, rom_loaded =0 ; -MemoryRegion *dram =g_new (MemoryRegion,1 ); +MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *flash =g_new (MemoryRegion,1 );MemoryRegion *cs =g_new (MemoryRegion,4 ); -memory_region_allocate_system_memory (dram,NULL ,"omap1.dram" , - palmte_binfo.ram_size); -memory_region_add_subregion (address_space_mem,OMAP_EMIFF_BASE , dram); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } + +memory_region_add_subregion (address_space_mem,OMAP_EMIFF_BASE , + machine->ram); - mpu =omap310_mpu_init (dram, machine->cpu_type); + mpu =omap310_mpu_init (machine->ram, machine->cpu_type);/* External Flash (EMIFS) */ memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
@@ -265,6 +269,8 @@ static void palmte_machine_init(MachineClass *mc) mc->init = palmte_init; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("ti925t" ); + mc->default_ram_size =0x02000000 ; + mc->default_ram_id ="omap1.dram" ; }DEFINE_MACHINE ("cheetah" , palmte_machine_init)
Signature · 1 line
2.7.4
PATCH v2 28/86 arm:raspi: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
remove no longer needed RasPiState
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/raspi.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
hw/arm/raspi.c +13 -21
@@ -32,11 +32,6 @@/* Table of Linux board IDs for different Pi versions */ static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 }; -typedef struct RasPiState { -BCM283XState soc; -MemoryRegion ram; -}RasPiState ; -static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {
@@ -166,7 +161,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi_init (MachineState *machine,int version) { -RasPiState *s =g_new0 (RasPiState,1 ); +Object *soc;uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;
@@ -179,30 +174,26 @@ static void raspi_init(MachineState *machine, int version)exit (1 ); } -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), - version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 , - &error_abort,NULL ); + soc =object_new (version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 ); +object_property_add_child (OBJECT (machine),"soc" , soc, &error_fatal); -/* Allocate and map RAM */ -memory_region_allocate_system_memory (&s->ram,OBJECT (machine),"ram" , - machine->ram_size);/* FIXME: Remove when we have custom CPU address space support */ -memory_region_add_subregion_overlap (get_system_memory (),0 , &s->ram,0 ); +memory_region_add_subregion_overlap (get_system_memory (),0 , + machine->ram,0 );/* Setup the SOC */ -object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), +object_property_add_const_link (soc,"ram" ,OBJECT (machine->ram), &error_abort); -object_property_set_int (OBJECT (&s->soc), machine->smp.cpus,"enabled-cpus" , +object_property_set_int (soc, machine->smp.cpus,"enabled-cpus" , &error_abort);int board_rev = version ==3 ?0xa02082 :0xa21041 ; -object_property_set_int (OBJECT (&s->soc), board_rev,"board-rev" , - &error_abort); -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_abort); +object_property_set_int (soc, board_rev,"board-rev" , &error_abort); +object_property_set_bool (soc, true,"realized" , &error_abort);/* Create and plug in the SD cards */ di =drive_get_next (IF_SD ); blk = di ?blk_by_legacy_dinfo (di) :NULL ; - bus =qdev_get_child_bus (DEVICE (&s->soc),"sd-bus" ); + bus =qdev_get_child_bus (DEVICE (soc),"sd-bus" );if (bus ==NULL ) {error_report ("No SD bus found in SOC object" );exit (1 );
@@ -211,8 +202,7 @@ static void raspi_init(MachineState *machine, int version)qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal);object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); - vcram_size =object_property_get_uint (OBJECT (&s->soc),"vcram-size" , - &error_abort); + vcram_size =object_property_get_uint (soc,"vcram-size" , &error_abort);setup_boot (machine, version, machine->ram_size - vcram_size); }
@@ -233,6 +223,7 @@ static void raspi2_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="ram" ; mc->ignore_memory_transaction_failures = true; };DEFINE_MACHINE ("raspi2" , raspi2_machine_init)
@@ -255,6 +246,7 @@ static void raspi3_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="ram" ; } DEFINE_MACHINE("raspi3", raspi3_machine_init)#endif
Signature · 1 line
2.7.4
Re: [PATCH v2 28/86] arm:raspi: use memdev for RAM
Quoted 106 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.PS:
remove no longer needed RasPiStateSigned-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/raspi.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)hw/arm/raspi.c +12
-21@@ -32,11 +32,6 @@/* Table of Linux board IDs for different Pi versions */ static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 }; -typedef struct RasPiState { -BCM283XState soc; -MemoryRegion ram; -}RasPiState ; -static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {@@ -166,7 +161,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi_init (MachineState *machine,int version) { -RasPiState *s =g_new0 (RasPiState,1 ); +Object *soc;uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;@@ -179,30 +174,26 @@ static void raspi_init(MachineState *machine, int version)exit (1 ); } -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), - version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 , - &error_abort,NULL ); + soc =object_new (version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 ); +object_property_add_child (OBJECT (machine),"soc" , soc, &error_fatal); -/* Allocate and map RAM */ -memory_region_allocate_system_memory (&s->ram,OBJECT (machine),"ram" , - machine->ram_size);/* FIXME: Remove when we have custom CPU address space support */ -memory_region_add_subregion_overlap (get_system_memory (),0 , &s->ram,0 ); +memory_region_add_subregion_overlap (get_system_memory (),0 , + machine->ram,0 );/* Setup the SOC */ -object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), +object_property_add_const_link (soc,"ram" ,OBJECT (machine->ram), &error_abort); -object_property_set_int (OBJECT (&s->soc), machine->smp.cpus,"enabled-cpus" , +object_property_set_int (soc, machine->smp.cpus,"enabled-cpus" , &error_abort);int board_rev = version ==3 ?0xa02082 :0xa21041 ; -object_property_set_int (OBJECT (&s->soc), board_rev,"board-rev" , - &error_abort); -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_abort); +object_property_set_int (soc, board_rev,"board-rev" , &error_abort); +object_property_set_bool (soc, true,"realized" , &error_abort);/* Create and plug in the SD cards */ di =drive_get_next (IF_SD ); blk = di ?blk_by_legacy_dinfo (di) :NULL ; - bus =qdev_get_child_bus (DEVICE (&s->soc),"sd-bus" ); + bus =qdev_get_child_bus (DEVICE (soc),"sd-bus" );if (bus ==NULL ) {error_report ("No SD bus found in SOC object" );exit (1 );@@ -211,8 +202,7 @@ static void raspi_init(MachineState *machine, int version)qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal);object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); - vcram_size =object_property_get_uint (OBJECT (&s->soc),"vcram-size" , - &error_abort); + vcram_size =object_property_get_uint (soc,"vcram-size" , &error_abort);setup_boot (machine, version, machine->ram_size - vcram_size); }@@ -233,6 +223,7 @@ static void raspi2_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="ram" ; mc->ignore_memory_transaction_failures = true; };DEFINE_MACHINE ("raspi2" , raspi2_machine_init)
hw/arm/raspi.c static void raspi3_machine_init(MachineClass *mc) · line 252
Quoted 7 lines
hw/arm/raspi.c +1
-0@@ -255,6 +246,7 @@ static void raspi3_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="ram" ; } DEFINE_MACHINE("raspi3", raspi3_machine_init)#endif
This patch diverges a lot from my current work:
https://www.mail-archive.com/[email protected]/msg653818.html
So I'm not very happy about it. Maybe my bad I should ping more aggressively my patches. I can respin mine preparing for your series on top.
Meanwhile if you are in a hurry I tested yours, so:
Re: [PATCH v2 28/86] arm:raspi: use memdev for RAM
Quoted 109 lines · On Wed, 15 Jan 2020 20:07:34 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 108 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.PS:
remove no longer needed RasPiStateSigned-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/raspi.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)hw/arm/raspi.c +12
-21@@ -32,11 +32,6 @@/* Table of Linux board IDs for different Pi versions */ static const int raspi_boardid[] = {[1 ] =0xc42 , [2 ] =0xc43 , [3 ] =0xc44 }; -typedef struct RasPiState { -BCM283XState soc; -MemoryRegion ram; -}RasPiState ; -static void write_smpboot (ARMCPU *cpu,const struct arm_boot_info *info) {static const uint32_t smpboot[] = {@@ -166,7 +161,7 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size)static void raspi_init (MachineState *machine,int version) { -RasPiState *s =g_new0 (RasPiState,1 ); +Object *soc;uint32_t vcram_size;DriveInfo *di;BlockBackend *blk;@@ -179,30 +174,26 @@ static void raspi_init(MachineState *machine, int version)exit (1 ); } -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), - version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 , - &error_abort,NULL ); + soc =object_new (version ==3 ?TYPE_BCM2837 :TYPE_BCM2836 ); +object_property_add_child (OBJECT (machine),"soc" , soc, &error_fatal); -/* Allocate and map RAM */ -memory_region_allocate_system_memory (&s->ram,OBJECT (machine),"ram" , - machine->ram_size);/* FIXME: Remove when we have custom CPU address space support */ -memory_region_add_subregion_overlap (get_system_memory (),0 , &s->ram,0 ); +memory_region_add_subregion_overlap (get_system_memory (),0 , + machine->ram,0 );/* Setup the SOC */ -object_property_add_const_link (OBJECT (&s->soc),"ram" ,OBJECT (&s->ram), +object_property_add_const_link (soc,"ram" ,OBJECT (machine->ram), &error_abort); -object_property_set_int (OBJECT (&s->soc), machine->smp.cpus,"enabled-cpus" , +object_property_set_int (soc, machine->smp.cpus,"enabled-cpus" , &error_abort);int board_rev = version ==3 ?0xa02082 :0xa21041 ; -object_property_set_int (OBJECT (&s->soc), board_rev,"board-rev" , - &error_abort); -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &error_abort); +object_property_set_int (soc, board_rev,"board-rev" , &error_abort); +object_property_set_bool (soc, true,"realized" , &error_abort);/* Create and plug in the SD cards */ di =drive_get_next (IF_SD ); blk = di ?blk_by_legacy_dinfo (di) :NULL ; - bus =qdev_get_child_bus (DEVICE (&s->soc),"sd-bus" ); + bus =qdev_get_child_bus (DEVICE (soc),"sd-bus" );if (bus ==NULL ) {error_report ("No SD bus found in SOC object" );exit (1 );@@ -211,8 +202,7 @@ static void raspi_init(MachineState *machine, int version)qdev_prop_set_drive (carddev,"drive" , blk, &error_fatal);object_property_set_bool (OBJECT (carddev), true,"realized" , &error_fatal); - vcram_size =object_property_get_uint (OBJECT (&s->soc),"vcram-size" , - &error_abort); + vcram_size =object_property_get_uint (soc,"vcram-size" , &error_abort);setup_boot (machine, version, machine->ram_size - vcram_size); }@@ -233,6 +223,7 @@ static void raspi2_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="ram" ; mc->ignore_memory_transaction_failures = true; };DEFINE_MACHINE ("raspi2" , raspi2_machine_init)@@ -255,6 +246,7 @@ static void raspi3_machine_init(MachineClass *mc) mc->min_cpus =BCM283X_NCPUS ; mc->default_cpus =BCM283X_NCPUS ; mc->default_ram_size =1 * GiB;
Quoted 8 lines
hw/arm/raspi.c static void raspi3_machine_init(MachineClass *mc) · line 252
Quoted 5 lines
hw/arm/raspi.c +1
-0+ mc->default_ram_id ="ram" ; } DEFINE_MACHINE("raspi3", raspi3_machine_init)#endif This patch diverges a lot from my current work:
https://www.mail-archive.com/[email protected]/msg653818.html
perhaps we could generalize size checks on top of that. there were some ideas in that direction in
"[PATCH v2 66/86] ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup"
thread
Quoted 2 lines
So I'm not very happy about it. Maybe my bad I should ping more aggressively my patches. I can respin mine preparing for your series on top.
this patch is trivial,
if your patches merged before this, than I'll just rebase.
Quoted 6 lines
Meanwhile if you are in a hurry I tested yours, so:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
PATCH v2 29/86 arm:sabrelite: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
remove no longer needed IMX6Sabrelite
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/sabrelite.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
hw/arm/sabrelite.c +8 -15
@@ -19,11 +19,6 @@#include "qemu/error-report.h" #include "sysemu/qtest.h" -typedef struct IMX6Sabrelite { -FslIMX6State soc; -MemoryRegion ram; -}IMX6Sabrelite ; -static struct arm_boot_info sabrelite_binfo = {/* DDR memory start */ .loader_start =FSL_IMX6_MMDC_ADDR ,
@@ -45,7 +40,7 @@ static void sabrelite_reset_secondary(ARMCPU *cpu,static void sabrelite_init (MachineState *machine) { -IMX6Sabrelite *s =g_new0 (IMX6Sabrelite,1 ); +FslIMX6State *s;Error *err =NULL ;/* Check the amount of memory is compatible with the SOC */
@@ -55,19 +50,16 @@ static void sabrelite_init(MachineState *machine)exit (1 ); } -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc), -TYPE_FSL_IMX6 , &error_abort,NULL ); - -object_property_set_bool (OBJECT (&s->soc), true,"realized" , &err); + s =FSL_IMX6 (object_new (TYPE_FSL_IMX6 )); +object_property_add_child (OBJECT (machine),"soc" ,OBJECT (s), &error_fatal); +object_property_set_bool (OBJECT (s), true,"realized" , &err);if (err !=NULL ) {error_report ("%s" ,error_get_pretty (err));exit (1 ); } -memory_region_allocate_system_memory (&s->ram,NULL ,"sabrelite.ram" , - machine->ram_size);memory_region_add_subregion (get_system_memory (),FSL_IMX6_MMDC_ADDR , - &s->ram); + machine->ram); {/*
@@ -78,7 +70,7 @@ static void sabrelite_init(MachineState *machine)/* Add the sst25vf016b NOR FLASH memory to first SPI */ Object *spi_dev; - spi_dev =object_resolve_path_component (OBJECT (&s->soc),"spi1" ); + spi_dev =object_resolve_path_component (OBJECT (s),"spi1" );if (spi_dev) {SSIBus *spi_bus;
@@ -109,7 +101,7 @@ static void sabrelite_init(MachineState *machine) sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary;if (!qtest_enabled ()) { -arm_load_kernel (&s->soc.cpu[0 ], machine, &sabrelite_binfo); +arm_load_kernel (&s->cpu[0 ], machine, &sabrelite_binfo); } }
@@ -119,6 +111,7 @@ static void sabrelite_machine_init(MachineClass *mc) mc->init = sabrelite_init; mc->max_cpus =FSL_IMX6_NUM_CPUS ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="sabrelite.ram" ; }DEFINE_MACHINE ("sabrelite" , sabrelite_machine_init)
Signature · 1 line
2.7.4
PATCH v2 30/86 arm:sbsa-ref: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/sbsa-ref.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/sbsa-ref.c +3 -4
@@ -593,7 +593,6 @@ static void sbsa_ref_init(MachineState *machine)MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *sysmem =get_system_memory ();MemoryRegion *secure_sysmem =g_new (MemoryRegion,1 ); -MemoryRegion *ram =g_new (MemoryRegion,1 );bool firmware_loaded;const CPUArchIdList *possible_cpus;int n, sbsa_max_cpus;
@@ -685,9 +684,8 @@ static void sbsa_ref_init(MachineState *machine)object_unref (cpuobj); } -memory_region_allocate_system_memory (ram,NULL ,"sbsa-ref.ram" , - machine->ram_size); -memory_region_add_subregion (sysmem, sbsa_ref_memmap[SBSA_MEM ].base, ram); +memory_region_add_subregion (sysmem, sbsa_ref_memmap[SBSA_MEM ].base, + machine->ram);create_fdt (sms);
@@ -785,6 +783,7 @@ static void sbsa_ref_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_IDE ; mc->no_cdrom =1 ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="sbsa-ref.ram" ; mc->default_cpus =4 ; mc->possible_cpu_arch_ids = sbsa_ref_possible_cpu_arch_ids; mc->cpu_index_to_instance_props = sbsa_ref_cpu_index_to_props;
Signature · 1 line
2.7.4
Re: [PATCH v2 30/86] arm:sbsa-ref: use memdev for RAM
Quoted 44 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/sbsa-ref.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/sbsa-ref.c +2
-4@@ -593,7 +593,6 @@ static void sbsa_ref_init(MachineState *machine)MachineClass *mc =MACHINE_GET_CLASS (machine);MemoryRegion *sysmem =get_system_memory ();MemoryRegion *secure_sysmem =g_new (MemoryRegion,1 ); -MemoryRegion *ram =g_new (MemoryRegion,1 );bool firmware_loaded;const CPUArchIdList *possible_cpus;int n, sbsa_max_cpus;@@ -685,9 +684,8 @@ static void sbsa_ref_init(MachineState *machine)object_unref (cpuobj); } -memory_region_allocate_system_memory (ram,NULL ,"sbsa-ref.ram" , - machine->ram_size); -memory_region_add_subregion (sysmem, sbsa_ref_memmap[SBSA_MEM ].base, ram); +memory_region_add_subregion (sysmem, sbsa_ref_memmap[SBSA_MEM ].base, + machine->ram);create_fdt (sms);
hw/arm/sbsa-ref.c static void sbsa_ref_class_init(ObjectClass *oc, void *data) · line 789
Quoted 7 lines
hw/arm/sbsa-ref.c +1
-0@@ -785,6 +783,7 @@ static void sbsa_ref_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_IDE ; mc->no_cdrom =1 ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="sbsa-ref.ram" ; mc->default_cpus =4 ; mc->possible_cpu_arch_ids = sbsa_ref_possible_cpu_arch_ids; mc->cpu_index_to_instance_props = sbsa_ref_cpu_index_to_props;
PATCH v2 31/86 arm:versatilepb: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
--- hw/arm/versatilepb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/versatilepb.c +3 -4
@@ -184,7 +184,6 @@ static void versatile_init(MachineState *machine, int board_id)Object *cpuobj;ARMCPU *cpu;MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );qemu_irq pic[32 ];qemu_irq sic[32 ];DeviceState *dev, *sysctl;
@@ -220,11 +219,9 @@ static void versatile_init(MachineState *machine, int board_id) cpu =ARM_CPU (cpuobj); -memory_region_allocate_system_memory (ram,NULL ,"versatile.ram" , - machine->ram_size);/* ??? RAM should repeat to fill physical memory space. */ /* SDRAM at address zero. */ -memory_region_add_subregion (sysmem,0 , ram); +memory_region_add_subregion (sysmem,0 , machine->ram); sysctl =qdev_create (NULL ,"realview_sysctl" );qdev_prop_set_uint32 (sysctl,"sys_id" ,0x41007004 );
@@ -398,6 +395,7 @@ static void versatilepb_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_SCSI ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_id ="versatile.ram" ; }static const TypeInfo versatilepb_type = {
@@ -415,6 +413,7 @@ static void versatileab_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_SCSI ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_id ="versatile.ram" ; }static const TypeInfo versatileab_type = {
Signature · 1 line
2.7.4
Re: [PATCH v2 31/86] arm:versatilepb: use memdev for RAM
Quoted 51 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]--- hw/arm/versatilepb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/versatilepb.c +2
-4@@ -184,7 +184,6 @@ static void versatile_init(MachineState *machine, int board_id)Object *cpuobj;ARMCPU *cpu;MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );qemu_irq pic[32 ];qemu_irq sic[32 ];DeviceState *dev, *sysctl;@@ -220,11 +219,9 @@ static void versatile_init(MachineState *machine, int board_id) cpu =ARM_CPU (cpuobj); -memory_region_allocate_system_memory (ram,NULL ,"versatile.ram" , - machine->ram_size);/* ??? RAM should repeat to fill physical memory space. */ /* SDRAM at address zero. */ -memory_region_add_subregion (sysmem,0 , ram); +memory_region_add_subregion (sysmem,0 , machine->ram); sysctl =qdev_create (NULL ,"realview_sysctl" );qdev_prop_set_uint32 (sysctl,"sys_id" ,0x41007004 );@@ -398,6 +395,7 @@ static void versatilepb_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_SCSI ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_id ="versatile.ram" ; }static const TypeInfo versatilepb_type = {
hw/arm/versatilepb.c static void versatileab_class_init(ObjectClass *oc, void *data) · line 419
Quoted 7 lines
hw/arm/versatilepb.c +1
-0@@ -415,6 +413,7 @@ static void versatileab_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_SCSI ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("arm926" ); + mc->default_ram_id ="versatile.ram" ; }static const TypeInfo versatileab_type = {
PATCH v2 32/86 arm:vexpress: use memdev for RAM
In reply to Igor Mammedovreplace 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.
---
CC: [email protected]
CC: [email protected]
--- hw/arm/vexpress.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
hw/arm/vexpress.c +5 -9
@@ -273,7 +273,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms, {MachineState *machine =MACHINE (vms);MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *lowram =g_new (MemoryRegion,1 );ram_addr_t low_ram_size;
@@ -283,8 +282,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,exit (1 ); } -memory_region_allocate_system_memory (ram,NULL ,"vexpress.highmem" , - ram_size); low_ram_size = ram_size;if (low_ram_size >0x4000000 ) { low_ram_size =0x4000000 ;
@@ -293,9 +290,10 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,* address space should in theory be remappable to various * things including ROM or RAM; we always map the RAM there. */ -memory_region_init_alias (lowram,NULL ,"vexpress.lowmem" , ram,0 , low_ram_size); +memory_region_init_alias (lowram,NULL ,"vexpress.lowmem" , machine->ram, +0 , low_ram_size);memory_region_add_subregion (sysmem,0x0 , lowram); -memory_region_add_subregion (sysmem,0x60000000 , ram); +memory_region_add_subregion (sysmem,0x60000000 , machine->ram);/* 0x1e000000 A9MPCore (SCU) private memory region */ init_cpus(machine, cpu_type, TYPE_A9MPCORE_PRIV, 0x1e000000, pic,
@@ -360,7 +358,6 @@ static void a15_daughterboard_init(const VexpressMachineState *vms, {MachineState *machine =MACHINE (vms);MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *sram =g_new (MemoryRegion,1 ); {
@@ -375,10 +372,8 @@ static void a15_daughterboard_init(const VexpressMachineState *vms, } } -memory_region_allocate_system_memory (ram,NULL ,"vexpress.highmem" , - ram_size);/* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */ -memory_region_add_subregion (sysmem,0x80000000 , ram); +memory_region_add_subregion (sysmem,0x80000000 , machine->ram);/* 0x2c000000 A15MPCore private memory region (GIC) */ init_cpus(machine, cpu_type, TYPE_A15MPCORE_PRIV,
@@ -795,6 +790,7 @@ static void vexpress_class_init(ObjectClass *oc, void *data) mc->init = vexpress_common_init; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="vexpress.highmem" ; }static void vexpress_a9_class_init (ObjectClass *oc,void *data)
Signature · 1 line
2.7.4
Re: [PATCH v2 32/86] arm:vexpress: use memdev for RAM
Quoted 71 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]--- hw/arm/vexpress.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)hw/arm/vexpress.c +4
-9@@ -273,7 +273,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms, {MachineState *machine =MACHINE (vms);MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *lowram =g_new (MemoryRegion,1 );ram_addr_t low_ram_size;@@ -283,8 +282,6 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,exit (1 ); } -memory_region_allocate_system_memory (ram,NULL ,"vexpress.highmem" , - ram_size); low_ram_size = ram_size;if (low_ram_size >0x4000000 ) { low_ram_size =0x4000000 ;@@ -293,9 +290,10 @@ static void a9_daughterboard_init(const VexpressMachineState *vms,* address space should in theory be remappable to various * things including ROM or RAM; we always map the RAM there. */ -memory_region_init_alias (lowram,NULL ,"vexpress.lowmem" , ram,0 , low_ram_size); +memory_region_init_alias (lowram,NULL ,"vexpress.lowmem" , machine->ram, +0 , low_ram_size);memory_region_add_subregion (sysmem,0x0 , lowram); -memory_region_add_subregion (sysmem,0x60000000 , ram); +memory_region_add_subregion (sysmem,0x60000000 , machine->ram);/* 0x1e000000 A9MPCore (SCU) private memory region */ init_cpus(machine, cpu_type, TYPE_A9MPCORE_PRIV, 0x1e000000, pic,@@ -360,7 +358,6 @@ static void a15_daughterboard_init(const VexpressMachineState *vms, {MachineState *machine =MACHINE (vms);MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *sram =g_new (MemoryRegion,1 ); {@@ -375,10 +372,8 @@ static void a15_daughterboard_init(const VexpressMachineState *vms, } } -memory_region_allocate_system_memory (ram,NULL ,"vexpress.highmem" , - ram_size);/* RAM is from 0x80000000 upwards; there is no low-memory alias for it. */ -memory_region_add_subregion (sysmem,0x80000000 , ram); +memory_region_add_subregion (sysmem,0x80000000 , machine->ram);/* 0x2c000000 A15MPCore private memory region (GIC) */ init_cpus(machine, cpu_type, TYPE_A15MPCORE_PRIV,
hw/arm/vexpress.c static void vexpress_class_init(ObjectClass *oc, void *data) · line 796
Quoted 7 lines
hw/arm/vexpress.c +1
-0@@ -795,6 +790,7 @@ static void vexpress_class_init(ObjectClass *oc, void *data) mc->init = vexpress_common_init; mc->max_cpus =4 ; mc->ignore_memory_transaction_failures = true; + mc->default_ram_id ="vexpress.highmem" ; }static void vexpress_a9_class_init (ObjectClass *oc,void *data)
PATCH v2 33/86 arm:virt: use memdev for RAM
In reply to Igor Mammedovmemory_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 then map memory region provided by
MachineState::ram_memdev
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/virt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/arm/virt.c +3 -4
@@ -1512,7 +1512,6 @@ static void machvirt_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();MemoryRegion *secure_sysmem =NULL ;int n, virt_max_cpus; -MemoryRegion *ram =g_new (MemoryRegion,1 );bool firmware_loaded;bool aarch64 = true;bool has_ged = !vmc->no_ged;
@@ -1701,9 +1700,8 @@ static void machvirt_init(MachineState *machine) } } -memory_region_allocate_system_memory (ram,NULL ,"mach-virt.ram" , - machine->ram_size); -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, ram); +memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, + machine->ram);if (machine->device_memory) {memory_region_add_subregion (sysmem, machine->device_memory->base, &machine->device_memory->mr);
@@ -2053,6 +2051,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->unplug_request = virt_machine_device_unplug_request_cb; mc->numa_mem_supported = true; mc->auto_enable_numa_with_memhp = true; + mc->default_ram_id ="mach-virt.ram" ; }static void virt_instance_init (Object *obj)
Signature · 1 line
2.7.4
Re: [PATCH v2 33/86] arm:virt: use memdev for RAM
Quoted 43 lines · Igor Mammedov
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 then map memory region provided by
MachineState::ram_memdevSigned-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/virt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/arm/virt.c +2
-4@@ -1512,7 +1512,6 @@ static void machvirt_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();MemoryRegion *secure_sysmem =NULL ;int n, virt_max_cpus; -MemoryRegion *ram =g_new (MemoryRegion,1 );bool firmware_loaded;bool aarch64 = true;bool has_ged = !vmc->no_ged;@@ -1701,9 +1700,8 @@ static void machvirt_init(MachineState *machine) } } -memory_region_allocate_system_memory (ram,NULL ,"mach-virt.ram" , - machine->ram_size); -memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, ram); +memory_region_add_subregion (sysmem, vms->memmap[VIRT_MEM ].base, + machine->ram);if (machine->device_memory) {memory_region_add_subregion (sysmem, machine->device_memory->base, &machine->device_memory->mr);
hw/arm/virt.c static void virt_machine_class_init(ObjectClass *oc, void *data) · line 2057
Quoted 7 lines
hw/arm/virt.c +1
-0@@ -2053,6 +2051,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->unplug_request = virt_machine_device_unplug_request_cb; mc->numa_mem_supported = true; mc->auto_enable_numa_with_memhp = true; + mc->default_ram_id ="mach-virt.ram" ; }static void virt_instance_init (Object *obj)
PATCH v2 34/86 arm:xilinx_zynq: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/xilinx_zynq.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/arm/xilinx_zynq.c +8 -8
@@ -158,7 +158,6 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,static void zynq_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ext_ram =g_new (MemoryRegion,1 );
@@ -168,6 +167,12 @@ static void zynq_init(MachineState *machine)qemu_irq pic[64 ];int n; +/* max 2GB ram */ +if (machine->ram_size >0x80000000 ) { +error_report ("RAM size more than %d is not supported" ,0x80000000 ); +exit (EXIT_FAILURE ); + } + cpu =ARM_CPU (object_new (machine->cpu_type));/* By default A9 CPUs have EL3 enabled. This board does not
@@ -184,14 +189,9 @@ static void zynq_init(MachineState *machine) &error_fatal);object_property_set_bool (OBJECT (cpu), true,"realized" , &error_fatal); -/* max 2GB ram */ -if (ram_size >0x80000000 ) { - ram_size =0x80000000 ; - } -/* DDR remapped to address zero. */ memory_region_allocate_system_memory (ext_ram,NULL ,"zynq.ext_ram" , - ram_size); + machine->ram_size);memory_region_add_subregion (address_space_mem,0 , ext_ram);/* 256K of on-chip memory */
@@ -300,7 +300,7 @@ static void zynq_init(MachineState *machine)sysbus_connect_irq (busdev,0 , pic[40 -IRQ_OFFSET ]);sysbus_mmio_map (busdev,0 ,0xF8007000 ); - zynq_binfo.ram_size = ram_size; + zynq_binfo.ram_size = machine->ram_size; zynq_binfo.nb_cpus =1 ; zynq_binfo.board_id =0xd32 ; zynq_binfo.loader_start =0 ;
Signature · 1 line
2.7.4
Re: [PATCH v2 34/86] arm:xilinx_zynq: drop RAM size fixup
Quoted 10 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
Signed-off-by Igor Mammedov <[email protected]>
Alistair
Quoted 63 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/xilinx_zynq.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)hw/arm/xilinx_zynq.c +8
-9@@ -158,7 +158,6 @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,static void zynq_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ext_ram =g_new (MemoryRegion,1 );@@ -168,6 +167,12 @@ static void zynq_init(MachineState *machine)qemu_irq pic[64 ];int n; +/* max 2GB ram */ +if (machine->ram_size >0x80000000 ) { +error_report ("RAM size more than %d is not supported" ,0x80000000 ); +exit (EXIT_FAILURE ); + } + cpu =ARM_CPU (object_new (machine->cpu_type));/* By default A9 CPUs have EL3 enabled. This board does not @@ -184,14 +189,9 @@ static void zynq_init(MachineState *machine) &error_fatal);object_property_set_bool (OBJECT (cpu), true,"realized" , &error_fatal); -/* max 2GB ram */ -if (ram_size >0x80000000 ) { - ram_size =0x80000000 ; - } -/* DDR remapped to address zero. */ memory_region_allocate_system_memory (ext_ram,NULL ,"zynq.ext_ram" , - ram_size); + machine->ram_size);memory_region_add_subregion (address_space_mem,0 , ext_ram);/* 256K of on-chip memory */ @@ -300,7 +300,7 @@ static void zynq_init(MachineState *machine)sysbus_connect_irq (busdev,0 , pic[40 -IRQ_OFFSET ]);sysbus_mmio_map (busdev,0 ,0xF8007000 ); - zynq_binfo.ram_size = ram_size; + zynq_binfo.ram_size = machine->ram_size; zynq_binfo.nb_cpus =1 ; zynq_binfo.board_id =0xd32 ; zynq_binfo.loader_start =0 ; --2.7.4
PATCH v2 35/86 arm:xilinx_zynq: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/xilinx_zynq.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/arm/xilinx_zynq.c +2 -4
@@ -160,7 +160,6 @@ static void zynq_init(MachineState *machine) {ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ext_ram =g_new (MemoryRegion,1 );MemoryRegion *ocm_ram =g_new (MemoryRegion,1 );DeviceState *dev;SysBusDevice *busdev;
@@ -190,9 +189,7 @@ static void zynq_init(MachineState *machine)object_property_set_bool (OBJECT (cpu), true,"realized" , &error_fatal);/* DDR remapped to address zero. */ -memory_region_allocate_system_memory (ext_ram,NULL ,"zynq.ext_ram" , - machine->ram_size); -memory_region_add_subregion (address_space_mem,0 , ext_ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* 256K of on-chip memory */ memory_region_init_ram(ocm_ram, NULL, "zynq.ocm_ram", 256 * KiB,
@@ -318,6 +315,7 @@ static void zynq_machine_init(MachineClass *mc) mc->no_sdcard =1 ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); + mc->default_ram_id ="zynq.ext_ram" ; }DEFINE_MACHINE ("xilinx-zynq-a9" , zynq_machine_init)
Signature · 1 line
2.7.4
Re: [PATCH v2 35/86] arm:xilinx_zynq: use memdev for RAM
Quoted 43 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/xilinx_zynq.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)hw/arm/xilinx_zynq.c +1
-4@@ -160,7 +160,6 @@ static void zynq_init(MachineState *machine) {ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ext_ram =g_new (MemoryRegion,1 );MemoryRegion *ocm_ram =g_new (MemoryRegion,1 );DeviceState *dev;SysBusDevice *busdev;@@ -190,9 +189,7 @@ static void zynq_init(MachineState *machine)object_property_set_bool (OBJECT (cpu), true,"realized" , &error_fatal);/* DDR remapped to address zero. */ -memory_region_allocate_system_memory (ext_ram,NULL ,"zynq.ext_ram" , - machine->ram_size); -memory_region_add_subregion (address_space_mem,0 , ext_ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* 256K of on-chip memory */ memory_region_init_ram(ocm_ram, NULL, "zynq.ocm_ram", 256 * KiB,
hw/arm/xilinx_zynq.c static void zynq_machine_init(MachineClass *mc) · line 321
Quoted 7 lines
hw/arm/xilinx_zynq.c +1
-0@@ -318,6 +315,7 @@ static void zynq_machine_init(MachineClass *mc) mc->no_sdcard =1 ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); + mc->default_ram_id ="zynq.ext_ram" ; }DEFINE_MACHINE ("xilinx-zynq-a9" , zynq_machine_init)
Re: [PATCH v2 35/86] arm:xilinx_zynq: use memdev for RAM
In reply to Igor MammedovQuoted 10 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Alistair
Quoted 44 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/xilinx_zynq.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)hw/arm/xilinx_zynq.c +2
-5@@ -160,7 +160,6 @@ static void zynq_init(MachineState *machine) {ARMCPU *cpu;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ext_ram =g_new (MemoryRegion,1 );MemoryRegion *ocm_ram =g_new (MemoryRegion,1 );DeviceState *dev;SysBusDevice *busdev;@@ -190,9 +189,7 @@ static void zynq_init(MachineState *machine)object_property_set_bool (OBJECT (cpu), true,"realized" , &error_fatal);/* DDR remapped to address zero. */ -memory_region_allocate_system_memory (ext_ram,NULL ,"zynq.ext_ram" , - machine->ram_size); -memory_region_add_subregion (address_space_mem,0 , ext_ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* 256K of on-chip memory */ memory_region_init_ram(ocm_ram, NULL, "zynq.ocm_ram", 256 * KiB,@@ -318,6 +315,7 @@ static void zynq_machine_init(MachineClass *mc) mc->no_sdcard =1 ; mc->ignore_memory_transaction_failures = true; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a9" ); + mc->default_ram_id ="zynq.ext_ram" ; }DEFINE_MACHINE ("xilinx-zynq-a9" , zynq_machine_init) --2.7.4
PATCH v2 36/86 arm:xlnx-versal-virt: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/arm/xlnx-versal-virt.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/arm/xlnx-versal-virt.c +2 -5
@@ -30,7 +30,6 @@ typedef struct VersalVirt {MachineState parent_obj;Versal soc; -MemoryRegion mr_ddr;void *fdt;int fdt_size;
@@ -414,12 +413,9 @@ static void versal_virt_init(MachineState *machine) psci_conduit =QEMU_PSCI_CONDUIT_SMC ; } -memory_region_allocate_system_memory (&s->mr_ddr,NULL ,"ddr" , - machine->ram_size); -sysbus_init_child_obj (OBJECT (machine),"xlnx-ve" , &s->soc,sizeof (s->soc),TYPE_XLNX_VERSAL ); -object_property_set_link (OBJECT (&s->soc),OBJECT (&s->mr_ddr), +object_property_set_link (OBJECT (&s->soc),OBJECT (machine->ram),"ddr" , &error_abort);object_property_set_int (OBJECT (&s->soc), psci_conduit,"psci-conduit" , &error_abort);
@@ -473,6 +469,7 @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) mc->max_cpus =XLNX_VERSAL_NR_ACPUS ; mc->default_cpus =XLNX_VERSAL_NR_ACPUS ; mc->no_cdrom = true; + mc->default_ram_id ="ddr" ; }static const TypeInfo versal_virt_machine_init_typeinfo = {
Signature · 1 line
2.7.4
PATCH v2 37/86 arm:xlnx-zcu102: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/arm/xlnx-zcu102.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/arm/xlnx-zcu102.c +2 -5
@@ -28,7 +28,6 @@ typedef struct XlnxZCU102 {MachineState parent_obj;XlnxZynqMPState soc; -MemoryRegion ddr_ram;bool secure;bool virt;
@@ -87,13 +86,10 @@ static void xlnx_zcu102_init(MachineState *machine) ram_size); } -memory_region_allocate_system_memory (&s->ddr_ram,NULL ,"ddr-ram" , - ram_size); -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc),TYPE_XLNX_ZYNQMP , &error_abort,NULL ); -object_property_set_link (OBJECT (&s->soc),OBJECT (&s->ddr_ram), +object_property_set_link (OBJECT (&s->soc),OBJECT (machine->ram),"ddr-ram" , &error_abort);object_property_set_bool (OBJECT (&s->soc), s->secure,"secure" , &error_fatal);
@@ -211,6 +207,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; + mc->default_ram_id ="ddr-ram" ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
Signature · 1 line
2.7.4
Re: [PATCH v2 37/86] arm:xlnx-zcu102: use memdev for RAM
Quoted 47 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/xlnx-zcu102.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/arm/xlnx-zcu102.c +1
-5@@ -28,7 +28,6 @@ typedef struct XlnxZCU102 {MachineState parent_obj;XlnxZynqMPState soc; -MemoryRegion ddr_ram;bool secure;bool virt;@@ -87,13 +86,10 @@ static void xlnx_zcu102_init(MachineState *machine) ram_size); } -memory_region_allocate_system_memory (&s->ddr_ram,NULL ,"ddr-ram" , - ram_size); -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc),TYPE_XLNX_ZYNQMP , &error_abort,NULL ); -object_property_set_link (OBJECT (&s->soc),OBJECT (&s->ddr_ram), +object_property_set_link (OBJECT (&s->soc),OBJECT (machine->ram),"ddr-ram" , &error_abort);object_property_set_bool (OBJECT (&s->soc), s->secure,"secure" , &error_fatal);
hw/arm/xlnx-zcu102.c static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) · line 213
Quoted 7 lines
hw/arm/xlnx-zcu102.c +1
-0@@ -211,6 +207,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; + mc->default_ram_id ="ddr-ram" ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
Re: [PATCH v2 37/86] arm:xlnx-zcu102: use memdev for RAM
In reply to Igor MammedovQuoted 10 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Alistair
Quoted 48 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/arm/xlnx-zcu102.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)hw/arm/xlnx-zcu102.c +2
-6@@ -28,7 +28,6 @@ typedef struct XlnxZCU102 {MachineState parent_obj;XlnxZynqMPState soc; -MemoryRegion ddr_ram;bool secure;bool virt;@@ -87,13 +86,10 @@ static void xlnx_zcu102_init(MachineState *machine) ram_size); } -memory_region_allocate_system_memory (&s->ddr_ram,NULL ,"ddr-ram" , - ram_size); -object_initialize_child (OBJECT (machine),"soc" , &s->soc,sizeof (s->soc),TYPE_XLNX_ZYNQMP , &error_abort,NULL ); -object_property_set_link (OBJECT (&s->soc),OBJECT (&s->ddr_ram), +object_property_set_link (OBJECT (&s->soc),OBJECT (machine->ram),"ddr-ram" , &error_abort);object_property_set_bool (OBJECT (&s->soc), s->secure,"secure" , &error_fatal);@@ -211,6 +207,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; + mc->default_ram_id ="ddr-ram" ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = { --2.7.4
PATCH v2 38/86 s390x:s390-virtio-ccw: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/s390x/s390-virtio-ccw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/s390x/s390-virtio-ccw.c +3 -4
@@ -154,14 +154,12 @@ static void virtio_ccw_register_hcalls(void) virtio_ccw_hcall_early_printk); } -static void s390_memory_init (ram_addr_t mem_size) +static void s390_memory_init (MemoryRegion *ram) {MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );Error *local_err =NULL ;/* allocate RAM for core */ -memory_region_allocate_system_memory (ram,NULL ,"s390.ram" , mem_size);memory_region_add_subregion (sysmem,0 , ram);/*
@@ -245,7 +243,7 @@ static void ccw_init(MachineState *machine)s390_sclp_init ();/* init memory + setup max page size. Required for the CPU model */ -s390_memory_init (machine->ram_size); +s390_memory_init (machine->ram);/* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus (machine);
@@ -471,6 +469,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; nc->nmi_monitor_handler = s390_nmi; + mc->default_ram_id ="s390.ram" ; }static inline bool machine_get_aes_key_wrap (Object *obj,Error **errp)
Signature · 1 line
2.7.4
Re: [PATCH v2 38/86] s390x:s390-virtio-ccw: use memdev for RAM
Quoted 51 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/s390x/s390-virtio-ccw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/s390x/s390-virtio-ccw.c +2
-4@@ -154,14 +154,12 @@ static void virtio_ccw_register_hcalls(void) virtio_ccw_hcall_early_printk); } -static void s390_memory_init (ram_addr_t mem_size) +static void s390_memory_init (MemoryRegion *ram) {MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );Error *local_err =NULL ;/* allocate RAM for core */ -memory_region_allocate_system_memory (ram,NULL ,"s390.ram" , mem_size);memory_region_add_subregion (sysmem,0 , ram);/* @@ -245,7 +243,7 @@ static void ccw_init(MachineState *machine)s390_sclp_init ();/* init memory + setup max page size. Required for the CPU model */ -s390_memory_init (machine->ram_size); +s390_memory_init (machine->ram);/* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus (machine);
hw/s390x/s390-virtio-ccw.c static void ccw_machine_class_init(ObjectClass *oc, void *data) · line 475
Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +1
-0@@ -471,6 +469,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; nc->nmi_monitor_handler = s390_nmi; + mc->default_ram_id ="s390.ram" ; }static inline bool machine_get_aes_key_wrap (Object *obj,Error **errp)
Re: [PATCH v2 38/86] s390x:s390-virtio-ccw: use memdev for RAM
In reply to Igor MammedovQuoted 51 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/s390x/s390-virtio-ccw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)hw/s390x/s390-virtio-ccw.c +2
-4@@ -154,14 +154,12 @@ static void virtio_ccw_register_hcalls(void) virtio_ccw_hcall_early_printk); } -static void s390_memory_init (ram_addr_t mem_size) +static void s390_memory_init (MemoryRegion *ram) {MemoryRegion *sysmem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );Error *local_err =NULL ;/* allocate RAM for core */ -memory_region_allocate_system_memory (ram,NULL ,"s390.ram" , mem_size);memory_region_add_subregion (sysmem,0 , ram);/* @@ -245,7 +243,7 @@ static void ccw_init(MachineState *machine)s390_sclp_init ();/* init memory + setup max page size. Required for the CPU model */ -s390_memory_init (machine->ram_size); +s390_memory_init (machine->ram);/* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus (machine);
hw/s390x/s390-virtio-ccw.c static void ccw_machine_class_init(ObjectClass *oc, void *data) · line 475
Quoted 7 lines
hw/s390x/s390-virtio-ccw.c +1
-0@@ -471,6 +469,7 @@ static void ccw_machine_class_init(ObjectClass *oc, void *data) hc->plug = s390_machine_device_plug; hc->unplug_request = s390_machine_device_unplug_request; nc->nmi_monitor_handler = s390_nmi; + mc->default_ram_id ="s390.ram" ; }static inline bool machine_get_aes_key_wrap (Object *obj,Error **errp)
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 39/86 null-machine: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/core/null-machine.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/core/null-machine.c +3 -5
@@ -32,11 +32,8 @@ static void machine_none_init(MachineState *mch) }/* RAM at address zero */ -if (mch->ram_size) { -MemoryRegion *ram =g_new (MemoryRegion,1 ); - -memory_region_allocate_system_memory (ram,NULL ,"ram" , mch->ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +if (mch->ram) { +memory_region_add_subregion (get_system_memory (),0 , mch->ram); }if (mch->kernel_filename) {
@@ -52,6 +49,7 @@ static void machine_none_machine_init(MachineClass *mc) mc->init = machine_none_init; mc->max_cpus =1 ; mc->default_ram_size =0 ; + mc->default_ram_id ="ram" ; }DEFINE_MACHINE ("none" , machine_none_machine_init)
Signature · 1 line
2.7.4
PATCH v2 40/86 cris:axis_dev88: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
--- hw/cris/axis_dev88.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
hw/cris/axis_dev88.c +2 -6
@@ -249,7 +249,6 @@ static struct cris_load_info li;static void axisdev88_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;CRISCPU *cpu;
@@ -261,16 +260,12 @@ void axisdev88_init(MachineState *machine)struct etraxfs_dma_client *dma_eth;int i;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_ram =g_new (MemoryRegion,1 );MemoryRegion *phys_intmem =g_new (MemoryRegion,1 );/* init CPUs */ cpu =CRIS_CPU (cpu_create (machine->cpu_type)); -/* allocate RAM */ -memory_region_allocate_system_memory (phys_ram,NULL ,"axisdev88.ram" , - ram_size); -memory_region_add_subregion (address_space_mem,0x40000000 , phys_ram); +memory_region_add_subregion (address_space_mem,0x40000000 , machine->ram);/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the internal memory. */
@@ -351,6 +346,7 @@ static void axisdev88_machine_init(MachineClass *mc) mc->init = axisdev88_init; mc->is_default =1 ; mc->default_cpu_type =CRIS_CPU_TYPE_NAME ("crisv32" ); + mc->default_ram_id ="axisdev88.ram" ; }DEFINE_MACHINE ("axis-dev88" , axisdev88_machine_init)
Signature · 1 line
2.7.4
Re: [PATCH v2 40/86] cris:axis_dev88: use memdev for RAM
Quoted 47 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]--- hw/cris/axis_dev88.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)hw/cris/axis_dev88.c +1
-6@@ -249,7 +249,6 @@ static struct cris_load_info li;static void axisdev88_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;CRISCPU *cpu;@@ -261,16 +260,12 @@ void axisdev88_init(MachineState *machine)struct etraxfs_dma_client *dma_eth;int i;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_ram =g_new (MemoryRegion,1 );MemoryRegion *phys_intmem =g_new (MemoryRegion,1 );/* init CPUs */ cpu =CRIS_CPU (cpu_create (machine->cpu_type)); -/* allocate RAM */ -memory_region_allocate_system_memory (phys_ram,NULL ,"axisdev88.ram" , - ram_size); -memory_region_add_subregion (address_space_mem,0x40000000 , phys_ram); +memory_region_add_subregion (address_space_mem,0x40000000 , machine->ram);/* The ETRAX-FS has 128Kb on chip ram, the docs refer to it as the internal memory. */
hw/cris/axis_dev88.c static void axisdev88_machine_init(MachineClass *mc) · line 352
Quoted 7 lines
hw/cris/axis_dev88.c +1
-0@@ -351,6 +346,7 @@ static void axisdev88_machine_init(MachineClass *mc) mc->init = axisdev88_init; mc->is_default =1 ; mc->default_cpu_type =CRIS_CPU_TYPE_NAME ("crisv32" ); + mc->default_ram_id ="axisdev88.ram" ; }DEFINE_MACHINE ("axis-dev88" , axisdev88_machine_init)
PATCH v2 41/86 hw/hppa/machine: Correctly check the firmware is in PDC range
In reply to Igor MammedovFrom: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below FIRMWARE_START, it is incorrect, regardless the RAM size.
--- hw/hppa/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/hppa/machine.c +1 -1
@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)qemu_log_mask (CPU_LOG_PAGE ,"Firmware loaded at 0x%08" PRIx64"-0x%08" PRIx64", entry at 0x%08" PRIx64".\n" , firmware_low, firmware_high, firmware_entry); -if (firmware_low < ram_size || firmware_high >=FIRMWARE_END ) { +if (firmware_low <FIRMWARE_START || firmware_high >=FIRMWARE_END ) {error_report ("Firmware overlaps with memory or IO space" );exit (1 ); }
Signature · 1 line
2.7.4
Re: [PATCH v2 41/86] hw/hppa/machine: Correctly check the firmware is in PDC range
Quoted 19 lines · Igor Mammedov
From: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below
FIRMWARE_START, it is incorrect, regardless the RAM size.Acked-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
hw/hppa/machine.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/hppa/machine.c +0
-0
hw/hppa/machine.c static void machine_hppa_init(MachineState *machine) · line 160
Quoted 7 lines
hw/hppa/machine.c +1
-1@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)qemu_log_mask (CPU_LOG_PAGE ,"Firmware loaded at 0x%08" PRIx64"-0x%08" PRIx64", entry at 0x%08" PRIx64".\n" , firmware_low, firmware_high, firmware_entry); -if (firmware_low < ram_size || firmware_high >=FIRMWARE_END ) { +if (firmware_low <FIRMWARE_START || firmware_high >=FIRMWARE_END ) {error_report ("Firmware overlaps with memory or IO space" );exit (1 );
Should this also be EXIT_FAILURE like in other places when you're changing the line nearby?
Regards,
BALATON Zoltan
Re: [PATCH v2 41/86] hw/hppa/machine: Correctly check the firmware is in PDC range
Quoted 15 lines · BALATON Zoltan
Quoted 14 lines · Igor Mammedov
From: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below
FIRMWARE_START, it is incorrect, regardless the RAM size.Acked-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
hw/hppa/machine.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 5 lines
hw/hppa/machine.c +0
-0@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)Quoted 8 lines
qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
firmware_low,firmware_high,firmware_entry); - if (firmware_low<ram_size||firmware_high>=FIRMWARE_END) { + if (firmware_low<FIRMWARE_START||firmware_high>=FIRMWARE_END) {
error_report("Firmware overlaps with memory or IO space"); exit(1);Should this also be
EXIT_FAILURElike in other places when you're changing the line nearby?
I didn't changed this line, this seems unrelated to the patch purpose.
Re: [PATCH v2 41/86] hw/hppa/machine: Correctly check the firmware is in PDC range
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 15 lines · BALATON Zoltan
Quoted 14 lines · Igor Mammedov
From: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below
FIRMWARE_START, it is incorrect, regardless the RAM size.Acked-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
hw/hppa/machine.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
Quoted 5 lines
hw/hppa/machine.c +0
-0@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)Quoted 7 lines
qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
firmware_low,firmware_high,firmware_entry); - if (firmware_low<ram_size||firmware_high>=FIRMWARE_END) { + if (firmware_low<FIRMWARE_START||firmware_high>=FIRMWARE_END) {error_report("Firmware overlaps with memory or IO space"); exit(1);Should this also be
EXIT_FAILURElike in other places when you're changing the line nearby?
Quoted 1 line
I didn't changed this line, this seems unrelated to the patch purpose.
Fair enough. Just thought because there was patch 85/86 making that change to keep consistency. Maybe you can change this in that patch but I don't really mind just spotted it.
Regards,
BALATON Zoltan
Re: [PATCH v2 41/86] hw/hppa/machine: Correctly check the firmware is in PDC range
Quoted 34 lines · BALATON Zoltan
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 31 lines · BALATON Zoltan
Quoted 20 lines · Igor Mammedov
From: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below
FIRMWARE_START, it is incorrect, regardless the RAM size.Acked-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
hw/hppa/machine.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/hppa/machine.c +0
-0@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)Quoted 8 lines
qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
firmware_low,firmware_high,firmware_entry); - if (firmware_low<ram_size||firmware_high>=FIRMWARE_END) { + if (firmware_low<FIRMWARE_START||firmware_high>=FIRMWARE_END) {
error_report("Firmware overlaps with memory or IO space"); exit(1);Should this also be
EXIT_FAILURElike in other places when you're changing the line nearby?
Quoted 3 lines
Quoted 1 line
I didn't changed this line, this seems unrelated to the patch purpose.
Fair enough. Just thought because there was patch 85/86 making that change to keep consistency. Maybe you can change this in that patch but I don't really mind just spotted it.
Ah this is because it is a patch of mine included in Igor series, and Igor uses EXIT_FAILURE in his other patches, OK now it makes sense.
Maybe the EXIT_FAILURE can be done in a new series, calling 'sed' to update the full repository.
Re: [PATCH v2 41/86] hw/hppa/machine: Correctly check the firmware is in PDC range
Quoted 42 lines · On Thu, 16 Jan 2020 16:14:45 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 35 lines · BALATON Zoltan
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 32 lines · BALATON Zoltan
Quoted 20 lines · Igor Mammedov
From: Philippe Mathieu-Daudé <[email protected]>
The firmware has to reside in the PDC range. If the Elf file expects to load it below
FIRMWARE_START, it is incorrect, regardless the RAM size.Acked-by Helge Deller <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>Signed-off-by Igor Mammedov <[email protected]>---
hw/hppa/machine.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/hppa/machine.c +0
-0@@ -155,7 +155,7 @@ static void machine_hppa_init(MachineState *machine)Quoted 8 lines
qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n",
firmware_low,firmware_high,firmware_entry); - if (firmware_low<ram_size||firmware_high>=FIRMWARE_END) { + if (firmware_low<FIRMWARE_START||firmware_high>=FIRMWARE_END) {
error_report("Firmware overlaps with memory or IO space"); exit(1);Should this also be
EXIT_FAILURElike in other places when you're changing the line nearby?Quoted 5 lines
Quoted 1 line
I didn't changed this line, this seems unrelated to the patch purpose.
Fair enough. Just thought because there was patch 85/86 making that change to keep consistency. Maybe you can change this in that patch but I don't really mind just spotted it.
Quoted 5 lines
Ah this is because it is a patch of mine included in Igor series, and Igor uses
EXIT_FAILUREin his other patches, OK now it makes sense.Maybe the
EXIT_FAILUREcan be done in a new series, calling 'sed' to update the full repository.
I'll fix it up on respin
Quoted 1 line
PATCH v2 42/86 hw/hppa/machine: Restrict the total memory size to 3GB
In reply to Igor MammedovFrom: Philippe Mathieu-Daudé <[email protected]>
The hardware expects DIMM slots of 1 or 2 GB, allowing up to 4 GB of memory. We want to accept the same amount of memory the hardware can deal with. DIMMs of 768MB are not available.
However we have to deal with a firmware limitation: currently SeaBIOS only supports 32-bit, and expects the RAM size in a 32-bit register. When using a 4GB configuration, the 32-bit register get truncated and we report a size of 0MB to SeaBIOS, which ends halting the machine:
$ qemu-system-hppa -m 4g -serial stdio
SeaBIOS: Machine configured with too little memory (0 MB), minimum is 16 MB.
SeaBIOS wants SYSTEM HALT.
The easiest way is to restrict the machine to 3GB of memory.
--- hw/hppa/machine.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/hppa/machine.c +4 -5
@@ -90,12 +90,11 @@ static void machine_hppa_init(MachineState *machine)g_free (name); } -/* Limit main memory. */ -if (ram_size >FIRMWARE_START ) { - machine->ram_size = ram_size =FIRMWARE_START ; - } -/* Main memory region. */ +if (machine->ram_size >3 * GiB) { +error_report ("RAM size is currently restricted to 3GB" ); +exit (EXIT_FAILURE ); + } ram_region =g_new (MemoryRegion,1 );memory_region_allocate_system_memory (ram_region,OBJECT (machine),"ram" , ram_size);
Signature · 1 line
2.7.4
PATCH v2 43/86 hw/hppa/machine: Map the PDC memory region with higher priority
In reply to Igor MammedovFrom: Philippe Mathieu-Daudé <[email protected]>
The region in range [0xf0000000 - 0xf1000000] is the PDC area (Processor Dependent Code), where the firmware is loaded. This region has higher priority than the main memory.
When the machine has more than 3840MB of RAM, there is an overlap. Since the PDC is closer to the CPU in the bus hierarchy, it gets accessed first, and the CPU does not have access to the RAM in this range.
To model the same behavior and keep a simple memory layout, reduce the priority of the RAM region. The PDC region ends overlapping the RAM.
--- hw/hppa/machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/hppa/machine.c +1 -1
@@ -98,7 +98,7 @@ static void machine_hppa_init(MachineState *machine) ram_region =g_new (MemoryRegion,1 );memory_region_allocate_system_memory (ram_region,OBJECT (machine),"ram" , ram_size); -memory_region_add_subregion (addr_space,0 , ram_region); +memory_region_add_subregion_overlap (addr_space,0 , ram_region,-1 );/* Init Dino (PCI host bus chip). */ pci_bus =dino_init (addr_space, &rtc_irq, &serial_irq);
Signature · 1 line
2.7.4
PATCH v2 44/86 hppa: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
--- hw/hppa/machine.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
hw/hppa/machine.c +3 -7
@@ -70,13 +70,10 @@ static void machine_hppa_init(MachineState *machine)uint64_t kernel_entry =0 , kernel_low, kernel_high;MemoryRegion *addr_space =get_system_memory ();MemoryRegion *rom_region; -MemoryRegion *ram_region;MemoryRegion *cpu_region;long i;unsigned int smp_cpus = machine->smp.cpus; - ram_size = machine->ram_size; -/* Create CPUs. */ for (i =0 ; i < smp_cpus; i++) {char *name =g_strdup_printf ("cpu%ld-io-eir" , i);
@@ -95,10 +92,8 @@ static void machine_hppa_init(MachineState *machine)error_report ("RAM size is currently restricted to 3GB" );exit (EXIT_FAILURE ); } - ram_region =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (ram_region,OBJECT (machine), -"ram" , ram_size); -memory_region_add_subregion_overlap (addr_space,0 , ram_region,-1 ); +memory_region_add_subregion_overlap (addr_space,0 , machine->ram,-1 ); +/* Init Dino (PCI host bus chip). */ pci_bus =dino_init (addr_space, &rtc_irq, &serial_irq);
@@ -282,6 +277,7 @@ static void machine_hppa_machine_init(MachineClass *mc) mc->is_default =1 ; mc->default_ram_size =512 * MiB; mc->default_boot_order ="cd" ; + mc->default_ram_id ="ram" ; }DEFINE_MACHINE ("hppa" , machine_hppa_machine_init)
Signature · 1 line
2.7.4
PATCH v2 45/86 x86:microvm: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/i386/microvm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
hw/i386/microvm.c +5 -7
@@ -167,7 +167,7 @@ static void microvm_memory_init(MicrovmMachineState *mms) {MachineState *machine =MACHINE (mms);X86MachineState *x86ms =X86_MACHINE (mms); -MemoryRegion *ram, *ram_below_4g, *ram_above_4g; +MemoryRegion *ram_below_4g, *ram_above_4g;MemoryRegion *system_memory =get_system_memory ();FWCfgState *fw_cfg;ram_addr_t lowmem;
@@ -214,12 +214,8 @@ static void microvm_memory_init(MicrovmMachineState *mms) x86ms->below_4g_mem_size = machine->ram_size; } - ram =g_malloc (sizeof (*ram)); -memory_region_allocate_system_memory (ram,NULL ,"microvm.ram" , - machine->ram_size); - ram_below_4g =g_malloc (sizeof (*ram_below_4g)); -memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , ram, +memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , machine->ram,0 , x86ms->below_4g_mem_size);memory_region_add_subregion (system_memory,0 , ram_below_4g);
@@ -227,7 +223,8 @@ static void microvm_memory_init(MicrovmMachineState *mms)if (x86ms->above_4g_mem_size >0 ) { ram_above_4g =g_malloc (sizeof (*ram_above_4g)); -memory_region_init_alias (ram_above_4g,NULL ,"ram-above-4g" , ram, +memory_region_init_alias (ram_above_4g,NULL ,"ram-above-4g" , + machine->ram, x86ms->below_4g_mem_size, x86ms->above_4g_mem_size); memory_region_add_subregion(system_memory, 0x100000000ULL,
@@ -502,6 +499,7 @@ static void microvm_class_init(ObjectClass *oc, void *data) mc->auto_enable_numa_with_memhp = false; mc->default_cpu_type =TARGET_DEFAULT_CPU_TYPE ; mc->nvdimm_supported = false; + mc->default_ram_id ="microvm.ram" ;/* Avoid relying too much on kernel components */ mc->default_kernel_irqchip_split = true;
Signature · 1 line
2.7.4
PATCH v2 46/86 x86:pc: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/i386/pc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
hw/i386/pc.c +9 -10
@@ -935,7 +935,7 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion **ram_memory) {int linux_boot, i; -MemoryRegion *ram, *option_rom_mr; +MemoryRegion *option_rom_mr;MemoryRegion *ram_below_4g, *ram_above_4g;FWCfgState *fw_cfg;MachineState *machine =MACHINE (pcms);
@@ -948,22 +948,20 @@ void pc_memory_init(PCMachineState *pcms, linux_boot = (machine->kernel_filename !=NULL ); -/* Allocate RAM. We allocate it as a single memory region and use -* aliases to address portions of it, mostly for backwards compatibility -* with older qemus that used qemu_ram_alloc(). +/* +* Split single memory region and use aliases to address portions of it, +* done for backwards compatibility with older qemus. */ - ram =g_malloc (sizeof (*ram)); -memory_region_allocate_system_memory (ram,NULL ,"pc.ram" , - machine->ram_size); - *ram_memory = ram; + *ram_memory = machine->ram; ram_below_4g =g_malloc (sizeof (*ram_below_4g)); -memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , ram, +memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , machine->ram,0 , x86ms->below_4g_mem_size);memory_region_add_subregion (system_memory,0 , ram_below_4g);e820_add_entry (0 , x86ms->below_4g_mem_size,E820_RAM );if (x86ms->above_4g_mem_size >0 ) { ram_above_4g =g_malloc (sizeof (*ram_above_4g)); -memory_region_init_alias (ram_above_4g,NULL ,"ram-above-4g" , ram, +memory_region_init_alias (ram_above_4g,NULL ,"ram-above-4g" , + machine->ram, x86ms->below_4g_mem_size, x86ms->above_4g_mem_size); memory_region_add_subregion(system_memory, 0x100000000ULL,
@@ -1950,6 +1948,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =TARGET_DEFAULT_CPU_TYPE ; mc->nvdimm_supported = true; mc->numa_mem_supported = true; + mc->default_ram_id ="pc.ram" ; object_class_property_add(oc, PC_MACHINE_DEVMEM_REGION_SIZE, "int", pc_machine_get_device_memory_region_size, NULL,
Signature · 1 line
2.7.4
PATCH v2 47/86 lm32:lm32_boards: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/lm32/lm32_boards.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
hw/lm32/lm32_boards.c +23 -13
@@ -75,22 +75,27 @@ static void main_cpu_reset(void *opaque)static void lm32_evr_init (MachineState *machine) { +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;LM32CPU *cpu;CPULM32State *env;DriveInfo *dinfo;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_ram =g_new (MemoryRegion,1 );qemu_irq irq[32 ];ResetInfo *reset_info;int i; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* memory map */ hwaddr flash_base =0x04000000 ;size_t flash_sector_size =256 * KiB;size_t flash_size =32 * MiB;hwaddr ram_base =0x08000000 ; -size_t ram_size =64 * MiB;hwaddr timer0_base =0x80002000 ;hwaddr uart0_base =0x80006000 ;hwaddr timer1_base =0x8000a000 ;
@@ -107,9 +112,7 @@ static void lm32_evr_init(MachineState *machine) reset_info->flash_base = flash_base; -memory_region_allocate_system_memory (phys_ram,NULL ,"lm32_evr.sdram" , - ram_size); -memory_region_add_subregion (address_space_mem, ram_base, phys_ram); +memory_region_add_subregion (address_space_mem, ram_base, machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 );/* Spansion S29NS128P */
@@ -144,7 +147,7 @@ static void lm32_evr_init(MachineState *machine)if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, ram_base, - ram_size); + machine->ram_size); reset_info->bootstrap_pc = ram_base; }
@@ -159,6 +162,7 @@ static void lm32_evr_init(MachineState *machine)static void lm32_uclinux_init (MachineState *machine) { +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -166,18 +170,22 @@ static void lm32_uclinux_init(MachineState *machine)CPULM32State *env;DriveInfo *dinfo;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_ram =g_new (MemoryRegion,1 );qemu_irq irq[32 ];HWSetup *hw;ResetInfo *reset_info;int i; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* memory map */ hwaddr flash_base =0x04000000 ;size_t flash_sector_size =256 * KiB;size_t flash_size =32 * MiB;hwaddr ram_base =0x08000000 ; -size_t ram_size =64 * MiB;hwaddr uart0_base =0x80000000 ;hwaddr timer0_base =0x80002000 ;hwaddr timer1_base =0x80010000 ;
@@ -200,9 +208,7 @@ static void lm32_uclinux_init(MachineState *machine) reset_info->flash_base = flash_base; -memory_region_allocate_system_memory (phys_ram,NULL , -"lm32_uclinux.sdram" , ram_size); -memory_region_add_subregion (address_space_mem, ram_base, phys_ram); +memory_region_add_subregion (address_space_mem, ram_base, machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 );/* Spansion S29NS128P */
@@ -238,7 +244,7 @@ static void lm32_uclinux_init(MachineState *machine)if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, ram_base, - ram_size); + machine->ram_size); reset_info->bootstrap_pc = ram_base; }
@@ -252,7 +258,7 @@ static void lm32_uclinux_init(MachineState *machine) hw =hwsetup_init ();hwsetup_add_cpu (hw,"LM32" ,75000000 );hwsetup_add_flash (hw,"flash" , flash_base, flash_size); -hwsetup_add_ddr_sdram (hw,"ddr_sdram" , ram_base, ram_size); +hwsetup_add_ddr_sdram (hw,"ddr_sdram" , ram_base, machine->ram_size);hwsetup_add_timer (hw,"timer0" , timer0_base, timer0_irq);hwsetup_add_timer (hw,"timer1_dev_only" , timer1_base, timer1_irq);hwsetup_add_timer (hw,"timer2_dev_only" , timer2_base, timer2_irq);
@@ -288,6 +294,8 @@ static void lm32_evr_class_init(ObjectClass *oc, void *data) mc->init = lm32_evr_init; mc->is_default =1 ; mc->default_cpu_type =LM32_CPU_TYPE_NAME ("lm32-full" ); + mc->default_ram_size =64 * MiB; + mc->default_ram_id ="lm32_evr.sdram" ; }static const TypeInfo lm32_evr_type = {
@@ -304,6 +312,8 @@ static void lm32_uclinux_class_init(ObjectClass *oc, void *data) mc->init = lm32_uclinux_init; mc->is_default =0 ; mc->default_cpu_type =LM32_CPU_TYPE_NAME ("lm32-full" ); + mc->default_ram_size =64 * MiB; + mc->default_ram_id ="lm32_uclinux.sdram" ; }static const TypeInfo lm32_uclinux_type = {
Signature · 1 line
2.7.4
PATCH v2 48/86 lm32:milkymist: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/lm32/milkymist.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
hw/lm32/milkymist.c +12 -7
@@ -82,6 +82,7 @@ static void main_cpu_reset(void *opaque)static void milkymist_init (MachineState *machine) { +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -90,22 +91,26 @@ milkymist_init(MachineState *machine)int kernel_size;DriveInfo *dinfo;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_sdram =g_new (MemoryRegion,1 );qemu_irq irq[32 ];int i;char *bios_filename;ResetInfo *reset_info; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* memory map */ hwaddr flash_base =0x00000000 ;size_t flash_sector_size =128 * KiB;size_t flash_size =32 * MiB;hwaddr sdram_base =0x40000000 ; -size_t sdram_size =128 * MiB;hwaddr initrd_base = sdram_base +0x1002000 ;hwaddr cmdline_base = sdram_base +0x1000000 ; -size_t initrd_max = sdram_size -0x1002000 ; +size_t initrd_max = machine->ram_size -0x1002000 ; reset_info =g_malloc0 (sizeof (ResetInfo));
@@ -116,9 +121,7 @@ milkymist_init(MachineState *machine)cpu_lm32_set_phys_msb_ignore (env,1 ); -memory_region_allocate_system_memory (phys_sdram,NULL ,"milkymist.sdram" , - sdram_size); -memory_region_add_subregion (address_space_mem, sdram_base, phys_sdram); +memory_region_add_subregion (address_space_mem, sdram_base, machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 );/* Numonyx JS28F256J3F105 */
@@ -183,7 +186,7 @@ milkymist_init(MachineState *machine)if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, sdram_base, - sdram_size); + machine->ram_size); reset_info->bootstrap_pc = sdram_base; }
@@ -216,6 +219,8 @@ static void milkymist_machine_init(MachineClass *mc) mc->init = milkymist_init; mc->is_default =0 ; mc->default_cpu_type =LM32_CPU_TYPE_NAME ("lm32-full" ); + mc->default_ram_size =128 * MiB; + mc->default_ram_id ="milkymist.sdram" ; }DEFINE_MACHINE ("milkymist" , milkymist_machine_init)
Signature · 1 line
2.7.4
Re: [PATCH v2 48/86] lm32:milkymist: use memdev for RAM
Quoted 38 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)--- hw/lm32/milkymist.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/lm32/milkymist.c +1
-0@@ -82,6 +82,7 @@ static void main_cpu_reset(void *opaque)static void milkymist_init (MachineState *machine) { +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -90,22 +91,26 @@ milkymist_init(MachineState *machine)int kernel_size;DriveInfo *dinfo;
hw/lm32/milkymist.c milkymist_init(MachineState *machine) · line 101
Quoted 10 lines
hw/lm32/milkymist.c +3
-1MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_sdram =g_new (MemoryRegion,1 );qemu_irq irq[32 ];int i;char *bios_filename;ResetInfo *reset_info; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size);
I'd be displayed nicer using size_to_str(). Can be improved later.
Quoted 47 lines
hw/lm32/milkymist.c +8
-6+exit (EXIT_FAILURE ); + } +/* memory map */ hwaddr flash_base =0x00000000 ;size_t flash_sector_size =128 * KiB;size_t flash_size =32 * MiB;hwaddr sdram_base =0x40000000 ; -size_t sdram_size =128 * MiB;hwaddr initrd_base = sdram_base +0x1002000 ;hwaddr cmdline_base = sdram_base +0x1000000 ; -size_t initrd_max = sdram_size -0x1002000 ; +size_t initrd_max = machine->ram_size -0x1002000 ; reset_info =g_malloc0 (sizeof (ResetInfo));@@ -116,9 +121,7 @@ milkymist_init(MachineState *machine)cpu_lm32_set_phys_msb_ignore (env,1 ); -memory_region_allocate_system_memory (phys_sdram,NULL ,"milkymist.sdram" , - sdram_size); -memory_region_add_subregion (address_space_mem, sdram_base, phys_sdram); +memory_region_add_subregion (address_space_mem, sdram_base, machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 );/* Numonyx JS28F256J3F105 */ @@ -183,7 +186,7 @@ milkymist_init(MachineState *machine)if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, sdram_base, - sdram_size); + machine->ram_size); reset_info->bootstrap_pc = sdram_base; }@@ -216,6 +219,8 @@ static void milkymist_machine_init(MachineClass *mc) mc->init = milkymist_init; mc->is_default =0 ; mc->default_cpu_type =LM32_CPU_TYPE_NAME ("lm32-full" ); + mc->default_ram_size =128 * MiB; + mc->default_ram_id ="milkymist.sdram" ; }DEFINE_MACHINE ("milkymist" , milkymist_machine_init)
Re: [PATCH v2 48/86] lm32:milkymist: use memdev for RAM
Quoted 46 lines · On Wed, 15 Jan 2020 19:32:19 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 45 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.PS:
while at it add check for user supplied RAM size and error out if it mismatches board expected value.Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)--- hw/lm32/milkymist.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)hw/lm32/milkymist.c +1
-1@@ -82,6 +82,7 @@ static void main_cpu_reset(void *opaque)static void milkymist_init (MachineState *machine) { +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -90,22 +91,26 @@ milkymist_init(MachineState *machine)int kernel_size;DriveInfo *dinfo;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *phys_sdram =g_new (MemoryRegion,1 );qemu_irq irq[32 ];int i;char *bios_filename;ResetInfo *reset_info;
Quoted 5 lines
hw/lm32/milkymist.c milkymist_init(MachineState *machine) · line 101
Quoted 3 lines
hw/lm32/milkymist.c +3
-0+if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size);I'd be displayed nicer using
size_to_str(). Can be improved later.
I'll use it on respin, including similar places on other boards
Quoted 51 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 47 lines
hw/lm32/milkymist.c +8
-6+exit (EXIT_FAILURE ); + } +/* memory map */ hwaddr flash_base =0x00000000 ;size_t flash_sector_size =128 * KiB;size_t flash_size =32 * MiB;hwaddr sdram_base =0x40000000 ; -size_t sdram_size =128 * MiB;hwaddr initrd_base = sdram_base +0x1002000 ;hwaddr cmdline_base = sdram_base +0x1000000 ; -size_t initrd_max = sdram_size -0x1002000 ; +size_t initrd_max = machine->ram_size -0x1002000 ; reset_info =g_malloc0 (sizeof (ResetInfo));@@ -116,9 +121,7 @@ milkymist_init(MachineState *machine)cpu_lm32_set_phys_msb_ignore (env,1 ); -memory_region_allocate_system_memory (phys_sdram,NULL ,"milkymist.sdram" , - sdram_size); -memory_region_add_subregion (address_space_mem, sdram_base, phys_sdram); +memory_region_add_subregion (address_space_mem, sdram_base, machine->ram); dinfo =drive_get (IF_PFLASH ,0 ,0 );/* Numonyx JS28F256J3F105 */ @@ -183,7 +186,7 @@ milkymist_init(MachineState *machine)if (kernel_size <0 ) { kernel_size =load_image_targphys (kernel_filename, sdram_base, - sdram_size); + machine->ram_size); reset_info->bootstrap_pc = sdram_base; }@@ -216,6 +219,8 @@ static void milkymist_machine_init(MachineClass *mc) mc->init = milkymist_init; mc->is_default =0 ; mc->default_cpu_type =LM32_CPU_TYPE_NAME ("lm32-full" ); + mc->default_ram_size =128 * MiB; + mc->default_ram_id ="milkymist.sdram" ; }DEFINE_MACHINE ("milkymist" , milkymist_machine_init)
PATCH v2 49/86 m68k:an5206: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/m68k/an5206.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/m68k/an5206.c +2 -3
@@ -33,7 +33,6 @@ static void an5206_init(MachineState *machine)uint64_t elf_entry;hwaddr entry;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *sram =g_new (MemoryRegion,1 ); cpu =M68K_CPU (cpu_create (machine->cpu_type));
@@ -46,8 +45,7 @@ static void an5206_init(MachineState *machine) env->rambar0 =AN5206_RAMBAR_ADDR |1 ;/* DRAM at address zero */ -memory_region_allocate_system_memory (ram,NULL ,"an5206.ram" , ram_size); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* Internal SRAM. */ memory_region_init_ram (sram,NULL ,"an5206.sram" ,512 , &error_fatal);
@@ -89,6 +87,7 @@ static void an5206_machine_init(MachineClass *mc) mc->desc ="Arnewsh 5206" ; mc->init = an5206_init; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m5206" ); + mc->default_ram_id ="an5206.ram" ; }DEFINE_MACHINE ("an5206" , an5206_machine_init)
Signature · 1 line
2.7.4
PATCH v2 50/86 m68k:mcf5208: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/m68k/mcf5208.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/m68k/mcf5208.c +2 -3
@@ -234,7 +234,6 @@ static void mcf5208evb_init(MachineState *machine)qemu_irq *pic;MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *rom =g_new (MemoryRegion,1 ); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *sram =g_new (MemoryRegion,1 ); cpu =M68K_CPU (cpu_create (machine->cpu_type));
@@ -249,8 +248,7 @@ static void mcf5208evb_init(MachineState *machine)memory_region_add_subregion (address_space_mem,0x00000000 , rom);/* DRAM at 0x40000000 */ -memory_region_allocate_system_memory (ram,NULL ,"mcf5208.ram" , ram_size); -memory_region_add_subregion (address_space_mem,0x40000000 , ram); +memory_region_add_subregion (address_space_mem,0x40000000 , machine->ram);/* Internal SRAM. */ memory_region_init_ram (sram,NULL ,"mcf5208.sram" ,16 * KiB, &error_fatal);
@@ -354,6 +352,7 @@ static void mcf5208evb_machine_init(MachineClass *mc) mc->init = mcf5208evb_init; mc->is_default =1 ; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m5208" ); + mc->default_ram_id ="mcf5208.ram" ; }DEFINE_MACHINE ("mcf5208evb" , mcf5208evb_machine_init)
Signature · 1 line
2.7.4
PATCH v2 51/86 m68k:next-cube: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/m68k/next-cube.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
hw/m68k/next-cube.c +2 -3
@@ -860,7 +860,6 @@ static void next_cube_init(MachineState *machine) {M68kCPU *cpu;CPUM68KState *env; -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *rom =g_new (MemoryRegion,1 );MemoryRegion *mmiomem =g_new (MemoryRegion,1 );MemoryRegion *scrmem =g_new (MemoryRegion,1 );
@@ -893,8 +892,7 @@ static void next_cube_init(MachineState *machine)memcpy (ns->rtc.ram, rtc_ram2,32 );/* 64MB RAM starting at 0x04000000 */ -memory_region_allocate_system_memory (ram,NULL ,"next.ram" , ram_size); -memory_region_add_subregion (sysmem,0x04000000 , ram); +memory_region_add_subregion (sysmem,0x04000000 , machine->ram);/* Framebuffer */ dev =qdev_create (NULL ,TYPE_NEXTFB );
@@ -967,6 +965,7 @@ static void next_machine_class_init(ObjectClass *oc, void *data) mc->desc ="NeXT Cube" ; mc->init = next_cube_init; mc->default_ram_size =RAM_SIZE ; + mc->default_ram_id ="next.ram" ; mc->default_cpu_type =M68K_CPU_TYPE_NAME ("m68040" ); }
Signature · 1 line
2.7.4
PATCH v2 52/86 mips:boston-cube: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/mips/boston.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/mips/boston.c +5 -6
@@ -427,7 +427,7 @@ static void boston_mach_init(MachineState *machine)DeviceState *dev;BostonState *s;Error *err =NULL ; -MemoryRegion *flash, *ddr, *ddr_low_alias, *lcd, *platreg; +MemoryRegion *flash, *ddr_low_alias, *lcd, *platreg;MemoryRegion *sys_mem =get_system_memory ();XilinxPCIEHost *pcie2;PCIDevice *ahci;
@@ -473,14 +473,12 @@ static void boston_mach_init(MachineState *machine)memory_region_init_rom (flash,NULL ,"boston.flash" ,128 * MiB, &err);memory_region_add_subregion_overlap (sys_mem,0x18000000 , flash,0 ); - ddr =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (ddr,NULL ,"boston.ddr" , - machine->ram_size); -memory_region_add_subregion_overlap (sys_mem,0x80000000 , ddr,0 ); +memory_region_add_subregion_overlap (sys_mem,0x80000000 , machine->ram,0 ); ddr_low_alias =g_new (MemoryRegion,1 );memory_region_init_alias (ddr_low_alias,NULL ,"boston_low.ddr" , - ddr,0 ,MIN (machine->ram_size, (256 * MiB))); + machine->ram,0 , +MIN (machine->ram_size, (256 * MiB)));memory_region_add_subregion_overlap (sys_mem,0 , ddr_low_alias,0 ); xilinx_pcie_init(sys_mem, 0,
@@ -552,6 +550,7 @@ static void boston_mach_class_init(MachineClass *mc) mc->init = boston_mach_init; mc->block_default_type =IF_IDE ; mc->default_ram_size =1 * GiB; + mc->default_ram_id ="boston.ddr" ; mc->max_cpus =16 ; mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("I6400" ); }
Signature · 1 line
2.7.4
PATCH v2 53/86 mips:mips_fulong2e: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
---
v2:
* fix format string cousing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/mips/mips_fulong2e.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
hw/mips/mips_fulong2e.c +8 -5
@@ -296,7 +296,6 @@ static void mips_fulong2e_init(MachineState *machine)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 ); -ram_addr_t ram_size = machine->ram_size;long bios_size;uint8_t *spd_data;Error *err =NULL ;
@@ -315,10 +314,14 @@ static void mips_fulong2e_init(MachineState *machine)qemu_register_reset (main_cpu_reset, cpu);/* TODO: support more than 256M RAM as highmem */ - ram_size =256 * MiB; +if (machine->ram_size !=256 * MiB) { +error_report ("Invalid RAM size, should be %" PRIu64,256 * MiB); +exit (EXIT_FAILURE ); + }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"fulong2e.ram" , ram_size); +memory_region_allocate_system_memory (ram,NULL ,"fulong2e.ram" , + machine->ram_size);memory_region_init_ram (bios,NULL ,"fulong2e.bios" ,BIOS_SIZE , &error_fatal);memory_region_set_readonly (bios, true);
@@ -332,7 +335,7 @@ static void mips_fulong2e_init(MachineState *machine)*/ if (kernel_filename) { - loaderparams.ram_size = ram_size; + loaderparams.ram_size = machine->ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename;
@@ -378,7 +381,7 @@ static void mips_fulong2e_init(MachineState *machine) }/* Populate SPD eeprom data */ - spd_data =spd_data_generate (DDR , ram_size, &err); + spd_data =spd_data_generate (DDR , machine->ram_size, &err);if (err) {warn_report_err (err); }
Signature · 1 line
2.7.4
Re: [PATCH v2 53/86] mips:mips_fulong2e: drop RAM size fixup
Quoted 35 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fix format string cousing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)---
hw/mips/mips_fulong2e.c| 13 ++++++++-----1 file changed, 8 insertions(+), 5 deletions(-)hw/mips/mips_fulong2e.c +0
-1@@ -296,7 +296,6 @@ static void mips_fulong2e_init(MachineState *machine)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 ); -ram_addr_t ram_size = machine->ram_size;long bios_size;uint8_t *spd_data;Error *err =NULL ;
hw/mips/mips_fulong2e.c static void mips_fulong2e_init(MachineState *machine) · line 318
Quoted 6 lines
hw/mips/mips_fulong2e.c +2
-1@@ -315,10 +314,14 @@ static void mips_fulong2e_init(MachineState *machine)qemu_register_reset (main_cpu_reset, cpu);/* TODO: support more than 256M RAM as highmem */ - ram_size =256 * MiB; +if (machine->ram_size !=256 * MiB) { +error_report ("Invalid RAM size, should be %" PRIu64,256 * MiB);
Should this just print 256M without any format string or print it in MiB instead of bytes like for mips_r4k (considering that default for -m option is value as postfixed by M so it makes more sense for the user to print that what they can easily specify in the option).
Regards,
BALATON Zoltan
PATCH v3 53/86 mips:mips_fulong2e: drop RAM size fixup
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
---
v2:
* fix format string cousing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
v3:
* since size is ifxed, just hardcode 256Mb value as text in error message
(BALATON Zoltan <[email protected]>)
--- hw/mips/mips_fulong2e.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
hw/mips/mips_fulong2e.c +8 -5
@@ -296,7 +296,6 @@ static void mips_fulong2e_init(MachineState *machine)MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 ); -ram_addr_t ram_size = machine->ram_size;long bios_size;uint8_t *spd_data;Error *err =NULL ;
@@ -315,10 +314,14 @@ static void mips_fulong2e_init(MachineState *machine)qemu_register_reset (main_cpu_reset, cpu);/* TODO: support more than 256M RAM as highmem */ - ram_size =256 * MiB; +if (machine->ram_size !=256 * MiB) { +error_report ("Invalid RAM size, should be 256MB" ); +exit (EXIT_FAILURE ); + }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"fulong2e.ram" , ram_size); +memory_region_allocate_system_memory (ram,NULL ,"fulong2e.ram" , + machine->ram_size);memory_region_init_ram (bios,NULL ,"fulong2e.bios" ,BIOS_SIZE , &error_fatal);memory_region_set_readonly (bios, true);
@@ -332,7 +335,7 @@ static void mips_fulong2e_init(MachineState *machine)*/ if (kernel_filename) { - loaderparams.ram_size = ram_size; + loaderparams.ram_size = machine->ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename;
@@ -378,7 +381,7 @@ static void mips_fulong2e_init(MachineState *machine) }/* Populate SPD eeprom data */ - spd_data =spd_data_generate (DDR , ram_size, &err); + spd_data =spd_data_generate (DDR , machine->ram_size, &err);if (err) {warn_report_err (err); }
Signature · 1 line
2.7.4
PATCH v2 54/86 mips:mips_fulong2e: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/mips/mips_fulong2e.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/mips/mips_fulong2e.c +2 -4
@@ -294,7 +294,6 @@ static void mips_fulong2e_init(MachineState *machine)const char *initrd_filename = machine->initrd_filename;char *filename;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );long bios_size;uint8_t *spd_data;
@@ -320,13 +319,11 @@ static void mips_fulong2e_init(MachineState *machine) }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"fulong2e.ram" , - machine->ram_size);memory_region_init_ram (bios,NULL ,"fulong2e.bios" ,BIOS_SIZE , &error_fatal);memory_region_set_readonly (bios, true); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);memory_region_add_subregion (address_space_mem,0x1fc00000LL , bios);/*
@@ -402,6 +399,7 @@ static void mips_fulong2e_machine_init(MachineClass *mc) mc->block_default_type =IF_IDE ; mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("Loongson-2E" ); mc->default_ram_size =256 * MiB; + mc->default_ram_id ="fulong2e.ram" ; }DEFINE_MACHINE ("fulong2e" , mips_fulong2e_machine_init)
Signature · 1 line
2.7.4
PATCH v2 55/86 mips:mips_jazz: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/mips/mips_jazz.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
hw/mips/mips_jazz.c +3 -4
@@ -159,7 +159,6 @@ static void mips_jazz_init(MachineState *machine,ISABus *isa_bus;ISADevice *pit;DriveInfo *fds[MAX_FD ]; -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );MemoryRegion *bios2 =g_new (MemoryRegion,1 );SysBusESPState *sysbus_esp;
@@ -191,9 +190,7 @@ static void mips_jazz_init(MachineState *machine, cc->do_transaction_failed = mips_jazz_do_transaction_failed;/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"mips_jazz.ram" , - machine->ram_size); -memory_region_add_subregion (address_space,0 , ram); +memory_region_add_subregion (address_space,0 , machine->ram);memory_region_init_ram (bios,NULL ,"mips_jazz.bios" ,MAGNUM_BIOS_SIZE , &error_fatal);
@@ -393,6 +390,7 @@ static void mips_magnum_class_init(ObjectClass *oc, void *data) mc->init = mips_magnum_init; mc->block_default_type =IF_SCSI ; mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("R4000" ); + mc->default_ram_id ="mips_jazz.ram" ; }static const TypeInfo mips_magnum_type = {
@@ -409,6 +407,7 @@ static void mips_pica61_class_init(ObjectClass *oc, void *data) mc->init = mips_pica61_init; mc->block_default_type =IF_SCSI ; mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("R4000" ); + mc->default_ram_id ="mips_jazz.ram" ; }static const TypeInfo mips_pica61_type = {
Signature · 1 line
2.7.4
PATCH v2 56/86 mips:mips_malta: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/mips/mips_malta.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
hw/mips/mips_malta.c +4 -6
@@ -1223,7 +1223,6 @@ void mips_malta_init(MachineState *machine)char *filename;PFlashCFI01 *fl;MemoryRegion *system_memory =get_system_memory (); -MemoryRegion *ram_high =g_new (MemoryRegion,1 );MemoryRegion *ram_low_preio =g_new (MemoryRegion,1 );MemoryRegion *ram_low_postio;MemoryRegion *bios, *bios_copy =g_new (MemoryRegion,1 );
@@ -1261,13 +1260,11 @@ void mips_malta_init(MachineState *machine) }/* register RAM at high address where it is undisturbed by IO */ -memory_region_allocate_system_memory (ram_high,NULL ,"mips_malta.ram" , - ram_size); -memory_region_add_subregion (system_memory,0x80000000 , ram_high); +memory_region_add_subregion (system_memory,0x80000000 , machine->ram);/* alias for pre IO hole access */ memory_region_init_alias (ram_low_preio,NULL ,"mips_malta_low_preio.ram" , - ram_high,0 ,MIN (ram_size,256 * MiB)); + machine->ram,0 ,MIN (ram_size,256 * MiB));memory_region_add_subregion (system_memory,0 , ram_low_preio);/* alias for post IO hole access, if there is enough RAM */
@@ -1275,7 +1272,7 @@ void mips_malta_init(MachineState *machine) ram_low_postio =g_new (MemoryRegion,1 );memory_region_init_alias (ram_low_postio,NULL ,"mips_malta_low_postio.ram" , - ram_high,512 * MiB, + machine->ram,512 * MiB, ram_size -512 * MiB);memory_region_add_subregion (system_memory,512 * MiB, ram_low_postio);
@@ -1447,6 +1444,7 @@ static void mips_malta_machine_init(MachineClass *mc)#else mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif + mc->default_ram_id ="mips_malta.ram" ; }DEFINE_MACHINE ("malta" , mips_malta_machine_init)
Signature · 1 line
2.7.4
PATCH v2 57/86 mips:mips_mipssim: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/mips/mips_mipssim.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
hw/mips/mips_mipssim.c +3 -6
@@ -143,14 +143,12 @@ static void mipsnet_init(int base, qemu_irq irq, NICInfo *nd)static void mips_mipssim_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;char *filename;MemoryRegion *address_space_mem =get_system_memory ();MemoryRegion *isa =g_new (MemoryRegion,1 ); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );MIPSCPU *cpu;CPUMIPSState *env;
@@ -167,13 +165,11 @@ mips_mipssim_init(MachineState *machine)qemu_register_reset (main_cpu_reset, reset_info);/* Allocate RAM. */ -memory_region_allocate_system_memory (ram,NULL ,"mips_mipssim.ram" , - ram_size);memory_region_init_ram (bios,NULL ,"mips_mipssim.bios" ,BIOS_SIZE , &error_fatal);memory_region_set_readonly (bios, true); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);/* Map the BIOS / boot exception handler. */ memory_region_add_subregion (address_space_mem,0x1fc00000LL , bios);
@@ -200,7 +196,7 @@ mips_mipssim_init(MachineState *machine) }if (kernel_filename) { - loaderparams.ram_size = ram_size; + loaderparams.ram_size = machine->ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename;
@@ -245,6 +241,7 @@ static void mips_mipssim_machine_init(MachineClass *mc)#else mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif + mc->default_ram_id ="mips_mipssim.ram" ; }DEFINE_MACHINE ("mipssim" , mips_mipssim_machine_init)
Signature · 1 line
2.7.4
PATCH v2 58/86 mips:mips_r4k: use memdev for RAM
In reply to Igor Mammedovmemory_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.
--- hw/mips/mips_r4k.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
hw/mips/mips_r4k.c +4 -8
@@ -171,13 +171,11 @@ static const int sector_len = 32 * KiB;static void mips_r4k_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;char *filename;MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios;MemoryRegion *iomem =g_new (MemoryRegion,1 );MemoryRegion *isa_io =g_new (MemoryRegion,1 );
@@ -203,14 +201,12 @@ void mips_r4k_init(MachineState *machine)qemu_register_reset (main_cpu_reset, reset_info);/* allocate RAM */ -if (ram_size >256 * MiB) { +if (machine->ram_size >256 * MiB) {error_report ("Too much memory for this machine: %" PRId64"MB," " maximum 256MB" , ram_size / MiB);exit (1 ); } -memory_region_allocate_system_memory (ram,NULL ,"mips_r4k.ram" , ram_size); - -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram);memory_region_init_io (iomem,NULL , &mips_qemu_ops,NULL ,"mips-qemu" ,0x10000 );
@@ -261,7 +257,7 @@ void mips_r4k_init(MachineState *machine)g_free (filename);if (kernel_filename) { - loaderparams.ram_size = ram_size; + loaderparams.ram_size = machine->ram_size; loaderparams.kernel_filename = kernel_filename; loaderparams.kernel_cmdline = kernel_cmdline; loaderparams.initrd_filename = initrd_filename;
@@ -316,7 +312,7 @@ static void mips_machine_init(MachineClass *mc)#else mc->default_cpu_type =MIPS_CPU_TYPE_NAME ("24Kf" );#endif - + mc->default_ram_id ="mips_r4k.ram" ; }DEFINE_MACHINE ("mips" , mips_machine_init)
Signature · 1 line
2.7.4
PATCH v2 59/86 ppc:e500: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
While at it, replace usage of global ram_size with machine->ram_size
---
v2:
* fix format string cousing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/ppc/e500.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
hw/ppc/e500.c +9 -7
@@ -906,12 +906,14 @@ void ppce500_init(MachineState *machine) env = firstenv; -/* Fixup Memory size on a alignment boundary */ - ram_size &= ~(RAM_SIZES_ALIGN -1 ); - machine->ram_size = ram_size; +if (!QEMU_IS_ALIGNED (machine->ram_size,RAM_SIZES_ALIGN )) { +error_report ("RAM size must be multiple of %" PRIu64,RAM_SIZES_ALIGN ); +exit (EXIT_FAILURE ); + }/* Register Memory */ -memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , ram_size); +memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , + machine->ram_size);memory_region_add_subregion (address_space_mem,0 , ram); dev =qdev_create (NULL ,"e500-ccsr" );
@@ -1083,7 +1085,7 @@ void ppce500_init(MachineState *machine) kernel_base = cur_base; kernel_size =load_image_targphys (machine->kernel_filename, cur_base, - ram_size - cur_base); + machine->ram_size - cur_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , machine->kernel_filename);
@@ -1097,7 +1099,7 @@ void ppce500_init(MachineState *machine)if (machine->initrd_filename) { initrd_base = (cur_base +INITRD_LOAD_PAD ) & ~INITRD_PAD_MASK ; initrd_size =load_image_targphys (machine->initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) { error_report("could not load initial ram disk '%s'",
@@ -1115,7 +1117,7 @@ void ppce500_init(MachineState *machine)* ensures enough space between kernel and initrd. */ dt_base = (loadaddr + payload_size +DTC_LOAD_PAD ) & ~DTC_PAD_MASK ; -if (dt_base +DTB_MAX_SIZE > ram_size) { +if (dt_base +DTB_MAX_SIZE > machine->ram_size) {error_report ("not enough memory for device tree" );exit (1 ); }
Signature · 1 line
2.7.4
Re: [PATCH v2 59/86] ppc:e500: drop RAM size fixup
Quoted 5 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Quoted 7 lines
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
While at it, replace usage of global
ram_sizewithmachine->ram_sizeSigned-off-by Igor Mammedov <[email protected]>
Quoted 62 lines
---
v2:
* fix format string cousing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)--- hw/ppc/e500.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)hw/ppc/e500.c +9
-7@@ -906,12 +906,14 @@ void ppce500_init(MachineState *machine) env = firstenv; -/* Fixup Memory size on a alignment boundary */ - ram_size &= ~(RAM_SIZES_ALIGN -1 ); - machine->ram_size = ram_size; +if (!QEMU_IS_ALIGNED (machine->ram_size,RAM_SIZES_ALIGN )) { +error_report ("RAM size must be multiple of %" PRIu64,RAM_SIZES_ALIGN ); +exit (EXIT_FAILURE ); + }/* Register Memory */ -memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , ram_size); +memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , + machine->ram_size);memory_region_add_subregion (address_space_mem,0 , ram); dev =qdev_create (NULL ,"e500-ccsr" );@@ -1083,7 +1085,7 @@ void ppce500_init(MachineState *machine) kernel_base = cur_base; kernel_size =load_image_targphys (machine->kernel_filename, cur_base, - ram_size - cur_base); + machine->ram_size - cur_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , machine->kernel_filename);@@ -1097,7 +1099,7 @@ void ppce500_init(MachineState *machine)if (machine->initrd_filename) { initrd_base = (cur_base +INITRD_LOAD_PAD ) & ~INITRD_PAD_MASK ; initrd_size =load_image_targphys (machine->initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) { error_report("could not load initial ram disk '%s'",@@ -1115,7 +1117,7 @@ void ppce500_init(MachineState *machine)* ensures enough space between kernel and initrd. */ dt_base = (loadaddr + payload_size +DTC_LOAD_PAD ) & ~DTC_PAD_MASK ; -if (dt_base +DTB_MAX_SIZE > ram_size) { +if (dt_base +DTB_MAX_SIZE > machine->ram_size) {error_report ("not enough memory for device tree" );exit (1 ); }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 60/86 ppc:e500: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
--- hw/ppc/e500.c | 5 +---- hw/ppc/e500plat.c | 1 + hw/ppc/mpc8544ds.c | 1 + 3 files changed, 3 insertions(+), 4 deletions(-)
hw/ppc/e500.c +1 -4
@@ -831,7 +831,6 @@ static void ppce500_power_off(void *opaque, int line, int on)void ppce500_init (MachineState *machine) {MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );PPCE500MachineState *pms =PPCE500_MACHINE (machine);const PPCE500MachineClass *pmc =PPCE500_MACHINE_GET_CLASS (machine);PCIBus *pci_bus;
@@ -912,9 +911,7 @@ void ppce500_init(MachineState *machine) }/* Register Memory */ -memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , - machine->ram_size); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram); dev =qdev_create (NULL ,"e500-ccsr" ); object_property_add_child(qdev_get_machine(), "e500-ccsr",
hw/ppc/e500plat.c +1 -0
@@ -97,6 +97,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->init = e500plat_init; mc->max_cpus =32 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); + mc->default_ram_id ="mpc8544ds.ram" ;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_ETSEC_COMMON ); }
hw/ppc/mpc8544ds.c +1 -0
@@ -55,6 +55,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->init = mpc8544ds_init; mc->max_cpus =15 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); + mc->default_ram_id ="mpc8544ds.ram" ; }#define TYPE_MPC8544DS_MACHINE MACHINE_TYPE_NAME("mpc8544ds")
Signature · 1 line
2.7.4
Re: [PATCH v2 60/86] ppc:e500: use memdev for RAM
Quoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Quoted 56 lines
---
CC: [email protected]
CC: [email protected]--- hw/ppc/e500.c | 5 +---- hw/ppc/e500plat.c | 1 + hw/ppc/mpc8544ds.c | 1 + 3 files changed, 3 insertions(+), 4 deletions(-)hw/ppc/e500.c +1
-4@@ -831,7 +831,6 @@ static void ppce500_power_off(void *opaque, int line, int on)void ppce500_init (MachineState *machine) {MemoryRegion *address_space_mem =get_system_memory (); -MemoryRegion *ram =g_new (MemoryRegion,1 );PPCE500MachineState *pms =PPCE500_MACHINE (machine);const PPCE500MachineClass *pmc =PPCE500_MACHINE_GET_CLASS (machine);PCIBus *pci_bus;@@ -912,9 +911,7 @@ void ppce500_init(MachineState *machine) }/* Register Memory */ -memory_region_allocate_system_memory (ram,NULL ,"mpc8544ds.ram" , - machine->ram_size); -memory_region_add_subregion (address_space_mem,0 , ram); +memory_region_add_subregion (address_space_mem,0 , machine->ram); dev =qdev_create (NULL ,"e500-ccsr" ); object_property_add_child(qdev_get_machine(), "e500-ccsr",hw/ppc/e500plat.c +1
-0@@ -97,6 +97,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->init = e500plat_init; mc->max_cpus =32 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); + mc->default_ram_id ="mpc8544ds.ram" ;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_ETSEC_COMMON ); }hw/ppc/mpc8544ds.c +1
-0@@ -55,6 +55,7 @@ static void e500plat_machine_class_init(ObjectClass *oc, void *data) mc->init = mpc8544ds_init; mc->max_cpus =15 ; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("e500v2_v30" ); + mc->default_ram_id ="mpc8544ds.ram" ; }#define TYPE_MPC8544DS_MACHINE MACHINE_TYPE_NAME("mpc8544ds")
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 61/86 ppc:mac_newworld: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/ppc/mac_newworld.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ppc/mac_newworld.c +3 -3
@@ -118,7 +118,7 @@ static void ppc_core99_init(MachineState *machine)char *filename;IrqLines *openpic_irqs;int linux_boot, i, j, k; -MemoryRegion *ram =g_new (MemoryRegion,1 ), *bios =g_new (MemoryRegion,1 ); +MemoryRegion *bios =g_new (MemoryRegion,1 );hwaddr kernel_base, initrd_base, cmdline_base =0 ;long kernel_size, initrd_size;UNINHostState *uninorth_pci;
@@ -152,8 +152,7 @@ static void ppc_core99_init(MachineState *machine) }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"ppc_core99.ram" , ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_core99.bios", BIOS_SIZE,
@@ -586,6 +585,7 @@ static void core99_machine_class_init(ObjectClass *oc, void *data)#else mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("7400_v2.9" );#endif + mc->default_ram_id ="ppc_core99.ram" ; mc->ignore_boot_device_suffixes = true; fwc->get_dev_path = core99_fw_dev_path; }
Signature · 1 line
2.7.4
Re: [PATCH v2 61/86] ppc:mac_newworld: use memdev for RAM
Quoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Quoted 39 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/ppc/mac_newworld.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/ppc/mac_newworld.c +3
-3@@ -118,7 +118,7 @@ static void ppc_core99_init(MachineState *machine)char *filename;IrqLines *openpic_irqs;int linux_boot, i, j, k; -MemoryRegion *ram =g_new (MemoryRegion,1 ), *bios =g_new (MemoryRegion,1 ); +MemoryRegion *bios =g_new (MemoryRegion,1 );hwaddr kernel_base, initrd_base, cmdline_base =0 ;long kernel_size, initrd_size;UNINHostState *uninorth_pci;@@ -152,8 +152,7 @@ static void ppc_core99_init(MachineState *machine) }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"ppc_core99.ram" , ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_core99.bios", BIOS_SIZE,@@ -586,6 +585,7 @@ static void core99_machine_class_init(ObjectClass *oc, void *data)#else mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("7400_v2.9" );#endif + mc->default_ram_id ="ppc_core99.ram" ; mc->ignore_boot_device_suffixes = true; fwc->get_dev_path = core99_fw_dev_path; }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH v2 61/86] ppc:mac_newworld: use memdev for RAM
In reply to Igor MammedovQuoted 41 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/ppc/mac_newworld.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)hw/ppc/mac_newworld.c +2
-3@@ -118,7 +118,7 @@ static void ppc_core99_init(MachineState *machine)char *filename;IrqLines *openpic_irqs;int linux_boot, i, j, k; -MemoryRegion *ram =g_new (MemoryRegion,1 ), *bios =g_new (MemoryRegion,1 ); +MemoryRegion *bios =g_new (MemoryRegion,1 );hwaddr kernel_base, initrd_base, cmdline_base =0 ;long kernel_size, initrd_size;UNINHostState *uninorth_pci;@@ -152,8 +152,7 @@ static void ppc_core99_init(MachineState *machine) }/* allocate RAM */ -memory_region_allocate_system_memory (ram,NULL ,"ppc_core99.ram" , ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_core99.bios", BIOS_SIZE,
hw/ppc/mac_newworld.c static void core99_machine_class_init(ObjectClass *oc, void *data) · line 591
Quoted 7 lines
hw/ppc/mac_newworld.c +1
-0@@ -586,6 +585,7 @@ static void core99_machine_class_init(ObjectClass *oc, void *data)#else mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("7400_v2.9" );#endif + mc->default_ram_id ="ppc_core99.ram" ; mc->ignore_boot_device_suffixes = true; fwc->get_dev_path = core99_fw_dev_path; }
ATB,
Mark.
PATCH v2 62/86 ppc:mac_oldworld: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/ppc/mac_oldworld.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/ppc/mac_oldworld.c +2 -4
@@ -91,7 +91,6 @@ static void ppc_heathrow_init(MachineState *machine)CPUPPCState *env =NULL ;char *filename;int linux_boot, i; -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );uint32_t kernel_base, initrd_base, cmdline_base =0 ;int32_t kernel_size, initrd_size;
@@ -127,9 +126,7 @@ static void ppc_heathrow_init(MachineState *machine)exit (1 ); } -memory_region_allocate_system_memory (ram,NULL ,"ppc_heathrow.ram" , - ram_size); -memory_region_add_subregion (sysmem,0 , ram); +memory_region_add_subregion (sysmem,0 , machine->ram);/* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE,
@@ -446,6 +443,7 @@ static void heathrow_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("750_v3.1" ); mc->default_display ="std" ; mc->ignore_boot_device_suffixes = true; + mc->default_ram_id ="ppc_heathrow.ram" ; fwc->get_dev_path = heathrow_fw_dev_path; }
Signature · 1 line
2.7.4
Re: [PATCH v2 62/86] ppc:mac_oldworld: use memdev for RAM
Quoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH v2 62/86] ppc:mac_oldworld: use memdev for RAM
In reply to Igor MammedovQuoted 41 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/ppc/mac_oldworld.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)hw/ppc/mac_oldworld.c +1
-4@@ -91,7 +91,6 @@ static void ppc_heathrow_init(MachineState *machine)CPUPPCState *env =NULL ;char *filename;int linux_boot, i; -MemoryRegion *ram =g_new (MemoryRegion,1 );MemoryRegion *bios =g_new (MemoryRegion,1 );uint32_t kernel_base, initrd_base, cmdline_base =0 ;int32_t kernel_size, initrd_size;@@ -127,9 +126,7 @@ static void ppc_heathrow_init(MachineState *machine)exit (1 ); } -memory_region_allocate_system_memory (ram,NULL ,"ppc_heathrow.ram" , - ram_size); -memory_region_add_subregion (sysmem,0 , ram); +memory_region_add_subregion (sysmem,0 , machine->ram);/* allocate and load BIOS */ memory_region_init_ram(bios, NULL, "ppc_heathrow.bios", BIOS_SIZE,
hw/ppc/mac_oldworld.c static void heathrow_class_init(ObjectClass *oc, void *data) · line 448
Quoted 6 lines
hw/ppc/mac_oldworld.c +1
-0@@ -446,6 +443,7 @@ static void heathrow_class_init(ObjectClass *oc, void *data) mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("750_v3.1" ); mc->default_display ="std" ; mc->ignore_boot_device_suffixes = true; + mc->default_ram_id ="ppc_heathrow.ram" ; fwc->get_dev_path = heathrow_fw_dev_path; }
ATB,
Mark.
PATCH v2 63/86 ppc:pnv: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- hw/ppc/pnv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
hw/ppc/pnv.c +2 -6
@@ -676,7 +676,6 @@ static void pnv_init(MachineState *machine) {PnvMachineState *pnv =PNV_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine); -MemoryRegion *ram;char *fw_filename;long fw_size;int i;
@@ -688,11 +687,7 @@ static void pnv_init(MachineState *machine)if (machine->ram_size < (1 * GiB)) {warn_report ("skiboot may not work with < 1GB of RAM" ); } - - ram =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (ram,NULL ,"pnv.ram" , - machine->ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* * Create our simple PNOR device
@@ -1785,6 +1780,7 @@ static void pnv_machine_class_init(ObjectClass *oc, void *data)* enough to fit the maximum initrd size at it's load address */ mc->default_ram_size =INITRD_LOAD_ADDR +INITRD_MAX_SIZE ; + mc->default_ram_id ="pnv.ram" ; ispc->print_info = pnv_pic_print_info; }
Signature · 1 line
2.7.4
Re: [PATCH v2 63/86] ppc:pnv: use memdev for RAM
Quoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH v2 63/86] ppc:pnv: use memdev for RAM
In reply to Igor MammedovQuoted 9 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.Signed-off-by Igor Mammedov <[email protected]>
C.
Quoted 42 lines
---
CC: [email protected]
CC: [email protected]
CC: [email protected]--- hw/ppc/pnv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)hw/ppc/pnv.c +2
-6@@ -676,7 +676,6 @@ static void pnv_init(MachineState *machine) {PnvMachineState *pnv =PNV_MACHINE (machine);MachineClass *mc =MACHINE_GET_CLASS (machine); -MemoryRegion *ram;char *fw_filename;long fw_size;int i;@@ -688,11 +687,7 @@ static void pnv_init(MachineState *machine)if (machine->ram_size < (1 * GiB)) {warn_report ("skiboot may not work with < 1GB of RAM" ); } - - ram =g_new (MemoryRegion,1 ); -memory_region_allocate_system_memory (ram,NULL ,"pnv.ram" , - machine->ram_size); -memory_region_add_subregion (get_system_memory (),0 , ram); +memory_region_add_subregion (get_system_memory (),0 , machine->ram);/* * Create our simple PNOR device @@ -1785,6 +1780,7 @@ static void pnv_machine_class_init(ObjectClass *oc, void *data)* enough to fit the maximum initrd size at it's load address */ mc->default_ram_size =INITRD_LOAD_ADDR +INITRD_MAX_SIZE ; + mc->default_ram_id ="pnv.ram" ; ispc->print_info = pnv_pic_print_info; }
PATCH v2 64/86 ppc:ppc405_boards: add RAM size checks
In reply to Igor MammedovIf user provided non-sense RAM size, board will ignore it and continue running with fixed RAM size.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix CLI.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
PS:
move fixed RAM size into mc->default_ram_size, so that generic code will know how much to allocate.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
--- hw/ppc/ppc405_boards.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)
hw/ppc/ppc405_boards.c +23 -13
@@ -137,7 +137,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)static void ref405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -161,15 +161,20 @@ static void ref405ep_init(MachineState *machine)DriveInfo *dinfo;MemoryRegion *sysmem =get_system_memory (); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* XXX: fix this */ memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , -0x08000000 ); + machine->ram_size); ram_bases[0 ] =0 ; - ram_sizes[0 ] =0x08000000 ; + ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); ram_bases[1 ] =0x00000000 ; ram_sizes[1 ] =0x00000000 ; - ram_size =128 * MiB; env =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );/* allocate SRAM */
@@ -227,7 +232,7 @@ static void ref405ep_init(MachineState *machine)if (linux_boot) {memset (&bd,0 ,sizeof (bd)); bd.bi_memstart =0x00000000 ; - bd.bi_memsize = ram_size; + bd.bi_memsize = machine->ram_size; bd.bi_flashstart = -bios_size; bd.bi_flashsize = -bios_size; bd.bi_flashoffset =0 ;
@@ -255,7 +260,7 @@ static void ref405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );
@@ -266,7 +271,7 @@ static void ref405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);
@@ -304,6 +309,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo ref405ep_type = {
@@ -408,7 +414,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)static void taihu_405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *initrd_filename = machine->initrd_filename;char *filename;
@@ -425,10 +431,13 @@ static void taihu_405ep_init(MachineState *machine)int fl_idx;DriveInfo *dinfo; -/* RAM is soldered to the board so the size cannot be changed */ - ram_size =0x08000000 ; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + }memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - ram_size); + machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;
@@ -500,7 +509,7 @@ static void taihu_405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );
@@ -509,7 +518,7 @@ static void taihu_405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);
@@ -533,6 +542,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo taihu_type = {
Signature · 1 line
2.7.4
Re: [PATCH v2 64/86] ppc:ppc405_boards: add RAM size checks
Quoted 107 lines · Igor Mammedov
If user provided non-sense RAM size, board will ignore it and continue running with fixed RAM size.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix CLI.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
PS:
move fixed RAM size intomc->default_ram_size, so that generic code will know how much to allocate.Signed-off-by Igor Mammedov <[email protected]>---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)---
hw/ppc/ppc405_boards.c| 36 +++++++++++++++++++++++-------------1 file changed, 23 insertions(+), 13 deletions(-)hw/ppc/ppc405_boards.c +14
-8@@ -137,7 +137,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)static void ref405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -161,15 +161,20 @@ static void ref405ep_init(MachineState *machine)DriveInfo *dinfo;MemoryRegion *sysmem =get_system_memory (); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* XXX: fix this */ memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , -0x08000000 ); + machine->ram_size); ram_bases[0 ] =0 ; - ram_sizes[0 ] =0x08000000 ; + ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); ram_bases[1 ] =0x00000000 ; ram_sizes[1 ] =0x00000000 ; - ram_size =128 * MiB; env =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );/* allocate SRAM */ @@ -227,7 +232,7 @@ static void ref405ep_init(MachineState *machine)if (linux_boot) {memset (&bd,0 ,sizeof (bd)); bd.bi_memstart =0x00000000 ; - bd.bi_memsize = ram_size; + bd.bi_memsize = machine->ram_size; bd.bi_flashstart = -bios_size; bd.bi_flashsize = -bios_size; bd.bi_flashoffset =0 ;@@ -255,7 +260,7 @@ static void ref405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );@@ -266,7 +271,7 @@ static void ref405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);@@ -304,6 +309,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo ref405ep_type = {@@ -408,7 +414,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)static void taihu_405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *initrd_filename = machine->initrd_filename;char *filename;
hw/ppc/ppc405_boards.c static void taihu_405ep_init(MachineState *machine) · line 435
Quoted 7 lines
hw/ppc/ppc405_boards.c +2
-2@@ -425,10 +431,13 @@ static void taihu_405ep_init(MachineState *machine)int fl_idx;DriveInfo *dinfo; -/* RAM is soldered to the board so the size cannot be changed */ - ram_size =0x08000000 ; +if (machine->ram_size != mc->default_ram_size) { + error_report("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes",
Likewise, should this rather print valid value in M instead of bytes?
Regards,
BALATON Zoltan
Quoted 36 lines
hw/ppc/ppc405_boards.c +7
-3+ mc->default_ram_size); +exit (EXIT_FAILURE ); + }memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - ram_size); + machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;@@ -500,7 +509,7 @@ static void taihu_405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );@@ -509,7 +518,7 @@ static void taihu_405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);@@ -533,6 +542,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo taihu_type = {
PATCH v3 64/86 ppc:ppc405_boards: add RAM size checks
If user provided non-sense RAM size, board will ignore it and continue running with fixed RAM size.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix CLI.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
PS:
move fixed RAM size into mc->default_ram_size, so that generic code will know how much to allocate.
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)
v3:
* use size_to_str() to pretty print size in MiB (Philippe Mathieu-Daudé <[email protected]>/ BALATON Zoltan <[email protected]>)
--- hw/ppc/ppc405_boards.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
hw/ppc/ppc405_boards.c +26 -13
@@ -40,6 +40,7 @@#include "qemu/error-report.h" #include "hw/loader.h" #include "exec/address-spaces.h" +#include "qemu/cutils.h" #define BIOS_FILENAME "ppc405_rom.bin"#define BIOS_SIZE (2 * MiB)
@@ -137,7 +138,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)static void ref405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -161,15 +162,21 @@ static void ref405ep_init(MachineState *machine)DriveInfo *dinfo;MemoryRegion *sysmem =get_system_memory (); +if (machine->ram_size != mc->default_ram_size) { +char *sz =size_to_str (mc->default_ram_size); +error_report ("Invalid RAM size, should be %s" , sz); +g_free (sz); +exit (EXIT_FAILURE ); + } +/* XXX: fix this */ memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , -0x08000000 ); + machine->ram_size); ram_bases[0 ] =0 ; - ram_sizes[0 ] =0x08000000 ; + ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); ram_bases[1 ] =0x00000000 ; ram_sizes[1 ] =0x00000000 ; - ram_size =128 * MiB; env =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );/* allocate SRAM */
@@ -227,7 +234,7 @@ static void ref405ep_init(MachineState *machine)if (linux_boot) {memset (&bd,0 ,sizeof (bd)); bd.bi_memstart =0x00000000 ; - bd.bi_memsize = ram_size; + bd.bi_memsize = machine->ram_size; bd.bi_flashstart = -bios_size; bd.bi_flashsize = -bios_size; bd.bi_flashoffset =0 ;
@@ -255,7 +262,7 @@ static void ref405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );
@@ -266,7 +273,7 @@ static void ref405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);
@@ -304,6 +311,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo ref405ep_type = {
@@ -408,7 +416,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)static void taihu_405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *initrd_filename = machine->initrd_filename;char *filename;
@@ -425,10 +433,14 @@ static void taihu_405ep_init(MachineState *machine)int fl_idx;DriveInfo *dinfo; -/* RAM is soldered to the board so the size cannot be changed */ - ram_size =0x08000000 ; +if (machine->ram_size != mc->default_ram_size) { +char *sz =size_to_str (mc->default_ram_size); +error_report ("Invalid RAM size, should be %s" , sz); +g_free (sz); +exit (EXIT_FAILURE ); + }memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - ram_size); + machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;
@@ -500,7 +512,7 @@ static void taihu_405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );
@@ -509,7 +521,7 @@ static void taihu_405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);
@@ -533,6 +545,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo taihu_type = {
Signature · 1 line
2.7.4
Re: [PATCH v2 64/86] ppc:ppc405_boards: add RAM size checks
In reply to Igor MammedovQuoted 6 lines · Igor Mammedov
If user provided non-sense RAM size, board will ignore it and continue running with fixed RAM size.
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix CLI.
Quoted 8 lines
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
PS:
move fixed RAM size intomc->default_ram_size, so that generic code will know how much to allocate.Signed-off-by Igor Mammedov <[email protected]>
Wow, that's spectacularly broken.
Quoted 135 lines
---
v2:
* fix format string causing build failure on 32-bit host (Philippe Mathieu-Daudé <[email protected]>)--- hw/ppc/ppc405_boards.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-)hw/ppc/ppc405_boards.c +23
-13@@ -137,7 +137,7 @@ static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)static void ref405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -161,15 +161,20 @@ static void ref405ep_init(MachineState *machine)DriveInfo *dinfo;MemoryRegion *sysmem =get_system_memory (); +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + } +/* XXX: fix this */ memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , -0x08000000 ); + machine->ram_size); ram_bases[0 ] =0 ; - ram_sizes[0 ] =0x08000000 ; + ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 ); ram_bases[1 ] =0x00000000 ; ram_sizes[1 ] =0x00000000 ; - ram_size =128 * MiB; env =ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );/* allocate SRAM */ @@ -227,7 +232,7 @@ static void ref405ep_init(MachineState *machine)if (linux_boot) {memset (&bd,0 ,sizeof (bd)); bd.bi_memstart =0x00000000 ; - bd.bi_memsize = ram_size; + bd.bi_memsize = machine->ram_size; bd.bi_flashstart = -bios_size; bd.bi_flashsize = -bios_size; bd.bi_flashoffset =0 ;@@ -255,7 +260,7 @@ static void ref405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );@@ -266,7 +271,7 @@ static void ref405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);@@ -304,6 +309,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo ref405ep_type = {@@ -408,7 +414,7 @@ static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)static void taihu_405ep_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size; +MachineClass *mc =MACHINE_GET_CLASS (machine);const char *kernel_filename = machine->kernel_filename;const char *initrd_filename = machine->initrd_filename;char *filename;@@ -425,10 +431,13 @@ static void taihu_405ep_init(MachineState *machine)int fl_idx;DriveInfo *dinfo; -/* RAM is soldered to the board so the size cannot be changed */ - ram_size =0x08000000 ; +if (machine->ram_size != mc->default_ram_size) { +error_report ("Invalid RAM size, should be " RAM_ADDR_UFMT " Bytes" , + mc->default_ram_size); +exit (EXIT_FAILURE ); + }memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - ram_size); + machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;@@ -500,7 +509,7 @@ static void taihu_405ep_init(MachineState *machine) kernel_base =KERNEL_LOAD_ADDR ;/* now we can load the kernel */ kernel_size =load_image_targphys (kernel_filename, kernel_base, - ram_size - kernel_base); + machine->ram_size - kernel_base);if (kernel_size <0 ) {error_report ("could not load kernel '%s'" , kernel_filename);exit (1 );@@ -509,7 +518,7 @@ static void taihu_405ep_init(MachineState *machine)if (initrd_filename) { initrd_base =INITRD_LOAD_ADDR ; initrd_size =load_image_targphys (initrd_filename, initrd_base, - ram_size - initrd_base); + machine->ram_size - initrd_base);if (initrd_size <0 ) {error_report ("could not load initial ram disk '%s'" , initrd_filename);@@ -533,6 +542,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; + mc->default_ram_size =0x08000000 ; }static const TypeInfo taihu_type = {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 65/86 ppc:ppc405_boards: use memdev for RAM
In reply to Igor Mammedovmemory_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.
PS:
in ref405ep alias RAM into ram_memories[] to avoid re-factoring its user ppc405ep_init(), which would be invasive and out of scope this patch.
---
CC: [email protected]
CC: [email protected]
--- hw/ppc/ppc405_boards.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
hw/ppc/ppc405_boards.c +6 -7
@@ -168,8 +168,8 @@ static void ref405ep_init(MachineState *machine) }/* XXX: fix this */ -memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , - machine->ram_size); +memory_region_init_alias (&ram_memories[0 ],NULL ,"ef405ep.ram.alias" , + machine->ram,0 , machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 );
@@ -310,6 +310,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo ref405ep_type = {
@@ -422,7 +423,6 @@ static void taihu_405ep_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();MemoryRegion *bios;MemoryRegion *ram_memories =g_new (MemoryRegion,2 ); -MemoryRegion *ram =g_malloc0 (sizeof (*ram));hwaddr ram_bases[2 ], ram_sizes[2 ];long bios_size;target_ulong kernel_base, initrd_base;
@@ -436,18 +436,16 @@ static void taihu_405ep_init(MachineState *machine) mc->default_ram_size);exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;memory_region_init_alias (&ram_memories[0 ],NULL , -"taihu_405ep.ram-0" , ram, ram_bases[0 ], +"taihu_405ep.ram-0" , machine->ram, ram_bases[0 ], ram_sizes[0 ]); ram_bases[1 ] =0x04000000 ; ram_sizes[1 ] =0x04000000 ;memory_region_init_alias (&ram_memories[1 ],NULL , -"taihu_405ep.ram-1" , ram, ram_bases[1 ], +"taihu_405ep.ram-1" , machine->ram, ram_bases[1 ], ram_sizes[1 ]);ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );
@@ -543,6 +541,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo taihu_type = {
Signature · 1 line
2.7.4
Re: [PATCH v2 65/86] ppc:ppc405_boards: use memdev for RAM
Quoted 8 lines · Igor Mammedov
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 usingMachineState::raminstead of manually initializing RAM memory region.
Quoted 6 lines
PS:
in ref405ep alias RAM into ram_memories[] to avoid re-factoring its userppc405ep_init(), which would be invasive and out of scope this patch.Signed-off-by Igor Mammedov <[email protected]>
Quoted 67 lines
---
CC: [email protected]
CC: [email protected]--- hw/ppc/ppc405_boards.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)hw/ppc/ppc405_boards.c +6
-7@@ -168,8 +168,8 @@ static void ref405ep_init(MachineState *machine) }/* XXX: fix this */ -memory_region_allocate_system_memory (&ram_memories[0 ],NULL ,"ef405ep.ram" , - machine->ram_size); +memory_region_init_alias (&ram_memories[0 ],NULL ,"ef405ep.ram.alias" , + machine->ram,0 , machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] = machine->ram_size;memory_region_init (&ram_memories[1 ],NULL ,"ef405ep.ram1" ,0 );@@ -310,6 +310,7 @@ static void ref405ep_class_init(ObjectClass *oc, void *data) mc->desc ="ref405ep" ; mc->init = ref405ep_init; mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo ref405ep_type = {@@ -422,7 +423,6 @@ static void taihu_405ep_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();MemoryRegion *bios;MemoryRegion *ram_memories =g_new (MemoryRegion,2 ); -MemoryRegion *ram =g_malloc0 (sizeof (*ram));hwaddr ram_bases[2 ], ram_sizes[2 ];long bios_size;target_ulong kernel_base, initrd_base;@@ -436,18 +436,16 @@ static void taihu_405ep_init(MachineState *machine) mc->default_ram_size);exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (ram,NULL ,"taihu_405ep.ram" , - machine->ram_size); ram_bases[0 ] =0 ; ram_sizes[0 ] =0x04000000 ;memory_region_init_alias (&ram_memories[0 ],NULL , -"taihu_405ep.ram-0" , ram, ram_bases[0 ], +"taihu_405ep.ram-0" , machine->ram, ram_bases[0 ], ram_sizes[0 ]); ram_bases[1 ] =0x04000000 ; ram_sizes[1 ] =0x04000000 ;memory_region_init_alias (&ram_memories[1 ],NULL , -"taihu_405ep.ram-1" , ram, ram_bases[1 ], +"taihu_405ep.ram-1" , machine->ram, ram_bases[1 ], ram_sizes[1 ]);ppc405ep_init (sysmem, ram_memories, ram_bases, ram_sizes,33333333 , &pic, kernel_filename ==NULL ?0 :1 );@@ -543,6 +541,7 @@ static void taihu_class_init(ObjectClass *oc, void *data) mc->desc ="taihu" ; mc->init = taihu_405ep_init; mc->default_ram_size =0x08000000 ; + mc->default_ram_id ="ef405ep.ram" ; }static const TypeInfo taihu_type = {
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 66/86 ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup
In reply to Igor MammedovIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926: find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAM
---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
--- include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)
include/hw/ppc/ppc4xx.h +4 -5
@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],
hw/ppc/ppc440_bamboo.c +4 -7
@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_prep (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );
@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",
@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );
hw/ppc/ppc4xx_devs.c +29 -27
86 lines not on this page · raw message
hw/ppc/sam460ex.c +2 -3
@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_prep (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Signature · 1 line
2.7.4
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup
Subject line is still wrong, it's sam460ex not sam460x. Also you change ppc:whatever to ppc/whatever here but left : as path separator in all other patches. This is not consistent with other commits where the tag in the title is usually a path of the changed part or in this case could be ppc/ arm/ etc. Colon as path separator looks weird so I think this change should be done for all patches to match other commits not just this one,
Quoted 14 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAM
Quoted 5 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
Thanks but prep is not a good name in PPC context as one of the arch standards is also called that (PowerPC Reference Platform or PReP) so using that here is ambiguous. Better spell it out or call it something else (such as ppc4xx_sdram_banks).
Quoted 130 lines
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +4
-7@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_prep (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +14
-8@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;@@ -690,7 +690,11 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) { + ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; } }if (!size_left) {@@ -699,34 +703,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { + g_string_append_printf(s, "%" PRIi64 "%s",
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 721
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +10
-0+ sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i + 1] ? " ," : ""); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE );
This is certainly better than to just bail out and let the user wonder what would work but I've not yet given up to keep current functionality (also for other boards where this series would drop it). If you don't like a generic callback then how about letting the board optionally specify in the machine class next to default_ram_size some constraints such as min_ram_size, max_ram_size and an array of valid_ram_sizes (like ppc460ex_sdram_bank_sizes[]) that the generic code doing the allocation could check and clamp sizes to the nearest valid one emitting a warning and only bail out if constraints are not given. This would cover most cases expect the e500 where it has an alignment without max so representing it as a list of valid values is probably not practical (could also have ram_alignment but then a generic callback may be simpler). Would that way work for you?
Regards,
BALATON Zoltan
Quoted 49 lines
hw/ppc/ppc4xx_devs.c +5
-19}memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_prep (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup
Quoted 28 lines · On Wed, 15 Jan 2020 22:33:46 +0100 (CET) BALATON Zoltan <[email protected]>…
Subject line is still wrong, it's sam460ex not sam460x. Also you change ppc:whatever to ppc/whatever here but left : as path separator in all other patches. This is not consistent with other commits where the tag in the title is usually a path of the changed part or in this case could be ppc/ arm/ etc. Colon as path separator looks weird so I think this change should be done for all patches to match other commits not just this one,
Quoted 14 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMQuoted 5 lines
Signed-off-by Igor Mammedov <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
Quoted 4 lines
Thanks but prep is not a good name in PPC context as one of the arch standards is also called that (PowerPC Reference Platform or PReP) so using that here is ambiguous. Better spell it out or call it something else (such as
ppc4xx_sdram_banks).
Thanks, I'll change it as suggested
Quoted 136 lines
Quoted 136 lines
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +4
-7@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_prep (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +19
-8@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;@@ -690,7 +690,11 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) { + ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; } }if (!size_left) {@@ -699,34 +703,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str);
Quoted 8 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 721
Quoted 5 lines
hw/ppc/ppc4xx_devs.c +5
-0+error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE );This is certainly better than to just bail out and let the user wonder what would work
v2 basically works the same as original code, except of that instead of fixing up ram_size, it ask user to fix CLI to the same value.
Quoted 4 lines
but I've not yet given up to keep current functionality
(also for other boards where this series would drop it). If you don't like a generic callback then how about letting the board optionally specify in the machine class next todefault_ram_sizesome constraints such as
Quoted 8 lines
min_ram_size,max_ram_sizeand an array ofvalid_ram_sizes(like ppc460ex_sdram_bank_sizes[]) that the generic code doing the allocation could check and clamp sizes to the nearest valid one emitting a warning and only bail out if constraints are not given. This would cover most cases expect the e500 where it has an alignment without max so representing it as a list of valid values is probably not practical (could also haveram_alignmentbut then a generic callback may be simpler). Would that way work for you?
I agree that we need to consolidate ram_size checks, that would allow to clean up boards that practically do the mostly the same. In the end it would allow to introspect supported ram_sizes which would be good for upper layers.
I even started something in that direction but dropped all of that patches as not directly related to this series purpose.
Phillipe is also trying to something like this for raspi board.
As for clamping, I still think that it's not good idea to accept invalid value and fix it up.
Users should get what they asked for or get a clear error (it's double true if user is management software as it won't read any sort of warnings, well not all human users would head warnings either as far as QEMU continues to run)
Anyways, most maintainers agreed to dropping fixups and generalizing checks or generalizing fix up for convenience of users frameworks are out of scope of this series.
Someone can work on these refactorings later on
(assuming someone is enough interested in it)
PS:
If you insist on fixing ram_size up, it would still be possible to do so locally within board. One can take all RAM that user provided and then create clamped memory region alias. It's rather ugly but will do the job without affecting generic code. (though I wouldn't volunteer to write up such a hack)
Quoted 53 lines
Regards,
BALATON ZoltanQuoted 49 lines
hw/ppc/ppc4xx_devs.c +5
-19}memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_prep (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo, sam460x}: drop RAM size fixup
Quoted 3 lines · Igor Mammedov
On Wed, 15 Jan 2020 22:33:46 +0100 (CET)
BALATON Zoltan <[email protected]> wrote:
[...]
Quoted 42 lines
v2 basically works the same as original code, except of that instead of fixing up
ram_size, it ask user to fix CLI to the same value.Quoted 4 lines
but I've not yet given up to keep current functionality
(also for other boards where this series would drop it). If you don't like a generic callback then how about letting the board optionally specify in the machine class next todefault_ram_sizesome constraints such asQuoted 8 lines
min_ram_size,max_ram_sizeand an array ofvalid_ram_sizes(like ppc460ex_sdram_bank_sizes[]) that the generic code doing the allocation could check and clamp sizes to the nearest valid one emitting a warning and only bail out if constraints are not given. This would cover most cases expect the e500 where it has an alignment without max so representing it as a list of valid values is probably not practical (could also haveram_alignmentbut then a generic callback may be simpler). Would that way work for you?I agree that we need to consolidate
ram_sizechecks, that would allow to clean up boards that practically do the mostly the same. In the end it would allow to introspect supportedram_sizeswhich would be good for upper layers.I even started something in that direction but dropped all of that patches as not directly related to this series purpose.
Phillipe is also trying to something like this for raspi board.As for clamping, I still think that it's not good idea to accept invalid value and fix it up.
Users should get what they asked for or get a clear error (it's double true if user is management software as it won't read any sort of warnings, well not all human users would head warnings either as far as QEMU continues to run)Anyways, most maintainers agreed to dropping fixups and generalizing checks or generalizing fix up for convenience of users frameworks are out of scope of this series.
Someone can work on these refactorings later on
(assuming someone is enough interested in it)
Quoted 6 lines
PS:
If you insist on fixingram_sizeup, it would still be possible to do so locally within board. One can take all RAM that user provided and then create clamped memory region alias. It's rather ugly but will do the job without affecting generic code. (though I wouldn't volunteer to write up such a hack)
I think from the virtualization point of view, you don't want to allocate unused resources. Is that why you say it is "ugly"?
From the emulation point of view, it is easier to stay as close as possible to the hardware, where sometimes resources are wasted to simplify the design (or reduce production delays). If it matches hardware, clamping doesn't look "ugly" to me.
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup
Quoted 54 lines · On Fri, 17 Jan 2020 16:38:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 3 lines · Igor Mammedov
On Wed, 15 Jan 2020 22:33:46 +0100 (CET)
BALATON Zoltan <[email protected]> wrote:[...]
Quoted 42 lines
v2 basically works the same as original code, except of that instead of fixing up
ram_size, it ask user to fix CLI to the same value.Quoted 4 lines
but I've not yet given up to keep current functionality
(also for other boards where this series would drop it). If you don't like a generic callback then how about letting the board optionally specify in the machine class next todefault_ram_sizesome constraints such asQuoted 8 lines
min_ram_size,max_ram_sizeand an array ofvalid_ram_sizes(like ppc460ex_sdram_bank_sizes[]) that the generic code doing the allocation could check and clamp sizes to the nearest valid one emitting a warning and only bail out if constraints are not given. This would cover most cases expect the e500 where it has an alignment without max so representing it as a list of valid values is probably not practical (could also haveram_alignmentbut then a generic callback may be simpler). Would that way work for you?I agree that we need to consolidate
ram_sizechecks, that would allow to clean up boards that practically do the mostly the same. In the end it would allow to introspect supportedram_sizeswhich would be good for upper layers.I even started something in that direction but dropped all of that patches as not directly related to this series purpose.
Phillipe is also trying to something like this for raspi board.As for clamping, I still think that it's not good idea to accept invalid value and fix it up.
Users should get what they asked for or get a clear error (it's double true if user is management software as it won't read any sort of warnings, well not all human users would head warnings either as far as QEMU continues to run)Anyways, most maintainers agreed to dropping fixups and generalizing checks or generalizing fix up for convenience of users frameworks are out of scope of this series.
Someone can work on these refactorings later on
(assuming someone is enough interested in it)Quoted 6 lines
PS:
If you insist on fixingram_sizeup, it would still be possible to do so locally within board. One can take all RAM that user provided and then create clamped memory region alias. It's rather ugly but will do the job without affecting generic code. (though I wouldn't volunteer to write up such a hack)
Quoted 8 lines
I think from the virtualization point of view, you don't want to allocate unused resources. Is that why you say it is "ugly"?
From the emulation point of view, it is easier to stay as close as
possible to the hardware, where sometimes resources are wasted to simplify the design (or reduce production delays).
If it matches hardware, clamping doesn't look "ugly" to me.
gist of discussion in this case is that:
bamboo HW supports 4 banks of RAM that could be populated by 256/128/64/32/16/8Mb DIMMs
so -m XXX must be multiple of that, otherwise we are not able distribute all -m specified size between supported banks.
Current patch then would error out with
"Max 4 banks of 256, 128, 64, 32, 16, 8 MB DIMM/bank supported" "Possible valid RAM size: XXX"
where XXX is clamped value original code uses to after fixup
Argument was that it's not convenient for users do what they would do on real hw (i.e. calculate desired size manually based on available banks/DIMMs).
I gave an attempt to dumping all possible sizes and it results in not practically useful unique ~80 entries list, so that idea also goes down the drain.
I agree that it's not convenient, but I think that human user can easily adapt to error message and either fix CLI to use suggested value (i.e. what they are getting now) or pick desired DIMMs number/size and do the math.
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo,sam460x}: drop RAM size fixup
Quoted 66 lines · Igor Mammedov
Quoted 54 lines · On Fri, 17 Jan 2020 16:38:02 +0100 Philippe Mathieu-Daudé <[email protected]>…
Quoted 3 lines · Igor Mammedov
On Wed, 15 Jan 2020 22:33:46 +0100 (CET)
BALATON Zoltan <[email protected]> wrote:[...]
Quoted 42 lines
v2 basically works the same as original code, except of that instead of fixing up
ram_size, it ask user to fix CLI to the same value.Quoted 4 lines
but I've not yet given up to keep current functionality
(also for other boards where this series would drop it). If you don't like a generic callback then how about letting the board optionally specify in the machine class next todefault_ram_sizesome constraints such asQuoted 8 lines
min_ram_size,max_ram_sizeand an array ofvalid_ram_sizes(like ppc460ex_sdram_bank_sizes[]) that the generic code doing the allocation could check and clamp sizes to the nearest valid one emitting a warning and only bail out if constraints are not given. This would cover most cases expect the e500 where it has an alignment without max so representing it as a list of valid values is probably not practical (could also haveram_alignmentbut then a generic callback may be simpler). Would that way work for you?I agree that we need to consolidate
ram_sizechecks, that would allow to clean up boards that practically do the mostly the same. In the end it would allow to introspect supportedram_sizeswhich would be good for upper layers.I even started something in that direction but dropped all of that patches as not directly related to this series purpose.
Phillipe is also trying to something like this for raspi board.As for clamping, I still think that it's not good idea to accept invalid value and fix it up.
Users should get what they asked for or get a clear error (it's double true if user is management software as it won't read any sort of warnings, well not all human users would head warnings either as far as QEMU continues to run)Anyways, most maintainers agreed to dropping fixups and generalizing checks or generalizing fix up for convenience of users frameworks are out of scope of this series.
Someone can work on these refactorings later on
(assuming someone is enough interested in it)Quoted 6 lines
PS:
If you insist on fixingram_sizeup, it would still be possible to do so locally within board. One can take all RAM that user provided and then create clamped memory region alias. It's rather ugly but will do the job without affecting generic code. (though I wouldn't volunteer to write up such a hack)Quoted 8 lines
I think from the virtualization point of view, you don't want to allocate unused resources. Is that why you say it is "ugly"?
From the emulation point of view, it is easier to stay as close as
possible to the hardware, where sometimes resources are wasted to simplify the design (or reduce production delays).
If it matches hardware, clamping doesn't look "ugly" to me.
Quoted 4 lines
gist of discussion in this case is that:
bamboo HW supports 4 banks of RAM that could be populated by 256/128/64/32/16/8Mb DIMMs
I care more about sam460ex but limitations are similar (with different list of supported DIMMs). This comes from how the SoC's memory controller stores memory size (that's similar to how SPD data encodes it) so we can't represent different size.
Quoted 11 lines
so -m XXX must be multiple of that, otherwise we are not able distribute all -m specified size between supported banks.
Current patch then would error out with
"Max 4 banks of 256, 128, 64, 32, 16, 8 MB DIMM/bank supported" "Possible valid RAM size: XXX"
where XXX is clamped value original code uses to after fixupArgument was that it's not convenient for users do what they would do on real hw (i.e. calculate desired size manually based on available banks/DIMMs).
On real hardware one cannot have invalid RAM size because you can only plug DIMMs of above sizes so the problem does not happen. The argument was more that it worked before and now users may find their previously working options to error out. Current version of this patch is better as it gives valid option so the user who does not know about SoC limitations can just use the printed value and doesn't have to calculate valid value.
Quoted 8 lines
I gave an attempt to dumping all possible sizes and it results in not practically useful unique ~80 entries list, so that idea also goes down the drain.
I agree that it's not convenient, but I think that human user can easily adapt to error message and either fix CLI to use suggested value (i.e. what they are getting now) or pick desired DIMMs number/size and do the math.
This version is acceptable and I can live with it. If every other board is happy with returning error then it's OK to do the same here as long as it's easy for users to fix their command line by using the printed value.
Regards,
BALATON Zoltan
PATCH v3 64/84 ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
In reply to BALATON ZoltanIf user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926: find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAM
---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message
--- include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)
include/hw/ppc/ppc4xx.h +4 -5
@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],
hw/ppc/ppc440_bamboo.c +4 -7
@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_banks (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );
@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",
@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );
hw/ppc/ppc4xx_devs.c +29 -27
86 lines not on this page · raw message
hw/ppc/sam460ex.c +2 -3
@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Signature · 1 line
2.7.4
Re: [PATCH v3 64/84] ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
Quoted 181 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>Acked-by David Gibson <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +4
-7@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_banks (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +24
-21@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;@@ -690,7 +690,11 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) { + ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; } }if (!size_left) {@@ -699,34 +703,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size;
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 731
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +5
-4- size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); }
Looking at it once again I'm not sure the above change (and moving the remaining part of the loop in subsequent patch) is really identical. There's a break; in the original second for j loop which the first one's missing so does this still select same bank sizes and wouldn't it create more alias regions than it should after these patches? I have to admit I haven't tried to understand this function because it did what I needed for sam460ex so I don't know if it has any preexisting bugs.
It also appears to rely not only on sdram_bank_sizes[] being 0 terminated but on values being reverse sorted so that should also be mentioned in the comment before the function.
Regards,
BALATON Zoltan
Quoted 22 lines
hw/ppc/ppc4xx_devs.c +0
-2- -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v3 64/84] ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
Quoted 130 lines · On Mon, 20 Jan 2020 18:02:57 +0100 (CET) BALATON Zoltan <[email protected]>…
Quoted 129 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>Acked-by David Gibson <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +4
-7@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_banks (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +5
-5@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;
Quoted 9 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 697
Quoted 9 lines
hw/ppc/ppc4xx_devs.c +4
-0@@ -690,7 +690,11 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) { + ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i;
should be:
+ break;
Quoted 54 lines
Quoted 43 lines
hw/ppc/ppc4xx_devs.c +15
-16} }if (!size_left) {@@ -699,34 +703,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size;hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 731
Quoted 10 lines
hw/ppc/ppc4xx_devs.c +5
-4- size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); }
Quoted 7 lines
Looking at it once again I'm not sure the above change (and moving the remaining part of the loop in subsequent patch) is really identical. There's a break; in the original second for j loop which the first one's missing so does this still select same bank sizes and wouldn't it create more alias regions than it should after these patches? I have to admit I haven't tried to understand this function because it did what I needed for sam460ex so I don't know if it has any preexisting bugs.
It's my bug, thanks for spotting it.
When I combined loops, I should have moved 'reak statement as well to make sure back first matched bank size would be processed and the rest were ignored.
Testing shows that adding missing "break" in the j loop fixes issue and RAM is distributed like in the original code.
Quoted 30 lines
It also appears to rely not only on sdram_bank_sizes[] being 0 terminated but on values being reverse sorted so that should also be mentioned in the comment before the function.
Regards,
BALATON ZoltanQuoted 22 lines
hw/ppc/ppc4xx_devs.c +0
-2- -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
PATCH v3 64/82 ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926: find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAM
---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message
v3.1
* add lost 'break' statement in 'j' loop
--- include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 57 ++++++++++++++++++++++++++----------------------- hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 40 insertions(+), 42 deletions(-)
include/hw/ppc/ppc4xx.h +4 -5
@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],
hw/ppc/ppc440_bamboo.c +4 -7
@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_banks (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );
@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",
@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );
hw/ppc/ppc4xx_devs.c +30 -27
87 lines not on this page · raw message
hw/ppc/sam460ex.c +2 -3
@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Signature · 1 line
2.7.4
Re: [PATCH v3 64/82] ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
Quoted 74 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message
v3.1
* add lost 'break' statement in 'j' loop---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 57 ++++++++++++++++++++++++++----------------------- hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 40 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +0
-1@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;
hw/ppc/ppc440_bamboo.c static void bamboo_init(MachineState *machine) · line 205
Quoted 8 lines
hw/ppc/ppc440_bamboo.c +1
-4@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); + ppc4xx_sdram_banks(ram_size, PPC440EP_SDRAM_NR_BANKS, ram_memories,
Is ram_size still valid here or should this be machine->ram_size as well?
Quoted 49 lines
hw/ppc/ppc440_bamboo.c +3
-2+ ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +5
-5@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 692
Quoted 3 lines
hw/ppc/ppc4xx_devs.c +0
-0@@ -690,7 +690,12 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) {
Does this blow up if values in sdram_bank_sizes are not sorted from big to small? If so this should be noted in the comment above.
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 698
Quoted 6 lines
hw/ppc/ppc4xx_devs.c +5
-0+ ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; +break ;
I'm not sure how it is supposed to work. (I never knew as this is not my code but was there before.) AFAIU the idea was to use as many available bank sizes first on one ram_base before moving on to the next. This does not seem to do that and will go to the next ram after populating the first bank if I understood correctly. But the original code was also not going through with that and in the second loop only used the first bank selected so that does not make much sense.
The problem here is that e.g. sam460ex has only one RAM slot so its firmware does not bother checking any other slot (even if the SoC could handle 4 slots) so unless we put everything (possibly with different banks) in the first RAM slot it won't work. The other constraint is the SoC's memory controller that encodes ram_base and ram_size in a single register and only allows certain sizes.
What happens if we try to set 1.5GB or 768MB? I think SPD could represent that using different bank sizes even if uncommon (I wrote spd_data_generate() in hw/i2c/smbus_eeprom.c but that was a long ago and forgot about it since) but probably the ppc440 SDRAM controller does not have values for this size so not sure if it would work. Currently this functions lets 1.5G and 768M through and that much RAM is allocated but only 1G or 512M will be mapped.
I guess the situation is not worse after your changes with not allocating unmapped RAM, the machine still gets the same amount (only annoying users about it).
Regards,
BALATON Zoltan
Quoted 75 lines
hw/ppc/ppc4xx_devs.c +20
-22} }if (!size_left) {@@ -699,34 +704,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v3 64/82] ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
Quoted 78 lines · On Tue, 21 Jan 2020 20:31:48 +0100 (CET) BALATON Zoltan <[email protected]>…
Quoted 77 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message
v3.1
* add lost 'break' statement in 'j' loop---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 57 ++++++++++++++++++++++++++----------------------- hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 40 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +0
-1@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes));
Quoted 8 lines
hw/ppc/ppc440_bamboo.c static void bamboo_init(MachineState *machine) · line 205
Quoted 5 lines
hw/ppc/ppc440_bamboo.c +1
-4- ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); + ppc4xx_sdram_banks(ram_size, PPC440EP_SDRAM_NR_BANKS, ram_memories,Is
ram_sizestill valid here or should this bemachine->ram_sizeas well?
it is, as there is global ram_size which is equal to machine->ram_size. As for this line I can s/ram_size/machine->ram_size/ on respin if you'd like to.
Cleaning up global ram_size and machine->ram_size should be another series. When all patches from this series get merged it should be easier to remove global ram_size variable altogether and maybe machine->ram_size as well.
Quoted 50 lines
Quoted 50 lines
hw/ppc/ppc440_bamboo.c +3
-2+ ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +5
-5@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;
Quoted 7 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 692
Quoted 4 lines
hw/ppc/ppc4xx_devs.c +0
-0@@ -690,7 +690,12 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) {Does this blow up if values in
sdram_bank_sizesare not sorted from big to small? If so this should be noted in the comment above.
would something like this work for you?
hw/ppc/ppc4xx_devs.c +2 -1
@@ -668,7 +668,8 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,/* Split RAM between SDRAM banks. * -* sdram_bank_sizes[] must be 0-terminated. +* sdram_bank_sizes[] must be sorted by sizes[i] > sizes[i+1] rule +* and must be 0-terminated. * * The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported
Quoted 31 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 698
Quoted 7 lines
hw/ppc/ppc4xx_devs.c +5
-0+ ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; +break ;I'm not sure how it is supposed to work. (I never knew as this is not my code but was there before.) AFAIU the idea was to use as many available bank sizes first on one
ram_basebefore moving on to the next. This does not seem to do that and will go to the next ram after populating the first bank if I understood correctly. But the original code was also not going through with that and in the second loop only used the first bank selected so that does not make much sense.The problem here is that e.g. sam460ex has only one RAM slot so its firmware does not bother checking any other slot (even if the SoC could handle 4 slots) so unless we put everything (possibly with different banks) in the first RAM slot it won't work. The other constraint is the SoC's memory controller that encodes
ram_baseandram_sizein a single register and only allows certain sizes.What happens if we try to set 1.5GB or 768MB? I think SPD could represent that using different bank sizes even if uncommon (I wrote
spd_data_generate()inhw/i2c/smbus_eeprom.cbut that was a long ago and forgot about it since) but probably the ppc440 SDRAM controller does not have values for this size so not sure if it would work. Currently this functions lets 1.5G and 768M through and that much RAM is allocated but only 1G or 512M will be mapped.
Quoted 3 lines
I guess the situation is not worse after your changes with not allocating unmapped RAM, the machine still gets the same amount (only annoying users about it).
Probably it's like you're saying (current logic tries to put as much as RAM into slot as possible and then move to the next slot).
But then rewriting RAM distribution logic is certainly out of scope of this series. And probably should be done by some one who knows how this specific hw is supposed to work.
Quoted 80 lines
Regards,
BALATON ZoltanQuoted 75 lines
hw/ppc/ppc4xx_devs.c +20
-22} }if (!size_left) {@@ -699,34 +704,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v3 64/82] ppc/{ppc440_bamboo,sam460ex}: drop RAM size fixup
Quoted 89 lines · Igor Mammedov
Quoted 78 lines · On Tue, 21 Jan 2020 20:31:48 +0100 (CET) BALATON Zoltan <[email protected]>…
Quoted 77 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size
v3:
* s/ppc4xx_sdram_prep/ppc4xx_sdram_banks/
(BALATON Zoltan <[email protected]>)
* fix subject line in commit message
v3.1
* add lost 'break' statement in 'j' loop---
include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 57 ++++++++++++++++++++++++++----------------------- hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 40 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +0
-1@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes));Quoted 8 lines
hw/ppc/ppc440_bamboo.c static void bamboo_init(MachineState *machine) · line 205
Quoted 5 lines
hw/ppc/ppc440_bamboo.c +1
-4- ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); + ppc4xx_sdram_banks(ram_size, PPC440EP_SDRAM_NR_BANKS, ram_memories,Is
ram_sizestill valid here or should this bemachine->ram_sizeas well?
Quoted 7 lines
it is, as there is global
ram_sizewhich is equal tomachine->ram_size. As for this line I can s/ram_size/machine->ram_size/ on respin if you'd like to.Cleaning up global
ram_sizeandmachine->ram_sizeshould be another series. When all patches from this series get merged it should be easier to remove globalram_sizevariable altogether and maybemachine->ram_sizeas well.
As you see fit. If ram_size is still valid here you can change it in later patch or do it now if you like. I wasn't sure because you seemed to change every other appearance of this and I was not aware of the global with same name.
Using machine->ram_size is probably clearer because 1) it was using that before and 2) function gets machine as parameter so it's easier to see where it comes from than using the global.
(If in future patch you remove both the ram_size global and machine->ram_size how would a machine know how much ram it should have?)
Quoted 63 lines
Quoted 48 lines
Quoted 48 lines
hw/ppc/ppc440_bamboo.c +3
-2+ ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +5
-5@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_banks (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;Quoted 7 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 692
Quoted 4 lines
hw/ppc/ppc4xx_devs.c +0
-0@@ -690,7 +690,12 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) {Does this blow up if values in
sdram_bank_sizesare not sorted from big to small? If so this should be noted in the comment above.would something like this work for you?
hw/ppc/ppc4xx_devs.c +0
-0
hw/ppc/ppc4xx_devs.c void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, · line 671
Quoted 5 lines
hw/ppc/ppc4xx_devs.c +1
-1@@ -668,7 +668,8 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,/* Split RAM between SDRAM banks. * -* sdram_bank_sizes[] must be 0-terminated. +* sdram_bank_sizes[] must be sorted by sizes[i] > sizes[i+1] rule
Maybe: "must be in descending order, that is sizes[i] > sizes[i+1]" just to make it clearer but your version is also correct.
Quoted 39 lines
hw/ppc/ppc4xx_devs.c +1
-0+* and must be 0-terminated. * * The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported Quoted 32 lines
hw/ppc/ppc4xx_devs.c ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, · line 698
Quoted 8 lines
hw/ppc/ppc4xx_devs.c +5
-0+ ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; +break ;I'm not sure how it is supposed to work. (I never knew as this is not my code but was there before.) AFAIU the idea was to use as many available bank sizes first on one
ram_basebefore moving on to the next. This does not seem to do that and will go to the next ram after populating the first bank if I understood correctly. But the original code was also not going through with that and in the second loop only used the first bank selected so that does not make much sense.The problem here is that e.g. sam460ex has only one RAM slot so its firmware does not bother checking any other slot (even if the SoC could handle 4 slots) so unless we put everything (possibly with different banks) in the first RAM slot it won't work. The other constraint is the SoC's memory controller that encodes
ram_baseandram_sizein a single register and only allows certain sizes.What happens if we try to set 1.5GB or 768MB? I think SPD could represent that using different bank sizes even if uncommon (I wrote
spd_data_generate()inhw/i2c/smbus_eeprom.cbut that was a long ago and forgot about it since) but probably the ppc440 SDRAM controller does not have values for this size so not sure if it would work. Currently this functions lets 1.5G and 768M through and that much RAM is allocated but only 1G or 512M will be mapped.Quoted 3 lines
I guess the situation is not worse after your changes with not allocating unmapped RAM, the machine still gets the same amount (only annoying users about it).
Quoted 6 lines
Probably it's like you're saying (current logic tries to put as much as RAM into slot as possible and then move to the next slot).
But then rewriting RAM distribution logic is certainly out of scope of this series. And probably should be done by some one who knows how this specific hw is supposed to work.
Yes, I did not mean you should rewrite it just trying to understand what this function was trying to do and if it still does the same after your patches. I'm still not quite sure but I think this version is good enough now.
Regards,
BALATON Zoltan
Quoted 79 lines
Quoted 76 lines
Quoted 75 lines
hw/ppc/ppc4xx_devs.c +20
-22} }if (!size_left) {@@ -699,34 +704,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_banks (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Re: [PATCH v2 66/86] ppc/{ppc440_bamboo, sam460x}: drop RAM size fixup
In reply to Igor MammedovQuoted 9 lines · Igor Mammedov
If user provided non-sense RAM size, board will complain and continue running with max RAM size supported or sometimes crash like this:
%QEMU -M bamboo -m 1
exec.c:1926:find_ram_offset: Assertion `size != 0' failed. Aborted (core dumped)
Also RAM is going to be allocated by generic code, so it won't be possible for board to fix things up for user.
Quoted 6 lines
Make it error message and exit to force user fix CLI, instead of accepting non-sense CLI values.
That also fixes crash issue, since wrongly calculated size isn't used to allocate RAMSigned-off-by Igor Mammedov <[email protected]>
Quoted 192 lines
---
v2:
* s/ppc4xx_sdram_adjust/ppc4xx_sdram_prep/
(BALATON Zoltan <[email protected]>)
* print possible valid ram size id not all RAM was distributed
* initialize ram_bases/ram_bases at the same time we are checking that user supplied RAM would fit available banks and drop nested loop that were duplicating the same calculations.
* coincidentally fix crash when -m is less than minimal bank size--- include/hw/ppc/ppc4xx.h | 9 ++++---- hw/ppc/ppc440_bamboo.c | 11 ++++------ hw/ppc/ppc4xx_devs.c | 56 +++++++++++++++++++++++++------------------------ hw/ppc/sam460ex.c | 5 ++--- 4 files changed, 39 insertions(+), 42 deletions(-)include/hw/ppc/ppc4xx.h +4
-5@@ -42,11 +42,10 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]); +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]); void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks, MemoryRegion ram_memories[],hw/ppc/ppc440_bamboo.c +4
-7@@ -158,7 +158,6 @@ static void main_cpu_reset(void *opaque)static void bamboo_init (MachineState *machine) { -ram_addr_t ram_size = machine->ram_size;const char *kernel_filename = machine->kernel_filename;const char *kernel_cmdline = machine->kernel_cmdline;const char *initrd_filename = machine->initrd_filename;@@ -203,10 +202,8 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); - ram_size =ppc4xx_sdram_adjust (ram_size,PPC440EP_SDRAM_NR_BANKS , - ram_memories, - ram_bases, ram_sizes, - ppc440ep_sdram_bank_sizes); +ppc4xx_sdram_prep (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, + ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init (env, pic[14 ],PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes,1 );@@ -268,7 +265,7 @@ static void bamboo_init(MachineState *machine)/* Load initrd. */ if (initrd_filename) { initrd_size =load_image_targphys (initrd_filename,RAMDISK_ADDR , - ram_size -RAMDISK_ADDR ); + machine->ram_size -RAMDISK_ADDR );if (initrd_size <0 ) { error_report("could not load ram disk '%s' at %x",@@ -279,7 +276,7 @@ static void bamboo_init(MachineState *machine)/* If we're loading a kernel directly, we must load the device tree too. */ if (kernel_filename) { -if (bamboo_load_device_tree (FDT_ADDR , ram_size,RAMDISK_ADDR , +if (bamboo_load_device_tree (FDT_ADDR , machine->ram_size,RAMDISK_ADDR , initrd_size, kernel_cmdline) <0 ) {error_report ("couldn't load device tree" );exit (1 );hw/ppc/ppc4xx_devs.c +29
-27@@ -673,16 +673,16 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -ram_addr_t ppc4xx_sdram_adjust (ram_addr_t ram_size,int nr_banks, -MemoryRegion ram_memories[], -hwaddr ram_bases[], -hwaddr ram_sizes[], -const ram_addr_t sdram_bank_sizes[]) +void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +MemoryRegion ram_memories[], +hwaddr ram_bases[],hwaddr ram_sizes[], +const ram_addr_t sdram_bank_sizes[]) {MemoryRegion *ram =g_malloc0 (sizeof (*ram));ram_addr_t size_left = ram_size;ram_addr_t base =0 ;ram_addr_t bank_size; +int last_bank =0 ;int i;int j;@@ -690,7 +690,11 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks,for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { bank_size = sdram_bank_sizes[j];if (bank_size <= size_left) { + ram_bases[i] = base; + ram_sizes[i] = bank_size; + base += bank_size; size_left -= bank_size; + last_bank = i; } }if (!size_left) {@@ -699,34 +703,32 @@ ram_addr_t ppc4xx_sdram_adjust(ram_addr_t ram_size, int nr_banks, } } - ram_size -= size_left;if (size_left) { -error_report ("Truncating memory to %" PRId64" MiB to fit SDRAM" -" controller limits" , ram_size / MiB); +ram_addr_t used_size = ram_size - size_left; +GString *s =g_string_new (NULL ); + +for (i =0 ; sdram_bank_sizes[i]; i++) { +g_string_append_printf (s,"%" PRIi64"%s" , + sdram_bank_sizes[i] / MiB, + sdram_bank_sizes[i +1 ] ?" ," :"" ); + } +error_report ("Max %d banks of %s MB DIMM/bank supported" , + nr_banks, s->str); +error_report ("Possible valid RAM size: %" PRIi64, + used_size ? used_size / MiB : sdram_bank_sizes[i -1 ] / MiB); + +g_string_free (s, true); +exit (EXIT_FAILURE ); }memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); - size_left = ram_size; -for (i =0 ; i < nr_banks && size_left; i++) { -for (j =0 ; sdram_bank_sizes[j] !=0 ; j++) { - bank_size = sdram_bank_sizes[j]; - -if (bank_size <= size_left) { -char name[32 ]; -snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); -memory_region_init_alias (&ram_memories[i],NULL , name, ram, - base, bank_size); - ram_bases[i] = base; - ram_sizes[i] = bank_size; - base += bank_size; - size_left -= bank_size; -break ; - } - } +for (i =0 ; i <= last_bank; i++) { +char name[32 ]; +snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i); +memory_region_init_alias (&ram_memories[i],NULL , name, ram, + ram_bases[i], ram_sizes[i]); } - -return ram_size; }/*****************************************************************************/ hw/ppc/sam460ex.c +2
-3@@ -324,9 +324,8 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ - machine->ram_size =ppc4xx_sdram_adjust (machine->ram_size,1 , - ram_memories, ram_bases, ram_sizes, - ppc460ex_sdram_bank_sizes); +ppc4xx_sdram_prep (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, + ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */ ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
PATCH v2 67/86 ppc:ppc440_bamboo/sam460ex: use memdev for RAM
In reply to Igor Mammedovmemory_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.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- include/hw/ppc/ppc4xx.h | 2 +- hw/ppc/ppc440_bamboo.c | 3 ++- hw/ppc/ppc4xx_devs.c | 9 +++------ hw/ppc/sam460ex.c | 3 ++- 4 files changed, 8 insertions(+), 9 deletions(-)
include/hw/ppc/ppc4xx.h +1 -1
@@ -42,7 +42,7 @@ enum {qemu_irq *ppcuic_init (CPUPPCState *env,qemu_irq *irqs,uint32_t dcr_base,int has_ssr,int has_vr); -void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +void ppc4xx_sdram_prep (MemoryRegion *ram,int nr_banks,MemoryRegion ram_memories[],hwaddr ram_bases[],hwaddr ram_sizes[],const ram_addr_t sdram_bank_sizes[]);
hw/ppc/ppc440_bamboo.c +2 -1
@@ -202,7 +202,7 @@ static void bamboo_init(MachineState *machine)/* SDRAM controller */ memset (ram_bases,0 ,sizeof (ram_bases));memset (ram_sizes,0 ,sizeof (ram_sizes)); -ppc4xx_sdram_prep (ram_size,PPC440EP_SDRAM_NR_BANKS , ram_memories, +ppc4xx_sdram_prep (machine->ram,PPC440EP_SDRAM_NR_BANKS , ram_memories, ram_bases, ram_sizes, ppc440ep_sdram_bank_sizes);/* XXX 440EP's ECC interrupts are on UIC1, but we've only created UIC0. */ ppc4xx_sdram_init(env, pic[14], PPC440EP_SDRAM_NR_BANKS, ram_memories,
@@ -289,6 +289,7 @@ static void bamboo_machine_init(MachineClass *mc) mc->desc ="bamboo" ; mc->init = bamboo_init; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("440epb" ); + mc->default_ram_id ="ppc4xx.sdram" ; }DEFINE_MACHINE ("bamboo" , bamboo_machine_init)
hw/ppc/ppc4xx_devs.c +3 -6
@@ -673,13 +673,12 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int nbanks,* The 4xx SDRAM controller supports a small number of banks, and each bank * must be one of a small set of sizes. The number of banks and the supported * sizes varies by SoC. */ -void ppc4xx_sdram_prep (ram_addr_t ram_size,int nr_banks, +void ppc4xx_sdram_prep (MemoryRegion *ram,int nr_banks,MemoryRegion ram_memories[],hwaddr ram_bases[],hwaddr ram_sizes[],const ram_addr_t sdram_bank_sizes[]) { -MemoryRegion *ram =g_malloc0 (sizeof (*ram)); -ram_addr_t size_left = ram_size; +ram_addr_t size_left =memory_region_size (ram);ram_addr_t base =0 ;ram_addr_t bank_size;int last_bank =0 ;
@@ -704,7 +703,7 @@ void ppc4xx_sdram_prep(ram_addr_t ram_size, int nr_banks, }if (size_left) { -ram_addr_t used_size = ram_size - size_left; +ram_addr_t used_size =memory_region_size (ram) - size_left;GString *s =g_string_new (NULL );for (i =0 ; sdram_bank_sizes[i]; i++) {
@@ -721,8 +720,6 @@ void ppc4xx_sdram_prep(ram_addr_t ram_size, int nr_banks,exit (EXIT_FAILURE ); } -memory_region_allocate_system_memory (ram,NULL ,"ppc4xx.sdram" , ram_size); -for (i =0 ; i <= last_bank; i++) {char name[32 ];snprintf (name,sizeof (name),"ppc4xx.sdram%d" , i);
hw/ppc/sam460ex.c +2 -1
@@ -324,7 +324,7 @@ static void sam460ex_init(MachineState *machine)/* SDRAM controller */ /* put all RAM on first bank because board has one slot * and firmware only checks that */ -ppc4xx_sdram_prep (machine->ram_size,1 , ram_memories, ram_bases, ram_sizes, +ppc4xx_sdram_prep (machine->ram,1 , ram_memories, ram_bases, ram_sizes, ppc460ex_sdram_bank_sizes);/* FIXME: does 460EX have ECC interrupts? */
@@ -483,6 +483,7 @@ static void sam460ex_machine_init(MachineClass *mc) mc->init = sam460ex_init; mc->default_cpu_type =POWERPC_CPU_TYPE_NAME ("460exb" ); mc->default_ram_size =512 * MiB; + mc->default_ram_id ="ppc4xx.sdram" ; }DEFINE_MACHINE ("sam460ex" , sam460ex_machine_init)
Signature · 1 line
2.7.4