summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/LynxPoint/SampleCode/PchPolicyInit/Pei/PchPolicyInitPei.c
blob: 08e0cf704c4bda7ef2136116d059ac1323ccb715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/** @file
  This file is SampleCode for Intel PCH PEI Platform Policy initialzation.

@copyright
  Copyright (c) 2009 - 2013 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains a 'Sample Driver' and is licensed as such
  under the terms of your license agreement with Intel or your
  vendor.  This file may be modified by the user, subject to
  the additional terms of the license agreement

**/
#include "PchPolicyInitPei.h"
#include "..\Common\PchPolicyInitCommon.h"
#ifdef RAPID_START_FLAG
#include "RapidStartCommonLib.h"
#endif

/**
  This PEIM performs PCH PEI Platform Policy initialzation.

  @param[in] FfsHeader            Pointer to Firmware File System file header.
  @param[in] PeiServices          General purpose services available to every PEIM.

  @retval EFI_SUCCESS             The PPI is installed and initialized.
  @retval EFI ERRORS              The PPI is not successfully installed.
  @retval EFI_OUT_OF_RESOURCES    Do not have enough resources to initialize the driver
**/
EFI_STATUS
EFIAPI
PchPolicyInitPeiEntryPoint (
  IN EFI_FFS_FILE_HEADER       *FfsHeader,
  IN EFI_PEI_SERVICES          **PeiServices
  )
{
  EFI_STATUS                    Status;
  EFI_PEI_PPI_DESCRIPTOR        *PchPlatformPolicyPpiDesc;
  PCH_PLATFORM_POLICY_PPI       *PchPlatformPolicyPpi;
  PCH_GBE_CONFIG                *GbeConfig;
  PCH_THERMAL_MANAGEMENT        *ThermalMgmt;
  PCH_MEMORY_THROTTLING         *MemoryThrottling;
  PCH_HPET_CONFIG               *HpetConfig;
  PCH_SATA_CONTROL              *SataConfig;
  PCH_SATA_TRACE_CONFIG         *SataTraceConfig;
  PCH_PCIE_CONFIG               *PcieConfig;
  PCH_IOAPIC_CONFIG             *IoApicConfig;
  PCH_PLATFORM_DATA             *PlatformData;
  PCH_USB_CONFIG                *UsbConfig;
#ifdef USB_PRECONDITION_ENABLE_FLAG
  EFI_BOOT_MODE                 BootMode;
#endif  // USB_PRECONDITION_ENABLE_FLAG
  UINT8                         PortIndex;

  PchPlatformPolicyPpiDesc = (EFI_PEI_PPI_DESCRIPTOR *) AllocateZeroPool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
  ASSERT (PchPlatformPolicyPpiDesc != NULL);
  if (PchPlatformPolicyPpiDesc == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  PchPlatformPolicyPpi = (PCH_PLATFORM_POLICY_PPI *) AllocateZeroPool (sizeof (PCH_PLATFORM_POLICY_PPI));
  ASSERT (PchPlatformPolicyPpi != NULL);
  if (PchPlatformPolicyPpi == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  GbeConfig = (PCH_GBE_CONFIG *) AllocateZeroPool (sizeof (PCH_GBE_CONFIG));
  ASSERT (GbeConfig != NULL);
  if (GbeConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  ThermalMgmt = (PCH_THERMAL_MANAGEMENT *) AllocateZeroPool (sizeof (PCH_THERMAL_MANAGEMENT));
  ASSERT (ThermalMgmt != NULL);
  if (ThermalMgmt == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  MemoryThrottling = (PCH_MEMORY_THROTTLING *) AllocateZeroPool (sizeof (PCH_MEMORY_THROTTLING));
  ASSERT (MemoryThrottling != NULL);
  if (MemoryThrottling == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  HpetConfig = (PCH_HPET_CONFIG *) AllocateZeroPool (sizeof (PCH_HPET_CONFIG));
  ASSERT (HpetConfig != NULL);
  if (HpetConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  SataConfig = (PCH_SATA_CONTROL *) AllocateZeroPool (sizeof (PCH_SATA_CONTROL));
  ASSERT (SataConfig != NULL);
  if (SataConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  SataTraceConfig = (PCH_SATA_TRACE_CONFIG *) AllocateZeroPool (sizeof (PCH_SATA_TRACE_CONFIG));
  ASSERT (SataTraceConfig != NULL);
  if (SataTraceConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  PcieConfig = (PCH_PCIE_CONFIG *) AllocateZeroPool (sizeof (PCH_PCIE_CONFIG));
  ASSERT (PcieConfig != NULL);
  if (PcieConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  IoApicConfig = (PCH_IOAPIC_CONFIG *) AllocateZeroPool (sizeof (PCH_IOAPIC_CONFIG));
  ASSERT (IoApicConfig != NULL);
  if (IoApicConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  PlatformData = (PCH_PLATFORM_DATA *) AllocateZeroPool (sizeof (PCH_PLATFORM_DATA));
  ASSERT (PlatformData != NULL);
  if (PlatformData == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }

  UsbConfig = (PCH_USB_CONFIG *) AllocateZeroPool (sizeof (PCH_USB_CONFIG));
  ASSERT (UsbConfig != NULL);
  if (UsbConfig == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
  PchPlatformPolicyPpi->Revision                = PCH_PLATFORM_POLICY_PPI_REVISION_4;
  PchPlatformPolicyPpi->BusNumber               = 0;
  PchPlatformPolicyPpi->Rcba                    = PCH_LPC_RCBA_BASE_ADDRESS;
  PchPlatformPolicyPpi->PmBase                  = PCH_LPC_ACPI_BASE_ADDRESS;
  PchPlatformPolicyPpi->GpioBase                = PCH_LPC_GPIO_BASE_ADDRESS;
  PchPlatformPolicyPpi->Port80Route             = 0;

  PchPlatformPolicyPpi->GbeConfig               = GbeConfig;
  PchPlatformPolicyPpi->ThermalMgmt             = ThermalMgmt;
  PchPlatformPolicyPpi->HpetConfig              = HpetConfig;
  PchPlatformPolicyPpi->SataConfig              = SataConfig;
  PchPlatformPolicyPpi->PcieConfig              = PcieConfig;
  PchPlatformPolicyPpi->IoApicConfig            = IoApicConfig;
  PchPlatformPolicyPpi->PlatformData            = PlatformData;
  PchPlatformPolicyPpi->UsbConfig               = UsbConfig;

  GbeConfig->EnableGbe      = 1;
  ThermalMgmt->MemoryThrottling                                 = MemoryThrottling;
  MemoryThrottling->Enable                                      = PCH_DEVICE_DISABLE;
  MemoryThrottling->TsGpioPinSetting[TsGpioC].PmsyncEnable      = PCH_DEVICE_ENABLE;
  MemoryThrottling->TsGpioPinSetting[TsGpioD].PmsyncEnable      = PCH_DEVICE_ENABLE;
  MemoryThrottling->TsGpioPinSetting[TsGpioC].C0TransmitEnable  = PCH_DEVICE_ENABLE;
  MemoryThrottling->TsGpioPinSetting[TsGpioD].C0TransmitEnable  = PCH_DEVICE_ENABLE;
  MemoryThrottling->TsGpioPinSetting[TsGpioC].PinSelection      = 1;
  MemoryThrottling->TsGpioPinSetting[TsGpioD].PinSelection      = 0;

  HpetConfig->Enable = 1;
  HpetConfig->Base = PCH_HPET_BASE_ADDRESS;

  SataConfig->SataMode = PchSataModeAhci;
  SataConfig->SataTraceConfig = SataTraceConfig;

  SataTraceConfig->TestMode        = PCH_DEVICE_DISABLE;
  for( PortIndex = 0; PortIndex < 6; PortIndex++ ) {
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[0].Enable = PCH_DEVICE_DISABLE;
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[1].Enable = PCH_DEVICE_DISABLE;
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[2].Enable = PCH_DEVICE_DISABLE;
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[0].RxEq = 0x0;
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[1].RxEq = 0x0;
    SataTraceConfig->PortRxEq[PortIndex].GenSpeed[2].RxEq = 0x0;
  }

  PcieConfig->PcieSpeed[0] = PchPcieAuto;
  PcieConfig->PcieSpeed[1] = PchPcieAuto;
  PcieConfig->PcieSpeed[2] = PchPcieAuto;
  PcieConfig->PcieSpeed[3] = PchPcieAuto;
  PcieConfig->PcieSpeed[4] = PchPcieAuto;
  PcieConfig->PcieSpeed[5] = PchPcieAuto;
  PcieConfig->PcieSpeed[6] = PchPcieAuto;
  PcieConfig->PcieSpeed[7] = PchPcieAuto;

  IoApicConfig->IoApicId = 0x02;
  IoApicConfig->ApicRangeSelect = 0x00;
  IoApicConfig->IoApicEntry24_39 = PCH_DEVICE_ENABLE;

  PlatformData->EcPresent = 0;
  ///
  /// PlatformData->SmmBwp value directly depends on the value of CpuConfig->Pfat
  /// (found in CpuPolicyInitPei.c file)
  /// If CpuConfig->Pfat is set to 1 (enabled) then
  ///   PlatformData->SmmBwp has to be set to 1 (enabled)
  /// This is a PFAT Security requirement that needs to be addressed
  /// If CpuConfig->Pfat is set to 0 (disabled) then
  ///   PlatformData->SmmBwp value don't care, it can be set to either
  ///   1 (enabled) or 0 (disabled) based on customer implementation
  ///
  PlatformData->SmmBwp    = 0;

  ///
  /// Temporary Memory Base Address for PCI devices to be used to initialize MMIO registers.
  /// Minimum size is 64KB bytes.
  ///
  PlatformData->TempMemBaseAddr   = PCH_TEMP_MEM_BASE_ADDRESS;

  ///
  /// Init USB related setting
  ///
  InitPchUsbConfig (UsbConfig);

  PchPlatformPolicyPpiDesc->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
  PchPlatformPolicyPpiDesc->Guid  = &gPchPlatformPolicyPpiGuid;

  UpdatePeiPchPlatformPolicy (PeiServices, PchPlatformPolicyPpi);
#ifdef RAPID_START_FLAG
  if (RapidStartResumeCheck () == TRUE) {
    ///
    /// This is RapidStart resume, skip the UsbPrecondition feature in PEI phase
    ///
    PchPlatformPolicyPpi->UsbConfig->UsbPrecondition = 0;
  }
#endif


  PchPlatformPolicyPpiDesc->Ppi = PchPlatformPolicyPpi;
#ifdef USB_PRECONDITION_ENABLE_FLAG
  ///
  /// Update Precondition option for S4 resume. 
  /// Skip Precondition for S4 resume in case this boot may not connect BIOS USB driver.
  /// If BIOS USB driver will be connected always for S4, then disable below update.
  /// To keep consistency during boot, must enabled or disabled below function in both PEI and DXE
  /// PlatformPolicyInit driver.
  ///
  if (UsbConfig->UsbPrecondition == TRUE) {
    (*PeiServices)->GetBootMode (PeiServices, &BootMode);
    if (BootMode == BOOT_ON_S4_RESUME) {
      UsbConfig->UsbPrecondition = FALSE;
      DEBUG ((EFI_D_INFO, "BootMode is BOOT_ON_S4_RESUME, disable Precondition\n"));
    }
  }
#endif  // USB_PRECONDITION_ENABLE_FLAG

  ///
  /// Install PCH Platform Policy PPI
  ///
  Status = (**PeiServices).InstallPpi (PeiServices, PchPlatformPolicyPpiDesc);
  ASSERT_EFI_ERROR (Status);

  return Status;
}