1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup PerCPUData |
---|
5 | * |
---|
6 | * @brief Definition of custom per-CPU items. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2018 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _RTEMS_SCORE_PERCPUDATA_H |
---|
24 | #define _RTEMS_SCORE_PERCPUDATA_H |
---|
25 | |
---|
26 | #include <rtems/score/percpu.h> |
---|
27 | #include <rtems/linkersets.h> |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif /* __cplusplus */ |
---|
32 | |
---|
33 | /** |
---|
34 | * @defgroup PerCPUData Flexible Per-CPU Data |
---|
35 | * |
---|
36 | * @ingroup PerCPU |
---|
37 | * |
---|
38 | * @brief Flexible Per-CPU Data |
---|
39 | * |
---|
40 | * Provides the definition of custom per-CPU items. The items are collected in |
---|
41 | * a special linker set. During system initialization the content of the |
---|
42 | * linker set is duplicated for all secondary processors using memory allocated |
---|
43 | * from the workspace. The begin and end of the per-CPU data area is cache |
---|
44 | * line aligned (CPU_CACHE_LINE_BYTES). |
---|
45 | * |
---|
46 | * @{ |
---|
47 | */ |
---|
48 | |
---|
49 | RTEMS_LINKER_RWSET_DECLARE( _Per_CPU_Data, char ); |
---|
50 | |
---|
51 | /** |
---|
52 | * @brief Declares a per-CPU item of the specified type. |
---|
53 | * |
---|
54 | * Items declared with this macro have external linkage. |
---|
55 | * |
---|
56 | * @param type The type of the item. |
---|
57 | * @param item The designator of the item. |
---|
58 | */ |
---|
59 | #define PER_CPU_DATA_ITEM_DECLARE( type, item ) \ |
---|
60 | RTEMS_LINKER_RWSET_ITEM_DECLARE( _Per_CPU_Data, type, item ) |
---|
61 | |
---|
62 | /** |
---|
63 | * @brief Defines a per-CPU item of the specified type. |
---|
64 | * |
---|
65 | * @param type The type of the item. |
---|
66 | * @param item The designator of the item. |
---|
67 | */ |
---|
68 | #define PER_CPU_DATA_ITEM( type, item ) \ |
---|
69 | RTEMS_LINKER_RWSET_ITEM( _Per_CPU_Data, type, item ) |
---|
70 | |
---|
71 | /** |
---|
72 | * @brief Returns the offset of the per-CPU item to the begin of the per-CPU |
---|
73 | * data area. |
---|
74 | * |
---|
75 | * @param item The designator of the item. |
---|
76 | */ |
---|
77 | #define PER_CPU_DATA_OFFSET( item ) \ |
---|
78 | ( (uintptr_t) &_Linker_set__Per_CPU_Data_##item \ |
---|
79 | - (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) ) |
---|
80 | |
---|
81 | /** |
---|
82 | * @brief Returns a pointer of the specified type to the per-CPU item at the |
---|
83 | * specified offset for the specified processor. |
---|
84 | * |
---|
85 | * @param cpu The processor of the item. |
---|
86 | * @param type The type of the item. |
---|
87 | * @param offset The offset of the item. |
---|
88 | */ |
---|
89 | #ifdef RTEMS_SMP |
---|
90 | #define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \ |
---|
91 | (type *) ( cpu->data + offset ) |
---|
92 | #else |
---|
93 | #define PER_CPU_DATA_GET_BY_OFFSET( cpu, type, offset ) \ |
---|
94 | (type *) ( (uintptr_t) RTEMS_LINKER_SET_BEGIN( _Per_CPU_Data ) + offset ), \ |
---|
95 | (void) cpu |
---|
96 | #endif |
---|
97 | |
---|
98 | /** |
---|
99 | * @brief Returns a pointer of the specified type to the specified per-CPU item |
---|
100 | * for the specified processor. |
---|
101 | * |
---|
102 | * @param cpu The processor of the item. |
---|
103 | * @param type The type of the item. |
---|
104 | * @param item The designator of the item. |
---|
105 | */ |
---|
106 | #ifdef RTEMS_SMP |
---|
107 | #define PER_CPU_DATA_GET( cpu, type, item ) \ |
---|
108 | PER_CPU_DATA_GET_BY_OFFSET( cpu, type, PER_CPU_DATA_OFFSET( item ) ) |
---|
109 | #else |
---|
110 | #define PER_CPU_DATA_GET( cpu, type, item ) \ |
---|
111 | &_Linker_set__Per_CPU_Data_##item, (void) cpu |
---|
112 | #endif |
---|
113 | |
---|
114 | /** @} */ |
---|
115 | |
---|
116 | #ifdef __cplusplus |
---|
117 | } |
---|
118 | #endif /* __cplusplus */ |
---|
119 | |
---|
120 | #endif /* _RTEMS_SCORE_PERCPUDATA_H */ |
---|