3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available under
6 the terms and conditions of the BSD License that accompanies this distribution.
7 The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include "PciPlatform.h"
25 #include "PchAccess.h"
26 #include "VlvCommonDefinitions.h"
27 #include "PlatformBootMode.h"
29 #include <Library/BaseLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Protocol/CpuIo.h>
32 #include <Protocol/PciIo.h>
33 #include <Guid/SetupVariable.h>
34 #include <Protocol/PciRootBridgeIo.h>
35 #include "SetupMode.h"
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/DebugLib.h>
39 #include <Protocol/FirmwareVolume.h>
40 #include <Library/HobLib.h>
41 #include <IndustryStandard/Pci22.h>
43 extern PCI_OPTION_ROM_TABLE mPciOptionRomTable
[];
44 extern UINTN mSizeOptionRomTable
;
46 EFI_PCI_PLATFORM_PROTOCOL mPciPlatform
= {
48 PlatformPrepController
,
53 EFI_HANDLE mPciPlatformHandle
= NULL
;
56 SYSTEM_CONFIGURATION mSystemConfiguration
;
60 IN EFI_GUID
*NameGuid
,
66 EFI_HANDLE
*HandleBuffer
;
69 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
70 UINT32 AuthenticationStatus
;
72 Status
= gBS
->LocateHandleBuffer (
74 &gEfiFirmwareVolumeProtocolGuid
,
79 if (EFI_ERROR (Status
) || HandleCount
== 0) {
84 // Find desired image in all Fvs
86 for (Index
= 0; Index
< HandleCount
; Index
++) {
87 Status
= gBS
->HandleProtocol(
89 &gEfiFirmwareVolumeProtocolGuid
,
93 if ( EFI_ERROR ( Status
) ) {
94 return EFI_LOAD_ERROR
;
102 Status
= Fv
->ReadSection (
109 &AuthenticationStatus
112 if ( !EFI_ERROR ( Status
)) {
117 if ( Index
>= HandleCount
) {
118 return EFI_NOT_FOUND
;
127 IN EFI_PCI_PLATFORM_PROTOCOL
*This
,
128 IN EFI_HANDLE HostBridge
,
129 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
,
130 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
133 return EFI_UNSUPPORTED
;
139 PlatformPrepController (
140 IN EFI_PCI_PLATFORM_PROTOCOL
*This
,
141 IN EFI_HANDLE HostBridge
,
142 IN EFI_HANDLE RootBridge
,
143 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress
,
144 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
,
145 IN EFI_PCI_CHIPSET_EXECUTION_PHASE ChipsetPhase
148 return EFI_UNSUPPORTED
;
154 IN CONST EFI_PCI_PLATFORM_PROTOCOL
*This
,
155 OUT EFI_PCI_PLATFORM_POLICY
*PciPolicy
158 *PciPolicy
= EFI_RESERVE_VGA_IO_ALIAS
;
163 GetPciRom from platform specific location for specific PCI device
165 @param This Protocol instance
166 @param PciHandle Identify the specific PCI devic
167 @param RomImage Returns the ROM Image memory location
168 @param RomSize Returns Rom Image size
171 @retval EFI_NOT_FOUND
172 @retval EFI_OUT_OF_RESOURCES
178 IN CONST EFI_PCI_PLATFORM_PROTOCOL
*This
,
179 IN EFI_HANDLE PciHandle
,
185 EFI_PCI_IO_PROTOCOL
*PciIo
;
186 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
197 EFI_PLATFORM_SETUP_ID
*BootModeBuffer
;
199 EFI_PEI_HOB_POINTERS GuidHob
;
204 // Check if system is in manufacturing mode.
206 GuidHob
.Raw
= GetHobList ();
207 if (GuidHob
.Raw
== NULL
) {
208 return EFI_NOT_FOUND
;
211 if ((GuidHob
.Raw
= GetNextGuidHob (&gEfiPlatformBootModeGuid
, GuidHob
.Raw
)) != NULL
) {
212 BootModeBuffer
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
213 if (!CompareMem (&BootModeBuffer
->SetupName
, MANUFACTURE_SETUP_NAME
,
214 StrSize (MANUFACTURE_SETUP_NAME
)))
217 // System is in manufacturing mode.
223 Status
= gBS
->HandleProtocol (
225 &gEfiPciIoProtocolGuid
,
228 if (EFI_ERROR (Status
)) {
229 return EFI_NOT_FOUND
;
232 Status
= gBS
->LocateProtocol (
233 &gEfiPciRootBridgeIoProtocolGuid
,
235 (void **)&PciRootBridgeIo
238 if (EFI_ERROR (Status
)) {
239 return EFI_NOT_FOUND
;
242 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 0x0A, 1, &DeviceClass
);
244 PciIo
->GetLocation (PciIo
, &Segment
, &Bus
, &Device
, &Function
);
246 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 0, 1, &VendorId
);
248 PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint16
, 2, 1, &DeviceId
);
251 // WA for PCIe SATA card (SYBA SY-PEX400-40)
253 if ((VendorId
== 0x1B21) && (DeviceId
== 0x0612)) {
255 PciIo
->Pci
.Write (PciIo
, EfiPciIoWidthUint8
, 4, 1, &Data8
);
259 // Do not run RAID or AHCI Option ROM if IDE
261 if ( (DeviceClass
== ((PCI_CLASS_MASS_STORAGE
<< 8 ) | PCI_CLASS_MASS_STORAGE_IDE
)) ) {
262 return EFI_NOT_FOUND
;
266 // Run PXE ROM only if Boot network is enabled and not in MFG mode
268 if (DeviceClass
== ((PCI_CLASS_NETWORK
<< 8 ) | PCI_CLASS_NETWORK_ETHERNET
)) {
269 if (((mSystemConfiguration
.BootNetwork
== 0) && (MfgMode
== FALSE
)) || (mSystemConfiguration
.FastBoot
== 1)) {
270 return EFI_NOT_FOUND
;
275 // Loop through table of Onboard option rom descriptions
277 for (TableIndex
= 0; mPciOptionRomTable
[TableIndex
].VendorId
!= 0xffff; TableIndex
++) {
280 // See if the PCI device specified by PciHandle matches at device in mPciOptionRomTable
282 if (VendorId
!= mPciOptionRomTable
[TableIndex
].VendorId
||
283 DeviceId
!= mPciOptionRomTable
[TableIndex
].DeviceId
||
284 ((DeviceClass
== ((PCI_CLASS_NETWORK
<< 8 ) | PCI_CLASS_NETWORK_ETHERNET
)) &&
285 (mPciOptionRomTable
[TableIndex
].Flag
!= mSystemConfiguration
.BootNetwork
)) ) {
289 Status
= GetRawImage(
290 &mPciOptionRomTable
[TableIndex
].FileName
,
295 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_VLV_A0
)) {
296 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_VLV_A0
;
299 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_II
)) {
300 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_II
;
303 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_0BE4
)) {
304 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_0BE4
;
307 if ((VendorId
== IGD_VID
) && (DeviceId
== IGD_DID_QS
)) {
308 *(UINT16
*)(((UINTN
) *RomImage
) + OPROM_DID_OFFSET
) = IGD_DID_QS
;
312 if (EFI_ERROR (Status
)) {
318 return EFI_NOT_FOUND
;
323 @param (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
330 PciPlatformDriverEntry (
331 IN EFI_HANDLE ImageHandle
,
332 IN EFI_SYSTEM_TABLE
*SystemTable
338 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
339 Status
= gRT
->GetVariable(
341 &gEfiNormalSetupGuid
,
344 &mSystemConfiguration
346 if (EFI_ERROR (Status
) || VarSize
!= sizeof(SYSTEM_CONFIGURATION
)) {
347 //The setup variable is corrupted
348 VarSize
= sizeof(SYSTEM_CONFIGURATION
);
349 Status
= gRT
->GetVariable(
351 &gEfiNormalSetupGuid
,
354 &mSystemConfiguration
356 ASSERT_EFI_ERROR (Status
);
360 // Install on a new handle
362 Status
= gBS
->InstallProtocolInterface (
364 &gEfiPciPlatformProtocolGuid
,
365 EFI_NATIVE_INTERFACE
,