From patchwork Mon Sep 12 21:32:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9328133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C80860231 for ; Mon, 12 Sep 2016 21:36:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B89028ED0 for ; Mon, 12 Sep 2016 21:36:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8046728ED8; Mon, 12 Sep 2016 21:36:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA1D428ED0 for ; Mon, 12 Sep 2016 21:36:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bjYsM-0005gy-Nc; Mon, 12 Sep 2016 21:34:50 +0000 Received: from mail-yb0-f181.google.com ([209.85.213.181]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bjYrD-00053X-Bo for linux-arm-kernel@lists.infradead.org; Mon, 12 Sep 2016 21:33:43 +0000 Received: by mail-yb0-f181.google.com with SMTP id u125so55244344ybg.3 for ; Mon, 12 Sep 2016 14:33:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eUBuRHbjf6pag0HFqzZPTlwa1Nl8lntn+UajR/pzooY=; b=B5hNMrQLub/BI5dSIq8paESVvhZdPSz9GUlNC6QuQ/+g3BqHKC7bQMo++fFz6MWCln 0YWCa0rDMDQbNuq6mYcQovuDQ1TVH/wOv6rHUoD61LBfwAOVf6t1iGSuuhMuhvpZMVGt fXt1eT/5J5tbbdOphStR0OwBdorNkBLdWcemevhnUUKj86KIPbhkDHpmVs9sz0w+8Ej3 XJ7S1ZNGi4w5YQu/x3usPTWzOlY8AlalxmEbSmSUMg30jihNrT9ZtklSzb+hr3v5XCrB AMgfJUDiqJ6CTz8V8CGrCkAb35iYZe0y6PH9IL6er2BZJS7JWq8iPUmCqok90f+NALHg uj/A== X-Gm-Message-State: AE9vXwO/KUzdyUeP/yUzrwLOUBck6ihxe9/VtwleMhGaeucH1jw3htIpYnMQX5T1qR0GSx9a X-Received: by 10.37.47.138 with SMTP id v132mr21223984ybv.102.1473715997934; Mon, 12 Sep 2016 14:33:17 -0700 (PDT) Received: from labbott-redhat-machine.redhat.com ([2601:602:9800:177f::2946]) by smtp.gmail.com with ESMTPSA id x184sm5644931ywe.56.2016.09.12.14.33.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Sep 2016 14:33:16 -0700 (PDT) From: Laura Abbott To: Sumit Semwal , John Stultz , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Riley Andrews Subject: [RFCv3][PATCH 4/5] staging: android: ion: Convert to the kernel_force_cache APIs Date: Mon, 12 Sep 2016 14:32:57 -0700 Message-Id: <1473715978-11633-5-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473715978-11633-1-git-send-email-labbott@redhat.com> References: <1473715978-11633-1-git-send-email-labbott@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160912_143339_643078_2EFD1EF6 X-CRM114-Status: GOOD ( 17.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devel@driverdev.osuosl.org, Jon Medhurst , Android Kernel Team , Arnd Bergmann , Greg Kroah-Hartman , Daniel Vetter , Will Deacon , Russell King , linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, Rohit kumar , Bryan Huntsman , Eun Taik Lee , Catalin Marinas , Liviu Dudau , Laura Abbott , Jeremy Gebben , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now that there exists a proper set of cache sync APIs, move away from the dma_sync and do less bad things. Signed-off-by: Laura Abbott --- v3: Rebased to latest-next --- drivers/staging/android/ion/ion.c | 22 ++++------------------ drivers/staging/android/ion/ion_carveout_heap.c | 8 +++++--- drivers/staging/android/ion/ion_chunk_heap.c | 12 +++++++----- drivers/staging/android/ion/ion_page_pool.c | 7 ++++--- drivers/staging/android/ion/ion_priv.h | 11 ----------- drivers/staging/android/ion/ion_system_heap.c | 6 +++--- 6 files changed, 23 insertions(+), 43 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 396ded5..c2125de 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -37,6 +37,8 @@ #include #include +#include + #include "ion.h" #include "ion_priv.h" #include "compat_ion.h" @@ -817,22 +819,6 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, { } -void ion_pages_sync_for_device(struct device *dev, struct page *page, - size_t size, enum dma_data_direction dir) -{ - struct scatterlist sg; - - sg_init_table(&sg, 1); - sg_set_page(&sg, page, size, 0); - /* - * This is not correct - sg_dma_address needs a dma_addr_t that is valid - * for the targeted device, but this works on the currently targeted - * hardware. - */ - sg_dma_address(&sg) = page_to_phys(page); - dma_sync_sg_for_device(dev, &sg, 1, dir); -} - struct ion_vma_list { struct list_head list; struct vm_area_struct *vma; @@ -857,8 +843,8 @@ static void ion_buffer_sync_for_device(struct ion_buffer *buffer, struct page *page = buffer->pages[i]; if (ion_buffer_page_is_dirty(page)) - ion_pages_sync_for_device(dev, ion_buffer_page(page), - PAGE_SIZE, dir); + kernel_force_cache_clean(ion_buffer_page(page), + PAGE_SIZE); ion_buffer_page_clean(buffer->pages + i); } diff --git a/drivers/staging/android/ion/ion_carveout_heap.c b/drivers/staging/android/ion/ion_carveout_heap.c index c4f0795..af81edc 100644 --- a/drivers/staging/android/ion/ion_carveout_heap.c +++ b/drivers/staging/android/ion/ion_carveout_heap.c @@ -22,6 +22,9 @@ #include #include #include + +#include + #include "ion.h" #include "ion_priv.h" @@ -105,8 +108,7 @@ static void ion_carveout_heap_free(struct ion_buffer *buffer) ion_heap_buffer_zero(buffer); if (ion_buffer_cached(buffer)) - dma_sync_sg_for_device(NULL, table->sgl, table->nents, - DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, buffer->size); ion_carveout_free(heap, paddr, buffer->size); sg_free_table(table); @@ -132,7 +134,7 @@ struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *heap_data) page = pfn_to_page(PFN_DOWN(heap_data->base)); size = heap_data->size; - ion_pages_sync_for_device(NULL, page, size, DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, size); ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL)); if (ret) diff --git a/drivers/staging/android/ion/ion_chunk_heap.c b/drivers/staging/android/ion/ion_chunk_heap.c index 70495dc..f6d1bae 100644 --- a/drivers/staging/android/ion/ion_chunk_heap.c +++ b/drivers/staging/android/ion/ion_chunk_heap.c @@ -21,6 +21,9 @@ #include #include #include + +#include + #include "ion.h" #include "ion_priv.h" @@ -104,11 +107,10 @@ static void ion_chunk_heap_free(struct ion_buffer *buffer) ion_heap_buffer_zero(buffer); - if (ion_buffer_cached(buffer)) - dma_sync_sg_for_device(NULL, table->sgl, table->nents, - DMA_BIDIRECTIONAL); - for_each_sg(table->sgl, sg, table->nents, i) { + if (ion_buffer_cached(buffer)) + kernel_force_cache_clean(sg_page(table->sgl), + sg->length); gen_pool_free(chunk_heap->pool, page_to_phys(sg_page(sg)), sg->length); } @@ -135,7 +137,7 @@ struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *heap_data) page = pfn_to_page(PFN_DOWN(heap_data->base)); size = heap_data->size; - ion_pages_sync_for_device(NULL, page, size, DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, size); ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL)); if (ret) diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c index aea89c1..f289d88 100644 --- a/drivers/staging/android/ion/ion_page_pool.c +++ b/drivers/staging/android/ion/ion_page_pool.c @@ -22,6 +22,9 @@ #include #include #include + +#include + #include "ion_priv.h" static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) @@ -30,9 +33,7 @@ static void *ion_page_pool_alloc_pages(struct ion_page_pool *pool) if (!page) return NULL; - if (!pool->cached) - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << pool->order, - DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, PAGE_SIZE << pool->order); return page; } diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 3c3b324..a344190 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -441,17 +441,6 @@ void ion_page_pool_free(struct ion_page_pool *, struct page *); int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, int nr_to_scan); -/** - * ion_pages_sync_for_device - cache flush pages for use with the specified - * device - * @dev: the device the pages will be used with - * @page: the first page to be flushed - * @size: size in bytes of region to be flushed - * @dir: direction of dma transfer - */ -void ion_pages_sync_for_device(struct device *dev, struct page *page, - size_t size, enum dma_data_direction dir); - long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); int ion_sync_for_device(struct ion_client *client, int fd); diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 7e023d5..8eefe83 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "ion.h" #include "ion_priv.h" @@ -76,8 +77,7 @@ static struct page *alloc_buffer_page(struct ion_system_heap *heap, page = ion_page_pool_alloc(pool); if (cached) - ion_pages_sync_for_device(NULL, page, PAGE_SIZE << order, - DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, PAGE_SIZE << order); return page; } @@ -408,7 +408,7 @@ static int ion_system_contig_heap_allocate(struct ion_heap *heap, buffer->sg_table = table; - ion_pages_sync_for_device(NULL, page, len, DMA_BIDIRECTIONAL); + kernel_force_cache_clean(page, len); return 0;