1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2023-2024 Intel Corporation
4 */
5
6 #include <linux/errno.h>
7 #include <linux/sysctl.h>
8
9 #include <uapi/drm/xe_drm.h>
10
11 #include "xe_oa.h"
12 #include "xe_observation.h"
13
14 u32 xe_observation_paranoid = true;
15 static struct ctl_table_header *sysctl_header;
16
xe_oa_ioctl(struct drm_device * dev,struct drm_xe_observation_param * arg,struct drm_file * file)17 static int xe_oa_ioctl(struct drm_device *dev, struct drm_xe_observation_param *arg,
18 struct drm_file *file)
19 {
20 switch (arg->observation_op) {
21 case DRM_XE_OBSERVATION_OP_STREAM_OPEN:
22 return xe_oa_stream_open_ioctl(dev, arg->param, file);
23 case DRM_XE_OBSERVATION_OP_ADD_CONFIG:
24 return xe_oa_add_config_ioctl(dev, arg->param, file);
25 case DRM_XE_OBSERVATION_OP_REMOVE_CONFIG:
26 return xe_oa_remove_config_ioctl(dev, arg->param, file);
27 default:
28 return -EINVAL;
29 }
30 }
31
32 /**
33 * xe_observation_ioctl - The top level observation layer ioctl
34 * @dev: @drm_device
35 * @data: pointer to struct @drm_xe_observation_param
36 * @file: @drm_file
37 *
38 * The function is called for different observation streams types and
39 * allows execution of different operations supported by those stream
40 * types.
41 *
42 * Return: 0 on success or a negative error code on failure.
43 */
xe_observation_ioctl(struct drm_device * dev,void * data,struct drm_file * file)44 int xe_observation_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
45 {
46 struct drm_xe_observation_param *arg = data;
47
48 if (arg->extensions)
49 return -EINVAL;
50
51 switch (arg->observation_type) {
52 case DRM_XE_OBSERVATION_TYPE_OA:
53 return xe_oa_ioctl(dev, arg, file);
54 default:
55 return -EINVAL;
56 }
57 }
58
59 static struct ctl_table observation_ctl_table[] = {
60 {
61 .procname = "observation_paranoid",
62 .data = &xe_observation_paranoid,
63 .maxlen = sizeof(xe_observation_paranoid),
64 .mode = 0644,
65 .proc_handler = proc_dointvec_minmax,
66 .extra1 = SYSCTL_ZERO,
67 .extra2 = SYSCTL_ONE,
68 },
69 };
70
71 /**
72 * xe_observation_sysctl_register - Register xe_observation_paranoid sysctl
73 *
74 * Normally only superuser/root can access observation stream
75 * data. However, superuser can set xe_observation_paranoid sysctl to 0 to
76 * allow non-privileged users to also access observation data.
77 *
78 * Return: always returns 0
79 */
xe_observation_sysctl_register(void)80 int xe_observation_sysctl_register(void)
81 {
82 sysctl_header = register_sysctl("dev/xe", observation_ctl_table);
83 return 0;
84 }
85
86 /**
87 * xe_observation_sysctl_unregister - Unregister xe_observation_paranoid sysctl
88 */
xe_observation_sysctl_unregister(void)89 void xe_observation_sysctl_unregister(void)
90 {
91 unregister_sysctl_table(sysctl_header);
92 }
93