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

Last change on this file since c4fb617 was c4fb617, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:28:43

cpukit/rtems/src/[a-r]*.c: Change license to BSD-2

Updates #3053.

  • 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  if ( buffer_size == 0 )
109    return RTEMS_INVALID_SIZE;
110
111  if ( length < buffer_size )
112    return RTEMS_INVALID_SIZE;
113
114  /*
115   * Ensure that the buffer size is an integral multiple of the pointer size so
116   * that each buffer begin meets the chain node alignment.
117   */
118  if ( buffer_size % CPU_SIZEOF_POINTER != 0 ) {
119    return RTEMS_INVALID_SIZE;
120  }
121
122  if ( buffer_size < sizeof( Chain_Node ) )
123    return RTEMS_INVALID_SIZE;
124
125  /*
126   * Ensure that the buffer area starting address is aligned on a pointer
127   * boundary so that each buffer begin meets the chain node alignment.
128   */
129  if ( (uintptr_t) starting_address % CPU_SIZEOF_POINTER != 0 ) {
130    return RTEMS_INVALID_ADDRESS;
131  }
132
133#if defined(RTEMS_MULTIPROCESSING)
134  if ( !_System_state_Is_multiprocessing ) {
135    attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
136  }
137#endif
138
139  the_partition = _Partition_Allocate();
140
141  if ( !the_partition ) {
142    _Objects_Allocator_unlock();
143    return RTEMS_TOO_MANY;
144  }
145
146#if defined(RTEMS_MULTIPROCESSING)
147  if ( _Attributes_Is_global( attribute_set ) &&
148       !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
149                            the_partition->Object.id, false ) ) ) {
150    _Objects_Free( &_Partition_Information, &the_partition->Object );
151    _Objects_Allocator_unlock();
152    return RTEMS_TOO_MANY;
153  }
154#endif
155
156  _Partition_Initialize(
157    the_partition,
158    starting_address,
159    length,
160    buffer_size,
161    attribute_set
162  );
163
164  *id = _Objects_Open_u32(
165    &_Partition_Information,
166    &the_partition->Object,
167    name
168  );
169
170#if defined(RTEMS_MULTIPROCESSING)
171  if ( _Attributes_Is_global( attribute_set ) )
172    _Partition_MP_Send_process_packet(
173      PARTITION_MP_ANNOUNCE_CREATE,
174      the_partition->Object.id,
175      name,
176      0                  /* Not used */
177    );
178#endif
179
180  _Objects_Allocator_unlock();
181  return RTEMS_SUCCESSFUL;
182}
183
184static void _Partition_Manager_initialization( void )
185{
186  _Objects_Initialize_information( &_Partition_Information );
187}
188
189RTEMS_SYSINIT_ITEM(
190  _Partition_Manager_initialization,
191  RTEMS_SYSINIT_CLASSIC_PARTITION,
192  RTEMS_SYSINIT_ORDER_MIDDLE
193);
Note: See TracBrowser for help on using the repository browser.