f69436f60b613b43e42eed53832d6654fe135e85
[coreboot.git] / src / vendorcode / amd / agesa / f14 / Proc / CPU / Family / 0x10 / F10PmNbPstateInit.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_10 NB Pstate Initialization
6  *
7  * Performs the action described in F3x1F0[NbPstate] as
8  * described in the BKDG.
9  *
10  * @xrefitem bom "File Content Label" "Release Content"
11  * @e project:      AGESA
12  * @e sub-project:  CPU/F10
13  * @e \$Revision: 35877 $   @e \$Date: 2010-08-03 12:51:46 +0800 (Tue, 03 Aug 2010) $
14  *
15  */
16 /*
17  *****************************************************************************
18  *
19  * Copyright (c) 2011, Advanced Micro Devices, Inc.
20  * All rights reserved.
21  * 
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are met:
24  *     * Redistributions of source code must retain the above copyright
25  *       notice, this list of conditions and the following disclaimer.
26  *     * Redistributions in binary form must reproduce the above copyright
27  *       notice, this list of conditions and the following disclaimer in the
28  *       documentation and/or other materials provided with the distribution.
29  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of 
30  *       its contributors may be used to endorse or promote products derived 
31  *       from this software without specific prior written permission.
32  * 
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
34  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
35  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
37  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
40  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43  * 
44  * ***************************************************************************
45  *
46  */
47
48 /*----------------------------------------------------------------------------------------
49  *                             M O D U L E S    U S E D
50  *----------------------------------------------------------------------------------------
51  */
52 #include "AGESA.h"
53 #include "amdlib.h"
54 #include "cpuRegisters.h"
55 #include "cpuF10PowerMgmt.h"
56 #include "cpuApicUtilities.h"
57 #include "GeneralServices.h"
58 #include "cpuFamilyTranslation.h"
59 #include "F10PmNbPstateInit.h"
60 #include "F10PackageType.h"
61 #include "Filecode.h"
62 CODE_GROUP (G1_PEICC)
63 RDATA_GROUP (G1_PEICC)
64
65 #define FILECODE PROC_CPU_FAMILY_0X10_F10PMNBPSTATEINIT_FILECODE
66
67 /*----------------------------------------------------------------------------------------
68  *                   D E F I N I T I O N S    A N D    M A C R O S
69  *----------------------------------------------------------------------------------------
70  */
71
72 /*----------------------------------------------------------------------------------------
73  *                  T Y P E D E F S     A N D     S T R U C T U R E S
74  *----------------------------------------------------------------------------------------
75  */
76 /// Structure used for modifying the P-state
77 /// MSRs on fuse enable CPUs.
78 typedef struct {
79   UINT8   NbVid1;             ///< Destination NB VID code
80   UINT8   NbPstate;           ///< Status of NbVidUpdateAll
81 } NB_PSTATE_INIT;
82
83 /*----------------------------------------------------------------------------------------
84  *           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
85  *----------------------------------------------------------------------------------------
86  */
87 VOID
88 STATIC
89 PmNbPstateInitCore (
90   IN       VOID *NbPstateParams,
91   IN       AMD_CONFIG_PARAMS *StdHeader
92   );
93
94 /*----------------------------------------------------------------------------------------
95  *                          E X P O R T E D    F U N C T I O N S
96  *----------------------------------------------------------------------------------------
97  */
98
99 /*---------------------------------------------------------------------------------------*/
100 /**
101  * Family 10h core 0 entry point for performing the actions described in the
102  * description of F3x1F0[NbPstate].
103  *
104  * If F3x1F0[NbPstate] is non zero, it specifies the highest performance
105  * P-state in which to enable NbDid.  Each core must loop through their
106  * P-state MSRs, enabling NbDid and changing NbVid to a lower voltage.
107  *
108  * @param[in]  FamilySpecificServices  The current Family Specific Services.
109  * @param[in]  CpuEarlyParamsPtr       Service related parameters (unused).
110  * @param[in]  StdHeader               Config handle for library and services.
111  *
112  */
113 VOID
114 F10PmNbPstateInit (
115   IN       CPU_SPECIFIC_SERVICES *FamilySpecificServices,
116   IN       AMD_CPU_EARLY_PARAMS  *CpuEarlyParamsPtr,
117   IN       AMD_CONFIG_PARAMS     *StdHeader
118   )
119 {
120   UINT32         Core;
121   UINT32         Module;
122   UINT32         PciRegister;
123   UINT32         Socket;
124   AP_TASK        TaskPtr;
125   PCI_ADDR       PciAddress;
126   AGESA_STATUS   IgnoredSts;
127   NB_PSTATE_INIT ApParams;
128
129   if (FamilySpecificServices->IsNbPstateEnabled (FamilySpecificServices, &CpuEarlyParamsPtr->PlatformConfig, StdHeader)) {
130     if (CpuEarlyParamsPtr->PlatformConfig.PlatformProfile.PlatformPowerPolicy == BatteryLife) {
131       IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);
132       ASSERT (Core == 0);
133       GetPciAddress (StdHeader, Socket, Module, &PciAddress, &IgnoredSts);
134       PciAddress.Address.Function = FUNC_3;
135       PciAddress.Address.Register = 0x1F0;
136       LibAmdPciRead (AccessWidth32, PciAddress, &PciRegister, StdHeader);
137       if ((PciRegister & 0x00070000) != 0) {
138         ApParams.NbPstate = (UINT8) ((PciRegister & 0x00070000) >> 16);
139         ASSERT (ApParams.NbPstate < NM_PS_REG);
140
141         PciAddress.Address.Function = FUNC_4;
142         PciAddress.Address.Register = 0x1F4;
143         LibAmdPciRead (AccessWidth32, PciAddress, &PciRegister, StdHeader);
144         ApParams.NbVid1 = (UINT8) ((PciRegister & 0x00003F80) >> 7);
145
146         TaskPtr.FuncAddress.PfApTaskI = PmNbPstateInitCore;
147         TaskPtr.DataTransfer.DataSizeInDwords = SIZE_IN_DWORDS (NB_PSTATE_INIT);
148         TaskPtr.DataTransfer.DataPtr = &ApParams;
149         TaskPtr.DataTransfer.DataTransferFlags = 0;
150         TaskPtr.ExeFlags = WAIT_FOR_CORE;
151         ApUtilRunCodeOnAllLocalCoresAtEarly (&TaskPtr, StdHeader, CpuEarlyParamsPtr);
152
153       }
154     }
155   }
156 }
157
158
159 /*---------------------------------------------------------------------------------------*/
160 /**
161  * Support routine for F10PmNbPstateInit.
162  *
163  * This function modifies NbVid and NbDid on each core.
164  *
165  * @param[in]  NbPstateParams     Appropriate NbVid1 and NbPstate as determined by core 0.
166  * @param[in]  StdHeader          Config handle for library and services.
167  *
168  */
169 VOID
170 STATIC
171 PmNbPstateInitCore (
172   IN       VOID *NbPstateParams,
173   IN       AMD_CONFIG_PARAMS *StdHeader
174   )
175 {
176   UINT32 MsrAddress;
177   UINT64 MsrRegister;
178
179   for (MsrAddress = (PS_REG_BASE + ((NB_PSTATE_INIT *) NbPstateParams)->NbPstate); MsrAddress <= PS_MAX_REG; MsrAddress++) {
180     LibAmdMsrRead (MsrAddress, &MsrRegister, StdHeader);
181     if (((PSTATE_MSR *) &MsrRegister)->PsEnable == 1) {
182       ((PSTATE_MSR *) &MsrRegister)->NbDid = 1;
183       ((PSTATE_MSR *) &MsrRegister)->NbVid = ((NB_PSTATE_INIT *) NbPstateParams)->NbVid1;
184       LibAmdMsrWrite (MsrAddress, &MsrRegister, StdHeader);
185     }
186   }
187 }
188