Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4087683ybl; Mon, 13 Jan 2020 07:39:02 -0800 (PST) X-Google-Smtp-Source: APXvYqylekqg5LjplsItfRCMDsE6ov0p5wGsXUhcKRZnhlpvfe+AOMY6dZWIZequ2ltx4KG0bh99 X-Received: by 2002:a05:6808:8f5:: with SMTP id d21mr13436182oic.58.1578929942255; Mon, 13 Jan 2020 07:39:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578929942; cv=none; d=google.com; s=arc-20160816; b=bzn9j5sn7xdkW08WjiJyHAydjRyJ8gsf8MKsCHPAgK6Bi1pGFgmHgK4Bos1pMW0EN+ eBus4/nnqlczIfULbZQuY8qPNS/+YPPXDWIqT5rL38V36P1+B+f4pYJoTcjjuuaPbpco qWTm+HsyhTOWDi3qNe4NE4EcfPFYCRLmYSVzLrhVm3rOhYIJ/okQiQmOUqWIBDZajt5A 1lM65bM7cKtVCZ5HYOn0oChKQOd5bKmFlWLVtaxObRT3r2MB05ySUOkRBON1luQIMt4t KrJH4a8e0wwCeNmcmRKYcO/w9LgBc1rmgL7MKEU87FGPPBKNrvC2ZZZ9rRVXWo7kYw4s QcXQ== 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=loDIHBoPYn2n1QOh85N5e2eDCf5hlfrUH2iJe1lXbAU=; b=04uGGXeMPt3SMpPCc+mXBcLz3AiVh41QtcHzf/q/SGpbRMyurzNj9zDEiHz63ddj1c czmTaqmWTqJ5I2k5WLxoFUFasohvD4nTocUiBKn8BbzFBPLJEC6OZVvxsF1Q7aoyaDGa OCL37PregJEVmRfm+bTBEBGI2KuivqZWO1uyi26tOhCSZyc0Emi8xRfwQ9EsImuQuMrd lqilbrYBUjr6CB0zCy85jsV8Y+WlzpRwCWpoeDTWw3xBB6Lh7xBuBakRR2+k7n6aM4mu LXCPD3CTYFk/3B3SwGmbq9WzEFVE5KD9onUnRTJ1WzS5LRm/916JKGlXO2vxIgLWb23A XrPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brkho-com.20150623.gappssmtp.com header.s=20150623 header.b=JzTeFNQl; 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 t1si5887830oic.140.2020.01.13.07.38.50; Mon, 13 Jan 2020 07:39:02 -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=JzTeFNQl; 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 S1728656AbgAMPhv (ORCPT + 99 others); Mon, 13 Jan 2020 10:37:51 -0500 Received: from mail-yw1-f98.google.com ([209.85.161.98]:40430 "EHLO mail-yw1-f98.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbgAMPhv (ORCPT ); Mon, 13 Jan 2020 10:37:51 -0500 Received: by mail-yw1-f98.google.com with SMTP id i126so6328537ywe.7 for ; Mon, 13 Jan 2020 07:37:49 -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=loDIHBoPYn2n1QOh85N5e2eDCf5hlfrUH2iJe1lXbAU=; b=JzTeFNQlIcxcKxsUt4WBb8hrFA5YPZaFijIKGvuDSFMwdwDHmqP+1UYQ5if0ikCuvU 4KRRfiPXa766MYXZHZoy/FtEVZPfN6Zv/8AKhQ1CW8T7a6GXHxBU9P7XQy6tEJ4hv7mU crp2IwkesyxUt7jPDuVUbQvk4Hvh+Fzy0I4b/h3zaVlsfKwmdvZu2Lrdgo1FYocJanIa I/r1ukjZxsfTOxX6t6c5FfANAfYcw/ww5qn0rvkLa+SK+RFms70oogsnmTiLnbjdwX4x LkQbRq5Em1icHZ6PeY5Yzqzj4Kac72h9zRIafr2DqPBXnQDcJ/T1WVd+xaQVZ4PqWcjd BQNQ== 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=loDIHBoPYn2n1QOh85N5e2eDCf5hlfrUH2iJe1lXbAU=; b=qse+V4L4DAUq0Hph5W/hJr1yITOi9yReVo6pKoX2iKsznv3j0YbnNcpxRknTuSNAEg UM44fxHcVDokTS1N2eA28hpcjU0pkcYCNOgvDmEUo88kKkobJ/CPzw7ZKZO7FikJQOmK PVjLxcJ9C1HX0RKcjy8Q21NRmIZl63lejgPBkRX1HiJ/ssvLRqjQhba7YE83wfKbUOLo vySg3Wd1sTL3SLvdt9ys6EcTpDhxZhuiPlPmVnguG5CX0Xa9Au81MmZrX2/No+KHyhxB ++5xTAbUMNDdVOq0l31FVzSHesQe8zLLIA6izy1kIWrojDuj5BSQAZJFL4Gz33Dy5Ese pXRA== X-Gm-Message-State: APjAAAVXma3oN+cjXx3gZ8qVk2dyd/8Qwa5MRpqECaQcfvr2wzFYMXhq JQ7UvSTym8AQdPxYp5TienPScXqWeu/EaxlvXf3RceiGoFMOmA== X-Received: by 2002:a25:3883:: with SMTP id f125mr14312395yba.271.1578929868538; Mon, 13 Jan 2020 07:37:48 -0800 (PST) Received: from hob1.nyc.corp.google.com ([100.118.32.120]) by smtp-relay.gmail.com with ESMTPS id m193sm1672393ywd.0.2020.01.13.07.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 07:37:48 -0800 (PST) X-Relaying-Domain: brkho.com From: Brian Ho To: freedreno@lists.freedesktop.org Cc: hoegsberg@chromium.org, robdclark@chromium.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 2/2] drm/msm: Add MSM_WAIT_IOVA ioctl Date: Mon, 13 Jan 2020 10:36:05 -0500 Message-Id: <20200113153605.52350-3-brian@brkho.com> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200113153605.52350-1-brian@brkho.com> References: <20200113153605.52350-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 | 63 +++++++++++++++++++++++++++++++++-- include/uapi/drm/msm_drm.h | 13 ++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index c84f0a8b3f2c..dcc46874a5a2 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,63 @@ 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 *vaddr; + int ret; + + if (args->pad) + return -EINVAL; + + if (!gpu) + return 0; + + obj = drm_gem_object_lookup(file, args->handle); + if (!obj) + return -ENOENT; + + base_vaddr = msm_gem_get_vaddr(obj); + if (IS_ERR(base_vaddr)) { + ret = PTR_ERR(base_vaddr); + goto err_put_gem_object; + } + if (args->offset + sizeof(*vaddr) > obj->size) { + ret = -EINVAL; + goto err_put_vaddr; + } + + vaddr = base_vaddr + args->offset; + + /* Assumes WC mapping */ + ret = wait_event_interruptible_timeout( + gpu->event, *vaddr >= args->value, remaining_jiffies); + + if (ret == 0) { + ret = -ETIMEDOUT; + goto err_put_vaddr; + } else if (ret == -ERESTARTSYS) { + goto err_put_vaddr; + } + + msm_gem_put_vaddr(obj); + drm_gem_object_put_unlocked(obj); + return 0; + +err_put_vaddr: + 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 +1022,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..8477f28a4ee1 100644 --- a/include/uapi/drm/msm_drm.h +++ b/include/uapi/drm/msm_drm.h @@ -298,6 +298,17 @@ struct drm_msm_submitqueue_query { __u32 pad; }; +/* This ioctl blocks until the u64 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; /* offset into bo */ + __u64 value; /* reference value */ +}; + #define DRM_MSM_GET_PARAM 0x00 /* placeholder: #define DRM_MSM_SET_PARAM 0x01 @@ -315,6 +326,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 +339,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