diff --git a/packages/genodelabs/depot-targets.nix b/packages/genodelabs/depot-targets.nix index 216dfb6..e4ddcdc 100644 --- a/packages/genodelabs/depot-targets.nix +++ b/packages/genodelabs/depot-targets.nix @@ -78,7 +78,7 @@ in { noux.portInputs = [ libc ]; - platform_drv = { }; + platform_drv.patches = [ ./platform_drv.patch ]; posix = { buildInputs = [ self.libc ]; diff --git a/packages/genodelabs/platform_drv.patch b/packages/genodelabs/platform_drv.patch new file mode 100644 index 0000000..5e29960 --- /dev/null +++ b/packages/genodelabs/platform_drv.patch @@ -0,0 +1,132 @@ +From f747e139da4fda694363a27010cb6d62c3b1e941 Mon Sep 17 00:00:00 2001 +From: Emery Hemingway +Date: Tue, 10 Nov 2020 12:51:12 +0100 +Subject: [PATCH 1/2] drivers/platform/x86: move PCI capabilities to PCI report + sub-nodes + +--- + .../os/src/drivers/platform/spec/x86/pci_session_component.h | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +index a7439a224d..54b4492983 100644 +--- a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h ++++ b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +@@ -1110,7 +1110,9 @@ class Platform::Root : public Genode::Root_component + + for (Genode::uint16_t val = 0; cap; cap = val >> 8) { + val = config.read(config_access, cap, Platform::Device::ACCESS_16BIT); +- xml.attribute("cap", String<8>(Hex(val & 0xff))); ++ xml.node("cap", [&] () { ++ xml.attribute("type", String<8>(Hex(val & 0xff))); ++ }); + } + } catch (...) { + xml.attribute("cap", "failed to read"); +-- +2.28.0 + + +From 1a687e4b6d3544bf369a01aeb1d8bdffc27139b1 Mon Sep 17 00:00:00 2001 +From: Emery Hemingway +Date: Tue, 10 Nov 2020 14:46:59 +0100 +Subject: [PATCH 2/2] drivers/platform/x86: assign device by optional index + +Optionally assign PCI devices to sessions using indexes into the list of +devices matching that PCI class. This is configured by an "index" +attribute on nodes. An index is not valid if the +"pci" node does not also contain a "class" attribute. + +Fix #3946 +--- + repos/os/src/drivers/platform/spec/x86/README | 13 +++++++----- + .../platform/spec/x86/pci_session_component.h | 20 +++++++++++++++---- + 2 files changed, 24 insertions(+), 9 deletions(-) + +diff --git a/repos/os/src/drivers/platform/spec/x86/README b/repos/os/src/drivers/platform/spec/x86/README +index 83649f3b33..1c605e93fd 100644 +--- a/repos/os/src/drivers/platform/spec/x86/README ++++ b/repos/os/src/drivers/platform/spec/x86/README +@@ -59,11 +59,14 @@ Non PCI devices, as the PS2 controller are named by a "device" node in the polic + + + The first entry ('pci' or 'dev') of the policy node that matches will grant +-access of a device or device class to the client. Subsequent entries will not +-be checked. If a 'bus', 'device', 'function' triple was specified in one of the +-policies and in another policy a fuzzy pci class alias which would include +-the device specified by the triple, the device will not appear during device +-discovery by the client with the fuzzy pci class policy. ++access of a device or device class to the client. If a 'pci' policy specifies ++'class' and 'index' attributes then the device will be selected by an index ++into the list of devices matching that class. ++ ++If a 'bus', 'device', 'function' triple was specified in one of the policies ++and in another policy a fuzzy pci class alias which would include the device ++specified by the triple, the device will not appear during device discovery ++by the client with the fuzzy pci class policy. + + + By default the driver will try to use MSIs if the device and the used kernel +diff --git a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +index 54b4492983..b321df6fcb 100644 +--- a/repos/os/src/drivers/platform/spec/x86/pci_session_component.h ++++ b/repos/os/src/drivers/platform/spec/x86/pci_session_component.h +@@ -379,7 +379,7 @@ class Platform::Session_component : public Genode::Rpc_object + /** + * Check according session policy device usage + */ +- bool permit_device(Bdf const bdf, unsigned class_code) ++ bool permit_device(Bdf const bdf, unsigned class_code, unsigned &class_index) + { + using namespace Genode; + +@@ -404,6 +404,16 @@ class Platform::Session_component : public Genode::Rpc_object + if (class_sub_prog && (class_sub_prog ^ class_code) >> DONT_CHECK_PROGIF) + return; + ++ /* ++ *if policy specifies an index into devices ++ * of this class and it doesn't match - deny ++ */ ++ unsigned long policy_index = node.attribute_value("index", ~0UL); ++ if (policy_index != ~0UL) { ++ if (class_index++ != policy_index) ++ return; ++ } ++ + /* if this bdf is used by some policy - deny */ + if (find_dev_in_policy(bdf)) + return; +@@ -535,9 +545,9 @@ class Platform::Session_component : public Genode::Rpc_object + throw Genode::Service_denied(); + } + +- /* sanity check that 'class' is the only attribute */ ++ /* sanity check that 'class' and 'index' are the only attributes */ + try { +- node.attribute(1); ++ node.attribute(node.has_attribute("index") ? 2 : 1); + Genode::error("'", _label, "' - attributes beside 'class' detected"); + throw Genode::Service_denied(); + } +@@ -663,6 +673,7 @@ class Platform::Session_component : public Genode::Rpc_object + */ + Device_config config; + ++ unsigned class_index = 0; + while (true) { + function += 1; + if (!_pci_bus.find_next(bus, device, function, &config, +@@ -682,7 +693,8 @@ class Platform::Session_component : public Genode::Rpc_object + if (permit_device(Bdf { (unsigned)bus, + (unsigned)device, + (unsigned)function }, +- config.class_code())) ++ config.class_code(), ++ class_index)) + break; + } + +-- +2.28.0 +