2 * Jailhouse, a Linux-based partitioning hypervisor
4 * Copyright (c) Siemens AG, 2013-2016
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.
15 #define CMDLINE_BUFFER_SIZE 256
16 CMDLINE_BUFFER(CMDLINE_BUFFER_SIZE);
18 #define POLLUTE_CACHE_SIZE (512 * 1024)
20 #ifdef CONFIG_UART_OXPCIE952
21 #define UART_BASE 0xe010
23 #define UART_BASE 0x3f8
26 #define UART_LSR_THRE 0x20
27 #define UART_IDLE_LOOPS 100
29 #define APIC_TIMER_VECTOR 32
31 static unsigned long expected_time;
32 static unsigned long min = -1, max;
34 static void irq_handler(void)
38 delta = tsc_read() - expected_time;
43 printk("Timer fired, jitter: %6ld ns, min: %6ld ns, max: %6ld ns\n",
46 expected_time += 100 * NS_PER_MSEC;
47 apic_timer_set(expected_time - tsc_read());
50 static void init_apic(void)
52 unsigned long apic_freq_khz;
55 int_set_handler(APIC_TIMER_VECTOR, irq_handler);
57 apic_freq_khz = apic_timer_init(APIC_TIMER_VECTOR);
58 printk("Calibrated APIC frequency: %lu kHz\n", apic_freq_khz);
60 expected_time = tsc_read() + NS_PER_MSEC;
61 apic_timer_set(NS_PER_MSEC);
66 static void pollute_cache(void)
68 char *mem = (char *)HEAP_BASE;
69 unsigned long cpu_cache_line_size, ebx;
72 asm volatile("cpuid" : "=b" (ebx) : "a" (1)
73 : "rcx", "rdx", "memory");
74 cpu_cache_line_size = (ebx & 0xff00) >> 5;
76 for (n = 0; n < POLLUTE_CACHE_SIZE; n += cpu_cache_line_size)
80 void inmate_main(void)
82 bool allow_terminate = false;
83 bool terminate = false;
84 unsigned long tsc_freq;
88 printk_uart_base = UART_BASE;
90 for (n = 0; n < UART_IDLE_LOOPS; n++)
91 if (!(inb(UART_BASE + UART_LSR) & UART_LSR_THRE))
93 } while (n < UART_IDLE_LOOPS);
95 comm_region->cell_state = JAILHOUSE_CELL_RUNNING_LOCKED;
97 cache_pollution = cmdline_parse_bool("pollute_cache");
99 printk("Cache pollution enabled\n");
101 tsc_freq = tsc_init();
102 printk("Calibrated TSC frequency: %lu.%03u kHz\n", tsc_freq / 1000,
113 switch (comm_region->msg_to_cell) {
114 case JAILHOUSE_MSG_SHUTDOWN_REQUEST:
115 if (!allow_terminate) {
116 printk("Rejecting first shutdown request - "
118 jailhouse_send_reply_from_cell(comm_region,
119 JAILHOUSE_MSG_REQUEST_DENIED);
120 allow_terminate = true;
125 jailhouse_send_reply_from_cell(comm_region,
126 JAILHOUSE_MSG_UNKNOWN);
131 printk("Stopped APIC demo\n");
132 comm_region->cell_state = JAILHOUSE_CELL_SHUT_DOWN;