summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2021-01-27 13:32:57 +0100
committerMarge Bot <eric+marge@anholt.net>2021-01-28 16:14:06 +0000
commitf33b95801001376e10f2d1fd0433046defb06af4 (patch)
tree0407d6d5fb0525566dac1fa66c9f4415d252f75a
parente25a3e21f83390342a1de5f13d41caa0ea076dfa (diff)
vc4: add drm-shim
Is enought to run shader-db. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8736>
-rw-r--r--src/broadcom/drm-shim/README.md10
-rw-r--r--src/broadcom/drm-shim/meson.build9
-rw-r--r--src/broadcom/drm-shim/vc4_noop.c123
3 files changed, 142 insertions, 0 deletions
diff --git a/src/broadcom/drm-shim/README.md b/src/broadcom/drm-shim/README.md
index dde21c1b838..16cbff75825 100644
--- a/src/broadcom/drm-shim/README.md
+++ b/src/broadcom/drm-shim/README.md
@@ -15,3 +15,13 @@ The submit ioctl is stubbed out to not execute anything.
Export `MESA_LOADER_DRIVER_OVERRIDE=v3d
LD_PRELOAD=$prefix/lib/libv3d_noop_drm_shim.so`. This will be a V3D
4.2 device.
+
+### vc4_noop backend
+
+This implements the minimum of vc4 in order to make shader-db work.
+The submit ioctl is stubbed out to not execute anything.
+
+Export `MESA_LOADER_DRIVER_OVERRIDE=vc4
+LD_PRELOAD=$prefix/lib/libvc4_noop_drm_shim.so`. This will be a VC4
+2.1 device.
+
diff --git a/src/broadcom/drm-shim/meson.build b/src/broadcom/drm-shim/meson.build
index cbad07067c1..b44b6c15d18 100644
--- a/src/broadcom/drm-shim/meson.build
+++ b/src/broadcom/drm-shim/meson.build
@@ -18,6 +18,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+libvc4_noop_drm_shim = shared_library(
+ ['vc4_noop_drm_shim'],
+ 'vc4_noop.c',
+ include_directories: [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
+ dependencies: dep_drm_shim,
+ gnu_symbol_visibility : 'hidden',
+ install : true,
+)
+
libv3d_noop_drm_shim = shared_library(
['v3d_noop_drm_shim'],
'v3d_noop.c',
diff --git a/src/broadcom/drm-shim/vc4_noop.c b/src/broadcom/drm-shim/vc4_noop.c
new file mode 100644
index 00000000000..3f85158e6df
--- /dev/null
+++ b/src/broadcom/drm-shim/vc4_noop.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2021 Etnaviv Project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include "drm-uapi/vc4_drm.h"
+#include "drm-shim/drm_shim.h"
+
+bool drm_shim_driver_prefers_first_render_node = true;
+
+static int
+vc4_ioctl_noop(int fd, unsigned long request, void *arg)
+{
+ return 0;
+}
+
+static int
+vc4_ioctl_create_bo(int fd, unsigned long request, void *arg)
+{
+ struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
+ struct drm_vc4_create_bo *create = arg;
+ struct shim_bo *bo = calloc(1, sizeof(*bo));
+
+ drm_shim_bo_init(bo, create->size);
+ create->handle = drm_shim_bo_get_handle(shim_fd, bo);
+ drm_shim_bo_put(bo);
+
+ return 0;
+}
+
+static int
+vc4_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
+{
+ struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
+ struct drm_vc4_mmap_bo *map = arg;
+ struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
+
+ map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
+
+ drm_shim_bo_put(bo);
+
+ return 0;
+}
+
+static int
+vc4_ioctl_get_param(int fd, unsigned long request, void *arg)
+{
+ struct drm_vc4_get_param *gp = arg;
+ static const uint32_t param_map[] = {
+ [DRM_VC4_PARAM_V3D_IDENT0] = 0x2000000,
+ [DRM_VC4_PARAM_V3D_IDENT1] = 0x0000001,
+ };
+
+ switch (gp->param) {
+ case DRM_VC4_PARAM_SUPPORTS_BRANCHES:
+ case DRM_VC4_PARAM_SUPPORTS_ETC1:
+ case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:
+ case DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER:
+ gp->value = 1;
+ return 0;
+
+ case DRM_VC4_PARAM_SUPPORTS_MADVISE:
+ case DRM_VC4_PARAM_SUPPORTS_PERFMON:
+ gp->value = 0;
+ return 0;
+
+ default:
+ break;
+ }
+
+ if (gp->param < ARRAY_SIZE(param_map) && param_map[gp->param]) {
+ gp->value = param_map[gp->param];
+ return 0;
+ }
+
+ fprintf(stderr, "Unknown DRM_IOCTL_VC4_GET_PARAM %d\n", gp->param);
+ return -1;
+}
+
+static ioctl_fn_t driver_ioctls[] = {
+ [DRM_VC4_CREATE_BO] = vc4_ioctl_create_bo,
+ [DRM_VC4_MMAP_BO] = vc4_ioctl_mmap_bo,
+ [DRM_VC4_GET_PARAM] = vc4_ioctl_get_param,
+ [DRM_VC4_GET_TILING] = vc4_ioctl_noop,
+ [DRM_VC4_LABEL_BO] = vc4_ioctl_noop,
+};
+
+void
+drm_shim_driver_init(void)
+{
+ shim_device.bus_type = DRM_BUS_PLATFORM;
+ shim_device.driver_name = "vc4";
+ shim_device.driver_ioctls = driver_ioctls;
+ shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
+
+ drm_shim_override_file("OF_FULLNAME=/rdb/vc4\n"
+ "OF_COMPATIBLE_N=1\n"
+ "OF_COMPATIBLE_0=brcm,7278-vc4\n",
+ "/sys/dev/char/%d:%d/device/uevent",
+ DRM_MAJOR, render_node_minor);
+}