cpumap.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2013-2014 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Processors represented as bit maps.
  19. *
  20. * This module acts as a convenient frontend for the bitmap and kmem modules.
  21. * Since the size of a CPU map varies with the maximum number of processors
  22. * that can be managed by the system, maps must not be allocated from the
  23. * stack.
  24. */
  25. #ifndef KERN_CPUMAP_H
  26. #define KERN_CPUMAP_H
  27. #include <kern/bitmap.h>
  28. #include <kern/init.h>
  29. struct cpumap {
  30. BITMAP_DECLARE(cpus, CONFIG_MAX_CPUS);
  31. };
  32. static inline void
  33. cpumap_zero(struct cpumap *cpumap)
  34. {
  35. bitmap_zero(cpumap->cpus, CONFIG_MAX_CPUS);
  36. }
  37. static inline void
  38. cpumap_fill(struct cpumap *cpumap)
  39. {
  40. bitmap_fill(cpumap->cpus, CONFIG_MAX_CPUS);
  41. }
  42. static inline void
  43. cpumap_copy(struct cpumap *dest, const struct cpumap *src)
  44. {
  45. bitmap_copy(dest->cpus, src->cpus, CONFIG_MAX_CPUS);
  46. }
  47. static inline int
  48. cpumap_cmp(const struct cpumap *a, const struct cpumap *b)
  49. {
  50. return bitmap_cmp(a->cpus, b->cpus, CONFIG_MAX_CPUS);
  51. }
  52. static inline void
  53. cpumap_set(struct cpumap *cpumap, int index)
  54. {
  55. bitmap_set(cpumap->cpus, index);
  56. }
  57. static inline void
  58. cpumap_set_atomic(struct cpumap *cpumap, int index)
  59. {
  60. bitmap_set_atomic(cpumap->cpus, index);
  61. }
  62. static inline void
  63. cpumap_clear(struct cpumap *cpumap, int index)
  64. {
  65. bitmap_clear(cpumap->cpus, index);
  66. }
  67. static inline void
  68. cpumap_clear_atomic(struct cpumap *cpumap, int index)
  69. {
  70. bitmap_clear_atomic(cpumap->cpus, index);
  71. }
  72. static inline int
  73. cpumap_test(const struct cpumap *cpumap, int index)
  74. {
  75. return bitmap_test(cpumap->cpus, index);
  76. }
  77. static inline void
  78. cpumap_and(struct cpumap *a, const struct cpumap *b)
  79. {
  80. bitmap_and(a->cpus, b->cpus, CONFIG_MAX_CPUS);
  81. }
  82. static inline void
  83. cpumap_or(struct cpumap *a, const struct cpumap *b)
  84. {
  85. bitmap_or(a->cpus, b->cpus, CONFIG_MAX_CPUS);
  86. }
  87. static inline void
  88. cpumap_xor(struct cpumap *a, const struct cpumap *b)
  89. {
  90. bitmap_xor(a->cpus, b->cpus, CONFIG_MAX_CPUS);
  91. }
  92. static inline int
  93. cpumap_find_next(const struct cpumap *cpumap, int index)
  94. {
  95. return bitmap_find_next(cpumap->cpus, CONFIG_MAX_CPUS, index);
  96. }
  97. static inline int
  98. cpumap_find_first(const struct cpumap *cpumap)
  99. {
  100. return bitmap_find_first(cpumap->cpus, CONFIG_MAX_CPUS);
  101. }
  102. static inline int
  103. cpumap_find_next_zero(const struct cpumap *cpumap, int index)
  104. {
  105. return bitmap_find_next_zero(cpumap->cpus, CONFIG_MAX_CPUS, index);
  106. }
  107. static inline int
  108. cpumap_find_first_zero(const struct cpumap *cpumap)
  109. {
  110. return bitmap_find_first_zero(cpumap->cpus, CONFIG_MAX_CPUS);
  111. }
  112. #define cpumap_for_each(cpumap, index) \
  113. bitmap_for_each((cpumap)->cpus, CONFIG_MAX_CPUS, index)
  114. #define cpumap_for_each_zero(cpumap, index) \
  115. bitmap_for_each_zero((cpumap)->cpus, CONFIG_MAX_CPUS, index)
  116. /*
  117. * Return a cpumap representing all active processors.
  118. *
  119. * Until the cpumap module is initialized, the cpumap returned by this
  120. * function describes the BSP only.
  121. */
  122. const struct cpumap * cpumap_all(void);
  123. /*
  124. * Allocate a CPU map.
  125. *
  126. * The new map is uninitialized.
  127. */
  128. int cpumap_create(struct cpumap **cpumapp);
  129. /*
  130. * Release a CPU map.
  131. */
  132. void cpumap_destroy(struct cpumap *cpumap);
  133. /*
  134. * Check the validity of a CPU map.
  135. *
  136. * If the map doesn't identify at least one managed processor, return
  137. * EINVAL.
  138. */
  139. int cpumap_check(const struct cpumap *cpumap);
  140. /*
  141. * This init operation provides :
  142. * - cpumap creation
  143. * - module fully initialized
  144. */
  145. INIT_OP_DECLARE(cpumap_setup);
  146. #endif /* KERN_CPUMAP_H */