source: rtems/cpukit/rtems/src/part.c @ 97e2729d

4.104.114.84.95
Last change on this file since 97e2729d was 97e2729d, checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 17:38:09

Added --disable-multiprocessing flag and modified a lot of files to make
it work.

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