Skip to contentSkip to conversation

target/xtensa: sim: instantiate local memories

PATCH New Max Filippov 2 participants 2 messages Feb 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/xtensa: sim: instantiate local memories

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.

---
 hw/xtensa/sim.c              |  40 ++++++++---
 target/xtensa/cpu.h          |  16 +++++
 target/xtensa/overlay_tool.h | 160 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+), 9 deletions(-)
hw/xtensa/sim.c +31 -9
index 5e94004..d2d1d3a 100644
@@ -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;
target/xtensa/cpu.h +16 -0
index 7e7131a..ecca17d 100644
@@ -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;
target/xtensa/overlay_tool.h +160 -0

187 lines not on this page · raw message

Signature · 1 line
2.1.4
#1 lore raw
This series seems to have some coding style problems. See output below for more information:

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH] target/xtensa: sim: instantiate local memories

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
dc3c051 target/xtensa: sim: instantiate local memories

=== OUTPUT BEGIN ===
Checking PATCH 1/1: target/xtensa: sim: instantiate local memories...
ERROR: Macros with complex values should be enclosed in parenthesis #180: FILE: target/xtensa/overlay_tool.h:403:
+#define MEM_SECTIONS(name) \

+    MEM_LOCATION(name, 0), \
+    MEM_LOCATION(name, 1), \
+    MEM_LOCATION(name, 2), \
+    MEM_LOCATION(name, 3)

total: 1 errors, 0 warnings, 280 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]