source: rtems/cpukit/rtems/src/part.c @ 3235ad9

4.104.114.84.95
Last change on this file since 3235ad9 was 3235ad9, checked in by Joel Sherrill <joel.sherrill@…>, on 08/23/95 at 19:30:23

Support for variable length names added to Object Handler. This supports
both fixed length "raw" names and strings from the API's point of view.

Both inline and macro implementations were tested.

  • Property mode set to 100644
File size: 8.5 KB
Line 
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
37void _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  );
50
51}
52
53/*PAGE
54 *
55 *  rtems_partition_create
56 *
57 *  This directive creates a partiton of fixed sized buffers from the
58 *  given contiguous memory area.
59 *
60 *  Input parameters:
61 *    name             - user defined partition name
62 *    starting_address - physical start address of partition
63 *    length           - physical length in bytes
64 *    buffer_size      - size of buffers in bytes
65 *    attribute_set    - partition attributes
66 *    id               - pointer to partition id
67 *
68 *  Output parameters:
69 *    id                - partition id
70 *    RTEMS_SUCCESSFUL - if successful
71 *    error code        - if unsuccessful
72 */
73
74rtems_status_code rtems_partition_create(
75  rtems_name          name,
76  void               *starting_address,
77  unsigned32          length,
78  unsigned32          buffer_size,
79  rtems_attribute  attribute_set,
80  Objects_Id         *id
81)
82{
83  register Partition_Control *the_partition;
84
85  if ( !rtems_is_name_valid( name ) )
86    return ( RTEMS_INVALID_NAME );
87
88  if ( length == 0 || buffer_size == 0 || length < buffer_size ||
89         !_Partition_Is_buffer_size_aligned( buffer_size ) )
90    return ( RTEMS_INVALID_SIZE );
91
92  if ( !_Addresses_Is_aligned( starting_address ) )
93     return( RTEMS_INVALID_ADDRESS );
94
95  if ( _Attributes_Is_global( attribute_set ) &&
96       !_Configuration_Is_multiprocessing() )
97    return( RTEMS_MP_NOT_CONFIGURED );
98
99  _Thread_Disable_dispatch();               /* prevents deletion */
100
101  the_partition = _Partition_Allocate();
102
103  if ( !the_partition ) {
104    _Thread_Enable_dispatch();
105    return( RTEMS_TOO_MANY );
106  }
107
108  if ( _Attributes_Is_global( attribute_set ) &&
109       !( _Objects_MP_Open( &_Partition_Information, name,
110                            the_partition->Object.id, FALSE ) ) ) {
111    _Partition_Free( the_partition );
112    _Thread_Enable_dispatch();
113    return( RTEMS_TOO_MANY );
114  }
115  the_partition->starting_address      = starting_address;
116  the_partition->length                = length;
117  the_partition->buffer_size           = buffer_size;
118  the_partition->attribute_set         = attribute_set;
119  the_partition->number_of_used_blocks = 0;
120
121  _Chain_Initialize( &the_partition->Memory, starting_address,
122                        length / buffer_size, buffer_size );
123
124  _Objects_Open( &_Partition_Information, &the_partition->Object, &name );
125
126  *id = the_partition->Object.id;
127  if ( _Attributes_Is_global( attribute_set ) )
128    _Partition_MP_Send_process_packet(
129      PARTITION_MP_ANNOUNCE_CREATE,
130      the_partition->Object.id,
131      name,
132      0                  /* Not used */
133    );
134
135  _Thread_Enable_dispatch();
136  return( RTEMS_SUCCESSFUL );
137}
138
139/*PAGE
140 *
141 *  rtems_partition_ident
142 *
143 *  This directive returns the system ID associated with
144 *  the partition name.
145 *
146 *  Input parameters:
147 *    name - user defined partition name
148 *    node - node(s) to be searched
149 *    id   - pointer to partition id
150 *
151 *  Output parameters:
152 *    *id               - partition id
153 *    RTEMS_SUCCESSFUL - if successful
154 *    error code        - if unsuccessful
155 */
156
157rtems_status_code rtems_partition_ident(
158  rtems_name    name,
159  unsigned32    node,
160  Objects_Id   *id
161)
162{
163  return _Objects_Name_to_id( &_Partition_Information, &name, node, id );
164}
165
166/*PAGE
167 *
168 *  rtems_partition_delete
169 *
170 *  This directive allows a thread to delete a partition specified by
171 *  the partition identifier, provided that none of its buffers are
172 *  still allocated.
173 *
174 *  Input parameters:
175 *    id - partition id
176 *
177 *  Output parameters:
178 *    RTEMS_SUCCESSFUL - if successful
179 *    error code        - if unsuccessful
180 */
181
182rtems_status_code rtems_partition_delete(
183  Objects_Id id
184)
185{
186  register Partition_Control *the_partition;
187  Objects_Locations                  location;
188
189  the_partition = _Partition_Get( id, &location );
190  switch ( location ) {
191    case OBJECTS_ERROR:
192      return( RTEMS_INVALID_ID );
193    case OBJECTS_REMOTE:
194      _Thread_Dispatch();
195      return( RTEMS_ILLEGAL_ON_REMOTE_OBJECT );
196    case OBJECTS_LOCAL:
197      if ( the_partition->number_of_used_blocks == 0 ) {
198        _Objects_Close( &_Partition_Information, &the_partition->Object );
199        _Partition_Free( the_partition );
200        if ( _Attributes_Is_global( the_partition->attribute_set ) ) {
201
202          _Objects_MP_Close(
203            &_Partition_Information,
204            the_partition->Object.id
205          );
206
207          _Partition_MP_Send_process_packet(
208            PARTITION_MP_ANNOUNCE_DELETE,
209            the_partition->Object.id,
210            0,                         /* Not used */
211            0                          /* Not used */
212          );
213        }
214
215        _Thread_Enable_dispatch();
216        return( RTEMS_SUCCESSFUL );
217      }
218      _Thread_Enable_dispatch();
219      return( RTEMS_RESOURCE_IN_USE );
220  }
221
222  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
223}
224
225/*PAGE
226 *
227 *  rtems_partition_get_buffer
228 *
229 *  This directive will obtain a buffer from a buffer partition.
230 *
231 *  Input parameters:
232 *    id     - partition id
233 *    buffer - pointer to buffer address
234 *
235 *  Output parameters:
236 *    buffer            - pointer to buffer address filled in
237 *    RTEMS_SUCCESSFUL - if successful
238 *    error code        - if unsuccessful
239 */
240
241rtems_status_code rtems_partition_get_buffer(
242  Objects_Id   id,
243  void       **buffer
244)
245{
246  register Partition_Control *the_partition;
247  Objects_Locations           location;
248  void                       *the_buffer;
249
250  the_partition = _Partition_Get( id, &location );
251  switch ( location ) {
252    case OBJECTS_ERROR:
253      return( RTEMS_INVALID_ID );
254    case OBJECTS_REMOTE:
255      _Thread_Executing->Wait.return_argument = buffer;
256      return(
257        _Partition_MP_Send_request_packet(
258          PARTITION_MP_GET_BUFFER_REQUEST,
259          id,
260          0           /* Not used */
261        )
262      );
263    case OBJECTS_LOCAL:
264      the_buffer = _Partition_Allocate_buffer( the_partition );
265      if ( the_buffer ) {
266        the_partition->number_of_used_blocks += 1;
267        _Thread_Enable_dispatch();
268        *buffer = the_buffer;
269        return( RTEMS_SUCCESSFUL );
270      }
271      _Thread_Enable_dispatch();
272      return( RTEMS_UNSATISFIED );
273  }
274
275  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
276}
277
278/*PAGE
279 *
280 *  rtems_partition_return_buffer
281 *
282 *  This directive will return the given buffer to the specified
283 *  buffer partition.
284 *
285 *  Input parameters:
286 *    id     - partition id
287 *    buffer - pointer to buffer address
288 *
289 *  Output parameters:
290 *    RTEMS_SUCCESSFUL - if successful
291 *    error code - if unsuccessful
292 */
293
294rtems_status_code rtems_partition_return_buffer(
295  Objects_Id  id,
296  void       *buffer
297)
298{
299  register Partition_Control *the_partition;
300  Objects_Locations           location;
301
302  the_partition = _Partition_Get( id, &location );
303  switch ( location ) {
304    case OBJECTS_ERROR:
305      return( RTEMS_INVALID_ID );
306    case OBJECTS_REMOTE:
307      return(
308        _Partition_MP_Send_request_packet(
309          PARTITION_MP_RETURN_BUFFER_REQUEST,
310          id,
311          buffer
312        )
313      );
314    case OBJECTS_LOCAL:
315      if ( _Partition_Is_buffer_valid( buffer, the_partition ) ) {
316        _Partition_Free_buffer( the_partition, buffer );
317        the_partition->number_of_used_blocks -= 1;
318        _Thread_Enable_dispatch();
319        return( RTEMS_SUCCESSFUL );
320      }
321      _Thread_Enable_dispatch();
322      return( RTEMS_INVALID_ADDRESS );
323  }
324
325  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
326}
Note: See TracBrowser for help on using the repository browser.