source: rtems/cpukit/include/rtems/rtems/partimpl.h @ b2de426

5
Last change on this file since b2de426 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
RevLine 
[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
20#include <rtems/rtems/part.h>
21#include <rtems/score/chainimpl.h>
[a2e3f33]22#include <rtems/score/objectimpl.h>
[8695cae]23
24#ifdef __cplusplus
25extern "C" {
[4d24fccb]26#endif
27
[8695cae]28/**
29 * @defgroup ClassicPartImpl Classic Partition Manager Implementation
30 *
31 * @ingroup ClassicPart
32 *
33 * @{
34 */
[ac7d5ef0]35
[8695cae]36/**
37 *  The following defines the information control block used to
38 *  manage this class of objects.
39 */
[fd3cc36f]40extern Objects_Information _Partition_Information;
[067a96a]41
42/**
[7ee5bc4c]43 *  @brief Allocate a buffer from the_partition.
[1a8fde6c]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.
[ac7d5ef0]48 */
[503dc058]49RTEMS_INLINE_ROUTINE void *_Partition_Allocate_buffer (
[ac7d5ef0]50   Partition_Control *the_partition
51)
52{
[3570ec6]53  return _Chain_Get_unprotected( &the_partition->Memory );
[ac7d5ef0]54}
55
[067a96a]56/**
[7ee5bc4c]57 *  @brief Frees the_buffer to the_partition.
[1a8fde6c]58 *
59 *  This routine frees the_buffer to the_partition.
[ac7d5ef0]60 */
[503dc058]61RTEMS_INLINE_ROUTINE void _Partition_Free_buffer (
[ac7d5ef0]62  Partition_Control *the_partition,
63  Chain_Node        *the_buffer
64)
65{
[3570ec6]66  _Chain_Append_unprotected( &the_partition->Memory, the_buffer );
[ac7d5ef0]67}
68
[067a96a]69/**
[7ee5bc4c]70 *  @brief Checks whether is on a valid buffer boundary for the_partition.
[1a8fde6c]71 *
72 *  This function returns TRUE if the_buffer is on a valid buffer
73 *  boundary for the_partition, and FALSE otherwise.
[ac7d5ef0]74 */
[484a769]75RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_on_boundary (
[ac7d5ef0]76  void              *the_buffer,
77  Partition_Control *the_partition
78)
79{
[b2de426]80  intptr_t offset;
[ac7d5ef0]81
[b2de426]82  offset = _Addresses_Subtract(
[ac7d5ef0]83    the_buffer,
84    the_partition->starting_address
85  );
86
87  return ((offset % the_partition->buffer_size) == 0);
88}
89
[067a96a]90/**
[7ee5bc4c]91 *  @brief Checks whether the_buffer is a valid buffer from the_partition.
[1a8fde6c]92 *
93 *  This function returns TRUE if the_buffer is a valid buffer from
94 *  the_partition, otherwise FALSE is returned.
[ac7d5ef0]95 */
[484a769]96RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_valid (
[ac7d5ef0]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
[27bbc05]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
[ac7d5ef0]122)
123{
[27bbc05]124  return (((uintptr_t) starting_address) % CPU_SIZEOF_POINTER) == 0;
[ac7d5ef0]125}
126
[067a96a]127/**
[7ee5bc4c]128 *  @brief Allocates a partition control block from the
129 *  inactive chain of free partition control blocks.
[1a8fde6c]130 *
131 *  This function allocates a partition control block from
132 *  the inactive chain of free partition control blocks.
[ac7d5ef0]133 */
[503dc058]134RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void )
[ac7d5ef0]135{
136  return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
137}
138
[3570ec6]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
[067a96a]170/**
[7ee5bc4c]171 *  @brief Frees a partition control block to the
172 *  inactive chain of free partition control blocks.
[1a8fde6c]173 *
174 *  This routine frees a partition control block to the
175 *  inactive chain of free partition control blocks.
[ac7d5ef0]176 */
[503dc058]177RTEMS_INLINE_ROUTINE void _Partition_Free (
[ac7d5ef0]178   Partition_Control *the_partition
179)
180{
181  _Objects_Free( &_Partition_Information, &the_partition->Object );
182}
183
[0a00b2b]184RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Get(
[ac7d5ef0]185  Objects_Id         id,
[3570ec6]186  ISR_lock_Context  *lock_context
187)
188{
[582bb23c]189  return (Partition_Control *) _Objects_Get(
[3570ec6]190    id,
[0a00b2b]191    lock_context,
192    &_Partition_Information
[3570ec6]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
[ac7d5ef0]207)
208{
[3570ec6]209  _ISR_lock_Release_and_ISR_enable( &the_partition->Lock, lock_context );
[ac7d5ef0]210}
211
[067a96a]212/**@}*/
213
[8695cae]214#ifdef __cplusplus
215}
216#endif
217
218#if defined(RTEMS_MULTIPROCESSING)
219#include <rtems/rtems/partmp.h>
220#endif
221
[ac7d5ef0]222#endif
223/* end of include file */
Note: See TracBrowser for help on using the repository browser.