source: rtems/cpukit/rtems/src/partcreate.c @ 6b5f22dc

Last change on this file since 6b5f22dc was 6b5f22dc, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/20 at 10:45:47

rtems: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSImplClassicPartition
5 *
6 * @brief This source file contains the implementation of
7 *   rtems_partition_create() and the Partition Manager system initialization.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2014.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/rtems/partimpl.h>
24#include <rtems/rtems/attrimpl.h>
25#include <rtems/rtems/support.h>
26#include <rtems/score/chainimpl.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/sysinit.h>
29
30static Partition_Control *_Partition_Allocate( void )
31{
32  return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
33}
34
35static void _Partition_Initialize(
36  Partition_Control *the_partition,
37  void              *starting_address,
38  uintptr_t          length,
39  size_t             buffer_size,
40  rtems_attribute    attribute_set
41)
42{
43  the_partition->starting_address      = starting_address;
44  the_partition->length                = length;
45  the_partition->buffer_size           = buffer_size;
46  the_partition->attribute_set         = attribute_set;
47  the_partition->number_of_used_blocks = 0;
48
49  _Chain_Initialize(
50    &the_partition->Memory,
51    starting_address,
52    length / buffer_size,
53    buffer_size
54  );
55
56  _ISR_lock_Initialize( &the_partition->Lock, "Partition" );
57}
58
59rtems_status_code rtems_partition_create(
60  rtems_name       name,
61  void            *starting_address,
62  uintptr_t        length,
63  size_t           buffer_size,
64  rtems_attribute  attribute_set,
65  rtems_id        *id
66)
67{
68  Partition_Control *the_partition;
69
70  if ( !rtems_is_name_valid( name ) ) {
71    return RTEMS_INVALID_NAME;
72  }
73
74  if ( id == NULL ) {
75    return RTEMS_INVALID_ADDRESS;
76  }
77
78  if ( starting_address == NULL ) {
79    return RTEMS_INVALID_ADDRESS;
80  }
81
82  if ( length == 0 )
83    return RTEMS_INVALID_SIZE;
84
85  if ( buffer_size == 0 )
86    return RTEMS_INVALID_SIZE;
87
88  if ( length < buffer_size )
89    return RTEMS_INVALID_SIZE;
90
91  /*
92   * Ensure that the buffer size is an integral multiple of the pointer size so
93   * that each buffer begin meets the chain node alignment.
94   */
95  if ( buffer_size % CPU_SIZEOF_POINTER != 0 ) {
96    return RTEMS_INVALID_SIZE;
97  }
98
99  if ( buffer_size < sizeof( Chain_Node ) )
100    return RTEMS_INVALID_SIZE;
101
102  /*
103   * Ensure that the buffer area starting address is aligned on a pointer
104   * boundary so that each buffer begin meets the chain node alignment.
105   */
106  if ( (uintptr_t) starting_address % CPU_SIZEOF_POINTER != 0 ) {
107    return RTEMS_INVALID_ADDRESS;
108  }
109
110#if defined(RTEMS_MULTIPROCESSING)
111  if ( !_System_state_Is_multiprocessing ) {
112    attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
113  }
114#endif
115
116  the_partition = _Partition_Allocate();
117
118  if ( !the_partition ) {
119    _Objects_Allocator_unlock();
120    return RTEMS_TOO_MANY;
121  }
122
123#if defined(RTEMS_MULTIPROCESSING)
124  if ( _Attributes_Is_global( attribute_set ) &&
125       !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
126                            the_partition->Object.id, false ) ) ) {
127    _Partition_Free( the_partition );
128    _Objects_Allocator_unlock();
129    return RTEMS_TOO_MANY;
130  }
131#endif
132
133  _Partition_Initialize(
134    the_partition,
135    starting_address,
136    length,
137    buffer_size,
138    attribute_set
139  );
140
141  _Objects_Open(
142    &_Partition_Information,
143    &the_partition->Object,
144    (Objects_Name) name
145  );
146
147  *id = the_partition->Object.id;
148#if defined(RTEMS_MULTIPROCESSING)
149  if ( _Attributes_Is_global( attribute_set ) )
150    _Partition_MP_Send_process_packet(
151      PARTITION_MP_ANNOUNCE_CREATE,
152      the_partition->Object.id,
153      name,
154      0                  /* Not used */
155    );
156#endif
157
158  _Objects_Allocator_unlock();
159  return RTEMS_SUCCESSFUL;
160}
161
162static void _Partition_Manager_initialization( void )
163{
164  _Objects_Initialize_information( &_Partition_Information );
165}
166
167RTEMS_SYSINIT_ITEM(
168  _Partition_Manager_initialization,
169  RTEMS_SYSINIT_CLASSIC_PARTITION,
170  RTEMS_SYSINIT_ORDER_MIDDLE
171);
Note: See TracBrowser for help on using the repository browser.