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