From 634f983088731b620bf10d89a8a1700ecf4bf33b Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 16 Jul 2014 13:46:49 +0200 Subject: [PATCH] inmates: Map Comm Region always at 0x100000 for inmates framework Standardize mapping and access to the Comm Region within the inmates framework. Reduces the work to be done for new inmates. We will move it higher once paging services are available so that larger inmates can be created. Signed-off-by: Jan Kiszka --- inmates/demos/x86/apic-demo.c | 15 ++++++--------- inmates/demos/x86/tiny-demo.c | 7 ++----- inmates/lib/x86/inmate.h | 17 ++++++++++------- inmates/lib/x86/pm-timer.c | 2 +- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/inmates/demos/x86/apic-demo.c b/inmates/demos/x86/apic-demo.c index b2231a9..1796204 100644 --- a/inmates/demos/x86/apic-demo.c +++ b/inmates/demos/x86/apic-demo.c @@ -42,9 +42,6 @@ static unsigned long apic_frequency; static unsigned long expected_time; static unsigned long min = -1, max; -static struct jailhouse_comm_region *comm_region = - (struct jailhouse_comm_region *)0x100000UL; - struct desc_table_reg { u16 limit; u64 base; @@ -77,7 +74,7 @@ void irq_handler(void) write_msr(X2APIC_EOI, APIC_EOI_ACK); - delta = read_pm_timer(comm_region) - expected_time; + delta = read_pm_timer() - expected_time; if (delta < min) min = delta; if (delta > max) @@ -86,7 +83,7 @@ void irq_handler(void) delta, min, max); expected_time += 100 * NS_PER_MSEC; - write_msr(X2APIC_TMICT, (expected_time - read_pm_timer(comm_region)) * + write_msr(X2APIC_TMICT, (expected_time - read_pm_timer()) * apic_frequency / NS_PER_SEC); } @@ -101,13 +98,13 @@ static void init_apic(void) write_msr(X2APIC_TDCR, 3); - start = read_pm_timer(comm_region); + start = read_pm_timer(); write_msr(X2APIC_TMICT, 0xffffffff); - while (read_pm_timer(comm_region) - start < 100 * NS_PER_MSEC) + while (read_pm_timer() - start < 100 * NS_PER_MSEC) cpu_relax(); - end = read_pm_timer(comm_region); + end = read_pm_timer(); tmr = read_msr(X2APIC_TMCCT); apic_frequency = (0xffffffff - tmr) * NS_PER_SEC / (end - start); @@ -124,7 +121,7 @@ static void init_apic(void) write_idtr(&dtr); write_msr(X2APIC_LVTT, APIC_TIMER_VECTOR); - expected_time = read_pm_timer(comm_region); + expected_time = read_pm_timer(); write_msr(X2APIC_TMICT, 1); asm volatile("sti"); diff --git a/inmates/demos/x86/tiny-demo.c b/inmates/demos/x86/tiny-demo.c index 985b6e9..92c9dc2 100644 --- a/inmates/demos/x86/tiny-demo.c +++ b/inmates/demos/x86/tiny-demo.c @@ -18,9 +18,6 @@ #define UART_BASE 0x2f8 #endif -static struct jailhouse_comm_region *comm_region = - (struct jailhouse_comm_region *)0x100000UL; - void inmate_main(void) { unsigned long long start, now; @@ -29,10 +26,10 @@ void inmate_main(void) printk_uart_base = UART_BASE; printk("Hello from this tiny cell!\n"); - start = read_pm_timer(comm_region); + start = read_pm_timer(); for (n = 0; n < 10; n++) { do { - now = read_pm_timer(comm_region); + now = read_pm_timer(); cpu_relax(); } while (now - start < 1000000000ULL); start += 1000000000ULL; diff --git a/inmates/lib/x86/inmate.h b/inmates/lib/x86/inmate.h index 85e1616..3aa3c26 100644 --- a/inmates/lib/x86/inmate.h +++ b/inmates/lib/x86/inmate.h @@ -10,11 +10,12 @@ * the COPYING file in the top-level directory. */ -#define FSEGMENT_BASE 0xf0000 +#define FSEGMENT_BASE 0x0f0000 +#define COMM_REGION_BASE 0x100000 -#define INMATE_CS32 0x8 -#define INMATE_CS64 0x10 -#define INMATE_DS32 0x18 +#define INMATE_CS32 0x8 +#define INMATE_CS64 0x10 +#define INMATE_DS32 0x18 #ifndef __ASSEMBLY__ typedef signed char s8; @@ -43,8 +44,6 @@ typedef u64 __u64; typedef enum { true=1, false=0 } bool; -#include - static inline void cpu_relax(void) { asm volatile("rep; nop" : : : "memory"); @@ -69,6 +68,10 @@ static inline u32 inl(u16 port) return v; } +#include + +#define comm_region ((struct jailhouse_comm_region *)COMM_REGION_BASE) + extern unsigned int printk_uart_base; void printk(const char *fmt, ...); @@ -79,5 +82,5 @@ void irq_handler(void); void inmate_main(void); -unsigned long read_pm_timer(struct jailhouse_comm_region *comm_region); +unsigned long read_pm_timer(void); #endif diff --git a/inmates/lib/x86/pm-timer.c b/inmates/lib/x86/pm-timer.c index 3c1c292..2264132 100644 --- a/inmates/lib/x86/pm-timer.c +++ b/inmates/lib/x86/pm-timer.c @@ -17,7 +17,7 @@ #define PM_TIMER_HZ 3579545 #define PM_TIMER_OVERFLOW ((0x1000000 * 1000000000ULL) / PM_TIMER_HZ) -unsigned long read_pm_timer(struct jailhouse_comm_region *comm_region) +unsigned long read_pm_timer(void) { static unsigned long last, overflows; unsigned long tmr; -- 2.39.2