1 | /* |
---|
2 | * Region Manager - Extend (add memory to) a Region |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2009. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #if HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <rtems/system.h> |
---|
17 | #include <rtems/rtems/status.h> |
---|
18 | #include <rtems/rtems/support.h> |
---|
19 | #include <rtems/score/object.h> |
---|
20 | #include <rtems/rtems/options.h> |
---|
21 | #include <rtems/rtems/region.h> |
---|
22 | #include <rtems/score/states.h> |
---|
23 | #include <rtems/score/thread.h> |
---|
24 | #include <rtems/score/apimutex.h> |
---|
25 | |
---|
26 | /* |
---|
27 | * rtems_region_extend |
---|
28 | * |
---|
29 | * This directive attempts to grow a region of physical contiguous memory area |
---|
30 | * from which variable sized segments can be allocated. |
---|
31 | * |
---|
32 | * Input parameters: |
---|
33 | * id - id of region to grow |
---|
34 | * start - starting address of memory area for extension |
---|
35 | * length - physical length in bytes to grow the region |
---|
36 | * |
---|
37 | * Output parameters: |
---|
38 | * RTEMS_SUCCESSFUL - if successful |
---|
39 | * error code - if unsuccessful |
---|
40 | */ |
---|
41 | |
---|
42 | rtems_status_code rtems_region_extend( |
---|
43 | rtems_id id, |
---|
44 | void *starting_address, |
---|
45 | uintptr_t length |
---|
46 | ) |
---|
47 | { |
---|
48 | uintptr_t amount_extended; |
---|
49 | Objects_Locations location; |
---|
50 | rtems_status_code return_status; |
---|
51 | Region_Control *the_region; |
---|
52 | |
---|
53 | if ( !starting_address ) |
---|
54 | return RTEMS_INVALID_ADDRESS; |
---|
55 | |
---|
56 | _RTEMS_Lock_allocator(); /* to prevent deletion */ |
---|
57 | |
---|
58 | the_region = _Region_Get( id, &location ); |
---|
59 | switch ( location ) { |
---|
60 | |
---|
61 | case OBJECTS_LOCAL: |
---|
62 | |
---|
63 | amount_extended = _Heap_Extend( |
---|
64 | &the_region->Memory, |
---|
65 | starting_address, |
---|
66 | length, |
---|
67 | 0 |
---|
68 | ); |
---|
69 | |
---|
70 | if ( amount_extended > 0 ) { |
---|
71 | the_region->length += amount_extended; |
---|
72 | the_region->maximum_segment_size += amount_extended; |
---|
73 | return_status = RTEMS_SUCCESSFUL; |
---|
74 | } else { |
---|
75 | return_status = RTEMS_INVALID_ADDRESS; |
---|
76 | } |
---|
77 | break; |
---|
78 | |
---|
79 | #if defined(RTEMS_MULTIPROCESSING) |
---|
80 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
81 | break; |
---|
82 | #endif |
---|
83 | |
---|
84 | case OBJECTS_ERROR: |
---|
85 | default: |
---|
86 | return_status = RTEMS_INVALID_ID; |
---|
87 | break; |
---|
88 | } |
---|
89 | |
---|
90 | _RTEMS_Unlock_allocator(); |
---|
91 | return return_status; |
---|
92 | } |
---|