Message ID | 20221119204435.97113-4-ogabbay@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp861562wrr; Sat, 19 Nov 2022 12:46:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5m0wUQaVaZxFkSILwvo9tFpNcBTNzk9dEkSXzPKm6T6ODnJURNqbRc+6yIzy+gZudp/NXi X-Received: by 2002:a17:903:2582:b0:188:758f:f45e with SMTP id jb2-20020a170903258200b00188758ff45emr389613plb.12.1668890816181; Sat, 19 Nov 2022 12:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668890816; cv=none; d=google.com; s=arc-20160816; b=zcz5UP4jbZ2L8fAiXKQ6aoPmFwUA1JkMZXVZjdWxRvw6yqWdwDCFig+25mS53tWoce WWDte4q8OwU+e1emTBHCOWPQPvAtuESz5xXWA3WQV3HcwW72OM9i1Mt80KzoqD0/g4r7 Y/Vkc6HO59q8kUu2kFJVA62JzwUHo/BRTjau6CxPUzCduv+myiyosGowfe7HFDhyz79S 3g02FavVphlPHZqZ36uq/I8hKqWlqeMJgo/P2u7A9h6j64RdhbPTn3JDgIgNCzaEkS2+ iSZEFuIACdzNjqiO75VkOSmB3/M4qCH4OZQEqkDdG8ePiEZvNEDiWF2UzZY6vC/LCjTN +6ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=inItD80LLBQ/LJS/QvEzA3jBHnte0zDf5370MU7IJtw=; b=EdMrPph6uu5axnXDrpw0G4pKBwbNHLRkhtCX7PzfBxSentoYY4sO6+0HCivBvclRTJ fPGvgqAhFeMc6zAsRGDPfdB35HT6t2dfgMdJGzFT3eEischAkTKiXM/u/slI8zLwgX7c zy1sRJ+SWbpHwzzFtVYOC22sgCDUgqNDQwrM7EWkFuqYa2/dnNGMsu1aH6QHH29+J3mF kn4qdPkZTEip1l2VJWMKh0IblZ/AAs0jvqjkcippPP7fYoHlIga0OzyZXJbC6AFJQwIX Lyav0FYhI+SiUCafJ4K9GqlKE41h9cDRmSD2gRk+WVK4kPffBxEavZdmKU9n3VLY+990 fJvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2NEXGh6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s36-20020a056a0017a400b0053652e1c0b6si8268230pfg.12.2022.11.19.12.46.43; Sat, 19 Nov 2022 12:46:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2NEXGh6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234833AbiKSUpT (ORCPT <rfc822;zhanghuayu.dev@gmail.com> + 99 others); Sat, 19 Nov 2022 15:45:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234764AbiKSUpK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 19 Nov 2022 15:45:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4A5B13DF0 for <linux-kernel@vger.kernel.org>; Sat, 19 Nov 2022 12:45:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1E6F0B80881 for <linux-kernel@vger.kernel.org>; Sat, 19 Nov 2022 20:45:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EFDAC433D7; Sat, 19 Nov 2022 20:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668890703; bh=x8lGYDn9NFmqVJtumKwmzsrFD5VVbJMslBuQbFaO9io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2NEXGh6JcoUDqF9UdTVqfeRfestW21R7J7JPniO6r8qZ70dstO+gZlUl3KftvZhs gjUEd+oekzsWc+u3qxY/dbZkM79VHPFSjzDBJYIK/frgSPfGMe/YHGP7NyRR9x0xZ4 ge9SfKkmGVwbCjLMd9ZA4jexRaJQTC4+i22nMPQs74VkYzPVTzQJT8uaa8j7laFHy7 TM+//Fwnut7XJneOfmGWaw4f0mQvuBPKdkEg+PBGCxdThsLVv4UsbHMSbY/dog1gAE wdt4s6jQqyfssPzaZld9u05oCuz/noIgT1mgK1yilduC67B5H0NM5peBlR1sVUij2A /LxHfpZ37HSaQ== From: Oded Gabbay <ogabbay@kernel.org> To: David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, Arnd Bergmann <arnd@arndb.de>, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Yuji Ishikawa <yuji2.ishikawa@toshiba.co.jp>, Jiho Chu <jiho.chu@samsung.com>, Daniel Stone <daniel@fooishbar.org>, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>, Jason Gunthorpe <jgg@nvidia.com>, Jeffrey Hugo <quic_jhugo@quicinc.com>, Christoph Hellwig <hch@infradead.org>, Kevin Hilman <khilman@baylibre.com>, Jagan Teki <jagan@amarulasolutions.com>, John Hubbard <jhubbard@nvidia.com>, Alex Deucher <alexander.deucher@amd.com>, Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>, Maciej Kwapulinski <maciej.kwapulinski@linux.intel.com>, Christopher Friedt <chrisfriedt@gmail.com> Subject: [PATCH v4 3/4] drm: initialize accel framework Date: Sat, 19 Nov 2022 22:44:34 +0200 Message-Id: <20221119204435.97113-4-ogabbay@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221119204435.97113-1-ogabbay@kernel.org> References: <20221119204435.97113-1-ogabbay@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749958856550626905?= X-GMAIL-MSGID: =?utf-8?q?1749958856550626905?= |
Series | new subsystem for compute accelerator devices | |
Commit Message
Oded Gabbay
Nov. 19, 2022, 8:44 p.m. UTC
Now that we have the accel framework code ready, let's call the
accel functions from all the appropriate places. These places are the
drm module init/exit functions, and all the drm_minor handling
functions.
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
drivers/gpu/drm/drm_drv.c | 102 ++++++++++++++++++++++++++----------
drivers/gpu/drm/drm_sysfs.c | 24 ++++++---
2 files changed, 91 insertions(+), 35 deletions(-)
Comments
On 11/19, Oded Gabbay wrote: > Now that we have the accel framework code ready, let's call the > accel functions from all the appropriate places. These places are the > drm module init/exit functions, and all the drm_minor handling > functions. Hi Oded, The proposal overall LGTM, but I didn't manage to compile the kernel with your patch series when DRM is enabled but accel support doesn't. Multiple missing link errors... Am I missing something? Can you take a look at it from this patch 3/4? Thanks, Melissa > > Signed-off-by: Oded Gabbay <ogabbay@kernel.org> > --- > drivers/gpu/drm/drm_drv.c | 102 ++++++++++++++++++++++++++---------- > drivers/gpu/drm/drm_sysfs.c | 24 ++++++--- > 2 files changed, 91 insertions(+), 35 deletions(-) > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index 8214a0b1ab7f..1aec019f6389 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -35,6 +35,7 @@ > #include <linux/slab.h> > #include <linux/srcu.h> > > +#include <drm/drm_accel.h> > #include <drm/drm_cache.h> > #include <drm/drm_client.h> > #include <drm/drm_color_mgmt.h> > @@ -90,6 +91,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, > return &dev->primary; > case DRM_MINOR_RENDER: > return &dev->render; > + case DRM_MINOR_ACCEL: > + return &dev->accel; > default: > BUG(); > } > @@ -104,9 +107,13 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) > > put_device(minor->kdev); > > - spin_lock_irqsave(&drm_minor_lock, flags); > - idr_remove(&drm_minors_idr, minor->index); > - spin_unlock_irqrestore(&drm_minor_lock, flags); > + if (minor->type == DRM_MINOR_ACCEL) { > + accel_minor_remove(minor->index); > + } else { > + spin_lock_irqsave(&drm_minor_lock, flags); > + idr_remove(&drm_minors_idr, minor->index); > + spin_unlock_irqrestore(&drm_minor_lock, flags); > + } > } > > static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > @@ -123,13 +130,17 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > minor->dev = dev; > > idr_preload(GFP_KERNEL); > - spin_lock_irqsave(&drm_minor_lock, flags); > - r = idr_alloc(&drm_minors_idr, > - NULL, > - 64 * type, > - 64 * (type + 1), > - GFP_NOWAIT); > - spin_unlock_irqrestore(&drm_minor_lock, flags); > + if (type == DRM_MINOR_ACCEL) { > + r = accel_minor_alloc(); > + } else { > + spin_lock_irqsave(&drm_minor_lock, flags); > + r = idr_alloc(&drm_minors_idr, > + NULL, > + 64 * type, > + 64 * (type + 1), > + GFP_NOWAIT); > + spin_unlock_irqrestore(&drm_minor_lock, flags); > + } > idr_preload_end(); > > if (r < 0) > @@ -161,10 +172,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > if (!minor) > return 0; > > - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > - if (ret) { > - DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > - goto err_debugfs; > + if (minor->type == DRM_MINOR_ACCEL) { > + accel_debugfs_init(minor, minor->index); > + } else { > + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > + if (ret) { > + DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > + goto err_debugfs; > + } > } > > ret = device_add(minor->kdev); > @@ -172,9 +187,13 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > goto err_debugfs; > > /* replace NULL with @minor so lookups will succeed from now on */ > - spin_lock_irqsave(&drm_minor_lock, flags); > - idr_replace(&drm_minors_idr, minor, minor->index); > - spin_unlock_irqrestore(&drm_minor_lock, flags); > + if (minor->type == DRM_MINOR_ACCEL) { > + accel_minor_replace(minor, minor->index); > + } else { > + spin_lock_irqsave(&drm_minor_lock, flags); > + idr_replace(&drm_minors_idr, minor, minor->index); > + spin_unlock_irqrestore(&drm_minor_lock, flags); > + } > > DRM_DEBUG("new minor registered %d\n", minor->index); > return 0; > @@ -194,9 +213,13 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) > return; > > /* replace @minor with NULL so lookups will fail from now on */ > - spin_lock_irqsave(&drm_minor_lock, flags); > - idr_replace(&drm_minors_idr, NULL, minor->index); > - spin_unlock_irqrestore(&drm_minor_lock, flags); > + if (minor->type == DRM_MINOR_ACCEL) { > + accel_minor_replace(NULL, minor->index); > + } else { > + spin_lock_irqsave(&drm_minor_lock, flags); > + idr_replace(&drm_minors_idr, NULL, minor->index); > + spin_unlock_irqrestore(&drm_minor_lock, flags); > + } > > device_del(minor->kdev); > dev_set_drvdata(minor->kdev, NULL); /* safety belt */ > @@ -603,6 +626,14 @@ static int drm_dev_init(struct drm_device *dev, > /* no per-device feature limits by default */ > dev->driver_features = ~0u; > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) && > + (drm_core_check_feature(dev, DRIVER_RENDER) || > + drm_core_check_feature(dev, DRIVER_MODESET))) { > + > + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n"); > + return -EINVAL; > + } > + > drm_legacy_init_members(dev); > INIT_LIST_HEAD(&dev->filelist); > INIT_LIST_HEAD(&dev->filelist_internal); > @@ -628,15 +659,21 @@ static int drm_dev_init(struct drm_device *dev, > > dev->anon_inode = inode; > > - if (drm_core_check_feature(dev, DRIVER_RENDER)) { > - ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) { > + ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL); > if (ret) > goto err; > - } > + } else { > + if (drm_core_check_feature(dev, DRIVER_RENDER)) { > + ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > + if (ret) > + goto err; > + } > > - ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > - if (ret) > - goto err; > + ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > + if (ret) > + goto err; > + } > > ret = drm_legacy_create_map_hash(dev); > if (ret) > @@ -883,6 +920,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > if (ret) > goto err_minors; > > + ret = drm_minor_register(dev, DRM_MINOR_ACCEL); > + if (ret) > + goto err_minors; > + > ret = create_compat_control_link(dev); > if (ret) > goto err_minors; > @@ -902,12 +943,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > driver->name, driver->major, driver->minor, > driver->patchlevel, driver->date, > dev->dev ? dev_name(dev->dev) : "virtual device", > - dev->primary->index); > + dev->primary ? dev->primary->index : dev->accel->index); > > goto out_unlock; > > err_minors: > remove_compat_control_link(dev); > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > drm_minor_unregister(dev, DRM_MINOR_RENDER); > out_unlock: > @@ -950,6 +992,7 @@ void drm_dev_unregister(struct drm_device *dev) > drm_legacy_rmmaps(dev); > > remove_compat_control_link(dev); > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > drm_minor_unregister(dev, DRM_MINOR_RENDER); > } > @@ -1034,6 +1077,7 @@ static const struct file_operations drm_stub_fops = { > static void drm_core_exit(void) > { > drm_privacy_screen_lookup_exit(); > + accel_core_exit(); > unregister_chrdev(DRM_MAJOR, "drm"); > debugfs_remove(drm_debugfs_root); > drm_sysfs_destroy(); > @@ -1061,6 +1105,10 @@ static int __init drm_core_init(void) > if (ret < 0) > goto error; > > + ret = accel_core_init(); > + if (ret < 0) > + goto error; > + > drm_privacy_screen_lookup_init(); > > drm_core_init_complete = true; > diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c > index 430e00b16eec..b8da978d85bb 100644 > --- a/drivers/gpu/drm/drm_sysfs.c > +++ b/drivers/gpu/drm/drm_sysfs.c > @@ -19,6 +19,7 @@ > #include <linux/kdev_t.h> > #include <linux/slab.h> > > +#include <drm/drm_accel.h> > #include <drm/drm_connector.h> > #include <drm/drm_device.h> > #include <drm/drm_file.h> > @@ -471,19 +472,26 @@ struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) > struct device *kdev; > int r; > > - if (minor->type == DRM_MINOR_RENDER) > - minor_str = "renderD%d"; > - else > - minor_str = "card%d"; > - > kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); > if (!kdev) > return ERR_PTR(-ENOMEM); > > device_initialize(kdev); > - kdev->devt = MKDEV(DRM_MAJOR, minor->index); > - kdev->class = drm_class; > - kdev->type = &drm_sysfs_device_minor; > + > + if (minor->type == DRM_MINOR_ACCEL) { > + minor_str = "accel%d"; > + accel_set_device_instance_params(kdev, minor->index); > + } else { > + if (minor->type == DRM_MINOR_RENDER) > + minor_str = "renderD%d"; > + else > + minor_str = "card%d"; > + > + kdev->devt = MKDEV(DRM_MAJOR, minor->index); > + kdev->class = drm_class; > + kdev->type = &drm_sysfs_device_minor; > + } > + > kdev->parent = minor->dev->dev; > kdev->release = drm_sysfs_release; > dev_set_drvdata(kdev, minor); > -- > 2.25.1 >
On Tue, Nov 22, 2022 at 12:56 PM Melissa Wen <mwen@igalia.com> wrote: > > On 11/19, Oded Gabbay wrote: > > Now that we have the accel framework code ready, let's call the > > accel functions from all the appropriate places. These places are the > > drm module init/exit functions, and all the drm_minor handling > > functions. > > Hi Oded, > > The proposal overall LGTM, but I didn't manage to compile the kernel > with your patch series when DRM is enabled but accel support doesn't. > Multiple missing link errors... > > Am I missing something? Can you take a look at it from this patch 3/4? > > Thanks, > > Melissa Looking at it now, thanks for letting me know. Oded > > > > Signed-off-by: Oded Gabbay <ogabbay@kernel.org> > > --- > > drivers/gpu/drm/drm_drv.c | 102 ++++++++++++++++++++++++++---------- > > drivers/gpu/drm/drm_sysfs.c | 24 ++++++--- > > 2 files changed, 91 insertions(+), 35 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > > index 8214a0b1ab7f..1aec019f6389 100644 > > --- a/drivers/gpu/drm/drm_drv.c > > +++ b/drivers/gpu/drm/drm_drv.c > > @@ -35,6 +35,7 @@ > > #include <linux/slab.h> > > #include <linux/srcu.h> > > > > +#include <drm/drm_accel.h> > > #include <drm/drm_cache.h> > > #include <drm/drm_client.h> > > #include <drm/drm_color_mgmt.h> > > @@ -90,6 +91,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, > > return &dev->primary; > > case DRM_MINOR_RENDER: > > return &dev->render; > > + case DRM_MINOR_ACCEL: > > + return &dev->accel; > > default: > > BUG(); > > } > > @@ -104,9 +107,13 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) > > > > put_device(minor->kdev); > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > - idr_remove(&drm_minors_idr, minor->index); > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > + if (minor->type == DRM_MINOR_ACCEL) { > > + accel_minor_remove(minor->index); > > + } else { > > + spin_lock_irqsave(&drm_minor_lock, flags); > > + idr_remove(&drm_minors_idr, minor->index); > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > + } > > } > > > > static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > @@ -123,13 +130,17 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > minor->dev = dev; > > > > idr_preload(GFP_KERNEL); > > - spin_lock_irqsave(&drm_minor_lock, flags); > > - r = idr_alloc(&drm_minors_idr, > > - NULL, > > - 64 * type, > > - 64 * (type + 1), > > - GFP_NOWAIT); > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > + if (type == DRM_MINOR_ACCEL) { > > + r = accel_minor_alloc(); > > + } else { > > + spin_lock_irqsave(&drm_minor_lock, flags); > > + r = idr_alloc(&drm_minors_idr, > > + NULL, > > + 64 * type, > > + 64 * (type + 1), > > + GFP_NOWAIT); > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > + } > > idr_preload_end(); > > > > if (r < 0) > > @@ -161,10 +172,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > if (!minor) > > return 0; > > > > - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > - if (ret) { > > - DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > - goto err_debugfs; > > + if (minor->type == DRM_MINOR_ACCEL) { > > + accel_debugfs_init(minor, minor->index); > > + } else { > > + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > + if (ret) { > > + DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > + goto err_debugfs; > > + } > > } > > > > ret = device_add(minor->kdev); > > @@ -172,9 +187,13 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > goto err_debugfs; > > > > /* replace NULL with @minor so lookups will succeed from now on */ > > - spin_lock_irqsave(&drm_minor_lock, flags); > > - idr_replace(&drm_minors_idr, minor, minor->index); > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > + if (minor->type == DRM_MINOR_ACCEL) { > > + accel_minor_replace(minor, minor->index); > > + } else { > > + spin_lock_irqsave(&drm_minor_lock, flags); > > + idr_replace(&drm_minors_idr, minor, minor->index); > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > + } > > > > DRM_DEBUG("new minor registered %d\n", minor->index); > > return 0; > > @@ -194,9 +213,13 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) > > return; > > > > /* replace @minor with NULL so lookups will fail from now on */ > > - spin_lock_irqsave(&drm_minor_lock, flags); > > - idr_replace(&drm_minors_idr, NULL, minor->index); > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > + if (minor->type == DRM_MINOR_ACCEL) { > > + accel_minor_replace(NULL, minor->index); > > + } else { > > + spin_lock_irqsave(&drm_minor_lock, flags); > > + idr_replace(&drm_minors_idr, NULL, minor->index); > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > + } > > > > device_del(minor->kdev); > > dev_set_drvdata(minor->kdev, NULL); /* safety belt */ > > @@ -603,6 +626,14 @@ static int drm_dev_init(struct drm_device *dev, > > /* no per-device feature limits by default */ > > dev->driver_features = ~0u; > > > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) && > > + (drm_core_check_feature(dev, DRIVER_RENDER) || > > + drm_core_check_feature(dev, DRIVER_MODESET))) { > > + > > + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n"); > > + return -EINVAL; > > + } > > + > > drm_legacy_init_members(dev); > > INIT_LIST_HEAD(&dev->filelist); > > INIT_LIST_HEAD(&dev->filelist_internal); > > @@ -628,15 +659,21 @@ static int drm_dev_init(struct drm_device *dev, > > > > dev->anon_inode = inode; > > > > - if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > - ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) { > > + ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL); > > if (ret) > > goto err; > > - } > > + } else { > > + if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > + ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > + if (ret) > > + goto err; > > + } > > > > - ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > - if (ret) > > - goto err; > > + ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > + if (ret) > > + goto err; > > + } > > > > ret = drm_legacy_create_map_hash(dev); > > if (ret) > > @@ -883,6 +920,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > if (ret) > > goto err_minors; > > > > + ret = drm_minor_register(dev, DRM_MINOR_ACCEL); > > + if (ret) > > + goto err_minors; > > + > > ret = create_compat_control_link(dev); > > if (ret) > > goto err_minors; > > @@ -902,12 +943,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > driver->name, driver->major, driver->minor, > > driver->patchlevel, driver->date, > > dev->dev ? dev_name(dev->dev) : "virtual device", > > - dev->primary->index); > > + dev->primary ? dev->primary->index : dev->accel->index); > > > > goto out_unlock; > > > > err_minors: > > remove_compat_control_link(dev); > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > out_unlock: > > @@ -950,6 +992,7 @@ void drm_dev_unregister(struct drm_device *dev) > > drm_legacy_rmmaps(dev); > > > > remove_compat_control_link(dev); > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > } > > @@ -1034,6 +1077,7 @@ static const struct file_operations drm_stub_fops = { > > static void drm_core_exit(void) > > { > > drm_privacy_screen_lookup_exit(); > > + accel_core_exit(); > > unregister_chrdev(DRM_MAJOR, "drm"); > > debugfs_remove(drm_debugfs_root); > > drm_sysfs_destroy(); > > @@ -1061,6 +1105,10 @@ static int __init drm_core_init(void) > > if (ret < 0) > > goto error; > > > > + ret = accel_core_init(); > > + if (ret < 0) > > + goto error; > > + > > drm_privacy_screen_lookup_init(); > > > > drm_core_init_complete = true; > > diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c > > index 430e00b16eec..b8da978d85bb 100644 > > --- a/drivers/gpu/drm/drm_sysfs.c > > +++ b/drivers/gpu/drm/drm_sysfs.c > > @@ -19,6 +19,7 @@ > > #include <linux/kdev_t.h> > > #include <linux/slab.h> > > > > +#include <drm/drm_accel.h> > > #include <drm/drm_connector.h> > > #include <drm/drm_device.h> > > #include <drm/drm_file.h> > > @@ -471,19 +472,26 @@ struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) > > struct device *kdev; > > int r; > > > > - if (minor->type == DRM_MINOR_RENDER) > > - minor_str = "renderD%d"; > > - else > > - minor_str = "card%d"; > > - > > kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); > > if (!kdev) > > return ERR_PTR(-ENOMEM); > > > > device_initialize(kdev); > > - kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > - kdev->class = drm_class; > > - kdev->type = &drm_sysfs_device_minor; > > + > > + if (minor->type == DRM_MINOR_ACCEL) { > > + minor_str = "accel%d"; > > + accel_set_device_instance_params(kdev, minor->index); > > + } else { > > + if (minor->type == DRM_MINOR_RENDER) > > + minor_str = "renderD%d"; > > + else > > + minor_str = "card%d"; > > + > > + kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > + kdev->class = drm_class; > > + kdev->type = &drm_sysfs_device_minor; > > + } > > + > > kdev->parent = minor->dev->dev; > > kdev->release = drm_sysfs_release; > > dev_set_drvdata(kdev, minor); > > -- > > 2.25.1 > >
On Tue, Nov 22, 2022 at 12:59 PM Oded Gabbay <ogabbay@kernel.org> wrote: > > On Tue, Nov 22, 2022 at 12:56 PM Melissa Wen <mwen@igalia.com> wrote: > > > > On 11/19, Oded Gabbay wrote: > > > Now that we have the accel framework code ready, let's call the > > > accel functions from all the appropriate places. These places are the > > > drm module init/exit functions, and all the drm_minor handling > > > functions. > > > > Hi Oded, > > > > The proposal overall LGTM, but I didn't manage to compile the kernel > > with your patch series when DRM is enabled but accel support doesn't. > > Multiple missing link errors... > > > > Am I missing something? Can you take a look at it from this patch 3/4? > > > > Thanks, > > > > Melissa > Looking at it now, thanks for letting me know. > Oded Found the issue, missing } at end of accel_debugfs_init() in drm_accel.h. Only compiles when accel support isn't compiled in. I'll fix it before sending the PR to Dave. Much appreciated :) Oded > > > > > > > Signed-off-by: Oded Gabbay <ogabbay@kernel.org> > > > --- > > > drivers/gpu/drm/drm_drv.c | 102 ++++++++++++++++++++++++++---------- > > > drivers/gpu/drm/drm_sysfs.c | 24 ++++++--- > > > 2 files changed, 91 insertions(+), 35 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > > > index 8214a0b1ab7f..1aec019f6389 100644 > > > --- a/drivers/gpu/drm/drm_drv.c > > > +++ b/drivers/gpu/drm/drm_drv.c > > > @@ -35,6 +35,7 @@ > > > #include <linux/slab.h> > > > #include <linux/srcu.h> > > > > > > +#include <drm/drm_accel.h> > > > #include <drm/drm_cache.h> > > > #include <drm/drm_client.h> > > > #include <drm/drm_color_mgmt.h> > > > @@ -90,6 +91,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, > > > return &dev->primary; > > > case DRM_MINOR_RENDER: > > > return &dev->render; > > > + case DRM_MINOR_ACCEL: > > > + return &dev->accel; > > > default: > > > BUG(); > > > } > > > @@ -104,9 +107,13 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) > > > > > > put_device(minor->kdev); > > > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > - idr_remove(&drm_minors_idr, minor->index); > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > + accel_minor_remove(minor->index); > > > + } else { > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > + idr_remove(&drm_minors_idr, minor->index); > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + } > > > } > > > > > > static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > > @@ -123,13 +130,17 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > > minor->dev = dev; > > > > > > idr_preload(GFP_KERNEL); > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > - r = idr_alloc(&drm_minors_idr, > > > - NULL, > > > - 64 * type, > > > - 64 * (type + 1), > > > - GFP_NOWAIT); > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + if (type == DRM_MINOR_ACCEL) { > > > + r = accel_minor_alloc(); > > > + } else { > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > + r = idr_alloc(&drm_minors_idr, > > > + NULL, > > > + 64 * type, > > > + 64 * (type + 1), > > > + GFP_NOWAIT); > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + } > > > idr_preload_end(); > > > > > > if (r < 0) > > > @@ -161,10 +172,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > > if (!minor) > > > return 0; > > > > > > - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > > - if (ret) { > > > - DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > > - goto err_debugfs; > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > + accel_debugfs_init(minor, minor->index); > > > + } else { > > > + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > > + if (ret) { > > > + DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > > + goto err_debugfs; > > > + } > > > } > > > > > > ret = device_add(minor->kdev); > > > @@ -172,9 +187,13 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > > goto err_debugfs; > > > > > > /* replace NULL with @minor so lookups will succeed from now on */ > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > - idr_replace(&drm_minors_idr, minor, minor->index); > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > + accel_minor_replace(minor, minor->index); > > > + } else { > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > + idr_replace(&drm_minors_idr, minor, minor->index); > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + } > > > > > > DRM_DEBUG("new minor registered %d\n", minor->index); > > > return 0; > > > @@ -194,9 +213,13 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) > > > return; > > > > > > /* replace @minor with NULL so lookups will fail from now on */ > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > - idr_replace(&drm_minors_idr, NULL, minor->index); > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > + accel_minor_replace(NULL, minor->index); > > > + } else { > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > + idr_replace(&drm_minors_idr, NULL, minor->index); > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > + } > > > > > > device_del(minor->kdev); > > > dev_set_drvdata(minor->kdev, NULL); /* safety belt */ > > > @@ -603,6 +626,14 @@ static int drm_dev_init(struct drm_device *dev, > > > /* no per-device feature limits by default */ > > > dev->driver_features = ~0u; > > > > > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) && > > > + (drm_core_check_feature(dev, DRIVER_RENDER) || > > > + drm_core_check_feature(dev, DRIVER_MODESET))) { > > > + > > > + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n"); > > > + return -EINVAL; > > > + } > > > + > > > drm_legacy_init_members(dev); > > > INIT_LIST_HEAD(&dev->filelist); > > > INIT_LIST_HEAD(&dev->filelist_internal); > > > @@ -628,15 +659,21 @@ static int drm_dev_init(struct drm_device *dev, > > > > > > dev->anon_inode = inode; > > > > > > - if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > > - ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) { > > > + ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL); > > > if (ret) > > > goto err; > > > - } > > > + } else { > > > + if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > > + ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > > + if (ret) > > > + goto err; > > > + } > > > > > > - ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > > - if (ret) > > > - goto err; > > > + ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > > + if (ret) > > > + goto err; > > > + } > > > > > > ret = drm_legacy_create_map_hash(dev); > > > if (ret) > > > @@ -883,6 +920,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > > if (ret) > > > goto err_minors; > > > > > > + ret = drm_minor_register(dev, DRM_MINOR_ACCEL); > > > + if (ret) > > > + goto err_minors; > > > + > > > ret = create_compat_control_link(dev); > > > if (ret) > > > goto err_minors; > > > @@ -902,12 +943,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > > driver->name, driver->major, driver->minor, > > > driver->patchlevel, driver->date, > > > dev->dev ? dev_name(dev->dev) : "virtual device", > > > - dev->primary->index); > > > + dev->primary ? dev->primary->index : dev->accel->index); > > > > > > goto out_unlock; > > > > > > err_minors: > > > remove_compat_control_link(dev); > > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > > out_unlock: > > > @@ -950,6 +992,7 @@ void drm_dev_unregister(struct drm_device *dev) > > > drm_legacy_rmmaps(dev); > > > > > > remove_compat_control_link(dev); > > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > > } > > > @@ -1034,6 +1077,7 @@ static const struct file_operations drm_stub_fops = { > > > static void drm_core_exit(void) > > > { > > > drm_privacy_screen_lookup_exit(); > > > + accel_core_exit(); > > > unregister_chrdev(DRM_MAJOR, "drm"); > > > debugfs_remove(drm_debugfs_root); > > > drm_sysfs_destroy(); > > > @@ -1061,6 +1105,10 @@ static int __init drm_core_init(void) > > > if (ret < 0) > > > goto error; > > > > > > + ret = accel_core_init(); > > > + if (ret < 0) > > > + goto error; > > > + > > > drm_privacy_screen_lookup_init(); > > > > > > drm_core_init_complete = true; > > > diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c > > > index 430e00b16eec..b8da978d85bb 100644 > > > --- a/drivers/gpu/drm/drm_sysfs.c > > > +++ b/drivers/gpu/drm/drm_sysfs.c > > > @@ -19,6 +19,7 @@ > > > #include <linux/kdev_t.h> > > > #include <linux/slab.h> > > > > > > +#include <drm/drm_accel.h> > > > #include <drm/drm_connector.h> > > > #include <drm/drm_device.h> > > > #include <drm/drm_file.h> > > > @@ -471,19 +472,26 @@ struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) > > > struct device *kdev; > > > int r; > > > > > > - if (minor->type == DRM_MINOR_RENDER) > > > - minor_str = "renderD%d"; > > > - else > > > - minor_str = "card%d"; > > > - > > > kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); > > > if (!kdev) > > > return ERR_PTR(-ENOMEM); > > > > > > device_initialize(kdev); > > > - kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > > - kdev->class = drm_class; > > > - kdev->type = &drm_sysfs_device_minor; > > > + > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > + minor_str = "accel%d"; > > > + accel_set_device_instance_params(kdev, minor->index); > > > + } else { > > > + if (minor->type == DRM_MINOR_RENDER) > > > + minor_str = "renderD%d"; > > > + else > > > + minor_str = "card%d"; > > > + > > > + kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > > + kdev->class = drm_class; > > > + kdev->type = &drm_sysfs_device_minor; > > > + } > > > + > > > kdev->parent = minor->dev->dev; > > > kdev->release = drm_sysfs_release; > > > dev_set_drvdata(kdev, minor); > > > -- > > > 2.25.1 > > >
11/22, Oded Gabbay wrote: > On Tue, Nov 22, 2022 at 12:59 PM Oded Gabbay <ogabbay@kernel.org> wrote: > > > > On Tue, Nov 22, 2022 at 12:56 PM Melissa Wen <mwen@igalia.com> wrote: > > > > > > On 11/19, Oded Gabbay wrote: > > > > Now that we have the accel framework code ready, let's call the > > > > accel functions from all the appropriate places. These places are the > > > > drm module init/exit functions, and all the drm_minor handling > > > > functions. > > > > > > Hi Oded, > > > > > > The proposal overall LGTM, but I didn't manage to compile the kernel > > > with your patch series when DRM is enabled but accel support doesn't. > > > Multiple missing link errors... > > > > > > Am I missing something? Can you take a look at it from this patch 3/4? > > > > > > Thanks, > > > > > > Melissa > > Looking at it now, thanks for letting me know. > > Oded > Found the issue, missing } at end of accel_debugfs_init() in > drm_accel.h. Only compiles when accel support isn't compiled in. > I'll fix it before sending the PR to Dave. > Much appreciated :) > Oded Oh, great! Just checked here and everything is fine now. With that, you can add my r-b for the entire series too Reviewed-by: Melissa Wen <mwen@igalia.com> Thanks for working on it, Melissa > > > > > > > > > > > Signed-off-by: Oded Gabbay <ogabbay@kernel.org> > > > > --- > > > > drivers/gpu/drm/drm_drv.c | 102 ++++++++++++++++++++++++++---------- > > > > drivers/gpu/drm/drm_sysfs.c | 24 ++++++--- > > > > 2 files changed, 91 insertions(+), 35 deletions(-) > > > > > > > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > > > > index 8214a0b1ab7f..1aec019f6389 100644 > > > > --- a/drivers/gpu/drm/drm_drv.c > > > > +++ b/drivers/gpu/drm/drm_drv.c > > > > @@ -35,6 +35,7 @@ > > > > #include <linux/slab.h> > > > > #include <linux/srcu.h> > > > > > > > > +#include <drm/drm_accel.h> > > > > #include <drm/drm_cache.h> > > > > #include <drm/drm_client.h> > > > > #include <drm/drm_color_mgmt.h> > > > > @@ -90,6 +91,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, > > > > return &dev->primary; > > > > case DRM_MINOR_RENDER: > > > > return &dev->render; > > > > + case DRM_MINOR_ACCEL: > > > > + return &dev->accel; > > > > default: > > > > BUG(); > > > > } > > > > @@ -104,9 +107,13 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) > > > > > > > > put_device(minor->kdev); > > > > > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > > - idr_remove(&drm_minors_idr, minor->index); > > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > > + accel_minor_remove(minor->index); > > > > + } else { > > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > > + idr_remove(&drm_minors_idr, minor->index); > > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + } > > > > } > > > > > > > > static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > > > @@ -123,13 +130,17 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) > > > > minor->dev = dev; > > > > > > > > idr_preload(GFP_KERNEL); > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > > - r = idr_alloc(&drm_minors_idr, > > > > - NULL, > > > > - 64 * type, > > > > - 64 * (type + 1), > > > > - GFP_NOWAIT); > > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + if (type == DRM_MINOR_ACCEL) { > > > > + r = accel_minor_alloc(); > > > > + } else { > > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > > + r = idr_alloc(&drm_minors_idr, > > > > + NULL, > > > > + 64 * type, > > > > + 64 * (type + 1), > > > > + GFP_NOWAIT); > > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + } > > > > idr_preload_end(); > > > > > > > > if (r < 0) > > > > @@ -161,10 +172,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > > > if (!minor) > > > > return 0; > > > > > > > > - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > > > - if (ret) { > > > > - DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > > > - goto err_debugfs; > > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > > + accel_debugfs_init(minor, minor->index); > > > > + } else { > > > > + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); > > > > + if (ret) { > > > > + DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); > > > > + goto err_debugfs; > > > > + } > > > > } > > > > > > > > ret = device_add(minor->kdev); > > > > @@ -172,9 +187,13 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) > > > > goto err_debugfs; > > > > > > > > /* replace NULL with @minor so lookups will succeed from now on */ > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > > - idr_replace(&drm_minors_idr, minor, minor->index); > > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > > + accel_minor_replace(minor, minor->index); > > > > + } else { > > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > > + idr_replace(&drm_minors_idr, minor, minor->index); > > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + } > > > > > > > > DRM_DEBUG("new minor registered %d\n", minor->index); > > > > return 0; > > > > @@ -194,9 +213,13 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) > > > > return; > > > > > > > > /* replace @minor with NULL so lookups will fail from now on */ > > > > - spin_lock_irqsave(&drm_minor_lock, flags); > > > > - idr_replace(&drm_minors_idr, NULL, minor->index); > > > > - spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > > + accel_minor_replace(NULL, minor->index); > > > > + } else { > > > > + spin_lock_irqsave(&drm_minor_lock, flags); > > > > + idr_replace(&drm_minors_idr, NULL, minor->index); > > > > + spin_unlock_irqrestore(&drm_minor_lock, flags); > > > > + } > > > > > > > > device_del(minor->kdev); > > > > dev_set_drvdata(minor->kdev, NULL); /* safety belt */ > > > > @@ -603,6 +626,14 @@ static int drm_dev_init(struct drm_device *dev, > > > > /* no per-device feature limits by default */ > > > > dev->driver_features = ~0u; > > > > > > > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) && > > > > + (drm_core_check_feature(dev, DRIVER_RENDER) || > > > > + drm_core_check_feature(dev, DRIVER_MODESET))) { > > > > + > > > > + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n"); > > > > + return -EINVAL; > > > > + } > > > > + > > > > drm_legacy_init_members(dev); > > > > INIT_LIST_HEAD(&dev->filelist); > > > > INIT_LIST_HEAD(&dev->filelist_internal); > > > > @@ -628,15 +659,21 @@ static int drm_dev_init(struct drm_device *dev, > > > > > > > > dev->anon_inode = inode; > > > > > > > > - if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > > > - ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > > > + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) { > > > > + ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL); > > > > if (ret) > > > > goto err; > > > > - } > > > > + } else { > > > > + if (drm_core_check_feature(dev, DRIVER_RENDER)) { > > > > + ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); > > > > + if (ret) > > > > + goto err; > > > > + } > > > > > > > > - ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > > > - if (ret) > > > > - goto err; > > > > + ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); > > > > + if (ret) > > > > + goto err; > > > > + } > > > > > > > > ret = drm_legacy_create_map_hash(dev); > > > > if (ret) > > > > @@ -883,6 +920,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > > > if (ret) > > > > goto err_minors; > > > > > > > > + ret = drm_minor_register(dev, DRM_MINOR_ACCEL); > > > > + if (ret) > > > > + goto err_minors; > > > > + > > > > ret = create_compat_control_link(dev); > > > > if (ret) > > > > goto err_minors; > > > > @@ -902,12 +943,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > > > > driver->name, driver->major, driver->minor, > > > > driver->patchlevel, driver->date, > > > > dev->dev ? dev_name(dev->dev) : "virtual device", > > > > - dev->primary->index); > > > > + dev->primary ? dev->primary->index : dev->accel->index); > > > > > > > > goto out_unlock; > > > > > > > > err_minors: > > > > remove_compat_control_link(dev); > > > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > > > out_unlock: > > > > @@ -950,6 +992,7 @@ void drm_dev_unregister(struct drm_device *dev) > > > > drm_legacy_rmmaps(dev); > > > > > > > > remove_compat_control_link(dev); > > > > + drm_minor_unregister(dev, DRM_MINOR_ACCEL); > > > > drm_minor_unregister(dev, DRM_MINOR_PRIMARY); > > > > drm_minor_unregister(dev, DRM_MINOR_RENDER); > > > > } > > > > @@ -1034,6 +1077,7 @@ static const struct file_operations drm_stub_fops = { > > > > static void drm_core_exit(void) > > > > { > > > > drm_privacy_screen_lookup_exit(); > > > > + accel_core_exit(); > > > > unregister_chrdev(DRM_MAJOR, "drm"); > > > > debugfs_remove(drm_debugfs_root); > > > > drm_sysfs_destroy(); > > > > @@ -1061,6 +1105,10 @@ static int __init drm_core_init(void) > > > > if (ret < 0) > > > > goto error; > > > > > > > > + ret = accel_core_init(); > > > > + if (ret < 0) > > > > + goto error; > > > > + > > > > drm_privacy_screen_lookup_init(); > > > > > > > > drm_core_init_complete = true; > > > > diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c > > > > index 430e00b16eec..b8da978d85bb 100644 > > > > --- a/drivers/gpu/drm/drm_sysfs.c > > > > +++ b/drivers/gpu/drm/drm_sysfs.c > > > > @@ -19,6 +19,7 @@ > > > > #include <linux/kdev_t.h> > > > > #include <linux/slab.h> > > > > > > > > +#include <drm/drm_accel.h> > > > > #include <drm/drm_connector.h> > > > > #include <drm/drm_device.h> > > > > #include <drm/drm_file.h> > > > > @@ -471,19 +472,26 @@ struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) > > > > struct device *kdev; > > > > int r; > > > > > > > > - if (minor->type == DRM_MINOR_RENDER) > > > > - minor_str = "renderD%d"; > > > > - else > > > > - minor_str = "card%d"; > > > > - > > > > kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); > > > > if (!kdev) > > > > return ERR_PTR(-ENOMEM); > > > > > > > > device_initialize(kdev); > > > > - kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > > > - kdev->class = drm_class; > > > > - kdev->type = &drm_sysfs_device_minor; > > > > + > > > > + if (minor->type == DRM_MINOR_ACCEL) { > > > > + minor_str = "accel%d"; > > > > + accel_set_device_instance_params(kdev, minor->index); > > > > + } else { > > > > + if (minor->type == DRM_MINOR_RENDER) > > > > + minor_str = "renderD%d"; > > > > + else > > > > + minor_str = "card%d"; > > > > + > > > > + kdev->devt = MKDEV(DRM_MAJOR, minor->index); > > > > + kdev->class = drm_class; > > > > + kdev->type = &drm_sysfs_device_minor; > > > > + } > > > > + > > > > kdev->parent = minor->dev->dev; > > > > kdev->release = drm_sysfs_release; > > > > dev_set_drvdata(kdev, minor); > > > > -- > > > > 2.25.1 > > > >
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 8214a0b1ab7f..1aec019f6389 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -35,6 +35,7 @@ #include <linux/slab.h> #include <linux/srcu.h> +#include <drm/drm_accel.h> #include <drm/drm_cache.h> #include <drm/drm_client.h> #include <drm/drm_color_mgmt.h> @@ -90,6 +91,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, return &dev->primary; case DRM_MINOR_RENDER: return &dev->render; + case DRM_MINOR_ACCEL: + return &dev->accel; default: BUG(); } @@ -104,9 +107,13 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) put_device(minor->kdev); - spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + if (minor->type == DRM_MINOR_ACCEL) { + accel_minor_remove(minor->index); + } else { + spin_lock_irqsave(&drm_minor_lock, flags); + idr_remove(&drm_minors_idr, minor->index); + spin_unlock_irqrestore(&drm_minor_lock, flags); + } } static int drm_minor_alloc(struct drm_device *dev, unsigned int type) @@ -123,13 +130,17 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) minor->dev = dev; idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - r = idr_alloc(&drm_minors_idr, - NULL, - 64 * type, - 64 * (type + 1), - GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); + if (type == DRM_MINOR_ACCEL) { + r = accel_minor_alloc(); + } else { + spin_lock_irqsave(&drm_minor_lock, flags); + r = idr_alloc(&drm_minors_idr, + NULL, + 64 * type, + 64 * (type + 1), + GFP_NOWAIT); + spin_unlock_irqrestore(&drm_minor_lock, flags); + } idr_preload_end(); if (r < 0) @@ -161,10 +172,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) if (!minor) return 0; - ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); - if (ret) { - DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); - goto err_debugfs; + if (minor->type == DRM_MINOR_ACCEL) { + accel_debugfs_init(minor, minor->index); + } else { + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); + if (ret) { + DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); + goto err_debugfs; + } } ret = device_add(minor->kdev); @@ -172,9 +187,13 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) goto err_debugfs; /* replace NULL with @minor so lookups will succeed from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, minor, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + if (minor->type == DRM_MINOR_ACCEL) { + accel_minor_replace(minor, minor->index); + } else { + spin_lock_irqsave(&drm_minor_lock, flags); + idr_replace(&drm_minors_idr, minor, minor->index); + spin_unlock_irqrestore(&drm_minor_lock, flags); + } DRM_DEBUG("new minor registered %d\n", minor->index); return 0; @@ -194,9 +213,13 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) return; /* replace @minor with NULL so lookups will fail from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, NULL, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + if (minor->type == DRM_MINOR_ACCEL) { + accel_minor_replace(NULL, minor->index); + } else { + spin_lock_irqsave(&drm_minor_lock, flags); + idr_replace(&drm_minors_idr, NULL, minor->index); + spin_unlock_irqrestore(&drm_minor_lock, flags); + } device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -603,6 +626,14 @@ static int drm_dev_init(struct drm_device *dev, /* no per-device feature limits by default */ dev->driver_features = ~0u; + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) && + (drm_core_check_feature(dev, DRIVER_RENDER) || + drm_core_check_feature(dev, DRIVER_MODESET))) { + + DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n"); + return -EINVAL; + } + drm_legacy_init_members(dev); INIT_LIST_HEAD(&dev->filelist); INIT_LIST_HEAD(&dev->filelist_internal); @@ -628,15 +659,21 @@ static int drm_dev_init(struct drm_device *dev, dev->anon_inode = inode; - if (drm_core_check_feature(dev, DRIVER_RENDER)) { - ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); + if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) { + ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL); if (ret) goto err; - } + } else { + if (drm_core_check_feature(dev, DRIVER_RENDER)) { + ret = drm_minor_alloc(dev, DRM_MINOR_RENDER); + if (ret) + goto err; + } - ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); - if (ret) - goto err; + ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY); + if (ret) + goto err; + } ret = drm_legacy_create_map_hash(dev); if (ret) @@ -883,6 +920,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) if (ret) goto err_minors; + ret = drm_minor_register(dev, DRM_MINOR_ACCEL); + if (ret) + goto err_minors; + ret = create_compat_control_link(dev); if (ret) goto err_minors; @@ -902,12 +943,13 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) driver->name, driver->major, driver->minor, driver->patchlevel, driver->date, dev->dev ? dev_name(dev->dev) : "virtual device", - dev->primary->index); + dev->primary ? dev->primary->index : dev->accel->index); goto out_unlock; err_minors: remove_compat_control_link(dev); + drm_minor_unregister(dev, DRM_MINOR_ACCEL); drm_minor_unregister(dev, DRM_MINOR_PRIMARY); drm_minor_unregister(dev, DRM_MINOR_RENDER); out_unlock: @@ -950,6 +992,7 @@ void drm_dev_unregister(struct drm_device *dev) drm_legacy_rmmaps(dev); remove_compat_control_link(dev); + drm_minor_unregister(dev, DRM_MINOR_ACCEL); drm_minor_unregister(dev, DRM_MINOR_PRIMARY); drm_minor_unregister(dev, DRM_MINOR_RENDER); } @@ -1034,6 +1077,7 @@ static const struct file_operations drm_stub_fops = { static void drm_core_exit(void) { drm_privacy_screen_lookup_exit(); + accel_core_exit(); unregister_chrdev(DRM_MAJOR, "drm"); debugfs_remove(drm_debugfs_root); drm_sysfs_destroy(); @@ -1061,6 +1105,10 @@ static int __init drm_core_init(void) if (ret < 0) goto error; + ret = accel_core_init(); + if (ret < 0) + goto error; + drm_privacy_screen_lookup_init(); drm_core_init_complete = true; diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 430e00b16eec..b8da978d85bb 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -19,6 +19,7 @@ #include <linux/kdev_t.h> #include <linux/slab.h> +#include <drm/drm_accel.h> #include <drm/drm_connector.h> #include <drm/drm_device.h> #include <drm/drm_file.h> @@ -471,19 +472,26 @@ struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) struct device *kdev; int r; - if (minor->type == DRM_MINOR_RENDER) - minor_str = "renderD%d"; - else - minor_str = "card%d"; - kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); if (!kdev) return ERR_PTR(-ENOMEM); device_initialize(kdev); - kdev->devt = MKDEV(DRM_MAJOR, minor->index); - kdev->class = drm_class; - kdev->type = &drm_sysfs_device_minor; + + if (minor->type == DRM_MINOR_ACCEL) { + minor_str = "accel%d"; + accel_set_device_instance_params(kdev, minor->index); + } else { + if (minor->type == DRM_MINOR_RENDER) + minor_str = "renderD%d"; + else + minor_str = "card%d"; + + kdev->devt = MKDEV(DRM_MAJOR, minor->index); + kdev->class = drm_class; + kdev->type = &drm_sysfs_device_minor; + } + kdev->parent = minor->dev->dev; kdev->release = drm_sysfs_release; dev_set_drvdata(kdev, minor);