source: rtems/cpukit/rtems/src/part.c @ 98e4ebf

4.104.114.84.95
Last change on this file since 98e4ebf was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

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