diff options
Diffstat (limited to 'lib/mesa/src/drm-shim')
-rw-r--r-- | lib/mesa/src/drm-shim/device.c | 13 | ||||
-rw-r--r-- | lib/mesa/src/drm-shim/drm_shim.c | 54 | ||||
-rw-r--r-- | lib/mesa/src/drm-shim/drm_shim.h | 4 | ||||
-rw-r--r-- | lib/mesa/src/drm-shim/meson.build | 7 |
4 files changed, 69 insertions, 9 deletions
diff --git a/lib/mesa/src/drm-shim/device.c b/lib/mesa/src/drm-shim/device.c index 8020c2ae5..f3f0e5334 100644 --- a/lib/mesa/src/drm-shim/device.c +++ b/lib/mesa/src/drm-shim/device.c @@ -190,6 +190,16 @@ drm_shim_ioctl_gem_close(int fd, unsigned long request, void *arg) } static int +drm_shim_ioctl_syncobj_create(int fd, unsigned long request, void *arg) +{ + struct drm_syncobj_create *create = arg; + + create->handle = 1; /* 0 is invalid */ + + return 0; +} + +static int drm_shim_ioctl_stub(int fd, unsigned long request, void *arg) { return 0; @@ -199,10 +209,11 @@ ioctl_fn_t core_ioctls[] = { [_IOC_NR(DRM_IOCTL_VERSION)] = drm_shim_ioctl_version, [_IOC_NR(DRM_IOCTL_GET_CAP)] = drm_shim_ioctl_get_cap, [_IOC_NR(DRM_IOCTL_GEM_CLOSE)] = drm_shim_ioctl_gem_close, - [_IOC_NR(DRM_IOCTL_SYNCOBJ_CREATE)] = drm_shim_ioctl_stub, + [_IOC_NR(DRM_IOCTL_SYNCOBJ_CREATE)] = drm_shim_ioctl_syncobj_create, [_IOC_NR(DRM_IOCTL_SYNCOBJ_DESTROY)] = drm_shim_ioctl_stub, [_IOC_NR(DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD)] = drm_shim_ioctl_stub, [_IOC_NR(DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE)] = drm_shim_ioctl_stub, + [_IOC_NR(DRM_IOCTL_SYNCOBJ_WAIT)] = drm_shim_ioctl_stub, }; /** diff --git a/lib/mesa/src/drm-shim/drm_shim.c b/lib/mesa/src/drm-shim/drm_shim.c index 7c7d5f0f0..61a1cb2ae 100644 --- a/lib/mesa/src/drm-shim/drm_shim.c +++ b/lib/mesa/src/drm-shim/drm_shim.c @@ -75,6 +75,7 @@ REAL_FUNCTION_POINTER(opendir); REAL_FUNCTION_POINTER(readdir); REAL_FUNCTION_POINTER(readdir64); REAL_FUNCTION_POINTER(readlink); +REAL_FUNCTION_POINTER(realpath); REAL_FUNCTION_POINTER(__xstat); REAL_FUNCTION_POINTER(__xstat64); REAL_FUNCTION_POINTER(__fxstat); @@ -84,6 +85,8 @@ REAL_FUNCTION_POINTER(__fxstat64); static char *render_node_path; /* renderD* */ static char *render_node_dirent_name; +/* /sys/dev/char/major:minor/device */ +static char *device_path; /* /sys/dev/char/major:minor/device/subsystem */ static char *subsystem_path; int render_node_minor = -1; @@ -94,9 +97,11 @@ struct file_override { }; static struct file_override file_overrides[10]; static int file_overrides_count; +extern bool drm_shim_driver_prefers_first_render_node; -/* Come up with a filename for a render node that doesn't actually exist on - * the system. +/* Pick the minor and filename for our shimmed render node. This can be + * either a new one that didn't exist on the system, or if the driver wants, + * it can replace the first render node. */ static void get_dri_render_node_minor(void) @@ -107,7 +112,8 @@ get_dri_render_node_minor(void) asprintf(&render_node_path, "/dev/dri/%s", render_node_dirent_name); struct stat st; - if (stat(render_node_path, &st) == -1) { + if (drm_shim_driver_prefers_first_render_node || + stat(render_node_path, &st) == -1) { render_node_minor = minor; return; @@ -187,6 +193,7 @@ init_shim(void) GET_FUNCTION_POINTER(readdir); GET_FUNCTION_POINTER(readdir64); GET_FUNCTION_POINTER(readlink); + GET_FUNCTION_POINTER(realpath); GET_FUNCTION_POINTER(__xstat); GET_FUNCTION_POINTER(__xstat64); GET_FUNCTION_POINTER(__fxstat); @@ -199,6 +206,10 @@ init_shim(void) render_node_path); } + asprintf(&device_path, + "/sys/dev/char/%d:%d/device", + DRM_MAJOR, render_node_minor); + asprintf(&subsystem_path, "/sys/dev/char/%d:%d/device/subsystem", DRM_MAJOR, render_node_minor); @@ -219,6 +230,7 @@ PUBLIC FILE *fopen(const char *path, const char *mode) pipe(fds); write(fds[1], file_overrides[i].contents, strlen(file_overrides[i].contents)); + close(fds[1]); return fdopen(fds[0], "r"); } } @@ -451,12 +463,44 @@ readlink(const char *path, char *buf, size_t size) if (strcmp(path, subsystem_path) != 0) return real_readlink(path, buf, size); - strncpy(buf, "/platform", size); - buf[size - 1] = 0; + + static const struct { + const char *name; + int bus_type; + } bus_types[] = { + { "/pci", DRM_BUS_PCI }, + { "/usb", DRM_BUS_USB }, + { "/platform", DRM_BUS_PLATFORM }, + { "/spi", DRM_BUS_PLATFORM }, + { "/host1x", DRM_BUS_HOST1X }, + }; + + for (uint32_t i = 0; i < ARRAY_SIZE(bus_types); i++) { + if (bus_types[i].bus_type != shim_device.bus_type) + continue; + + strncpy(buf, bus_types[i].name, size); + buf[size - 1] = 0; + break; + } return strlen(buf) + 1; } +/* Handles libdrm's realpath to figure out what kind of device we have. */ +PUBLIC char * +realpath(const char *path, char *resolved_path) +{ + init_shim(); + + if (strcmp(path, device_path) != 0) + return real_realpath(path, resolved_path); + + strcpy(resolved_path, path); + + return resolved_path; +} + /* Main entrypoint to DRM drivers: the ioctl syscall. We send all ioctls on * our DRM fd to drm_shim_ioctl(). */ diff --git a/lib/mesa/src/drm-shim/drm_shim.h b/lib/mesa/src/drm-shim/drm_shim.h index 2cd053f6d..4a151d49b 100644 --- a/lib/mesa/src/drm-shim/drm_shim.h +++ b/lib/mesa/src/drm-shim/drm_shim.h @@ -24,6 +24,8 @@ #include "util/macros.h" #include "util/hash_table.h" +#include <xf86drm.h> + #ifdef __linux__ #define DRM_MAJOR 226 #endif @@ -44,6 +46,7 @@ struct shim_device { /* Returned by drmGetVersion(). */ const char *driver_name; int version_major, version_minor, version_patchlevel; + int bus_type; }; extern struct shim_device shim_device; @@ -82,3 +85,4 @@ uint64_t drm_shim_bo_get_mmap_offset(struct shim_fd *shim_fd, /* driver-specific hooks. */ void drm_shim_driver_init(void); +extern bool drm_shim_driver_prefers_new_render_node; diff --git a/lib/mesa/src/drm-shim/meson.build b/lib/mesa/src/drm-shim/meson.build index ab05f9af0..197c82539 100644 --- a/lib/mesa/src/drm-shim/meson.build +++ b/lib/mesa/src/drm-shim/meson.build @@ -24,10 +24,11 @@ drm_shim = static_library( 'device.c', 'drm_shim.c', ], - include_directories: [inc_common], - dependencies: [idep_mesautil, dep_dl], + include_directories: [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux], + dependencies: [dep_libdrm, idep_mesautil, dep_dl], c_args : [c_vis_args, '-std=gnu99'], ) dep_drm_shim = declare_dependency( - link_with: drm_shim + link_with: drm_shim, + dependencies: dep_libdrm, ) |