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