Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1ckT-0006he-ML for qemu-devel@nongnu.org; Wed, 06 May 2009 04:45:05 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1ckQ-0006g3-DU for qemu-devel@nongnu.org; Wed, 06 May 2009 04:45:04 -0400 Received: from [199.232.76.173] (port=33358 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1ckP-0006fk-TO for qemu-devel@nongnu.org; Wed, 06 May 2009 04:45:01 -0400 Received: from flounder.pepperfish.net ([87.237.62.181]:50099) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M1ckP-000160-1M for qemu-devel@nongnu.org; Wed, 06 May 2009 04:45:01 -0400 From: Vincent Sanders Date: Wed, 6 May 2009 09:44:54 +0100 Message-Id: <1241599494-28654-16-git-send-email-vince@simtec.co.uk> In-Reply-To: <1241599494-28654-1-git-send-email-vince@simtec.co.uk> References: <1241599494-28654-1-git-send-email-vince@simtec.co.uk> Subject: [Qemu-devel] [PATCH 15/15] Add bast and smdk2410 boards which use S3C2410 SOC List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Vincent Sanders Signed-off-by: Vincent Sanders --- Makefile.target | 1 + hw/bast.c | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/boards.h | 6 ++ hw/smdk2410.c | 120 ++++++++++++++++++++++++++++++++ target-arm/machine.c | 2 + 5 files changed, 316 insertions(+), 0 deletions(-) create mode 100644 hw/bast.c create mode 100644 hw/smdk2410.c diff --git a/Makefile.target b/Makefile.target index b8074ad..e6f74b3 100644 --- a/Makefile.target +++ b/Makefile.target @@ -678,6 +678,7 @@ OBJS+= s3c24xx_memc.o s3c24xx_irq.o s3c24xx_clkcon.o s3c24xx_timers.o OBJS+= s3c24xx_serial.o s3c24xx_rtc.o s3c24xx_gpio.o s3c24xx_iic.o OBJS+= s3c24xx_lcd.o s3c24xx_nand.o OBJS+= s3c2410x.o s3c2440x.o +OBJS+= bast.o smdk2410.o OBJS+= framebuffer.o CPPFLAGS += -DHAS_AUDIO endif diff --git a/hw/bast.c b/hw/bast.c new file mode 100644 index 0000000..1725de4 --- /dev/null +++ b/hw/bast.c @@ -0,0 +1,187 @@ +/* hw/bast.c + * + * System emulation for the Simtec Electronics BAST + * + * Copyright 2006, 2008 Daniel Silverstone and Vincent Sanders + * + * This file is under the terms of the GNU General Public + * License Version 2. + */ + +#include "hw.h" +#include "sysemu.h" +#include "arm-misc.h" +#include "net.h" +#include "smbus.h" +#include "flash.h" +#include "devices.h" +#include "boards.h" + +#include "s3c2410x.h" + +#define BIOS_FILENAME "able.bin" + +typedef struct { + S3CState *soc; + unsigned char cpld_ctrl2; + struct nand_flash_s *nand[4]; +} STCBState; + +/* Bytes in a Kilobyte */ +#define KILO 1024 +/* Bytes in a megabyte */ +#define MEGA 1024 * KILO +/* Bytes */ +#define BYTE 1 +/* Bits in a byte */ +#define BIT 8 + +/* Useful defines */ +#define BAST_NOR_RO_BASE CPU_S3C2410X_CS0 +#define BAST_NOR_RW_BASE (CPU_S3C2410X_CS1 + 0x4000000) +#define BAST_NOR_SIZE 16 * MEGA / BIT +#define BAST_BOARD_ID 331 + +#define BAST_CS1_CPLD_BASE ((target_phys_addr_t)(CPU_S3C2410X_CS1 | (0xc << 23))) +#define BAST_CS5_CPLD_BASE ((target_phys_addr_t)(CPU_S3C2410X_CS5 | (0xc << 23))) +#define BAST_CPLD_SIZE (4<<23) + +static uint32_t cpld_read(void *opaque, target_phys_addr_t address) +{ + STCBState *stcb = (STCBState *)opaque; + int reg = (address >> 23) & 0xf; + if (reg == 0xc) + return stcb->cpld_ctrl2; + return 0; +} + +static void cpld_write(void *opaque, target_phys_addr_t address, + uint32_t value) +{ + STCBState *stcb = (STCBState *)opaque; + int reg = (address >> 23) & 0xf; + if (reg == 0xc) { + stcb->cpld_ctrl2 = value; + s3c24xx_nand_attach(stcb->soc, stcb->nand[stcb->cpld_ctrl2 & 3]); + } +} + +static CPUReadMemoryFunc *cpld_readfn[] = { + cpld_read, + cpld_read, + cpld_read +}; + +static CPUWriteMemoryFunc *cpld_writefn[] = { + cpld_write, + cpld_write, + cpld_write +}; + +static void stcb_cpld_register(STCBState *stcb) +{ + int tag = cpu_register_io_memory(0, cpld_readfn, cpld_writefn, stcb); + cpu_register_physical_memory(BAST_CS1_CPLD_BASE, BAST_CPLD_SIZE, tag); + cpu_register_physical_memory(BAST_CS5_CPLD_BASE, BAST_CPLD_SIZE, tag); + stcb->cpld_ctrl2 = 0; +} + +static void stcb_i2c_setup(STCBState *stcb) +{ + i2c_bus *bus = s3c24xx_i2c_bus(stcb->soc->iic); +} + +static struct arm_boot_info bast_binfo = { + .board_id = BAST_BOARD_ID, + .ram_size = 0x10000000, /* 256MB */ +}; + +static void stcb_init(ram_addr_t _ram_size, + int vga_ram_size, + const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + STCBState *stcb; + int ret, index; + ram_addr_t flash_mem; + BlockDriverState *flash_bds = NULL; + + /* ensure memory is limited to 256MB */ + if (_ram_size > (256 * MEGA * BYTE)) + _ram_size = 256 * MEGA * BYTE; + ram_size = _ram_size; + + /* initialise board informations */ + bast_binfo.ram_size = ram_size; + bast_binfo.kernel_filename = kernel_filename; + bast_binfo.kernel_cmdline = kernel_cmdline; + bast_binfo.initrd_filename = initrd_filename; + bast_binfo.nb_cpus = 1; + bast_binfo.loader_start = BAST_NOR_RO_BASE; + + /* allocate storage for board state */ + stcb = malloc(sizeof(STCBState)); + + /* initialise SOC */ + stcb->soc = s3c2410x_init(ram_size); + + /* Register the NOR flash ROM */ + flash_mem = qemu_ram_alloc(BAST_NOR_SIZE); + + /* Read only ROM type mapping */ + cpu_register_physical_memory(BAST_NOR_RO_BASE, + BAST_NOR_SIZE, + flash_mem | IO_MEM_ROM); + + /* Aquire flash contents and register pflash device */ + index = drive_get_index(IF_PFLASH, 0, 0); + if (index != -1) { + /* load from specified flash device */ + flash_bds = drives_table[index].bdrv; + } else { + /* Try and load default bootloader image */ + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); + ret = load_image_targphys(buf, BAST_NOR_RO_BASE, BAST_NOR_SIZE); + } + pflash_cfi02_register(BAST_NOR_RW_BASE, flash_mem, flash_bds, + 65536, 32, 1, 2, + 0x00BF, 0x234B, 0x0000, 0x0000, 0x5555, 0x2AAA); + + + /* if kernel is given, boot that directly */ + if (kernel_filename != NULL) { + bast_binfo.loader_start = CPU_S3C2410X_RAM; + arm_load_kernel(stcb->soc->cpu_env, &bast_binfo); + } + + /* Setup initial (reset) program counter */ + stcb->soc->cpu_env->regs[15] = bast_binfo.loader_start; + + /* Initialise the BAST CPLD */ + stcb_cpld_register(stcb); + + /* attach i2c devices */ + stcb_i2c_setup(stcb); + + /* Attach some NAND devices */ + stcb->nand[0] = NULL; + stcb->nand[1] = NULL; + index = drive_get_index(IF_MTD, 0, 0); + if (index == -1) + stcb->nand[2] = NULL; + else + stcb->nand[2] = nand_init(0xEC, 0x79); /* 128MiB small-page */ + + /* And we're good to go */ +} + + +QEMUMachine bast_machine = { + .name = "bast", + .desc = "Simtec Electronics BAST (S3C2410A, ARM920T)", + .init = stcb_init, + .max_cpus = 1, +}; diff --git a/hw/boards.h b/hw/boards.h index 5611d2c..327b2b5 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -128,4 +128,10 @@ extern QEMUMachine musicpal_machine; /* tosa.c */ extern QEMUMachine tosapda_machine; +/* bast.c */ +extern QEMUMachine bast_machine; + +/* smdk2410.c */ +extern QEMUMachine smdk2410_machine; + #endif diff --git a/hw/smdk2410.c b/hw/smdk2410.c new file mode 100644 index 0000000..371f2aa --- /dev/null +++ b/hw/smdk2410.c @@ -0,0 +1,120 @@ +/* hw/smdk2410.c + * + * System emulation for the Samsung SMDK2410 + * + * Copyright 2006, 2008 Daniel Silverstone and Vincent Sanders + * + * This file is under the terms of the GNU General Public + * License Version 2. + */ + +#include "hw.h" +#include "sysemu.h" +#include "arm-misc.h" +#include "net.h" +#include "smbus.h" +#include "flash.h" +#include "devices.h" +#include "boards.h" + +#include "s3c2410x.h" + +#define BIOS_FILENAME "smdk2410.bin" + +typedef struct { + S3CState *soc; + unsigned char cpld_ctrl2; + struct nand_flash_s *nand[4]; +} SMDK2410State; + +/* Bytes in a Kilobyte */ +#define KILO 1024 +/* Bytes in a megabyte */ +#define MEGA 1024 * KILO +/* Bytes */ +#define BYTE 1 +/* Bits in a byte */ +#define BIT 8 + +/* Useful defines */ +#define SMDK2410_NOR_BASE CPU_S3C2410X_CS0 +#define SMDK2410_NOR_SIZE 16 * MEGA / BIT +#define SMDK2410_BOARD_ID 193 + +static struct arm_boot_info smdk2410_binfo = { + .board_id = SMDK2410_BOARD_ID, + .ram_size = 0x10000000, /* 256MB */ +}; + +static void smdk2410_init(ram_addr_t _ram_size, + int vga_ram_size, + const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + SMDK2410State *stcb; + int ret, index; + + /* ensure memory is limited to 256MB */ + if (_ram_size > (256 * MEGA * BYTE)) + _ram_size = 256 * MEGA * BYTE; + ram_size = _ram_size; + + /* allocate storage for board state */ + stcb = malloc(sizeof(SMDK2410State)); + + /* initialise CPU and memory */ + stcb->soc = s3c2410x_init(ram_size); + + /* Register the NOR flash ROM */ + cpu_register_physical_memory(SMDK2410_NOR_BASE, + SMDK2410_NOR_SIZE, + qemu_ram_alloc(SMDK2410_NOR_SIZE) | IO_MEM_ROM); + + /* initialise board informations */ + smdk2410_binfo.ram_size = ram_size; + smdk2410_binfo.kernel_filename = kernel_filename; + smdk2410_binfo.kernel_cmdline = kernel_cmdline; + smdk2410_binfo.initrd_filename = initrd_filename; + smdk2410_binfo.nb_cpus = 1; + smdk2410_binfo.loader_start = SMDK2410_NOR_BASE; + + if (kernel_filename == NULL) { + /* No kernel given so try and aquire a bootloader */ + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); + ret = load_image_targphys(buf, smdk2410_binfo.loader_start, SMDK2410_NOR_SIZE); + if (ret <= 0) { + perror("qemu"); + fprintf(stderr, "qemu: warning, could not load SMDK2410 BIOS from %s\n", buf); + exit (1); + } else { + fprintf(stdout, "qemu: info, loaded SMDK2410 BIOS %d bytes from %s\n", ret, buf); + } + } else { + smdk2410_binfo.loader_start = CPU_S3C2410X_RAM; + arm_load_kernel(stcb->soc->cpu_env, &smdk2410_binfo); + } + + /* Setup initial (reset) program counter */ + stcb->soc->cpu_env->regs[15] = smdk2410_binfo.loader_start; + + /* Attach some NAND devices */ + stcb->nand[0] = NULL; + stcb->nand[1] = NULL; + index = drive_get_index(IF_MTD, 0, 0); + if (index == -1) + stcb->nand[2] = NULL; + else + stcb->nand[2] = nand_init(0xEC, 0x79); /* 128MiB small-page */ + +} + + +QEMUMachine smdk2410_machine = { + .name = "smdk2410", + .desc = "Samsung SMDK2410 (S3C2410A, ARM920T)", + .init = smdk2410_init, + .max_cpus = 1, +}; diff --git a/target-arm/machine.c b/target-arm/machine.c index 323bace..ed97185 100644 --- a/target-arm/machine.c +++ b/target-arm/machine.c @@ -7,6 +7,8 @@ void register_machines(void) qemu_register_machine(&versatilepb_machine); qemu_register_machine(&versatileab_machine); qemu_register_machine(&realview_machine); + qemu_register_machine(&bast_machine); + qemu_register_machine(&smdk2410_machine); qemu_register_machine(&akitapda_machine); qemu_register_machine(&spitzpda_machine); qemu_register_machine(&borzoipda_machine); -- 1.5.4.3