1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Partition Create |
---|
5 | * @ingroup ClassicPart Partitions |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/partimpl.h> |
---|
22 | #include <rtems/rtems/attrimpl.h> |
---|
23 | #include <rtems/rtems/support.h> |
---|
24 | #include <rtems/score/threaddispatch.h> |
---|
25 | #include <rtems/score/sysstate.h> |
---|
26 | |
---|
27 | /* |
---|
28 | * rtems_partition_create |
---|
29 | * |
---|
30 | * This directive creates a partiton of fixed sized buffers from the |
---|
31 | * given contiguous memory area. |
---|
32 | * |
---|
33 | * Input parameters: |
---|
34 | * name - user defined partition name |
---|
35 | * starting_address - physical start address of partition |
---|
36 | * length - physical length in bytes |
---|
37 | * buffer_size - size of buffers in bytes |
---|
38 | * attribute_set - partition attributes |
---|
39 | * id - pointer to partition id |
---|
40 | * |
---|
41 | * Output parameters: |
---|
42 | * id - partition id |
---|
43 | * RTEMS_SUCCESSFUL - if successful |
---|
44 | * error code - if unsuccessful |
---|
45 | */ |
---|
46 | |
---|
47 | rtems_status_code rtems_partition_create( |
---|
48 | rtems_name name, |
---|
49 | void *starting_address, |
---|
50 | uint32_t length, |
---|
51 | uint32_t buffer_size, |
---|
52 | rtems_attribute attribute_set, |
---|
53 | rtems_id *id |
---|
54 | ) |
---|
55 | { |
---|
56 | Partition_Control *the_partition; |
---|
57 | |
---|
58 | if ( !rtems_is_name_valid( name ) ) |
---|
59 | return RTEMS_INVALID_NAME; |
---|
60 | |
---|
61 | if ( !starting_address ) |
---|
62 | return RTEMS_INVALID_ADDRESS; |
---|
63 | |
---|
64 | if ( !id ) |
---|
65 | return RTEMS_INVALID_ADDRESS; |
---|
66 | |
---|
67 | if ( length == 0 || buffer_size == 0 || length < buffer_size || |
---|
68 | !_Partition_Is_buffer_size_aligned( buffer_size ) ) |
---|
69 | return RTEMS_INVALID_SIZE; |
---|
70 | |
---|
71 | if ( !_Addresses_Is_aligned( starting_address ) ) |
---|
72 | return RTEMS_INVALID_ADDRESS; |
---|
73 | |
---|
74 | #if defined(RTEMS_MULTIPROCESSING) |
---|
75 | if ( _Attributes_Is_global( attribute_set ) && |
---|
76 | !_System_state_Is_multiprocessing ) |
---|
77 | return RTEMS_MP_NOT_CONFIGURED; |
---|
78 | #endif |
---|
79 | |
---|
80 | _Thread_Disable_dispatch(); /* prevents deletion */ |
---|
81 | |
---|
82 | the_partition = _Partition_Allocate(); |
---|
83 | |
---|
84 | if ( !the_partition ) { |
---|
85 | _Thread_Enable_dispatch(); |
---|
86 | return RTEMS_TOO_MANY; |
---|
87 | } |
---|
88 | |
---|
89 | #if defined(RTEMS_MULTIPROCESSING) |
---|
90 | if ( _Attributes_Is_global( attribute_set ) && |
---|
91 | !( _Objects_MP_Allocate_and_open( &_Partition_Information, name, |
---|
92 | the_partition->Object.id, false ) ) ) { |
---|
93 | _Partition_Free( the_partition ); |
---|
94 | _Thread_Enable_dispatch(); |
---|
95 | return RTEMS_TOO_MANY; |
---|
96 | } |
---|
97 | #endif |
---|
98 | |
---|
99 | the_partition->starting_address = starting_address; |
---|
100 | the_partition->length = length; |
---|
101 | the_partition->buffer_size = buffer_size; |
---|
102 | the_partition->attribute_set = attribute_set; |
---|
103 | the_partition->number_of_used_blocks = 0; |
---|
104 | |
---|
105 | _Chain_Initialize( &the_partition->Memory, starting_address, |
---|
106 | length / buffer_size, buffer_size ); |
---|
107 | |
---|
108 | _Objects_Open( |
---|
109 | &_Partition_Information, |
---|
110 | &the_partition->Object, |
---|
111 | (Objects_Name) name |
---|
112 | ); |
---|
113 | |
---|
114 | *id = the_partition->Object.id; |
---|
115 | #if defined(RTEMS_MULTIPROCESSING) |
---|
116 | if ( _Attributes_Is_global( attribute_set ) ) |
---|
117 | _Partition_MP_Send_process_packet( |
---|
118 | PARTITION_MP_ANNOUNCE_CREATE, |
---|
119 | the_partition->Object.id, |
---|
120 | name, |
---|
121 | 0 /* Not used */ |
---|
122 | ); |
---|
123 | #endif |
---|
124 | |
---|
125 | _Thread_Enable_dispatch(); |
---|
126 | return RTEMS_SUCCESSFUL; |
---|
127 | } |
---|