#
# Configuration for using SR-IOV with i915.
#
# vim: et:ts=2:sw=2:
#
{ deprekages, pkgs, ... }:
{
  # Use looking-glass a as a viewer for SRIOV.
  imports = [
    ./looking-glass.nix
  ];

  # Support Intel device SRIOV.
  boot = {
    # Use our kernel, with its specialized config.
    kernelPackages = deprekages.linuxPackages_i915-sriov;
    kernelParams = [
      "iommu=pt"
      "intel_iommu=on"
      "i915.enable_guc=3"
      "i915.max_vfs=7"
    ];

    # This replaces the i915 module with an extended one.
    extraModulePackages = [ deprekages.i915-sriov ];
  };

  # Make a virtual function for a VM ready and available on VM start.
  virtualisation.libvirtd.hooks.qemu = {

    ready_sriov = pkgs.writeScript "sriov.sh" ''
      #!${pkgs.bash}/bin/bash
      echo 0 > /sys/devices/pci0000:00/0000:00:02.0/sriov_drivers_autoprobe
      echo 1 > /sys/devices/pci0000:00/0000:00:02.0/sriov_numvfs
    '';

  };

}
