1 | /* |
---|
2 | * Partition Manager |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * All rights assigned to U.S. Government, 1994. |
---|
8 | * |
---|
9 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
10 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
11 | * notice must appear in all copies of this file and its derivatives. |
---|
12 | * |
---|
13 | * $Id$ |
---|
14 | */ |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/support.h> |
---|
18 | #include <rtems/address.h> |
---|
19 | #include <rtems/config.h> |
---|
20 | #include <rtems/object.h> |
---|
21 | #include <rtems/part.h> |
---|
22 | #include <rtems/thread.h> |
---|
23 | |
---|
24 | /*PAGE |
---|
25 | * |
---|
26 | * _Partition_Manager_initialization |
---|
27 | * |
---|
28 | * This routine initializes all partition manager related |
---|
29 | * data structures. |
---|
30 | * |
---|
31 | * Input parameters: |
---|
32 | * maximum_partitions - number of partitions to initialize |
---|
33 | * |
---|
34 | * Output parameters: NONE |
---|
35 | */ |
---|
36 | |
---|
37 | void _Partition_Manager_initialization( |
---|
38 | unsigned32 maximum_partitions |
---|
39 | ) |
---|
40 | { |
---|
41 | _Objects_Initialize_information( |
---|
42 | &_Partition_Information, |
---|
43 | OBJECTS_RTEMS_PARTITIONS, |
---|
44 | TRUE, |
---|
45 | maximum_partitions, |
---|
46 | sizeof( Partition_Control ), |
---|
47 | FALSE, |
---|
48 | RTEMS_MAXIMUM_NAME_LENGTH, |
---|
49 | FALSE |
---|
50 | ); |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | /*PAGE |
---|
55 | * |
---|
56 | * rtems_partition_create |
---|
57 | * |
---|
58 | * This directive creates a partiton of fixed sized buffers from the |
---|
59 | * given contiguous memory area. |
---|
60 | * |
---|
61 | * Input parameters: |
---|
62 | * name - user defined partition name |
---|
63 | * starting_address - physical start address of partition |
---|
64 | * length - physical length in bytes |
---|
65 | * buffer_size - size of buffers in bytes |
---|
66 | * attribute_set - partition attributes |
---|
67 | * id - pointer to partition id |
---|
68 | * |
---|
69 | * Output parameters: |
---|
70 | * id - partition id |
---|
71 | * RTEMS_SUCCESSFUL - if successful |
---|
72 | * error code - if unsuccessful |
---|
73 | */ |
---|
74 | |
---|
75 | rtems_status_code rtems_partition_create( |
---|
76 | rtems_name name, |
---|
77 | void *starting_address, |
---|
78 | unsigned32 length, |
---|
79 | unsigned32 buffer_size, |
---|
80 | rtems_attribute attribute_set, |
---|
81 | Objects_Id *id |
---|
82 | ) |
---|
83 | { |
---|
84 | register Partition_Control *the_partition; |
---|
85 | |
---|
86 | if ( !rtems_is_name_valid( name ) ) |
---|
87 | return ( RTEMS_INVALID_NAME ); |
---|
88 | |
---|
89 | if ( length == 0 || buffer_size == 0 || length < buffer_size || |
---|
90 | !_Partition_Is_buffer_size_aligned( buffer_size ) ) |
---|
91 | return ( RTEMS_INVALID_SIZE ); |
---|
92 | |
---|
93 | if ( !_Addresses_Is_aligned( starting_address ) ) |
---|
94 | return( RTEMS_INVALID_ADDRESS ); |
---|
95 | |
---|
96 | if ( _Attributes_Is_global( attribute_set ) && |
---|
97 | !_Configuration_Is_multiprocessing() ) |
---|
98 | return( RTEMS_MP_NOT_CONFIGURED ); |
---|
99 | |
---|
100 | _Thread_Disable_dispatch(); /* prevents deletion */ |
---|
101 | |
---|
102 | the_partition = _Partition_Allocate(); |
---|
103 | |
---|
104 | if ( !the_partition ) { |
---|
105 | _Thread_Enable_dispatch(); |
---|
106 | return( RTEMS_TOO_MANY ); |
---|
107 | } |
---|
108 | |
---|
109 | if ( _Attributes_Is_global( attribute_set ) && |
---|
110 | !( _Objects_MP_Allocate_and_open( &_Partition_Information, name, |
---|
111 | the_partition->Object.id, FALSE ) ) ) { |
---|
112 | _Partition_Free( the_partition ); |
---|
113 | _Thread_Enable_dispatch(); |
---|
114 | return( RTEMS_TOO_MANY ); |
---|
115 | } |
---|
116 | the_partition->starting_address = starting_address; |
---|
117 | the_partition->length = length; |
---|
118 | the_partition->buffer_size = buffer_size; |
---|
119 | the_partition->attribute_set = attribute_set; |
---|
120 | the_partition->number_of_used_blocks = 0; |
---|
121 | |
---|
122 | _Chain_Initialize( &the_partition->Memory, starting_address, |
---|
123 | length / buffer_size, buffer_size ); |
---|
124 | |
---|
125 | _Objects_Open( &_Partition_Information, &the_partition->Object, &name ); |
---|
126 | |
---|
127 | *id = the_partition->Object.id; |
---|
128 | if ( _Attributes_Is_global( attribute_set ) ) |
---|
129 | _Partition_MP_Send_process_packet( |
---|
130 | PARTITION_MP_ANNOUNCE_CREATE, |
---|
131 | the_partition->Object.id, |
---|
132 | name, |
---|
133 | 0 /* Not used */ |
---|
134 | ); |
---|
135 | |
---|
136 | _Thread_Enable_dispatch(); |
---|
137 | return( RTEMS_SUCCESSFUL ); |
---|
138 | } |
---|
139 | |
---|
140 | /*PAGE |
---|
141 | * |
---|
142 | * rtems_partition_ident |
---|
143 | * |
---|
144 | * This directive returns the system ID associated with |
---|
145 | * the partition name. |
---|
146 | * |
---|
147 | * Input parameters: |
---|
148 | * name - user defined partition name |
---|
149 | * node - node(s) to be searched |
---|
150 | * id - pointer to partition id |
---|
151 | * |
---|
152 | * Output parameters: |
---|
153 | * *id - partition id |
---|
154 | * RTEMS_SUCCESSFUL - if successful |
---|
155 | * error code - if unsuccessful |
---|
156 | */ |
---|
157 | |
---|
158 | rtems_status_code rtems_partition_ident( |
---|
159 | rtems_name name, |
---|
160 | unsigned32 node, |
---|
161 | Objects_Id *id |
---|
162 | ) |
---|
163 | { |
---|
164 | return _Objects_Name_to_id( &_Partition_Information, &name, node, id ); |
---|
165 | } |
---|
166 | |
---|
167 | /*PAGE |
---|
168 | * |
---|
169 | * rtems_partition_delete |
---|
170 | * |
---|
171 | * This directive allows a thread to delete a partition specified by |
---|
172 | * the partition identifier, provided that none of its buffers are |
---|
173 | * still allocated. |
---|
174 | * |
---|
175 | * Input parameters: |
---|
176 | * id - partition id |
---|
177 | * |
---|
178 | * Output parameters: |
---|
179 | * RTEMS_SUCCESSFUL - if successful |
---|
180 | * error code - if unsuccessful |
---|
181 | */ |
---|
182 | |
---|
183 | rtems_status_code rtems_partition_delete( |
---|
184 | Objects_Id id |
---|
185 | ) |
---|
186 | { |
---|
187 | register Partition_Control *the_partition; |
---|
188 | Objects_Locations location; |
---|
189 | |
---|
190 | the_partition = _Partition_Get( id, &location ); |
---|
191 | switch ( location ) { |
---|
192 | case OBJECTS_ERROR: |
---|
193 | return( RTEMS_INVALID_ID ); |
---|
194 | case OBJECTS_REMOTE: |
---|
195 | _Thread_Dispatch(); |
---|
196 | return( RTEMS_ILLEGAL_ON_REMOTE_OBJECT ); |
---|
197 | case OBJECTS_LOCAL: |
---|
198 | if ( the_partition->number_of_used_blocks == 0 ) { |
---|
199 | _Objects_Close( &_Partition_Information, &the_partition->Object ); |
---|
200 | _Partition_Free( the_partition ); |
---|
201 | if ( _Attributes_Is_global( the_partition->attribute_set ) ) { |
---|
202 | |
---|
203 | _Objects_MP_Close( |
---|
204 | &_Partition_Information, |
---|
205 | the_partition->Object.id |
---|
206 | ); |
---|
207 | |
---|
208 | _Partition_MP_Send_process_packet( |
---|
209 | PARTITION_MP_ANNOUNCE_DELETE, |
---|
210 | the_partition->Object.id, |
---|
211 | 0, /* Not used */ |
---|
212 | 0 /* Not used */ |
---|
213 | ); |
---|
214 | } |
---|
215 | |
---|
216 | _Thread_Enable_dispatch(); |
---|
217 | return( RTEMS_SUCCESSFUL ); |
---|
218 | } |
---|
219 | _Thread_Enable_dispatch(); |
---|
220 | return( RTEMS_RESOURCE_IN_USE ); |
---|
221 | } |
---|
222 | |
---|
223 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
224 | } |
---|
225 | |
---|
226 | /*PAGE |
---|
227 | * |
---|
228 | * rtems_partition_get_buffer |
---|
229 | * |
---|
230 | * This directive will obtain a buffer from a buffer partition. |
---|
231 | * |
---|
232 | * Input parameters: |
---|
233 | * id - partition id |
---|
234 | * buffer - pointer to buffer address |
---|
235 | * |
---|
236 | * Output parameters: |
---|
237 | * buffer - pointer to buffer address filled in |
---|
238 | * RTEMS_SUCCESSFUL - if successful |
---|
239 | * error code - if unsuccessful |
---|
240 | */ |
---|
241 | |
---|
242 | rtems_status_code rtems_partition_get_buffer( |
---|
243 | Objects_Id id, |
---|
244 | void **buffer |
---|
245 | ) |
---|
246 | { |
---|
247 | register Partition_Control *the_partition; |
---|
248 | Objects_Locations location; |
---|
249 | void *the_buffer; |
---|
250 | |
---|
251 | the_partition = _Partition_Get( id, &location ); |
---|
252 | switch ( location ) { |
---|
253 | case OBJECTS_ERROR: |
---|
254 | return( RTEMS_INVALID_ID ); |
---|
255 | case OBJECTS_REMOTE: |
---|
256 | _Thread_Executing->Wait.return_argument = buffer; |
---|
257 | return( |
---|
258 | _Partition_MP_Send_request_packet( |
---|
259 | PARTITION_MP_GET_BUFFER_REQUEST, |
---|
260 | id, |
---|
261 | 0 /* Not used */ |
---|
262 | ) |
---|
263 | ); |
---|
264 | case OBJECTS_LOCAL: |
---|
265 | the_buffer = _Partition_Allocate_buffer( the_partition ); |
---|
266 | if ( the_buffer ) { |
---|
267 | the_partition->number_of_used_blocks += 1; |
---|
268 | _Thread_Enable_dispatch(); |
---|
269 | *buffer = the_buffer; |
---|
270 | return( RTEMS_SUCCESSFUL ); |
---|
271 | } |
---|
272 | _Thread_Enable_dispatch(); |
---|
273 | return( RTEMS_UNSATISFIED ); |
---|
274 | } |
---|
275 | |
---|
276 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
277 | } |
---|
278 | |
---|
279 | /*PAGE |
---|
280 | * |
---|
281 | * rtems_partition_return_buffer |
---|
282 | * |
---|
283 | * This directive will return the given buffer to the specified |
---|
284 | * buffer partition. |
---|
285 | * |
---|
286 | * Input parameters: |
---|
287 | * id - partition id |
---|
288 | * buffer - pointer to buffer address |
---|
289 | * |
---|
290 | * Output parameters: |
---|
291 | * RTEMS_SUCCESSFUL - if successful |
---|
292 | * error code - if unsuccessful |
---|
293 | */ |
---|
294 | |
---|
295 | rtems_status_code rtems_partition_return_buffer( |
---|
296 | Objects_Id id, |
---|
297 | void *buffer |
---|
298 | ) |
---|
299 | { |
---|
300 | register Partition_Control *the_partition; |
---|
301 | Objects_Locations location; |
---|
302 | |
---|
303 | the_partition = _Partition_Get( id, &location ); |
---|
304 | switch ( location ) { |
---|
305 | case OBJECTS_ERROR: |
---|
306 | return( RTEMS_INVALID_ID ); |
---|
307 | case OBJECTS_REMOTE: |
---|
308 | return( |
---|
309 | _Partition_MP_Send_request_packet( |
---|
310 | PARTITION_MP_RETURN_BUFFER_REQUEST, |
---|
311 | id, |
---|
312 | buffer |
---|
313 | ) |
---|
314 | ); |
---|
315 | case OBJECTS_LOCAL: |
---|
316 | if ( _Partition_Is_buffer_valid( buffer, the_partition ) ) { |
---|
317 | _Partition_Free_buffer( the_partition, buffer ); |
---|
318 | the_partition->number_of_used_blocks -= 1; |
---|
319 | _Thread_Enable_dispatch(); |
---|
320 | return( RTEMS_SUCCESSFUL ); |
---|
321 | } |
---|
322 | _Thread_Enable_dispatch(); |
---|
323 | return( RTEMS_INVALID_ADDRESS ); |
---|
324 | } |
---|
325 | |
---|
326 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
327 | } |
---|