summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/SystemAgent/SampleCode/SaPolicyInit/Dxe/SaDxePolicyInit.c
blob: f907f4fabc8e39a96f73d44cbfa0d000332073bf (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
/** @file
  This file is a wrapper for Intel SA Platform Policy driver.
  Get Setup Value to initilize Intel SA DXE Platform Policy.

@copyright
  Copyright (c) 1999 - 2014 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 "SaDxePolicyInit.h"

DXE_PLATFORM_SA_POLICY_PROTOCOL mDxePlatformSaPolicy;

PCIE_ASPM_DEV_INFO mPcieAspmDevsOverride[] = {
  ///
  /// Tekoa w/o iAMT
  ///
  {0x8086, 0x108b, 0xff, 2, 2},
  ///
  /// Tekoa A2
  ///
  {0x8086, 0x108c, 0x00, 0, 0},
  ///
  /// Tekoa others
  ///
  {0x8086, 0x108c, 0xff, 2, 2},
  ///
  /// Vidalia
  ///
  {0x8086, 0x109a, 0xff, 2, 2},
  ///
  /// 3945ABG
  ///
  {0x8086, 0x4222, 0xff, 2, 3},
  ///
  /// 3945ABG
  ///
  {0x8086, 0x4227, 0xff, 2, 3},
  ///
  /// 3945ABG
  ///
  {0x8086, 0x4228, 0xff, 2, 3},
  ///
  /// End of table
  ///
  {SA_PCIE_DEV_END_OF_TABLE, 0, 0, 0, 0}
};

PCIE_LTR_DEV_INFO mPcieLtrDevsOverride[] = {
  ///
  /// Place holder for PCIe devices with correct LTR requirements
  ///
  ///
  /// End of table
  ///
  {SA_PCIE_DEV_END_OF_TABLE, 0, 0, 0, 0}
};
///
/// Function implementations
///
/**
  Initilize Intel SA DXE Platform Policy

  @param[in] ImageHandle       Image handle of this driver.
  @param[in] SystemTable       Global system service table.

  @retval EFI_SUCCESS           Initialization complete.
  @exception EFI_UNSUPPORTED       The chipset is unsupported by this driver.
  @retval EFI_OUT_OF_RESOURCES  Do not have enough resources to initialize the driver.
  @retval EFI_DEVICE_ERROR      Device error, driver exits abnormally.
**/
EFI_STATUS
EFIAPI
SaDxePolicyInitEntryPoint (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  EFI_STATUS  Status;
  UINT8       pegFn;
  UINT8       Index;

  SetMem (&mDxePlatformSaPolicy, sizeof (DXE_PLATFORM_SA_POLICY_PROTOCOL), 0);
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_VTD_CONFIGURATION), &(mDxePlatformSaPolicy.Vtd));
  ASSERT_EFI_ERROR (Status);
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_MEMORY_CONFIGURATION), &(mDxePlatformSaPolicy.MemoryConfig));
  ASSERT_EFI_ERROR (Status);
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_PCIE_CONFIGURATION), &(mDxePlatformSaPolicy.PcieConfig));
  ASSERT_EFI_ERROR (Status);
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_IGD_CONFIGURATION), &(mDxePlatformSaPolicy.IgdConfig));
  ASSERT_EFI_ERROR (Status);
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_MISC_CONFIGURATION), &(mDxePlatformSaPolicy.MiscConfig));
  ASSERT_EFI_ERROR (Status);
#ifdef SG_SUPPORT
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_SG_VBIOS_CONFIGURATION), &(mDxePlatformSaPolicy.VbiosConfig));
  ASSERT_EFI_ERROR (Status);
#endif

  ///
  /// SA DXE Policy Init
  ///
  mDxePlatformSaPolicy.Revision = DXE_SA_PLATFORM_POLICY_PROTOCOL_REVISION_8;

  ///
  /// Initialize the VTD Configuration
  ///
  mDxePlatformSaPolicy.Vtd->VtdEnable       = 0;
  mDxePlatformSaPolicy.Vtd->BaseAddress[0]  = 0xFED90000;
  mDxePlatformSaPolicy.Vtd->BaseAddress[1]  = 0xFED91000;
  ///
  /// RMRR Base and Limit Address for USB
  ///
  Status = (gBS->AllocatePool) (EfiBootServicesData, (sizeof (EFI_PHYSICAL_ADDRESS) * 2), (VOID **) &mDxePlatformSaPolicy.Vtd->RmrrUsbBaseAddress);
  ASSERT_EFI_ERROR (Status);
  ///
  /// BIOS must update USB RMRR base address
  ///
  mDxePlatformSaPolicy.Vtd->RmrrUsbBaseAddress[0] = 0x3E2E0000;
  mDxePlatformSaPolicy.Vtd->RmrrUsbBaseAddress[1] = 0x3E2FFFFF;

  ///
  /// Initialize the PCIE Configuration
  ///
  mDxePlatformSaPolicy.PcieConfig->DmiAspm = PcieAspmL0sL1;
  ///
  /// PEG ASPM per port configuration. 3 PEG controllers i.e. 0,1,2
  ///
  for (pegFn = 0; pegFn < 3; pegFn++) {
    mDxePlatformSaPolicy.PcieConfig->PegAspm[pegFn]       = PcieAspmAutoConfig;
    mDxePlatformSaPolicy.PcieConfig->PegAspmL0s[pegFn]    = 0;
    mDxePlatformSaPolicy.PcieConfig->PegDeEmphasis[pegFn] = 1;
  }

  mDxePlatformSaPolicy.PcieConfig->DmiExtSync     = 0;
  mDxePlatformSaPolicy.PcieConfig->DmiDeEmphasis  = 0;
  mDxePlatformSaPolicy.PcieConfig->DmiIot = 0;
  mDxePlatformSaPolicy.PcieConfig->C7Allowed = 0;
  for (Index = 0; Index < SA_PEG_MAX_FUN; Index++) {
    mDxePlatformSaPolicy.PcieConfig->PegPwrOpt[Index].LtrEnable            = 1;
    mDxePlatformSaPolicy.PcieConfig->PegPwrOpt[Index].LtrMaxSnoopLatency   = V_SA_LTR_MAX_SNOOP_LATENCY_VALUE;
    mDxePlatformSaPolicy.PcieConfig->PegPwrOpt[Index].LtrMaxNoSnoopLatency = V_SA_LTR_MAX_NON_SNOOP_LATENCY_VALUE;
    mDxePlatformSaPolicy.PcieConfig->PegPwrOpt[Index].ObffEnable           = 1;
  }

  mDxePlatformSaPolicy.PcieConfig->PcieAspmDevsOverride = mPcieAspmDevsOverride;
  mDxePlatformSaPolicy.PcieConfig->PcieLtrDevsOverride  = mPcieLtrDevsOverride;

  ///
  /// Initialize the Memory Configuration
  ///
  ///
  /// DIMM SMBus addresses info
  /// Refer to the SpdAddressTable[] mapping rule in SaPlatformPolicy.h
  ///
  Status = (gBS->AllocatePool) (EfiBootServicesData, (sizeof (UINT8) * 4), (VOID **) &mDxePlatformSaPolicy.MemoryConfig->SpdAddressTable);
  ASSERT_EFI_ERROR (Status);

  mDxePlatformSaPolicy.MemoryConfig->SpdAddressTable[0] = DIMM_SMB_SPD_P0C0D0;
  mDxePlatformSaPolicy.MemoryConfig->SpdAddressTable[1] = DIMM_SMB_SPD_P0C0D1;
  mDxePlatformSaPolicy.MemoryConfig->SpdAddressTable[2] = DIMM_SMB_SPD_P0C1D0;
  mDxePlatformSaPolicy.MemoryConfig->SpdAddressTable[3] = DIMM_SMB_SPD_P0C1D1;

  mDxePlatformSaPolicy.MemoryConfig->ChannelASlotMap    = 0x01;
  mDxePlatformSaPolicy.MemoryConfig->ChannelBSlotMap    = 0x01;
  mDxePlatformSaPolicy.MemoryConfig->RmtBdatEnable      = 0x00;

  ///
  /// Initialize the Graphics configuration
  ///
  mDxePlatformSaPolicy.IgdConfig->RenderStandby     = 1;
  mDxePlatformSaPolicy.IgdConfig->VbtAddress        = 0x00000000;
  mDxePlatformSaPolicy.IgdConfig->Size              = 0;
  mDxePlatformSaPolicy.IgdConfig->CdClk             = 0;
  mDxePlatformSaPolicy.IgdConfig->PlatformConfig    = 1;

  ///
  /// SA internal devices and misc configuration
  ///
  mDxePlatformSaPolicy.MiscConfig->ChapDeviceEnable = FALSE;
  mDxePlatformSaPolicy.MiscConfig->Device4Enable    = FALSE;
  mDxePlatformSaPolicy.MiscConfig->CridEnable       = FALSE;
  mDxePlatformSaPolicy.MiscConfig->AudioEnable      = TRUE;
  mDxePlatformSaPolicy.MiscConfig->FviReport        = 1;
  ///
  /// Default Enable FVI SMBIOS Report
  ///
  mDxePlatformSaPolicy.MiscConfig->FviSmbiosType = 0xDD;
  ///
  /// Default SMBIOS Type 221
  ///
  Status = (gBS->AllocatePool) (EfiBootServicesData, sizeof (SA_DEFAULT_SVID_SID), (VOID **) &mDxePlatformSaPolicy.MiscConfig->DefaultSvidSid);
  ASSERT_EFI_ERROR (Status);
  mDxePlatformSaPolicy.MiscConfig->DefaultSvidSid->SubSystemVendorId = V_SA_MC_VID;
  ///
  /// 0x8086;
  ///
  mDxePlatformSaPolicy.MiscConfig->DefaultSvidSid->SubSystemId = 0x2010;


#ifdef SG_SUPPORT
  ///
  /// Initialize the Switchable Graphics DXE Policies
  ///

  ///
  /// 1 = Load secondary display device VBIOS
  /// 0 = Do not load
  ///
  mDxePlatformSaPolicy.VbiosConfig->LoadVbios = 0;
  ///
  /// 1 = Execute the secondary display device VBIOS (only if LoadVbios == 1)
  /// 0 = Do no execute
  ///
  mDxePlatformSaPolicy.VbiosConfig->ExecuteVbios = 0;
  ///
  /// 1 = secondary display device VBIOS Source is PCI Card
  /// 0 = secondary display device VBIOS Source is FW Volume
  ///
  mDxePlatformSaPolicy.VbiosConfig->VbiosSource = 1;
#endif

  UpdateDxeSaPlatformPolicy (&mDxePlatformSaPolicy);

  ///
  /// Install protocol to to allow access to this Policy.
  ///
  Status = gBS->InstallMultipleProtocolInterfaces (
                  &ImageHandle,
                  &gDxePlatformSaPolicyGuid,
                  &mDxePlatformSaPolicy,
                  NULL
                  );
  ASSERT_EFI_ERROR (Status);

  return Status;
}