From patchwork Fri Dec 13 22:24:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 22425 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8D45B23FBA for ; Fri, 13 Dec 2013 22:27:43 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id vb8sf8730779obc.0 for ; Fri, 13 Dec 2013 14:27:43 -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=WBL0/w22UhWsyNADTeRce+b5Kgl4mx2u6iTB3BjOyL0=; b=ZIOmFRZLyde7opw/LpQ5qI8GkmdkdZ/uGrGgQeg8BfHu09m6/uYSebW05+Yq2M43pi egm5jNSMN07HMOSqHKXT1QmWHfAym0kTxoJdL6nM00gaTkj4Xm6Yv0OLzjTfch6djTdw E9d2J5en4ZpNBCHEaYIOzsZKSei+usZ7BQG4681LL0X9nS1T5jZo+ZB5neh0u6gV9ypJ qYLXEfBffTZ6mC3vVv9ZSgXLNMZJKJHgMdxgt5v1Yy8fzkEkUn62K7uifnLqrsPc6QaG PmubyJFGNt8cTdsoEalqFqsQwYEZzgiVfs8gdPK2E8Z4MzrtYGDw2b1ksNWlViDg8qHY eVTA== X-Gm-Message-State: ALoCoQl+Ds9u/mX2xbTVu1XtuTXTdkXopgW4zfOo8JQbDiyN9Ky6Oc6g8zC583U0XqxWV0+E3Uic X-Received: by 10.50.126.69 with SMTP id mw5mr2248674igb.7.1386973663155; Fri, 13 Dec 2013 14:27:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.105.193 with SMTP id go1ls1210860qeb.97.gmail; Fri, 13 Dec 2013 14:27:42 -0800 (PST) X-Received: by 10.58.217.169 with SMTP id oz9mr2180458vec.42.1386973662926; Fri, 13 Dec 2013 14:27:42 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id fu7si939844vec.69.2013.12.13.14.27.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:42 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id lh4so1736458vcb.37 for ; Fri, 13 Dec 2013 14:27:42 -0800 (PST) X-Received: by 10.52.75.99 with SMTP id b3mr929434vdw.80.1386973662855; Fri, 13 Dec 2013 14:27:42 -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 u4csp73568vcz; Fri, 13 Dec 2013 14:27:42 -0800 (PST) X-Received: by 10.66.20.225 with SMTP id q1mr5960849pae.57.1386973661859; Fri, 13 Dec 2013 14:27:41 -0800 (PST) Received: from mail-pb0-f41.google.com (mail-pb0-f41.google.com [209.85.160.41]) by mx.google.com with ESMTPS id v7si2525474pbi.8.2013.12.13.14.27.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:41 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.41 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.41; Received: by mail-pb0-f41.google.com with SMTP id jt11so3160223pbb.0 for ; Fri, 13 Dec 2013 14:27:41 -0800 (PST) X-Received: by 10.68.134.98 with SMTP id pj2mr6088791pbb.110.1386973661459; Fri, 13 Dec 2013 14:27:41 -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.27.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 13 Dec 2013 14:27:40 -0800 (PST) From: John Stultz To: LKML Cc: Greg KH , Android Kernel Team , Sumit Semwal , Jesse Barker , Colin Cross , Johan Mossberg , John Stultz Subject: [PATCH 060/115] gpu: ion: Add support for sharing buffers with dma buf kernel handles Date: Fri, 13 Dec 2013 14:24:34 -0800 Message-Id: <1386973529-4884-61-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.220.178 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: Johan Mossberg Currently ion can only share buffers with dma buf fd's. Fd's can not be used inside the kernel as they are process specific so support for sharing buffers with dma buf kernel handles is needed to support kernel only use cases. An example use case could be a GPU driver using ion that wants to share its output buffers with a 3d party display controller driver supporting dma buf. Signed-off-by: Johan Mossberg [jstultz: modified patch to apply to staging directory] Signed-off-by: John Stultz --- drivers/staging/android/ion/ion.c | 26 ++++++++++++++++++++------ drivers/staging/android/ion/ion.h | 12 ++++++++++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 054e672..ba65bef 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -949,19 +949,19 @@ struct dma_buf_ops dma_buf_ops = { .kunmap = ion_dma_buf_kunmap, }; -int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) +struct dma_buf *ion_share_dma_buf(struct ion_client *client, + struct ion_handle *handle) { struct ion_buffer *buffer; struct dma_buf *dmabuf; bool valid_handle; - int fd; mutex_lock(&client->lock); valid_handle = ion_handle_validate(client, handle); mutex_unlock(&client->lock); if (!valid_handle) { WARN(1, "%s: invalid handle passed to share.\n", __func__); - return -EINVAL; + return ERR_PTR(-EINVAL); } buffer = handle->buffer; @@ -969,15 +969,29 @@ int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle) dmabuf = dma_buf_export(buffer, &dma_buf_ops, buffer->size, O_RDWR); if (IS_ERR(dmabuf)) { ion_buffer_put(buffer); - return PTR_ERR(dmabuf); + return dmabuf; } + + return dmabuf; +} +EXPORT_SYMBOL(ion_share_dma_buf); + +int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle) +{ + struct dma_buf *dmabuf; + int fd; + + dmabuf = ion_share_dma_buf(client, handle); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + fd = dma_buf_fd(dmabuf, O_CLOEXEC); if (fd < 0) dma_buf_put(dmabuf); return fd; } -EXPORT_SYMBOL(ion_share_dma_buf); +EXPORT_SYMBOL(ion_share_dma_buf_fd); struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) { @@ -1086,7 +1100,7 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (copy_from_user(&data, (void __user *)arg, sizeof(data))) return -EFAULT; - data.fd = ion_share_dma_buf(client, data.handle); + data.fd = ion_share_dma_buf_fd(client, data.handle); if (copy_to_user((void __user *)arg, &data, sizeof(data))) return -EFAULT; if (data.fd < 0) diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 0f67014f..976123b 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -212,11 +212,19 @@ void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle); void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle); /** - * ion_share_dma_buf() - given an ion client, create a dma-buf fd + * ion_share_dma_buf() - share buffer as dma-buf * @client: the client * @handle: the handle */ -int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle); +struct dma_buf *ion_share_dma_buf(struct ion_client *client, + struct ion_handle *handle); + +/** + * ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd + * @client: the client + * @handle: the handle + */ +int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle); /** * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle