4 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
6 This program and the accompanying materials are licensed and made available under
7 the terms and conditions of the BSD License that accompanies this distribution.
8 The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 This is the driver that initializes the Intel ValleyView.
26 #include "VlvPlatformInit.h"
27 #include <Protocol/VlvPlatformPolicy.h>
29 extern DXE_VLV_PLATFORM_POLICY_PROTOCOL
*DxePlatformSaPolicy
;
32 DXE_VLV_PLATFORM_POLICY_PROTOCOL
*DxePlatformSaPolicy
;
35 "Poll Status" for GT Readiness
37 @param Base Base address of MMIO
38 @param Offset MMIO Offset
40 @param Result Value to wait for
58 GtStatus
= MmioRead32 ((UINTN
)Base
+ Offset
);
60 while (((GtStatus
& Mask
) != Result
)) {
62 GtStatus
= MmioRead32 ((UINTN
)Base
+ Offset
);
68 Do Post GT PM Init Steps after VBIOS Initialization.
70 @param Event A pointer to the Event that triggered the callback.
71 @param Context A pointer to private data registered with the callback function.
73 @retval EFI_SUCCESS GC_TODO
84 UINT64 OriginalGTTMMADR
;
85 UINT32 LoGTBaseAddress
;
86 UINT32 HiGTBaseAddress
;
89 // Enable Bus Master, I/O and Memory access on 0:2:0
91 PciOr8 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_CMD
), (BIT2
| BIT1
));
94 // only 32bit read/write is legal for device 0:2:0
96 OriginalGTTMMADR
= (UINT64
) PciRead32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
));
97 OriginalGTTMMADR
= LShiftU64 ((UINT64
) PciRead32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
+ 4)), 32) | (OriginalGTTMMADR
);
100 // 64bit GTTMADR does not work for S3 save script table since it is executed in PEIM phase
101 // Program temporarily 32bits GTTMMADR for POST and S3 resume
103 LoGTBaseAddress
= (UINT32
) (GTTMMADR
& 0xFFFFFFFF);
104 HiGTBaseAddress
= (UINT32
) RShiftU64 ((GTTMMADR
& 0xFFFFFFFF00000000), 32);
105 S3PciWrite32(PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
), LoGTBaseAddress
);
106 S3PciWrite32(PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
+4), HiGTBaseAddress
);
111 // Restore original GTTMMADR
113 LoGTBaseAddress
= (UINT32
) (OriginalGTTMMADR
& 0xFFFFFFFF);
114 HiGTBaseAddress
= (UINT32
) RShiftU64 ((OriginalGTTMMADR
& 0xFFFFFFFF00000000), 32);
116 S3PciWrite32(PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
), LoGTBaseAddress
);
117 S3PciWrite32(PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_GTTMMADR
+4), HiGTBaseAddress
);
121 // Lock the following registers, GGC, BDSM, BGSM
123 PciOr32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_MGGC_OFFSET
), LockBit
);
124 PciOr32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_BSM_OFFSET
), LockBit
);
125 PciOr32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0,IGD_R_BGSM
), LockBit
);
127 gBS
->CloseEvent (Event
);
130 // Return final status
139 Initialize GT Post Routines.
141 @param ImageHandle Handle for the image of this driver
142 @param DxePlatformSaPolicy SA DxePlatformPolicy protocol
144 @retval EFI_SUCCESS GT POST initialization complete
149 IN EFI_HANDLE ImageHandle
,
150 IN DXE_VLV_PLATFORM_POLICY_PROTOCOL
*DxePlatformSaPolicy
154 EFI_EVENT mConOutEvent
;
155 VOID
*gConOutNotifyReg
;
159 EFI_PHYSICAL_ADDRESS MemBaseAddress
;
160 UINT32 LoGTBaseAddress
;
161 UINT32 HiGTBaseAddress
;
164 Status
= EFI_SUCCESS
;
167 // If device 0:2:0 (Internal Graphics Device, or GT) is enabled, then Program GTTMMADR,
169 if (PciRead16(PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_VID
)) != 0xFFFF) {
174 // Enable Bus Master, I/O and Memory access on 0:2:0
176 PciOr8(PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_CMD
), (BIT2
| BIT1
| BIT0
));
179 // Means Allocate 4MB for GTTMADDR
181 MemBaseAddress
= 0x0ffffffff;
183 Status
= gDS
->AllocateMemorySpace (
184 EfiGcdAllocateMaxAddressSearchBottomUp
,
185 EfiGcdMemoryTypeMemoryMappedIo
,
192 ASSERT_EFI_ERROR (Status
);
195 // Program GT PM Settings if GTTMMADR allocation is Successful
197 GTTMMADR
= (UINTN
) MemBaseAddress
;
199 LoGTBaseAddress
= (UINT32
) (MemBaseAddress
& 0xFFFFFFFF);
200 HiGTBaseAddress
= (UINT32
) RShiftU64 ((MemBaseAddress
& 0xFFFFFFFF00000000), 32);
202 PciWrite32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_GTTMMADR
), LoGTBaseAddress
);
203 PciWrite32 (PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_GTTMMADR
+4), HiGTBaseAddress
);
206 S3PciRead32(PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_GTTMMADR
));
209 S3MmioRead32(IGD_R_GTTMMADR
+ 4);
212 S3PciRead8(PCI_LIB_ADDRESS(0, IGD_DEV
, 0, IGD_R_CMD
));
215 // Do POST GT PM Init Steps after VBIOS Initialization in DoPostPmInitCallBack
217 Status
= gBS
->CreateEvent (
220 (EFI_EVENT_NOTIFY
)PostPmInitCallBack
,
225 ASSERT_EFI_ERROR (Status
);
226 if (EFI_ERROR (Status
)) {
231 Status
= gBS
->RegisterProtocolNotify (
232 &gEfiGraphicsOutputProtocolGuid
,
239 MmioWrite64 (IGD_R_GTTMMADR
, 0);
242 // Free allocated resources
244 gDS
->FreeMemorySpace (
256 This is the standard EFI driver point that detects
257 whether there is an ICH southbridge in the system
258 and if so, initializes the chip.
260 @param ImageHandle Handle for the image of this driver
261 @param SystemTable Pointer to the EFI System Table
263 @retval EFI_SUCCESS The function completed successfully
268 VlvPlatformInitEntryPoint (
269 IN EFI_HANDLE ImageHandle
,
270 IN EFI_SYSTEM_TABLE
*SystemTable
275 Status
= gBS
->LocateProtocol (&gDxeVlvPlatformPolicyGuid
, NULL
, (void **)&DxePlatformSaPolicy
);
276 ASSERT_EFI_ERROR (Status
);
279 // GtPostInit Initialization
281 DEBUG ((EFI_D_ERROR
, "Initializing GT PowerManagement and other GT POST related\n"));
282 IgdPmHook (ImageHandle
, DxePlatformSaPolicy
);
285 // IgdOpRegion Install Initialization
287 DEBUG ((EFI_D_ERROR
, "Initializing IGD OpRegion\n"));