From patchwork Sat Oct 1 14:19:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Burton X-Patchwork-Id: 677344 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 3smVnn196Rz9s2G for ; Sun, 2 Oct 2016 00:20:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5D60AA756B; Sat, 1 Oct 2016 16:20:10 +0200 (CEST) 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 T4jVSNBSrtGo; Sat, 1 Oct 2016 16:20:10 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 05F00A757A; Sat, 1 Oct 2016 16:20:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A9A96A756B for ; Sat, 1 Oct 2016 16:20:06 +0200 (CEST) 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 L8XbhOdxLxN7 for ; Sat, 1 Oct 2016 16:20:06 +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 mailapp01.imgtec.com (mailapp02.imgtec.com [217.156.133.132]) by theia.denx.de (Postfix) with ESMTP id 7AE37A757A for ; Sat, 1 Oct 2016 16:20:05 +0200 (CEST) Received: from HHMAIL03.hh.imgtec.org (unknown [10.44.0.21]) by Forcepoint Email with ESMTPS id 1E447FA7E21E5; Sat, 1 Oct 2016 15:20:00 +0100 (IST) Received: from localhost (192.168.159.74) by HHMAIL03.hh.imgtec.org (10.44.0.22) with Microsoft SMTP Server (TLS) id 14.3.294.0; Sat, 1 Oct 2016 15:20:03 +0100 From: Paul Burton To: Date: Sat, 1 Oct 2016 15:19:04 +0100 Message-ID: <20161001141931.32354-2-paul.burton@imgtec.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161001141931.32354-1-paul.burton@imgtec.com> References: <20161001141931.32354-1-paul.burton@imgtec.com> MIME-Version: 1.0 X-Originating-IP: [192.168.159.74] Cc: Scott McNutt , Mike Frysinger , Angelo Dureghello , Alexey Brodkin , Alison Wang , Macpaul Lin Subject: [U-Boot] [PATCH 01/27] Provide a generic io.h & address mapping functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Most architectures currently supported by U-Boot use trivial implementations of map_to_physmem & virt_to_phys which simply cast a physical address to a pointer for use a virtual address & vice-versa. This results in a lot of duplicate implementations of these mapping functions. The functions provided by different architectures also differs, with some having implementations of phys_to_virt & others not. A later patch in this series will make use of phys_to_virt, so requires that it be provided for all architectures. This patch introduces an asm-generic/io.h which provides generic implementations of address mapping functions, allowing the duplication of them between architectures to be removed. Once architectures are converted to make use of this generic header it will also ensure that all of phys_to_virt, virt_to_phys, map_physmem & unmap_physmem are provided. The 2 families of functions differ in that map_physmem may create dynamic mappings whilst phys_to_virt may not & therefore is more limited in scope but doesn't require information such as a length & flags. This patch doesn't convert any architectures to make use of this generic header - later patches in the series will do so. Signed-off-by: Paul Burton Cc: Albert Aribaud Cc: Alexey Brodkin Cc: Alison Wang Cc: Angelo Dureghello Cc: Bin Meng Cc: Daniel Schwierzeck Cc: Francois Retief Cc: Macpaul Lin Cc: Michal Simek Cc: Mike Frysinger Cc: Nobuhiro Iwamatsu Cc: Scott McNutt Cc: Sonic Zhang Cc: Thomas Chou Cc: Wolfgang Denk Acked-by: Angelo Dureghello Tested-by: Angelo Dureghello Reviewed-by: Simon Glass --- include/asm-generic/io.h | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 include/asm-generic/io.h diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h new file mode 100644 index 0000000..dd3a46d --- /dev/null +++ b/include/asm-generic/io.h @@ -0,0 +1,110 @@ +/* + * Generic I/O functions. + * + * Copyright (c) 2016 Imagination Technologies Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __ASM_GENERIC_IO_H__ +#define __ASM_GENERIC_IO_H__ + +/* + * This file should be included at the end of each architecture-specific + * asm/io.h such that we may provide generic implementations without + * conflicting with architecture-specific code. + */ + +#ifndef __ASSEMBLY__ + +/** + * phys_to_virt() - Return a virtual address mapped to a given physical address + * @paddr: the physical address + * + * Returns a virtual address which the CPU can access that maps to the physical + * address @paddr. This should only be used where it is known that no dynamic + * mapping is required. In general, map_physmem should be used instead. + * + * Returns: a virtual address which maps to @paddr + */ +#ifndef phys_to_virt +static inline void *phys_to_virt(phys_addr_t paddr) +{ + return (void *)(unsigned long)paddr; +} +#endif + +/** + * virt_to_phys() - Return the physical address that a virtual address maps to + * @vaddr: the virtual address + * + * Returns the physical address which the CPU-accessible virtual address @vaddr + * maps to. + * + * Returns: the physical address which @vaddr maps to + */ +#ifndef virt_to_phys +static inline phys_addr_t virt_to_phys(void *vaddr) +{ + return (phys_addr_t)((unsigned long)vaddr); +} +#endif + +/* + * Flags for use with map_physmem() & unmap_physmem(). Architectures need not + * support all of these, in which case they will be defined as zero here & + * ignored. Callers that may run on multiple architectures should therefore + * treat them as hints rather than requirements. + */ +#ifndef MAP_NOCACHE +# define MAP_NOCACHE 0 /* Produce an uncached mapping */ +#endif +#ifndef MAP_WRCOMBINE +# define MAP_WRCOMBINE 0 /* Allow write-combining on the mapping */ +#endif +#ifndef MAP_WRBACK +# define MAP_WRBACK 0 /* Map using write-back caching */ +#endif +#ifndef MAP_WRTHROUGH +# define MAP_WRTHROUGH 0 /* Map using write-through caching */ +#endif + +/** + * map_physmem() - Return a virtual address mapped to a given physical address + * @paddr: the physical address + * @len: the length of the required mapping + * @flags: flags affecting the type of mapping + * + * Return a virtual address through which the CPU may access the memory at + * physical address @paddr. The mapping will be valid for at least @len bytes, + * and may be affected by flags passed to the @flags argument. This function + * may create new mappings, so should generally be paired with a matching call + * to unmap_physmem once the caller is finished with the memory in question. + * + * Returns: a virtual address suitably mapped to @paddr + */ +#ifndef map_physmem +static inline void * +map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) +{ + return phys_to_virt(paddr); +} +#endif + +/** + * unmap_physmem() - Remove mappings created by a prior call to map_physmem() + * @vaddr: the virtual address which map_physmem() previously returned + * @flags: flags matching those originally passed to map_physmem() + * + * Unmap memory which was previously mapped by a call to map_physmem(). If + * map_physmem() dynamically created a mapping for the memory in question then + * unmap_physmem() will remove that mapping. + */ +#ifndef unmap_physmem +static inline void unmap_physmem(void *vaddr, unsigned long flags) +{ +} +#endif + +#endif /* !__ASSEMBLY__ */ +#endif /* __ASM_GENERIC_IO_H__ */