From 421d2bed4032a45d68f388ceb07e3bb243465559 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Fri, 16 Apr 2021 15:08:21 +0200 Subject: [PATCH] platform driver: make device info XML optional * The device XML information dataspace is only provided, when the client's policy states `info="yes"` * The device XM information gets changed to include the physical resource names (I/O memory and IRQ addresses) instead of virtual ids and page offset Fix #4077 --- .../drivers.config | 6 +- .../raw/drivers_nic-imx53_qsb/drivers.config | 2 +- .../drivers.config | 2 +- .../drivers_nic-imx7d_sabre/drivers.config | 2 +- .../raw/drivers_nic-imx8q_evk/drivers.config | 2 +- repos/dde_linux/run/usb_hid_raw.run | 6 +- .../drivers_managed-imx8q_evk/drivers.config | 8 +- .../raw/drivers_nic-rpi/drivers.config | 2 +- .../spec/arm/platform_session/client.h | 3 + .../spec/arm/platform_session/connection.h | 25 ++---- .../spec/arm/platform_session/device.h | 6 +- .../arm/platform_session/platform_session.h | 11 ++- repos/os/include/virtio/mmio_device.h | 21 +++-- repos/os/include/virtio/pci_device.h | 7 ++ .../drivers_interactive-pbxa9/drivers.config | 12 +-- .../raw/drivers_nic-virt_qemu/drivers.config | 4 +- repos/os/run/tz_vmm.run | 2 +- repos/os/src/drivers/nic/virtio/component.h | 25 ++---- .../os/src/drivers/nic/virtio/mmio_device.cc | 63 +++----------- repos/os/src/drivers/nic/virtio/pci_device.cc | 7 +- .../src/drivers/nic/virtio/platform_device.h | 45 ---------- .../src/drivers/platform/spec/arm/device.cc | 16 ++-- .../os/src/drivers/platform/spec/arm/root.cc | 15 ++-- .../platform/spec/arm/session_component.cc | 16 +++- .../platform/spec/arm/session_component.h | 5 +- repos/os/src/drivers/ps2/pl050/main.cc | 11 ++- repos/os/src/drivers/sd_card/pl180/driver.cc | 4 +- repos/os/src/drivers/sd_card/pl180/driver.h | 2 +- .../os/src/drivers/touch/synaptics_dsx/i2c.h | 12 +-- .../drivers/touch/synaptics_dsx/irq_handler.h | 21 +++-- .../src/drivers/touch/synaptics_dsx/main.cc | 87 ++----------------- repos/os/src/drivers/virtdev_rom/main.cc | 5 +- 32 files changed, 145 insertions(+), 310 deletions(-) delete mode 100644 repos/os/src/drivers/nic/virtio/platform_device.h 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 78fb7b9668..d323b71be6 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 @@ -145,14 +145,14 @@ - - + + - + 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 f344baa8c4..90e1d72369 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 @@ -25,7 +25,7 @@ - + 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 69cd6afeed..7d344ba2f5 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 @@ -26,7 +26,7 @@ - + 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 02591ac229..55b75dd3fe 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 @@ -30,7 +30,7 @@ - + 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 0d4e5507c1..c6ff9ec18f 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 @@ -25,7 +25,7 @@ - + diff --git a/repos/dde_linux/run/usb_hid_raw.run b/repos/dde_linux/run/usb_hid_raw.run index 452f09ff44..ff3bd368d5 100644 --- a/repos/dde_linux/run/usb_hid_raw.run +++ b/repos/dde_linux/run/usb_hid_raw.run @@ -79,7 +79,7 @@ proc platform_drv_config_non_x86 {} { - + } } if {[have_board imx6q_sabrelite]} { @@ -98,7 +98,7 @@ proc platform_drv_config_non_x86 {} { - + @@ -112,7 +112,7 @@ proc platform_drv_config_non_x86 {} { - + } } return "" 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 c50b5daa6d..ff606b4cfb 100644 --- a/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config +++ b/repos/gems/recipes/raw/drivers_managed-imx8q_evk/drivers.config @@ -196,14 +196,14 @@ - - + + - + @@ -212,7 +212,7 @@ - + diff --git a/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config b/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config index 37dc671624..6b246e01fd 100644 --- a/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config +++ b/repos/gems/recipes/raw/drivers_nic-rpi/drivers.config @@ -23,7 +23,7 @@ - + diff --git a/repos/os/include/spec/arm/platform_session/client.h b/repos/os/include/spec/arm/platform_session/client.h index 5b3da31d9f..0dedda5ecc 100644 --- a/repos/os/include/spec/arm/platform_session/client.h +++ b/repos/os/include/spec/arm/platform_session/client.h @@ -31,6 +31,9 @@ struct Platform::Client : Genode::Rpc_client Capability acquire_device(Device_name const &name) override { return call(name); } + Capability acquire_single_device() override { + return call(); } + void release_device(Capability device) override { call(device); } diff --git a/repos/os/include/spec/arm/platform_session/connection.h b/repos/os/include/spec/arm/platform_session/connection.h index 5dbfd734f7..c9e128b6e1 100644 --- a/repos/os/include/spec/arm/platform_session/connection.h +++ b/repos/os/include/spec/arm/platform_session/connection.h @@ -76,6 +76,12 @@ class Platform::Connection : public Genode::Connection, return Client::acquire_device(name); }); } + Capability acquire_device() + { + return retry_with_upgrade(Ram_quota{6*1024}, Cap_quota{6}, [&] () { + return Client::acquire_single_device(); }); + } + Ram_dataspace_capability alloc_dma_buffer(size_t size, Cache cache) override { return retry_with_upgrade(Ram_quota{size}, Cap_quota{2}, [&] () { @@ -94,25 +100,6 @@ class Platform::Connection : public Genode::Connection, warning("Devices rom has invalid XML syntax"); } } - Capability device_by_index(unsigned idx) - { - Capability cap; - - with_xml([&] (Xml_node & xml) { - try { - Xml_node node = xml.sub_node(idx); - Device_name name = node.attribute_value("name", - Device_name()); - cap = acquire_device(name.string()); - } catch(Xml_node::Nonexistent_sub_node) { - error(__func__, ": invalid device index ", idx); - error("device ROM content: ", xml); - } - }); - - return cap; - } - Capability device_by_type(char const * type) { using String = Genode::String<64>; diff --git a/repos/os/include/spec/arm/platform_session/device.h b/repos/os/include/spec/arm/platform_session/device.h index 84ea085b4f..42277a4ac9 100644 --- a/repos/os/include/spec/arm/platform_session/device.h +++ b/repos/os/include/spec/arm/platform_session/device.h @@ -58,9 +58,9 @@ class Platform::Device : Interface, Noncopyable struct Index { unsigned value; }; - Device(Connection &platform, Index index) + explicit Device(Connection &platform) : - _platform(platform), _cap(platform.device_by_index(index.value)) + _platform(platform), _cap(platform.acquire_device()) { } struct Type { String<64> name; }; @@ -70,8 +70,6 @@ class Platform::Device : Interface, Noncopyable _platform(platform), _cap(platform.device_by_type(type.name.string())) { } - explicit Device(Connection &platform) : Device(platform, Index { 0 }) { } - ~Device() { _platform.release_device(_cap); } }; diff --git a/repos/os/include/spec/arm/platform_session/platform_session.h b/repos/os/include/spec/arm/platform_session/platform_session.h index b47715d9ab..c666c1c441 100644 --- a/repos/os/include/spec/arm/platform_session/platform_session.h +++ b/repos/os/include/spec/arm/platform_session/platform_session.h @@ -72,6 +72,11 @@ struct Platform::Session : Genode::Session */ virtual Capability acquire_device(Device_name const &name) = 0; + /** + * Acquire the first resp. single device of this session + */ + virtual Capability acquire_single_device() = 0; + /** * Free server-internal data structures representing the device * @@ -103,6 +108,8 @@ struct Platform::Session : Genode::Session GENODE_RPC_THROW(Rpc_acquire_device, Capability, acquire_device, GENODE_TYPE_LIST(Out_of_ram, Out_of_caps), Device_name const &); + GENODE_RPC_THROW(Rpc_acquire_single_device, Capability, + acquire_single_device, GENODE_TYPE_LIST(Out_of_ram, Out_of_caps)); GENODE_RPC(Rpc_release_device, void, release_device, Capability); GENODE_RPC_THROW(Rpc_alloc_dma_buffer, Ram_dataspace_capability, alloc_dma_buffer, @@ -112,8 +119,8 @@ struct Platform::Session : Genode::Session GENODE_RPC(Rpc_dma_addr, addr_t, dma_addr, Ram_dataspace_capability); - GENODE_RPC_INTERFACE(Rpc_devices_rom, Rpc_acquire_device, Rpc_release_device, - Rpc_alloc_dma_buffer, Rpc_free_dma_buffer, + GENODE_RPC_INTERFACE(Rpc_devices_rom, Rpc_acquire_device, Rpc_acquire_single_device, + Rpc_release_device, Rpc_alloc_dma_buffer, Rpc_free_dma_buffer, Rpc_dma_addr); }; diff --git a/repos/os/include/virtio/mmio_device.h b/repos/os/include/virtio/mmio_device.h index 2217dd4bb6..3ebfc466e6 100644 --- a/repos/os/include/virtio/mmio_device.h +++ b/repos/os/include/virtio/mmio_device.h @@ -14,9 +14,7 @@ #ifndef _INCLUDE__VIRTIO__MMIO_DEVICE_H_ #define _INCLUDE__VIRTIO__MMIO_DEVICE_H_ -#include -#include -#include +#include #include @@ -26,7 +24,7 @@ namespace Virtio { } -class Virtio::Device : Genode::Attached_dataspace, Genode::Mmio +class Virtio::Device : Platform::Device::Mmio { public: @@ -97,13 +95,13 @@ class Virtio::Device : Genode::Attached_dataspace, Genode::Mmio Device(Device const &) = delete; Device &operator = (Device const &) = delete; + Platform::Device::Irq _irq; + public: - Device(Genode::Env &env, - Genode::Io_mem_dataspace_capability io_mem_ds, - size_t offset) - : Attached_dataspace(env.rm(), io_mem_ds) - , Mmio((addr_t)local_addr() + offset) + Device(Platform::Device & device) + : + Platform::Device::Mmio(device), _irq(device, {0}) { if (read() != VIRTIO_MMIO_MAGIC) { throw Invalid_device(); } @@ -196,6 +194,11 @@ class Virtio::Device : Genode::Attached_dataspace, Genode::Mmio write(isr); return isr; } + + void irq_sigh(Signal_context_capability cap) { + _irq.sigh(cap); } + + void irq_ack() { _irq.ack(); } }; #endif /* _INCLUDE__VIRTIO__MMIO_DEVICE_H_ */ diff --git a/repos/os/include/virtio/pci_device.h b/repos/os/include/virtio/pci_device.h index 4c53d6b43c..dd662cf4da 100644 --- a/repos/os/include/virtio/pci_device.h +++ b/repos/os/include/virtio/pci_device.h @@ -15,6 +15,7 @@ #define _INCLUDE__VIRTIO__PCI_DEVICE_H_ #include +#include #include #include @@ -96,6 +97,7 @@ class Virtio::Device Genode::Env &_env; Platform::Device_client &_device; + Genode::Irq_session_client _irq { _device.irq(0) }; uint32_t _notify_offset_multiplier = 0; Genode::Constructible _cfg_common { }; Genode::Constructible _dev_config { }; @@ -277,6 +279,11 @@ class Virtio::Device uint32_t read_isr() { return _isr->read(); } + + void irq_sigh(Signal_context_capability cap) { + _irq.sigh(cap); } + + void irq_ack() { _irq.ack_irq(); } }; #endif /* _INCLUDE__VIRTIO__PCI_DEVICE_H_ */ diff --git a/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config b/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config index 393097b875..a15d4a446d 100644 --- a/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config +++ b/repos/os/recipes/raw/drivers_interactive-pbxa9/drivers.config @@ -29,26 +29,22 @@ - + - - - - + - + - - + diff --git a/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config b/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config index 49fd168e37..3da1efcdaf 100644 --- a/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config +++ b/repos/os/recipes/raw/drivers_nic-virt_qemu/drivers.config @@ -18,7 +18,7 @@ - + @@ -36,7 +36,7 @@ - + diff --git a/repos/os/run/tz_vmm.run b/repos/os/run/tz_vmm.run index b93aa60a07..381d515996 100644 --- a/repos/os/run/tz_vmm.run +++ b/repos/os/run/tz_vmm.run @@ -155,7 +155,7 @@ append_if $trusted_led config { - + diff --git a/repos/os/src/drivers/nic/virtio/component.h b/repos/os/src/drivers/nic/virtio/component.h index cffa11cee2..f5e65aadd4 100644 --- a/repos/os/src/drivers/nic/virtio/component.h +++ b/repos/os/src/drivers/nic/virtio/component.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -154,7 +153,6 @@ class Virtio_nic::Device : Noncopyable Hardware_features const _hw_features; Rx_queue_type _rx_vq; Tx_queue_type _tx_vq; - Irq_session_client _irq; void _init_virtio_device() { @@ -294,7 +292,6 @@ class Virtio_nic::Device : Noncopyable Device(Genode::Env &env, Virtio::Device &device, - Irq_session_capability irq_cap, Genode::Xml_node const &xml) try : _verbose { xml.attribute_value("verbose", false) }, @@ -305,8 +302,7 @@ class Virtio_nic::Device : Noncopyable _buf_size(RX_VQ, xml, "rx_buffer_size") }, _tx_vq { env.ram(), env.rm(), _vq_size(TX_VQ, xml, "tx_queue_size"), - _buf_size(TX_VQ, xml, "tx_buffer_size") }, - _irq { irq_cap } + _buf_size(TX_VQ, xml, "tx_buffer_size") } { } catch (Tx_queue_type::Invalid_buffer_size) { @@ -345,7 +341,7 @@ class Virtio_nic::Device : Noncopyable if ((reasons & IRQ_CONFIG_CHANGE) && _hw_features.link_status_available) { handle_link_state(); } - _irq.ack_irq(); + _device.irq_ack(); } bool tx_vq_write_pkt(char const *pkt_base, @@ -409,8 +405,8 @@ class Virtio_nic::Device : Noncopyable void init(Genode::Signal_context_capability irq_handler) { _setup_virtio_queues(); - _irq.sigh(irq_handler); - _irq.ack_irq(); + _device.irq_sigh(irq_handler); + _device.irq_ack(); } }; @@ -528,14 +524,13 @@ class Virtio_nic::Session_component : public Nic::Session_component, Session_component(Genode::Env &env, Genode::Allocator &rx_block_md_alloc, Virtio::Device &device, - Irq_session_capability irq_cap, Genode::Xml_node const &xml, Genode::size_t const tx_buf_size, Genode::size_t const rx_buf_size) : Nic::Session_component { tx_buf_size, rx_buf_size, Genode::CACHED, rx_block_md_alloc, env }, - Device { env, device, irq_cap, xml }, + Device { env, device, xml }, _irq_handler { env.ep(), *this, &Session_component::_handle_irq }, _link_up { link_state() } { @@ -562,7 +557,6 @@ class Virtio_nic::Root : public Genode::Root_component { env.ep(), md_alloc }, _env { env }, _device { device }, - _config_rom { config_rom }, - _irq_cap { irq_cap } + _config_rom { config_rom } { } }; @@ -681,10 +673,9 @@ class Genode::Uplink_client : public Virtio_nic::Device, Uplink_client(Env &env, Allocator &alloc, Virtio::Device &device, - Irq_session_capability irq_cap, Genode::Xml_node const &xml) : - Device { env, device, irq_cap, xml }, + Device { env, device, xml }, Uplink_client_base { env, alloc, read_mac_address() }, _irq_handler { env.ep(), *this, &Uplink_client::_handle_irq } { diff --git a/repos/os/src/drivers/nic/virtio/mmio_device.cc b/repos/os/src/drivers/nic/virtio/mmio_device.cc index b94e184eb8..b9a522c6ef 100644 --- a/repos/os/src/drivers/nic/virtio/mmio_device.cc +++ b/repos/os/src/drivers/nic/virtio/mmio_device.cc @@ -22,7 +22,6 @@ /* local includes */ #include "component.h" -#include "platform_device.h" namespace Virtio_mmio_nic { using namespace Genode; @@ -33,50 +32,14 @@ struct Virtio_mmio_nic::Main { struct Device_not_found : Genode::Exception { }; - struct Device_info { - using String = Genode::String<64>; - - String name {}; - size_t io_mem_offset = 0; - - Device_info(Platform::Connection & platform) { - bool found = false; - platform.with_xml([&] (Xml_node & xml) { - xml.for_each_sub_node("device", [&] (Xml_node node) { - if (found) return; - - node.for_each_sub_node("property", [&] (Xml_node node) { - if ((node.attribute_value("name", String()) == "type") && - (node.attribute_value("value", String()) == "nic")) { - found = true; } - }); - - if (!found) return; - - name = node.attribute_value("name", String()); - - node.for_each_sub_node("io_mem", [&] (Xml_node node) { - io_mem_offset = node.attribute_value("page_offset", 0); - }); - }); - }); - if (!found) { - error("No device was found"); - throw Device_not_found(); - } - } - }; - - Genode::Env &env; - Genode::Heap heap { env.ram(), env.rm() }; - Platform::Connection platform { env }; - Device_info info { platform }; - Platform::Device_client platform_device { platform.acquire_device(info.name.string()) }; - Virtio::Device virtio_device { env, platform_device.io_mem_dataspace(), - info.io_mem_offset }; - Attached_rom_dataspace config_rom { env, "config" }; - Genode::Constructible root { }; - Genode::Constructible uplink_client { }; + Env & env; + Heap heap { env.ram(), env.rm() }; + Platform::Connection platform { env }; + Platform::Device platform_device { platform, { "nic" } }; + Virtio::Device device { platform_device }; + Attached_rom_dataspace config_rom { env, "config" }; + Constructible root { }; + Constructible uplink_client { }; Main(Env &env) try : env(env) @@ -89,19 +52,13 @@ struct Virtio_mmio_nic::Main switch (mode) { case Nic_driver_mode::NIC_SERVER: - root.construct( - env, heap, virtio_device, platform_device.irq(0), - config_rom); - + root.construct( env, heap, device, config_rom); env.parent().announce(env.ep().manage(*root)); break; case Nic_driver_mode::UPLINK_CLIENT: - uplink_client.construct( - env, heap, virtio_device, platform_device.irq(0), - config_rom.xml()); - + uplink_client.construct( env, heap, device, config_rom.xml()); break; } } diff --git a/repos/os/src/drivers/nic/virtio/pci_device.cc b/repos/os/src/drivers/nic/virtio/pci_device.cc index a940a3c2d3..5fabc58e8a 100644 --- a/repos/os/src/drivers/nic/virtio/pci_device.cc +++ b/repos/os/src/drivers/nic/virtio/pci_device.cc @@ -62,9 +62,7 @@ struct Virtio_pci_nic::Main switch (mode) { case Nic_driver_mode::NIC_SERVER: - root.construct( - env, heap, virtio_device, platform_device.irq(0), - config_rom); + root.construct(env, heap, virtio_device, config_rom); env.parent().announce(env.ep().manage(*root)); break; @@ -72,8 +70,7 @@ struct Virtio_pci_nic::Main case Nic_driver_mode::UPLINK_CLIENT: uplink_client.construct( - env, heap, virtio_device, platform_device.irq(0), - config_rom.xml()); + env, heap, virtio_device, config_rom.xml()); break; } diff --git a/repos/os/src/drivers/nic/virtio/platform_device.h b/repos/os/src/drivers/nic/virtio/platform_device.h deleted file mode 100644 index dea93915b8..0000000000 --- a/repos/os/src/drivers/nic/virtio/platform_device.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * \brief Client stub for Platform::Device client - * \author Norman Feske - * \date 2021-04-15 - * - * The 'Device_client' is a mere compatibilty wrapper used until the - * driver has been coverted to the 'Platform::Device::Mmio' API. - */ - -/* - * Copyright (C) 2021 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _PLATFORM_DEVICE_H_ -#define _PLATFORM_DEVICE_H_ - -namespace Platform { struct Device_client; } - - -struct Platform::Device_client : Rpc_client -{ - Device_client(Capability cap) - : Rpc_client(cap) { } - - Irq_session_capability irq(unsigned id = 0) - { - return call(id); - } - - Io_mem_session_capability io_mem(unsigned id, Range &range, Cache cache) - { - return call(id, range, cache); - } - - Io_mem_dataspace_capability io_mem_dataspace(unsigned id = 0) - { - Range range { }; - return Io_mem_session_client(io_mem(id, range, UNCACHED)).dataspace(); - } -}; - -#endif /* _PLATFORM_DEVICE_H_ */ diff --git a/repos/os/src/drivers/platform/spec/arm/device.cc b/repos/os/src/drivers/platform/spec/arm/device.cc index a00dc47ef2..bca09a313e 100644 --- a/repos/os/src/drivers/platform/spec/arm/device.cc +++ b/repos/os/src/drivers/platform/spec/arm/device.cc @@ -124,25 +124,19 @@ Driver::Device::io_mem(unsigned idx, Range &range, Cache cache, Session_componen void Driver::Device::report(Xml_generator & xml, Session_component & sc) { - unsigned io_mem_id = 0; - unsigned irq_id = 0; - - static constexpr addr_t page_off_mask = (addr_t)((1 << 12) - 1); - 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++); - xml.attribute("size", io_mem.size); - xml.attribute("page_offset", - io_mem.base & page_off_mask); + xml.attribute("phys_addr", String<16>(Hex(io_mem.base))); + xml.attribute("size", String<16>(Hex(io_mem.size))); }); }); - _irq_list.for_each([&] (Irq &) { + _irq_list.for_each([&] (Irq & irq) { xml.node("irq", [&] () { - xml.attribute("id", irq_id++); }); + xml.attribute("number", irq.number); + }); }); _property_list.for_each([&] (Property & p) { xml.node("property", [&] () { diff --git a/repos/os/src/drivers/platform/spec/arm/root.cc b/repos/os/src/drivers/platform/spec/arm/root.cc index 770f4f7ac8..919f2c134f 100644 --- a/repos/os/src/drivers/platform/spec/arm/root.cc +++ b/repos/os/src/drivers/platform/spec/arm/root.cc @@ -48,17 +48,18 @@ Driver::Session_component * Driver::Root::_create_session(const char *args) Session_component * sc = nullptr; try { - sc = new (md_alloc()) Session_component(_env, - _sessions, - session_label_from_args(args), - session_resources_from_args(args), - session_diag_from_args(args)); + Session::Label const label { session_label_from_args(args) }; + Session_policy const policy { label, _env.config.xml() }; + + sc = new (md_alloc()) + Session_component(_env, _sessions, label, + session_resources_from_args(args), + session_diag_from_args(args), + policy.attribute_value("info", false)); - Session_policy const policy { sc->_label, _env.config.xml() }; policy.for_each_sub_node("device", [&] (Xml_node node) { sc->add(node.attribute_value("name", Driver::Device::Name())); }); } catch (Session_policy::No_policy_defined) { - if (sc) { Genode::destroy(md_alloc(), sc); } error("Invalid session request, no matching policy for ", "'", label_from_args(args).string(), "'"); throw Service_denied(); diff --git a/repos/os/src/drivers/platform/spec/arm/session_component.cc b/repos/os/src/drivers/platform/spec/arm/session_component.cc index d3eb348793..e383b757fd 100644 --- a/repos/os/src/drivers/platform/spec/arm/session_component.cc +++ b/repos/os/src/drivers/platform/spec/arm/session_component.cc @@ -20,6 +20,7 @@ using Driver::Session_component; void Session_component::produce_xml(Xml_generator &xml) { + if (!_info) { return; } for (Device_list_element * e = _device_list.first(); e; e = e->next()) { e->object()->report(xml); } } @@ -96,6 +97,16 @@ Session_component::acquire_device(Platform::Session::Device_name const &name) } +Genode::Capability +Session_component::acquire_single_device() +{ + Device_list_element * e = _device_list.first(); + if (!e) { return Capability(); } + + return acquire_device(e->object()->device()); +} + + void Session_component::release_device(Capability device_cap) { _env.env.ep().rpc_ep().apply(device_cap, [&] (Device_component * dc) { @@ -163,11 +174,12 @@ Session_component::Session_component(Driver::Env & env, Session_registry & registry, Label const & label, Resources const & resources, - Diag const & diag) + Diag const & diag, + bool const info) : Session_object(env.env.ep(), resources, label, diag), Session_registry::Element(registry, *this), Dynamic_rom_session::Xml_producer("devices"), - _env(env) + _env(env), _info(info) { /* * FIXME: As the ROM session does not propagate Out_of_* diff --git a/repos/os/src/drivers/platform/spec/arm/session_component.h b/repos/os/src/drivers/platform/spec/arm/session_component.h index 10cf05feb9..cdcad9bbad 100644 --- a/repos/os/src/drivers/platform/spec/arm/session_component.h +++ b/repos/os/src/drivers/platform/spec/arm/session_component.h @@ -45,7 +45,8 @@ class Driver::Session_component Session_registry & registry, Label const & label, Resources const & resources, - Diag const & diag); + Diag const & diag, + bool const info); ~Session_component(); Heap & heap(); @@ -69,6 +70,7 @@ class Driver::Session_component Rom_session_capability devices_rom() override; Device_capability acquire_device(Device_name const &) override; + Device_capability acquire_single_device() override; void release_device(Device_capability) override; Ram_dataspace_capability alloc_dma_buffer(size_t, Cache) override; void free_dma_buffer(Ram_dataspace_capability ram_cap) override; @@ -98,6 +100,7 @@ class Driver::Session_component List _buffer_list { }; Dynamic_rom_session _rom_session { _env.env.ep(), _env.env.ram(), _env.env.rm(), *this }; + bool const _info; /* * Noncopyable diff --git a/repos/os/src/drivers/ps2/pl050/main.cc b/repos/os/src/drivers/ps2/pl050/main.cc index 759b69f2f2..12c2f1a576 100644 --- a/repos/os/src/drivers/ps2/pl050/main.cc +++ b/repos/os/src/drivers/ps2/pl050/main.cc @@ -40,14 +40,13 @@ struct Ps2::Main using Device = Platform::Device; - Device _device_keyboard { _platform, Device::Index { 0 } }; - Device _device_mouse { _platform, Device::Index { 1 } }; + Device _device { _platform }; - Device::Mmio _mmio_keyboard { _device_keyboard }; - Device::Mmio _mmio_mouse { _device_mouse }; + Device::Mmio _mmio_keyboard { _device, { 0 } }; + Device::Mmio _mmio_mouse { _device, { 1 } }; - Device::Irq _irq_keyboard { _device_keyboard }; - Device::Irq _irq_mouse { _device_mouse }; + Device::Irq _irq_keyboard { _device, { 0 } }; + Device::Irq _irq_mouse { _device, { 1 } }; Pl050 _pl050 { _mmio_keyboard, _mmio_mouse }; diff --git a/repos/os/src/drivers/sd_card/pl180/driver.cc b/repos/os/src/drivers/sd_card/pl180/driver.cc index 5a855a783d..414723029e 100644 --- a/repos/os/src/drivers/sd_card/pl180/driver.cc +++ b/repos/os/src/drivers/sd_card/pl180/driver.cc @@ -141,8 +141,8 @@ void Driver::_write_data(unsigned length, Driver::Driver(Env &env, Platform::Connection & platform) : Block::Driver(env.ram()), - Platform::Device(platform, Platform::Device::Index { 0 }), - Platform::Device::Mmio(*this, Platform::Device::Mmio::Index { 0 }), + Platform::Device(platform), + Platform::Device::Mmio(*this, { 0 }), _platform(platform), _timer(env) { diff --git a/repos/os/src/drivers/sd_card/pl180/driver.h b/repos/os/src/drivers/sd_card/pl180/driver.h index 5e0fe00d6f..bf1f342f79 100644 --- a/repos/os/src/drivers/sd_card/pl180/driver.h +++ b/repos/os/src/drivers/sd_card/pl180/driver.h @@ -122,7 +122,7 @@ class Sd_card::Driver : public Block::Driver, { using Device = Platform::Device_interface; - Capability device_cap = platform.device_by_index(0); + Capability device_cap = platform.acquire_device(); Device::Range range { }; Io_mem_session_client io_mem { diff --git a/repos/os/src/drivers/touch/synaptics_dsx/i2c.h b/repos/os/src/drivers/touch/synaptics_dsx/i2c.h index ed096ad48c..6a9905b6bc 100644 --- a/repos/os/src/drivers/touch/synaptics_dsx/i2c.h +++ b/repos/os/src/drivers/touch/synaptics_dsx/i2c.h @@ -15,7 +15,7 @@ #define _DRIVERS__INPUT__SPEC__IMX53__I2C_H_ /* Genode includes */ -#include +#include #include /* local includes */ @@ -27,7 +27,7 @@ namespace I2c } -class I2c::I2c : Genode::Mmio +class I2c::I2c : Platform::Device::Mmio { private: @@ -64,7 +64,7 @@ class I2c::I2c : Genode::Mmio class No_ack : Genode::Exception {}; - Irq_handler & _irq_handler; + Irq_handler _irq_handler; void _busy() { while (!read()); } @@ -111,9 +111,9 @@ class I2c::I2c : Genode::Mmio public: - I2c(Genode::addr_t const base, Irq_handler &irq_handler) - : Mmio(base), - _irq_handler(irq_handler) + I2c(Genode::Env & env, Platform::Device & dev) + : Platform::Device::Mmio(dev, {0}), + _irq_handler(env, dev) { write(0); write(0); diff --git a/repos/os/src/drivers/touch/synaptics_dsx/irq_handler.h b/repos/os/src/drivers/touch/synaptics_dsx/irq_handler.h index 277ded979f..316fb9189c 100644 --- a/repos/os/src/drivers/touch/synaptics_dsx/irq_handler.h +++ b/repos/os/src/drivers/touch/synaptics_dsx/irq_handler.h @@ -15,39 +15,38 @@ #define _IRQ_HANDLER_H_ /* Genode includes */ -#include +#include class Irq_handler { private: - Genode::Env &_env; - Genode::Irq_session_client _irq; - Genode::Io_signal_handler _handler; - unsigned _sem_cnt = 1; void _handle() { _sem_cnt = 0; } + Platform::Device::Irq _irq; + Genode::Entrypoint & _ep; + Genode::Io_signal_handler _handler { _ep, *this, &Irq_handler::_handle }; + public: - Irq_handler(Genode::Env &env, Genode::Irq_session_capability irq) + Irq_handler(Genode::Env & env, Platform::Device & dev) : - _env(env), _irq(irq), - _handler(env.ep(), *this, &Irq_handler::_handle) + _irq(dev, { 0 }), _ep(env.ep()) { _irq.sigh(_handler); - _irq.ack_irq(); + _irq.ack(); } void wait() { _sem_cnt++; while (_sem_cnt > 0) - _env.ep().wait_and_dispatch_one_io_signal(); + _ep.wait_and_dispatch_one_io_signal(); } - void ack() { _irq.ack_irq(); } + void ack() { _irq.ack(); } }; #endif /* _IRQ_HANDLER_H_ */ diff --git a/repos/os/src/drivers/touch/synaptics_dsx/main.cc b/repos/os/src/drivers/touch/synaptics_dsx/main.cc index b9ccb355fd..4553e73ed1 100644 --- a/repos/os/src/drivers/touch/synaptics_dsx/main.cc +++ b/repos/os/src/drivers/touch/synaptics_dsx/main.cc @@ -23,42 +23,6 @@ using namespace Genode; - -namespace Platform { - - using Device_capability = Capability; - - struct Device_client; -} - - -/* - * Transitionally wrapper for accessing platform devices used until - * the migration to Platform::Device::Mmio API is completed. - */ -struct Platform::Device_client : Rpc_client -{ - Device_client(Capability cap) - : Rpc_client(cap) { } - - Irq_session_capability irq(unsigned id = 0) - { - return call(id); - } - - Io_mem_session_capability io_mem(unsigned id, Range &range, Cache cache) - { - return call(id, range, cache); - } - - Dataspace_capability io_mem_dataspace(unsigned id = 0) - { - Range range { }; - return Io_mem_session_client(io_mem(id, range, UNCACHED)).dataspace(); - } -}; - - struct Finger_data { uint8_t status; @@ -97,9 +61,7 @@ struct Synaptics enum Gpio_irq { IRQ = 135 }; Genode::Env &env; - Irq_handler _i2c_irq_handler; - Attached_dataspace _i2c_ds; - I2c::I2c _i2c { (addr_t)_i2c_ds.local_addr(), _i2c_irq_handler }; + I2c::I2c _i2c; Gpio::Connection _gpio { env, IRQ }; Irq_session_client _irq { _gpio.irq_session(Gpio::Session::LOW_LEVEL) }; Io_signal_handler _irq_dispatcher { env.ep(), *this, &Synaptics::_handle_irq }; @@ -153,11 +115,8 @@ struct Synaptics _irq.ack_irq(); } - Synaptics(Env &env, Dataspace_capability io_mem, - Irq_session_capability irq) - : env(env), - _i2c_irq_handler(env, irq), - _i2c_ds(env.rm(), io_mem) + Synaptics(Env &env, Platform::Device & i2c_dev) + : env(env), _i2c(env, i2c_dev) { /* set page 0 */ @@ -186,42 +145,12 @@ struct Synaptics struct Main { - Platform::Connection _platform_connection; - Constructible _synaptics { }; + Genode::Env & _env; + Platform::Connection _platform { _env }; + Platform::Device _device { _platform }; + Synaptics _synaptics { _env, _device }; - Main(Env &env) - : _platform_connection(env) - { - using namespace Platform; - - Device_capability cap; - try { - cap = _platform_connection.device_by_index(0); - } catch (...) { - error("Could not acquire device resources"); - return; - } - - if (cap.valid() == false) { - return; - } - - Device_client device { cap }; - - Dataspace_capability io_mem = device.io_mem_dataspace(); - if (io_mem.valid() == false) { - Genode::warning("No 'io_mem' node present ... skipping"); - return; - } - - Irq_session_capability irq = device.irq(); - if (irq.valid() == false) { - Genode::warning("No 'irq' node present ... skipping"); - return; - } - - _synaptics.construct(env, io_mem, irq); - } + Main(Env &env) : _env(env) { } }; void Component::construct(Genode::Env &env) { static Main main(env); } diff --git a/repos/os/src/drivers/virtdev_rom/main.cc b/repos/os/src/drivers/virtdev_rom/main.cc index f0e2865865..af83faa9f7 100644 --- a/repos/os/src/drivers/virtdev_rom/main.cc +++ b/repos/os/src/drivers/virtdev_rom/main.cc @@ -161,6 +161,7 @@ struct Virtdev_rom::Main static char name[DEVICE_NAME_LEN]; snprintf(name, sizeof(name), "%s%u", _name_for_id(id), device_type_idx[id - 1]++); xml.attribute("name", name); + xml.attribute("type", _name_for_id(id)); xml.node("io_mem", [&] () { xml.attribute("address", addr); xml.attribute("size", DEVICE_SIZE); @@ -168,10 +169,6 @@ struct Virtdev_rom::Main xml.node("irq", [&] () { xml.attribute("number", IRQ_BASE + idx); }); - xml.node("property", [&] () { - xml.attribute("name", "type"); - xml.attribute("value", _name_for_id(id)); - }); }); }