From d1cf9c86b8d8bebc77b7cd39480ee0f351b3aec4 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Thu, 15 Apr 2021 14:30:15 +0200 Subject: [PATCH] os: introduce device type in platform driver * Move "compatible" property value to "type" attribute * Turn device_by_property helper in Platform::Connection into device_by_type Fix #4074 --- .../drivers.config | 12 ++---- .../raw/drivers_nic-imx53_qsb/drivers.config | 3 +- .../drivers.config | 3 +- .../drivers_nic-imx7d_sabre/drivers.config | 6 +-- .../raw/drivers_nic-imx8q_evk/drivers.config | 3 +- repos/dde_linux/run/usb_hid_raw.run | 15 +++---- .../src/drivers/framebuffer/imx8/lx_emul.cc | 9 ++-- .../dde_linux/src/drivers/nic/fec/lx_emul.cc | 19 ++++----- .../src/drivers/usb_host/spec/arm/platform.cc | 7 ++++ .../drivers_managed-imx8q_evk/drivers.config | 18 +++----- .../raw/drivers_nic-rpi/drivers.config | 4 +- repos/libports/run/fatfs_blkio.run | 5 +-- repos/libports/run/libc_block.run | 5 +-- repos/libports/run/libc_filesystem_test.inc | 5 +-- .../libports/run/libc_vfs_filesystem_test.inc | 5 +-- repos/libports/run/libc_vfs_fs_test.inc | 5 +-- .../spec/arm/platform_session/connection.h | 23 ++++------ .../drivers_interactive-pbxa9/drivers.config | 12 ++---- .../raw/drivers_nic-pbxa9/drivers.config | 3 +- repos/os/run/sd_card.run | 5 +-- repos/os/run/sd_card_bench.run | 42 ++++++++++--------- .../os/src/drivers/framebuffer/pl11x/main.cc | 6 +-- .../platform/imx8mq/device_model_policy.cc | 3 +- .../src/drivers/platform/imx8mq/imx_device.h | 3 +- .../platform/rpi/device_model_policy.cc | 3 +- .../os/src/drivers/platform/rpi/rpi_device.h | 3 +- .../src/drivers/platform/spec/arm/device.cc | 8 +++- .../os/src/drivers/platform/spec/arm/device.h | 12 ++++-- .../platform/spec/arm/device_model_policy.cc | 3 +- 29 files changed, 112 insertions(+), 138 deletions(-) diff --git a/repos/dde_linux/recipes/raw/drivers_interactive-imx8q_evk/drivers.config b/repos/dde_linux/recipes/raw/drivers_interactive-imx8q_evk/drivers.config index 40fe0dd290..96a98635d6 100644 --- a/repos/dde_linux/recipes/raw/drivers_interactive-imx8q_evk/drivers.config +++ b/repos/dde_linux/recipes/raw/drivers_interactive-imx8q_evk/drivers.config @@ -68,7 +68,7 @@ - + @@ -84,12 +84,11 @@ rate="500000000"/> - - + - @@ -121,7 +119,7 @@ - + @@ -137,16 +135,14 @@ parent="system_pll1_div3" rate="266000000" driver_name="core"/> - - + - diff --git a/repos/dde_linux/recipes/raw/drivers_nic-imx53_qsb/drivers.config b/repos/dde_linux/recipes/raw/drivers_nic-imx53_qsb/drivers.config index 6674216403..f344baa8c4 100644 --- a/repos/dde_linux/recipes/raw/drivers_nic-imx53_qsb/drivers.config +++ b/repos/dde_linux/recipes/raw/drivers_nic-imx53_qsb/drivers.config @@ -20,10 +20,9 @@ - + - diff --git a/repos/dde_linux/recipes/raw/drivers_nic-imx6q_sabrelite/drivers.config b/repos/dde_linux/recipes/raw/drivers_nic-imx6q_sabrelite/drivers.config index 3cc66e957b..69cd6afeed 100644 --- a/repos/dde_linux/recipes/raw/drivers_nic-imx6q_sabrelite/drivers.config +++ b/repos/dde_linux/recipes/raw/drivers_nic-imx6q_sabrelite/drivers.config @@ -20,11 +20,10 @@ - + - diff --git a/repos/dde_linux/recipes/raw/drivers_nic-imx7d_sabre/drivers.config b/repos/dde_linux/recipes/raw/drivers_nic-imx7d_sabre/drivers.config index e32bfef50a..02591ac229 100644 --- a/repos/dde_linux/recipes/raw/drivers_nic-imx7d_sabre/drivers.config +++ b/repos/dde_linux/recipes/raw/drivers_nic-imx7d_sabre/drivers.config @@ -18,18 +18,16 @@ - + - - + - diff --git a/repos/dde_linux/recipes/raw/drivers_nic-imx8q_evk/drivers.config b/repos/dde_linux/recipes/raw/drivers_nic-imx8q_evk/drivers.config index f6579a06b9..0d4e5507c1 100644 --- a/repos/dde_linux/recipes/raw/drivers_nic-imx8q_evk/drivers.config +++ b/repos/dde_linux/recipes/raw/drivers_nic-imx8q_evk/drivers.config @@ -18,12 +18,11 @@ - + - diff --git a/repos/dde_linux/run/usb_hid_raw.run b/repos/dde_linux/run/usb_hid_raw.run index 917f394942..452f09ff44 100644 --- a/repos/dde_linux/run/usb_hid_raw.run +++ b/repos/dde_linux/run/usb_hid_raw.run @@ -60,7 +60,7 @@ if { [get_cmd_switch --autopilot] && proc platform_drv_config_non_x86 {} { if {[have_board imx8q_evk]} { return { - + @@ -76,7 +76,6 @@ proc platform_drv_config_non_x86 {} { rate="500000000"/> - @@ -85,20 +84,17 @@ proc platform_drv_config_non_x86 {} { } if {[have_board imx6q_sabrelite]} { return { - + - - + - - + - @@ -111,11 +107,10 @@ proc platform_drv_config_non_x86 {} { } if {[have_board rpi]} { return { - + - } diff --git a/repos/dde_linux/src/drivers/framebuffer/imx8/lx_emul.cc b/repos/dde_linux/src/drivers/framebuffer/imx8/lx_emul.cc index 1b91889734..7a25297a2c 100644 --- a/repos/dde_linux/src/drivers/framebuffer/imx8/lx_emul.cc +++ b/repos/dde_linux/src/drivers/framebuffer/imx8/lx_emul.cc @@ -74,22 +74,19 @@ Platform::Device_client & Lx_kit::platform_device(Device_id id) { if (id == DCSS) { static Platform::Device_client dcss { - platform_connection().device_by_property("compatible", - "nxp,imx8mq-dcss") }; + platform_connection().device_by_type("nxp,imx8mq-dcss") }; return dcss; } if (id == HDMI) { static Platform::Device_client hdmi { - platform_connection().device_by_property("compatible", - "fsl,imx8mq-hdmi") }; + platform_connection().device_by_type("fsl,imx8mq-hdmi") }; return hdmi; } if (id == MIPI) { static Platform::Device_client mipi { - platform_connection().device_by_property("compatible", - "fsl,imx8mq-mipi-dsi_drm") }; + platform_connection().device_by_type("fsl,imx8mq-mipi-dsi_drm") }; static bool update = true; if (update) { platform_connection().update(); diff --git a/repos/dde_linux/src/drivers/nic/fec/lx_emul.cc b/repos/dde_linux/src/drivers/nic/fec/lx_emul.cc index 38ebba643f..87e888c2ad 100644 --- a/repos/dde_linux/src/drivers/nic/fec/lx_emul.cc +++ b/repos/dde_linux/src/drivers/nic/fec/lx_emul.cc @@ -249,9 +249,8 @@ struct Fec : public Genode::List::Element { using namespace Genode; + phy_driver = xml.attribute_value("type", String()); xml.for_each_sub_node("property", [&] (Xml_node node) { - if (String("compatible") == node.attribute_value("name", String())) { - phy_driver = node.attribute_value("value", String()); } if (String("mdio_bus") == node.attribute_value("name", String())) { mdio_bus = node.attribute_value("value", String()); } if (String("mdio_reg") == node.attribute_value("name", String())) { @@ -292,9 +291,8 @@ struct Fec : public Genode::List::Element { using namespace Genode; + type = xml.attribute_value("type", String()); xml.for_each_sub_node("property", [&] (Xml_node node) { - if (String("compatible") == node.attribute_value("name", String())) { - type = node.attribute_value("value", String()); } if (String("mii") == node.attribute_value("name", String())) { phy_mode = node.attribute_value("value", String()); } if (String("phy") == node.attribute_value("name", String())) { @@ -376,14 +374,11 @@ int platform_driver_register(struct platform_driver * drv) xml.for_each_sub_node("device", [&] (Xml_node node) { String name = node.attribute_value("name", String()); - String compatible; - node.for_each_sub_node("property", [&] (Xml_node node) { - if (String("compatible") == node.attribute_value("name", String())) { - compatible = node.attribute_value("value", String()); }}); + String type = node.attribute_value("type", String()); - if (compatible == "fsl,imx6q-fec" || - compatible == "fsl,imx6sx-fec" || - compatible == "fsl,imx25-fec") { + if (type == "fsl,imx6q-fec" || + type == "fsl,imx6sx-fec" || + type == "fsl,imx25-fec") { Fec * f = new (Lx_kit::env().heap()) Fec(name, node, platform_connection().acquire_device(name.string())); @@ -396,7 +391,7 @@ int platform_driver_register(struct platform_driver * drv) return; } - if (compatible == "ethernet-phy-ieee802.3-c22") { + if (type == "ethernet-phy-ieee802.3-c22") { Fec::Mdio::Phy * p = new (Lx_kit::env().heap()) Fec::Mdio::Phy(name, node, platform_connection().acquire_device(name.string())); for (Fec * f = fec_devices().first(); f; f = f->next()) { diff --git a/repos/dde_linux/src/drivers/usb_host/spec/arm/platform.cc b/repos/dde_linux/src/drivers/usb_host/spec/arm/platform.cc index f88bd90919..03a26a37db 100644 --- a/repos/dde_linux/src/drivers/usb_host/spec/arm/platform.cc +++ b/repos/dde_linux/src/drivers/usb_host/spec/arm/platform.cc @@ -94,6 +94,7 @@ void lx_platform_device_init() xml.for_each_sub_node("device", [&] (Xml_node node) { Device::Name name = node.attribute_value("name", Device::Name()); + Device::Name type = node.attribute_value("type", Device::Name()); Platform::Device_client device { resource_env().platform.acquire_device(name.string()) }; @@ -138,6 +139,12 @@ void lx_platform_device_init() pdev->dev.of_node->dev = &pdev->dev; property ** prop = &pdev->dev.of_node->properties; + *prop = (property*) kzalloc(sizeof(property), 0); + (*prop)->name = "compatible"; + (*prop)->value = kzalloc(64,0); + copy_cstring((char*)(*prop)->value, type.string(), 64); + prop = &(*prop)->next; + node.for_each_sub_node("property", [&] (Xml_node node) { *prop = (property*) kzalloc(sizeof(property), 0); (*prop)->name = (char*)kzalloc(64,0); diff --git a/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config b/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config index 30a6f602ce..661f313fbb 100644 --- a/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config +++ b/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config @@ -103,7 +103,7 @@ - + @@ -119,12 +119,11 @@ rate="500000000"/> - - + - @@ -156,7 +154,7 @@ - + @@ -172,33 +170,29 @@ parent="system_pll1_div3" rate="266000000" driver_name="core"/> - - + - - + - - + - diff --git a/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config b/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config index 779d9a70de..37dc671624 100644 --- a/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config +++ b/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config @@ -18,13 +18,11 @@ - + - - diff --git a/repos/libports/run/fatfs_blkio.run b/repos/libports/run/fatfs_blkio.run index 22e62547ea..2fd784938a 100644 --- a/repos/libports/run/fatfs_blkio.run +++ b/repos/libports/run/fatfs_blkio.run @@ -100,12 +100,11 @@ append_if $use_sd_card_drv config { - + - - + diff --git a/repos/libports/run/libc_block.run b/repos/libports/run/libc_block.run index 63d2b01d27..a8ad25082b 100644 --- a/repos/libports/run/libc_block.run +++ b/repos/libports/run/libc_block.run @@ -84,12 +84,11 @@ append_if $use_sd_card_drv config { - + - - + diff --git a/repos/libports/run/libc_filesystem_test.inc b/repos/libports/run/libc_filesystem_test.inc index bf1a557ed6..d11676c3ba 100644 --- a/repos/libports/run/libc_filesystem_test.inc +++ b/repos/libports/run/libc_filesystem_test.inc @@ -121,12 +121,11 @@ append_if $use_sd_card_drv config { - + - - + diff --git a/repos/libports/run/libc_vfs_filesystem_test.inc b/repos/libports/run/libc_vfs_filesystem_test.inc index b128341586..a19b966540 100644 --- a/repos/libports/run/libc_vfs_filesystem_test.inc +++ b/repos/libports/run/libc_vfs_filesystem_test.inc @@ -128,12 +128,11 @@ append_if $use_sd_card_drv config { - + - - + diff --git a/repos/libports/run/libc_vfs_fs_test.inc b/repos/libports/run/libc_vfs_fs_test.inc index add6c8d39b..634477eeef 100644 --- a/repos/libports/run/libc_vfs_fs_test.inc +++ b/repos/libports/run/libc_vfs_fs_test.inc @@ -104,12 +104,11 @@ append_if $use_sd_card_drv config { - + - - + diff --git a/repos/os/include/spec/arm/platform_session/connection.h b/repos/os/include/spec/arm/platform_session/connection.h index c237e47649..515c7b2f29 100644 --- a/repos/os/include/spec/arm/platform_session/connection.h +++ b/repos/os/include/spec/arm/platform_session/connection.h @@ -101,8 +101,7 @@ class Platform::Connection : public Genode::Connection, return cap; } - Device_capability device_by_property(char const * property, - char const * value) + Device_capability device_by_type(char const * type) { using String = Genode::String<64>; @@ -113,23 +112,15 @@ class Platform::Connection : public Genode::Connection, /* already found a device? */ if (cap.valid()) { return; } - bool found = false; - node.for_each_sub_node("property", [&] (Xml_node node) { - if ((node.attribute_value("name", String()) == property) && - (node.attribute_value("value", String()) == value)) { - found = true; - } - }); + if (node.attribute_value("type", String()) != type) { + return; } - if (found) { - Device::Name name = node.attribute_value("name", - Device::Name()); - cap = acquire_device(name.string()); - } + Device::Name name = node.attribute_value("name", + Device::Name()); + cap = acquire_device(name.string()); }); if (!cap.valid()) { - error(__func__, ": property=", property, " value=", - value, " not found!"); + error(__func__, ": type=", type, " not found!"); error("device ROM content: ", xml); } }); diff --git a/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config b/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config index c2da674548..393097b875 100644 --- a/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config +++ b/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config @@ -21,26 +21,22 @@ - + - - + - - + - - + - diff --git a/repos/os/recipes/raw/drivers_nic-pbxa9/drivers.config b/repos/os/recipes/raw/drivers_nic-pbxa9/drivers.config index 32256e822d..fac8369821 100644 --- a/repos/os/recipes/raw/drivers_nic-pbxa9/drivers.config +++ b/repos/os/recipes/raw/drivers_nic-pbxa9/drivers.config @@ -21,10 +21,9 @@ - + - diff --git a/repos/os/run/sd_card.run b/repos/os/run/sd_card.run index 0922c15239..ea6aa391fe 100644 --- a/repos/os/run/sd_card.run +++ b/repos/os/run/sd_card.run @@ -24,9 +24,8 @@ install_config { - - - + + diff --git a/repos/os/run/sd_card_bench.run b/repos/os/run/sd_card_bench.run index 925c0fcace..f447dd164c 100644 --- a/repos/os/run/sd_card_bench.run +++ b/repos/os/run/sd_card_bench.run @@ -33,41 +33,46 @@ proc platform_drv {} { return platform_drv } -proc device_resources {} { +proc device {} { if {[have_board pbxa9]} { return { - - + + + } } if {[have_board imx8q_evk]} { return { - - - - - - + + + + + + + } } if {[have_board imx6q_sabrelite]} { return { - - - + + + + } } if {[have_board imx53_qsb] || [have_board imx53_qsb_tz]} { return { - - - + + + + } } if {[have_board rpi]} { return { - - + + + } } puts "\n Run script is not supported on this platform. \n"; @@ -96,8 +101,7 @@ install_config { - - } [device_resources] { + } [device] { diff --git a/repos/os/src/drivers/framebuffer/pl11x/main.cc b/repos/os/src/drivers/framebuffer/pl11x/main.cc index 3d3e214a73..6f430df966 100644 --- a/repos/os/src/drivers/framebuffer/pl11x/main.cc +++ b/repos/os/src/drivers/framebuffer/pl11x/main.cc @@ -85,10 +85,8 @@ struct Pl11x_driver::Main */ Platform::Connection _platform { _env }; - Platform::Device_client _pl11x_dev { - _platform.device_by_property("compatible", "arm,pl111") }; - Platform::Device_client _sp810_dev { - _platform.device_by_property("compatible", "arm,sp810") }; + Platform::Device_client _pl11x_dev { _platform.device_by_type("arm,pl111") }; + Platform::Device_client _sp810_dev { _platform.device_by_type("arm,sp810") }; Attached_dataspace _lcd_io_mem { _env.rm(), _pl11x_dev.io_mem_dataspace() }; Attached_dataspace _sys_mem { _env.rm(), diff --git a/repos/os/src/drivers/platform/imx8mq/device_model_policy.cc b/repos/os/src/drivers/platform/imx8mq/device_model_policy.cc index f534e21d48..900ef59e88 100644 --- a/repos/os/src/drivers/platform/imx8mq/device_model_policy.cc +++ b/repos/os/src/drivers/platform/imx8mq/device_model_policy.cc @@ -54,7 +54,8 @@ void Device_model::destroy_element(Device & dev) Device & Device_model::create_element(Genode::Xml_node node) { Device::Name name = node.attribute_value("name", Device::Name()); - return *(new (_env.heap) Imx_device(name)); + Device::Type type = node.attribute_value("type", Device::Type()); + return *(new (_env.heap) Imx_device(name, type)); } diff --git a/repos/os/src/drivers/platform/imx8mq/imx_device.h b/repos/os/src/drivers/platform/imx8mq/imx_device.h index cff0cf7ace..0c60225aef 100644 --- a/repos/os/src/drivers/platform/imx8mq/imx_device.h +++ b/repos/os/src/drivers/platform/imx8mq/imx_device.h @@ -58,7 +58,8 @@ class Driver::Imx_device : public Driver::Device bool acquire(Session_component &) override; void release(Session_component &) override; - Imx_device(Device::Name name) : Device(name) {} + Imx_device(Device::Name name, Device::Type type) + : Device(name, type) {} protected: diff --git a/repos/os/src/drivers/platform/rpi/device_model_policy.cc b/repos/os/src/drivers/platform/rpi/device_model_policy.cc index 3fcaa799fc..6b0d4791e3 100644 --- a/repos/os/src/drivers/platform/rpi/device_model_policy.cc +++ b/repos/os/src/drivers/platform/rpi/device_model_policy.cc @@ -49,7 +49,8 @@ void Device_model::destroy_element(Device & dev) Device & Device_model::create_element(Genode::Xml_node node) { Device::Name name = node.attribute_value("name", Device::Name()); - return *(new (_env.heap) Rpi_device(name)); + Device::Type type = node.attribute_value("type", Device::Type()); + return *(new (_env.heap) Rpi_device(name, type)); } diff --git a/repos/os/src/drivers/platform/rpi/rpi_device.h b/repos/os/src/drivers/platform/rpi/rpi_device.h index 92902eaedf..2e93a323f1 100644 --- a/repos/os/src/drivers/platform/rpi/rpi_device.h +++ b/repos/os/src/drivers/platform/rpi/rpi_device.h @@ -42,7 +42,8 @@ class Driver::Rpi_device : public Driver::Device bool acquire(Session_component &) override; void release(Session_component &) override; - Rpi_device(Device::Name name) : Device(name) {} + Rpi_device(Device::Name name, Device::Type type) + : Device(name, type) {} protected: diff --git a/repos/os/src/drivers/platform/spec/arm/device.cc b/repos/os/src/drivers/platform/spec/arm/device.cc index d9199ef05f..0e8e886400 100644 --- a/repos/os/src/drivers/platform/spec/arm/device.cc +++ b/repos/os/src/drivers/platform/spec/arm/device.cc @@ -17,6 +17,9 @@ Driver::Device::Name Driver::Device::name() const { return _name; } +Driver::Device::Type Driver::Device::type() const { return _type; } + + bool Driver::Device::acquire(Session_component & sc) { if (_session.valid() && _session != sc.label()) { return false; } @@ -125,6 +128,7 @@ void Driver::Device::report(Xml_generator & xml, Session_component & sc) xml.node("device", [&] () { xml.attribute("name", name()); + xml.attribute("type", type()); _io_mem_list.for_each([&] (Io_mem & io_mem) { xml.node("io_mem", [&] () { xml.attribute("id", io_mem_id++); @@ -166,8 +170,8 @@ Genode::size_t Driver::Device::_ram_quota_required() } -Driver::Device::Device(Name name) -: _name(name) { } +Driver::Device::Device(Name name, Type type) +: _name(name), _type(type) { } Driver::Device::~Device() diff --git a/repos/os/src/drivers/platform/spec/arm/device.h b/repos/os/src/drivers/platform/spec/arm/device.h index 8722eaf31d..14fcf99237 100644 --- a/repos/os/src/drivers/platform/spec/arm/device.h +++ b/repos/os/src/drivers/platform/spec/arm/device.h @@ -71,11 +71,13 @@ class Driver::Device : private List_model::Element }; using Name = Genode::String<64>; + using Type = Genode::String<64>; - Device(Name name); + Device(Name name, Type type); virtual ~Device(); Name name() const; + Type type() const; virtual bool acquire(Session_component &); virtual void release(Session_component &); @@ -100,6 +102,7 @@ class Driver::Device : private List_model::Element friend class List; Name _name; + Type _type; Platform::Session::Label _session {}; List_model _io_mem_list {}; List_model _irq_list {}; @@ -145,8 +148,11 @@ class Driver::Device_model : Device & create_element(Xml_node node); void update_element(Device & device, Xml_node node); static bool element_matches_xml_node(Device const & dev, - Genode::Xml_node n) { - return dev.name() == n.attribute_value("name", Device::Name()); } + Genode::Xml_node n) + { + return dev.name() == n.attribute_value("name", Device::Name()) && + dev.type() == n.attribute_value("type", Device::Type()); + } static bool node_is_element(Genode::Xml_node node) { return node.has_type("device"); } diff --git a/repos/os/src/drivers/platform/spec/arm/device_model_policy.cc b/repos/os/src/drivers/platform/spec/arm/device_model_policy.cc index 0321693b93..9442a8c895 100644 --- a/repos/os/src/drivers/platform/spec/arm/device_model_policy.cc +++ b/repos/os/src/drivers/platform/spec/arm/device_model_policy.cc @@ -41,7 +41,8 @@ void Device_model::destroy_element(Device & device) Device & Device_model::create_element(Genode::Xml_node node) { Device::Name name = node.attribute_value("name", Device::Name()); - return *(new (_env.heap) Device(name)); + Device::Type type = node.attribute_value("type", Device::Type()); + return *(new (_env.heap) Device(name, type)); }