summarylogtreecommitdiffstats
path: root/kernel-5.4.patch
blob: be73f9a6dcd3e954ccaf3806f9af362ed030bda9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From f90c388c755a6bd9b72cb51c712a0ae686e0b377 Mon Sep 17 00:00:00 2001
From: Alberto Milone <alberto.milone@canonical.com>
Date: Wed, 27 Nov 2019 13:01:18 +0100
Subject: [PATCH 1/1] Add support for Linux 5.4
---
 conftest.sh              | 46 ++++++++++++++++++++++++++++++++++++++++
 nv-drm.c                 |  9 +++++---
 nvidia-modules-common.mk |  2 +-
 3 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/conftest.sh b/conftest.sh
index fb0bf60..babbb50 100755
--- a/conftest.sh
+++ b/conftest.sh
@@ -265,6 +265,23 @@ build_cflags() {
     if [ -n "$BUILD_PARAMS" ]; then
         CFLAGS="$CFLAGS -D$BUILD_PARAMS"
     fi
+
+    # Check if gcc supports asm goto and set CC_HAVE_ASM_GOTO if it does.
+    # Older kernels perform this check and set this flag in Kbuild, and since
+    # conftest.sh runs outside of Kbuild it ends up building without this flag.
+    # Starting with commit e9666d10a5677a494260d60d1fa0b73cc7646eb3 this test
+    # is done within Kconfig, and the preprocessor flag is no longer needed.
+
+    GCC_GOTO_SH="$SOURCES/build/gcc-goto.sh"
+
+    if [ -f "$GCC_GOTO_SH" ]; then
+        # Newer versions of gcc-goto.sh don't print anything on success, but
+        # this is okay, since it's no longer necessary to set CC_HAVE_ASM_GOTO
+        # based on the output of those versions of gcc-goto.sh.
+        if [ `/bin/sh "$GCC_GOTO_SH" "$CC"` = "y" ]; then
+            CFLAGS="$CFLAGS -DCC_HAVE_ASM_GOTO"
+        fi
+    fi
 }
 
 CONFTEST_PREAMBLE="#include \"conftest.h\"
@@ -1521,6 +1538,35 @@ compile_test() {
             compile_check_conftest "$CODE" "NV_DRM_AVAILABLE" "" "generic"
         ;;
 
+        drm_driver_prime_flag_present)
+            #
+            # Determine whether driver feature flag DRIVER_PRIME is present.
+            #
+            # The DRIVER_PRIME flag was added by commit 3248877ea179 (drm:
+            # base prime/dma-buf support (v5)) in v3.4 (2011-11-25) and is
+            # removed by commit 0424fdaf883a (drm/prime: Actually remove
+            # DRIVER_PRIME everywhere) on 2019-06-17.
+            #
+            # DRIVER_PRIME definition moved from drmP.h to drm_drv.h by
+            # commit 85e634bce01a (drm: Extract drm_drv.h) in v4.10
+            # (2016-11-14).
+            #
+            # DRIVER_PRIME define is changed to enum value by commit
+            # 0e2a933b02c9 (drm: Switch DRIVER_ flags to an enum) in v5.1
+            # (2019-01-29).
+            #
+            CODE="
+            #include <drm/drmP.h>
+            #if defined(NV_DRM_DRM_DRV_H_PRESENT)
+            #include <drm/drm_drv.h>
+            #endif
+            unsigned int drm_driver_prime_flag_present_conftest(void) {
+                return DRIVER_PRIME;
+            }"
+
+            compile_check_conftest "$CODE" "NV_DRM_DRIVER_PRIME_FLAG_PRESENT" "" "types"
+        ;;
+
         proc_create_data)
             #
             # Determine if the proc_create_data() function is present.
diff --git a/nv-drm.c b/nv-drm.c
index 76719bb..12f7029 100644
--- a/nv-drm.c
+++ b/nv-drm.c
@@ -156,11 +156,14 @@ static const struct file_operations nv_drm_fops = {
 };
 
 static struct drm_driver nv_drm_driver = {
+    .driver_features =
+#if defined(NV_DRM_DRIVER_PRIME_FLAG_PRESENT)
+                       DRIVER_PRIME |
+#endif
 #if defined(DRIVER_LEGACY) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
-    .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
-#else
-    .driver_features = DRIVER_GEM | DRIVER_PRIME,
+                       DRIVER_LEGACY |
 #endif
+                       DRIVER_GEM,
     .load = nv_drm_load,
     .unload = nv_drm_unload,
     .fops = &nv_drm_fops,
diff --git a/nvidia-modules-common.mk b/nvidia-modules-common.mk
index 8ac7058..7418005 100644
--- a/nvidia-modules-common.mk
+++ b/nvidia-modules-common.mk
@@ -180,7 +180,7 @@ ifndef NV_VERBOSE
 endif
 
 KBUILD_PARAMS += KBUILD_VERBOSE=$(NV_VERBOSE)
-KBUILD_PARAMS += -C $(KERNEL_SOURCES) SUBDIRS=$(PWD)
+KBUILD_PARAMS += -C $(KERNEL_SOURCES) M=$(PWD)
 KBUILD_PARAMS += ARCH=$(ARCH)
 
 #
-- 
2.20.1