Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScorePerCPUData
0007  *
0008  * @brief This header file provides the interfaces of the
0009  *   @ref RTEMSScorePerCPUData.
0010  */
0011 
0012 /*
0013  * Copyright (c) 2018 embedded brains GmbH & Co. KG
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _RTEMS_SCORE_PERCPUDATA_H
0038 #define _RTEMS_SCORE_PERCPUDATA_H
0039 
0040 #include <rtems/score/percpu.h>
0041 #include <rtems/linkersets.h>
0042 
0043 #ifdef __cplusplus
0044 extern "C" {
0045 #endif /* __cplusplus */
0046 
0047 /**
0048  * @defgroup RTEMSScorePerCPUData Flexible Per-CPU Data
0049  *
0050  * @ingroup RTEMSScorePerCPU
0051  *
0052  * @brief This group contains the implementation to support flexible per-CPU
0053  *   data.
0054  *
0055  * Macros to define custom per-CPU items are provided.  The items are collected
0056  * in a special linker set.  During system initialization the content of the
0057  * linker set is duplicated for all secondary processors using memory allocated
0058  * from the workspace.  The begin and end of the per-CPU data area is cache
0059  * line aligned (CPU_CACHE_LINE_BYTES).
0060  *
0061  * @{
0062  */
0063 
0064 RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char );
0065 
0066 /**
0067  * @brief Translation units which define per-CPU items shall call this macro
0068  *   exactly once at file scope.
0069  */
0070 #ifdef RTEMS_SMP
0071 #define PER_CPU_DATA_NEED_INITIALIZATION() \
0072   static const char * const _Per_CPU_Data_reference \
0073   RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
0074   RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data )
0075 #else
0076 #define PER_CPU_DATA_NEED_INITIALIZATION() \
0077   RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char )
0078 #endif
0079 
0080 /**
0081  * @brief Declares a per-CPU item of the specified type.
0082  *
0083  * Items declared with this macro have external linkage.
0084  *
0085  * @param type The type of the item.
0086  * @param item The designator of the item.
0087  */
0088 #define PER_CPU_DATA_ITEM_DECLARE( type, item ) \
0089   RTEMS_LINKER_RWSET_ITEM_DECLARE( _Per_CPU_Data, type, item )
0090 
0091 /**
0092  * @brief Defines a per-CPU item of the specified type.
0093  *
0094  * @param type The type of the item.
0095  * @param item The designator of the item.
0096  */
0097 #define PER_CPU_DATA_ITEM( type, item ) \
0098   RTEMS_LINKER_RWSET_ITEM( _Per_CPU_Data, type, item )
0099 
0100 /**
0101  * @brief Returns the offset of the per-CPU item to the begin of the per-CPU
0102  * data area.
0103  *
0104  * @param item The designator of the item.
0105  */
0106 #define PER_CPU_DATA_OFFSET( item ) \
0107   ( (uintptr_t) &_Linker_set__Per_CPU_Data_##item \
0108     - (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) )
0109 
0110 /**
0111  * @brief Returns a pointer of the specified type to the per-CPU item at the
0112  * specified offset for the specified processor.
0113  *
0114  * @param cpu The processor of the item.
0115  * @param type The type of the item.
0116  * @param offset The offset of the item.
0117  */
0118 #ifdef RTEMS_SMP
0119 #define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
0120   (type *) ( cpu->data + offset )
0121 #else
0122 #define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
0123   (type *) ( (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) + offset ), \
0124     (void) cpu
0125 #endif
0126 
0127 /**
0128  * @brief Returns a pointer of the specified type to the specified per-CPU item
0129  * for the specified processor.
0130  *
0131  * @param cpu The processor of the item.
0132  * @param type The type of the item.
0133  * @param item The designator of the item.
0134  */
0135 #ifdef RTEMS_SMP
0136 #define PER_CPU_DATA_GET( cpu, type, item ) \
0137   PER_CPU_DATA_GET_BY_OFFSET( cpu, type, PER_CPU_DATA_OFFSET( item ) )
0138 #else
0139 #define PER_CPU_DATA_GET( cpu, type, item ) \
0140   &_Linker_set__Per_CPU_Data_##item, (void) cpu
0141 #endif
0142 
0143 /** @} */
0144 
0145 #ifdef __cplusplus
0146 }
0147 #endif /* __cplusplus */
0148 
0149 #endif /* _RTEMS_SCORE_PERCPUDATA_H */