From 46cb20e2c08b4a6dbad879c14690766c29449e94 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Tue, 28 Jun 2016 14:45:49 +0200 Subject: [PATCH] sel4: add io_port service to core Fixes #1718 Issue #2044 --- repos/base-sel4/lib/mk/core.mk | 5 +- .../src/core/io_port_session_support.cc | 103 ++++++++++++++++++ repos/base-sel4/src/core/platform.cc | 3 + 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 repos/base-sel4/src/core/io_port_session_support.cc diff --git a/repos/base-sel4/lib/mk/core.mk b/repos/base-sel4/lib/mk/core.mk index 2c6e860a5..2018a41b6 100644 --- a/repos/base-sel4/lib/mk/core.mk +++ b/repos/base-sel4/lib/mk/core.mk @@ -16,6 +16,8 @@ SRC_CC += \ pd_upgrade_ram_quota.cc \ io_mem_session_component.cc \ io_mem_session_support.cc \ + io_port_session_component.cc \ + io_port_session_support.cc \ thread_start.cc \ platform_thread.cc \ platform_pd.cc \ @@ -55,7 +57,8 @@ vpath pd_upgrade_ram_quota.cc $(GEN_CORE_DIR) vpath region_map_component.cc $(GEN_CORE_DIR) vpath io_mem_session_component.cc $(GEN_CORE_DIR) vpath io_mem_session_support.cc $(GEN_CORE_DIR) -vpath platform_services.cc $(GEN_CORE_DIR) +vpath io_port_session_component.cc $(GEN_CORE_DIR)/spec/x86 +vpath platform_services.cc $(GEN_CORE_DIR)/spec/x86 vpath signal_source_component.cc $(GEN_CORE_DIR) vpath trace_session_component.cc $(GEN_CORE_DIR) vpath dataspace_component.cc $(GEN_CORE_DIR) diff --git a/repos/base-sel4/src/core/io_port_session_support.cc b/repos/base-sel4/src/core/io_port_session_support.cc new file mode 100644 index 000000000..ed680b6cd --- /dev/null +++ b/repos/base-sel4/src/core/io_port_session_support.cc @@ -0,0 +1,103 @@ +/* + * \brief Core implementation of the IO_PORT session interface + * \author Alexander Boettcher + * \date 2016-07-17 + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include + +/* core includes */ +#include + +#include + +using namespace Genode; + + +/************** + ** Port API ** + **************/ +unsigned char Io_port_session_component::inb(unsigned short address) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned char))) return 0; + + seL4_X86_IOPort_In8_t v = seL4_X86_IOPort_In8(seL4_CapIOPort, address); + if (v.error == seL4_NoError) + return v.result; + + Genode::error(__PRETTY_FUNCTION__, " failed ", v.error); + return 0; +} + + +unsigned short Io_port_session_component::inw(unsigned short address) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned short))) return 0; + + seL4_X86_IOPort_In16_t v = seL4_X86_IOPort_In16(seL4_CapIOPort, address); + if (v.error == seL4_NoError) + return v.result; + + Genode::error(__PRETTY_FUNCTION__, " failed ", v.error); + return 0; +} + + +unsigned Io_port_session_component::inl(unsigned short address) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned))) return 0; + + seL4_X86_IOPort_In32_t v = seL4_X86_IOPort_In32(seL4_CapIOPort, address); + if (v.error == seL4_NoError) + return v.result; + + Genode::error(__PRETTY_FUNCTION__, " failed ", v.error); + return 0; +} + + +void Io_port_session_component::outb(unsigned short address, unsigned char value) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned char))) return; + + int error = seL4_X86_IOPort_Out8(seL4_CapIOPort, address, value); + + if (error != seL4_NoError) + Genode::error(__PRETTY_FUNCTION__, " failed ", error); +} + + +void Io_port_session_component::outw(unsigned short address, unsigned short value) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned short))) return; + + int error = seL4_X86_IOPort_Out16(seL4_CapIOPort, address, value); + + if (error != seL4_NoError) + Genode::error(__PRETTY_FUNCTION__, " failed ", error); +} + + +void Io_port_session_component::outl(unsigned short address, unsigned value) +{ + /* check boundaries */ + if (!_in_bounds(address, sizeof(unsigned))) return; + + int error = seL4_X86_IOPort_Out32(seL4_CapIOPort, address, value); + + if (error != seL4_NoError) + Genode::error(__PRETTY_FUNCTION__, " failed ", error); +} diff --git a/repos/base-sel4/src/core/platform.cc b/repos/base-sel4/src/core/platform.cc index 7583411e1..aa8e5cd22 100644 --- a/repos/base-sel4/src/core/platform.cc +++ b/repos/base-sel4/src/core/platform.cc @@ -384,6 +384,9 @@ Platform::Platform() Core_cspace::CORE_VM_ID, _core_page_table_registry) { + /* I/O port allocator (only meaningful for x86) */ + _io_port_alloc.add_range(0, 0x10000); + /* * Log statistics about allocator initialization */