1#!/bin/sh 2 3PATH="${PATH}:/bin:/sbin:/usr/bin" 4 5# make sure we are in the directory containing this script 6SCRIPTDIR=`dirname $0` 7cd $SCRIPTDIR 8 9CC="$1" 10ARCH=$2 11SOURCES=$3 12HEADERS=$SOURCES/include 13OUTPUT=$4 14XEN_PRESENT=1 15PREEMPT_RT_PRESENT=0 16 17# VGX_BUILD parameter defined only for VGX builds (vGPU Host driver) 18# VGX_KVM_BUILD parameter defined only vGPU builds on KVM hypervisor 19# GRID_BUILD parameter defined only for GRID builds (GRID Guest driver) 20# GRID_BUILD_CSP parameter defined only for GRID CSP builds (GRID Guest driver for CSPs) 21 22test_xen() { 23 # 24 # Determine if the target kernel is a Xen kernel. It used to be 25 # sufficient to check for CONFIG_XEN, but the introduction of 26 # modular para-virtualization (CONFIG_PARAVIRT, etc.) and 27 # Xen guest support, it is no longer possible to determine the 28 # target environment at build time. Therefore, if both 29 # CONFIG_XEN and CONFIG_PARAVIRT are present, text_xen() treats 30 # the kernel as a stand-alone kernel. 31 # 32 if ! test_configuration_option CONFIG_XEN || 33 test_configuration_option CONFIG_PARAVIRT; then 34 XEN_PRESENT=0 35 fi 36} 37 38append_conftest() { 39 # 40 # Echo data from stdin: this is a transitional function to make it easier 41 # to port conftests from drivers with parallel conftest generation to 42 # older driver versions 43 # 44 45 while read LINE; do 46 echo ${LINE} 47 done 48} 49 50test_header_presence() { 51 # 52 # Determine if the given header file (which may or may not be 53 # present) is provided by the target kernel. 54 # 55 # Input: 56 # $1: relative file path 57 # 58 # This routine creates an upper case, underscore version of each of the 59 # relative file paths, and uses that as the token to either define or 60 # undefine in a C header file. For example, linux/fence.h becomes 61 # NV_LINUX_FENCE_H_PRESENT, and that is either defined or undefined, in the 62 # output (which goes to stdout, just like the rest of this file). 63 64 TEST_CFLAGS="-E -M $CFLAGS" 65 66 file="$1" 67 file_define=NV_`echo $file | tr '/.\-a-z' '___A-Z'`_PRESENT 68 69 CODE="#include <$file>" 70 71 if echo "$CODE" | $CC $TEST_CFLAGS - > /dev/null 2>&1; then 72 echo "#define $file_define" 73 else 74 # If preprocessing failed, it could have been because the header 75 # file under test is not present, or because it is present but 76 # depends upon the inclusion of other header files. Attempting 77 # preprocessing again with -MG will ignore a missing header file 78 # but will still fail if the header file is present. 79 if echo "$CODE" | $CC $TEST_CFLAGS -MG - > /dev/null 2>&1; then 80 echo "#undef $file_define" 81 else 82 echo "#define $file_define" 83 fi 84 fi 85} 86 87build_cflags() { 88 ISYSTEM=`$CC -print-file-name=include 2> /dev/null` 89 BASE_CFLAGS="-O2 -D__KERNEL__ \ 90-DKBUILD_BASENAME=\"#conftest$$\" -DKBUILD_MODNAME=\"#conftest$$\" \ 91-nostdinc -isystem $ISYSTEM \ 92-Wno-implicit-function-declaration -Wno-strict-prototypes" 93 94 if [ "$OUTPUT" != "$SOURCES" ]; then 95 OUTPUT_CFLAGS="-I$OUTPUT/include2 -I$OUTPUT/include" 96 if [ -f "$OUTPUT/include/generated/autoconf.h" ]; then 97 AUTOCONF_FILE="$OUTPUT/include/generated/autoconf.h" 98 else 99 AUTOCONF_FILE="$OUTPUT/include/linux/autoconf.h" 100 fi 101 else 102 if [ -f "$HEADERS/generated/autoconf.h" ]; then 103 AUTOCONF_FILE="$HEADERS/generated/autoconf.h" 104 else 105 AUTOCONF_FILE="$HEADERS/linux/autoconf.h" 106 fi 107 fi 108 109 test_xen 110 111 if [ "$XEN_PRESENT" != "0" ]; then 112 MACH_CFLAGS="-I$HEADERS/asm/mach-xen" 113 fi 114 115 KERNEL_ARCH="$ARCH" 116 117 if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]; then 118 if [ -d "$SOURCES/arch/x86" ]; then 119 KERNEL_ARCH="x86" 120 fi 121 fi 122 123 SOURCE_HEADERS="$HEADERS" 124 SOURCE_ARCH_HEADERS="$SOURCES/arch/$KERNEL_ARCH/include" 125 OUTPUT_HEADERS="$OUTPUT/include" 126 OUTPUT_ARCH_HEADERS="$OUTPUT/arch/$KERNEL_ARCH/include" 127 128 # Look for mach- directories on this arch, and add it to the list of 129 # includes if that platform is enabled in the configuration file, which 130 # may have a definition like this: 131 # #define CONFIG_ARCH_<MACHUPPERCASE> 1 132 for _mach_dir in `ls -1d $SOURCES/arch/$KERNEL_ARCH/mach-* 2>/dev/null`; do 133 _mach=`echo $_mach_dir | \ 134 sed -e "s,$SOURCES/arch/$KERNEL_ARCH/mach-,," | \ 135 tr 'a-z' 'A-Z'` 136 grep "CONFIG_ARCH_$_mach \+1" $AUTOCONF_FILE > /dev/null 2>&1 137 if [ $? -eq 0 ]; then 138 MACH_CFLAGS="$MACH_CFLAGS -I$_mach_dir/include" 139 fi 140 done 141 142 if [ "$ARCH" = "arm" ]; then 143 MACH_CFLAGS="$MACH_CFLAGS -D__LINUX_ARM_ARCH__=7" 144 fi 145 146 # Add the mach-default includes (only found on x86/older kernels) 147 MACH_CFLAGS="$MACH_CFLAGS -I$SOURCE_HEADERS/asm-$KERNEL_ARCH/mach-default" 148 MACH_CFLAGS="$MACH_CFLAGS -I$SOURCE_ARCH_HEADERS/asm/mach-default" 149 150 CFLAGS="$BASE_CFLAGS $MACH_CFLAGS $OUTPUT_CFLAGS -include $AUTOCONF_FILE" 151 CFLAGS="$CFLAGS -I$SOURCE_HEADERS" 152 CFLAGS="$CFLAGS -I$SOURCE_HEADERS/uapi" 153 CFLAGS="$CFLAGS -I$SOURCE_HEADERS/xen" 154 CFLAGS="$CFLAGS -I$OUTPUT_HEADERS/generated/uapi" 155 CFLAGS="$CFLAGS -I$SOURCE_ARCH_HEADERS" 156 CFLAGS="$CFLAGS -I$SOURCE_ARCH_HEADERS/uapi" 157 CFLAGS="$CFLAGS -I$OUTPUT_ARCH_HEADERS/generated" 158 CFLAGS="$CFLAGS -I$OUTPUT_ARCH_HEADERS/generated/uapi" 159 160 if [ -n "$BUILD_PARAMS" ]; then 161 CFLAGS="$CFLAGS -D$BUILD_PARAMS" 162 fi 163 164 # Check if gcc supports asm goto and set CC_HAVE_ASM_GOTO if it does. 165 # Older kernels perform this check and set this flag in Kbuild, and since 166 # conftest.sh runs outside of Kbuild it ends up building without this flag. 167 # Starting with commit e9666d10a5677a494260d60d1fa0b73cc7646eb3 this test 168 # is done within Kconfig, and the preprocessor flag is no longer needed. 169 170 GCC_GOTO_SH="$SOURCES/build/gcc-goto.sh" 171 172 if [ -f "$GCC_GOTO_SH" ]; then 173 # Newer versions of gcc-goto.sh don't print anything on success, but 174 # this is okay, since it's no longer necessary to set CC_HAVE_ASM_GOTO 175 # based on the output of those versions of gcc-goto.sh. 176 if [ `/bin/sh "$GCC_GOTO_SH" "$CC"` = "y" ]; then 177 CFLAGS="$CFLAGS -DCC_HAVE_ASM_GOTO" 178 fi 179 fi 180 181 # 182 # If CONFIG_HAVE_FENTRY is enabled and gcc supports -mfentry flags then set 183 # CC_USING_FENTRY and add -mfentry into cflags. 184 # 185 # linux/ftrace.h file indirectly gets included into the conftest source and 186 # fails to get compiled, because conftest.sh runs outside of Kbuild it ends 187 # up building without -mfentry and CC_USING_FENTRY flags. 188 # 189 grep "CONFIG_HAVE_FENTRY \+1" $AUTOCONF_FILE > /dev/null 2>&1 190 if [ $? -eq 0 ]; then 191 echo "" > conftest$$.c 192 193 $CC -mfentry -c -x c conftest$$.c > /dev/null 2>&1 194 rm -f conftest$$.c 195 196 if [ -f conftest$$.o ]; then 197 rm -f conftest$$.o 198 199 CFLAGS="$CFLAGS -mfentry -DCC_USING_FENTRY" 200 fi 201 fi 202} 203 204CONFTEST_PREAMBLE="#include \"conftest/headers.h\" 205 #if defined(NV_LINUX_KCONFIG_H_PRESENT) 206 #include <linux/kconfig.h> 207 #endif 208 #if defined(NV_GENERATED_AUTOCONF_H_PRESENT) 209 #include <generated/autoconf.h> 210 #else 211 #include <linux/autoconf.h> 212 #endif 213 #if defined(CONFIG_XEN) && \ 214 defined(CONFIG_XEN_INTERFACE_VERSION) && !defined(__XEN_INTERFACE_VERSION__) 215 #define __XEN_INTERFACE_VERSION__ CONFIG_XEN_INTERFACE_VERSION 216 #endif 217 #if defined(CONFIG_KASAN) && defined(CONFIG_ARM64) 218 #if defined(CONFIG_KASAN_SW_TAGS) 219 #define KASAN_SHADOW_SCALE_SHIFT 4 220 #else 221 #define KASAN_SHADOW_SCALE_SHIFT 3 222 #endif 223 #endif" 224 225test_configuration_option() { 226 # 227 # Check to see if the given configuration option is defined 228 # 229 230 get_configuration_option $1 >/dev/null 2>&1 231 232 return $? 233 234} 235 236set_configuration() { 237 # 238 # Set a specific configuration option. This function is called to always 239 # enable a configuration, in order to verify whether the test code for that 240 # configuration is no longer required and the corresponding 241 # conditionally-compiled code in the driver can be removed. 242 # 243 DEF="$1" 244 245 if [ "$3" = "" ] 246 then 247 VAL="" 248 CAT="$2" 249 else 250 VAL="$2" 251 CAT="$3" 252 fi 253 254 echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}" 255} 256 257unset_configuration() { 258 # 259 # Un-set a specific configuration option. This function is called to 260 # always disable a configuration, in order to verify whether the test 261 # code for that configuration is no longer required and the corresponding 262 # conditionally-compiled code in the driver can be removed. 263 # 264 DEF="$1" 265 CAT="$2" 266 267 echo "#undef ${DEF}" | append_conftest "${CAT}" 268} 269 270compile_check_conftest() { 271 # 272 # Compile the current conftest C file and check+output the result 273 # 274 CODE="$1" 275 DEF="$2" 276 VAL="$3" 277 CAT="$4" 278 279 echo "$CONFTEST_PREAMBLE 280 $CODE" > conftest$$.c 281 282 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 283 rm -f conftest$$.c 284 285 if [ -f conftest$$.o ]; then 286 rm -f conftest$$.o 287 if [ "${CAT}" = "functions" ]; then 288 # 289 # The logic for "functions" compilation tests is inverted compared to 290 # other compilation steps: if the function is present, the code 291 # snippet will fail to compile because the function call won't match 292 # the prototype. If the function is not present, the code snippet 293 # will produce an object file with the function as an unresolved 294 # symbol. 295 # 296 echo "#undef ${DEF}" | append_conftest "${CAT}" 297 else 298 echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}" 299 fi 300 return 301 else 302 if [ "${CAT}" = "functions" ]; then 303 echo "#define ${DEF} ${VAL}" | append_conftest "${CAT}" 304 else 305 echo "#undef ${DEF}" | append_conftest "${CAT}" 306 fi 307 return 308 fi 309} 310 311export_symbol_present_conftest() { 312 # 313 # Check Module.symvers to see whether the given symbol is present. 314 # 315 316 SYMBOL="$1" 317 TAB=' ' 318 319 if grep -e "${TAB}${SYMBOL}${TAB}.*${TAB}EXPORT_SYMBOL.*\$" \ 320 "$OUTPUT/Module.symvers" >/dev/null 2>&1; then 321 echo "#define NV_IS_EXPORT_SYMBOL_PRESENT_$SYMBOL 1" | 322 append_conftest "symbols" 323 else 324 # May be a false negative if Module.symvers is absent or incomplete, 325 # or if the Module.symvers format changes. 326 echo "#define NV_IS_EXPORT_SYMBOL_PRESENT_$SYMBOL 0" | 327 append_conftest "symbols" 328 fi 329} 330 331export_symbol_gpl_conftest() { 332 # 333 # Check Module.symvers to see whether the given symbol is present and its 334 # export type is GPL-only (including deprecated GPL-only symbols). 335 # 336 337 SYMBOL="$1" 338 TAB=' ' 339 340 if grep -e "${TAB}${SYMBOL}${TAB}.*${TAB}EXPORT_\(UNUSED_\)*SYMBOL_GPL\$" \ 341 "$OUTPUT/Module.symvers" >/dev/null 2>&1; then 342 echo "#define NV_IS_EXPORT_SYMBOL_GPL_$SYMBOL 1" | 343 append_conftest "symbols" 344 else 345 # May be a false negative if Module.symvers is absent or incomplete, 346 # or if the Module.symvers format changes. 347 echo "#define NV_IS_EXPORT_SYMBOL_GPL_$SYMBOL 0" | 348 append_conftest "symbols" 349 fi 350} 351 352get_configuration_option() { 353 # 354 # Print the value of given configuration option, if defined 355 # 356 RET=1 357 OPTION=$1 358 359 OLD_FILE="linux/autoconf.h" 360 NEW_FILE="generated/autoconf.h" 361 FILE="" 362 363 if [ -f $HEADERS/$NEW_FILE -o -f $OUTPUT/include/$NEW_FILE ]; then 364 FILE=$NEW_FILE 365 elif [ -f $HEADERS/$OLD_FILE -o -f $OUTPUT/include/$OLD_FILE ]; then 366 FILE=$OLD_FILE 367 fi 368 369 if [ -n "$FILE" ]; then 370 # 371 # We are looking at a configured source tree; verify 372 # that its configuration includes the given option 373 # via a compile check, and print the option's value. 374 # 375 376 if [ -f $HEADERS/$FILE ]; then 377 INCLUDE_DIRECTORY=$HEADERS 378 elif [ -f $OUTPUT/include/$FILE ]; then 379 INCLUDE_DIRECTORY=$OUTPUT/include 380 else 381 return 1 382 fi 383 384 echo "#include <$FILE> 385 #ifndef $OPTION 386 #error $OPTION not defined! 387 #endif 388 389 $OPTION 390 " > conftest$$.c 391 392 $CC -E -P -I$INCLUDE_DIRECTORY -o conftest$$ conftest$$.c > /dev/null 2>&1 393 394 if [ -e conftest$$ ]; then 395 tr -d '\r\n\t ' < conftest$$ 396 RET=$? 397 fi 398 399 rm -f conftest$$.c conftest$$ 400 else 401 CONFIG=$OUTPUT/.config 402 if [ -f $CONFIG ] && grep "^$OPTION=" $CONFIG; then 403 grep "^$OPTION=" $CONFIG | cut -f 2- -d "=" 404 RET=$? 405 fi 406 fi 407 408 return $RET 409 410} 411 412check_for_ib_peer_memory_symbols() { 413 kernel_dir="$1" 414 module_symvers="${kernel_dir}/Module.symvers" 415 416 sym_ib_register="ib_register_peer_memory_client" 417 sym_ib_unregister="ib_unregister_peer_memory_client" 418 tab=' ' 419 420 # Return 0 for true(no errors), 1 for false 421 if [ ! -f "${module_symvers}" ]; then 422 return 1 423 fi 424 425 if grep -e "${tab}${sym_ib_register}${tab}.*${tab}EXPORT_SYMBOL.*\$" \ 426 "${module_symvers}" > /dev/null 2>&1 && 427 grep -e "${tab}${sym_ib_unregister}${tab}.*${tab}EXPORT_SYMBOL.*\$" \ 428 "${module_symvers}" > /dev/null 2>&1; then 429 return 0 430 else 431 return 1 432 fi 433} 434 435compile_test() { 436 case "$1" in 437 set_memory_uc) 438 # 439 # Determine if the set_memory_uc() function is present. 440 # It does not exist on all architectures. 441 # 442 CODE=" 443 #include <linux/types.h> 444 #if defined(NV_ASM_SET_MEMORY_H_PRESENT) 445 #if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT) 446 #include <asm/pgtable_types.h> 447 #endif 448 #if defined(NV_ASM_PAGE_H_PRESENT) 449 #include <asm/page.h> 450 #endif 451 #include <asm/set_memory.h> 452 #else 453 #include <asm/cacheflush.h> 454 #endif 455 void conftest_set_memory_uc(void) { 456 set_memory_uc(); 457 }" 458 459 compile_check_conftest "$CODE" "NV_SET_MEMORY_UC_PRESENT" "" "functions" 460 ;; 461 462 set_memory_array_uc) 463 # 464 # Determine if the set_memory_array_uc() function is present. 465 # It does not exist on all architectures. 466 # 467 CODE=" 468 #include <linux/types.h> 469 #if defined(NV_ASM_SET_MEMORY_H_PRESENT) 470 #if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT) 471 #include <asm/pgtable_types.h> 472 #endif 473 #if defined(NV_ASM_PAGE_H_PRESENT) 474 #include <asm/page.h> 475 #endif 476 #include <asm/set_memory.h> 477 #else 478 #include <asm/cacheflush.h> 479 #endif 480 void conftest_set_memory_array_uc(void) { 481 set_memory_array_uc(); 482 }" 483 484 compile_check_conftest "$CODE" "NV_SET_MEMORY_ARRAY_UC_PRESENT" "" "functions" 485 ;; 486 487 sysfs_slab_unlink) 488 # 489 # Determine if the sysfs_slab_unlink() function is present. 490 # 491 # This test is useful to check for the presence a fix for the deferred 492 # kmem_cache destroy feature (see nvbug: 2543505). 493 # 494 # Added by commit d50d82faa0c9 ("slub: fix failure when we delete and 495 # create a slab cache") in 4.18 (2018-06-27). 496 # 497 CODE=" 498 #include <linux/slab.h> 499 void conftest_sysfs_slab_unlink(void) { 500 sysfs_slab_unlink(); 501 }" 502 503 compile_check_conftest "$CODE" "NV_SYSFS_SLAB_UNLINK_PRESENT" "" "functions" 504 ;; 505 506 list_is_first) 507 # 508 # Determine if the list_is_first() function is present. 509 # 510 # Added by commit 70b44595eafe ("mm, compaction: use free lists 511 # to quickly locate a migration source") in 5.1 (2019-03-05) 512 # 513 CODE=" 514 #include <linux/list.h> 515 void conftest_list_is_first(void) { 516 list_is_first(); 517 }" 518 519 compile_check_conftest "$CODE" "NV_LIST_IS_FIRST_PRESENT" "" "functions" 520 ;; 521 522 set_pages_uc) 523 # 524 # Determine if the set_pages_uc() function is present. 525 # It does not exist on all architectures. 526 # 527 CODE=" 528 #include <linux/types.h> 529 #if defined(NV_ASM_SET_MEMORY_H_PRESENT) 530 #if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT) 531 #include <asm/pgtable_types.h> 532 #endif 533 #if defined(NV_ASM_PAGE_H_PRESENT) 534 #include <asm/page.h> 535 #endif 536 #include <asm/set_memory.h> 537 #else 538 #include <asm/cacheflush.h> 539 #endif 540 void conftest_set_pages_uc(void) { 541 set_pages_uc(); 542 }" 543 544 compile_check_conftest "$CODE" "NV_SET_PAGES_UC_PRESENT" "" "functions" 545 ;; 546 547 set_pages_array_uc) 548 # 549 # Determine if the set_pages_array_uc() function is present. 550 # It does not exist on all architectures. 551 # 552 # set_pages_array_uc() was added by commit 553 # 0f3507555f6fa4acbc85a646d6e8766230db38fc ("x86, CPA: Add 554 # set_pages_arrayuc and set_pages_array_wb") in v2.6.30-rc1 (Thu Mar 555 # 19 14:51:15 2009) 556 # 557 CODE=" 558 #include <linux/types.h> 559 #if defined(NV_ASM_SET_MEMORY_H_PRESENT) 560 #if defined(NV_ASM_PGTABLE_TYPES_H_PRESENT) 561 #include <asm/pgtable_types.h> 562 #endif 563 #if defined(NV_ASM_PAGE_H_PRESENT) 564 #include <asm/page.h> 565 #endif 566 #include <asm/set_memory.h> 567 #else 568 #include <asm/cacheflush.h> 569 #endif 570 void conftest_set_pages_array_uc(void) { 571 set_pages_array_uc(); 572 }" 573 574 compile_check_conftest "$CODE" "NV_SET_PAGES_ARRAY_UC_PRESENT" "" "functions" 575 ;; 576 577 flush_cache_all) 578 # 579 # Determine if flush_cache_all() function is present 580 # 581 # flush_cache_all() was removed by commit id 582 # 68234df4ea79 ("arm64: kill flush_cache_all()") in 4.2 (2015-04-20) 583 # for aarch64 584 # 585 CODE=" 586 #include <asm/cacheflush.h> 587 int conftest_flush_cache_all(void) { 588 return flush_cache_all(); 589 }" 590 compile_check_conftest "$CODE" "NV_FLUSH_CACHE_ALL_PRESENT" "" "functions" 591 ;; 592 593 pci_get_domain_bus_and_slot) 594 # 595 # Determine if the pci_get_domain_bus_and_slot() function 596 # is present. 597 # 598 # Added by commit 3c299dc22635 ("PCI: add 599 # pci_get_domain_bus_and_slot function") in 2.6.33 but aarch64 600 # support was added by commit d1e6dc91b532 601 # ("arm64: Add architectural support for PCI") in 3.18-rc1 602 # 603 CODE=" 604 #include <linux/pci.h> 605 void conftest_pci_get_domain_bus_and_slot(void) { 606 pci_get_domain_bus_and_slot(); 607 }" 608 609 compile_check_conftest "$CODE" "NV_PCI_GET_DOMAIN_BUS_AND_SLOT_PRESENT" "" "functions" 610 ;; 611 612 pci_bus_address) 613 # 614 # Determine if the pci_bus_address() function is 615 # present. 616 # 617 # Added by commit 06cf56e497c8 ("PCI: Add pci_bus_address() to 618 # get bus address of a BAR") in v3.14 619 # 620 CODE=" 621 #include <linux/pci.h> 622 void conftest_pci_bus_address(void) { 623 pci_bus_address(); 624 }" 625 626 compile_check_conftest "$CODE" "NV_PCI_BUS_ADDRESS_PRESENT" "" "functions" 627 ;; 628 629 hash__remap_4k_pfn) 630 # 631 # Determine if the hash__remap_4k_pfn() function is 632 # present. 633 # 634 # Added by commit 6cc1a0ee4ce2 ("powerpc/mm/radix: Add radix 635 # callback for pmd accessors") in v4.7 (committed 2016-04-29). 636 # Present only in arch/powerpc 637 # 638 CODE=" 639 #if defined(NV_ASM_BOOK3S_64_HASH_64K_H_PRESENT) 640 #include <linux/mm.h> 641 #include <asm/book3s/64/hash-64k.h> 642 #endif 643 void conftest_hash__remap_4k_pfn(void) { 644 hash__remap_4k_pfn(); 645 }" 646 647 compile_check_conftest "$CODE" "NV_HASH__REMAP_4K_PFN_PRESENT" "" "functions" 648 ;; 649 650 register_cpu_notifier) 651 # 652 # Determine if register_cpu_notifier() is present 653 # 654 # Removed by commit 530e9b76ae8f ("cpu/hotplug: Remove obsolete 655 # cpu hotplug register/unregister functions") in v4.10 656 # (2016-12-21) 657 # 658 CODE=" 659 #include <linux/cpu.h> 660 void conftest_register_cpu_notifier(void) { 661 register_cpu_notifier(); 662 }" 663 compile_check_conftest "$CODE" "NV_REGISTER_CPU_NOTIFIER_PRESENT" "" "functions" 664 ;; 665 666 cpuhp_setup_state) 667 # 668 # Determine if cpuhp_setup_state() is present 669 # 670 # Added by commit 5b7aa87e0482 ("cpu/hotplug: Implement 671 # setup/removal interface") in v4.6 (commited 2016-02-26) 672 # 673 # It is used as a replacement for register_cpu_notifier 674 CODE=" 675 #include <linux/cpu.h> 676 void conftest_cpuhp_setup_state(void) { 677 cpuhp_setup_state(); 678 }" 679 compile_check_conftest "$CODE" "NV_CPUHP_SETUP_STATE_PRESENT" "" "functions" 680 ;; 681 682 ioremap_cache) 683 # 684 # Determine if the ioremap_cache() function is present. 685 # It does not exist on all architectures. 686 # 687 CODE=" 688 #include <asm/io.h> 689 void conftest_ioremap_cache(void) { 690 ioremap_cache(); 691 }" 692 693 compile_check_conftest "$CODE" "NV_IOREMAP_CACHE_PRESENT" "" "functions" 694 ;; 695 696 ioremap_wc) 697 # 698 # Determine if the ioremap_wc() function is present. 699 # It does not exist on all architectures. 700 # 701 CODE=" 702 #include <asm/io.h> 703 void conftest_ioremap_wc(void) { 704 ioremap_wc(); 705 }" 706 707 compile_check_conftest "$CODE" "NV_IOREMAP_WC_PRESENT" "" "functions" 708 ;; 709 710 ioremap_driver_hardened) 711 # 712 # Determine if the ioremap_driver_hardened() function is present. 713 # It does not exist on all architectures. 714 # TODO: Update the commit ID once the API is upstreamed. 715 # 716 CODE=" 717 #include <asm/io.h> 718 void conftest_ioremap_driver_hardened(void) { 719 ioremap_driver_hardened(); 720 }" 721 722 compile_check_conftest "$CODE" "NV_IOREMAP_DRIVER_HARDENED_PRESENT" "" "functions" 723 ;; 724 725 ioremap_driver_hardened_wc) 726 # 727 # Determine if the ioremap_driver_hardened_wc() function is present. 728 # It does not exist on all architectures. 729 # TODO: Update the commit ID once the API is upstreamed. 730 # 731 CODE=" 732 #include <asm/io.h> 733 void conftest_ioremap_driver_hardened_wc(void) { 734 ioremap_driver_hardened_wc(); 735 }" 736 737 compile_check_conftest "$CODE" "NV_IOREMAP_DRIVER_HARDENED_WC_PRESENT" "" "functions" 738 ;; 739 740 ioremap_cache_shared) 741 # 742 # Determine if the ioremap_cache_shared() function is present. 743 # It does not exist on all architectures. 744 # TODO: Update the commit ID once the API is upstreamed. 745 # 746 CODE=" 747 #include <asm/io.h> 748 void conftest_ioremap_cache_shared(void) { 749 ioremap_cache_shared(); 750 }" 751 752 compile_check_conftest "$CODE" "NV_IOREMAP_CACHE_SHARED_PRESENT" "" "functions" 753 ;; 754 dom0_kernel_present) 755 # Add config parameter if running on DOM0. 756 if [ -n "$VGX_BUILD" ]; then 757 echo "#define NV_DOM0_KERNEL_PRESENT" | append_conftest "generic" 758 else 759 echo "#undef NV_DOM0_KERNEL_PRESENT" | append_conftest "generic" 760 fi 761 return 762 ;; 763 764 nvidia_vgpu_kvm_build) 765 # Add config parameter if running on KVM host. 766 if [ -n "$VGX_KVM_BUILD" ]; then 767 echo "#define NV_VGPU_KVM_BUILD" | append_conftest "generic" 768 else 769 echo "#undef NV_VGPU_KVM_BUILD" | append_conftest "generic" 770 fi 771 return 772 ;; 773 774 vfio_register_notifier) 775 # 776 # Check number of arguments required. 777 # 778 # New parameters added by commit 22195cbd3451 ("vfio: 779 # vfio_register_notifier: classify iommu notifier") in v4.10 780 # 781 echo "$CONFTEST_PREAMBLE 782 #include <linux/vfio.h> 783 int conftest_vfio_register_notifier(void) { 784 return vfio_register_notifier((struct device *) NULL, (struct notifier_block *) NULL); 785 }" > conftest$$.c 786 787 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 788 rm -f conftest$$.c 789 790 if [ -f conftest$$.o ]; then 791 echo "#define NV_VFIO_NOTIFIER_ARGUMENT_COUNT 2" | append_conftest "functions" 792 rm -f conftest$$.o 793 return 794 else 795 echo "#define NV_VFIO_NOTIFIER_ARGUMENT_COUNT 4" | append_conftest "functions" 796 return 797 fi 798 ;; 799 800 vfio_info_add_capability_has_cap_type_id_arg) 801 # 802 # Check if vfio_info_add_capability() has cap_type_id parameter. 803 # 804 # Removed by commit dda01f787df9 ("vfio: Simplify capability 805 # helper") in v4.16 (2017-12-12) 806 # 807 CODE=" 808 #include <linux/vfio.h> 809 int vfio_info_add_capability(struct vfio_info_cap *caps, 810 int cap_type_id, 811 void *cap_type) { 812 return 0; 813 }" 814 815 compile_check_conftest "$CODE" "NV_VFIO_INFO_ADD_CAPABILITY_HAS_CAP_TYPE_ID_ARGS" "" "types" 816 ;; 817 818 nvidia_grid_build) 819 if [ -n "$GRID_BUILD" ]; then 820 echo "#define NV_GRID_BUILD" | append_conftest "generic" 821 else 822 echo "#undef NV_GRID_BUILD" | append_conftest "generic" 823 fi 824 return 825 ;; 826 827 nvidia_grid_csp_build) 828 if [ -n "$GRID_BUILD_CSP" ]; then 829 echo "#define NV_GRID_BUILD_CSP $GRID_BUILD_CSP" | append_conftest "generic" 830 else 831 echo "#undef NV_GRID_BUILD_CSP" | append_conftest "generic" 832 fi 833 return 834 ;; 835 836 vm_fault_has_address) 837 # 838 # Determine if the 'vm_fault' structure has an 'address', or a 839 # 'virtual_address' field. The .virtual_address field was 840 # effectively renamed to .address: 841 # 842 # 'address' added by commit 82b0f8c39a38 ("mm: join 843 # struct fault_env and vm_fault") in v4.10 (2016-12-14) 844 # 845 # 'virtual_address' removed by commit 1a29d85eb0f1 ("mm: use 846 # vmf->address instead of of vmf->virtual_address") in v4.10 847 # (2016-12-14) 848 # 849 CODE=" 850 #include <linux/mm.h> 851 int conftest_vm_fault_has_address(void) { 852 return offsetof(struct vm_fault, address); 853 }" 854 855 compile_check_conftest "$CODE" "NV_VM_FAULT_HAS_ADDRESS" "" "types" 856 ;; 857 858 kmem_cache_has_kobj_remove_work) 859 # 860 # Determine if the 'kmem_cache' structure has 'kobj_remove_work'. 861 # 862 # 'kobj_remove_work' was added by commit 3b7b314053d02 ("slub: make 863 # sysfs file removal asynchronous") in v4.12 (2017-06-23). This 864 # commit introduced a race between kmem_cache destroy and create 865 # which we need to workaround in our driver (see nvbug: 2543505). 866 # Also see comment for sysfs_slab_unlink conftest. 867 # 868 CODE=" 869 #include <linux/mm.h> 870 #include <linux/slab.h> 871 #include <linux/slub_def.h> 872 int conftest_kmem_cache_has_kobj_remove_work(void) { 873 return offsetof(struct kmem_cache, kobj_remove_work); 874 }" 875 876 compile_check_conftest "$CODE" "NV_KMEM_CACHE_HAS_KOBJ_REMOVE_WORK" "" "types" 877 ;; 878 879 mdev_uuid) 880 # 881 # Determine if mdev_uuid() function is present or not 882 # 883 # Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device 884 # private and abstract interfaces") in v4.10 885 # 886 CODE=" 887 #include <linux/pci.h> 888 #include <linux/mdev.h> 889 void conftest_mdev_uuid() { 890 mdev_uuid(); 891 }" 892 893 compile_check_conftest "$CODE" "NV_MDEV_UUID_PRESENT" "" "functions" 894 895 # 896 # Determine if mdev_uuid() returns 'const guid_t *'. 897 # 898 # mdev_uuid() function prototype updated to return 'const guid_t *' 899 # by commit 278bca7f318e ("vfio-mdev: Switch to use new generic UUID 900 # API") in v5.1 (2019-01-10). 901 # 902 CODE=" 903 #include <linux/pci.h> 904 #include <linux/mdev.h> 905 const guid_t *conftest_mdev_uuid_return_guid_ptr(struct mdev_device *mdev) { 906 return mdev_uuid(mdev); 907 }" 908 909 compile_check_conftest "$CODE" "NV_MDEV_UUID_RETURN_GUID_PTR" "" "types" 910 ;; 911 912 mdev_dev) 913 # 914 # Determine if mdev_dev() function is present or not 915 # 916 # Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device 917 # private and abstract interfaces") in v4.10 918 # 919 CODE=" 920 #include <linux/pci.h> 921 #include <linux/mdev.h> 922 void conftest_mdev_dev() { 923 mdev_dev(); 924 }" 925 926 compile_check_conftest "$CODE" "NV_MDEV_DEV_PRESENT" "" "functions" 927 ;; 928 929 mdev_get_type_group_id) 930 # 931 # Determine if mdev_get_type_group_id() function is present or not 932 # 933 # Added by commit 15fcc44be0c7a ("vfio/mdev: Add 934 # mdev/mtype_get_type_group_id()") in v5.13 935 # 936 CODE=" 937 #include <linux/pci.h> 938 #include <linux/mdev.h> 939 void conftest_mdev_get_type_group_id() { 940 mdev_get_type_group_id(); 941 }" 942 943 compile_check_conftest "$CODE" "NV_MDEV_GET_TYPE_GROUP_ID_PRESENT" "" "functions" 944 ;; 945 946 vfio_device_mig_state) 947 # 948 # Determine if vfio_device_mig_state enum is present or not 949 # 950 # Added by commit 115dcec65f61d ("vfio: Define device 951 # migration protocol v2") in v5.18 952 # 953 CODE=" 954 #include <linux/pci.h> 955 #include <linux/vfio.h> 956 enum vfio_device_mig_state device_state; 957 " 958 959 compile_check_conftest "$CODE" "NV_VFIO_DEVICE_MIG_STATE_PRESENT" "" "types" 960 ;; 961 962 vfio_migration_ops) 963 # 964 # Determine if vfio_migration_ops struct is present or not 965 # 966 # Added by commit 6e97eba8ad874 ("vfio: Split migration ops 967 # from main device ops") in v6.0 968 # 969 CODE=" 970 #include <linux/pci.h> 971 #include <linux/vfio.h> 972 struct vfio_migration_ops mig_ops; 973 " 974 975 compile_check_conftest "$CODE" "NV_VFIO_MIGRATION_OPS_PRESENT" "" "types" 976 ;; 977 978 vfio_precopy_info) 979 # 980 # Determine if vfio_precopy_info struct is present or not 981 # 982 # Added by commit 4db52602a6074 ("vfio: Extend the device migration 983 # protocol with PRE_COPY" in v6.2 984 # 985 CODE=" 986 #include <linux/vfio.h> 987 struct vfio_precopy_info precopy_info; 988 " 989 990 compile_check_conftest "$CODE" "NV_VFIO_PRECOPY_INFO_PRESENT" "" "types" 991 ;; 992 993 vfio_log_ops) 994 # 995 # Determine if vfio_log_ops struct is present or not 996 # 997 # Added by commit 80c4b92a2dc48 ("vfio: Introduce the DMA 998 # logging feature support") in v6.1 999 # 1000 CODE=" 1001 #include <linux/pci.h> 1002 #include <linux/vfio.h> 1003 struct vfio_log_ops log_ops; 1004 " 1005 1006 compile_check_conftest "$CODE" "NV_VFIO_LOG_OPS_PRESENT" "" "types" 1007 ;; 1008 1009 vfio_migration_ops_has_migration_get_data_size) 1010 # 1011 # Determine if vfio_migration_ops struct has .migration_get_data_size field. 1012 # 1013 # Added by commit in 4e016f969529f ("vfio: Add an option to get migration 1014 # data size") in v6.2 kernel. 1015 # 1016 CODE=" 1017 #include <linux/pci.h> 1018 #include <linux/vfio.h> 1019 int conftest_mdev_vfio_migration_ops_has_migration_get_data_size(void) { 1020 return offsetof(struct vfio_migration_ops, migration_get_data_size); 1021 }" 1022 1023 compile_check_conftest "$CODE" "NV_VFIO_MIGRATION_OPS_HAS_MIGRATION_GET_DATA_SIZE" "" "types" 1024 ;; 1025 1026 mdev_parent_ops) 1027 # 1028 # Determine if the struct mdev_parent_ops type is present. 1029 # 1030 # Added by commit 42930553a7c1 ("vfio-mdev: de-polute the 1031 # namespace, rename parent_device & parent_ops") in v4.10 1032 # 1033 CODE=" 1034 #include <linux/pci.h> 1035 #include <linux/mdev.h> 1036 struct mdev_parent_ops conftest_mdev_parent_ops; 1037 " 1038 1039 compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_STRUCT_PRESENT" "" "types" 1040 ;; 1041 1042 mdev_parent) 1043 # 1044 # Determine if the struct mdev_parent type is present. 1045 # 1046 # Added by commit 89345d5177aa ("vfio/mdev: embedd struct mdev_parent in 1047 # the parent data structure") in v6.1 1048 # 1049 CODE=" 1050 #include <linux/pci.h> 1051 #include <linux/mdev.h> 1052 struct mdev_parent conftest_mdev_parent; 1053 " 1054 1055 compile_check_conftest "$CODE" "NV_MDEV_PARENT_STRUCT_PRESENT" "" "types" 1056 ;; 1057 1058 mdev_parent_dev) 1059 # 1060 # Determine if mdev_parent_dev() function is present or not 1061 # 1062 # Added by commit 9372e6feaafb ("vfio-mdev: Make mdev_parent 1063 # private") in v4.10 1064 # 1065 CODE=" 1066 #include <linux/pci.h> 1067 #include <linux/mdev.h> 1068 void conftest_mdev_parent_dev() { 1069 mdev_parent_dev(); 1070 }" 1071 1072 compile_check_conftest "$CODE" "NV_MDEV_PARENT_DEV_PRESENT" "" "functions" 1073 ;; 1074 1075 vfio_free_device) 1076 # 1077 # Determine if vfio_free_device() function is present or not 1078 # 1079 # Removed by commit 913447d06f03 ("vfio: Remove vfio_free_device") 1080 # in v6.2 1081 # 1082 CODE=" 1083 #include <linux/pci.h> 1084 #include <linux/vfio.h> 1085 void conftest_vfio_free_device() { 1086 vfio_free_device(); 1087 }" 1088 1089 compile_check_conftest "$CODE" "NV_VFIO_FREE_DEVICE_PRESENT" "" "functions" 1090 ;; 1091 1092 mdev_from_dev) 1093 # 1094 # Determine if mdev_from_dev() function is present or not. 1095 # 1096 # Added by commit 99e3123e3d72 ("vfio-mdev: Make mdev_device 1097 # private and abstract interfaces") in v4.10 (2016-12-30) 1098 # 1099 CODE=" 1100 #include <linux/pci.h> 1101 #include <linux/mdev.h> 1102 void conftest_mdev_from_dev() { 1103 mdev_from_dev(); 1104 }" 1105 1106 compile_check_conftest "$CODE" "NV_MDEV_FROM_DEV_PRESENT" "" "functions" 1107 ;; 1108 1109 mdev_set_iommu_device) 1110 # 1111 # Determine if mdev_set_iommu_device() function is present or not. 1112 # 1113 # Added by commit 8ac13175cbe9 ("vfio/mdev: Add iommu related member 1114 # in mdev_device) in v5.1 (2019-04-12) 1115 # 1116 CODE=" 1117 #include <linux/pci.h> 1118 #include <linux/mdev.h> 1119 void conftest_mdev_set_iommu_device() { 1120 mdev_set_iommu_device(); 1121 }" 1122 1123 compile_check_conftest "$CODE" "NV_MDEV_SET_IOMMU_DEVICE_PRESENT" "" "functions" 1124 ;; 1125 1126 mdev_parent_ops_has_open_device) 1127 # Determine if 'mdev_parent_ops' structure has a 'open_device' 1128 # field. 1129 # 1130 # Added by commit 2fd585f4ed9d ("vfio: Provide better generic support 1131 # for open/release vfio_device_ops") in 5.15 (2021-08-05) 1132 # 1133 CODE=" 1134 #include <linux/pci.h> 1135 #include <linux/mdev.h> 1136 int conftest_mdev_parent_ops_has_open_device(void) { 1137 return offsetof(struct mdev_parent_ops, open_device); 1138 }" 1139 1140 compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_HAS_OPEN_DEVICE" "" "types" 1141 ;; 1142 1143 mdev_parent_ops_has_device_driver) 1144 # 1145 # Determine if 'mdev_parent_ops' structure has 'device_driver' field. 1146 # 1147 # Added by commit 88a21f265ce5 ("vfio/mdev: Allow the mdev_parent_ops 1148 # to specify the device driver to bind) in v5.14 (2021-06-17) 1149 # 1150 CODE=" 1151 #include <linux/pci.h> 1152 #include <linux/mdev.h> 1153 int conftest_mdev_parent_ops_has_device_driver(void) { 1154 return offsetof(struct mdev_parent_ops, device_driver); 1155 }" 1156 1157 compile_check_conftest "$CODE" "NV_MDEV_PARENT_OPS_HAS_DEVICE_DRIVER" "" "types" 1158 ;; 1159 1160 mdev_driver_has_supported_type_groups) 1161 # 1162 # Determine if 'mdev_driver' structure has 'supported_type_groups' field. 1163 # 1164 # Added by commit 6b42f491e17c ("vfio/mdev: Remove mdev_parent_ops) 1165 # in v5.19 (2022-04-11) 1166 # 1167 CODE=" 1168 #include <linux/pci.h> 1169 #include <linux/mdev.h> 1170 int conftest_mdev_driver_has_supported_type_groups(void) { 1171 return offsetof(struct mdev_driver, supported_type_groups); 1172 }" 1173 1174 compile_check_conftest "$CODE" "NV_MDEV_DRIVER_HAS_SUPPORTED_TYPE_GROUPS" "" "types" 1175 ;; 1176 1177 vfio_device_ops_has_dma_unmap) 1178 # 1179 # Determine if 'vfio_device_ops' struct has 'dma_unmap' field. 1180 # 1181 # Added by commit ce4b4657ff18 ("vfio: Replace the DMA unmapping 1182 # notifier with a callback") in v6.0 1183 # 1184 CODE=" 1185 #include <linux/pci.h> 1186 #include <linux/vfio.h> 1187 int conftest_vfio_device_ops_has_dma_unmap(void) { 1188 return offsetof(struct vfio_device_ops, dma_unmap); 1189 }" 1190 1191 compile_check_conftest "$CODE" "NV_VFIO_DEVICE_OPS_HAS_DMA_UNMAP" "" "types" 1192 ;; 1193 1194 vfio_device_ops_has_bind_iommufd) 1195 # 1196 # Determine if 'vfio_device_ops' struct has 'bind_iommufd' field. 1197 # 1198 # Added by commit a4d1f91db5021 ("vfio-iommufd: Support iommufd 1199 # for physical VFIO devices") in v6.2 1200 # 1201 CODE=" 1202 #include <linux/pci.h> 1203 #include <linux/vfio.h> 1204 int conftest_vfio_device_ops_has_bind_iommufd(void) { 1205 return offsetof(struct vfio_device_ops, bind_iommufd); 1206 }" 1207 1208 compile_check_conftest "$CODE" "NV_VFIO_DEVICE_OPS_HAS_BIND_IOMMUFD" "" "types" 1209 ;; 1210 1211 pci_irq_vector_helpers) 1212 # 1213 # Determine if pci_alloc_irq_vectors(), pci_free_irq_vectors() 1214 # functions are present or not. 1215 # 1216 # Added by commit aff171641d181ea573 (PCI: Provide sensible IRQ 1217 # vector alloc/free routines) (2016-07-12) 1218 # 1219 CODE=" 1220 #include <linux/pci.h> 1221 #include <linux/msi.h> 1222 void conftest_pci_irq_vector_helpers() { 1223 pci_alloc_irq_vectors(); 1224 pci_free_irq_vectors (); 1225 }" 1226 1227 compile_check_conftest "$CODE" "NV_PCI_IRQ_VECTOR_HELPERS_PRESENT" "" "functions" 1228 ;; 1229 1230 1231 vfio_device_gfx_plane_info) 1232 # 1233 # determine if the 'struct vfio_device_gfx_plane_info' type is present. 1234 # 1235 # Added by commit e20eaa2382e7 ("vfio: ABI for mdev display 1236 # dma-buf operation") in v4.16 (2017-11-23) 1237 # 1238 CODE=" 1239 #include <linux/vfio.h> 1240 struct vfio_device_gfx_plane_info info;" 1241 1242 compile_check_conftest "$CODE" "NV_VFIO_DEVICE_GFX_PLANE_INFO_PRESENT" "" "types" 1243 ;; 1244 1245 vfio_device_migration_has_start_pfn) 1246 # 1247 # Determine if the 'vfio_device_migration_info' structure has 1248 # a 'start_pfn' field. 1249 # 1250 # This member was present in proposed interface for vGPU Migration 1251 # ("[PATCH v3 0/5] Add migration support for VFIO device ") 1252 # https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg05176.html 1253 # which is not present in upstreamed commit a8a24f3f6e38 (vfio: UAPI 1254 # for migration interface for device state) in v5.8 (2020-05-29) 1255 # 1256 CODE=" 1257 #include <linux/vfio.h> 1258 int conftest_vfio_device_migration_has_start_pfn(void) { 1259 return offsetof(struct vfio_device_migration_info, start_pfn); 1260 }" 1261 1262 compile_check_conftest "$CODE" "NV_VFIO_DEVICE_MIGRATION_HAS_START_PFN" "" "types" 1263 ;; 1264 1265 vfio_uninit_group_dev) 1266 # 1267 # Determine if vfio_uninit_group_dev() function is present or not. 1268 # 1269 # Added by commit ae03c3771b8c (vfio: Introduce a vfio_uninit_group_dev() 1270 # API call) in v5.15 1271 # 1272 CODE=" 1273 #include <linux/vfio.h> 1274 void conftest_vfio_uninit_group_dev() { 1275 vfio_uninit_group_dev(); 1276 }" 1277 1278 compile_check_conftest "$CODE" "NV_VFIO_UNINIT_GROUP_DEV_PRESENT" "" "functions" 1279 ;; 1280 1281 vfio_pci_core_available) 1282 # Determine if VFIO_PCI_CORE is available 1283 # 1284 # Added by commit 7fa005caa35e ("vfio/pci: Introduce 1285 # vfio_pci_core.ko") in v5.16 (2021-08-26) 1286 # 1287 1288 CODE=" 1289 #if defined(NV_LINUX_VFIO_PCI_CORE_H_PRESENT) 1290 #include <linux/vfio_pci_core.h> 1291 #endif 1292 1293 #if !defined(CONFIG_VFIO_PCI_CORE) && !defined(CONFIG_VFIO_PCI_CORE_MODULE) 1294 #error VFIO_PCI_CORE not enabled 1295 #endif 1296 void conftest_vfio_pci_core_available(void) { 1297 struct vfio_pci_core_device dev; 1298 }" 1299 1300 compile_check_conftest "$CODE" "NV_VFIO_PCI_CORE_PRESENT" "" "generic" 1301 ;; 1302 1303 mdev_available) 1304 # Determine if MDEV is available 1305 # 1306 # Added by commit 7b96953bc640 ("vfio: Mediated device Core driver") 1307 # in v4.10 1308 # 1309 CODE=" 1310 #if defined(NV_LINUX_MDEV_H_PRESENT) 1311 #include <linux/pci.h> 1312 #include <linux/mdev.h> 1313 #endif 1314 1315 #if !defined(CONFIG_VFIO_MDEV) && !defined(CONFIG_VFIO_MDEV_MODULE) 1316 #error MDEV not enabled 1317 #endif 1318 void conftest_mdev_available(void) { 1319 struct mdev_device *mdev; 1320 }" 1321 1322 compile_check_conftest "$CODE" "NV_MDEV_PRESENT" "" "generic" 1323 ;; 1324 1325 vfio_alloc_device) 1326 # 1327 # Determine if vfio_alloc_device() function is present or not. 1328 # 1329 # Added by commit cb9ff3f3b84c (vfio: Add helpers for unifying vfio_device 1330 # life cycle) in v6.1 1331 # 1332 CODE=" 1333 #include <linux/vfio.h> 1334 void conftest_vfio_alloc_device() { 1335 vfio_alloc_device(); 1336 }" 1337 1338 compile_check_conftest "$CODE" "NV_VFIO_ALLOC_DEVICE_PRESENT" "" "functions" 1339 ;; 1340 1341 vfio_register_emulated_iommu_dev) 1342 # 1343 # Determine if vfio_register_emulated_iommu_dev() function is present or not. 1344 # 1345 # Added by commit c68ea0d00ad8 (vfio: simplify iommu group allocation 1346 # for mediated devices) in v5.16 1347 # 1348 CODE=" 1349 #include <linux/vfio.h> 1350 void conftest_vfio_register_emulated_iommu_dev() { 1351 vfio_register_emulated_iommu_dev(); 1352 }" 1353 1354 compile_check_conftest "$CODE" "NV_VFIO_REGISTER_EMULATED_IOMMU_DEV_PRESENT" "" "functions" 1355 ;; 1356 1357 drm_available) 1358 # Determine if the DRM subsystem is usable 1359 CODE=" 1360 #if defined(NV_DRM_DRMP_H_PRESENT) 1361 #include <drm/drmP.h> 1362 #endif 1363 1364 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 1365 #include <drm/drm_drv.h> 1366 #endif 1367 1368 #if !defined(CONFIG_DRM) && !defined(CONFIG_DRM_MODULE) 1369 #error DRM not enabled 1370 #endif 1371 1372 void conftest_drm_available(void) { 1373 struct drm_driver drv; 1374 1375 /* 2013-10-02 1bb72532ac260a2d3982b40bdd4c936d779d0d16 */ 1376 (void)drm_dev_alloc; 1377 1378 /* 2013-10-02 c22f0ace1926da399d9a16dfaf09174c1b03594c */ 1379 (void)drm_dev_register; 1380 1381 /* 2013-10-02 c3a49737ef7db0bdd4fcf6cf0b7140a883e32b2a */ 1382 (void)drm_dev_unregister; 1383 }" 1384 1385 compile_check_conftest "$CODE" "NV_DRM_AVAILABLE" "" "generic" 1386 ;; 1387 1388 drm_dev_unref) 1389 # 1390 # Determine if drm_dev_unref() is present. 1391 # If it isn't, we use drm_dev_free() instead. 1392 # 1393 # drm_dev_free was added by commit 0dc8fe5985e0 ("drm: introduce 1394 # drm_dev_free() to fix error paths") in v3.13 (2013-10-02) 1395 # 1396 # Renamed to drm_dev_unref by commit 099d1c290e2e 1397 # ("drm: provide device-refcount") in v3.15 (2014-01-29) 1398 # 1399 CODE=" 1400 #if defined(NV_DRM_DRMP_H_PRESENT) 1401 #include <drm/drmP.h> 1402 #endif 1403 void conftest_drm_dev_unref(void) { 1404 drm_dev_unref(); 1405 }" 1406 1407 compile_check_conftest "$CODE" "NV_DRM_DEV_UNREF_PRESENT" "" "functions" 1408 ;; 1409 1410 pde_data) 1411 # 1412 # Determine if the pde_data() function is present. 1413 # 1414 # The commit c28198889c15 removed the function 1415 # 'PDE_DATA()', and replaced it with 'pde_data()' 1416 # ("proc: remove PDE_DATA() completely") in v5.17-rc1. 1417 # 1418 CODE=" 1419 #include <linux/proc_fs.h> 1420 void conftest_pde_data(void) { 1421 pde_data(); 1422 }" 1423 1424 compile_check_conftest "$CODE" "NV_PDE_DATA_LOWER_CASE_PRESENT" "" "functions" 1425 ;; 1426 1427 get_num_physpages) 1428 # 1429 # Determine if the get_num_physpages() function is 1430 # present. 1431 # 1432 # Added by commit 7ee3d4e8cd56 ("mm: introduce helper function 1433 # mem_init_print_info() to simplify mem_init()") in v3.11 1434 # 1435 CODE=" 1436 #include <linux/mm.h> 1437 void conftest_get_num_physpages(void) { 1438 get_num_physpages(NULL); 1439 }" 1440 1441 compile_check_conftest "$CODE" "NV_GET_NUM_PHYSPAGES_PRESENT" "" "functions" 1442 ;; 1443 1444 backing_dev_info) 1445 # 1446 # Determine if the 'address_space' structure has 1447 # a 'backing_dev_info' field. 1448 # 1449 # Removed by commit b83ae6d42143 ("fs: remove 1450 # mapping->backing_dev_info") in v4.0 1451 # 1452 CODE=" 1453 #include <linux/fs.h> 1454 int conftest_backing_dev_info(void) { 1455 return offsetof(struct address_space, backing_dev_info); 1456 }" 1457 1458 compile_check_conftest "$CODE" "NV_ADDRESS_SPACE_HAS_BACKING_DEV_INFO" "" "types" 1459 ;; 1460 1461 xen_ioemu_inject_msi) 1462 # Determine if the xen_ioemu_inject_msi() function is present. 1463 CODE=" 1464 #if defined(NV_XEN_IOEMU_H_PRESENT) 1465 #include <linux/kernel.h> 1466 #include <xen/interface/xen.h> 1467 #include <xen/hvm.h> 1468 #include <xen/ioemu.h> 1469 #endif 1470 void conftest_xen_ioemu_inject_msi(void) { 1471 xen_ioemu_inject_msi(); 1472 }" 1473 1474 compile_check_conftest "$CODE" "NV_XEN_IOEMU_INJECT_MSI" "" "functions" 1475 ;; 1476 1477 phys_to_dma) 1478 # 1479 # Determine if the phys_to_dma function is present. 1480 # It does not exist on all architectures. 1481 # 1482 CODE=" 1483 #include <linux/dma-mapping.h> 1484 void conftest_phys_to_dma(void) { 1485 phys_to_dma(); 1486 }" 1487 1488 compile_check_conftest "$CODE" "NV_PHYS_TO_DMA_PRESENT" "" "functions" 1489 ;; 1490 1491 1492 dma_attr_macros) 1493 # 1494 # Determine if the NV_DMA_ATTR_SKIP_CPU_SYNC_PRESENT macro present. 1495 # It does not exist on all architectures. 1496 # 1497 CODE=" 1498 #include <linux/dma-mapping.h> 1499 void conftest_dma_attr_macros(void) { 1500 int ret; 1501 ret = DMA_ATTR_SKIP_CPU_SYNC(); 1502 }" 1503 compile_check_conftest "$CODE" "NV_DMA_ATTR_SKIP_CPU_SYNC_PRESENT" "" "functions" 1504 ;; 1505 1506 dma_map_page_attrs) 1507 # 1508 # Determine if the dma_map_page_attrs function is present. 1509 # It does not exist on all architectures. 1510 # 1511 CODE=" 1512 #include <linux/dma-mapping.h> 1513 void conftest_dma_map_page_attrs(void) { 1514 dma_map_page_attrs(); 1515 }" 1516 1517 compile_check_conftest "$CODE" "NV_DMA_MAP_PAGE_ATTRS_PRESENT" "" "functions" 1518 ;; 1519 1520 dma_ops) 1521 # 1522 # Determine if the 'dma_ops' structure is present. 1523 # It does not exist on all architectures. 1524 # 1525 CODE=" 1526 #include <linux/dma-mapping.h> 1527 void conftest_dma_ops(void) { 1528 (void)dma_ops; 1529 }" 1530 1531 compile_check_conftest "$CODE" "NV_DMA_OPS_PRESENT" "" "symbols" 1532 ;; 1533 1534 swiotlb_dma_ops) 1535 # 1536 # Determine if the 'swiotlb_dma_ops' structure is present. 1537 # It does not exist on all architectures. 1538 # 1539 CODE=" 1540 #include <linux/dma-mapping.h> 1541 void conftest_dma_ops(void) { 1542 (void)swiotlb_dma_ops; 1543 }" 1544 1545 compile_check_conftest "$CODE" "NV_SWIOTLB_DMA_OPS_PRESENT" "" "symbols" 1546 ;; 1547 1548 get_dma_ops) 1549 # 1550 # Determine if the get_dma_ops() function is present. 1551 # 1552 # The structure was made available to all architectures by commit 1553 # e1c7e324539a ("dma-mapping: always provide the dma_map_ops 1554 # based implementation") in v4.5 1555 # 1556 # Commit 0a0f0d8be76d ("dma-mapping: split <linux/dma-mapping.h>") 1557 # in v5.10-rc1 (2020-09-22), moved get_dma_ops() function 1558 # prototype from <linux/dma-mapping.h> to <linux/dma-map-ops.h>. 1559 # 1560 CODE=" 1561 #if defined(NV_LINUX_DMA_MAP_OPS_H_PRESENT) 1562 #include <linux/dma-map-ops.h> 1563 #else 1564 #include <linux/dma-mapping.h> 1565 #endif 1566 void conftest_get_dma_ops(void) { 1567 get_dma_ops(); 1568 }" 1569 1570 compile_check_conftest "$CODE" "NV_GET_DMA_OPS_PRESENT" "" "functions" 1571 ;; 1572 1573 noncoherent_swiotlb_dma_ops) 1574 # 1575 # Determine if the 'noncoherent_swiotlb_dma_ops' symbol is present. 1576 # This API only exists on ARM64. 1577 # 1578 # Added by commit 7363590d2c46 ("arm64: Implement coherent DMA API 1579 # based on swiotlb") in v3.15 1580 # 1581 # Removed by commit 9d3bfbb4df58 ("arm64: Combine coherent and 1582 # non-coherent swiotlb dma_ops") in v4.0 1583 # 1584 CODE=" 1585 #include <linux/dma-mapping.h> 1586 void conftest_noncoherent_swiotlb_dma_ops(void) { 1587 (void)noncoherent_swiotlb_dma_ops; 1588 }" 1589 1590 compile_check_conftest "$CODE" "NV_NONCOHERENT_SWIOTLB_DMA_OPS_PRESENT" "" "symbols" 1591 ;; 1592 1593 dma_map_resource) 1594 # 1595 # Determine if the dma_map_resource() function is present. 1596 # 1597 # Added by commit 6f3d87968f9c ("dma-mapping: add 1598 # dma_{map,unmap}_resource") in v4.9 (2016-08-10) 1599 # 1600 CODE=" 1601 #include <linux/dma-mapping.h> 1602 void conftest_dma_map_resource(void) { 1603 dma_map_resource(); 1604 }" 1605 1606 compile_check_conftest "$CODE" "NV_DMA_MAP_RESOURCE_PRESENT" "" "functions" 1607 ;; 1608 1609 write_cr4) 1610 # 1611 # Determine if the write_cr4() function is present. 1612 # 1613 CODE=" 1614 #include <asm/processor.h> 1615 void conftest_write_cr4(void) { 1616 write_cr4(); 1617 }" 1618 1619 compile_check_conftest "$CODE" "NV_WRITE_CR4_PRESENT" "" "functions" 1620 ;; 1621 1622 nvhost_dma_fence_unpack) 1623 # 1624 # Determine if the nvhost_dma_fence_unpack function is present. 1625 # This is only present in NVIDIA Tegra downstream kernels. 1626 # 1627 CODE=" 1628 #if defined(NV_LINUX_NVHOST_H_PRESENT) 1629 #include <linux/nvhost.h> 1630 #endif 1631 void conftest_nvhost_dma_fence_unpack(void) { 1632 nvhost_dma_fence_unpack(); 1633 }" 1634 1635 compile_check_conftest "$CODE" "NV_NVHOST_DMA_FENCE_UNPACK_PRESENT" "" "functions" 1636 ;; 1637 1638 of_find_node_by_phandle) 1639 # 1640 # Determine if the of_find_node_by_phandle function is present. 1641 # 1642 # Support for kernels without CONFIG_OF defined added by commit 1643 # ce16b9d23561 ("of: define of_find_node_by_phandle for 1644 # !CONFIG_OF") in v4.2 1645 # 1646 # Test if linux/of.h header file inclusion is successful or not and 1647 # define/undefine NV_LINUX_OF_H_USABLE depending upon status of inclusion. 1648 # 1649 echo "$CONFTEST_PREAMBLE 1650 #include <linux/of.h> 1651 " > conftest$$.c 1652 1653 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1654 rm -f conftest$$.c 1655 1656 if [ -f conftest$$.o ]; then 1657 rm -f conftest$$.o 1658 echo "#define NV_LINUX_OF_H_USABLE" | append_conftest "generic" 1659 CODE=" 1660 #include <linux/of.h> 1661 void conftest_of_find_node_by_phandle() { 1662 of_find_node_by_phandle(); 1663 }" 1664 1665 compile_check_conftest "$CODE" "NV_OF_FIND_NODE_BY_PHANDLE_PRESENT" "" "functions" 1666 else 1667 echo "#undef NV_LINUX_OF_H_USABLE" | append_conftest "generic" 1668 echo "#undef NV_OF_FIND_NODE_BY_PHANDLE_PRESENT" | append_conftest "functions" 1669 fi 1670 ;; 1671 1672 of_node_to_nid) 1673 # 1674 # Determine if of_node_to_nid is present 1675 # 1676 # Dummy implementation added by commit 559e2b7ee7a1 1677 # ("of: Provide default of_node_to_nid() implementation.") in v2.6.36 1678 # 1679 # Real implementation added by commit 298535c00a2c 1680 # ("of, numa: Add NUMA of binding implementation.") in v4.7 1681 # 1682 # Test if linux/of.h header file inclusion is successful or not and 1683 # define/undefine NV_LINUX_OF_H_USABLE depending upon status of inclusion. 1684 # 1685 echo "$CONFTEST_PREAMBLE 1686 #include <linux/of.h> 1687 " > conftest$$.c 1688 1689 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1690 rm -f conftest$$.c 1691 1692 if [ -f conftest$$.o ]; then 1693 rm -f conftest$$.o 1694 echo "#define NV_LINUX_OF_H_USABLE" | append_conftest "generic" 1695 CODE=" 1696 #include <linux/version.h> 1697 #include <linux/utsname.h> 1698 #include <linux/of.h> 1699 void conftest_of_node_to_nid() { 1700 of_node_to_nid(); 1701 }" 1702 1703 compile_check_conftest "$CODE" "NV_OF_NODE_TO_NID_PRESENT" "" "functions" 1704 else 1705 echo "#undef NV_LINUX_OF_H_USABLE" | append_conftest "generic" 1706 echo "#undef NV_OF_NODE_TO_NID_PRESENT" | append_conftest "functions" 1707 fi 1708 ;; 1709 1710 pnv_pci_get_npu_dev) 1711 # 1712 # Determine if the pnv_pci_get_npu_dev function is present. 1713 # 1714 # Added by commit 5d2aa710e697 ("powerpc/powernv: Add support 1715 # for Nvlink NPUs") in v4.5 1716 # 1717 CODE=" 1718 #include <linux/pci.h> 1719 void conftest_pnv_pci_get_npu_dev() { 1720 pnv_pci_get_npu_dev(); 1721 }" 1722 1723 compile_check_conftest "$CODE" "NV_PNV_PCI_GET_NPU_DEV_PRESENT" "" "functions" 1724 ;; 1725 1726 kernel_write_has_pointer_pos_arg) 1727 # 1728 # Determine the pos argument type, which was changed by 1729 # commit e13ec939e96b1 (fs: fix kernel_write prototype) on 1730 # 9/1/2017. 1731 # 1732 echo "$CONFTEST_PREAMBLE 1733 #include <linux/fs.h> 1734 ssize_t kernel_write(struct file *file, const void *buf, 1735 size_t count, loff_t *pos) 1736 { 1737 return 0; 1738 }" > conftest$$.c; 1739 1740 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1741 rm -f conftest$$.c 1742 1743 if [ -f conftest$$.o ]; then 1744 echo "#define NV_KERNEL_WRITE_HAS_POINTER_POS_ARG" | append_conftest "function" 1745 rm -f conftest$$.o 1746 else 1747 echo "#undef NV_KERNEL_WRITE_HAS_POINTER_POS_ARG" | append_conftest "function" 1748 fi 1749 ;; 1750 1751 kernel_read_has_pointer_pos_arg) 1752 # 1753 # Determine the pos argument type, which was changed by 1754 # commit bdd1d2d3d251c (fs: fix kernel_read prototype) on 1755 # 9/1/2017. 1756 # 1757 echo "$CONFTEST_PREAMBLE 1758 #include <linux/fs.h> 1759 ssize_t kernel_read(struct file *file, void *buf, size_t count, 1760 loff_t *pos) 1761 { 1762 return 0; 1763 }" > conftest$$.c; 1764 1765 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1766 rm -f conftest$$.c 1767 1768 if [ -f conftest$$.o ]; then 1769 echo "#define NV_KERNEL_READ_HAS_POINTER_POS_ARG" | append_conftest "function" 1770 rm -f conftest$$.o 1771 else 1772 echo "#undef NV_KERNEL_READ_HAS_POINTER_POS_ARG" | append_conftest "function" 1773 fi 1774 ;; 1775 1776 vm_insert_pfn_prot) 1777 # 1778 # Determine if vm_insert_pfn_prot function is present 1779 # 1780 # Added by commit 1745cbc5d0de ("mm: Add vm_insert_pfn_prot()") in 1781 # v3.16.59 1782 # 1783 # Removed by commit f5e6d1d5f8f3 ("mm: introduce 1784 # vmf_insert_pfn_prot()") in v4.20. 1785 # 1786 CODE=" 1787 #include <linux/mm.h> 1788 void conftest_vm_insert_pfn_prot() { 1789 vm_insert_pfn_prot(); 1790 }" 1791 1792 compile_check_conftest "$CODE" "NV_VM_INSERT_PFN_PROT_PRESENT" "" "functions" 1793 ;; 1794 1795 vmf_insert_pfn_prot) 1796 # 1797 # Determine if vmf_insert_pfn_prot function is present 1798 # 1799 # Added by commit f5e6d1d5f8f3 ("mm: introduce 1800 # vmf_insert_pfn_prot()") in v4.20. 1801 # 1802 CODE=" 1803 #include <linux/mm.h> 1804 void conftest_vmf_insert_pfn_prot() { 1805 vmf_insert_pfn_prot(); 1806 }" 1807 1808 compile_check_conftest "$CODE" "NV_VMF_INSERT_PFN_PROT_PRESENT" "" "functions" 1809 ;; 1810 1811 drm_atomic_available) 1812 # 1813 # Determine if the DRM atomic modesetting subsystem is usable 1814 # 1815 # Added by commit 036ef5733ba4 1816 # ("drm/atomic: Allow drivers to subclass drm_atomic_state, v3") in 1817 # v4.2 (2018-05-18). 1818 # 1819 # Make conftest more robust by adding test for 1820 # drm_atomic_set_mode_prop_for_crtc(), this function added by 1821 # commit 955f3c334f0f ("drm/atomic: Add MODE_ID property") in v4.2 1822 # (2015-05-25). If the DRM atomic modesetting subsystem is 1823 # back ported to Linux kernel older than v4.2, then commit 1824 # 955f3c334f0f must be back ported in order to get NVIDIA-DRM KMS 1825 # support. 1826 # Commit 72fdb40c1a4b ("drm: extract drm_atomic_uapi.c") in v4.20 1827 # (2018-09-05), moved drm_atomic_set_mode_prop_for_crtc() function 1828 # prototype from drm/drm_atomic.h to drm/drm_atomic_uapi.h. 1829 # 1830 echo "$CONFTEST_PREAMBLE 1831 #if defined(NV_DRM_DRMP_H_PRESENT) 1832 #include <drm/drmP.h> 1833 #endif 1834 #include <drm/drm_atomic.h> 1835 #if !defined(CONFIG_DRM) && !defined(CONFIG_DRM_MODULE) 1836 #error DRM not enabled 1837 #endif 1838 void conftest_drm_atomic_modeset_available(void) { 1839 size_t a; 1840 1841 a = offsetof(struct drm_mode_config_funcs, atomic_state_alloc); 1842 }" > conftest$$.c; 1843 1844 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1845 rm -f conftest$$.c 1846 1847 if [ -f conftest$$.o ]; then 1848 rm -f conftest$$.o 1849 1850 echo "$CONFTEST_PREAMBLE 1851 #if defined(NV_DRM_DRMP_H_PRESENT) 1852 #include <drm/drmP.h> 1853 #endif 1854 #include <drm/drm_atomic.h> 1855 #if defined(NV_DRM_DRM_ATOMIC_UAPI_H_PRESENT) 1856 #include <drm/drm_atomic_uapi.h> 1857 #endif 1858 void conftest_drm_atomic_set_mode_prop_for_crtc(void) { 1859 drm_atomic_set_mode_prop_for_crtc(); 1860 }" > conftest$$.c; 1861 1862 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 1863 rm -f conftest$$.c 1864 1865 if [ -f conftest$$.o ]; then 1866 rm -f conftest$$.o 1867 echo "#undef NV_DRM_ATOMIC_MODESET_AVAILABLE" | append_conftest "generic" 1868 else 1869 echo "#define NV_DRM_ATOMIC_MODESET_AVAILABLE" | append_conftest "generic" 1870 fi 1871 else 1872 echo "#undef NV_DRM_ATOMIC_MODESET_AVAILABLE" | append_conftest "generic" 1873 fi 1874 ;; 1875 1876 drm_bus_present) 1877 # 1878 # Determine if the 'struct drm_bus' type is present. 1879 # 1880 # Added by commit 8410ea3b95d1 ("drm: rework PCI/platform driver 1881 # interface.") in v2.6.39 (2010-12-15) 1882 # 1883 # Removed by commit c5786fe5f1c5 ("drm: Goody bye, drm_bus!") 1884 # in v3.18 (2014-08-29) 1885 # 1886 CODE=" 1887 #if defined(NV_DRM_DRMP_H_PRESENT) 1888 #include <drm/drmP.h> 1889 #endif 1890 1891 void conftest_drm_bus_present(void) { 1892 struct drm_bus bus; 1893 }" 1894 1895 compile_check_conftest "$CODE" "NV_DRM_BUS_PRESENT" "" "types" 1896 ;; 1897 1898 drm_bus_has_bus_type) 1899 # 1900 # Determine if the 'drm_bus' structure has a 'bus_type' field. 1901 # 1902 # Added by commit 8410ea3b95d1 ("drm: rework PCI/platform driver 1903 # interface.") in v2.6.39 (2010-12-15) 1904 # 1905 # Removed by commit 42b21049fc26 ("drm: kill drm_bus->bus_type") 1906 # in v3.16 (2013-11-03) 1907 # 1908 CODE=" 1909 #if defined(NV_DRM_DRMP_H_PRESENT) 1910 #include <drm/drmP.h> 1911 #endif 1912 1913 int conftest_drm_bus_has_bus_type(void) { 1914 return offsetof(struct drm_bus, bus_type); 1915 }" 1916 1917 compile_check_conftest "$CODE" "NV_DRM_BUS_HAS_BUS_TYPE" "" "types" 1918 ;; 1919 1920 drm_bus_has_get_irq) 1921 # 1922 # Determine if the 'drm_bus' structure has a 'get_irq' field. 1923 # 1924 # Added by commit 8410ea3b95d1 ("drm: rework PCI/platform 1925 # driver interface.") in v2.6.39 (2010-12-15) 1926 # 1927 # Removed by commit b2a21aa25a39 ("drm: remove bus->get_irq 1928 # implementations") in v3.16 (2013-11-03) 1929 # 1930 CODE=" 1931 #if defined(NV_DRM_DRMP_H_PRESENT) 1932 #include <drm/drmP.h> 1933 #endif 1934 1935 int conftest_drm_bus_has_get_irq(void) { 1936 return offsetof(struct drm_bus, get_irq); 1937 }" 1938 1939 compile_check_conftest "$CODE" "NV_DRM_BUS_HAS_GET_IRQ" "" "types" 1940 ;; 1941 1942 drm_bus_has_get_name) 1943 # 1944 # Determine if the 'drm_bus' structure has a 'get_name' field. 1945 # 1946 # Added by commit 8410ea3b95d1 ("drm: rework PCI/platform driver 1947 # interface.") in v2.6.39 (2010-12-15) 1948 # 1949 # removed by commit 9de1b51f1fae ("drm: remove drm_bus->get_name") 1950 # in v3.16 (2013-11-03) 1951 # 1952 CODE=" 1953 #if defined(NV_DRM_DRMP_H_PRESENT) 1954 #include <drm/drmP.h> 1955 #endif 1956 1957 int conftest_drm_bus_has_get_name(void) { 1958 return offsetof(struct drm_bus, get_name); 1959 }" 1960 1961 compile_check_conftest "$CODE" "NV_DRM_BUS_HAS_GET_NAME" "" "types" 1962 ;; 1963 1964 drm_driver_has_device_list) 1965 # 1966 # Determine if the 'drm_driver' structure has a 'device_list' field. 1967 # 1968 # Renamed from device_list to legacy_device_list by commit 1969 # b3f2333de8e8 ("drm: restrict the device list for shadow 1970 # attached drivers") in v3.14 (2013-12-11) 1971 # 1972 CODE=" 1973 #if defined(NV_DRM_DRMP_H_PRESENT) 1974 #include <drm/drmP.h> 1975 #endif 1976 1977 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 1978 #include <drm/drm_drv.h> 1979 #endif 1980 1981 int conftest_drm_driver_has_device_list(void) { 1982 return offsetof(struct drm_driver, device_list); 1983 }" 1984 1985 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_DEVICE_LIST" "" "types" 1986 ;; 1987 1988 1989 drm_driver_has_legacy_dev_list) 1990 # 1991 # Determine if the 'drm_driver' structure has a 'legacy_dev_list' field. 1992 # 1993 # Renamed from device_list to legacy_device_list by commit 1994 # b3f2333de8e8 ("drm: restrict the device list for shadow 1995 # attached drivers") in v3.14 (2013-12-11) 1996 # 1997 # The commit 57bb1ee60340 ("drm: Compile out legacy chunks from 1998 # struct drm_device") compiles out the legacy chunks like 1999 # drm_driver::legacy_dev_list. 2000 # 2001 CODE=" 2002 #if defined(NV_DRM_DRMP_H_PRESENT) 2003 #include <drm/drmP.h> 2004 #endif 2005 2006 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 2007 #include <drm/drm_drv.h> 2008 #endif 2009 2010 int conftest_drm_driver_has_legacy_dev_list(void) { 2011 return offsetof(struct drm_driver, legacy_dev_list); 2012 }" 2013 2014 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_LEGACY_DEV_LIST" "" "types" 2015 ;; 2016 2017 jiffies_to_timespec) 2018 # 2019 # Determine if jiffies_to_timespec() is present 2020 # 2021 # removed by commit 751addac78b6 2022 # ("y2038: remove obsolete jiffies conversion functions") 2023 # in v5.6-rc1 (2019-12-13). 2024 CODE=" 2025 #include <linux/jiffies.h> 2026 void conftest_jiffies_to_timespec(void){ 2027 jiffies_to_timespec(); 2028 }" 2029 compile_check_conftest "$CODE" "NV_JIFFIES_TO_TIMESPEC_PRESENT" "" "functions" 2030 ;; 2031 2032 drm_init_function_args) 2033 # 2034 # Determine if these functions: 2035 # drm_universal_plane_init() 2036 # drm_crtc_init_with_planes() 2037 # drm_encoder_init() 2038 # have a 'name' argument, which was added by these commits: 2039 # drm_universal_plane_init: 2015-12-09 b0b3b7951114315d65398c27648705ca1c322faa 2040 # drm_crtc_init_with_planes: 2015-12-09 f98828769c8838f526703ef180b3088a714af2f9 2041 # drm_encoder_init: 2015-12-09 13a3d91f17a5f7ed2acd275d18b6acfdb131fb15 2042 # 2043 # Additionally determine whether drm_universal_plane_init() has a 2044 # 'format_modifiers' argument, which was added by: 2045 # 2017-07-23 e6fc3b68558e4c6d8d160b5daf2511b99afa8814 2046 # 2047 CODE=" 2048 #if defined(NV_DRM_DRMP_H_PRESENT) 2049 #include <drm/drmP.h> 2050 #endif 2051 2052 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 2053 #include <drm/drm_crtc.h> 2054 #endif 2055 2056 int conftest_drm_crtc_init_with_planes_has_name_arg(void) { 2057 return 2058 drm_crtc_init_with_planes( 2059 NULL, /* struct drm_device *dev */ 2060 NULL, /* struct drm_crtc *crtc */ 2061 NULL, /* struct drm_plane *primary */ 2062 NULL, /* struct drm_plane *cursor */ 2063 NULL, /* const struct drm_crtc_funcs *funcs */ 2064 NULL); /* const char *name */ 2065 }" 2066 2067 compile_check_conftest "$CODE" "NV_DRM_CRTC_INIT_WITH_PLANES_HAS_NAME_ARG" "" "types" 2068 2069 CODE=" 2070 #if defined(NV_DRM_DRMP_H_PRESENT) 2071 #include <drm/drmP.h> 2072 #endif 2073 2074 #if defined(NV_DRM_DRM_ENCODER_H_PRESENT) 2075 #include <drm/drm_encoder.h> 2076 #endif 2077 2078 int conftest_drm_encoder_init_has_name_arg(void) { 2079 return 2080 drm_encoder_init( 2081 NULL, /* struct drm_device *dev */ 2082 NULL, /* struct drm_encoder *encoder */ 2083 NULL, /* const struct drm_encoder_funcs *funcs */ 2084 DRM_MODE_ENCODER_NONE, /* int encoder_type */ 2085 NULL); /* const char *name */ 2086 }" 2087 2088 compile_check_conftest "$CODE" "NV_DRM_ENCODER_INIT_HAS_NAME_ARG" "" "types" 2089 2090 echo "$CONFTEST_PREAMBLE 2091 #if defined(NV_DRM_DRMP_H_PRESENT) 2092 #include <drm/drmP.h> 2093 #endif 2094 2095 #if defined(NV_DRM_DRM_PLANE_H_PRESENT) 2096 #include <drm/drm_plane.h> 2097 #endif 2098 2099 int conftest_drm_universal_plane_init_has_format_modifiers_arg(void) { 2100 return 2101 drm_universal_plane_init( 2102 NULL, /* struct drm_device *dev */ 2103 NULL, /* struct drm_plane *plane */ 2104 0, /* unsigned long possible_crtcs */ 2105 NULL, /* const struct drm_plane_funcs *funcs */ 2106 NULL, /* const uint32_t *formats */ 2107 0, /* unsigned int format_count */ 2108 NULL, /* const uint64_t *format_modifiers */ 2109 DRM_PLANE_TYPE_PRIMARY, 2110 NULL); /* const char *name */ 2111 }" > conftest$$.c 2112 2113 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2114 rm -f conftest$$.c 2115 2116 if [ -f conftest$$.o ]; then 2117 rm -f conftest$$.o 2118 2119 echo "#define NV_DRM_UNIVERSAL_PLANE_INIT_HAS_FORMAT_MODIFIERS_ARG" | append_conftest "types" 2120 echo "#define NV_DRM_UNIVERSAL_PLANE_INIT_HAS_NAME_ARG" | append_conftest "types" 2121 else 2122 echo "#undef NV_DRM_UNIVERSAL_PLANE_INIT_HAS_FORMAT_MODIFIERS_ARG" | append_conftest "types" 2123 2124 CODE=" 2125 #if defined(NV_DRM_DRMP_H_PRESENT) 2126 #include <drm/drmP.h> 2127 #endif 2128 2129 #if defined(NV_DRM_DRM_PLANE_H_PRESENT) 2130 #include <drm/drm_plane.h> 2131 #endif 2132 2133 int conftest_drm_universal_plane_init_has_name_arg(void) { 2134 return 2135 drm_universal_plane_init( 2136 NULL, /* struct drm_device *dev */ 2137 NULL, /* struct drm_plane *plane */ 2138 0, /* unsigned long possible_crtcs */ 2139 NULL, /* const struct drm_plane_funcs *funcs */ 2140 NULL, /* const uint32_t *formats */ 2141 0, /* unsigned int format_count */ 2142 DRM_PLANE_TYPE_PRIMARY, 2143 NULL); /* const char *name */ 2144 }" 2145 2146 compile_check_conftest "$CODE" "NV_DRM_UNIVERSAL_PLANE_INIT_HAS_NAME_ARG" "" "types" 2147 fi 2148 ;; 2149 2150 drm_driver_has_set_busid) 2151 # 2152 # Determine if the drm_driver structure has a 'set_busid' callback 2153 # field. 2154 # 2155 # Added by commit 915b4d11b8b9 ("drm: add driver->set_busid() 2156 # callback") in v3.18 (2014-08-29) 2157 # 2158 CODE=" 2159 #if defined(NV_DRM_DRMP_H_PRESENT) 2160 #include <drm/drmP.h> 2161 #endif 2162 2163 int conftest_drm_driver_has_set_busid(void) { 2164 return offsetof(struct drm_driver, set_busid); 2165 }" 2166 2167 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_SET_BUSID" "" "types" 2168 ;; 2169 2170 drm_driver_has_gem_prime_res_obj) 2171 # 2172 # Determine if the drm_driver structure has a 'gem_prime_res_obj' 2173 # callback field. 2174 # 2175 # Added by commit 3aac4502fd3f ("dma-buf: use reservation 2176 # objects") in v3.17 (2014-07-01). 2177 # 2178 # Removed by commit 51c98747113e (drm/prime: Ditch 2179 # gem_prime_res_obj hook) in v5.4. 2180 # 2181 CODE=" 2182 #if defined(NV_DRM_DRMP_H_PRESENT) 2183 #include <drm/drmP.h> 2184 #endif 2185 2186 int conftest_drm_driver_has_gem_prime_res_obj(void) { 2187 return offsetof(struct drm_driver, gem_prime_res_obj); 2188 }" 2189 2190 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_GEM_PRIME_RES_OBJ" "" "types" 2191 ;; 2192 2193 drm_crtc_state_has_connectors_changed) 2194 # 2195 # Determine if the crtc_state has a 'connectors_changed' field. 2196 # 2197 # Added by commit fc596660dd4e ("drm/atomic: add 2198 # connectors_changed to separate it from mode_changed, v2") 2199 # in v4.3 (2015-07-21) 2200 # 2201 CODE=" 2202 #include <drm/drm_crtc.h> 2203 void conftest_drm_crtc_state_has_connectors_changed(void) { 2204 struct drm_crtc_state foo; 2205 (void)foo.connectors_changed; 2206 }" 2207 2208 compile_check_conftest "$CODE" "NV_DRM_CRTC_STATE_HAS_CONNECTORS_CHANGED" "" "types" 2209 ;; 2210 2211 drm_reinit_primary_mode_group) 2212 # 2213 # Determine if the function drm_reinit_primary_mode_group() is 2214 # present. 2215 # 2216 # Added by commit 2390cd11bfbe ("drm/crtc: add interface to 2217 # reinitialise the legacy mode group") in v3.17 (2014-06-05) 2218 # 2219 # Removed by commit 3fdefa399e46 ("drm: gc now dead 2220 # mode_group code") in v4.3 (2015-07-09) 2221 # 2222 CODE=" 2223 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 2224 #include <drm/drm_crtc.h> 2225 #endif 2226 void conftest_drm_reinit_primary_mode_group(void) { 2227 drm_reinit_primary_mode_group(); 2228 }" 2229 2230 compile_check_conftest "$CODE" "NV_DRM_REINIT_PRIMARY_MODE_GROUP_PRESENT" "" "functions" 2231 ;; 2232 2233 drm_helper_crtc_enable_color_mgmt) 2234 # 2235 # Determine if the function drm_helper_crtc_enable_color_mgmt() is 2236 # present. 2237 # 2238 # Added by commit 5488dc16fde7 ("drm: introduce pipe color 2239 # correction properties") in v4.6 (2016-03-08). 2240 # 2241 # Removed by commit f8ed34ac7b45 ("drm: drm_helper_crtc_enable_color_mgmt() 2242 # => drm_crtc_enable_color_mgmt()") in v4.8-rc1 (2016-06-07). 2243 # 2244 CODE=" 2245 #include <drm/drm_crtc_helper.h> 2246 void conftest_drm_helper_crtc_enable_color_mgmt(void) { 2247 drm_helper_crtc_enable_color_mgmt(); 2248 }" 2249 2250 compile_check_conftest "$CODE" "NV_DRM_HELPER_CRTC_ENABLE_COLOR_MGMT_PRESENT" "" "functions" 2251 2252 ;; 2253 2254 drm_crtc_enable_color_mgmt) 2255 # 2256 # Determine if the function drm_crtc_enable_color_mgmt() is 2257 # present. 2258 # 2259 # Added by commit f8ed34ac7b45 ("drm: drm_helper_crtc_enable_color_mgmt() 2260 # => drm_crtc_enable_color_mgmt()") in v4.8-rc1 (2016-06-07), replacing 2261 # drm_helper_crtc_enable_color_mgmt(). 2262 # 2263 # Moved to drm_color_mgmt.[ch] by commit f1e2f66ce2d9 ("drm: Extract 2264 # drm_color_mgmt.[hc]") in v4.9-rc1 (2016-09-22) 2265 # 2266 CODE=" 2267 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 2268 #include <drm/drm_crtc.h> 2269 #endif 2270 #if defined(NV_DRM_DRM_COLOR_MGMT_H_PRESENT) 2271 #include <drm/drm_color_mgmt.h> 2272 #endif 2273 void conftest_drm_crtc_enable_color_mgmt(void) { 2274 drm_crtc_enable_color_mgmt(); 2275 }" 2276 2277 compile_check_conftest "$CODE" "NV_DRM_CRTC_ENABLE_COLOR_MGMT_PRESENT" "" "functions" 2278 ;; 2279 2280 drm_atomic_helper_legacy_gamma_set) 2281 # 2282 # Determine if the function drm_atomic_helper_legacy_gamma_set() is 2283 # present. 2284 # 2285 # Added by commit 5488dc16fde7 ("drm: introduce pipe color 2286 # correction properties") in v4.6 (2016-03-08) 2287 # 2288 # Accidentally moved to drm_atomic_state_helper.[ch] by commit 2289 # 9ef8a9dc4b21 ("drm: Extract drm_atomic_state_helper.[ch]") 2290 # and moved back to drm_atomic_helper.[ch] by commit 1d8224e790c7 2291 # ("drm: Fix up drm_atomic_state_helper.[hc] extraction") in 2292 # v5.0-rc1 2293 # 2294 # Removed by commit 6ca2ab8086af ("drm: automatic legacy gamma 2295 # support") in v5.12 (2020-12-15) 2296 # 2297 CODE=" 2298 #if defined(NV_DRM_DRM_ATOMIC_HELPER_H_PRESENT) 2299 #include <drm/drm_atomic_helper.h> 2300 #endif 2301 #if defined(NV_DRM_DRM_ATOMIC_STATE_HELPER_H_PRESENT) 2302 #include <drm/drm_atomic_state_helper.h> 2303 #endif 2304 void conftest_drm_atomic_helper_legacy_gamma_set(void) { 2305 drm_atomic_helper_legacy_gamma_set(); 2306 }" 2307 2308 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_LEGACY_GAMMA_SET_PRESENT" "" "functions" 2309 ;; 2310 2311 wait_on_bit_lock_argument_count) 2312 # 2313 # Determine how many arguments wait_on_bit_lock takes. 2314 # 2315 # Changed by commit 743162013d40 ("sched: Remove proliferation 2316 # of wait_on_bit() action functions") in v3.17 (2014-07-07) 2317 # 2318 echo "$CONFTEST_PREAMBLE 2319 #include <linux/wait.h> 2320 void conftest_wait_on_bit_lock(void) { 2321 wait_on_bit_lock(NULL, 0, 0); 2322 }" > conftest$$.c 2323 2324 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2325 rm -f conftest$$.c 2326 2327 if [ -f conftest$$.o ]; then 2328 rm -f conftest$$.o 2329 echo "#define NV_WAIT_ON_BIT_LOCK_ARGUMENT_COUNT 3" | append_conftest "functions" 2330 return 2331 fi 2332 2333 echo "$CONFTEST_PREAMBLE 2334 #include <linux/wait.h> 2335 void conftest_wait_on_bit_lock(void) { 2336 wait_on_bit_lock(NULL, 0, NULL, 0); 2337 }" > conftest$$.c 2338 2339 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2340 rm -f conftest$$.c 2341 2342 if [ -f conftest$$.o ]; then 2343 rm -f conftest$$.o 2344 echo "#define NV_WAIT_ON_BIT_LOCK_ARGUMENT_COUNT 4" | append_conftest "functions" 2345 return 2346 fi 2347 echo "#error wait_on_bit_lock() conftest failed!" | append_conftest "functions" 2348 ;; 2349 2350 pci_stop_and_remove_bus_device) 2351 # 2352 # Determine if the pci_stop_and_remove_bus_device() function is present. 2353 # 2354 # Added by commit 210647af897a ("PCI: Rename pci_remove_bus_device 2355 # to pci_stop_and_remove_bus_device") in v3.4 (2012-02-25) but 2356 # aarch64 support was added by commit d1e6dc91b532 2357 # ("arm64: Add architectural support for PCI") in v3.18-rc1. 2358 # 2359 CODE=" 2360 #include <linux/types.h> 2361 #include <linux/pci.h> 2362 void conftest_pci_stop_and_remove_bus_device() { 2363 pci_stop_and_remove_bus_device(); 2364 }" 2365 2366 compile_check_conftest "$CODE" "NV_PCI_STOP_AND_REMOVE_BUS_DEVICE_PRESENT" "" "functions" 2367 ;; 2368 2369 drm_helper_mode_fill_fb_struct | drm_helper_mode_fill_fb_struct_has_const_mode_cmd_arg) 2370 # 2371 # Determine if the drm_helper_mode_fill_fb_struct function takes 2372 # 'dev' argument. 2373 # 2374 # The drm_helper_mode_fill_fb_struct() has been updated to 2375 # take 'dev' parameter by commit a3f913ca9892 ("drm: Pass 'dev' 2376 # to drm_helper_mode_fill_fb_struct()") in v4.11 (2016-12-14) 2377 # 2378 echo "$CONFTEST_PREAMBLE 2379 #include <drm/drm_crtc_helper.h> 2380 void drm_helper_mode_fill_fb_struct(struct drm_device *dev, 2381 struct drm_framebuffer *fb, 2382 const struct drm_mode_fb_cmd2 *mode_cmd) 2383 { 2384 return; 2385 }" > conftest$$.c; 2386 2387 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2388 rm -f conftest$$.c 2389 2390 if [ -f conftest$$.o ]; then 2391 echo "#define NV_DRM_HELPER_MODE_FILL_FB_STRUCT_HAS_DEV_ARG" | append_conftest "function" 2392 echo "#define NV_DRM_HELPER_MODE_FILL_FB_STRUCT_HAS_CONST_MODE_CMD_ARG" | append_conftest "function" 2393 rm -f conftest$$.o 2394 else 2395 echo "#undef NV_DRM_HELPER_MODE_FILL_FB_STRUCT_HAS_DEV_ARG" | append_conftest "function" 2396 2397 # 2398 # Determine if the drm_mode_fb_cmd2 pointer argument is const in 2399 # drm_mode_config_funcs::fb_create and drm_helper_mode_fill_fb_struct(). 2400 # 2401 # The drm_mode_fb_cmd2 pointer through this call chain was made 2402 # const by commit 1eb83451ba55 ("drm: Pass the user drm_mode_fb_cmd2 2403 # as const to .fb_create()") in v4.5 (2015-11-11) 2404 # 2405 echo "$CONFTEST_PREAMBLE 2406 #include <drm/drm_crtc_helper.h> 2407 void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, 2408 const struct drm_mode_fb_cmd2 *mode_cmd) 2409 { 2410 return; 2411 }" > conftest$$.c; 2412 2413 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2414 rm -f conftest$$.c 2415 2416 if [ -f conftest$$.o ]; then 2417 echo "#define NV_DRM_HELPER_MODE_FILL_FB_STRUCT_HAS_CONST_MODE_CMD_ARG" | append_conftest "function" 2418 rm -f conftest$$.o 2419 else 2420 echo "#undef NV_DRM_HELPER_MODE_FILL_FB_STRUCT_HAS_CONST_MODE_CMD_ARG" | append_conftest "function" 2421 fi 2422 fi 2423 ;; 2424 2425 mm_context_t) 2426 # 2427 # Determine if the 'mm_context_t' data type is present 2428 # and if it has an 'id' member. 2429 # It does not exist on all architectures. 2430 # 2431 echo "$CONFTEST_PREAMBLE 2432 #include <linux/mm.h> 2433 int conftest_mm_context_t(void) { 2434 return offsetof(mm_context_t, id); 2435 }" > conftest$$.c 2436 2437 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2438 rm -f conftest$$.c 2439 2440 if [ -f conftest$$.o ]; then 2441 echo "#define NV_MM_CONTEXT_T_HAS_ID" | append_conftest "types" 2442 rm -f conftest$$.o 2443 return 2444 else 2445 echo "#undef NV_MM_CONTEXT_T_HAS_ID" | append_conftest "types" 2446 return 2447 fi 2448 ;; 2449 2450 pci_dev_has_ats_enabled) 2451 # 2452 # Determine if the 'pci_dev' data type has a 'ats_enabled' member. 2453 # 2454 # Added by commit d544d75ac96aa ("PCI: Embed ATS info directly 2455 # into struct pci_dev") in v4.3-rc1 (2015-08-14) 2456 # 2457 CODE=" 2458 #include <linux/pci.h> 2459 int conftest_pci_dev_ats_enabled_t(void) { 2460 return ((struct pci_dev *)0)->ats_enabled; 2461 }" 2462 2463 compile_check_conftest "$CODE" "NV_PCI_DEV_HAS_ATS_ENABLED" "" "types" 2464 ;; 2465 2466 get_user_pages) 2467 # 2468 # Conftest for get_user_pages() 2469 # 2470 # Use long type for get_user_pages and unsigned long for nr_pages 2471 # by commit 28a35716d317 ("mm: use long type for page counts 2472 # in mm_populate() and get_user_pages()") in v3.9 (2013-02-22) 2473 # 2474 # Removed struct task_struct *tsk & struct mm_struct *mm from 2475 # get_user_pages by commit cde70140fed8 ("mm/gup: Overload 2476 # get_user_pages() functions") in v4.6 (2016-02-12) 2477 # 2478 # Replaced get_user_pages6 with get_user_pages by commit 2479 # c12d2da56d0e ("mm/gup: Remove the macro overload API migration 2480 # helpers from the get_user*() APIs") in v4.6 (2016-04-04) 2481 # 2482 # Replaced write and force parameters with gup_flags by 2483 # commit 768ae309a961 ("mm: replace get_user_pages() write/force 2484 # parameters with gup_flags") in v4.9 (2016-10-13) 2485 # 2486 # Removed vmas parameter from get_user_pages() by commit 7bbf9c8c99 2487 # ("mm/gup: remove unused vmas parameter from get_user_pages()") 2488 # in linux-next, expected in v6.5-rc1 2489 # 2490 # linux-4.4.168 cherry-picked commit 768ae309a961 without 2491 # c12d2da56d0e which is covered in Conftest #3. 2492 # 2493 2494 # 2495 # This function sets the NV_GET_USER_PAGES_* macros as per the below 2496 # passing conftest's 2497 # 2498 set_get_user_pages_defines () { 2499 if [ "$1" = "NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE_VMAS" ]; then 2500 echo "#define NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE_VMAS" | append_conftest "functions" 2501 else 2502 echo "#undef NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE_VMAS" | append_conftest "functions" 2503 fi 2504 2505 if [ "$1" = "NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE_VMAS" ]; then 2506 echo "#define NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE_VMAS" | append_conftest "functions" 2507 else 2508 echo "#undef NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE_VMAS" | append_conftest "functions" 2509 fi 2510 2511 if [ "$1" = "NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS_VMAS" ]; then 2512 echo "#define NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS_VMAS" | append_conftest "functions" 2513 else 2514 echo "#undef NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS_VMAS" | append_conftest "functions" 2515 fi 2516 2517 if [ "$1" = "NV_GET_USER_PAGES_HAS_ARGS_FLAGS_VMAS" ]; then 2518 echo "#define NV_GET_USER_PAGES_HAS_ARGS_FLAGS_VMAS" | append_conftest "functions" 2519 else 2520 echo "#undef NV_GET_USER_PAGES_HAS_ARGS_FLAGS_VMAS" | append_conftest "functions" 2521 fi 2522 2523 if [ "$1" = "NV_GET_USER_PAGES_HAS_ARGS_FLAGS" ]; then 2524 echo "#define NV_GET_USER_PAGES_HAS_ARGS_FLAGS" | append_conftest "functions" 2525 else 2526 echo "#undef NV_GET_USER_PAGES_HAS_ARGS_FLAGS" | append_conftest "functions" 2527 fi 2528 2529 } 2530 2531 # Conftest #1: Check if get_user_pages accepts 6 arguments. 2532 # Return if true. 2533 # Fall through to conftest #2 on failure. 2534 2535 echo "$CONFTEST_PREAMBLE 2536 #include <linux/mm.h> 2537 long get_user_pages(unsigned long start, 2538 unsigned long nr_pages, 2539 int write, 2540 int force, 2541 struct page **pages, 2542 struct vm_area_struct **vmas) { 2543 return 0; 2544 }" > conftest$$.c 2545 2546 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2547 rm -f conftest$$.c 2548 if [ -f conftest$$.o ]; then 2549 set_get_user_pages_defines "NV_GET_USER_PAGES_HAS_ARGS_WRITE_FORCE_VMAS" 2550 rm -f conftest$$.o 2551 return 2552 fi 2553 2554 # Conftest #2: Check if get_user_pages has gup_flags instead of 2555 # write and force parameters. And that gup doesn't accept a 2556 # task_struct and mm_struct as its first arguments. get_user_pages 2557 # has vm_area_struct as its last argument. 2558 # Return if available. 2559 # Fall through to conftest #3 on failure. 2560 2561 echo "$CONFTEST_PREAMBLE 2562 #include <linux/mm.h> 2563 long get_user_pages(unsigned long start, 2564 unsigned long nr_pages, 2565 unsigned int gup_flags, 2566 struct page **pages, 2567 struct vm_area_struct **vmas) { 2568 return 0; 2569 }" > conftest$$.c 2570 2571 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2572 rm -f conftest$$.c 2573 2574 if [ -f conftest$$.o ]; then 2575 set_get_user_pages_defines "NV_GET_USER_PAGES_HAS_ARGS_FLAGS_VMAS" 2576 rm -f conftest$$.o 2577 return 2578 fi 2579 2580 # Conftest #3: Check if get_user_pages has gup_flags instead of 2581 # write and force parameters. The gup has task_struct and 2582 # mm_struct as its first arguments. get_user_pages 2583 # has vm_area_struct as its last argument. 2584 # Return if available. 2585 # Fall through to conftest #4 on failure. 2586 2587 echo "$CONFTEST_PREAMBLE 2588 #include <linux/mm.h> 2589 long get_user_pages(struct task_struct *tsk, 2590 struct mm_struct *mm, 2591 unsigned long start, 2592 unsigned long nr_pages, 2593 unsigned int gup_flags, 2594 struct page **pages, 2595 struct vm_area_struct **vmas) { 2596 return 0; 2597 }" > conftest$$.c 2598 2599 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2600 rm -f conftest$$.c 2601 2602 if [ -f conftest$$.o ]; then 2603 set_get_user_pages_defines "NV_GET_USER_PAGES_HAS_ARGS_TSK_FLAGS_VMAS" 2604 rm -f conftest$$.o 2605 return 2606 fi 2607 2608 # Conftest #4: gup doesn't accept a task_struct and mm_struct as 2609 # its first arguments. check if get_user_pages() does not take 2610 # vmas argument. 2611 # Fall through to default case otherwise. 2612 2613 echo "$CONFTEST_PREAMBLE 2614 #include <linux/mm.h> 2615 long get_user_pages(unsigned long start, 2616 unsigned long nr_pages, 2617 unsigned int gup_flags, 2618 struct page **pages) { 2619 return 0; 2620 }" > conftest$$.c 2621 2622 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2623 rm -f conftest$$.c 2624 2625 if [ -f conftest$$.o ]; then 2626 set_get_user_pages_defines "NV_GET_USER_PAGES_HAS_ARGS_FLAGS" 2627 rm -f conftest$$.o 2628 return 2629 fi 2630 2631 set_get_user_pages_defines "NV_GET_USER_PAGES_HAS_ARGS_TSK_WRITE_FORCE_VMAS" 2632 2633 return 2634 ;; 2635 2636 get_user_pages_remote) 2637 # 2638 # Determine if the function get_user_pages_remote() is 2639 # present and has write/force/locked/tsk parameters. 2640 # 2641 # get_user_pages_remote() was added by commit 1e9877902dc7 2642 # ("mm/gup: Introduce get_user_pages_remote()") in v4.6 (2016-02-12) 2643 # 2644 # get_user_pages[_remote]() write/force parameters 2645 # replaced with gup_flags by commits 768ae309a961 ("mm: replace 2646 # get_user_pages() write/force parameters with gup_flags") and 2647 # commit 9beae1ea8930 ("mm: replace get_user_pages_remote() 2648 # write/force parameters with gup_flags") in v4.9 (2016-10-13) 2649 # 2650 # get_user_pages_remote() added 'locked' parameter by 2651 # commit 5b56d49fc31d ("mm: add locked parameter to 2652 # get_user_pages_remote()") in v4.10 (2016-12-14) 2653 # 2654 # get_user_pages_remote() removed 'tsk' parameter by 2655 # commit 64019a2e467a ("mm/gup: remove task_struct pointer for 2656 # all gup code") in v5.9-rc1 (2020-08-11). 2657 # 2658 # Removed vmas parameter from get_user_pages_remote() by commit 2659 # a4bde14d549 ("mm/gup: remove vmas parameter from get_user_pages_remote()") 2660 # in linux-next, expected in v6.5-rc1 2661 # 2662 2663 # 2664 # This function sets the NV_GET_USER_PAGES_REMOTE_* macros as per 2665 # the below passing conftest's 2666 # 2667 set_get_user_pages_remote_defines () { 2668 if [ "$1" = "" ]; then 2669 echo "#undef NV_GET_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions" 2670 else 2671 echo "#define NV_GET_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions" 2672 fi 2673 2674 if [ "$1" = "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_WRITE_FORCE_VMAS" ]; then 2675 echo "#define NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_WRITE_FORCE_VMAS" | append_conftest "functions" 2676 else 2677 echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_WRITE_FORCE_VMAS" | append_conftest "functions" 2678 fi 2679 2680 if [ "$1" = "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_VMAS" ]; then 2681 echo "#define NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_VMAS" | append_conftest "functions" 2682 else 2683 echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_VMAS" | append_conftest "functions" 2684 fi 2685 2686 if [ "$1" = "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_LOCKED_VMAS" ]; then 2687 echo "#define NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_LOCKED_VMAS" | append_conftest "functions" 2688 else 2689 echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_LOCKED_VMAS" | append_conftest "functions" 2690 fi 2691 2692 if [ "$1" = "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED_VMAS" ]; then 2693 echo "#define NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED_VMAS" | append_conftest "functions" 2694 else 2695 echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED_VMAS" | append_conftest "functions" 2696 fi 2697 2698 if [ "$1" = "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED" ]; then 2699 echo "#define NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED" | append_conftest "functions" 2700 else 2701 echo "#undef NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED" | append_conftest "functions" 2702 fi 2703 2704 } 2705 2706 # conftest #1: check if get_user_pages_remote() is available 2707 # return if not available. 2708 # Fall through to conftest #2 if it is present 2709 2710 echo "$CONFTEST_PREAMBLE 2711 #include <linux/mm.h> 2712 void conftest_get_user_pages_remote(void) { 2713 get_user_pages_remote(); 2714 }" > conftest$$.c 2715 2716 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2717 rm -f conftest$$.c 2718 2719 if [ -f conftest$$.o ]; then 2720 set_get_user_pages_remote_defines "" 2721 rm -f conftest$$.o 2722 return 2723 fi 2724 2725 # 2726 # conftest #2: check if get_user_pages_remote() has write, force 2727 # and vmas arguments. Return if these arguments are present 2728 # Fall through to conftest #3 if these args are absent. 2729 # 2730 echo "$CONFTEST_PREAMBLE 2731 #include <linux/mm.h> 2732 long get_user_pages_remote(struct task_struct *tsk, 2733 struct mm_struct *mm, 2734 unsigned long start, 2735 unsigned long nr_pages, 2736 int write, 2737 int force, 2738 struct page **pages, 2739 struct vm_area_struct **vmas) { 2740 return 0; 2741 }" > conftest$$.c 2742 2743 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2744 rm -f conftest$$.c 2745 2746 if [ -f conftest$$.o ]; then 2747 set_get_user_pages_remote_defines "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_WRITE_FORCE_VMAS" 2748 rm -f conftest$$.o 2749 return 2750 fi 2751 2752 # 2753 # conftest #3: check if get_user_pages_remote() has gpu_flags and 2754 # vmas arguments. Return if these arguments are present 2755 # Fall through to conftest #4 if these args are absent. 2756 # 2757 echo "$CONFTEST_PREAMBLE 2758 #include <linux/mm.h> 2759 long get_user_pages_remote(struct task_struct *tsk, 2760 struct mm_struct *mm, 2761 unsigned long start, 2762 unsigned long nr_pages, 2763 unsigned int gpu_flags, 2764 struct page **pages, 2765 struct vm_area_struct **vmas) { 2766 return 0; 2767 }" > conftest$$.c 2768 2769 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2770 rm -f conftest$$.c 2771 2772 if [ -f conftest$$.o ]; then 2773 set_get_user_pages_remote_defines "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_VMAS" 2774 rm -f conftest$$.o 2775 return 2776 fi 2777 2778 # 2779 # conftest #4: check if get_user_pages_remote() has locked and 2780 # vmas argument 2781 # Return if these arguments are present. Fall through to conftest #5 2782 # if these args are absent. 2783 # 2784 echo "$CONFTEST_PREAMBLE 2785 #include <linux/mm.h> 2786 long get_user_pages_remote(struct task_struct *tsk, 2787 struct mm_struct *mm, 2788 unsigned long start, 2789 unsigned long nr_pages, 2790 unsigned int gup_flags, 2791 struct page **pages, 2792 struct vm_area_struct **vmas, 2793 int *locked) { 2794 return 0; 2795 }" > conftest$$.c 2796 2797 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2798 rm -f conftest$$.c 2799 2800 if [ -f conftest$$.o ]; then 2801 set_get_user_pages_remote_defines "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_TSK_FLAGS_LOCKED_VMAS" 2802 rm -f conftest$$.o 2803 return 2804 fi 2805 2806 # 2807 # conftest #5: check if get_user_pages_remote() does not take 2808 # tsk argument. 2809 # 2810 echo "$CONFTEST_PREAMBLE 2811 #include <linux/mm.h> 2812 long get_user_pages_remote(struct mm_struct *mm, 2813 unsigned long start, 2814 unsigned long nr_pages, 2815 unsigned int gup_flags, 2816 struct page **pages, 2817 struct vm_area_struct **vmas, 2818 int *locked) { 2819 return 0; 2820 }" > conftest$$.c 2821 2822 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2823 rm -f conftest$$.c 2824 2825 if [ -f conftest$$.o ]; then 2826 set_get_user_pages_remote_defines "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED_VMAS" 2827 rm -f conftest$$.o 2828 fi 2829 2830 # 2831 # conftest #6: check if get_user_pages_remote() does not take 2832 # vmas argument. 2833 # 2834 echo "$CONFTEST_PREAMBLE 2835 #include <linux/mm.h> 2836 long get_user_pages_remote(struct mm_struct *mm, 2837 unsigned long start, 2838 unsigned long nr_pages, 2839 unsigned int gup_flags, 2840 struct page **pages, 2841 int *locked) { 2842 return 0; 2843 }" > conftest$$.c 2844 2845 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2846 rm -f conftest$$.c 2847 2848 if [ -f conftest$$.o ]; then 2849 set_get_user_pages_remote_defines "NV_GET_USER_PAGES_REMOTE_HAS_ARGS_FLAGS_LOCKED" 2850 rm -f conftest$$.o 2851 fi 2852 2853 ;; 2854 2855 pin_user_pages) 2856 # 2857 # Determine if the function pin_user_pages() is present. 2858 # Presence of pin_user_pages() also implies the presence of 2859 # unpin-user_page(). Both were added in the v5.6-rc1 2860 # 2861 # pin_user_pages() was added by commit eddb1c228f7951d399240 2862 # ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") in 2863 # v5.6-rc1 (2020-01-30) 2864 # 2865 # Removed vmas parameter from pin_user_pages() by commit 2866 # 40896a02751("mm/gup: remove vmas parameter from pin_user_pages()") 2867 # in linux-next, expected in v6.5-rc1 2868 2869 set_pin_user_pages_defines () { 2870 if [ "$1" = "" ]; then 2871 echo "#undef NV_PIN_USER_PAGES_PRESENT" | append_conftest "functions" 2872 else 2873 echo "#define NV_PIN_USER_PAGES_PRESENT" | append_conftest "functions" 2874 fi 2875 2876 if [ "$1" = "NV_PIN_USER_PAGES_HAS_ARGS_VMAS" ]; then 2877 echo "#define NV_PIN_USER_PAGES_HAS_ARGS_VMAS" | append_conftest "functions" 2878 else 2879 echo "#undef NV_PIN_USER_PAGES_HAS_ARGS_VMAS" | append_conftest "functions" 2880 fi 2881 2882 } 2883 2884 # conftest #1: check if pin_user_pages() is available 2885 # return if not available. 2886 # Fall through to conftest #2 if it is present 2887 # 2888 echo "$CONFTEST_PREAMBLE 2889 #include <linux/mm.h> 2890 void conftest_pin_user_pages(void) { 2891 pin_user_pages(); 2892 }" > conftest$$.c 2893 2894 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2895 rm -f conftest$$.c 2896 2897 if [ -f conftest$$.o ]; then 2898 set_pin_user_pages_defines "" 2899 rm -f conftest$$.o 2900 return 2901 fi 2902 2903 # conftest #2: Check if pin_user_pages() has vmas argument 2904 echo "$CONFTEST_PREAMBLE 2905 #include <linux/mm.h> 2906 long pin_user_pages(unsigned long start, 2907 unsigned long nr_pages, 2908 unsigned int gup_flags, 2909 struct page **pages, 2910 struct vm_area_struct **vmas) { 2911 return 0; 2912 }" > conftest$$.c 2913 2914 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2915 rm -f conftest$$.c 2916 2917 if [ -f conftest$$.o ]; then 2918 set_pin_user_pages_defines "NV_PIN_USER_PAGES_HAS_ARGS_VMAS" 2919 rm -f conftest$$.o 2920 else 2921 set_pin_user_pages_defines "NV_PIN_USER_PAGES_PRESENT" 2922 fi 2923 ;; 2924 2925 pin_user_pages_remote) 2926 # Determine if the function pin_user_pages_remote() is present 2927 # 2928 # pin_user_pages_remote() was added by commit eddb1c228f7951d399240 2929 # ("mm/gup: introduce pin_user_pages*() and FOLL_PIN") 2930 # in v5.6 (2020-01-30) 2931 2932 # pin_user_pages_remote() removed 'tsk' parameter by 2933 # commit 64019a2e467a ("mm/gup: remove task_struct pointer for 2934 # all gup code") in v5.9-rc1 (2020-08-11). 2935 # 2936 # Removed unused vmas parameter from pin_user_pages_remote() by 2937 # commit 83bcc2e132 ("mm/gup: remove unused vmas parameter from 2938 # pin_user_pages_remote()") in linux-next, expected in v6.5-rc1 2939 2940 # 2941 # This function sets the NV_PIN_USER_PAGES_REMOTE_* macros as per 2942 # the below passing conftest's 2943 # 2944 set_pin_user_pages_remote_defines () { 2945 if [ "$1" = "" ]; then 2946 echo "#undef NV_PIN_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions" 2947 else 2948 echo "#define NV_PIN_USER_PAGES_REMOTE_PRESENT" | append_conftest "functions" 2949 fi 2950 2951 if [ "$1" = "NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS" ]; then 2952 echo "#define NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS" | append_conftest "functions" 2953 else 2954 echo "#undef NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS" | append_conftest "functions" 2955 fi 2956 2957 if [ "$1" = "NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_VMAS" ]; then 2958 echo "#define NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_VMAS" | append_conftest "functions" 2959 else 2960 echo "#undef NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_VMAS" | append_conftest "functions" 2961 fi 2962 } 2963 2964 # conftest #1: check if pin_user_pages_remote() is available 2965 # return if not available. 2966 # Fall through to conftest #2 if it is present 2967 # 2968 echo "$CONFTEST_PREAMBLE 2969 #include <linux/mm.h> 2970 void conftest_pin_user_pages_remote(void) { 2971 pin_user_pages_remote(); 2972 }" > conftest$$.c 2973 2974 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 2975 rm -f conftest$$.c 2976 2977 if [ -f conftest$$.o ]; then 2978 set_pin_user_pages_remote_defines "" 2979 rm -f conftest$$.o 2980 return 2981 fi 2982 2983 # conftest #2: Check if pin_user_pages_remote() has tsk and 2984 # vmas argument 2985 # Return if these arguments are present else fall through to 2986 # conftest #3 2987 2988 echo "$CONFTEST_PREAMBLE 2989 #include <linux/mm.h> 2990 long pin_user_pages_remote(struct task_struct *tsk, 2991 struct mm_struct *mm, 2992 unsigned long start, 2993 unsigned long nr_pages, 2994 unsigned int gup_flags, 2995 struct page **pages, 2996 struct vm_area_struct **vmas, 2997 int *locked) { 2998 return 0; 2999 }" > conftest$$.c 3000 3001 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3002 rm -f conftest$$.c 3003 3004 if [ -f conftest$$.o ]; then 3005 set_pin_user_pages_remote_defines "NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_TSK_VMAS" 3006 rm -f conftest$$.o 3007 return 3008 fi 3009 3010 # conftest #3: Check if pin_user_pages_remote() has vmas argument 3011 echo "$CONFTEST_PREAMBLE 3012 #include <linux/mm.h> 3013 long pin_user_pages_remote(struct mm_struct *mm, 3014 unsigned long start, 3015 unsigned long nr_pages, 3016 unsigned int gup_flags, 3017 struct page **pages, 3018 struct vm_area_struct **vmas, 3019 int *locked) { 3020 return 0; 3021 }" > conftest$$.c 3022 3023 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3024 rm -f conftest$$.c 3025 3026 if [ -f conftest$$.o ]; then 3027 set_pin_user_pages_remote_defines "NV_PIN_USER_PAGES_REMOTE_HAS_ARGS_VMAS" 3028 rm -f conftest$$.o 3029 else 3030 set_pin_user_pages_remote_defines "NV_PIN_USER_PAGES_REMOTE_PRESENT" 3031 fi 3032 3033 ;; 3034 3035 vfio_pin_pages_has_vfio_device_arg) 3036 # 3037 # Determine if vfio_pin_pages() kABI accepts "struct vfio_device *" 3038 # argument instead of "struct device *" 3039 # 3040 # Replaced "struct device *" with "struct vfio_device *" by commit 3041 # 8e432bb015b6c ("vfio/mdev: Pass in a struct vfio_device * to 3042 # vfio_pin/unpin_pages()") in v5.19 3043 # 3044 echo "$CONFTEST_PREAMBLE 3045 #include <linux/pci.h> 3046 #include <linux/vfio.h> 3047 int vfio_pin_pages(struct vfio_device *device, 3048 unsigned long *user_pfn, 3049 int npage, 3050 int prot, 3051 unsigned long *phys_pfn) { 3052 return 0; 3053 }" > conftest$$.c 3054 3055 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3056 rm -f conftest$$.c 3057 3058 if [ -f conftest$$.o ]; then 3059 echo "#define NV_VFIO_PIN_PAGES_HAS_VFIO_DEVICE_ARG" | append_conftest "functions" 3060 rm -f conftest$$.o 3061 else 3062 echo "#undef NV_VFIO_PIN_PAGES_HAS_VFIO_DEVICE_ARG" | append_conftest "functions" 3063 fi 3064 ;; 3065 3066 vfio_pin_pages_has_pages_arg) 3067 # 3068 # Determine if vfio_pin_pages() kABI accepts "struct pages **: 3069 # argument instead of "unsigned long *phys_pfn" 3070 # 3071 # Replaced "unsigned long *phys_pfn" with "struct pages **pages" 3072 # in commit 34a255e676159 ("vfio: Replace phys_pfn with pages for 3073 # vfio_pin_pages()") in v6.0. 3074 # 3075 echo "$CONFTEST_PREAMBLE 3076 #include <linux/pci.h> 3077 #include <linux/vfio.h> 3078 int vfio_pin_pages(struct vfio_device *device, 3079 dma_addr_t iova, 3080 int npage, 3081 int prot, 3082 struct page **pages) { 3083 return 0; 3084 }" > conftest$$.c 3085 3086 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3087 rm -f conftest$$.c 3088 3089 if [ -f conftest$$.o ]; then 3090 echo "#define NV_VFIO_PIN_PAGES_HAS_PAGES_ARG" | append_conftest "functions" 3091 rm -f conftest$$.o 3092 else 3093 echo "#undef NV_VFIO_PIN_PAGES_HAS_PAGES_ARG" | append_conftest "functions" 3094 fi 3095 ;; 3096 3097 enable_apicv) 3098 # 3099 # Determine if enable_apicv boolean is exported by kernel. 3100 # 3101 # Added by commit fdf513e37a3bd ("KVM: x86: Use common 'enable_apicv' 3102 # variable for both APICv and AVIC") 3103 # 3104 CODE=" 3105 $CONFTEST_PREAMBLE 3106 #include <asm/kvm_host.h> 3107 3108 bool is_enable_apicv_present() { 3109 return enable_apicv; 3110 }" 3111 3112 compile_check_conftest "$CODE" "NV_ENABLE_APICV_PRESENT" "" "types" 3113 ;; 3114 3115 pci_driver_has_driver_managed_dma) 3116 # 3117 # Determine if "struct pci_driver" has .driver_managed_dma member. 3118 # 3119 # Added by commit 512881eacfa7 ("bus: platform,amba,fsl-mc,PCI: 3120 # Add device DMA ownership management") in v5.19 3121 # 3122 CODE=" 3123 #include <linux/pci.h> 3124 int conftest_pci_driver_has_driver_managed_dma(void) { 3125 return offsetof(struct pci_driver, driver_managed_dma); 3126 }" 3127 3128 compile_check_conftest "$CODE" "NV_PCI_DRIVER_HAS_DRIVER_MANAGED_DMA" "" "types" 3129 ;; 3130 3131 radix_tree_empty) 3132 # 3133 # Determine if the function radix_tree_empty() is present. 3134 # 3135 # Added by commit e9256efcc8e3 ("radix-tree: introduce 3136 # radix_tree_empty") in v4.7 (2016-05-20) 3137 # 3138 CODE=" 3139 #include <linux/radix-tree.h> 3140 int conftest_radix_tree_empty(void) { 3141 radix_tree_empty(); 3142 }" 3143 3144 compile_check_conftest "$CODE" "NV_RADIX_TREE_EMPTY_PRESENT" "" "functions" 3145 ;; 3146 3147 drm_gem_object_lookup) 3148 # 3149 # Determine the number of arguments of drm_gem_object_lookup(). 3150 # 3151 # First argument of type drm_device removed by commit 3152 # a8ad0bd84f98 ("drm: Remove unused drm_device from 3153 # drm_gem_object_lookup()") in v4.7 (2016-05-09) 3154 # 3155 echo "$CONFTEST_PREAMBLE 3156 #if defined(NV_DRM_DRMP_H_PRESENT) 3157 #include <drm/drmP.h> 3158 #endif 3159 #if defined(NV_DRM_DRM_GEM_H_PRESENT) 3160 #include <drm/drm_gem.h> 3161 #endif 3162 void conftest_drm_gem_object_lookup(void) { 3163 drm_gem_object_lookup(NULL, NULL, 0); 3164 }" > conftest$$.c 3165 3166 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3167 rm -f conftest$$.c 3168 3169 if [ -f conftest$$.o ]; then 3170 echo "#define NV_DRM_GEM_OBJECT_LOOKUP_ARGUMENT_COUNT 3" | append_conftest "functions" 3171 rm -f conftest$$.o 3172 return 3173 else 3174 echo "#define NV_DRM_GEM_OBJECT_LOOKUP_ARGUMENT_COUNT 2" | append_conftest "functions" 3175 fi 3176 ;; 3177 3178 drm_master_drop_has_from_release_arg) 3179 # 3180 # Determine if drm_driver::master_drop() has 'from_release' argument. 3181 # 3182 # Last argument 'bool from_release' has been removed by commit 3183 # d6ed682eba54 ("drm: Refactor drop/set master code a bit") 3184 # in v4.8 (2016-06-21) 3185 # 3186 CODE=" 3187 #if defined(NV_DRM_DRMP_H_PRESENT) 3188 #include <drm/drmP.h> 3189 #endif 3190 3191 void conftest_drm_master_drop_has_from_release_arg(struct drm_driver *drv) { 3192 drv->master_drop(NULL, NULL, false); 3193 }" 3194 3195 compile_check_conftest "$CODE" "NV_DRM_MASTER_DROP_HAS_FROM_RELEASE_ARG" "" "types" 3196 ;; 3197 3198 drm_master_has_leases) 3199 # 3200 # Determine if drm_master has 'leases', 'lessor', 'lessee_idr' fields. 3201 # Also checks for struct drm_mode_revoke_lease. 3202 # 3203 # Added by commits 2ed077e467ee ("drm: Add drm_object lease infrastructure [v5]") 3204 # and 62884cd386b8 ("drm: Add four ioctls for managing drm mode object leases [v7]") 3205 # in v4.15 (2017-10-24) 3206 # 3207 CODE=" 3208 #if defined(NV_DRM_DRMP_H_PRESENT) 3209 #include <drm/drmP.h> 3210 #endif 3211 #if defined(NV_DRM_DRM_AUTH_H_PRESENT) 3212 #include <drm/drm_auth.h> 3213 #endif 3214 #include <uapi/drm/drm_mode.h> 3215 3216 int conftest_drm_master_leases(void) { 3217 return offsetof(struct drm_master, leases); 3218 } 3219 int conftest_drm_master_lessor(void) { 3220 return offsetof(struct drm_master, lessor); 3221 } 3222 int conftest_drm_master_lessee_idr(void) { 3223 return offsetof(struct drm_master, lessee_idr); 3224 } 3225 int conftest_drm_mode_revoke_lease(void) { 3226 return offsetof(struct drm_mode_revoke_lease, lessee_id); 3227 }" 3228 3229 compile_check_conftest "$CODE" "NV_DRM_MASTER_HAS_LEASES" "" "types" 3230 ;; 3231 3232 drm_file_get_master) 3233 # 3234 # Determine if function drm_file_get_master() is present. 3235 # 3236 # Added by commit 56f0729a510f ("drm: protect drm_master pointers in drm_lease.c") 3237 # in v5.15 (2021-07-20) 3238 # 3239 3240 CODE=" 3241 #if defined(NV_DRM_DRMP_H_PRESENT) 3242 #include <drm/drmP.h> 3243 #endif 3244 #if defined(NV_DRM_DRM_AUTH_H_PRESENT) 3245 #include <drm/drm_auth.h> 3246 #endif 3247 3248 void conftest_drm_file_get_master(void) { 3249 drm_file_get_master(); 3250 }" 3251 3252 compile_check_conftest "$CODE" "NV_DRM_FILE_GET_MASTER_PRESENT" "" "functions" 3253 ;; 3254 3255 drm_connector_lookup) 3256 # 3257 # Determine if function drm_connector_lookup() is present. 3258 # 3259 # Added by commit b164d31f50b2 ("drm/modes: add connector reference 3260 # counting. (v2)") in v4.7 (2016-05-04), when it replaced 3261 # drm_connector_find(). 3262 # 3263 # It was originally added in drm_crtc.h, then moved to 3264 # drm_connector.h by commit 522171951761 3265 # ("drm: Extract drm_connector.[hc]") in v4.9 (2016-08-12) 3266 # 3267 3268 CODE=" 3269 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 3270 #include <drm/drm_crtc.h> 3271 #endif 3272 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 3273 #include <drm/drm_connector.h> 3274 #endif 3275 void conftest_drm_connector_lookup(void) { 3276 drm_connector_lookup(); 3277 }" 3278 3279 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_LOOKUP_PRESENT" "" "functions" 3280 ;; 3281 3282 drm_connector_put) 3283 # 3284 # Determine if function drm_connector_put() is present. 3285 # 3286 # Added by commit ad09360750af ("drm: Introduce 3287 # drm_connector_{get,put}()") in v4.12 (2017-02-28), 3288 # when it replaced drm_connector_unreference() that 3289 # was added with NV_DRM_CONNECTOR_LOOKUP_PRESENT. 3290 # 3291 3292 CODE=" 3293 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 3294 #include <drm/drm_connector.h> 3295 #endif 3296 void conftest_drm_connector_put(void) { 3297 drm_connector_put(); 3298 }" 3299 3300 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_PUT_PRESENT" "" "functions" 3301 ;; 3302 3303 drm_modeset_lock_all_end) 3304 # 3305 # Determine the number of arguments of the 3306 # DRM_MODESET_LOCK_ALL_END() macro. 3307 # 3308 # DRM_MODESET_LOCK_ALL_END() is added with two arguments by commit 3309 # b7ea04d299c7 (drm: drm: Add DRM_MODESET_LOCK_BEGIN/END helpers) 3310 # in v5.0 (2018-11-29). The definition and prototype is changed to 3311 # also take the third argument drm_device, by commit 77ef38574beb 3312 # (drm/modeset-lock: Take the modeset BKL for legacy drivers) 3313 # in v5.9 (2020-08-17). 3314 # 3315 DRM_MODESET_3_COMPILED=0 3316 DRM_MODESET_2_COMPILED=0 3317 DRM_MODESET_INCLUDES=" 3318 #if defined(NV_DRM_DRM_DEVICE_H_PRESENT) 3319 #include <drm/drm_device.h> 3320 #endif 3321 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 3322 #include <drm/drm_drv.h> 3323 #endif 3324 #if defined(NV_DRM_DRM_MODESET_LOCK_H_PRESENT) 3325 #include <drm/drm_modeset_lock.h> 3326 #endif" 3327 3328 echo "$CONFTEST_PREAMBLE 3329 $DRM_MODESET_INCLUDES 3330 3331 void conftest_drm_modeset_lock_all_end( 3332 struct drm_device *dev, 3333 struct drm_modeset_acquire_ctx ctx, 3334 int ret) { 3335 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); 3336 DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); 3337 }" > conftest$$.c 3338 3339 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3340 rm -f conftest$$.c 3341 3342 if [ -f conftest$$.o ]; then 3343 DRM_MODESET_3_COMPILED=1 3344 rm -f conftest$$.o 3345 fi 3346 3347 echo "$CONFTEST_PREAMBLE 3348 $DRM_MODESET_INCLUDES 3349 3350 void conftest_drm_modeset_lock_all_end( 3351 struct drm_device *dev, 3352 struct drm_modeset_acquire_ctx ctx, 3353 int ret) { 3354 DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); 3355 DRM_MODESET_LOCK_ALL_END(ctx, ret); 3356 }" > conftest$$.c 3357 3358 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3359 rm -f conftest$$.c 3360 3361 if [ -f conftest$$.o ]; then 3362 DRM_MODESET_2_COMPILED=1 3363 rm -f conftest$$.o 3364 fi 3365 3366 # If the macro is undefined, both code snippets will still compile, 3367 # so we need to check both and make sure only one compiles successfully. 3368 if [ "$DRM_MODESET_3_COMPILED" = "1" ] && 3369 [ "$DRM_MODESET_2_COMPILED" = "0" ]; then 3370 echo "#define NV_DRM_MODESET_LOCK_ALL_END_ARGUMENT_COUNT 3" | append_conftest "functions" 3371 elif [ "$DRM_MODESET_3_COMPILED" = "0" ] && 3372 [ "$DRM_MODESET_2_COMPILED" = "1" ]; then 3373 echo "#define NV_DRM_MODESET_LOCK_ALL_END_ARGUMENT_COUNT 2" | append_conftest "functions" 3374 else 3375 echo "#define NV_DRM_MODESET_LOCK_ALL_END_ARGUMENT_COUNT 0" | append_conftest "functions" 3376 fi 3377 ;; 3378 3379 drm_atomic_state_ref_counting) 3380 # 3381 # Determine if functions drm_atomic_state_get/put() are 3382 # present. 3383 # 3384 # Added by commit 0853695c3ba4 ("drm: Add reference counting to 3385 # drm_atomic_state") in v4.10 (2016-10-14) 3386 # 3387 CODE=" 3388 #if defined(NV_DRM_DRM_ATOMIC_H_PRESENT) 3389 #include <drm/drm_atomic.h> 3390 #endif 3391 void conftest_drm_atomic_state_get(void) { 3392 drm_atomic_state_get(); 3393 }" 3394 3395 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_STATE_REF_COUNTING_PRESENT" "" "functions" 3396 ;; 3397 3398 vm_ops_fault_removed_vma_arg) 3399 # 3400 # Determine if vma.vm_ops.fault takes (vma, vmf), or just (vmf) 3401 # args. Acronym key: 3402 # vma: struct vm_area_struct 3403 # vm_ops: struct vm_operations_struct 3404 # vmf: struct vm_fault 3405 # 3406 # The redundant vma arg was removed from BOTH vma.vm_ops.fault and 3407 # vma.vm_ops.page_mkwrite by commit 11bac8000449 ("mm, fs: reduce 3408 # fault, page_mkwrite, and pfn_mkwrite to take only vmf") in 3409 # v4.11 (2017-02-24) 3410 # 3411 CODE=" 3412 #include <linux/mm.h> 3413 void conftest_vm_ops_fault_removed_vma_arg(void) { 3414 struct vm_operations_struct vm_ops; 3415 struct vm_fault *vmf; 3416 (void)vm_ops.fault(vmf); 3417 }" 3418 3419 compile_check_conftest "$CODE" "NV_VM_OPS_FAULT_REMOVED_VMA_ARG" "" "types" 3420 ;; 3421 3422 pnv_npu2_init_context) 3423 # 3424 # Determine if the pnv_npu2_init_context() function is 3425 # present and the signature of its callback. 3426 # 3427 # Added by commit 1ab66d1fbada ("powerpc/powernv: Introduce 3428 # address translation services for Nvlink2") in v4.12 3429 # (2017-04-03). 3430 # 3431 echo "$CONFTEST_PREAMBLE 3432 #if defined(NV_ASM_POWERNV_H_PRESENT) 3433 #include <linux/pci.h> 3434 #include <asm/powernv.h> 3435 #endif 3436 void conftest_pnv_npu2_init_context(void) { 3437 pnv_npu2_init_context(); 3438 }" > conftest$$.c 3439 3440 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3441 rm -f conftest$$.c 3442 if [ -f conftest$$.o ]; then 3443 echo "#undef NV_PNV_NPU2_INIT_CONTEXT_PRESENT" | append_conftest "functions" 3444 echo "#undef NV_PNV_NPU2_INIT_CONTEXT_CALLBACK_RETURNS_VOID" | append_conftest "functions" 3445 rm -f conftest$$.o 3446 return 3447 fi 3448 3449 echo "#define NV_PNV_NPU2_INIT_CONTEXT_PRESENT" | append_conftest "functions" 3450 3451 # Check the callback signature 3452 echo "$CONFTEST_PREAMBLE 3453 #if defined(NV_ASM_POWERNV_H_PRESENT) 3454 #include <linux/pci.h> 3455 #include <asm/powernv.h> 3456 #endif 3457 3458 struct npu_context *pnv_npu2_init_context(struct pci_dev *gpdev, 3459 unsigned long flags, 3460 void (*cb)(struct npu_context *, void *), 3461 void *priv) { 3462 return NULL; 3463 }" > conftest$$.c 3464 3465 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3466 rm -f conftest$$.c 3467 if [ -f conftest$$.o ]; then 3468 echo "#define NV_PNV_NPU2_INIT_CONTEXT_CALLBACK_RETURNS_VOID" | append_conftest "functions" 3469 rm -f conftest$$.o 3470 return 3471 fi 3472 3473 echo "#undef NV_PNV_NPU2_INIT_CONTEXT_CALLBACK_RETURNS_VOID" | append_conftest "functions" 3474 ;; 3475 3476 of_get_ibm_chip_id) 3477 # 3478 # Determine if the of_get_ibm_chip_id() function is present. 3479 # 3480 # Added by commit b130e7c04f11 ("powerpc: export 3481 # of_get_ibm_chip_id function") in v4.2 (2015-05-07) 3482 # 3483 CODE=" 3484 #include <linux/version.h> 3485 #if defined(NV_ASM_PROM_H_PRESENT) 3486 #include <asm/prom.h> 3487 #endif 3488 void conftest_of_get_ibm_chip_id(void) { 3489 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) 3490 of_get_ibm_chip_id(); 3491 #endif 3492 }" 3493 3494 compile_check_conftest "$CODE" "NV_OF_GET_IBM_CHIP_ID_PRESENT" "" "functions" 3495 ;; 3496 3497 drm_driver_unload_has_int_return_type) 3498 # 3499 # Determine if drm_driver::unload() returns integer value 3500 # 3501 # Changed to void by commit 11b3c20bdd15 ("drm: Change the return 3502 # type of the unload hook to void") in v4.11 (2017-01-06) 3503 # 3504 CODE=" 3505 #if defined(NV_DRM_DRMP_H_PRESENT) 3506 #include <drm/drmP.h> 3507 #endif 3508 3509 int conftest_drm_driver_unload_has_int_return_type(struct drm_driver *drv) { 3510 return drv->unload(NULL /* dev */); 3511 }" 3512 3513 compile_check_conftest "$CODE" "NV_DRM_DRIVER_UNLOAD_HAS_INT_RETURN_TYPE" "" "types" 3514 ;; 3515 3516 is_export_symbol_present_*) 3517 export_symbol_present_conftest $(echo $1 | cut -f5- -d_) 3518 ;; 3519 3520 is_export_symbol_gpl_*) 3521 export_symbol_gpl_conftest $(echo $1 | cut -f5- -d_) 3522 ;; 3523 3524 drm_atomic_helper_crtc_destroy_state_has_crtc_arg) 3525 # 3526 # Determine if __drm_atomic_helper_crtc_destroy_state() has 'crtc' 3527 # argument. 3528 # 3529 # 'crtc' argument removed by commit ec2dc6a0fe38 ("drm: Drop crtc 3530 # argument from __drm_atomic_helper_crtc_destroy_state") in v4.7 3531 # (2016-05-09) 3532 # 3533 CODE=" 3534 #if defined(NV_DRM_DRM_ATOMIC_HELPER_H_PRESENT) 3535 #include <drm/drm_atomic_helper.h> 3536 #endif 3537 void conftest_drm_atomic_helper_crtc_destroy_state_has_crtc_arg(void) { 3538 __drm_atomic_helper_crtc_destroy_state(NULL, NULL); 3539 }" 3540 3541 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_CRTC_DESTROY_STATE_HAS_CRTC_ARG" "" "types" 3542 ;; 3543 3544 drm_atomic_helper_plane_destroy_state_has_plane_arg) 3545 # 3546 # Determine if __drm_atomic_helper_plane_destroy_state has 3547 # 'plane' argument. 3548 # 3549 # 'plane' argument removed by commit 2f701695fd3a (drm: Drop plane 3550 # argument from __drm_atomic_helper_plane_destroy_state") in v4.7 3551 # (2016-05-09) 3552 # 3553 CODE=" 3554 #if defined(NV_DRM_DRM_ATOMIC_HELPER_H_PRESENT) 3555 #include <drm/drm_atomic_helper.h> 3556 #endif 3557 void conftest_drm_atomic_helper_plane_destroy_state_has_plane_arg(void) { 3558 __drm_atomic_helper_plane_destroy_state(NULL, NULL); 3559 }" 3560 3561 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_PLANE_DESTROY_STATE_HAS_PLANE_ARG" "" "types" 3562 ;; 3563 3564 drm_atomic_helper_connector_dpms) 3565 # 3566 # Determine if the function drm_atomic_helper_connector_dpms() is present. 3567 # 3568 # Removed by commit 7d902c05b480 ("drm: Nuke 3569 # drm_atomic_helper_connector_dpms") in v4.14 (2017-07-25) 3570 # 3571 CODE=" 3572 #if defined(NV_DRM_DRM_ATOMIC_HELPER_H_PRESENT) 3573 #include <drm/drm_atomic_helper.h> 3574 #endif 3575 void conftest_drm_atomic_helper_connector_dpms(void) { 3576 drm_atomic_helper_connector_dpms(); 3577 }" 3578 3579 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_CONNECTOR_DPMS_PRESENT" "" "functions" 3580 ;; 3581 3582 get_backlight_device_by_name) 3583 # 3584 # Determine if the get_backlight_device_by_name() function is present 3585 # 3586 CODE=" 3587 #include <linux/backlight.h> 3588 int conftest_get_backlight_device_by_name(void) { 3589 return get_backlight_device_by_name(); 3590 }" 3591 compile_check_conftest "$CODE" "NV_GET_BACKLIGHT_DEVICE_BY_NAME_PRESENT" "" "functions" 3592 ;; 3593 3594 timer_setup) 3595 # 3596 # Determine if the function timer_setup() is present. 3597 # 3598 # Added by commit 686fef928bba ("timer: Prepare to change timer 3599 # callback argument type") in v4.14 (2017-09-28) 3600 # 3601 CODE=" 3602 #include <linux/timer.h> 3603 int conftest_timer_setup(void) { 3604 return timer_setup(); 3605 }" 3606 compile_check_conftest "$CODE" "NV_TIMER_SETUP_PRESENT" "" "functions" 3607 ;; 3608 3609 radix_tree_replace_slot) 3610 # 3611 # Determine if the radix_tree_replace_slot() function is 3612 # present and how many arguments it takes. 3613 # 3614 # root parameter added to radix_tree_replace_slot (but the symbol 3615 # was not exported) by commit 6d75f366b924 ("lib: radix-tree: 3616 # check accounting of existing slot replacement users") in v4.10 3617 # (2016-12-12) 3618 # 3619 # radix_tree_replace_slot symbol export added by commit 3620 # 10257d719686 ("EXPORT_SYMBOL radix_tree_replace_slot") in v4.11 3621 # (2017-01-11) 3622 # 3623 CODE=" 3624 #include <linux/radix-tree.h> 3625 #include <linux/version.h> 3626 void conftest_radix_tree_replace_slot(void) { 3627 #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)) 3628 radix_tree_replace_slot(); 3629 #endif 3630 }" 3631 compile_check_conftest "$CODE" "NV_RADIX_TREE_REPLACE_SLOT_PRESENT" "" "functions" 3632 3633 echo "$CONFTEST_PREAMBLE 3634 #include <linux/radix-tree.h> 3635 void conftest_radix_tree_replace_slot(void) { 3636 radix_tree_replace_slot(NULL, NULL); 3637 }" > conftest$$.c 3638 3639 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3640 rm -f conftest$$.c 3641 3642 if [ -f conftest$$.o ]; then 3643 rm -f conftest$$.o 3644 echo "#define NV_RADIX_TREE_REPLACE_SLOT_ARGUMENT_COUNT 2" | append_conftest "functions" 3645 return 3646 fi 3647 3648 echo "$CONFTEST_PREAMBLE 3649 #include <linux/radix-tree.h> 3650 void conftest_radix_tree_replace_slot(void) { 3651 radix_tree_replace_slot(NULL, NULL, NULL); 3652 }" > conftest$$.c 3653 3654 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3655 rm -f conftest$$.c 3656 3657 if [ -f conftest$$.o ]; then 3658 rm -f conftest$$.o 3659 echo "#define NV_RADIX_TREE_REPLACE_SLOT_ARGUMENT_COUNT 3" | append_conftest "functions" 3660 return 3661 else 3662 echo "#error radix_tree_replace_slot() conftest failed!" | append_conftest "functions" 3663 fi 3664 ;; 3665 3666 cpumask_of_node) 3667 # 3668 # Determine whether cpumask_of_node is available. 3669 # 3670 # ARM support for cpumask_of_node() lagged until commit 1a2db300348b 3671 # ("arm64, numa: Add NUMA support for arm64 platforms.") in v4.7 3672 # (2016-04-08) 3673 # 3674 CODE=" 3675 #include <asm/topology.h> 3676 void conftest_cpumask_of_node(void) { 3677 (void)cpumask_of_node(); 3678 }" 3679 3680 compile_check_conftest "$CODE" "NV_CPUMASK_OF_NODE_PRESENT" "" "functions" 3681 ;; 3682 3683 drm_mode_object_find_has_file_priv_arg) 3684 # 3685 # Determine if drm_mode_object_find() has 'file_priv' arguments. 3686 # 3687 # Updated to take 'file_priv' argument by commit 418da17214ac 3688 # ("drm: Pass struct drm_file * to __drm_mode_object_find [v2]") 3689 # in v4.15 (2017-03-14) 3690 # 3691 CODE=" 3692 #include <drm/drm_mode_object.h> 3693 void conftest_drm_mode_object_find_has_file_priv_arg( 3694 struct drm_device *dev, 3695 struct drm_file *file_priv, 3696 uint32_t id, 3697 uint32_t type) { 3698 (void)drm_mode_object_find(dev, file_priv, id, type); 3699 }" 3700 3701 compile_check_conftest "$CODE" "NV_DRM_MODE_OBJECT_FIND_HAS_FILE_PRIV_ARG" | append_conftest "types" 3702 ;; 3703 3704 pci_enable_msix_range) 3705 # 3706 # Determine if the pci_enable_msix_range() function is present. 3707 # 3708 # Added by commit 302a2523c277 ("PCI/MSI: Add 3709 # pci_enable_msi_range() and pci_enable_msix_range()") in v3.14 3710 # (2013-12-30) 3711 # 3712 CODE=" 3713 #include <linux/pci.h> 3714 void conftest_pci_enable_msix_range(void) { 3715 pci_enable_msix_range(); 3716 }" 3717 3718 compile_check_conftest "$CODE" "NV_PCI_ENABLE_MSIX_RANGE_PRESENT" "" "functions" 3719 ;; 3720 3721 dma_buf_owner) 3722 # 3723 # Determine if the dma_buf struct has an owner member. 3724 # 3725 # Added by commit 9abdffe286c1 ("dma-buf: add ref counting for 3726 # module as exporter") in v4.2 (2015-05-05) 3727 # 3728 CODE=" 3729 #include <linux/dma-buf.h> 3730 int conftest_dma_buf_owner(void) { 3731 return offsetof(struct dma_buf, owner); 3732 }" 3733 3734 compile_check_conftest "$CODE" "NV_DMA_BUF_OWNER_PRESENT" "" "types" 3735 ;; 3736 3737 dma_buf_export_args) 3738 # 3739 # Determine argument count for dma_buf_export(). 3740 # 3741 # 4 arguments added by commit d15bd7ee445d 3742 # ("dma-buf: Introduce dma buffer sharing mechanism") 3743 # in v3.3 (2011-12-26) 3744 # 3745 # Additional argument added by commit 3aac4502fd3f 3746 # ("dma-buf: use reservation objects") in v3.17 (2014-07-01). 3747 # 3748 # Parameters wrapped in a single struct dma_buf_export_info by commit: 3749 # d8fbe341beb6("dma-buf: cleanup dma_buf_export() to make it easily extensible") 3750 # in v4.1 (2015-01-23). 3751 # 3752 echo "$CONFTEST_PREAMBLE 3753 #include <linux/dma-buf.h> 3754 struct dma_buf* conftest_dma_buf_export(void) { 3755 return dma_buf_export(NULL); 3756 }" > conftest$$.c 3757 3758 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3759 rm -f conftest$$.c 3760 3761 if [ -f conftest$$.o ]; then 3762 rm -f conftest$$.o 3763 echo "#define NV_DMA_BUF_EXPORT_ARGUMENT_COUNT 1" | append_conftest "functions" 3764 return 3765 fi 3766 3767 echo "$CONFTEST_PREAMBLE 3768 #include <linux/dma-buf.h> 3769 struct dma_buf* conftest_dma_buf_export(void) { 3770 return dma_buf_export(NULL, NULL, 0, 0); 3771 }" > conftest$$.c 3772 3773 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3774 rm -f conftest$$.c 3775 3776 if [ -f conftest$$.o ]; then 3777 rm -f conftest$$.o 3778 echo "#define NV_DMA_BUF_EXPORT_ARGUMENT_COUNT 4" | append_conftest "functions" 3779 return 3780 fi 3781 3782 echo "$CONFTEST_PREAMBLE 3783 #include <linux/dma-buf.h> 3784 struct dma_buf* conftest_dma_buf_export(void) { 3785 return dma_buf_export(NULL, NULL, 0, 0, NULL); 3786 }" > conftest$$.c 3787 3788 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3789 rm -f conftest$$.c 3790 3791 if [ -f conftest$$.o ]; then 3792 rm -f conftest$$.o 3793 echo "#define NV_DMA_BUF_EXPORT_ARGUMENT_COUNT 5" | append_conftest "functions" 3794 return 3795 fi 3796 echo "#error dma_buf_export() conftest failed!" | append_conftest "functions" 3797 ;; 3798 3799 dma_buf_ops_has_kmap) 3800 # 3801 # Determine if .kmap exists in dma_buf_ops. 3802 # In some kernels, this is a mandatory callback. 3803 # 3804 # Added by commit fc13020e086b 3805 # ("dma-buf: add support for kernel cpu access") in v3.4 (2012-03-20) 3806 # 3807 echo "$CONFTEST_PREAMBLE 3808 #include <linux/dma-buf.h> 3809 int conftest_dma_buf_ops_has_kmap(void) { 3810 return offsetof(struct dma_buf_ops, kmap); 3811 } 3812 int conftest_dma_buf_ops_has_kunmap(void) { 3813 return offsetof(struct dma_buf_ops, kunmap); 3814 }" > conftest$$.c 3815 3816 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3817 rm -f conftest$$.c 3818 3819 if [ -f conftest$$.o ]; then 3820 echo "#define NV_DMA_BUF_OPS_HAS_KMAP" | append_conftest "types" 3821 rm -f conftest$$.o 3822 return 3823 else 3824 echo "#undef NV_DMA_BUF_OPS_HAS_KMAP" | append_conftest "types" 3825 return 3826 fi 3827 ;; 3828 3829 dma_buf_ops_has_kmap_atomic) 3830 # 3831 # Determine if .kmap_atomic exists in dma_buf_ops. 3832 # In some kernels, this is a mandatory callback. 3833 # 3834 # Added by commit fc13020e086b 3835 # ("dma-buf: add support for kernel cpu access")in v3.4 (2012-03-20) 3836 # 3837 echo "$CONFTEST_PREAMBLE 3838 #include <linux/dma-buf.h> 3839 int conftest_dma_buf_ops_has_kmap_atomic(void) { 3840 return offsetof(struct dma_buf_ops, kmap_atomic); 3841 } 3842 int conftest_dma_buf_ops_has_kunmap_atomic(void) { 3843 return offsetof(struct dma_buf_ops, kunmap_atomic); 3844 }" > conftest$$.c 3845 3846 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3847 rm -f conftest$$.c 3848 3849 if [ -f conftest$$.o ]; then 3850 echo "#define NV_DMA_BUF_OPS_HAS_KMAP_ATOMIC" | append_conftest "types" 3851 rm -f conftest$$.o 3852 return 3853 else 3854 echo "#undef NV_DMA_BUF_OPS_HAS_KMAP_ATOMIC" | append_conftest "types" 3855 return 3856 fi 3857 ;; 3858 3859 dma_buf_ops_has_map) 3860 # 3861 # Determine if .map exists in dma_buf_ops. 3862 # In some kernels, this is a mandatory callback. 3863 # 3864 # Added by commit f9b67f0014cb 3865 # ("dma-buf: Rename dma-ops to prevent conflict with kunmap_atomic macro") 3866 # in v4.12 (2017-04-19) 3867 # 3868 # Removed as a mandatory callback by commit f82aab2d521e 3869 # ("dma-buf: Remove requirement for ops->map() from dma_buf_export") 3870 # in v4.20 (2018-08-07) 3871 # 3872 # Completely removed from dma-buf by commit 4337ebbbbda3 3873 # ("dma-buf: Remove kernel map/unmap hooks") in v5.6 (2019-11-18) 3874 # 3875 echo "$CONFTEST_PREAMBLE 3876 #include <linux/dma-buf.h> 3877 int conftest_dma_buf_ops_has_map(void) { 3878 return offsetof(struct dma_buf_ops, map); 3879 } 3880 int conftest_dma_buf_ops_has_unmap(void) { 3881 return offsetof(struct dma_buf_ops, unmap); 3882 }" > conftest$$.c 3883 3884 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3885 rm -f conftest$$.c 3886 3887 if [ -f conftest$$.o ]; then 3888 echo "#define NV_DMA_BUF_OPS_HAS_MAP" | append_conftest "types" 3889 rm -f conftest$$.o 3890 return 3891 else 3892 echo "#undef NV_DMA_BUF_OPS_HAS_MAP" | append_conftest "types" 3893 return 3894 fi 3895 ;; 3896 3897 dma_buf_ops_has_map_atomic) 3898 # 3899 # Determine if map_atomic/unmap_atomic exists in dma_buf_ops. 3900 # In some kernels, this is a mandatory callback. 3901 # 3902 # Added by commit f9b67f0014cb 3903 # ("dma-buf: Rename dma-ops to prevent conflict with kunmap_atomic macro") 3904 # in v4.12 (2017-04-19) 3905 # 3906 # Removed by commit f664a5269542 3907 # ("dma-buf: remove kmap_atomic interface") in v4.19 (2018-05-28) 3908 # 3909 echo "$CONFTEST_PREAMBLE 3910 #include <linux/dma-buf.h> 3911 int conftest_dma_buf_ops_has_map_atomic(void) { 3912 return offsetof(struct dma_buf_ops, map_atomic); 3913 } 3914 int conftest_dma_buf_ops_has_unmap_atomic(void) { 3915 return offsetof(struct dma_buf_ops, unmap_atomic); 3916 }" > conftest$$.c 3917 3918 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3919 rm -f conftest$$.c 3920 3921 if [ -f conftest$$.o ]; then 3922 echo "#define NV_DMA_BUF_OPS_HAS_MAP_ATOMIC" | append_conftest "types" 3923 rm -f conftest$$.o 3924 return 3925 else 3926 echo "#undef NV_DMA_BUF_OPS_HAS_MAP_ATOMIC" | append_conftest "types" 3927 return 3928 fi 3929 ;; 3930 3931 dma_buf_has_dynamic_attachment) 3932 # 3933 # Determine if the function dma_buf_attachment_is_dynamic() 3934 # is present. 3935 # 3936 # Added by commit: 15fd552d186c 3937 # ("dma-buf: change DMA-buf locking convention v3") in v5.5 (2018-07-03) 3938 # 3939 echo "$CONFTEST_PREAMBLE 3940 #include <linux/dma-buf.h> 3941 bool conftest_dma_buf_attachment_is_dynamic(void) { 3942 return dma_buf_attachment_is_dynamic(NULL); 3943 }" > conftest$$.c 3944 3945 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3946 rm -f conftest$$.c 3947 3948 if [ -f conftest$$.o ]; then 3949 echo "#define NV_DMA_BUF_HAS_DYNAMIC_ATTACHMENT" | append_conftest "functions" 3950 rm -f conftest$$.o 3951 return 3952 else 3953 echo "#undef NV_DMA_BUF_HAS_DYNAMIC_ATTACHMENT" | append_conftest "functions" 3954 return 3955 fi 3956 ;; 3957 3958 dma_buf_attachment_has_peer2peer) 3959 # 3960 # Determine if peer2peer is present in struct dma_buf_attachment. 3961 # peer2peer being true indicates that a dma-buf importer is able 3962 # to handle peer resources not backed by struct page. 3963 # 3964 # Added by commit: 09606b5446c2 3965 # ("dma-buf: add peer2peer flag") in v5.8 (2018-03-22) 3966 # 3967 echo "$CONFTEST_PREAMBLE 3968 #include <linux/dma-buf.h> 3969 int conftest_dma_buf_peer2peer(void) { 3970 return offsetof(struct dma_buf_attachment, peer2peer); 3971 }" > conftest$$.c 3972 3973 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 3974 rm -f conftest$$.c 3975 3976 if [ -f conftest$$.o ]; then 3977 echo "#define NV_DMA_BUF_ATTACHMENT_HAS_PEER2PEER" | append_conftest "types" 3978 rm -f conftest$$.o 3979 return 3980 else 3981 echo "#undef NV_DMA_BUF_ATTACHMENT_HAS_PEER2PEER" | append_conftest "types" 3982 return 3983 fi 3984 ;; 3985 3986 drm_connector_funcs_have_mode_in_name) 3987 # 3988 # Determine if _mode_ is present in connector function names. We 3989 # only test drm_mode_connector_attach_encoder() and assume the 3990 # other functions are changed in sync. 3991 # 3992 # drm_mode_connector_attach_encoder() was renamed to 3993 # drm_connector_attach_encoder() by commit cde4c44d8769 ("drm: 3994 # drop _mode_ from drm_mode_connector_attach_encoder") in v4.19 3995 # (2018-07-09) 3996 # 3997 # drm_mode_connector_update_edid_property() was renamed by commit 3998 # c555f02371c3 ("drm: drop _mode_ from update_edit_property()") 3999 # in v4.19 (2018-07-09). 4000 # 4001 # The other DRM functions were renamed by commit 97e14fbeb53f 4002 # ("drm: drop _mode_ from remaining connector functions") in v4.19 4003 # (2018-07-09) 4004 # 4005 # Note that drm_connector.h by introduced by commit 522171951761 4006 # ("drm: Extract drm_connector.[hc]") in v4.9 (2016-08-12) 4007 # 4008 # Note: up to 4.9 function was provided by drm_crtc.h by commit 4009 # f453ba046074 in 2.6.29 (2008-12-29) 4010 # 4011 CODE=" 4012 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 4013 #include <drm/drm_connector.h> 4014 #endif 4015 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 4016 #include <drm/drm_crtc.h> 4017 #endif 4018 void conftest_drm_connector_funcs_have_mode_in_name(void) { 4019 drm_mode_connector_attach_encoder(); 4020 }" 4021 4022 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_FUNCS_HAVE_MODE_IN_NAME" "" "functions" 4023 ;; 4024 4025 drm_connector_has_vrr_capable_property) 4026 # 4027 # Determine if drm_connector_attach_vrr_capable_property and 4028 # drm_connector_set_vrr_capable_property is present 4029 # 4030 # Added by commit ba1b0f6c73d4ea1390f0d5381f715ffa20c75f09 ("drm: 4031 # Add vrr_capable property to the drm connector") in v5.0-rc1 4032 # (2018-11-28) 4033 # 4034 CODE=" 4035 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 4036 #include <drm/drm_connector.h> 4037 #endif 4038 4039 void conftest_drm_connector_has_vrr_capable_property(void) { 4040 drm_connector_attach_vrr_capable_property(); 4041 }" 4042 4043 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_HAS_VRR_CAPABLE_PROPERTY" "" "functions" 4044 ;; 4045 4046 vm_fault_t) 4047 # 4048 # Determine if vm_fault_t is present 4049 # 4050 # Added by commit 1c8f422059ae5da07db7406ab916203f9417e396 ("mm: 4051 # change return type to vm_fault_t") in v4.17 (2018-04-05) 4052 # 4053 CODE=" 4054 #include <linux/mm.h> 4055 vm_fault_t conftest_vm_fault_t; 4056 " 4057 compile_check_conftest "$CODE" "NV_VM_FAULT_T_IS_PRESENT" "" "types" 4058 ;; 4059 4060 vmf_insert_pfn) 4061 # 4062 # Determine if the function vmf_insert_pfn() is 4063 # present. 4064 # 4065 # Added by commit 1c8f422059ae5da07db7406ab916203f9417e396 ("mm: 4066 # change return type to vm_fault_t") in v4.17 (2018-04-05) 4067 # 4068 CODE=" 4069 #include <linux/mm.h> 4070 void conftest_vmf_insert_pfn(void) { 4071 vmf_insert_pfn(); 4072 }" 4073 4074 compile_check_conftest "$CODE" "NV_VMF_INSERT_PFN_PRESENT" "" "functions" 4075 ;; 4076 4077 drm_framebuffer_get) 4078 # 4079 # Determine if the function drm_framebuffer_get() is present. 4080 # 4081 # Added by commit a4a69da06bc1 ("drm: Introduce 4082 # drm_framebuffer_{get,put}()") in v4.12 (2017-02-28). 4083 # 4084 CODE=" 4085 #if defined(NV_DRM_DRMP_H_PRESENT) 4086 #include <drm/drmP.h> 4087 #endif 4088 4089 #if defined(NV_DRM_DRM_FRAMEBUFFER_H_PRESENT) 4090 #include <drm/drm_framebuffer.h> 4091 #endif 4092 4093 void conftest_drm_framebuffer_get(void) { 4094 drm_framebuffer_get(); 4095 }" 4096 4097 compile_check_conftest "$CODE" "NV_DRM_FRAMEBUFFER_GET_PRESENT" "" "functions" 4098 ;; 4099 4100 drm_gem_object_get) 4101 # 4102 # Determine if the function drm_gem_object_get() is present. 4103 # 4104 # Added by commit e6b62714e87c ("drm: Introduce 4105 # drm_gem_object_{get,put}()") in v4.12 (2017-02-28). 4106 # 4107 CODE=" 4108 #if defined(NV_DRM_DRMP_H_PRESENT) 4109 #include <drm/drmP.h> 4110 #endif 4111 4112 #if defined(NV_DRM_DRM_GEM_H_PRESENT) 4113 #include <drm/drm_gem.h> 4114 #endif 4115 void conftest_drm_gem_object_get(void) { 4116 drm_gem_object_get(); 4117 }" 4118 4119 compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_GET_PRESENT" "" "functions" 4120 ;; 4121 4122 drm_dev_put) 4123 # 4124 # Determine if the function drm_dev_put() is present. 4125 # 4126 # Added by commit 9a96f55034e4 ("drm: introduce drm_dev_{get/put} 4127 # functions") in v4.15 (2017-09-26). 4128 # 4129 CODE=" 4130 #if defined(NV_DRM_DRMP_H_PRESENT) 4131 #include <drm/drmP.h> 4132 #endif 4133 4134 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 4135 #include <drm/drm_drv.h> 4136 #endif 4137 void conftest_drm_dev_put(void) { 4138 drm_dev_put(); 4139 }" 4140 4141 compile_check_conftest "$CODE" "NV_DRM_DEV_PUT_PRESENT" "" "functions" 4142 ;; 4143 4144 drm_connector_list_iter) 4145 # 4146 # Determine if the drm_connector_list_iter struct is present. 4147 # 4148 # Added by commit 613051dac40da1751ab269572766d3348d45a197 ("drm: 4149 # locking&new iterators for connector_list") in v4.11 (2016-12-14). 4150 # 4151 CODE=" 4152 #include <drm/drm_connector.h> 4153 int conftest_drm_connector_list_iter(void) { 4154 struct drm_connector_list_iter conn_iter; 4155 }" 4156 4157 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_LIST_ITER_PRESENT" "" "types" 4158 4159 # 4160 # Determine if the function drm_connector_list_iter_get() is 4161 # renamed to drm_connector_list_iter_begin(). 4162 # 4163 # Renamed by b982dab1e66d2b998e80a97acb6eaf56518988d3 (drm: Rename 4164 # connector list iterator API) in v4.12 (2017-02-28). 4165 # 4166 CODE=" 4167 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 4168 #include <drm/drm_connector.h> 4169 #endif 4170 void conftest_drm_connector_list_iter_begin(void) { 4171 drm_connector_list_iter_begin(); 4172 }" 4173 4174 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_LIST_ITER_BEGIN_PRESENT" "" "functions" 4175 ;; 4176 4177 drm_atomic_helper_swap_state_has_stall_arg) 4178 # 4179 # Determine if drm_atomic_helper_swap_state() has 'stall' argument. 4180 # 4181 # drm_atomic_helper_swap_state() function prototype updated to take 4182 # 'state' and 'stall' arguments by commit 4183 # 5e84c2690b805caeff3b4c6c9564c7b8de54742d (drm/atomic-helper: 4184 # Massage swap_state signature somewhat) 4185 # in v4.8 (2016-06-10). 4186 # 4187 CODE=" 4188 #include <drm/drm_atomic_helper.h> 4189 void conftest_drm_atomic_helper_swap_state_has_stall_arg( 4190 struct drm_atomic_state *state, 4191 bool stall) { 4192 (void)drm_atomic_helper_swap_state(state, stall); 4193 }" 4194 4195 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_SWAP_STATE_HAS_STALL_ARG" | append_conftest "types" 4196 4197 # 4198 # Determine if drm_atomic_helper_swap_state() returns int. 4199 # 4200 # drm_atomic_helper_swap_state() function prototype 4201 # updated to return int by commit 4202 # c066d2310ae9bbc695c06e9237f6ea741ec35e43 (drm/atomic: Change 4203 # drm_atomic_helper_swap_state to return an error.) in v4.14 4204 # (2017-07-11). 4205 # 4206 CODE=" 4207 #include <drm/drm_atomic_helper.h> 4208 int conftest_drm_atomic_helper_swap_state_return_int( 4209 struct drm_atomic_state *state, 4210 bool stall) { 4211 return drm_atomic_helper_swap_state(state, stall); 4212 }" 4213 4214 compile_check_conftest "$CODE" "NV_DRM_ATOMIC_HELPER_SWAP_STATE_RETURN_INT" | append_conftest "types" 4215 ;; 4216 4217 pm_runtime_available) 4218 # 4219 # Determine if struct dev_pm_info has the 'usage_count' field. 4220 # 4221 # This was added to the kernel in commit 5e928f77a09a0 in v2.6.32 4222 # (2008-08-18), but originally were dependent on CONFIG_PM_RUNTIME, 4223 # which was folded into the more generic CONFIG_PM in commit 4224 # d30d819dc8310 in v3.19 (2014-11-27). 4225 # Rather than attempt to select the appropriate CONFIG option, 4226 # simply check if this member is present. 4227 # 4228 CODE=" 4229 #include <linux/pm.h> 4230 void pm_runtime_conftest(void) { 4231 struct dev_pm_info dpmi; 4232 atomic_set(&dpmi.usage_count, 1); 4233 }" 4234 4235 compile_check_conftest "$CODE" "NV_PM_RUNTIME_AVAILABLE" "" "generic" 4236 ;; 4237 4238 dma_direct_map_resource) 4239 # 4240 # Determine whether dma_is_direct() exists. 4241 # 4242 # dma_is_direct() was added by commit 356da6d0cde3 ("dma-mapping: 4243 # bypass indirect calls for dma-direct") in 5.1 (2018-12-06). 4244 # 4245 # If dma_is_direct() does exist, then we assume that 4246 # dma_direct_map_resource() exists. Both functions were added 4247 # as part of the same patchset. 4248 # 4249 # The presence of dma_is_direct() and dma_direct_map_resource() 4250 # means that dma_direct can perform DMA mappings itself. 4251 # 4252 CODE=" 4253 #include <linux/dma-mapping.h> 4254 void conftest_dma_is_direct(void) { 4255 dma_is_direct(); 4256 }" 4257 4258 compile_check_conftest "$CODE" "NV_DMA_IS_DIRECT_PRESENT" "" "functions" 4259 ;; 4260 4261 tegra_get_platform) 4262 # 4263 # Determine if tegra_get_platform() function is present 4264 # 4265 CODE=" 4266 #if defined NV_SOC_TEGRA_CHIP_ID_H_PRESENT 4267 #include <soc/tegra/chip-id.h> 4268 #elif defined(NV_SOC_TEGRA_FUSE_H_PRESENT) 4269 #include <soc/tegra/fuse.h> 4270 #endif 4271 void conftest_tegra_get_platform(void) { 4272 tegra_get_platform(0); 4273 } 4274 " 4275 4276 compile_check_conftest "$CODE" "NV_TEGRA_GET_PLATFORM_PRESENT" "" "functions" 4277 ;; 4278 4279 tegra_bpmp_send_receive) 4280 # 4281 # Determine if tegra_bpmp_send_receive() function is present 4282 # 4283 CODE=" 4284 #if defined NV_SOC_TEGRA_TEGRA_BPMP_H_PRESENT 4285 #include <soc/tegra/tegra_bpmp.h> 4286 #endif 4287 int conftest_tegra_bpmp_send_receive( 4288 int mrq, 4289 void *ob_data, 4290 int ob_sz, 4291 void *ib_data, 4292 int ib_sz) { 4293 return tegra_bpmp_send_receive(mrq, ob_data, ob_sz, ib_data, ib_sz); 4294 } 4295 " 4296 4297 compile_check_conftest "$CODE" "NV_TEGRA_BPMP_SEND_RECEIVE" "" "functions" 4298 ;; 4299 4300 cmd_uphy_display_port_init) 4301 # 4302 # Determine if CMD_UPHY_DISPLAY_PORT_INIT enum present in bpmp-abi header 4303 # This enum is used only in Tegra down-stream kernel. 4304 # 4305 CODE=" 4306 #include <stdint.h> 4307 #include <soc/tegra/bpmp-abi.h> 4308 4309 int conftest_cmd_uphy_display_port_init(void) { 4310 return CMD_UPHY_DISPLAY_PORT_INIT; 4311 } 4312 " 4313 compile_check_conftest "$CODE" "NV_CMD_UPHY_DISPLAY_PORT_INIT_PRESENT" "" "generic" 4314 4315 ;; 4316 4317 cmd_uphy_display_port_off) 4318 # 4319 # Determine if CMD_UPHY_DISPLAY_PORT_OFF enum present in bpmp-abi header 4320 # This enum is used only in Tegra down-stream kernel. 4321 # 4322 CODE=" 4323 #include <stdint.h> 4324 #include <soc/tegra/bpmp-abi.h> 4325 4326 int conftest_cmd_uphy_display_port_off(void) { 4327 return CMD_UPHY_DISPLAY_PORT_OFF; 4328 } 4329 " 4330 compile_check_conftest "$CODE" "NV_CMD_UPHY_DISPLAY_PORT_OFF_PRESENT" "" "generic" 4331 4332 ;; 4333 4334 drm_alpha_blending_available) 4335 # 4336 # Determine if the DRM subsystem supports alpha blending 4337 # 4338 # This conftest using "generic" rather than "functions" because 4339 # with the logic of "functions" the presence of 4340 # *either*_alpha_property or _blend_mode_property would be enough 4341 # to cause NV_DRM_ALPHA_BLENDING_AVAILABLE to be defined. 4342 # 4343 CODE=" 4344 #if defined(NV_DRM_DRM_BLEND_H_PRESENT) 4345 #include <drm/drm_blend.h> 4346 #endif 4347 void conftest_drm_alpha_blending_available(void) { 4348 /* 2018-04-11 ae0e28265e216dad11d4cbde42fc15e92919af78 */ 4349 (void)drm_plane_create_alpha_property; 4350 4351 /* 2018-08-23 a5ec8332d4280500544e316f76c04a7adc02ce03 */ 4352 (void)drm_plane_create_blend_mode_property; 4353 }" 4354 4355 compile_check_conftest "$CODE" "NV_DRM_ALPHA_BLENDING_AVAILABLE" "" "generic" 4356 ;; 4357 4358 drm_rotation_available) 4359 # 4360 # Determine if the DRM subsystem supports rotation. 4361 # 4362 # drm_plane_create_rotation_property() was added on 2016-09-26 by 4363 # d138dd3c0c70979215f3184cf36f95875e37932e (drm: Add support for 4364 # optional per-plane rotation property) in linux kernel. Presence 4365 # of it is sufficient to say that DRM subsystem support rotation. 4366 # 4367 CODE=" 4368 #if defined(NV_DRM_DRM_BLEND_H_PRESENT) 4369 #include <drm/drm_blend.h> 4370 #endif 4371 void conftest_drm_rotation_available(void) { 4372 drm_plane_create_rotation_property(); 4373 }" 4374 4375 compile_check_conftest "$CODE" "NV_DRM_ROTATION_AVAILABLE" "" "functions" 4376 ;; 4377 4378 drm_driver_prime_flag_present) 4379 # 4380 # Determine whether driver feature flag DRIVER_PRIME is present. 4381 # 4382 # The DRIVER_PRIME flag was added by commit 3248877ea179 (drm: 4383 # base prime/dma-buf support (v5)) in v3.4 (2011-11-25) and is 4384 # removed by commit 0424fdaf883a (drm/prime: Actually remove 4385 # DRIVER_PRIME everywhere) on 2019-06-17. 4386 # 4387 # DRIVER_PRIME definition moved from drmP.h to drm_drv.h by 4388 # commit 85e634bce01a (drm: Extract drm_drv.h) in v4.10 4389 # (2016-11-14). 4390 # 4391 # DRIVER_PRIME define is changed to enum value by commit 4392 # 0e2a933b02c9 (drm: Switch DRIVER_ flags to an enum) in v5.1 4393 # (2019-01-29). 4394 # 4395 CODE=" 4396 #if defined(NV_DRM_DRMP_H_PRESENT) 4397 #include <drm/drmP.h> 4398 #endif 4399 4400 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 4401 #include <drm/drm_drv.h> 4402 #endif 4403 4404 unsigned int drm_driver_prime_flag_present_conftest(void) { 4405 return DRIVER_PRIME; 4406 }" 4407 4408 compile_check_conftest "$CODE" "NV_DRM_DRIVER_PRIME_FLAG_PRESENT" "" "types" 4409 ;; 4410 4411 drm_connector_for_each_possible_encoder) 4412 # 4413 # Determine the number of arguments of the 4414 # drm_connector_for_each_possible_encoder() macro. 4415 # 4416 # drm_connector_for_each_possible_encoder() is added by commit 4417 # 83aefbb887b5 (drm: Add drm_connector_for_each_possible_encoder()) 4418 # in v4.19. The definition and prorotype is changed to take only 4419 # two arguments connector and encoder, by commit 62afb4ad425a 4420 # (drm/connector: Allow max possible encoders to attach to a 4421 # connector) in v5.5rc1. 4422 # 4423 echo "$CONFTEST_PREAMBLE 4424 #if defined(NV_DRM_DRMP_H_PRESENT) 4425 #include <drm/drmP.h> 4426 #endif 4427 4428 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 4429 #include <drm/drm_connector.h> 4430 #endif 4431 4432 void conftest_drm_connector_for_each_possible_encoder( 4433 struct drm_connector *connector, 4434 struct drm_encoder *encoder, 4435 int i) { 4436 4437 drm_connector_for_each_possible_encoder(connector, encoder, i) { 4438 } 4439 }" > conftest$$.c 4440 4441 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 4442 rm -f conftest$$.c 4443 4444 if [ -f conftest$$.o ]; then 4445 echo "#define NV_DRM_CONNECTOR_FOR_EACH_POSSIBLE_ENCODER_ARGUMENT_COUNT 3" | append_conftest "functions" 4446 rm -f conftest$$.o 4447 return 4448 else 4449 echo "#define NV_DRM_CONNECTOR_FOR_EACH_POSSIBLE_ENCODER_ARGUMENT_COUNT 2" | append_conftest "functions" 4450 fi 4451 ;; 4452 4453 mmu_notifier_ops_invalidate_range) 4454 # 4455 # Determine if the mmu_notifier_ops struct has the 4456 # 'invalidate_range' member. 4457 # 4458 # struct mmu_notifier_ops.invalidate_range was added by commit 4459 # 0f0a327fa12cd55de5e7f8c05a70ac3d047f405e ("mmu_notifier: add the 4460 # callback for mmu_notifier_invalidate_range()") in v3.19 4461 # (2014-11-13). 4462 CODE=" 4463 #include <linux/mmu_notifier.h> 4464 int conftest_mmu_notifier_ops_invalidate_range(void) { 4465 return offsetof(struct mmu_notifier_ops, invalidate_range); 4466 }" 4467 4468 compile_check_conftest "$CODE" "NV_MMU_NOTIFIER_OPS_HAS_INVALIDATE_RANGE" "" "types" 4469 ;; 4470 4471 drm_format_num_planes) 4472 # 4473 # Determine if drm_format_num_planes() function is present. 4474 # 4475 # The drm_format_num_planes() function was added by commit 4476 # d0d110e09629 drm: Add drm_format_num_planes() utility function in 4477 # v3.3 (2011-12-20). Prototype was moved from drm_crtc.h to 4478 # drm_fourcc.h by commit ae4df11a0f53 (drm: Move format-related 4479 # helpers to drm_fourcc.c) in v4.8 (2016-06-09). 4480 # drm_format_num_planes() has been removed by commit 05c452c115bf 4481 # (drm: Remove users of drm_format_num_planes) removed v5.3 4482 # (2019-05-16). 4483 # 4484 CODE=" 4485 4486 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 4487 #include <drm/drm_crtc.h> 4488 #endif 4489 4490 #if defined(NV_DRM_DRM_FOURCC_H_PRESENT) 4491 #include <drm/drm_fourcc.h> 4492 #endif 4493 4494 void conftest_drm_format_num_planes(void) { 4495 drm_format_num_planes(); 4496 } 4497 " 4498 4499 compile_check_conftest "$CODE" "NV_DRM_FORMAT_NUM_PLANES_PRESENT" "" "functions" 4500 ;; 4501 4502 drm_gem_object_has_resv) 4503 # 4504 # Determine if the 'drm_gem_object' structure has a 'resv' field. 4505 # 4506 # A 'resv' filed in the 'drm_gem_object' structure, is added by 4507 # commit 1ba627148ef5 (drm: Add reservation_object to 4508 # drm_gem_object) in v5.2. 4509 # 4510 CODE="$CONFTEST_PREAMBLE 4511 #if defined(NV_DRM_DRM_GEM_H_PRESENT) 4512 #include <drm/drm_gem.h> 4513 #endif 4514 4515 int conftest_drm_gem_object_has_resv(void) { 4516 return offsetof(struct drm_gem_object, resv); 4517 }" 4518 4519 compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_HAS_RESV" "" "types" 4520 ;; 4521 4522 proc_ops) 4523 # 4524 # Determine if the 'struct proc_ops' type is present. 4525 # 4526 # Added by commit d56c0d45f0e2 ("proc: decouple proc from VFS with 4527 # "struct proc_ops"") in 5.6-rc1 4528 # 4529 CODE=" 4530 #include <linux/proc_fs.h> 4531 4532 struct proc_ops p_ops; 4533 " 4534 4535 compile_check_conftest "$CODE" "NV_PROC_OPS_PRESENT" "" "types" 4536 ;; 4537 4538 drm_crtc_state_has_async_flip) 4539 # 4540 # Determine if the 'drm_crtc_state' structure has a 'async_flip' 4541 # field. 4542 # 4543 # Commit 4d85f45c73a2 (drm/atomic: Rename crtc_state->pageflip_flags 4544 # to async_flip) replaced 'pageflip_flags' by 'async_flip' in v5.4. 4545 # 4546 CODE=" 4547 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 4548 #include <drm/drm_crtc.h> 4549 #endif 4550 4551 int conftest_drm_crtc_state_has_async_flip(void) { 4552 return offsetof(struct drm_crtc_state, async_flip); 4553 }" 4554 4555 compile_check_conftest "$CODE" "NV_DRM_CRTC_STATE_HAS_ASYNC_FLIP" "" "types" 4556 ;; 4557 4558 drm_crtc_state_has_pageflip_flags) 4559 # 4560 # Determine if the 'drm_crtc_state' structure has a 4561 # 'pageflip_flags' field. 4562 # 4563 # 'pageflip_flags' added by commit 6cbe5c466d73 (drm/atomic: Save 4564 # flip flags in drm_crtc_state) in v4.12. Commit 4d85f45c73a2 4565 # (drm/atomic: Rename crtc_state->pageflip_flags to async_flip) 4566 # replaced 'pageflip_flags' by 'async_flip' in v5.4. 4567 # 4568 CODE=" 4569 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 4570 #include <drm/drm_crtc.h> 4571 #endif 4572 4573 int conftest_drm_crtc_state_has_pageflip_flags(void) { 4574 return offsetof(struct drm_crtc_state, pageflip_flags); 4575 }" 4576 4577 compile_check_conftest "$CODE" "NV_DRM_CRTC_STATE_HAS_PAGEFLIP_FLAGS" "" "types" 4578 ;; 4579 4580 drm_crtc_state_has_vrr_enabled) 4581 # 4582 # Determine if 'drm_crtc_state' structure has a 4583 # 'vrr_enabled' field. 4584 # 4585 # Added by commit 1398958cfd8d331342d657d37151791dd7256b40 ("drm: 4586 # Add vrr_enabled property to drm CRTC") in v5.0-rc1 (2018-11-28) 4587 # 4588 CODE=" 4589 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 4590 #include <drm/drm_crtc.h> 4591 #endif 4592 4593 int conftest_drm_crtc_state_has_vrr_enabled(void) { 4594 return offsetof(struct drm_crtc_state, vrr_enabled); 4595 }" 4596 4597 compile_check_conftest "$CODE" "NV_DRM_CRTC_STATE_HAS_VRR_ENABLED" "" "types" 4598 ;; 4599 4600 ktime_get_raw_ts64) 4601 # 4602 # Determine if ktime_get_raw_ts64() is present 4603 # 4604 # Added by commit fb7fcc96a86cf ("timekeeping: Standardize on 4605 # ktime_get_*() naming") in 4.18 (2018-04-27) 4606 # 4607 CODE=" 4608 #include <linux/ktime.h> 4609 void conftest_ktime_get_raw_ts64(void){ 4610 ktime_get_raw_ts64(); 4611 }" 4612 compile_check_conftest "$CODE" "NV_KTIME_GET_RAW_TS64_PRESENT" "" "functions" 4613 ;; 4614 4615 ktime_get_real_ts64) 4616 # 4617 # Determine if ktime_get_real_ts64() is present 4618 # 4619 # Added by commit d6d29896c665d ("timekeeping: Provide timespec64 4620 # based interfaces") in 3.17 (2014-07-16) 4621 # 4622 CODE=" 4623 #include <linux/ktime.h> 4624 void conftest_ktime_get_real_ts64(void){ 4625 ktime_get_real_ts64(); 4626 }" 4627 compile_check_conftest "$CODE" "NV_KTIME_GET_REAL_TS64_PRESENT" "" "functions" 4628 ;; 4629 4630 drm_format_modifiers_present) 4631 # 4632 # Determine whether the base DRM format modifier support is present. 4633 # 4634 # This will show up in a few places: 4635 # 4636 # -Definition of the format modifier constructor macro, which 4637 # we can use to reconstruct our bleeding-edge format modifiers 4638 # when the local kernel headers don't include them. 4639 # 4640 # -The first set of format modifier vendor macros, including the 4641 # poorly named "NV" vendor, which was later renamed "NVIDIA". 4642 # 4643 # -the "modifier[]" member of the AddFB2 ioctl's parameter 4644 # structure. 4645 # 4646 # All these were added by commit e3eb3250d84e (drm: add support for 4647 # tiled/compressed/etc modifier in addfb2) in 4.1-rc1 (2015-02-05). 4648 CODE=" 4649 #include <drm/drm_mode.h> 4650 #include <drm/drm_fourcc.h> 4651 int conftest_fourcc_fb_modifiers(void) { 4652 u64 my_fake_mod = fourcc_mod_code(INTEL, 0); 4653 (void)my_fake_mod; 4654 return offsetof(struct drm_mode_fb_cmd2, modifier); 4655 }" 4656 4657 compile_check_conftest "$CODE" "NV_DRM_FORMAT_MODIFIERS_PRESENT" "" "types" 4658 4659 ;; 4660 4661 timespec64) 4662 # 4663 # Determine if struct timespec64 is present 4664 # Added by commit 361a3bf00582 ("time64: Add time64.h header and 4665 # define struct timespec64") in 3.17 (2014-07-16) 4666 # 4667 CODE=" 4668 #include <linux/time.h> 4669 4670 struct timespec64 ts64; 4671 " 4672 compile_check_conftest "$CODE" "NV_TIMESPEC64_PRESENT" "" "types" 4673 4674 ;; 4675 4676 vmalloc_has_pgprot_t_arg) 4677 # 4678 # Determine if __vmalloc has the 'pgprot' argument. 4679 # 4680 # The third argument to __vmalloc, page protection 4681 # 'pgprot_t prot', was removed by commit 88dca4ca5a93 4682 # (mm: remove the pgprot argument to __vmalloc) 4683 # in v5.8-rc1 (2020-06-01). 4684 CODE=" 4685 #include <linux/vmalloc.h> 4686 4687 void conftest_vmalloc_has_pgprot_t_arg(void) { 4688 pgprot_t prot; 4689 (void)__vmalloc(0, 0, prot); 4690 }" 4691 4692 compile_check_conftest "$CODE" "NV_VMALLOC_HAS_PGPROT_T_ARG" "" "types" 4693 4694 ;; 4695 4696 mm_has_mmap_lock) 4697 # 4698 # Determine if the 'mm_struct' structure has a 'mmap_lock' field. 4699 # 4700 # Kernel commit da1c55f1b272 ("mmap locking API: rename mmap_sem 4701 # to mmap_lock") replaced the field 'mmap_sem' by 'mmap_lock' 4702 # in v5.8-rc1 (2020-06-08). 4703 CODE=" 4704 #include <linux/mm_types.h> 4705 4706 int conftest_mm_has_mmap_lock(void) { 4707 return offsetof(struct mm_struct, mmap_lock); 4708 }" 4709 4710 compile_check_conftest "$CODE" "NV_MM_HAS_MMAP_LOCK" "" "types" 4711 ;; 4712 4713 full_name_hash) 4714 # 4715 # Determine how many arguments full_name_hash takes. 4716 # 4717 # Changed by commit 8387ff2577e ("vfs: make the string hashes salt 4718 # the hash") in v4.8 (2016-06-10) 4719 # 4720 echo "$CONFTEST_PREAMBLE 4721 #include <linux/stringhash.h> 4722 void conftest_full_name_hash(void) { 4723 full_name_hash(NULL, NULL, 0); 4724 }" > conftest$$.c 4725 4726 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 4727 rm -f conftest$$.c 4728 4729 if [ -f conftest$$.o ]; then 4730 rm -f conftest$$.o 4731 echo "#define NV_FULL_NAME_HASH_ARGUMENT_COUNT 3" | append_conftest "functions" 4732 else 4733 echo "#define NV_FULL_NAME_HASH_ARGUMENT_COUNT 2" | append_conftest "functions" 4734 fi 4735 ;; 4736 4737 drm_vma_offset_exact_lookup_locked) 4738 # 4739 # Determine if the drm_vma_offset_exact_lookup_locked() function 4740 # is present. 4741 # 4742 # Added by commit 2225cfe46bcc ("drm/gem: Use kref_get_unless_zero 4743 # for the weak mmap references") in v4.4 4744 # 4745 CODE=" 4746 #include <drm/drm_vma_manager.h> 4747 void conftest_drm_vma_offset_exact_lookup_locked(void) { 4748 drm_vma_offset_exact_lookup_locked(); 4749 }" 4750 4751 compile_check_conftest "$CODE" "NV_DRM_VMA_OFFSET_EXACT_LOOKUP_LOCKED_PRESENT" "" "functions" 4752 ;; 4753 4754 drm_vma_node_is_allowed_has_tag_arg) 4755 # 4756 # Determine if drm_vma_node_is_allowed() has 'tag' arguments of 4757 # 'struct drm_file *' type. 4758 # 4759 # Updated to take 'tag' argument by commit d9a1f0b4eb60 ("drm: use 4760 # drm_file to tag vm-bos") in v4.9 4761 # 4762 CODE=" 4763 #include <drm/drm_vma_manager.h> 4764 bool drm_vma_node_is_allowed(struct drm_vma_offset_node *node, 4765 struct drm_file *tag) { 4766 return true; 4767 }" 4768 4769 compile_check_conftest "$CODE" "NV_DRM_VMA_NODE_IS_ALLOWED_HAS_TAG_ARG" | append_conftest "types" 4770 ;; 4771 4772 drm_vma_offset_node_has_readonly) 4773 # 4774 # Determine if the 'drm_vma_offset_node' structure has a 'readonly' 4775 # field. 4776 # 4777 # Added by commit 3e977ac6179b ("drm/i915: Prevent writing into a 4778 # read-only object via a GGTT mmap") in v4.19. 4779 # 4780 CODE=" 4781 #include <drm/drm_vma_manager.h> 4782 4783 int conftest_drm_vma_offset_node_has_readonly(void) { 4784 return offsetof(struct drm_vma_offset_node, readonly); 4785 }" 4786 4787 compile_check_conftest "$CODE" "NV_DRM_VMA_OFFSET_NODE_HAS_READONLY" "" "types" 4788 4789 ;; 4790 4791 pci_enable_atomic_ops_to_root) 4792 # pci_enable_atomic_ops_to_root was added by 4793 # commit 430a23689dea ("PCI: Add pci_enable_atomic_ops_to_root()") 4794 # in v4.16-rc1 (2018-01-05) 4795 # 4796 CODE=" 4797 #include <linux/pci.h> 4798 void conftest_pci_enable_atomic_ops_to_root(void) { 4799 pci_enable_atomic_ops_to_root(); 4800 }" 4801 compile_check_conftest "$CODE" "NV_PCI_ENABLE_ATOMIC_OPS_TO_ROOT_PRESENT" "" "functions" 4802 ;; 4803 4804 kvmalloc) 4805 # 4806 # Determine if kvmalloc() is present 4807 # 4808 # Added by commit a7c3e901a46ff54c016d040847eda598a9e3e653 ("mm: 4809 # introduce kv[mz]alloc helpers") in v4.12 (2017-05-08). 4810 # 4811 CODE=" 4812 #include <linux/mm.h> 4813 void conftest_kvmalloc(void){ 4814 kvmalloc(); 4815 }" 4816 compile_check_conftest "$CODE" "NV_KVMALLOC_PRESENT" "" "functions" 4817 4818 ;; 4819 4820 drm_gem_object_put_unlocked) 4821 # 4822 # Determine if the function drm_gem_object_put_unlocked() is present. 4823 # 4824 # In v5.9-rc1, commit 2f4dd13d4bb8 ("drm/gem: add 4825 # drm_gem_object_put helper") removes drm_gem_object_put_unlocked() 4826 # function and replace its definition by transient macro. Commit 4827 # ab15d56e27be ("drm: remove transient 4828 # drm_gem_object_put_unlocked()") finally removes 4829 # drm_gem_object_put_unlocked() macro. 4830 # 4831 CODE=" 4832 #if defined(NV_DRM_DRMP_H_PRESENT) 4833 #include <drm/drmP.h> 4834 #endif 4835 4836 #if defined(NV_DRM_DRM_GEM_H_PRESENT) 4837 #include <drm/drm_gem.h> 4838 #endif 4839 void conftest_drm_gem_object_put_unlocked(void) { 4840 drm_gem_object_put_unlocked(); 4841 }" 4842 4843 compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_PUT_UNLOCK_PRESENT" "" "functions" 4844 ;; 4845 4846 drm_display_mode_has_vrefresh) 4847 # 4848 # Determine if the 'drm_display_mode' structure has a 'vrefresh' 4849 # field. 4850 # 4851 # Removed by commit 0425662fdf05 ("drm: Nuke mode->vrefresh") in 4852 # v5.9-rc1. 4853 # 4854 CODE=" 4855 #include <drm/drm_modes.h> 4856 4857 int conftest_drm_display_mode_has_vrefresh(void) { 4858 return offsetof(struct drm_display_mode, vrefresh); 4859 }" 4860 4861 compile_check_conftest "$CODE" "NV_DRM_DISPLAY_MODE_HAS_VREFRESH" "types" 4862 4863 ;; 4864 4865 drm_driver_master_set_has_int_return_type) 4866 # 4867 # Determine if drm_driver::master_set() returns integer value 4868 # 4869 # Changed to void by commit 907f53200f98 ("drm: vmwgfx: remove 4870 # drm_driver::master_set() return type") in v5.9-rc1. 4871 # 4872 CODE=" 4873 #if defined(NV_DRM_DRMP_H_PRESENT) 4874 #include <drm/drmP.h> 4875 #endif 4876 4877 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 4878 #include <drm/drm_drv.h> 4879 #endif 4880 4881 int conftest_drm_driver_master_set_has_int_return_type(struct drm_driver *drv, 4882 struct drm_device *dev, struct drm_file *file_priv, bool from_open) { 4883 4884 return drv->master_set(dev, file_priv, from_open); 4885 }" 4886 4887 compile_check_conftest "$CODE" "NV_DRM_DRIVER_SET_MASTER_HAS_INT_RETURN_TYPE" "" "types" 4888 ;; 4889 4890 drm_driver_has_gem_free_object) 4891 # 4892 # Determine if the 'drm_driver' structure has a 'gem_free_object' 4893 # function pointer. 4894 # 4895 # drm_driver::gem_free_object is removed by commit 1a9458aeb8eb 4896 # ("drm: remove drm_driver::gem_free_object") in v5.9-rc1. 4897 # 4898 CODE=" 4899 #if defined(NV_DRM_DRMP_H_PRESENT) 4900 #include <drm/drmP.h> 4901 #endif 4902 4903 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 4904 #include <drm/drm_drv.h> 4905 #endif 4906 4907 int conftest_drm_driver_has_gem_free_object(void) { 4908 return offsetof(struct drm_driver, gem_free_object); 4909 }" 4910 4911 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_GEM_FREE_OBJECT" "" "types" 4912 ;; 4913 4914 vga_tryget) 4915 # 4916 # Determine if vga_tryget() is present 4917 # 4918 # vga_tryget() was removed by commit f369bc3f9096 ("vgaarb: mark 4919 # vga_tryget static") in v5.9-rc1 (2020-08-01). 4920 # 4921 CODE=" 4922 #include <linux/vgaarb.h> 4923 void conftest_vga_tryget(void) { 4924 vga_tryget(); 4925 }" 4926 4927 compile_check_conftest "$CODE" "NV_VGA_TRYGET_PRESENT" "" "functions" 4928 ;; 4929 4930 pci_channel_state) 4931 # 4932 # Determine if pci_channel_state enum type is present. 4933 # 4934 # pci_channel_state was removed by commit 16d79cd4e23b ("PCI: Use 4935 # 'pci_channel_state_t' instead of 'enum pci_channel_state'") in 4936 # v5.9-rc1 (2020-07-02). 4937 # 4938 CODE=" 4939 #include <linux/pci.h> 4940 4941 enum pci_channel_state state; 4942 " 4943 4944 compile_check_conftest "$CODE" "NV_PCI_CHANNEL_STATE_PRESENT" "" "types" 4945 ;; 4946 4947 cc_platform_has) 4948 # 4949 # Determine if 'cc_platform_has()' is present. 4950 # 4951 # Added by commit aa5a461171f9 ("x86/sev: Add an x86 version of 4952 # cc_platform_has()") in v5.15.3 (2021-10-04) 4953 CODE=" 4954 #if defined(NV_LINUX_CC_PLATFORM_H_PRESENT) 4955 #include <linux/cc_platform.h> 4956 #endif 4957 4958 void conftest_cc_platfrom_has(void) { 4959 cc_platform_has(); 4960 }" 4961 4962 compile_check_conftest "$CODE" "NV_CC_PLATFORM_PRESENT" "" "functions" 4963 ;; 4964 4965 drm_prime_pages_to_sg_has_drm_device_arg) 4966 # 4967 # Determine if drm_prime_pages_to_sg() has 'dev' argument. 4968 # 4969 # drm_prime_pages_to_sg() is updated to take 'dev' argument by commit 4970 # 707d561f77b5 ("drm: allow limiting the scatter list size."). 4971 # 4972 CODE=" 4973 #if defined(NV_DRM_DRMP_H_PRESENT) 4974 #include <drm/drmP.h> 4975 #endif 4976 #if defined(NV_DRM_DRM_PRIME_H_PRESENT) 4977 #include <drm/drm_prime.h> 4978 #endif 4979 4980 struct sg_table *drm_prime_pages_to_sg(struct drm_device *dev, 4981 struct page **pages, 4982 unsigned int nr_pages) { 4983 return 0; 4984 }" 4985 4986 compile_check_conftest "$CODE" "NV_DRM_PRIME_PAGES_TO_SG_HAS_DRM_DEVICE_ARG" "" "types" 4987 ;; 4988 4989 drm_driver_has_gem_prime_callbacks) 4990 # 4991 # Determine if drm_driver structure has the GEM and PRIME callback 4992 # function pointers. 4993 # 4994 # The GEM and PRIME callback are removed from drm_driver 4995 # structure, by commit d693def4fd1c ("drm: Remove obsolete GEM and 4996 # PRIME callbacks from struct drm_driver"). 4997 # 4998 CODE=" 4999 #if defined(NV_DRM_DRMP_H_PRESENT) 5000 #include <drm/drmP.h> 5001 #endif 5002 5003 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 5004 #include <drm/drm_drv.h> 5005 #endif 5006 5007 void conftest_drm_driver_has_gem_and_prime_callbacks(void) { 5008 struct drm_driver drv; 5009 5010 drv.gem_prime_pin = 0; 5011 drv.gem_prime_get_sg_table = 0; 5012 drv.gem_prime_vmap = 0; 5013 drv.gem_prime_vunmap = 0; 5014 drv.gem_vm_ops = 0; 5015 }" 5016 5017 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_GEM_PRIME_CALLBACKS" "" "types" 5018 ;; 5019 5020 drm_crtc_atomic_check_has_atomic_state_arg) 5021 # 5022 # Determine if drm_crtc_helper_funcs::atomic_check takes 'state' 5023 # argument of 'struct drm_atomic_state' type. 5024 # 5025 # The commit 29b77ad7b9ca ("drm/atomic: Pass the full state to CRTC 5026 # atomic_check") passed the full atomic state to 5027 # drm_crtc_helper_funcs::atomic_check() 5028 # 5029 # To test the signature of drm_crtc_helper_funcs::atomic_check(), 5030 # declare a function prototype with typeof ::atomic_check(), and then 5031 # define the corresponding function implementation with the expected 5032 # signature. Successful compilation indicates that ::atomic_check() 5033 # has the expected signature. 5034 # 5035 echo "$CONFTEST_PREAMBLE 5036 #include <drm/drm_modeset_helper_vtables.h> 5037 5038 static const struct drm_crtc_helper_funcs *funcs; 5039 typeof(*funcs->atomic_check) conftest_drm_crtc_atomic_check_has_atomic_state_arg; 5040 5041 int conftest_drm_crtc_atomic_check_has_atomic_state_arg( 5042 struct drm_crtc *crtc, struct drm_atomic_state *state) { 5043 return 0; 5044 }" > conftest$$.c 5045 5046 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 5047 rm -f conftest$$.c 5048 5049 if [ -f conftest$$.o ]; then 5050 rm -f conftest$$.o 5051 echo "#define NV_DRM_CRTC_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG" | append_conftest "types" 5052 else 5053 echo "#undef NV_DRM_CRTC_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG" | append_conftest "types" 5054 fi 5055 ;; 5056 5057 drm_gem_object_vmap_has_map_arg) 5058 # 5059 # Determine if drm_gem_object_funcs::vmap takes 'map' 5060 # argument of 'struct dma_buf_map' type. 5061 # 5062 # The commit 49a3f51dfeee ("drm/gem: Use struct dma_buf_map in GEM 5063 # vmap ops and convert GEM backends") update 5064 # drm_gem_object_funcs::vmap to take 'map' argument. 5065 # 5066 CODE=" 5067 #include <drm/drm_gem.h> 5068 int conftest_drm_gem_object_vmap_has_map_arg( 5069 struct drm_gem_object *obj, struct dma_buf_map *map) { 5070 return obj->funcs->vmap(obj, map); 5071 }" 5072 5073 compile_check_conftest "$CODE" "NV_DRM_GEM_OBJECT_VMAP_HAS_MAP_ARG" "" "types" 5074 ;; 5075 5076 seq_read_iter) 5077 # 5078 # Determine if seq_read_iter() is present 5079 # 5080 # seq_read_iter() was added by commit d4d50710a8b4 ("seq_file: 5081 # add seq_read_iter") in v5.10-rc1 (2020-11-04). 5082 # 5083 CODE=" 5084 #include <linux/seq_file.h> 5085 void conftest_seq_read_iter(void) { 5086 seq_read_iter(); 5087 }" 5088 5089 compile_check_conftest "$CODE" "NV_SEQ_READ_ITER_PRESENT" "" "functions" 5090 ;; 5091 5092 pci_class_multimedia_hd_audio) 5093 # 5094 # Determine if 'PCI_CLASS_MULTIMEDIA_HD_AUDIO' macro is present 5095 # in <linux/pci_ids.h>. 5096 # 5097 # The commit 07f4f97d7b4b ("vga_switcheroo: Use device link for HDA 5098 # controller") has moved 'PCI_CLASS_MULTIMEDIA_HD_AUDIO' macro from 5099 # <sound/hdaudio.h> to <linux/pci_ids.h> in v4.17-rc1 (2018-03-03). 5100 # 5101 CODE=" 5102 #include <linux/pci_ids.h> 5103 unsigned int conftest_pci_class_multimedia_hd_audio(void) { 5104 return PCI_CLASS_MULTIMEDIA_HD_AUDIO; 5105 }" 5106 5107 compile_check_conftest "$CODE" "NV_PCI_CLASS_MULTIMEDIA_HD_AUDIO_PRESENT" "" "generic" 5108 ;; 5109 5110 unsafe_follow_pfn) 5111 # 5112 # Determine if unsafe_follow_pfn() is present. 5113 # 5114 # unsafe_follow_pfn() was added by commit 69bacee7f9ad 5115 # ("mm: Add unsafe_follow_pfn") in v5.13-rc1. 5116 # 5117 CODE=" 5118 #include <linux/mm.h> 5119 void conftest_unsafe_follow_pfn(void) { 5120 unsafe_follow_pfn(); 5121 }" 5122 5123 compile_check_conftest "$CODE" "NV_UNSAFE_FOLLOW_PFN_PRESENT" "" "functions" 5124 ;; 5125 5126 drm_plane_atomic_check_has_atomic_state_arg) 5127 # 5128 # Determine if drm_plane_helper_funcs::atomic_check takes 'state' 5129 # argument of 'struct drm_atomic_state' type. 5130 # 5131 # The commit 7c11b99a8e58 ("drm/atomic: Pass the full state to 5132 # planes atomic_check") passed the full atomic state to 5133 # drm_plane_helper_funcs::atomic_check() 5134 # 5135 # To test the signature of drm_plane_helper_funcs::atomic_check(), 5136 # declare a function prototype with typeof ::atomic_check(), and then 5137 # define the corresponding function implementation with the expected 5138 # signature. Successful compilation indicates that ::atomic_check() 5139 # has the expected signature. 5140 # 5141 echo "$CONFTEST_PREAMBLE 5142 #include <drm/drm_modeset_helper_vtables.h> 5143 5144 static const struct drm_plane_helper_funcs *funcs; 5145 typeof(*funcs->atomic_check) conftest_drm_plane_atomic_check_has_atomic_state_arg; 5146 5147 int conftest_drm_plane_atomic_check_has_atomic_state_arg( 5148 struct drm_plane *plane, struct drm_atomic_state *state) { 5149 return 0; 5150 }" > conftest$$.c 5151 5152 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 5153 rm -f conftest$$.c 5154 5155 if [ -f conftest$$.o ]; then 5156 rm -f conftest$$.o 5157 echo "#define NV_DRM_PLANE_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG" | append_conftest "types" 5158 else 5159 echo "#undef NV_DRM_PLANE_ATOMIC_CHECK_HAS_ATOMIC_STATE_ARG" | append_conftest "types" 5160 fi 5161 ;; 5162 5163 ib_peer_memory_symbols) 5164 # 5165 # Determine if the following symbols exist in Module.symvers: 5166 # 1. ib_register_peer_memory_client 5167 # 2. ib_unregister_peer_memory_client 5168 # The conftest first checks in the kernel's own Module.symvers in 5169 # the regular path. If the symbols are not found there, it's possible 5170 # that MOFED is installed and check for these symbols in MOFED's 5171 # Module.symvers whose path is different from the kernel's symvers. 5172 # 5173 # Note: KERNELRELEASE and ARCH are defined by Kbuild and automatically 5174 # passed down to conftest.sh as env vars. 5175 5176 MLNX_OFED_KERNEL_DIR=/usr/src/ofa_kernel 5177 VAR_DKMS_SOURCES_DIR=$(test -d /var/lib/dkms/mlnx-ofed-kernel && 5178 ls -d /var/lib/dkms/mlnx-ofed-kernel/*/build 2>/dev/null) 5179 5180 if check_for_ib_peer_memory_symbols "$OUTPUT" || \ 5181 check_for_ib_peer_memory_symbols "$MLNX_OFED_KERNEL_DIR/$ARCH/$KERNELRELEASE" || \ 5182 check_for_ib_peer_memory_symbols "$MLNX_OFED_KERNEL_DIR/$KERNELRELEASE" || \ 5183 check_for_ib_peer_memory_symbols "$MLNX_OFED_KERNEL_DIR/default" || \ 5184 check_for_ib_peer_memory_symbols "$VAR_DKMS_SOURCES_DIR"; then 5185 echo "#define NV_MLNX_IB_PEER_MEM_SYMBOLS_PRESENT" | append_conftest "symbols" 5186 else 5187 echo "#undef NV_MLNX_IB_PEER_MEM_SYMBOLS_PRESENT" | append_conftest "symbols" 5188 fi 5189 ;; 5190 5191 add_memory_driver_managed) 5192 # 5193 # Determine if the add_memory_driver_managed function is present 5194 # 5195 # Added by commit 7b7b27214bba ("mm/memory_hotplug: introduce 5196 # add_memory_driver_managed()") in v5.8-rc1 (2020-06-05) 5197 # 5198 CODE=" 5199 #include <linux/memory_hotplug.h> 5200 void conftest_add_memory_driver_managed() { 5201 add_memory_driver_managed(); 5202 }" 5203 5204 compile_check_conftest "$CODE" "NV_ADD_MEMORY_DRIVER_MANAGED_PRESENT" "" "functions" 5205 ;; 5206 5207 add_memory_driver_managed_has_mhp_flags_arg) 5208 # 5209 # Check if add_memory_driver_managed() has mhp_flags arg. 5210 # 5211 # Added by commit b6117199787c ("mm/memory_hotplug: prepare passing flags to 5212 # add_memory() and friends") in v5.10-rc1 (2020-10-16) 5213 # 5214 CODE=" 5215 #include <linux/memory_hotplug.h> 5216 int add_memory_driver_managed(int nid, u64 start, u64 size, 5217 const char *resource_name, 5218 mhp_t mhp_flags) { 5219 return 0; 5220 }" 5221 5222 compile_check_conftest "$CODE" "NV_ADD_MEMORY_DRIVER_MANAGED_HAS_MHP_FLAGS_ARG" "" "types" 5223 ;; 5224 5225 remove_memory_has_nid_arg) 5226 # 5227 # Check if remove_memory() has nid parameter. 5228 # 5229 # Removed by commit e1c158e4956612e7 ("mm/memory_hotplug: remove nid 5230 # parameter from remove_memory() and friends") in v5.15-rc1 (2021-09-09) 5231 # 5232 CODE=" 5233 #include <linux/memory_hotplug.h> 5234 int remove_memory(int nid, u64 start, u64 size) { 5235 return 0; 5236 }" 5237 5238 compile_check_conftest "$CODE" "NV_REMOVE_MEMORY_HAS_NID_ARG" "" "types" 5239 ;; 5240 5241 offline_and_remove_memory) 5242 # 5243 # Determine if the offline_and_remove_memory function is present. 5244 # 5245 # Added by commit 08b3acd7a68fc179 ("mm/memory_hotplug: Introduce 5246 # offline_and_remove_memory()") in v5.8-rc1 (2020-06-05) 5247 # 5248 CODE=" 5249 #include <linux/memory_hotplug.h> 5250 void conftest_offline_and_remove_memory() { 5251 offline_and_remove_memory(); 5252 }" 5253 5254 compile_check_conftest "$CODE" "NV_OFFLINE_AND_REMOVE_MEMORY_PRESENT" "" "functions" 5255 ;; 5256 5257 device_property_read_u64) 5258 # 5259 # Determine if the device_property_read_u64 function is present 5260 # 5261 # Added by commit b31384fa5de37a1 ("Driver core: Unified device 5262 # properties interface for platform firmware") in v3.19-rc1 (2014-11-05) 5263 # 5264 CODE=" 5265 #include <linux/acpi.h> 5266 void conftest_device_property_read_u64() { 5267 device_property_read_u64(); 5268 }" 5269 5270 compile_check_conftest "$CODE" "NV_DEVICE_PROPERTY_READ_U64_PRESENT" "" "functions" 5271 ;; 5272 5273 of_property_count_elems_of_size) 5274 # 5275 # Determine if of_property_count_elems_of_size is present 5276 # 5277 # Added by commit 1df09bcof (" Move OF property and graph API from 5278 # base.c to property.c" 5279 # 5280 # Test if linux/of.h header file inclusion is successful or not, 5281 # depending on that check, for of_property_count_elems_of_size 5282 # presence 5283 # 5284 echo "$CONFTEST_PREAMBLE 5285 #include <linux/of.h> 5286 " > conftest$$.c 5287 5288 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 5289 rm -f conftest$$.c 5290 5291 if [ -f conftest$$.o ]; then 5292 rm -f conftest$$.o 5293 CODE=" 5294 #include <linux/of.h> 5295 void conftest_of_property_count_elems_of_size() { 5296 of_property_count_elems_of_size(); 5297 }" 5298 5299 compile_check_conftest "$CODE" "NV_OF_PROPERTY_COUNT_ELEMS_OF_SIZE_PRESENT" "" "functions" 5300 else 5301 echo "#undef NV_OF_PROPERTY_COUNT_ELEMS_OF_SIZE_PRESENT" | append_conftest "functions" 5302 fi 5303 ;; 5304 5305 of_property_read_variable_u8_array) 5306 # 5307 # Determine if of_property_read_variable_u8_array is present 5308 # 5309 # Added by commit 1df09bcof (" Move OF property and graph API from 5310 # base.c to property.c" 5311 # 5312 # Test if linux/of.h header file inclusion is successful or not, 5313 # depending on that, check for of_property_read_variable_u8_array 5314 # presence 5315 # 5316 echo "$CONFTEST_PREAMBLE 5317 #include <linux/of.h> 5318 " > conftest$$.c 5319 5320 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 5321 rm -f conftest$$.c 5322 5323 if [ -f conftest$$.o ]; then 5324 rm -f conftest$$.o 5325 CODE=" 5326 #include <linux/of.h> 5327 void conftest_of_property_read_variable_u8_array() { 5328 of_property_read_variable_u8_array(); 5329 }" 5330 5331 compile_check_conftest "$CODE" "NV_OF_PROPERTY_READ_VARIABLE_U8_ARRAY_PRESENT" "" "functions" 5332 else 5333 echo "#undef NV_OF_PROPERTY_READ_VARIABLE_U8_ARRAY_PRESENT" | append_conftest "functions" 5334 fi 5335 ;; 5336 5337 of_property_read_variable_u32_array) 5338 # 5339 # Determine if of_property_read_variable_u32_array is present 5340 # 5341 # Added by commit 1df09bcof (" Move OF property and graph API from 5342 # base.c to property.c" 5343 # 5344 # Test if linux/of.h header file inclusion is successful or not, 5345 # depending on that, check for of_property_read_variable_u32_array 5346 # presence 5347 # 5348 echo "$CONFTEST_PREAMBLE 5349 #include <linux/of.h> 5350 " > conftest$$.c 5351 5352 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 5353 rm -f conftest$$.c 5354 5355 if [ -f conftest$$.o ]; then 5356 rm -f conftest$$.o 5357 CODE=" 5358 #include <linux/of.h> 5359 void conftest_of_property_read_variable_u32_array() { 5360 of_property_read_variable_u32_array(); 5361 }" 5362 5363 compile_check_conftest "$CODE" "NV_OF_PROPERTY_READ_VARIABLE_U32_ARRAY_PRESENT" "" "functions" 5364 else 5365 echo "#undef NV_OF_PROPERTY_READ_VARIABLE_U32_ARRAY_PRESENT" | append_conftest "functions" 5366 fi 5367 ;; 5368 5369 devm_of_platform_populate) 5370 # 5371 # Determine if devm_of_platform_populate() function is present 5372 # 5373 # Added by commit 38b0b21of (add devm_ functions for populate and 5374 # depopulate") 5375 # 5376 CODE=" 5377 #if defined(NV_LINUX_OF_PLATFORM_H_PRESENT) 5378 #include <linux/of_platform.h> 5379 #endif 5380 void conftest_devm_of_platform_populate(void) 5381 { 5382 devm_of_platform_populate(NULL, NULL); 5383 } 5384 " 5385 compile_check_conftest "$CODE" "NV_DEVM_OF_PLATFORM_POPULATE_PRESENT" "" "functions" 5386 ;; 5387 5388 of_dma_configure) 5389 # 5390 # Determine if of_dma_configure() function is present 5391 # 5392 # Added by commit 591c1eeof ("configure the platform device 5393 # dma parameters") 5394 # 5395 CODE=" 5396 #if defined(NV_LINUX_OF_DEVICE_H_PRESENT) 5397 #include <linux/of_device.h> 5398 #endif 5399 void conftest_of_dma_configure(void) 5400 { 5401 of_dma_configure(); 5402 } 5403 " 5404 5405 compile_check_conftest "$CODE" "NV_OF_DMA_CONFIGURE_PRESENT" "" "functions" 5406 ;; 5407 5408 icc_get) 5409 # 5410 # Determine if icc_get() function is present 5411 # 5412 # Added by commit 11f1cec ("interconnect: Add generic on-chip 5413 # interconnect API") 5414 # 5415 CODE=" 5416 #if defined(NV_LINUX_INTERCONNECT_H_PRESENT) 5417 #include <linux/interconnect.h> 5418 #endif 5419 void conftest_icc_get(void) 5420 { 5421 icc_get(); 5422 } 5423 " 5424 5425 compile_check_conftest "$CODE" "NV_ICC_GET_PRESENT" "" "functions" 5426 ;; 5427 5428 icc_set_bw) 5429 # 5430 # Determine if icc_set_bw() function is present 5431 # 5432 # Added by commit 11f1cec ("interconnect: Add generic on-chip 5433 # interconnect API") 5434 # 5435 CODE=" 5436 #if defined(NV_LINUX_INTERCONNECT_H_PRESENT) 5437 #include <linux/interconnect.h> 5438 #endif 5439 void conftest_icc_set_bw(void) 5440 { 5441 icc_set_bw(); 5442 } 5443 " 5444 5445 compile_check_conftest "$CODE" "NV_ICC_SET_BW_PRESENT" "" "functions" 5446 ;; 5447 5448 icc_put) 5449 # 5450 # Determine if icc_put() function is present 5451 # 5452 # Added by commit 11f1cec ("interconnect: Add generic on-chip 5453 # interconnect API") 5454 # 5455 CODE=" 5456 #if defined(NV_LINUX_INTERCONNECT_H_PRESENT) 5457 #include <linux/interconnect.h> 5458 #endif 5459 void conftest_icc_put(void) 5460 { 5461 icc_put(); 5462 } 5463 " 5464 5465 compile_check_conftest "$CODE" "NV_ICC_PUT_PRESENT" "" "functions" 5466 ;; 5467 5468 i2c_new_client_device) 5469 # 5470 # Determine if i2c_new_client_device() function is present 5471 # 5472 # Added by commit 390fd04i2c ("remove deprecated i2c_new_device API") 5473 # 5474 CODE=" 5475 #include <linux/i2c.h> 5476 void conftest_i2c_new_client_device(void) 5477 { 5478 i2c_new_client_device(); 5479 } 5480 " 5481 5482 compile_check_conftest "$CODE" "NV_I2C_NEW_CLIENT_DEVICE_PRESENT" "" "functions" 5483 ;; 5484 5485 i2c_unregister_device) 5486 # 5487 # Determine if i2c_unregister_device() function is present 5488 # 5489 # Added by commit 9c1600ei2c ("Add i2c_board_info and i2c_new_device()") 5490 # 5491 CODE=" 5492 #include <linux/i2c.h> 5493 void conftest_i2c_unregister_device(void) 5494 { 5495 i2c_unregister_device(); 5496 } 5497 " 5498 5499 compile_check_conftest "$CODE" "NV_I2C_UNREGISTER_DEVICE_PRESENT" "" "functions" 5500 ;; 5501 5502 of_get_named_gpio) 5503 # 5504 # Determine if of_get_named_gpio() function is present 5505 # 5506 # Added by commit a6b0919 ("of/gpio: Add new method for getting gpios 5507 # under different property names") 5508 # 5509 CODE=" 5510 #if defined(NV_LINUX_OF_GPIO_H_PRESENT) 5511 #include <linux/of_gpio.h> 5512 #endif 5513 void conftest_of_get_named_gpio(void) 5514 { 5515 of_get_named_gpio(); 5516 } 5517 " 5518 5519 compile_check_conftest "$CODE" "NV_OF_GET_NAME_GPIO_PRESENT" "" "functions" 5520 ;; 5521 5522 devm_gpio_request_one) 5523 # 5524 # Determine if devm_gpio_request_one() function is present 5525 # 5526 # Added by commit 09d71ff (gpiolib: Implement devm_gpio_request_one()") 5527 # 5528 CODE=" 5529 #if defined(NV_LINUX_GPIO_H_PRESENT) 5530 #include <linux/gpio.h> 5531 #endif 5532 void conftest_devm_gpio_request_one(void) 5533 { 5534 devm_gpio_request_one(); 5535 } 5536 " 5537 5538 compile_check_conftest "$CODE" "NV_DEVM_GPIO_REQUEST_ONE_PRESENT" "" "functions" 5539 ;; 5540 5541 gpio_direction_input) 5542 # 5543 # Determine if gpio_direction_input() function is present 5544 # 5545 # Added by commit c7caf86 (gpio: remove gpio_ensure_requested()") 5546 # 5547 CODE=" 5548 #if defined(NV_LINUX_GPIO_H_PRESENT) 5549 #include <linux/gpio.h> 5550 #endif 5551 void conftest_gpio_direction_input(void) 5552 { 5553 gpio_direction_input(); 5554 } 5555 " 5556 5557 compile_check_conftest "$CODE" "NV_GPIO_DIRECTION_INPUT_PRESENT" "" "functions" 5558 ;; 5559 5560 gpio_direction_output) 5561 # 5562 # Determine if gpio_direction_output() function is present 5563 # 5564 # Added by commit c7caf86 (gpio: remove gpio_ensure_requested()") 5565 # 5566 CODE=" 5567 #if defined(NV_LINUX_GPIO_H_PRESENT) 5568 #include <linux/gpio.h> 5569 #endif 5570 void conftest_gpio_direction_output(void) 5571 { 5572 gpio_direction_output(); 5573 } 5574 " 5575 5576 compile_check_conftest "$CODE" "NV_GPIO_DIRECTION_OUTPUT_PRESENT" "" "functions" 5577 ;; 5578 5579 gpio_get_value) 5580 # 5581 # Determine if gpio_get_value() function is present 5582 # 5583 # Added by commit 7563bbf ("gpiolib/arches: Centralise bolierplate 5584 # asm/gpio.h") 5585 # 5586 CODE=" 5587 #if defined(NV_LINUX_GPIO_H_PRESENT) 5588 #include <linux/gpio.h> 5589 #endif 5590 void conftest_gpio_get_value(void) 5591 { 5592 gpio_get_value(); 5593 } 5594 " 5595 5596 compile_check_conftest "$CODE" "NV_GPIO_GET_VALUE_PRESENT" "" "functions" 5597 ;; 5598 5599 gpio_set_value) 5600 # 5601 # Determine if gpio_set_value() function is present 5602 # 5603 # Added by commit 7563bbf ("gpiolib/arches: Centralise bolierplate 5604 # asm/gpio.h") 5605 # 5606 CODE=" 5607 #if defined(NV_LINUX_GPIO_H_PRESENT) 5608 #include <linux/gpio.h> 5609 #endif 5610 void conftest_gpio_set_value(void) 5611 { 5612 gpio_set_value(); 5613 } 5614 " 5615 5616 compile_check_conftest "$CODE" "NV_GPIO_SET_VALUE_PRESENT" "" "functions" 5617 ;; 5618 5619 gpio_to_irq) 5620 # 5621 # Determine if gpio_to_irq() function is present 5622 # 5623 # Added by commit 7563bbf ("gpiolib/arches: Centralise bolierplate 5624 # asm/gpio.h") 5625 # 5626 CODE=" 5627 #if defined(NV_LINUX_GPIO_H_PRESENT) 5628 #include <linux/gpio.h> 5629 #endif 5630 void conftest_gpio_to_irq(void) 5631 { 5632 gpio_to_irq(); 5633 } 5634 " 5635 5636 compile_check_conftest "$CODE" "NV_GPIO_TO_IRQ_PRESENT" "" "functions" 5637 ;; 5638 5639 migrate_vma_setup) 5640 # 5641 # Determine if migrate_vma_setup() function is present 5642 # 5643 # migrate_vma_setup() function was added by commit 5644 # a7d1f22bb74f32cf3cd93f52776007e161f1a738 ("mm: turn migrate_vma 5645 # upside down) in v5.4. 5646 # (2019-08-20). 5647 CODE=" 5648 #include <linux/migrate.h> 5649 int conftest_migrate_vma_setup(void) { 5650 migrate_vma_setup(); 5651 }" 5652 5653 compile_check_conftest "$CODE" "NV_MIGRATE_VMA_SETUP_PRESENT" "" "functions" 5654 ;; 5655 5656 migrate_vma_added_flags) 5657 # 5658 # Determine if migrate_vma structure has flags 5659 # 5660 # flags were added to struct migrate_vma by commit 5661 # 5143192cd410c4fc83be09a2e73423765aee072b ("mm/migrate: add a flags 5662 # parameter to_migrate_vma) in v5.9. 5663 # (2020-07-28). 5664 CODE=" 5665 #include <linux/migrate.h> 5666 int conftest_migrate_vma_added_flags(void) { 5667 return offsetof(struct migrate_vma, flags); 5668 }" 5669 5670 compile_check_conftest "$CODE" "NV_MIGRATE_VMA_FLAGS_PRESENT" "" "types" 5671 ;; 5672 5673 drm_device_has_pdev) 5674 # 5675 # Determine if the 'drm_device' structure has a 'pdev' field. 5676 # 5677 # Removed by commit b347e04452ff ("drm: Remove pdev field from 5678 # struct drm_device") in v5.14-rc1. 5679 # 5680 CODE=" 5681 #if defined(NV_DRM_DRMP_H_PRESENT) 5682 #include <drm/drmP.h> 5683 #endif 5684 5685 #if defined(NV_DRM_DRM_DEVICE_H_PRESENT) 5686 #include <drm/drm_device.h> 5687 #endif 5688 5689 int conftest_drm_device_has_pdev(void) { 5690 return offsetof(struct drm_device, pdev); 5691 }" 5692 5693 compile_check_conftest "$CODE" "NV_DRM_DEVICE_HAS_PDEV" "" "types" 5694 ;; 5695 5696 make_device_exclusive_range) 5697 # 5698 # Determine if the make_device_exclusive_range() function is present 5699 # 5700 # make_device_exclusive_range() function was added by commit 5701 # b756a3b5e7ead ("mm: device exclusive memory access") in v5.14 5702 # (2021-06-30). 5703 CODE=" 5704 #include <linux/rmap.h> 5705 int conftest_make_device_exclusive_range(void) { 5706 make_device_exclusive_range(); 5707 }" 5708 5709 compile_check_conftest "$CODE" "NV_MAKE_DEVICE_EXCLUSIVE_RANGE_PRESENT" "" "functions" 5710 ;; 5711 5712 migrate_device_range) 5713 # 5714 # Determine if the migrate_device_range() function is present 5715 # 5716 # migrate_device_range() function was added by commit 5717 # e778406b40dbb ("mm/migrate_device.c: add migrate_device_range()") 5718 # in v6.1 (2022-09-28). 5719 CODE=" 5720 #include <linux/migrate.h> 5721 int conftest_migrate_device_range(void) { 5722 migrate_device_range(); 5723 }" 5724 5725 compile_check_conftest "$CODE" "NV_MIGRATE_DEVICE_RANGE_PRESENT" "" "functions" 5726 ;; 5727 5728 ioasid_get) 5729 # 5730 # Determine if ioasid_get() function is present 5731 # 5732 # ioasid_get() function was added by commit 5733 # cb4789b0d19ff231ce9f73376a023341300aed96 (iommu/ioasid: Add ioasidreferences) in v5.11. 5734 # (2020-11-23). 5735 CODE=" 5736 #if defined(NV_LINUX_IOASID_H_PRESENT) 5737 #include <linux/ioasid.h> 5738 #endif 5739 void conftest_ioasid_get(void) { 5740 ioasid_get(); 5741 }" 5742 5743 compile_check_conftest "$CODE" "NV_IOASID_GET_PRESENT" "" "functions" 5744 ;; 5745 5746 mm_pasid_set) 5747 # 5748 # Determine if mm_pasid_set() function is present 5749 # 5750 # mm_pasid_set() function was added by commit 5751 # 701fac40384f07197b106136012804c3cae0b3de (iommu/sva: Assign a 5752 # PASID to mm on PASID allocation and free it on mm exit) in v5.18. 5753 # (2022-02-15). 5754 CODE=" 5755 #if defined(NV_LINUX_SCHED_MM_H_PRESENT) 5756 #include <linux/sched/mm.h> 5757 #endif 5758 void conftest_mm_pasid_set(void) { 5759 mm_pasid_set(); 5760 }" 5761 5762 compile_check_conftest "$CODE" "NV_MM_PASID_SET_PRESENT" "" "functions" 5763 ;; 5764 5765 drm_crtc_state_has_no_vblank) 5766 # 5767 # Determine if the 'drm_crtc_state' structure has 'no_vblank'. 5768 # 5769 # drm_crtc_state::no_vblank was added by commit b25c60af7a877 5770 # ("drm/crtc: Add a generic infrastructure to fake VBLANK events") 5771 # in 4.18.0-rc3 (2018-07-03). 5772 # 5773 CODE=" 5774 #include <drm/drm_crtc.h> 5775 void conftest_drm_crtc_state_has_no_vblank(void) { 5776 struct drm_crtc_state foo; 5777 (void)foo.no_vblank; 5778 }" 5779 5780 compile_check_conftest "$CODE" "NV_DRM_CRTC_STATE_HAS_NO_VBLANK" "" "types" 5781 ;; 5782 5783 drm_mode_config_has_allow_fb_modifiers) 5784 # 5785 # Determine if the 'drm_mode_config' structure has 5786 # an 'allow_fb_modifiers' field. 5787 # 5788 # an 'allow_fb_modifiers' field in the 'drm_mode_config' structure, 5789 # is added by commit e3eb3250d84e ("drm: add support for 5790 # tiled/compressed/etc modifier in addfb2") in v4.1, and removed by 5791 # commit 3d082157a242 ("drm: remove allow_fb_modifiers") in v5.18-rc1. 5792 # 5793 # The 'struct drm_mode_config' definition, is moved to 5794 # drm_mode_config.h file by commit 28575f165d36 ("drm: Extract 5795 # drm_mode_config.[hc]") in v4.10. 5796 # 5797 CODE="$CONFTEST_PREAMBLE 5798 #if defined(NV_DRM_DRM_MODE_CONFIG_H_PRESENT) 5799 #include <drm/drm_mode_config.h> 5800 #else 5801 #include <drm/drm_crtc.h> 5802 #endif 5803 int conftest_drm_mode_config_has_allow_fb_modifiers(void) { 5804 return offsetof(struct drm_mode_config, allow_fb_modifiers); 5805 }" 5806 5807 compile_check_conftest "$CODE" "NV_DRM_MODE_CONFIG_HAS_ALLOW_FB_MODIFIERS" "" "types" 5808 ;; 5809 5810 dma_set_mask_and_coherent) 5811 # 5812 # Determine if dma_set_mask_and_coherent function is present. 5813 # Added by commit 4aa806b771d1 ("DMA-API: provide a helper to set both DMA 5814 # and coherent DMA masks") in v3.13 (2013-06-26). 5815 # 5816 CODE=" 5817 #include <linux/dma-mapping.h> 5818 void conftest_dma_set_mask_and_coherent(void) { 5819 dma_set_mask_and_coherent(); 5820 }" 5821 5822 compile_check_conftest "$CODE" "NV_DMA_SET_MASK_AND_COHERENT_PRESENT" "" "functions" 5823 ;; 5824 5825 drm_has_hdr_output_metadata) 5826 # 5827 # Determine if drm_mode.h has 'hdr_output_metadata' structure. 5828 # 5829 # struct hdr_output_metadata was added by commit fbb5d0353c62d 5830 # ("drm: Add HDR source metadata property") in 5.1.0-rc5 5831 # (2019-05-16) 5832 # 5833 CODE=" 5834 #include <drm/drm_mode.h> 5835 void conftest_drm_has_hdr_output_metadata(void) { 5836 struct hdr_output_metadata foo; 5837 (void)foo; 5838 }" 5839 5840 compile_check_conftest "$CODE" "NV_DRM_HAS_HDR_OUTPUT_METADATA" "" "types" 5841 ;; 5842 5843 uts_release) 5844 # 5845 # print the kernel's UTS_RELEASE string. 5846 # 5847 echo "#include <generated/utsrelease.h> 5848 UTS_RELEASE" > conftest$$.c 5849 5850 $CC $CFLAGS -E -P conftest$$.c 5851 rm -f conftest$$.c 5852 ;; 5853 5854 platform_irq_count) 5855 # 5856 # Determine if the platform_irq_count() function is present 5857 # 5858 # platform_irq_count was added by commit 5859 # 4b83555d5098e73cf2c5ca7f86c17ca0ba3b968e ("driver-core: platform: Add platform_irq_count()") 5860 # in 4.5-rc1 (2016-01-07) 5861 # 5862 CODE=" 5863 #include <linux/platform_device.h> 5864 int conftest_platform_irq_count(void) { 5865 return platform_irq_count(); 5866 }" 5867 compile_check_conftest "$CODE" "NV_PLATFORM_IRQ_COUNT_PRESENT" "" "functions" 5868 ;; 5869 5870 devm_clk_bulk_get_all) 5871 # 5872 # Determine if devm_clk_bulk_get_all() function is present 5873 # 5874 # Added by commit f08c2e286 ("clk: add managed version of clk_bulk_get_all") 5875 # 5876 CODE=" 5877 #if defined(NV_LINUX_CLK_H_PRESENT) 5878 #include <linux/clk.h> 5879 #endif 5880 void conftest_devm_clk_bulk_get_all(void) 5881 { 5882 devm_clk_bulk_get_all(); 5883 } 5884 " 5885 compile_check_conftest "$CODE" "NV_DEVM_CLK_BULK_GET_ALL_PRESENT" "" "functions" 5886 ;; 5887 5888 mmget_not_zero) 5889 # 5890 # Determine if mmget_not_zero() function is present 5891 # 5892 # mmget_not_zero() function was added by commit 5893 # d2005e3f41d4f9299e2df6a967c8beb5086967a9 ("userfaultfd: don't pin 5894 # the user memory in userfaultfd_file_create()") in v4.7 5895 # (2016-05-20) in linux/sched.h but then moved to linux/sched/mm.h 5896 # by commit 68e21be2916b359fd8afb536c1911dc014cfd03e 5897 # ("sched/headers: Move task->mm handling methods to 5898 # <linux/sched/mm.h>") in v4.11 (2017-02-01). 5899 CODE=" 5900 #if defined(NV_LINUX_SCHED_MM_H_PRESENT) 5901 #include <linux/sched/mm.h> 5902 #elif defined(NV_LINUX_SCHED_H_PRESENT) 5903 #include <linux/sched.h> 5904 #endif 5905 void conftest_mmget_not_zero(void) { 5906 mmget_not_zero(); 5907 }" 5908 5909 compile_check_conftest "$CODE" "NV_MMGET_NOT_ZERO_PRESENT" "" "functions" 5910 ;; 5911 5912 mmgrab) 5913 # 5914 # Determine if mmgrab() function is present 5915 # 5916 # mmgrab() function was added by commit 5917 # f1f1007644ffc8051a4c11427d58b1967ae7b75a ("mm: add new 5918 # mmgrab() helper") in v4.11 (2017-02-01). See comment for 5919 # mmget_not_zero for a description of how the headers have 5920 # changed. 5921 CODE=" 5922 #if defined(NV_LINUX_SCHED_MM_H_PRESENT) 5923 #include <linux/sched/mm.h> 5924 #elif defined(NV_LINUX_SCHED_H_PRESENT) 5925 #include <linux/sched.h> 5926 #endif 5927 void conftest_mmgrab(void) { 5928 mmgrab(); 5929 }" 5930 5931 compile_check_conftest "$CODE" "NV_MMGRAB_PRESENT" "" "functions" 5932 ;; 5933 5934 dma_resv_add_fence) 5935 # 5936 # Determine if the dma_resv_add_fence() function is present. 5937 # 5938 # dma_resv_add_excl_fence() and dma_resv_add_shared_fence() were 5939 # removed and replaced with dma_resv_add_fence() by commit 5940 # 73511edf8b19 ("dma-buf: specify usage while adding fences to 5941 # dma_resv obj v7") in linux-next, expected in v5.19-rc1. 5942 # 5943 CODE=" 5944 #if defined(NV_LINUX_DMA_RESV_H_PRESENT) 5945 #include <linux/dma-resv.h> 5946 #endif 5947 void conftest_dma_resv_add_fence(void) { 5948 dma_resv_add_fence(); 5949 }" 5950 5951 compile_check_conftest "$CODE" "NV_DMA_RESV_ADD_FENCE_PRESENT" "" "functions" 5952 ;; 5953 5954 dma_resv_reserve_fences) 5955 # 5956 # Determine if the dma_resv_reserve_fences() function is present. 5957 # 5958 # dma_resv_reserve_shared() was removed and replaced with 5959 # dma_resv_reserve_fences() by commit c8d4c18bfbc4 5960 # ("dma-buf/drivers: make reserving a shared slot mandatory v4") in 5961 # linux-next, expected in v5.19-rc1. 5962 # 5963 CODE=" 5964 #if defined(NV_LINUX_DMA_RESV_H_PRESENT) 5965 #include <linux/dma-resv.h> 5966 #endif 5967 void conftest_dma_resv_reserve_fences(void) { 5968 dma_resv_reserve_fences(); 5969 }" 5970 5971 compile_check_conftest "$CODE" "NV_DMA_RESV_RESERVE_FENCES_PRESENT" "" "functions" 5972 ;; 5973 5974 reservation_object_reserve_shared_has_num_fences_arg) 5975 # 5976 # Determine if reservation_object_reserve_shared() has 'num_fences' 5977 # argument. 5978 # 5979 # reservation_object_reserve_shared() function prototype was updated 5980 # to take 'num_fences' argument by commit ca05359f1e64 ("dma-buf: 5981 # allow reserving more than one shared fence slot") in v4.21-rc1 5982 # (2018-12-14). 5983 # 5984 CODE=" 5985 #include <linux/reservation.h> 5986 void conftest_reservation_object_reserve_shared_has_num_fences_arg( 5987 struct reservation_object *obj, 5988 unsigned int num_fences) { 5989 (void) reservation_object_reserve_shared(obj, num_fences); 5990 }" 5991 5992 compile_check_conftest "$CODE" "NV_RESERVATION_OBJECT_RESERVE_SHARED_HAS_NUM_FENCES_ARG" "" "types" 5993 ;; 5994 5995 get_task_ioprio) 5996 # 5997 # Determine if the __get_task_ioprio() function is present. 5998 # 5999 # __get_task_ioprio was added by commit 893e5d32d583 6000 # ("block: Generalize get_current_ioprio() for any task") for 6001 # v5.20 linux-next (2022-06-23). 6002 # 6003 CODE=" 6004 #include <linux/ioprio.h> 6005 void conftest_get_task_ioprio(void) { 6006 __get_task_ioprio(); 6007 }" 6008 6009 compile_check_conftest "$CODE" "NV_GET_TASK_IOPRIO_PRESENT" "" "functions" 6010 ;; 6011 6012 num_registered_fb) 6013 # 6014 # Determine if 'num_registered_fb' variable is present. 6015 # 6016 # 'num_registered_fb' was removed by commit 5727dcfd8486 6017 # ("fbdev: Make registered_fb[] private to fbmem.c") for 6018 # v5.20 linux-next (2022-07-27). 6019 # 6020 CODE=" 6021 #include <linux/fb.h> 6022 int conftest_num_registered_fb(void) { 6023 return num_registered_fb; 6024 }" 6025 6026 compile_check_conftest "$CODE" "NV_NUM_REGISTERED_FB_PRESENT" "" "types" 6027 ;; 6028 6029 acpi_video_backlight_use_native) 6030 # 6031 # Determine if acpi_video_backlight_use_native() function is present 6032 # 6033 # acpi_video_backlight_use_native was added by commit 2600bfa3df99 6034 # (ACPI: video: Add acpi_video_backlight_use_native() helper) for 6035 # v6.0 (2022-08-17). Note: the include directive for <linux/types.h> 6036 # in this conftest is necessary in order to support kernels between 6037 # commit 0b9f7d93ca61 ("ACPI / i915: ignore firmware requests for 6038 # backlight change") for v3.16 (2014-07-07) and commit 3bd6bce369f5 6039 # ("ACPI / video: Port to new backlight interface selection API") 6040 # for v4.2 (2015-07-16). Kernels within this range use the 'bool' 6041 # type and the related 'false' value in <acpi/video.h> without first 6042 # including the definitions of that type and value. 6043 # 6044 CODE=" 6045 #include <linux/types.h> 6046 #include <acpi/video.h> 6047 void conftest_acpi_video_backglight_use_native(void) { 6048 acpi_video_backlight_use_native(0); 6049 }" 6050 6051 compile_check_conftest "$CODE" "NV_ACPI_VIDEO_BACKLIGHT_USE_NATIVE" "" "functions" 6052 ;; 6053 6054 vm_fault_to_errno) 6055 # 6056 # Determine if the vm_fault_to_errno() function is present. 6057 # 6058 # vm_fault_to_errno() was added by commit 9a291a7c94281 (mm/hugetlb: 6059 # report -EHWPOISON not -EFAULT when FOLL_HWPOISON is specified) in 6060 # v4.12 (2017-06-02). 6061 # 6062 CODE=" 6063 #include <linux/mm_types.h> 6064 void conftest_vm_fault_to_errno(void) { 6065 vm_fault_to_errno(); 6066 }" 6067 6068 compile_check_conftest "$CODE" "NV_VM_FAULT_TO_ERRNO_PRESENT" "" "functions" 6069 ;; 6070 6071 handle_mm_fault_has_mm_arg) 6072 # 6073 # Determine if handle_mm_fault() has mm argument. 6074 # 6075 # mm argument was removed from handle_mm_fault() by commit 6076 # dcddffd41d3f1d3bdcc1dce3f1cd142779b6d4c1 (07/26/2016) ("mm: do not 6077 # pass mm_struct into handle_mm_fault") in v4.8. 6078 # 6079 # To test if handle_mm_fault() has mm argument, define a function 6080 # with the expected signature and then define the corresponding 6081 # function implementation with the expected signature. Successful 6082 # compilation indicates that handle_mm_fault has the mm argument. 6083 # 6084 CODE=" 6085 #include <linux/mm.h> 6086 #include <linux/mm_types.h> 6087 6088 typeof(handle_mm_fault) conftest_handle_mm_fault_has_mm_arg; 6089 int conftest_handle_mm_fault_has_mm_arg(struct mm_struct *mm, 6090 struct vm_area_struct *vma, 6091 unsigned long address, 6092 unsigned int flags) { 6093 return 0; 6094 }" 6095 6096 compile_check_conftest "$CODE" "NV_HANDLE_MM_FAULT_HAS_MM_ARG" "" "types" 6097 ;; 6098 6099 handle_mm_fault_has_pt_regs_arg) 6100 # 6101 # Determine if handle_mm_fault() has pt_regs argument. 6102 # 6103 # pt_regs argument was added to handle_mm_fault by commit 6104 # bce617edecada007aee8610fbe2c14d10b8de2f6 (08/12/2020) ("mm: do 6105 # page fault accounting in handle_mm_fault") in v5.9. 6106 # 6107 # To test if handle_mm_fault() has pt_regs argument, define a 6108 # function with the expected signature and then define the 6109 # corresponding function implementation with the expected signature. 6110 # Successful compilation indicates that handle_mm_fault has the 6111 # pt_regs argument. 6112 # 6113 CODE=" 6114 #include <linux/mm.h> 6115 #include <linux/mm_types.h> 6116 6117 typeof(handle_mm_fault) conftest_handle_mm_fault_has_pt_regs_arg; 6118 vm_fault_t conftest_handle_mm_fault_has_pt_regs_arg(struct vm_area_struct *vma, 6119 unsigned long address, 6120 unsigned int flags, 6121 struct pt_regs *regs) { 6122 return 0; 6123 }" 6124 6125 compile_check_conftest "$CODE" "NV_HANDLE_MM_FAULT_HAS_PT_REGS_ARG" "" "types" 6126 ;; 6127 6128 pci_rebar_get_possible_sizes) 6129 # 6130 # Determine if the pci_rebar_get_possible_sizes() function is present. 6131 # 6132 # Added by commit 8fbdbb66f8c10 ("PCI: Add resizable BAR infrastructure 6133 # ") in v5.12 6134 # 6135 CODE=" 6136 #include <linux/pci.h> 6137 void conftest_pci_rebar_get_possible_sizes(void) { 6138 pci_rebar_get_possible_sizes(); 6139 }" 6140 6141 compile_check_conftest "$CODE" "NV_PCI_REBAR_GET_POSSIBLE_SIZES_PRESENT" "" "functions" 6142 ;; 6143 6144 wait_for_random_bytes) 6145 # 6146 # Determine if the wait_for_random_bytes() function is present. 6147 # 6148 # Added by commit e297a783e4156 ("random: add wait_for_random_bytes 6149 # API") in v4.13 6150 # 6151 CODE=" 6152 #include <linux/random.h> 6153 int conftest_wait_for_random_bytes(void) { 6154 return wait_for_random_bytes(0); 6155 }" 6156 6157 compile_check_conftest "$CODE" "NV_WAIT_FOR_RANDOM_BYTES_PRESENT" "" "functions" 6158 ;; 6159 6160 drm_connector_has_override_edid) 6161 # 6162 # Determine if 'struct drm_connector' has an 'override_edid' member. 6163 # 6164 # Removed by commit 90b575f52c6ab ("drm/edid: detach debugfs EDID 6165 # override from EDID property update") in linux-next, expected in 6166 # v6.2-rc1. 6167 # 6168 CODE=" 6169 #if defined(NV_DRM_DRM_CRTC_H_PRESENT) 6170 #include <drm/drm_crtc.h> 6171 #endif 6172 #if defined(NV_DRM_DRM_CONNECTOR_H_PRESENT) 6173 #include <drm/drm_connector.h> 6174 #endif 6175 int conftest_drm_connector_has_override_edid(void) { 6176 return offsetof(struct drm_connector, override_edid); 6177 }" 6178 6179 compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_HAS_OVERRIDE_EDID" "" "types" 6180 ;; 6181 6182 iommu_sva_bind_device_has_drvdata_arg) 6183 # 6184 # Check if iommu_sva_bind_device() has drvdata parameter. 6185 # 6186 # drvdata argument was removed by commit 6187 # 942fd5435dccb273f90176b046ae6bbba60cfbd8 ("iommu: Remove 6188 # SVM_FLAG_SUPERVISOR_MODE support") in v6.2 (2022-10-31) 6189 # 6190 CODE=" 6191 #include <linux/iommu.h> 6192 #include <linux/mm_types.h> 6193 #include <linux/device.h> 6194 void conftest_iommu_sva_bind_device_has_drvdata_arg(struct device *dev, 6195 struct mm_struct *mm, 6196 void *drvdata) { 6197 (void) iommu_sva_bind_device(dev, mm, drvdata); 6198 }" 6199 6200 compile_check_conftest "$CODE" "NV_IOMMU_SVA_BIND_DEVICE_HAS_DRVDATA_ARG" "" "types" 6201 ;; 6202 6203 vm_area_struct_has_const_vm_flags) 6204 # 6205 # Determine if the 'vm_area_struct' structure has 6206 # const 'vm_flags'. 6207 # 6208 # A union of '__vm_flags' and 'const vm_flags' was added 6209 # by commit bc292ab00f6c ("mm: introduce vma->vm_flags 6210 # wrapper functions") in mm-stable branch (2023-02-09) 6211 # of the akpm/mm maintainer tree. 6212 # 6213 CODE=" 6214 #include <linux/mm_types.h> 6215 int conftest_vm_area_struct_has_const_vm_flags(void) { 6216 return offsetof(struct vm_area_struct, __vm_flags); 6217 }" 6218 6219 compile_check_conftest "$CODE" "NV_VM_AREA_STRUCT_HAS_CONST_VM_FLAGS" "" "types" 6220 ;; 6221 6222 drm_driver_has_dumb_destroy) 6223 # 6224 # Determine if the 'drm_driver' structure has a 'dumb_destroy' 6225 # function pointer. 6226 # 6227 # Removed by commit 96a7b60f6ddb2 ("drm: remove dumb_destroy 6228 # callback") in v6.3 linux-next (2023-02-10). 6229 # 6230 CODE=" 6231 #if defined(NV_DRM_DRMP_H_PRESENT) 6232 #include <drm/drmP.h> 6233 #endif 6234 6235 #if defined(NV_DRM_DRM_DRV_H_PRESENT) 6236 #include <drm/drm_drv.h> 6237 #endif 6238 6239 int conftest_drm_driver_has_dumb_destroy(void) { 6240 return offsetof(struct drm_driver, dumb_destroy); 6241 }" 6242 6243 compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_DUMB_DESTROY" "" "types" 6244 ;; 6245 6246 memory_failure_has_trapno_arg) 6247 # 6248 # Check if memory_failure() has trapno parameter. 6249 # 6250 # trapno argument was removed by commit 6251 # 83b57531c58f4173d1c0d0b2c0bc88c853c32ea5 ("mm/memory_failure: 6252 # Remove unused trapno from memory_failure") in v4.15.0 (2017-7-9) 6253 # 6254 CODE=" 6255 #include <linux/mm.h> 6256 void conftest_memory_failure_has_trapno_arg(unsigned long pfn, 6257 int trapno, 6258 int flags) { 6259 (void) memory_failure(pfn, trapno, flags); 6260 }" 6261 6262 compile_check_conftest "$CODE" "NV_MEMORY_FAILURE_HAS_TRAPNO_ARG" "" "types" 6263 ;; 6264 6265 memory_failure_mf_sw_simulated_defined) 6266 # 6267 # Check if memory_failure() flag MF_SW_SIMULATED is defined. 6268 # 6269 # MF_SW_SIMULATED was added by commit 6270 # 67f22ba7750f940bcd7e1b12720896c505c2d63f ("mm/hwpoison: 6271 # fix unpoison_memory()") in v5.19.0-rc2 (2022-6-16) 6272 # 6273 CODE=" 6274 #include <linux/mm.h> 6275 int conftest_memory_failure_mf_sw_simulated_defined(void) { 6276 return MF_SW_SIMULATED; 6277 }" 6278 6279 compile_check_conftest "$CODE" "NV_MEMORY_FAILURE_MF_SW_SIMULATED_DEFINED" "" "types" 6280 ;; 6281 6282 crypto) 6283 # 6284 # Determine if we support various crypto functions. 6285 # This test is not complete and may return false positive. 6286 # 6287 CODE=" 6288 #include <crypto/akcipher.h> 6289 #include <crypto/algapi.h> 6290 #include <crypto/ecc_curve.h> 6291 #include <crypto/ecdh.h> 6292 #include <crypto/hash.h> 6293 #include <crypto/internal/ecc.h> 6294 #include <crypto/kpp.h> 6295 #include <crypto/public_key.h> 6296 #include <crypto/sm3.h> 6297 #include <keys/asymmetric-type.h> 6298 #include <linux/crypto.h> 6299 void conftest_crypto(void) { 6300 struct shash_desc sd; 6301 struct crypto_shash cs; 6302 (void)crypto_shash_tfm_digest; 6303 }" 6304 6305 compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols" 6306 ;; 6307 6308 mempolicy_has_unified_nodes) 6309 # 6310 # Determine if the 'mempolicy' structure has 6311 # nodes union. 6312 # 6313 # nodes field was added by commit 269fbe72cd ("mm/mempolicy: 6314 # use unified 'nodes' for bind/interleave/prefer policies") in 6315 # v5.14 (2021-06-30). 6316 # 6317 CODE=" 6318 #include <linux/mempolicy.h> 6319 int conftest_mempolicy_has_unified_nodes(void) { 6320 return offsetof(struct mempolicy, nodes); 6321 }" 6322 6323 compile_check_conftest "$CODE" "NV_MEMPOLICY_HAS_UNIFIED_NODES" "" "types" 6324 ;; 6325 6326 mempolicy_has_home_node) 6327 # 6328 # Determine if the 'mempolicy' structure has 6329 # home_node field. 6330 # 6331 # home_node field was added by commit c6018b4b254 6332 # ("mm/mempolicy: add set_mempolicy_home_node syscall") in v5.17 6333 # (2022-01-14). 6334 # 6335 CODE=" 6336 #include <linux/mempolicy.h> 6337 int conftest_mempolicy_has_home_node(void) { 6338 return offsetof(struct mempolicy, home_node); 6339 }" 6340 6341 compile_check_conftest "$CODE" "NV_MEMPOLICY_HAS_HOME_NODE" "" "types" 6342 ;; 6343 6344 # When adding a new conftest entry, please use the correct format for 6345 # specifying the relevant upstream Linux kernel commit. 6346 # 6347 # <function> was added|removed|etc by commit <sha> ("<commit message") 6348 # in <kernel-version> (<commit date>). 6349 6350 *) 6351 # Unknown test name given 6352 echo "Error: unknown conftest '$1' requested" >&2 6353 exit 1 6354 ;; 6355 esac 6356} 6357 6358case "$5" in 6359 cc_sanity_check) 6360 # 6361 # Check if the selected compiler can create object files 6362 # in the current environment. 6363 # 6364 VERBOSE=$6 6365 6366 echo "int cc_sanity_check(void) { 6367 return 0; 6368 }" > conftest$$.c 6369 6370 $CC -c conftest$$.c > /dev/null 2>&1 6371 rm -f conftest$$.c 6372 6373 if [ ! -f conftest$$.o ]; then 6374 if [ "$VERBOSE" = "full_output" ]; then 6375 echo ""; 6376 fi 6377 if [ "$CC" != "cc" ]; then 6378 echo "The C compiler '$CC' does not appear to be able to" 6379 echo "create object files. Please make sure you have " 6380 echo "your Linux distribution's libc development package" 6381 echo "installed and that '$CC' is a valid C compiler"; 6382 echo "name." 6383 else 6384 echo "The C compiler '$CC' does not appear to be able to" 6385 echo "create executables. Please make sure you have " 6386 echo "your Linux distribution's gcc and libc development" 6387 echo "packages installed." 6388 fi 6389 if [ "$VERBOSE" = "full_output" ]; then 6390 echo ""; 6391 echo "*** Failed CC sanity check. Bailing out! ***"; 6392 echo ""; 6393 fi 6394 exit 1 6395 else 6396 rm -f conftest$$.o 6397 exit 0 6398 fi 6399 ;; 6400 6401 cc_version_check) 6402 # 6403 # Verify that the same compiler major and minor version is 6404 # used for the kernel and kernel module. A mismatch condition is 6405 # not considered fatal, so this conftest returns a success status 6406 # code, even if it fails. Failure of the test can be distinguished 6407 # by testing for empty (success) versus non-empty (failure) output. 6408 # 6409 # Some gcc version strings that have proven problematic for parsing 6410 # in the past: 6411 # 6412 # gcc.real (GCC) 3.3 (Debian) 6413 # gcc-Version 3.3 (Debian) 6414 # gcc (GCC) 3.1.1 20020606 (Debian prerelease) 6415 # version gcc 3.2.3 6416 # 6417 # As of this writing, GCC uses a version number as x.y.z and below 6418 # are the typical version strings seen with various distributions. 6419 # gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-23) 6420 # gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 6421 # gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4) 6422 # gcc (GCC) 10.2.1 20200723 (Red Hat 10.2.1-1) 6423 # gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 6424 # gcc (Ubuntu 7.5.0-3ubuntu1~16.04) 7.5.0 6425 # gcc (Debian 8.3.0-6) 8.3.0 6426 # aarch64-linux-gcc.br_real (Buildroot 2020.08-14-ge5a2a90) 9.3.0, GNU ld (GNU Binutils) 2.33.1 6427 # 6428 # In order to extract GCC version correctly for version strings 6429 # like the last one above, we first check for x.y.z and if that 6430 # fails, we fallback to x.y format. 6431 VERBOSE=$6 6432 6433 kernel_compile_h=$OUTPUT/include/generated/compile.h 6434 6435 if [ ! -f ${kernel_compile_h} ]; then 6436 # The kernel's compile.h file is not present, so there 6437 # isn't a convenient way to identify the compiler version 6438 # used to build the kernel. 6439 IGNORE_CC_MISMATCH=1 6440 fi 6441 6442 if [ -n "$IGNORE_CC_MISMATCH" ]; then 6443 exit 0 6444 fi 6445 6446 kernel_cc_string=`cat ${kernel_compile_h} | \ 6447 grep LINUX_COMPILER | cut -f 2 -d '"'` 6448 6449 kernel_cc_version=`echo ${kernel_cc_string} | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' | head -n 1` 6450 if [ -z "${kernel_cc_version}" ]; then 6451 kernel_cc_version=`echo ${kernel_cc_string} | grep -o '[0-9]\+\.[0-9]\+' | head -n 1` 6452 fi 6453 kernel_cc_major=`echo ${kernel_cc_version} | cut -d '.' -f 1` 6454 kernel_cc_minor=`echo ${kernel_cc_version} | cut -d '.' -f 2` 6455 6456 echo " 6457 #if (__GNUC__ != ${kernel_cc_major}) || (__GNUC_MINOR__ != ${kernel_cc_minor}) 6458 #error \"cc version mismatch\" 6459 #endif 6460 " > conftest$$.c 6461 6462 $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1 6463 rm -f conftest$$.c 6464 6465 if [ -f conftest$$.o ]; then 6466 rm -f conftest$$.o 6467 exit 0; 6468 else 6469 # 6470 # The gcc version check failed 6471 # 6472 6473 if [ "$VERBOSE" = "full_output" ]; then 6474 echo ""; 6475 echo "Warning: Compiler version check failed:"; 6476 echo ""; 6477 echo "The major and minor number of the compiler used to"; 6478 echo "compile the kernel:"; 6479 echo ""; 6480 echo "${kernel_cc_string}"; 6481 echo ""; 6482 echo "does not match the compiler used here:"; 6483 echo ""; 6484 $CC --version 6485 echo ""; 6486 echo "It is recommended to set the CC environment variable"; 6487 echo "to the compiler that was used to compile the kernel."; 6488 echo "" 6489 echo "To skip the test and silence this warning message, set"; 6490 echo "the IGNORE_CC_MISMATCH environment variable to \"1\"."; 6491 echo "However, mixing compiler versions between the kernel"; 6492 echo "and kernel modules can result in subtle bugs that are"; 6493 echo "difficult to diagnose."; 6494 echo ""; 6495 echo "*** Failed CC version check. ***"; 6496 echo ""; 6497 elif [ "$VERBOSE" = "just_msg" ]; then 6498 echo "Warning: The kernel was built with ${kernel_cc_string}, but the" \ 6499 "current compiler version is `$CC --version | head -n 1`."; 6500 fi 6501 exit 0; 6502 fi 6503 ;; 6504 6505 xen_sanity_check) 6506 # 6507 # Check if the target kernel is a Xen kernel. If so, exit, since 6508 # the RM doesn't currently support Xen. 6509 # 6510 VERBOSE=$6 6511 6512 if [ -n "$IGNORE_XEN_PRESENCE" -o -n "$VGX_BUILD" ]; then 6513 exit 0 6514 fi 6515 6516 test_xen 6517 6518 if [ "$XEN_PRESENT" != "0" ]; then 6519 echo "The kernel you are installing for is a Xen kernel!"; 6520 echo ""; 6521 echo "The NVIDIA driver does not currently support Xen kernels. If "; 6522 echo "you are using a stock distribution kernel, please install "; 6523 echo "a variant of this kernel without Xen support; if this is a "; 6524 echo "custom kernel, please install a standard Linux kernel. Then "; 6525 echo "try installing the NVIDIA kernel module again."; 6526 echo ""; 6527 if [ "$VERBOSE" = "full_output" ]; then 6528 echo "*** Failed Xen sanity check. Bailing out! ***"; 6529 echo ""; 6530 fi 6531 exit 1 6532 else 6533 exit 0 6534 fi 6535 ;; 6536 6537 preempt_rt_sanity_check) 6538 # 6539 # Check if the target kernel has the PREEMPT_RT patch set applied. If 6540 # so, exit, since the RM doesn't support this configuration. 6541 # 6542 VERBOSE=$6 6543 6544 if [ -n "$IGNORE_PREEMPT_RT_PRESENCE" ]; then 6545 exit 0 6546 fi 6547 6548 if test_configuration_option CONFIG_PREEMPT_RT; then 6549 PREEMPT_RT_PRESENT=1 6550 elif test_configuration_option CONFIG_PREEMPT_RT_FULL; then 6551 PREEMPT_RT_PRESENT=1 6552 fi 6553 6554 if [ "$PREEMPT_RT_PRESENT" != "0" ]; then 6555 echo "The kernel you are installing for is a PREEMPT_RT kernel!"; 6556 echo ""; 6557 echo "The NVIDIA driver does not support real-time kernels. If you "; 6558 echo "are using a stock distribution kernel, please install "; 6559 echo "a variant of this kernel that does not have the PREEMPT_RT "; 6560 echo "patch set applied; if this is a custom kernel, please "; 6561 echo "install a standard Linux kernel. Then try installing the "; 6562 echo "NVIDIA kernel module again."; 6563 echo ""; 6564 if [ "$VERBOSE" = "full_output" ]; then 6565 echo "*** Failed PREEMPT_RT sanity check. Bailing out! ***"; 6566 echo ""; 6567 fi 6568 exit 1 6569 else 6570 exit 0 6571 fi 6572 ;; 6573 6574 patch_check) 6575 # 6576 # Check for any "official" patches that may have been applied and 6577 # construct a description table for reporting purposes. 6578 # 6579 PATCHES="" 6580 6581 for PATCH in patch-*.h; do 6582 if [ -f $PATCH ]; then 6583 echo "#include \"$PATCH\"" 6584 PATCHES="$PATCHES "`echo $PATCH | sed -s 's/patch-\(.*\)\.h/\1/'` 6585 fi 6586 done 6587 6588 echo "static struct { 6589 const char *short_description; 6590 const char *description; 6591 } __nv_patches[] = {" 6592 for i in $PATCHES; do 6593 echo "{ \"$i\", NV_PATCH_${i}_DESCRIPTION }," 6594 done 6595 echo "{ NULL, NULL } };" 6596 6597 exit 0 6598 ;; 6599 6600 compile_tests) 6601 # 6602 # Run a series of compile tests to determine the set of interfaces 6603 # and features available in the target kernel. 6604 # 6605 shift 5 6606 6607 CFLAGS=$1 6608 shift 6609 6610 for i in $*; do compile_test $i; done 6611 6612 exit 0 6613 ;; 6614 6615 dom0_sanity_check) 6616 # 6617 # Determine whether running in DOM0. 6618 # 6619 VERBOSE=$6 6620 6621 if [ -n "$VGX_BUILD" ]; then 6622 if [ -f /proc/xen/capabilities ]; then 6623 if [ "`cat /proc/xen/capabilities`" == "control_d" ]; then 6624 exit 0 6625 fi 6626 else 6627 echo "The kernel is not running in DOM0."; 6628 echo ""; 6629 if [ "$VERBOSE" = "full_output" ]; then 6630 echo "*** Failed DOM0 sanity check. Bailing out! ***"; 6631 echo ""; 6632 fi 6633 fi 6634 exit 1 6635 fi 6636 ;; 6637 vgpu_kvm_sanity_check) 6638 # 6639 # Determine whether we are running a vGPU on KVM host. 6640 # 6641 VERBOSE=$6 6642 iommu=CONFIG_VFIO_IOMMU_TYPE1 6643 mdev=CONFIG_VFIO_MDEV 6644 kvm=CONFIG_KVM_VFIO 6645 vfio_pci_core=CONFIG_VFIO_PCI_CORE 6646 VFIO_IOMMU_PRESENT=0 6647 VFIO_MDEV_PRESENT=0 6648 KVM_PRESENT=0 6649 VFIO_PCI_CORE_PRESENT=0 6650 6651 if [ -n "$VGX_KVM_BUILD" ]; then 6652 if (test_configuration_option ${iommu} || test_configuration_option ${iommu}_MODULE); then 6653 VFIO_IOMMU_PRESENT=1 6654 fi 6655 6656 if (test_configuration_option ${mdev} || test_configuration_option ${mdev}_MODULE); then 6657 VFIO_MDEV_PRESENT=1 6658 fi 6659 6660 if (test_configuration_option ${kvm} || test_configuration_option ${kvm}_MODULE); then 6661 KVM_PRESENT=1 6662 fi 6663 6664 if (test_configuration_option ${vfio_pci_core} || test_configuration_option ${vfio_pci_core}_MODULE); then 6665 VFIO_PCI_CORE_PRESENT=1 6666 fi 6667 6668 # When this sanity check is run via nvidia-installer, it sets ARCH as aarch64. 6669 # But, when it is run via Kbuild, ARCH is set as arm64 6670 if [ "$ARCH" = "aarch64" ]; then 6671 ARCH="arm64" 6672 fi 6673 6674 if [ "$VFIO_IOMMU_PRESENT" != "0" ] && [ "$KVM_PRESENT" != "0" ] ; then 6675 6676 # On x86_64, vGPU requires MDEV framework to be present. 6677 # On aarch64, vGPU requires MDEV or vfio-pci-core framework to be present. 6678 if ([ "$ARCH" = "arm64" ] && ([ "$VFIO_MDEV_PRESENT" != "0" ] || [ "$VFIO_PCI_CORE_PRESENT" != "0" ])) || 6679 ([ "$ARCH" = "x86_64" ] && [ "$VFIO_MDEV_PRESENT" != "0" ];) then 6680 exit 0 6681 fi 6682 fi 6683 6684 echo "Below CONFIG options are missing on the kernel for installing"; 6685 echo "NVIDIA vGPU driver on KVM host"; 6686 if [ "$VFIO_IOMMU_PRESENT" = "0" ]; then 6687 echo "CONFIG_VFIO_IOMMU_TYPE1"; 6688 fi 6689 6690 if [ "$ARCH" = "arm64" ] && [ "$VFIO_MDEV_PRESENT" = "0" ] && [ "$VFIO_PCI_CORE_PRESENT" = "0" ]; then 6691 echo "either CONFIG_VFIO_MDEV or CONFIG_VFIO_PCI_CORE"; 6692 fi 6693 6694 if [ "$ARCH" = "x86_64" ] && [ "$VFIO_MDEV_PRESENT" = "0" ]; then 6695 echo "CONFIG_VFIO_MDEV"; 6696 fi 6697 6698 if [ "$KVM_PRESENT" = "0" ]; then 6699 echo "CONFIG_KVM"; 6700 fi 6701 echo "Please install the kernel with above CONFIG options set, then"; 6702 echo "try installing again"; 6703 echo ""; 6704 6705 if [ "$VERBOSE" = "full_output" ]; then 6706 echo "*** Failed vGPU on KVM sanity check. Bailing out! ***"; 6707 echo ""; 6708 fi 6709 exit 1 6710 else 6711 exit 0 6712 fi 6713 ;; 6714 test_configuration_option) 6715 # 6716 # Check to see if the given config option is set. 6717 # 6718 OPTION=$6 6719 6720 test_configuration_option $OPTION 6721 exit $? 6722 ;; 6723 6724 get_configuration_option) 6725 # 6726 # Get the value of the given config option. 6727 # 6728 OPTION=$6 6729 6730 get_configuration_option $OPTION 6731 exit $? 6732 ;; 6733 6734 6735 guess_module_signing_hash) 6736 # 6737 # Determine the best cryptographic hash to use for module signing, 6738 # to the extent that is possible. 6739 # 6740 6741 HASH=$(get_configuration_option CONFIG_MODULE_SIG_HASH) 6742 6743 if [ $? -eq 0 ] && [ -n "$HASH" ]; then 6744 echo $HASH 6745 exit 0 6746 else 6747 for SHA in 512 384 256 224 1; do 6748 if test_configuration_option CONFIG_MODULE_SIG_SHA$SHA; then 6749 echo sha$SHA 6750 exit 0 6751 fi 6752 done 6753 fi 6754 exit 1 6755 ;; 6756 6757 6758 test_kernel_header) 6759 # 6760 # Check for the availability of the given kernel header 6761 # 6762 6763 CFLAGS=$6 6764 6765 test_header_presence "${7}" 6766 6767 exit $? 6768 ;; 6769 6770 6771 build_cflags) 6772 # 6773 # Generate CFLAGS for use in the compile tests 6774 # 6775 6776 build_cflags 6777 echo $CFLAGS 6778 exit 0 6779 ;; 6780 6781 module_symvers_sanity_check) 6782 # 6783 # Check whether Module.symvers exists and contains at least one 6784 # EXPORT_SYMBOL* symbol from vmlinux 6785 # 6786 6787 if [ -n "$IGNORE_MISSING_MODULE_SYMVERS" ]; then 6788 exit 0 6789 fi 6790 6791 TAB=' ' 6792 6793 if [ -f "$OUTPUT/Module.symvers" ] && \ 6794 grep -e "^[^${TAB}]*${TAB}[^${TAB}]*${TAB}\+vmlinux" \ 6795 "$OUTPUT/Module.symvers" >/dev/null 2>&1; then 6796 exit 0 6797 fi 6798 6799 echo "The Module.symvers file is missing, or does not contain any" 6800 echo "symbols exported from the kernel. This could cause the NVIDIA" 6801 echo "kernel modules to be built against a configuration that does" 6802 echo "not accurately reflect the actual target kernel." 6803 echo "The Module.symvers file check can be disabled by setting the" 6804 echo "environment variable IGNORE_MISSING_MODULE_SYMVERS to 1." 6805 6806 exit 1 6807 ;; 6808esac 6809