c99411e8fbc5ca9754c92a68444fc6bd61e280c7
[linux-flexiantxendom0-3.2.10.git] / include / asm-mips / smp.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General
3  * Public License.  See the file "COPYING" in the main directory of this
4  * archive for more details.
5  *
6  * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
7  * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
8  * Copyright (C) 2000, 2001, 2002 Ralf Baechle
9  * Copyright (C) 2000, 2001 Broadcom Corporation
10  */
11 #ifndef __ASM_SMP_H
12 #define __ASM_SMP_H
13
14 #include <linux/config.h>
15
16 #ifdef CONFIG_SMP
17
18 #include <linux/bitops.h>
19 #include <linux/threads.h>
20 #include <asm/atomic.h>
21
22 #define smp_processor_id()      (current_thread_info()->cpu)
23
24 /* Map from cpu id to sequential logical cpu number.  This will only
25    not be idempotent when cpus failed to come on-line.  */
26 extern int __cpu_number_map[NR_CPUS];
27 #define cpu_number_map(cpu)  __cpu_number_map[cpu]
28
29 /* The reverse map from sequential logical cpu number to cpu id.  */
30 extern int __cpu_logical_map[NR_CPUS];
31 #define cpu_logical_map(cpu)  __cpu_logical_map[cpu]
32
33 #define NO_PROC_ID      (-1)
34
35 struct call_data_struct {
36         void            (*func)(void *);
37         void            *info;
38         atomic_t        started;
39         atomic_t        finished;
40         int             wait;
41 };
42
43 extern struct call_data_struct *call_data;
44
45 #define SMP_RESCHEDULE_YOURSELF 0x1     /* XXX braindead */
46 #define SMP_CALL_FUNCTION       0x2
47
48 #if (NR_CPUS <= _MIPS_SZLONG)
49
50 typedef unsigned long   cpumask_t;
51
52 #define CPUMASK_CLRALL(p)       (p) = 0
53 #define CPUMASK_SETB(p, bit)    (p) |= 1UL << (bit)
54 #define CPUMASK_CLRB(p, bit)    (p) &= ~(1UL << (bit))
55 #define CPUMASK_TSTB(p, bit)    ((p) & (1UL << (bit)))
56
57 #elif (NR_CPUS <= 128)
58
59 /*
60  * The foll should work till 128 cpus.
61  */
62 #define CPUMASK_SIZE            (NR_CPUS/_MIPS_SZLONG)
63 #define CPUMASK_INDEX(bit)      ((bit) >> 6)
64 #define CPUMASK_SHFT(bit)       ((bit) & 0x3f)
65
66 typedef struct {
67         unsigned long   _bits[CPUMASK_SIZE];
68 } cpumask_t;
69
70 #define CPUMASK_CLRALL(p)       (p)._bits[0] = 0, (p)._bits[1] = 0
71 #define CPUMASK_SETB(p, bit)    (p)._bits[CPUMASK_INDEX(bit)] |= \
72                                         (1UL << CPUMASK_SHFT(bit))
73 #define CPUMASK_CLRB(p, bit)    (p)._bits[CPUMASK_INDEX(bit)] &= \
74                                         ~(1UL << CPUMASK_SHFT(bit))
75 #define CPUMASK_TSTB(p, bit)    ((p)._bits[CPUMASK_INDEX(bit)] & \
76                                         (1UL << CPUMASK_SHFT(bit)))
77
78 #else
79 #error cpumask macros only defined for 128p kernels
80 #endif
81
82 extern cpumask_t phys_cpu_present_map;
83 extern cpumask_t cpu_online_map;
84
85 #define cpu_possible(cpu) (phys_cpu_present_map & (1<<(cpu)))
86 #define cpu_online(cpu) (cpu_online_map & (1<<(cpu)))
87
88 extern inline unsigned int num_online_cpus(void)
89 {
90         return hweight32(cpu_online_map);
91 }
92
93 extern volatile unsigned long cpu_callout_map;
94 /* We don't mark CPUs online until __cpu_up(), so we need another measure */
95 static inline int num_booting_cpus(void)
96 {
97         return hweight32(cpu_callout_map);
98 }
99
100 #endif /* CONFIG_SMP */
101
102 #endif /* __ASM_SMP_H */