1 /* Public domain. */ 2 3 #ifndef _LINUX_XARRAY_H 4 #define _LINUX_XARRAY_H 5 6 #include <linux/gfp.h> 7 8 #include <sys/tree.h> 9 10 #define XA_FLAGS_ALLOC 1 11 #define XA_FLAGS_ALLOC1 2 12 13 struct xarray_entry { 14 SPLAY_ENTRY(xarray_entry) entry; 15 int id; 16 void *ptr; 17 }; 18 19 struct xarray { 20 gfp_t xa_flags; 21 SPLAY_HEAD(xarray_tree, xarray_entry) xa_tree; 22 }; 23 24 void xa_init_flags(struct xarray *, gfp_t); 25 void xa_destroy(struct xarray *); 26 int xa_alloc(struct xarray *, u32 *, void *, int, gfp_t); 27 void *xa_load(struct xarray *, unsigned long); 28 void *xa_erase(struct xarray *, unsigned long); 29 void *xa_get_next(struct xarray *, unsigned long *); 30 31 #define xa_for_each(xa, index, entry) \ 32 for (index = 0; ((entry) = xa_get_next(xa, &(index))) != NULL; index++) 33 34 #define xa_limit_32b 0 35 36 static inline void * 37 xa_mk_value(unsigned long v) 38 { 39 unsigned long r = (v << 1) | 1; 40 return (void *)r; 41 } 42 43 static inline bool 44 xa_is_value(const void *e) 45 { 46 unsigned long v = (unsigned long)e; 47 return v & 1; 48 } 49 50 static inline unsigned long 51 xa_to_value(const void *e) 52 { 53 unsigned long v = (unsigned long)e; 54 return v >> 1; 55 } 56 57 #endif 58