/
vr_btable.h
74 lines (59 loc) · 1.86 KB
/
vr_btable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* vr_btable.h --
*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#ifndef __VR_BTABLE_H__
#define __VR_BTABLE_H__
#define VB_FLAG_MEMORY_ATTACHED 0x1
#define VR_SINGLE_ALLOC_LIMIT (4 * 1024 * 1024)
struct vr_btable_partition {
unsigned int vb_offset;
unsigned int vb_mem_size;
};
struct vr_btable {
unsigned int vb_entries;
unsigned short vb_esize;
unsigned short vb_partitions;
unsigned int vb_flags;
unsigned int vb_alloc_limit;
unsigned short vb_alloc_limit_log;
unsigned int vb_alloc_limit_mask;
void **vb_mem;
struct vr_btable_partition *vb_table_info;
};
struct vr_btable_partition *vr_btable_get_partition(struct vr_btable *,
unsigned int);
void *vr_btable_get_address(struct vr_btable *, unsigned int);
void vr_btable_free(struct vr_btable *);
struct vr_btable *vr_btable_alloc(unsigned int, unsigned int);
struct vr_btable *vr_btable_attach(struct iovec *, unsigned int, unsigned short);
static inline unsigned int
vr_btable_entries(struct vr_btable *table)
{
return table->vb_entries;
}
static inline unsigned int
vr_btable_size(struct vr_btable *table)
{
return table->vb_entries * table->vb_esize;
}
static inline void *
vr_btable_get(struct vr_btable *table, unsigned int entry)
{
unsigned int t_index, t_offset, entry_cont;
if (entry >= table->vb_entries)
return NULL;
entry_cont = entry * table->vb_esize;
if (table->vb_alloc_limit_mask) {
t_index = entry_cont >> table->vb_alloc_limit_log;
t_offset = entry_cont & table->vb_alloc_limit_mask;
} else {
t_index = entry_cont / table->vb_alloc_limit;
t_offset = entry_cont % table->vb_alloc_limit;
}
if (t_index >= table->vb_partitions)
return NULL;
return ((char *)table->vb_mem[t_index] + t_offset);
}
#endif /* __VR_BTABLE_H__ */