3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include "PciPlatform.h"
20 #include "PchAccess.h"
21 #include "VlvCommonDefinitions.h"
22 #include "PlatformBootMode.h"
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>
38 extern PCI_OPTION_ROM_TABLE mPciOptionRomTable
[];
39 extern UINTN mSizeOptionRomTable
;
41 EFI_PCI_PLATFORM_PROTOCOL mPciPlatform
= {
43 PlatformPrepController
,
48 EFI_HANDLE mPciPlatformHandle
= NULL
;
51 SYSTEM_CONFIGURATION mSystemConfiguration
;
55 IN EFI_GUID
*NameGuid
,
61 EFI_HANDLE
*HandleBuffer
;
64 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
65 UINT32 AuthenticationStatus
;
67 Status
= gBS
->LocateHandleBuffer (
69 &gEfiFirmwareVolume2ProtocolGuid
,
74 if (EFI_ERROR (Status
) || HandleCount
== 0) {
79 // Find desired image in all Fvs
81 for (Index
= 0; Index
< HandleCount
; Index
++) {
82 Status
= gBS
->HandleProtocol(
84 &gEfiFirmwareVolume2ProtocolGuid
,
88 if ( EFI_ERROR ( Status
) ) {
89 return EFI_LOAD_ERROR
;
97 Status
= Fv
->ReadSection (
104 &AuthenticationStatus
107 if ( !EFI_ERROR ( Status
)) {
112 if ( Index
>= HandleCount
) {
113 return EFI_NOT_FOUND
;
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
128 return EFI_UNSUPPORTED
;
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
143 return EFI_UNSUPPORTED
;
149 IN CONST EFI_PCI_PLATFORM_PROTOCOL
*This
,
150 OUT EFI_PCI_PLATFORM_POLICY
*PciPolicy
153 *PciPolicy
= EFI_RESERVE_VGA_IO_ALIAS
;
158 GetPciRom from platform specific location for specific PCI device
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
166 @retval EFI_NOT_FOUND
167 @retval EFI_OUT_OF_RESOURCES
173 IN CONST EFI_PCI_PLATFORM_PROTOCOL
*This
,
174 IN EFI_HANDLE PciHandle
,
180 EFI_PCI_IO_PROTOCOL
*PciIo
;
181 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
192 EFI_PLATFORM_SETUP_ID
*BootModeBuffer
;
194 EFI_PEI_HOB_POINTERS GuidHob
;
199 // Check if system is in manufacturing mode.
201 GuidHob
.Raw
= GetHobList ();
202 if (GuidHob
.Raw
== NULL
) {
203 return EFI_NOT_FOUND
;
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
)))
212 // System is in manufacturing mode.
218 Status
= gBS
->HandleProtocol (
220 &gEfiPciIoProtocolGuid
,
223 if (EFI_ERROR (Status
)) {
224 return EFI_NOT_FOUND
;
227 Status
= gBS
->LocateProtocol (
228 &gEfiPciRootBridgeIoProtocolGuid
,
230 (void **)&PciRootBridgeIo
233 if (EFI_ERROR (Status
)) {
234 return EFI_NOT_FOUND
;
237 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 0x0A, 1, &DeviceClass
);
239 PciIo
->GetLocation (PciIo
, &Segment
, &Bus
, &Device
, &Function
);
241 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 0, 1, &VendorId
);
243 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 2, 1, &DeviceId
);
246 // WA for PCIe SATA card (SYBA SY-PEX400-40)
248 if ((VendorId
== 0x1B21) && (DeviceId
== 0x0612)) {
250 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 4, 1, &Data8
);
254 // Do not run RAID or AHCI Option ROM if IDE
256 if ( (DeviceClass
== ((PCI_CLASS_MASS_STORAGE
<< 8 ) | PCI_CLASS_MASS_STORAGE_IDE
)) ) {
257 return EFI_NOT_FOUND
;
261 // Run PXE ROM only if Boot network is enabled and not in MFG mode
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
;
270 // Loop through table of Onboard option rom descriptions
272 for (TableIndex
= 0; mPciOptionRomTable
[TableIndex
].VendorId
!= 0xffff; TableIndex
++) {
275 // See if the PCI device specified by PciHandle matches at device in mPciOptionRomTable
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
)) ) {
284 Status
= GetRawImage(
285 &mPciOptionRomTable
[TableIndex
].FileName
,
290 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_VLV_A0
)) {
291 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_VLV_A0
;
294 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_II
)) {
295 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_II
;
298 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_0BE4
)) {
299 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_0BE4
;
302 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_QS
)) {
303 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_QS
;
307 if (EFI_ERROR (Status
)) {
313 return EFI_NOT_FOUND
;
318 @param (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
325 PciPlatformDriverEntry (
326 IN EFI_HANDLE ImageHandle
,
327 IN EFI_SYSTEM_TABLE
*SystemTable
333 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
334 Status
= gRT
->GetVariable(
336 &gEfiNormalSetupGuid
,
339 &mSystemConfiguration
341 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
342 //The setup variable is corrupted
343 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
344 Status
= gRT
->GetVariable(
346 &gEfiNormalSetupGuid
,
349 &mSystemConfiguration
351 ASSERT_EFI_ERROR (Status
);
355 // Install on a new handle
357 Status
= gBS
->InstallProtocolInterface (
359 &gEfiPciPlatformProtocolGuid
,
360 EFI_NATIVE_INTERFACE
,