81a906924efe5bb721e48ac74cff425507d9ed77
[linux-flexiantxendom0-3.2.10.git] / include / linux / smp.h
1 #ifndef __LINUX_SMP_H
2 #define __LINUX_SMP_H
3
4 /*
5  *      Generic SMP support
6  *              Alan Cox. <alan@redhat.com>
7  */
8
9 #include <linux/config.h>
10
11 #ifdef CONFIG_SMP
12
13 #include <linux/preempt.h>
14 #include <linux/kernel.h>
15 #include <linux/compiler.h>
16 #include <linux/thread_info.h>
17 #include <asm/smp.h>
18 #include <asm/bug.h>
19
20 /*
21  * main cross-CPU interfaces, handles INIT, TLB flush, STOP, etc.
22  * (defined in asm header):
23  */ 
24
25 /*
26  * stops all CPUs but the current one:
27  */
28 extern void smp_send_stop(void);
29
30 /*
31  * sends a 'reschedule' event to another CPU:
32  */
33 extern void FASTCALL(smp_send_reschedule(int cpu));
34
35
36 /*
37  * Prepare machine for booting other CPUs.
38  */
39 extern void smp_prepare_cpus(unsigned int max_cpus);
40
41 /*
42  * Bring a CPU up
43  */
44 extern int __cpu_up(unsigned int cpunum);
45
46 /*
47  * Final polishing of CPUs
48  */
49 extern void smp_cpus_done(unsigned int max_cpus);
50
51 /*
52  * Call a function on all other processors
53  */
54 extern int smp_call_function (void (*func) (void *info), void *info,
55                               int retry, int wait);
56
57 /*
58  * Call a function on all processors
59  */
60 static inline int on_each_cpu(void (*func) (void *info), void *info,
61                               int retry, int wait)
62 {
63         int ret = 0;
64
65         preempt_disable();
66         ret = smp_call_function(func, info, retry, wait);
67         func(info);
68         preempt_enable();
69         return ret;
70 }
71
72 /*
73  * True once the per process idle is forked
74  */
75 extern int smp_threads_ready;
76
77 extern volatile unsigned long smp_msg_data;
78 extern volatile int smp_src_cpu;
79 extern volatile int smp_msg_id;
80
81 #define MSG_ALL_BUT_SELF        0x8000  /* Assume <32768 CPU's */
82 #define MSG_ALL                 0x8001
83
84 #define MSG_INVALIDATE_TLB      0x0001  /* Remote processor TLB invalidate */
85 #define MSG_STOP_CPU            0x0002  /* Sent to shut down slave CPU's
86                                          * when rebooting
87                                          */
88 #define MSG_RESCHEDULE          0x0003  /* Reschedule request from master CPU*/
89 #define MSG_CALL_FUNCTION       0x0004  /* Call function on all other CPUs */
90
91 struct notifier_block;
92
93 /* Need to know about CPUs going up/down? */
94 extern int register_cpu_notifier(struct notifier_block *nb);
95 extern void unregister_cpu_notifier(struct notifier_block *nb);
96
97 int cpu_up(unsigned int cpu);
98
99 /*
100  * Mark the boot cpu "online" so that it can call console drivers in
101  * printk() and can access its per-cpu storage.
102  */
103 void smp_prepare_boot_cpu(void);
104
105 #else /* !SMP */
106
107 /*
108  *      These macros fold the SMP functionality into a single CPU system
109  */
110  
111 #define smp_processor_id()                      0
112 #define hard_smp_processor_id()                 0
113 #define smp_threads_ready                       1
114 #define smp_call_function(func,info,retry,wait) ({ 0; })
115 #define on_each_cpu(func,info,retry,wait)       ({ func(info); 0; })
116 static inline void smp_send_reschedule(int cpu) { }
117 static inline void smp_send_reschedule_all(void) { }
118 #define cpu_online_map                          1
119 #define cpu_online(cpu)                         ({ BUG_ON((cpu) != 0); 1; })
120 #define num_online_cpus()                       1
121 #define num_booting_cpus()                      1
122 #define cpu_possible(cpu)                       ({ BUG_ON((cpu) != 0); 1; })
123 #define smp_prepare_boot_cpu()                  do {} while (0)
124
125 struct notifier_block;
126
127 /* Need to know about CPUs going up/down? */
128 static inline int register_cpu_notifier(struct notifier_block *nb)
129 {
130         return 0;
131 }
132 static inline void unregister_cpu_notifier(struct notifier_block *nb)
133 {
134 }
135 #endif /* !SMP */
136
137 #define get_cpu()               ({ preempt_disable(); smp_processor_id(); })
138 #define put_cpu()               preempt_enable()
139 #define put_cpu_no_resched()    preempt_enable_no_resched()
140
141 #endif /* __LINUX_SMP_H */