embox

Форк
0
76 строк · 1.5 Кб
1
/**
2
 * @file
3
 *
4
 * @date
5
 * @author
6
 */
7

8
#include <hal/clock.h>
9
#include <kernel/time/clock_source.h>
10
#include <kernel/irq.h>
11
#include <kernel/panic.h>
12
#include <xen/event_channel.h>
13
#include <xen_hypercall-x86_32.h>
14

15
#include <embox/unit.h>
16

17
#include <math.h>
18
#include <time.h>
19
#include <xen/xen.h>
20

21
extern shared_info_t xen_shared_info;
22

23
static int integratorcp_clock_setup(struct clock_source *cs) {
24
	return 0;
25
}
26

27
static struct time_event_device xen_event_device = {
28
	.name = "xen event device",
29
	.set_periodic = integratorcp_clock_setup,
30
	.irq_nr = -1
31
};
32

33
static cycle_t xen_tcd_read(struct clock_source *cs) {
34
	return 0;
35
}
36

37
static struct time_counter_device xen_tcd = {
38
	.cycle_hz = 1000,
39
	.read = xen_tcd_read,
40
};
41

42
static uint64_t system_time;
43

44
static uint64_t xen_time(void) {
45
	return xen_shared_info.vcpu_info[0].time.system_time;
46
}
47

48
static irq_return_t clock_handler(unsigned int irq_nr, void *dev_id) {
49
	uint64_t time = xen_time();
50

51
	const int n = (time - system_time) / NSEC_PER_MSEC;
52
	for (int i = 0; i < n; i++) {
53
		clock_tick_handler(dev_id);
54
	}
55

56
	return IRQ_HANDLED;
57
}
58

59
static int xen_clock_init(struct clock_source *cs) {
60

61
	evtchn_bind_virq_t op;
62

63
	op.virq = VIRQ_TIMER;
64
	op.vcpu = 0;
65
	if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op) != 0) {
66
		panic("Error has happened during timer initialization.\n");
67
	}
68
	xen_event_device.irq_nr = op.port;
69

70
	system_time = xen_time();
71

72
	return irq_attach(op.port, clock_handler, 0, cs, "xen clock irq");
73
}
74

75
CLOCK_SOURCE_DEF(xen,  xen_clock_init, NULL,
76
	&xen_event_device, &xen_tcd);
77

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.