From patchwork Fri Dec 13 22:23:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22383 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 51CC723FBA for ; Fri, 13 Dec 2013 22:26:35 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id e9sf4360044qcy.5 for ; Fri, 13 Dec 2013 14:26:35 -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=mw1oJ+LzoEaSF1MlEefHhmDaqxPm4uQe10qlIDu0BJc=; b=hxyHNf88v6uFzuQjnItg1/araTj1t9vf6Ctmm4SM9YGccnJXS9MPxlmqRCrcaQAZFB X2sxqiRLiljU1jAcMU+R2gvVbgtB0piiKM1+061tjY3/WdgSSAQFtzL+3CRfMc2ekbGQ Z1VXR7kyZgBCfgPez2TPqE1BgtvREg0f29v0ws1Ce2n5bL9McFcqHcj1dYedrzqi1iXu wjAXUE1Jae5vOMlXp85SXkBwOtSoI27bQTTGMWdfYgjGOGNre//KAYo1RQcME+7vvY68 eIAmLLvmnBtFs8yrECoSrhH983DsjKjzVkTwMp72CrrbZLDetOAo0+QakDKg2PD9N7uL 0y7g== X-Gm-Message-State: ALoCoQkKeuOGufgmRjCEDsvZ4JDtm/bJed9fX15dQmG5cJqvzrPE4JPUdF5u0m/tlMF54NZTPmzd X-Received: by 10.58.204.2 with SMTP id ku2mr1649981vec.39.1386973595158; Fri, 13 Dec 2013 14:26:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.121.98 with SMTP id lj2ls1195685qeb.45.gmail; Fri, 13 Dec 2013 14:26:35 -0800 (PST) X-Received: by 10.52.244.73 with SMTP id xe9mr1314393vdc.78.1386973595024; Fri, 13 Dec 2013 14:26:35 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id gq10si1193236vdc.69.2013.12.13.14.26.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 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.54; Received: by mail-vb0-f54.google.com with SMTP id g10so1760200vbg.27 for ; Fri, 13 Dec 2013 14:26:34 -0800 (PST) X-Received: by 10.220.186.202 with SMTP id ct10mr2255769vcb.14.1386973594942; Fri, 13 Dec 2013 14:26:34 -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 u4csp73472vcz; Fri, 13 Dec 2013 14:26:34 -0800 (PST) X-Received: by 10.66.217.166 with SMTP id oz6mr6190651pac.22.1386973594126; Fri, 13 Dec 2013 14:26:34 -0800 (PST) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id tt8si2521971pbc.48.2013.12.13.14.26.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.50; Received: by mail-pb0-f50.google.com with SMTP id rr13so3162411pbb.9 for ; Fri, 13 Dec 2013 14:26:33 -0800 (PST) X-Received: by 10.66.16.131 with SMTP id g3mr6108704pad.138.1386973593730; Fri, 13 Dec 2013 14:26:33 -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.31 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:26:32 -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 018/115] gpu: ion: Add explicit sync ioctl Date: Fri, 13 Dec 2013 14:23:52 -0800 Message-Id: <1386973529-4884-19-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.212.54 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 This is deprecated in favor of using the dma_buf api which will automatically sync a buffer to memory when it is mapped to a device. However, that functionality is not ready, so this patch adds the ability to sync a buffer explicitly. 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 | 38 ++++++++++++++++++++++++++++++++++++-- drivers/staging/android/ion/ion.h | 12 +++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index bc9e922..d4e4c68 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -684,8 +684,7 @@ 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; - if (buffer->flags & ION_FLAG_CACHED) - ion_buffer_sync_for_device(buffer, attachment->dev, direction); + ion_buffer_sync_for_device(buffer, attachment->dev, direction); return buffer->sg_table; } @@ -721,6 +720,10 @@ static void ion_buffer_sync_for_device(struct ion_buffer *buffer, pr_debug("%s: syncing for device %s\n", __func__, dev ? dev_name(dev) : "null"); + + if (!(buffer->flags & ION_FLAG_CACHED)) + return; + mutex_lock(&buffer->lock); for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) { if (!test_bit(i, buffer->dirty)) @@ -958,6 +961,28 @@ end: return handle; } +static int ion_sync_for_device(struct ion_client *client, int fd) +{ + struct dma_buf *dmabuf; + struct ion_buffer *buffer; + + dmabuf = dma_buf_get(fd); + if (IS_ERR_OR_NULL(dmabuf)) + return PTR_ERR(dmabuf); + + /* if this memory came from ion */ + if (dmabuf->ops != &dma_buf_ops) { + pr_err("%s: can not sync dmabuf from another exporter\n", + __func__); + dma_buf_put(dmabuf); + return -EINVAL; + } + buffer = dmabuf->priv; + ion_buffer_sync_for_device(buffer, NULL, DMA_BIDIRECTIONAL); + dma_buf_put(dmabuf); + return 0; +} + static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct ion_client *client = filp->private_data; @@ -1022,6 +1047,15 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return -EFAULT; break; } + case ION_IOC_SYNC: + { + struct ion_fd_data data; + if (copy_from_user(&data, (void __user *)arg, + sizeof(struct ion_fd_data))) + return -EFAULT; + ion_sync_for_device(client, data.fd); + break; + } case ION_IOC_CUSTOM: { struct ion_device *dev = client->dev; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 88b9a2f..83baa38 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -328,7 +328,17 @@ struct ion_custom_data { * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle * filed set to the corresponding opaque handle. */ -#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, int) +#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) + +/** + * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory + * + * Deprecated in favor of using the dma_buf api's correctly (syncing + * will happend automatically when the buffer is mapped to a device). + * If necessary should be used after touching a cached buffer from the cpu, + * this will make the buffer in memory coherent. + */ +#define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) /** * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl