diff --git a/repos/os/src/drivers/rtc/spec/x86/linux.cc b/repos/os/src/drivers/rtc/spec/x86/linux.cc index d42629815b..cd4a70448f 100644 --- a/repos/os/src/drivers/rtc/spec/x86/linux.cc +++ b/repos/os/src/drivers/rtc/spec/x86/linux.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -17,7 +17,7 @@ #include "rtc.h" -Rtc::Timestamp Rtc::get_time(void) +Rtc::Timestamp Rtc::get_time(Env &) { Timestamp ts { 0 }; diff --git a/repos/os/src/drivers/rtc/spec/x86/main.cc b/repos/os/src/drivers/rtc/spec/x86/main.cc index c580924214..78f9e1686b 100644 --- a/repos/os/src/drivers/rtc/spec/x86/main.cc +++ b/repos/os/src/drivers/rtc/spec/x86/main.cc @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -15,7 +15,6 @@ #include #include #include -#include #include "rtc.h" @@ -31,32 +30,41 @@ namespace Rtc { struct Rtc::Session_component : public Genode::Rpc_object { + Env &_env; + Timestamp current_time() override { - Timestamp ret = Rtc::get_time(); + Timestamp ret = Rtc::get_time(_env); return ret; } + + Session_component(Env &env) : _env(env) { } }; class Rtc::Root : public Genode::Root_component { + private: + + Env &_env; + protected: Session_component *_create_session(const char *args) { - return new (md_alloc()) Session_component(); + return new (md_alloc()) Session_component(_env); } public: - Root(Entrypoint &ep, Allocator &md_alloc) + Root(Env &env, Allocator &md_alloc) : - Genode::Root_component(&ep.rpc_ep(), &md_alloc) + Genode::Root_component(&env.ep().rpc_ep(), &md_alloc), + _env(env) { /* trigger initial RTC read */ - Rtc::get_time(); + Rtc::get_time(_env); } }; @@ -67,7 +75,7 @@ struct Rtc::Main Sliced_heap sliced_heap { env.ram(), env.rm() }; - Root root { env.ep(), sliced_heap }; + Root root { env, sliced_heap }; Main(Env &env) : env(env) { env.parent().announce(env.ep().manage(root)); } }; diff --git a/repos/os/src/drivers/rtc/spec/x86/rtc.cc b/repos/os/src/drivers/rtc/spec/x86/rtc.cc index f7e893c3f0..a8187f214a 100644 --- a/repos/os/src/drivers/rtc/spec/x86/rtc.cc +++ b/repos/os/src/drivers/rtc/spec/x86/rtc.cc @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2007-2015 Genode Labs GmbH + * Copyright (C) 2007-2017 Genode Labs GmbH * Copyright (C) 2012 Intel Corporation * * This file is part of the Genode OS framework, which is distributed @@ -14,13 +14,6 @@ */ /* Genode */ -#include -#include -#include -#include -#include -#include -#include #include #include "rtc.h" @@ -73,23 +66,12 @@ enum RTC }; -/* - * Our RTC port session - */ -static Io_port_connection & rtc_ports() -{ - static Io_port_connection inst(RTC_PORT_BASE, RTC_PORT_SIZE); - - return inst; -} - - -static inline unsigned cmos_read(unsigned char addr) +static inline unsigned cmos_read(Io_port_connection &rtc_ports, unsigned char addr) { unsigned char val; - rtc_ports().outb(RTC_PORT_ADDR, addr); + rtc_ports.outb(RTC_PORT_ADDR, addr); // iodelay(); - val = rtc_ports().inb(RTC_PORT_DATA); + val = rtc_ports.inb(RTC_PORT_DATA); // iodelay(); return val; } @@ -100,8 +82,13 @@ static inline unsigned cmos_read(unsigned char addr) #define BIN_TO_BCD(val) ((val) = (((val)/10) << 4) + (val) % 10) -Rtc::Timestamp Rtc::get_time(void) +Rtc::Timestamp Rtc::get_time(Env &env) { + /* + * Our RTC port session + */ + static Io_port_connection rtc_ports(env, RTC_PORT_BASE, RTC_PORT_SIZE); + unsigned year, mon, day, hour, min, sec; int i; @@ -112,22 +99,22 @@ Rtc::Timestamp Rtc::get_time(void) /* read RTC exactly on falling edge of update flag */ for (i = 0 ; i < 1000000 ; i++) - if (cmos_read(RTC_FREQ_SELECT) & RTC_UIP) break; + if (cmos_read(rtc_ports, RTC_FREQ_SELECT) & RTC_UIP) break; for (i = 0 ; i < 1000000 ; i++) - if (!(cmos_read(RTC_FREQ_SELECT) & RTC_UIP)) break; + if (!(cmos_read(rtc_ports, RTC_FREQ_SELECT) & RTC_UIP)) break; do { - sec = cmos_read(RTC_SECONDS); - min = cmos_read(RTC_MINUTES); - hour = cmos_read(RTC_HOURS); - day = cmos_read(RTC_DAY_OF_MONTH); - mon = cmos_read(RTC_MONTH); - year = cmos_read(RTC_YEAR); - } while (sec != cmos_read(RTC_SECONDS)); + sec = cmos_read(rtc_ports, RTC_SECONDS); + min = cmos_read(rtc_ports, RTC_MINUTES); + hour = cmos_read(rtc_ports, RTC_HOURS); + day = cmos_read(rtc_ports, RTC_DAY_OF_MONTH); + mon = cmos_read(rtc_ports, RTC_MONTH); + year = cmos_read(rtc_ports, RTC_YEAR); + } while (sec != cmos_read(rtc_ports, RTC_SECONDS)); /* convert BCD to binary format if needed */ - if (!(cmos_read(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { + if (!(cmos_read(rtc_ports, RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { BCD_TO_BIN(sec); BCD_TO_BIN(min); BCD_TO_BIN(hour); diff --git a/repos/os/src/drivers/rtc/spec/x86/rtc.h b/repos/os/src/drivers/rtc/spec/x86/rtc.h index c80b1f5d42..b287cda12e 100644 --- a/repos/os/src/drivers/rtc/spec/x86/rtc.h +++ b/repos/os/src/drivers/rtc/spec/x86/rtc.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2015 Genode Labs GmbH + * Copyright (C) 2015-2017 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. @@ -14,12 +14,14 @@ #ifndef _DRIVERS__RTC__SPEC__X86__RTC_H_ #define _DRIVERS__RTC__SPEC__X86__RTC_H_ -#include + +#include #include namespace Rtc { + using namespace Genode; - Timestamp get_time(); + Timestamp get_time(Env &env); } #endif /* _DRIVERS__RTC__SPEC__X86__RTC_H_ */