From patchwork Wed Oct 23 07:50:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 11205843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EFD114E5 for ; Wed, 23 Oct 2019 07:50:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 060AC2084C for ; Wed, 23 Oct 2019 07:50:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 060AC2084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8729E6E980; Wed, 23 Oct 2019 07:50:50 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75BA26E980 for ; Wed, 23 Oct 2019 07:50:48 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2019 00:50:47 -0700 X-IronPort-AV: E=Sophos;i="5.68,220,1569308400"; d="scan'208";a="201915786" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.17]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2019 00:50:44 -0700 From: Janusz Krzysztofik To: intel-gfx@lists.freedesktop.org Date: Wed, 23 Oct 2019 09:50:37 +0200 Message-Id: <20191023075039.21740-1-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 1/3] drm/i915/dmabuf: Implement pwrite() callback X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Vetter , Matthew Auld Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" We need dmabuf specific pwrite() callback utilizing dma-buf API, otherwise GEM_PWRITE IOCTL will no longer work with dma-buf backed (i.e., PRIME imported) objects on hardware with no mappable aperture. Signed-off-by: Janusz Krzysztofik Cc: Daniele Ceraolo Spurio Cc: Michal Wajdeczko --- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c index 96ce95c8ac5a..93eea1031c82 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c @@ -248,9 +248,64 @@ static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj, DMA_BIDIRECTIONAL); } +static int i915_gem_object_pwrite_dmabuf(struct drm_i915_gem_object *obj, + const struct drm_i915_gem_pwrite *args) +{ + struct dma_buf *dmabuf = obj->base.import_attach->dmabuf; + void __user *user_data = u64_to_user_ptr(args->data_ptr); + struct file *file = dmabuf->file; + const struct file_operations *fop = file->f_op; + void __force *vaddr; + int ret; + + if (fop->write) { + loff_t offset = args->offset; + + /* + * fop->write() is supposed to call dma_buf_begin_cpu_access() + * if O_SYNC flag is set, avoid calling it twice + */ + if (!(file->f_flags & O_SYNC)) { + ret = dma_buf_begin_cpu_access(dmabuf, DMA_TO_DEVICE); + if (ret) + return ret; + } + + ret = fop->write(file, user_data, args->size, &offset); + + if (!(file->f_flags & O_SYNC)) + dma_buf_end_cpu_access(dmabuf, DMA_TO_DEVICE); + + if (!ret) + return 0; + } + + /* dma-buf file .write() not supported or failed, try dma_buf_vmap() */ + ret = dma_buf_begin_cpu_access(dmabuf, DMA_TO_DEVICE); + if (ret) + return ret; + + vaddr = dma_buf_vmap(dmabuf); + if (!vaddr) + goto out_err; + + ret = copy_from_user(vaddr + args->offset, user_data, args->size); + dma_buf_vunmap(dmabuf, vaddr); + if (!ret) + goto out_end; + +out_err: + /* fall back to GTT mapping */ + ret = -ENODEV; +out_end: + dma_buf_end_cpu_access(dmabuf, DMA_TO_DEVICE); + return ret; +} + static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = { .get_pages = i915_gem_object_get_pages_dmabuf, .put_pages = i915_gem_object_put_pages_dmabuf, + .pwrite = i915_gem_object_pwrite_dmabuf, }; struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,