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