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 #ifndef _JAILHOUSE_ASM_PERCPU_H
14 #define _JAILHOUSE_ASM_PERCPU_H
16 #include <jailhouse/types.h>
17 #include <asm/paging.h>
19 #define NUM_ENTRY_REGS 13
21 /* Keep in sync with struct per_cpu! */
22 #define PERCPU_SIZE_SHIFT 13
23 #define PERCPU_STACK_END PAGE_SIZE
24 #define PERCPU_LINUX_SP PERCPU_STACK_END
31 /* Keep these two in sync with defines above! */
33 unsigned long linux_sp;
34 unsigned long linux_ret;
35 unsigned long linux_flags;
37 struct per_cpu *cpu_data;
42 u32 stats[JAILHOUSE_NUM_CPU_STATS];
44 unsigned long linux_reg[NUM_ENTRY_REGS];
45 // unsigned long linux_ip;
52 } __attribute__((aligned(PAGE_SIZE)));
54 #define DEFINE_PER_CPU_ACCESSOR(field) \
55 static inline typeof(((struct per_cpu *)0)->field) this_##field(void) \
57 typeof(((struct per_cpu *)0)->field) tmp = 0; \
62 DEFINE_PER_CPU_ACCESSOR(cpu_data)
63 DEFINE_PER_CPU_ACCESSOR(cpu_id)
64 DEFINE_PER_CPU_ACCESSOR(cell)
66 static inline struct per_cpu *per_cpu(unsigned int cpu)
68 extern u8 __page_pool[];
70 return (struct per_cpu *)(__page_pool + (cpu << PERCPU_SIZE_SHIFT));
73 /* Validate defines */
74 #define CHECK_ASSUMPTION(assume) ((void)sizeof(char[1 - 2*!(assume)]))
76 static inline void __check_assumptions(void)
78 struct per_cpu cpu_data;
80 CHECK_ASSUMPTION(sizeof(struct per_cpu) == (1 << PERCPU_SIZE_SHIFT));
81 CHECK_ASSUMPTION(sizeof(cpu_data.stack) == PERCPU_STACK_END);
82 CHECK_ASSUMPTION(__builtin_offsetof(struct per_cpu, linux_sp) ==
85 #endif /* !__ASSEMBLY__ */
87 #endif /* !_JAILHOUSE_ASM_PERCPU_H */