From patchwork Wed Mar 14 14:05:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10282235 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 2804A602BD for ; Wed, 14 Mar 2018 14:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16E2F2895B for ; Wed, 14 Mar 2018 14:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A1D628960; Wed, 14 Mar 2018 14:05:58 +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_SIGNED, 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 3D32A2895B for ; Wed, 14 Mar 2018 14:05:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A068D6E6D5; Wed, 14 Mar 2018 14:05:56 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id EBCF16E6D5 for ; Wed, 14 Mar 2018 14:05:55 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u10so4106433wmu.4 for ; Wed, 14 Mar 2018 07:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=0FF4Z7UVKSrj5i9q0jKMpTln6+VVFBCrN7s3yJr/CuM=; b=WYHYFoy2k/dmgAfCARZcsoreaebJoK5qh2UAs7UfoVWPJksVEc485WHo3FWqdrFIjB 0tddxgXL4HtcW3sUFhBLlUme93gZpPOKdmQxBNtvbVNMO108EO88Fy/XbUgOjFJP6KJj oCmyFRJ6TrWy36JjBdabhxIqkFuOY0eZia6m8E4yu2d0wNtmRukxPe1tFgDfiCFeAwsq LJ0W9ev08ApZ9ag5Qi04yx9me9QOu7Lsjs1ib2091RtrjVA8p/vsRVhx7oky9mM+Jsfw WaR7/0U1gjWtJrfxQxcgxVv1TkMBrtVMZ9w4/vGBs7hpuRN80xXD4Rv0zp1gBOp5TwNX otgw== 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; bh=0FF4Z7UVKSrj5i9q0jKMpTln6+VVFBCrN7s3yJr/CuM=; b=EaQb33Qi0ByNSz2M1a8+icFw0fYNDJXQiSYmYVGd8G3L5bqxYCa2Zc78ZkbheoWhjE hpoGl8SXD9ieZz9uxSBX0c+txYmXvq6JPQofD3x6ehvJH26fSnwIG+RARReQu+3h1nH3 b0ve+W6JPiMbiNL1BTIBR1TedSBOg8upzOWV0zOZIwV1Nsd5J/4LOwrhaSo0d2Dj+fof OIPzN7pj0YsvWQsyBzae/mUKanGZCkan/RdS29zmvyWePKIjoXONeJWLBpa0fFc/KSZG msNYKMO5fRAax9gSL78X2eYm1kUeIXKo50Lml8sf+BsEXvrdPAAVRKNbI6TH4594TF0N R2lw== X-Gm-Message-State: AElRT7G40Lm1WGLOmHCKqHMv8w/PxjIRBivCwTyUPE3FYUx5YSjk46// 3T/DPwxcfA/xeJA8NEWUxgD11KOg X-Google-Smtp-Source: AG47ELuBbaRdgu0x1V9dGQYo1TPHli6t5pN7L9o+dKAeln9R7ZJuMRFTmHKEbM+b8r+jnK6lrAANnw== X-Received: by 10.28.10.81 with SMTP id 78mr1797341wmk.115.1521036354334; Wed, 14 Mar 2018 07:05:54 -0700 (PDT) Received: from localhost.localdomain ([95.146.144.186]) by smtp.gmail.com with ESMTPSA id e10sm2849978wrh.38.2018.03.14.07.05.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 07:05:53 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 14 Mar 2018 14:05:39 +0000 Message-Id: <20180314140539.9287-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.14.1 Subject: [Intel-gfx] [RFC] drm/i915: Engine discovery query 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: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Engine discovery query allows userspace to enumerate engines, probe their configuration features, all without needing to maintain the internal PCI ID based database. A new query for the generic i915 query ioctl is added named DRM_I915_QUERY_ENGINE_INFO, together with accompanying structure drm_i915_query_engine_info. The address of latter should be passed to the kernel in the query.data_ptr field, and should be large enough for the kernel to fill out all known engines as struct drm_i915_engine_info elements trailing the query. As with other queries, setting the item query length to zero allows userspace to query minimum required buffer size. Enumerated engines have common type mask which can be used to query all hardware engines, versus engines userspace can submit to using the execbuf uAPI. Engines also have capabilities which are per engine class namespace of bits describing features not present on all engine instances. Signed-off-by: Tvrtko Ursulin Cc: Chris Wilson Cc: Jon Bloomfield Cc: Dmitry Rogozhkin Cc: Lionel Landwerlin Cc: Joonas Lahtinen --- This is RFC for now since it is not very usable before the new execbuf API or virtual engine queue submission gets closer. In this version I have added capability of distinguishing between hardware engines and ABI engines. This is to account for probable future use cases like virtualization, where guest might only see one engine instance, but will want to know overall hardware capabilities in order to tune its behaviour. In general I think we will have to wait a bit before defining the final look of the uAPI, but in the meantime I thought it useful to share as RFC. --- drivers/gpu/drm/i915/i915_query.c | 61 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_engine_cs.c | 3 ++ drivers/gpu/drm/i915/intel_ringbuffer.h | 3 ++ include/uapi/drm/i915_drm.h | 44 ++++++++++++++++++++++++ 4 files changed, 111 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c index 3ace929dd90f..e00d02796d42 100644 --- a/drivers/gpu/drm/i915/i915_query.c +++ b/drivers/gpu/drm/i915/i915_query.c @@ -82,9 +82,70 @@ static int query_topology_info(struct drm_i915_private *dev_priv, return total_length; } +static int +query_engine_info(struct drm_i915_private *i915, + struct drm_i915_query_item *query_item) +{ + struct drm_i915_query_engine_info query, *q; + struct drm_i915_engine_info *info; + struct intel_engine_cs *engine; + enum intel_engine_id id; + int len; + + if (query_item->flags) + return -EINVAL; + + len = sizeof(struct drm_i915_query_engine_info) + + I915_NUM_ENGINES * sizeof(struct drm_i915_engine_info); + + if (!query_item->length) + return len; + else if (query_item->length < len) + return -EINVAL; + + if (copy_from_user(&query, u64_to_user_ptr(query_item->data_ptr), + sizeof(query))) + return -EFAULT; + + if (query.num_engines || + query.rsvd[0] || query.rsvd[1] || query.rsvd[2]) + return -EINVAL; + + if (!access_ok(VERIFY_WRITE, u64_to_user_ptr(query_item->data_ptr), + len)) + return -EFAULT; + + q = kzalloc(len, GFP_KERNEL); + if (!q) + return -ENOMEM; + + info = &q->engines[0]; + + for_each_engine(engine, i915, id) { + info->class = engine->uabi_class; + info->instance = engine->instance; + info->type = I915_ENGINE_TYPE_PHYSICAL | + I915_ENGINE_TYPE_UAPI; + info->capabilities = engine->capabilities; + info++; + q->num_engines++; + } + + if (__copy_to_user(u64_to_user_ptr(query_item->data_ptr), q, len)) { + len = -EFAULT; + goto out; + } + +out: + kfree(q); + + return len; +} + static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv, struct drm_i915_query_item *query_item) = { query_topology_info, + query_engine_info, }; int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file) diff --git a/drivers/gpu/drm/i915/intel_engine_cs.c b/drivers/gpu/drm/i915/intel_engine_cs.c index a2b1e9e2c008..81be4acd8358 100644 --- a/drivers/gpu/drm/i915/intel_engine_cs.c +++ b/drivers/gpu/drm/i915/intel_engine_cs.c @@ -86,6 +86,7 @@ struct engine_info { unsigned int uabi_id; u8 class; u8 instance; + u32 capabilities; u32 mmio_base; unsigned irq_shift; }; @@ -114,6 +115,7 @@ static const struct engine_info intel_engines[] = { .instance = 0, .mmio_base = GEN6_BSD_RING_BASE, .irq_shift = GEN8_VCS1_IRQ_SHIFT, + .capabilities = I915_VCS_CLASS_CAPABILITY_HEVC, }, [VCS2] = { .hw_id = VCS2_HW, @@ -279,6 +281,7 @@ intel_engine_setup(struct drm_i915_private *dev_priv, engine->irq_shift = info->irq_shift; engine->class = info->class; engine->instance = info->instance; + engine->capabilities = info->capabilities; engine->uabi_id = info->uabi_id; engine->uabi_class = class_info->uabi_class; diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index 81cdbbf257ec..c73e1345f376 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -329,6 +329,9 @@ struct intel_engine_cs { u8 class; u8 instance; + + u32 capabilities; + u32 context_size; u32 mmio_base; unsigned int irq_shift; diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h index 7f5634ce8e88..57b61dbda723 100644 --- a/include/uapi/drm/i915_drm.h +++ b/include/uapi/drm/i915_drm.h @@ -1620,6 +1620,7 @@ struct drm_i915_perf_oa_config { struct drm_i915_query_item { __u64 query_id; #define DRM_I915_QUERY_TOPOLOGY_INFO 1 +#define DRM_I915_QUERY_ENGINE_INFO 2 /* * When set to zero by userspace, this is filled with the size of the @@ -1717,6 +1718,49 @@ struct drm_i915_query_topology_info { __u8 data[]; }; +/** + * struct drm_i915_engine_info + * + * Describes one engine known to the driver, whether or not is physical engine + * only, or it can also be targetted from userspace, and what are its + * capabilities where applicable. + */ +struct drm_i915_engine_info { + /** Engine class as in enum drm_i915_gem_engine_class. */ + __u8 class; + + /** Engine instance number. */ + __u8 instance; + + /** Engine type flags. */ + __u16 type; +#define I915_ENGINE_TYPE_PHYSICAL BIT(0) +#define I915_ENGINE_TYPE_UAPI BIT(1) + + /** Capabilities of this engine. */ + __u32 capabilities; +#define I915_VCS_CLASS_CAPABILITY_HEVC BIT(0) + + __u32 rsvd[4]; +}; + +/** + * struct drm_i915_query_engine_info + * + * Engine info query enumerates all the engines known to the driver returning + * the array of struct drm_i915_engine_info structures. + */ +struct drm_i915_query_engine_info { + /** Number of struct drm_i915_engine_info structs following. */ + __u32 num_engines; + + /** MBZ */ + __u32 rsvd[3]; + + /** Marker for drm_i915_engine_info structures. */ + struct drm_i915_engine_info engines[]; +}; + #if defined(__cplusplus) } #endif