4 * 2002-10-18 written by Jim Houston jim.houston@ccur.com
5 * Copyright (C) 2002 by Concurrent Computer Corporation
6 * Distributed under the GNU GPL license version 2.
8 * Small id to pointer translation service avoiding fixed sized
11 #include <linux/types.h>
12 #include <asm/bitops.h>
14 #define RESERVED_ID_BITS 8
16 #if BITS_PER_LONG == 32
18 # define IDR_FULL 0xfffffffful
19 #elif BITS_PER_LONG == 64
21 # define IDR_FULL 0xfffffffffffffffful
23 # error "BITS_PER_LONG is not 32 or 64"
26 #define IDR_SIZE (1 << IDR_BITS)
27 #define IDR_MASK ((1 << IDR_BITS)-1)
29 /* Define the size of the id's */
30 #define BITS_PER_INT (sizeof(int)*8)
32 #define MAX_ID_SHIFT (BITS_PER_INT - RESERVED_ID_BITS)
33 #define MAX_ID_BIT (1 << MAX_ID_SHIFT)
34 #define MAX_ID_MASK (MAX_ID_BIT - 1)
36 /* Leave the possibility of an incomplete final layer */
37 #define MAX_LEVEL (MAX_ID_SHIFT + IDR_BITS - 1) / IDR_BITS
39 /* Number of id_layer structs to leave in free list */
40 #define IDR_FREE_MAX MAX_LEVEL + MAX_LEVEL
43 unsigned long bitmap; /* A zero bit means "space here" */
44 struct idr_layer *ary[1<<IDR_BITS];
45 int count; /* When zero, we can release it */
49 struct idr_layer *top;
50 struct idr_layer *id_free;
57 #define IDR_INIT(name) \
64 .lock = SPIN_LOCK_UNLOCKED, \
66 #define DEFINE_IDR(name) struct idr name = IDR_INIT(name)
69 * This is what we export.
72 void *idr_find(struct idr *idp, int id);
73 int idr_pre_get(struct idr *idp, unsigned gfp_mask);
74 int idr_get_new(struct idr *idp, void *ptr);
75 void idr_remove(struct idr *idp, int id);
76 void idr_init(struct idr *idp);
78 extern kmem_cache_t *idr_layer_cache;