xref: /aosp_15_r20/external/mesa3d/src/broadcom/drm-shim/vc4_noop.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 
31 bool drm_shim_driver_prefers_first_render_node = true;
32 
33 static int
vc4_ioctl_noop(int fd,unsigned long request,void * arg)34 vc4_ioctl_noop(int fd, unsigned long request, void *arg)
35 {
36         return 0;
37 }
38 
39 static int
vc4_ioctl_create_bo(int fd,unsigned long request,void * arg)40 vc4_ioctl_create_bo(int fd, unsigned long request, void *arg)
41 {
42         struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
43         struct drm_vc4_create_bo *create = arg;
44         struct shim_bo *bo = calloc(1, sizeof(*bo));
45 
46         drm_shim_bo_init(bo, create->size);
47         create->handle = drm_shim_bo_get_handle(shim_fd, bo);
48         drm_shim_bo_put(bo);
49 
50         return 0;
51 }
52 
53 static int
vc4_ioctl_create_shader_bo(int fd,unsigned long request,void * arg)54 vc4_ioctl_create_shader_bo(int fd, unsigned long request, void *arg)
55 {
56         struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
57         struct drm_vc4_create_shader_bo *create = arg;
58         struct shim_bo *bo = calloc(1, sizeof(*bo));
59 
60         drm_shim_bo_init(bo, create->size);
61         create->handle = drm_shim_bo_get_handle(shim_fd, bo);
62         drm_shim_bo_put(bo);
63 
64         return 0;
65 }
66 
67 static int
vc4_ioctl_mmap_bo(int fd,unsigned long request,void * arg)68 vc4_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
69 {
70         struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
71         struct drm_vc4_mmap_bo *map = arg;
72         struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
73 
74         map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
75 
76         drm_shim_bo_put(bo);
77 
78         return 0;
79 }
80 
81 static int
vc4_ioctl_get_param(int fd,unsigned long request,void * arg)82 vc4_ioctl_get_param(int fd, unsigned long request, void *arg)
83 {
84         struct drm_vc4_get_param *gp = arg;
85         static const uint32_t param_map[] = {
86                 [DRM_VC4_PARAM_V3D_IDENT0] = 0x2000000,
87                 [DRM_VC4_PARAM_V3D_IDENT1] = 0x0000001,
88         };
89 
90         switch (gp->param) {
91         case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
92         case DRM_VC4_PARAM_SUPPORTS_ETC1:
93         case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
94         case DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER:
95                 gp->value = 1;
96                 return 0;
97 
98         case DRM_VC4_PARAM_SUPPORTS_MADVISE:
99         case DRM_VC4_PARAM_SUPPORTS_PERFMON:
100                 gp->value = 0;
101                 return 0;
102 
103         default:
104                 break;
105         }
106 
107         if (gp->param < ARRAY_SIZE(param_map) && param_map[gp->param]) {
108                 gp->value = param_map[gp->param];
109                 return 0;
110         }
111 
112         fprintf(stderr, "Unknown DRM_IOCTL_VC4_GET_PARAM %d\n", gp->param);
113         return -1;
114 }
115 
116 static ioctl_fn_t driver_ioctls[] = {
117         [DRM_VC4_CREATE_BO] = vc4_ioctl_create_bo,
118         [DRM_VC4_CREATE_SHADER_BO] = vc4_ioctl_create_shader_bo,
119         [DRM_VC4_MMAP_BO] = vc4_ioctl_mmap_bo,
120         [DRM_VC4_GET_PARAM] = vc4_ioctl_get_param,
121         [DRM_VC4_GET_TILING] = vc4_ioctl_noop,
122         [DRM_VC4_LABEL_BO] = vc4_ioctl_noop,
123 };
124 
125 void
drm_shim_driver_init(void)126 drm_shim_driver_init(void)
127 {
128         shim_device.bus_type = DRM_BUS_PLATFORM;
129         shim_device.driver_name = "vc4";
130         shim_device.driver_ioctls = driver_ioctls;
131         shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
132 
133         drm_shim_override_file("OF_FULLNAME=/rdb/vc4\n"
134                                "OF_COMPATIBLE_N=1\n"
135                                "OF_COMPATIBLE_0=brcm,7278-vc4\n",
136                                "/sys/dev/char/%d:%d/device/uevent",
137                                DRM_MAJOR, render_node_minor);
138 }
139