From patchwork Sat Dec 14 03:26:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22477 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 909F623908 for ; Sat, 14 Dec 2013 03:27:10 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wm4sf9438984obc.11 for ; Fri, 13 Dec 2013 19:27:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=YUxxP3Twp9Ki+WoOllz8BCrdGxvtFUvmF7a0AuE8zwU=; b=imV/84LjSaSyZIGMJl+qqMKcioA2qJG/KPRuRvQNKE/vAk9OZATNqYXg9Ngq/oeJCK 9+ytp8LxS6UxbVsX/0U7SmwJ1ZikRnkLpdgITJmQmgw57U8kfPMMM5mUS4IPyuaKQgZ1 10cflMpWGmUHRyNOqyo9z9PyYe1mBF/YnAwMXQ3KAOQqwyK0+CWXvZEt2Tff8MD7XltD KA8b1RSX/oslTRT81tIeqAtzrFGwg7O4rUjfaR1s3tlIBGPgZR/hzNZ8peg6T1b7TAHF 1X2l8+JE6BPMmIg2lkTrd1LITdpiXrBw8Ol0hU9mivtItw0wZTj/OPlpVhkGjymQ8Xat +jsA== X-Gm-Message-State: ALoCoQl2/qRxNJXzpf1tFnMQZ3BYxc9V3ORAwL2o9nO+qn9Pg/XZrtuRV4s6vYPXil6pN14RAjQ4 X-Received: by 10.42.210.68 with SMTP id gj4mr1940542icb.1.1386991630167; Fri, 13 Dec 2013 19:27:10 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.9 with SMTP id z9ls1219533qem.79.gmail; Fri, 13 Dec 2013 19:27:10 -0800 (PST) X-Received: by 10.58.207.76 with SMTP id lu12mr2622205vec.30.1386991630007; Fri, 13 Dec 2013 19:27:10 -0800 (PST) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by mx.google.com with ESMTPS id ti3si1430587vdc.15.2013.12.13.19.27.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.43; Received: by mail-vb0-f43.google.com with SMTP id p6so1830738vbe.2 for ; Fri, 13 Dec 2013 19:27:09 -0800 (PST) X-Received: by 10.58.187.129 with SMTP id fs1mr2547219vec.45.1386991629931; Fri, 13 Dec 2013 19:27:09 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp86961vcz; Fri, 13 Dec 2013 19:27:09 -0800 (PST) X-Received: by 10.68.134.98 with SMTP id pj2mr7229762pbb.110.1386991629132; Fri, 13 Dec 2013 19:27:09 -0800 (PST) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id tt8si2959896pbc.288.2013.12.13.19.27.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:09 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id z10so3225545pdj.16 for ; Fri, 13 Dec 2013 19:27:08 -0800 (PST) X-Received: by 10.68.195.70 with SMTP id ic6mr7199609pbc.112.1386991628754; Fri, 13 Dec 2013 19:27:08 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id nw11sm11680086pab.13.2013.12.13.19.27.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 19:27:08 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , John Stultz Subject: [PATCH 107/115] ion: use alloc_pages in system contig heap Date: Fri, 13 Dec 2013 19:26:27 -0800 Message-Id: <1386991595-6251-15-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386991595-6251-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> <1386991595-6251-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Colin Cross There is no reason to use kzalloc, just call alloc_pages directly. Change the GFP from GFP_KERNEL to include __GFP_HIGH, to allow it to return contiguous pages from highmem. virt_to_* functions aren't valid on highmem pages, so store the struct page * in an sg_table in buffer->priv_virt like most other heaps, and replace virt_to_* with page_to_*. Signed-off-by: Colin Cross Signed-off-by: John Stultz --- drivers/staging/android/ion/ion_system_heap.c | 71 ++++++++++++++++++--------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 53afa33..841511d 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -360,29 +360,69 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap, unsigned long flags) { int order = get_order(len); + struct page *page; + struct sg_table *table; + unsigned long i; + int ret; if (align > (PAGE_SIZE << order)) return -EINVAL; - if (ion_buffer_fault_user_mappings(buffer)) - return -EINVAL; - - buffer->priv_virt = kzalloc(len, GFP_KERNEL); - if (!buffer->priv_virt) + page = alloc_pages(low_order_gfp_flags, order); + if (!page) return -ENOMEM; + + split_page(page, order); + + len = PAGE_ALIGN(len); + for (i = len >> PAGE_SHIFT; i < (1 << order); i++) + __free_page(page + i); + + table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!table) { + ret = -ENOMEM; + goto out; + } + + ret = sg_alloc_table(table, 1, GFP_KERNEL); + if (ret) + goto out; + + sg_set_page(table->sgl, page, len, 0); + + buffer->priv_virt = table; + + ion_pages_sync_for_device(NULL, page, len, DMA_BIDIRECTIONAL); + return 0; + +out: + for (i = 0; i < len >> PAGE_SHIFT; i++) + __free_page(page + i); + kfree(table); + return ret; } void ion_system_contig_heap_free(struct ion_buffer *buffer) { - kfree(buffer->priv_virt); + struct sg_table *table = buffer->priv_virt; + struct page *page = sg_page(table->sgl); + unsigned long pages = PAGE_ALIGN(buffer->size) >> PAGE_SHIFT; + unsigned long i; + + for (i = 0; i < pages; i++) + __free_page(page + i); + sg_free_table(table); + kfree(table); } static int ion_system_contig_heap_phys(struct ion_heap *heap, struct ion_buffer *buffer, ion_phys_addr_t *addr, size_t *len) { - *addr = virt_to_phys(buffer->priv_virt); + struct sg_table *table = buffer->priv_virt; + struct page *page = sg_page(table->sgl); + *addr = page_to_phys(page); *len = buffer->size; return 0; } @@ -390,27 +430,12 @@ static int ion_system_contig_heap_phys(struct ion_heap *heap, struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { - struct sg_table *table; - int ret; - - table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); - if (!table) - return ERR_PTR(-ENOMEM); - ret = sg_alloc_table(table, 1, GFP_KERNEL); - if (ret) { - kfree(table); - return ERR_PTR(ret); - } - sg_set_page(table->sgl, virt_to_page(buffer->priv_virt), buffer->size, - 0); - return table; + return buffer->priv_virt; } void ion_system_contig_heap_unmap_dma(struct ion_heap *heap, struct ion_buffer *buffer) { - sg_free_table(buffer->sg_table); - kfree(buffer->sg_table); } static struct ion_heap_ops kmalloc_ops = {