fix build with kernel 5.10
[packages/xorg-driver-video-nvidia-legacy-390xx.git] / kernel-5.10.patch
1 --- NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/common/inc/nv-linux.h.orig   2020-12-22 11:58:13.756901968 +0100
2 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/common/inc/nv-linux.h        2020-12-22 12:34:56.069935099 +0100
3 @@ -1304,7 +1304,8 @@
4   * device.  So if SWIOTLB is enabled, we should avoid making
5   * mapping calls.
6   */
7 -static inline NvBool nv_dma_maps_swiotlb(struct pci_dev *dev)
8 +static inline NvBool
9 +nv_dma_maps_swiotlb(struct pci_dev *dev)
10  {
11      NvBool swiotlb_in_use = NV_FALSE;
12  #if defined(CONFIG_SWIOTLB)
13 @@ -1316,7 +1317,6 @@
14       * get_dma_ops() interface.
15       */
16      #if defined(NV_GET_DMA_OPS_PRESENT)
17 -      #if defined(NV_DMA_MAP_OPS_PRESENT) || defined(NV_SWIOTLB_DMA_OPS_PRESENT)
18      /*
19       * The __attribute__ ((unused)) is necessary because in at least one
20       * case, *none* of the preprocessor branches below are taken, and
21 @@ -1324,14 +1324,11 @@
22       * happen with the (NV_IS_EXPORT_SYMBOL_PRESENT_swiotlb_map_sg_attrs == 1)
23       * case.
24       */
25 -    const struct dma_map_ops *ops __attribute__ ((unused)) = get_dma_ops(&dev->dev);
26 -      #else
27 -    const struct dma_mapping_ops *ops __attribute__ ((unused)) = get_dma_ops(&dev->dev);
28 -      #endif
29 +    const struct dma_map_ops *ops __attribute__ ((unused)) = get_dma_ops(&dev->dev);
30      #else
31      const struct dma_mapping_ops *ops __attribute__ ((unused)) = dma_ops;
32      #endif
33 -    #if defined(NV_DMA_MAP_OPS_PRESENT) || defined(NV_SWIOTLB_DMA_OPS_PRESENT)
34 +
35      /*
36       * The switch from dma_mapping_ops -> dma_map_ops coincided with the
37       * switch from swiotlb_map_sg -> swiotlb_map_sg_attrs.
38 @@ -1352,9 +1349,9 @@
39         * NV_IS_EXPORT_SYMBOL_PRESENT_swiotlb_dma_ops == 0) does
40         * nothing, and ends up dropping us out to the last line of this function,
41         * effectively returning false. The nearly-human-readable version of that
42 -       * case is "Either struct dma_map_ops or struct swiotlb_dma_ops is present
43 -       * (NV_DMA_MAP_OPS_PRESENT or NV_SWIOTLB_DMA_OPS_PRESENT is defined) but
44 -       * neither swiotlb_map_sg_attrs nor swiotlb_dma_ops is present".
45 +       * case is "struct swiotlb_dma_ops is present (NV_SWIOTLB_DMA_OPS_PRESENT
46 +       * is defined) but neither swiotlb_map_sg_attrs nor swiotlb_dma_ops is
47 +       * present".
48         *
49         * That can happen on kernels that fall within below range:
50         *
51 @@ -1378,17 +1375,6 @@
52         * we just return NV_FALSE and in nv_compute_gfp_mask() we check for
53         * whether swiotlb could possibly be used (outside of swiotlb=force).
54         */
55 -    #else
56 -    swiotlb_in_use = (ops->map_sg == swiotlb_map_sg);
57 -    #endif
58 -  #elif defined(NVCPU_X86_64)
59 -    /*
60 -     * Fallback for old 2.6 kernels - if the DMA operations infrastructure
61 -     * isn't in place, use the swiotlb flag. Before dma_ops was added, this
62 -     * flag used to be exported. It still exists in modern kernels but is no
63 -     * longer exported.
64 -     */
65 -    swiotlb_in_use = (swiotlb == 1);
66    #endif
67  #endif
68  
69 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/common/inc/nv-linux.h NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/common/inc/nv-linux.h
70 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/common/inc/nv-linux.h   2020-12-22 12:36:18.220333393 +0100
71 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/common/inc/nv-linux.h        2020-12-22 12:43:57.293884303 +0100
72 @@ -178,6 +178,10 @@
73  #include <linux/dma-mapping.h>
74  #endif
75  
76 +#if defined(NV_LINUX_DMA_MAP_OPS_H_PRESENT)
77 +#include <linux/dma-map-ops.h>
78 +#endif
79 +
80  #if defined(CONFIG_SWIOTLB) && defined(NVCPU_AARCH64)
81  #include <linux/swiotlb.h>
82  #endif
83 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/conftest.sh NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/conftest.sh
84 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/conftest.sh     2020-12-22 12:36:18.166999801 +0100
85 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/conftest.sh  2020-12-22 12:43:18.766880222 +0100
86 @@ -134,6 +134,7 @@
87      FILES="$FILES linux/fence.h"
88      FILES="$FILES linux/ktime.h"
89      FILES="$FILES linux/dma-resv.h"
90 +    FILES="$FILES linux/dma-map-ops.h"
91  
92      # Arch specific headers which need testing
93      FILES_ARCH="asm/book3s/64/hash-64k.h"
94 @@ -2097,8 +2098,20 @@
95              #
96              # Determine if the get_dma_ops() function is present.
97              #
98 +            # The structure was made available to all architectures by commit
99 +            # e1c7e324539a ("dma-mapping: always provide the dma_map_ops
100 +            # based implementation") in v4.5
101 +            #
102 +            # Commit 0a0f0d8be76d ("dma-mapping: split <linux/dma-mapping.h>")
103 +            # in v5.10-rc1 (2020-09-22), moved get_dma_ops() function
104 +            # prototype from <linux/dma-mapping.h> to <linux/dma-map-ops.h>.
105 +            #
106              CODE="
107 +            #if defined(NV_LINUX_DMA_MAP_OPS_H_PRESENT)
108 +            #include <linux/dma-map-ops.h>
109 +            #else
110              #include <linux/dma-mapping.h>
111 +            #endif
112              void conftest_get_dma_ops(void) {
113                  get_dma_ops();
114              }"
115 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/conftest.sh NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/conftest.sh
116 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/conftest.sh     2020-12-22 13:14:54.092636780 +0100
117 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/conftest.sh  2020-12-22 13:17:31.066679257 +0100
118 @@ -4244,6 +4244,30 @@
119  
120              compile_check_conftest "$CODE" "NV_VGA_TRYGET_PRESENT" "" "functions"
121          ;;
122 +
123 +        drm_prime_pages_to_sg_has_drm_device_arg)
124 +            #
125 +            # Determine if drm_prime_pages_to_sg() has 'dev' argument.
126 +            #
127 +            # drm_prime_pages_to_sg() is updated to take 'dev' argument by commit
128 +            # 707d561f77b5 ("drm: allow limiting the scatter list size.").
129 +            #
130 +            CODE="
131 +            #if defined(NV_DRM_DRMP_H_PRESENT)
132 +            #include <drm/drmP.h>
133 +            #endif
134 +            #if defined(NV_DRM_DRM_PRIME_H_PRESENT)
135 +            #include <drm/drm_prime.h>
136 +            #endif
137 +
138 +            struct sg_table *drm_prime_pages_to_sg(struct drm_device *dev,
139 +                                                   struct page **pages,
140 +                                                   unsigned int nr_pages) {
141 +                return 0;
142 +            }"
143 +
144 +            compile_check_conftest "$CODE" "NV_DRM_PRIME_PAGES_TO_SG_HAS_DRM_DEVICE_ARG" "" "types"
145 +        ;;
146      esac
147  }
148  
149 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm-gem-user-memory.c NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm-gem-user-memory.c
150 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm-gem-user-memory.c 2020-05-14 14:29:25.000000000 +0200
151 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm-gem-user-memory.c      2020-12-22 13:18:37.296993224 +0100
152 @@ -29,6 +29,7 @@
153  #endif
154  
155  #include "nvidia-drm-gem-user-memory.h"
156 +#include "nvidia-drm-helper.h"
157  #include "nvidia-drm-ioctl.h"
158  
159  static inline
160 @@ -46,9 +46,11 @@
161      struct nv_drm_gem_object *nv_gem)
162  {
163      struct nv_drm_gem_user_memory *nv_user_memory = to_nv_user_memory(nv_gem);
164 +    struct drm_gem_object *gem = &nv_gem->base;
165  
166 -    return drm_prime_pages_to_sg(nv_user_memory->pages,
167 -                                 nv_user_memory->pages_count);
168 +    return nv_drm_prime_pages_to_sg(gem->dev,
169 +                                    nv_user_memory->pages,
170 +                                    nv_user_memory->pages_count);
171  }
172  
173  static void *__nv_drm_gem_user_memory_prime_vmap(
174 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm-helper.h NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm-helper.h
175 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm-helper.h  2020-05-14 14:29:24.000000000 +0200
176 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm-helper.h       2020-12-22 13:18:10.323531096 +0100
177 @@ -55,6 +55,21 @@
178  #endif
179  }
180  
181 +#if defined(NV_DRM_DRM_PRIME_H_PRESENT)
182 +#include <drm/drm_prime.h>
183 +#endif
184
185 +static inline struct sg_table*
186 +nv_drm_prime_pages_to_sg(struct drm_device *dev,
187 +                         struct page **pages, unsigned int nr_pages)
188 +{
189 +#if defined(NV_DRM_PRIME_PAGES_TO_SG_HAS_DRM_DEVICE_ARG)
190 +    return drm_prime_pages_to_sg(dev, pages, nr_pages);
191 +#else
192 +    return drm_prime_pages_to_sg(pages, nr_pages);
193 +#endif
194 +}
195 +
196  #if defined(NV_DRM_ATOMIC_MODESET_AVAILABLE)
197  
198  /*
199 diff --color -ur NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm.Kbuild NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm.Kbuild
200 --- NVIDIA-Linux-x86_64-390.138-no-compat32.orig/kernel/nvidia-drm/nvidia-drm.Kbuild    2020-05-14 11:37:09.000000000 +0200
201 +++ NVIDIA-Linux-x86_64-390.138-no-compat32/kernel/nvidia-drm/nvidia-drm.Kbuild 2020-12-22 13:32:37.631385816 +0100
202 @@ -92,3 +92,4 @@
203  NV_CONFTEST_TYPE_COMPILE_TESTS += drm_gem_prime_export_has_dev_arg
204  NV_CONFTEST_TYPE_COMPILE_TESTS += vm_fault_t
205  NV_CONFTEST_TYPE_COMPILE_TESTS += drm_gem_object_has_resv
206 +NV_CONFTEST_TYPE_COMPILE_TESTS += drm_prime_pages_to_sg_has_drm_device_arg
This page took 0.221033 seconds and 3 git commands to generate.