]> rtime.felk.cvut.cz Git - jailhouse.git/blob - inmates/lib/x86/inmate.h
38c5151a95b7a50e53d77a1b34d770125335412c
[jailhouse.git] / inmates / lib / x86 / inmate.h
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #define FSEGMENT_BASE           0x0f0000
14 #define COMM_REGION_BASE        0x100000
15
16 #define INMATE_CS32             0x8
17 #define INMATE_CS64             0x10
18 #define INMATE_DS32             0x18
19
20 #define NS_PER_MSEC             1000000UL
21 #define NS_PER_SEC              1000000000UL
22
23 #define X2APIC_ID               0x802
24
25 #ifndef __ASSEMBLY__
26 typedef signed char s8;
27 typedef unsigned char u8;
28
29 typedef signed short s16;
30 typedef unsigned short u16;
31
32 typedef signed int s32;
33 typedef unsigned int u32;
34
35 typedef signed long long s64;
36 typedef unsigned long long u64;
37
38 typedef s8 __s8;
39 typedef u8 __u8;
40
41 typedef s16 __s16;
42 typedef u16 __u16;
43
44 typedef s32 __s32;
45 typedef u32 __u32;
46
47 typedef s64 __s64;
48 typedef u64 __u64;
49
50 typedef enum { true=1, false=0 } bool;
51
52 static inline void cpu_relax(void)
53 {
54         asm volatile("rep; nop" : : : "memory");
55 }
56
57 static inline void outb(u8 v, u16 port)
58 {
59         asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
60 }
61
62 static inline u8 inb(u16 port)
63 {
64         u8 v;
65         asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
66         return v;
67 }
68
69 static inline u32 inl(u16 port)
70 {
71         u32 v;
72         asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
73         return v;
74 }
75
76 static inline u64 read_msr(unsigned int msr)
77 {
78         u32 low, high;
79
80         asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
81         return low | ((u64)high << 32);
82 }
83
84 static inline void write_msr(unsigned int msr, u64 val)
85 {
86         asm volatile("wrmsr"
87                 : /* no output */
88                 : "c" (msr), "a" (val), "d" (val >> 32)
89                 : "memory");
90 }
91
92 static inline unsigned int cpu_id(void)
93 {
94         return read_msr(X2APIC_ID);
95 }
96
97 #include <jailhouse/hypercall.h>
98
99 #define comm_region     ((struct jailhouse_comm_region *)COMM_REGION_BASE)
100
101 extern unsigned int printk_uart_base;
102 void printk(const char *fmt, ...);
103
104 void *memset(void *s, int c, unsigned long n);
105
106 typedef void(*int_handler_t)(void);
107
108 void int_init(void);
109 void int_set_handler(unsigned int vector, int_handler_t handler);
110
111 void inmate_main(void);
112
113 unsigned long pm_timer_read(void);
114 unsigned long apic_timer_init(unsigned int vector);
115 void apic_timer_set(unsigned long timeout_ns);
116 #endif