From patchwork Fri Dec 9 11:21:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 9467961 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 A163460586 for ; Fri, 9 Dec 2016 11:22:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E881285C8 for ; Fri, 9 Dec 2016 11:22:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 713F9285F7; Fri, 9 Dec 2016 11:22:26 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F0B60285C8 for ; Fri, 9 Dec 2016 11:22:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1436D6E97D; Fri, 9 Dec 2016 11:22:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x243.google.com (mail-wj0-x243.google.com [IPv6:2a00:1450:400c:c01::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE3986E97C for ; Fri, 9 Dec 2016 11:21:52 +0000 (UTC) Received: by mail-wj0-x243.google.com with SMTP id j10so1978748wjb.3 for ; Fri, 09 Dec 2016 03:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8nMXz4KoTzwGCD6VK7vM7cpWJTJY0J67CdCEv3yndlo=; b=Bd3pznViE5nNzGgSiCMZPjGa8cdSIrbQtxWNt+nKJMxJrxM+nz3j/haVC4SxWnjgXX nXH/Ydn+mSDSF5chbmlWhFdDNNtBBV4uH1gBmpr0jHuYS+dxBWZaRo0DSRyDAPordipc t4wChlpgZMlFNPDe2tu2xTJS9rDh8l0hVGn+r/GnbP2prBuGoPxOymMgOElW7+evz/FS G3euN2ZSKlUp/8AwVMRZ4WVhvV4pYhcw/BWc/dbSJErJ1b1oHHeJAUAmfbQ3EQ3rHZqA VmsJw6fDuokBvDIuZaBjl+Rkz0rQ7IJuvslRGU5DDGiQ2OJ4InnpmDpFgXzd2AiJEUfI if7A== 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=8nMXz4KoTzwGCD6VK7vM7cpWJTJY0J67CdCEv3yndlo=; b=FKI7Y+vqV9eoYrPsIMUjWqDqV88hyZgiMoHokbyrBy0XiVyh6eXwJkkhUwxOHJGFe7 zlPtdWwmNAcJZblyNeLuVkXDaW0WAEnxRp0216F4B+m6WT9RNmyjtAoR3GQzXI5fkOiJ BQdeVs49k7ynsmftLbScZ6Q4pZ9Dd8PAjxTf2imiGMZx/9t4KoiF5HbMDOey4c629ymj +fnI9k/L3CI2zs9USpIEdn0bEFotGr9+akAbMafAzIlaF7SZ0iSepqNYxV91VLytfKrb dQbedLS2NQP2fOkJE9QoofWvOM5yj6HHbLNi1ge8UBDHlFmd8lRol3nWaRbW60rbsEap u/cg== X-Gm-Message-State: AKaTC01YtP39BL95eVCTJ4JL6E/l6XkUbtZE9vT5IMXx5wKFaDO3uCodd3amWUL4TutxVQ== X-Received: by 10.194.94.166 with SMTP id dd6mr77182674wjb.88.1481282511044; Fri, 09 Dec 2016 03:21:51 -0800 (PST) Received: from linux.fritz.box.fritz.box (178-190-139-123.adsl.highway.telekom.at. [178.190.139.123]) by smtp.gmail.com with ESMTPSA id v2sm41824518wja.41.2016.12.09.03.21.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Dec 2016 03:21:50 -0800 (PST) From: Christian Gmeiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/10] drm/etnaviv: copy readbacks from userspace Date: Fri, 9 Dec 2016 12:21:26 +0100 Message-Id: <20161209112131.3924-6-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161209112131.3924-1-christian.gmeiner@gmail.com> References: <20161209112131.3924-1-christian.gmeiner@gmail.com> Cc: linux+etnaviv@armlinux.org.uk, cphealy@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 53 ++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c index ede5d71..a69eff7 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c @@ -277,6 +277,40 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream, return 0; } +static int submit_readback(struct etnaviv_gem_submit *submit, + struct etnaviv_cmdbuf *cmdbuf, + const struct drm_etnaviv_gem_submit_readback *readbacks, + u32 nr_readbacks) +{ + u32 i; + + for (i = 0; i < nr_readbacks; i++) { + const struct drm_etnaviv_gem_submit_readback *r = readbacks + i; + struct etnaviv_gem_submit_bo *bo; + int ret; + + ret = submit_bo(submit, r->readback_idx, &bo); + if (ret) + return ret; + + if (r->readback_offset >= bo->obj->base.size - sizeof(u32)) { + DRM_ERROR("readback offset %u outside object", i); + return -EINVAL; + } + + if (r->flags) { + DRM_ERROR("readback flags not 0"); + return -EINVAL; + } + + cmdbuf->readbacks[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base); + cmdbuf->readbacks[i].offset = r->readback_offset; + cmdbuf->readbacks[i].reg = r->reg; + } + + return 0; +} + static void submit_cleanup(struct etnaviv_gem_submit *submit) { unsigned i; @@ -298,6 +332,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, struct etnaviv_drm_private *priv = dev->dev_private; struct drm_etnaviv_gem_submit *args = data; struct drm_etnaviv_gem_submit_reloc *relocs; + struct drm_etnaviv_gem_submit_readback *readbacks; struct drm_etnaviv_gem_submit_bo *bos; struct etnaviv_gem_submit *submit; struct etnaviv_cmdbuf *cmdbuf; @@ -331,10 +366,11 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, */ bos = drm_malloc_ab(args->nr_bos, sizeof(*bos)); relocs = drm_malloc_ab(args->nr_relocs, sizeof(*relocs)); + readbacks = drm_malloc_ab(args->nr_readbacks, sizeof(*readbacks)); stream = drm_malloc_ab(1, args->stream_size); cmdbuf = etnaviv_gpu_cmdbuf_new(gpu, ALIGN(args->stream_size, 8) + 8, - args->nr_bos, 0); - if (!bos || !relocs || !stream || !cmdbuf) { + args->nr_bos, args->nr_readbacks); + if (!bos || !relocs || !readbacks || !stream || !cmdbuf) { ret = -ENOMEM; goto err_submit_cmds; } @@ -356,6 +392,13 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, goto err_submit_cmds; } + ret = copy_from_user(readbacks, u64_to_user_ptr(args->readbacks), + args->nr_readbacks * sizeof(*readbacks)); + if (ret) { + ret = -EFAULT; + goto err_submit_cmds; + } + ret = copy_from_user(stream, u64_to_user_ptr(args->stream), args->stream_size); if (ret) { @@ -396,6 +439,10 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, if (ret) goto out; + ret = submit_readback(submit, cmdbuf, readbacks, args->nr_readbacks); + if (ret) + goto out; + memcpy(cmdbuf->vaddr, stream, args->stream_size); cmdbuf->user_size = ALIGN(args->stream_size, 8); @@ -429,6 +476,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, drm_free_large(bos); if (relocs) drm_free_large(relocs); + if (readbacks) + drm_free_large(readbacks); return ret; }