From patchwork Sat Apr 20 18:42:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 238162 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 875422C014C for ; Sun, 21 Apr 2013 04:45:05 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 87B424A438; Sat, 20 Apr 2013 20:44:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 50Mge-2MUI-P; Sat, 20 Apr 2013 20:44:34 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CBB734A435; Sat, 20 Apr 2013 20:43:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4C1BF4A365 for ; Sat, 20 Apr 2013 20:43:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ySnEdmjKuAEv for ; Sat, 20 Apr 2013 20:43:31 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-yh0-f74.google.com (mail-yh0-f74.google.com [209.85.213.74]) by theia.denx.de (Postfix) with ESMTPS id 504D04A3A7 for ; Sat, 20 Apr 2013 20:43:17 +0200 (CEST) Received: by mail-yh0-f74.google.com with SMTP id q10so545943yhf.1 for ; Sat, 20 Apr 2013 11:43:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=fz2xUDCrMjE5/EQQlj/OOyUfHr7zZi5oA2PIqQextZs=; b=gaX//CiUJrOG/REyCATk0GPeeXmsV9bH2Qr6VhuXYRxcJ16hqAhxfpu3ScgFaZwrZw ggFxi1JoOSEuNnw8F8ykJcWm/i5cReL74Run2SSZEb+zrYbCA7UaH3gD2U6CHMBPae6+ s5QPdVQfxNRN2K5Au8RTUvHKofkcOgHm/c7x5jZTo/SgXJuk8dqnfdkWTN5qwg19vx4S fZFKd7aOT1T9IPmFXZU1X6GeZqtTM1JkxWxuhrjkqNyA68csVLoFgFujuDFzWfv+Cipp d5VqY7rSvpFnqyiabkLp5SAjigL/Sie5W376kD7ixqeIjuqs4FRnpWO1CcAUoyR8TOCm qN6g== X-Received: by 10.236.137.206 with SMTP id y54mr10090348yhi.36.1366483394794; Sat, 20 Apr 2013 11:43:14 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id s80si4201415yhe.6.2013.04.20.11.43.14 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 20 Apr 2013 11:43:14 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id A3C0031C16A; Sat, 20 Apr 2013 11:43:14 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 52C1C16068E; Sat, 20 Apr 2013 11:43:14 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Apr 2013 11:42:37 -0700 Message-Id: <1366483372-16523-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366483372-16523-1-git-send-email-sjg@chromium.org> References: <1366483372-16523-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQl+zZEcAf9cuBm8KMHeOiNrR4ly8Ki8KSeUOm6CVJc+idBapXGx3cI1vn9BcRqp6QN5y/tMEUJ525BCsLQPoTzODxzeKDvMh94LvnBctVYWEFfWFG8p8dUBP2riqoV+UYUyGuWbtpP0QWOkF/juKzixyXxuFtVdynXTgDnxLkZLIoF5tEVvNtWkqsstHQIuLveUWx2q Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [PATCH v3 02/17] sandbox: Provide a way to map from host RAM to U-Boot RAM X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In many cases, pointers to memory are passed around, and these pointers refer to U-Boot memory, not host memory. This in itself is not a problem. However, in a few places, we cast that pointer back to a ulong (being a U-Boot memory address). It is possible to convert many of these cases to avoid this. However there are data structures (e.g. struct bootm_headers) which use pointers. We could with a lot of effort adjust the structs and all code that uses them to use ulong instead of pointers. This seems like an unacceptable cost, since our objective with sandbox is to minimise the impact on U-Boot code while maximising the features available to sandbox. Therefore, create a map_to_sysmem() function which converts from a pointer to a U-Boot address. This can be used sparingly when needed. Signed-off-by: Simon Glass --- Changes in v3: - Rebase on master, to take account of generic board Changes in v2: - Use gd->arch.ram_buf instead of gd->ram_buf (now that generic board is in) arch/sandbox/cpu/cpu.c | 5 +++++ arch/sandbox/include/asm/io.h | 3 +++ include/common.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index b2788d5..dd8d495 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -57,6 +57,11 @@ void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) return (void *)(gd->arch.ram_buf + paddr); } +phys_addr_t map_to_sysmem(void *ptr) +{ + return (u8 *)ptr - gd->arch.ram_buf; +} + void flush_dcache_range(unsigned long start, unsigned long stop) { } diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h index d8c0236..54051a3 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -49,3 +49,6 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) static inline void unmap_sysmem(const void *vaddr) { } + +/* Map from a pointer to our RAM buffer */ +phys_addr_t map_to_sysmem(void *ptr); diff --git a/include/common.h b/include/common.h index 0cfa6a8..76c79ae 100644 --- a/include/common.h +++ b/include/common.h @@ -897,6 +897,11 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) static inline void unmap_sysmem(const void *vaddr) { } + +static inline phys_addr_t map_to_sysmem(void *ptr) +{ + return (phys_addr_t)(uintptr_t)ptr; +} # endif #endif /* __ASSEMBLY__ */