Debian Codegraph @

src/broadcom/drm-shim/v3d_noop.c

raw
1 /*
2 * Copyright © 2018 Broadcom
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/v3d_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 struct v3d_bo {
35 struct shim_bo base;
36 uint32_t offset;
37 };
38
39 static struct v3d_bo *
40 v3d_bo(struct shim_bo *bo)
41 {
42 return (struct v3d_bo *)bo;
43 }
44
45 struct v3d_device {
46 uint32_t next_offset;
47 };
48
49 static struct v3d_device v3d = {
50 .next_offset = 0x1000,
51 };
52
53 static int
54 v3d_ioctl_noop(int fd, unsigned long request, void *arg)
55 {
56 return 0;
57 }
58
59 static int
60 v3d_ioctl_create_bo(int fd, unsigned long request, void *arg)
61 {
62 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
63 struct drm_v3d_create_bo *create = arg;
64 struct v3d_bo *bo = calloc(1, sizeof(*bo));
65
66 drm_shim_bo_init(&bo->base, create->size);
67
68 assert(UINT_MAX - v3d.next_offset > create->size);
69 bo->offset = v3d.next_offset;
70 v3d.next_offset += create->size;
71
72 create->offset = bo->offset;
73 create->handle = drm_shim_bo_get_handle(shim_fd, &bo->base);
74
75 drm_shim_bo_put(&bo->base);
76
77 return 0;
78 }
79
80 static int
81 v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg)
82 {
83 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
84 struct drm_v3d_get_bo_offset *args = arg;
85 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, args->handle);
86
87 args->offset = v3d_bo(bo)->offset;
88
89 drm_shim_bo_put(bo);
90
91 return 0;
92 }
93
94 static int
95 v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
96 {
97 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
98 struct drm_v3d_mmap_bo *map = arg;
99 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
100
101 map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
102
103 drm_shim_bo_put(bo);
104
105 return 0;
106 }
107
108 static int
109 v3d_ioctl_get_param(int fd, unsigned long request, void *arg)
110 {
111 struct drm_v3d_get_param *gp = arg;
112 static const uint32_t v3d42_reg_map[] = {
113 [DRM_V3D_PARAM_V3D_UIFCFG] = 0x00000045,
114 [DRM_V3D_PARAM_V3D_HUB_IDENT1] = 0x000e1124,
115 [DRM_V3D_PARAM_V3D_HUB_IDENT2] = 0x00000100,
116 [DRM_V3D_PARAM_V3D_HUB_IDENT3] = 0x00000e00,
117 [DRM_V3D_PARAM_V3D_CORE0_IDENT0] = 0x04443356,
118 [DRM_V3D_PARAM_V3D_CORE0_IDENT1] = 0x81001422,
119 [DRM_V3D_PARAM_V3D_CORE0_IDENT2] = 0x40078121,
120 };
121
122 switch (gp->param) {
123 case DRM_V3D_PARAM_SUPPORTS_TFU:
124 gp->value = 1;
125 return 0;
126 case DRM_V3D_PARAM_SUPPORTS_CSD:
127 gp->value = 1;
128 return 0;
129 case DRM_V3D_PARAM_SUPPORTS_CACHE_FLUSH:
130 gp->value = 1;
131 return 0;
132 case DRM_V3D_PARAM_SUPPORTS_PERFMON:
133 gp->value = 1;
134 return 0;
135 case DRM_V3D_PARAM_SUPPORTS_MULTISYNC_EXT:
136 gp->value = 1;
137 return 0;
138 default:
139 break;
140 }
141
142 if (gp->param < ARRAY_SIZE(v3d42_reg_map) && v3d42_reg_map[gp->param]) {
143 gp->value = v3d42_reg_map[gp->param];
144 return 0;
145 }
146
147 mesa_loge("Unknown DRM_IOCTL_V3D_GET_PARAM %d", gp->param);
148 return -1;
149 }
150
151 static ioctl_fn_t driver_ioctls[] = {
152 [DRM_V3D_SUBMIT_CL] = v3d_ioctl_noop,
153 [DRM_V3D_SUBMIT_TFU] = v3d_ioctl_noop,
154 [DRM_V3D_WAIT_BO] = v3d_ioctl_noop,
155 [DRM_V3D_CREATE_BO] = v3d_ioctl_create_bo,
156 [DRM_V3D_GET_PARAM] = v3d_ioctl_get_param,
157 [DRM_V3D_GET_BO_OFFSET] = v3d_ioctl_get_bo_offset,
158 [DRM_V3D_MMAP_BO] = v3d_ioctl_mmap_bo,
159 };
160
161 void
162 drm_shim_driver_init(void)
163 {
164 shim_device.bus_type = DRM_BUS_PLATFORM;
165 shim_device.driver_name = "v3d";
166 shim_device.driver_ioctls = driver_ioctls;
167 shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
168
169 drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"
170 "OF_COMPATIBLE_N=1\n"
171 "OF_COMPATIBLE_0=brcm,2711-v3d\n",
172 "/sys/dev/char/%d:%d/device/uevent",
173 DRM_MAJOR, render_node_minor);
174 }