AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuIoCstate.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU IO Cstate function declarations.
6  *
7  * Contains code that declares the AGESA CPU IO Cstate related APIs
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Feature
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  */
14 /*
15  ******************************************************************************
16  *
17  * Copyright (C) 2012 Advanced Micro Devices, Inc.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are met:
22  *     * Redistributions of source code must retain the above copyright
23  *       notice, this list of conditions and the following disclaimer.
24  *     * Redistributions in binary form must reproduce the above copyright
25  *       notice, this list of conditions and the following disclaimer in the
26  *       documentation and/or other materials provided with the distribution.
27  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
28  *       its contributors may be used to endorse or promote products derived
29  *       from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  *
42  ******************************************************************************
43  */
44
45 /*----------------------------------------------------------------------------------------
46  *                             M O D U L E S    U S E D
47  *----------------------------------------------------------------------------------------
48  */
49
50 #include "AGESA.h"
51 #include "amdlib.h"
52 #include "cpuFeatures.h"
53 #include "cpuIoCstate.h"
54 #include "cpuServices.h"
55 #include "cpuFamilyTranslation.h"
56 #include "cpuApicUtilities.h"
57 #include "OptionMultiSocket.h"
58 #include "Filecode.h"
59 CODE_GROUP (G1_PEICC)
60 RDATA_GROUP (G2_PEI)
61
62 #define FILECODE PROC_CPU_FEATURE_CPUIOCSTATE_FILECODE
63
64 /*----------------------------------------------------------------------------------------
65  *                   D E F I N I T I O N S    A N D    M A C R O S
66  *----------------------------------------------------------------------------------------
67  */
68
69 /*----------------------------------------------------------------------------------------
70  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
71  *----------------------------------------------------------------------------------------
72  */
73
74 /*----------------------------------------------------------------------------------------
75  *           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
76  *----------------------------------------------------------------------------------------
77  */
78
79 VOID
80 STATIC
81 EnableIoCstateOnSocket (
82   IN       VOID *EntryPoint,
83   IN       AMD_CONFIG_PARAMS *StdHeader,
84   IN       AMD_CPU_EARLY_PARAMS *CpuEarlyParams
85   );
86 /*----------------------------------------------------------------------------------------
87  *                          E X P O R T E D    F U N C T I O N S
88  *----------------------------------------------------------------------------------------
89  */
90 extern CPU_FAMILY_SUPPORT_TABLE    IoCstateFamilyServiceTable;
91 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
92
93 /*---------------------------------------------------------------------------------------*/
94 /**
95  *  Should IO Cstate be enabled
96  *  If all processors support IO Cstate, return TRUE. Otherwise, return FALSE
97  *
98  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
99  * @param[in]    StdHeader          Config Handle for library, services.
100  *
101  * @retval       TRUE               IO Cstate is supported.
102  * @retval       FALSE              IO Cstate cannot be enabled.
103  *
104  */
105 BOOLEAN
106 STATIC
107 IsIoCstateFeatureSupported (
108   IN       PLATFORM_CONFIGURATION *PlatformConfig,
109   IN       AMD_CONFIG_PARAMS      *StdHeader
110   )
111 {
112   UINT32                    Socket;
113   BOOLEAN                   IsSupported;
114   IO_CSTATE_FAMILY_SERVICES *IoCstateServices;
115
116   IsSupported = FALSE;
117   if ((PlatformConfig->CStateIoBaseAddress != 0) && (PlatformConfig->CStateIoBaseAddress <= 0xFFF8)) {
118     for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
119       if (IsProcessorPresent (Socket, StdHeader)) {
120         GetFeatureServicesOfSocket (&IoCstateFamilyServiceTable, Socket, (CONST VOID **)&IoCstateServices, StdHeader);
121         if (IoCstateServices != NULL) {
122           if (IoCstateServices->IsIoCstateSupported (IoCstateServices, Socket, StdHeader)) {
123             IsSupported = TRUE;
124           } else {
125             // Stop checking remaining socket(s) once we find one that does not support IO Cstates
126             IsSupported = FALSE;
127             break;
128           }
129         } else {
130           // Exit the for loop if we found a socket that does not have the IO Cstates feature installed
131           IsSupported = FALSE;
132           break;
133         }
134       }
135     }
136   }
137   return IsSupported;
138 }
139
140 /*---------------------------------------------------------------------------------------*/
141 /**
142  *  Enable IO Cstate feature
143  *
144  * @param[in]    EntryPoint         Timepoint designator.
145  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
146  * @param[in]    StdHeader          Config Handle for library, services.
147  *
148  * @retval       AGESA_SUCCESS      Always succeeds.
149  *
150  */
151 AGESA_STATUS
152 STATIC
153 InitializeIoCstateFeature (
154   IN       UINT64                 EntryPoint,
155   IN       PLATFORM_CONFIGURATION *PlatformConfig,
156   IN       AMD_CONFIG_PARAMS      *StdHeader
157   )
158 {
159   AP_TASK TaskPtr;
160   AMD_CPU_EARLY_PARAMS CpuEarlyParams;
161
162   IDS_HDT_CONSOLE (CPU_TRACE, "    IO C-state is enabled\n");
163
164   CpuEarlyParams.PlatformConfig = *PlatformConfig;
165
166   TaskPtr.FuncAddress.PfApTaskIC = EnableIoCstateOnSocket;
167   TaskPtr.DataTransfer.DataSizeInDwords = 2;
168   TaskPtr.DataTransfer.DataPtr = &EntryPoint;
169   TaskPtr.DataTransfer.DataTransferFlags = 0;
170   TaskPtr.ExeFlags = PASS_EARLY_PARAMS;
171   OptionMultiSocketConfiguration.BscRunCodeOnAllSystemCore0s (&TaskPtr, StdHeader, &CpuEarlyParams);
172
173   return AGESA_SUCCESS;
174 }
175
176 /*---------------------------------------------------------------------------------------*/
177 /**
178  *  'Local' core 0 task to enable IO Cstate on it's socket.
179  *
180  * @param[in]    EntryPoint         Timepoint designator.
181  * @param[in]    StdHeader          Config Handle for library, services.
182  * @param[in]    CpuEarlyParams     Service parameters.
183  *
184  */
185 VOID
186 STATIC
187 EnableIoCstateOnSocket (
188   IN       VOID *EntryPoint,
189   IN       AMD_CONFIG_PARAMS *StdHeader,
190   IN       AMD_CPU_EARLY_PARAMS *CpuEarlyParams
191   )
192 {
193   IO_CSTATE_FAMILY_SERVICES *FamilyServices;
194
195   GetFeatureServicesOfCurrentCore (&IoCstateFamilyServiceTable, (CONST VOID **)&FamilyServices, StdHeader);
196   FamilyServices->InitializeIoCstate (FamilyServices,
197                                      *((UINT64 *) EntryPoint),
198                                      &CpuEarlyParams->PlatformConfig,
199                                      StdHeader);
200 }
201
202 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureIoCstate =
203 {
204   IoCstate,
205   (CPU_FEAT_AFTER_PM_INIT),
206   IsIoCstateFeatureSupported,
207   InitializeIoCstateFeature
208 };