AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x15 / OR / F15OrC6State.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD Family_15 Orochi C6 C-state feature support functions.
6  *
7  * Provides the functions necessary to initialize the C6 feature.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/F15/OR
12  * @e \$Revision: 55600 $   @e \$Date: 2011-06-23 12:39:18 -0600 (Thu, 23 Jun 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (C) 2012 Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions are met:
23  *     * Redistributions of source code must retain the above copyright
24  *       notice, this list of conditions and the following disclaimer.
25  *     * Redistributions in binary form must reproduce the above copyright
26  *       notice, this list of conditions and the following disclaimer in the
27  *       documentation and/or other materials provided with the distribution.
28  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
29  *       its contributors may be used to endorse or promote products derived
30  *       from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  ******************************************************************************
44  */
45
46 /*----------------------------------------------------------------------------------------
47  *                             M O D U L E S    U S E D
48  *----------------------------------------------------------------------------------------
49  */
50 #include "AGESA.h"
51 #include "amdlib.h"
52 #include "Ids.h"
53 #include "cpuRegisters.h"
54 #include "cpuFeatures.h"
55 #include "cpuC6State.h"
56 #include "cpuApicUtilities.h"
57 #include "cpuF15PowerMgmt.h"
58 #include "cpuF15OrPowerMgmt.h"
59 #include "cpuServices.h"
60 #include "cpuFamilyTranslation.h"
61 #include "OptionFamily15hEarlySample.h"
62 #include "OptionMultiSocket.h"
63 #include "Filecode.h"
64 CODE_GROUP (G3_DXE)
65 RDATA_GROUP (G3_DXE)
66
67 #define FILECODE PROC_CPU_FAMILY_0X15_OR_F15ORC6STATE_FILECODE
68
69 /*----------------------------------------------------------------------------------------
70  *                   D E F I N I T I O N S    A N D    M A C R O S
71  *----------------------------------------------------------------------------------------
72  */
73 extern F15_OR_ES_C6_SUPPORT F15OrEarlySampleC6Support;
74 extern F15_OR_ES_MCU_PATCH F15OrEarlySampleLoadMcuPatch;
75 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
76
77 /*----------------------------------------------------------------------------------------
78  *                  T Y P E D E F S     A N D     S T R U C T U R E S
79  *----------------------------------------------------------------------------------------
80  */
81
82 /*----------------------------------------------------------------------------------------
83  *           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
84  *----------------------------------------------------------------------------------------
85  */
86 VOID
87 F15OrReloadMicrocodePatchAfterMemInit (
88   IN       AMD_CONFIG_PARAMS *StdHeader
89   );
90
91 /*----------------------------------------------------------------------------------------
92  *                          E X P O R T E D    F U N C T I O N S
93  *----------------------------------------------------------------------------------------
94  */
95
96 /*---------------------------------------------------------------------------------------*/
97 /**
98  *  Is C6 supported on this CPU
99  *
100  * @param[in]    C6Services         Pointer to this CPU's C6 family services.
101  * @param[in]    Socket             This core's zero-based socket number.
102  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
103  * @param[in]    StdHeader          Config Handle for library, services.
104  *
105  * @retval       TRUE               C6 state is supported.
106  * @retval       FALSE              C6 state is not supported.
107  *
108  */
109 BOOLEAN
110 STATIC
111 F15OrIsC6Supported (
112   IN       C6_FAMILY_SERVICES      *C6Services,
113   IN       UINT32                  Socket,
114   IN       PLATFORM_CONFIGURATION  *PlatformConfig,
115   IN       AMD_CONFIG_PARAMS       *StdHeader
116   )
117 {
118   BOOLEAN  IsEnabled;
119
120   IsEnabled = TRUE;
121   IsEnabled = IsFeatureEnabled (IoCstate, PlatformConfig, StdHeader);
122
123   F15OrEarlySampleC6Support.F15OrIsC6SupportedHook (&IsEnabled, StdHeader);
124
125   return IsEnabled;
126 }
127
128 /*---------------------------------------------------------------------------------------*/
129 /**
130  *  Enable C6 on a family 15h CPU.
131  *
132  * @param[in]    C6Services         Pointer to this CPU's C6 family services.
133  * @param[in]    EntryPoint         Timepoint designator.
134  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
135  * @param[in]    StdHeader          Config Handle for library, services.
136  *
137  * @return       AGESA_SUCCESS      Always succeeds.
138  *
139  */
140 AGESA_STATUS
141 STATIC
142 F15OrInitializeC6 (
143   IN       C6_FAMILY_SERVICES *C6Services,
144   IN       UINT64 EntryPoint,
145   IN       PLATFORM_CONFIGURATION *PlatformConfig,
146   IN       AMD_CONFIG_PARAMS *StdHeader
147   )
148 {
149   UINT32   LocalPciRegister;
150   UINT32   PciMask;
151   PCI_ADDR PciAddress;
152
153   if ((EntryPoint & CPU_FEAT_AFTER_PM_INIT) != 0) {
154     // Initialize F4x118
155     // bits[24] PwrGateEnCstAct1 = 1
156     PciAddress.Address.Function = FUNC_4;
157     PciAddress.Address.Register = CSTATE_CTRL1_REG;
158     LocalPciRegister = 0x01000000;
159     PciMask = 0xFFFFFFFF;
160     OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, PciMask, LocalPciRegister, StdHeader);
161   }
162
163   return AGESA_SUCCESS;
164 }
165
166 /**
167  *  Reload microcode patch after memory is initialized.
168  *
169  * @param[in]    StdHeader          Config Handle for library, services.
170  *
171  */
172 VOID
173 F15OrReloadMicrocodePatchAfterMemInit (
174   IN       AMD_CONFIG_PARAMS *StdHeader
175   )
176 {
177   F15OrEarlySampleLoadMcuPatch.F15OrUpdateMcuPatchHook (StdHeader);
178 }
179
180 CONST C6_FAMILY_SERVICES ROMDATA F15OrC6Support =
181 {
182     0,
183     F15OrIsC6Supported,
184     F15OrInitializeC6,
185     F15OrReloadMicrocodePatchAfterMemInit
186 };