source: rtems/cpukit/include/rtems/score/percpudata.h @ 7ebce359

Last change on this file since 7ebce359 was 7ebce359, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:15:58

cpukit/include/rtems/score/[a-r]*.h: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScorePerCPUData
7 *
8 * @brief This header file provides the interfaces of the
9 *   @ref RTEMSScorePerCPUData.
10 */
11
12/*
13 * Copyright (c) 2018 embedded brains GmbH.  All rights reserved.
14 *
15 *  embedded brains GmbH
16 *  Dornierstr. 4
17 *  82178 Puchheim
18 *  Germany
19 *  <rtems@embedded-brains.de>
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifndef _RTEMS_SCORE_PERCPUDATA_H
44#define _RTEMS_SCORE_PERCPUDATA_H
45
46#include <rtems/score/percpu.h>
47#include <rtems/linkersets.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif /* __cplusplus */
52
53/**
54 * @defgroup RTEMSScorePerCPUData Flexible Per-CPU Data
55 *
56 * @ingroup RTEMSScorePerCPU
57 *
58 * @brief This group contains the implementation to support flexible per-CPU
59 *   data.
60 *
61 * Macros to define custom per-CPU items are provided.  The items are collected
62 * in a special linker set.  During system initialization the content of the
63 * linker set is duplicated for all secondary processors using memory allocated
64 * from the workspace.  The begin and end of the per-CPU data area is cache
65 * line aligned (CPU_CACHE_LINE_BYTES).
66 *
67 * @{
68 */
69
70RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char );
71
72/**
73 * @brief Translation units which define per-CPU items shall call this macro
74 *   exactly once at file scope.
75 */
76#ifdef RTEMS_SMP
77#define PER_CPU_DATA_NEED_INITIALIZATION() \
78  static const char * const _Per_CPU_Data_reference \
79  RTEMS_SECTION( ".rtemsroset.reference" ) RTEMS_USED = \
80  RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data )
81#else
82#define PER_CPU_DATA_NEED_INITIALIZATION() \
83  RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char )
84#endif
85
86/**
87 * @brief Declares a per-CPU item of the specified type.
88 *
89 * Items declared with this macro have external linkage.
90 *
91 * @param type The type of the item.
92 * @param item The designator of the item.
93 */
94#define PER_CPU_DATA_ITEM_DECLARE( type, item ) \
95  RTEMS_LINKER_RWSET_ITEM_DECLARE( _Per_CPU_Data, type, item )
96
97/**
98 * @brief Defines a per-CPU item of the specified type.
99 *
100 * @param type The type of the item.
101 * @param item The designator of the item.
102 */
103#define PER_CPU_DATA_ITEM( type, item ) \
104  RTEMS_LINKER_RWSET_ITEM( _Per_CPU_Data, type, item )
105
106/**
107 * @brief Returns the offset of the per-CPU item to the begin of the per-CPU
108 * data area.
109 *
110 * @param item The designator of the item.
111 */
112#define PER_CPU_DATA_OFFSET( item ) \
113  ( (uintptr_t) &_Linker_set__Per_CPU_Data_##item \
114    - (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) )
115
116/**
117 * @brief Returns a pointer of the specified type to the per-CPU item at the
118 * specified offset for the specified processor.
119 *
120 * @param cpu The processor of the item.
121 * @param type The type of the item.
122 * @param offset The offset of the item.
123 */
124#ifdef RTEMS_SMP
125#define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
126  (type *) ( cpu->data + offset )
127#else
128#define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \
129  (type *) ( (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) + offset ), \
130    (void) cpu
131#endif
132
133/**
134 * @brief Returns a pointer of the specified type to the specified per-CPU item
135 * for the specified processor.
136 *
137 * @param cpu The processor of the item.
138 * @param type The type of the item.
139 * @param item The designator of the item.
140 */
141#ifdef RTEMS_SMP
142#define PER_CPU_DATA_GET( cpu, type, item ) \
143  PER_CPU_DATA_GET_BY_OFFSET( cpu, type, PER_CPU_DATA_OFFSET( item ) )
144#else
145#define PER_CPU_DATA_GET( cpu, type, item ) \
146  &_Linker_set__Per_CPU_Data_##item, (void) cpu
147#endif
148
149/** @} */
150
151#ifdef __cplusplus
152}
153#endif /* __cplusplus */
154
155#endif /* _RTEMS_SCORE_PERCPUDATA_H */
Note: See TracBrowser for help on using the repository browser.