summaryrefslogtreecommitdiff
path: root/ReferenceCode/Haswell/CpuS3/Pei/MpCommon.h
blob: 63a28d7807ea11c2d49b26d06895bebc4ee09ad4 (plain)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/** @file
  some definitions for MP and HT driver.

@copyright
  Copyright (c) 2005 - 2012 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains a 'Sample Driver' and is licensed as such
  under the terms of your license agreement with Intel or your
  vendor.  This file may be modified by the user, subject to
  the additional terms of the license agreement
**/
#ifndef _MP_COMMON_
#define _MP_COMMON_

#include "Tiano.h"
#include "EfiCombinationLib.h"
#include "CpuAccess.h"
#include "CpuPlatformLib.h"
#include "EdkIIGlueBaseLib.h"

///
/// Protocol produced by this driver
///
/// #include EFI_PROTOCOL_PRODUCER (MpService)
///
/// Protocol consumed by this driver
///
#include EFI_PPI_DEPENDENCY (Stall)
#include EFI_GUID_DEFINITION (SmramCpuDataHeader)
#include EFI_PPI_DEFINITION (CpuPlatformPolicy)

#define VacantFlag          0x00
#define NotVacantFlag       0xff

#define MICROSECOND         10

#define MAXIMUM_CPU_NUMBER  0x40
#define STACK_SIZE_PER_PROC 0x8000

#define MAXIMUM_CPU_S3_TABLE_SIZE     0x1000

#define IO_APIC_INDEX_REGISTER        0xFEC00000
#define IO_APIC_DATA_REGISTER         0xFEC00010
extern UINTN FixedMtrrNumber;
extern UINTN MtrrDefTypeNumber;
extern UINTN VariableMtrrNumber;

typedef struct {
  UINT16 Index;
  UINT64 Value;
} EFI_MTRR_VALUES;

typedef struct {
  UINT32 ApicId;
  UINT32 MsrIndex;
  UINT64 MsrValue;
} MP_CPU_S3_SCRIPT_DATA;

typedef struct {
  UINT32 S3BootScriptTable;
  UINT32 S3BspMtrrTable;
  UINT32 VirtualWireMode;
} MP_CPU_S3_DATA_POINTER;

typedef struct {
  UINT32                Lock;
  UINT32                StackStart;
  UINT32                StackSize;
  UINT32                ApFunction;
  PSEUDO_DESCRIPTOR     GdtrProfile;
  PSEUDO_DESCRIPTOR     IdtrProfile;
  UINT32                BufferStart;
  UINT32                PmodeOffset;
  UINT32                AcpiCpuDataAddress;
  UINT32                MtrrValuesAddress;
  UINT32                FinishedCount;
  UINT32                WakeupCount;
  UINT32                SerializeLock;
  UINT32                MicrocodePointer;
  MP_CPU_S3_SCRIPT_DATA *S3BootScriptTable;
  UINT32                StartState;
  UINT32                VirtualWireMode;
  VOID (*SemaphoreCheck)(
          UINT32 *SemaphoreAddress
          );
  UINT32                      McuLoadCount;
  EFI_PEI_SERVICES            **PeiServices;
  PEI_STALL_PPI               *PeiStall;
  UINT64                      CpuPerfCtrlValue;
  PEI_CPU_PLATFORM_POLICY_PPI *CpuPlatformPolicyPpi;
} MP_CPU_EXCHANGE_INFO;

/**
  Get protected mode code offset

  @retval Offset of protected mode code
**/
VOID *
AsmGetPmodeOffset (
  VOID
  );

/**
  Get code offset of SemaphoreCheck

  @retval Offset of SemaphoreCheck
**/
UINT32
AsmGetSemaphoreCheckOffset (
  VOID
  );

/**
  Read MTRR settings

  @param[in] PeiServices - General purpose services available to every PEIM.
  @param[in] MtrrValues  - buffer to store MTRR settings
**/
VOID
ReadMtrrRegisters (
  IN EFI_PEI_SERVICES **PeiServices,
  UINT64              *MtrrValues
  );

/**
  Syncup MTRR settings between all processors

  @param[in] MtrrValues  - buffer to store MTRR settings
**/
VOID
MpMtrrSynchUp (
  UINT64 *MtrrValues
  );

/**
  Set MTRR registers

  @param[in] PeiServices - General purpose services available to every PEIM.
  @param[in] MtrrArray   - buffer with MTRR settings
**/
VOID
SetMtrrRegisters (
  IN EFI_PEI_SERVICES **PeiServices,
  IN EFI_MTRR_VALUES  *MtrrArray
  );

#ifdef EFI_DEBUG
/**
  Print MTRR settings in debug build BIOS

  @param[in] PeiServices - General purpose services available to every PEIM.
  @param[in] MtrrArray   - buffer with MTRR settings
**/
VOID
ShowMtrrRegisters (
  IN EFI_PEI_SERVICES **PeiServices,
  IN EFI_MTRR_VALUES  *MtrrArray
  );
#endif

/**
  This will locate a processor microcode and if it finds a newer revision, it will
  load it to the processor.

  @param[in] ExchangeInfo           - Pointer to the exchange info buffer for output.
  @param[in] MicrocodePointerBuffer - The Array of pointers which each points to 1 microcode update binary (in memory)
  @param[in] FailedRevision         - The microcode revision that fails to be loaded

  @retval EFI_SUCCESS           - A new microcode update is loaded
  @retval Other                 - Due to some reason, no new microcode update is loaded
**/
EFI_STATUS
InitializeMicrocode (
  IN MP_CPU_EXCHANGE_INFO     *ExchangeInfo,
  IN EFI_CPU_MICROCODE_HEADER **MicrocodePointerBuffer,
  OUT UINT32                  *FailedRevision
  );

///
/// Functions shared in MP/HT drivers
///
/**
  Send interrupt to CPU

  @param[in] BroadcastMode - interrupt broadcast mode
  @param[in] ApicID        - APIC ID for sending interrupt
  @param[in] VectorNumber  - Vector number
  @param[in] DeliveryMode  - Interrupt delivery mode
  @param[in] TriggerMode   - Interrupt trigger mode
  @param[in] Assert        - Interrupt pin polarity
  @param[in] PeiServices   - Indirect reference to the PEI Services Table
  @param[in] PeiStall      - EFI_PEI_STALL_PPI to stall for some interval

  @retval EFI_INVALID_PARAMETER - input parameter not correct
  @retval EFI_NOT_READY         - there was a pending interrupt
  @retval EFI_SUCCESS           - interrupt sent successfully
**/
EFI_STATUS
SendInterrupt (
  IN UINT32           BroadcastMode,
  IN UINT32           ApicID,
  IN UINT32           VectorNumber,
  IN UINT32           DeliveryMode,
  IN UINT32           TriggerMode,
  IN BOOLEAN          Assert,
  IN EFI_PEI_SERVICES **PeiServices,
  IN PEI_STALL_PPI    *PeiStall
  );

/**
  Get APIC ID of processor

  @retval APIC ID of processor
**/
UINT32
GetApicID (
  VOID
  );

/**
  Programs Local APIC registers for virtual wire mode.

  @param[in] BSP             - Is this BSP?
**/
VOID
ProgramXApic (
  BOOLEAN BSP
  );

/**
  Lock APs

  @param[in] Lock  - Lock state
**/
VOID
AsmAcquireMPLock (
  IN UINT8 *Lock
  );

/**
  Release APs

  @param[in] Lock  - Lock state
**/
VOID
AsmReleaseMPLock (
  IN UINT8 *Lock
  );

/**
  Get address map of RendezvousFunnelProc.

  @retval AddressMap  - Output buffer for address map information
**/
VOID *
AsmGetAddressMap (
  VOID
  );

/**
  Do CLI and HALT processor
**/
VOID
AsmCliHltLoop (
  VOID
  );

#endif