1 | /** |
---|
2 | * @file rtems/rtems/region.h |
---|
3 | * |
---|
4 | * This include file contains all the constants and structures associated |
---|
5 | * with the Region Manager. This manager provides facilities to dynamically |
---|
6 | * allocate memory in variable sized units which are returned as segments. |
---|
7 | * |
---|
8 | * Directives provided are: |
---|
9 | * |
---|
10 | * - create a region |
---|
11 | * - get an ID of a region |
---|
12 | * - delete a region |
---|
13 | * - get a segment from a region |
---|
14 | * - return a segment to a region |
---|
15 | */ |
---|
16 | |
---|
17 | /* COPYRIGHT (c) 1989-2008. |
---|
18 | * On-Line Applications Research Corporation (OAR). |
---|
19 | * |
---|
20 | * The license and distribution terms for this file may be |
---|
21 | * found in the file LICENSE in this distribution or at |
---|
22 | * http://www.rtems.com/license/LICENSE. |
---|
23 | * |
---|
24 | * $Id$ |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef _RTEMS_RTEMS_REGION_H |
---|
28 | #define _RTEMS_RTEMS_REGION_H |
---|
29 | |
---|
30 | #include <stddef.h> |
---|
31 | |
---|
32 | #include <rtems/score/object.h> |
---|
33 | #include <rtems/score/threadq.h> |
---|
34 | #include <rtems/score/heap.h> |
---|
35 | #include <rtems/debug.h> |
---|
36 | #include <rtems/rtems/attr.h> |
---|
37 | #include <rtems/rtems/options.h> |
---|
38 | #include <rtems/rtems/status.h> |
---|
39 | #include <rtems/rtems/support.h> |
---|
40 | #include <rtems/rtems/types.h> |
---|
41 | |
---|
42 | /** |
---|
43 | * @defgroup ClassicRegion Classic API Region |
---|
44 | * |
---|
45 | * This encapsulates functionality which XXX |
---|
46 | */ |
---|
47 | /**@{*/ |
---|
48 | |
---|
49 | /** |
---|
50 | * This constant is defined to extern most of the time when using |
---|
51 | * this header file. However by defining it to nothing, the data |
---|
52 | * declared in this header file can be instantiated. This is done |
---|
53 | * in a single per manager file. |
---|
54 | */ |
---|
55 | #ifndef RTEMS_REGION_EXTERN |
---|
56 | #define RTEMS_REGION_EXTERN extern |
---|
57 | #endif |
---|
58 | |
---|
59 | #ifdef __cplusplus |
---|
60 | extern "C" { |
---|
61 | #endif |
---|
62 | |
---|
63 | /** |
---|
64 | * The following records define the control block used to manage |
---|
65 | * each region. |
---|
66 | */ |
---|
67 | |
---|
68 | typedef struct { |
---|
69 | Objects_Control Object; |
---|
70 | Thread_queue_Control Wait_queue; /* waiting threads */ |
---|
71 | void *starting_address; /* physical start addr */ |
---|
72 | intptr_t length; /* physical length(bytes) */ |
---|
73 | uint32_t page_size; /* in bytes */ |
---|
74 | intptr_t maximum_segment_size; /* in bytes */ |
---|
75 | rtems_attribute attribute_set; |
---|
76 | uint32_t number_of_used_blocks; /* blocks allocated */ |
---|
77 | Heap_Control Memory; |
---|
78 | } Region_Control; |
---|
79 | |
---|
80 | /** |
---|
81 | * The following defines the information control block used to |
---|
82 | * manage this class of objects. |
---|
83 | */ |
---|
84 | RTEMS_REGION_EXTERN Objects_Information _Region_Information; |
---|
85 | |
---|
86 | /** |
---|
87 | * @brief _Region_Manager_initialization |
---|
88 | * |
---|
89 | * This routine performs the initialization necessary for this manager. |
---|
90 | */ |
---|
91 | void _Region_Manager_initialization(void); |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief rtems_region_create |
---|
95 | * |
---|
96 | * This routine implements the rtems_region_create directive. The |
---|
97 | * region will have the name name. The memory area managed by |
---|
98 | * the region is of length bytes and starts at starting_address. |
---|
99 | * The memory area will be divided into as many allocatable units of |
---|
100 | * page_size bytes as possible. The attribute_set determines which |
---|
101 | * thread queue discipline is used by the region. It returns the |
---|
102 | * id of the created region in ID. |
---|
103 | */ |
---|
104 | rtems_status_code rtems_region_create( |
---|
105 | rtems_name name, |
---|
106 | void *starting_address, |
---|
107 | intptr_t length, |
---|
108 | uint32_t page_size, |
---|
109 | rtems_attribute attribute_set, |
---|
110 | Objects_Id *id |
---|
111 | ); |
---|
112 | |
---|
113 | /** |
---|
114 | * @brief rtems_region_extend |
---|
115 | * |
---|
116 | * This routine implements the rtems_region_extend directive. The |
---|
117 | * region will have the name name. The memory area managed by |
---|
118 | * the region will be attempted to be grown by length bytes using |
---|
119 | * the memory starting at starting_address. |
---|
120 | */ |
---|
121 | rtems_status_code rtems_region_extend( |
---|
122 | Objects_Id id, |
---|
123 | void *starting_address, |
---|
124 | intptr_t length |
---|
125 | ); |
---|
126 | |
---|
127 | /** |
---|
128 | * @brief rtems_region_ident |
---|
129 | * |
---|
130 | * This routine implements the rtems_region_ident directive. |
---|
131 | * This directive returns the region ID associated with name. |
---|
132 | * If more than one region is named name, then the region |
---|
133 | * to which the ID belongs is arbitrary. |
---|
134 | */ |
---|
135 | rtems_status_code rtems_region_ident( |
---|
136 | rtems_name name, |
---|
137 | Objects_Id *id |
---|
138 | ); |
---|
139 | |
---|
140 | /** |
---|
141 | * @brief rtems_region_get_information |
---|
142 | * |
---|
143 | * This routine implements the rtems_region_get_information directive. |
---|
144 | * This directive returns information about the heap associated with |
---|
145 | * this region. |
---|
146 | */ |
---|
147 | rtems_status_code rtems_region_get_information( |
---|
148 | Objects_Id id, |
---|
149 | Heap_Information_block *the_info |
---|
150 | ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief rtems_region_get_free_information |
---|
154 | * |
---|
155 | * This routine implements the rtems_region_get_free_information directive. |
---|
156 | * This directive returns information about the free blocks in the |
---|
157 | * heap associated with this region. |
---|
158 | */ |
---|
159 | rtems_status_code rtems_region_get_free_information( |
---|
160 | Objects_Id id, |
---|
161 | Heap_Information_block *the_info |
---|
162 | ); |
---|
163 | |
---|
164 | /** |
---|
165 | * @brief rtems_region_delete |
---|
166 | * |
---|
167 | * This routine implements the rtems_region_delete directive. The |
---|
168 | * region indicated by ID is deleted. |
---|
169 | */ |
---|
170 | rtems_status_code rtems_region_delete( |
---|
171 | Objects_Id id |
---|
172 | ); |
---|
173 | |
---|
174 | /** |
---|
175 | * @brief rtems_region_get_segment |
---|
176 | * |
---|
177 | * This routine implements the rtems_region_get_segment directive. It |
---|
178 | * attempts to allocate a segment from the region associated with ID. |
---|
179 | * If a segment of the requested size can be allocated, its address |
---|
180 | * is returned in segment. If no segment is available, then the task |
---|
181 | * may return immediately or block waiting for a segment with an optional |
---|
182 | * timeout of timeout clock ticks. Whether the task blocks or returns |
---|
183 | * immediately is based on the no_wait option in the option_set. |
---|
184 | */ |
---|
185 | rtems_status_code rtems_region_get_segment( |
---|
186 | Objects_Id id, |
---|
187 | intptr_t size, |
---|
188 | rtems_option option_set, |
---|
189 | rtems_interval timeout, |
---|
190 | void **segment |
---|
191 | ); |
---|
192 | |
---|
193 | /** |
---|
194 | * @brief rtems_region_get_segment_size |
---|
195 | * |
---|
196 | * This routine implements the rtems_region_get_segment_size directive. It |
---|
197 | * returns the size in bytes of the specified user memory area. |
---|
198 | */ |
---|
199 | rtems_status_code rtems_region_get_segment_size( |
---|
200 | Objects_Id id, |
---|
201 | void *segment, |
---|
202 | intptr_t *size |
---|
203 | ); |
---|
204 | |
---|
205 | /** |
---|
206 | * @brief rtems_region_return_segment |
---|
207 | * |
---|
208 | * This routine implements the rtems_region_return_segment directive. It |
---|
209 | * frees the segment to the region associated with ID. The segment must |
---|
210 | * have been previously allocated from the same region. If freeing the |
---|
211 | * segment results in enough memory being available to satisfy the |
---|
212 | * rtems_region_get_segment of the first blocked task, then that task and as |
---|
213 | * many subsequent tasks as possible will be unblocked with their requests |
---|
214 | * satisfied. |
---|
215 | */ |
---|
216 | rtems_status_code rtems_region_return_segment( |
---|
217 | Objects_Id id, |
---|
218 | void *segment |
---|
219 | ); |
---|
220 | |
---|
221 | /** |
---|
222 | * @brief rtems_region_resize_segment |
---|
223 | * |
---|
224 | * This routine implements the rtems_region_resize_segment directive. It |
---|
225 | * tries to resize segment in the region associated with 'id' to the new size |
---|
226 | * 'size' in place. The first 'size' or old size bytes of the segment |
---|
227 | * (whatever is less) are guaranteed to remain unmodified. The segment must |
---|
228 | * have been previously allocated from the same region. If resizing the |
---|
229 | * segment results in enough memory being available to satisfy the |
---|
230 | * rtems_region_get_segment of the first blocked task, then that task and as |
---|
231 | * many subsequent tasks as possible will be unblocked with their requests |
---|
232 | * satisfied. |
---|
233 | * Returns: |
---|
234 | * RTEMS_SUCCESSFUL - operation successful |
---|
235 | * RTEMS_UNSATISFIED - the segment can't be resized in place |
---|
236 | * any other code - failure. |
---|
237 | * On RTEMS_SUCCESSFUL or RTEMS_UNSATISFIED exit it returns into the |
---|
238 | * 'old_size' the old size in bytes of the user memory area of the specified |
---|
239 | * segment. |
---|
240 | */ |
---|
241 | rtems_status_code rtems_region_resize_segment( |
---|
242 | Objects_Id id, |
---|
243 | void *segment, |
---|
244 | intptr_t size, |
---|
245 | intptr_t *old_size |
---|
246 | ); |
---|
247 | |
---|
248 | #ifndef __RTEMS_APPLICATION__ |
---|
249 | #include <rtems/rtems/region.inl> |
---|
250 | /** |
---|
251 | * @brief Region_Process_queue |
---|
252 | * |
---|
253 | * This is a helper routine which is invoked any time memory is |
---|
254 | * freed. It looks at the set of waiting tasks and attempts to |
---|
255 | * satisfy all outstanding requests. |
---|
256 | */ |
---|
257 | extern void _Region_Process_queue(Region_Control *the_region); |
---|
258 | |
---|
259 | #endif |
---|
260 | |
---|
261 | #if defined(RTEMS_MULTIPROCESSING) |
---|
262 | #include <rtems/rtems/regionmp.h> |
---|
263 | #endif |
---|
264 | |
---|
265 | /** |
---|
266 | * @brief _Region_Debug_Walk |
---|
267 | * |
---|
268 | * This routine is invoked to verify the integrity of a heap associated |
---|
269 | * with the_region. |
---|
270 | */ |
---|
271 | #ifdef RTEMS_DEBUG |
---|
272 | |
---|
273 | #define _Region_Debug_Walk( _the_region, _source ) \ |
---|
274 | do { \ |
---|
275 | if ( _Debug_Is_enabled( RTEMS_DEBUG_REGION ) ) \ |
---|
276 | _Heap_Walk( &(_the_region)->Memory, _source, false ); \ |
---|
277 | } while ( 0 ) |
---|
278 | |
---|
279 | #else |
---|
280 | |
---|
281 | #define _Region_Debug_Walk( _the_region, _source ) |
---|
282 | |
---|
283 | #endif |
---|
284 | |
---|
285 | #ifdef __cplusplus |
---|
286 | } |
---|
287 | #endif |
---|
288 | |
---|
289 | /**@}*/ |
---|
290 | |
---|
291 | #endif |
---|
292 | /* end of include file */ |
---|