source: rtems/cpukit/include/rtems/score/percpudata.h @ 878487b0

5
Last change on this file since 878487b0 was aaa6653, checked in by Sebastian Huber <sebastian.huber@…>, on 09/13/18 at 09:33:11

score: Fix PER_CPU_DATA_ITEM_DECLARE()

Fix PER_CPU_DATA_ITEM_DECLARE() for targets with a small-data area.

Update #3507.

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