]> rtime.felk.cvut.cz Git - jailhouse.git/blob - inmates/lib/x86/inmate.h
inmates: Factor our interrupt library services
[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 X2APIC_ID               0x802
21
22 #ifndef __ASSEMBLY__
23 typedef signed char s8;
24 typedef unsigned char u8;
25
26 typedef signed short s16;
27 typedef unsigned short u16;
28
29 typedef signed int s32;
30 typedef unsigned int u32;
31
32 typedef signed long long s64;
33 typedef unsigned long long u64;
34
35 typedef s8 __s8;
36 typedef u8 __u8;
37
38 typedef s16 __s16;
39 typedef u16 __u16;
40
41 typedef s32 __s32;
42 typedef u32 __u32;
43
44 typedef s64 __s64;
45 typedef u64 __u64;
46
47 typedef enum { true=1, false=0 } bool;
48
49 static inline void cpu_relax(void)
50 {
51         asm volatile("rep; nop" : : : "memory");
52 }
53
54 static inline void outb(u8 v, u16 port)
55 {
56         asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
57 }
58
59 static inline u8 inb(u16 port)
60 {
61         u8 v;
62         asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
63         return v;
64 }
65
66 static inline u32 inl(u16 port)
67 {
68         u32 v;
69         asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
70         return v;
71 }
72
73 static inline u64 read_msr(unsigned int msr)
74 {
75         u32 low, high;
76
77         asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
78         return low | ((u64)high << 32);
79 }
80
81 static inline void write_msr(unsigned int msr, u64 val)
82 {
83         asm volatile("wrmsr"
84                 : /* no output */
85                 : "c" (msr), "a" (val), "d" (val >> 32)
86                 : "memory");
87 }
88
89 static inline unsigned int cpu_id(void)
90 {
91         return read_msr(X2APIC_ID);
92 }
93
94 #include <jailhouse/hypercall.h>
95
96 #define comm_region     ((struct jailhouse_comm_region *)COMM_REGION_BASE)
97
98 extern unsigned int printk_uart_base;
99 void printk(const char *fmt, ...);
100
101 void *memset(void *s, int c, unsigned long n);
102
103 typedef void(*int_handler_t)(void);
104
105 void int_init(void);
106 void int_set_handler(unsigned int vector, int_handler_t handler);
107
108 void inmate_main(void);
109
110 unsigned long read_pm_timer(void);
111 #endif