From patchwork Sun Oct 30 18:03:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 122655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3F22AB6F77 for ; Mon, 31 Oct 2011 05:04:44 +1100 (EST) Received: from localhost ([::1]:52516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKZkO-0004Px-7M for incoming@patchwork.ozlabs.org; Sun, 30 Oct 2011 14:04:40 -0400 Received: from eggs.gnu.org ([140.186.70.92]:33676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKZjm-0002XY-CG for qemu-devel@nongnu.org; Sun, 30 Oct 2011 14:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RKZjk-0003T4-VL for qemu-devel@nongnu.org; Sun, 30 Oct 2011 14:04:02 -0400 Received: from [188.134.19.124] (port=46218 helo=octofox.metropolis) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RKZjk-0003St-Iu for qemu-devel@nongnu.org; Sun, 30 Oct 2011 14:04:00 -0400 Received: from octofox.metropolis (localhost [127.0.0.1]) by octofox.metropolis (8.14.5/8.14.5) with ESMTP id p9UI3tTV010889; Sun, 30 Oct 2011 22:03:55 +0400 Received: (from jcmvbkbc@localhost) by octofox.metropolis (8.14.5/8.14.5/Submit) id p9UI3tOU010888; Sun, 30 Oct 2011 22:03:55 +0400 From: Max Filippov To: qemu-devel@nongnu.org Date: Sun, 30 Oct 2011 22:03:12 +0400 Message-Id: <1319997794-10542-2-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.7.6.4 In-Reply-To: <1319997794-10542-1-git-send-email-jcmvbkbc@gmail.com> References: <1319997794-10542-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 188.134.19.124 Cc: jcmvbkbc@gmail.com Subject: [Qemu-devel] [PATCH 1/3] xtensa_lx60: add FLASH support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org LX60 carry 4 Mbyte FLASH and 128 Kbyte SRAM, LX200 carry 16 Mbyte FLASH and 32 Mbyte SRAM. Either of these memories may be mapped to the system ROM region. Select boot from FLASH if -kernel option is not specified, otherwise boot from SRAM. Signed-off-by: Max Filippov --- default-configs/xtensa-softmmu.mak | 1 + default-configs/xtensaeb-softmmu.mak | 1 + hw/xtensa_lx60.c | 79 ++++++++++++++++++++++++++++++--- 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/default-configs/xtensa-softmmu.mak b/default-configs/xtensa-softmmu.mak index 7f0df34..9d8899c 100644 --- a/default-configs/xtensa-softmmu.mak +++ b/default-configs/xtensa-softmmu.mak @@ -2,3 +2,4 @@ CONFIG_SERIAL=y CONFIG_OPENCORES_ETH=y +CONFIG_PFLASH_CFI01=y diff --git a/default-configs/xtensaeb-softmmu.mak b/default-configs/xtensaeb-softmmu.mak index 7f0df34..9d8899c 100644 --- a/default-configs/xtensaeb-softmmu.mak +++ b/default-configs/xtensaeb-softmmu.mak @@ -2,3 +2,4 @@ CONFIG_SERIAL=y CONFIG_OPENCORES_ETH=y +CONFIG_PFLASH_CFI01=y diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c index 3cebca1..cb047d2 100644 --- a/hw/xtensa_lx60.c +++ b/hw/xtensa_lx60.c @@ -33,6 +33,13 @@ #include "exec-memory.h" #include "pc.h" #include "sysbus.h" +#include "flash.h" + +typedef struct LxBoardDesc { + size_t flash_size; + size_t flash_sector_size; + size_t sram_size; +} LxBoardDesc; typedef struct Lx60FpgaState { MemoryRegion iomem; @@ -142,8 +149,8 @@ static void lx60_reset(void *env) cpu_reset(env); } -static void lx60_init(ram_addr_t ram_size, - const char *boot_device, +static void lx_init(const LxBoardDesc *board, + ram_addr_t ram_size, const char *boot_device, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { @@ -155,8 +162,14 @@ static void lx60_init(ram_addr_t ram_size, MemoryRegion *system_memory = get_system_memory(); CPUState *env = NULL; MemoryRegion *ram, *rom, *system_io; + DriveInfo *dinfo; + pflash_t *flash = NULL; int n; + if (!cpu_model) { + cpu_model = "dc232b"; + } + for (n = 0; n < smp_cpus; n++) { env = cpu_init(cpu_model); if (!env) { @@ -195,6 +208,20 @@ static void lx60_init(ram_addr_t ram_size, serial_mm_init(system_io, 0x0d050020, 2, xtensa_get_extint(env, 0), 115200, serial_hds[0], DEVICE_NATIVE_ENDIAN); + 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. */ if (kernel_filename) { uint64_t elf_entry; uint64_t elf_lowaddr; @@ -203,6 +230,16 @@ static void lx60_init(ram_addr_t ram_size, if (success > 0) { env->pc = elf_entry; } + } 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); + } } } @@ -211,10 +248,28 @@ static void xtensa_lx60_init(ram_addr_t ram_size, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { - if (!cpu_model) { - cpu_model = "dc232b"; - } - lx60_init(ram_size, boot_device, kernel_filename, kernel_cmdline, + static const LxBoardDesc lx60_board = { + .flash_size = 0x400000, + .flash_sector_size = 0x10000, + .sram_size = 0x20000, + }; + lx_init(&lx60_board, ram_size, boot_device, + kernel_filename, kernel_cmdline, + initrd_filename, cpu_model); +} + +static void xtensa_lx200_init(ram_addr_t ram_size, + const char *boot_device, + const char *kernel_filename, const char *kernel_cmdline, + const char *initrd_filename, const char *cpu_model) +{ + static const LxBoardDesc lx200_board = { + .flash_size = 0x1000000, + .flash_sector_size = 0x20000, + .sram_size = 0x2000000, + }; + lx_init(&lx200_board, ram_size, boot_device, + kernel_filename, kernel_cmdline, initrd_filename, cpu_model); } @@ -225,9 +280,17 @@ static QEMUMachine xtensa_lx60_machine = { .max_cpus = 4, }; -static void xtensa_lx60_machine_init(void) +static QEMUMachine xtensa_lx200_machine = { + .name = "lx200", + .desc = "lx200 EVB (dc232b)", + .init = xtensa_lx200_init, + .max_cpus = 4, +}; + +static void xtensa_lx_machines_init(void) { qemu_register_machine(&xtensa_lx60_machine); + qemu_register_machine(&xtensa_lx200_machine); } -machine_init(xtensa_lx60_machine_init); +machine_init(xtensa_lx_machines_init);