|
| 1 | +# kmod-nvidia-open.inc — NVIDIA open GPU kernel module subpackage |
| 2 | +# |
| 3 | +# Phases: package, prep, build, install, files |
| 4 | +# Activated by: setting _kmod_phase global + include from kernel.comp.toml overlays |
| 5 | +# |
| 6 | +# Requires these defines/sources in kernel.spec (injected via comp.toml overlays): |
| 7 | +# nvidia_open_version — NVIDIA driver version (e.g. 595.58.03) |
| 8 | +# SOURCE6000 — open-gpu-kernel-modules tarball |
| 9 | +# SOURCE6001 — kmod-nvidia-open-modprobe.conf |
| 10 | + |
| 11 | +# ========================================================================= |
| 12 | +# Phase: package — subpackage declaration |
| 13 | +# ========================================================================= |
| 14 | +%if "%{_kmod_phase}" == "package" && %{with_up_base} |
| 15 | + |
| 16 | +%ifarch x86_64 aarch64 |
| 17 | +%package -n kmod-%{_kmod_name}-%{KVERREL} |
| 18 | +Summary: NVIDIA open GPU kernel modules (driver %{nvidia_open_version}) |
| 19 | +AutoReq: no |
| 20 | +# NOTE: Version is inherited from kernel (%{version}), NOT nvidia_open_version. |
| 21 | +# Track the actual NVIDIA driver version via Provides for dependency resolution. |
| 22 | +Provides: nvidia-open-kmod-version = %{nvidia_open_version} |
| 23 | +provides: nvidia-kmod = %{nvidia_open_version} |
| 24 | +Provides: kmod-%{_kmod_name} = %{version}-%{release} |
| 25 | +Requires: %{name}-core-uname-r = %{KVERREL} |
| 26 | +Requires(post): kmod |
| 27 | +Requires(postun): kmod |
| 28 | +Conflicts: nvidia-closed-kmod |
| 29 | + |
| 30 | +%description -n kmod-%{_kmod_name}-%{KVERREL} |
| 31 | +Open-source NVIDIA GPU kernel modules (driver version %{nvidia_open_version}) |
| 32 | +built from the official NVIDIA/open-gpu-kernel-modules repository for |
| 33 | +kernel %{KVERREL}. |
| 34 | + |
| 35 | +These modules support CUDA workloads on NVIDIA GPUs (Turing and later). |
| 36 | +Modules: nvidia.ko, nvidia-modeset.ko, nvidia-drm.ko, nvidia-uvm.ko, |
| 37 | +nvidia-peermem.ko. |
| 38 | + |
| 39 | +Each kernel version produces a separate kmod package (kmod-nvidia-open-<KVERREL>) |
| 40 | +so that multiple kernel versions can coexist with their own NVIDIA modules. |
| 41 | +Use 'Requires: nvidia-open-kmod-version = %{nvidia_open_version}' to depend on a |
| 42 | +specific NVIDIA driver version, or 'Requires: kmod-nvidia-open' for any version. |
| 43 | +%endif |
| 44 | + |
| 45 | +%endif |
| 46 | + |
| 47 | +# ========================================================================= |
| 48 | +# Phase: prep — extract NVIDIA source tarball |
| 49 | +# ========================================================================= |
| 50 | +%if "%{_kmod_phase}" == "prep" && %{with_up_base} |
| 51 | + |
| 52 | +%ifarch x86_64 aarch64 |
| 53 | +cd %{_builddir} |
| 54 | +tar -xf %{SOURCE6000} |
| 55 | +cd - |
| 56 | +%endif |
| 57 | + |
| 58 | +%endif |
| 59 | + |
| 60 | +# ========================================================================= |
| 61 | +# Phase: build — compile NVIDIA kernel modules |
| 62 | +# ========================================================================= |
| 63 | +%if "%{_kmod_phase}" == "build" && %{with_up_base} |
| 64 | + |
| 65 | +%ifarch x86_64 aarch64 |
| 66 | +%{log_msg "Building NVIDIA open GPU kernel modules %{nvidia_open_version} for %{KVERREL}"} |
| 67 | +pushd %{_builddir}/open-gpu-kernel-modules-%{nvidia_open_version} |
| 68 | +# Unset LDFLAGS — NVIDIA kbuild invokes ld directly, not via gcc |
| 69 | +unset LDFLAGS |
| 70 | +# IGNORE_CC_MISMATCH=1: kmod is a kernel subpackage built in the same |
| 71 | +# mock chroot with the same GCC. The flag suppresses NVIDIA's compiler-string |
| 72 | +# comparison which can false-positive on path or version-string formatting |
| 73 | +# differences even when the toolchain is identical. |
| 74 | +make %{?_smp_mflags} modules \ |
| 75 | + KERNEL_UNAME="%{KVERREL}" \ |
| 76 | + SYSSRC="%{_builddir}/kernel-%{tarfile_release}/linux-%{KVERREL}" \ |
| 77 | + SYSOUT="%{_builddir}/kernel-%{tarfile_release}/linux-%{KVERREL}" \ |
| 78 | + IGNORE_CC_MISMATCH=1 \ |
| 79 | + IGNORE_XEN_PRESENCE=1 \ |
| 80 | + IGNORE_PREEMPT_RT_PRESENCE=1 \ |
| 81 | + NV_EXCLUDE_BUILD_MODULES="" |
| 82 | +popd |
| 83 | +%endif |
| 84 | + |
| 85 | +%endif |
| 86 | + |
| 87 | +# ========================================================================= |
| 88 | +# Phase: install — install modules, config, and license |
| 89 | +# ========================================================================= |
| 90 | +%if "%{_kmod_phase}" == "install" && %{with_up_base} |
| 91 | + |
| 92 | +%ifarch x86_64 aarch64 |
| 93 | +%{log_msg "Installing NVIDIA open GPU kernel modules for %{KVERREL}"} |
| 94 | +install -d %{buildroot}/lib/modules/%{KVERREL}/extra/nvidia |
| 95 | +for mod in nvidia nvidia-modeset nvidia-drm nvidia-uvm nvidia-peermem; do |
| 96 | + ko="%{_builddir}/open-gpu-kernel-modules-%{nvidia_open_version}/kernel-open/${mod}.ko" |
| 97 | + install -m 0644 "${ko}" %{buildroot}/lib/modules/%{KVERREL}/extra/nvidia/ |
| 98 | +done |
| 99 | +# Install modprobe config to blacklist conflicting modules |
| 100 | +install -D -m 0644 %{SOURCE6001} %{buildroot}%{_sysconfdir}/modprobe.d/kmod-%{_kmod_name}-%{KVERREL}.conf |
| 101 | +# Install depmod override config |
| 102 | +install -d %{buildroot}%{_sysconfdir}/depmod.d |
| 103 | +cat > %{buildroot}%{_sysconfdir}/depmod.d/kmod-%{_kmod_name}-%{KVERREL}.conf << 'DEPMOD_EOF' |
| 104 | +override nvidia %{KVERREL} extra/nvidia |
| 105 | +override nvidia-modeset %{KVERREL} extra/nvidia |
| 106 | +override nvidia-drm %{KVERREL} extra/nvidia |
| 107 | +override nvidia-uvm %{KVERREL} extra/nvidia |
| 108 | +override nvidia-peermem %{KVERREL} extra/nvidia |
| 109 | +DEPMOD_EOF |
| 110 | +# Install NVIDIA license file |
| 111 | +install -D -m 0644 %{_builddir}/open-gpu-kernel-modules-%{nvidia_open_version}/COPYING \ |
| 112 | + %{buildroot}%{_datadir}/licenses/kmod-%{_kmod_name}-%{KVERREL}/COPYING |
| 113 | +%endif |
| 114 | + |
| 115 | +%endif |
| 116 | + |
| 117 | +# ========================================================================= |
| 118 | +# Phase: files — scriptlets and file list |
| 119 | +# ========================================================================= |
| 120 | +%if "%{_kmod_phase}" == "files" && %{with_up_base} |
| 121 | + |
| 122 | +%ifarch x86_64 aarch64 |
| 123 | +%post -n kmod-%{_kmod_name}-%{KVERREL} |
| 124 | +%{_sbindir}/depmod -a %{KVERREL} || : |
| 125 | + |
| 126 | +%postun -n kmod-%{_kmod_name}-%{KVERREL} |
| 127 | +%{_sbindir}/depmod -a %{KVERREL} || : |
| 128 | + |
| 129 | +%files -n kmod-%{_kmod_name}-%{KVERREL} |
| 130 | +%license %{_datadir}/licenses/kmod-%{_kmod_name}-%{KVERREL}/COPYING |
| 131 | +/lib/modules/%{KVERREL}/extra/nvidia/nvidia.ko.%{compext} |
| 132 | +/lib/modules/%{KVERREL}/extra/nvidia/nvidia-modeset.ko.%{compext} |
| 133 | +/lib/modules/%{KVERREL}/extra/nvidia/nvidia-drm.ko.%{compext} |
| 134 | +/lib/modules/%{KVERREL}/extra/nvidia/nvidia-uvm.ko.%{compext} |
| 135 | +/lib/modules/%{KVERREL}/extra/nvidia/nvidia-peermem.ko.%{compext} |
| 136 | +%config(noreplace) %{_sysconfdir}/modprobe.d/kmod-%{_kmod_name}-%{KVERREL}.conf |
| 137 | +%{_sysconfdir}/depmod.d/kmod-%{_kmod_name}-%{KVERREL}.conf |
| 138 | +%endif |
| 139 | + |
| 140 | +%endif |
0 commit comments