From patchwork Fri Dec 13 22:23:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22368 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C561923FBA for ; Fri, 13 Dec 2013 22:26:10 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kl14sf1963576pab.2 for ; Fri, 13 Dec 2013 14:26: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=amtX5WIUQQuvID5F9PyMwlNhJMiUeXFgoOzolf3EdGU=; b=K080+5RV7DcYRxQHDLvu6t4xpumhG50rXlT+jPGxGLuOXZhTQfyMg13ZVks9Igjxwz ASdBmaJkSbtimDY7WnwLcTEBThOTnV7Vdkr8GOCKDNuQpIe3DLYFGWk4bSbB9P4gq0jI aienMNYpj1fppwhEmjdqO/2nHlCWiNT6IW3U9aaYratMvz+uKp3Abyaaj8kWEscrMXpL Cw+Vt0EMJVubeNJD4w49UzdCZuAWiRAbKWtaP0ZGbPHIUgLLsBhtLOa3vmmKT2XCNkJh ubmE/2NwGPOusHXspM7TPdBjH5dxMlmrZfBfb49QJv82Xfrpf8Fp102wJ6h1mqxNtYqc TJmg== X-Gm-Message-State: ALoCoQmeBnOLngg7NzTtv+4cZNEYdZxxhUVjjqgSs46Deu47WU+Hw7nRDp9IsT/hc9TC6urq0k+y X-Received: by 10.66.102.36 with SMTP id fl4mr3019390pab.20.1386973569855; Fri, 13 Dec 2013 14:26:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.38.131 with SMTP id g3ls1078424qek.33.gmail; Fri, 13 Dec 2013 14:26:09 -0800 (PST) X-Received: by 10.221.51.206 with SMTP id vj14mr2218996vcb.17.1386973569669; Fri, 13 Dec 2013 14:26:09 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id k17si1192358vck.102.2013.12.13.14.26.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:09 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db12so1829877veb.36 for ; Fri, 13 Dec 2013 14:26:09 -0800 (PST) X-Received: by 10.52.0.9 with SMTP id 9mr1831444vda.47.1386973569559; Fri, 13 Dec 2013 14:26: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 u4csp73430vcz; Fri, 13 Dec 2013 14:26:09 -0800 (PST) X-Received: by 10.66.192.74 with SMTP id he10mr6094709pac.126.1386973568571; Fri, 13 Dec 2013 14:26:08 -0800 (PST) Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by mx.google.com with ESMTPS id qz9si2501837pab.133.2013.12.13.14.26.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.176 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.176; Received: by mail-pd0-f176.google.com with SMTP id w10so3035714pde.35 for ; Fri, 13 Dec 2013 14:26:08 -0800 (PST) X-Received: by 10.68.196.227 with SMTP id ip3mr5930576pbc.163.1386973568145; Fri, 13 Dec 2013 14:26: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 qz9sm7457908pbc.3.2013.12.13.14.26.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:07 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Rebecca Schultz Zavin , John Stultz Subject: [PATCH 003/115] ion: Switch map/unmap dma api to sg_tables Date: Fri, 13 Dec 2013 14:23:37 -0800 Message-Id: <1386973529-4884-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1386973529-4884-1-git-send-email-john.stultz@linaro.org> References: <1386973529-4884-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.128.177 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: Rebecca Schultz Zavin Switch these api's from scatterlists to sg_tables Signed-off-by: Rebecca Schultz Zavin [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 16 +++---- drivers/staging/android/ion/ion.h | 6 +-- drivers/staging/android/ion/ion_priv.h | 18 ++------ drivers/staging/android/ion/ion_system_heap.c | 66 ++++++++++++++++----------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index d93fb33..bca8d9e 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -445,11 +445,11 @@ void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle) return vaddr; } -struct scatterlist *ion_map_dma(struct ion_client *client, +struct sg_table *ion_map_dma(struct ion_client *client, struct ion_handle *handle) { struct ion_buffer *buffer; - struct scatterlist *sglist; + struct sg_table *table; mutex_lock(&client->lock); if (!ion_handle_validate(client, handle)) { @@ -469,16 +469,16 @@ struct scatterlist *ion_map_dma(struct ion_client *client, return ERR_PTR(-ENODEV); } if (_ion_map(&buffer->dmap_cnt, &handle->dmap_cnt)) { - sglist = buffer->heap->ops->map_dma(buffer->heap, buffer); - if (IS_ERR_OR_NULL(sglist)) + table = buffer->heap->ops->map_dma(buffer->heap, buffer); + if (IS_ERR_OR_NULL(table)) _ion_unmap(&buffer->dmap_cnt, &handle->dmap_cnt); - buffer->sglist = sglist; + buffer->sg_table = table; } else { - sglist = buffer->sglist; + table = buffer->sg_table; } mutex_unlock(&buffer->lock); mutex_unlock(&client->lock); - return sglist; + return table; } void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle) @@ -505,7 +505,7 @@ void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle) mutex_lock(&buffer->lock); if (_ion_unmap(&buffer->dmap_cnt, &handle->dmap_cnt)) { buffer->heap->ops->unmap_dma(buffer->heap, buffer); - buffer->sglist = NULL; + buffer->sg_table = NULL; } mutex_unlock(&buffer->lock); mutex_unlock(&client->lock); diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 60b2543..87f6a45 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -169,10 +169,10 @@ void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); * @client: the client * @handle: handle to map * - * Return an sglist describing the given handle + * Return an sg_table describing the given handle */ -struct scatterlist *ion_map_dma(struct ion_client *client, - struct ion_handle *handle); +struct sg_table *ion_map_dma(struct ion_client *client, + struct ion_handle *handle); /** * ion_unmap_dma() - destroy a dma mapping for a handle diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index cbd9f03..7a77f6f 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -24,18 +24,6 @@ #include "ion.h" -struct ion_mapping; - -struct ion_dma_mapping { - struct kref ref; - struct scatterlist *sglist; -}; - -struct ion_kernel_mapping { - struct kref ref; - void *vaddr; -}; - struct ion_buffer *ion_handle_buffer(struct ion_handle *handle); /** @@ -54,7 +42,7 @@ struct ion_buffer *ion_handle_buffer(struct ion_handle *handle); * @kmap_cnt: number of times the buffer is mapped to the kernel * @vaddr: the kenrel mapping if kmap_cnt is not zero * @dmap_cnt: number of times the buffer is mapped for dma - * @sglist: the scatterlist for the buffer is dmap_cnt is not zero + * @sg_table: the sg table for the buffer if dmap_cnt is not zero */ struct ion_buffer { struct kref ref; @@ -71,7 +59,7 @@ struct ion_buffer { int kmap_cnt; void *vaddr; int dmap_cnt; - struct scatterlist *sglist; + struct sg_table *sg_table; }; /** @@ -93,7 +81,7 @@ struct ion_heap_ops { void (*free) (struct ion_buffer *buffer); int (*phys) (struct ion_heap *heap, struct ion_buffer *buffer, ion_phys_addr_t *addr, size_t *len); - struct scatterlist *(*map_dma) (struct ion_heap *heap, + struct sg_table *(*map_dma) (struct ion_heap *heap, struct ion_buffer *buffer); void (*unmap_dma) (struct ion_heap *heap, struct ion_buffer *buffer); void * (*map_kernel) (struct ion_heap *heap, struct ion_buffer *buffer); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 3daa1ee..d7e0fa0 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -38,40 +38,46 @@ void ion_system_heap_free(struct ion_buffer *buffer) vfree(buffer->priv_virt); } -struct scatterlist *ion_system_heap_map_dma(struct ion_heap *heap, - struct ion_buffer *buffer) +struct sg_table *ion_system_heap_map_dma(struct ion_heap *heap, + struct ion_buffer *buffer) { - struct scatterlist *sglist; - struct page *page; + struct sg_table *table; + struct scatterlist *sg; int i; int npages = PAGE_ALIGN(buffer->size) / PAGE_SIZE; void *vaddr = buffer->priv_virt; + int ret; - sglist = vmalloc(npages * sizeof(struct scatterlist)); - if (!sglist) + table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!table) return ERR_PTR(-ENOMEM); - memset(sglist, 0, npages * sizeof(struct scatterlist)); - sg_init_table(sglist, npages); - for (i = 0; i < npages; i++) { + ret = sg_alloc_table(table, npages, GFP_KERNEL); + if (ret) + goto err0; + for_each_sg(table->sgl, sg, table->nents, i) { + struct page *page; page = vmalloc_to_page(vaddr); - if (!page) - goto end; - sg_set_page(&sglist[i], page, PAGE_SIZE, 0); + if (!page) { + ret = -ENOMEM; + goto err1; + } + sg_set_page(sg, page, PAGE_SIZE, 0); vaddr += PAGE_SIZE; } - /* XXX do cache maintenance for dma? */ - return sglist; -end: - vfree(sglist); - return NULL; + return table; +err1: + sg_free_table(table); +err0: + kfree(table); + return ERR_PTR(ret); } void ion_system_heap_unmap_dma(struct ion_heap *heap, struct ion_buffer *buffer) { - /* XXX undo cache maintenance for dma? */ - if (buffer->sglist) - vfree(buffer->sglist); + if (buffer->sg_table) + sg_free_table(buffer->sg_table); + kfree(buffer->sg_table); } void *ion_system_heap_map_kernel(struct ion_heap *heap, @@ -144,17 +150,23 @@ static int ion_system_contig_heap_phys(struct ion_heap *heap, return 0; } -struct scatterlist *ion_system_contig_heap_map_dma(struct ion_heap *heap, +struct sg_table *ion_system_contig_heap_map_dma(struct ion_heap *heap, struct ion_buffer *buffer) { - struct scatterlist *sglist; + struct sg_table *table; + int ret; - sglist = vmalloc(sizeof(struct scatterlist)); - if (!sglist) + table = kzalloc(sizeof(struct sg_table), GFP_KERNEL); + if (!table) return ERR_PTR(-ENOMEM); - sg_init_table(sglist, 1); - sg_set_page(sglist, virt_to_page(buffer->priv_virt), buffer->size, 0); - return sglist; + 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; } int ion_system_contig_heap_map_user(struct ion_heap *heap,