-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.sh
More file actions
executable file
·1226 lines (1056 loc) · 40.1 KB
/
Copy pathconftest.sh
File metadata and controls
executable file
·1226 lines (1056 loc) · 40.1 KB
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
# 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=LG_`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
}
build_cflags() {
ISYSTEM=`$CC -print-file-name=include 2> /dev/null`
BASE_CFLAGS="-O2 -D__KERNEL__ \
-DKBUILD_BASENAME=\"#conftest$$\" -DKBUILD_MODNAME=\"#conftest$$\" \
-nostdinc -isystem $ISYSTEM \
-Wno-implicit-function-declaration -Wno-strict-prototypes"
if [ "$OUTPUT" != "$SOURCES" ]; then
OUTPUT_CFLAGS="-I$OUTPUT/include2 -I$OUTPUT/include"
if [ -f "$OUTPUT/include/generated/autoconf.h" ]; then
AUTOCONF_FILE="$OUTPUT/include/generated/autoconf.h"
else
AUTOCONF_FILE="$OUTPUT/include/linux/autoconf.h"
fi
else
if [ -f "$HEADERS/generated/autoconf.h" ]; then
AUTOCONF_FILE="$HEADERS/generated/autoconf.h"
else
AUTOCONF_FILE="$HEADERS/linux/autoconf.h"
fi
fi
test_xen
if [ "$XEN_PRESENT" != "0" ]; then
MACH_CFLAGS="-I$HEADERS/asm/mach-xen"
fi
KERNEL_ARCH="$ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]; then
if [ -d "$SOURCES/arch/x86" ]; then
KERNEL_ARCH="x86"
fi
fi
SOURCE_HEADERS="$HEADERS"
SOURCE_ARCH_HEADERS="$SOURCES/arch/$KERNEL_ARCH/include"
OUTPUT_HEADERS="$OUTPUT/include"
OUTPUT_ARCH_HEADERS="$OUTPUT/arch/$KERNEL_ARCH/include"
# Look for mach- directories on this arch, and add it to the list of
# includes if that platform is enabled in the configuration file, which
# may have a definition like this:
# #define CONFIG_ARCH_<MACHUPPERCASE> 1
for _mach_dir in `ls -1d $SOURCES/arch/$KERNEL_ARCH/mach-* 2>/dev/null`; do
_mach=`echo $_mach_dir | \
sed -e "s,$SOURCES/arch/$KERNEL_ARCH/mach-,," | \
tr 'a-z' 'A-Z'`
grep "CONFIG_ARCH_$_mach \+1" $AUTOCONF_FILE > /dev/null 2>&1
if [ $? -eq 0 ]; then
MACH_CFLAGS="$MACH_CFLAGS -I$_mach_dir/include"
fi
done
if [ "$ARCH" = "arm" ]; then
MACH_CFLAGS="$MACH_CFLAGS -D__LINUX_ARM_ARCH__=7"
fi
# Add the mach-default includes (only found on x86/older kernels)
MACH_CFLAGS="$MACH_CFLAGS -I$SOURCE_HEADERS/asm-$KERNEL_ARCH/mach-default"
MACH_CFLAGS="$MACH_CFLAGS -I$SOURCE_ARCH_HEADERS/asm/mach-default"
CFLAGS="$BASE_CFLAGS $MACH_CFLAGS $OUTPUT_CFLAGS -include $AUTOCONF_FILE"
CFLAGS="$CFLAGS -I$SOURCE_HEADERS"
CFLAGS="$CFLAGS -I$SOURCE_HEADERS/uapi"
CFLAGS="$CFLAGS -I$SOURCE_HEADERS/xen"
CFLAGS="$CFLAGS -I$OUTPUT_HEADERS/generated/uapi"
CFLAGS="$CFLAGS -I$SOURCE_ARCH_HEADERS"
CFLAGS="$CFLAGS -I$SOURCE_ARCH_HEADERS/uapi"
CFLAGS="$CFLAGS -I$OUTPUT_ARCH_HEADERS/generated"
CFLAGS="$CFLAGS -I$OUTPUT_ARCH_HEADERS/generated/uapi"
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
#
# If CONFIG_HAVE_FENTRY is enabled and gcc supports -mfentry flags then set
# CC_USING_FENTRY and add -mfentry into cflags.
#
# linux/ftrace.h file indirectly gets included into the conftest source and
# fails to get compiled, because conftest.sh runs outside of Kbuild it ends
# up building without -mfentry and CC_USING_FENTRY flags.
#
grep "CONFIG_HAVE_FENTRY \+1" $AUTOCONF_FILE > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "" > conftest$$.c
$CC -mfentry -c -x c conftest$$.c > /dev/null 2>&1
rm -f conftest$$.c
if [ -f conftest$$.o ]; then
rm -f conftest$$.o
CFLAGS="$CFLAGS -mfentry -DCC_USING_FENTRY"
fi
fi
#
# If CONFIG_CPU_LOONGSON64 is enabled then reset _LOONGARCH_ISA to
# _LOONGARCH_ISA_LOONGARCH64.
#
grep "CONFIG_CPU_LOONGSON64 \+1" $AUTOCONF_FILE > /dev/null 2>&1
if [ $? -eq 0 ]; then
CFLAGS="$CFLAGS -U_LOONGARCH_ISA -D_LOONGARCH_ISA=_LOONGARCH_ISA_LOONGARCH64"
fi
}
CONFTEST_PREAMBLE="#include \"conftest/headers.h\"
#if defined(LG_LINUX_KCONFIG_H_PRESENT)
#include <linux/kconfig.h>
#endif
#if defined(LG_GENERATED_AUTOCONF_H_PRESENT)
#include <generated/autoconf.h>
#else
#include <linux/autoconf.h>
#endif
#if defined(CONFIG_XEN) && \
defined(CONFIG_XEN_INTERFACE_VERSION) && !defined(__XEN_INTERFACE_VERSION__)
#define __XEN_INTERFACE_VERSION__ CONFIG_XEN_INTERFACE_VERSION
#endif
#if defined(CONFIG_KASAN) && defined(CONFIG_ARM64)
#if defined(CONFIG_KASAN_SW_TAGS)
#define KASAN_SHADOW_SCALE_SHIFT 4
#else
#define KASAN_SHADOW_SCALE_SHIFT 3
#endif
#endif"
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\(_GPL\)\?\s*\$" \
"$OUTPUT/Module.symvers" >/dev/null 2>&1; then
echo "#define LS_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 LS_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\s*\$" \
"$OUTPUT/Module.symvers" >/dev/null 2>&1; then
echo "#define LG_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 LG_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 -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
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") in v5.4.
#
# 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="
#if defined(LG_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" "LG_DRM_DRIVER_PRIME_FLAG_PRESENT" "" "types"
;;
drm_gem_object_reference)
#
# Determine if drm_gem_object_reference exists.
#
# Changed by commit 3e70fd160cf0b1945225eaa08dd2cb8544f21cb8 ("drm:
# remove deprecated "[__]drm_gem_object_[un]reference[_locked]" functions") in 4.20-rc4
#
CODE="
#include <drm/drm_gem.h>
typeof(drm_gem_object_reference) conftest_drm_gem_object_reference;
void conftest_drm_gem_object_reference(struct drm_gem_object *obj) {
return;
}"
compile_check_conftest "$CODE" "LG_DRM_GEM_OBJECT_REFERENCE" "" "types"
;;
dma_resv_reserve_fences)
#
# Determine if dma_resv_reserve_fences exists.
#
# Changed by commit c8d4c18bfbc4ab467188dbe45cc8155759f49d9e ("dma-buf/
# drivers: make reserving a shared slot mandatory v4") in 5.18-rc2
# proting in 6.6
#
CODE="
#include <linux/dma-resv.h>
typeof(dma_resv_reserve_fences) conftest_dma_resv_reserve_fences;
int conftest_dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences) {
return 0;
}"
compile_check_conftest "$CODE" "LG_HAS_DMA_RESV_RESERVE_FENCES" "" "types"
;;
vm_operations_fault_ret_int)
#
# Determine if the return type of vm_operations_struct->fault()
# is int.
#
# commit 1c8f422059ae5da07db7406ab916203f9417e396 ("mm:
# change return type to vm_fault_t") in v4.17-rc1.
#
CODE="
#include <linux/mm.h>
static const struct vm_operations_struct *ops;
typeof(*ops->fault) conftest_vm_operations_fault_ret_int;
int conftest_vm_operations_fault_ret_int(struct vm_fault *vmf) {
return 0;
}"
compile_check_conftest "$CODE" "LG_VM_OPERATIONS_FAULT_RET_INT" "" "types"
;;
drm_mode_config_has_allow_fb_modifiers)
#
# Determine if the drm_mode_config->allow_fb_modifiers exists
#
# by commit 3d082157a24216ca084082ce421a37d14ecfcfad ("drm:
# remove allow_fb_modifiers")
# in v5.17-rc3
CODE="
#include <drm/drm_mode_config.h>
int conftest_drm_mode_config_has_allow_fb_modifiers(void) {
return offsetof(struct drm_mode_config, allow_fb_modifiers);
}"
compile_check_conftest "$CODE" "LG_DRM_MODE_CONFIG_HAS_FB_MOD" "" "types"
;;
gem_prime_export_has_device)
#
# Determine if the argument type of drm_driver->gem_prime_export()
# has drm_device.
#
# commit e4fa8457b2197118538a1400b75c898f9faaf164 ("drm/prime::
# Align gem_prime_export with obj_funcs.export") in v5.2-rc6.
#
CODE="
#include <drm/drm_drv.h>
static const struct drm_driver *ops;
typeof(*ops->gem_prime_export) conftest_gem_prime_export_has_device;
struct dma_buf *conftest_gem_prime_export_has_device(
struct drm_device *dev,
struct drm_gem_object *obj,
int flags) {
return NULL;
}"
compile_check_conftest "$CODE" "LG_GEM_PRIME_EXPORT_HAS_DRM_DEVICE" "" "types"
;;
drm_driver_has_gem_prime_export)
#
# Determine if the drm_driver->gem_prime_export exists
#
# by commit d693def4fd1c23f1ca5aed1afb9993b3a2069ad2 ("drm:
# Remove obsolete GEM and PRIME callbacks from struct drm_driver")
# in v5.9-rc7
CODE="
#include <drm/drm_drv.h>
int conftest_drm_driver_has_gem_prime_export(void) {
return offsetof(struct drm_driver, gem_prime_export);
}"
compile_check_conftest "$CODE" "LG_DRM_DRIVER_HAS_EXPORT" "" "types"
;;
drm_gem_object_has_resv)
#
# Determine if the drm_gem_object->resv exists
#
# by commit 1ba627148ef5d9dee879585687c4b0ee644f7ab5 ("drm:
# Add reservation_object to drm_gem_object")
# in v5.0-rc8
CODE="
#include <drm/drm_gem.h>
int conftest_drm_gem_object_has_resv(void) {
return offsetof(struct drm_gem_object, resv);
}"
compile_check_conftest "$CODE" "LG_DRM_GEM_OBJECT_HAS_RESV" "" "types"
;;
dma_resv_get_excl)
#
# Determine if dma_resv_get_excl() is present.
#
# dma_resv_get_excl is removed
# by commit 2254e49cef7015d7697bd1617d19e620e2788ec5 ("dma-resv: Fix kerneldoc") in v5.13-rc5
#
CODE="
#include <linux/dma-resv.h>
typeof(dma_resv_get_excl) conftest_dma_resv_get_excl;
struct dma_fence *conftest_dma_resv_get_excl(struct dma_resv *obj) {
return NULL;
}"
compile_check_conftest "$CODE" "LG_DMA_RESV_GET_EXCL_PRESENT" "" "types"
;;
dma_resv_add_fence)
#
# Determine if dma_resv_add_fence function exists.
#
# Changed by commit 047a1b877ed48098bed71fcfb1d4891e1b54441d ("dma-buf:
# remove dma_resv workaround") in v5.18-rc2
# proting in 6.6
#
CODE="
#include <linux/dma-resv.h>
typeof(dma_resv_add_fence) conftest_dma_resv_add_fence;
void conftest_dma_resv_add_fence(struct dma_resv *obj,
struct dma_fence *fence,
enum dma_resv_usage usage) {
return;
}"
compile_check_conftest "$CODE" "LG_DMA_RESV_ADD_FENCE" "" "types"
;;
dma_resv_wait_timeout)
#
# Determine if the dma_resv_wait_timeout function exists.
#
# Changed by commit d3fae3b3daac09961ab871a25093b0ae404282d5 ("dma-buf:
# drop the _rcu postfix on function names v3") in v5.13-rc5
#
CODE="
#include <linux/dma-resv.h>
typeof(dma_resv_wait_timeout) conftest_dma_resv_wait_timeout;
long conftest_dma_resv_wait_timeout(struct dma_resv *obj,
enum dma_resv_usage usage,
bool intr,
unsigned long timeout) {
return (long)0;
}"
compile_check_conftest "$CODE" "LG_DMA_RESV_WAIT_TIMEOUT" "" "types"
;;
dma_buf_ops_vmap_arg_dma_buf)
#
# Determine if the argument type of dma_buf_ops->vmap()
# is dma_buf.
#
# commit 6619ccf1bb1d0ebb071f758111efa83918b216fc ("dma-buf:
# Use struct dma_buf_map in dma_buf_vmap() interfaces") in v5.9-rc8.
#
CODE="
#include <linux/dma-buf.h>
static const struct dma_buf_ops *ops;
typeof(*ops->vmap) conftest_dma_buf_ops_vmap_arg_dma_buf;
void *conftest_dma_buf_ops_vmap_arg_dma_buf(
struct dma_buf *arg) {
void *ret = NULL;
return ret;
}"
compile_check_conftest "$CODE" "LG_DMA_BUF_OPS_VMAP_ARG_DMA_BUF" "" "types"
;;
dma_buf_ops_vmap_arg_dma_buf_map)
#
# Determine if the argument type of dma_buf_ops->vmap()
# has dma_buf_map.
#
# commit 20e76f1a70596590dec32a5d1f598fba04859526 ("dma-buf:
# Use struct dma_buf_map in dma_buf_vunmap() interfaces") in v5.9-rc8.
#
CODE="
#include <linux/dma-buf.h>
static const struct dma_buf_ops *ops;
typeof(*ops->vmap) conftest_dma_buf_ops_vmap_arg_dma_buf;
int conftest_dma_buf_ops_vmap_arg_dma_buf(struct dma_buf *arg,
struct dma_buf_map *map) {
return 0;
}"
compile_check_conftest "$CODE" "LG_DMA_BUF_OPS_VMAP_ARG_DMA_BUF_MAP" "" "types"
;;
mmap_read_lock)
#
# Determine if mmap_read_lock function exists.
#
# Added by commit 9740ca4e95b43b91a4a848694a20d01ba6818f7b
# ("mmap locking API: initial implementation as rwsem wrappers")
# in v5.8-rc1
CODE="
#include <linux/mmap_lock.h>
typeof(mmap_read_lock) conftest_mmap_read_lock;
void conftest_mmap_read_lock(struct mm_struct *mm) {
return;
}"
compile_check_conftest "$CODE" "LG_MMAP_READ_LOCK" "" "types"
;;
drm_dev_fini)
#
# Determine if drm_dev_fini function exists.
#
# Added by commit d33b58d0115e7eee011fddee2d8e25c6a09fb279
# ("drm: Garbage collect drm_dev_fini")
# in v5.6-rc7
CODE="
#include <drm/drm_drv.h>
typeof(drm_dev_fini) conftest_drm_dev_fini;
void conftest_drm_dev_fini(struct drm_device *dev) {
return;
}"
compile_check_conftest "$CODE" "LG_DRM_DEV_FINI" "" "types"
;;
platform_driver_remove_ret_type)
#
# Determine if the return type of platform_driver->remove()
# is void.
#
# commit 0edb555a65d1ef047a9805051c36922b52a38a9d ("platform:
# Make platform_driver::remove() return void") in v6.10-rc2.
#
CODE="
#include <linux/platform_device.h>
static const struct platform_driver *ops;
typeof(*ops->remove) conftest_platform_driver_remove_ret_type;
void conftest_platform_driver_remove_ret_type(
struct platform_device *p) {
return;
}"
compile_check_conftest "$CODE" "LG_PLATFORM_REMOVE_RET_VOID" "" "types"
;;
drm_ioctl_flags)
#
# Determine if drm_ioctl_flags enum contains the DRM_UNLOCKED.
#
# Changed by commit 2798ffcc1d6a788b5769b1fbcf0750dfc06ae98a ("drm:
# Remove locking for legacy ioctls and DRM_UNLOCKED") in v6.7-rc5.
#
CODE="
#include <drm/drm_ioctl.h>
enum drm_ioctl_flags conftest_drm_ioctl_flags(void) {
return DRM_UNLOCKED;
}"
compile_check_conftest "$CODE" "LG_DRM_IOCTL_FLAGS_UNLOCKED" "" "types"
;;
drm_driver_has_gem_dumb_destroy)
#
# Determine if the drm_driver->dumb_destroy exists
#
# by commit 96a7b60f6ddb2bc966fac800c1dd18876a6e3c3f ("drm:
# remove dumb_destroy callback")
# in v6.4
CODE="
#include <drm/drm_drv.h>
int conftest_drm_driver_has_gem_dumb_destroy(void) {
return offsetof(struct drm_driver, gem_dumb_destroy);
}"
compile_check_conftest "$CODE" "LG_DRM_DRIVER_HAS_GEM_DUMB_DESTROY" "" "types"
;;
drm_driver_has_gem_prime_mmap)
#
# Determine if the drm_driver->gem_prime_mmap exists
#
# by commit 0adec22702d497385dbdc52abb165f379a00efba ("drm:
# Remove struct drm_driver.gem_prime_mmap")
# in v6.4
CODE="
#include <drm/drm_drv.h>
int conftest_drm_driver_has_gem_prime_mmap(void) {
return offsetof(struct drm_driver, gem_prime_mmap);
}"
compile_check_conftest "$CODE" "LG_DRM_DRIVER_HAS_GEM_PRIME_MMAP" "" "types"
;;
vm_flags_set)
#
# Determine if vm_flags_set function exists.
#
# Added by commit bc292ab00f6c7a661a8a605c714e8a148f629ef6
# ("mm: introduce vma->vm_flags wrapper functions")
# in v6.2-rc8
CODE="
#include <linux/mm.h>
typeof(vm_flags_set) conftest_vm_flags_set;
void conftest_vm_flags_set(struct vm_area_struct *vma,
vm_flags_t flags) {
return;
}"
compile_check_conftest "$CODE" "LG_VM_FLAGS_SET" "" "types"
;;
drm_gem_object_has_funcs)
#
# Determine if the drm_gem_object has an funcs member.
#
# Added by commit b39b5394fabc79acbaafb26b777fd348c868bf7e
# ("drm/gem: Add drm_gem_object_funcs")
# in v4.20-rc4
CODE="
#include <drm/drm_gem.h>
int conftest_drm_gem_object_has_funcs(void) {
return offsetof(struct drm_gem_object, funcs);
}"
compile_check_conftest "$CODE" "LG_DRM_GEM_OBJECT_HAS_FUNCS" "" "types"
;;
dma_buf_ops_has_cache_sgt_mapping)
#
# Determine if the dma_buf_ops has an cache_sgt_mapping member.
#
# Added by commit f13e143e7444bffc53f5c2904aeed76646da69d6
# ("dma-buf: start caching of sg_table objects v2")
# in v5.2-rc2.
CODE="
#include <linux/dma-buf.h>
int conftest_dma_buf_ops_has_cache_sgt_mapping(void) {
return offsetof(struct dma_buf_ops, cache_sgt_mapping);
}"
compile_check_conftest "$CODE" "LG_DMA_BUF_OPS_HAS_CACHE_SGT_MAPPING" "" "types"
;;
class_create_has_owner_arg)
#
# Determine if class_create has 'owner' arg
#
# The 'owner' arg was removed by commit 1aaba11da9aa7
# ("driver core: class: remove module * from class_create())
# in v6.3-rc3.
#
CODE="
#if defined (LG_LINUX_DEVICE_CLASS_H_PRESENT)
#include <linux/device/class.h>
#else
#include <linux/device.h>
#endif
void conftest_class_create_has_owner_arg(void) {
class_create(
0,
0);
}"
compile_check_conftest "$CODE" "LG_CLASS_CREATE_HAS_OWNER_ARG" "" "types"
;;
class_devnode_has_const)
#
# Determine if class_create has 'owner' arg
#
# The 'owner' arg was removed by commit f62b8e6588f
# ("driver core: make struct class.devnode() take a const *")
# in v6.1-rc7.
#
CODE="
#if defined (LG_LINUX_DEVICE_CLASS_H_PRESENT)
#include <linux/device/class.h>
#else
#include <linux/device.h>
#endif
static char *test_devnode(const struct device *dev, umode_t *mode){}
void conftest_class_devnode_has_const(void) {
struct class * test_class;
test_class->devnode = test_devnode;
}"
compile_check_conftest "$CODE" "LG_CLASS_DEVNODE_HAS_CONST" "" "types"
;;
uts_release)
#
# print the kernel's UTS_RELEASE string.
#
echo "#include <generated/utsrelease.h>
UTS_RELEASE" > conftest$$.c
$CC $CFLAGS -E -P conftest$$.c
rm -f conftest$$.c
;;
# When adding a new conftest entry, please use the correct format for
# specifying the relevant upstream Linux kernel commit. Please
# avoid specifying -rc kernels, and only use SHAs that actually exist
# in the upstream Linux kernel git repository.
#
# Added|Removed|etc by commit <short-sha> ("<commit message") in
# <kernel-version>.
*)
# Unknown test name given
echo "Error: unknown conftest '$1' requested" >&2
exit 1
;;
esac
}
case "$5" in
cc_sanity_check)
#
# Check if the selected compiler can create object files
# in the current environment.
#
VERBOSE=$6
echo "int cc_sanity_check(void) {
return 0;
}" > conftest$$.c
$CC -c conftest$$.c > /dev/null 2>&1
rm -f conftest$$.c
if [ ! -f conftest$$.o ]; then
if [ "$VERBOSE" = "full_output" ]; then
echo "";
fi
if [ "$CC" != "cc" ]; then
echo "The C compiler '$CC' does not appear to be able to"
echo "create object files. Please make sure you have "
echo "your Linux distribution's libc development package"
echo "installed and that '$CC' is a valid C compiler";
echo "name."
else
echo "The C compiler '$CC' does not appear to be able to"
echo "create executables. Please make sure you have "
echo "your Linux distribution's gcc and libc development"
echo "packages installed."
fi
if [ "$VERBOSE" = "full_output" ]; then
echo "";
echo "*** Failed CC sanity check. Bailing out! ***";
echo "";
fi
exit 1
else
rm -f conftest$$.o
exit 0
fi
;;
cc_version_check)
#
# Verify that the same compiler major and minor version is
# used for the kernel and kernel module. A mismatch condition is
# not considered fatal, so this conftest returns a success status
# code, even if it fails. Failure of the test can be distinguished
# by testing for empty (success) versus non-empty (failure) output.
#
# Some gcc version strings that have proven problematic for parsing
# in the past:
#
# gcc.real (GCC) 3.3 (Debian)
# gcc-Version 3.3 (Debian)
# gcc (GCC) 3.1.1 20020606 (Debian prerelease)
# version gcc 3.2.3
#
# As of this writing, GCC uses a version number as x.y.z and below
# are the typical version strings seen with various distributions.
# gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23)
# gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
# gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
# gcc (GCC) 10.2.1 20200723 (Red Hat 10.2.1-1)
# gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
# gcc (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0
# gcc (Debian 8.3.0-6) 8.3.0
# aarch64-linux-gcc.br_real (Buildroot 2020.08-14-ge5a2a90) 9.3.0, GNU ld (GNU Binutils) 2.33.1
#
# In order to extract GCC version correctly for version strings
# like the last one above, we first check for x.y.z and if that
# fails, we fallback to x.y format.
VERBOSE=$6
kernel_compile_h=$OUTPUT/include/generated/compile.h
if [ ! -f ${kernel_compile_h} ]; then
# The kernel's compile.h file is not present, so there
# isn't a convenient way to identify the compiler version