[d964f79] | 1 | /** |
---|
[8695cae] | 2 | * @file |
---|
[067a96a] | 3 | * |
---|
[8695cae] | 4 | * @ingroup ClassicPartImpl |
---|
| 5 | * |
---|
| 6 | * @brief Classic Partition Manager Implementation |
---|
[067a96a] | 7 | */ |
---|
| 8 | |
---|
[f9293df] | 9 | /* COPYRIGHT (c) 1989-2008. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 15 | */ |
---|
| 16 | |
---|
[8695cae] | 17 | #ifndef _RTEMS_RTEMS_PARTIMPL_H |
---|
| 18 | #define _RTEMS_RTEMS_PARTIMPL_H |
---|
| 19 | |
---|
[f00c5c6] | 20 | #include <rtems/rtems/partdata.h> |
---|
[8695cae] | 21 | #include <rtems/score/chainimpl.h> |
---|
[a2e3f33] | 22 | #include <rtems/score/objectimpl.h> |
---|
[8695cae] | 23 | |
---|
| 24 | #ifdef __cplusplus |
---|
| 25 | extern "C" { |
---|
[4d24fccb] | 26 | #endif |
---|
| 27 | |
---|
[8695cae] | 28 | /** |
---|
| 29 | * @defgroup ClassicPartImpl Classic Partition Manager Implementation |
---|
| 30 | * |
---|
| 31 | * @ingroup ClassicPart |
---|
| 32 | * |
---|
| 33 | * @{ |
---|
| 34 | */ |
---|
[ac7d5ef0] | 35 | |
---|
[067a96a] | 36 | /** |
---|
[7ee5bc4c] | 37 | * @brief Allocate a buffer from the_partition. |
---|
[1a8fde6c] | 38 | * |
---|
| 39 | * This function attempts to allocate a buffer from the_partition. |
---|
| 40 | * If successful, it returns the address of the allocated buffer. |
---|
| 41 | * Otherwise, it returns NULL. |
---|
[ac7d5ef0] | 42 | */ |
---|
[503dc058] | 43 | RTEMS_INLINE_ROUTINE void *_Partition_Allocate_buffer ( |
---|
[ac7d5ef0] | 44 | Partition_Control *the_partition |
---|
| 45 | ) |
---|
| 46 | { |
---|
[3570ec6] | 47 | return _Chain_Get_unprotected( &the_partition->Memory ); |
---|
[ac7d5ef0] | 48 | } |
---|
| 49 | |
---|
[067a96a] | 50 | /** |
---|
[7ee5bc4c] | 51 | * @brief Frees the_buffer to the_partition. |
---|
[1a8fde6c] | 52 | * |
---|
| 53 | * This routine frees the_buffer to the_partition. |
---|
[ac7d5ef0] | 54 | */ |
---|
[503dc058] | 55 | RTEMS_INLINE_ROUTINE void _Partition_Free_buffer ( |
---|
[ac7d5ef0] | 56 | Partition_Control *the_partition, |
---|
| 57 | Chain_Node *the_buffer |
---|
| 58 | ) |
---|
| 59 | { |
---|
[3570ec6] | 60 | _Chain_Append_unprotected( &the_partition->Memory, the_buffer ); |
---|
[ac7d5ef0] | 61 | } |
---|
| 62 | |
---|
[067a96a] | 63 | /** |
---|
[7ee5bc4c] | 64 | * @brief Checks whether is on a valid buffer boundary for the_partition. |
---|
[1a8fde6c] | 65 | * |
---|
| 66 | * This function returns TRUE if the_buffer is on a valid buffer |
---|
| 67 | * boundary for the_partition, and FALSE otherwise. |
---|
[ac7d5ef0] | 68 | */ |
---|
[484a769] | 69 | RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary ( |
---|
[ac7d5ef0] | 70 | void *the_buffer, |
---|
| 71 | Partition_Control *the_partition |
---|
| 72 | ) |
---|
| 73 | { |
---|
[b2de426] | 74 | intptr_t offset; |
---|
[ac7d5ef0] | 75 | |
---|
[b2de426] | 76 | offset = _Addresses_Subtract( |
---|
[ac7d5ef0] | 77 | the_buffer, |
---|
| 78 | the_partition->starting_address |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | return ((offset % the_partition->buffer_size) == 0); |
---|
| 82 | } |
---|
| 83 | |
---|
[067a96a] | 84 | /** |
---|
[7ee5bc4c] | 85 | * @brief Checks whether the_buffer is a valid buffer from the_partition. |
---|
[1a8fde6c] | 86 | * |
---|
| 87 | * This function returns TRUE if the_buffer is a valid buffer from |
---|
| 88 | * the_partition, otherwise FALSE is returned. |
---|
[ac7d5ef0] | 89 | */ |
---|
[484a769] | 90 | RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_valid ( |
---|
[ac7d5ef0] | 91 | Chain_Node *the_buffer, |
---|
| 92 | Partition_Control *the_partition |
---|
| 93 | ) |
---|
| 94 | { |
---|
| 95 | void *starting; |
---|
| 96 | void *ending; |
---|
| 97 | |
---|
| 98 | starting = the_partition->starting_address; |
---|
| 99 | ending = _Addresses_Add_offset( starting, the_partition->length ); |
---|
| 100 | |
---|
| 101 | return ( |
---|
| 102 | _Addresses_Is_in_range( the_buffer, starting, ending ) && |
---|
| 103 | _Partition_Is_buffer_on_boundary( the_buffer, the_partition ) |
---|
| 104 | ); |
---|
| 105 | } |
---|
| 106 | |
---|
[27bbc05] | 107 | RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_size_aligned( |
---|
| 108 | uint32_t buffer_size |
---|
| 109 | ) |
---|
| 110 | { |
---|
| 111 | return (buffer_size % CPU_SIZEOF_POINTER) == 0; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_area_aligned( |
---|
| 115 | const void *starting_address |
---|
[ac7d5ef0] | 116 | ) |
---|
| 117 | { |
---|
[27bbc05] | 118 | return (((uintptr_t) starting_address) % CPU_SIZEOF_POINTER) == 0; |
---|
[ac7d5ef0] | 119 | } |
---|
| 120 | |
---|
[067a96a] | 121 | /** |
---|
[7ee5bc4c] | 122 | * @brief Allocates a partition control block from the |
---|
| 123 | * inactive chain of free partition control blocks. |
---|
[1a8fde6c] | 124 | * |
---|
| 125 | * This function allocates a partition control block from |
---|
| 126 | * the inactive chain of free partition control blocks. |
---|
[ac7d5ef0] | 127 | */ |
---|
[503dc058] | 128 | RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void ) |
---|
[ac7d5ef0] | 129 | { |
---|
| 130 | return (Partition_Control *) _Objects_Allocate( &_Partition_Information ); |
---|
| 131 | } |
---|
| 132 | |
---|
[3570ec6] | 133 | RTEMS_INLINE_ROUTINE void _Partition_Initialize( |
---|
| 134 | Partition_Control *the_partition, |
---|
| 135 | void *starting_address, |
---|
| 136 | uint32_t length, |
---|
| 137 | uint32_t buffer_size, |
---|
| 138 | rtems_attribute attribute_set |
---|
| 139 | ) |
---|
| 140 | { |
---|
| 141 | the_partition->starting_address = starting_address; |
---|
| 142 | the_partition->length = length; |
---|
| 143 | the_partition->buffer_size = buffer_size; |
---|
| 144 | the_partition->attribute_set = attribute_set; |
---|
| 145 | the_partition->number_of_used_blocks = 0; |
---|
| 146 | |
---|
| 147 | _Chain_Initialize( |
---|
| 148 | &the_partition->Memory, |
---|
| 149 | starting_address, |
---|
| 150 | length / buffer_size, |
---|
| 151 | buffer_size |
---|
| 152 | ); |
---|
| 153 | |
---|
| 154 | _ISR_lock_Initialize( &the_partition->Lock, "Partition" ); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | RTEMS_INLINE_ROUTINE void _Partition_Destroy( |
---|
| 158 | Partition_Control *the_partition |
---|
| 159 | ) |
---|
| 160 | { |
---|
| 161 | _ISR_lock_Destroy( &the_partition->Lock ); |
---|
| 162 | } |
---|
| 163 | |
---|
[067a96a] | 164 | /** |
---|
[7ee5bc4c] | 165 | * @brief Frees a partition control block to the |
---|
| 166 | * inactive chain of free partition control blocks. |
---|
[1a8fde6c] | 167 | * |
---|
| 168 | * This routine frees a partition control block to the |
---|
| 169 | * inactive chain of free partition control blocks. |
---|
[ac7d5ef0] | 170 | */ |
---|
[503dc058] | 171 | RTEMS_INLINE_ROUTINE void _Partition_Free ( |
---|
[ac7d5ef0] | 172 | Partition_Control *the_partition |
---|
| 173 | ) |
---|
| 174 | { |
---|
| 175 | _Objects_Free( &_Partition_Information, &the_partition->Object ); |
---|
| 176 | } |
---|
| 177 | |
---|
[0a00b2b] | 178 | RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get( |
---|
[ac7d5ef0] | 179 | Objects_Id id, |
---|
[3570ec6] | 180 | ISR_lock_Context *lock_context |
---|
| 181 | ) |
---|
| 182 | { |
---|
[582bb23c] | 183 | return (Partition_Control *) _Objects_Get( |
---|
[3570ec6] | 184 | id, |
---|
[0a00b2b] | 185 | lock_context, |
---|
| 186 | &_Partition_Information |
---|
[3570ec6] | 187 | ); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | RTEMS_INLINE_ROUTINE void _Partition_Acquire_critical( |
---|
| 191 | Partition_Control *the_partition, |
---|
| 192 | ISR_lock_Context *lock_context |
---|
| 193 | ) |
---|
| 194 | { |
---|
| 195 | _ISR_lock_Acquire( &the_partition->Lock, lock_context ); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | RTEMS_INLINE_ROUTINE void _Partition_Release( |
---|
| 199 | Partition_Control *the_partition, |
---|
| 200 | ISR_lock_Context *lock_context |
---|
[ac7d5ef0] | 201 | ) |
---|
| 202 | { |
---|
[3570ec6] | 203 | _ISR_lock_Release_and_ISR_enable( &the_partition->Lock, lock_context ); |
---|
[ac7d5ef0] | 204 | } |
---|
| 205 | |
---|
[067a96a] | 206 | /**@}*/ |
---|
| 207 | |
---|
[8695cae] | 208 | #ifdef __cplusplus |
---|
| 209 | } |
---|
| 210 | #endif |
---|
| 211 | |
---|
| 212 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 213 | #include <rtems/rtems/partmp.h> |
---|
| 214 | #endif |
---|
| 215 | |
---|
[ac7d5ef0] | 216 | #endif |
---|
| 217 | /* end of include file */ |
---|