File: | home/coreboot/node-root/workspace/coreboot_scanbuild/3rdparty/stm/Stm/StmPkg/Core/Runtime/PeSmiHandler.c |
Warning: | line 131, column 6 Value stored to 'RootState' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /** @file |
2 | |
3 | PE SMI handler - Used used for getting the other processor state and handling |
4 | SMI's during VM/PE build and execution |
5 | |
6 | This program and the accompanying materials |
7 | are licensed and made available under the terms and conditions of the BSD License |
8 | which accompanies this distribution. The full text of the license may be found at |
9 | http://opensource.org/licenses/bsd-license.php. |
10 | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. |
13 | |
14 | **/ |
15 | |
16 | #include "StmRuntime.h" |
17 | #include "PeStm.h" |
18 | #include "PeLoadVm.h" |
19 | |
20 | PE_SMI_CONTROL PeSmiControl; |
21 | |
22 | extern void SignalPeVm(UINT32 CpuIndex); |
23 | extern int CheckAndGetState(UINT32 CpuIndex); |
24 | extern void CpuReadySync(UINT32 Index); |
25 | extern PE_VM_DATA PeVmData[4]; // right now support a max of 3 PE VM (VM 0 is the SMI_HANDLER) |
26 | extern int CheckTimerSTS(UINT32 Index); |
27 | extern void StopSwTimer(void); |
28 | extern void SetEndOfSmi(void); |
29 | extern void PrintVmxState(UINT32 CpuIndex, ROOT_VMX_STATE * RootState); |
30 | |
31 | static UINT32 HandleTimer = 0; |
32 | static UINT32 HandleSmi = 0; |
33 | |
34 | // additional VM/PE SMI handling |
35 | |
36 | static UINT32 retvalue = 0; |
37 | |
38 | UINT32 PeSmiHandler(UINT32 CpuIndex) |
39 | { |
40 | ROOT_VMX_STATE * RootState; |
41 | UINT64 * NumProcessors; |
42 | UINT32 PeType = PE_PERM1; |
43 | UINT32 CpuNum; |
44 | UINT32 TimerSTS = 0; |
45 | |
46 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMINULL0, PESMIHSMI2); |
47 | //DEBUG((EFI_D_INFO, "%ld PeSmiHandler - CurrPeSmiState %ld\n", CpuIndex, PeSmiControl.PeSmiState)); |
48 | |
49 | if(PeSmiControl.PeCpuIndex == (INT32)CpuIndex ) // when the pe/vm comes in... |
50 | { |
51 | #if 0 |
52 | DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
53 | "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
54 | CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
55 | PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld PeSmiHandler - VM/PE responded to SMI, CurrPeSmiState %ld\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))); |
56 | #endif |
57 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPNMI25, PESMINULL0); |
58 | } |
59 | |
60 | if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPNMI3, PESMIPNMI25) == PESMIPNMI3) |
61 | { |
62 | // eventually the VM/PE will be started (or at least built) and this will cause one of the processors |
63 | // to send a NMI to the VM/PE processor causing it to drop out and process the SMI |
64 | // when it does, all processors will exit this loop and process the SMI as usual |
65 | |
66 | SignalPeVm(CpuIndex); // make sure that the PE/VM processes this SMI as well |
67 | } |
68 | |
69 | CpuReadySync(CpuIndex); // everyone waits until processor 0 figures out what to do |
70 | |
71 | switch(PeSmiControl.PeSmiState) |
72 | { |
73 | case PESMIPSMI1: |
74 | |
75 | // VM/PE sends a SMI to the other processors when it wants state information from other CPU's |
76 | |
77 | NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm; |
78 | |
79 | //sizeof(*NumProcessors) + sizeof(*NumProcessors)); |
80 | RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64); |
81 | |
82 | // get the local processor state |
83 | |
84 | GetRootVmxState(CpuIndex, &RootState[CpuIndex]); |
85 | |
86 | CpuReadySync(CpuIndex); // wait for everyone to finish |
87 | if(CpuIndex == 0) |
88 | { |
89 | // Reset the state |
90 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIPSMI1, PESMINULL0); |
91 | } |
92 | return 1; // tell the SmiEventHandler that there is one less processor |
93 | |
94 | break; |
95 | |
96 | case PESMIHSMI2: |
97 | |
98 | if(PeSmiControl.PeCpuIndex == (INT32)CpuIndex ) |
99 | { |
100 | InterlockedCompareExchange32(&retvalue, 1, 0); // make sure that this is zero |
101 | |
102 | if(InterlockedCompareExchange32(&PeSmiControl.PeWaitTimer, 1, 1) == 1) |
103 | { |
104 | TimerSTS = CheckTimerSTS(CpuIndex); |
105 | |
106 | if (TimerSTS == 2) |
107 | { |
108 | // we have an additional SMI |
109 | InterlockedCompareExchange32 (&retvalue, 1, 0); |
110 | |
111 | } |
112 | else |
113 | { |
114 | |
115 | InterlockedCompareExchange32 (&retvalue, 0, 1); |
116 | } |
117 | |
118 | if(TimerSTS != 0) |
119 | { |
120 | #if 0 |
121 | DEBUG((EFI_D_INFO,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
122 | "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
123 | CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
124 | PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x00000040, "%ld CheckAndGetState - (PESMIHSMI) Processing VM/PE startup PeSmiState: %d\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))); |
125 | #endif |
126 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHSMI2, PESMIHTMR4); |
127 | |
128 | NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm; |
129 | |
130 | //sizeof(*NumProcessors) + sizeof(*NumProcessors)); |
131 | RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64); |
Value stored to 'RootState' is never read | |
132 | } |
133 | } |
134 | } |
135 | |
136 | CpuReadySync(CpuIndex); |
137 | |
138 | if(InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHTMR4, PESMIHTMR4) == PESMIHTMR4) |
139 | { |
140 | NumProcessors = (UINT64 *) PeVmData[PeType].SharedPageStm; |
141 | |
142 | //sizeof(*NumProcessors) + sizeof(*NumProcessors)); |
143 | RootState = (ROOT_VMX_STATE *) ((char *)NumProcessors + 64); |
144 | |
145 | GetRootVmxState(CpuIndex, &RootState[CpuIndex]); |
146 | CpuReadySync(CpuIndex); |
147 | |
148 | if (PeSmiControl.PeCpuIndex == (INT32)CpuIndex) |
149 | { |
150 | InterlockedCompareExchange32(&PeSmiControl.PeWaitTimer, 1, 0); |
151 | StopSwTimer(); |
152 | |
153 | // start the VM/PE |
154 | PeVmData[PeType].StartMode = PEVM_PRESTART_SMI3; // starting from SMI |
155 | SetEndOfSmi(); // make sure that the timer SMI has been cleared |
156 | |
157 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHTMR4, PESMINULL0); |
158 | |
159 | for(CpuNum = 0; CpuNum < mHostContextCommon.CpuNum; CpuNum++) |
160 | { |
161 | PrintVmxState(CpuNum, &RootState[CpuNum]); |
162 | } |
163 | |
164 | if( mHostContextCommon.StmShutdown == 1) |
165 | { |
166 | // time to quit |
167 | StmTeardown(CpuIndex); |
168 | } |
169 | |
170 | if(TimerSTS == 2) |
171 | { |
172 | // SMI has happened at the same time, so process it |
173 | PeVmData[PeType].PeVmState = PE_VM_WAIT_START8; |
174 | return 0; |
175 | } |
176 | |
177 | RunPermVM(CpuIndex); |
178 | } |
179 | |
180 | // we do not reset the state here as the VM/PE will be processing |
181 | // when it competes it should end with a PeSmiState pf PESMIPNMI (waiting for NMI) |
182 | } |
183 | else |
184 | { |
185 | if(CpuIndex == 0) |
186 | { |
187 | // One of these will work |
188 | InterlockedCompareExchange32(&PeSmiControl.PeSmiState, PESMIHSMI2, PESMINULL0); |
189 | } |
190 | retvalue = 0; |
191 | } |
192 | return retvalue; |
193 | |
194 | break; |
195 | |
196 | case PESMINULL0: |
197 | |
198 | return 0; // process normally |
199 | break; |
200 | |
201 | case PESMIPNMI3: |
202 | case PESMIHTMR4: |
203 | // at this point, if this is set, the VM/PE is in the startup process and |
204 | // has set this so that at the next SMI, if it occurs while the VM/PE is active |
205 | // the pesmihandler can shoot down the VM/PE |
206 | |
207 | // we have a one return because the VM/PE will stay in SMM |
208 | |
209 | //SetEndOfSmi(); // make sure that the timer SMI has been cleared |
210 | |
211 | return 1; |
212 | break; |
213 | |
214 | default: |
215 | |
216 | DEBUG((EFI_D_ERROR,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
217 | "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n",do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
218 | CpuIndex,do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))) |
219 | PeSmiControl.PeSmiState))do { if (DebugPrintEnabled ()) { DebugPrint (0x80000000, "%ld CheckAndGetState (default) ERROR incorrect PeSmiState: %ld, setting to PESMINULL (0)\n" , CpuIndex, PeSmiControl.PeSmiState); } } while (((BOOLEAN)(0 ==1))); |
220 | PeSmiControl.PeSmiState = PESMINULL0; |
221 | return 0; |
222 | } |
223 | |
224 | } |