ia64/xen-unstable

view xen/include/xen/nodemask.h @ 19800:78962f85c562

IOMMU: Add two generic functions to vendor neutral interface

Add 2 generic functions into the vendor neutral iommu interface, The
reason is that from changeset 19732, there is only one global flag
"iommu_enabled" that controls iommu enablement for both vtd and amd
systems, so we need different code paths for vtd and amd iommu systems
if this flag has been turned on. Also, the early checking of
"iommu_enabled" in iommu_setup() is removed to prevent iommu
functionalities from been disabled on amd systems.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 19 08:41:50 2009 +0100 (2009-06-19)
parents 3db344ea8070
children
line source
1 #ifndef __LINUX_NODEMASK_H
2 #define __LINUX_NODEMASK_H
4 /*
5 * Nodemasks provide a bitmap suitable for representing the
6 * set of Node's in a system, one bit position per Node number.
7 *
8 * See detailed comments in the file linux/bitmap.h describing the
9 * data type on which these nodemasks are based.
10 *
11 * For details of nodemask_scnprintf() and nodemask_parse(),
12 * see bitmap_scnprintf() and bitmap_parse() in lib/bitmap.c.
13 *
14 * The available nodemask operations are:
15 *
16 * void node_set(node, mask) turn on bit 'node' in mask
17 * void node_clear(node, mask) turn off bit 'node' in mask
18 * void nodes_setall(mask) set all bits
19 * void nodes_clear(mask) clear all bits
20 * int node_isset(node, mask) true iff bit 'node' set in mask
21 * int node_test_and_set(node, mask) test and set bit 'node' in mask
22 *
23 * void nodes_and(dst, src1, src2) dst = src1 & src2 [intersection]
24 * void nodes_or(dst, src1, src2) dst = src1 | src2 [union]
25 * void nodes_xor(dst, src1, src2) dst = src1 ^ src2
26 * void nodes_andnot(dst, src1, src2) dst = src1 & ~src2
27 * void nodes_complement(dst, src) dst = ~src
28 *
29 * int nodes_equal(mask1, mask2) Does mask1 == mask2?
30 * int nodes_intersects(mask1, mask2) Do mask1 and mask2 intersect?
31 * int nodes_subset(mask1, mask2) Is mask1 a subset of mask2?
32 * int nodes_empty(mask) Is mask empty (no bits sets)?
33 * int nodes_full(mask) Is mask full (all bits sets)?
34 * int nodes_weight(mask) Hamming weight - number of set bits
35 *
36 * void nodes_shift_right(dst, src, n) Shift right
37 * void nodes_shift_left(dst, src, n) Shift left
38 *
39 * int first_node(mask) Number lowest set bit, or MAX_NUMNODES
40 * int next_node(node, mask) Next node past 'node', or MAX_NUMNODES
41 * int first_unset_node(mask) First node not set in mask, or
42 * MAX_NUMNODES.
43 *
44 * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set
45 * NODE_MASK_ALL Initializer - all bits set
46 * NODE_MASK_NONE Initializer - no bits set
47 * unsigned long *nodes_addr(mask) Array of unsigned long's in mask
48 *
49 * int nodemask_scnprintf(buf, len, mask) Format nodemask for printing
50 * int nodemask_parse(ubuf, ulen, mask) Parse ascii string as nodemask
51 *
52 * for_each_node_mask(node, mask) for-loop node over mask
53 *
54 * int num_online_nodes() Number of online Nodes
55 * int num_possible_nodes() Number of all possible Nodes
56 *
57 * int node_online(node) Is some node online?
58 * int node_possible(node) Is some node possible?
59 *
60 * int any_online_node(mask) First online node in mask
61 *
62 * node_set_online(node) set bit 'node' in node_online_map
63 * node_set_offline(node) clear bit 'node' in node_online_map
64 *
65 * for_each_node(node) for-loop node over node_possible_map
66 * for_each_online_node(node) for-loop node over node_online_map
67 *
68 * Subtlety:
69 * 1) The 'type-checked' form of node_isset() causes gcc (3.3.2, anyway)
70 * to generate slightly worse code. So use a simple one-line #define
71 * for node_isset(), instead of wrapping an inline inside a macro, the
72 * way we do the other calls.
73 */
75 #include <xen/kernel.h>
76 #include <xen/bitmap.h>
77 #include <xen/numa.h>
79 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
80 extern nodemask_t _unused_nodemask_arg_;
82 #define node_set(node, dst) __node_set((node), &(dst))
83 static inline void __node_set(int node, volatile nodemask_t *dstp)
84 {
85 set_bit(node, dstp->bits);
86 }
88 #define node_clear(node, dst) __node_clear((node), &(dst))
89 static inline void __node_clear(int node, volatile nodemask_t *dstp)
90 {
91 clear_bit(node, dstp->bits);
92 }
94 #define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES)
95 static inline void __nodes_setall(nodemask_t *dstp, int nbits)
96 {
97 bitmap_fill(dstp->bits, nbits);
98 }
100 #define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES)
101 static inline void __nodes_clear(nodemask_t *dstp, int nbits)
102 {
103 bitmap_zero(dstp->bits, nbits);
104 }
106 /* No static inline type checking - see Subtlety (1) above. */
107 #define node_isset(node, nodemask) test_bit((node), (nodemask).bits)
109 #define node_test_and_set(node, nodemask) \
110 __node_test_and_set((node), &(nodemask))
111 static inline int __node_test_and_set(int node, nodemask_t *addr)
112 {
113 return test_and_set_bit(node, addr->bits);
114 }
116 #define nodes_and(dst, src1, src2) \
117 __nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES)
118 static inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,
119 const nodemask_t *src2p, int nbits)
120 {
121 bitmap_and(dstp->bits, src1p->bits, src2p->bits, nbits);
122 }
124 #define nodes_or(dst, src1, src2) \
125 __nodes_or(&(dst), &(src1), &(src2), MAX_NUMNODES)
126 static inline void __nodes_or(nodemask_t *dstp, const nodemask_t *src1p,
127 const nodemask_t *src2p, int nbits)
128 {
129 bitmap_or(dstp->bits, src1p->bits, src2p->bits, nbits);
130 }
132 #define nodes_xor(dst, src1, src2) \
133 __nodes_xor(&(dst), &(src1), &(src2), MAX_NUMNODES)
134 static inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1p,
135 const nodemask_t *src2p, int nbits)
136 {
137 bitmap_xor(dstp->bits, src1p->bits, src2p->bits, nbits);
138 }
140 #define nodes_andnot(dst, src1, src2) \
141 __nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES)
142 static inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,
143 const nodemask_t *src2p, int nbits)
144 {
145 bitmap_andnot(dstp->bits, src1p->bits, src2p->bits, nbits);
146 }
148 #define nodes_complement(dst, src) \
149 __nodes_complement(&(dst), &(src), MAX_NUMNODES)
150 static inline void __nodes_complement(nodemask_t *dstp,
151 const nodemask_t *srcp, int nbits)
152 {
153 bitmap_complement(dstp->bits, srcp->bits, nbits);
154 }
156 #define nodes_equal(src1, src2) \
157 __nodes_equal(&(src1), &(src2), MAX_NUMNODES)
158 static inline int __nodes_equal(const nodemask_t *src1p,
159 const nodemask_t *src2p, int nbits)
160 {
161 return bitmap_equal(src1p->bits, src2p->bits, nbits);
162 }
164 #define nodes_intersects(src1, src2) \
165 __nodes_intersects(&(src1), &(src2), MAX_NUMNODES)
166 static inline int __nodes_intersects(const nodemask_t *src1p,
167 const nodemask_t *src2p, int nbits)
168 {
169 return bitmap_intersects(src1p->bits, src2p->bits, nbits);
170 }
172 #define nodes_subset(src1, src2) \
173 __nodes_subset(&(src1), &(src2), MAX_NUMNODES)
174 static inline int __nodes_subset(const nodemask_t *src1p,
175 const nodemask_t *src2p, int nbits)
176 {
177 return bitmap_subset(src1p->bits, src2p->bits, nbits);
178 }
180 #define nodes_empty(src) __nodes_empty(&(src), MAX_NUMNODES)
181 static inline int __nodes_empty(const nodemask_t *srcp, int nbits)
182 {
183 return bitmap_empty(srcp->bits, nbits);
184 }
186 #define nodes_full(nodemask) __nodes_full(&(nodemask), MAX_NUMNODES)
187 static inline int __nodes_full(const nodemask_t *srcp, int nbits)
188 {
189 return bitmap_full(srcp->bits, nbits);
190 }
192 #define nodes_weight(nodemask) __nodes_weight(&(nodemask), MAX_NUMNODES)
193 static inline int __nodes_weight(const nodemask_t *srcp, int nbits)
194 {
195 return bitmap_weight(srcp->bits, nbits);
196 }
198 #define nodes_shift_right(dst, src, n) \
199 __nodes_shift_right(&(dst), &(src), (n), MAX_NUMNODES)
200 static inline void __nodes_shift_right(nodemask_t *dstp,
201 const nodemask_t *srcp, int n, int nbits)
202 {
203 bitmap_shift_right(dstp->bits, srcp->bits, n, nbits);
204 }
206 #define nodes_shift_left(dst, src, n) \
207 __nodes_shift_left(&(dst), &(src), (n), MAX_NUMNODES)
208 static inline void __nodes_shift_left(nodemask_t *dstp,
209 const nodemask_t *srcp, int n, int nbits)
210 {
211 bitmap_shift_left(dstp->bits, srcp->bits, n, nbits);
212 }
214 /* FIXME: better would be to fix all architectures to never return
215 > MAX_NUMNODES, then the silly min_ts could be dropped. */
217 #define first_node(src) __first_node(&(src))
218 static inline int __first_node(const nodemask_t *srcp)
219 {
220 return min_t(int, MAX_NUMNODES, find_first_bit(srcp->bits, MAX_NUMNODES));
221 }
223 #define next_node(n, src) __next_node((n), &(src))
224 static inline int __next_node(int n, const nodemask_t *srcp)
225 {
226 return min_t(int,MAX_NUMNODES,find_next_bit(srcp->bits, MAX_NUMNODES, n+1));
227 }
229 #define nodemask_of_node(node) \
230 ({ \
231 typeof(_unused_nodemask_arg_) m; \
232 if (sizeof(m) == sizeof(unsigned long)) { \
233 m.bits[0] = 1UL<<(node); \
234 } else { \
235 nodes_clear(m); \
236 node_set((node), m); \
237 } \
238 m; \
239 })
241 #define first_unset_node(mask) __first_unset_node(&(mask))
242 static inline int __first_unset_node(const nodemask_t *maskp)
243 {
244 return min_t(int,MAX_NUMNODES,
245 find_first_zero_bit(maskp->bits, MAX_NUMNODES));
246 }
248 #define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES)
250 #if MAX_NUMNODES <= BITS_PER_LONG
252 #define NODE_MASK_ALL \
253 ((nodemask_t) { { \
254 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
255 } })
257 #else
259 #define NODE_MASK_ALL \
260 ((nodemask_t) { { \
261 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL, \
262 [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \
263 } })
265 #endif
267 #define NODE_MASK_NONE \
268 ((nodemask_t) { { \
269 [0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] = 0UL \
270 } })
272 #define nodes_addr(src) ((src).bits)
274 #if 0
275 #define nodemask_scnprintf(buf, len, src) \
276 __nodemask_scnprintf((buf), (len), &(src), MAX_NUMNODES)
277 static inline int __nodemask_scnprintf(char *buf, int len,
278 const nodemask_t *srcp, int nbits)
279 {
280 return bitmap_scnprintf(buf, len, srcp->bits, nbits);
281 }
283 #define nodemask_parse(ubuf, ulen, dst) \
284 __nodemask_parse((ubuf), (ulen), &(dst), MAX_NUMNODES)
285 static inline int __nodemask_parse(const char __user *buf, int len,
286 nodemask_t *dstp, int nbits)
287 {
288 return bitmap_parse(buf, len, dstp->bits, nbits);
289 }
290 #endif
292 #if MAX_NUMNODES > 1
293 #define for_each_node_mask(node, mask) \
294 for ((node) = first_node(mask); \
295 (node) < MAX_NUMNODES; \
296 (node) = next_node((node), (mask)))
297 #else /* MAX_NUMNODES == 1 */
298 #define for_each_node_mask(node, mask) \
299 if (!nodes_empty(mask)) \
300 for ((node) = 0; (node) < 1; (node)++)
301 #endif /* MAX_NUMNODES */
303 /*
304 * The following particular system nodemasks and operations
305 * on them manage all possible and online nodes.
306 */
308 extern nodemask_t node_online_map;
309 extern nodemask_t node_possible_map;
311 #if MAX_NUMNODES > 1
312 #define num_online_nodes() nodes_weight(node_online_map)
313 #define num_possible_nodes() nodes_weight(node_possible_map)
314 #define node_online(node) node_isset((node), node_online_map)
315 #define node_possible(node) node_isset((node), node_possible_map)
316 #else
317 #define num_online_nodes() 1
318 #define num_possible_nodes() 1
319 #define node_online(node) ((node) == 0)
320 #define node_possible(node) ((node) == 0)
321 #endif
323 #define any_online_node(mask) \
324 ({ \
325 int node; \
326 for_each_node_mask(node, (mask)) \
327 if (node_online(node)) \
328 break; \
329 node; \
330 })
332 #define node_set_online(node) set_bit((node), node_online_map.bits)
333 #define node_set_offline(node) clear_bit((node), node_online_map.bits)
335 #define for_each_node(node) for_each_node_mask((node), node_possible_map)
336 #define for_each_online_node(node) for_each_node_mask((node), node_online_map)
338 #endif /* __LINUX_NODEMASK_H */