5 * Generic CPU feature dispatcher and related services.
7 * Provides a feature processing engine to handle feature in a
10 * @xrefitem bom "File Content Label" "Release Content"
12 * @e sub-project: Common
13 * @e \$Revision: 54493 $ @e \$Date: 2011-06-08 15:21:06 -0600 (Wed, 08 Jun 2011) $
17 ******************************************************************************
19 * Copyright (C) 2012 Advanced Micro Devices, Inc.
20 * All rights reserved.
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.
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.
44 ******************************************************************************
47 #ifndef _CPU_FEATURES_H_
48 #define _CPU_FEATURES_H_
51 * @page cpufeatimpl CPU Generic Feature Implementation Guide
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.
57 * @par Determine if a New Feature is a Suitable Candidate
59 * A feature must meet the following requirements:
61 * <li> Any core in the system must be able to determine if the feature should be enabled or not.
64 * <li> MSRs cannot be read in multisocket systems in the 'IsEnabled' function.
66 * <li> Cores cannot be launched in the 'IsEnabled' function.
70 * @par Determine the Time Point at which the Feature Should be Enabled
72 * Factors to consider in making this determination:
75 * <li> Determine if there are any dependencies on other settings that require strict ordering.
77 * <li> Consider the state of the APs that you will need.
79 * <li> Remember that features enabled during AmdInitEarly will automatically be restored on S3 resume.
82 * @par Implementing a new feature
84 * Perform the following steps to implement a new feature:
87 * <li> Create a unique equate for your time point, @b if you cannot use an existing time point.
89 * <li> Create a new value in the DISPATCHABLE_CPU_FEATURES enum for your feature.
91 * <li> Add a new 'C' file to the Features folder for your feature.
94 * <li> The 'C' file must implement 2 functions -- 'IsEnabled' and 'Initialize'
96 * <li> The 'C' file must instantiate a CPU_FEATURE_DESCRIPTOR structure.
99 * <li> Add a new 'H' file to the Features folder for your feature.
102 * <li> The 'H' file declares whatever family specific functions required by the feature.
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,
109 * <li> Create 'C' files in all applicable family folders.
112 * <li> Implement the required family specific functions.
114 * <li> Instantiate a family specific services structure.
117 * <li> Create \<feature name\>Install.h in the include folder.
120 * <li> Add logic to determine when your feature should be included in the build.
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.
125 * <li> Create a family translation table pointing to all applicable instantiations of
126 * family specific function structures.
129 * <li> Modify OptionCpuFeaturesInstall.h in the include folder.
132 * <li> Include \<feature name\>Install.h.
134 * <li> Add OPTION_\<feature name\> to the SupportedCpuFeatureList array.
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.
144 /*----------------------------------------------------------------------------------------
145 * M I X E D (Definitions And Macros / Typedefs, Structures, Enums)
146 *----------------------------------------------------------------------------------------
149 /*----------------------------------------------------------------------------------------
150 * D E F I N I T I O N S A N D M A C R O S
151 *----------------------------------------------------------------------------------------
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 *----------------------------------------------------------------------------------------
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)
168 * Enumerated list of supported features.
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;
187 /*---------------------------------------------------------------------------------------*/
189 * Feature specific call to check if it is supported by the system.
191 * @param[in] PlatformConfig Contains the runtime modifiable feature input data.
192 * @param[in] StdHeader Config Handle for library, services.
194 * @retval TRUE Feature is supported.
195 * @retval FALSE Feature is not supported.
198 typedef BOOLEAN F_CPU_FEATURE_IS_ENABLED (
199 IN PLATFORM_CONFIGURATION *PlatformConfig,
200 IN AMD_CONFIG_PARAMS *StdHeader
203 /// Reference to a Method.
204 typedef F_CPU_FEATURE_IS_ENABLED *PF_CPU_FEATURE_IS_ENABLED;
206 /*---------------------------------------------------------------------------------------*/
208 * The feature's main entry point for enablement.
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.
214 * @return Family specific error value.
217 typedef AGESA_STATUS F_CPU_FEATURE_INITIALIZE (
218 IN UINT64 EntryPoint,
219 IN PLATFORM_CONFIGURATION *PlatformConfig,
220 IN AMD_CONFIG_PARAMS *StdHeader
223 /// Reference to a Method.
224 typedef F_CPU_FEATURE_INITIALIZE *PF_CPU_FEATURE_INITIALIZE;
228 * Generic feature descriptor
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;
238 * Table descriptor for the installed features.
241 UINT8 NumberOfFeats; ///< Number of valid entries in the table.
242 CPU_FEATURE_DESCRIPTOR *FeatureList; ///< Pointer to the first element in the array.
245 /*----------------------------------------------------------------------------------------
246 * F U N C T I O N P R O T O T Y P E
247 *----------------------------------------------------------------------------------------
252 IN DISPATCHABLE_CPU_FEATURES Feature,
253 IN PLATFORM_CONFIGURATION *PlatformConfig,
254 IN AMD_CONFIG_PARAMS *StdHeader
258 DispatchCpuFeatures (
259 IN UINT64 EntryPoint,
260 IN PLATFORM_CONFIGURATION *PlatformConfig,
261 IN AMD_CONFIG_PARAMS *StdHeader
266 IN AMD_CONFIG_PARAMS *StdHeader
269 #endif // _CPU_FEATURES_H_