From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752002AbcEYTsk (ORCPT ); Wed, 25 May 2016 15:48:40 -0400 Received: from mail-qk0-f174.google.com ([209.85.220.174]:33557 "EHLO mail-qk0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751205AbcEYTsi (ORCPT ); Wed, 25 May 2016 15:48:38 -0400 From: Laura Abbott To: Sumit Semwal , John Stultz , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Riley Andrews Cc: Laura Abbott , Daniel Vetter , linaro-mm-sig@lists.linaro.org, devel@driverdev.osuosl.org, Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Eun Taik Lee , Rohit kumar , Liviu Dudau , Jon Medhurst , Mitchel Humpherys , Jeremy Gebben , Bryan Huntsman , Greg Kroah-Hartman , Android Kernel Team Subject: [RFC][PATCH 3/3] staging: ion: Add dma_map/dma_unmap calls to dma_buf calls Date: Wed, 25 May 2016 12:48:04 -0700 Message-Id: <1464205684-5587-4-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464205684-5587-1-git-send-email-labbott@redhat.com> References: <1464205684-5587-1-git-send-email-labbott@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The .map_dma_buf/.unmap_dma_buf function calls are designed for buffer users to perform DMA accesses. Ion doesn't call into the lower DMA layer currently. This may leave mapping incomplete for devices with more complex topologies (e.g. IOMMUs). Add the appropriate dma_map calls to the dma_buf call backs. Signed-off-by: Laura Abbott --- drivers/staging/android/ion/ion.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 2096592..52dbea4 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -980,7 +980,18 @@ static struct sg_table *ion_map_dma_buf(struct dma_buf_attachment *attachment, struct dma_buf *dmabuf = attachment->dmabuf; struct ion_buffer *buffer = dmabuf->priv; + /* Necessary but not sufficient: This is for userspace */ ion_buffer_sync_for_device(buffer, attachment->dev, direction); + + /* The rest of this is for the standard mappings */ + buffer->sg_table->nents = dma_map_sg(attachment->dev, + buffer->sg_table->sgl, + buffer->sg_table->orig_nents, + direction); + + if (!buffer->sg_table->nents) + return ERR_PTR(-EIO); + return buffer->sg_table; } @@ -988,6 +999,7 @@ static void ion_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table, enum dma_data_direction direction) { + dma_unmap_sg(attachment->dev, table->sgl, table->nents, direction); } static int ion_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) -- 2.5.5