1###########################################################################
2# Kbuild fragment for nvidia.ko
3###########################################################################
4
5#
6# Define NVIDIA_{SOURCES,OBJECTS}
7#
8
9include $(src)/nvidia/nvidia-sources.Kbuild
10NVIDIA_OBJECTS = $(patsubst %.c,%.o,$(NVIDIA_SOURCES))
11
12obj-m += nvidia.o
13nvidia-y := $(NVIDIA_OBJECTS)
14
15NVIDIA_KO = nvidia/nvidia.ko
16
17
18#
19# nv-kernel.o_binary is the core binary component of nvidia.ko, shared
20# across all UNIX platforms. Create a symlink, "nv-kernel.o" that
21# points to nv-kernel.o_binary, and add nv-kernel.o to the list of
22# objects to link into nvidia.ko.
23#
24# Note that:
25# - The kbuild "clean" rule will delete all objects in nvidia-y (which
26# is why we use a symlink instead of just adding nv-kernel.o_binary
27# to nvidia-y).
28# - kbuild normally uses the naming convention of ".o_shipped" for
29# binary files. That is not used here, because the kbuild rule to
30# create the "normal" object file from ".o_shipped" does a copy, not
31# a symlink. This file is quite large, so a symlink is preferred.
32# - The file added to nvidia-y should be relative to gmake's cwd.
33# But, the target for the symlink rule should be prepended with $(obj).
34# - The "symlink" command is called using kbuild's if_changed macro to
35# generate an .nv-kernel.o.cmd file which can be used on subsequent
36# runs to determine if the command line to create the symlink changed
37# and needs to be re-executed.
38#
39
40NVIDIA_BINARY_OBJECT := $(src)/nvidia/nv-kernel.o_binary
41NVIDIA_BINARY_OBJECT_O := nvidia/nv-kernel.o
42
43quiet_cmd_symlink = SYMLINK $@
44 cmd_symlink = ln -sf $< $@
45
46targets += $(NVIDIA_BINARY_OBJECT_O)
47
48$(obj)/$(NVIDIA_BINARY_OBJECT_O): $(NVIDIA_BINARY_OBJECT) FORCE
49	$(call if_changed,symlink)
50
51nvidia-y += $(NVIDIA_BINARY_OBJECT_O)
52
53
54#
55# Define nvidia.ko-specific CFLAGS.
56#
57
58NVIDIA_CFLAGS += -I$(src)/nvidia
59NVIDIA_CFLAGS += -DNVIDIA_UNDEF_LEGACY_BIT_MACROS
60
61ifeq ($(NV_BUILD_TYPE),release)
62 NVIDIA_CFLAGS += -UDEBUG -U_DEBUG -DNDEBUG
63endif
64
65ifeq ($(NV_BUILD_TYPE),develop)
66 NVIDIA_CFLAGS += -UDEBUG -U_DEBUG -DNDEBUG -DNV_MEM_LOGGER
67endif
68
69ifeq ($(NV_BUILD_TYPE),debug)
70 NVIDIA_CFLAGS += -DDEBUG -D_DEBUG -UNDEBUG -DNV_MEM_LOGGER
71endif
72
73$(call ASSIGN_PER_OBJ_CFLAGS, $(NVIDIA_OBJECTS), $(NVIDIA_CFLAGS))
74
75
76#
77# nv-procfs.c requires nv-compiler.h
78#
79
80NV_COMPILER_VERSION_HEADER = $(obj)/nv_compiler.h
81
82$(NV_COMPILER_VERSION_HEADER):
83	@echo \#define NV_COMPILER \"`$(CC) -v 2>&1 | tail -n 1`\" > $@
84
85$(obj)/nvidia/nv-procfs.o: $(NV_COMPILER_VERSION_HEADER)
86
87clean-files += $(NV_COMPILER_VERSION_HEADER)
88
89
90#
91# Build nv-interface.o from the kernel interface layer objects, suitable
92# for further processing by the top-level makefile to produce a precompiled
93# kernel interface file.
94#
95
96NVIDIA_INTERFACE := nvidia/nv-interface.o
97
98# Linux kernel v5.12 and later looks at "always-y", Linux kernel versions
99# before v5.6 looks at "always"; kernel versions between v5.12 and v5.6
100# look at both.
101
102always += $(NVIDIA_INTERFACE)
103always-y += $(NVIDIA_INTERFACE)
104
105$(obj)/$(NVIDIA_INTERFACE): $(addprefix $(obj)/,$(NVIDIA_OBJECTS))
106	$(LD) -r -o $@ $^
107
108
109#
110# Register the conftests needed by nvidia.ko
111#
112
113NV_OBJECTS_DEPEND_ON_CONFTEST += $(NVIDIA_OBJECTS)
114
115NV_CONFTEST_FUNCTION_COMPILE_TESTS += hash__remap_4k_pfn
116NV_CONFTEST_FUNCTION_COMPILE_TESTS += set_pages_uc
117NV_CONFTEST_FUNCTION_COMPILE_TESTS += list_is_first
118NV_CONFTEST_FUNCTION_COMPILE_TESTS += set_memory_uc
119NV_CONFTEST_FUNCTION_COMPILE_TESTS += set_memory_array_uc
120NV_CONFTEST_FUNCTION_COMPILE_TESTS += set_pages_array_uc
121NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_cache
122NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_wc
123NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_driver_hardened
124NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_driver_hardened_wc
125NV_CONFTEST_FUNCTION_COMPILE_TESTS += ioremap_cache_shared
126NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_get_domain_bus_and_slot
127NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_num_physpages
128NV_CONFTEST_FUNCTION_COMPILE_TESTS += pde_data
129NV_CONFTEST_FUNCTION_COMPILE_TESTS += xen_ioemu_inject_msi
130NV_CONFTEST_FUNCTION_COMPILE_TESTS += phys_to_dma
131NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_dma_ops
132NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_attr_macros
133NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_map_page_attrs
134NV_CONFTEST_FUNCTION_COMPILE_TESTS += write_cr4
135NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_find_node_by_phandle
136NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_node_to_nid
137NV_CONFTEST_FUNCTION_COMPILE_TESTS += pnv_pci_get_npu_dev
138NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_get_ibm_chip_id
139NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_bus_address
140NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_stop_and_remove_bus_device
141NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_rebar_get_possible_sizes
142NV_CONFTEST_FUNCTION_COMPILE_TESTS += wait_for_random_bytes
143NV_CONFTEST_FUNCTION_COMPILE_TESTS += register_cpu_notifier
144NV_CONFTEST_FUNCTION_COMPILE_TESTS += cpuhp_setup_state
145NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_map_resource
146NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_backlight_device_by_name
147NV_CONFTEST_FUNCTION_COMPILE_TESTS += timer_setup
148NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_enable_msix_range
149NV_CONFTEST_FUNCTION_COMPILE_TESTS += kernel_read_has_pointer_pos_arg
150NV_CONFTEST_FUNCTION_COMPILE_TESTS += kernel_write_has_pointer_pos_arg
151NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_direct_map_resource
152NV_CONFTEST_FUNCTION_COMPILE_TESTS += tegra_get_platform
153NV_CONFTEST_FUNCTION_COMPILE_TESTS += tegra_bpmp_send_receive
154NV_CONFTEST_FUNCTION_COMPILE_TESTS += flush_cache_all
155NV_CONFTEST_FUNCTION_COMPILE_TESTS += vmf_insert_pfn
156NV_CONFTEST_FUNCTION_COMPILE_TESTS += jiffies_to_timespec
157NV_CONFTEST_FUNCTION_COMPILE_TESTS += ktime_get_raw_ts64
158NV_CONFTEST_FUNCTION_COMPILE_TESTS += ktime_get_real_ts64
159NV_CONFTEST_FUNCTION_COMPILE_TESTS += full_name_hash
160NV_CONFTEST_FUNCTION_COMPILE_TESTS += pci_enable_atomic_ops_to_root
161NV_CONFTEST_FUNCTION_COMPILE_TESTS += vga_tryget
162NV_CONFTEST_FUNCTION_COMPILE_TESTS += cc_platform_has
163NV_CONFTEST_FUNCTION_COMPILE_TESTS += seq_read_iter
164NV_CONFTEST_FUNCTION_COMPILE_TESTS += unsafe_follow_pfn
165NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_gem_object_get
166NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_gem_object_put_unlocked
167NV_CONFTEST_FUNCTION_COMPILE_TESTS += add_memory_driver_managed
168NV_CONFTEST_FUNCTION_COMPILE_TESTS += device_property_read_u64
169NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_of_platform_populate
170NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_dma_configure
171NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_property_count_elems_of_size
172NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_property_read_variable_u8_array
173NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_property_read_variable_u32_array
174NV_CONFTEST_FUNCTION_COMPILE_TESTS += i2c_new_client_device
175NV_CONFTEST_FUNCTION_COMPILE_TESTS += i2c_unregister_device
176NV_CONFTEST_FUNCTION_COMPILE_TESTS += of_get_named_gpio
177NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_gpio_request_one
178NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_direction_input
179NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_direction_output
180NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_get_value
181NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_set_value
182NV_CONFTEST_FUNCTION_COMPILE_TESTS += gpio_to_irq
183NV_CONFTEST_FUNCTION_COMPILE_TESTS += icc_get
184NV_CONFTEST_FUNCTION_COMPILE_TESTS += icc_put
185NV_CONFTEST_FUNCTION_COMPILE_TESTS += icc_set_bw
186NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_export_args
187NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_ops_has_kmap
188NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_ops_has_kmap_atomic
189NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_ops_has_map
190NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_ops_has_map_atomic
191NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_has_dynamic_attachment
192NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_buf_attachment_has_peer2peer
193NV_CONFTEST_FUNCTION_COMPILE_TESTS += dma_set_mask_and_coherent
194NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_clk_bulk_get_all
195NV_CONFTEST_FUNCTION_COMPILE_TESTS += get_task_ioprio
196NV_CONFTEST_FUNCTION_COMPILE_TESTS += mdev_set_iommu_device
197NV_CONFTEST_FUNCTION_COMPILE_TESTS += offline_and_remove_memory
198
199NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_gpl_of_node_to_nid
200NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_gpl_sme_active
201NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_swiotlb_map_sg_attrs
202NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_swiotlb_dma_ops
203NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present___close_fd
204NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_close_fd
205NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_get_unused_fd
206NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_get_unused_fd_flags
207NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_nvhost_get_default_device
208NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_nvhost_syncpt_unit_interface_get_byte_offset
209NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_nvhost_syncpt_unit_interface_get_aperture
210NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_dce_register_ipc_client
211NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_dce_unregister_ipc_client
212NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_dce_client_ipc_send_recv
213NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_dram_clk_to_mc_clk
214NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_get_dram_num_channels
215NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_dram_types
216NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_pxm_to_node
217NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_screen_info
218NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_i2c_bus_status
219NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_fuse_control_read
220NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tegra_get_platform
221NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_pci_find_host_bridge
222NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tsec_comms_send_cmd
223NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tsec_comms_set_init_cb
224NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tsec_comms_clear_init_cb
225NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tsec_comms_alloc_mem_from_gscco
226NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_tsec_comms_free_gscco_mem
227NV_CONFTEST_SYMBOL_COMPILE_TESTS += is_export_symbol_present_memory_block_size_bytes
228NV_CONFTEST_SYMBOL_COMPILE_TESTS += crypto
229
230NV_CONFTEST_TYPE_COMPILE_TESTS += dma_ops
231NV_CONFTEST_TYPE_COMPILE_TESTS += swiotlb_dma_ops
232NV_CONFTEST_TYPE_COMPILE_TESTS += noncoherent_swiotlb_dma_ops
233NV_CONFTEST_TYPE_COMPILE_TESTS += vm_fault_has_address
234NV_CONFTEST_TYPE_COMPILE_TESTS += vm_insert_pfn_prot
235NV_CONFTEST_TYPE_COMPILE_TESTS += vmf_insert_pfn_prot
236NV_CONFTEST_TYPE_COMPILE_TESTS += vm_ops_fault_removed_vma_arg
237NV_CONFTEST_TYPE_COMPILE_TESTS += kmem_cache_has_kobj_remove_work
238NV_CONFTEST_TYPE_COMPILE_TESTS += sysfs_slab_unlink
239NV_CONFTEST_TYPE_COMPILE_TESTS += proc_ops
240NV_CONFTEST_TYPE_COMPILE_TESTS += timespec64
241NV_CONFTEST_TYPE_COMPILE_TESTS += vmalloc_has_pgprot_t_arg
242NV_CONFTEST_TYPE_COMPILE_TESTS += mm_has_mmap_lock
243NV_CONFTEST_TYPE_COMPILE_TESTS += pci_channel_state
244NV_CONFTEST_TYPE_COMPILE_TESTS += pci_dev_has_ats_enabled
245NV_CONFTEST_TYPE_COMPILE_TESTS += remove_memory_has_nid_arg
246NV_CONFTEST_TYPE_COMPILE_TESTS += add_memory_driver_managed_has_mhp_flags_arg
247NV_CONFTEST_TYPE_COMPILE_TESTS += num_registered_fb
248NV_CONFTEST_TYPE_COMPILE_TESTS += pci_driver_has_driver_managed_dma
249NV_CONFTEST_TYPE_COMPILE_TESTS += vm_area_struct_has_const_vm_flags
250NV_CONFTEST_TYPE_COMPILE_TESTS += memory_failure_has_trapno_arg
251
252NV_CONFTEST_GENERIC_COMPILE_TESTS += dom0_kernel_present
253NV_CONFTEST_GENERIC_COMPILE_TESTS += nvidia_vgpu_kvm_build
254NV_CONFTEST_GENERIC_COMPILE_TESTS += nvidia_grid_build
255NV_CONFTEST_GENERIC_COMPILE_TESTS += nvidia_grid_csp_build
256NV_CONFTEST_GENERIC_COMPILE_TESTS += get_user_pages
257NV_CONFTEST_GENERIC_COMPILE_TESTS += get_user_pages_remote
258NV_CONFTEST_GENERIC_COMPILE_TESTS += pin_user_pages
259NV_CONFTEST_GENERIC_COMPILE_TESTS += pin_user_pages_remote
260NV_CONFTEST_GENERIC_COMPILE_TESTS += pm_runtime_available
261NV_CONFTEST_GENERIC_COMPILE_TESTS += vm_fault_t
262NV_CONFTEST_GENERIC_COMPILE_TESTS += pci_class_multimedia_hd_audio
263NV_CONFTEST_GENERIC_COMPILE_TESTS += drm_available
264NV_CONFTEST_GENERIC_COMPILE_TESTS += vfio_pci_core_available
265NV_CONFTEST_GENERIC_COMPILE_TESTS += mdev_available
266NV_CONFTEST_GENERIC_COMPILE_TESTS += cmd_uphy_display_port_init
267NV_CONFTEST_GENERIC_COMPILE_TESTS += cmd_uphy_display_port_off
268NV_CONFTEST_GENERIC_COMPILE_TESTS += memory_failure_mf_sw_simulated_defined
269