From 858a0124b078b5e601ea377bd89f933d5e96963a Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 19 Dec 2020 15:23:35 +0100 Subject: [PATCH] nixos: use usb_block_drv for USB storage --- nixos-modules/hardware.nix | 96 +++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/nixos-modules/hardware.nix b/nixos-modules/hardware.nix index 36e458f..ae43eeb 100644 --- a/nixos-modules/hardware.nix +++ b/nixos-modules/hardware.nix @@ -36,8 +36,17 @@ with lib; hardware.genode = { - usb.enable = lib.mkEnableOption "USB driver"; - usb.storage.enable = lib.mkEnableOption "USB mass storage driver"; + usb = { + + enable = lib.mkEnableOption "USB driver"; + storage.enable = lib.mkEnableOption "USB mass storage driver"; + + ehciSupport = lib.mkEnableOption "EHCI support" // { default = true; }; + ohciSupport = lib.mkEnableOption "OHCI support" // { default = true; }; + uhciSupport = lib.mkEnableOption "UHCI support" // { default = false; }; + xhciSupport = lib.mkEnableOption "XHCI support" // { default = true; }; + + }; framebuffer = { enable = lib.mkEnableOption "framebuffer driver"; @@ -305,7 +314,10 @@ with lib; ''; }; - genode.core.children.usb_drv = mkIf config.hardware.genode.usb.enable { + genode.core.children.usb_drv = let + cfg = config.hardware.genode.usb; + toYesNo = b: if b then "yes" else "no"; + in mkIf cfg.enable { inputs = [ pkgs.genodePackages.usb_drv ]; configFile = builtins.toFile "usb_drv.dhall" '' let Genode = env:DHALL_GENODE @@ -314,36 +326,74 @@ with lib; let Init = Genode.Init - let storageEnable = ${ - if config.hardware.genode.usb.storage.enable then "True" else "False" - } - in Init.Child.flat Init.Child.Attributes::{ , binary = "usb_drv" , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 12 } + , romReports = let local = "devices" in [ { local, route = local } ] , 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 "part_block" + , config = + let storagePolicy = + Init.Config.Policy::{ + , service = "Usb" + , label = Init.LabelSelector.prefix "usb_block_drv" + , attributes = toMap { class = "8" } + , diag = Some True + } + + in Init.Config::{ + , attributes = toMap + { ehci = "${toYesNo cfg.ehciSupport}" + , ohci = "${toYesNo cfg.ohciSupport}" + , uhci = "${toYesNo cfg.uhciSupport}" + , xhci = "${toYesNo cfg.xhciSupport}" + } + , content = + [ XML.element + { name = "raw" + , attributes = XML.emptyAttributes + , content = + [ XML.leaf + { name = "report" + , attributes = toMap { devices = "yes" } + } + , Init.Config.Policy.toXML storagePolicy + ] } - ] - else [] : List Init.Config.Policy.Type - } + ] + , policies = [ storagePolicy ] + } } ''; }; + genode.core.children.usb_block_drv = + mkIf config.hardware.genode.usb.storage.enable { + inputs = [ pkgs.genodePackages.usb_block_drv ]; + configFile = builtins.toFile "usb_block_drv.dhall" '' + let Genode = env:DHALL_GENODE + + let XML = Genode.Prelude.XML + + let Init = Genode.Init + + in Init.Child.flat + Init.Child.Attributes::{ + , binary = "usb_block_drv" + , resources = Init.Resources::{ caps = 256, ram = Genode.units.MiB 4 } + , config = Init.Config::{ + , attributes = toMap { writeable = "yes" } + , policies = + [ Init.Config.Policy::{ + , service = "Block" + , label = Init.LabelSelector.prefix "part_block" + } + ] + } + } + ''; + }; + genode.core.children.fb_drv = mkIf config.hardware.genode.framebuffer.enable { inputs = with pkgs.genodePackages;