1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicPart Partitions |
---|
5 | * |
---|
6 | * @brief RTEMS Partition Create |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2014. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifdef HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/rtems/partimpl.h> |
---|
23 | #include <rtems/rtems/attrimpl.h> |
---|
24 | #include <rtems/rtems/support.h> |
---|
25 | #include <rtems/score/threaddispatch.h> |
---|
26 | #include <rtems/score/sysstate.h> |
---|
27 | #include <rtems/sysinit.h> |
---|
28 | |
---|
29 | |
---|
30 | rtems_status_code rtems_partition_create( |
---|
31 | rtems_name name, |
---|
32 | void *starting_address, |
---|
33 | uintptr_t length, |
---|
34 | size_t buffer_size, |
---|
35 | rtems_attribute attribute_set, |
---|
36 | rtems_id *id |
---|
37 | ) |
---|
38 | { |
---|
39 | Partition_Control *the_partition; |
---|
40 | |
---|
41 | if ( !rtems_is_name_valid( name ) ) |
---|
42 | return RTEMS_INVALID_NAME; |
---|
43 | |
---|
44 | if ( !starting_address ) |
---|
45 | return RTEMS_INVALID_ADDRESS; |
---|
46 | |
---|
47 | if ( !id ) |
---|
48 | return RTEMS_INVALID_ADDRESS; |
---|
49 | |
---|
50 | if ( length == 0 ) |
---|
51 | return RTEMS_INVALID_SIZE; |
---|
52 | |
---|
53 | if ( buffer_size == 0 ) |
---|
54 | return RTEMS_INVALID_SIZE; |
---|
55 | |
---|
56 | if ( length < buffer_size ) |
---|
57 | return RTEMS_INVALID_SIZE; |
---|
58 | |
---|
59 | if ( !_Partition_Is_buffer_size_aligned( buffer_size ) ) |
---|
60 | return RTEMS_INVALID_SIZE; |
---|
61 | |
---|
62 | if ( buffer_size < sizeof( Chain_Node ) ) |
---|
63 | return RTEMS_INVALID_SIZE; |
---|
64 | |
---|
65 | if ( !_Partition_Is_buffer_area_aligned( starting_address ) ) |
---|
66 | return RTEMS_INVALID_ADDRESS; |
---|
67 | |
---|
68 | #if defined(RTEMS_MULTIPROCESSING) |
---|
69 | if ( _Attributes_Is_global( attribute_set ) && |
---|
70 | !_System_state_Is_multiprocessing ) |
---|
71 | return RTEMS_MP_NOT_CONFIGURED; |
---|
72 | #endif |
---|
73 | |
---|
74 | the_partition = _Partition_Allocate(); |
---|
75 | |
---|
76 | if ( !the_partition ) { |
---|
77 | _Objects_Allocator_unlock(); |
---|
78 | return RTEMS_TOO_MANY; |
---|
79 | } |
---|
80 | |
---|
81 | #if defined(RTEMS_MULTIPROCESSING) |
---|
82 | if ( _Attributes_Is_global( attribute_set ) && |
---|
83 | !( _Objects_MP_Allocate_and_open( &_Partition_Information, name, |
---|
84 | the_partition->Object.id, false ) ) ) { |
---|
85 | _Partition_Free( the_partition ); |
---|
86 | _Objects_Allocator_unlock(); |
---|
87 | return RTEMS_TOO_MANY; |
---|
88 | } |
---|
89 | #endif |
---|
90 | |
---|
91 | _Partition_Initialize( |
---|
92 | the_partition, |
---|
93 | starting_address, |
---|
94 | length, |
---|
95 | buffer_size, |
---|
96 | attribute_set |
---|
97 | ); |
---|
98 | |
---|
99 | _Objects_Open( |
---|
100 | &_Partition_Information, |
---|
101 | &the_partition->Object, |
---|
102 | (Objects_Name) name |
---|
103 | ); |
---|
104 | |
---|
105 | *id = the_partition->Object.id; |
---|
106 | #if defined(RTEMS_MULTIPROCESSING) |
---|
107 | if ( _Attributes_Is_global( attribute_set ) ) |
---|
108 | _Partition_MP_Send_process_packet( |
---|
109 | PARTITION_MP_ANNOUNCE_CREATE, |
---|
110 | the_partition->Object.id, |
---|
111 | name, |
---|
112 | 0 /* Not used */ |
---|
113 | ); |
---|
114 | #endif |
---|
115 | |
---|
116 | _Objects_Allocator_unlock(); |
---|
117 | return RTEMS_SUCCESSFUL; |
---|
118 | } |
---|
119 | |
---|
120 | static void _Partition_Manager_initialization( void ) |
---|
121 | { |
---|
122 | _Objects_Initialize_information( &_Partition_Information ); |
---|
123 | } |
---|
124 | |
---|
125 | RTEMS_SYSINIT_ITEM( |
---|
126 | _Partition_Manager_initialization, |
---|
127 | RTEMS_SYSINIT_CLASSIC_PARTITION, |
---|
128 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
129 | ); |
---|