Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6954133ybl; Wed, 15 Jan 2020 12:59:32 -0800 (PST) X-Google-Smtp-Source: APXvYqygaOPETyRPZMpjirSXgunyF9bjOxdYz1DYTqWoHU7mHNLRsEce1ZvlYKqucfb25/NcRPJI X-Received: by 2002:aca:2109:: with SMTP id 9mr1344824oiz.119.1579121972143; Wed, 15 Jan 2020 12:59:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579121972; cv=none; d=google.com; s=arc-20160816; b=RZ0eZRj8uP2wOCQ7xCrrcm+41UDedqzCv2ICIFSuFYBNjMkaPNJq5uHPhSvrAjAsTH INfbAo6Sn0IBmt0/N5T44T30xVEEh5V6IoESFhxKEUzgwi/pJwD7jtp4CfRNFcsmwX1E amrnWBPR2CVQO258fEjSY8HuxcZ5fVqqB4imMgvEanfJGcxirIIRYHJxHyqY1XCLK6la MS+hxzkTccmtUiwtfDuFAeLVvnvDlOEmUT6aa6kjnqvECSi0M9IXs+3erSKUHFyIGv40 rA31kLHcC/6KqqHvvpfzjmVPP5AdtojSQFkPkjEWBpvtJOLnCANrhOS8yFqD3Uf+D1ge SD+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MoaLqRsXbsF8WWfj7JkWTIfWhuB0czfd/jbk7/+hexM=; b=lZ3j2UCaoEgL2HQvsUt5uRKMkMtOJstG8CRx4l0EqCMhhHri8pD2kbXnxYcCYd5QPo hXTb8ky0bXeyDxgMr0++LKMIO3EDE93TQI1Umhm51/YwRQ5TsRaUkuQ+jbJ7uHGU4Abd xdQC55qbGk/qXMLCBeUlrMD/iTaKP6sSz8pV+MkUBHIEO81VuNpOk4XXouXxqApME9Ip 0F5JBGG4xcGfHp8WfORV9ZYIvJlHhmw2AiCw+VbV9i/qW7/V181+c2eojJdakfnggK8O VYFtGRad8D8ETMta6tssJ+jWGsrcRUnY0/pEg02CGtZmnX+yF4p0irzsvK8y6CF4beZE HJIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brkho-com.20150623.gappssmtp.com header.s=20150623 header.b=ksKqKO6U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 25si9930360oiz.230.2020.01.15.12.59.19; Wed, 15 Jan 2020 12:59:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brkho-com.20150623.gappssmtp.com header.s=20150623 header.b=ksKqKO6U; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729366AbgAOU5j (ORCPT + 99 others); Wed, 15 Jan 2020 15:57:39 -0500 Received: from mail-vs1-f98.google.com ([209.85.217.98]:44401 "EHLO mail-vs1-f98.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728909AbgAOU5i (ORCPT ); Wed, 15 Jan 2020 15:57:38 -0500 Received: by mail-vs1-f98.google.com with SMTP id p6so11307486vsj.11 for ; Wed, 15 Jan 2020 12:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brkho-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MoaLqRsXbsF8WWfj7JkWTIfWhuB0czfd/jbk7/+hexM=; b=ksKqKO6Uhobvq/K9pBY4ix3j3Vkphyaa/mEZ535OVhGl9gLs0a7c8MJ5OmR87Vf+10 5mEsnaytE8agpwaKvl+1JEpKFyCVqGXGk86ZEtZDhZl64V1b7FlM27TjWUdL+TViZxBr roDScgykIksCyMPlsZf2jsPV2NY9Y3e/rhuaNaqSrYV1O65LVpJ2eBs1boUQZfSdB88/ FS2am7QPK8rOs/bSwXlNR0jhR4M4myAQGPv8450qrCSUmpsW6VzDcm5oAIwLOsYH31rw Cuu/fvR7S3p40ad5eRyeky7sPs/tRlm3g9z2FKx2uIfPngHMJLMwqXmStnxes1H731++ kwVw== 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:mime-version:content-transfer-encoding; bh=MoaLqRsXbsF8WWfj7JkWTIfWhuB0czfd/jbk7/+hexM=; b=LntkLpAjKeCYrJRO9HiL+kYAEPlolBtoX5AQYvpZnKBcKh325IHmAKoLcHBGKQ0ck2 eYV755024uG3u4BcYVR52hAHjl1kCYDC8PRbzektu2HwwwJF6jxhq2ZTsr6iah6QZdDZ QwsLpyeXXqeXZxWK2wSapYw+TO5Wo2GUHF/KUJsX7CIcNPvIzDow+BQes9rwU4dGmHRw rAqnlw5HgMYy6Q45+bk57isAkGydwfKYY4V5xv0gLJq9d3xxZqhQ7Q2dkZPzBOjIfaR9 ANzXwcvzyiot7niosMBWPA78llWkOv+Ds0Dgcg6mowUqflXcXidm+0uHz6Mw2ef9AMhT JQQg== X-Gm-Message-State: APjAAAV2rWo6CAQ1Z6ZwQmmhQzyO8GKm1uShc1CVfhMXDSYGcdwQ2Blz 6488MiURPqBZgOTZnPOOSHb4APnq/G0G/Mw8DkUhtKAePD8nJA== X-Received: by 2002:a67:6746:: with SMTP id b67mr5544300vsc.193.1579121856991; Wed, 15 Jan 2020 12:57:36 -0800 (PST) Received: from hob1.nyc.corp.google.com ([100.118.32.120]) by smtp-relay.gmail.com with ESMTPS id j26sm1472756uak.1.2020.01.15.12.57.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2020 12:57:36 -0800 (PST) X-Relaying-Domain: brkho.com From: Brian Ho To: freedreno@lists.freedesktop.org Cc: hoegsberg@chromium.org, robdclark@chromium.org, jcrouse@codeaurora.org, Brian Ho , Rob Clark , Sean Paul , David Airlie , Daniel Vetter , linux-arm-msm@vger.kernel.org (open list:DRM DRIVER FOR MSM ADRENO GPU), dri-devel@lists.freedesktop.org (open list:DRM DRIVER FOR MSM ADRENO GPU), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/2] drm/msm: Add MSM_WAIT_IOVA ioctl Date: Wed, 15 Jan 2020 15:56:49 -0500 Message-Id: <20200115205649.12971-3-brian@brkho.com> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200115205649.12971-1-brian@brkho.com> References: <20200115205649.12971-1-brian@brkho.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implements an ioctl to wait until a value at a given iova is greater than or equal to a supplied value. This will initially be used by turnip (open-source Vulkan driver for QC in mesa) for occlusion queries where the userspace driver can block on a query becoming available before continuing via vkGetQueryPoolResults. Signed-off-by: Brian Ho --- drivers/gpu/drm/msm/msm_drv.c | 61 +++++++++++++++++++++++++++++++++-- include/uapi/drm/msm_drm.h | 14 ++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index c84f0a8b3f2c..92853c795c5c 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -36,10 +36,11 @@ * MSM_GEM_INFO ioctl. * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get * GEM object's debug name - * - 1.5.0 - Add SUBMITQUERY_QUERY ioctl + * - 1.5.0 - Add SUBMITQUEUE_QUERY ioctl + * - 1.6.0 - Add WAIT_IOVA ioctl */ #define MSM_VERSION_MAJOR 1 -#define MSM_VERSION_MINOR 5 +#define MSM_VERSION_MINOR 6 #define MSM_VERSION_PATCHLEVEL 0 static const struct drm_mode_config_funcs mode_config_funcs = { @@ -952,6 +953,61 @@ static int msm_ioctl_submitqueue_close(struct drm_device *dev, void *data, return msm_submitqueue_remove(file->driver_priv, id); } +static int msm_ioctl_wait_iova(struct drm_device *dev, void *data, + struct drm_file *file) +{ + struct msm_drm_private *priv = dev->dev_private; + struct drm_gem_object *obj; + struct drm_msm_wait_iova *args = data; + ktime_t timeout = to_ktime(args->timeout); + unsigned long remaining_jiffies = timeout_to_jiffies(&timeout); + struct msm_gpu *gpu = priv->gpu; + void *base_vaddr; + uint64_t ref_value = args->value & args->mask; + uint64_t *vaddr; + int ret; + + if (args->pad) + return -EINVAL; + + if (!gpu) + return -ENODEV; + + obj = drm_gem_object_lookup(file, args->handle); + if (!obj) + return -ENOENT; + + if (args->offset + sizeof(*vaddr) < args->offset || + args->offset + sizeof(*vaddr) > obj->size) { + ret = -EINVAL; + goto err_put_gem_object; + } + + base_vaddr = msm_gem_get_vaddr(obj); + if (IS_ERR(base_vaddr)) { + ret = PTR_ERR(base_vaddr); + goto err_put_gem_object; + } + + vaddr = base_vaddr + args->offset; + + /* TODO: Support 64 bit reference values with a flag. */ + ret = wait_event_interruptible_timeout(gpu->event, + (int32_t)((uint32_t)*vaddr - (uint32_t)ref_value) >= 0, + remaining_jiffies); + + if (ret == 0) + ret = -ETIMEDOUT; + else if (ret > 0) + ret = 0; + + msm_gem_put_vaddr(obj); + +err_put_gem_object: + drm_gem_object_put_unlocked(obj); + return ret; +} + static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_RENDER_ALLOW), @@ -964,6 +1020,7 @@ static const struct drm_ioctl_desc msm_ioctls[] = { DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_NEW, msm_ioctl_submitqueue_new, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_CLOSE, msm_ioctl_submitqueue_close, DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(MSM_SUBMITQUEUE_QUERY, msm_ioctl_submitqueue_query, DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(MSM_WAIT_IOVA, msm_ioctl_wait_iova, DRM_RENDER_ALLOW), }; static const struct vm_operations_struct vm_ops = { diff --git a/include/uapi/drm/msm_drm.h b/include/uapi/drm/msm_drm.h index 0b85ed6a3710..d4eac312f56e 100644 --- a/include/uapi/drm/msm_drm.h +++ b/include/uapi/drm/msm_drm.h @@ -298,6 +298,18 @@ struct drm_msm_submitqueue_query { __u32 pad; }; +/* This ioctl blocks until the value at bo + offset is greater than or equal + * to the reference value. + */ +struct drm_msm_wait_iova { + __u32 handle; /* in, GEM handle */ + __u32 pad; + struct drm_msm_timespec timeout; /* in */ + __u64 offset; /* in, offset into bo */ + __u64 mask; /* in, mask of the value at bo + offset */ + __u64 value; /* in, reference value, 32 bits */ +}; + #define DRM_MSM_GET_PARAM 0x00 /* placeholder: #define DRM_MSM_SET_PARAM 0x01 @@ -315,6 +327,7 @@ struct drm_msm_submitqueue_query { #define DRM_MSM_SUBMITQUEUE_NEW 0x0A #define DRM_MSM_SUBMITQUEUE_CLOSE 0x0B #define DRM_MSM_SUBMITQUEUE_QUERY 0x0C +#define DRM_MSM_WAIT_IOVA 0x0D #define DRM_IOCTL_MSM_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GET_PARAM, struct drm_msm_param) #define DRM_IOCTL_MSM_GEM_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_GEM_NEW, struct drm_msm_gem_new) @@ -327,6 +340,7 @@ struct drm_msm_submitqueue_query { #define DRM_IOCTL_MSM_SUBMITQUEUE_NEW DRM_IOWR(DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_NEW, struct drm_msm_submitqueue) #define DRM_IOCTL_MSM_SUBMITQUEUE_CLOSE DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_CLOSE, __u32) #define DRM_IOCTL_MSM_SUBMITQUEUE_QUERY DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_SUBMITQUEUE_QUERY, struct drm_msm_submitqueue_query) +#define DRM_IOCTL_MSM_WAIT_IOVA DRM_IOW (DRM_COMMAND_BASE + DRM_MSM_WAIT_IOVA, struct drm_msm_wait_iova) #if defined(__cplusplus) } -- 2.25.0.rc1.283.g88dfdc4193-goog