source: rtems/cpukit/rtems/src/part.c @ 9863dbf

4.104.114.84.95
Last change on this file since 9863dbf was 9863dbf, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 18, 1995 at 9:42:58 PM

+ Added object type field to object id.

+ Added name pointer to Object_Control.

+ Modified Object Open and Close to address name field.

+ Removed name as separate element from Thread and Proxy Control.

+ Added parameter "object class" to calls to Initialize Information

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