From patchwork Sun Nov 6 21:02:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 16183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1675116wru; Sun, 6 Nov 2022 13:07:50 -0800 (PST) X-Google-Smtp-Source: AMsMyM5XGWkE9aKFI1ITDAJ4cxQjJ2Xmh9qgu5xsyHLHxfoOehFES8YAJ24GEBu1Cd2OmyolZFjt X-Received: by 2002:a17:90b:3a8f:b0:214:2211:8143 with SMTP id om15-20020a17090b3a8f00b0021422118143mr28260610pjb.219.1667768870015; Sun, 06 Nov 2022 13:07:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667768870; cv=none; d=google.com; s=arc-20160816; b=is24Yf3gjs4+NhZ9o3vKspU10EmQjRxsKJrF/81jQV/go4Nu3ikuCBXE4C8PsqFsJl fD8bBWVnfRESeJViYe3j/XU7KUm9Y3bSbL9f4bPJbbBdKEg0OZm2a+JQDtDAhKR+znVe iswWtl3kQDKz39tVCiYxRaaYA0y+pwby0ow35aPquVxP3eFKDVqLSe+dV1Y9xd52Gnxu dTGjsAQagEg5uYGQysvfzRLY7/lp0EVXzn5GiG+3dMZblZw6OwQi6jPEJAk7QtdcZbI0 dCQxFfJS2/Ah5/w+Pjp7dW7YgL8H0aY6Ne2Nigf4DMYn2+rNBnBuDKunNAFdpjaBK+aL WY0g== 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=yvbuJ50LOOOhdnLo2x73gAeV0ELoQkx8EITpfESay3A=; b=SmFylLINJKBJSeTR9SgI2mLAgs8K41eGo1X8wpYBbgYgg/swTxnNSpF2zRsvvVUFEr pQJeL/NUhQQ8Z+lPcTzWJ/FPlrCu9eYflhWGuwBiI+/qFF1/fvCvMf4MpSDfnOLUKeTK P+lxokJ1qy2HQqHbnp4sltEEJK0i+b0p2kyKE2hrJRf0Ez7/6tR7GCtgbUBhuNGC8pEn 8LLlJn28vyFe0Z1qXS4i2+r4Ewyh/SajGsFOyLXyagG6SScgs0AVVH50sUOv1/XWdwRh eFCIepD+YSFrIrzQAEjHiF/tb2ZZ/kZujBW4lyTcU6tucD9XqXsVjNq7dXMYtlaKaF1c QB0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dbkxpuUb; 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 v5-20020a170902b7c500b001868a25da0dsi6646508plz.40.2022.11.06.13.07.36; Sun, 06 Nov 2022 13:07:49 -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=dbkxpuUb; 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 S230121AbiKFVCv (ORCPT + 99 others); Sun, 6 Nov 2022 16:02:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230126AbiKFVCm (ORCPT ); Sun, 6 Nov 2022 16:02:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E353BFAD1 for ; Sun, 6 Nov 2022 13:02:40 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 70D4660DBE for ; Sun, 6 Nov 2022 21:02:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C624C433D6; Sun, 6 Nov 2022 21:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667768559; bh=x9wBA/wDVGwAmccu7UlxFcr3O9baMkLq3SaTCROKc4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dbkxpuUbQ+2nbfGMr1cThYEanOWHaqNMWx6TGrHsOYAXxa6nVnRNYOfBBuIyBA1L6 21Pe0X4nTepV4SZfn2iG1Jdbw5CZh/v5WdRYon3eTK8Rzm9QK1Jx7Dm+qgYkrVoBWZ GaBsehWXWoX735urjNPnQVRu8VNjDe2BxnGFrR35Ol7ublwJ52sHwAqLTN3dP8EbZu HU+lJxKUclKCmbSaDA3AknjwnT1lJCbOwYDAc6FWFo0jJUfUUm1Qvr4BCNoc5KQ87v lG8wlUx1SfwraYS/jPcBBdP9ok3Eji44RpKGj4I8PzwR67dTKWYpozgItSs8pIHngr LDj6rdCVoEkQQ== From: Oded Gabbay To: David Airlie , Daniel Vetter , Arnd Bergmann , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Jason Gunthorpe , John Hubbard , Alex Deucher Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Yuji Ishikawa , Jiho Chu , Daniel Stone , Tvrtko Ursulin , Jeffrey Hugo , Christoph Hellwig , Kevin Hilman , Jagan Teki , Jacek Lawrynowicz , Maciej Kwapulinski , Stanislaw Gruszka , Randy Dunlap Subject: [RFC PATCH v3 1/3] drivers/accel: define kconfig and register a new major Date: Sun, 6 Nov 2022 23:02:23 +0200 Message-Id: <20221106210225.2065371-2-ogabbay@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221106210225.2065371-1-ogabbay@kernel.org> References: <20221106210225.2065371-1-ogabbay@kernel.org> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748782410801588519?= X-GMAIL-MSGID: =?utf-8?q?1748782410801588519?= Add a new Kconfig for the accel subsystem. The Kconfig currently contains only the basic CONFIG_DRM_ACCEL option that will be used to decide whether to compile the accel registration code. Therefore, the kconfig option is defined as bool. The accel code will be compiled as part of drm.ko and will be called directly from the DRM core code. The reason we compile it as part of drm.ko and not as a separate module is because of cyclic dependency between drm.ko and the separate module (if it would have existed). This is due to the fact that DRM core code calls accel functions and vice-versa. The accelerator devices will be exposed to the user space with a new, dedicated major number - 261. The accel init function registers the new major number as a char device and create corresponding sysfs and debugfs root entries, similar to what is done in DRM init function. I added a new header called drm_accel.h to include/drm/, that will hold the prototypes of the drm_accel.c functions. In case CONFIG_DRM_ACCEL is set to 'N', that header will contain empty inline implementations of those functions, to allow DRM core code to compile successfully without dependency on CONFIG_DRM_ACCEL. I Updated the MAINTAINERS file accordingly with the newly added folder and I have taken the liberty to appropriate the dri-devel mailing list and the dri-devel IRC channel for the accel subsystem. Signed-off-by: Oded Gabbay Tested-by: Stanislaw Gruszka --- Changes in v3: - Remove accel kernel module and build the code as part of drm.ko. - Rename CONFIG_ACCEL to CONFIG_DRM_ACCEL as the code is built as part of drm.ko. - Rename accel_drv.c to drm_accel.c - Change kconfig option to be bool instead of tristate - Add . at end of help text in kconfig Documentation/admin-guide/devices.txt | 5 ++ MAINTAINERS | 8 +++ drivers/Kconfig | 2 + drivers/accel/Kconfig | 24 ++++++++ drivers/accel/drm_accel.c | 82 +++++++++++++++++++++++++++ drivers/gpu/drm/Makefile | 1 + include/drm/drm_accel.h | 31 ++++++++++ 7 files changed, 153 insertions(+) create mode 100644 drivers/accel/Kconfig create mode 100644 drivers/accel/drm_accel.c create mode 100644 include/drm/drm_accel.h -- 2.25.1 diff --git a/Documentation/admin-guide/devices.txt b/Documentation/admin-guide/devices.txt index 9764d6edb189..06c525e01ea5 100644 --- a/Documentation/admin-guide/devices.txt +++ b/Documentation/admin-guide/devices.txt @@ -3080,6 +3080,11 @@ ... 255 = /dev/osd255 256th OSD Device + 261 char Compute Acceleration Devices + 0 = /dev/accel/accel0 First acceleration device + 1 = /dev/accel/accel1 Second acceleration device + ... + 384-511 char RESERVED FOR DYNAMIC ASSIGNMENT Character devices that request a dynamic allocation of major number will take numbers starting from 511 and downward, diff --git a/MAINTAINERS b/MAINTAINERS index 30e3df70daec..5b07d81c985e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6825,6 +6825,14 @@ F: include/drm/drm* F: include/linux/vga* F: include/uapi/drm/drm* +DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK +M: Oded Gabbay +L: dri-devel@lists.freedesktop.org +S: Maintained +C: irc://irc.oftc.net/dri-devel +T: git https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/accel.git +F: drivers/accel/ + DRM DRIVERS FOR ALLWINNER A10 M: Maxime Ripard M: Chen-Yu Tsai diff --git a/drivers/Kconfig b/drivers/Kconfig index 19ee995bd0ae..968bd0a6fd78 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -99,6 +99,8 @@ source "drivers/media/Kconfig" source "drivers/video/Kconfig" +source "drivers/accel/Kconfig" + source "sound/Kconfig" source "drivers/hid/Kconfig" diff --git a/drivers/accel/Kconfig b/drivers/accel/Kconfig new file mode 100644 index 000000000000..c9ce849b2984 --- /dev/null +++ b/drivers/accel/Kconfig @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Compute Acceleration device configuration +# +# This framework provides support for compute acceleration devices, such +# as, but not limited to, Machine-Learning and Deep-Learning acceleration +# devices +# +menuconfig DRM_ACCEL + bool "Compute Acceleration Framework" + depends on DRM + help + Framework for device drivers of compute acceleration devices, such + as, but not limited to, Machine-Learning and Deep-Learning + acceleration devices. + If you say Y here, you need to select the module that's right for + your acceleration device from the list below. + This framework is integrated with the DRM subsystem as compute + accelerators and GPUs share a lot in common and can use almost the + same infrastructure code. + Having said that, acceleration devices will have a different + major number than GPUs, and will be exposed to user-space using + different device files, called accel/accel* (in /dev, sysfs + and debugfs). diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c new file mode 100644 index 000000000000..943d960ddefc --- /dev/null +++ b/drivers/accel/drm_accel.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * Copyright 2022 HabanaLabs, Ltd. + * All Rights Reserved. + * + */ + +#include +#include + +#include +#include +#include + +static struct dentry *accel_debugfs_root; +static struct class *accel_class; + +static char *accel_devnode(struct device *dev, umode_t *mode) +{ + return kasprintf(GFP_KERNEL, "accel/%s", dev_name(dev)); +} + +static int accel_sysfs_init(void) +{ + accel_class = class_create(THIS_MODULE, "accel"); + if (IS_ERR(accel_class)) + return PTR_ERR(accel_class); + + accel_class->devnode = accel_devnode; + + return 0; +} + +static void accel_sysfs_destroy(void) +{ + if (IS_ERR_OR_NULL(accel_class)) + return; + class_destroy(accel_class); + accel_class = NULL; +} + +static int accel_stub_open(struct inode *inode, struct file *filp) +{ + return -EOPNOTSUPP; +} + +static const struct file_operations accel_stub_fops = { + .owner = THIS_MODULE, + .open = accel_stub_open, + .llseek = noop_llseek, +}; + +void accel_core_exit(void) +{ + unregister_chrdev(ACCEL_MAJOR, "accel"); + debugfs_remove(accel_debugfs_root); + accel_sysfs_destroy(); +} + +int __init accel_core_init(void) +{ + int ret; + + ret = accel_sysfs_init(); + if (ret < 0) { + DRM_ERROR("Cannot create ACCEL class: %d\n", ret); + goto error; + } + + accel_debugfs_root = debugfs_create_dir("accel", NULL); + + ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops); + if (ret < 0) + goto error; + +error: + /* Any cleanup will be done in drm_core_exit() that will call + * to accel_core_exit() + */ + return ret; +} diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 6e55c47288e4..f51aa5eca7e7 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -70,6 +70,7 @@ drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \ drm_privacy_screen.o \ drm_privacy_screen_x86.o +drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_NOMODESET) += drm_nomodeset.o diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h new file mode 100644 index 000000000000..31b42d3d6a15 --- /dev/null +++ b/include/drm/drm_accel.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright 2022 HabanaLabs, Ltd. + * All Rights Reserved. + * + */ + +#ifndef DRM_ACCEL_H_ +#define DRM_ACCEL_H_ + +#define ACCEL_MAJOR 261 + +#if IS_ENABLED(CONFIG_DRM_ACCEL) + +void accel_core_exit(void); +int accel_core_init(void); + +#else + +static inline void accel_core_exit(void) +{ +} + +static inline int __init accel_core_init(void) +{ + return 0; +} + +#endif /* IS_ENABLED(CONFIG_DRM_ACCEL) */ + +#endif /* DRM_ACCEL_H_ */