From patchwork Thu Jan 31 01:00:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 2070381 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id F11B4DF2A1 for ; Thu, 31 Jan 2013 01:03:15 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U0iWW-0007er-2v; Thu, 31 Jan 2013 01:01:04 +0000 Received: from lgemrelse7q.lge.com ([156.147.1.151]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U0iW4-0007ae-BM for linux-arm-kernel@lists.infradead.org; Thu, 31 Jan 2013 01:00:38 +0000 X-AuditID: 9c930197-b7ca4ae000006ba8-a0-5109c2280203 Received: from js1304-P5Q-DELUXE.LGE.NET ( [10.177.220.249]) by LGEMRELSE7Q.lge.com (Symantec Brightmail Gateway) with SMTP id 8E.39.27560.822C9015; Thu, 31 Jan 2013 10:00:24 +0900 (KST) From: Joonsoo Kim To: Russell King Subject: [PATCH v4 2/3] ARM: ioremap: introduce an infrastructure for static mapped area Date: Thu, 31 Jan 2013 10:00:07 +0900 Message-Id: <1359594008-14688-3-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359594008-14688-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1359594008-14688-1-git-send-email-iamjoonsoo.kim@lge.com> X-Brightmail-Tracker: AAAAAA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130130_200036_809757_7E74DA16 X-CRM114-Status: GOOD ( 13.11 ) X-Spam-Score: -4.9 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [156.147.1.151 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: js1304@gmail.com, Nicolas Pitre , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, Joonsoo Kim , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org In current implementation, we used ARM-specific flag, that is, VM_ARM_STATIC_MAPPING, for distinguishing ARM specific static mapped area. The purpose of static mapped area is to re-use static mapped area when entire physical address range of the ioremap request can be covered by this area. This implementation causes needless overhead for some cases. For example, assume that there is only one static mapped area and vmlist has 300 areas. Every time we call ioremap, we check 300 areas for deciding whether it is matched or not. Moreover, even if there is no static mapped area and vmlist has 300 areas, every time we call ioremap, we check 300 areas in now. If we construct a extra list for static mapped area, we can eliminate above mentioned overhead. With a extra list, if there is one static mapped area, we just check only one area and proceed next operation quickly. In fact, it is not a critical problem, because ioremap is not frequently used. But reducing overhead is better idea. Another reason for doing this work is for removing architecture dependency on vmalloc layer. I think that vmlist and vmlist_lock is internal data structure for vmalloc layer. Some codes for debugging and stat inevitably use vmlist and vmlist_lock. But it is preferable that they are used as least as possible in outside of vmalloc.c Now, I introduce an ARM-specific infrastructure for static mapped area. In the following patch, we will use this and resolve above mentioned problem. Signed-off-by: Joonsoo Kim diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c index 88fd86c..ceb34ae 100644 --- a/arch/arm/mm/ioremap.c +++ b/arch/arm/mm/ioremap.c @@ -39,6 +39,78 @@ #include #include "mm.h" + +LIST_HEAD(static_vmlist); +static DEFINE_RWLOCK(static_vmlist_lock); + +static struct static_vm *find_static_vm_paddr(phys_addr_t paddr, + size_t size, unsigned long flags) +{ + struct static_vm *svm; + struct vm_struct *vm; + + read_lock(&static_vmlist_lock); + list_for_each_entry(svm, &static_vmlist, list) { + if (svm->flags != flags) + continue; + + vm = &svm->vm; + if (vm->phys_addr > paddr || + paddr + size - 1 > vm->phys_addr + vm->size - 1) + continue; + + read_unlock(&static_vmlist_lock); + return svm; + } + + return NULL; +} + +struct static_vm *find_static_vm_vaddr(void *vaddr) +{ + struct static_vm *svm; + struct vm_struct *vm; + + read_lock(&static_vmlist_lock); + list_for_each_entry(svm, &static_vmlist, list) { + vm = &svm->vm; + + /* static_vmlist is ascending order */ + if (vm->addr > vaddr) + break; + + if (vm->addr <= vaddr && vm->addr + vm->size > vaddr) { + read_unlock(&static_vmlist_lock); + return svm; + } + } + read_unlock(&static_vmlist_lock); + + return NULL; +} + +void add_static_vm_early(struct static_vm *svm, unsigned long flags) +{ + struct static_vm *curr_svm; + struct vm_struct *vm; + void *vaddr; + + vm_area_add_early(&svm->vm); + + vaddr = svm->vm.addr; + svm->flags = flags; + + write_lock(&static_vmlist_lock); + list_for_each_entry(curr_svm, &static_vmlist, list) { + vm = &curr_svm->vm; + + if (vm->addr > vaddr) + break; + } + list_add_tail(&svm->list, &curr_svm->list); + write_unlock(&static_vmlist_lock); +} + int ioremap_page(unsigned long virt, unsigned long phys, const struct mem_type *mtype) { diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h index a8ee92d..fb45c79 100644 --- a/arch/arm/mm/mm.h +++ b/arch/arm/mm/mm.h @@ -1,4 +1,6 @@ #ifdef CONFIG_MMU +#include +#include /* the upper-most page table pointer */ extern pmd_t *top_pmd; @@ -65,6 +67,24 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page /* consistent regions used by dma_alloc_attrs() */ #define VM_ARM_DMA_CONSISTENT 0x20000000 + +/* ARM specific static_vm->flags bits */ +#define STATIC_VM_MEM 0x00000001 +#define STATIC_VM_EMPTY 0x00000002 +#define STATIC_VM_MTYPE(mtype) ((mtype) << 20) + +#define STATIC_VM_TYPE(type, mtype) (type | STATIC_VM_MTYPE(mtype)) + +struct static_vm { + struct vm_struct vm; + struct list_head list; + unsigned long flags; +}; + +extern struct list_head static_vmlist; +extern struct static_vm *find_static_vm_vaddr(void *vaddr); +extern void add_static_vm_early(struct static_vm *svm, unsigned long flags); + #endif #ifdef CONFIG_ZONE_DMA