From patchwork Thu Jun 14 23:13:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 138636 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp117245lji; Thu, 14 Jun 2018 16:13:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLm3RnWHoheFgiU8VjITDUNFASj8KuJNeluWBX4IGoysw8bvOev8S6zLwDqUtQWQi75PD8J X-Received: by 2002:a50:aea8:: with SMTP id e37-v6mr4039794edd.285.1529018005772; Thu, 14 Jun 2018 16:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529018005; cv=none; d=google.com; s=arc-20160816; b=W/MJgWyr7mGGnlwMlMkCD/b2OnV/rWmtrMzAHf6fyRG3mBPGnJ0kBBUn5YucQNwtxl GuAud26kRiIIRhfXKFyMB9g0Qj7Hb02ShAYmKWVzGEVfmQzTDyZ6/wYpY5P8UnGxTwk6 FfDVHonrOwoFrY26fhf0T2idR8LD0jF+42vXgfCJYu9vAMasKMhQWGLsb7zLa12mX6T5 8Z4w4c1T5UFvvj88N5s0tbtVqTt/KWRv31Qqnw27XKyy6sZaF6SlSbZnZmBIkRbGoYy4 b6Vk1oOOsqOPKKk2Zb9WgGH5CmxKhqIBzBpl68eQ+kzsqLs7OU7AvCZV7TDD5Fgv1wmk 0lIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=RC864Jvncgnncf+/IL/RUK42d/BwjKXlQnqZuax8qeg=; b=uft6KM/5KZkWe2uKFISmZuzWF5uOafNDFIEX4LstwuvvppcgE0JkpwgnY9BwNw2vRN C3r0w27JhQQ37yWS7hbf4DpP+jnDxpNTOmm71VpEe1vZdtq4l05ps+TLuljuj97G5/8+ jj8J+kW936QnQqLLH7csW+MLJmPamhlkt8bT7RNq0ke7ZT9bStqptzdjvJcpbO4O/zNk TqqDShKyiDAec6eVqmdEV4f05+jcmjX2xGiaXMPhvI8TfLxRrb7S+5JAvNVBM+nM79cy 3nrZEt7xqKgGsDKq8LPnPJ4ad877HOoVSk5FlSKmCGmH3AdUhsdyykBIxKXPgoSnXoaR JYxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id k91-v6si1278632edc.432.2018.06.14.16.13.24; Thu, 14 Jun 2018 16:13:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id AB57DC21E29; Thu, 14 Jun 2018 23:13:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0C1A4C21C29; Thu, 14 Jun 2018 23:13:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 92AA7C21C29; Thu, 14 Jun 2018 23:13:18 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 2BFA3C21BE5 for ; Thu, 14 Jun 2018 23:13:18 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CB2A3AE79; Thu, 14 Jun 2018 23:13:17 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Fri, 15 Jun 2018 01:13:16 +0200 Message-Id: <20180614231316.14201-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Heinrich Schuchardt Subject: [U-Boot] [RFC] sandbox: Enable 1:1 map X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" So far we've always had a split address space situation with "U-Boot addresses" (a number space starting from 0) and "host virtual addresses" (128MB mapped randomly in address space). This meant that we had to make sure all code is properly aware that addresses and pointers are not the same thing, so they must not cast between the two. However, most real boards do actually have a 1:1 map. So it's much easier to just expose the same in sandbox. So this patch maps sandbox RAM from 0x8000000-0x10000000. This address range fits just fine on both 32bit and 64bit systems. --- The patch is on top of my "efi-sandbox-v3" tree. But I'm sure it easily applies on vanilla too. I also don't know if this really is the best path forward, but at least it's one that gets rid of the one awkward target that does not have a 1:1 map ;) --- arch/sandbox/cpu/cpu.c | 18 ++---------------- arch/sandbox/cpu/state.c | 4 ++-- arch/sandbox/cpu/u-boot.lds | 3 +++ arch/sandbox/include/asm/io.h | 17 +++++------------ common/board_f.c | 4 +++- configs/sandbox64_defconfig | 6 +++--- configs/sandbox_defconfig | 6 +++--- configs/sandbox_flattree_defconfig | 4 ++-- configs/sandbox_noblk_defconfig | 4 ++-- configs/sandbox_spl_defconfig | 4 ++-- include/configs/sandbox.h | 22 +++++++++++----------- 11 files changed, 38 insertions(+), 54 deletions(-) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 23d8b70648..5f5d6c9158 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -58,16 +58,6 @@ int cleanup_before_linux_select(int flags) return 0; } -void *phys_to_virt(phys_addr_t paddr) -{ - return (void *)(gd->arch.ram_buf + paddr); -} - -phys_addr_t virt_to_phys(void *vaddr) -{ - return (phys_addr_t)((uint8_t *)vaddr - gd->arch.ram_buf); -} - void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) { #if defined(CONFIG_PCI) && !defined(CONFIG_SPL_BUILD) @@ -103,11 +93,6 @@ void sandbox_set_enable_pci_map(int enable) enable_pci_map = enable; } -phys_addr_t map_to_sysmem(const void *ptr) -{ - return (u8 *)ptr - gd->arch.ram_buf; -} - void flush_dcache_range(unsigned long start, unsigned long stop) { } @@ -187,7 +172,8 @@ void longjmp(jmp_buf jmp, int ret) */ void efi_add_known_memory(void) { - u64 ram_start = (uintptr_t)map_sysmem(0, gd->ram_size); + u64 ram_start = (uintptr_t)map_sysmem(CONFIG_SYS_SDRAM_BASE, + gd->ram_size); u64 ram_size = gd->ram_size; u64 start = (ram_start + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; u64 pages = (ram_size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT; diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index cc50819ab9..75ad564274 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -12,6 +12,7 @@ /* Main state record for the sandbox */ static struct sandbox_state main_state; static struct sandbox_state *state; /* Pointer to current state record */ +static __attribute__ ((section (".ram"))) u8 sandbox_ram[CONFIG_SYS_SDRAM_SIZE]; static int state_ensure_space(int extra_size) { @@ -366,8 +367,7 @@ int state_init(void) state = &main_state; state->ram_size = CONFIG_SYS_SDRAM_SIZE; - state->ram_buf = os_malloc(state->ram_size); - assert(state->ram_buf); + state->ram_buf = sandbox_ram; state_reset_for_test(state); /* diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds index 3a6cf55eb9..8d0dfadfe0 100644 --- a/arch/sandbox/cpu/u-boot.lds +++ b/arch/sandbox/cpu/u-boot.lds @@ -47,6 +47,9 @@ SECTIONS *(.__efi_runtime_rel_stop) } + .ram 0x8000000 : { + *(.ram) + } } INSERT BEFORE .data; diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index 81b7750628..fe792200a7 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -6,12 +6,6 @@ #ifndef __SANDBOX_ASM_IO_H #define __SANDBOX_ASM_IO_H -void *phys_to_virt(phys_addr_t paddr); -#define phys_to_virt phys_to_virt - -phys_addr_t virt_to_phys(void *vaddr); -#define virt_to_phys virt_to_phys - void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags); #define map_physmem map_physmem @@ -23,20 +17,19 @@ void unmap_physmem(const void *vaddr, unsigned long flags); #include -/* For sandbox, we want addresses to point into our RAM buffer */ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) { - return map_physmem(paddr, len, MAP_WRBACK); + return (void *)(unsigned long)paddr; } -/* Remove a previous mapping */ static inline void unmap_sysmem(const void *vaddr) { - unmap_physmem(vaddr, MAP_WRBACK); } -/* Map from a pointer to our RAM buffer */ -phys_addr_t map_to_sysmem(const void *ptr); +static inline phys_addr_t map_to_sysmem(const void *ptr) +{ + return (phys_addr_t)(unsigned long)ptr; +} /* Define nops for sandbox I/O access */ #define readb(addr) ((void)addr, 0) diff --git a/common/board_f.c b/common/board_f.c index e943347ce3..b06f9d30ad 100644 --- a/common/board_f.c +++ b/common/board_f.c @@ -219,7 +219,9 @@ static int setup_mon_len(void) { #if defined(__ARM__) || defined(__MICROBLAZE__) gd->mon_len = (ulong)&__bss_end - (ulong)_start; -#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP) +#elif defined(CONFIG_SANDBOX) + gd->mon_len = 0; +#elif defined(CONFIG_EFI_APP) gd->mon_len = (ulong)&_end - (ulong)_init; #elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA) gd->mon_len = CONFIG_SYS_MONITOR_LEN; diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 20a2ab3ffb..5c47b651d4 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x8000000 CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_SANDBOX64=y CONFIG_DEFAULT_DEVICE_TREE="sandbox64" @@ -11,13 +11,13 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y -CONFIG_BOOTSTAGE_STASH_ADDR=0x0 +CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_SILENT_CONSOLE=y CONFIG_PRE_CONSOLE_BUFFER=y -CONFIG_PRE_CON_BUF_ADDR=0x100000 +CONFIG_PRE_CON_BUF_ADDR=0x8100000 CONFIG_LOG_MAX_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_CMD_CPU=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2fc84a16c9..84828c972c 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x8000000 CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_DISTRO_DEFAULTS=y @@ -10,13 +10,13 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y -CONFIG_BOOTSTAGE_STASH_ADDR=0x0 +CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_SILENT_CONSOLE=y CONFIG_PRE_CONSOLE_BUFFER=y -CONFIG_PRE_CON_BUF_ADDR=0x100000 +CONFIG_PRE_CON_BUF_ADDR=0x8100000 CONFIG_LOG_MAX_LEVEL=6 CONFIG_LOG_ERROR_RETURN=y CONFIG_DISPLAY_BOARDINFO_LATE=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index e922c4b38f..567ec15c22 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x8000000 CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_DISTRO_DEFAULTS=y @@ -10,7 +10,7 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y -CONFIG_BOOTSTAGE_STASH_ADDR=0x0 +CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig index 8bdd4edcda..c46b0bc06c 100644 --- a/configs/sandbox_noblk_defconfig +++ b/configs/sandbox_noblk_defconfig @@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x8000000 CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_DISTRO_DEFAULTS=y @@ -10,7 +10,7 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y -CONFIG_BOOTSTAGE_STASH_ADDR=0x0 +CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 # CONFIG_USE_BOOTCOMMAND is not set CONFIG_CONSOLE_RECORD=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index fb6bb4baa2..4327e3f8b6 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -1,4 +1,4 @@ -CONFIG_SYS_TEXT_BASE=0 +CONFIG_SYS_TEXT_BASE=0x8000000 CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_SYS_MALLOC_F_LEN=0x2000 @@ -17,7 +17,7 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y -CONFIG_BOOTSTAGE_STASH_ADDR=0x0 +CONFIG_BOOTSTAGE_STASH_ADDR=0x8000000 CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 1a49d1dab5..49a583fbe8 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -11,7 +11,7 @@ #define CONFIG_TRACE_BUFFER_SIZE (16 << 20) #define CONFIG_TRACE_EARLY_SIZE (8 << 20) #define CONFIG_TRACE_EARLY -#define CONFIG_TRACE_EARLY_ADDR 0x00100000 +#define CONFIG_TRACE_EARLY_ADDR 0x08100000 #endif @@ -30,7 +30,7 @@ /* * Size of malloc() pool, before and after relocation */ -#define CONFIG_MALLOC_F_ADDR 0x0010000 +#define CONFIG_MALLOC_F_ADDR 0x08010000 #define CONFIG_SYS_MALLOC_LEN (32 << 20) /* 32MB */ #define CONFIG_SYS_CBSIZE 1024 /* Console I/O Buffer Size */ @@ -44,15 +44,15 @@ #define CONFIG_I2C_EDID /* Memory things - we don't really want a memory test */ -#define CONFIG_SYS_LOAD_ADDR 0x00000000 -#define CONFIG_SYS_MEMTEST_START 0x00100000 +#define CONFIG_SYS_LOAD_ADDR 0x08000000 +#define CONFIG_SYS_MEMTEST_START 0x08100000 #define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_MEMTEST_START + 0x1000) -#define CONFIG_SYS_FDT_LOAD_ADDR 0x100 +#define CONFIG_SYS_FDT_LOAD_ADDR 0x08000100 #define CONFIG_PHYSMEM /* Size of our emulated memory */ -#define CONFIG_SYS_SDRAM_BASE 0 +#define CONFIG_SYS_SDRAM_BASE 0x8000000 #define CONFIG_SYS_SDRAM_SIZE (128 << 20) #define CONFIG_SYS_MONITOR_BASE 0 #define CONFIG_NR_DRAM_BANKS 1 @@ -104,11 +104,11 @@ #define MEM_LAYOUT_ENV_SETTINGS \ "bootm_size=0x10000000\0" \ - "kernel_addr_r=0x1000000\0" \ - "fdt_addr_r=0xc00000\0" \ - "ramdisk_addr_r=0x2000000\0" \ - "scriptaddr=0x1000\0" \ - "pxefile_addr_r=0x2000\0" + "kernel_addr_r=0x9000000\0" \ + "fdt_addr_r=0x8c00000\0" \ + "ramdisk_addr_r=0xa000000\0" \ + "scriptaddr=0x8001000\0" \ + "pxefile_addr_r=0x8002000\0" #define CONFIG_EXTRA_ENV_SETTINGS \ SANDBOX_SERIAL_SETTINGS \