Skip to content

Instantly share code, notes, and snippets.

@rockorequin
Created March 23, 2021 04:24
Show Gist options
  • Save rockorequin/9f16d3dd2a3278c3d19d7871a72a4092 to your computer and use it in GitHub Desktop.
Save rockorequin/9f16d3dd2a3278c3d19d7871a72a4092 to your computer and use it in GitHub Desktop.
Patch to get evdi rockorequin-sickcodes-microhobby-patch-1.7.x branch working under Linux 5.11 (in Wayland)
diff --git a/module/Makefile b/module/Makefile
index 8212bde..dc1b69b 100644
--- a/module/Makefile
+++ b/module/Makefile
@@ -17,7 +17,7 @@ ifneq ($(DKMS_BUILD),)
KERN_DIR := /lib/modules/$(KERNELRELEASE)/build
-ccflags-y := -Iinclude/drm $(EL8FLAG) -DCONFIG_DRM_LEGACY
+ccflags-y := -Iinclude/drm $(EL8FLAG)
evdi-y := evdi_drv.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_main.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o
evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
obj-m := evdi.o
@@ -41,7 +41,7 @@ ifneq ($(KERNELRELEASE),)
# Note: this can be removed once it is in kernel tree and Kconfig is properly used
CONFIG_DRM_EVDI := m
LINUXINCLUDE := $(subst -I,-isystem,$(LINUXINCLUDE))
-ccflags-y := -isystem include/drm $(CFLAGS) $(EL8FLAG) -DCONFIG_DRM_LEGACY
+ccflags-y := -isystem include/drm $(CFLAGS) $(EL8FLAG)
evdi-y := evdi_drv.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_main.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o
evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
obj-$(CONFIG_DRM_EVDI) := evdi.o
diff --git a/module/evdi_drv.c b/module/evdi_drv.c
index 17d7938..d364efa 100644
--- a/module/evdi_drv.c
+++ b/module/evdi_drv.c
@@ -70,6 +70,8 @@ static const struct file_operations evdi_driver_fops = {
.llseek = noop_llseek,
};
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
+// We only need the enable/disable vblank functions here in 5.10 and below
static int evdi_enable_vblank(__always_unused struct drm_device *dev,
__always_unused unsigned int pipe)
{
@@ -80,6 +82,7 @@ static void evdi_disable_vblank(__always_unused struct drm_device *dev,
__always_unused unsigned int pipe)
{
}
+#endif
static struct drm_driver driver = {
#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE || defined(EL8)
@@ -96,16 +99,17 @@ static struct drm_driver driver = {
.postclose = evdi_driver_postclose,
/* gem hooks */
-#if KERNEL_VERSION(5, 9, 0) > LINUX_VERSION_CODE
+#if KERNEL_VERSION(5, 9, 0) >= LINUX_VERSION_CODE
// In 5.9 and below we have gem_free_object
.gem_free_object = evdi_gem_free_object,
-#elif KERNEL_VERSION(5, 10, 0) >= LINUX_VERSION_CODE
+#elif KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
// In 5.9 and 5.10 this is called gem_free_object_unlocked
.gem_free_object_unlocked = evdi_gem_free_object,
// Note that gem_free_object_unlocked no longer exists in 5.11 - it needs to be added to the gem object instead
#endif
+
#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
- // In 5.11+, this is set in the object instance
+ // This is for 5.10 and below - in 5.11+, this is set in the object instance
.gem_vm_ops = &evdi_gem_vm_ops,
#endif
@@ -123,14 +127,17 @@ static struct drm_driver driver = {
.gem_prime_import = drm_gem_prime_import,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
- // In kernel 5.11, these have been moved to the object instance
+ // This is for 5.10 and below, because they have been moved to the object instance
.gem_prime_export = drm_gem_prime_export,
.gem_prime_get_sg_table = evdi_prime_get_sg_table,
#endif
.gem_prime_import_sg_table = evdi_prime_import_sg_table,
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
+ // These hooks are only in 5.10 and below
.enable_vblank = evdi_enable_vblank,
.disable_vblank = evdi_disable_vblank,
+#endif
.name = DRIVER_NAME,
.desc = DRIVER_DESC,
diff --git a/module/evdi_gem.c b/module/evdi_gem.c
index ffb1345..de5e35e 100644
--- a/module/evdi_gem.c
+++ b/module/evdi_gem.c
@@ -17,6 +17,7 @@
#include <linux/shmem_fs.h>
#include <linux/dma-buf.h>
#include <drm/drm_cache.h>
+#include <drm/drm_gem.h>
void evdi_gem_free_object(struct drm_gem_object *gem_obj);
@@ -73,7 +74,7 @@ struct evdi_gem_object *evdi_gem_alloc_object(struct drm_device *dev,
}
funcs->free = evdi_gem_free_object;
funcs->vm_ops = &evdi_gem_vm_ops;
- // This is just setting the default drm_gem_prime_export kernel function, so wouldn't NULL also work?
+ // This just sets the default drm_gem_prime_export kernel function, so wouldn't NULL also work?
funcs->export = drm_gem_prime_export;
funcs->get_sg_table = evdi_prime_get_sg_table;
@@ -219,10 +220,15 @@ int evdi_gem_vmap(struct evdi_gem_object *obj)
if (obj->base.import_attach) {
#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
+ // In Linux 5.10 and below, dma_buf_vmap returns the mapping directly or NULL for error
obj->vmapping = dma_buf_vmap(obj->base.import_attach->dmabuf);
#else
- dma_buf_vmap(obj->base.import_attach->dmabuf, &map);
- obj->vmapping = map.vaddr;
+ // In Linux 5.11+, dma_buf_vmap returns zero for success or a negative code for error
+ if (dma_buf_vmap(obj->base.import_attach->dmabuf, &map) == 0) {
+ obj->vmapping = map.vaddr;
+ } else {
+ obj->vmapping = NULL;
+ }
#endif
if (!obj->vmapping)
return -ENOMEM;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment