From patchwork Sat May 12 00:17:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8539 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 783E323E20 for ; Sat, 12 May 2012 00:19:13 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 41C46A18C2F for ; Sat, 12 May 2012 00:19:13 +0000 (UTC) Received: by mail-yw0-f52.google.com with SMTP id p61so4054664yhp.11 for ; Fri, 11 May 2012 17:19:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=mz+oBBMK4ED3KZOW0hF72RZNErS2DkVL6ru4sQN4uFU=; b=Vi2ctxVww/b42tI9Uz3gwNSl9UGl1Ak6+nqiHS2LMAfdrBAhnVRW/hmS8g0SyacRB2 rn/Kmyl7Wnw80j42iEJyftR4r6gASu/QIGLyGX7EHeK+R+flAyJz7SETH34XZPkRD/1D 1BVKAOaF04qNejGTLz4+vUkXPlUtmdlU8ETyGhFMWFnZfDNFwyO2fYk4R8J/1CR04/tW KJ1iKLBVNr+t3n/NFsawboyGx0UVdy+9ciIYBKaj2EANuAIMgikPe486CezMfuqV3eDU rKtUKFitLXNSKgGxhZoqnyD+wfpbkHz0oU9r7GQgS1QX8S1omNXpyL+Q0IhBAhHvchBW /WFQ== Received: by 10.50.160.225 with SMTP id xn1mr9049igb.3.1336781952806; Fri, 11 May 2012 17:19:12 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.73.147 with SMTP id q19csp211509ibj; Fri, 11 May 2012 17:19:12 -0700 (PDT) Received: by 10.68.226.129 with SMTP id rs1mr338283pbc.29.1336781951684; Fri, 11 May 2012 17:19:11 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id p7si16197983pbk.104.2012.05.11.17.19.11 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 May 2012 17:19:11 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id rr4so4860215pbb.37 for ; Fri, 11 May 2012 17:19:11 -0700 (PDT) Received: by 10.68.223.67 with SMTP id qs3mr118218pbc.142.1336781951462; Fri, 11 May 2012 17:19:11 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id vl3sm14230670pbc.44.2012.05.11.17.19.09 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 11 May 2012 17:19:10 -0700 (PDT) Date: Fri, 11 May 2012 17:17:43 -0700 From: Anton Vorontsov To: Greg Kroah-Hartman , Kees Cook , Colin Cross Cc: Arnd Bergmann , John Stultz , arve@android.com, Rebecca Schultz Zavin , Jesper Juhl , Randy Dunlap , Stephen Boyd , Thomas Meyer , Andrew Morton , Marco Stornelli , WANG Cong , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com Subject: [PATCH 05/11] persistent_ram: Introduce persistent_ram_vmap() Message-ID: <20120512001743.GE14782@lizard> References: <20120512001506.GA8653@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120512001506.GA8653@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQkBsX4xPKvMXMza35BrrdcURLI9NZJoJ2Fvi0y55JCu5nAvATB7hI/771hIFhj0oLjjhxAy Factor out vmap logic out of persistent_ram_buffer_map(), this will make the code a bit more understandable when we'll add support for non-bootmem memory. Signed-off-by: Anton Vorontsov --- drivers/staging/android/persistent_ram.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/staging/android/persistent_ram.c b/drivers/staging/android/persistent_ram.c index c0c3d32..ab8bff1 100644 --- a/drivers/staging/android/persistent_ram.c +++ b/drivers/staging/android/persistent_ram.c @@ -318,14 +318,14 @@ void persistent_ram_free_old(struct persistent_ram_zone *prz) prz->old_log_size = 0; } -static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, - struct persistent_ram_zone *prz) +static void *persistent_ram_vmap(phys_addr_t start, size_t size) { struct page **pages; phys_addr_t page_start; unsigned int page_count; pgprot_t prot; unsigned int i; + void *vaddr; page_start = start - offset_in_page(start); page_count = DIV_ROUND_UP(size + offset_in_page(start), PAGE_SIZE); @@ -336,17 +336,26 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, if (!pages) { pr_err("%s: Failed to allocate array for %u pages\n", __func__, page_count); - return -ENOMEM; + return NULL; } for (i = 0; i < page_count; i++) { phys_addr_t addr = page_start + i * PAGE_SIZE; pages[i] = pfn_to_page(addr >> PAGE_SHIFT); } - prz->vaddr = vmap(pages, page_count, VM_MAP, prot); + vaddr = vmap(pages, page_count, VM_MAP, prot); kfree(pages); + + return vaddr; +} + +static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, + struct persistent_ram_zone *prz) +{ + prz->vaddr = persistent_ram_vmap(start, size); if (!prz->vaddr) { - pr_err("%s: Failed to map %u pages\n", __func__, page_count); + pr_err("%s: Failed to map 0x%llx pages at 0x%llx\n", __func__, + (unsigned long long)size, (unsigned long long)start); return -ENOMEM; }