6106e64aac
This commit moves the headers residing in `repos/base/include/spec/*/drivers` to `repos/base/include/drivers/defs` or repos/base/include/drivers/uart` respectively. The first one contains definitions about board-specific MMIO iand RAM addresses, or IRQ lines. While the latter contains device driver code for UART devices. Those definitions are used by driver implementations in `repos/base-hw`, `repos/os`, and `repos/dde-linux`, which now need to include them more explicitely. This work is a step in the direction of reducing 'SPEC' identifiers overall. Ref #2403
102 lines
2.0 KiB
C++
102 lines
2.0 KiB
C++
/*
|
|
* \brief Timer driver for core
|
|
* \author Reto Buerki
|
|
* \date 2015-04-14
|
|
*/
|
|
|
|
/*
|
|
* 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 Affero General Public License version 3.
|
|
*/
|
|
|
|
#ifndef _CORE__SPEC__X86_64__MUEN__TIMER_H_
|
|
#define _CORE__SPEC__X86_64__MUEN__TIMER_H_
|
|
|
|
/* base includes */
|
|
#include <base/log.h>
|
|
#include <kernel/types.h>
|
|
|
|
/* core includes */
|
|
#include <board.h>
|
|
#include <sinfo_instance.h>
|
|
|
|
namespace Genode
|
|
{
|
|
/**
|
|
* Timer driver for core on Muen
|
|
*/
|
|
class Timer;
|
|
}
|
|
|
|
class Genode::Timer
|
|
{
|
|
private:
|
|
|
|
using time_t = Kernel::time_t;
|
|
|
|
enum { TIMER_DISABLED = ~0ULL };
|
|
|
|
uint64_t _tics_per_ms;
|
|
|
|
struct Subject_timed_event
|
|
{
|
|
uint64_t tsc_trigger;
|
|
uint8_t event_nr :5;
|
|
} __attribute__((packed));
|
|
|
|
struct Subject_timed_event * _event_page = 0;
|
|
struct Subject_timed_event * _guest_event_page = 0;
|
|
|
|
|
|
inline uint64_t rdtsc()
|
|
{
|
|
uint32_t lo, hi;
|
|
asm volatile("rdtsc" : "=a" (lo), "=d" (hi));
|
|
return (uint64_t)hi << 32 | lo;
|
|
}
|
|
|
|
class Invalid_region {};
|
|
|
|
public:
|
|
|
|
Timer();
|
|
|
|
static unsigned interrupt_id(int) {
|
|
return Board::TIMER_VECTOR_KERNEL; }
|
|
|
|
inline void start_one_shot(time_t const tics, unsigned)
|
|
{
|
|
const uint64_t t = rdtsc() + tics;
|
|
_event_page->tsc_trigger = t;
|
|
|
|
if (_guest_event_page)
|
|
_guest_event_page->tsc_trigger = t;
|
|
}
|
|
|
|
time_t tics_to_us(time_t const tics) const {
|
|
return (tics / _tics_per_ms) * 1000; }
|
|
|
|
time_t us_to_tics(time_t const us) const {
|
|
return (us / 1000) * _tics_per_ms; }
|
|
|
|
time_t max_value() { return (time_t)~0; }
|
|
|
|
time_t value(unsigned)
|
|
{
|
|
const uint64_t now = rdtsc();
|
|
if (_event_page->tsc_trigger != TIMER_DISABLED
|
|
&& _event_page->tsc_trigger > now) {
|
|
return _event_page->tsc_trigger - now;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void disable_pit(void) { }
|
|
};
|
|
|
|
namespace Kernel { class Timer : public Genode::Timer { }; }
|
|
|
|
#endif /* _CORE__SPEC__X86_64__MUEN__TIMER_H_ */
|