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.
20 ACPI Platform Driver Hooks
25 // Statements that include other files.
27 #include "AcpiPlatform.h"
28 #include "AcpiPlatformHooks.h"
32 // Prototypes of the various hook functions.
34 #include "AcpiPlatformHooksLib.h"
36 extern EFI_GLOBAL_NVS_AREA_PROTOCOL mGlobalNvsArea
;
37 extern SYSTEM_CONFIGURATION mSystemConfiguration
;
39 ENHANCED_SPEEDSTEP_PROTOCOL
*mEistProtocol
= NULL
;
41 EFI_CPU_ID_MAP mCpuApicIdAcpiIdMapTable
[MAX_CPU_NUM
];
44 AppendCpuMapTableEntry (
45 IN EFI_ACPI_2_0_PROCESSOR_LOCAL_APIC_STRUCTURE
*AcpiLocalApic
51 for (Index
= 0; Index
< MAX_CPU_NUM
; Index
++) {
52 if ((mCpuApicIdAcpiIdMapTable
[Index
].ApicId
== AcpiLocalApic
->ApicId
) && mCpuApicIdAcpiIdMapTable
[Index
].Flags
) {
58 for (Index
= 0; Index
< MAX_CPU_NUM
; Index
++) {
59 if (!mCpuApicIdAcpiIdMapTable
[Index
].Flags
) {
60 mCpuApicIdAcpiIdMapTable
[Index
].Flags
= 1;
61 mCpuApicIdAcpiIdMapTable
[Index
].ApicId
= AcpiLocalApic
->ApicId
;
62 mCpuApicIdAcpiIdMapTable
[Index
].AcpiProcessorId
= AcpiLocalApic
->AcpiProcessorId
;
74 UINT32 AcpiProcessorId
79 ASSERT (AcpiProcessorId
< MAX_CPU_NUM
);
80 for (Index
= 0; Index
< MAX_CPU_NUM
; Index
++) {
81 if (mCpuApicIdAcpiIdMapTable
[Index
].Flags
&& (mCpuApicIdAcpiIdMapTable
[Index
].AcpiProcessorId
== AcpiProcessorId
)) {
82 return mCpuApicIdAcpiIdMapTable
[Index
].ApicId
;
90 GetProcNumberInPackage (
98 for (Index
= 0; Index
< MAX_CPU_NUM
; Index
++) {
99 if (mCpuApicIdAcpiIdMapTable
[Index
].Flags
&& (((mCpuApicIdAcpiIdMapTable
[Index
].ApicId
>> 0x04) & 0x01) == Package
)) {
108 LocateCpuEistProtocol (
110 OUT ENHANCED_SPEEDSTEP_PROTOCOL
**EistProtocol
114 EFI_HANDLE
*HandleBuffer
;
115 ENHANCED_SPEEDSTEP_PROTOCOL
*EistProt
;
121 gBS
->LocateHandleBuffer (
123 &gEnhancedSpeedstepProtocolGuid
,
131 Status
= EFI_NOT_FOUND
;
132 while (Index
< HandleCount
) {
133 gBS
->HandleProtocol (
135 &gEnhancedSpeedstepProtocolGuid
,
139 // Adjust the CpuIndex by +1 due to the AcpiProcessorId is 1 based.
141 ApicId
= ProcessorId2ApicId (CpuIndex
+1);
142 if (ApicId
== (UINT32
) -1) {
146 if (EistProt
->ProcApicId
== ApicId
) {
147 Status
= EFI_SUCCESS
;
154 if (HandleBuffer
!= NULL
) {
155 gBS
->FreePool (HandleBuffer
);
158 if (!EFI_ERROR (Status
)) {
159 *EistProtocol
= EistProt
;
161 *EistProtocol
= NULL
;
174 Status
= gBS
->LocateProtocol (
175 &gEnhancedSpeedstepProtocolGuid
,
177 (VOID
**) &mEistProtocol
180 ASSERT_EFI_ERROR (Status
);
186 Called for every ACPI table found in the BIOS flash.
187 Returns whether a table is active or not. Inactive tables
188 are not published in the ACPI table list.
190 This hook can be used to implement optional SSDT tables or
191 enabling/disabling specific functionality (e.g. SPCR table)
192 based on a setup switch or platform preference. In case of
193 optional SSDT tables,the platform flash will include all the
194 SSDT tables but will return EFI_SUCCESS only for those tables
195 that need to be published.
197 @param[in] *Table Pointer to the active table.
199 @retval EFI_SUCCESS if the table is active.
200 @retval EFI_UNSUPPORTED if the table is not active.
204 AcpiPlatformHooksIsActiveTable (
205 IN OUT EFI_ACPI_COMMON_HEADER
*Table
208 EFI_ACPI_DESCRIPTION_HEADER
*TableHeader
;
210 TableHeader
= (EFI_ACPI_DESCRIPTION_HEADER
*) Table
;
212 if (TableHeader
->Signature
== EFI_ACPI_2_0_STATIC_RESOURCE_AFFINITY_TABLE_SIGNATURE
) {
216 if ((mSystemConfiguration
.ENDBG2
== 0) && (CompareMem (&TableHeader
->OemTableId
, "INTLDBG2", 8) == 0)) {
217 return EFI_UNSUPPORTED
;
223 Update the GV3 SSDT table.
225 @param[in][out] *TableHeader The table to be set.
227 @retval EFI_SUCCESS Returns Success.
232 IN OUT EFI_ACPI_DESCRIPTION_HEADER
*TableHeader
243 UINT32 NewPackageSize
;
247 EFI_ACPI_NAME_COMMAND
*PssTable
;
248 EFI_PSS_PACKAGE
*PssTableItemPtr
;
249 ENHANCED_SPEEDSTEP_PROTOCOL
*EistProt
;
250 EIST_INFORMATION
*EistInfo
;
251 EFI_ACPI_CPU_PSS_STATE
*PssState
;
252 EFI_ACPI_NAMEPACK_DWORD
*NamePtr
;
254 // Loop through the ASL looking for values that we must fix up.
260 CurrPtr
= (UINT8
*) TableHeader
;
263 for (SsdtPointer
= CurrPtr
; SsdtPointer
<= (CurrPtr
+ ((EFI_ACPI_COMMON_HEADER
*) CurrPtr
)->Length
); SsdtPointer
++) {
264 Signature
= *(UINT32
*) SsdtPointer
;
267 case SIGNATURE_32 ('_', 'P', 'R', '_'):
269 // _CPUX ('0' to '0xF')
271 CpuIndex
= *(SsdtPointer
+ 7);
272 if (CpuIndex
>= '0' && CpuIndex
<= '9') {
275 if (CpuIndex
> '9') {
281 LocateCpuEistProtocol (CpuIndex
, &EistProt
);
284 case SIGNATURE_32 ('D', 'O', 'M', 'N'):
286 NamePtr
= ACPI_NAME_COMMAND_FROM_NAMEPACK_STR (SsdtPointer
);
287 if (NamePtr
->StartByte
!= AML_NAME_OP
) {
291 if (NamePtr
->Size
!= AML_NAME_DWORD_SIZE
) {
297 if (mCpuApicIdAcpiIdMapTable
[CpuIndex
].Flags
) {
298 NamePtr
->Value
= (mCpuApicIdAcpiIdMapTable
[CpuIndex
].ApicId
>> 0x04) & 0x01;
302 case SIGNATURE_32 ('N', 'C', 'P', 'U'):
304 NamePtr
= ACPI_NAME_COMMAND_FROM_NAMEPACK_STR (SsdtPointer
);
305 if (NamePtr
->StartByte
!= AML_NAME_OP
) {
309 if (NamePtr
->Size
!= AML_NAME_DWORD_SIZE
) {
314 if (mCpuApicIdAcpiIdMapTable
[CpuIndex
].Flags
) {
315 NamePtr
->Value
= GetProcNumberInPackage ((mCpuApicIdAcpiIdMapTable
[CpuIndex
].ApicId
>> 0x04) & 0x01);
319 case SIGNATURE_32 ('N', 'P', 'S', 'S'):
320 case SIGNATURE_32 ('S', 'P', 'S', 'S'):
321 if (EistProt
== NULL
) {
325 PssTable
= ACPI_NAME_COMMAND_FROM_NAME_STR (SsdtPointer
);
326 if (PssTable
->StartByte
!= AML_NAME_OP
) {
330 EistProt
->GetEistTable (EistProt
, &EistInfo
, (VOID
**) &PssState
);
332 AdjustSize
= PssTable
->NumEntries
* sizeof (EFI_PSS_PACKAGE
);
333 AdjustSize
-= EistInfo
->NumStates
* sizeof (EFI_PSS_PACKAGE
);
334 PackageSize
= (PssTable
->Size
& 0xF) + ((PssTable
->Size
& 0xFF00) >> 4);
335 NewPackageSize
= PackageSize
- AdjustSize
;
336 PssTable
->Size
= (UINT16
) ((NewPackageSize
& 0xF) + ((NewPackageSize
& 0x0FF0) << 4));
339 // Set most significant two bits of byte zero to 01, meaning two bytes used.
341 PssTable
->Size
|= 0x40;
344 // Set unused table to Noop Code.
346 SetMem( (UINT8
*) PssTable
+ NewPackageSize
+ AML_NAME_PREFIX_SIZE
, AdjustSize
, AML_NOOP_OP
);
347 PssTable
->NumEntries
= (UINT8
) EistInfo
->NumStates
;
348 PssTableItemPtr
= (EFI_PSS_PACKAGE
*) ((UINT8
*) PssTable
+ sizeof (EFI_ACPI_NAME_COMMAND
));
353 for (TableIndex
= 0; TableIndex
< EistInfo
->NumStates
; TableIndex
++) {
354 EntryIndex
= EistInfo
->NumStates
- TableIndex
- 1;
355 PssTableItemPtr
->CoreFreq
= PssState
[EntryIndex
].CoreFrequency
* PssState
[EntryIndex
].Control
;
356 PssTableItemPtr
->Power
= PssState
[EntryIndex
].Power
* 1000;
357 if (PssTable
->NameStr
== SIGNATURE_32 ('N', 'P', 'S', 'S')) {
358 PssTableItemPtr
->BMLatency
= PssState
[EntryIndex
].BusMasterLatency
;
359 PssTableItemPtr
->TransLatency
= PssState
[EntryIndex
].TransitionLatency
;
362 // This method should be supported by SMM PPM Handler.
364 PssTableItemPtr
->BMLatency
= PssState
[EntryIndex
].BusMasterLatency
* 2;
365 PssTableItemPtr
->TransLatency
= PssState
[EntryIndex
].TransitionLatency
* 10;
368 PssTableItemPtr
->Control
= PssState
[EntryIndex
].Control
;
369 PssTableItemPtr
->Status
= PssState
[EntryIndex
].Status
;
373 if (PssTable
->NameStr
== SIGNATURE_32 ('N', 'P', 'S', 'S')) {
379 SsdtPointer
= (UINT8
*) PssTable
+ PackageSize
;
385 // N fixes together currently.
387 ASSERT (CpuFixes
== (UINT32
) MAX_CPU_NUM
);
388 ASSERT (SpssFixes
== NpssFixes
);
389 ASSERT (CpuFixes
>= SpssFixes
);
395 Update the DSDT table.
397 @param[in][out] *TableHeader The table to be set.
399 @retval EFI_SUCCESS Returns EFI_SUCCESS.
404 IN OUT EFI_ACPI_DESCRIPTION_HEADER
*TableHeader
417 // Fix PCI32 resource "FIX0" -- PSYS system status area
419 CurrPtr
= (UINT8
*) &((EFI_ACPI_DESCRIPTION_HEADER
*) TableHeader
)[0];
420 EndPtr
= (UINT8
*) TableHeader
;
421 EndPtr
= EndPtr
+ TableHeader
->Length
;
422 while (CurrPtr
< (EndPtr
-2)) {
424 // Removed the _S3 tag to indicate that we do not support S3. The 4th byte is blank space
425 // since there are only 3 char "_S3".
427 if (mSystemConfiguration
.AcpiSuspendState
== 0) {
429 // For iasl compiler version 20061109.
431 if ((CurrPtr
[0] == '_') && (CurrPtr
[1] == 'S') && (CurrPtr
[2] == '3') && (CurrPtr
[3] == '_')) {
435 // For iasl compiler version 20040527.
437 if ((CurrPtr
[0] == '\\') && (CurrPtr
[1] == '_') && (CurrPtr
[2] == 'S') && (CurrPtr
[3] == '3')) {
443 CurrPtr
= (UINT8
*) &((EFI_ACPI_DESCRIPTION_HEADER
*) TableHeader
)[0];
444 EndPtr
= (UINT8
*) TableHeader
;
445 EndPtr
= EndPtr
+ TableHeader
->Length
;
446 while (CurrPtr
< (EndPtr
-2)) {
448 // For mipi dsi port select _DEP.
450 if (mSystemConfiguration
.MipiDsi
== 1) {
452 // For iasl compiler version 20061109.
454 if ((CurrPtr
[0] == 'N') && (CurrPtr
[1] == 'D') && (CurrPtr
[2] == 'E') && (CurrPtr
[3] == 'P')) {
460 if ((CurrPtr
[0] == 'P') && (CurrPtr
[1] == 'D') && (CurrPtr
[2] == 'E') && (CurrPtr
[3] == 'P')) {
469 // Loop through the ASL looking for values that we must fix up.
471 CurrPtr
= (UINT8
*) TableHeader
;
472 for (DsdtPointer
= CurrPtr
; DsdtPointer
<= (CurrPtr
+ ((EFI_ACPI_COMMON_HEADER
*) CurrPtr
)->Length
); DsdtPointer
++) {
473 Signature
= (UINT32
*) DsdtPointer
;
475 switch (*Signature
) {
477 // GNVS operation region.
479 case (SIGNATURE_32 ('G', 'N', 'V', 'S')):
481 // Conditional match. For Region Objects, the Operator will always be the
482 // byte immediately before the specific name. Therefore, subtract 1 to check
485 Operation
= DsdtPointer
- 1;
486 if (*Operation
== AML_OPREGION_OP
) {
487 Address
= (UINT32
*) (DsdtPointer
+ 6);
488 *Address
= (UINT32
) (UINTN
) mGlobalNvsArea
.Area
;
489 Size
= (UINT16
*) (DsdtPointer
+ 11);
490 *Size
= sizeof (EFI_GLOBAL_NVS_AREA
);