brcmsmac: rework of mac80211 .flush() callback operation
[pandora-kernel.git] / include / linux / cpu_rmap.h
1 #ifndef __LINUX_CPU_RMAP_H
2 #define __LINUX_CPU_RMAP_H
3
4 /*
5  * cpu_rmap.c: CPU affinity reverse-map support
6  * Copyright 2011 Solarflare Communications Inc.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License version 2 as published
10  * by the Free Software Foundation, incorporated herein by reference.
11  */
12
13 #include <linux/cpumask.h>
14 #include <linux/gfp.h>
15 #include <linux/slab.h>
16
17 /**
18  * struct cpu_rmap - CPU affinity reverse-map
19  * @size: Number of objects to be reverse-mapped
20  * @used: Number of objects added
21  * @obj: Pointer to array of object pointers
22  * @near: For each CPU, the index and distance to the nearest object,
23  *      based on affinity masks
24  */
25 struct cpu_rmap {
26         u16             size, used;
27         void            **obj;
28         struct {
29                 u16     index;
30                 u16     dist;
31         }               near[0];
32 };
33 #define CPU_RMAP_DIST_INF 0xffff
34
35 extern struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags);
36
37 /**
38  * free_cpu_rmap - free CPU affinity reverse-map
39  * @rmap: Reverse-map allocated with alloc_cpu_rmap(), or %NULL
40  */
41 static inline void free_cpu_rmap(struct cpu_rmap *rmap)
42 {
43         kfree(rmap);
44 }
45
46 extern int cpu_rmap_add(struct cpu_rmap *rmap, void *obj);
47 extern int cpu_rmap_update(struct cpu_rmap *rmap, u16 index,
48                            const struct cpumask *affinity);
49
50 static inline u16 cpu_rmap_lookup_index(struct cpu_rmap *rmap, unsigned int cpu)
51 {
52         return rmap->near[cpu].index;
53 }
54
55 static inline void *cpu_rmap_lookup_obj(struct cpu_rmap *rmap, unsigned int cpu)
56 {
57         return rmap->obj[rmap->near[cpu].index];
58 }
59
60 #ifdef CONFIG_GENERIC_HARDIRQS
61
62 /**
63  * alloc_irq_cpu_rmap - allocate CPU affinity reverse-map for IRQs
64  * @size: Number of objects to be mapped
65  *
66  * Must be called in process context.
67  */
68 static inline struct cpu_rmap *alloc_irq_cpu_rmap(unsigned int size)
69 {
70         return alloc_cpu_rmap(size, GFP_KERNEL);
71 }
72 extern void free_irq_cpu_rmap(struct cpu_rmap *rmap);
73
74 extern int irq_cpu_rmap_add(struct cpu_rmap *rmap, int irq);
75
76 #endif
77 #endif /* __LINUX_CPU_RMAP_H */