forked from NVIDIA/open-gpu-kernel-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.sh
executable file
·6008 lines (5265 loc) · 214 KB
/
conftest.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
PATH="${PATH}:/bin:/sbin:/usr/bin"
# make sure we are in the directory containing this script
SCRIPTDIR=`dirname $0`
cd $SCRIPTDIR
CC="$1"
ARCH=$2
SOURCES=$3
HEADERS=$SOURCES/include
OUTPUT=$4
XEN_PRESENT=1
PREEMPT_RT_PRESENT=0
CFLAGS=""
CONFTEST_PREAMBLE="#include \"conftest/headers.h\""
# VGX_BUILD parameter defined only for VGX builds (vGPU Host driver)
# VGX_KVM_BUILD parameter defined only vGPU builds on KVM hypervisor
# GRID_BUILD parameter defined only for GRID builds (GRID Guest driver)
# GRID_BUILD_CSP parameter defined only for GRID CSP builds (GRID Guest driver for CSPs)
test_xen() {
#
# Determine if the target kernel is a Xen kernel. It used to be
# sufficient to check for CONFIG_XEN, but the introduction of
# modular para-virtualization (CONFIG_PARAVIRT, etc.) and
# Xen guest support, it is no longer possible to determine the
# target environment at build time. Therefore, if both
# CONFIG_XEN and CONFIG_PARAVIRT are present, text_xen() treats
# the kernel as a stand-alone kernel.
#
if ! test_configuration_option CONFIG_XEN ||
test_configuration_option CONFIG_PARAVIRT; then
XEN_PRESENT=0
fi
}
append_conftest() {
#
# Echo data from stdin: this is a transitional function to make it easier
# to port conftests from drivers with parallel conftest generation to
# older driver versions
#
while read LINE; do
echo ${LINE}
done
}
test_header_presence() {
#
# Determine if the given header file (which may or may not be
# present) is provided by the target kernel.
#
# Input:
# $1: relative file path
#
# This routine creates an upper case, underscore version of each of the
# relative file paths, and uses that as the token to either define or
# undefine in a C header file. For example, linux/fence.h becomes
# NV_LINUX_FENCE_H_PRESENT, and that is either defined or undefined, in the
# output (which goes to stdout, just like the rest of this file).
TEST_CFLAGS="-E -M $CFLAGS"
file="$1"
file_define=NV_`echo $file | tr '/.\-a-z' '___A-Z'`_PRESENT
CODE="#include <$file>"
if echo "$CODE" | $CC $TEST_CFLAGS - > /dev/null 2>&1; then
echo "#define $file_define"
else
# If preprocessing failed, it could have been because the header
# file under test is not present, or because it is present but
# depends upon the inclusion of other header files. Attempting
# preprocessing again with -MG will ignore a missing header file
# but will still fail if the header file is present.
if echo "$CODE" | $CC $TEST_CFLAGS -MG - > /dev/null 2>&1; then
echo "#undef $file_define"
else
echo "#define $file_define"
fi
fi
}
test_configuration_option() {
#
# Check to see if the given configuration option is defined
#
get_configuration_option $1 >/dev/null 2>&1
return $?
}
set_configuration() {
#
# Set a specific configuration option. This function is called to always
# enable a configuration, in order to verify whether the test code for that
# configuration is no longer required and the corresponding
# conditionally-compiled code in the driver can be removed.
#
DEF="$1"
if [ "$3" = "" ]
then
VAL=""
CAT="$2"
else
VAL="$2"
CAT="$3"
fi
echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}"
}
unset_configuration() {
#
# Un-set a specific configuration option. This function is called to
# always disable a configuration, in order to verify whether the test
# code for that configuration is no longer required and the corresponding
# conditionally-compiled code in the driver can be removed.
#
DEF="$1"
CAT="$2"
echo "#undef ${DEF}" | append_conftest "${CAT}"
}
compile_check_conftest() {
#
# Compile the current conftest C file and check+output the result
#
CODE="$1"
DEF="$2"
VAL="$3"
CAT="$4"
echo "$CONFTEST_PREAMBLE
$CODE" > conftest$$.c
$CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
rm -f conftest$$.c
if [ -f conftest$$.o ]; then
rm -f conftest$$.o
if [ "${CAT}" = "functions" ]; then
#
# The logic for "functions" compilation tests is inverted compared to
# other compilation steps: if the function is present, the code
# snippet will fail to compile because the function call won't match
# the prototype. If the function is not present, the code snippet
# will produce an object file with the function as an unresolved
# symbol.
#
echo "#undef ${DEF}" | append_conftest "${CAT}"
else
echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}"
fi
return
else
if [ "${CAT}" = "functions" ]; then
echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}"
else
echo "#undef ${DEF}" | append_conftest "${CAT}"
fi
return
fi
}
export_symbol_present_conftest() {
#
# Check Module.symvers to see whether the given symbol is present.
#
SYMBOL="$1"
TAB=' '
if grep -e "${TAB}${SYMBOL}${TAB}.*${TAB}EXPORT_SYMBOL.*\$" \
"$OUTPUT/Module.symvers" >/dev/null 2>&1; then
echo "#define NV_IS_EXPORT_SYMBOL_PRESENT_$SYMBOL 1" |
append_conftest "symbols"
else
# May be a false negative if Module.symvers is absent or incomplete,
# or if the Module.symvers format changes.
echo "#define NV_IS_EXPORT_SYMBOL_PRESENT_$SYMBOL 0" |
append_conftest "symbols"
fi
}
export_symbol_gpl_conftest() {
#
# Check Module.symvers to see whether the given symbol is present and its
# export type is GPL-only (including deprecated GPL-only symbols).
#
SYMBOL="$1"
TAB=' '
if grep -e "${TAB}${SYMBOL}${TAB}.*${TAB}EXPORT_\(UNUSED_\)*SYMBOL_GPL\$" \
"$OUTPUT/Module.symvers" >/dev/null 2>&1; then
echo "#define NV_IS_EXPORT_SYMBOL_GPL_$SYMBOL 1" |
append_conftest "symbols"
else
# May be a false negative if Module.symvers is absent or incomplete,
# or if the Module.symvers format changes.
echo "#define NV_IS_EXPORT_SYMBOL_GPL_$SYMBOL 0" |
append_conftest "symbols"
fi
}
get_configuration_option() {
#
# Print the value of given configuration option, if defined
#
RET=1
OPTION=$1
OLD_FILE="linux/autoconf.h"
NEW_FILE="generated/autoconf.h"
FILE=""
if [ -f $HEADERS/$NEW_FILE -o -f $OUTPUT/include/$NEW_FILE ]; then
FILE=$NEW_FILE
elif [ -f $HEADERS/$OLD_FILE -o -f $OUTPUT/include/$OLD_FILE ]; then
FILE=$OLD_FILE
fi
if [ -n "$FILE" ]; then
#
# We are looking at a configured source tree; verify
# that its configuration includes the given option
# via a compile check, and print the option's value.
#
if [ -f $HEADERS/$FILE ]; then
INCLUDE_DIRECTORY=$HEADERS
elif [ -f $OUTPUT/include/$FILE ]; then
INCLUDE_DIRECTORY=$OUTPUT/include
else
return 1
fi
echo "#include <$FILE>
#ifndef $OPTION
#error $OPTION not defined!
#endif
$OPTION
" > conftest$$.c
$CC -E -P -I$INCLUDE_DIRECTORY -D__ASSEMBLY__ -o conftest$$ conftest$$.c > /dev/null 2>&1
if [ -e conftest$$ ]; then
tr -d '\r\n\t ' < conftest$$
RET=$?
fi
rm -f conftest$$.c conftest$$
else
CONFIG=$OUTPUT/.config
if [ -f $CONFIG ] && grep "^$OPTION=" $CONFIG; then
grep "^$OPTION=" $CONFIG | cut -f 2- -d "="
RET=$?
fi
fi
return $RET
}
check_for_ib_peer_memory_symbols() {
kernel_dir="$1"
module_symvers="${kernel_dir}/Module.symvers"
sym_ib_register="ib_register_peer_memory_client"
sym_ib_unregister="ib_unregister_peer_memory_client"
tab=' '
# Return 0 for true(no errors), 1 for false
if [ ! -f "${module_symvers}" ]; then
return 1
fi
if grep -e "${tab}${sym_ib_register}${tab}.*${tab}EXPORT_SYMBOL.*\$" \
"${module_symvers}" > /dev/null 2>&1 &&
grep -e "${tab}${sym_ib_unregister}${tab}.*${tab}EXPORT_SYMBOL.*\$" \
"${module_symvers}" > /dev/null 2>&1; then
return 0
else
return 1
fi
}
compile_test() {
case "$1" in
set_memory_uc)
#
# Determine if the set_memory_uc() function is present.
# It does not exist on all architectures.
#
CODE="
#include <linux/types.h>
#if defined(NV_ASM_SET_MEMORY_H_PRESENT)
#if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT)
#include <asm/pgtable_types.h>
#endif
#include <asm/set_memory.h>
#else
#include <asm/cacheflush.h>
#endif
void conftest_set_memory_uc(void) {
set_memory_uc();
}"
compile_check_conftest "$CODE" "NV_SET_MEMORY_UC_PRESENT" "" "functions"
;;
set_memory_array_uc)
#
# Determine if the set_memory_array_uc() function is present.
# It does not exist on all architectures.
#
CODE="
#include <linux/types.h>
#if defined(NV_ASM_SET_MEMORY_H_PRESENT)
#if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT)
#include <asm/pgtable_types.h>
#endif
#include <asm/set_memory.h>
#else
#include <asm/cacheflush.h>
#endif
void conftest_set_memory_array_uc(void) {
set_memory_array_uc();
}"
compile_check_conftest "$CODE" "NV_SET_MEMORY_ARRAY_UC_PRESENT" "" "functions"
;;
sysfs_slab_unlink)
#
# Determine if the sysfs_slab_unlink() function is present.
#
# This test is useful to check for the presence a fix for the deferred
# kmem_cache destroy feature (see nvbug: 2543505).
#
# Added by commit d50d82faa0c9 ("slub: fix failure when we delete and
# create a slab cache") in 4.18 (2018-06-27).
#
CODE="
#include <linux/slab.h>
void conftest_sysfs_slab_unlink(void) {
sysfs_slab_unlink();
}"
compile_check_conftest "$CODE" "NV_SYSFS_SLAB_UNLINK_PRESENT" "" "functions"
;;
list_is_first)
#
# Determine if the list_is_first() function is present.
#
# Added by commit 70b44595eafe ("mm, compaction: use free lists
# to quickly locate a migration source") in 5.1 (2019-03-05)
#
CODE="
#include <linux/list.h>
void conftest_list_is_first(void) {
list_is_first();
}"
compile_check_conftest "$CODE" "NV_LIST_IS_FIRST_PRESENT" "" "functions"
;;
set_pages_uc)
#
# Determine if the set_pages_uc() function is present.
# It does not exist on all architectures.
#
CODE="
#include <linux/types.h>
#if defined(NV_ASM_SET_MEMORY_H_PRESENT)
#if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT)
#include <asm/pgtable_types.h>
#endif
#include <asm/set_memory.h>
#else
#include <asm/cacheflush.h>
#endif
void conftest_set_pages_uc(void) {
set_pages_uc();
}"
compile_check_conftest "$CODE" "NV_SET_PAGES_UC_PRESENT" "" "functions"
;;
set_pages_array_uc)
#
# Determine if the set_pages_array_uc() function is present.
# It does not exist on all architectures.
#
# set_pages_array_uc() was added by commit
# 0f3507555f6fa4acbc85a646d6e8766230db38fc ("x86, CPA: Add
# set_pages_arrayuc and set_pages_array_wb") in v2.6.30-rc1 (Thu Mar
# 19 14:51:15 2009)
#
CODE="
#include <linux/types.h>
#if defined(NV_ASM_SET_MEMORY_H_PRESENT)
#if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT)
#include <asm/pgtable_types.h>
#endif
#include <asm/set_memory.h>
#else
#include <asm/cacheflush.h>
#endif
void conftest_set_pages_array_uc(void) {
set_pages_array_uc();
}"
compile_check_conftest "$CODE" "NV_SET_PAGES_ARRAY_UC_PRESENT" "" "functions"
;;
flush_cache_all)
#
# Determine if flush_cache_all() function is present
#
# flush_cache_all() was removed by commit id
# 68234df4ea79 ("arm64: kill flush_cache_all()") in 4.2 (2015-04-20)
# for aarch64
#
CODE="
#include <asm/cacheflush.h>
int conftest_flush_cache_all(void) {
return flush_cache_all();
}"
compile_check_conftest "$CODE" "NV_FLUSH_CACHE_ALL_PRESENT" "" "functions"
;;
pci_get_domain_bus_and_slot)
#
# Determine if the pci_get_domain_bus_and_slot() function
# is present.
#
# Added by commit 3c299dc22635 ("PCI: add
# pci_get_domain_bus_and_slot function") in 2.6.33 but aarch64
# support was added by commit d1e6dc91b532
# ("arm64: Add architectural support for PCI") in 3.18-rc1
#
CODE="
#include <linux/pci.h>
void conftest_pci_get_domain_bus_and_slot(void) {
pci_get_domain_bus_and_slot();
}"
compile_check_conftest "$CODE" "NV_PCI_GET_DOMAIN_BUS_AND_SLOT_PRESENT" "" "functions"
;;
pci_bus_address)
#
# Determine if the pci_bus_address() function is
# present.
#
# Added by commit 06cf56e497c8 ("PCI: Add pci_bus_address() to
# get bus address of a BAR") in v3.14
#
CODE="
#include <linux/pci.h>
void conftest_pci_bus_address(void) {
pci_bus_address();
}"
compile_check_conftest "$CODE" "NV_PCI_BUS_ADDRESS_PRESENT" "" "functions"
;;
hash__remap_4k_pfn)
#
# Determine if the hash__remap_4k_pfn() function is
# present.
#
# Added by commit 6cc1a0ee4ce2 ("powerpc/mm/radix: Add radix
# callback for pmd accessors") in v4.7 (committed 2016-04-29).
# Present only in arch/powerpc
#
CODE="
#if defined(NV_ASM_BOOK3S_64_HASH_64K_H_PRESENT)
#include <linux/mm.h>
#include <asm/book3s/64/hash-64k.h>
#endif
void conftest_hash__remap_4k_pfn(void) {
hash__remap_4k_pfn();
}"
compile_check_conftest "$CODE" "NV_HASH__REMAP_4K_PFN_PRESENT" "" "functions"
;;
register_cpu_notifier)
#
# Determine if register_cpu_notifier() is present
#
# Removed by commit 530e9b76ae8f ("cpu/hotplug: Remove obsolete
# cpu hotplug register/unregister functions") in v4.10
# (2016-12-21)
#
CODE="
#include <linux/cpu.h>
void conftest_register_cpu_notifier(void) {
register_cpu_notifier();
}"
compile_check_conftest "$CODE" "NV_REGISTER_CPU_NOTIFIER_PRESENT" "" "functions"
;;
cpuhp_setup_state)
#
# Determine if cpuhp_setup_state() is present
#
# Added by commit 5b7aa87e0482 ("cpu/hotplug: Implement
# setup/removal interface") in v4.6 (commited 2016-02-26)
#
# It is used as a replacement for register_cpu_notifier
CODE="
#include <linux/cpu.h>
void conftest_cpuhp_setup_state(void) {
cpuhp_setup_state();
}"
compile_check_conftest "$CODE" "NV_CPUHP_SETUP_STATE_PRESENT" "" "functions"
;;
ioremap_cache)
#
# Determine if the ioremap_cache() function is present.
# It does not exist on all architectures.
#
CODE="
#include <asm/io.h>
void conftest_ioremap_cache(void) {
ioremap_cache();
}"
compile_check_conftest "$CODE" "NV_IOREMAP_CACHE_PRESENT" "" "functions"
;;
ioremap_wc)
#
# Determine if the ioremap_wc() function is present.
# It does not exist on all architectures.
#
CODE="
#include <asm/io.h>
void conftest_ioremap_wc(void) {
ioremap_wc();
}"
compile_check_conftest "$CODE" "NV_IOREMAP_WC_PRESENT" "" "functions"
;;
dom0_kernel_present)
# Add config parameter if running on DOM0.
if [ -n "$VGX_BUILD" ]; then
echo "#define NV_DOM0_KERNEL_PRESENT" | append_conftest "generic"
else
echo "#undef NV_DOM0_KERNEL_PRESENT" | append_conftest "generic"
fi
return
;;
nvidia_vgpu_kvm_build)
# Add config parameter if running on KVM host.
if [ -n "$VGX_KVM_BUILD" ]; then
echo "#define NV_VGPU_KVM_BUILD" | append_conftest "generic"
else
echo "#undef NV_VGPU_KVM_BUILD" | append_conftest "generic"
fi
return
;;
vfio_register_notifier)
#
# Check number of arguments required.
#
# New parameters added by commit 22195cbd3451 ("vfio:
# vfio_register_notifier: classify iommu notifier") in v4.10
#
echo "$CONFTEST_PREAMBLE
#include <linux/vfio.h>
int conftest_vfio_register_notifier(void) {
return vfio_register_notifier((struct device *) NULL, (struct notifier_block *) NULL);
}" > conftest$$.c
$CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
rm -f conftest$$.c
if [ -f conftest$$.o ]; then
echo "#define NV_VFIO_NOTIFIER_ARGUMENT_COUNT 2" | append_conftest "functions"
rm -f conftest$$.o
return
else
echo "#define NV_VFIO_NOTIFIER_ARGUMENT_COUNT 4" | append_conftest "functions"
return
fi
;;
vfio_info_add_capability_has_cap_type_id_arg)
#
# Check if vfio_info_add_capability() has cap_type_id parameter.
#
# Removed by commit dda01f787df9 ("vfio: Simplify capability
# helper") in v4.16 (2017-12-12)
#
CODE="
#include <linux/vfio.h>
int vfio_info_add_capability(struct vfio_info_cap *caps,
int cap_type_id,
void *cap_type) {
return 0;
}"
compile_check_conftest "$CODE" "NV_VFIO_INFO_ADD_CAPABILITY_HAS_CAP_TYPE_ID_ARGS" "" "types"
;;
nvidia_grid_build)
if [ -n "$GRID_BUILD" ]; then
echo "#define NV_GRID_BUILD" | append_conftest "generic"
else
echo "#undef NV_GRID_BUILD" | append_conftest "generic"
fi
return
;;
nvidia_grid_csp_build)
if [ -n "$GRID_BUILD_CSP" ]; then
echo "#define NV_GRID_BUILD_CSP $GRID_BUILD_CSP" | append_conftest "generic"
else
echo "#undef NV_GRID_BUILD_CSP" | append_conftest "generic"
fi
return
;;
vm_fault_has_address)
#
# Determine if the 'vm_fault' structure has an 'address', or a
# 'virtual_address' field. The .virtual_address field was
# effectively renamed to .address:
#
# 'address' added by commit 82b0f8c39a38 ("mm: join
# struct fault_env and vm_fault") in v4.10 (2016-12-14)
#
# 'virtual_address' removed by commit 1a29d85eb0f1 ("mm: use
# vmf->address instead of of vmf->virtual_address") in v4.10
# (2016-12-14)
#
CODE="
#include <linux/mm.h>
int conftest_vm_fault_has_address(void) {
return offsetof(struct vm_fault, address);
}"
compile_check_conftest "$CODE" "NV_VM_FAULT_HAS_ADDRESS" "" "types"
;;
kmem_cache_has_kobj_remove_work)
#
# Determine if the 'kmem_cache' structure has 'kobj_remove_work'.
#
# 'kobj_remove_work' was added by commit 3b7b314053d02 ("slub: make
# sysfs file removal asynchronous") in v4.12 (2017-06-23). This
# commit introduced a race between kmem_cache destroy and create
# which we need to workaround in our driver (see nvbug: 2543505).
# Also see comment for sysfs_slab_unlink conftest.
#
CODE="
#include <linux/mm.h>
#include <linux/slab.h>
int conftest_kmem_cache_has_kobj_remove_work(void) {
return offsetof(struct kmem_cache, kobj_remove_work);
}"
compile_check_conftest "$CODE" "NV_KMEM_CACHE_HAS_KOBJ_REMOVE_WORK" "" "types"
;;
mdev_uuid)
#
# Determine if mdev_uuid() function is present or not
#
# Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device
# private and abstract interfaces") in v4.10
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_uuid(void) {
mdev_uuid();
}"
compile_check_conftest "$CODE" "NV_MDEV_UUID_PRESENT" "" "functions"
#
# Determine if mdev_uuid() returns 'const guid_t *'.
#
# mdev_uuid() function prototype updated to return 'const guid_t *'
# by commit 278bca7f318e ("vfio-mdev: Switch to use new generic UUID
# API") in v5.1 (2019-01-10).
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
const guid_t *conftest_mdev_uuid_return_guid_ptr(struct mdev_device *mdev) {
return mdev_uuid(mdev);
}"
compile_check_conftest "$CODE" "NV_MDEV_UUID_RETURN_GUID_PTR" "" "types"
;;
mdev_dev)
#
# Determine if mdev_dev() function is present or not
#
# Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device
# private and abstract interfaces") in v4.10
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_dev(void) {
mdev_dev();
}"
compile_check_conftest "$CODE" "NV_MDEV_DEV_PRESENT" "" "functions"
;;
mdev_get_type_group_id)
#
# Determine if mdev_get_type_group_id() function is present or not
#
# Added by commit 15fcc44be0c7a ("vfio/mdev: Add
# mdev/mtype_get_type_group_id()") in v5.13
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_get_type_group_id(void) {
mdev_get_type_group_id();
}"
compile_check_conftest "$CODE" "NV_MDEV_GET_TYPE_GROUP_ID_PRESENT" "" "functions"
;;
vfio_device_mig_state)
#
# Determine if vfio_device_mig_state enum is present or not
#
# Added by commit 115dcec65f61d ("vfio: Define device
# migration protocol v2") in v5.18
#
CODE="
#include <linux/pci.h>
#include <linux/vfio.h>
enum vfio_device_mig_state device_state;
"
compile_check_conftest "$CODE" "NV_VFIO_DEVICE_MIG_STATE_PRESENT" "" "types"
;;
vfio_migration_ops)
#
# Determine if vfio_migration_ops struct is present or not
#
# Added by commit 6e97eba8ad874 ("vfio: Split migration ops
# from main device ops") in v6.0
#
CODE="
#include <linux/pci.h>
#include <linux/vfio.h>
struct vfio_migration_ops mig_ops;
"
compile_check_conftest "$CODE" "NV_VFIO_MIGRATION_OPS_PRESENT" "" "types"
;;
mdev_parent)
#
# Determine if the struct mdev_parent type is present.
#
# Added by commit 42930553a7c1 ("vfio-mdev: de-polute the
# namespace, rename parent_device & parent_ops") in v4.10
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
struct mdev_parent_ops conftest_mdev_parent;
"
compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_STRUCT_PRESENT" "" "types"
;;
mdev_parent_dev)
#
# Determine if mdev_parent_dev() function is present or not
#
# Added by commit 9372e6feaafb ("vfio-mdev: Make mdev_parent
# private") in v4.10
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_parent_dev(void) {
mdev_parent_dev();
}"
compile_check_conftest "$CODE" "NV_MDEV_PARENT_DEV_PRESENT" "" "functions"
;;
mdev_from_dev)
#
# Determine if mdev_from_dev() function is present or not.
#
# Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device
# private and abstract interfaces") in v4.10 (2016-12-30)
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_from_dev(void) {
mdev_from_dev();
}"
compile_check_conftest "$CODE" "NV_MDEV_FROM_DEV_PRESENT" "" "functions"
;;
mdev_set_iommu_device)
#
# Determine if mdev_set_iommu_device() function is present or not.
#
# Added by commit 8ac13175cbe9 ("vfio/mdev: Add iommu related member
# in mdev_device) in v5.1 (2019-04-12)
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
void conftest_mdev_set_iommu_device(void) {
mdev_set_iommu_device();
}"
compile_check_conftest "$CODE" "NV_MDEV_SET_IOMMU_DEVICE_PRESENT" "" "functions"
;;
mdev_parent_ops_has_open_device)
# Determine if 'mdev_parent_ops' structure has a 'open_device'
# field.
#
# Added by commit 2fd585f4ed9d ("vfio: Provide better generic support
# for open/release vfio_device_ops") in 5.15 (2021-08-05)
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
int conftest_mdev_parent_ops_has_open_device(void) {
return offsetof(struct mdev_parent_ops, open_device);
}"
compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_HAS_OPEN_DEVICE" "" "types"
;;
mdev_parent_ops_has_device_driver)
#
# Determine if 'mdev_parent_ops' structure has 'device_driver' field.
#
# Added by commit 88a21f265ce5 ("vfio/mdev: Allow the mdev_parent_ops
# to specify the device driver to bind) in v5.14 (2021-06-17)
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
int conftest_mdev_parent_ops_has_device_driver(void) {
return offsetof(struct mdev_parent_ops, device_driver);
}"
compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_HAS_DEVICE_DRIVER" "" "types"
;;
mdev_driver_has_supported_type_groups)
#
# Determine if 'mdev_driver' structure has 'supported_type_groups' field.
#
# Added by commit 6b42f491e17c ("vfio/mdev: Remove mdev_parent_ops)
# in v5.19 (2022-04-11)
#
CODE="
#include <linux/pci.h>
#include <linux/mdev.h>
int conftest_mdev_driver_has_supported_type_groups(void) {
return offsetof(struct mdev_driver, supported_type_groups);
}"
compile_check_conftest "$CODE" "NV_MDEV_DRIVER_HAS_SUPPORTED_TYPE_GROUPS" "" "types"
;;
vfio_device_ops_has_dma_unmap)
#
# Determine if 'vfio_device_ops' struct has 'dma_unmap' field.
#
# Added by commit ce4b4657ff18 ("vfio: Replace the DMA unmapping
# notifier with a callback") in v6.0
#
CODE="
#include <linux/pci.h>
#include <linux/vfio.h>
int conftest_vfio_device_ops_has_dma_unmap(void) {
return offsetof(struct vfio_device_ops, dma_unmap);
}"
compile_check_conftest "$CODE" "NV_VFIO_DEVICE_OPS_HAS_DMA_UNMAP" "" "types"
;;
pci_irq_vector_helpers)
#
# Determine if pci_alloc_irq_vectors(), pci_free_irq_vectors()
# functions are present or not.
#
# Added by commit aff171641d181ea573 (PCI: Provide sensible IRQ
# vector alloc/free routines) (2016-07-12)
#
CODE="
#include <linux/pci.h>
#include <linux/msi.h>
void conftest_pci_irq_vector_helpers(void) {
pci_alloc_irq_vectors();
pci_free_irq_vectors ();
}"
compile_check_conftest "$CODE" "NV_PCI_IRQ_VECTOR_HELPERS_PRESENT" "" "functions"
;;
vfio_device_gfx_plane_info)
#
# determine if the 'struct vfio_device_gfx_plane_info' type is present.
#
# Added by commit e20eaa2382e7 ("vfio: ABI for mdev display
# dma-buf operation") in v4.16 (2017-11-23)
#
CODE="
#include <linux/vfio.h>
struct vfio_device_gfx_plane_info info;"
compile_check_conftest "$CODE" "NV_VFIO_DEVICE_GFX_PLANE_INFO_PRESENT" "" "types"
;;
vfio_device_migration_has_start_pfn)
#
# Determine if the 'vfio_device_migration_info' structure has
# a 'start_pfn' field.
#
# This member was present in proposed interface for vGPU Migration
# ("[PATCH v3 0/5] Add migration support for VFIO device ")
# https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05176.html
# which is not present in upstreamed commit a8a24f3f6e38 (vfio: UAPI
# for migration interface for device state) in v5.8 (2020-05-29)
#
CODE="
#include <linux/vfio.h>
int conftest_vfio_device_migration_has_start_pfn(void) {
return offsetof(struct vfio_device_migration_info, start_pfn);
}"
compile_check_conftest "$CODE" "NV_VFIO_DEVICE_MIGRATION_HAS_START_PFN" "" "types"
;;
vfio_uninit_group_dev)
#
# Determine if vfio_uninit_group_dev() function is present or not.
#
# Added by commit ae03c3771b8c (vfio: Introduce a vfio_uninit_group_dev()
# API call) in v5.15
#
CODE="
#include <linux/vfio.h>
void conftest_vfio_uninit_group_dev(void) {
vfio_uninit_group_dev();
}"
compile_check_conftest "$CODE" "NV_VFIO_UNINIT_GROUP_DEV_PRESENT" "" "functions"
;;
vfio_pci_core_available)
# Determine if VFIO_PCI_CORE is available
#
# Added by commit 7fa005caa35e ("vfio/pci: Introduce
# vfio_pci_core.ko") in v5.16 (2021-08-26)
#
CODE="
#if defined(NV_LINUX_VFIO_PCI_CORE_H_PRESENT)