source: rtems/cpukit/include/rtems/rtems/partimpl.h @ 21275b58

Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 22, 2018 at 6:14:51 PM

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ClassicPartImpl
5 *
6 * @brief Classic Partition Manager Implementation
7 */
8
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/chainimpl.h>
22#include <rtems/score/objectimpl.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * @defgroup ClassicPartImpl Classic Partition Manager Implementation
30 *
31 * @ingroup ClassicPart
32 *
33 * @{
34 */
35
36/**
37 *  @brief Allocate a buffer from the_partition.
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.
42 */
43RTEMS_INLINE_ROUTINE void *_Partition_Allocate_buffer (
44   Partition_Control *the_partition
45)
46{
47  return _Chain_Get_unprotected( &the_partition->Memory );
48}
49
50/**
51 *  @brief Frees the_buffer to the_partition.
52 *
53 *  This routine frees the_buffer to the_partition.
54 */
55RTEMS_INLINE_ROUTINE void _Partition_Free_buffer (
56  Partition_Control *the_partition,
57  Chain_Node        *the_buffer
58)
59{
60  _Chain_Append_unprotected( &the_partition->Memory, the_buffer );
61}
62
63/**
64 *  @brief Checks whether is on a valid buffer boundary for the_partition.
65 *
66 *  This function returns TRUE if the_buffer is on a valid buffer
67 *  boundary for the_partition, and FALSE otherwise.
68 */
69RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary (
70  void              *the_buffer,
71  Partition_Control *the_partition
72)
73{
74  intptr_t offset;
75
76  offset = _Addresses_Subtract(
77    the_buffer,
78    the_partition->starting_address
79  );
80
81  return ((offset % the_partition->buffer_size) == 0);
82}
83
84/**
85 *  @brief Checks whether the_buffer is a valid buffer from the_partition.
86 *
87 *  This function returns TRUE if the_buffer is a valid buffer from
88 *  the_partition, otherwise FALSE is returned.
89 */
90RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_valid (
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
107RTEMS_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
114RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_area_aligned(
115  const void *starting_address
116)
117{
118  return (((uintptr_t) starting_address) % CPU_SIZEOF_POINTER) == 0;
119}
120
121/**
122 *  @brief Allocates a partition control block from the
123 *  inactive chain of free partition control blocks.
124 *
125 *  This function allocates a partition control block from
126 *  the inactive chain of free partition control blocks.
127 */
128RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void )
129{
130  return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
131}
132
133RTEMS_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
157RTEMS_INLINE_ROUTINE void _Partition_Destroy(
158  Partition_Control *the_partition
159)
160{
161  _ISR_lock_Destroy( &the_partition->Lock );
162}
163
164/**
165 *  @brief Frees a partition control block to the
166 *  inactive chain of free partition control blocks.
167 *
168 *  This routine frees a partition control block to the
169 *  inactive chain of free partition control blocks.
170 */
171RTEMS_INLINE_ROUTINE void _Partition_Free (
172   Partition_Control *the_partition
173)
174{
175  _Objects_Free( &_Partition_Information, &the_partition->Object );
176}
177
178RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get(
179  Objects_Id         id,
180  ISR_lock_Context  *lock_context
181)
182{
183  return (Partition_Control *) _Objects_Get(
184    id,
185    lock_context,
186    &_Partition_Information
187  );
188}
189
190RTEMS_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
198RTEMS_INLINE_ROUTINE void _Partition_Release(
199  Partition_Control *the_partition,
200  ISR_lock_Context  *lock_context
201)
202{
203  _ISR_lock_Release_and_ISR_enable( &the_partition->Lock, lock_context );
204}
205
206/**@}*/
207
208#ifdef __cplusplus
209}
210#endif
211
212#if defined(RTEMS_MULTIPROCESSING)
213#include <rtems/rtems/partmp.h>
214#endif
215
216#endif
217/* end of include file */
Note: See TracBrowser for help on using the repository browser.