From patchwork Mon Mar 18 23:51:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 228865 X-Patchwork-Delegate: trini@ti.com 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 1AEA52C009B for ; Tue, 19 Mar 2013 11:01:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DA7024A146; Tue, 19 Mar 2013 00:58:45 +0100 (CET) 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 kLyWcd6jAkVj; Tue, 19 Mar 2013 00:58:45 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 91EB14A147; Tue, 19 Mar 2013 00:54:23 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF6164A040 for ; Tue, 19 Mar 2013 00:53:43 +0100 (CET) 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 qkIxJN-1mcoC for ; Tue, 19 Mar 2013 00:53:43 +0100 (CET) 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-qe0-f73.google.com (mail-qe0-f73.google.com [209.85.128.73]) by theia.denx.de (Postfix) with ESMTPS id CC79B4A087 for ; Tue, 19 Mar 2013 00:53:22 +0100 (CET) Received: by mail-qe0-f73.google.com with SMTP id a11so640802qen.4 for ; Mon, 18 Mar 2013 16:53:21 -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=El2AA9UckE1UGhmjgeCHAdqp0re+ADjQ3NFEaxBA3U0=; b=pnuWq7tp0O8mSVb7LQs03Zj0lEOTnLI+4r8oH97rW62cblA5lZJzO9PMONXANHSwVb FXxBms5Y88INJZ3KL0erycRUZqEI71+2oE4t9nzS8S5EKtifWERKoFngxSrLPKtyLJ7L bZV6Wf5NdhM+aF1J40qltW12Fzb+PukpUch0++FIQIb2ZS0QtLxNB2FIwI4maMW7dbxs 4JEzT4JQqu1o9tN3TPCp+lXVUM6J4jdjvGFgmT9QXwPDWd7c2WupFQXC/+2heUlu/cX3 O+00YvnvvlsO2RNblNKQrwBMM+7Gnt+b54OhP4XRlscIbXWXcNnszwe8MubTo72wWQ38 JBFA== X-Received: by 10.58.1.69 with SMTP id 5mr15935607vek.34.1363650801533; Mon, 18 Mar 2013 16:53:21 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id f64si2188125yhj.7.2013.03.18.16.53.21 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 18 Mar 2013 16:53:21 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 5E8415A41B0; Mon, 18 Mar 2013 16:53:21 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 3D5B016036D; Mon, 18 Mar 2013 16:53:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 18 Mar 2013 16:51:49 -0700 Message-Id: <1363650725-30459-30-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1363650725-30459-1-git-send-email-sjg@chromium.org> References: <1363650725-30459-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQnM6RvvI8gPEkeZNJHv8Tsq0qxz1u91ZoEU4siVt/4LV9G5BeUJkCRdFCsBTDr7iIrjxT3UjgECyc1Q+6S+Xvv9uPhQ0Jl6qe6/XlqI+iIdsDuYP0w9IB09aUOXU02E/TNofuyQxwkB+JJO95U5YEq+x1DNimCwhcsumL1GC+Tzx5nK9gUnbETEnyxuJGy9HNKTEVbt Cc: Joel A Fernandes , Will Drewry , u-boot-review@google.com, Bill Richardson , Randall Spangler , Tom Rini , Vadim Bendebury , =?UTF-8?q?Andreas=20B=C3=A4ck?= , Kees Cook Subject: [U-Boot] [PATCH v2 29/45] 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 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 | 2 ++ include/common.h | 5 +++++ 3 files changed, 12 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..4ce7a84 100644 --- a/arch/sandbox/include/asm/io.h +++ b/arch/sandbox/include/asm/io.h @@ -49,3 +49,5 @@ static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) static inline void unmap_sysmem(const void *vaddr) { } + +phys_addr_t map_to_sysmem(void *ptr); diff --git a/include/common.h b/include/common.h index 52f2b33..58fccd3 100644 --- a/include/common.h +++ b/include/common.h @@ -907,6 +907,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__ */