diff --git a/Makefile b/Makefile index 449c7f5854..38e228c9ae 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,19 @@ # To install the build kernel modules: run (as root) `make modules_install` ########################################################################### +# Experimental use of the Linux kernel's kbuild system +USE_KBUILD ?= 0 +export USE_KBUILD + +########################################################################### +# rules +########################################################################### + +.PHONY: all +all: modules + +ifneq ($(USE_KBUILD),1) + ########################################################################### # variables ########################################################################### @@ -16,15 +29,8 @@ nv_kernel_o_binary = kernel-open/nvidia/nv-kernel.o_binary nv_modeset_kernel_o = src/nvidia-modeset/$(OUTPUTDIR)/nv-modeset-kernel.o nv_modeset_kernel_o_binary = kernel-open/nvidia-modeset/nv-modeset-kernel.o_binary -########################################################################### -# rules -########################################################################### - include utils.mk -.PHONY: all -all: modules - ########################################################################### # nv-kernel.o is the OS agnostic portion of nvidia.ko ########################################################################### @@ -48,6 +54,9 @@ $(nv_modeset_kernel_o): $(nv_modeset_kernel_o_binary): $(nv_modeset_kernel_o) cd $(dir $@) && ln -sf ../../$^ $(notdir $@) +# Make the OS agnostic binaries a prerequisite of the modules target +modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary) +endif ########################################################################### # After the OS agnostic portions are built, descend into kernel-open/ and build @@ -55,7 +64,13 @@ $(nv_modeset_kernel_o_binary): $(nv_modeset_kernel_o) ########################################################################### .PHONY: modules -modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary) +modules: +ifeq ($(USE_KBUILD),1) +# create nv-kernel.o and nv-modeset-kernel.o by building stub modules -- a +# required hack to overcome kbuild limitations regarding the maximum number +# of object files to link into a module. + $(MAKE) -C kernel-open modules NV_PREPARE_ONLY=1 +endif $(MAKE) -C kernel-open modules ########################################################################### @@ -63,7 +78,7 @@ modules: $(nv_kernel_o_binary) $(nv_modeset_kernel_o_binary) ########################################################################### .PHONY: modules_install -modules_install: +modules_install: modules $(MAKE) -C kernel-open modules_install ########################################################################### @@ -75,11 +90,15 @@ clean: nvidia.clean nvidia-modeset.clean kernel-open.clean .PHONY: nvidia.clean nvidia.clean: +ifneq ($(USE_KBUILD),1) $(MAKE) -C src/nvidia clean +endif .PHONY: nvidia-modeset.clean nvidia-modeset.clean: +ifneq ($(USE_KBUILD),1) $(MAKE) -C src/nvidia-modeset clean +endif .PHONY: kernel-open.clean kernel-open.clean: diff --git a/README.md b/README.md index a897392661..7ddc4653c8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,10 @@ DEBUG - Set this to "1" to build the kernel modules as debug. By default, the build compiles without debugging information. This also enables various debug log messages in the kernel modules. +USE_KBUILD - Set this to "1" to build all sources using the linux kernel build + system. This is needed to support features like RANDSTRUCT, kCFI or + grsecurity kernels. + These variables can be set on the make command line. E.g., make modules -j$(nproc) NV_VERBOSE=1 diff --git a/kernel-open/Kbuild b/kernel-open/Kbuild index 60181c7f01..7905c9f136 100644 --- a/kernel-open/Kbuild +++ b/kernel-open/Kbuild @@ -39,9 +39,95 @@ NV_BUILD_TYPE ?= release # ASSIGN_PER_OBJ_CFLAGS = \ $(foreach _cflags_variable, \ - $(notdir $(1)) $(1), \ + $(sort $(notdir $(1)) $(1)), \ $(eval $(addprefix CFLAGS_,$(_cflags_variable)) += $(2))) +# +# As ASSIGN_PER_OBJ_CFLAGS, just for per-object CFLAGS_REMOVE. +# +ASSIGN_PER_OBJ_CFLAGS_REMOVE = \ + $(foreach _cflags_variable, \ + $(sort $(notdir $(1)) $(1)), \ + $(eval $(addprefix CFLAGS_REMOVE_,$(_cflags_variable)) += $(2))) + +# +# As ASSIGN_PER_OBJ_CFLAGS, just for per-object LDFLAGS. +# +ASSIGN_PER_OBJ_LDFLAGS = \ + $(foreach _ldflags_variable, \ + $(sort $(notdir $(1)) $(1)), \ + $(eval $(addprefix LDFLAGS_,$(_ldflags_variable)) += $(2))) + +# +# As ASSIGN_PER_OBJ_CFLAGS, just for per-object OBJCOPYFLAGS. +# +ASSIGN_PER_OBJ_OBJCOPYFLAGS = \ + $(foreach _objcopyflags_variable, \ + $(sort $(notdir $(1)) $(1)i), \ + $(eval $(addprefix OBJCOPYFLAGS_,$(_objcopyflags_variable)) += $(2))) + + +# +# Define rule for generating a source file containing identification information +# for the build. +# +# $(1) string name +# $(2) module name +# $(3) prerequisite object files +############################################################################## + +NV_BUILD_USER ?= $(shell whoami) +NV_BUILD_HOST ?= $(shell hostname) + +ifndef TARGET_OS + TARGET_OS := $(shell uname) +endif + +ifndef TARGET_ARCH + ifneq ($(TARGET_OS),SunOS) + TARGET_ARCH := $(shell uname -m) + else + TARGET_ARCH := $(shell isainfo -n) + endif + TARGET_ARCH := $(subst i386,x86,$(TARGET_ARCH)) + TARGET_ARCH := $(subst i486,x86,$(TARGET_ARCH)) + TARGET_ARCH := $(subst i586,x86,$(TARGET_ARCH)) + TARGET_ARCH := $(subst i686,x86,$(TARGET_ARCH)) + TARGET_ARCH := $(subst amd64,x86_64,$(TARGET_ARCH)) +endif + +DATE ?= date + +NVIDSTRING ?= g_nvid_string.c + +ifeq ($(NV_BUILD_TYPE),debug) + NVIDSTRING_BUILD_TYPE_STRING = Debug Build +else ifeq ($(NV_BUILD_TYPE),develop) + NVIDSTRING_BUILD_TYPE_STRING = Develop Build +else ifeq ($(NV_BUILD_TYPE),release) + NVIDSTRING_BUILD_TYPE_STRING = Release Build +else + NVIDSTRING_BUILD_TYPE_STRING = Custom '$(NV_BUILD_TYPE)' Build +endif + +# NV_VERSION_STRING is set as preprocessor define +NVIDIA_NVID_VERSION := \"NV_VERSION_STRING\" + +define GENERATE_NVIDSTRING + $(1)_BUILD_NVID := NVIDIA $$(strip $(2)) for $$(TARGET_ARCH) $$(NVIDIA_NVID_VERSION) + $(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) $$(NVIDSTRING_BUILD_TYPE_STRING) + ifneq ($$(NVIDIA_NVID_EXTRA),) + $(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) $$(NVIDIA_NVID_EXTRA) + endif + $(1)_BUILD_NVID := $$($$(strip $(1))_BUILD_NVID) ($$(NV_BUILD_USER)@$$(NV_BUILD_HOST)) + # g_nvid_string.c depends on all objects except g_nvid_string.o, and version.mk + # $(NVIDSTRING) evaluated early, to allow reusing it + $$(obj)/$(NVIDSTRING): $$(adprefix $$(obj)/,$$(filter-out $(NVIDSTRING:.c=.o), $(3))) $$(VERSION_MK) + @mkdir -p $$(dir $$@) + @echo "const char $(1)[] = \"nvidia id: $$($$(strip $(1))_BUILD_NVID) `$$(DATE)`\";" > $$@ + @echo "const char *const p$$(strip $(1)) = $(1) + 11;" >> $$@; +endef + # # Include the specifics of the individual NVIDIA kernel modules. @@ -70,13 +156,39 @@ endif quiet_cmd_symlink = SYMLINK $@ cmd_symlink = ln -sf $(abspath $<) $@ +# +# Command to neuter .modinfo section for stub modules which are our hacky +# attempt to make kbuild support nested compound objects. +# +# Intended usage: +# +# # stub module +# obj-m += nv-kernel.stub.o +# nv-kernel.stub-y := ... +# +# # real module wanting to make use of nv-kernel.o +# obj-m += ndidia.o +# nvidia-y += nv-kernel.clean.o ... +# -$(foreach _module, $(NV_KERNEL_MODULES), \ - $(eval include $(src)/$(_module)/$(_module).Kbuild)) +MOD_STUB := common/mod_stub.o +# not really needed, but to have conftest be the very first +NV_OBJECTS_DEPEND_ON_CONFTEST += $(MOD_STUB) +$(obj)/%.clean.o: OBJCOPYFLAGS += --rename-section .modinfo=.discard.modinfo +$(obj)/%.clean.o: $(obj)/%.stub.o FORCE + $(call if_changed,objcopy) + +# early flags, which may be filtered for USE_KBUILD=1 builds ccflags-y += -I$(src)/common/inc ccflags-y += -I$(src) + + +$(foreach _module, $(NV_KERNEL_MODULES), \ + $(eval include $(src)/$(_module)/$(_module).Kbuild)) + + ccflags-y += -Wall $(DEFINES) $(INCLUDES) -Wno-cast-qual -Wno-format-extra-args ccflags-y += -D__KERNEL__ -DMODULE -DNVRM ccflags-y += -DNV_VERSION_STRING=\"590.48.01\" diff --git a/kernel-open/Makefile b/kernel-open/Makefile index f7a8db69fb..c189f56136 100644 --- a/kernel-open/Makefile +++ b/kernel-open/Makefile @@ -64,12 +64,25 @@ else from CONFIG_CC_VERSION_TEXT in the kernel configuration.) else CC=$(cc_version_text) + CXX=$(subst cc,++,$(cc_version_text)) endif endif endif + ifneq ($(USE_KBUILD),1) + # RANDSTRUCT is incompatible with how we build the OS-agnostic part, leading + # to calling the wrong callback functions from pure *ops structures at + # runtime. + ranstruct_enabled=$(firstword $(shell . $(KERNEL_OUTPUT)/.config; \ + echo "$$CONFIG_RANDSTRUCT$$CONFIG_GCC_PLUGIN_RANDSTRUCT")) + ifneq ($(ranstruct_enabled),) + $(error RANDSTRUCT enabled kernel is incompatible with binary objects!)) + endif + endif + CC ?= cc LD ?= ld + CXX ?= c++ OBJDUMP ?= objdump AWK ?= awk # Bake the following awk program in a string. The program is needed to add C++ @@ -132,10 +145,18 @@ else KBUILD_PARAMS += NV_KERNEL_MODULES="$(NV_KERNEL_MODULES)" KBUILD_PARAMS += INSTALL_MOD_DIR="$(INSTALL_MOD_DIR)" KBUILD_PARAMS += NV_SPECTRE_V2=$(SPECTRE_V2_RETPOLINE) + ifeq ($(USE_KBUILD),1) + KBUILD_PARAMS += NV_PREPARE_ONLY=$(NV_PREPARE_ONLY) + ifeq ($(NV_PREPARE_ONLY),1) + KBUILD_PARAMS += KBUILD_MODPOST_NOFINAL=1 + KBUILD_PARAMS += MODPOST=/bin/true + KBUILD_PARAMS += objtool-enabled= + endif + endif .PHONY: modules module clean clean_conftest modules_install modules clean modules_install: - @$(MAKE) "LD=$(LD)" "CC=$(CC)" "OBJDUMP=$(OBJDUMP)" \ + @$(MAKE) "LD=$(LD)" "CC=$(CC)" "CXX=$(CXX)" "OBJDUMP=$(OBJDUMP)" \ $(PAHOLE_VARIABLES) $(KBUILD_PARAMS) $@ @if [ "$@" = "modules" ]; then \ for module in $(NV_KERNEL_MODULES); do \ diff --git a/kernel-open/common/mod_stub.c b/kernel-open/common/mod_stub.c new file mode 100644 index 0000000000..f3584c9520 --- /dev/null +++ b/kernel-open/common/mod_stub.c @@ -0,0 +1,4 @@ +/* Stub module fragment for emulated nested compound object kbuild support */ +#include + +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/kernel-open/conftest.sh b/kernel-open/conftest.sh index 59f3624d12..a515909db2 100755 --- a/kernel-open/conftest.sh +++ b/kernel-open/conftest.sh @@ -4919,6 +4919,38 @@ compile_test() { compile_check_conftest "$CODE" "NV_DRM_DRIVER_HAS_DATE" "" "types" ;; + drm_connector_helper_funcs_mode_valid_has_int_ret_type) + # + # Determine if the return type is 'int' for + # drm_connector_helper_funcs::mode_valid. + # + # It was changed to 'enum drm_mode_status' by commit 0993f1d0d8a1 + # ("drm: Make the connector mode_valid() vfunc return a + # drm_mode_status enum") in v3.14. + # + CODE=" + #include + + #ifndef __same_type + #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) + #endif + + /* BUILD_BUG_ON() from isn't working */ + #define CONF_BUILD_BUG_ON(cond) \ + char conf_bug_on_trigger[0 - !!(cond)] + + /* We exploit the fact, that 'int' and 'enum' are compatible but + * 'enum e1' and 'enum e2' are not to cause a build error if the + * return type of drm_connector_helper_funcs::mode_valid is an enum. + */ + enum conftest_enum { CONFTEST = -1 } conftest_enum; + const struct drm_connector_helper_funcs conftest_func; + CONF_BUILD_BUG_ON(!__same_type(conftest_func.mode_valid(NULL, NULL), conftest_enum)); + " + + compile_check_conftest "$CODE" "NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_INT_RET_TYPE" "" "types" + ;; + drm_connector_helper_funcs_mode_valid_has_const_mode_arg) # # Determine if the 'mode' pointer argument is const in @@ -4932,8 +4964,9 @@ compile_test() { CODE=" #include - static int conftest_drm_connector_mode_valid(struct drm_connector *connector, - const struct drm_display_mode *mode) { + static enum drm_mode_status + conftest_drm_connector_mode_valid(struct drm_connector *connector, + const struct drm_display_mode *mode) { return 0; } diff --git a/kernel-open/nvidia-drm/nvidia-drm-connector.c b/kernel-open/nvidia-drm/nvidia-drm-connector.c index fee5b91092..bb718c67bf 100644 --- a/kernel-open/nvidia-drm/nvidia-drm-connector.c +++ b/kernel-open/nvidia-drm/nvidia-drm-connector.c @@ -310,11 +310,16 @@ static int nv_drm_connector_get_modes(struct drm_connector *connector) return count; } -static int nv_drm_connector_mode_valid(struct drm_connector *connector, +#ifdef NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_INT_RET_TYPE +static int +#else +static enum drm_mode_status +#endif +nv_drm_connector_mode_valid(struct drm_connector *connector, #if defined(NV_DRM_CONNECTOR_HELPER_FUNCS_MODE_VALID_HAS_CONST_MODE_ARG) - const struct drm_display_mode *mode) + const struct drm_display_mode *mode) #else - struct drm_display_mode *mode) + struct drm_display_mode *mode) #endif { struct drm_device *dev = connector->dev; diff --git a/kernel-open/nvidia-drm/nvidia-drm-sources.mk b/kernel-open/nvidia-drm/nvidia-drm-sources.mk index a2c3a3862c..6bdc535cb8 100644 --- a/kernel-open/nvidia-drm/nvidia-drm-sources.mk +++ b/kernel-open/nvidia-drm/nvidia-drm-sources.mk @@ -107,5 +107,6 @@ NV_CONFTEST_TYPE_COMPILE_TESTS += drm_format_info_has_is_yuv NV_CONFTEST_TYPE_COMPILE_TESTS += drm_driver_has_gem_prime_mmap NV_CONFTEST_TYPE_COMPILE_TESTS += drm_output_poll_changed NV_CONFTEST_TYPE_COMPILE_TESTS += drm_driver_has_date +NV_CONFTEST_TYPE_COMPILE_TESTS += drm_connector_helper_funcs_mode_valid_has_int_ret_type NV_CONFTEST_TYPE_COMPILE_TESTS += drm_connector_helper_funcs_mode_valid_has_const_mode_arg NV_CONFTEST_TYPE_COMPILE_TESTS += drm_fb_create_takes_format_info diff --git a/kernel-open/nvidia-drm/nvidia-drm.Kbuild b/kernel-open/nvidia-drm/nvidia-drm.Kbuild index 892fa4dab5..9998773fde 100644 --- a/kernel-open/nvidia-drm/nvidia-drm.Kbuild +++ b/kernel-open/nvidia-drm/nvidia-drm.Kbuild @@ -14,8 +14,10 @@ NVIDIA_DRM_SOURCES += nvidia-drm/nvidia-drm-linux.c NVIDIA_DRM_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_DRM_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-drm.o nvidia-drm-y := $(NVIDIA_DRM_OBJECTS) +endif NVIDIA_DRM_KO = nvidia-drm/nvidia-drm.ko diff --git a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild index 15694fe5d3..43b88fd67b 100644 --- a/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild +++ b/kernel-open/nvidia-modeset/nvidia-modeset.Kbuild @@ -11,8 +11,21 @@ NVIDIA_MODESET_SOURCES += nvidia-modeset/nv-kthread-q.c NVIDIA_MODESET_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_MODESET_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-modeset.o nvidia-modeset-y := $(NVIDIA_MODESET_OBJECTS) +endif + +ifeq ($(USE_KBUILD),1) +# build nv-modeset-kernel.o using Linux's kbuild system +nvidia_modeset_src := ../src/nvidia-modeset +include $(src)/$(nvidia_modeset_src)/nvidia-modeset.Kbuild + +nvidia-modeset-y += $(NV_MODESET_KERNEL_O) + +NV_OBJECTS_DEPEND_ON_CONFTEST += $(NV_MODESET_KERNEL_O_OBJS) + +else # !USE_KBUILD NVIDIA_MODESET_KO = nvidia-modeset/nvidia-modeset.ko @@ -46,6 +59,7 @@ $(obj)/$(NVIDIA_MODESET_BINARY_OBJECT_O): $(NVIDIA_MODESET_BINARY_OBJECT) FORCE $(call if_changed,symlink) nvidia-modeset-y += $(NVIDIA_MODESET_BINARY_OBJECT_O) +endif # @@ -82,8 +96,10 @@ NVIDIA_MODESET_INTERFACE := nvidia-modeset/nv-modeset-interface.o # before v5.6 looks at "always"; kernel versions between v5.12 and v5.6 # look at both. +ifneq ($(NV_PREPARE_ONLY),1) always += $(NVIDIA_MODESET_INTERFACE) always-y += $(NVIDIA_MODESET_INTERFACE) +endif $(obj)/$(NVIDIA_MODESET_INTERFACE): $(addprefix $(obj)/,$(NVIDIA_MODESET_OBJECTS)) $(LD) -r -o $@ $^ diff --git a/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild b/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild index d2bcaf8d04..c52a74ed18 100644 --- a/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild +++ b/kernel-open/nvidia-peermem/nvidia-peermem.Kbuild @@ -11,8 +11,10 @@ NVIDIA_PEERMEM_SOURCES += nvidia-peermem/nvidia-peermem.c NVIDIA_PEERMEM_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_PEERMEM_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-peermem.o nvidia-peermem-y := $(NVIDIA_PEERMEM_OBJECTS) +endif NVIDIA_PEERMEM_KO = nvidia-peermem/nvidia-peermem.ko diff --git a/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild b/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild index c33f5c2f47..6df0d381c7 100644 --- a/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild +++ b/kernel-open/nvidia-uvm/nvidia-uvm.Kbuild @@ -13,8 +13,10 @@ NVIDIA_UVM_OBJECTS = include $(src)/nvidia-uvm/nvidia-uvm-sources.Kbuild NVIDIA_UVM_OBJECTS += $(patsubst %.c,%.o,$(NVIDIA_UVM_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia-uvm.o nvidia-uvm-y := $(NVIDIA_UVM_OBJECTS) +endif NVIDIA_UVM_KO = nvidia-uvm/nvidia-uvm.ko diff --git a/kernel-open/nvidia-uvm/uvm_global.c b/kernel-open/nvidia-uvm/uvm_global.c index 9137658092..e346d7738a 100644 --- a/kernel-open/nvidia-uvm/uvm_global.c +++ b/kernel-open/nvidia-uvm/uvm_global.c @@ -42,19 +42,19 @@ #include "nv_uvm_interface.h" uvm_global_t g_uvm_global; -static struct UvmEventsLinux g_exported_uvm_events; +static struct UvmEventsLinux g_exported_uvm_events = { + .isrTopHalf = uvm_isr_top_half_entry, + .suspend = uvm_suspend_entry, + .resume = uvm_resume_entry, + .drainP2P = uvm_suspend_and_drainP2P_entry, + .resumeP2P = uvm_resumeP2P_entry, +}; static bool g_ops_registered = false; static NV_STATUS uvm_register_callbacks(void) { NV_STATUS status = NV_OK; - g_exported_uvm_events.isrTopHalf = uvm_isr_top_half_entry; - g_exported_uvm_events.suspend = uvm_suspend_entry; - g_exported_uvm_events.resume = uvm_resume_entry; - g_exported_uvm_events.drainP2P = uvm_suspend_and_drainP2P_entry; - g_exported_uvm_events.resumeP2P = uvm_resumeP2P_entry; - // Register the UVM callbacks with the main GPU driver: status = uvm_rm_locked_call(nvUvmInterfaceRegisterUvmEvents(&g_exported_uvm_events)); if (status != NV_OK) diff --git a/kernel-open/nvidia/linux_nvswitch.c b/kernel-open/nvidia/linux_nvswitch.c index 015de1ca66..be2e0be700 100644 --- a/kernel-open/nvidia/linux_nvswitch.c +++ b/kernel-open/nvidia/linux_nvswitch.c @@ -259,7 +259,7 @@ struct file_operations ctl_fops = static int nvswitch_initialize_device_interrupt(NVSWITCH_DEV *nvswitch_dev); static void nvswitch_shutdown_device_interrupt(NVSWITCH_DEV *nvswitch_dev); static void nvswitch_load_bar_info(NVSWITCH_DEV *nvswitch_dev); -static void nvswitch_task_dispatch(NVSWITCH_DEV *nvswitch_dev); +static void nvswitch_task_dispatch(void *nvswitch_dev); static NvBool nvswitch_is_device_blacklisted @@ -313,7 +313,7 @@ nvswitch_init_background_tasks NV_ATOMIC_SET(nvswitch_dev->task_q_ready, 1); nv_kthread_q_item_init(&nvswitch_dev->task_item, - (nv_q_func_t) &nvswitch_task_dispatch, + &nvswitch_task_dispatch, nvswitch_dev); if (!nv_kthread_q_schedule_q_item(&nvswitch_dev->task_q, @@ -1208,9 +1208,10 @@ nvswitch_isr_thread static void nvswitch_task_dispatch ( - NVSWITCH_DEV *nvswitch_dev + void *_nvswitch_dev ) { + NVSWITCH_DEV *nvswitch_dev = _nvswitch_dev; NvU64 nsec; NvU64 timeout; NvS64 rc; diff --git a/kernel-open/nvidia/nvidia.Kbuild b/kernel-open/nvidia/nvidia.Kbuild index a04d6198ba..498d23eba6 100644 --- a/kernel-open/nvidia/nvidia.Kbuild +++ b/kernel-open/nvidia/nvidia.Kbuild @@ -9,8 +9,21 @@ include $(src)/nvidia/nvidia-sources.Kbuild NVIDIA_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_SOURCES)) +ifneq ($(NV_PREPARE_ONLY),1) obj-m += nvidia.o nvidia-y := $(NVIDIA_OBJECTS) +endif + +ifeq ($(USE_KBUILD),1) +# build nv-kernel.o using Linux's kbuild system +nvidia_src := ../src/nvidia +include $(src)/$(nvidia_src)/nvidia.Kbuild + +nvidia-y += $(NV_KERNEL_O) + +NV_OBJECTS_DEPEND_ON_CONFTEST += $(NV_KERNEL_O_OBJS) + +else # !USE_KBUILD NVIDIA_KO = nvidia/nvidia.ko @@ -46,6 +59,7 @@ $(obj)/$(NVIDIA_BINARY_OBJECT_O): $(NVIDIA_BINARY_OBJECT) FORCE $(call if_changed,symlink) nvidia-y += $(NVIDIA_BINARY_OBJECT_O) +endif # @@ -74,12 +88,12 @@ $(call ASSIGN_PER_OBJ_CFLAGS, $(NVIDIA_OBJECTS), $(NVIDIA_CFLAGS)) # nv-procfs.c requires nv-compiler.h # -NV_COMPILER_VERSION_HEADER = $(obj)/nv_compiler.h +NV_COMPILER_VERSION_HEADER = nv_compiler.h -$(NV_COMPILER_VERSION_HEADER): +$(obj)/$(NV_COMPILER_VERSION_HEADER): @echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -n 1`\" > $@ -$(obj)/nvidia/nv-procfs.o: $(NV_COMPILER_VERSION_HEADER) +$(obj)/nvidia/nv-procfs.o: $(obj)/$(NV_COMPILER_VERSION_HEADER) clean-files += $(NV_COMPILER_VERSION_HEADER) @@ -96,8 +110,10 @@ NVIDIA_INTERFACE := nvidia/nv-interface.o # before v5.6 looks at "always"; kernel versions between v5.12 and v5.6 # look at both. +ifneq ($(NV_PREPARE_ONLY),1) always += $(NVIDIA_INTERFACE) always-y += $(NVIDIA_INTERFACE) +endif $(obj)/$(NVIDIA_INTERFACE): $(addprefix $(obj)/,$(NVIDIA_OBJECTS)) $(LD) -r -o $@ $^ diff --git a/src/common/displayport/inc/dp_connectorimpl.h b/src/common/displayport/inc/dp_connectorimpl.h index c46bf265c3..bdc955d9bf 100644 --- a/src/common/displayport/inc/dp_connectorimpl.h +++ b/src/common/displayport/inc/dp_connectorimpl.h @@ -44,6 +44,10 @@ #include "dp_deviceimpl.h" #include "./dptestutil/dp_testmessage.h" +#ifndef DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR + #define DP_OPTION_AUTO_ENABLE_MST_STREAM_ENCR 0 +#endif + // HDCP abort codes #define HDCP_FLAGS_ABORT_DEVICE_REVOKED 0x00000800 // Abort due to a revoked device in DP1.2 topology #define HDCP_FLAGS_ABORT_DEVICE_INVALID 0x00080000 // Abort due to an invalid device in DP1.2 topology diff --git a/src/common/displayport/inc/dp_internal.h b/src/common/displayport/inc/dp_internal.h index 571e90076a..f06390a4f7 100644 --- a/src/common/displayport/inc/dp_internal.h +++ b/src/common/displayport/inc/dp_internal.h @@ -37,7 +37,7 @@ // #include -#include // size_t +#include // size_t #include "dp_object.h" #include "dp_ringbuffer.h" diff --git a/src/common/displayport/inc/dp_object.h b/src/common/displayport/inc/dp_object.h index 9bb02e8052..8da7d6f8d0 100644 --- a/src/common/displayport/inc/dp_object.h +++ b/src/common/displayport/inc/dp_object.h @@ -33,7 +33,7 @@ #define INCLUDED_DP_OBJECT_H #include "nvtypes.h" -#include "stddef.h" +#include "nv-stddef.h" #include "dp_hostimp.h" static inline void dpMemCopy(void * target, const void * source, size_t len) diff --git a/src/common/modeset/hdmipacket/nvhdmipkt.c b/src/common/modeset/hdmipacket/nvhdmipkt.c index 88317d0db1..58ecc58e54 100644 --- a/src/common/modeset/hdmipacket/nvhdmipkt.c +++ b/src/common/modeset/hdmipacket/nvhdmipkt.c @@ -25,7 +25,7 @@ * Purpose: Provide initialization functions for HDMI library */ -#include +#include #include "nvlimits.h" #include "nvhdmipkt_common.h" #include "nvhdmipkt_class.h" diff --git a/src/common/modeset/hdmipacket/nvhdmipkt_C671.c b/src/common/modeset/hdmipacket/nvhdmipkt_C671.c index abdb91f461..88605af4fc 100644 --- a/src/common/modeset/hdmipacket/nvhdmipkt_C671.c +++ b/src/common/modeset/hdmipacket/nvhdmipkt_C671.c @@ -25,7 +25,7 @@ * Purpose: Provides packet write functions for HDMI library for Ampere+ chips */ -#include +#include #include "nvhdmipkt_common.h" #include "nvhdmipkt_class.h" diff --git a/src/common/modeset/timing/nvt_dsc_pps.c b/src/common/modeset/timing/nvt_dsc_pps.c index 3f539ecbeb..883cc81160 100644 --- a/src/common/modeset/timing/nvt_dsc_pps.c +++ b/src/common/modeset/timing/nvt_dsc_pps.c @@ -35,7 +35,7 @@ #include "displayport/displayport.h" #include "displayport/displayport2x.h" #include "nvctassert.h" -#include +#include /* ------------------------ Macros ----------------------------------------- */ diff --git a/src/common/modeset/timing/nvtiming_pvt.h b/src/common/modeset/timing/nvtiming_pvt.h index 1a54d02118..8f9002f83c 100644 --- a/src/common/modeset/timing/nvtiming_pvt.h +++ b/src/common/modeset/timing/nvtiming_pvt.h @@ -49,7 +49,7 @@ #define nvt_assert(p) ((void)0) #endif // DD_UNITTEST -#include // NULL +#include // NULL #ifdef __cplusplus extern "C" { diff --git a/src/common/nvswitch/kernel/lr10/discovery_lr10.c b/src/common/nvswitch/kernel/lr10/discovery_lr10.c index f282ba5903..63f3d26162 100644 --- a/src/common/nvswitch/kernel/lr10/discovery_lr10.c +++ b/src/common/nvswitch/kernel/lr10/discovery_lr10.c @@ -921,37 +921,37 @@ nvswitch_nxbar_handle_data2_lr10 static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_ptop_lr10 = { - &_nvswitch_ptop_parse_entry_lr10, - &_nvswitch_ptop_parse_enum_lr10, - &_nvswitch_ptop_handle_data1_lr10, - &_nvswitch_ptop_handle_data2_lr10 + .parse_entry = _nvswitch_ptop_parse_entry_lr10, + .parse_enum = _nvswitch_ptop_parse_enum_lr10, + .handle_data1 = _nvswitch_ptop_handle_data1_lr10, + .handle_data2 = _nvswitch_ptop_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_npg_lr10 = { - &_nvswitch_npg_parse_entry_lr10, - &_nvswitch_npg_parse_enum_lr10, - &_nvswitch_npg_handle_data1_lr10, - &_nvswitch_npg_handle_data2_lr10 + .parse_entry = _nvswitch_npg_parse_entry_lr10, + .parse_enum = _nvswitch_npg_parse_enum_lr10, + .handle_data1 = _nvswitch_npg_handle_data1_lr10, + .handle_data2 = _nvswitch_npg_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_nvlw_lr10 = { - &nvswitch_nvlw_parse_entry_lr10, - &nvswitch_nvlw_parse_enum_lr10, - &nvswitch_nvlw_handle_data1_lr10, - &nvswitch_nvlw_handle_data2_lr10 + .parse_entry = nvswitch_nvlw_parse_entry_lr10, + .parse_enum = nvswitch_nvlw_parse_enum_lr10, + .handle_data1 = nvswitch_nvlw_handle_data1_lr10, + .handle_data2 = nvswitch_nvlw_handle_data2_lr10 }; static NVSWITCH_DISCOVERY_HANDLERS_LR10 discovery_handlers_nxbar_lr10 = { - &nvswitch_nxbar_parse_entry_lr10, - &nvswitch_nxbar_parse_enum_lr10, - &nvswitch_nxbar_handle_data1_lr10, - &nvswitch_nxbar_handle_data2_lr10 + .parse_entry = nvswitch_nxbar_parse_entry_lr10, + .parse_enum = nvswitch_nxbar_parse_enum_lr10, + .handle_data1 = nvswitch_nxbar_handle_data1_lr10, + .handle_data2 = nvswitch_nxbar_handle_data2_lr10 }; // diff --git a/src/common/nvswitch/kernel/ls10/discovery_ls10.c b/src/common/nvswitch/kernel/ls10/discovery_ls10.c index 01af0303d2..33a7d109b3 100644 --- a/src/common/nvswitch/kernel/ls10/discovery_ls10.c +++ b/src/common/nvswitch/kernel/ls10/discovery_ls10.c @@ -30,7 +30,7 @@ #include "nvswitch/ls10/nxbar_discovery.h" #include "nvswitch/ls10/dev_npg_ip.h" -#include +#include #define VERBOSE_MMIO_DISCOVERY 0 @@ -952,37 +952,37 @@ nvswitch_nxbar_handle_data2_ls10 static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_ptop_ls10 = { - &_nvswitch_ptop_parse_entry_ls10, - &_nvswitch_ptop_parse_enum_ls10, - &_nvswitch_ptop_handle_data1_ls10, - &_nvswitch_ptop_handle_data2_ls10 + .parse_entry = _nvswitch_ptop_parse_entry_ls10, + .parse_enum = _nvswitch_ptop_parse_enum_ls10, + .handle_data1 = _nvswitch_ptop_handle_data1_ls10, + .handle_data2 = _nvswitch_ptop_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_npg_ls10 = { - &_nvswitch_npg_parse_entry_ls10, - &_nvswitch_npg_parse_enum_ls10, - &_nvswitch_npg_handle_data1_ls10, - &_nvswitch_npg_handle_data2_ls10 + .parse_entry = _nvswitch_npg_parse_entry_ls10, + .parse_enum = _nvswitch_npg_parse_enum_ls10, + .handle_data1 = _nvswitch_npg_handle_data1_ls10, + .handle_data2 = _nvswitch_npg_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_nvlw_ls10 = { - &nvswitch_nvlw_parse_entry_ls10, - &nvswitch_nvlw_parse_enum_ls10, - &nvswitch_nvlw_handle_data1_ls10, - &nvswitch_nvlw_handle_data2_ls10 + .parse_entry = nvswitch_nvlw_parse_entry_ls10, + .parse_enum = nvswitch_nvlw_parse_enum_ls10, + .handle_data1 = nvswitch_nvlw_handle_data1_ls10, + .handle_data2 = nvswitch_nvlw_handle_data2_ls10 }; static NVSWITCH_DISCOVERY_HANDLERS_LS10 discovery_handlers_nxbar_ls10 = { - &nvswitch_nxbar_parse_entry_ls10, - &nvswitch_nxbar_parse_enum_ls10, - &nvswitch_nxbar_handle_data1_ls10, - &nvswitch_nxbar_handle_data2_ls10 + .parse_entry = nvswitch_nxbar_parse_entry_ls10, + .parse_enum = nvswitch_nxbar_parse_enum_ls10, + .handle_data1 = nvswitch_nxbar_handle_data1_ls10, + .handle_data2 = nvswitch_nxbar_handle_data2_ls10 }; // diff --git a/src/common/nvswitch/kernel/ls10/tnvl_ls10.c b/src/common/nvswitch/kernel/ls10/tnvl_ls10.c index 92e3f1eff3..ad948105b4 100644 --- a/src/common/nvswitch/kernel/ls10/tnvl_ls10.c +++ b/src/common/nvswitch/kernel/ls10/tnvl_ls10.c @@ -39,7 +39,7 @@ #include "nvswitch/ls10/ptop_discovery_ip.h" #include "nvswitch/ls10/dev_minion_ip.h" -#include +#include /* ------------------------ Macros ----------------------------------------- */ #define TNVL_MAX_CERT_CHAIN_SIZE (0x1000) diff --git a/src/common/sdk/nvidia/inc/nv-stddef.h b/src/common/sdk/nvidia/inc/nv-stddef.h new file mode 100644 index 0000000000..009f40ac77 --- /dev/null +++ b/src/common/sdk/nvidia/inc/nv-stddef.h @@ -0,0 +1,64 @@ +/* + * SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#ifndef _NV_STDDEF_H_ +#define _NV_STDDEF_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(__FreeBSD__) + #include // NULL +#elif defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #ifdef __cplusplus + // Hack to prevent from redefining 'bool' + #define _Bool int + #define bool LINUX_bool + #define true LINUX_true + #define false LINUX_false + #endif + #include // NULL + #include // size_t + #include // SIZE_MAX,... + #ifdef __cplusplus + #undef _Bool + #undef bool + #undef true + #undef false + // XXX: no fallback for pre-C++11 but we enforce it via -std=gnu++11 + #if __cplusplus >= 201103L + #undef NULL + #define NULL nullptr + #endif + #endif +#else + #include // NULL +#endif + +#ifndef __DECLARE_FLEX_ARRAY + #ifdef __cplusplus + #define __DECLARE_FLEX_ARRAY(T, field) T field[0] + #else + #define __DECLARE_FLEX_ARRAY(T, field) T field[] + #endif +#endif + +#endif // _NV_STDDEF_H_ diff --git a/src/common/shared/msgq/msgq.c b/src/common/shared/msgq/msgq.c index 76d9dd3616..86d750bfab 100644 --- a/src/common/shared/msgq/msgq.c +++ b/src/common/shared/msgq/msgq.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/src/common/softfloat/nvidia/stdbool.h b/src/common/softfloat/nvidia/stdbool.h new file mode 100644 index 0000000000..c50698c32c --- /dev/null +++ b/src/common/softfloat/nvidia/stdbool.h @@ -0,0 +1,10 @@ +#ifndef _NV_STDBOOL_H_ +#define _NV_STDBOOL_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #include +#else + #include_next +#endif + +#endif // _NV_STDBOOL_H_ diff --git a/src/common/softfloat/nvidia/stdint.h b/src/common/softfloat/nvidia/stdint.h new file mode 100644 index 0000000000..5dadb5d315 --- /dev/null +++ b/src/common/softfloat/nvidia/stdint.h @@ -0,0 +1,38 @@ +#ifndef _NV_STDINT_H_ +#define _NV_STDINT_H_ + +#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) + #include + + /* Linux lacks the '*fast/least*_t' variants. */ + typedef int8_t int_fast8_t; + typedef uint8_t uint_fast8_t; + + typedef int16_t int_fast16_t; + typedef uint16_t uint_fast16_t; + + typedef int32_t int_fast32_t; + typedef uint32_t uint_fast32_t; + + typedef int64_t int_fast64_t; + typedef uint64_t uint_fast64_t; + + typedef int8_t int_least8_t; + typedef uint8_t uint_least8_t; + + typedef int16_t int_least16_t; + typedef uint16_t uint_least16_t; + + typedef int32_t int_least32_t; + typedef uint32_t uint_least32_t; + + typedef int64_t int_least64_t; + typedef uint64_t uint_least64_t; + + #define INT64_C(x) S64_C(x) + #define UINT64_C(x) U64_C(x) +#else + #include_next +#endif + +#endif // _NV_STDINT_H_ diff --git a/src/common/unix/common/utils/interface/nv_mode_timings_utils.h b/src/common/unix/common/utils/interface/nv_mode_timings_utils.h index 62ef305c0b..6fafaf6679 100644 --- a/src/common/unix/common/utils/interface/nv_mode_timings_utils.h +++ b/src/common/unix/common/utils/interface/nv_mode_timings_utils.h @@ -33,7 +33,7 @@ #include "nv_mode_timings.h" #include "timing/nvtiming.h" -#include /* size_t */ +#include /* size_t */ /* * Macros used for printing values divided by 1000 without floating diff --git a/src/common/unix/common/utils/interface/nv_vasprintf.h b/src/common/unix/common/utils/interface/nv_vasprintf.h index ec94beb514..a8023f899a 100644 --- a/src/common/unix/common/utils/interface/nv_vasprintf.h +++ b/src/common/unix/common/utils/interface/nv_vasprintf.h @@ -28,8 +28,8 @@ extern "C" { #endif -#include -#include +#include +#include /* * nv_vasprintf() depends on nv_vasprintf_{alloc,free,vsnprintf}(). diff --git a/src/common/unix/common/utils/unix_rm_handle.c b/src/common/unix/common/utils/unix_rm_handle.c index b24d0e05e3..bd3b39b58b 100644 --- a/src/common/unix/common/utils/unix_rm_handle.c +++ b/src/common/unix/common/utils/unix_rm_handle.c @@ -37,7 +37,7 @@ * [15:00] Handle constant */ -#include +#include #include "unix_rm_handle.h" diff --git a/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h b/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h index 839a2da591..a64f933692 100644 --- a/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h +++ b/src/common/unix/nvidia-3d/interface/nvidia-3d-imports.h @@ -29,7 +29,7 @@ #ifndef __NVIDIA_3D_IMPORTS_H__ #define __NVIDIA_3D_IMPORTS_H__ -#include /* size_t */ +#include /* size_t */ void *nv3dImportAlloc(size_t size); void nv3dImportFree(void *ptr); diff --git a/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c b/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c index 6e28df2054..d561a7e924 100644 --- a/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c +++ b/src/common/unix/nvidia-3d/src/nvidia-3d-fermi.c @@ -33,6 +33,7 @@ #include #include +#define XZ_INTERNAL_CRC32 1 #include #if NV_PUSH_ALLOW_FLOAT diff --git a/src/common/unix/nvidia-3d/src/nvidia-3d-init.c b/src/common/unix/nvidia-3d/src/nvidia-3d-init.c index a59e54ffa5..dca2f2f802 100644 --- a/src/common/unix/nvidia-3d/src/nvidia-3d-init.c +++ b/src/common/unix/nvidia-3d/src/nvidia-3d-init.c @@ -309,30 +309,30 @@ static NvBool GetSpaVersion( } static const Nv3dHal _nv3dHalTuring = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelTuring, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTexturePascal, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelTuring, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTexturePascal, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; static const Nv3dHal _nv3dHalAmpere = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelTuring, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTexturePascal, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelTuring, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTexturePascal, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; static const Nv3dHal _nv3dHalHopper = { - _nv3dSetSpaVersionKepler, /* setSpaVersion */ - _nv3dInitChannelHopper, /* initChannel */ - _nv3dUploadDataInlineKepler, /* uploadDataInline */ - _nv3dSetProgramOffsetVolta, /* setProgramOffset */ - _nv3dAssignNv3dTextureHopper, /* assignNv3dTexture */ - _nv3dSetVertexStreamEndTuring, /* setVertexStreamEnd */ + .setSpaVersion = _nv3dSetSpaVersionKepler, + .initChannel = _nv3dInitChannelHopper, + .uploadDataInline = _nv3dUploadDataInlineKepler, + .setProgramOffset = _nv3dSetProgramOffsetVolta, + .assignNv3dTexture = _nv3dAssignNv3dTextureHopper, + .setVertexStreamEnd = _nv3dSetVertexStreamEndTuring }; NvBool nv3dAllocDevice( diff --git a/src/common/unix/nvidia-push/interface/nvidia-push-types.h b/src/common/unix/nvidia-push/interface/nvidia-push-types.h index ef0ce15486..7b3b4ad9dc 100644 --- a/src/common/unix/nvidia-push/interface/nvidia-push-types.h +++ b/src/common/unix/nvidia-push/interface/nvidia-push-types.h @@ -29,7 +29,7 @@ #ifndef __NVIDIA_PUSH_TYPES_H__ #define __NVIDIA_PUSH_TYPES_H__ -#include /* size_t */ +#include /* size_t */ diff --git a/src/common/uproc/os/common/include/libos_log.h b/src/common/uproc/os/common/include/libos_log.h index 7e59dd7392..25b4aeb204 100644 --- a/src/common/uproc/os/common/include/libos_log.h +++ b/src/common/uproc/os/common/include/libos_log.h @@ -25,7 +25,7 @@ #define LIBOS_LOGGER_H_ #include "nvtypes.h" -#include +#include "nv_stdarg.h" #include "libos_printf_arg.h" #if defined(NVRM) diff --git a/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c b/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c index 1ba1acda1c..fd0dc32d7a 100644 --- a/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c +++ b/src/common/uproc/os/libos-v3.1.0/lib/libdwarf.c @@ -23,7 +23,7 @@ #ifdef NVRM -# include +# include # include # define printf(fmt, ...) nv_printf(LEVEL_ERROR, fmt, ##__VA_ARGS__) diff --git a/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c b/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c index e5e79cfc49..406f223df0 100644 --- a/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c +++ b/src/common/uproc/os/libos-v3.1.0/lib/liblogdecode.c @@ -27,7 +27,7 @@ #ifdef NVRM # include -# include // size_t +# include // size_t #define LIBOS_LOG_DECODE_PRINTF(level, fmt, ...) portDbgExPrintfLevel(level, fmt, ##__VA_ARGS__) @@ -39,6 +39,7 @@ #include "time.h" #endif +# include # include # include # include @@ -75,8 +76,6 @@ #define LIBOS_LOG_DECODE_PRINTF(level, fmt, ...) printf(fmt, ...) #endif -#include - #include "nvtypes.h" #include "nvstatus.h" #include "liblogdecode.h" diff --git a/src/nvidia-modeset/Makefile b/src/nvidia-modeset/Makefile index b54138cc46..2ad070a1ce 100644 --- a/src/nvidia-modeset/Makefile +++ b/src/nvidia-modeset/Makefile @@ -2,12 +2,17 @@ # Makefile for nv-modeset-kernel.o ########################################################################### +ifeq ($(USE_KBUILD),1) +$(error nv-modeset-kernel.o gets build as part of kernel-open/) +endif + NV_MODULE_LOGGING_NAME ?= nvidia-modeset VERSION_MK_DIR = ../../ include ../../utils.mk include srcs.mk +include defs.mk ############################################################################## # Helper functions to determine the compiler type @@ -21,51 +26,11 @@ GET_COMPILER_TYPE = \ ALL_SRCS = $(SRCS) $(SRCS_CXX) ALL_SRCS += $(NVIDSTRING) -SRC_COMMON = ../common - CONDITIONAL_CFLAGS := -CFLAGS += -include $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h - -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc/hw -CFLAGS += -I $(SRC_COMMON)/shared/inc -CFLAGS += -I $(SRC_COMMON)/inc -CFLAGS += -I $(SRC_COMMON)/softfloat/nvidia -CFLAGS += -I $(SRC_COMMON)/softfloat/source/include -CFLAGS += -I $(SRC_COMMON)/softfloat/source/8086-SSE -CFLAGS += -I $(SRC_COMMON)/unix/common/utils/interface -CFLAGS += -I $(SRC_COMMON)/unix/common/inc -CFLAGS += -I $(SRC_COMMON)/modeset -CFLAGS += -I os-interface/include -CFLAGS += -I kapi/interface -CFLAGS += -I ../nvidia/arch/nvalloc/unix/include -CFLAGS += -I interface -CFLAGS += -I include -CFLAGS += -I kapi/include -CFLAGS += -I generated -CFLAGS += -I $(SRC_COMMON)/displayport/inc -CFLAGS += -I $(SRC_COMMON)/displayport/inc/dptestutil -CFLAGS += -I $(SRC_COMMON)/inc/displayport - -CFLAGS += -DNDEBUG -CFLAGS += -D_LANGUAGE_C -CFLAGS += -D__NO_CTYPE - -CFLAGS += -DNV_CPU_INTRINSICS_KERNEL -CFLAGS += -DNVHDMIPKT_RM_CALLS_INTERNAL=0 -CFLAGS += -DNVHDMIPKT_NVKMS - -# XXX it would be nice to only define these for appropriate files... -CFLAGS += -DSOFTFLOAT_ROUND_ODD -CFLAGS += -DSOFTFLOAT_FAST_DIV32TO16 -CFLAGS += -DSOFTFLOAT_FAST_DIV64TO32 - -# Tell nvtiming to use nvkms import functions -CFLAGS += -DNVT_USE_NVKMS - -# Tell SMG we're being compiled into kernel -CFLAGS += -DNV_SMG_IN_NVKMS +CFLAGS += $(addprefix -include ,$(NV_INCLUDE)) +CFLAGS += $(addprefix -I ,$(NV_INCDIRS)) +CFLAGS += $(NV_DEFINES) CFLAGS += -Wformat CFLAGS += -Wreturn-type @@ -172,19 +137,6 @@ CXX_ONLY_CFLAGS += -fcheck-new SHADER_OBJS = -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-3d/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-push/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-3d/include -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-push/include -CFLAGS += -I $(SRC_COMMON)/unix/xzminidec/interface -CFLAGS += -I $(SRC_COMMON)/unix/nvidia-headsurface -CFLAGS += -I src/shaders - -CFLAGS += -DNV_PUSH_IN_KERNEL -CFLAGS += -DNV_XZ_CUSTOM_MEM_HOOKS -CFLAGS += -DNV_XZ_USE_NVTYPES -CFLAGS += -DXZ_DEC_SINGLE - # Compress the shaders and embed in ELF object files. define COMPRESS_SHADERS $$(OUTPUTDIR)/$(1)_shaders.xz: src/shaders/g_$(1)_shaders @@ -196,11 +148,7 @@ $$(eval $$(call READ_ONLY_OBJECT_FROM_FILE_RULE,$$(OUTPUTDIR)/$(1)_shaders.xz)) SHADER_OBJS += $$(OUTPUTDIR)/$(1)_shaders.xz.o endef -$(eval $(call COMPRESS_SHADERS,turing)) -$(eval $(call COMPRESS_SHADERS,ampere)) -$(eval $(call COMPRESS_SHADERS,hopper)) -$(eval $(call COMPRESS_SHADERS,blackwell)) -$(eval $(call COMPRESS_SHADERS,gb20x)) +$(foreach shader, $(SHADERS), $(eval $(call COMPRESS_SHADERS,$(shader)))) OBJS = $(call BUILD_OBJECT_LIST,$(ALL_SRCS)) OBJS += $(SHADER_OBJS) diff --git a/src/nvidia-modeset/defs.mk b/src/nvidia-modeset/defs.mk new file mode 100644 index 0000000000..a3471756d0 --- /dev/null +++ b/src/nvidia-modeset/defs.mk @@ -0,0 +1,62 @@ +# shared make defines for Makefile and Kbuild + +SRC_COMMON := ../common + +NV_INCLUDE := +NV_INCDIRS := +NV_DEFINES := + +NV_INCLUDE += $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h + +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc/hw +NV_INCDIRS += $(SRC_COMMON)/shared/inc +NV_INCDIRS += $(SRC_COMMON)/inc +NV_INCDIRS += $(SRC_COMMON)/softfloat/nvidia +NV_INCDIRS += $(SRC_COMMON)/softfloat/source/include +NV_INCDIRS += $(SRC_COMMON)/softfloat/source/8086-SSE +NV_INCDIRS += $(SRC_COMMON)/unix/common/utils/interface +NV_INCDIRS += $(SRC_COMMON)/unix/common/inc +NV_INCDIRS += $(SRC_COMMON)/modeset +NV_INCDIRS += os-interface/include +NV_INCDIRS += kapi/interface +NV_INCDIRS += ../nvidia/arch/nvalloc/unix/include +NV_INCDIRS += interface +NV_INCDIRS += include +NV_INCDIRS += kapi/include +NV_INCDIRS += generated +NV_INCDIRS += $(SRC_COMMON)/displayport/inc +NV_INCDIRS += $(SRC_COMMON)/displayport/inc/dptestutil +NV_INCDIRS += $(SRC_COMMON)/inc/displayport + +NV_DEFINES += -DNDEBUG +NV_DEFINES += -D_LANGUAGE_C +NV_DEFINES += -D__NO_CTYPE + +NV_DEFINES += -DNV_CPU_INTRINSICS_KERNEL +NV_DEFINES += -DNVHDMIPKT_RM_CALLS_INTERNAL=0 +NV_DEFINES += -DNVHDMIPKT_NVKMS + +# XXX it would be nice to only define these for appropriate files... +NV_DEFINES += -DSOFTFLOAT_ROUND_ODD +NV_DEFINES += -DSOFTFLOAT_FAST_DIV32TO16 +NV_DEFINES += -DSOFTFLOAT_FAST_DIV64TO32 + +# Tell nvtiming to use nvkms import functions +NV_DEFINES += -DNVT_USE_NVKMS + +# Tell SMG we're being compiled into kernel +NV_DEFINES += -DNV_SMG_IN_NVKMS + +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-3d/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-push/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-3d/include +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-push/include +NV_INCDIRS += $(SRC_COMMON)/unix/xzminidec/interface +NV_INCDIRS += $(SRC_COMMON)/unix/nvidia-headsurface +NV_INCDIRS += src/shaders + +NV_DEFINES += -DNV_PUSH_IN_KERNEL +NV_DEFINES += -DNV_XZ_CUSTOM_MEM_HOOKS +NV_DEFINES += -DNV_XZ_USE_NVTYPES +NV_DEFINES += -DXZ_DEC_SINGLE diff --git a/src/nvidia-modeset/include/nvkms-evo-states.h b/src/nvidia-modeset/include/nvkms-evo-states.h index ab34f2a675..cd9a82632c 100644 --- a/src/nvidia-modeset/include/nvkms-evo-states.h +++ b/src/nvidia-modeset/include/nvkms-evo-states.h @@ -39,25 +39,6 @@ typedef enum NVEvoLockSignal { NV_EVO_LOCK_SIGNAL_STEREO, } NVEvoLockSignal; -typedef enum NVEvoLockAction { - NV_EVO_PROHIBIT_LOCK, - NV_EVO_PROHIBIT_LOCK_DISABLE, - NV_EVO_LOCK_HEADS, - NV_EVO_UNLOCK_HEADS, - NV_EVO_ADD_FRAME_LOCK_SERVER, - NV_EVO_REM_FRAME_LOCK_SERVER, - NV_EVO_ADD_FRAME_LOCK_HOUSE_SYNC, - NV_EVO_REM_FRAME_LOCK_HOUSE_SYNC, - NV_EVO_ADD_FRAME_LOCK_CLIENT, - NV_EVO_REM_FRAME_LOCK_CLIENT, - NV_EVO_ADD_FRAME_LOCK_REF, - NV_EVO_REM_FRAME_LOCK_REF, - NV_EVO_ADD_SLI_SECONDARY, - NV_EVO_ADD_SLI_LAST_SECONDARY, - NV_EVO_ADD_SLI_PRIMARY, - NV_EVO_REM_SLI, -} NVEvoLockAction; - /* nv_evo.c */ NVEvoLockPin nvEvoGetPinForSignal(const NVDispEvoRec *, diff --git a/src/nvidia-modeset/include/nvkms-types.h b/src/nvidia-modeset/include/nvkms-types.h index 1bc0d328f9..3b7f7fbe47 100644 --- a/src/nvidia-modeset/include/nvkms-types.h +++ b/src/nvidia-modeset/include/nvkms-types.h @@ -61,7 +61,7 @@ extern "C" { #include "timing/dpsdp.h" #include "hdmipacket/nvhdmi_frlInterface.h" // HDMI_{SRC,SINK}_CAPS -#include +#include #include "nv_smg.h" @@ -796,6 +796,25 @@ typedef struct { NvU32 surfaceCount; } NVHsStateOneHeadAllDisps; +typedef enum NVEvoLockAction { + NV_EVO_PROHIBIT_LOCK, + NV_EVO_PROHIBIT_LOCK_DISABLE, + NV_EVO_LOCK_HEADS, + NV_EVO_UNLOCK_HEADS, + NV_EVO_ADD_FRAME_LOCK_SERVER, + NV_EVO_REM_FRAME_LOCK_SERVER, + NV_EVO_ADD_FRAME_LOCK_HOUSE_SYNC, + NV_EVO_REM_FRAME_LOCK_HOUSE_SYNC, + NV_EVO_ADD_FRAME_LOCK_CLIENT, + NV_EVO_REM_FRAME_LOCK_CLIENT, + NV_EVO_ADD_FRAME_LOCK_REF, + NV_EVO_REM_FRAME_LOCK_REF, + NV_EVO_ADD_SLI_SECONDARY, + NV_EVO_ADD_SLI_LAST_SECONDARY, + NV_EVO_ADD_SLI_PRIMARY, + NV_EVO_REM_SLI, +} NVEvoLockAction; + /* Subdevice-specific, channel-independent state */ typedef struct _NVEvoSubDevRec { NvU32 subDeviceInstance; @@ -812,7 +831,7 @@ typedef struct _NVEvoSubDevRec { void *cursorPio[NVKMS_MAX_HEADS_PER_DISP]; NvBool (*scanLockState)(NVDispEvoPtr pDispEvo, NVEvoSubDevPtr pEvoSubDev, - NvU32 action, + NVEvoLockAction action, /* NV_INVALID_HEAD-terminated * array of head indices */ const NvU32 *pHeads); diff --git a/src/nvidia-modeset/lib/nvkms-format.c b/src/nvidia-modeset/lib/nvkms-format.c index cb8c8fd1aa..fb50558ff7 100644 --- a/src/nvidia-modeset/lib/nvkms-format.c +++ b/src/nvidia-modeset/lib/nvkms-format.c @@ -25,7 +25,7 @@ #include "nv_common_utils.h" #include "nvctassert.h" -#include +#include #define RGB_ENTRY(_format, _depth, _bytesPerPixel) \ [NvKmsSurfaceMemoryFormat##_format] = { \ diff --git a/src/nvidia-modeset/nv-modeset-kernel.ld b/src/nvidia-modeset/nv-modeset-kernel.ld new file mode 100644 index 0000000000..8305d6d87c --- /dev/null +++ b/src/nvidia-modeset/nv-modeset-kernel.ld @@ -0,0 +1,28 @@ +/* + * nv-modeset-kernel.o linker script + * + * g++ puts inline functions, vtables, template functions, etc, in separate + * ".gnu.linkonce.*" / ".text.*" /... sections even without '-ffunction-sections + * -fdata-sections'. Duplicates will be collapsed at link time via + * '--force-group-allocation'. However, the weird section names will still be + * preserved which just increases module load time. + + * Merge these sections with this little linker script. + * + * C++ symbols/sections get filtered by their common '_Z' prefix, demanded by + * the Itanium ABI. + */ + +SECTIONS { + + .text : { *(.text) *(.text._Z*) *(.gnu.linkonce.t._Z*) } + + .rodata : { *(.rodata) *(.rodata._Z*) *(.gnu.linkonce.r._Z*) } + + .data : { *(.data) *(.data._Z*) } + + .bss : { *(.bss) *(.bss._Z*) } + + /* The rest of the sections ("orphaned sections") will just be copied from + the input to the output */ +} diff --git a/src/nvidia-modeset/nvidia-modeset.Kbuild b/src/nvidia-modeset/nvidia-modeset.Kbuild new file mode 100644 index 0000000000..3e61d1227c --- /dev/null +++ b/src/nvidia-modeset/nvidia-modeset.Kbuild @@ -0,0 +1,161 @@ +########################################################################### +# nvidia-modeset.Kbuild, included by kernel-open/nvidia-modeset/nvidia-modeset.Kbuild +########################################################################### + +nvidia_modeset_src ?= . + +NV_MODESET_KERNEL_O = nv-modeset-kernel.clean.o +NV_MODESET_KERNEL_O_OBJS = $(nv-modeset-kernel-objs) + +include $(src)/$(nvidia_modeset_src)/srcs.mk +include $(src)/$(nvidia_modeset_src)/defs.mk + +# The source files for nv-modeset-kernel.o are all SRCS and SRCS_CXX defined in +# srcs.mk, the NVIDIA ID string and the shaders +SRCS := $(addprefix $(nvidia_modeset_src)/,$(SRCS)) +SRCS_CXX := $(addprefix $(nvidia_modeset_src)/,$(SRCS_CXX)) +NVIDSTRING := $(addprefix $(nvidia_modeset_src)/,g_nvid_string.c) +ALL_SRCS := $(SRCS) $(SRCS_CXX) $(NVIDSTRING) + +# g_${shader}_shaders -> $[shaders}_shaders.xz.o +SHADER_OBJS := \ + $(addprefix $(nvidia_modeset_src)/src/shaders/,\ + $(addsuffix .xz.o,$(addsuffix _shaders,$(SHADERS)))) + +nv-modeset-kernel-objs := $(SRCS:.c=.o) +nv-modeset-kernel-objs += $(SRCS_CXX:.cpp=.o) +nv-modeset-kernel-objs += $(NVIDSTRING:.c=.o) +nv-modeset-kernel-objs += $(SHADER_OBJS) + +# Hack to create a relocatable intermediate object file to avoid '/bin/sh: +# Argument list too long' errors for the real module. +ifeq ($(NV_PREPARE_ONLY),1) +obj-m += nv-modeset-kernel.stub.o +nv-modeset-kernel.stub-y := $(nv-modeset-kernel-objs) $(MOD_STUB) +endif + +# for the 'clean' target +targets += $(nv-modeset-kernel-objs) +# ensure to use "our" NVIDSTRING +$(eval targets += $(NVIDSTRING)) + +# Define how to generate the NVIDIA ID string -- intentionally deviates from +# the OS-agnostic build +$(eval $(call GENERATE_NVIDSTRING, \ + NV_KMS_ID, \ + Linux Open Kernel Mode Setting Driver, $(nv-modeset-kernel-objs))) + +# now compile the final ccflags +nv-modeset-kernel-cflags := $(addprefix -include $(src)/$(nvidia_modeset_src)/,$(NV_INCLUDE)) +nv-modeset-kernel-cflags += $(addprefix -I $(src)/$(nvidia_modeset_src)/,$(NV_INCDIRS)) +nv-modeset-kernel-cflags += $(NV_DEFINES) + +# suppress some warnings +nv-modeset-kernel-cflags += -Wno-format-zero-length +nv-modeset-kernel-cflags += -Wno-implicit-fallthrough + +# Get rid of COMDAT groups when linking nv-modeset-kernel.stub.o to not cause +# objtool-generated cross-section linker errors on sections the linker is about +# to drop. Also merge all related C++-specific sections with the help of a +# linker script to reduce them to a sensible number of to-be-loaded sections. +nv-modeset-kernel-ldflags := --force-group-allocation +nv-modeset-kernel-ldflags += -T $(src)/$(nvidia_modeset_src)/$(LINKER_SCRIPT) + +# XXX: Using -ffunction-sections / -fdata-sections makes no sense without +# XXX: --gc-sections. However, we cannot make use of --gc-sections as that +# XXX: would also drop crucial sections like .alt_instructions or +# XXX: .return_sites. So just disable these. +#nv-modeset-kernel-cflags += -ffunction-sections +#nv-modeset-kernel-cflags += -fdata-sections + +# move early -I... flags to after ours -- what a hack! +ccflags-includes := $(filter -I$(src)%,$(ccflags-y)) +nv-modeset-kernel-cflags += $(patsubst -I%,-I %,$(ccflags-includes)) +nv-modeset-kernel-cflags-remove += $(ccflags-includes) + +$(call ASSIGN_PER_OBJ_CFLAGS_REMOVE, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags-remove)) +$(call ASSIGN_PER_OBJ_CFLAGS, $(nv-modeset-kernel-objs), $(nv-modeset-kernel-cflags)) +$(call ASSIGN_PER_OBJ_LDFLAGS, nv-modeset-kernel.stub.o, $(nv-modeset-kernel-ldflags)) + +$(obj)/nv-modeset-kernel.stub.o: $(obj)/$(nvidia_modeset_src)/$(LINKER_SCRIPT) + +nv-modeset-kernel-cxxflags := -std=gnu++11 +nv-modeset-kernel-cxxflags += -fno-operator-names +nv-modeset-kernel-cxxflags += -fno-rtti +nv-modeset-kernel-cxxflags += -fno-exceptions +nv-modeset-kernel-cxxflags += -fcheck-new + +# ... referenced in section `__mcount_loc' of ...: defined in discarded section ... :/ +nv-modeset-kernel-cxxflags += -mno-record-mcount + +# --- 8< --- taken from scripts/Makefile.lib, adapted for C++ +# + +# strip C-only options from c_flags +cxx_cflags_filter := -W%implicit +cxx_cflags_filter += -W%implicit-int +cxx_cflags_filter += -W%implicit-function-declaration +cxx_cflags_filter += -W%strict-prototypes +cxx_cflags_filter += -W%missing-prototypes +cxx_cflags_filter += -W%pointer-sign +cxx_cflags_filter += -W%incompatible-pointer-types +cxx_cflags_filter += -W%designated-init +cxx_cflags_filter += -W%override-init +cxx_cflags_filter += -std=gnu11 + +CXX_FLAGS := $(nv-modeset-kernel-cxxflags) + +cxx_flags = $(filter-out $(cxx_cflags_filter),$(c_flags)) $(CXX_FLAGS) +quiet_cmd_cc_o_cxx = CXX $(quiet_modtag) $@ + cmd_cc_o_cxx = $(CXX) $(cxx_flags) -c -o $@ $< \ + $(cmd_ld_single) #\ + $(cmd_objtool) # disabled for now, as .return_sites / .call_sites reference to-be-discarded symbols + +define rule_cc_o_cxx + $(call cmd_and_fixdep,cc_o_cxx) + $(call cmd,checksrc) + $(call cmd,checkdoc) + $(call cmd,gen_objtooldep) + $(call cmd,gen_symversions_c)$(eval # genksyms can only parse C code!) + $(call cmd,record_mcount) + $(call cmd,warn_shared_object) +endef + +$(obj)/%.o: $(obj)/%.cpp $(recordmcount_source) FORCE + $(call if_changed_rule,cc_o_cxx) + $(call cmd,force_checksrc) +# +# --- >8 --- + +# shader rules +# +ld_o_xz-ldflags = -r -z noexecstack --format=binary +ld_o_xz-objcopy = --rename-section .data=.rodata,contents,alloc,load,data,readonly + +# changing into the directory of the .xz is needed to get sane names for the +# _binary_..._start/_end/_size symbols +quiet_cmd_ld_o_xz = LD XZO $@ + cmd_ld_o_xz = (cd $(dir $<) && $(LD) $(ld_o_xz-ldflags) $(notdir $<) -o $@.tmp) && $(OBJCOPY) $(ld_o_xz-objcopy) $@.tmp $@ && rm -f $@.tmp + +$(obj)/%.xz.o: $(obj)/%.xz FORCE + $(call if_changed,ld_o_xz) + +quiet_cmd_shader_xz = XZRAW $@ + cmd_shader_xz = cat $< | $(XZ) -ce -C none > $@ + +# This one is needed because we want to change the basename of the file and '%' +# would match the full path, including directories,prefixing the 'g_' at the +# wrong spot. +define mk_shader_rules +$$(obj)/$(1).xz: $$(obj)/$(dir $(1))/g_$(notdir $(1)) FORCE + $$(call if_changed,shader_xz) + +# for 'make clean' +targets += $(1).xz + +# not really needed, but to have conftest be the very first +NV_OBJECTS_DEPEND_ON_CONFTEST += $(1).xz +endef + +$(foreach shader, $(SHADER_OBJS:.xz.o=), $(eval $(call mk_shader_rules,$(shader)))) + diff --git a/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h b/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h index d4d656e766..e97754a8e0 100644 --- a/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h +++ b/src/nvidia-modeset/os-interface/include/nvidia-modeset-os-interface.h @@ -29,11 +29,7 @@ #if !defined(_NVIDIA_MODESET_OS_INTERFACE_H_) #define _NVIDIA_MODESET_OS_INTERFACE_H_ -#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) -#include /* size_t */ -#else -#include /* size_t */ -#endif +#include /* size_t */ #include "nvtypes.h" /* NvU8 */ #include "nvkms.h" diff --git a/src/nvidia-modeset/os-interface/include/nvkms.h b/src/nvidia-modeset/os-interface/include/nvkms.h index d350ef7564..55c8abd647 100644 --- a/src/nvidia-modeset/os-interface/include/nvkms.h +++ b/src/nvidia-modeset/os-interface/include/nvkms.h @@ -25,11 +25,7 @@ #define __NV_KMS_H__ #include "nvtypes.h" -#if defined(NV_KERNEL_INTERFACE_LAYER) && defined(NV_LINUX) -#include /* size_t */ -#else -#include /* size_t */ -#endif +#include /* size_t, NULL */ #include "nvkms-kapi.h" diff --git a/src/nvidia-modeset/src/dp/nvdp-host.cpp b/src/nvidia-modeset/src/dp/nvdp-host.cpp index eb1128b065..18c7019fd2 100644 --- a/src/nvidia-modeset/src/dp/nvdp-host.cpp +++ b/src/nvidia-modeset/src/dp/nvdp-host.cpp @@ -23,7 +23,7 @@ /* DisplayPort management routines */ -#include +#include #include "nvkms-utils.h" diff --git a/src/nvidia-modeset/src/nvkms-dma.c b/src/nvidia-modeset/src/nvkms-dma.c index a6c0b57b62..b8b3743e72 100644 --- a/src/nvidia-modeset/src/nvkms-dma.c +++ b/src/nvidia-modeset/src/nvkms-dma.c @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include +#include #include "nvkms-dma.h" #include "nvkms-utils.h" diff --git a/src/nvidia-modeset/src/nvkms-push.c b/src/nvidia-modeset/src/nvkms-push.c index 4b6094ac39..81bd96d184 100644 --- a/src/nvidia-modeset/src/nvkms-push.c +++ b/src/nvidia-modeset/src/nvkms-push.c @@ -233,24 +233,24 @@ static void NvPushImportLogNvDiss( #endif /* DEBUG */ static const NvPushImports NvKmsNvPushImports = { - NvPushImportRmApiControl, /* rmApiControl */ - NvPushImportRmApiAlloc, /* rmApiAlloc */ - NvPushImportRmApiFree, /* rmApiFree */ - NvPushImportRmApiMapMemoryDma, /* rmApiMapMemoryDma */ - NvPushImportRmApiUnmapMemoryDma, /* rmApiUnmapMemoryDma */ - NvPushImportRmApiAllocMemory64, /* rmApiAllocMemory64 */ - NvPushImportRmApiVidHeapControl, /* rmApiVidHeapControl */ - NvPushImportRmApiMapMemory, /* rmApiMapMemory */ - NvPushImportRmApiUnmapMemory, /* rmApiUnmapMemory */ - NvPushImportGetMilliSeconds, /* getMilliSeconds */ - NvPushImportYield, /* yield */ - NvPushImportWaitForEvent, /* waitForEvent */ - NvPushImportEmptyEventFifo, /* emptyEventFifo */ - NvPushImportChannelErrorOccurred, /* channelErrorOccurred */ - NvPushImportPushbufferWrapped, /* pushbufferWrapped */ - NvPushImportLogError, /* logError */ + .rmApiControl = NvPushImportRmApiControl, + .rmApiAlloc = NvPushImportRmApiAlloc, + .rmApiFree = NvPushImportRmApiFree, + .rmApiMapMemoryDma = NvPushImportRmApiMapMemoryDma, + .rmApiUnmapMemoryDma = NvPushImportRmApiUnmapMemoryDma, + .rmApiAllocMemory64 = NvPushImportRmApiAllocMemory64, + .rmApiVidHeapControl = NvPushImportRmApiVidHeapControl, + .rmApiMapMemory = NvPushImportRmApiMapMemory, + .rmApiUnmapMemory = NvPushImportRmApiUnmapMemory, + .getMilliSeconds = NvPushImportGetMilliSeconds, + .yield = NvPushImportYield, + .waitForEvent = NvPushImportWaitForEvent, + .emptyEventFifo = NvPushImportEmptyEventFifo, + .channelErrorOccurred = NvPushImportChannelErrorOccurred, + .pushbufferWrapped = NvPushImportPushbufferWrapped, + .logError = NvPushImportLogError, #if defined(DEBUG) - NvPushImportLogNvDiss, /* logNvDiss */ + .logNvDiss = NvPushImportLogNvDiss, #endif }; diff --git a/src/nvidia-modeset/srcs.mk b/src/nvidia-modeset/srcs.mk index bda977fbc4..f44f8edb0c 100644 --- a/src/nvidia-modeset/srcs.mk +++ b/src/nvidia-modeset/srcs.mk @@ -1,5 +1,5 @@ -SRCS ?= -SRCS_CXX ?= +SRCS := +SRCS_CXX := SRCS += ../common/shared/nvstatus/nvstatus.c SRCS += ../common/softfloat/source/8086-SSE/s_commonNaNToF16UI.c @@ -227,3 +227,12 @@ SRCS += ../common/unix/xzminidec/src/xz_crc32.c SRCS += ../common/unix/xzminidec/src/xz_dec_bcj.c SRCS += ../common/unix/xzminidec/src/xz_dec_lzma2.c SRCS += ../common/unix/xzminidec/src/xz_dec_stream.c + +# shaders +SHADERS += turing +SHADERS += ampere +SHADERS += hopper +SHADERS += blackwell +SHADERS += gb20x + +LINKER_SCRIPT := nv-modeset-kernel.ld diff --git a/src/nvidia/Makefile b/src/nvidia/Makefile index d1d6d86632..1a005d1b15 100644 --- a/src/nvidia/Makefile +++ b/src/nvidia/Makefile @@ -2,6 +2,10 @@ # Makefile for nv-kernel.o ########################################################################### +ifeq ($(USE_KBUILD),1) +$(error nv-kernel.o gets build as part of kernel-open/) +endif + NV_MODULE_LOGGING_NAME ?= nvidia VERSION_MK_DIR = ../../ @@ -9,6 +13,7 @@ VERSION_MK_DIR = ../../ include ../../utils.mk include srcs.mk +include defs.mk ############################################################################## # Helper functions to determine the compiler type @@ -22,54 +27,17 @@ GET_COMPILER_TYPE = \ ALL_SRCS = $(SRCS) $(SRCS_CXX) ALL_SRCS += $(NVIDSTRING) -SRC_COMMON = ../common CONDITIONAL_CFLAGS := -CFLAGS += -include $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h - -CFLAGS += -I kernel/inc -CFLAGS += -I interface -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc -CFLAGS += -I $(SRC_COMMON)/sdk/nvidia/inc/hw -CFLAGS += -I arch/nvalloc/common/inc -CFLAGS += -I arch/nvalloc/common/inc/gsp -CFLAGS += -I arch/nvalloc/common/inc/deprecated -CFLAGS += -I arch/nvalloc/unix/include -CFLAGS += -I inc -CFLAGS += -I inc/os -CFLAGS += -I $(SRC_COMMON)/shared/inc -CFLAGS += -I $(SRC_COMMON)/shared/msgq/inc -CFLAGS += -I $(SRC_COMMON)/inc - -CFLAGS += -I $(SRC_COMMON)/uproc/os/libos-v2.0.0/include -CFLAGS += -I $(SRC_COMMON)/uproc/os/common/include -CFLAGS += -I $(SRC_COMMON)/inc/swref -CFLAGS += -I $(SRC_COMMON)/inc/swref/published - -CFLAGS += -I generated -CFLAGS += -I $(SRC_COMMON)/nvswitch/kernel/inc -CFLAGS += -I $(SRC_COMMON)/nvswitch/interface -CFLAGS += -I $(SRC_COMMON)/nvswitch/common/inc/ -CFLAGS += -I $(SRC_COMMON)/inc/displayport -CFLAGS += -I $(SRC_COMMON)/nvlink/interface/ -CFLAGS += -I $(SRC_COMMON)/nvlink/inband/interface -CFLAGS += -I src/mm/uvm/interface -CFLAGS += -I inc/libraries -CFLAGS += -I src/libraries -CFLAGS += -I inc/kernel +CFLAGS += $(addprefix -include ,$(NV_INCLUDE)) +CFLAGS += $(addprefix -I ,$(NV_INCDIRS)) +CFLAGS += $(NV_DEFINES) # Libspdm source requires additional include paths and build flags. include src/libraries/libspdm/nvidia/openspdm.mk $(call BUILD_OBJECT_LIST,$(LIBSPDM_SOURCES)): CFLAGS += $(addprefix -I ,$(LIBSPDM_INCLUDES)) $(call BUILD_OBJECT_LIST,$(LIBSPDM_SOURCES)): CFLAGS += $(addprefix -D,$(LIBSPDM_DEFINES)) -#if NV_USE_MBEDTLS -MBEDTLS_VERSION ?= 3.6.2 -CFLAGS += -I $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/include -CFLAGS += -I $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/nvidia -CFLAGS += -D"MBEDTLS_USER_CONFIG_FILE=" -#endif - CFLAGS += -Werror-implicit-function-declaration CFLAGS += -Wwrite-strings CFLAGS += -Wundef @@ -104,40 +72,6 @@ endif CFLAGS += -fno-pic -CFLAGS += -D_LANGUAGE_C -CFLAGS += -D__NO_CTYPE -CFLAGS += -DNVRM -CFLAGS += -DLOCK_VAL_ENABLED=0 -CFLAGS += -DPORT_ATOMIC_64_BIT_SUPPORTED=1 -CFLAGS += -DPORT_IS_KERNEL_BUILD=1 -CFLAGS += -DPORT_IS_CHECKED_BUILD=0 -CFLAGS += -DPORT_MODULE_atomic=1 -CFLAGS += -DPORT_MODULE_core=1 -CFLAGS += -DPORT_MODULE_cpu=1 -CFLAGS += -DPORT_MODULE_crypto=1 -CFLAGS += -DPORT_MODULE_debug=1 -CFLAGS += -DPORT_MODULE_memory=1 -CFLAGS += -DPORT_MODULE_safe=1 -CFLAGS += -DPORT_MODULE_string=1 -CFLAGS += -DPORT_MODULE_sync=1 -CFLAGS += -DPORT_MODULE_thread=1 -CFLAGS += -DPORT_MODULE_util=1 -CFLAGS += -DPORT_MODULE_example=0 -CFLAGS += -DPORT_MODULE_mmio=0 -CFLAGS += -DPORT_MODULE_time=0 -CFLAGS += -DRS_STANDALONE=0 -CFLAGS += -DRS_STANDALONE_TEST=0 -CFLAGS += -DRS_COMPATABILITY_MODE=1 -CFLAGS += -DRS_PROVIDES_API_STATE=0 -CFLAGS += -DNV_CONTAINERS_NO_TEMPLATES - -CFLAGS += -DINCLUDE_NVLINK_LIB -CFLAGS += -DINCLUDE_NVSWITCH_LIB - -CFLAGS += -DNV_PRINTF_STRINGS_ALLOWED=1 -CFLAGS += -DNV_ASSERT_FAILED_USES_STRINGS=1 -CFLAGS += -DPORT_ASSERT_FAILED_USES_STRINGS=1 - ifeq ($(DEBUG),1) CFLAGS += -gsplit-dwarf endif @@ -150,7 +84,6 @@ endif CFLAGS += -ffunction-sections CFLAGS += -fdata-sections NV_KERNEL_O_LDFLAGS += --gc-sections -EXPORTS_LINK_COMMAND = exports_link_command.txt ifeq ($(TARGET_ARCH),x86_64) COMPILER_TYPE := $(call GET_COMPILER_TYPE, $(CC)) @@ -207,8 +140,6 @@ NV_KERNEL_O = $(OUTPUTDIR)/nv-kernel.o .PHONY: all all: $(NV_KERNEL_O) -LINKER_SCRIPT = nv-kernel.ld - NV_KERNEL_O_LDFLAGS += $(LDFLAGS) $(NV_KERNEL_O): $(OBJS) $(EXPORTS_LINK_COMMAND) $(LINKER_SCRIPT) diff --git a/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h b/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h index 5788558d8a..0ce30835d2 100644 --- a/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h +++ b/src/nvidia/arch/nvalloc/unix/include/x86emu/x86emui.h @@ -51,7 +51,7 @@ #ifndef NO_SYS_HEADERS #define NO_SYS_HEADERS #endif -#include /* NULL */ +#define NULL ((void *)0) #if defined(__cplusplus) && !defined(_NO_INLINE) #define _INLINE inline #else diff --git a/src/nvidia/defs.mk b/src/nvidia/defs.mk new file mode 100644 index 0000000000..96af68db94 --- /dev/null +++ b/src/nvidia/defs.mk @@ -0,0 +1,81 @@ +# shared make defines for Makefile and Kbuild + +SRC_COMMON := ../common + +NV_INCLUDE := +NV_INCDIRS := +NV_DEFINES := + +NV_INCLUDE += $(SRC_COMMON)/sdk/nvidia/inc/cpuopsys.h + +NV_INCDIRS += kernel/inc +NV_INCDIRS += interface +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc +NV_INCDIRS += $(SRC_COMMON)/sdk/nvidia/inc/hw +NV_INCDIRS += arch/nvalloc/common/inc +NV_INCDIRS += arch/nvalloc/common/inc/gsp +NV_INCDIRS += arch/nvalloc/common/inc/deprecated +NV_INCDIRS += arch/nvalloc/unix/include +NV_INCDIRS += inc +NV_INCDIRS += inc/os +NV_INCDIRS += $(SRC_COMMON)/shared/inc +NV_INCDIRS += $(SRC_COMMON)/shared/msgq/inc +NV_INCDIRS += $(SRC_COMMON)/inc + +NV_INCDIRS += $(SRC_COMMON)/uproc/os/libos-v2.0.0/include +NV_INCDIRS += $(SRC_COMMON)/uproc/os/common/include +NV_INCDIRS += $(SRC_COMMON)/inc/swref +NV_INCDIRS += $(SRC_COMMON)/inc/swref/published + +NV_INCDIRS += generated +NV_INCDIRS += $(SRC_COMMON)/nvswitch/kernel/inc +NV_INCDIRS += $(SRC_COMMON)/nvswitch/interface +NV_INCDIRS += $(SRC_COMMON)/nvswitch/common/inc/ +NV_INCDIRS += $(SRC_COMMON)/inc/displayport +NV_INCDIRS += $(SRC_COMMON)/nvlink/interface/ +NV_INCDIRS += $(SRC_COMMON)/nvlink/inband/interface +NV_INCDIRS += src/mm/uvm/interface +NV_INCDIRS += inc/libraries +NV_INCDIRS += src/libraries +NV_INCDIRS += inc/kernel + +#if NV_USE_MBEDTLS +MBEDTLS_VERSION ?= 3.6.2 +NV_INCDIRS += $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/include +NV_INCDIRS += $(SRC_COMMON)/mbedtls/$(MBEDTLS_VERSION)/nvidia +NV_DEFINES += -D"MBEDTLS_USER_CONFIG_FILE=" +#endif + +NV_DEFINES += -D_LANGUAGE_C +NV_DEFINES += -D__NO_CTYPE +NV_DEFINES += -DNVRM +NV_DEFINES += -DLOCK_VAL_ENABLED=0 +NV_DEFINES += -DPORT_ATOMIC_64_BIT_SUPPORTED=1 +NV_DEFINES += -DPORT_IS_KERNEL_BUILD=1 +NV_DEFINES += -DPORT_IS_CHECKED_BUILD=0 +NV_DEFINES += -DPORT_MODULE_atomic=1 +NV_DEFINES += -DPORT_MODULE_core=1 +NV_DEFINES += -DPORT_MODULE_cpu=1 +NV_DEFINES += -DPORT_MODULE_crypto=1 +NV_DEFINES += -DPORT_MODULE_debug=1 +NV_DEFINES += -DPORT_MODULE_memory=1 +NV_DEFINES += -DPORT_MODULE_safe=1 +NV_DEFINES += -DPORT_MODULE_string=1 +NV_DEFINES += -DPORT_MODULE_sync=1 +NV_DEFINES += -DPORT_MODULE_thread=1 +NV_DEFINES += -DPORT_MODULE_util=1 +NV_DEFINES += -DPORT_MODULE_example=0 +NV_DEFINES += -DPORT_MODULE_mmio=0 +NV_DEFINES += -DPORT_MODULE_time=0 +NV_DEFINES += -DRS_STANDALONE=0 +NV_DEFINES += -DRS_STANDALONE_TEST=0 +NV_DEFINES += -DRS_COMPATABILITY_MODE=1 +NV_DEFINES += -DRS_PROVIDES_API_STATE=0 +NV_DEFINES += -DNV_CONTAINERS_NO_TEMPLATES + +NV_DEFINES += -DINCLUDE_NVLINK_LIB +NV_DEFINES += -DINCLUDE_NVSWITCH_LIB + +NV_DEFINES += -DNV_PRINTF_STRINGS_ALLOWED=1 +NV_DEFINES += -DNV_ASSERT_FAILED_USES_STRINGS=1 +NV_DEFINES += -DPORT_ASSERT_FAILED_USES_STRINGS=1 diff --git a/src/nvidia/generated/g_gpu_access_nvoc.h b/src/nvidia/generated/g_gpu_access_nvoc.h index e644e01214..b00aa7d47d 100644 --- a/src/nvidia/generated/g_gpu_access_nvoc.h +++ b/src/nvidia/generated/g_gpu_access_nvoc.h @@ -69,9 +69,9 @@ typedef NvU32 (*GpuReadRegCallback)(OBJGPU *, void *, NvU32 addr, NvU32 accessSi union GPUHWREG { - volatile NvV8 Reg008[1]; - volatile NvV16 Reg016[1]; - volatile NvV32 Reg032[1]; + volatile __DECLARE_FLEX_ARRAY(NvV8, Reg008); + volatile __DECLARE_FLEX_ARRAY(NvV16, Reg016); + volatile __DECLARE_FLEX_ARRAY(NvV32, Reg032); }; typedef union GPUHWREG GPUHWREG; diff --git a/src/nvidia/inc/kernel/core/prelude.h b/src/nvidia/inc/kernel/core/prelude.h index 3273c2f58d..5c72252d68 100644 --- a/src/nvidia/inc/kernel/core/prelude.h +++ b/src/nvidia/inc/kernel/core/prelude.h @@ -23,12 +23,10 @@ #ifndef __PRELUDE_H__ #define __PRELUDE_H__ -/* ------------------------ C library --------------------------------------- */ -#include // NULL - /* ------------------------ SDK includes ------------------------------------ */ #include "nvtypes.h" +#include "nv-stddef.h" #include "nvrangetypes.h" #include "nvstatus.h" #include "nvmisc.h" diff --git a/src/nvidia/inc/libraries/nvport/inline/util_valist.h b/src/nvidia/inc/libraries/nvport/inline/util_valist.h index 4d293c3fd2..fb67c05aca 100644 --- a/src/nvidia/inc/libraries/nvport/inline/util_valist.h +++ b/src/nvidia/inc/libraries/nvport/inline/util_valist.h @@ -27,4 +27,4 @@ */ // We used to have custom implementations in here, but now we just take the standard ones -#include // define va_* +#include // define va_* diff --git a/src/nvidia/inc/libraries/nvport/util.h b/src/nvidia/inc/libraries/nvport/util.h index 6234d618af..194b7a43e5 100644 --- a/src/nvidia/inc/libraries/nvport/util.h +++ b/src/nvidia/inc/libraries/nvport/util.h @@ -183,7 +183,7 @@ PORT_UTIL_INLINE NvU32 portUtilCountTrailingZeros32(NvU32 n); /// @} End core functions -#include /* NULL */ +#include /* NULL */ /** * @name Extended Functions diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c b/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c index 6a88b6f92a..c2502ae309 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_allocmemory.c @@ -37,7 +37,7 @@ #include "ctrl/ctrl2080/ctrl2080fb.h" // NV2080_CTRL_FB_INFO -#include +#include typedef NV_STATUS RmAllocMemoryFunc( DEPRECATED_CONTEXT *pContext, diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_control.c b/src/nvidia/interface/deprecated/rmapi_deprecated_control.c index 0a647ed35d..0ffdba52a5 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_control.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_control.c @@ -45,7 +45,7 @@ #include "rmapi/rs_utils.h" #include "rmapi/rmapi.h" -#include // NULL +#include // NULL /** * Kernel-space deprecated control conversion. diff --git a/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c b/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c index 0b2f8bb9b9..257bc23582 100644 --- a/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c +++ b/src/nvidia/interface/deprecated/rmapi_deprecated_utils.c @@ -28,7 +28,7 @@ #include "ctrl/ctrl0080/ctrl0080gpu.h" // NV0080_CTRL_CMD_GPU_FIND_SUBDEVICE_HANDLE #include "nvos.h" -#include +#include NV_STATUS RmDeprecatedGetHandleParent diff --git a/src/nvidia/interface/rmapi/src/g_finn_rm_api.c b/src/nvidia/interface/rmapi/src/g_finn_rm_api.c index dfb6812ed0..b6368ec09b 100644 --- a/src/nvidia/interface/rmapi/src/g_finn_rm_api.c +++ b/src/nvidia/interface/rmapi/src/g_finn_rm_api.c @@ -21,8 +21,10 @@ #include "ctrl/ctrlb06f.h" #if defined(NVRM) /* Kernel Mode */ -#include -#include +#include +#ifndef NV_KERNEL_INTERFACE_LAYER +# include +#endif #include "nvport/nvport.h" #elif defined(NV_LIBOS) /* LIBOS */ #include diff --git a/src/nvidia/nvidia.Kbuild b/src/nvidia/nvidia.Kbuild new file mode 100644 index 0000000000..90787377ac --- /dev/null +++ b/src/nvidia/nvidia.Kbuild @@ -0,0 +1,92 @@ +########################################################################### +# nvidia.Kbuild, included by kernel-open/nvidia/nvidia.Kbuild +########################################################################### + +nvidia_src ?= . + +NV_KERNEL_O = nv-kernel.clean.o +NV_KERNEL_O_OBJS = $(nv-kernel-objs) + +include $(src)/$(nvidia_src)/srcs.mk +include $(src)/$(nvidia_src)/defs.mk + +# The source files for nv-kernel.o are all SRCS and SRCS_CXX defined in +# srcs.mk, and the NVIDIA ID string +SRCS := $(addprefix $(nvidia_src)/,$(SRCS)) +SRCS_CXX := $(addprefix $(nvidia_src)/,$(SRCS_CXX)) +NVIDSTRING := $(addprefix $(nvidia_src)/,g_nvid_string.c) + +nv-kernel-objs := $(SRCS:.c=.o) +nv-kernel-objs += $(SRCS_CXX:.cpp=.o) +nv-kernel-objs += $(NVIDSTRING:.c=.o) + +# Hack to create a relocatable intermediate object file to avoid '/bin/sh: +# Argument list too long' errors for the real module. +ifeq ($(NV_PREPARE_ONLY),1) +obj-m += nv-kernel.stub.o +nv-kernel.stub-y := $(nv-kernel-objs) $(MOD_STUB) +endif + +# for the 'clean' target +targets += $(nv-kernel-objs) +# ensure to use "our" NVIDSTRING +$(eval targets += $(NVIDSTRING)) + +# Define how to generate the NVIDIA ID string -- intentionally deviates from +# the OS-agnostic build +$(eval $(call GENERATE_NVIDSTRING, \ + NVRM_ID, \ + Linux Open Kernel Module, $(nv-kernel-objs))) + +# now compile the final ccflags +nv-kernel-cflags := $(addprefix -include $(src)/$(nvidia_src)/,$(NV_INCLUDE)) +nv-kernel-cflags += $(addprefix -I $(src)/$(nvidia_src)/,$(NV_INCDIRS)) +nv-kernel-cflags += $(NV_DEFINES) + +# quite some implicit fall-through cases +nv-kernel-cflags += -Wno-implicit-fallthrough +# lots of missing prototypes, all accross the board +nv-kernel-cflags-remove := -Wmissing-declarations -Wmissing-prototypes + +# Define how to perform dead code elimination: place each symbol in its own +# section at compile time, and garbage collect unreachable sections at link +# time. exports_link_command.txt tells the linker which symbols need to be +# exported from $(NV_KERNEL_O) so the linker can determine which symbols are +# unreachable. +nv-kernel-cflags += -ffunction-sections +nv-kernel-cflags += -fdata-sections + +nv-kernel-ldflags := --gc-sections +nv-kernel-ldflags += @$(src)/$(nvidia_src)/$(EXPORTS_LINK_COMMAND) +nv-kernel-ldflags += -T $(src)/$(nvidia_src)/$(LINKER_SCRIPT) + +nv-kernel-objcopyflags := --localize-symbol=memset +nv-kernel-objcopyflags += --localize-symbol=memcpy +#nv-kernel-objcopyflags += --remove-section=.note.gnu.property + +# move early -I... flags to after ours -- what a hack! +ccflags-includes := $(filter -I$(src)%,$(ccflags-y)) +nv-kernel-cflags += $(patsubst -I%,-I %,$(ccflags-includes)) +nv-kernel-cflags-remove += $(ccflags-includes) + +$(call ASSIGN_PER_OBJ_CFLAGS_REMOVE, $(nv-kernel-objs), $(nv-kernel-cflags-remove)) +$(call ASSIGN_PER_OBJ_CFLAGS, $(nv-kernel-objs), $(nv-kernel-cflags)) +$(call ASSIGN_PER_OBJ_LDFLAGS, nv-kernel.stub.o, $(nv-kernel-ldflags)) +$(call ASSIGN_PER_OBJ_OBJCOPYFLAGS, nv-kernel.clean.o, $(nv-kernel-objcopyflags)) + +$(obj)/nv-kernel.stub.o: $(addprefix $(obj)/$(nvidia_src)/,\ + $(EXPORTS_LINK_COMMAND) $(LINKER_SCRIPT)) + +## Libspdm source requires additional include paths and build flags. +include $(src)/$(nvidia_src)/src/libraries/libspdm/nvidia/openspdm.mk +# is sufficient to get all required defines and types +LIBSPDM_DEFINES += "LIBSPDM_STDINT_ALT=" +LIBSPDM_DEFINES += "LIBSPDM_STDBOOL_ALT=" +LIBSPDM_DEFINES += "LIBSPDM_STDDEF_ALT=" + +libspdm-objs := $(addprefix $(nvidia_src)/,$(LIBSPDM_SOURCES:.c=.o)) + +libspdm-cflags := $(addprefix -I $(src)/$(nvidia_src)/,$(LIBSPDM_INCLUDES)) +libspdm-cflags += $(addprefix -D,$(LIBSPDM_DEFINES)) + +$(call ASSIGN_PER_OBJ_CFLAGS, $(libspdm-objs), $(libspdm-cflags)) diff --git a/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c b/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c index f5ab03e268..bf2a26d886 100644 --- a/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c +++ b/src/nvidia/src/kernel/gpu/conf_compute/ccsl.c @@ -31,7 +31,7 @@ #include "nvport/nvport.h" #include "rmapi/rmapi.h" #include "ctrl/ctrlc56f.h" -#include +#include // This guard is here until we fix CONF_COMPUTE and SPDM guards across whole RM #include "kernel/gpu/spdm/libspdm_includes.h" #include diff --git a/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c b/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c index cc2098b022..476b174e35 100644 --- a/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c +++ b/src/nvidia/src/kernel/gpu/mem_mgr/arch/maxwell/virt_mem_allocator_gm107.c @@ -1692,7 +1692,7 @@ dmaFreeMapping_GM107 if (pCliMapInfo != NULL && pCliMapInfo->pDmaMappingInfo->bNeedL2InvalidateAtUnmap) { - GMMU_APERTURE aperture = (pCliMapInfo->pDmaMappingInfo->aperture == GMMU_APERTURE_PEER) ? + FB_CACHE_MEMTYPE aperture = (pCliMapInfo->pDmaMappingInfo->aperture == GMMU_APERTURE_PEER) ? FB_CACHE_PEER_MEMORY : FB_CACHE_SYSTEM_MEMORY; kmemsysCacheOp_HAL(pGpu, GPU_GET_KERNEL_MEMORY_SYSTEM(pGpu), NULL, aperture, FB_CACHE_INVALIDATE); diff --git a/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c b/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c index bae762f397..ebb3b8c43a 100644 --- a/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c +++ b/src/nvidia/src/kernel/gpu/mmu/bar2_walk.c @@ -935,11 +935,11 @@ _bar2WalkCBWriteBuffer const MMU_WALK_CALLBACKS g_bar2WalkCallbacks = { - _bar2WalkCBLevelAlloc, - _bar2WalkCBLevelFree, - _bar2WalkCBUpdatePdb, - _bar2WalkCBUpdatePde, - _bar2WalkCBFillEntries, - NULL, - _bar2WalkCBWriteBuffer, + .LevelAlloc = _bar2WalkCBLevelAlloc, + .LevelFree = _bar2WalkCBLevelFree, + .UpdatePdb = _bar2WalkCBUpdatePdb, + .UpdatePde = _bar2WalkCBUpdatePde, + .FillEntries = _bar2WalkCBFillEntries, + .CopyEntries = NULL, + .WriteBuffer = _bar2WalkCBWriteBuffer, }; diff --git a/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c b/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c index 17dda40f40..6092316ea2 100644 --- a/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c +++ b/src/nvidia/src/kernel/gpu/mmu/gmmu_trace.c @@ -546,17 +546,17 @@ _gmmuSwToHwLevel const MMU_TRACE_CALLBACKS g_gmmuTraceCallbacks = { - _gmmuIsPte, // isPte - _gmmuGetFmtPde, // getFmtPde - _gmmuGetFmtPte, // getFmtPte - _gmmuGetPdePa, // getPdePa - _gmmuGetPtePa, // getPtePa - _gmmuPrintPdb, // printPdb - _gmmuPrintPde, // printPde - _gmmuPrintPt, // printPt - _gmmuPrintPte, // printPte - _gmmuIsInvalidPdeOk, // isInvalidPdeOk - _gmmuPdeAddrSpace, // pdeAddrSpace - _gmmuPteAddrSpace, // pteAddrSpace - _gmmuSwToHwLevel, // swToHwLevel + .isPte = _gmmuIsPte, + .getFmtPde = _gmmuGetFmtPde, + .getFmtPte = _gmmuGetFmtPte, + .getPdePa = _gmmuGetPdePa, + .getPtePa = _gmmuGetPtePa, + .printPdb = _gmmuPrintPdb, + .printPde = _gmmuPrintPde, + .printPt = _gmmuPrintPt, + .printPte = _gmmuPrintPte, + .isInvalidPdeOk = _gmmuIsInvalidPdeOk, + .pdeAddrSpace = _gmmuPdeAddrSpace, + .pteAddrSpace = _gmmuPteAddrSpace, + .swToHwLevel = _gmmuSwToHwLevel, }; diff --git a/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c b/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c index f72063c787..9b735c53bd 100644 --- a/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c +++ b/src/nvidia/src/kernel/gpu/mmu/gmmu_walk.c @@ -1002,11 +1002,11 @@ _gmmuWalkCBCopyEntries const MMU_WALK_CALLBACKS g_gmmuWalkCallbacks = { - _gmmuWalkCBLevelAlloc, - _gmmuWalkCBLevelFree, - _gmmuWalkCBUpdatePdb, - _gmmuWalkCBUpdatePde, - _gmmuWalkCBFillEntries, - _gmmuWalkCBCopyEntries, - NULL, + .LevelAlloc = _gmmuWalkCBLevelAlloc, + .LevelFree = _gmmuWalkCBLevelFree, + .UpdatePdb = _gmmuWalkCBUpdatePdb, + .UpdatePde = _gmmuWalkCBUpdatePde, + .FillEntries = _gmmuWalkCBFillEntries, + .CopyEntries = _gmmuWalkCBCopyEntries, + .WriteBuffer = NULL, }; diff --git a/src/nvidia/src/kernel/gpu/timer/timer.c b/src/nvidia/src/kernel/gpu/timer/timer.c index 5a28338c04..b5f41cd84e 100644 --- a/src/nvidia/src/kernel/gpu/timer/timer.c +++ b/src/nvidia/src/kernel/gpu/timer/timer.c @@ -1769,7 +1769,7 @@ tmrapiDeregisterEvents_IMPL(TimerApi *pTimerApi) // inner callback and calls it correctly from itself. Hacky but it should work around the // limitations in the SDK (all RM derived types undefined, so TIMEPROC type is impossible). // -typedef NvU32 (*TMR_CALLBACK_FUNCTION)(void *pCallbackData); +typedef void (*TMR_CALLBACK_FUNCTION)(void *pCallbackData); typedef struct { @@ -1822,7 +1822,7 @@ tmrCtrlCmdEventCreate ) { NV_STATUS rc; - TMR_EVENT *pEvent; + TMR_EVENT *pEvent = NULL; wrapperStorage_t *pWrapper; OBJTMR *pTmr = GPU_GET_TIMER(pGpu); diff --git a/src/nvidia/srcs.mk b/src/nvidia/srcs.mk index 675167f371..17acb032cb 100644 --- a/src/nvidia/srcs.mk +++ b/src/nvidia/srcs.mk @@ -1,5 +1,5 @@ -SRCS ?= -SRCS_CXX ?= +SRCS := +SRCS_CXX := SRCS += generated/g_access_cntr_buffer_nvoc.c SRCS += generated/g_all_dcl_pb.c @@ -1017,3 +1017,6 @@ SRCS += src/libraries/utils/nvassert.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/libdwarf.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/libelf.c SRCS += ../common/uproc/os/libos-v3.1.0/lib/liblogdecode.c + +LINKER_SCRIPT := nv-kernel.ld +EXPORTS_LINK_COMMAND := exports_link_command.txt