2020-12-03 12:48:07 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
2021-03-20 19:46:52 +01:00
|
|
|
options.hardware.genode.usb = let
|
|
|
|
mkEnableOption' = text: default:
|
|
|
|
lib.mkEnableOption text // {
|
|
|
|
inherit default;
|
|
|
|
};
|
|
|
|
in {
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-12-19 15:23:35 +01:00
|
|
|
enable = lib.mkEnableOption "USB driver";
|
|
|
|
storage.enable = lib.mkEnableOption "USB mass storage driver";
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-03-20 19:46:52 +01:00
|
|
|
biosHandoff = mkEnableOption' "perform the BIOS handoff procedure" true;
|
|
|
|
|
|
|
|
ehciSupport = mkEnableOption' "EHCI support" true;
|
|
|
|
ohciSupport = mkEnableOption' "OHCI support" true;
|
|
|
|
uhciSupport = mkEnableOption' "UHCI support" false;
|
|
|
|
xhciSupport = mkEnableOption' "XHCI support" true;
|
2020-12-03 12:48:07 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-03-20 19:46:52 +01:00
|
|
|
config = let
|
|
|
|
cfg = config.hardware.genode.usb;
|
|
|
|
|
|
|
|
usbEris = lib.attrsets.mapAttrs (_: lib.getEris "bin") {
|
|
|
|
inherit (pkgs.genodePackages) part_block usb_block_drv usb_drv;
|
|
|
|
};
|
|
|
|
|
|
|
|
managerConfig = pkgs.writeText "usb_device_manager.dhall" ''
|
|
|
|
let Manager = ${pkgs.genodePackages.usb_device_manager.dhall}/package.dhall
|
|
|
|
|
|
|
|
in Manager.toChildAttributes
|
|
|
|
Manager::{
|
|
|
|
, part_block.binary = "${usbEris.part_block.cap}"
|
|
|
|
, usb_block.binary = "${usbEris.usb_block_drv.cap}"
|
|
|
|
, usb_driver =
|
|
|
|
{ binary = "${usbEris.usb_drv.cap}"
|
|
|
|
, bios_handoff = True
|
|
|
|
, ehci = True
|
|
|
|
, ohci = False
|
|
|
|
, uhci = False
|
|
|
|
, xhci = False
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2020-12-19 15:23:35 +01:00
|
|
|
in {
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-03-20 19:46:52 +01:00
|
|
|
hardware.genode.usb.enable = lib.mkDefault cfg.storage.enable;
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2020-12-19 15:23:35 +01:00
|
|
|
hardware.genode.platform.policies = lib.optional cfg.enable
|
2020-12-03 12:48:07 +01:00
|
|
|
(builtins.toFile ("usb.platform-policy.dhall") ''
|
2021-03-28 15:07:21 +02:00
|
|
|
let Sigil = env:DHALL_SIGIL
|
2020-12-03 12:48:07 +01:00
|
|
|
|
2021-03-28 15:07:21 +02:00
|
|
|
in Sigil.Init.Config.Policy::{
|
2020-12-03 12:48:07 +01:00
|
|
|
, service = "Platform"
|
2021-03-28 15:07:21 +02:00
|
|
|
, label = Sigil.Init.LabelSelector.prefix "drivers -> usb"
|
2020-12-03 12:48:07 +01:00
|
|
|
, content =
|
2021-03-28 15:07:21 +02:00
|
|
|
[ Sigil.Prelude.XML.leaf
|
2020-12-03 12:48:07 +01:00
|
|
|
{ name = "pci", attributes = toMap { class = "USB" } }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
'');
|
|
|
|
|
2020-12-21 00:53:17 +01:00
|
|
|
virtualisation.qemu.options = lib.optional cfg.enable
|
|
|
|
(lib.optional (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) "-usb"
|
|
|
|
++ lib.optional (pkgs.stdenv.isAarch32 || pkgs.stdenv.isAarch64)
|
2021-03-20 19:46:52 +01:00
|
|
|
"-device usb-ehci,id=usb0");
|
2020-12-21 00:53:17 +01:00
|
|
|
|
2020-12-03 12:48:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|