From patchwork Thu Feb 23 18:52:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 9588841 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 27C2060578 for ; Thu, 23 Feb 2017 19:09:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17A742879E for ; Thu, 23 Feb 2017 19:09:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C25F287F7; Thu, 23 Feb 2017 19:09:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60E082879E for ; Thu, 23 Feb 2017 19:08:59 +0000 (UTC) Received: from localhost ([::1]:60424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgyl8-0001uU-KZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 Feb 2017 14:08:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgyVt-0003fN-8a for qemu-devel@nongnu.org; Thu, 23 Feb 2017 13:53:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgyVo-0005Zn-Ch for qemu-devel@nongnu.org; Thu, 23 Feb 2017 13:53:13 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:35307) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cgyVo-0005WC-45 for qemu-devel@nongnu.org; Thu, 23 Feb 2017 13:53:08 -0500 Received: by mail-pf0-x243.google.com with SMTP id 68so1954369pfx.2 for ; Thu, 23 Feb 2017 10:53:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=7azVcQ54QstrUp5WBYjMSLyiEWehgz51ixQj/9YzxFI=; b=BNKDgXLxrWZRPR83P2oiUl5mqgExcb7s1Lf84zKKZXnZYA7JVepMfGHfV22yZ8ULtJ dHFUHRuXh7GAspNKRXYM1pn5+GZgg5LZepoQVtJe9pHkJrQgzKwiV4uiOVPptWjt1Zaa WRhn5ugBvBm8LD0LpuMHJPmWgGN8vHtlJzoeocYWbcCSePoUpZMUFGufLucaMxFASGfa GqNCEXfRb9449+X/hEE6leUcm9NQ7SllEtbV12+xnxC7SP8+9LE4Ja4Q9xL5QO1zgAbX /m2SocNsImaDNwec9yh0OiqX1JVr/6IFqlYtQem7WNdDN+CNSOdWEDalKF61OZekh8db +cHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=7azVcQ54QstrUp5WBYjMSLyiEWehgz51ixQj/9YzxFI=; b=M5tK4cMlPQ6XDWjpUkjTqoOz3u73GuvC2LiRHu1FF8ZFdWgCgyNTZe1yN5WZ57opuA /riSxvdeFEWOWEwqVepZ8iSrMx2D3+SJc3RSZOoO/gm00q/tfln3Hy0lmZsZEfWbeXdX s2o+GMGZasY+4qi6Snc3AcpHBfoFG04ghsOp1odJrGpJQnJdxiKY34sdnH2m8Ie4mMEl 6RIGUdNyqEKDaUN66UGWj5kHuFNE+JICzHsbMcIkiHz5gj+GrT44MqZJ0wGqrHVIR1Ng Mn+6jqnbLmGt/hdAAhyBAMIxZuk/vGKxmWvrD6AB43/48+9g5Z1bYP6yrTlOY8qOn8ru Y63w== X-Gm-Message-State: AMke39mykRzWYGGTWFovNYuhQsxOOQsF2fS9jxt0VI9lgTmF6WeCij/r3DxoYKygIoI3MA== X-Received: by 10.99.112.75 with SMTP id a11mr49865012pgn.7.1487875985373; Thu, 23 Feb 2017 10:53:05 -0800 (PST) Received: from octofox.metropolis (corp.Cadence.COM. [158.140.1.28]) by smtp.gmail.com with ESMTPSA id p66sm11132334pfb.88.2017.02.23.10.53.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Feb 2017 10:53:04 -0800 (PST) From: Max Filippov To: qemu-devel@nongnu.org Date: Thu, 23 Feb 2017 10:52:48 -0800 Message-Id: <1487875968-23454-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH] target/xtensa: sim: instantiate local memories X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Xtensa core may have a number of RAM and ROM areas configured. Record their size and location from the core configuration overlay and instantiate them as RAM regions in the SIM machine. Signed-off-by: Max Filippov --- hw/xtensa/sim.c | 40 ++++++++--- target/xtensa/cpu.h | 16 +++++ target/xtensa/overlay_tool.h | 160 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+), 9 deletions(-) diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index 5e94004..d2d1d3a 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -37,6 +37,27 @@ #include "exec/address-spaces.h" #include "qemu/error-report.h" +static void xtensa_create_memory_regions(const XtensaMemory *memory, + const char *name) +{ + unsigned i; + char *num_name = malloc(strlen(name) + sizeof(i) * 3 + 1); + + for (i = 0; i < memory->num; ++i) { + MemoryRegion *m; + + sprintf(num_name, "%s%u", name, i); + m = g_malloc(sizeof(*m)); + memory_region_init_ram(m, NULL, num_name, + memory->location[i].size, + &error_fatal); + vmstate_register_ram_global(m); + memory_region_add_subregion(get_system_memory(), + memory->location[i].addr, m); + } + free(num_name); +} + static uint64_t translate_phys_addr(void *opaque, uint64_t addr) { XtensaCPU *cpu = opaque; @@ -55,7 +76,6 @@ static void xtensa_sim_init(MachineState *machine) { XtensaCPU *cpu = NULL; CPUXtensaState *env = NULL; - MemoryRegion *ram, *rom; ram_addr_t ram_size = machine->ram_size; const char *cpu_model = machine->cpu_model; const char *kernel_filename = machine->kernel_filename; @@ -82,15 +102,17 @@ static void xtensa_sim_init(MachineState *machine) sim_reset(cpu); } - ram = g_malloc(sizeof(*ram)); - memory_region_init_ram(ram, NULL, "xtensa.sram", ram_size, &error_fatal); - vmstate_register_ram_global(ram); - memory_region_add_subregion(get_system_memory(), 0, ram); + if (env) { + XtensaMemory sysram = env->config->sysram; - rom = g_malloc(sizeof(*rom)); - memory_region_init_ram(rom, NULL, "xtensa.rom", 0x1000, &error_fatal); - vmstate_register_ram_global(rom); - memory_region_add_subregion(get_system_memory(), 0xfe000000, rom); + sysram.location[0].size = ram_size; + xtensa_create_memory_regions(&env->config->instrom, "xtensa.instrom"); + xtensa_create_memory_regions(&env->config->instram, "xtensa.instram"); + xtensa_create_memory_regions(&env->config->datarom, "xtensa.datarom"); + xtensa_create_memory_regions(&env->config->dataram, "xtensa.dataram"); + xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom"); + xtensa_create_memory_regions(&sysram, "xtensa.sysram"); + } if (kernel_filename) { uint64_t elf_entry; diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index 7e7131a..ecca17d 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -212,6 +212,7 @@ enum { #define MAX_NCCOMPARE 3 #define MAX_TLB_WAY_SIZE 8 #define MAX_NDBREAK 2 +#define MAX_NMEMORY 4 #define REGION_PAGE_MASK 0xe0000000 @@ -321,6 +322,14 @@ typedef struct XtensaCcompareTimer { QEMUTimer *timer; } XtensaCcompareTimer; +typedef struct XtensaMemory { + unsigned num; + struct XtensaMemoryRegion { + uint32_t addr; + uint32_t size; + } location[MAX_NMEMORY]; +} XtensaMemory; + struct XtensaConfig { const char *name; uint64_t options; @@ -352,6 +361,13 @@ struct XtensaConfig { unsigned dcache_ways; uint32_t memctl_mask; + XtensaMemory instrom; + XtensaMemory instram; + XtensaMemory datarom; + XtensaMemory dataram; + XtensaMemory sysrom; + XtensaMemory sysram; + uint32_t configid[2]; uint32_t clock_freq_khz; diff --git a/target/xtensa/overlay_tool.h b/target/xtensa/overlay_tool.h index 38e9be9..12bde44 100644 --- a/target/xtensa/overlay_tool.h +++ b/target/xtensa/overlay_tool.h @@ -318,6 +318,16 @@ .itlb = ITLB(XCHAL_HAVE_SPANNING_WAY), \ .dtlb = DTLB(XCHAL_HAVE_SPANNING_WAY) +#ifndef XCHAL_SYSROM0_PADDR +#define XCHAL_SYSROM0_PADDR 0xfe000000 +#define XCHAL_SYSROM0_SIZE 0x02000000 +#endif + +#ifndef XCHAL_SYSRAM0_PADDR +#define XCHAL_SYSRAM0_PADDR 0x00000000 +#define XCHAL_SYSRAM0_SIZE 0x08000000 +#endif + #elif XCHAL_HAVE_XLT_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR #define TLB_TEMPLATE { \ @@ -331,6 +341,28 @@ .itlb = TLB_TEMPLATE, \ .dtlb = TLB_TEMPLATE +#ifndef XCHAL_SYSROM0_PADDR +#define XCHAL_SYSROM0_PADDR 0x60000000 +#define XCHAL_SYSROM0_SIZE 0x04000000 +#endif + +#ifndef XCHAL_SYSRAM0_PADDR +#define XCHAL_SYSRAM0_PADDR 0x50000000 +#define XCHAL_SYSRAM0_SIZE 0x04000000 +#endif + +#else + +#ifndef XCHAL_SYSROM0_PADDR +#define XCHAL_SYSROM0_PADDR 0x60000000 +#define XCHAL_SYSROM0_SIZE 0x04000000 +#endif + +#ifndef XCHAL_SYSRAM0_PADDR +#define XCHAL_SYSRAM0_PADDR 0x50000000 +#define XCHAL_SYSRAM0_SIZE 0x04000000 +#endif + #endif #if (defined(TARGET_WORDS_BIGENDIAN) != 0) == (XCHAL_HAVE_BE != 0) @@ -362,6 +394,53 @@ MEMCTL_ISNP | MEMCTL_DSNP | \ (XCHAL_HAVE_LOOPS && XCHAL_LOOP_BUFFER_SIZE ? MEMCTL_IL0EN : 0) +#define MEM_LOCATION(name, n) \ + { \ + .addr = XCHAL_ ## name ## n ## _PADDR, \ + .size = XCHAL_ ## name ## n ## _SIZE, \ + } + +#define MEM_SECTIONS(name) \ + MEM_LOCATION(name, 0), \ + MEM_LOCATION(name, 1), \ + MEM_LOCATION(name, 2), \ + MEM_LOCATION(name, 3) + +#define MEM_SECTION(name) \ + .num = XCHAL_NUM_ ## name, \ + .location = { \ + MEM_SECTIONS(name) \ + } + +#define SYSMEM_SECTION(name) \ + .num = 1, \ + .location = { \ + { \ + .addr = XCHAL_ ## name ## 0_PADDR, \ + .size = XCHAL_ ## name ## 0_SIZE, \ + } \ + } + +#define LOCAL_MEMORIES_SECTION \ + .instrom = { \ + MEM_SECTION(INSTROM) \ + }, \ + .instram = { \ + MEM_SECTION(INSTRAM) \ + }, \ + .datarom = { \ + MEM_SECTION(DATAROM) \ + }, \ + .dataram = { \ + MEM_SECTION(DATARAM) \ + }, \ + .sysrom = { \ + SYSMEM_SECTION(SYSROM) \ + }, \ + .sysram = { \ + SYSMEM_SECTION(SYSRAM) \ + } + #define CONFIG_SECTION \ .configid = { \ XCHAL_HW_CONFIGID0, \ @@ -377,6 +456,7 @@ TLB_SECTION, \ DEBUG_SECTION, \ CACHE_SECTION, \ + LOCAL_MEMORIES_SECTION, \ CONFIG_SECTION @@ -629,3 +709,83 @@ #define XTHAL_TIMER_UNCONFIGURED 0 + +#if XCHAL_NUM_INSTROM < 1 +#define XCHAL_INSTROM0_PADDR 0 +#define XCHAL_INSTROM0_SIZE 0 +#endif +#if XCHAL_NUM_INSTROM < 2 +#define XCHAL_INSTROM1_PADDR 0 +#define XCHAL_INSTROM1_SIZE 0 +#endif +#if XCHAL_NUM_INSTROM < 3 +#define XCHAL_INSTROM2_PADDR 0 +#define XCHAL_INSTROM2_SIZE 0 +#endif +#if XCHAL_NUM_INSTROM < 4 +#define XCHAL_INSTROM3_PADDR 0 +#define XCHAL_INSTROM3_SIZE 0 +#endif +#if XCHAL_NUM_INSTROM > MAX_NMEMORY +#error XCHAL_NUM_INSTROM > MAX_NMEMORY +#endif + +#if XCHAL_NUM_INSTRAM < 1 +#define XCHAL_INSTRAM0_PADDR 0 +#define XCHAL_INSTRAM0_SIZE 0 +#endif +#if XCHAL_NUM_INSTRAM < 2 +#define XCHAL_INSTRAM1_PADDR 0 +#define XCHAL_INSTRAM1_SIZE 0 +#endif +#if XCHAL_NUM_INSTRAM < 3 +#define XCHAL_INSTRAM2_PADDR 0 +#define XCHAL_INSTRAM2_SIZE 0 +#endif +#if XCHAL_NUM_INSTRAM < 4 +#define XCHAL_INSTRAM3_PADDR 0 +#define XCHAL_INSTRAM3_SIZE 0 +#endif +#if XCHAL_NUM_INSTRAM > MAX_NMEMORY +#error XCHAL_NUM_INSTRAM > MAX_NMEMORY +#endif + +#if XCHAL_NUM_DATAROM < 1 +#define XCHAL_DATAROM0_PADDR 0 +#define XCHAL_DATAROM0_SIZE 0 +#endif +#if XCHAL_NUM_DATAROM < 2 +#define XCHAL_DATAROM1_PADDR 0 +#define XCHAL_DATAROM1_SIZE 0 +#endif +#if XCHAL_NUM_DATAROM < 3 +#define XCHAL_DATAROM2_PADDR 0 +#define XCHAL_DATAROM2_SIZE 0 +#endif +#if XCHAL_NUM_DATAROM < 4 +#define XCHAL_DATAROM3_PADDR 0 +#define XCHAL_DATAROM3_SIZE 0 +#endif +#if XCHAL_NUM_DATAROM > MAX_NMEMORY +#error XCHAL_NUM_DATAROM > MAX_NMEMORY +#endif + +#if XCHAL_NUM_DATARAM < 1 +#define XCHAL_DATARAM0_PADDR 0 +#define XCHAL_DATARAM0_SIZE 0 +#endif +#if XCHAL_NUM_DATARAM < 2 +#define XCHAL_DATARAM1_PADDR 0 +#define XCHAL_DATARAM1_SIZE 0 +#endif +#if XCHAL_NUM_DATARAM < 3 +#define XCHAL_DATARAM2_PADDR 0 +#define XCHAL_DATARAM2_SIZE 0 +#endif +#if XCHAL_NUM_DATARAM < 4 +#define XCHAL_DATARAM3_PADDR 0 +#define XCHAL_DATARAM3_SIZE 0 +#endif +#if XCHAL_NUM_DATARAM > MAX_NMEMORY +#error XCHAL_NUM_DATARAM > MAX_NMEMORY +#endif