Debian Codegraph @

src/broadcom/drm-shim/vc4_noop.c

raw
1 /*
2 * Copyright (c) 2021 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/ioctl.h>
28 #include "drm-uapi/vc4_drm.h"
29 #include "drm-shim/drm_shim.h"
30 #include "util/log.h"
31
32 bool drm_shim_driver_prefers_first_render_node = true;
33
34 static int
35 vc4_ioctl_noop(int fd, unsigned long request, void *arg)
36 {
37 return 0;
38 }
39
40 static int
41 vc4_ioctl_create_bo(int fd, unsigned long request, void *arg)
42 {
43 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
44 struct drm_vc4_create_bo *create = arg;
45 struct shim_bo *bo = calloc(1, sizeof(*bo));
46
47 drm_shim_bo_init(bo, create->size);
48 create->handle = drm_shim_bo_get_handle(shim_fd, bo);
49 drm_shim_bo_put(bo);
50
51 return 0;
52 }
53
54 static int
55 vc4_ioctl_create_shader_bo(int fd, unsigned long request, void *arg)
56 {
57 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
58 struct drm_vc4_create_shader_bo *create = arg;
59 struct shim_bo *bo = calloc(1, sizeof(*bo));
60
61 drm_shim_bo_init(bo, create->size);
62 create->handle = drm_shim_bo_get_handle(shim_fd, bo);
63 drm_shim_bo_put(bo);
64
65 return 0;
66 }
67
68 static int
69 vc4_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
70 {
71 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
72 struct drm_vc4_mmap_bo *map = arg;
73 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
74
75 map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
76
77 drm_shim_bo_put(bo);
78
79 return 0;
80 }
81
82 static int
83 vc4_ioctl_get_param(int fd, unsigned long request, void *arg)
84 {
85 struct drm_vc4_get_param *gp = arg;
86 static const uint32_t param_map[] = {
87 [DRM_VC4_PARAM_V3D_IDENT0] = 0x2000000,
88 [DRM_VC4_PARAM_V3D_IDENT1] = 0x0000001,
89 };
90
91 switch (gp->param) {
92 case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
93 case DRM_VC4_PARAM_SUPPORTS_ETC1:
94 case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
95 case DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER:
96 gp->value = 1;
97 return 0;
98
99 case DRM_VC4_PARAM_SUPPORTS_MADVISE:
100 case DRM_VC4_PARAM_SUPPORTS_PERFMON:
101 gp->value = 0;
102 return 0;
103
104 default:
105 break;
106 }
107
108 if (gp->param < ARRAY_SIZE(param_map) && param_map[gp->param]) {
109 gp->value = param_map[gp->param];
110 return 0;
111 }
112
113 mesa_loge("Unknown DRM_IOCTL_VC4_GET_PARAM %d", gp->param);
114 return -1;
115 }
116
117 static ioctl_fn_t driver_ioctls[] = {
118 [DRM_VC4_CREATE_BO] = vc4_ioctl_create_bo,
119 [DRM_VC4_CREATE_SHADER_BO] = vc4_ioctl_create_shader_bo,
120 [DRM_VC4_MMAP_BO] = vc4_ioctl_mmap_bo,
121 [DRM_VC4_GET_PARAM] = vc4_ioctl_get_param,
122 [DRM_VC4_GET_TILING] = vc4_ioctl_noop,
123 [DRM_VC4_LABEL_BO] = vc4_ioctl_noop,
124 };
125
126 void
127 drm_shim_driver_init(void)
128 {
129 shim_device.bus_type = DRM_BUS_PLATFORM;
130 shim_device.driver_name = "vc4";
131 shim_device.driver_ioctls = driver_ioctls;
132 shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
133
134 drm_shim_override_file("OF_FULLNAME=/rdb/vc4\n"
135 "OF_COMPATIBLE_N=1\n"
136 "OF_COMPATIBLE_0=brcm,7278-vc4\n",
137 "/sys/dev/char/%d:%d/device/uevent",
138 DRM_MAJOR, render_node_minor);
139 }