Skip to content

Commit 8bf4889

Browse files
committed
drivers/accel: define kconfig and register a new major
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 <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Jeffrey Hugo <[email protected]> Reviewed-by: Dave Airlie <[email protected]> Acked-by: Thomas Zimmermann <[email protected]> Acked-by: Jacek Lawrynowicz <[email protected]> Tested-by: Jacek Lawrynowicz <[email protected]> Reviewed-by: Melissa Wen <[email protected]>
1 parent fc58764 commit 8bf4889

File tree

7 files changed

+155
-0
lines changed

7 files changed

+155
-0
lines changed

Documentation/admin-guide/devices.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,6 +3080,11 @@
30803080
...
30813081
255 = /dev/osd255 256th OSD Device
30823082

3083+
261 char Compute Acceleration Devices
3084+
0 = /dev/accel/accel0 First acceleration device
3085+
1 = /dev/accel/accel1 Second acceleration device
3086+
...
3087+
30833088
384-511 char RESERVED FOR DYNAMIC ASSIGNMENT
30843089
Character devices that request a dynamic allocation of major
30853090
number will take numbers starting from 511 and downward,

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6833,6 +6833,14 @@ F: include/drm/drm*
68336833
F: include/linux/vga*
68346834
F: include/uapi/drm/drm*
68356835

6836+
DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK
6837+
M: Oded Gabbay <[email protected]>
6838+
6839+
S: Maintained
6840+
C: irc://irc.oftc.net/dri-devel
6841+
T: git https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/accel.git
6842+
F: drivers/accel/
6843+
68366844
DRM DRIVERS FOR ALLWINNER A10
68376845
M: Maxime Ripard <[email protected]>
68386846
M: Chen-Yu Tsai <[email protected]>

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ source "drivers/media/Kconfig"
9999

100100
source "drivers/video/Kconfig"
101101

102+
source "drivers/accel/Kconfig"
103+
102104
source "sound/Kconfig"
103105

104106
source "drivers/hid/Kconfig"

drivers/accel/Kconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
#
3+
# Compute Acceleration device configuration
4+
#
5+
# This framework provides support for compute acceleration devices, such
6+
# as, but not limited to, Machine-Learning and Deep-Learning acceleration
7+
# devices
8+
#
9+
menuconfig DRM_ACCEL
10+
bool "Compute Acceleration Framework"
11+
depends on DRM
12+
help
13+
Framework for device drivers of compute acceleration devices, such
14+
as, but not limited to, Machine-Learning and Deep-Learning
15+
acceleration devices.
16+
If you say Y here, you need to select the module that's right for
17+
your acceleration device from the list below.
18+
This framework is integrated with the DRM subsystem as compute
19+
accelerators and GPUs share a lot in common and can use almost the
20+
same infrastructure code.
21+
Having said that, acceleration devices will have a different
22+
major number than GPUs, and will be exposed to user-space using
23+
different device files, called accel/accel* (in /dev, sysfs
24+
and debugfs).

drivers/accel/drm_accel.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
/*
4+
* Copyright 2022 HabanaLabs, Ltd.
5+
* All Rights Reserved.
6+
*
7+
*/
8+
9+
#include <linux/debugfs.h>
10+
#include <linux/device.h>
11+
12+
#include <drm/drm_accel.h>
13+
#include <drm/drm_ioctl.h>
14+
#include <drm/drm_print.h>
15+
16+
static struct dentry *accel_debugfs_root;
17+
static struct class *accel_class;
18+
19+
static char *accel_devnode(struct device *dev, umode_t *mode)
20+
{
21+
return kasprintf(GFP_KERNEL, "accel/%s", dev_name(dev));
22+
}
23+
24+
static int accel_sysfs_init(void)
25+
{
26+
accel_class = class_create(THIS_MODULE, "accel");
27+
if (IS_ERR(accel_class))
28+
return PTR_ERR(accel_class);
29+
30+
accel_class->devnode = accel_devnode;
31+
32+
return 0;
33+
}
34+
35+
static void accel_sysfs_destroy(void)
36+
{
37+
if (IS_ERR_OR_NULL(accel_class))
38+
return;
39+
class_destroy(accel_class);
40+
accel_class = NULL;
41+
}
42+
43+
static int accel_stub_open(struct inode *inode, struct file *filp)
44+
{
45+
return -EOPNOTSUPP;
46+
}
47+
48+
static const struct file_operations accel_stub_fops = {
49+
.owner = THIS_MODULE,
50+
.open = accel_stub_open,
51+
.llseek = noop_llseek,
52+
};
53+
54+
void accel_core_exit(void)
55+
{
56+
unregister_chrdev(ACCEL_MAJOR, "accel");
57+
debugfs_remove(accel_debugfs_root);
58+
accel_sysfs_destroy();
59+
}
60+
61+
int __init accel_core_init(void)
62+
{
63+
int ret;
64+
65+
ret = accel_sysfs_init();
66+
if (ret < 0) {
67+
DRM_ERROR("Cannot create ACCEL class: %d\n", ret);
68+
goto error;
69+
}
70+
71+
accel_debugfs_root = debugfs_create_dir("accel", NULL);
72+
73+
ret = register_chrdev(ACCEL_MAJOR, "accel", &accel_stub_fops);
74+
if (ret < 0)
75+
DRM_ERROR("Cannot register ACCEL major: %d\n", ret);
76+
77+
error:
78+
/*
79+
* Any cleanup due to errors will be done in drm_core_exit() that
80+
* will call accel_core_exit()
81+
*/
82+
return ret;
83+
}

drivers/gpu/drm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
7070
drm-$(CONFIG_DRM_PRIVACY_SCREEN) += \
7171
drm_privacy_screen.o \
7272
drm_privacy_screen_x86.o
73+
drm-$(CONFIG_DRM_ACCEL) += ../../accel/drm_accel.o
7374
obj-$(CONFIG_DRM) += drm.o
7475

7576
obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o

include/drm/drm_accel.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* SPDX-License-Identifier: GPL-2.0
2+
*
3+
* Copyright 2022 HabanaLabs, Ltd.
4+
* All Rights Reserved.
5+
*
6+
*/
7+
8+
#ifndef DRM_ACCEL_H_
9+
#define DRM_ACCEL_H_
10+
11+
#define ACCEL_MAJOR 261
12+
13+
#if IS_ENABLED(CONFIG_DRM_ACCEL)
14+
15+
void accel_core_exit(void);
16+
int accel_core_init(void);
17+
18+
#else
19+
20+
static inline void accel_core_exit(void)
21+
{
22+
}
23+
24+
static inline int __init accel_core_init(void)
25+
{
26+
/* Return 0 to allow drm_core_init to complete successfully */
27+
return 0;
28+
}
29+
30+
#endif /* IS_ENABLED(CONFIG_DRM_ACCEL) */
31+
32+
#endif /* DRM_ACCEL_H_ */

0 commit comments

Comments
 (0)