summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/bspsmp.h
blob: b712c4fe95de3ce87998a37f9fb8afe937ab4832 (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
/**
 *  @file  rtems/bspsmp.h
 *
 *  @brief Interface Between RTEMS and an SMP Aware BSP
 *
 *  This include file defines the interface between RTEMS and an
 *  SMP aware BSP.  These methods will only be used when RTEMS
 *  is configured with SMP support enabled.
 */

/*
 *  COPYRIGHT (c) 1989-2011.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#ifndef _RTEMS_BSPSMP_H
#define _RTEMS_BSPSMP_H

#include <rtems/score/cpuopts.h>

#if defined (RTEMS_SMP)
#include <rtems/score/percpu.h>

/**
 *  @defgroup RTEMS BSP SMP Interface
 *
 *  @ingroup Score
 *
 *  This defines the interface between RTEMS and the BSP for
 *  SMP support.  The interface uses the term primary
 *  to refer to the "boot" processor and secondary to refer
 *  to the "application" processors.  Different architectures
 *  use different terminology.
 *
 *  It is assumed that when the processor is reset and thus
 *  when RTEMS is initialized, that the primary processor is
 *  the only one executing.  The others are assumed to be in
 *  a quiescent or reset state awaiting a command to come online.
 */

/**@{*/

#ifdef __cplusplus
extern "C" {
#endif


#ifndef ASM

/**
 * @brief Performs BSP specific SMP initialization in the context of the main
 * processor.
 *
 * This function is invoked on the main processor by RTEMS during
 * initialization.  All interrupt stacks are allocated at this point in case
 * the CPU port allocates the interrupt stacks.
 *
 * The BSP may start secondary processors now.
 *
 * @param[in] configured_cpu_count The count of processors requested by the
 * application configuration.
 *
 * @return The count of processors available for the application in the system.
 * This value is less than or equal to the configured count of processors.
 */
uint32_t bsp_smp_initialize( uint32_t configured_cpu_count );

/**
 *  @brief Obtain current CPU index.
 *
 *  This method is invoked by RTEMS when it needs to know the index
 *  of the CPU it is executing on.
 *
 *  @retval This method returns the current CPU index.
 */
int bsp_smp_processor_id(void) RTEMS_COMPILER_PURE_ATTRIBUTE;

/**
 *  @brief Generate an interprocessor broadcast interrupt.
 *
 *  This method is invoked when RTEMS wants to let all of the other
 *  CPUs know that it has sent them message.  CPUs not including
 *  the originating CPU should receive the interrupt.

 *
 *  @note On CPUs without the capability to generate a broadcast
 *        to all other CPUs interrupt, this can be implemented by
 *        a loop of sending interrupts to specific CPUs.
 */
void bsp_smp_broadcast_interrupt(void);

/**
 *  @brief Generate a interprocessor interrupt.
 *
 *  This method is invoked by RTEMS to let @a cpu know that it
 *  has sent it a message.
 *
 *  @param [in] cpu is the recipient CPU
 */
void bsp_smp_interrupt_cpu(
  int cpu
);

/**
 *  @brief Obtain CPU core number.
 *
 *  This method is invoked by RTEMS when it needs to know which core
 *  number it is executing on.  This is used when it needs to perform
 *  some action or bookkeeping and needs to distinguish itself from
 *  the other cores.  For example, it may need to realize it needs to
 *  preempt a thread on another node.
 *
 *  @retval This method returns the Id of the current CPU core.
 */
int   bsp_smp_processor_id( void );

/**
 * @brief Performs high-level initialization of a secondary processor and runs
 * the application threads.
 *
 * The low-level initialization code must call this function to hand over the
 * control of this processor to RTEMS.  Interrupts must be disabled.  It must
 * be possible to send inter-processor interrupts to this processor.  Since
 * interrupts are disabled the inter-processor interrupt delivery is postponed
 * until interrupts are enabled the first time.  This is usually a side-effect
 * of the context switch to the first thread.
 *
 * The pre-requisites for the call to this function are
 * - disabled interrupts,
 * - delivery of inter-processor interrupts is possible,
 * - a valid stack pointer and enough stack space,
 * - a valid code memory, and
 * - a valid BSS section.
 *
 * This function must not be called by the main processor.  This function does
 * not return to the caller.
 */
void rtems_smp_secondary_cpu_initialize( void )
  RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;

/**
 *  @brief Process the incoming interprocessor request.
 *
 *  This is the method called by the BSP's interrupt handler
 *  to process the incoming interprocessor request.
 */
void rtems_smp_process_interrupt(void);

#endif

#ifdef __cplusplus
}
#endif

#else
  #define bsp_smp_processor_id()  0
#endif

/**@}*/
#endif

/* end of include file */