2007-04-24 11:40:49 +04:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC 405 evaluation boards emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-04-24 11:40:49 +04:00
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2007-04-24 11:40:49 +04:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-08-12 08:23:38 +03:00
|
|
|
|
2016-01-26 21:16:58 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-25 15:42:24 +03:00
|
|
|
#include "qemu/units.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2020-10-28 14:36:57 +03:00
|
|
|
#include "qemu/datadir.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/ppc/ppc.h"
|
2020-10-16 21:27:38 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
|
|
|
#include "hw/sysbus.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "ppc405.h"
|
2019-10-04 02:03:54 +03:00
|
|
|
#include "hw/rtc/m48t59.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/block/flash.h"
|
2013-08-05 17:27:23 +04:00
|
|
|
#include "sysemu/qtest.h"
|
2019-08-12 08:23:38 +03:00
|
|
|
#include "sysemu/reset.h"
|
2014-10-07 15:59:18 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/boards.h"
|
2013-08-05 17:27:23 +04:00
|
|
|
#include "qemu/error-report.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/loader.h"
|
2020-02-19 19:09:37 +03:00
|
|
|
#include "qemu/cutils.h"
|
2021-12-17 19:57:17 +03:00
|
|
|
#include "elf.h"
|
2007-04-24 11:40:49 +04:00
|
|
|
|
|
|
|
#define BIOS_FILENAME "ppc405_rom.bin"
|
2018-06-25 15:42:24 +03:00
|
|
|
#define BIOS_SIZE (2 * MiB)
|
2007-04-24 11:40:49 +04:00
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
#define KERNEL_LOAD_ADDR 0x01000000
|
2007-04-24 11:40:49 +04:00
|
|
|
#define INITRD_LOAD_ADDR 0x01800000
|
|
|
|
|
2022-08-17 18:08:38 +03:00
|
|
|
#define PPC405EP_SDRAM_BASE 0x00000000
|
|
|
|
#define PPC405EP_SRAM_BASE 0xFFF00000
|
|
|
|
#define PPC405EP_SRAM_SIZE (512 * KiB)
|
|
|
|
|
2007-04-24 11:40:49 +04:00
|
|
|
#define USE_FLASH_BIOS
|
|
|
|
|
2022-08-09 18:38:42 +03:00
|
|
|
#define TYPE_PPC405_MACHINE MACHINE_TYPE_NAME("ppc405")
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(Ppc405MachineState, PPC405_MACHINE);
|
|
|
|
|
|
|
|
struct Ppc405MachineState {
|
|
|
|
/* Private */
|
|
|
|
MachineState parent_obj;
|
|
|
|
/* Public */
|
2022-08-09 18:38:45 +03:00
|
|
|
|
|
|
|
Ppc405SoCState soc;
|
2022-08-09 18:38:42 +03:00
|
|
|
};
|
|
|
|
|
2022-08-17 18:08:38 +03:00
|
|
|
/* CPU reset handler when booting directly from a loaded kernel */
|
2021-12-17 19:57:17 +03:00
|
|
|
static struct boot_info {
|
|
|
|
uint32_t entry;
|
|
|
|
uint32_t bdloc;
|
|
|
|
uint32_t initrd_base;
|
|
|
|
uint32_t initrd_size;
|
|
|
|
uint32_t cmdline_base;
|
|
|
|
uint32_t cmdline_size;
|
|
|
|
} boot_info;
|
|
|
|
|
|
|
|
static void main_cpu_reset(void *opaque)
|
|
|
|
{
|
|
|
|
PowerPCCPU *cpu = opaque;
|
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
struct boot_info *bi = env->load_info;
|
|
|
|
|
|
|
|
cpu_reset(CPU(cpu));
|
|
|
|
|
|
|
|
/* stack: top of sram */
|
|
|
|
env->gpr[1] = PPC405EP_SRAM_BASE + PPC405EP_SRAM_SIZE - 8;
|
|
|
|
|
|
|
|
/* Tune our boot state */
|
|
|
|
env->gpr[3] = bi->bdloc;
|
|
|
|
env->gpr[4] = bi->initrd_base;
|
|
|
|
env->gpr[5] = bi->initrd_base + bi->initrd_size;
|
|
|
|
env->gpr[6] = bi->cmdline_base;
|
|
|
|
env->gpr[7] = bi->cmdline_size;
|
|
|
|
|
|
|
|
env->nip = bi->entry;
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:38 +03:00
|
|
|
/* Bootinfo as set-up by u-boot */
|
|
|
|
typedef struct {
|
|
|
|
uint32_t bi_memstart;
|
|
|
|
uint32_t bi_memsize;
|
|
|
|
uint32_t bi_flashstart;
|
|
|
|
uint32_t bi_flashsize;
|
|
|
|
uint32_t bi_flashoffset; /* 0x10 */
|
|
|
|
uint32_t bi_sramstart;
|
|
|
|
uint32_t bi_sramsize;
|
|
|
|
uint32_t bi_bootflags;
|
|
|
|
uint32_t bi_ipaddr; /* 0x20 */
|
|
|
|
uint8_t bi_enetaddr[6];
|
|
|
|
uint16_t bi_ethspeed;
|
|
|
|
uint32_t bi_intfreq;
|
|
|
|
uint32_t bi_busfreq; /* 0x30 */
|
|
|
|
uint32_t bi_baudrate;
|
|
|
|
uint8_t bi_s_version[4];
|
|
|
|
uint8_t bi_r_version[32];
|
|
|
|
uint32_t bi_procfreq;
|
|
|
|
uint32_t bi_plb_busfreq;
|
|
|
|
uint32_t bi_pci_busfreq;
|
|
|
|
uint8_t bi_pci_enetaddr[6];
|
|
|
|
uint8_t bi_pci_enetaddr2[6]; /* PPC405EP specific */
|
|
|
|
uint32_t bi_opbfreq;
|
|
|
|
uint32_t bi_iic_fast[2];
|
|
|
|
} ppc4xx_bd_info_t;
|
|
|
|
|
|
|
|
static void ppc405_set_default_bootinfo(ppc4xx_bd_info_t *bd,
|
|
|
|
ram_addr_t ram_size)
|
|
|
|
{
|
|
|
|
memset(bd, 0, sizeof(*bd));
|
|
|
|
|
|
|
|
bd->bi_memstart = PPC405EP_SDRAM_BASE;
|
|
|
|
bd->bi_memsize = ram_size;
|
|
|
|
bd->bi_sramstart = PPC405EP_SRAM_BASE;
|
|
|
|
bd->bi_sramsize = PPC405EP_SRAM_SIZE;
|
|
|
|
bd->bi_bootflags = 0;
|
|
|
|
bd->bi_intfreq = 133333333;
|
|
|
|
bd->bi_busfreq = 33333333;
|
|
|
|
bd->bi_baudrate = 115200;
|
|
|
|
bd->bi_s_version[0] = 'Q';
|
|
|
|
bd->bi_s_version[1] = 'M';
|
|
|
|
bd->bi_s_version[2] = 'U';
|
|
|
|
bd->bi_s_version[3] = '\0';
|
|
|
|
bd->bi_r_version[0] = 'Q';
|
|
|
|
bd->bi_r_version[1] = 'E';
|
|
|
|
bd->bi_r_version[2] = 'M';
|
|
|
|
bd->bi_r_version[3] = 'U';
|
|
|
|
bd->bi_r_version[4] = '\0';
|
|
|
|
bd->bi_procfreq = 133333333;
|
|
|
|
bd->bi_plb_busfreq = 33333333;
|
|
|
|
bd->bi_pci_busfreq = 33333333;
|
|
|
|
bd->bi_opbfreq = 33333333;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ram_addr_t __ppc405_set_bootinfo(CPUPPCState *env, ppc4xx_bd_info_t *bd)
|
|
|
|
{
|
|
|
|
CPUState *cs = env_cpu(env);
|
|
|
|
ram_addr_t bdloc;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
/* We put the bd structure at the top of memory */
|
|
|
|
if (bd->bi_memsize >= 0x01000000UL) {
|
|
|
|
bdloc = 0x01000000UL - sizeof(ppc4xx_bd_info_t);
|
|
|
|
} else {
|
|
|
|
bdloc = bd->bi_memsize - sizeof(ppc4xx_bd_info_t);
|
|
|
|
}
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x00, bd->bi_memstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x04, bd->bi_memsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x08, bd->bi_flashstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x0C, bd->bi_flashsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x10, bd->bi_flashoffset);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x14, bd->bi_sramstart);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x18, bd->bi_sramsize);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x1C, bd->bi_bootflags);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x20, bd->bi_ipaddr);
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
stb_phys(cs->as, bdloc + 0x24 + i, bd->bi_enetaddr[i]);
|
|
|
|
}
|
|
|
|
stw_be_phys(cs->as, bdloc + 0x2A, bd->bi_ethspeed);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x2C, bd->bi_intfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x30, bd->bi_busfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x34, bd->bi_baudrate);
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
stb_phys(cs->as, bdloc + 0x38 + i, bd->bi_s_version[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
stb_phys(cs->as, bdloc + 0x3C + i, bd->bi_r_version[i]);
|
|
|
|
}
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x5C, bd->bi_procfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x60, bd->bi_plb_busfreq);
|
|
|
|
stl_be_phys(cs->as, bdloc + 0x64, bd->bi_pci_busfreq);
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
stb_phys(cs->as, bdloc + 0x68 + i, bd->bi_pci_enetaddr[i]);
|
|
|
|
}
|
|
|
|
n = 0x70; /* includes 2 bytes hole */
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
stb_phys(cs->as, bdloc + n++, bd->bi_pci_enetaddr2[i]);
|
|
|
|
}
|
|
|
|
stl_be_phys(cs->as, bdloc + n, bd->bi_opbfreq);
|
|
|
|
n += 4;
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
stl_be_phys(cs->as, bdloc + n, bd->bi_iic_fast[i]);
|
|
|
|
n += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bdloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ram_addr_t ppc405_set_bootinfo(CPUPPCState *env, ram_addr_t ram_size)
|
|
|
|
{
|
|
|
|
ppc4xx_bd_info_t bd;
|
|
|
|
|
|
|
|
memset(&bd, 0, sizeof(bd));
|
|
|
|
|
|
|
|
ppc405_set_default_bootinfo(&bd, ram_size);
|
|
|
|
|
|
|
|
return __ppc405_set_bootinfo(env, &bd);
|
|
|
|
}
|
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
static void boot_from_kernel(MachineState *machine, PowerPCCPU *cpu)
|
|
|
|
{
|
|
|
|
CPUPPCState *env = &cpu->env;
|
|
|
|
hwaddr boot_entry;
|
|
|
|
hwaddr kernel_base;
|
|
|
|
int kernel_size;
|
|
|
|
hwaddr initrd_base;
|
|
|
|
int initrd_size;
|
|
|
|
ram_addr_t bdloc;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
bdloc = ppc405_set_bootinfo(env, machine->ram_size);
|
|
|
|
boot_info.bdloc = bdloc;
|
|
|
|
|
|
|
|
kernel_size = load_elf(machine->kernel_filename, NULL, NULL, NULL,
|
|
|
|
&boot_entry, &kernel_base, NULL, NULL,
|
|
|
|
1, PPC_ELF_MACHINE, 0, 0);
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
error_report("Could not load kernel '%s' : %s",
|
|
|
|
machine->kernel_filename, load_elf_strerror(kernel_size));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
boot_info.entry = boot_entry;
|
|
|
|
|
|
|
|
/* load initrd */
|
|
|
|
if (machine->initrd_filename) {
|
|
|
|
initrd_base = INITRD_LOAD_ADDR;
|
|
|
|
initrd_size = load_image_targphys(machine->initrd_filename, initrd_base,
|
|
|
|
machine->ram_size - initrd_base);
|
|
|
|
if (initrd_size < 0) {
|
|
|
|
error_report("could not load initial ram disk '%s'",
|
|
|
|
machine->initrd_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
boot_info.initrd_base = initrd_base;
|
|
|
|
boot_info.initrd_size = initrd_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (machine->kernel_cmdline) {
|
|
|
|
len = strlen(machine->kernel_cmdline);
|
|
|
|
bdloc -= ((len + 255) & ~255);
|
|
|
|
cpu_physical_memory_write(bdloc, machine->kernel_cmdline, len + 1);
|
|
|
|
boot_info.cmdline_base = bdloc;
|
|
|
|
boot_info.cmdline_size = bdloc + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Install our custom reset handler to start from Linux */
|
|
|
|
qemu_register_reset(main_cpu_reset, cpu);
|
|
|
|
env->load_info = &boot_info;
|
|
|
|
}
|
|
|
|
|
2022-08-09 18:38:43 +03:00
|
|
|
static void ppc405_init(MachineState *machine)
|
2007-04-24 11:40:49 +04:00
|
|
|
{
|
2022-08-09 18:38:45 +03:00
|
|
|
Ppc405MachineState *ppc405 = PPC405_MACHINE(machine);
|
2014-05-07 18:42:57 +04:00
|
|
|
const char *kernel_filename = machine->kernel_filename;
|
2011-09-12 17:43:53 +04:00
|
|
|
MemoryRegion *sysmem = get_system_memory();
|
2007-04-24 11:40:49 +04:00
|
|
|
|
2022-08-09 18:38:45 +03:00
|
|
|
object_initialize_child(OBJECT(machine), "soc", &ppc405->soc,
|
|
|
|
TYPE_PPC405_SOC);
|
|
|
|
object_property_set_link(OBJECT(&ppc405->soc), "dram",
|
|
|
|
OBJECT(machine->ram), &error_abort);
|
2022-08-09 18:38:46 +03:00
|
|
|
object_property_set_uint(OBJECT(&ppc405->soc), "sys-clk", 33333333,
|
|
|
|
&error_abort);
|
2022-08-09 18:38:45 +03:00
|
|
|
qdev_realize(DEVICE(&ppc405->soc), NULL, &error_fatal);
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2007-04-24 11:40:49 +04:00
|
|
|
/* allocate and load BIOS */
|
2021-12-17 19:57:17 +03:00
|
|
|
if (machine->firmware) {
|
|
|
|
MemoryRegion *bios = g_new(MemoryRegion, 1);
|
2022-04-05 15:35:34 +03:00
|
|
|
g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
|
|
|
|
machine->firmware);
|
2021-12-17 19:57:17 +03:00
|
|
|
long bios_size;
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2020-02-24 19:04:51 +03:00
|
|
|
memory_region_init_rom(bios, NULL, "ef405ep.bios", BIOS_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 17:51:43 +03:00
|
|
|
&error_fatal);
|
ppc: fix -mem-path failure
commit e938ba0c tried to enable -mem-path for ppc but breaked some ppc
boards.
The problems are:
1. it fails when allocating memory for rom, sram whose sizes are less
than huge page size:
./ppc-softmmu/qemu-system-ppc -m 512 -mem-path /hugepages/ \
-kernel /home/hutao/Downloads/vmlinux-ppc -initrd \
/home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: /mnt/data/projects/qemu/exec.c:1184: qemu_ram_set_idstr: Assertion `new_block' failed.
2. if there is a numa node backed by memory backend object, qemu fails
with message:
./ppc-softmmu/qemu-system-ppc -m 512 \
-object memory-backend-file,size=512M,mem-path=/hugepages,id=f0 \
-numa node,nodeid=0,memdev=f0 \
-kernel /home/hutao/Downloads/vmlinux-ppc \
-initrd /home/hutao/Downloads/initrd-ppc.gz
qemu-system-ppc: memory backend f0 is used multiple times. Each -numa option must use a different memdev value.
This patch does following:
1. replaces memory_region_allocate_system_memory() with
memory_region_init_ram() for rom, sram. Then only system memory
is backed by hugepages when specifying mem-path.
2. for memory banks, allocates all ram with
one memory_region_allocate_system_memory(), and use
memory_region_init_alias() to initialize memory banks.
Tested machines: default(g3beige), mac99, taihu, bamboo, ref405ep.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2014-07-21 13:30:17 +04:00
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
if (!filename) {
|
|
|
|
error_report("Could not find firmware '%s'", machine->firmware);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bios_size = load_image_size(filename,
|
|
|
|
memory_region_get_ram_ptr(bios),
|
|
|
|
BIOS_SIZE);
|
|
|
|
if (bios_size < 0) {
|
|
|
|
error_report("Could not load PowerPC BIOS '%s'", machine->firmware);
|
2013-08-05 17:27:23 +04:00
|
|
|
exit(1);
|
2009-05-30 03:52:44 +04:00
|
|
|
}
|
2021-12-17 19:57:17 +03:00
|
|
|
|
|
|
|
bios_size = (bios_size + 0xfff) & ~0xfff;
|
|
|
|
memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
|
2007-04-24 11:40:49 +04:00
|
|
|
}
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2021-12-17 19:57:17 +03:00
|
|
|
/* Load kernel and initrd using U-Boot images */
|
|
|
|
if (kernel_filename && machine->firmware) {
|
|
|
|
target_ulong kernel_base, initrd_base;
|
|
|
|
long kernel_size, initrd_size;
|
|
|
|
|
2007-04-24 11:40:49 +04:00
|
|
|
kernel_base = KERNEL_LOAD_ADDR;
|
2009-04-10 18:29:45 +04:00
|
|
|
kernel_size = load_image_targphys(kernel_filename, kernel_base,
|
2020-02-19 19:09:37 +03:00
|
|
|
machine->ram_size - kernel_base);
|
2007-04-24 11:40:49 +04:00
|
|
|
if (kernel_size < 0) {
|
hw/ppc: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines were then manually tweaked to pass checkpatch and some curly
braces were added to match QEMU style.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: qemu-ppc@nongnu.org
Conversions that aren't followed by exit() dropped, because they might
be inappropriate.
Also trim trailing punctuation from error messages.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-10-armbru@redhat.com>
2018-02-03 11:43:10 +03:00
|
|
|
error_report("could not load kernel '%s'", kernel_filename);
|
2007-04-24 11:40:49 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2021-12-17 19:57:17 +03:00
|
|
|
|
2007-04-24 11:40:49 +04:00
|
|
|
/* load initrd */
|
2021-12-17 19:57:17 +03:00
|
|
|
if (machine->initrd_filename) {
|
2007-04-24 11:40:49 +04:00
|
|
|
initrd_base = INITRD_LOAD_ADDR;
|
2021-12-17 19:57:17 +03:00
|
|
|
initrd_size = load_image_targphys(machine->initrd_filename,
|
|
|
|
initrd_base,
|
2020-02-19 19:09:37 +03:00
|
|
|
machine->ram_size - initrd_base);
|
2007-04-24 11:40:49 +04:00
|
|
|
if (initrd_size < 0) {
|
hw/ppc: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines were then manually tweaked to pass checkpatch and some curly
braces were added to match QEMU style.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: qemu-ppc@nongnu.org
Conversions that aren't followed by exit() dropped, because they might
be inappropriate.
Also trim trailing punctuation from error messages.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-10-armbru@redhat.com>
2018-02-03 11:43:10 +03:00
|
|
|
error_report("could not load initial ram disk '%s'",
|
2021-12-17 19:57:17 +03:00
|
|
|
machine->initrd_filename);
|
2007-04-24 11:40:49 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2021-12-17 19:57:17 +03:00
|
|
|
|
|
|
|
/* Load ELF kernel and rootfs.cpio */
|
|
|
|
} else if (kernel_filename && !machine->firmware) {
|
2022-09-24 15:28:02 +03:00
|
|
|
ppc4xx_sdram_ddr_enable(&ppc405->soc.sdram);
|
2022-08-09 18:38:47 +03:00
|
|
|
boot_from_kernel(machine, &ppc405->soc.cpu);
|
2007-04-24 11:40:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:08:38 +03:00
|
|
|
static void ppc405_machine_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
|
|
|
mc->desc = "PPC405 generic machine";
|
|
|
|
mc->init = ppc405_init;
|
|
|
|
mc->default_ram_size = 128 * MiB;
|
|
|
|
mc->default_ram_id = "ppc405.ram";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ppc405_machine_type = {
|
|
|
|
.name = TYPE_PPC405_MACHINE,
|
|
|
|
.parent = TYPE_MACHINE,
|
|
|
|
.instance_size = sizeof(Ppc405MachineState),
|
|
|
|
.class_init = ppc405_machine_class_init,
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* PPC405EP reference board (IBM) */
|
|
|
|
/*
|
|
|
|
* Standalone board with:
|
|
|
|
* - PowerPC 405EP CPU
|
|
|
|
* - SDRAM (0x00000000)
|
|
|
|
* - Flash (0xFFF80000)
|
|
|
|
* - SRAM (0xFFF00000)
|
|
|
|
* - NVRAM (0xF0000000)
|
|
|
|
* - FPGA (0xF0300000)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PPC405EP_NVRAM_BASE 0xF0000000
|
|
|
|
#define PPC405EP_FPGA_BASE 0xF0300000
|
|
|
|
#define PPC405EP_FLASH_BASE 0xFFF80000
|
|
|
|
|
|
|
|
#define TYPE_REF405EP_FPGA "ref405ep-fpga"
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(Ref405epFpgaState, REF405EP_FPGA);
|
|
|
|
struct Ref405epFpgaState {
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
|
|
|
MemoryRegion iomem;
|
|
|
|
|
|
|
|
uint8_t reg0;
|
|
|
|
uint8_t reg1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)
|
|
|
|
{
|
|
|
|
Ref405epFpgaState *fpga = opaque;
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x0:
|
|
|
|
ret = fpga->reg0;
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
ret = fpga->reg1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ref405ep_fpga_writeb(void *opaque, hwaddr addr, uint64_t value,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
Ref405epFpgaState *fpga = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x0:
|
|
|
|
/* Read only */
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
fpga->reg1 = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps ref405ep_fpga_ops = {
|
|
|
|
.read = ref405ep_fpga_readb,
|
|
|
|
.write = ref405ep_fpga_writeb,
|
|
|
|
.impl.min_access_size = 1,
|
|
|
|
.impl.max_access_size = 1,
|
|
|
|
.valid.min_access_size = 1,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ref405ep_fpga_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
Ref405epFpgaState *fpga = REF405EP_FPGA(dev);
|
|
|
|
|
|
|
|
fpga->reg0 = 0x00;
|
|
|
|
fpga->reg1 = 0x0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ref405ep_fpga_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
Ref405epFpgaState *s = REF405EP_FPGA(dev);
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &ref405ep_fpga_ops, s,
|
|
|
|
"fpga", 0x00000100);
|
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ref405ep_fpga_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
|
|
|
|
dc->realize = ref405ep_fpga_realize;
|
|
|
|
dc->reset = ref405ep_fpga_reset;
|
|
|
|
/* Reason: only works as part of a ppc405 board */
|
|
|
|
dc->user_creatable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo ref405ep_fpga_type = {
|
|
|
|
.name = TYPE_REF405EP_FPGA,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Ref405epFpgaState),
|
|
|
|
.class_init = ref405ep_fpga_class_init,
|
|
|
|
};
|
|
|
|
|
2022-08-09 18:38:43 +03:00
|
|
|
static void ref405ep_init(MachineState *machine)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *s;
|
2022-08-09 18:38:44 +03:00
|
|
|
MemoryRegion *sram = g_new(MemoryRegion, 1);
|
2022-08-09 18:38:43 +03:00
|
|
|
|
|
|
|
ppc405_init(machine);
|
|
|
|
|
2022-08-09 18:38:44 +03:00
|
|
|
/* allocate SRAM */
|
|
|
|
memory_region_init_ram(sram, NULL, "ref405ep.sram", PPC405EP_SRAM_SIZE,
|
|
|
|
&error_fatal);
|
|
|
|
memory_region_add_subregion(get_system_memory(), PPC405EP_SRAM_BASE, sram);
|
|
|
|
|
2022-08-09 18:38:43 +03:00
|
|
|
/* Register FPGA */
|
2022-08-17 18:08:37 +03:00
|
|
|
dev = qdev_new(TYPE_REF405EP_FPGA);
|
|
|
|
object_property_add_child(OBJECT(machine), "fpga", OBJECT(dev));
|
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, PPC405EP_FPGA_BASE);
|
|
|
|
|
2022-08-09 18:38:43 +03:00
|
|
|
/* Register NVRAM */
|
|
|
|
dev = qdev_new("sysbus-m48t08");
|
|
|
|
qdev_prop_set_int32(dev, "base-year", 1968);
|
|
|
|
s = SYS_BUS_DEVICE(dev);
|
|
|
|
sysbus_realize_and_unref(s, &error_fatal);
|
|
|
|
sysbus_mmio_map(s, 0, PPC405EP_NVRAM_BASE);
|
|
|
|
}
|
|
|
|
|
2015-09-19 11:49:44 +03:00
|
|
|
static void ref405ep_class_init(ObjectClass *oc, void *data)
|
2015-09-04 21:37:08 +03:00
|
|
|
{
|
2015-09-19 11:49:44 +03:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
|
|
|
|
2015-09-04 21:37:08 +03:00
|
|
|
mc->desc = "ref405ep";
|
|
|
|
mc->init = ref405ep_init;
|
|
|
|
}
|
|
|
|
|
2015-09-19 11:49:44 +03:00
|
|
|
static const TypeInfo ref405ep_type = {
|
|
|
|
.name = MACHINE_TYPE_NAME("ref405ep"),
|
2022-08-09 18:38:42 +03:00
|
|
|
.parent = TYPE_PPC405_MACHINE,
|
2015-09-19 11:49:44 +03:00
|
|
|
.class_init = ref405ep_class_init,
|
|
|
|
};
|
2007-04-24 11:40:49 +04:00
|
|
|
|
2015-09-19 11:49:44 +03:00
|
|
|
static void ppc405_machine_init(void)
|
|
|
|
{
|
2022-08-09 18:38:42 +03:00
|
|
|
type_register_static(&ppc405_machine_type);
|
2015-09-19 11:49:44 +03:00
|
|
|
type_register_static(&ref405ep_type);
|
2022-08-17 18:08:37 +03:00
|
|
|
type_register_static(&ref405ep_fpga_type);
|
2015-09-19 11:49:44 +03:00
|
|
|
}
|
|
|
|
|
2016-02-16 23:59:04 +03:00
|
|
|
type_init(ppc405_machine_init)
|