• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Header file for Multi-Processor support.
3 
4   Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
5   This program and the accompanying materials
6   are licensed and made available under the terms and conditions of the BSD License
7   which accompanies this distribution.  The full text of the license may be found at
8   http://opensource.org/licenses/bsd-license.php.
9 
10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef _DEBUG_MP_H_
16 #define _DEBUG_MP_H_
17 
18 #define DEBUG_CPU_MAX_COUNT             256
19 
20 typedef struct {
21   UINT32    CpuCount;                            ///< Processor count
22   UINT16    ApicID[DEBUG_CPU_MAX_COUNT];         ///< Record the local apic id for each processor
23 } DEBUG_CPU_DATA;
24 
25 typedef struct {
26   SPIN_LOCK                 MpContextSpinLock;   ///< Lock for writting MP context
27   SPIN_LOCK                 DebugPortSpinLock;   ///< Lock for access debug port
28   SPIN_LOCK                 MailboxSpinLock;     ///< Lock for accessing mail box
29   UINT8                     CpuBreakMask[DEBUG_CPU_MAX_COUNT/8];        ///< Bitmask of all breaking CPUs
30   UINT8                     CpuStopStatusMask[DEBUG_CPU_MAX_COUNT/8];   ///< Bitmask of CPU stop status
31   UINT32                    ViewPointIndex;      ///< Current view point to be debugged
32   UINT32                    BspIndex;            ///< Processor index value of BSP
33   UINT32                    BreakAtCpuIndex;     ///< Processor index value of the current breaking CPU
34   UINT32                    DebugTimerInitCount; ///< Record BSP's init timer count
35   BOOLEAN                   IpiSentByAp;         ///< TRUR: IPI is sent by AP. TALSE: IPI is sent by BSP
36   BOOLEAN                   RunCommandSet;       ///< TRUE: RUN commmand is executing. FALSE : RUN command has been executed.
37 } DEBUG_MP_CONTEXT;
38 
39 extern DEBUG_MP_CONTEXT volatile   mDebugMpContext;
40 extern DEBUG_CPU_DATA   volatile   mDebugCpuData;
41 
42 /**
43   Break the other processor by send IPI.
44 
45   @param[in] CurrentProcessorIndex  Current processor index value.
46 
47 **/
48 VOID
49 HaltOtherProcessors (
50   IN UINT32             CurrentProcessorIndex
51   );
52 
53 /**
54   Get the current processor's index.
55 
56   @return Processor index value.
57 
58 **/
59 UINT32
60 GetProcessorIndex (
61   VOID
62   );
63 
64 /**
65   Acquire a spin lock when Multi-processor supported.
66 
67   It will block in the function if cannot get the access control.
68   If Multi-processor is not supported, return directly.
69 
70   @param[in, out] MpSpinLock      A pointer to the spin lock.
71 
72 **/
73 VOID
74 AcquireMpSpinLock (
75   IN OUT SPIN_LOCK           *MpSpinLock
76   );
77 
78 /**
79   Release a spin lock when Multi-processor supported.
80 
81   @param[in, out] MpSpinLock      A pointer to the spin lock.
82 
83 **/
84 VOID
85 ReleaseMpSpinLock (
86   IN OUT SPIN_LOCK           *MpSpinLock
87   );
88 
89 /**
90   Check if the specified processor is BSP or not.
91 
92   @param[in] ProcessorIndex Processor index value.
93 
94   @retval TRUE    It is BSP.
95   @retval FALSE   It isn't BSP.
96 
97 **/
98 BOOLEAN
99 IsBsp (
100   IN UINT32             ProcessorIndex
101   );
102 
103 /**
104   Set processor stop flag bitmask in MP context.
105 
106   @param[in] ProcessorIndex Processor index value.
107   @param[in] StopFlag       TRUE means set stop flag.
108                             FALSE means clean break flag.
109 
110 **/
111 VOID
112 SetCpuStopFlagByIndex (
113   IN UINT32             ProcessorIndex,
114   IN BOOLEAN            StopFlag
115   );
116 
117 /**
118   Set processor break flag bitmask in MP context.
119 
120   @param[in] ProcessorIndex Processor index value.
121   @param[in] BreakFlag      TRUE means set break flag.
122                             FALSE means clean break flag.
123 
124 **/
125 VOID
126 SetCpuBreakFlagByIndex (
127   IN UINT32             ProcessorIndex,
128   IN BOOLEAN            BreakFlag
129   );
130 
131 /**
132   Check if processor is stopped already.
133 
134   @param[in] ProcessorIndex   Processor index value.
135 
136   @retval TRUE        Processor is stopped already.
137   @retval FALSE       Processor isn't stopped.
138 
139 **/
140 BOOLEAN
141 IsCpuStopped (
142   IN UINT32              ProcessorIndex
143   );
144 
145 /**
146   Set the run command flag.
147 
148   @param[in] RunningFlag   TRUE means run command flag is set.
149                            FALSE means run command flag is cleared.
150 
151 **/
152 VOID
153 SetCpuRunningFlag (
154   IN BOOLEAN            RunningFlag
155   );
156 
157 /**
158   Set the current view point to be debugged.
159 
160   @param[in] ProcessorIndex   Processor index value.
161 
162 **/
163 VOID
164 SetDebugViewPoint (
165   IN UINT32             ProcessorIndex
166   );
167 
168 /**
169   Set the IPI send by BPS/AP flag.
170 
171   @param[in] IpiSentByApFlag   TRUE means this IPI is sent by AP.
172                                FALSE means this IPI is sent by BSP.
173 
174 **/
175 VOID
176 SetIpiSentByApFlag (
177   IN BOOLEAN            IpiSentByApFlag
178   );
179 
180 /**
181   Check the next pending breaking CPU.
182 
183   @retval others      There is at least one processor broken, the minimum
184                       index number of Processor returned.
185   @retval -1          No any processor broken.
186 
187 **/
188 UINT32
189 FindNextPendingBreakCpu (
190   VOID
191   );
192 
193 /**
194   Check if all processors are in running status.
195 
196   @retval TRUE        All processors run.
197   @retval FALSE       At least one processor does not run.
198 
199 **/
200 BOOLEAN
201 IsAllCpuRunning (
202   VOID
203   );
204 
205 /**
206   Check if the current processor is the first breaking processor.
207 
208   If yes, halt other processors.
209 
210   @param[in] ProcessorIndex   Processor index value.
211 
212   @return TRUE       This processor is the first breaking processor.
213   @return FALSE      This processor is not the first breaking processor.
214 
215 **/
216 BOOLEAN
217 IsFirstBreakProcessor (
218   IN UINT32              ProcessorIndex
219   );
220 
221 #endif
222 
223