AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuFeatures.h
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Generic CPU feature dispatcher and related services.
6  *
7  * Provides a feature processing engine to handle feature in a
8  * more generic way.
9  *
10  * @xrefitem bom "File Content Label" "Release Content"
11  * @e project:      AGESA
12  * @e sub-project:  Common
13  * @e \$Revision: 54493 $   @e \$Date: 2011-06-08 15:21:06 -0600 (Wed, 08 Jun 2011) $
14  *
15  */
16 /*
17  ******************************************************************************
18  *
19  * Copyright (C) 2012 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 #ifndef _CPU_FEATURES_H_
48 #define _CPU_FEATURES_H_
49
50 /**
51  * @page cpufeatimpl CPU Generic Feature Implementation Guide
52  *
53  * The CPU generic feature dispatcher provides services which can be used to implement a
54  * wide range of features in a manner that isolates calling code from knowledge about which
55  * families or features are supported in the current build.
56  *
57  * @par Determine if a New Feature is a Suitable Candidate
58  *
59  * A feature must meet the following requirements:
60  * <ul>
61  * <li> Any core in the system must be able to determine if the feature should be enabled or not.
62  *
63  *   <ul>
64  *   <li> MSRs cannot be read in multisocket systems in the 'IsEnabled' function.
65  *
66  *   <li> Cores cannot be launched in the 'IsEnabled' function.
67  *   </ul>
68  * </ul>
69  *
70  * @par Determine the Time Point at which the Feature Should be Enabled
71  *
72  * Factors to consider in making this determination:
73  *
74  * <ul>
75  * <li> Determine if there are any dependencies on other settings that require strict ordering.
76  *
77  * <li> Consider the state of the APs that you will need.
78  *
79  * <li> Remember that features enabled during AmdInitEarly will automatically be restored on S3 resume.
80  * </ul>
81  *
82  * @par Implementing a new feature
83  *
84  * Perform the following steps to implement a new feature:
85  *
86  * <ul>
87  * <li> Create a unique equate for your time point, @b if you cannot use an existing time point.
88  *
89  * <li> Create a new value in the DISPATCHABLE_CPU_FEATURES enum for your feature.
90  *
91  * <li> Add a new 'C' file to the Features folder for your feature.
92  *
93  *   <ul>
94  *   <li> The 'C' file must implement 2 functions -- 'IsEnabled' and 'Initialize'
95  *
96  *   <li> The 'C' file must instantiate a CPU_FEATURE_DESCRIPTOR structure.
97  *   </ul>
98  *
99  * <li> Add a new 'H' file to the Features folder for your feature.
100  *
101  *   <ul>
102  *   <li> The 'H' file declares whatever family specific functions required by the feature.
103  *
104  *   <li> The 'H' file declares a structure containing all family specific functions.  For a reference
105  *        example, your feature API should have a set of conventions similar to cpu specific services,
106  *        @ref cpuimplfss.
107  *   </ul>
108  *
109  * <li> Create 'C' files in all applicable family folders.
110  *
111  *   <ul>
112  *   <li> Implement the required family specific functions.
113  *
114  *   <li> Instantiate a family specific services structure.
115  *   </ul>
116  *
117  * <li> Create \<feature name\>Install.h in the include folder.
118  *
119  *   <ul>
120  *   <li> Add logic to determine when your feature should be included in the build.
121  *
122  *   <li> If the feature should be included, define OPTION_\<feature name\> to the address of your
123  *        CPU_FEATURE_DESCRIPTOR instantiation.  If not, define OPTION_\<feature name\> to be blank.
124  *
125  *   <li> Create a family translation table pointing to all applicable instantiations of
126  *        family specific function structures.
127  *   </ul>
128  *
129  * <li> Modify OptionCpuFeaturesInstall.h in the include folder.
130  *
131  *   <ul>
132  *   <li> Include \<feature name\>Install.h.
133  *
134  *   <li> Add OPTION_\<feature name\> to the SupportedCpuFeatureList array.
135  *   </ul>
136  *
137  * <li> If a new time point was created, add a call to DispatchCpuFeatures at the desired location,
138  *      passing your new time point equate.
139  * </ul>
140  *
141  */
142
143
144 /*----------------------------------------------------------------------------------------
145  *          M I X E D   (Definitions And Macros / Typedefs, Structures, Enums)
146  *----------------------------------------------------------------------------------------
147  */
148
149 /*----------------------------------------------------------------------------------------
150  *                 D E F I N I T I O N S     A N D     M A C R O S
151  *----------------------------------------------------------------------------------------
152  */
153
154 /*----------------------------------------------------------------------------------------
155  *               T Y P E D E F S,   S T R U C T U R E S,    E N U M S
156  *----------------------------------------------------------------------------------------
157  */
158 #define CPU_FEAT_BEFORE_PM_INIT           (0x0000000000000001ull)
159 #define CPU_FEAT_AFTER_PM_INIT            (0x0000000000000002ull)
160 #define CPU_FEAT_AFTER_POST_MTRR_SYNC     (0x0000000000000004ull)
161 #define CPU_FEAT_INIT_MID_END             (0x0000000000000008ull)
162 #define CPU_FEAT_INIT_LATE_END            (0x0000000000000010ull)
163 #define CPU_FEAT_S3_LATE_RESTORE_END      (0x0000000000000020ull)
164 #define CPU_FEAT_AFTER_RESUME_MTRR_SYNC   (0x0000000000000040ull)
165 #define CPU_FEAT_AFTER_COHERENT_DISCOVERY (0x0000000000000080ull)
166 #define CPU_FEAT_BEFORE_RELINQUISH_AP     (0x0000000000000100ull)
167 /**
168  * Enumerated list of supported features.
169  */
170 typedef enum {
171   HardwareC1e,               ///< Hardware C1e
172   L3Features,                ///< L3 dependent features
173   MsgBasedC1e,               ///< Message-based C1e
174   SoftwareC1e,               ///< Software C1e
175   CoreLeveling,              ///< Core Leveling
176   C6Cstate,                  ///< C6 C-state
177   IoCstate,                  ///< IO C-state
178   CacheFlushOnHalt,          ///< Cache Flush On Halt
179   PreserveAroundMailbox,     ///< Save-Restore the registers used for AP mailbox, to preserve their normal function.
180   CoreBoost,                 ///< Core Performance Boost (CPB)
181   LowPwrPstate,              ///< 500 MHz Low Power P-state
182   PstateHpcMode,             ///< High performance computing mode
183   CpuApm,                    ///< Application Power Management
184   MaxCpuFeature              ///< Not a valid value, used for verifying input
185 } DISPATCHABLE_CPU_FEATURES;
186
187 /*---------------------------------------------------------------------------------------*/
188 /**
189  *  Feature specific call to check if it is supported by the system.
190  *
191  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
192  * @param[in]    StdHeader          Config Handle for library, services.
193  *
194  * @retval       TRUE               Feature is supported.
195  * @retval       FALSE              Feature is not supported.
196  *
197  */
198 typedef BOOLEAN F_CPU_FEATURE_IS_ENABLED (
199   IN       PLATFORM_CONFIGURATION *PlatformConfig,
200   IN       AMD_CONFIG_PARAMS      *StdHeader
201   );
202
203 /// Reference to a Method.
204 typedef F_CPU_FEATURE_IS_ENABLED *PF_CPU_FEATURE_IS_ENABLED;
205
206 /*---------------------------------------------------------------------------------------*/
207 /**
208  *  The feature's main entry point for enablement.
209  *
210  * @param[in]    EntryPoint         Timepoint designator.
211  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
212  * @param[in]    StdHeader          Config Handle for library, services.
213  *
214  * @return       Family specific error value.
215  *
216  */
217 typedef AGESA_STATUS F_CPU_FEATURE_INITIALIZE (
218   IN       UINT64                 EntryPoint,
219   IN       PLATFORM_CONFIGURATION *PlatformConfig,
220   IN       AMD_CONFIG_PARAMS      *StdHeader
221   );
222
223 /// Reference to a Method.
224 typedef F_CPU_FEATURE_INITIALIZE *PF_CPU_FEATURE_INITIALIZE;
225
226
227 /**
228  * Generic feature descriptor
229  */
230 typedef struct {
231   DISPATCHABLE_CPU_FEATURES Feature;     ///< Enumerated feature ID
232   UINT64                    EntryPoint;  ///< Timepoint designator
233   PF_CPU_FEATURE_IS_ENABLED IsEnabled;   ///< Pointer to the function that checks if the feature is supported
234   PF_CPU_FEATURE_INITIALIZE InitializeFeature; ///< Pointer to the function that enables the feature
235 } CPU_FEATURE_DESCRIPTOR;
236
237 /**
238  * Table descriptor for the installed features.
239  */
240 typedef struct {
241   UINT8       NumberOfFeats;      ///< Number of valid entries in the table.
242   CPU_FEATURE_DESCRIPTOR *FeatureList;       ///< Pointer to the first element in the array.
243 } CPU_FEATURE_TABLE;
244
245 /*----------------------------------------------------------------------------------------
246  *                        F U N C T I O N    P R O T O T Y P E
247  *----------------------------------------------------------------------------------------
248  */
249
250 BOOLEAN
251 IsFeatureEnabled (
252   IN       DISPATCHABLE_CPU_FEATURES Feature,
253   IN       PLATFORM_CONFIGURATION *PlatformConfig,
254   IN       AMD_CONFIG_PARAMS *StdHeader
255   );
256
257 AGESA_STATUS
258 DispatchCpuFeatures (
259   IN       UINT64                 EntryPoint,
260   IN       PLATFORM_CONFIGURATION *PlatformConfig,
261   IN       AMD_CONFIG_PARAMS      *StdHeader
262   );
263
264 BOOLEAN
265 IsNonCoherentHt1 (
266   IN       AMD_CONFIG_PARAMS *StdHeader
267   );
268
269 #endif // _CPU_FEATURES_H_