source: rtems/cpukit/rtems/src/part.c @ 88d594a

4.104.114.84.95
Last change on this file since 88d594a was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

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