Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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 <drm/xe_drm.h>
10
11#include "xe_oa.h"
12#include "xe_observation.h"
13
14u32 xe_observation_paranoid = true;
15static struct ctl_table_header *sysctl_header;
16
17static 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 */
44int 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
59static 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/**
73 * xe_observation_sysctl_register - Register xe_observation_paranoid sysctl
74 *
75 * Normally only superuser/root can access observation stream
76 * data. However, superuser can set xe_observation_paranoid sysctl to 0 to
77 * allow non-privileged users to also access observation data.
78 *
79 * Return: always returns 0
80 */
81int xe_observation_sysctl_register(void)
82{
83 sysctl_header = register_sysctl("dev/xe", observation_ctl_table);
84 return 0;
85}
86
87/**
88 * xe_observation_sysctl_unregister - Unregister xe_observation_paranoid sysctl
89 */
90void xe_observation_sysctl_unregister(void)
91{
92 unregister_sysctl_table(sysctl_header);
93}