2011-10-16 00:56:46 +02: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.
|
|
|
|
*/
|
|
|
|
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2011-10-16 00:56:46 +02:00
|
|
|
#include "boards.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "elf.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/memory.h"
|
|
|
|
#include "exec/address-spaces.h"
|
2012-10-17 09:54:19 +02:00
|
|
|
#include "serial.h"
|
2012-10-24 08:43:34 +02:00
|
|
|
#include "net/net.h"
|
2011-10-16 00:56:46 +02:00
|
|
|
#include "sysbus.h"
|
2011-10-30 18:21:15 +01:00
|
|
|
#include "flash.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/blockdev.h"
|
2012-12-17 18:20:05 +01:00
|
|
|
#include "char/char.h"
|
2011-10-30 18:24:26 +01:00
|
|
|
#include "xtensa_bootparam.h"
|
2011-10-30 18:21:15 +01:00
|
|
|
|
|
|
|
typedef struct LxBoardDesc {
|
|
|
|
size_t flash_size;
|
|
|
|
size_t flash_sector_size;
|
|
|
|
size_t sram_size;
|
|
|
|
} LxBoardDesc;
|
2011-10-16 00:56:46 +02: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 12:30:10 +02:00
|
|
|
static uint64_t lx60_fpga_read(void *opaque, hwaddr addr,
|
2011-10-16 00:56:46 +02:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
Lx60FpgaState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case 0x0: /*build date code*/
|
2011-10-30 18:18:27 +01:00
|
|
|
return 0x09272011;
|
2011-10-16 00:56:46 +02: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 12:30:10 +02:00
|
|
|
static void lx60_fpga_write(void *opaque, hwaddr addr,
|
2011-10-16 00:56:46 +02: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 12:30:10 +02:00
|
|
|
hwaddr base)
|
2011-10-16 00:56:46 +02:00
|
|
|
{
|
|
|
|
Lx60FpgaState *s = g_malloc(sizeof(Lx60FpgaState));
|
|
|
|
|
|
|
|
memory_region_init_io(&s->iomem, &lx60_fpga_ops, s,
|
2011-10-30 18:18:27 +01:00
|
|
|
"lx60.fpga", 0x10000);
|
2011-10-16 00:56:46 +02: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 12:30:10 +02:00
|
|
|
hwaddr base,
|
|
|
|
hwaddr descriptors,
|
|
|
|
hwaddr buffers,
|
2011-10-16 00:56:46 +02: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 02:47:33 +01:00
|
|
|
s = SYS_BUS_DEVICE(dev);
|
2011-10-16 00:56:46 +02: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));
|
2011-12-20 14:59:12 +01:00
|
|
|
memory_region_init_ram(ram, "open_eth.ram", 16384);
|
|
|
|
vmstate_register_ram_global(ram);
|
2011-10-16 00:56:46 +02:00
|
|
|
memory_region_add_subregion(address_space, buffers, ram);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t translate_phys_addr(void *env, uint64_t addr)
|
|
|
|
{
|
|
|
|
return cpu_get_phys_page_debug(env, addr);
|
|
|
|
}
|
|
|
|
|
2012-02-08 03:03:33 +01:00
|
|
|
static void lx60_reset(void *opaque)
|
2011-10-16 00:56:46 +02:00
|
|
|
{
|
2012-05-04 19:33:05 +02:00
|
|
|
XtensaCPU *cpu = opaque;
|
2012-02-08 03:03:33 +01:00
|
|
|
|
2012-05-04 19:33:05 +02:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-10-16 00:56:46 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 13:37:51 +02:00
|
|
|
static void lx_init(const LxBoardDesc *board, QEMUMachineInitArgs *args)
|
2011-10-16 00:56:46 +02:00
|
|
|
{
|
|
|
|
#ifdef TARGET_WORDS_BIGENDIAN
|
|
|
|
int be = 1;
|
|
|
|
#else
|
|
|
|
int be = 0;
|
|
|
|
#endif
|
|
|
|
MemoryRegion *system_memory = get_system_memory();
|
2012-05-04 19:31:25 +02:00
|
|
|
XtensaCPU *cpu = NULL;
|
2012-03-14 01:38:24 +01:00
|
|
|
CPUXtensaState *env = NULL;
|
2011-10-16 00:56:46 +02:00
|
|
|
MemoryRegion *ram, *rom, *system_io;
|
2011-10-30 18:21:15 +01:00
|
|
|
DriveInfo *dinfo;
|
|
|
|
pflash_t *flash = NULL;
|
2012-10-25 13:37:51 +02:00
|
|
|
const char *cpu_model = args->cpu_model;
|
|
|
|
const char *kernel_filename = args->kernel_filename;
|
|
|
|
const char *kernel_cmdline = args->kernel_cmdline;
|
2011-10-16 00:56:46 +02:00
|
|
|
int n;
|
|
|
|
|
2011-10-30 18:21:15 +01:00
|
|
|
if (!cpu_model) {
|
2012-08-08 12:07:14 +02:00
|
|
|
cpu_model = XTENSA_DEFAULT_CPU_MODEL;
|
2011-10-30 18:21:15 +01:00
|
|
|
}
|
|
|
|
|
2011-10-16 00:56:46 +02:00
|
|
|
for (n = 0; n < smp_cpus; n++) {
|
2012-05-04 19:31:25 +02:00
|
|
|
cpu = cpu_xtensa_init(cpu_model);
|
|
|
|
if (cpu == NULL) {
|
2011-10-16 00:56:46 +02:00
|
|
|
fprintf(stderr, "Unable to find CPU definition\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-05-04 19:31:25 +02:00
|
|
|
env = &cpu->env;
|
|
|
|
|
2011-10-16 00:56:46 +02:00
|
|
|
env->sregs[PRID] = n;
|
2012-05-04 19:33:05 +02:00
|
|
|
qemu_register_reset(lx60_reset, cpu);
|
2011-10-16 00:56:46 +02:00
|
|
|
/* Need MMU initialized prior to ELF loading,
|
|
|
|
* so that ELF gets loaded into virtual addresses
|
|
|
|
*/
|
2012-05-04 19:31:25 +02:00
|
|
|
cpu_reset(CPU(cpu));
|
2011-10-16 00:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ram = g_malloc(sizeof(*ram));
|
2012-10-25 13:37:51 +02:00
|
|
|
memory_region_init_ram(ram, "lx60.dram", args->ram_size);
|
2011-12-20 14:59:12 +01:00
|
|
|
vmstate_register_ram_global(ram);
|
2011-10-16 00:56:46 +02:00
|
|
|
memory_region_add_subregion(system_memory, 0, ram);
|
|
|
|
|
|
|
|
system_io = g_malloc(sizeof(*system_io));
|
2011-10-30 18:18:27 +01:00
|
|
|
memory_region_init(system_io, "lx60.io", 224 * 1024 * 1024);
|
2011-10-16 00:56:46 +02:00
|
|
|
memory_region_add_subregion(system_memory, 0xf0000000, system_io);
|
|
|
|
lx60_fpga_init(system_io, 0x0d020000);
|
2012-07-24 17:35:11 +02:00
|
|
|
if (nd_table[0].used) {
|
2011-10-16 00:56:46 +02: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-30 18:21:15 +01:00
|
|
|
dinfo = drive_get(IF_PFLASH, 0, 0);
|
|
|
|
if (dinfo) {
|
|
|
|
flash = pflash_cfi01_register(0xf8000000,
|
|
|
|
NULL, "lx60.io.flash", board->flash_size,
|
|
|
|
dinfo->bdrv, board->flash_sector_size,
|
|
|
|
board->flash_size / board->flash_sector_size,
|
|
|
|
4, 0x0000, 0x0000, 0x0000, 0x0000, be);
|
|
|
|
if (flash == NULL) {
|
|
|
|
fprintf(stderr, "Unable to mount pflash\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use presence of kernel file name as 'boot from SRAM' switch. */
|
2011-10-16 00:56:46 +02:00
|
|
|
if (kernel_filename) {
|
2011-10-30 18:24:26 +01:00
|
|
|
rom = g_malloc(sizeof(*rom));
|
2011-12-20 14:59:12 +01:00
|
|
|
memory_region_init_ram(rom, "lx60.sram", board->sram_size);
|
|
|
|
vmstate_register_ram_global(rom);
|
2011-10-30 18:24:26 +01:00
|
|
|
memory_region_add_subregion(system_memory, 0xfe000000, rom);
|
|
|
|
|
|
|
|
/* Put kernel bootparameters to the end of that SRAM */
|
|
|
|
if (kernel_cmdline) {
|
|
|
|
size_t cmdline_size = strlen(kernel_cmdline) + 1;
|
|
|
|
size_t bp_size = sizeof(BpTag[4]) + cmdline_size;
|
|
|
|
uint32_t tagptr = (0xfe000000 + board->sram_size - bp_size) & ~0xff;
|
|
|
|
|
|
|
|
env->regs[2] = tagptr;
|
|
|
|
|
|
|
|
tagptr = put_tag(tagptr, 0x7b0b, 0, NULL);
|
|
|
|
if (cmdline_size > 1) {
|
|
|
|
tagptr = put_tag(tagptr, 0x1001,
|
|
|
|
cmdline_size, kernel_cmdline);
|
|
|
|
}
|
|
|
|
tagptr = put_tag(tagptr, 0x7e0b, 0, NULL);
|
|
|
|
}
|
2011-10-16 00:56:46 +02:00
|
|
|
uint64_t elf_entry;
|
|
|
|
uint64_t elf_lowaddr;
|
|
|
|
int success = load_elf(kernel_filename, translate_phys_addr, env,
|
|
|
|
&elf_entry, &elf_lowaddr, NULL, be, ELF_MACHINE, 0);
|
|
|
|
if (success > 0) {
|
|
|
|
env->pc = elf_entry;
|
|
|
|
}
|
2011-10-30 18:21:15 +01:00
|
|
|
} else {
|
|
|
|
if (flash) {
|
|
|
|
MemoryRegion *flash_mr = pflash_cfi01_get_memory(flash);
|
|
|
|
MemoryRegion *flash_io = g_malloc(sizeof(*flash_io));
|
|
|
|
|
|
|
|
memory_region_init_alias(flash_io, "lx60.flash",
|
|
|
|
flash_mr, 0, board->flash_size);
|
|
|
|
memory_region_add_subregion(system_memory, 0xfe000000,
|
|
|
|
flash_io);
|
|
|
|
}
|
2011-10-16 00:56:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-15 22:22:02 +02:00
|
|
|
static void xtensa_lx60_init(QEMUMachineInitArgs *args)
|
2011-10-16 00:56:46 +02:00
|
|
|
{
|
2011-10-30 18:21:15 +01:00
|
|
|
static const LxBoardDesc lx60_board = {
|
|
|
|
.flash_size = 0x400000,
|
|
|
|
.flash_sector_size = 0x10000,
|
|
|
|
.sram_size = 0x20000,
|
|
|
|
};
|
2012-10-25 13:37:51 +02:00
|
|
|
lx_init(&lx60_board, args);
|
2011-10-30 18:21:15 +01:00
|
|
|
}
|
|
|
|
|
2012-10-15 22:22:02 +02:00
|
|
|
static void xtensa_lx200_init(QEMUMachineInitArgs *args)
|
2011-10-30 18:21:15 +01:00
|
|
|
{
|
|
|
|
static const LxBoardDesc lx200_board = {
|
|
|
|
.flash_size = 0x1000000,
|
|
|
|
.flash_sector_size = 0x20000,
|
|
|
|
.sram_size = 0x2000000,
|
|
|
|
};
|
2012-10-25 13:37:51 +02:00
|
|
|
lx_init(&lx200_board, args);
|
2011-10-16 00:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static QEMUMachine xtensa_lx60_machine = {
|
|
|
|
.name = "lx60",
|
2012-08-08 12:07:14 +02:00
|
|
|
.desc = "lx60 EVB (" XTENSA_DEFAULT_CPU_MODEL ")",
|
2011-10-16 00:56:46 +02:00
|
|
|
.init = xtensa_lx60_init,
|
|
|
|
.max_cpus = 4,
|
2013-01-08 08:06:30 +01:00
|
|
|
DEFAULT_MACHINE_OPTIONS,
|
2011-10-16 00:56:46 +02:00
|
|
|
};
|
|
|
|
|
2011-10-30 18:21:15 +01:00
|
|
|
static QEMUMachine xtensa_lx200_machine = {
|
|
|
|
.name = "lx200",
|
2012-08-08 12:07:14 +02:00
|
|
|
.desc = "lx200 EVB (" XTENSA_DEFAULT_CPU_MODEL ")",
|
2011-10-30 18:21:15 +01:00
|
|
|
.init = xtensa_lx200_init,
|
|
|
|
.max_cpus = 4,
|
2013-01-08 08:06:30 +01:00
|
|
|
DEFAULT_MACHINE_OPTIONS,
|
2011-10-30 18:21:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void xtensa_lx_machines_init(void)
|
2011-10-16 00:56:46 +02:00
|
|
|
{
|
|
|
|
qemu_register_machine(&xtensa_lx60_machine);
|
2011-10-30 18:21:15 +01:00
|
|
|
qemu_register_machine(&xtensa_lx200_machine);
|
2011-10-16 00:56:46 +02:00
|
|
|
}
|
|
|
|
|
2011-10-30 18:21:15 +01:00
|
|
|
machine_init(xtensa_lx_machines_init);
|