x86: decouples the GDT/TS/ETC from the stack
[akaros.git] / kern / include / smp.h
1 /*
2  * Copyright (c) 2009 The Regents of the University of California
3  * Barret Rhoden <brho@cs.berkeley.edu>
4  * See LICENSE for details.
5  */
6
7 #ifndef ROS_INC_SMP_H
8 #define ROS_INC_SMP_H
9
10 /* SMP related functions */
11
12 #include <arch/smp.h>
13 #include <ros/common.h>
14 #include <sys/queue.h>
15 #include <trap.h>
16 #include <atomic.h>
17 #include <process.h>
18 #include <syscall.h>
19
20 #ifdef __SHARC__
21 typedef sharC_env_t;
22 #endif
23
24 struct per_cpu_info {
25         spinlock_t lock;
26         // cur_proc should be valid on all cores that are not management cores.
27         struct proc *cur_proc;
28         trapframe_t *cur_tf;
29         struct sys_return cur_ret;
30
31 #ifdef __SHARC__
32         // held spin-locks. this will have to go elsewhere if multiple kernel
33         // threads can share a CPU.
34         // zra: Used by Ivy. Let me know if this should go elsewhere.
35         sharC_env_t sharC_env;
36 #endif
37 #ifdef __i386__
38         taskstate_t *tss;
39         segdesc_t *gdt;
40 #endif
41
42         spinlock_t immed_amsg_lock;
43         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) immed_amsgs;
44         spinlock_t routine_amsg_lock;
45         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) routine_amsgs;
46 }__attribute__((aligned(HW_CACHE_ALIGN)));
47
48 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
49
50 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
51 extern volatile uint32_t RO num_cpus;
52
53 /* SMP bootup functions */
54 void smp_boot(void);
55 void smp_idle(void) __attribute__((noreturn));
56 void smp_percpu_init(void); // this must be called by each core individually
57
58 /* SMP utility functions */
59 int smp_call_function_self(poly_isr_t handler, TV(t) data,
60                            handler_wrapper_t** wait_wrapper);
61 int smp_call_function_all(poly_isr_t handler, TV(t) data,
62                           handler_wrapper_t** wait_wrapper);
63 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
64                              handler_wrapper_t** wait_wrapper);
65 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
66
67 #endif /* !ROS_INC_SMP_H */