61bd4e5ca47f63bf2bbe881b0260302b90e5679c
[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         segdesc_t *gdt;
39 #endif
40
41         spinlock_t immed_amsg_lock;
42         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) immed_amsgs;
43         spinlock_t routine_amsg_lock;
44         struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) routine_amsgs;
45 }__attribute__((aligned(HW_CACHE_ALIGN)));
46
47 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
48
49 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
50 extern volatile uint32_t RO num_cpus;
51
52 /* SMP bootup functions */
53 void smp_boot(void);
54 void smp_idle(void) __attribute__((noreturn));
55 void smp_percpu_init(void); // this must be called by each core individually
56
57 /* SMP utility functions */
58 int smp_call_function_self(poly_isr_t handler, TV(t) data,
59                            handler_wrapper_t** wait_wrapper);
60 int smp_call_function_all(poly_isr_t handler, TV(t) data,
61                           handler_wrapper_t** wait_wrapper);
62 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
63                              handler_wrapper_t** wait_wrapper);
64 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
65
66 #endif /* !ROS_INC_SMP_H */