RTEMS
partimpl.h
Go to the documentation of this file.
1 
9 /* COPYRIGHT (c) 1989-2008.
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.org/license/LICENSE.
15  */
16 
17 #ifndef _RTEMS_RTEMS_PARTIMPL_H
18 #define _RTEMS_RTEMS_PARTIMPL_H
19 
20 #include <rtems/rtems/partdata.h>
21 #include <rtems/score/address.h>
22 #include <rtems/score/chainimpl.h>
23 #include <rtems/score/objectimpl.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
45  Partition_Control *the_partition
46 )
47 {
48  return _Chain_Get_unprotected( &the_partition->Memory );
49 }
50 
57  Partition_Control *the_partition,
58  Chain_Node *the_buffer
59 )
60 {
61  _Chain_Append_unprotected( &the_partition->Memory, the_buffer );
62 }
63 
71  void *the_buffer,
72  Partition_Control *the_partition
73 )
74 {
75  intptr_t offset;
76 
77  offset = _Addresses_Subtract(
78  the_buffer,
79  the_partition->starting_address
80  );
81 
82  return ((offset % the_partition->buffer_size) == 0);
83 }
84 
92  Chain_Node *the_buffer,
93  Partition_Control *the_partition
94 )
95 {
96  void *starting;
97  void *ending;
98 
99  starting = the_partition->starting_address;
100  ending = _Addresses_Add_offset( starting, the_partition->length );
101 
102  return (
103  _Addresses_Is_in_range( the_buffer, starting, ending ) &&
104  _Partition_Is_buffer_on_boundary( the_buffer, the_partition )
105  );
106 }
107 
108 RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_size_aligned(
109  uint32_t buffer_size
110 )
111 {
112  return (buffer_size % CPU_SIZEOF_POINTER) == 0;
113 }
114 
115 RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_area_aligned(
116  const void *starting_address
117 )
118 {
119  return (((uintptr_t) starting_address) % CPU_SIZEOF_POINTER) == 0;
120 }
121 
130 {
132 }
133 
134 RTEMS_INLINE_ROUTINE void _Partition_Initialize(
135  Partition_Control *the_partition,
136  void *starting_address,
137  uint32_t length,
138  uint32_t buffer_size,
139  rtems_attribute attribute_set
140 )
141 {
142  the_partition->starting_address = starting_address;
143  the_partition->length = length;
144  the_partition->buffer_size = buffer_size;
145  the_partition->attribute_set = attribute_set;
146  the_partition->number_of_used_blocks = 0;
147 
149  &the_partition->Memory,
150  starting_address,
151  length / buffer_size,
152  buffer_size
153  );
154 
155  _ISR_lock_Initialize( &the_partition->Lock, "Partition" );
156 }
157 
158 RTEMS_INLINE_ROUTINE void _Partition_Destroy(
159  Partition_Control *the_partition
160 )
161 {
162  _ISR_lock_Destroy( &the_partition->Lock );
163 }
164 
173  Partition_Control *the_partition
174 )
175 {
176  _Objects_Free( &_Partition_Information, &the_partition->Object );
177 }
178 
180  Objects_Id id,
181  ISR_lock_Context *lock_context
182 )
183 {
184  return (Partition_Control *) _Objects_Get(
185  id,
186  lock_context,
188  );
189 }
190 
191 RTEMS_INLINE_ROUTINE void _Partition_Acquire_critical(
192  Partition_Control *the_partition,
193  ISR_lock_Context *lock_context
194 )
195 {
196  _ISR_lock_Acquire( &the_partition->Lock, lock_context );
197 }
198 
199 RTEMS_INLINE_ROUTINE void _Partition_Release(
200  Partition_Control *the_partition,
201  ISR_lock_Context *lock_context
202 )
203 {
204  _ISR_lock_Release_and_ISR_enable( &the_partition->Lock, lock_context );
205 }
206 
209 #ifdef __cplusplus
210 }
211 #endif
212 
213 #if defined(RTEMS_MULTIPROCESSING)
214 #include <rtems/rtems/partmp.h>
215 #endif
216 
217 #endif
218 /* end of include file */
Objects_Control Object
Definition: partdata.h:39
Objects_Information _Partition_Information
The Classic Partition objects information.
Definition: part.c:47
#define _ISR_lock_Destroy(_lock)
Destroys an ISR lock.
Definition: isrlock.h:196
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:257
static __inline__ void _Partition_Free_buffer(Partition_Control *the_partition, Chain_Node *the_buffer)
Frees the_buffer to the_partition.
Definition: partimpl.h:56
uintptr_t length
Definition: partdata.h:45
void * starting_address
Definition: partdata.h:43
void _Chain_Initialize(Chain_Control *the_chain, void *starting_address, size_t number_nodes, size_t node_size)
Initializes a chain header.
Definition: chain.c:26
RTEMS_INLINE_ROUTINE bool _Addresses_Is_in_range(const void *address, const void *base, const void *limit)
Checks if address is in range.
Definition: address.h:138
Classic Partition Manager Data Structures.
#define CPU_SIZEOF_POINTER
Definition: cpu.h:734
Objects_Control * _Objects_Allocate(Objects_Information *information)
Allocates an object.
static __inline__ void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Appends a node (unprotected).
Definition: chainimpl.h:680
Inlined Routines in the Object Handler.
size_t buffer_size
Definition: partdata.h:47
RTEMS_INLINE_ROUTINE intptr_t _Addresses_Subtract(const void *left, const void *right)
Subtracts two addresses.
Definition: address.h:95
static __inline__ bool _Partition_Is_buffer_on_boundary(void *the_buffer, Partition_Control *the_partition)
Checks whether is on a valid buffer boundary for the_partition.
Definition: partimpl.h:70
Information Required to Manipulate Physical Addresses.
#define _ISR_lock_Acquire(_lock, _context)
Acquires an ISR lock inside an ISR disabled section.
Definition: isrlock.h:284
uintptr_t number_of_used_blocks
Definition: partdata.h:51
Chain Handler API.
uint32_t rtems_attribute
This type is used to represent Classic API attributes.
Definition: attr.h:91
static __inline__ bool _Partition_Is_buffer_valid(Chain_Node *the_buffer, Partition_Control *the_partition)
Checks whether the_buffer is a valid buffer from the_partition.
Definition: partimpl.h:91
rtems_attribute attribute_set
Definition: partdata.h:49
#define _ISR_lock_Initialize(_lock, _name)
Initializes an ISR lock.
Definition: isrlock.h:182
static __inline__ Partition_Control * _Partition_Allocate(void)
Allocates a partition control block from the inactive chain of free partition control blocks...
Definition: partimpl.h:129
uint32_t Objects_Id
Definition: object.h:80
Objects_Control * _Objects_Get(Objects_Id id, ISR_lock_Context *lock_context, const Objects_Information *information)
Maps the specified object identifier to the associated local object control block.
static __inline__ void * _Partition_Allocate_buffer(Partition_Control *the_partition)
Allocate a buffer from the_partition.
Definition: partimpl.h:44
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
Definition: basedefs.h:683
Chain_Control Memory
Definition: partdata.h:53
static __inline__ void _Partition_Free(Partition_Control *the_partition)
Frees a partition control block to the inactive chain of free partition control blocks.
Definition: partimpl.h:172
RTEMS_INLINE_ROUTINE void * _Addresses_Add_offset(const void *base, uintptr_t offset)
Adds offset to an address.
Definition: address.h:55
static __inline__ Chain_Node * _Chain_Get_unprotected(Chain_Control *the_chain)
Gets the first node (unprotected).
Definition: chainimpl.h:630
static __inline__ void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectimpl.h:933