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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/**
* Copyright (C) Mellanox Technologies Ltd. 2001-2015. ALL RIGHTS RESERVED.
*
* See file LICENSE for terms.
*/
/*
* The Page Table data structure organizes non-overlapping regions of memory in
* an efficient radix tree, optimized for large and/or aligned regions.
*
* A page table entry can point to either a region (indicated by setting the
* UCS_PGT_PTE_FLAG_REGION bit), or another entry (indicated by UCS_PGT_PTE_FLAG_DIR),
* or be empty - if none of these bits is set.
*
*/
/* Address alignment requirements */
/* Page table entry/directory constants */
/* Page table pointers constants and flags */
/* Declare a variable as aligned so it could be placed in page table entry */
/* Define the address type */
typedef unsigned long ucs_pgt_addr_t;
/* Forward declarations */
typedef struct ucs_pgtable ucs_pgtable_t;
typedef struct ucs_pgt_region ucs_pgt_region_t;
typedef struct ucs_pgt_entry ucs_pgt_entry_t;
typedef struct ucs_pgt_dir ucs_pgt_dir_t;
/**
* Callback for allocating a page table directory.
*
* @param [in] pgtable Pointer to the page table to allocate the directory for.
*
* @return Pointer to newly allocated pgdir, or NULL if failed. The pointer must
* be aligned to UCS_PGT_ENTRY_ALIGN boundary.
* */
typedef ucs_pgt_dir_t* ;
/**
* Callback for releasing a page table directory.
*
* @param [in] pgtable Pointer to the page table to in which the directory was
* allocated.
* @param [in] pgdir Page table directory to release.
*/
typedef void ;
/**
* Callback for searching for regions in the page table.
*
* @param [in] pgtable The page table.
* @param [in] region Found region.
* @param [in] arg User-defined argument.
*/
typedef void ;
/**
* Memory region in the page table.
* The structure itself, and the pointers in it, must be aligned to 2^PTR_SHIFT.
*/
UCS_PGT_ENTRY_V_ALIGNED;
/**
* Page table entry:
*
* +--------------------+---+---+
* | pointer (MSB) | d | r |
* +--------------------+---+---+
* | | | |
* 64 2 1 0
*
*/
;
/**
* Page table directory.
*/
;
/* Page table structure */
;
/**
* Initialize a page table.
*
* @param [in] pgtable Page table to initialize.
* @param [in] alloc_cb Callback that will be used to allocate page directory,
* which is the basic building block of the page table
* data structure. This may allow the page table functions
* to be safe to use from memory allocation context.
* @param [in] release_cb Callback to release memory which was allocated by alloc_cb.
*/
ucs_status_t ;
/**
* Cleanup the page table and release all associated memory.
*
* @param [in] pgtable Page table to initialize.
*/
void ;
/**
* Add a memory region to the page table.
*
* @param [in] pgtable Page table to insert the region to.
* @param [in] region Memory region to insert. The region must remain valid
* and unchanged s long as it's in the page table.
*
* @return UCS_OK - region was added.
* UCS_ERR_INVALID_PARAM - memory region address in invalid (misaligned or empty)
* UCS_ERR_ALREADY_EXISTS - the region overlaps with existing region.
*
*/
ucs_status_t ;
/**
* Remove a memory region from the page table.
*
* @param [in] pgtable Page table to remove the region from.
* @param [in] region Memory region to remove. This must be the same pointer
* passed to @ref ucs_pgtable_insert.
*
* @return UCS_OK - region was removed.
* UCS_ERR_INVALID_PARAM - memory region address in invalid (misaligned or empty)
* UCS_ERR_ALREADY_EXISTS - the region overlaps with existing region.
*
*/
ucs_status_t ;
/*
* Find a region which contains the given address.
*
* @param [in] pgtable Page table to search the address in.
* @param [in] address Address to search.
*
* @return Region which contains 'address', or NULL if not found.
*/
ucs_pgt_region_t *;
/**
* Search for all regions overlapping with a given address range.
*
* @param [in] pgtable Page table to search the range in.
* @param [in] from Lower bound of the range.
* @param [in] to Upper bound of the range (inclusive).
* @param [in] cb Callback to be called for every region found.
* The callback must not modify the page table.
* @param [in] arg User-defined argument to the callback.
*/
void ;
/**
* Remove all regions from the page table and call the provided callback for each.
*
* @param [in] pgtable Page table to clean up.
* @param [in] cb Callback to be called for every region, after it (and
* all others) are removed.
* The callback must not modify the page table.
* @param [in] arg User-defined argument to the callback.
*/
void ;
/**
* Dump page table to log.
*
* @param [in] pgtable Page table to dump.
* @param [in] log_level Which log level to use.
*/
void ;
/**
* @return >Number of regions currently present in the page table.
*/
static inline unsigned