File indexing completed on 2025-05-11 08:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041
0042 #include <rtems/rtems/partimpl.h>
0043 #include <rtems/rtems/attrimpl.h>
0044 #include <rtems/rtems/support.h>
0045 #include <rtems/score/address.h>
0046 #include <rtems/score/chainimpl.h>
0047 #include <rtems/score/sysstate.h>
0048 #include <rtems/sysinit.h>
0049
0050 static Partition_Control *_Partition_Allocate( void )
0051 {
0052 return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
0053 }
0054
0055 static void _Partition_Initialize(
0056 Partition_Control *the_partition,
0057 void *starting_address,
0058 uintptr_t length,
0059 size_t buffer_size,
0060 rtems_attribute attribute_set
0061 )
0062 {
0063 const void *limit_address;
0064
0065 limit_address = _Addresses_Add_offset( starting_address, length - 1 );
0066 the_partition->base_address = starting_address;
0067 the_partition->limit_address = limit_address;
0068 the_partition->buffer_size = buffer_size;
0069 the_partition->attribute_set = attribute_set;
0070 the_partition->number_of_used_blocks = 0;
0071
0072 _Chain_Initialize(
0073 &the_partition->Memory,
0074 starting_address,
0075 length / buffer_size,
0076 buffer_size
0077 );
0078
0079 _ISR_lock_Initialize( &the_partition->Lock, "Partition" );
0080 }
0081
0082 rtems_status_code rtems_partition_create(
0083 rtems_name name,
0084 void *starting_address,
0085 uintptr_t length,
0086 size_t buffer_size,
0087 rtems_attribute attribute_set,
0088 rtems_id *id
0089 )
0090 {
0091 Partition_Control *the_partition;
0092
0093 if ( !rtems_is_name_valid( name ) ) {
0094 return RTEMS_INVALID_NAME;
0095 }
0096
0097 if ( id == NULL ) {
0098 return RTEMS_INVALID_ADDRESS;
0099 }
0100
0101 if ( starting_address == NULL ) {
0102 return RTEMS_INVALID_ADDRESS;
0103 }
0104
0105 if ( length == 0 ) {
0106 return RTEMS_INVALID_SIZE;
0107 }
0108
0109 if ( buffer_size == 0 ) {
0110 return RTEMS_INVALID_SIZE;
0111 }
0112
0113 if ( length < buffer_size ) {
0114 return RTEMS_INVALID_SIZE;
0115 }
0116
0117
0118
0119
0120
0121 if ( buffer_size % CPU_SIZEOF_POINTER != 0 ) {
0122 return RTEMS_INVALID_SIZE;
0123 }
0124
0125 if ( buffer_size < sizeof( Chain_Node ) )
0126 return RTEMS_INVALID_SIZE;
0127
0128
0129
0130
0131
0132 if ( (uintptr_t) starting_address % CPU_SIZEOF_POINTER != 0 ) {
0133 return RTEMS_INVALID_ADDRESS;
0134 }
0135
0136 #if defined(RTEMS_MULTIPROCESSING)
0137 if ( !_System_state_Is_multiprocessing ) {
0138 attribute_set = _Attributes_Clear( attribute_set, RTEMS_GLOBAL );
0139 }
0140 #endif
0141
0142 the_partition = _Partition_Allocate();
0143
0144 if ( !the_partition ) {
0145 _Objects_Allocator_unlock();
0146 return RTEMS_TOO_MANY;
0147 }
0148
0149 #if defined(RTEMS_MULTIPROCESSING)
0150 if ( _Attributes_Is_global( attribute_set ) &&
0151 !( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
0152 the_partition->Object.id, false ) ) ) {
0153 _Objects_Free( &_Partition_Information, &the_partition->Object );
0154 _Objects_Allocator_unlock();
0155 return RTEMS_TOO_MANY;
0156 }
0157 #endif
0158
0159 _Partition_Initialize(
0160 the_partition,
0161 starting_address,
0162 length,
0163 buffer_size,
0164 attribute_set
0165 );
0166
0167 *id = _Objects_Open_u32(
0168 &_Partition_Information,
0169 &the_partition->Object,
0170 name
0171 );
0172
0173 #if defined(RTEMS_MULTIPROCESSING)
0174 if ( _Attributes_Is_global( attribute_set ) )
0175 _Partition_MP_Send_process_packet(
0176 PARTITION_MP_ANNOUNCE_CREATE,
0177 the_partition->Object.id,
0178 name,
0179 0
0180 );
0181 #endif
0182
0183 _Objects_Allocator_unlock();
0184 return RTEMS_SUCCESSFUL;
0185 }
0186
0187 static void _Partition_Manager_initialization( void )
0188 {
0189 _Objects_Initialize_information( &_Partition_Information );
0190 }
0191
0192 RTEMS_SYSINIT_ITEM(
0193 _Partition_Manager_initialization,
0194 RTEMS_SYSINIT_CLASSIC_PARTITION,
0195 RTEMS_SYSINIT_ORDER_MIDDLE
0196 );