summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/confdefs/percpu.h
blob: b91590bfd93f3850a1c5a643ca7330fb5c19ed33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* SPDX-License-Identifier: BSD-2-Clause */

/**
 * @file
 *
 * @ingroup RTEMSImplApplConfig
 *
 * @brief This header file evaluates configuration options related to the
 *   per-CPU configuration.
 *
 * Since the idle thread stack size (CONFIGURE_IDLE_TASK_STACK_SIZE) depends on
 * CONFIGURE_MINIMUM_TASK_STACK_SIZE, the POSIX-specific
 * CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE configuration option is also evaluated
 * in this header file for simplicity.
 *
 * This header file defines _CONFIGURE_MAXIMUM_PROCESSORS for use by other
 * configuration header files.
 */

/*
 * Copyright (C) 2018, 2020 embedded brains GmbH (http://www.embedded-brains.de)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _RTEMS_CONFDEFS_PERCPU_H
#define _RTEMS_CONFDEFS_PERCPU_H

#ifndef __CONFIGURATION_TEMPLATE_h
#error "Do not include this file directly, use <rtems/confdefs.h> instead"
#endif

#ifdef CONFIGURE_INIT

#include <rtems/confdefs/bsp.h>
#include <rtems/score/context.h>
#include <rtems/score/percpu.h>
#include <rtems/score/smp.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Ensure that _CONFIGURE_MAXIMUM_PROCESSORS > 1 only in SMP configurations */
#if defined(CONFIGURE_MAXIMUM_PROCESSORS) && defined(RTEMS_SMP)
  #define _CONFIGURE_MAXIMUM_PROCESSORS CONFIGURE_MAXIMUM_PROCESSORS
#else
  #define _CONFIGURE_MAXIMUM_PROCESSORS 1
#endif

#ifdef RTEMS_SMP
  const uint32_t _SMP_Processor_configured_maximum =
    _CONFIGURE_MAXIMUM_PROCESSORS;

  Per_CPU_Control_envelope
    _Per_CPU_Information[ _CONFIGURE_MAXIMUM_PROCESSORS ];
#endif

/* Interrupt stack configuration */

#ifndef CONFIGURE_INTERRUPT_STACK_SIZE
  #if !defined(CONFIGURE_DISABLE_BSP_SETTINGS) && \
    defined(BSP_INTERRUPT_STACK_SIZE)
    #define CONFIGURE_INTERRUPT_STACK_SIZE BSP_INTERRUPT_STACK_SIZE
  #else
    #define CONFIGURE_INTERRUPT_STACK_SIZE CPU_STACK_MINIMUM_SIZE
  #endif
#endif

#if CONFIGURE_INTERRUPT_STACK_SIZE % CPU_INTERRUPT_STACK_ALIGNMENT != 0
  #error "CONFIGURE_INTERRUPT_STACK_SIZE fails to meet the CPU port interrupt stack alignment"
#endif

RTEMS_DEFINE_GLOBAL_SYMBOL(
  _ISR_Stack_size,
  CONFIGURE_INTERRUPT_STACK_SIZE
);

#define _CONFIGURE_INTERRUPT_STACK_AREA_SIZE \
  ( CONFIGURE_INTERRUPT_STACK_SIZE * _CONFIGURE_MAXIMUM_PROCESSORS )

char _ISR_Stack_area_begin[ _CONFIGURE_INTERRUPT_STACK_AREA_SIZE ]
RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
RTEMS_SECTION( ".rtemsstack.interrupt" );

RTEMS_DEFINE_GLOBAL_SYMBOL(
  _ISR_Stack_area_end,
  RTEMS_SYMBOL_NAME( _ISR_Stack_area_begin )
    + _CONFIGURE_INTERRUPT_STACK_AREA_SIZE
);

/* Thread stack size configuration */

#ifndef CONFIGURE_MINIMUM_TASK_STACK_SIZE
  #define CONFIGURE_MINIMUM_TASK_STACK_SIZE CPU_STACK_MINIMUM_SIZE
#endif

#ifndef CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE
  #define CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE \
    ( 2 * CONFIGURE_MINIMUM_TASK_STACK_SIZE )
#endif

/* Idle thread configuration */

#ifndef CONFIGURE_IDLE_TASK_STACK_SIZE
  #if !defined(CONFIGURE_DISABLE_BSP_SETTINGS) && \
    defined(BSP_IDLE_TASK_STACK_SIZE)
    #define CONFIGURE_IDLE_TASK_STACK_SIZE BSP_IDLE_TASK_STACK_SIZE
  #else
    #define CONFIGURE_IDLE_TASK_STACK_SIZE CONFIGURE_MINIMUM_TASK_STACK_SIZE
  #endif
#endif

#if CONFIGURE_IDLE_TASK_STACK_SIZE < CONFIGURE_MINIMUM_TASK_STACK_SIZE
  #error "CONFIGURE_IDLE_TASK_STACK_SIZE less than CONFIGURE_MINIMUM_TASK_STACK_SIZE"
#endif

const size_t _Thread_Idle_stack_size = CONFIGURE_IDLE_TASK_STACK_SIZE;

/*
 * If the user provides a custom idle stack allocator, then we do not need
 * memory reserved for the stacks but the symbol is still referenced in
 * threadcreateidle.c. The code path just never uses it. Make it minimal
 * size to proceed.
 */
#ifndef CONFIGURE_TASK_STACK_ALLOCATOR_FOR_IDLE
  char _Thread_Idle_stacks[
    _CONFIGURE_MAXIMUM_PROCESSORS
      * ( CONFIGURE_IDLE_TASK_STACK_SIZE + CPU_IDLE_TASK_IS_FP * CONTEXT_FP_SIZE )
  ] RTEMS_ALIGNED( CPU_INTERRUPT_STACK_ALIGNMENT )
  RTEMS_SECTION( ".rtemsstack.idle" );
#endif

#if defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION) && \
  !defined(CONFIGURE_IDLE_TASK_BODY)
  #error "If you define CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION, then you must define CONFIGURE_IDLE_TASK_BODY as well"
#endif

#if !defined(CONFIGURE_IDLE_TASK_BODY) && \
  !defined(CONFIGURE_DISABLE_BSP_SETTINGS) && defined(BSP_IDLE_TASK_BODY)
  #define CONFIGURE_IDLE_TASK_BODY BSP_IDLE_TASK_BODY
#endif

#ifdef CONFIGURE_IDLE_TASK_BODY
  const Thread_Idle_body _Thread_Idle_body = CONFIGURE_IDLE_TASK_BODY;
#endif

#ifdef __cplusplus
}
#endif

#endif /* CONFIGURE_INIT */

#endif /* _RTEMS_CONFDEFS_PERCPU_H */