source: rtems/cpukit/rtems/src/partcreate.c @ a2360c4

Last change on this file since a2360c4 was a2360c4, checked in by Joel Sherrill <joel@…>, on 01/26/23 at 19:23:12

cpukit/rtems/src/partcreate.c: Correct style by adding braces

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassicPartition
7 *
8 * @brief This source file contains the implementation of
9 *   rtems_partition_create() and the Partition Manager system initialization.
10 */
11
12/*
13 *  COPYRIGHT (c) 1989-2014.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 *    notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 *    notice, this list of conditions and the following disclaimer in the
23 *    documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#endif
41
42#include <rtems/rtems/partimpl.h>
43#include <rtems/rtems/attrimpl.h>
44#include <rtems/rtems/support.h>
45#include <rtems/score/address.h>
46#include <rtems/score/chainimpl.h>
47#include <rtems/score/sysstate.h>
48#include <rtems/sysinit.h>
49
50static Partition_Control *_Partition_Allocate( void )
51{
52  return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
53}
54
55static void _Partition_Initialize(
56  Partition_Control *the_partition,
57  void              *starting_address,
58  uintptr_t          length,
59  size_t             buffer_size,
60  rtems_attribute    attribute_set
61)
62{
63  const void *limit_address;
64
65  limit_address = _Addresses_Add_offset( starting_address, length - 1 );
66  the_partition->base_address          = starting_address;
67  the_partition->limit_address         = limit_address;
68  the_partition->buffer_size           = buffer_size;
69  the_partition->attribute_set         = attribute_set;
70  the_partition->number_of_used_blocks = 0;
71
72  _Chain_Initialize(
73    &the_partition->Memory,
74    starting_address,
75    length / buffer_size,
76    buffer_size
77  );
78
79  _ISR_lock_Initialize( &the_partition->Lock, "Partition" );
80}
81
82rtems_status_code rtems_partition_create(
83  rtems_name       name,
84  void            *starting_address,
85  uintptr_t        length,
86  size_t           buffer_size,
87  rtems_attribute  attribute_set,
88  rtems_id        *id
89)
90{
91  Partition_Control *the_partition;
92
93  if ( !rtems_is_name_valid( name ) ) {
94    return RTEMS_INVALID_NAME;
95  }
96
97  if ( id == NULL ) {
98    return RTEMS_INVALID_ADDRESS;
99  }
100
101  if ( starting_address == NULL ) {
102    return RTEMS_INVALID_ADDRESS;
103  }
104
105  if ( length == 0 ) {
106    return RTEMS_INVALID_SIZE;
107  }
108
109  if ( buffer_size == 0 ) {
110    return RTEMS_INVALID_SIZE;
111  }
112
113  if ( length < buffer_size ) {
114    return RTEMS_INVALID_SIZE;
115  }
116
117  /*
118   * Ensure that the buffer size is an integral multiple of the pointer size so
119   * that each buffer begin meets the chain node alignment.
120   */
121  if ( buffer_size % CPU_SIZEOF_POINTER != 0 ) {
122    return RTEMS_INVALID_SIZE;
123  }
124
125  if ( buffer_size < sizeof( Chain_Node ) )
126    return RTEMS_INVALID_SIZE;
127
128  /*
129   * Ensure that the buffer area starting address is aligned on a pointer
130   * boundary so that each buffer begin meets the chain node alignment.
131   */
132  if ( (uintptr_t) starting_address % CPU_SIZEOF_POINTER != 0 ) {
133    return RTEMS_INVALID_ADDRESS;
134  }
135
136#if defined(RTEMS_MULTIPROCESSING)
137  if ( !_System_state_Is_multiprocessing ) {
138    attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
139  }
140#endif
141
142  the_partition = _Partition_Allocate();
143
144  if ( !the_partition ) {
145    _Objects_Allocator_unlock();
146    return RTEMS_TOO_MANY;
147  }
148
149#if defined(RTEMS_MULTIPROCESSING)
150  if ( _Attributes_Is_global( attribute_set ) &&
151       !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
152                            the_partition->Object.id, false ) ) ) {
153    _Objects_Free( &_Partition_Information, &the_partition->Object );
154    _Objects_Allocator_unlock();
155    return RTEMS_TOO_MANY;
156  }
157#endif
158
159  _Partition_Initialize(
160    the_partition,
161    starting_address,
162    length,
163    buffer_size,
164    attribute_set
165  );
166
167  *id = _Objects_Open_u32(
168    &_Partition_Information,
169    &the_partition->Object,
170    name
171  );
172
173#if defined(RTEMS_MULTIPROCESSING)
174  if ( _Attributes_Is_global( attribute_set ) )
175    _Partition_MP_Send_process_packet(
176      PARTITION_MP_ANNOUNCE_CREATE,
177      the_partition->Object.id,
178      name,
179      0                  /* Not used */
180    );
181#endif
182
183  _Objects_Allocator_unlock();
184  return RTEMS_SUCCESSFUL;
185}
186
187static void _Partition_Manager_initialization( void )
188{
189  _Objects_Initialize_information( &_Partition_Information );
190}
191
192RTEMS_SYSINIT_ITEM(
193  _Partition_Manager_initialization,
194  RTEMS_SYSINIT_CLASSIC_PARTITION,
195  RTEMS_SYSINIT_ORDER_MIDDLE
196);
Note: See TracBrowser for help on using the repository browser.