1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __LINUX_CPU_RMAP_H
3 #define __LINUX_CPU_RMAP_H
6 * cpu_rmap.c: CPU affinity reverse-map support
7 * Copyright 2011 Solarflare Communications Inc.
10 #include <linux/cpumask.h>
11 #include <linux/gfp.h>
12 #include <linux/slab.h>
13 #include <linux/kref.h>
16 * struct cpu_rmap - CPU affinity reverse-map
17 * @refcount: kref for object
18 * @size: Number of objects to be reverse-mapped
19 * @used: Number of objects added
20 * @obj: Pointer to array of object pointers
21 * @near: For each CPU, the index and distance to the nearest object,
22 * based on affinity masks
33 #define CPU_RMAP_DIST_INF 0xffff
35 extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
36 extern int cpu_rmap_put(struct cpu_rmap *rmap);
38 extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
39 extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
40 const struct cpumask *affinity);
42 static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
44 return rmap->near[cpu].index;
47 static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
49 return rmap->obj[rmap->near[cpu].index];
53 * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
54 * @size: Number of objects to be mapped
56 * Must be called in process context.
58 static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
60 return alloc_cpu_rmap(size, GFP_KERNEL);
62 extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
64 extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
66 #endif /* __LINUX_CPU_RMAP_H */