From patchwork Fri Jun 9 10:21:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 9777921 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 9243E6034B for ; Fri, 9 Jun 2017 10:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8229A285DD for ; Fri, 9 Jun 2017 10:21:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75485285E7; Fri, 9 Jun 2017 10:21:59 +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 1CA0D285DD for ; Fri, 9 Jun 2017 10:21:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 70FCE6E5BB; Fri, 9 Jun 2017 10:21:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39FA36E5B5; Fri, 9 Jun 2017 10:21:49 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id v104so5922764wrb.0; Fri, 09 Jun 2017 03:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lCSKaqMk+pCpd3vPBW0TGeWFTpUYn6C90gDtsHlmf2I=; b=cVZPnmFOXQY5jr7GYNm0Gjh46xDdtysuoCmx+eZzf+R0beYkdglRxuCOgE4+idEeOR 3BERFQ6cJ+WG/whd43e/nAAvP9fmvXpbY6Sw+UtW0gsOb86dsTalhxmK2iZEQiqp9kaR 0uECvmraafC4wn/pILoCZsaTqE1IIDQ5P3WLoMideDppLrHuMpR7UQ5w3pQKQoBpzR+L SrTYZSF8fmwhggluBSvRP/Fdcjz/DtAt3YNPBD9ZcCT153Sbbp95bchTkcSoT3RnBRPs h1zCf+glk46Nrjq45VMkazlQIkyFON7wE/1HcsxsJ6Ap4CtPMM02og+NkkXPdAHu0yHV TxGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lCSKaqMk+pCpd3vPBW0TGeWFTpUYn6C90gDtsHlmf2I=; b=S/4EXct0OEfPRB2GzsmxhLnvV5EtCikIrFg0hO0C5qoLAyuw3zrijwY7DElBlm1CyS NW7y7twbwZqTIFU+/Abgo9e6qux9ad91LRqvWq7uVJFFblipryEfDipLt81ruTTMyxiv GcyzNQFCgPAQUuaY1DKpLiFWwBXl0z/LguZwFgWQrLcZG5fUC83421mebgfGMXV/OnqJ YMGOjOXuuZ2bay6TF+3bgtsCpPZk4/6FBOc3EdS3T4d9JMFmSDvw9qYCGpMUeJCSFVxZ lxovwZfT3i9o6fv/X2scaDYXCd2MxaX38OvK+UtvFZccRkzRznP+VmqExsy1AnTH9mW5 QZmw== X-Gm-Message-State: AODbwcCo4SCt8OCl8szVKgACNSloqdDaUwHaAgGUEsCxBbC0pM0x68Cc ZheMWtL7hbn/7DkFTok= X-Received: by 10.223.136.48 with SMTP id d45mr29604372wrd.160.1497003707614; Fri, 09 Jun 2017 03:21:47 -0700 (PDT) Received: from localhost.localdomain (213-147-162-44.nat.highway.bob.at. [213.147.162.44]) by smtp.gmail.com with ESMTPSA id w52sm806952wrc.33.2017.06.09.03.21.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Jun 2017 03:21:46 -0700 (PDT) From: Christian Gmeiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/21] drm/etnaviv: copy pmrs from userspace Date: Fri, 9 Jun 2017 12:21:20 +0200 Message-Id: <20170609102123.2417-7-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170609102123.2417-1-christian.gmeiner@gmail.com> References: <20170609102123.2417-1-christian.gmeiner@gmail.com> Cc: linux+etnaviv@armlinux.org.uk, etnaviv@lists.freedesktop.org, 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 All performance monitor requests will be validated during this phase. Signed-off-by: Christian Gmeiner --- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 68 +++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c index fdfe31d..ed05b64 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c @@ -21,6 +21,7 @@ #include "etnaviv_drv.h" #include "etnaviv_gpu.h" #include "etnaviv_gem.h" +#include "etnaviv_perfmon.h" /* * Cmdstream submission: @@ -283,6 +284,53 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream, return 0; } +static int submit_perfmon_request(struct etnaviv_gem_submit *submit, + struct etnaviv_cmdbuf *cmdbuf, + const struct drm_etnaviv_gem_submit_pmr *pmrs, + u32 nr_pms) +{ + u32 i; + + for (i = 0; i < nr_pms; i++) { + const struct drm_etnaviv_gem_submit_pmr *r = pmrs + i; + struct etnaviv_gem_submit_bo *bo; + int ret; + + ret = submit_bo(submit, r->read_idx, &bo); + if (ret) + return ret; + + if (r->read_offset == 0) { + DRM_ERROR("perfmon request: offset is 0"); + return -EINVAL; + } + + if (r->read_offset >= bo->obj->base.size - sizeof(u32)) { + DRM_ERROR("perfmon request: offset %u outside object", i); + return -EINVAL; + } + + if (!r->flags) { + DRM_ERROR("perfmon request: flags are 0"); + return -EINVAL; + } + + if (etnaviv_pm_req_validate(r)) { + DRM_ERROR("perfmon request: domain or signal not valid"); + return -EINVAL; + } + + cmdbuf->pmrs[i].flags = r->flags; + cmdbuf->pmrs[i].domain = r->domain; + cmdbuf->pmrs[i].signal = r->signal; + cmdbuf->pmrs[i].sequence = r->sequence; + cmdbuf->pmrs[i].offset = r->read_offset; + cmdbuf->pmrs[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base); + } + + return 0; +} + static void submit_cleanup(struct etnaviv_gem_submit *submit) { unsigned i; @@ -306,6 +354,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_pmr *pmrs; struct drm_etnaviv_gem_submit_bo *bos; struct etnaviv_gem_submit *submit; struct etnaviv_cmdbuf *cmdbuf; @@ -347,11 +396,12 @@ 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)); + pmrs = drm_malloc_ab(args->nr_pmrs, sizeof(*pmrs)); stream = drm_malloc_ab(1, args->stream_size); cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, ALIGN(args->stream_size, 8) + 8, - args->nr_bos, 0); - if (!bos || !relocs || !stream || !cmdbuf) { + args->nr_bos, args->nr_pmrs); + if (!bos || !relocs || !pmrs || !stream || !cmdbuf) { ret = -ENOMEM; goto err_submit_cmds; } @@ -373,6 +423,13 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, goto err_submit_cmds; } + ret = copy_from_user(pmrs, u64_to_user_ptr(args->pmrs), + args->nr_pmrs * sizeof(*pmrs)); + if (ret) { + ret = -EFAULT; + goto err_submit_cmds; + } + ret = copy_from_user(stream, u64_to_user_ptr(args->stream), args->stream_size); if (ret) { @@ -441,8 +498,13 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, if (ret) goto out; + ret = submit_perfmon_request(submit, cmdbuf, pmrs, args->nr_pmrs); + if (ret) + goto out; + memcpy(cmdbuf->vaddr, stream, args->stream_size); cmdbuf->user_size = ALIGN(args->stream_size, 8); + cmdbuf->nr_pmrs = args->nr_pmrs; ret = etnaviv_gpu_submit(gpu, submit, cmdbuf); if (ret == 0) @@ -494,6 +556,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, drm_free_large(bos); if (relocs) drm_free_large(relocs); + if (pmrs) + drm_free_large(pmrs); return ret; }