2
* Copyright (c) 2021 Etnaviv Project
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:
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
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.
27
#include <sys/ioctl.h>
28
#include "drm-uapi/vc4_drm.h"
29
#include "drm-shim/drm_shim.h"
31
bool drm_shim_driver_prefers_first_render_node = true;
34
vc4_ioctl_noop(int fd, unsigned long request, void *arg)
40
vc4_ioctl_create_bo(int fd, unsigned long request, void *arg)
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));
46
drm_shim_bo_init(bo, create->size);
47
create->handle = drm_shim_bo_get_handle(shim_fd, bo);
54
vc4_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
56
struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
57
struct drm_vc4_mmap_bo *map = arg;
58
struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
60
map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
68
vc4_ioctl_get_param(int fd, unsigned long request, void *arg)
70
struct drm_vc4_get_param *gp = arg;
71
static const uint32_t param_map[] = {
72
[DRM_VC4_PARAM_V3D_IDENT0] = 0x2000000,
73
[DRM_VC4_PARAM_V3D_IDENT1] = 0x0000001,
77
case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
78
case DRM_VC4_PARAM_SUPPORTS_ETC1:
79
case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
80
case DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER:
84
case DRM_VC4_PARAM_SUPPORTS_MADVISE:
85
case DRM_VC4_PARAM_SUPPORTS_PERFMON:
93
if (gp->param < ARRAY_SIZE(param_map) && param_map[gp->param]) {
94
gp->value = param_map[gp->param];
98
fprintf(stderr, "Unknown DRM_IOCTL_VC4_GET_PARAM %d\n", gp->param);
102
static ioctl_fn_t driver_ioctls[] = {
103
[DRM_VC4_CREATE_BO] = vc4_ioctl_create_bo,
104
[DRM_VC4_MMAP_BO] = vc4_ioctl_mmap_bo,
105
[DRM_VC4_GET_PARAM] = vc4_ioctl_get_param,
106
[DRM_VC4_GET_TILING] = vc4_ioctl_noop,
107
[DRM_VC4_LABEL_BO] = vc4_ioctl_noop,
111
drm_shim_driver_init(void)
113
shim_device.bus_type = DRM_BUS_PLATFORM;
114
shim_device.driver_name = "vc4";
115
shim_device.driver_ioctls = driver_ioctls;
116
shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
118
drm_shim_override_file("OF_FULLNAME=/rdb/vc4\n"
119
"OF_COMPATIBLE_N=1\n"
120
"OF_COMPATIBLE_0=brcm,7278-vc4\n",
121
"/sys/dev/char/%d:%d/device/uevent",
122
DRM_MAJOR, render_node_minor);