]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/arm/include/asm/percpu.h
core: Move cpu_suspended setting into arch_panic_stop
[jailhouse.git] / hypervisor / arch / arm / include / asm / percpu.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 #ifndef _JAILHOUSE_ASM_PERCPU_H
14 #define _JAILHOUSE_ASM_PERCPU_H
15
16 #include <jailhouse/types.h>
17 #include <asm/paging.h>
18
19 #define NUM_ENTRY_REGS                  6
20
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
25
26 #ifndef __ASSEMBLY__
27
28 #include <asm/cell.h>
29
30 struct per_cpu {
31         /* Keep these two in sync with defines above! */
32         u8 stack[PAGE_SIZE];
33         unsigned long linux_sp;
34
35         struct per_cpu *cpu_data;
36         unsigned int cpu_id;
37 //      u32 apic_id;
38         struct cell *cell;
39
40         u32 stats[JAILHOUSE_NUM_CPU_STATS];
41
42         unsigned long linux_reg[NUM_ENTRY_REGS];
43 //      unsigned long linux_ip;
44         bool initialized;
45
46         bool flush_caches;
47         bool shutdown_cpu;
48         int shutdown_state;
49         bool failed;
50 } __attribute__((aligned(PAGE_SIZE)));
51
52 #define DEFINE_PER_CPU_ACCESSOR(field)                                      \
53 static inline typeof(((struct per_cpu *)0)->field) this_##field(void)       \
54 {                                                                           \
55         typeof(((struct per_cpu *)0)->field) tmp = 0;                       \
56                                                                             \
57         return tmp;                                                         \
58 }
59
60 DEFINE_PER_CPU_ACCESSOR(cpu_data)
61 DEFINE_PER_CPU_ACCESSOR(cpu_id)
62 DEFINE_PER_CPU_ACCESSOR(cell)
63
64 static inline struct per_cpu *per_cpu(unsigned int cpu)
65 {
66         extern u8 __page_pool[];
67
68         return (struct per_cpu *)(__page_pool + (cpu << PERCPU_SIZE_SHIFT));
69 }
70
71 /* Validate defines */
72 #define CHECK_ASSUMPTION(assume)        ((void)sizeof(char[1 - 2*!(assume)]))
73
74 static inline void __check_assumptions(void)
75 {
76         struct per_cpu cpu_data;
77
78         CHECK_ASSUMPTION(sizeof(struct per_cpu) == (1 << PERCPU_SIZE_SHIFT));
79         CHECK_ASSUMPTION(sizeof(cpu_data.stack) == PERCPU_STACK_END);
80         CHECK_ASSUMPTION(__builtin_offsetof(struct per_cpu, linux_sp) ==
81                          PERCPU_LINUX_SP);
82 }
83 #endif /* !__ASSEMBLY__ */
84
85 #endif /* !_JAILHOUSE_ASM_PERCPU_H */