Skip to content

Instantly share code, notes, and snippets.

@rockorequin
Created March 3, 2021 02:57
Show Gist options
  • Save rockorequin/a5dcbcad9289c4754b4312faf35dbf4f to your computer and use it in GitHub Desktop.
Save rockorequin/a5dcbcad9289c4754b4312faf35dbf4f to your computer and use it in GitHub Desktop.
remove CONFIG_DRM_LEGACY from evdi patch for kernel 5.11
diff --git a/module/Makefile b/module/Makefile
index 8212bde..e36770e 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 64952a6..d364efa 100644
--- a/module/evdi_drv.c
+++ b/module/evdi_drv.c
@@ -48,7 +48,7 @@ struct drm_ioctl_desc evdi_painter_ioctls[] = {
DRM_UNLOCKED),
};
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
static const struct vm_operations_struct evdi_gem_vm_ops = {
.fault = evdi_gem_fault,
.open = drm_gem_vm_open,
@@ -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)
@@ -89,23 +92,24 @@ static struct drm_driver driver = {
| DRIVER_ATOMIC,
#endif
.unload = evdi_driver_unload,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
.preclose = evdi_driver_preclose,
#endif
.postclose = evdi_driver_postclose,
/* gem hooks */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 9, 0)
+#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,
-#elsif LINUX_VERSION_CODE <= KERNEL_VERSION(5, 11, 0)
+#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 LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
- // In 5.11+, this is set in the object instance
+
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
+ // 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
@@ -122,15 +126,18 @@ static struct drm_driver driver = {
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
.gem_prime_import = drm_gem_prime_import,
.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 11, 0)
- // In kernel 5.11, these have been moved to the object instance
+#if KERNEL_VERSION(5, 11, 0) > LINUX_VERSION_CODE
+ // 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 8a7f2ca..f8e7bb8 100644
--- a/module/evdi_gem.c
+++ b/module/evdi_gem.c
@@ -17,10 +17,11 @@
#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);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE
static const struct vm_operations_struct evdi_gem_vm_ops = {
.fault = evdi_gem_fault,
.open = drm_gem_vm_open,
@@ -52,7 +53,7 @@ struct evdi_gem_object *evdi_gem_alloc_object(struct drm_device *dev,
size_t size)
{
struct evdi_gem_object *obj;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE
struct drm_gem_object_funcs *funcs;
#endif
@@ -65,7 +66,7 @@ struct evdi_gem_object *evdi_gem_alloc_object(struct drm_device *dev,
return NULL;
}
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE
funcs = kzalloc(sizeof(struct drm_gem_object_funcs), GFP_KERNEL);
if (funcs == NULL) {
kfree(obj);
@@ -277,9 +278,12 @@ void evdi_gem_free_object(struct drm_gem_object *gem_obj)
#endif
obj->resv = NULL;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
+#if KERNEL_VERSION(5, 11, 0) < LINUX_VERSION_CODE
// We allocated this in evdi_gem_alloc_object
- kfree(obj->base.funcs);
+ if (obj->base.funcs != NULL) {
+ kfree(obj->base.funcs);
+ obj->base.funcs = NULL;
+ }
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment