2 * Copyright © 2018 Broadcom
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/v3d_drm.h"
29 #include "drm-shim/drm_shim.h"
36 static struct v3d_bo
*
37 v3d_bo(struct shim_bo
*bo
)
39 return (struct v3d_bo
*)bo
;
46 static struct v3d_device v3d
= {
47 .next_offset
= 0x1000,
51 v3d_ioctl_noop(int fd
, unsigned long request
, void *arg
)
57 v3d_ioctl_create_bo(int fd
, unsigned long request
, void *arg
)
59 struct shim_fd
*shim_fd
= drm_shim_fd_lookup(fd
);
60 struct drm_v3d_create_bo
*create
= arg
;
61 struct v3d_bo
*bo
= calloc(1, sizeof(*bo
));
63 drm_shim_bo_init(&bo
->base
, create
->size
);
65 assert(UINT_MAX
- v3d
.next_offset
> create
->size
);
66 bo
->offset
= v3d
.next_offset
;
67 v3d
.next_offset
+= create
->size
;
69 create
->offset
= bo
->offset
;
70 create
->handle
= drm_shim_bo_get_handle(shim_fd
, &bo
->base
);
72 drm_shim_bo_put(&bo
->base
);
78 v3d_ioctl_get_bo_offset(int fd
, unsigned long request
, void *arg
)
80 struct shim_fd
*shim_fd
= drm_shim_fd_lookup(fd
);
81 struct drm_v3d_get_bo_offset
*args
= arg
;
82 struct shim_bo
*bo
= drm_shim_bo_lookup(shim_fd
, args
->handle
);
84 args
->offset
= v3d_bo(bo
)->offset
;
92 v3d_ioctl_mmap_bo(int fd
, unsigned long request
, void *arg
)
94 struct shim_fd
*shim_fd
= drm_shim_fd_lookup(fd
);
95 struct drm_v3d_mmap_bo
*map
= arg
;
96 struct shim_bo
*bo
= drm_shim_bo_lookup(shim_fd
, map
->handle
);
98 map
->offset
= drm_shim_bo_get_mmap_offset(shim_fd
, bo
);
106 v3d_ioctl_get_param(int fd
, unsigned long request
, void *arg
)
108 struct drm_v3d_get_param
*gp
= arg
;
109 static const uint32_t v3d42_reg_map
[] = {
110 [DRM_V3D_PARAM_V3D_UIFCFG
] = 0x00000045,
111 [DRM_V3D_PARAM_V3D_HUB_IDENT1
] = 0x000e1124,
112 [DRM_V3D_PARAM_V3D_HUB_IDENT2
] = 0x00000100,
113 [DRM_V3D_PARAM_V3D_HUB_IDENT3
] = 0x00000e00,
114 [DRM_V3D_PARAM_V3D_CORE0_IDENT0
] = 0x04443356,
115 [DRM_V3D_PARAM_V3D_CORE0_IDENT1
] = 0x81001422,
116 [DRM_V3D_PARAM_V3D_CORE0_IDENT2
] = 0x40078121,
120 case DRM_V3D_PARAM_SUPPORTS_TFU
:
127 if (gp
->param
< ARRAY_SIZE(v3d42_reg_map
) && v3d42_reg_map
[gp
->param
]) {
128 gp
->value
= v3d42_reg_map
[gp
->param
];
132 fprintf(stderr
, "Unknown DRM_IOCTL_V3D_GET_PARAM %d\n", gp
->param
);
136 static ioctl_fn_t driver_ioctls
[] = {
137 [DRM_V3D_SUBMIT_CL
] = v3d_ioctl_noop
,
138 [DRM_V3D_SUBMIT_TFU
] = v3d_ioctl_noop
,
139 [DRM_V3D_WAIT_BO
] = v3d_ioctl_noop
,
140 [DRM_V3D_CREATE_BO
] = v3d_ioctl_create_bo
,
141 [DRM_V3D_GET_PARAM
] = v3d_ioctl_get_param
,
142 [DRM_V3D_GET_BO_OFFSET
] = v3d_ioctl_get_bo_offset
,
143 [DRM_V3D_MMAP_BO
] = v3d_ioctl_mmap_bo
,
147 drm_shim_driver_init(void)
149 shim_device
.bus_type
= DRM_BUS_PLATFORM
;
150 shim_device
.driver_name
= "v3d";
151 shim_device
.driver_ioctls
= driver_ioctls
;
152 shim_device
.driver_ioctl_count
= ARRAY_SIZE(driver_ioctls
);
154 drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"
155 "OF_COMPATIBLE_N=1\n"
156 "OF_COMPATIBLE_0=brcm,7278-v3d\n",
157 "/sys/dev/char/%d:%d/device/uevent",
158 DRM_MAJOR
, render_node_minor
);