source: rtems/cpukit/include/rtems/rtems/partimpl.h @ 0fc87d47

5
Last change on this file since 0fc87d47 was b2de426, checked in by Sebastian Huber <sebastian.huber@…>, on 08/06/18 at 09:53:42

score: Fix _Addresses_Subtract()

Use architecture-specific integer type for an address difference.

Update #3486.

  • Property mode set to 100644
File size: 5.2 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/part.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 *  The following defines the information control block used to
38 *  manage this class of objects.
39 */
40extern Objects_Information _Partition_Information;
41
42/**
43 *  @brief Allocate a buffer from the_partition.
44 *
45 *  This function attempts to allocate a buffer from the_partition.
46 *  If successful, it returns the address of the allocated buffer.
47 *  Otherwise, it returns NULL.
48 */
49RTEMS_INLINE_ROUTINE void *_Partition_Allocate_buffer (
50   Partition_Control *the_partition
51)
52{
53  return _Chain_Get_unprotected( &the_partition->Memory );
54}
55
56/**
57 *  @brief Frees the_buffer to the_partition.
58 *
59 *  This routine frees the_buffer to the_partition.
60 */
61RTEMS_INLINE_ROUTINE void _Partition_Free_buffer (
62  Partition_Control *the_partition,
63  Chain_Node        *the_buffer
64)
65{
66  _Chain_Append_unprotected( &the_partition->Memory, the_buffer );
67}
68
69/**
70 *  @brief Checks whether is on a valid buffer boundary for the_partition.
71 *
72 *  This function returns TRUE if the_buffer is on a valid buffer
73 *  boundary for the_partition, and FALSE otherwise.
74 */
75RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary (
76  void              *the_buffer,
77  Partition_Control *the_partition
78)
79{
80  intptr_t offset;
81
82  offset = _Addresses_Subtract(
83    the_buffer,
84    the_partition->starting_address
85  );
86
87  return ((offset % the_partition->buffer_size) == 0);
88}
89
90/**
91 *  @brief Checks whether the_buffer is a valid buffer from the_partition.
92 *
93 *  This function returns TRUE if the_buffer is a valid buffer from
94 *  the_partition, otherwise FALSE is returned.
95 */
96RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_valid (
97   Chain_Node        *the_buffer,
98   Partition_Control *the_partition
99)
100{
101  void *starting;
102  void *ending;
103
104  starting = the_partition->starting_address;
105  ending   = _Addresses_Add_offset( starting, the_partition->length );
106
107  return (
108    _Addresses_Is_in_range( the_buffer, starting, ending ) &&
109    _Partition_Is_buffer_on_boundary( the_buffer, the_partition )
110  );
111}
112
113RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_size_aligned(
114  uint32_t buffer_size
115)
116{
117  return (buffer_size % CPU_SIZEOF_POINTER) == 0;
118}
119
120RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_area_aligned(
121  const void *starting_address
122)
123{
124  return (((uintptr_t) starting_address) % CPU_SIZEOF_POINTER) == 0;
125}
126
127/**
128 *  @brief Allocates a partition control block from the
129 *  inactive chain of free partition control blocks.
130 *
131 *  This function allocates a partition control block from
132 *  the inactive chain of free partition control blocks.
133 */
134RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void )
135{
136  return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
137}
138
139RTEMS_INLINE_ROUTINE void _Partition_Initialize(
140  Partition_Control *the_partition,
141  void              *starting_address,
142  uint32_t           length,
143  uint32_t           buffer_size,
144  rtems_attribute    attribute_set
145)
146{
147  the_partition->starting_address      = starting_address;
148  the_partition->length                = length;
149  the_partition->buffer_size           = buffer_size;
150  the_partition->attribute_set         = attribute_set;
151  the_partition->number_of_used_blocks = 0;
152
153  _Chain_Initialize(
154    &the_partition->Memory,
155    starting_address,
156    length / buffer_size,
157    buffer_size
158  );
159
160  _ISR_lock_Initialize( &the_partition->Lock, "Partition" );
161}
162
163RTEMS_INLINE_ROUTINE void _Partition_Destroy(
164  Partition_Control *the_partition
165)
166{
167  _ISR_lock_Destroy( &the_partition->Lock );
168}
169
170/**
171 *  @brief Frees a partition control block to the
172 *  inactive chain of free partition control blocks.
173 *
174 *  This routine frees a partition control block to the
175 *  inactive chain of free partition control blocks.
176 */
177RTEMS_INLINE_ROUTINE void _Partition_Free (
178   Partition_Control *the_partition
179)
180{
181  _Objects_Free( &_Partition_Information, &the_partition->Object );
182}
183
184RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get(
185  Objects_Id         id,
186  ISR_lock_Context  *lock_context
187)
188{
189  return (Partition_Control *) _Objects_Get(
190    id,
191    lock_context,
192    &_Partition_Information
193  );
194}
195
196RTEMS_INLINE_ROUTINE void _Partition_Acquire_critical(
197  Partition_Control *the_partition,
198  ISR_lock_Context  *lock_context
199)
200{
201  _ISR_lock_Acquire( &the_partition->Lock, lock_context );
202}
203
204RTEMS_INLINE_ROUTINE void _Partition_Release(
205  Partition_Control *the_partition,
206  ISR_lock_Context  *lock_context
207)
208{
209  _ISR_lock_Release_and_ISR_enable( &the_partition->Lock, lock_context );
210}
211
212/**@}*/
213
214#ifdef __cplusplus
215}
216#endif
217
218#if defined(RTEMS_MULTIPROCESSING)
219#include <rtems/rtems/partmp.h>
220#endif
221
222#endif
223/* end of include file */
Note: See TracBrowser for help on using the repository browser.