1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ClassicRegion Regions |
---|
5 | * |
---|
6 | * @brief rtems_region_create |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-1999. |
---|
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/regionimpl.h> |
---|
23 | #include <rtems/rtems/attrimpl.h> |
---|
24 | #include <rtems/rtems/support.h> |
---|
25 | #include <rtems/score/apimutex.h> |
---|
26 | #include <rtems/score/threadqimpl.h> |
---|
27 | #include <rtems/sysinit.h> |
---|
28 | |
---|
29 | rtems_status_code rtems_region_create( |
---|
30 | rtems_name name, |
---|
31 | void *starting_address, |
---|
32 | uintptr_t length, |
---|
33 | uintptr_t page_size, |
---|
34 | rtems_attribute attribute_set, |
---|
35 | rtems_id *id |
---|
36 | ) |
---|
37 | { |
---|
38 | rtems_status_code return_status; |
---|
39 | Region_Control *the_region; |
---|
40 | |
---|
41 | if ( !rtems_is_name_valid( name ) ) { |
---|
42 | return RTEMS_INVALID_NAME; |
---|
43 | } |
---|
44 | |
---|
45 | if ( id == NULL ) { |
---|
46 | return RTEMS_INVALID_ADDRESS; |
---|
47 | } |
---|
48 | |
---|
49 | if ( starting_address == NULL ) { |
---|
50 | return RTEMS_INVALID_ADDRESS; |
---|
51 | } |
---|
52 | |
---|
53 | the_region = _Region_Allocate(); |
---|
54 | |
---|
55 | if ( !the_region ) |
---|
56 | return_status = RTEMS_TOO_MANY; |
---|
57 | |
---|
58 | else { |
---|
59 | _Thread_queue_Object_initialize( &the_region->Wait_queue ); |
---|
60 | |
---|
61 | if ( _Attributes_Is_priority( attribute_set ) ) { |
---|
62 | the_region->wait_operations = &_Thread_queue_Operations_priority; |
---|
63 | } else { |
---|
64 | the_region->wait_operations = &_Thread_queue_Operations_FIFO; |
---|
65 | } |
---|
66 | |
---|
67 | the_region->maximum_segment_size = _Heap_Initialize( |
---|
68 | &the_region->Memory, starting_address, length, page_size |
---|
69 | ); |
---|
70 | |
---|
71 | if ( !the_region->maximum_segment_size ) { |
---|
72 | _Region_Free( the_region ); |
---|
73 | return_status = RTEMS_INVALID_SIZE; |
---|
74 | } else { |
---|
75 | the_region->attribute_set = attribute_set; |
---|
76 | |
---|
77 | _Objects_Open( |
---|
78 | &_Region_Information, |
---|
79 | &the_region->Object, |
---|
80 | (Objects_Name) name |
---|
81 | ); |
---|
82 | |
---|
83 | *id = the_region->Object.id; |
---|
84 | return_status = RTEMS_SUCCESSFUL; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | _Objects_Allocator_unlock(); |
---|
89 | |
---|
90 | return return_status; |
---|
91 | } |
---|
92 | |
---|
93 | static void _Region_Manager_initialization( void ) |
---|
94 | { |
---|
95 | _Objects_Initialize_information( &_Region_Information ); |
---|
96 | } |
---|
97 | |
---|
98 | RTEMS_SYSINIT_ITEM( |
---|
99 | _Region_Manager_initialization, |
---|
100 | RTEMS_SYSINIT_CLASSIC_REGION, |
---|
101 | RTEMS_SYSINIT_ORDER_MIDDLE |
---|
102 | ); |
---|