2011-10-16 06:56:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of the Open Source and Linux Lab nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 02:17:21 +08:00
|
|
|
#include "qemu/osdep.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/loader.h"
|
2011-10-16 06:56:46 +08:00
|
|
|
#include "elf.h"
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/memory.h"
|
|
|
|
#include "exec/address-spaces.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/char/serial.h"
|
2012-10-24 14:43:34 +08:00
|
|
|
#include "net/net.h"
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/sysbus.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/block/flash.h"
|
2014-10-07 19:59:13 +08:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-04-08 22:55:25 +08:00
|
|
|
#include "sysemu/char.h"
|
2014-06-23 22:45:43 +08:00
|
|
|
#include "sysemu/device_tree.h"
|
2014-06-21 20:14:56 +08:00
|
|
|
#include "qemu/error-report.h"
|
2014-06-21 14:39:58 +08:00
|
|
|
#include "bootparam.h"
|
2011-10-31 01:21:15 +08:00
|
|
|
|
|
|
|
typedef struct LxBoardDesc {
|
2014-02-02 06:44:41 +08:00
|
|
|
hwaddr flash_base;
|
2011-10-31 01:21:15 +08:00
|
|
|
size_t flash_size;
|
2014-06-20 22:02:10 +08:00
|
|
|
size_t flash_boot_base;
|
2011-10-31 01:21:15 +08:00
|
|
|
size_t flash_sector_size;
|
|
|
|
size_t sram_size;
|
|
|
|
} LxBoardDesc;
|
2011-10-16 06:56:46 +08:00
|
|
|
|
|
|
|
typedef struct Lx60FpgaState {
|
|
|
|
MemoryRegion iomem;
|
|
|
|
uint32_t leds;
|
|
|
|
uint32_t switches;
|
|
|
|
} Lx60FpgaState;
|
|
|
|
|
|
|
|
static void lx60_fpga_reset(void *opaque)
|
|
|
|
{
|
|
|
|
Lx60FpgaState *s = opaque;
|
|
|
|
|
|
|
|
s->leds = 0;
|
|
|
|
s->switches = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static uint64_t lx60_fpga_read(void *opaque, hwaddr addr,
|
2011-10-16 06:56:46 +08:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
Lx60FpgaState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x0: /*build date code*/
|
2011-10-31 01:18:27 +08:00
|
|
|
return 0x09272011;
|
2011-10-16 06:56:46 +08:00
|
|
|
|
|
|
|
case 0x4: /*processor clock frequency, Hz*/
|
|
|
|
return 10000000;
|
|
|
|
|
|
|
|
case 0x8: /*LEDs (off = 0, on = 1)*/
|
|
|
|
return s->leds;
|
|
|
|
|
|
|
|
case 0xc: /*DIP switches (off = 0, on = 1)*/
|
|
|
|
return s->switches;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static void lx60_fpga_write(void *opaque, hwaddr addr,
|
2011-10-16 06:56:46 +08:00
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
Lx60FpgaState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x8: /*LEDs (off = 0, on = 1)*/
|
|
|
|
s->leds = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x10: /*board reset*/
|
|
|
|
if (val == 0xdead) {
|
|
|
|
qemu_system_reset_request();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps lx60_fpga_ops = {
|
|
|
|
.read = lx60_fpga_read,
|
|
|
|
.write = lx60_fpga_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Lx60FpgaState *lx60_fpga_init(MemoryRegion *address_space,
|
2012-10-23 18:30:10 +08:00
|
|
|
hwaddr base)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
|
|
|
Lx60FpgaState *s = g_malloc(sizeof(Lx60FpgaState));
|
|
|
|
|
2013-06-06 17:41:28 +08:00
|
|
|
memory_region_init_io(&s->iomem, NULL, &lx60_fpga_ops, s,
|
2011-10-31 01:18:27 +08:00
|
|
|
"lx60.fpga", 0x10000);
|
2011-10-16 06:56:46 +08:00
|
|
|
memory_region_add_subregion(address_space, base, &s->iomem);
|
|
|
|
lx60_fpga_reset(s);
|
|
|
|
qemu_register_reset(lx60_fpga_reset, s);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lx60_net_init(MemoryRegion *address_space,
|
2012-10-23 18:30:10 +08:00
|
|
|
hwaddr base,
|
|
|
|
hwaddr descriptors,
|
|
|
|
hwaddr buffers,
|
2011-10-16 06:56:46 +08:00
|
|
|
qemu_irq irq, NICInfo *nd)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
|
|
|
MemoryRegion *ram;
|
|
|
|
|
|
|
|
dev = qdev_create(NULL, "open_eth");
|
|
|
|
qdev_set_nic_properties(dev, nd);
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
|
2013-01-20 09:47:33 +08:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2011-10-16 06:56:46 +08:00
|
|
|
sysbus_connect_irq(s, 0, irq);
|
|
|
|
memory_region_add_subregion(address_space, base,
|
|
|
|
sysbus_mmio_get_region(s, 0));
|
|
|
|
memory_region_add_subregion(address_space, descriptors,
|
|
|
|
sysbus_mmio_get_region(s, 1));
|
|
|
|
|
|
|
|
ram = g_malloc(sizeof(*ram));
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 22:51:43 +08:00
|
|
|
memory_region_init_ram(ram, OBJECT(s), "open_eth.ram", 16384,
|
|
|
|
&error_fatal);
|
2011-12-20 21:59:12 +08:00
|
|
|
vmstate_register_ram_global(ram);
|
2011-10-16 06:56:46 +08:00
|
|
|
memory_region_add_subregion(address_space, buffers, ram);
|
|
|
|
}
|
|
|
|
|
2015-09-27 23:21:19 +08:00
|
|
|
static pflash_t *xtfpga_flash_init(MemoryRegion *address_space,
|
|
|
|
const LxBoardDesc *board,
|
|
|
|
DriveInfo *dinfo, int be)
|
|
|
|
{
|
|
|
|
SysBusDevice *s;
|
|
|
|
DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
|
|
|
|
|
|
|
|
qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
|
|
|
|
&error_abort);
|
|
|
|
qdev_prop_set_uint32(dev, "num-blocks",
|
|
|
|
board->flash_size / board->flash_sector_size);
|
|
|
|
qdev_prop_set_uint64(dev, "sector-length", board->flash_sector_size);
|
|
|
|
qdev_prop_set_uint8(dev, "width", 4);
|
|
|
|
qdev_prop_set_bit(dev, "big-endian", be);
|
|
|
|
qdev_prop_set_string(dev, "name", "lx60.io.flash");
|
|
|
|
qdev_init_nofail(dev);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
|
|
|
memory_region_add_subregion(address_space, board->flash_base,
|
|
|
|
sysbus_mmio_get_region(s, 0));
|
|
|
|
return OBJECT_CHECK(pflash_t, (dev), "cfi.pflash01");
|
|
|
|
}
|
|
|
|
|
2013-06-30 00:55:54 +08:00
|
|
|
static uint64_t translate_phys_addr(void *opaque, uint64_t addr)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
2013-06-30 00:55:54 +08:00
|
|
|
XtensaCPU *cpu = opaque;
|
|
|
|
|
|
|
|
return cpu_get_phys_page_debug(CPU(cpu), addr);
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
|
2012-02-08 10:03:33 +08:00
|
|
|
static void lx60_reset(void *opaque)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
2012-05-05 01:33:05 +08:00
|
|
|
XtensaCPU *cpu = opaque;
|
2012-02-08 10:03:33 +08:00
|
|
|
|
2012-05-05 01:33:05 +08:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
|
2014-02-18 00:57:45 +08:00
|
|
|
static uint64_t lx60_io_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lx60_io_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps lx60_io_ops = {
|
|
|
|
.read = lx60_io_read,
|
|
|
|
.write = lx60_io_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2014-05-07 22:42:57 +08:00
|
|
|
static void lx_init(const LxBoardDesc *board, MachineState *machine)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
int be = 1;
|
|
|
|
#else
|
|
|
|
int be = 0;
|
|
|
|
#endif
|
|
|
|
MemoryRegion *system_memory = get_system_memory();
|
2012-05-05 01:31:25 +08:00
|
|
|
XtensaCPU *cpu = NULL;
|
2012-03-14 08:38:24 +08:00
|
|
|
CPUXtensaState *env = NULL;
|
2011-10-16 06:56:46 +08:00
|
|
|
MemoryRegion *ram, *rom, *system_io;
|
2011-10-31 01:21:15 +08:00
|
|
|
DriveInfo *dinfo;
|
|
|
|
pflash_t *flash = NULL;
|
2014-06-23 22:42:39 +08:00
|
|
|
QemuOpts *machine_opts = qemu_get_machine_opts();
|
2014-05-07 22:42:57 +08:00
|
|
|
const char *cpu_model = machine->cpu_model;
|
2014-06-23 22:42:39 +08:00
|
|
|
const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
|
|
|
|
const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
|
2014-06-23 22:45:43 +08:00
|
|
|
const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
|
2014-06-21 17:35:35 +08:00
|
|
|
const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
|
2011-10-16 06:56:46 +08:00
|
|
|
int n;
|
|
|
|
|
2011-10-31 01:21:15 +08:00
|
|
|
if (!cpu_model) {
|
2012-08-08 18:07:14 +08:00
|
|
|
cpu_model = XTENSA_DEFAULT_CPU_MODEL;
|
2011-10-31 01:21:15 +08:00
|
|
|
}
|
|
|
|
|
2011-10-16 06:56:46 +08:00
|
|
|
for (n = 0; n < smp_cpus; n++) {
|
2012-05-05 01:31:25 +08:00
|
|
|
cpu = cpu_xtensa_init(cpu_model);
|
|
|
|
if (cpu == NULL) {
|
2015-02-25 12:22:34 +08:00
|
|
|
error_report("unable to find CPU definition '%s'",
|
2014-06-21 20:14:56 +08:00
|
|
|
cpu_model);
|
|
|
|
exit(EXIT_FAILURE);
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
2012-05-05 01:31:25 +08:00
|
|
|
env = &cpu->env;
|
|
|
|
|
2011-10-16 06:56:46 +08:00
|
|
|
env->sregs[PRID] = n;
|
2012-05-05 01:33:05 +08:00
|
|
|
qemu_register_reset(lx60_reset, cpu);
|
2011-10-16 06:56:46 +08:00
|
|
|
/* Need MMU initialized prior to ELF loading,
|
|
|
|
* so that ELF gets loaded into virtual addresses
|
|
|
|
*/
|
2012-05-05 01:31:25 +08:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ram = g_malloc(sizeof(*ram));
|
2014-09-09 13:27:55 +08:00
|
|
|
memory_region_init_ram(ram, NULL, "lx60.dram", machine->ram_size,
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 22:51:43 +08:00
|
|
|
&error_fatal);
|
2011-12-20 21:59:12 +08:00
|
|
|
vmstate_register_ram_global(ram);
|
2011-10-16 06:56:46 +08:00
|
|
|
memory_region_add_subregion(system_memory, 0, ram);
|
|
|
|
|
|
|
|
system_io = g_malloc(sizeof(*system_io));
|
2014-02-18 00:57:45 +08:00
|
|
|
memory_region_init_io(system_io, NULL, &lx60_io_ops, NULL, "lx60.io",
|
|
|
|
224 * 1024 * 1024);
|
2011-10-16 06:56:46 +08:00
|
|
|
memory_region_add_subregion(system_memory, 0xf0000000, system_io);
|
|
|
|
lx60_fpga_init(system_io, 0x0d020000);
|
2012-07-24 23:35:11 +08:00
|
|
|
if (nd_table[0].used) {
|
2011-10-16 06:56:46 +08:00
|
|
|
lx60_net_init(system_io, 0x0d030000, 0x0d030400, 0x0d800000,
|
|
|
|
xtensa_get_extint(env, 1), nd_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!serial_hds[0]) {
|
|
|
|
serial_hds[0] = qemu_chr_new("serial0", "null", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0),
|
|
|
|
115200, serial_hds[0], DEVICE_NATIVE_ENDIAN);
|
|
|
|
|
2011-10-31 01:21:15 +08:00
|
|
|
dinfo = drive_get(IF_PFLASH, 0, 0);
|
|
|
|
if (dinfo) {
|
2015-09-27 23:21:19 +08:00
|
|
|
flash = xtfpga_flash_init(system_io, board, dinfo, be);
|
2011-10-31 01:21:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use presence of kernel file name as 'boot from SRAM' switch. */
|
2011-10-16 06:56:46 +08:00
|
|
|
if (kernel_filename) {
|
2013-03-04 11:07:52 +08:00
|
|
|
uint32_t entry_point = env->pc;
|
2014-06-23 21:24:48 +08:00
|
|
|
size_t bp_size = 3 * get_tag_size(0); /* first/last and memory tags */
|
2014-06-21 17:10:38 +08:00
|
|
|
uint32_t tagptr = 0xfe000000 + board->sram_size;
|
|
|
|
uint32_t cur_tagptr;
|
2014-06-23 21:24:48 +08:00
|
|
|
BpMemInfo memory_location = {
|
|
|
|
.type = tswap32(MEMORY_TYPE_CONVENTIONAL),
|
|
|
|
.start = tswap32(0),
|
|
|
|
.end = tswap32(machine->ram_size),
|
|
|
|
};
|
2014-06-23 22:45:43 +08:00
|
|
|
uint32_t lowmem_end = machine->ram_size < 0x08000000 ?
|
|
|
|
machine->ram_size : 0x08000000;
|
|
|
|
uint32_t cur_lowmem = QEMU_ALIGN_UP(lowmem_end / 2, 4096);
|
2014-06-21 17:10:38 +08:00
|
|
|
|
2011-10-31 01:24:26 +08:00
|
|
|
rom = g_malloc(sizeof(*rom));
|
2014-09-09 13:27:55 +08:00
|
|
|
memory_region_init_ram(rom, NULL, "lx60.sram", board->sram_size,
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 22:51:43 +08:00
|
|
|
&error_fatal);
|
2011-12-20 21:59:12 +08:00
|
|
|
vmstate_register_ram_global(rom);
|
2011-10-31 01:24:26 +08:00
|
|
|
memory_region_add_subregion(system_memory, 0xfe000000, rom);
|
|
|
|
|
2014-06-21 17:10:38 +08:00
|
|
|
if (kernel_cmdline) {
|
|
|
|
bp_size += get_tag_size(strlen(kernel_cmdline) + 1);
|
|
|
|
}
|
2014-06-23 22:45:43 +08:00
|
|
|
if (dtb_filename) {
|
|
|
|
bp_size += get_tag_size(sizeof(uint32_t));
|
|
|
|
}
|
2014-06-21 17:35:35 +08:00
|
|
|
if (initrd_filename) {
|
|
|
|
bp_size += get_tag_size(sizeof(BpMemInfo));
|
|
|
|
}
|
2014-06-21 17:10:38 +08:00
|
|
|
|
2011-10-31 01:24:26 +08:00
|
|
|
/* Put kernel bootparameters to the end of that SRAM */
|
2014-06-21 17:10:38 +08:00
|
|
|
tagptr = (tagptr - bp_size) & ~0xff;
|
|
|
|
cur_tagptr = put_tag(tagptr, BP_TAG_FIRST, 0, NULL);
|
2014-06-23 21:24:48 +08:00
|
|
|
cur_tagptr = put_tag(cur_tagptr, BP_TAG_MEMORY,
|
|
|
|
sizeof(memory_location), &memory_location);
|
2014-06-21 17:10:38 +08:00
|
|
|
|
2011-10-31 01:24:26 +08:00
|
|
|
if (kernel_cmdline) {
|
2014-06-21 17:10:38 +08:00
|
|
|
cur_tagptr = put_tag(cur_tagptr, BP_TAG_COMMAND_LINE,
|
|
|
|
strlen(kernel_cmdline) + 1, kernel_cmdline);
|
2011-10-31 01:24:26 +08:00
|
|
|
}
|
2014-06-23 22:45:43 +08:00
|
|
|
if (dtb_filename) {
|
|
|
|
int fdt_size;
|
|
|
|
void *fdt = load_device_tree(dtb_filename, &fdt_size);
|
|
|
|
uint32_t dtb_addr = tswap32(cur_lowmem);
|
|
|
|
|
|
|
|
if (!fdt) {
|
2015-02-25 12:22:34 +08:00
|
|
|
error_report("could not load DTB '%s'", dtb_filename);
|
2014-06-23 22:45:43 +08:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_physical_memory_write(cur_lowmem, fdt, fdt_size);
|
|
|
|
cur_tagptr = put_tag(cur_tagptr, BP_TAG_FDT,
|
|
|
|
sizeof(dtb_addr), &dtb_addr);
|
|
|
|
cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + fdt_size, 4096);
|
|
|
|
}
|
2014-06-21 17:35:35 +08:00
|
|
|
if (initrd_filename) {
|
|
|
|
BpMemInfo initrd_location = { 0 };
|
|
|
|
int initrd_size = load_ramdisk(initrd_filename, cur_lowmem,
|
|
|
|
lowmem_end - cur_lowmem);
|
|
|
|
|
|
|
|
if (initrd_size < 0) {
|
|
|
|
initrd_size = load_image_targphys(initrd_filename,
|
|
|
|
cur_lowmem,
|
|
|
|
lowmem_end - cur_lowmem);
|
|
|
|
}
|
|
|
|
if (initrd_size < 0) {
|
2015-02-25 12:22:34 +08:00
|
|
|
error_report("could not load initrd '%s'", initrd_filename);
|
2014-06-21 17:35:35 +08:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
initrd_location.start = tswap32(cur_lowmem);
|
|
|
|
initrd_location.end = tswap32(cur_lowmem + initrd_size);
|
|
|
|
cur_tagptr = put_tag(cur_tagptr, BP_TAG_INITRD,
|
|
|
|
sizeof(initrd_location), &initrd_location);
|
|
|
|
cur_lowmem = QEMU_ALIGN_UP(cur_lowmem + initrd_size, 4096);
|
|
|
|
}
|
2014-06-21 17:10:38 +08:00
|
|
|
cur_tagptr = put_tag(cur_tagptr, BP_TAG_LAST, 0, NULL);
|
|
|
|
env->regs[2] = tagptr;
|
|
|
|
|
2011-10-16 06:56:46 +08:00
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
2013-06-30 00:55:54 +08:00
|
|
|
int success = load_elf(kernel_filename, translate_phys_addr, cpu,
|
2015-05-11 14:29:10 +08:00
|
|
|
&elf_entry, &elf_lowaddr, NULL, be, EM_XTENSA, 0);
|
2011-10-16 06:56:46 +08:00
|
|
|
if (success > 0) {
|
2013-03-04 11:07:52 +08:00
|
|
|
entry_point = elf_entry;
|
|
|
|
} else {
|
|
|
|
hwaddr ep;
|
|
|
|
int is_linux;
|
2014-10-19 11:42:22 +08:00
|
|
|
success = load_uimage(kernel_filename, &ep, NULL, &is_linux,
|
2014-10-19 12:39:10 +08:00
|
|
|
translate_phys_addr, cpu);
|
2013-03-04 11:07:52 +08:00
|
|
|
if (success > 0 && is_linux) {
|
|
|
|
entry_point = ep;
|
|
|
|
} else {
|
2015-02-25 12:22:34 +08:00
|
|
|
error_report("could not load kernel '%s'",
|
2013-03-04 11:07:52 +08:00
|
|
|
kernel_filename);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entry_point != env->pc) {
|
|
|
|
static const uint8_t jx_a0[] = {
|
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
0x0a, 0, 0,
|
|
|
|
#else
|
|
|
|
0xa0, 0, 0,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
env->regs[0] = entry_point;
|
|
|
|
cpu_physical_memory_write(env->pc, jx_a0, sizeof(jx_a0));
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
2011-10-31 01:21:15 +08:00
|
|
|
} else {
|
|
|
|
if (flash) {
|
|
|
|
MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash);
|
|
|
|
MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
|
|
|
|
|
2013-06-06 17:41:28 +08:00
|
|
|
memory_region_init_alias(flash_io, NULL, "lx60.flash",
|
2014-06-20 22:02:10 +08:00
|
|
|
flash_mr, board->flash_boot_base,
|
|
|
|
board->flash_size - board->flash_boot_base < 0x02000000 ?
|
|
|
|
board->flash_size - board->flash_boot_base : 0x02000000);
|
2011-10-31 01:21:15 +08:00
|
|
|
memory_region_add_subregion(system_memory, 0xfe000000,
|
|
|
|
flash_io);
|
|
|
|
}
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 22:42:57 +08:00
|
|
|
static void xtensa_lx60_init(MachineState *machine)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
2011-10-31 01:21:15 +08:00
|
|
|
static const LxBoardDesc lx60_board = {
|
2015-09-27 23:21:19 +08:00
|
|
|
.flash_base = 0x08000000,
|
2014-02-02 06:44:41 +08:00
|
|
|
.flash_size = 0x00400000,
|
2011-10-31 01:21:15 +08:00
|
|
|
.flash_sector_size = 0x10000,
|
|
|
|
.sram_size = 0x20000,
|
|
|
|
};
|
2014-05-07 22:42:57 +08:00
|
|
|
lx_init(&lx60_board, machine);
|
2011-10-31 01:21:15 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 22:42:57 +08:00
|
|
|
static void xtensa_lx200_init(MachineState *machine)
|
2011-10-31 01:21:15 +08:00
|
|
|
{
|
|
|
|
static const LxBoardDesc lx200_board = {
|
2015-09-27 23:21:19 +08:00
|
|
|
.flash_base = 0x08000000,
|
2014-02-02 06:44:41 +08:00
|
|
|
.flash_size = 0x01000000,
|
2011-10-31 01:21:15 +08:00
|
|
|
.flash_sector_size = 0x20000,
|
|
|
|
.sram_size = 0x2000000,
|
|
|
|
};
|
2014-05-07 22:42:57 +08:00
|
|
|
lx_init(&lx200_board, machine);
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 22:42:57 +08:00
|
|
|
static void xtensa_ml605_init(MachineState *machine)
|
2014-02-02 06:44:41 +08:00
|
|
|
{
|
|
|
|
static const LxBoardDesc ml605_board = {
|
2015-09-27 23:21:19 +08:00
|
|
|
.flash_base = 0x08000000,
|
2015-02-17 03:30:21 +08:00
|
|
|
.flash_size = 0x01000000,
|
2014-02-02 06:44:41 +08:00
|
|
|
.flash_sector_size = 0x20000,
|
|
|
|
.sram_size = 0x2000000,
|
|
|
|
};
|
2014-05-07 22:42:57 +08:00
|
|
|
lx_init(&ml605_board, machine);
|
2014-02-02 06:44:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 22:42:57 +08:00
|
|
|
static void xtensa_kc705_init(MachineState *machine)
|
2014-02-02 06:44:41 +08:00
|
|
|
{
|
|
|
|
static const LxBoardDesc kc705_board = {
|
2015-09-27 23:21:19 +08:00
|
|
|
.flash_base = 0x00000000,
|
2014-02-02 06:44:41 +08:00
|
|
|
.flash_size = 0x08000000,
|
2014-06-20 22:02:10 +08:00
|
|
|
.flash_boot_base = 0x06000000,
|
2014-02-02 06:44:41 +08:00
|
|
|
.flash_sector_size = 0x20000,
|
|
|
|
.sram_size = 0x2000000,
|
|
|
|
};
|
2014-05-07 22:42:57 +08:00
|
|
|
lx_init(&kc705_board, machine);
|
2014-02-02 06:44:41 +08:00
|
|
|
}
|
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static void xtensa_lx60_class_init(ObjectClass *oc, void *data)
|
2015-09-05 02:37:08 +08:00
|
|
|
{
|
2015-09-19 16:49:44 +08:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2015-09-05 02:37:08 +08:00
|
|
|
mc->desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
|
|
|
|
mc->init = xtensa_lx60_init;
|
|
|
|
mc->max_cpus = 4;
|
|
|
|
}
|
2011-10-16 06:56:46 +08:00
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static const TypeInfo xtensa_lx60_type = {
|
|
|
|
.name = MACHINE_TYPE_NAME("lx60"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = xtensa_lx60_class_init,
|
|
|
|
};
|
2011-10-31 01:21:15 +08:00
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static void xtensa_lx200_class_init(ObjectClass *oc, void *data)
|
2015-09-05 02:37:08 +08:00
|
|
|
{
|
2015-09-19 16:49:44 +08:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2015-09-05 02:37:08 +08:00
|
|
|
mc->desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
|
|
|
|
mc->init = xtensa_lx200_init;
|
|
|
|
mc->max_cpus = 4;
|
|
|
|
}
|
2014-02-02 06:44:41 +08:00
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static const TypeInfo xtensa_lx200_type = {
|
|
|
|
.name = MACHINE_TYPE_NAME("lx200"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = xtensa_lx200_class_init,
|
|
|
|
};
|
2015-09-05 02:37:08 +08:00
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static void xtensa_ml605_class_init(ObjectClass *oc, void *data)
|
2015-09-05 02:37:08 +08:00
|
|
|
{
|
2015-09-19 16:49:44 +08:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2015-09-05 02:37:08 +08:00
|
|
|
mc->desc = "ml605 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
|
|
|
|
mc->init = xtensa_ml605_init;
|
|
|
|
mc->max_cpus = 4;
|
|
|
|
}
|
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static const TypeInfo xtensa_ml605_type = {
|
|
|
|
.name = MACHINE_TYPE_NAME("ml605"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = xtensa_ml605_class_init,
|
|
|
|
};
|
2014-02-02 06:44:41 +08:00
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static void xtensa_kc705_class_init(ObjectClass *oc, void *data)
|
2011-10-16 06:56:46 +08:00
|
|
|
{
|
2015-09-19 16:49:44 +08:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2015-09-05 02:37:08 +08:00
|
|
|
mc->desc = "kc705 EVB (" XTENSA_DEFAULT_CPU_MODEL ")";
|
|
|
|
mc->init = xtensa_kc705_init;
|
|
|
|
mc->max_cpus = 4;
|
2011-10-16 06:56:46 +08:00
|
|
|
}
|
|
|
|
|
2015-09-19 16:49:44 +08:00
|
|
|
static const TypeInfo xtensa_kc705_type = {
|
|
|
|
.name = MACHINE_TYPE_NAME("kc705"),
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.class_init = xtensa_kc705_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void xtensa_lx_machines_init(void)
|
|
|
|
{
|
|
|
|
type_register_static(&xtensa_lx60_type);
|
|
|
|
type_register_static(&xtensa_lx200_type);
|
|
|
|
type_register_static(&xtensa_ml605_type);
|
|
|
|
type_register_static(&xtensa_kc705_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
machine_init(xtensa_lx_machines_init)
|