aboutsummaryrefslogtreecommitdiff
path: root/src/vendorcode/amd/agesa/f16kb/Proc/CPU/Family/0x16/KB/F16KbPsi.c
blob: 7d9d4d2a96c3bd6b4ad0f1c8bf5e7710bc2ac1ad (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* $NoKeywords:$ */
/**
 * @file
 *
 * AMD Family_16 Kabini PSI Initialization
 *
 * Enables Power Status Indicator (PSI) feature
 *
 * @xrefitem bom "File Content Label" "Release Content"
 * @e project:      AGESA
 * @e sub-project:  CPU/Family/0x16/KB
 * @e \$Revision: 84150 $   @e \$Date: 2012-12-12 15:46:25 -0600 (Wed, 12 Dec 2012) $
 *
 */
/*
 ******************************************************************************
 *
 * Copyright (c) 2008 - 2013, Advanced Micro Devices, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
 *       its contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ******************************************************************************
 */

/*----------------------------------------------------------------------------------------
 *                             M O D U L E S    U S E D
 *----------------------------------------------------------------------------------------
 */
#include "AGESA.h"
#include "amdlib.h"
#include "cpuRegisters.h"
#include "cpuF16PowerMgmt.h"
#include "F16KbPowerMgmt.h"
#include "cpuFeatures.h"
#include "cpuServices.h"
#include "GeneralServices.h"
#include "cpuFamilyTranslation.h"
#include "CommonReturns.h"
#include "cpuPsi.h"
#include "Filecode.h"
CODE_GROUP (G2_PEI)
RDATA_GROUP (G2_PEI)

#define FILECODE PROC_CPU_FAMILY_0X16_KB_F16KBPSI_FILECODE

/*----------------------------------------------------------------------------------------
 *                   D E F I N I T I O N S    A N D    M A C R O S
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------
 *                  T Y P E D E F S     A N D     S T R U C T U R E S
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------
 *           P R O T O T Y P E S     O F     L O C A L     F U N C T I O N S
 *----------------------------------------------------------------------------------------
 */

VOID
STATIC
F16KbPmVrmLowPowerModeEnable (
  IN       CPU_SPECIFIC_SERVICES    *FamilySpecificServices,
  IN       PLATFORM_CONFIGURATION   *PlatformConfig,
  IN       PCI_ADDR                 PciAddress,
  IN       AMD_CONFIG_PARAMS        *StdHeader
  );

/*----------------------------------------------------------------------------------------
 *                          E X P O R T E D    F U N C T I O N S
 *----------------------------------------------------------------------------------------
 */

/*---------------------------------------------------------------------------------------*/
/**
 * Entry point for enabling Power Status Indicator
 *
 * This function must be run after all P-State routines have been executed
 *
 * @param[in]  PsiServices             The current CPU's family services.
 * @param[in]  EntryPoint              Timepoint designator.
 * @param[in]  PlatformConfig          Contains the runtime modifiable feature input data.
 * @param[in]  StdHeader               Config handle for library and services.
 *
 * @retval     AGESA_SUCCESS           Always succeeds.
 *
 */
AGESA_STATUS
STATIC
F16KbInitializePsi (
  IN       PSI_FAMILY_SERVICES    *PsiServices,
  IN       UINT64                  EntryPoint,
  IN       PLATFORM_CONFIGURATION *PlatformConfig,
  IN       AMD_CONFIG_PARAMS      *StdHeader
  )
{
  PCI_ADDR                  PciAddress;
  CPU_SPECIFIC_SERVICES     *FamilySpecificServices;

  if ((EntryPoint & (CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_AFTER_RESUME_MTRR_SYNC)) != 0) {
    GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, StdHeader);
    PciAddress.AddressValue = MAKE_SBDFO (0, 0, 24, 0, 0);
    // Configure PsiVid
    F16KbPmVrmLowPowerModeEnable (FamilySpecificServices, PlatformConfig, PciAddress, StdHeader);
  }

  return AGESA_SUCCESS;
}


/*---------------------------------------------------------------------------------------*/
/**
 * Sets up PSI_L operation.
 *
 * This function implements the LowPowerThreshold parameter.
 *
 * @param[in]  FamilySpecificServices  The current Family Specific Services.
 * @param[in]  PlatformConfig          Contains the runtime modifiable feature input data.
 * @param[in]  PciAddress              Segment, bus, device number of the node to transition.
 * @param[in]  StdHeader               Config handle for library and services.
 *
 */
VOID
STATIC
F16KbPmVrmLowPowerModeEnable (
  IN       CPU_SPECIFIC_SERVICES    *FamilySpecificServices,
  IN       PLATFORM_CONFIGURATION   *PlatformConfig,
  IN       PCI_ADDR                 PciAddress,
  IN       AMD_CONFIG_PARAMS        *StdHeader
  )
{
  PSTATE_MSR                     PstateMsr;
  CLK_PWR_TIMING_CTRL2_REGISTER  ClkPwrTimingCtrl2;
  POWER_CTRL_MISC_REGISTER       PwrCtrlMisc;
  UINT32                         CoreVrmLowPowerThreshold;
  UINT32                         Pstate;
  UINT32                         HwPstateMaxVal;
  UINT32                         PstateCurrent;
  UINT32                         NextPstateCurrent;
  UINT32                         PreviousVid;
  UINT32                         CurrentVid;

  NB_PSTATE_REGISTER             NbPstateReg;
  NB_PSTATE_CTRL_REGISTER        NbPsCtrl;
  MISC_VOLTAGE_REGISTER          MiscVoltageReg;
  UINT32                         NbVrmLowPowerThreshold;
  UINT32                         NbPstate;
  UINT32                         NbPstateMaxVal;
  UINT32                         NbPstateCurrent;
  UINT32                         NextNbPstateCurrent;
  UINT32                         PreviousNbVid;
  UINT32                         CurrentNbVid;

  IDS_HDT_CONSOLE (CPU_TRACE, "  F16KbPmVrmLowPowerModeEnable\n");

  if (PlatformConfig->VrmProperties[CoreVrm].LowPowerThreshold != 0) {
    // Set up PSI0_L for VDD
    CoreVrmLowPowerThreshold = PlatformConfig->VrmProperties[CoreVrm].LowPowerThreshold;
    IDS_HDT_CONSOLE (CPU_TRACE, "    Core VRM - LowPowerThreshold: %d\n", CoreVrmLowPowerThreshold);
    PreviousVid = 0xFF;
    CurrentVid = 0xFF;

    PciAddress.AddressValue = CPTC2_PCI_ADDR;
    LibAmdPciRead (AccessWidth32, PciAddress, &ClkPwrTimingCtrl2, StdHeader);
    HwPstateMaxVal = ClkPwrTimingCtrl2.HwPstateMaxVal;
    ASSERT (HwPstateMaxVal < NM_PS_REG);

    IDS_HDT_CONSOLE (CPU_TRACE, "    HwPstateMaxVal %d\n", HwPstateMaxVal);
    // Check P-state from P0 to HwPstateMaxVal
    for (Pstate = 0; Pstate <= HwPstateMaxVal; Pstate++) {
      FamilySpecificServices->GetProcIddMax (FamilySpecificServices, (UINT8) Pstate, &PstateCurrent, StdHeader);

      LibAmdMsrRead ((UINT32) (Pstate + PS_REG_BASE), (UINT64 *) &PstateMsr, StdHeader);
      CurrentVid = (UINT32) PstateMsr.CpuVid;

      if (Pstate == HwPstateMaxVal) {
        NextPstateCurrent = 0;
      } else {
        // Check P-state from P1 to HwPstateMaxVal
        FamilySpecificServices->GetProcIddMax (FamilySpecificServices, (UINT8) (Pstate + 1), &NextPstateCurrent, StdHeader);
      }

      if ((PstateCurrent <= CoreVrmLowPowerThreshold) &&
          (NextPstateCurrent <= CoreVrmLowPowerThreshold) &&
          (CurrentVid != PreviousVid)) {
        // Program PsiVid and PsiVidEn if PSI state is found and stop searching.
        PciAddress.AddressValue = PW_CTL_MISC_PCI_ADDR;
        LibAmdPciRead (AccessWidth32, PciAddress, &PwrCtrlMisc, StdHeader);
        PwrCtrlMisc.PsiVid = CurrentVid;
        PwrCtrlMisc.PsiVidEn = 1;
        LibAmdPciWrite (AccessWidth32, PciAddress, &PwrCtrlMisc, StdHeader);
        IDS_HDT_CONSOLE (CPU_TRACE, "    PsiVid is enabled at P-state %d. PsiVid: %d\n", Pstate, CurrentVid);
        break;
      } else {
        PstateCurrent = NextPstateCurrent;
        PreviousVid = CurrentVid;
      }
    }
  }

  if (PlatformConfig->VrmProperties[NbVrm].LowPowerThreshold != 0) {
    // Set up NBPSI0_L for VDDNB
    NbVrmLowPowerThreshold = PlatformConfig->VrmProperties[NbVrm].LowPowerThreshold;
    IDS_HDT_CONSOLE (CPU_TRACE, "    NB VRM - LowPowerThreshold: %d\n", NbVrmLowPowerThreshold);
    PreviousNbVid = 0xFF;
    CurrentNbVid = 0xFF;

    PciAddress.AddressValue = NB_PSTATE_CTRL_PCI_ADDR;
    LibAmdPciRead (AccessWidth32, PciAddress, &NbPsCtrl, StdHeader);
    NbPstateMaxVal = NbPsCtrl.NbPstateMaxVal;
    ASSERT (NbPstateMaxVal < NM_NB_PS_REG);

    IDS_HDT_CONSOLE (CPU_TRACE, "    NbPstateMaxVal %d\n", NbPstateMaxVal);
    for (NbPstate = 0; NbPstate <= NbPstateMaxVal; NbPstate++) {
      // Check only valid NB P-state
      if (FamilySpecificServices->GetNbIddMax (FamilySpecificServices, (UINT8) NbPstate, &NbPstateCurrent, StdHeader) != TRUE) {
        continue;
      }

      PciAddress.Address.Register = (NB_PSTATE_0 + (sizeof (NB_PSTATE_REGISTER) * NbPstate));
      LibAmdPciRead (AccessWidth32, PciAddress, &NbPstateReg, StdHeader);
      CurrentNbVid = (UINT32) GetF16KbNbVid (&NbPstateReg);

      if (NbPstate == NbPstateMaxVal) {
        NextNbPstateCurrent = 0;
      } else {
        // Check only valid NB P-state
        if (FamilySpecificServices->GetNbIddMax (FamilySpecificServices, (UINT8) (NbPstate + 1), &NextNbPstateCurrent, StdHeader) != TRUE) {
          continue;
        }
      }

      if ((NbPstateCurrent <= NbVrmLowPowerThreshold) &&
          (NextNbPstateCurrent <= NbVrmLowPowerThreshold) &&
          (CurrentNbVid != PreviousNbVid)) {
        // Program NbPsi0Vid and NbPsi0VidEn if PSI state is found and stop searching.
        PciAddress.AddressValue = MISC_VOLTAGES_PCI_ADDR;
        LibAmdPciRead (AccessWidth32, PciAddress, &MiscVoltageReg, StdHeader);
        MiscVoltageReg.NbPsi0Vid = CurrentNbVid;
        MiscVoltageReg.NbPsi0VidEn = 1;
        LibAmdPciWrite (AccessWidth32, PciAddress, &MiscVoltageReg, StdHeader);
        IDS_HDT_CONSOLE (CPU_TRACE, "    NbPsi0Vid is enabled at NB P-state %d. NbPsi0Vid: %d\n", NbPstate, CurrentNbVid);
        break;
      } else {
        PreviousNbVid = CurrentNbVid;
      }
    }
  }
}


CONST PSI_FAMILY_SERVICES ROMDATA F16KbPsiSupport =
{
  0,
  (PF_PSI_IS_SUPPORTED) CommonReturnTrue,
  F16KbInitializePsi
};