VSF Documented
idr.h
Go to the documentation of this file.
1#ifndef __VSF_LINUX_IDR_H__
2#define __VSF_LINUX_IDR_H__
3
4// for vsf_protect
5#include "hal/arch/vsf_arch.h"
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#ifndef VSF_LINUX_CFG_IDA_MAX
12# define VSF_LINUX_CFG_IDA_MAX 1024
13#endif
14
16
17struct ida {
18 vsf_bitmap(ida_bitmap) bitmap;
19 unsigned int id_cnt;
20};
21#define IDA_INIT(__NAME) { 0 }
22#define DEFINE_IDA(__NAME) struct ida __NAME = IDA_INIT(__NAME)
23
24extern int ida_alloc_range(struct ida *ida, unsigned int __min_to_avoid_conflict, unsigned int __max_to_avoid_confilict, gfp_t);
25static inline void ida_free(struct ida *ida, unsigned int id)
26{
28 vsf_bitmap_clear(&ida->bitmap, id);
30}
31
32static inline void ida_init(struct ida *ida)
33{
34 memset(ida, 0, sizeof(*ida));
35}
36static inline void ida_destroy(struct ida *ida)
37{
38 // nothing allocated, nothing to destroy
39}
40static inline int ida_alloc(struct ida *ida, gfp_t gfp)
41{
42 return ida_alloc_range(ida, 0, ~0, gfp);
43}
44static inline int ida_alloc_min(struct ida *ida, unsigned int __min_to_avoid_conflict, gfp_t gfp)
45{
46 return ida_alloc_range(ida, __min_to_avoid_conflict, ~0, gfp);
47}
48static inline int ida_alloc_max(struct ida *ida, unsigned int __max_to_avoid_confilict, gfp_t gfp)
49{
50 return ida_alloc_range(ida, 0, __max_to_avoid_confilict, gfp);
51}
52
53static inline bool ida_is_empty(const struct ida *ida)
54{
56 bool is_empty = ida->id_cnt == 0;
58 return is_empty;
59}
60
61#define ida_simple_get(ida, start, end, gfp) ida_alloc_range(ida, start, (end) - 1, gfp)
62#define ida_simple_remove(ida, id) ida_free(ida, id)
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif
unsigned int gfp_t
Definition gfp.h:10
int ida_alloc_range(struct ida *ida, unsigned int __min_to_avoid_conflict, unsigned int __max_to_avoid_confilict, gfp_t)
Definition vsf_linux_core.c:725
#define VSF_LINUX_CFG_IDA_MAX
Definition idr.h:12
void * memset(void *s, int ch, size_t n)
uintalu_t vsf_protect_t
Definition vsf_arch_abstraction.h:53
#define vsf_protect_int
Definition vsf_arch_abstraction.h:275
#define vsf_unprotect_int
Definition vsf_arch_abstraction.h:276
#define vsf_declare_bitmap(__name, __bit_size)
Definition vsf_bitmap.h:95
#define vsf_bitmap_clear(__bitmap_ptr, __bit)
Definition vsf_bitmap.h:110
#define vsf_bitmap(__name)
Definition vsf_bitmap.h:93