]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/PciPlatform/PciPlatform.c
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / Vlv2TbltDevicePkg / PciPlatform / PciPlatform.c
1 /** @file
2
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7
8
9 Module Name:
10
11
12 PciPlatform.c
13
14 Abstract:
15 --*/
16
17
18 #include "PciPlatform.h"
19 #include "PchRegs.h"
20 #include "PchAccess.h"
21 #include "VlvCommonDefinitions.h"
22 #include "PlatformBootMode.h"
23
24 #include <Library/BaseLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Protocol/CpuIo.h>
27 #include <Protocol/PciIo.h>
28 #include <Guid/SetupVariable.h>
29 #include <Protocol/PciRootBridgeIo.h>
30 #include "SetupMode.h"
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/DebugLib.h>
34 #include <Protocol/FirmwareVolume2.h>
35 #include <Library/HobLib.h>
36 #include <IndustryStandard/Pci22.h>
37
38 extern PCI_OPTION_ROM_TABLE mPciOptionRomTable[];
39 extern UINTN mSizeOptionRomTable;
40
41 EFI_PCI_PLATFORM_PROTOCOL mPciPlatform = {
42 PhaseNotify,
43 PlatformPrepController,
44 GetPlatformPolicy,
45 GetPciRom
46 };
47
48 EFI_HANDLE mPciPlatformHandle = NULL;
49
50
51 SYSTEM_CONFIGURATION mSystemConfiguration;
52
53 EFI_STATUS
54 GetRawImage (
55 IN EFI_GUID *NameGuid,
56 IN OUT VOID **Buffer,
57 IN OUT UINTN *Size
58 )
59 {
60 EFI_STATUS Status;
61 EFI_HANDLE *HandleBuffer;
62 UINTN HandleCount;
63 UINTN Index;
64 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
65 UINT32 AuthenticationStatus;
66
67 Status = gBS->LocateHandleBuffer (
68 ByProtocol,
69 &gEfiFirmwareVolume2ProtocolGuid,
70 NULL,
71 &HandleCount,
72 &HandleBuffer
73 );
74 if (EFI_ERROR (Status) || HandleCount == 0) {
75 return EFI_NOT_FOUND;
76 }
77
78 //
79 // Find desired image in all Fvs
80 //
81 for (Index = 0; Index < HandleCount; Index++) {
82 Status = gBS->HandleProtocol(
83 HandleBuffer[Index],
84 &gEfiFirmwareVolume2ProtocolGuid,
85 (VOID **) &Fv
86 );
87
88 if ( EFI_ERROR ( Status ) ) {
89 return EFI_LOAD_ERROR;
90 }
91
92 //
93 // Try a raw file
94 //
95 *Buffer = NULL;
96 *Size = 0;
97 Status = Fv->ReadSection (
98 Fv,
99 NameGuid,
100 EFI_SECTION_RAW,
101 0,
102 Buffer,
103 Size,
104 &AuthenticationStatus
105 );
106
107 if ( !EFI_ERROR ( Status )) {
108 break;
109 }
110 }
111
112 if ( Index >= HandleCount ) {
113 return EFI_NOT_FOUND;
114 }
115
116 return EFI_SUCCESS;
117 }
118
119 EFI_STATUS
120 EFIAPI
121 PhaseNotify (
122 IN EFI_PCI_PLATFORM_PROTOCOL *This,
123 IN EFI_HANDLE HostBridge,
124 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase,
125 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
126 )
127 {
128 return EFI_UNSUPPORTED;
129 }
130
131
132 EFI_STATUS
133 EFIAPI
134 PlatformPrepController (
135 IN EFI_PCI_PLATFORM_PROTOCOL *This,
136 IN EFI_HANDLE HostBridge,
137 IN EFI_HANDLE RootBridge,
138 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,
139 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase,
140 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
141 )
142 {
143 return EFI_UNSUPPORTED;
144 }
145
146 EFI_STATUS
147 EFIAPI
148 GetPlatformPolicy (
149 IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
150 OUT EFI_PCI_PLATFORM_POLICY *PciPolicy
151 )
152 {
153 *PciPolicy = EFI_RESERVE_VGA_IO_ALIAS;
154 return EFI_SUCCESS;
155 }
156
157 /**
158 GetPciRom from platform specific location for specific PCI device
159
160 @param This Protocol instance
161 @param PciHandle Identify the specific PCI devic
162 @param RomImage Returns the ROM Image memory location
163 @param RomSize Returns Rom Image size
164
165 @retval EFI_SUCCESS
166 @retval EFI_NOT_FOUND
167 @retval EFI_OUT_OF_RESOURCES
168
169 **/
170 EFI_STATUS
171 EFIAPI
172 GetPciRom (
173 IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
174 IN EFI_HANDLE PciHandle,
175 OUT VOID **RomImage,
176 OUT UINTN *RomSize
177 )
178 {
179 EFI_STATUS Status;
180 EFI_PCI_IO_PROTOCOL *PciIo;
181 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;
182 UINTN Segment;
183 UINTN Bus;
184 UINTN Device;
185 UINTN Function;
186 UINT16 VendorId;
187 UINT16 DeviceId;
188 UINT16 DeviceClass;
189 UINTN TableIndex;
190 UINT8 Data8;
191 BOOLEAN MfgMode;
192 EFI_PLATFORM_SETUP_ID *BootModeBuffer;
193
194 EFI_PEI_HOB_POINTERS GuidHob;
195
196 MfgMode = FALSE;
197
198 //
199 // Check if system is in manufacturing mode.
200 //
201 GuidHob.Raw = GetHobList ();
202 if (GuidHob.Raw == NULL) {
203 return EFI_NOT_FOUND;
204 }
205
206 if ((GuidHob.Raw = GetNextGuidHob (&gEfiPlatformBootModeGuid, GuidHob.Raw)) != NULL) {
207 BootModeBuffer = GET_GUID_HOB_DATA (GuidHob.Guid);
208 if (!CompareMem (&BootModeBuffer->SetupName, MANUFACTURE_SETUP_NAME,
209 StrSize (MANUFACTURE_SETUP_NAME)))
210 {
211 //
212 // System is in manufacturing mode.
213 //
214 MfgMode = TRUE;
215 }
216 }
217
218 Status = gBS->HandleProtocol (
219 PciHandle,
220 &gEfiPciIoProtocolGuid,
221 (void **)&PciIo
222 );
223 if (EFI_ERROR (Status)) {
224 return EFI_NOT_FOUND;
225 }
226
227 Status = gBS->LocateProtocol (
228 &gEfiPciRootBridgeIoProtocolGuid,
229 NULL,
230 (void **)&PciRootBridgeIo
231 );
232
233 if (EFI_ERROR (Status)) {
234 return EFI_NOT_FOUND;
235 }
236
237 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0x0A, 1, &DeviceClass);
238
239 PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);
240
241 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 0, 1, &VendorId);
242
243 PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, 2, 1, &DeviceId);
244
245 //
246 // WA for PCIe SATA card (SYBA SY-PEX400-40)
247 //
248 if ((VendorId == 0x1B21) && (DeviceId == 0x0612)) {
249 Data8 = 0x07;
250 PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 4, 1, &Data8);
251 }
252
253 //
254 // Do not run RAID or AHCI Option ROM if IDE
255 //
256 if ( (DeviceClass == ((PCI_CLASS_MASS_STORAGE << 8 ) | PCI_CLASS_MASS_STORAGE_IDE)) ) {
257 return EFI_NOT_FOUND;
258 }
259
260 //
261 // Run PXE ROM only if Boot network is enabled and not in MFG mode
262 //
263 if (DeviceClass == ((PCI_CLASS_NETWORK << 8 ) | PCI_CLASS_NETWORK_ETHERNET)) {
264 if (((mSystemConfiguration.BootNetwork == 0) && (MfgMode == FALSE )) || (mSystemConfiguration.FastBoot == 1)) {
265 return EFI_NOT_FOUND;
266 }
267 }
268
269 //
270 // Loop through table of Onboard option rom descriptions
271 //
272 for (TableIndex = 0; mPciOptionRomTable[TableIndex].VendorId != 0xffff; TableIndex++) {
273
274 //
275 // See if the PCI device specified by PciHandle matches at device in mPciOptionRomTable
276 //
277 if (VendorId != mPciOptionRomTable[TableIndex].VendorId ||
278 DeviceId != mPciOptionRomTable[TableIndex].DeviceId ||
279 ((DeviceClass == ((PCI_CLASS_NETWORK << 8 ) | PCI_CLASS_NETWORK_ETHERNET)) &&
280 (mPciOptionRomTable[TableIndex].Flag != mSystemConfiguration.BootNetwork)) ) {
281 continue;
282 }
283
284 Status = GetRawImage(
285 &mPciOptionRomTable[TableIndex].FileName,
286 RomImage,
287 RomSize
288 );
289
290 if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_VLV_A0)) {
291 *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_VLV_A0;
292 }
293
294 if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_II)) {
295 *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_II;
296 }
297
298 if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_0BE4)) {
299 *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_0BE4;
300 }
301
302 if ((VendorId == IGD_VID) && (DeviceId == IGD_DID_QS)) {
303 *(UINT16 *)(((UINTN) *RomImage) + OPROM_DID_OFFSET) = IGD_DID_QS;
304 }
305
306
307 if (EFI_ERROR (Status)) {
308 continue;
309 }
310 return EFI_SUCCESS;
311 }
312
313 return EFI_NOT_FOUND;
314 }
315
316 /**
317
318 @param (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
319
320 @retval EFI_STATUS
321
322 **/
323 EFI_STATUS
324 EFIAPI
325 PciPlatformDriverEntry (
326 IN EFI_HANDLE ImageHandle,
327 IN EFI_SYSTEM_TABLE *SystemTable
328 )
329 {
330 EFI_STATUS Status;
331 UINTN VarSize;
332
333 VarSize = sizeof(SYSTEM_CONFIGURATION);
334 Status = gRT->GetVariable(
335 L"Setup",
336 &gEfiNormalSetupGuid,
337 NULL,
338 &VarSize,
339 &mSystemConfiguration
340 );
341 if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
342 //The setup variable is corrupted
343 VarSize = sizeof(SYSTEM_CONFIGURATION);
344 Status = gRT->GetVariable(
345 L"SetupRecovery",
346 &gEfiNormalSetupGuid,
347 NULL,
348 &VarSize,
349 &mSystemConfiguration
350 );
351 ASSERT_EFI_ERROR (Status);
352 }
353
354 //
355 // Install on a new handle
356 //
357 Status = gBS->InstallProtocolInterface (
358 &mPciPlatformHandle,
359 &gEfiPciPlatformProtocolGuid,
360 EFI_NATIVE_INTERFACE,
361 &mPciPlatform
362 );
363
364 return Status;
365 }
366
367