Lines Matching +full:irqs +full:- +full:reserved

1 // SPDX-License-Identifier: GPL-2.0
43 * irq_alloc_matrix - Allocate a irq_matrix structure and initialize it
62 m->matrix_bits = matrix_bits; in irq_alloc_matrix()
63 m->alloc_start = alloc_start; in irq_alloc_matrix()
64 m->alloc_end = alloc_end; in irq_alloc_matrix()
65 m->alloc_size = alloc_end - alloc_start; in irq_alloc_matrix()
66 m->maps = alloc_percpu(*m->maps); in irq_alloc_matrix()
67 if (!m->maps) { in irq_alloc_matrix()
75 * irq_matrix_online - Bring the local CPU matrix online
80 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_online()
82 BUG_ON(cm->online); in irq_matrix_online()
84 if (!cm->initialized) { in irq_matrix_online()
85 cm->available = m->alloc_size; in irq_matrix_online()
86 cm->available -= cm->managed + m->systembits_inalloc; in irq_matrix_online()
87 cm->initialized = true; in irq_matrix_online()
89 m->global_available += cm->available; in irq_matrix_online()
90 cm->online = true; in irq_matrix_online()
91 m->online_maps++; in irq_matrix_online()
96 * irq_matrix_offline - Bring the local CPU matrix offline
101 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_offline()
104 m->global_available -= cm->available; in irq_matrix_offline()
105 cm->online = false; in irq_matrix_offline()
106 m->online_maps--; in irq_matrix_offline()
113 unsigned int area, start = m->alloc_start; in matrix_alloc_area()
114 unsigned int end = m->alloc_end; in matrix_alloc_area()
116 bitmap_or(m->scratch_map, cm->managed_map, m->system_map, end); in matrix_alloc_area()
117 bitmap_or(m->scratch_map, m->scratch_map, cm->alloc_map, end); in matrix_alloc_area()
118 area = bitmap_find_next_zero_area(m->scratch_map, end, start, num, 0); in matrix_alloc_area()
122 bitmap_set(cm->managed_map, area, num); in matrix_alloc_area()
124 bitmap_set(cm->alloc_map, area, num); in matrix_alloc_area()
138 cm = per_cpu_ptr(m->maps, cpu); in matrix_find_best_cpu()
140 if (!cm->online || cm->available <= maxavl) in matrix_find_best_cpu()
144 maxavl = cm->available; in matrix_find_best_cpu()
149 /* Find the best CPU which has the lowest number of managed IRQs allocated */
159 cm = per_cpu_ptr(m->maps, cpu); in matrix_find_best_cpu_managed()
161 if (!cm->online || cm->managed_allocated > allocated) in matrix_find_best_cpu_managed()
165 allocated = cm->managed_allocated; in matrix_find_best_cpu_managed()
171 * irq_matrix_assign_system - Assign system wide entry in the matrix
184 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_assign_system()
186 BUG_ON(bit > m->matrix_bits); in irq_matrix_assign_system()
187 BUG_ON(m->online_maps > 1 || (m->online_maps && !replace)); in irq_matrix_assign_system()
189 set_bit(bit, m->system_map); in irq_matrix_assign_system()
191 BUG_ON(!test_and_clear_bit(bit, cm->alloc_map)); in irq_matrix_assign_system()
192 cm->allocated--; in irq_matrix_assign_system()
193 m->total_allocated--; in irq_matrix_assign_system()
195 if (bit >= m->alloc_start && bit < m->alloc_end) in irq_matrix_assign_system()
196 m->systembits_inalloc++; in irq_matrix_assign_system()
202 * irq_matrix_reserve_managed - Reserve a managed interrupt in a CPU map
204 * @msk: On which CPUs the bits should be reserved.
215 struct cpumap *cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_reserve_managed()
219 if (bit >= m->alloc_end) in irq_matrix_reserve_managed()
221 cm->managed++; in irq_matrix_reserve_managed()
222 if (cm->online) { in irq_matrix_reserve_managed()
223 cm->available--; in irq_matrix_reserve_managed()
224 m->global_available--; in irq_matrix_reserve_managed()
236 return -ENOSPC; in irq_matrix_reserve_managed()
240 * irq_matrix_remove_managed - Remove managed interrupts in a CPU map
256 struct cpumap *cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_remove_managed()
257 unsigned int bit, end = m->alloc_end; in irq_matrix_remove_managed()
259 if (WARN_ON_ONCE(!cm->managed)) in irq_matrix_remove_managed()
263 bitmap_andnot(m->scratch_map, cm->managed_map, cm->alloc_map, end); in irq_matrix_remove_managed()
265 bit = find_first_bit(m->scratch_map, end); in irq_matrix_remove_managed()
269 clear_bit(bit, cm->managed_map); in irq_matrix_remove_managed()
271 cm->managed--; in irq_matrix_remove_managed()
272 if (cm->online) { in irq_matrix_remove_managed()
273 cm->available++; in irq_matrix_remove_managed()
274 m->global_available++; in irq_matrix_remove_managed()
281 * irq_matrix_alloc_managed - Allocate a managed interrupt in a CPU map
288 unsigned int bit, cpu, end = m->alloc_end; in irq_matrix_alloc_managed()
292 return -EINVAL; in irq_matrix_alloc_managed()
296 return -ENOSPC; in irq_matrix_alloc_managed()
298 cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_alloc_managed()
299 end = m->alloc_end; in irq_matrix_alloc_managed()
301 bitmap_andnot(m->scratch_map, cm->managed_map, cm->alloc_map, end); in irq_matrix_alloc_managed()
302 bit = find_first_bit(m->scratch_map, end); in irq_matrix_alloc_managed()
304 return -ENOSPC; in irq_matrix_alloc_managed()
305 set_bit(bit, cm->alloc_map); in irq_matrix_alloc_managed()
306 cm->allocated++; in irq_matrix_alloc_managed()
307 cm->managed_allocated++; in irq_matrix_alloc_managed()
308 m->total_allocated++; in irq_matrix_alloc_managed()
315 * irq_matrix_assign - Assign a preallocated interrupt in the local CPU map
323 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_assign()
325 if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end)) in irq_matrix_assign()
327 if (WARN_ON_ONCE(test_and_set_bit(bit, cm->alloc_map))) in irq_matrix_assign()
329 cm->allocated++; in irq_matrix_assign()
330 m->total_allocated++; in irq_matrix_assign()
331 cm->available--; in irq_matrix_assign()
332 m->global_available--; in irq_matrix_assign()
337 * irq_matrix_reserve - Reserve interrupts
341 * reserved interrupt bits w/o actually allocating them. This allows to
347 if (m->global_reserved <= m->global_available && in irq_matrix_reserve()
348 m->global_reserved + 1 > m->global_available) in irq_matrix_reserve()
351 m->global_reserved++; in irq_matrix_reserve()
356 * irq_matrix_remove_reserved - Remove interrupt reservation
360 * reserved interrupt bits. This is used to undo irq_matrix_reserve() when the
366 m->global_reserved--; in irq_matrix_remove_reserved()
371 * irq_matrix_alloc - Allocate a regular interrupt in a CPU map
374 * @reserved: Allocate previously reserved interrupts
378 bool reserved, unsigned int *mapped_cpu) in irq_matrix_alloc() argument
388 return -EINVAL; in irq_matrix_alloc()
392 return -ENOSPC; in irq_matrix_alloc()
394 cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_alloc()
396 if (bit >= m->alloc_end) in irq_matrix_alloc()
397 return -ENOSPC; in irq_matrix_alloc()
398 cm->allocated++; in irq_matrix_alloc()
399 cm->available--; in irq_matrix_alloc()
400 m->total_allocated++; in irq_matrix_alloc()
401 m->global_available--; in irq_matrix_alloc()
402 if (reserved) in irq_matrix_alloc()
403 m->global_reserved--; in irq_matrix_alloc()
411 * irq_matrix_free - Free allocated interrupt in the matrix
421 struct cpumap *cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_free()
423 if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end)) in irq_matrix_free()
426 clear_bit(bit, cm->alloc_map); in irq_matrix_free()
427 cm->allocated--; in irq_matrix_free()
429 cm->managed_allocated--; in irq_matrix_free()
431 if (cm->online) in irq_matrix_free()
432 m->total_allocated--; in irq_matrix_free()
435 cm->available++; in irq_matrix_free()
436 if (cm->online) in irq_matrix_free()
437 m->global_available++; in irq_matrix_free()
443 * irq_matrix_available - Get the number of globally available irqs
446 * the number of available irqs accordingly
450 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_available()
453 return m->global_available; in irq_matrix_available()
454 return m->global_available - cm->available; in irq_matrix_available()
458 * irq_matrix_reserved - Get the number of globally reserved irqs
463 return m->global_reserved; in irq_matrix_reserved()
467 * irq_matrix_allocated - Get the number of allocated irqs on the local cpu
470 * This returns number of allocated irqs
474 struct cpumap *cm = this_cpu_ptr(m->maps); in irq_matrix_allocated()
476 return cm->allocated; in irq_matrix_allocated()
481 * irq_matrix_debug_show - Show detailed allocation information
490 unsigned int nsys = bitmap_weight(m->system_map, m->matrix_bits); in irq_matrix_debug_show()
493 seq_printf(sf, "Online bitmaps: %6u\n", m->online_maps); in irq_matrix_debug_show()
494 seq_printf(sf, "Global available: %6u\n", m->global_available); in irq_matrix_debug_show()
495 seq_printf(sf, "Global reserved: %6u\n", m->global_reserved); in irq_matrix_debug_show()
496 seq_printf(sf, "Total allocated: %6u\n", m->total_allocated); in irq_matrix_debug_show()
497 seq_printf(sf, "System: %u: %*pbl\n", nsys, m->matrix_bits, in irq_matrix_debug_show()
498 m->system_map); in irq_matrix_debug_show()
502 struct cpumap *cm = per_cpu_ptr(m->maps, cpu); in irq_matrix_debug_show()
505 cpu, cm->available, cm->managed, in irq_matrix_debug_show()
506 cm->managed_allocated, cm->allocated, in irq_matrix_debug_show()
507 m->matrix_bits, cm->alloc_map); in irq_matrix_debug_show()