blob: 2f8996bc1a58fa73ef6c968b0abbce33b7239197 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/**
2 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
3 This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11
12Module Name:
13
14
15 PpmPolicy.c
16
17Abstract:
18
19 This file is a wrapper for Intel PPM Platform Policy driver.
20 Get Setup Value to initilize Intel PPM DXE Platform Policy.
21
22--*/
23#include "PpmPolicy.h"
24#include <Protocol/MpService.h>
25#include <Library/BaseLib.h>
26#include <Library/DebugLib.h>
27#include <Library/CpuIA32.h>
28
29#include <PchRegs.h>
30#include <Library/PchPlatformLib.h>
31
32#define EFI_CPUID_FAMILY 0x0F00
33#define EFI_CPUID_MODEL 0x00F0
34#define EFI_CPUID_STEPPING 0x000F
35
36
37
38EFI_STATUS
39EFIAPI
40PpmPolicyEntry(
41 IN EFI_HANDLE ImageHandle,
42 IN EFI_SYSTEM_TABLE *SystemTable
43)
44{
45 EFI_MP_SERVICES_PROTOCOL *MpService;
46 EFI_CPUID_REGISTER Cpuid01 = { 0, 0, 0, 0};
47 EFI_HANDLE Handle;
48 EFI_STATUS Status;
49 UINTN CpuCount;
50 UINT64 MaxRatio;
51 UINT8 CPUMobileFeature;
52
53 PCH_STEPPING Stepping;
54
55
56 gBS = SystemTable->BootServices;
57 pBS = SystemTable->BootServices;
58 pRS = SystemTable->RuntimeServices;
59
60 //
61 // Set PPM policy structure to known value
62 //
63 gBS->SetMem (&mDxePlatformPpmPolicy, sizeof(PPM_PLATFORM_POLICY_PROTOCOL), 0);
64
65 //
66 // Find the MpService Protocol
67 //
68 Status = pBS->LocateProtocol (&gEfiMpServiceProtocolGuid,
69 NULL,
70 (void **)&MpService
71 );
72 ASSERT_EFI_ERROR (Status);
73
74 //
75 // Get processor count from MP service.
76 //
77 Status = MpService->GetNumberOfProcessors (MpService, &CpuCount, NULL);
78 ASSERT_EFI_ERROR (Status);
79
80 //
81 // Store the CPUID for use by SETUP items.
82 //
83 AsmCpuid (EFI_CPUID_VERSION_INFO, &Cpuid01.RegEax, &Cpuid01.RegEbx, &Cpuid01.RegEcx, &Cpuid01.RegEdx);
84 MaxRatio = ((RShiftU64 (AsmReadMsr64(EFI_MSR_IA32_PLATFORM_ID), 8)) & 0x1F);
85
86
87 mDxePlatformPpmPolicy.Revision = PPM_PLATFORM_POLICY_PROTOCOL_REVISION_4;
88
89 //Read CPU Mobile feature from PLATFORM_ID_MSR MSR(0x17) NOTFB_I_AM_NOT_MOBILE_FUSE_CLIAMC00H Bit 28
90 //Bit Description: { Disables Mobile features 0 = I am NOT a mobile part 1 = I am a mobile part (default)"}
91 CPUMobileFeature = ((RShiftU64 (AsmReadMsr64(EFI_MSR_IA32_PLATFORM_ID), 28)) & 0x1);
92
93 if (!EFI_ERROR(Status)) {
94 if (CPUMobileFeature == 1){//CPU mobile feature
95 mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_ENABLE;
96 mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_ENABLE;
97 mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_DISABLE;
98 mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE;
99 //MaxC7
100 mDxePlatformPpmPolicy.FunctionEnables.EnableC7 = ICH_DEVICE_ENABLE;
101 mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_ENABLE;
102 mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_ENABLE;
103
104
105 }else{//CPU desktop feature
106 mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_DISABLE;
107 mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_DISABLE;
108 mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_DISABLE;
109 mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_DISABLE;
110 mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_DISABLE;
111 mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_DISABLE;
112 mDxePlatformPpmPolicy.FunctionEnables.EnableC7 = ICH_DEVICE_DISABLE;
113 }
114
115
116 mDxePlatformPpmPolicy.FunctionEnables.EnableProcHot = ICH_DEVICE_ENABLE;
117 mDxePlatformPpmPolicy.FunctionEnables.TStatesEnable = ICH_DEVICE_ENABLE;
118
119
120 Stepping = PchStepping();
121 if (Stepping < PchB3) {
122 // If SoC is B0~B2 Stepping, disable the Turbo
123 mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_DISABLE;
124 } else {
125 mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_ENABLE;
126 }
127
128 mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE;
129
130 mDxePlatformPpmPolicy.FunctionEnables.EnableCMP = ICH_DEVICE_ENABLE;
131
132 } else {
133 mDxePlatformPpmPolicy.FunctionEnables.EnableGv = ICH_DEVICE_ENABLE;
134 mDxePlatformPpmPolicy.FunctionEnables.EnableCx = ICH_DEVICE_ENABLE;
135 mDxePlatformPpmPolicy.FunctionEnables.EnableCxe = ICH_DEVICE_ENABLE;
136 mDxePlatformPpmPolicy.FunctionEnables.EnableTm = ICH_DEVICE_ENABLE;
137 mDxePlatformPpmPolicy.FunctionEnables.EnableProcHot = ICH_DEVICE_ENABLE;
138 mDxePlatformPpmPolicy.FunctionEnables.EnableCMP = ICH_DEVICE_DISABLE;
139 mDxePlatformPpmPolicy.FunctionEnables.TStatesEnable = ICH_DEVICE_ENABLE;
140 mDxePlatformPpmPolicy.FunctionEnables.EnableTurboMode= ICH_DEVICE_ENABLE;
141 mDxePlatformPpmPolicy.FunctionEnables.EnableC4 = ICH_DEVICE_ENABLE;
142 mDxePlatformPpmPolicy.FunctionEnables.EnableC6 = ICH_DEVICE_ENABLE;
143 }
144
145
146
147 mDxePlatformPpmPolicy.S3RestoreMsrSwSmiNumber = S3_RESTORE_MSR_SW_SMI;
148
149 Handle = NULL;
150 Status = gBS->InstallMultipleProtocolInterfaces (
151 &Handle,
152 &gPpmPlatformPolicyProtocolGuid,
153 &mDxePlatformPpmPolicy,
154 NULL
155 );
156
157 ASSERT_EFI_ERROR (Status);
158
159 return EFI_SUCCESS;
160}