#!/bin/bash
# Like mkinitcpio's kms hook, but excludes nouveau and nova when the
# proprietary NVIDIA driver handles early KMS. That keeps early KMS for any
# iGPU (i915, xe, amdgpu) and privacy screens without pulling in ~107 MiB of
# unused nouveau GSP firmware.

build() {
  local major minor

  # AGP and non-NVIDIA DRM modules for GPUs
  add_checked_modules -f '/drivers/gpu/drm/(nouveau|nova)/' '/drivers/(char/agp|gpu/drm)/'

  # modules that implement the privacy screen interface
  IFS=.- read -r major minor _ <<<"$KERNELVERSION"
  if ((major > 5 || (major == 5 && minor >= 17))); then
    add_checked_modules_from_symbol 'drm_privacy_screen_register' '=drivers/platform'
  fi
}

help() {
  cat <<HELPEOF
Adds non-NVIDIA KMS and privacy screen drivers to the initramfs image on
systems where the proprietary NVIDIA driver handles early KMS itself.
HELPEOF
}
