sigil/nixos-modules/hardware/usb.nix

83 lines
2.5 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
{
options = {
hardware.usb.genode.enable = lib.mkEnableOption "USB driver";
hardware.usb.genode.storage.enable =
lib.mkEnableOption "USB mass storage driver";
};
config = {
hardware.usb.genode.storage.enable = config.genode.boot.storeBackend
== "usb";
hardware.usb.genode.enable = config.hardware.usb.genode.storage.enable;
hardware.genode.platform.policies =
lib.optional config.hardware.usb.genode.enable
(builtins.toFile ("usb.platform-policy.dhall") ''
let Genode = env:DHALL_GENODE
in Genode.Init.Config.Policy::{
, service = "Platform"
, label = Genode.Init.LabelSelector.prefix "usb_drv"
, content =
[ Genode.Prelude.XML.leaf
{ name = "pci", attributes = toMap { class = "USB" } }
]
}
'');
genode.core.basePackages = lib.optional config.hardware.usb.genode.enable
pkgs.genodePackages.usb_drv;
genode.init.children.usb_drv = lib.mkIf config.hardware.usb.genode.enable {
coreROMs = [ "usb_drv" ];
configFile = builtins.toFile "usb_drv.dhall" ''
let Genode = env:DHALL_GENODE
let XML = Genode.Prelude.XML
let Init = Genode.Init
let storageEnable = ${
if config.hardware.usb.genode.storage.enable then "True" else "False"
}
in Init.Child.flat
Init.Child.Attributes::{
, binary = "usb_drv"
, provides = [ "Block", "Usb" ]
, resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 }
, routes = [ Init.ServiceRoute.parent "IO_MEM" ]
, config = Init.Config::{
, attributes = toMap { uhci = "yes", ehci = "yes", xhci = "yes" }
, content =
if storageEnable
then [ XML.leaf
{ name = "storage", attributes = XML.emptyAttributes }
]
else [] : List XML.Type
, policies =
if storageEnable
then [ Init.Config.Policy::{
, service = "Block"
, label = Init.LabelSelector.prefix "store_fs"
}
]
else [] : List Init.Config.Policy.Type
}
}
'';
};
};
}