2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2013
7 * Jan Kiszka <jan.kiszka@siemens.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #define HEAP_BASE 0x000000
14 #define FSEGMENT_BASE 0x0f0000
15 #define COMM_REGION_BASE 0x100000
17 #define INMATE_CS32 0x8
18 #define INMATE_CS64 0x10
19 #define INMATE_DS32 0x18
21 #define NS_PER_MSEC 1000000UL
22 #define NS_PER_SEC 1000000000UL
24 #define PAGE_SIZE (4 * 1024ULL)
26 #define HUGE_PAGE_SIZE (2 * 1024 * 1024ULL)
28 #define HUGE_PAGE_SIZE (4 * 1024 * 1024ULL)
30 #define PAGE_MASK (~(PAGE_SIZE - 1))
31 #define HUGE_PAGE_MASK (~(HUGE_PAGE_SIZE - 1))
33 #define X2APIC_ID 0x802
36 typedef signed char s8;
37 typedef unsigned char u8;
39 typedef signed short s16;
40 typedef unsigned short u16;
42 typedef signed int s32;
43 typedef unsigned int u32;
45 typedef signed long long s64;
46 typedef unsigned long long u64;
60 typedef enum { true=1, false=0 } bool;
62 static inline void cpu_relax(void)
64 asm volatile("rep; nop" : : : "memory");
67 static inline void outb(u8 v, u16 port)
69 asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
72 static inline u8 inb(u16 port)
75 asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
79 static inline u32 inl(u16 port)
82 asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
86 static inline u8 mmio_read8(void *address)
88 return *(volatile u8 *)address;
91 static inline u16 mmio_read16(void *address)
93 return *(volatile u16 *)address;
96 static inline u32 mmio_read32(void *address)
100 /* assembly-encoded to match the hypervisor MMIO parser support */
101 asm volatile("movl (%1),%0" : "=r" (value) : "r" (address));
105 static inline u64 mmio_read64(void *address)
107 return *(volatile u64 *)address;
110 static inline void mmio_write8(void *address, u8 value)
112 *(volatile u8 *)address = value;
115 static inline void mmio_write16(void *address, u16 value)
117 *(volatile u16 *)address = value;
120 static inline void mmio_write32(void *address, u32 value)
122 /* assembly-encoded to match the hypervisor MMIO parser support */
123 asm volatile("movl %0,(%1)" : : "r" (value), "r" (address));
126 static inline void mmio_write64(void *address, u64 value)
128 *(volatile u64 *)address = value;
131 static inline u64 read_msr(unsigned int msr)
135 asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
136 return low | ((u64)high << 32);
139 static inline void write_msr(unsigned int msr, u64 val)
143 : "c" (msr), "a" (val), "d" (val >> 32)
147 static inline unsigned int cpu_id(void)
149 return read_msr(X2APIC_ID);
152 #include <jailhouse/hypercall.h>
154 #define comm_region ((struct jailhouse_comm_region *)COMM_REGION_BASE)
156 extern unsigned int printk_uart_base;
157 void printk(const char *fmt, ...);
159 void *memset(void *s, int c, unsigned long n);
161 typedef void(*int_handler_t)(void);
164 void int_set_handler(unsigned int vector, int_handler_t handler);
166 void inmate_main(void);
168 unsigned long pm_timer_read(void);
169 unsigned long apic_timer_init(unsigned int vector);
170 void apic_timer_set(unsigned long timeout_ns);
172 enum map_type { MAP_CACHED, MAP_UNCACHED };
174 void *alloc(unsigned long size, unsigned long align);
175 void map_range(void *start, unsigned long size, enum map_type map_type);