summaryrefslogtreecommitdiff
path: root/kern/cpumap.h
blob: e0ac9fce7d1f6389b20a264c4b9b640d5ea5669b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * Copyright (c) 2013-2014 Richard Braun.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Processors represented as bit maps.
 *
 * This module acts as a convenient frontend for the bitmap and kmem modules.
 * Since the size of a CPU map varies with the maximum number of processors
 * that can be managed by the system, maps must not be allocated from the
 * stack.
 */

#ifndef KERN_CPUMAP_H
#define KERN_CPUMAP_H

#include <kern/bitmap.h>
#include <kern/init.h>

struct cpumap {
    BITMAP_DECLARE(cpus, CONFIG_MAX_CPUS);
};

static inline void
cpumap_zero(struct cpumap *cpumap)
{
    bitmap_zero(cpumap->cpus, CONFIG_MAX_CPUS);
}

static inline void
cpumap_fill(struct cpumap *cpumap)
{
    bitmap_fill(cpumap->cpus, CONFIG_MAX_CPUS);
}

static inline void
cpumap_copy(struct cpumap *dest, const struct cpumap *src)
{
    bitmap_copy(dest->cpus, src->cpus, CONFIG_MAX_CPUS);
}

static inline int
cpumap_cmp(const struct cpumap *a, const struct cpumap *b)
{
    return bitmap_cmp(a->cpus, b->cpus, CONFIG_MAX_CPUS);
}

static inline void
cpumap_set(struct cpumap *cpumap, int index)
{
    bitmap_set(cpumap->cpus, index);
}

static inline void
cpumap_set_atomic(struct cpumap *cpumap, int index)
{
    bitmap_set_atomic(cpumap->cpus, index);
}

static inline void
cpumap_clear(struct cpumap *cpumap, int index)
{
    bitmap_clear(cpumap->cpus, index);
}

static inline void
cpumap_clear_atomic(struct cpumap *cpumap, int index)
{
    bitmap_clear_atomic(cpumap->cpus, index);
}

static inline int
cpumap_test(const struct cpumap *cpumap, int index)
{
    return bitmap_test(cpumap->cpus, index);
}

static inline void
cpumap_and(struct cpumap *a, const struct cpumap *b)
{
    bitmap_and(a->cpus, b->cpus, CONFIG_MAX_CPUS);
}

static inline void
cpumap_or(struct cpumap *a, const struct cpumap *b)
{
    bitmap_or(a->cpus, b->cpus, CONFIG_MAX_CPUS);
}

static inline void
cpumap_xor(struct cpumap *a, const struct cpumap *b)
{
    bitmap_xor(a->cpus, b->cpus, CONFIG_MAX_CPUS);
}

static inline int
cpumap_find_next(const struct cpumap *cpumap, int index)
{
    return bitmap_find_next(cpumap->cpus, CONFIG_MAX_CPUS, index);
}

static inline int
cpumap_find_first(const struct cpumap *cpumap)
{
    return bitmap_find_first(cpumap->cpus, CONFIG_MAX_CPUS);
}

static inline int
cpumap_find_next_zero(const struct cpumap *cpumap, int index)
{
    return bitmap_find_next_zero(cpumap->cpus, CONFIG_MAX_CPUS, index);
}

static inline int
cpumap_find_first_zero(const struct cpumap *cpumap)
{
    return bitmap_find_first_zero(cpumap->cpus, CONFIG_MAX_CPUS);
}

#define cpumap_for_each(cpumap, index) \
    bitmap_for_each((cpumap)->cpus, CONFIG_MAX_CPUS, index)

#define cpumap_for_each_zero(cpumap, index) \
    bitmap_for_each_zero((cpumap)->cpus, CONFIG_MAX_CPUS, index)

/*
 * Return a cpumap representing all active processors.
 *
 * Until the cpumap module is initialized, the cpumap returned by this
 * function describes the BSP only.
 */
const struct cpumap * cpumap_all(void);

/*
 * Allocate a CPU map.
 *
 * The new map is uninitialized.
 */
int cpumap_create(struct cpumap **cpumapp);

/*
 * Release a CPU map.
 */
void cpumap_destroy(struct cpumap *cpumap);

/*
 * Check the validity of a CPU map.
 *
 * If the map doesn't identify at least one managed processor, return
 * EINVAL.
 */
int cpumap_check(const struct cpumap *cpumap);

/*
 * This init operation provides :
 *  - cpumap creation
 *  - module fully initialized
 */
INIT_OP_DECLARE(cpumap_setup);

#endif /* KERN_CPUMAP_H */