2 * Copyright (c) 2009 The Regents of the University of California
3 * Barret Rhoden <brho@cs.berkeley.edu>
4 * See LICENSE for details.
10 /* SMP related functions */
13 #include <ros/common.h>
14 #include <sys/queue.h>
30 /* Process management */
31 // cur_proc should be valid on all cores that are not management cores.
32 struct proc *cur_proc; /* which process context is loaded */
33 struct proc *owning_proc; /* proc owning the core / cur_ctx */
34 uint32_t owning_vcoreid; /* vcoreid of owning proc (if applicable */
35 struct user_context *cur_ctx; /* user ctx we came in on (can be 0) */
36 struct user_context actual_ctx; /* storage for cur_ctx */
37 uint32_t __ctx_depth; /* don't access directly. see trap.h. */
38 int __lock_depth_disabled; /* disables spinlock depth checking */
39 struct syscall *cur_sysc; /* ptr is into cur_proc's address space */
40 struct kthread *spare; /* useful when restarting */
41 struct timer_chain tchain; /* for the per-core alarm */
42 unsigned int lock_depth;
45 // held spin-locks. this will have to go elsewhere if multiple kernel
46 // threads can share a CPU.
47 // zra: Used by Ivy. Let me know if this should go elsewhere.
48 sharC_env_t sharC_env;
50 /* TODO: 64b (not sure if we'll need these at all */
56 spinlock_t immed_amsg_lock;
57 struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) immed_amsgs;
58 spinlock_t routine_amsg_lock;
59 struct kernel_msg_list NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) routine_amsgs;
60 }__attribute__((aligned(ARCH_CL_SIZE)));
62 /* Allows the kernel to figure out what process is running on this core. Can be
63 * used just like a pointer to a struct proc. */
64 #define current per_cpu_info[core_id()].cur_proc
65 /* Allows the kernel to figure out what *user* ctx is on this core's stack. Can
66 * be used just like a pointer to a struct user_context. Note the distinction
67 * between kernel and user contexts. The kernel always returns to its nested,
68 * interrupted contexts via iret/etc. We never do that for user contexts. */
69 #define current_ctx per_cpu_info[core_id()].cur_ctx
71 typedef struct per_cpu_info NTPTV(t) NTPTV(a0t) NTPTV(a1t) NTPTV(a2t) per_cpu_info_t;
73 extern per_cpu_info_t (RO per_cpu_info)[MAX_NUM_CPUS];
74 extern volatile uint32_t RO num_cpus;
76 /* SMP bootup functions */
78 void smp_idle(void) __attribute__((noreturn));
79 void smp_percpu_init(void); // this must be called by each core individually
80 void __arch_pcpu_init(uint32_t coreid); /* each arch has one of these */
82 /* SMP utility functions */
83 int smp_call_function_self(poly_isr_t handler, TV(t) data,
84 handler_wrapper_t** wait_wrapper);
85 int smp_call_function_all(poly_isr_t handler, TV(t) data,
86 handler_wrapper_t** wait_wrapper);
87 int smp_call_function_single(uint32_t dest, poly_isr_t handler, TV(t) data,
88 handler_wrapper_t** wait_wrapper);
89 int smp_call_wait(handler_wrapper_t*SAFE wrapper);
91 #endif /* !ROS_INC_SMP_H */