Martin Roth | 7687e77 | 2023-08-22 16:32:20 -0600 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | |
Marshall Dawson | f309388 | 2016-10-15 09:45:44 -0600 | [diff] [blame] | 3 | /* $NoKeywords:$ */ |
| 4 | /** |
| 5 | * @file |
| 6 | * |
| 7 | * AMD CPU Services |
| 8 | * |
| 9 | * Related to the General Services API's, but for the CPU component. |
| 10 | * |
| 11 | * @xrefitem bom "File Content Label" "Release Content" |
| 12 | * @e project: AGESA |
| 13 | * @e sub-project: CPU |
| 14 | * @e \$Revision$ @e \$Date$ |
| 15 | * |
| 16 | */ |
| 17 | /***************************************************************************** |
| 18 | * |
| 19 | * Copyright (c) 2008 - 2016, 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 | |
Martin Roth | ae01634 | 2017-11-16 22:46:56 -0700 | [diff] [blame] | 46 | #include <check_for_wrapper.h> |
| 47 | |
Marshall Dawson | f309388 | 2016-10-15 09:45:44 -0600 | [diff] [blame] | 48 | #ifndef _CPU_SERVICES_H_ |
| 49 | #define _CPU_SERVICES_H_ |
| 50 | |
| 51 | #include "Topology.h" |
| 52 | |
| 53 | /*---------------------------------------------------------------------------------------- |
| 54 | * M I X E D (Definitions And Macros / Typedefs, Structures, Enums) |
| 55 | *---------------------------------------------------------------------------------------- |
| 56 | */ |
| 57 | |
| 58 | /*---------------------------------------------------------------------------------------- |
| 59 | * D E F I N I T I O N S A N D M A C R O S |
| 60 | *---------------------------------------------------------------------------------------- |
| 61 | */ |
| 62 | /// WARM RESET STATE_BITS |
| 63 | #define WR_STATE_COLD 00 |
| 64 | #define WR_STATE_RESET 01 |
| 65 | #define WR_STATE_EARLY 02 |
| 66 | #define WR_STATE_POST 03 |
| 67 | |
| 68 | /*---------------------------------------------------------------------------------------- |
| 69 | * T Y P E D E F S, S T R U C T U R E S, E N U M S |
| 70 | *---------------------------------------------------------------------------------------- |
| 71 | */ |
| 72 | |
| 73 | /** |
| 74 | * The role of primary core for each compute unit can be relative to the cores' launch order. |
| 75 | * |
| 76 | * One core of a compute unit is always given the role as primary. In different feature algorithms |
| 77 | * the core performing the primary core role can be designated relative to compute order. In most cases, |
| 78 | * the primary core is the first core of a compute unit to execute. However, in some cases the primary core |
| 79 | * role is associated with the last core to execute. |
| 80 | * |
| 81 | * If the launch order is strictly ascending, then first core is the lowest number and last core is highest. |
| 82 | * But if the launch order is not ascending, the first and last core follow the launch order, not the numbering order. |
| 83 | * |
| 84 | * Note that for compute units with only one core (AllCoresMapping), that core is primary for both orderings. |
| 85 | * (This includes processors without hardware compute units.) |
| 86 | * |
| 87 | */ |
| 88 | typedef enum { |
| 89 | FirstCoreIsComputeUnitPrimary, ///< the primary core role associates with the first core. |
| 90 | LastCoreIsComputeUnitPrimary, ///< the primary core role associates with the last core. |
| 91 | MaxComputeUnitPrimarySelector, ///< limit check. |
| 92 | } COMPUTE_UNIT_PRIMARY_SELECTOR; |
| 93 | |
| 94 | /** |
| 95 | * The supported Core to Compute unit mappings. |
| 96 | */ |
| 97 | typedef enum { |
| 98 | AllCoresMapping, ///< All Cores are primary cores |
| 99 | EvenCoresMapping, ///< Compute units are even/odd core pairs. |
| 100 | TripleCoresMapping, ///< Compute units has three cores enabled. |
| 101 | QuadCoresMapping, ///< Compute units has four cores enabled. |
| 102 | BitMapMapping, ///< Currently not supported by any family, arbitrary core |
| 103 | ///< to compute unit mapping. |
| 104 | MaxComputeUnitMapping ///< Not a mapping, use for limit check. |
| 105 | } COMPUTE_UNIT_MAPPING; |
| 106 | |
| 107 | /** |
| 108 | * Compute unit status register. |
| 109 | */ |
| 110 | |
| 111 | /** |
| 112 | * Compute Unit Map entry. |
| 113 | * Provide for interpreting the core pairing for the processor's compute units. |
| 114 | * |
| 115 | * HT_LIST_TERMINAL as an Enabled value means the end of a list of map structs. |
| 116 | * Zero as an Enabled value implies Compute Units are not supported by the processor |
| 117 | * and the mapping is assumed to be AllCoresMapping. |
| 118 | * |
| 119 | */ |
| 120 | typedef struct { |
| 121 | UINT8 Enabled; ///< The value of the Enabled Compute Units |
| 122 | UINT8 DualCore; ///< The value of the Dual Core Compute Units |
| 123 | UINT8 TripleCore; ///< the value of the Triple Core Compute Units |
| 124 | UINT8 QuadCore; ///< the value of the Quad Core Compute Units |
| 125 | COMPUTE_UNIT_MAPPING Mapping; ///< When the processor module matches these values, use this mapping method. |
| 126 | } COMPUTE_UNIT_MAP; |
| 127 | |
| 128 | //---------------------------------------------------------------------------- |
| 129 | // CPU SYSTEM INFO TYPEDEFS, STRUCTURES, ENUMS |
| 130 | // |
| 131 | //---------------------------------------------------------------------------- |
| 132 | /// SYSTEM INFO |
| 133 | typedef struct _SYSTEM_INFO { |
| 134 | UINT32 TotalNumberOfSockets; ///< Total Number of Sockets |
| 135 | UINT32 TotalNumberOfCores; ///< Total Number Of Cores |
| 136 | UINT32 CurrentSocketNum; ///< Current Socket Number |
| 137 | UINT32 CurrentCoreNum; ///< Current Core Number |
| 138 | UINT32 CurrentCoreApicId; ///< Current Core Apic ID |
| 139 | UINT32 CurrentLogicalCpuId; ///< Current Logical CPU ID |
| 140 | } SYSTEM_INFO; |
| 141 | |
| 142 | /// WARM_RESET_REQUEST |
| 143 | typedef struct _WARM_RESET_REQUEST { |
| 144 | UINT8 RequestBit:1; ///< Request Bit |
| 145 | UINT8 StateBits:2; ///< State Bits |
| 146 | UINT8 PostStage:2; ///< Post Stage |
| 147 | UINT8 Reserved:(8 - 5); ///< Reserved |
| 148 | } WARM_RESET_REQUEST; |
| 149 | /*---------------------------------------------------------------------------------------- |
| 150 | * F U N C T I O N P R O T O T Y P E |
| 151 | *---------------------------------------------------------------------------------------- |
| 152 | */ |
| 153 | |
| 154 | /** |
| 155 | * Get the current Platform's number of Sockets, regardless of how many are populated. |
| 156 | * |
| 157 | */ |
| 158 | UINT32 |
| 159 | GetPlatformNumberOfSockets ( VOID ); |
| 160 | |
| 161 | /** |
| 162 | * Get the number of Modules to check presence in each Processor. |
| 163 | * |
| 164 | */ |
| 165 | UINT32 |
| 166 | GetPlatformNumberOfModules ( VOID ); |
| 167 | |
| 168 | BOOLEAN |
| 169 | IsProcessorPresent ( |
| 170 | IN UINT32 Socket, |
| 171 | IN AMD_CONFIG_PARAMS *StdHeader |
| 172 | ); |
| 173 | |
| 174 | /** |
| 175 | * For a specific Node, get its Socket and Module ids. |
| 176 | * |
| 177 | */ |
| 178 | BOOLEAN |
| 179 | GetSocketModuleOfNode ( |
| 180 | IN UINT32 Node, |
| 181 | OUT UINT32 *Socket, |
| 182 | OUT UINT32 *Module, |
| 183 | IN AMD_CONFIG_PARAMS *StdHeader |
| 184 | ); |
| 185 | |
| 186 | /** |
| 187 | * Get the current core's Processor APIC Index. |
| 188 | */ |
| 189 | UINT32 |
| 190 | GetProcessorApicIndex ( |
| 191 | IN UINT32 Node, |
| 192 | IN AMD_CONFIG_PARAMS *StdHeader |
| 193 | ); |
| 194 | |
| 195 | /** |
| 196 | * Provide the number of installed processors (not Nodes! and not Sockets!) |
| 197 | */ |
| 198 | UINT32 |
| 199 | GetNumberOfProcessors ( |
| 200 | IN AMD_CONFIG_PARAMS *StdHeader |
| 201 | ); |
| 202 | |
| 203 | VOID |
| 204 | GetActiveCoresInCurrentSocket ( |
| 205 | OUT UINT32 *CoreCount, |
| 206 | IN AMD_CONFIG_PARAMS *StdHeader |
| 207 | ); |
| 208 | |
| 209 | UINTN |
| 210 | GetActiveCoresInCurrentModule ( |
| 211 | IN AMD_CONFIG_PARAMS *StdHeader |
| 212 | ); |
| 213 | |
| 214 | UINTN |
| 215 | GetNumberOfCompUnitsInCurrentModule ( |
| 216 | IN AMD_CONFIG_PARAMS *StdHeader |
| 217 | ); |
| 218 | |
| 219 | BOOLEAN |
| 220 | GetGivenModuleCoreRange ( |
| 221 | IN UINT32 Socket, |
| 222 | IN UINT32 Module, |
| 223 | OUT UINT32 *LowCore, |
| 224 | OUT UINT32 *HighCore, |
| 225 | IN AMD_CONFIG_PARAMS *StdHeader |
| 226 | ); |
| 227 | |
| 228 | VOID |
| 229 | GetCurrentCore ( |
| 230 | OUT UINT32 *Core, |
| 231 | IN AMD_CONFIG_PARAMS *StdHeader |
| 232 | ); |
| 233 | |
| 234 | VOID |
| 235 | GetCurrentNodeAndCore ( |
| 236 | OUT UINT32 *Node, |
| 237 | OUT UINT32 *Core, |
| 238 | IN AMD_CONFIG_PARAMS *StdHeader |
| 239 | ); |
| 240 | |
| 241 | BOOLEAN |
| 242 | IsCurrentCorePrimary ( |
| 243 | IN AMD_CONFIG_PARAMS *StdHeader |
| 244 | ); |
| 245 | |
| 246 | |
| 247 | BOOLEAN |
| 248 | GetNodeId ( |
| 249 | IN UINT32 SocketId, |
| 250 | IN UINT32 ModuleId, |
| 251 | OUT UINT8 *NodeId, |
| 252 | IN AMD_CONFIG_PARAMS *StdHeader |
| 253 | ); |
| 254 | |
| 255 | VOID |
| 256 | WaitMicroseconds ( |
| 257 | IN UINT32 Microseconds, |
| 258 | IN AMD_CONFIG_PARAMS *StdHeader |
| 259 | ); |
| 260 | |
| 261 | /** |
| 262 | * Get the compute unit mapping algorithm. |
| 263 | */ |
| 264 | COMPUTE_UNIT_MAPPING |
| 265 | GetComputeUnitMapping ( |
| 266 | IN AMD_CONFIG_PARAMS *StdHeader |
| 267 | ); |
| 268 | |
| 269 | /** |
| 270 | * Does the current core have the role of primary core for the compute unit? |
| 271 | */ |
| 272 | BOOLEAN |
| 273 | IsCoreComputeUnitPrimary ( |
| 274 | IN COMPUTE_UNIT_PRIMARY_SELECTOR Selector, |
| 275 | IN AMD_CONFIG_PARAMS *StdHeader |
| 276 | ); |
| 277 | |
| 278 | VOID |
| 279 | SetWarmResetFlag ( |
| 280 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 281 | IN WARM_RESET_REQUEST *Request |
| 282 | ); |
| 283 | |
| 284 | VOID |
| 285 | GetWarmResetFlag ( |
| 286 | IN AMD_CONFIG_PARAMS *StdHeader, |
| 287 | OUT WARM_RESET_REQUEST *Request |
| 288 | ); |
| 289 | |
| 290 | BOOLEAN |
| 291 | IsWarmReset ( |
| 292 | IN AMD_CONFIG_PARAMS *StdHeader |
| 293 | ); |
| 294 | |
| 295 | AGESA_STATUS |
| 296 | CheckBistStatus ( |
| 297 | IN AMD_CONFIG_PARAMS *StdHeader |
| 298 | ); |
| 299 | |
| 300 | VOID |
| 301 | SetWarmResetAtEarly ( |
| 302 | IN UINT32 Data, |
| 303 | IN AMD_CONFIG_PARAMS *StdHeader |
| 304 | ); |
| 305 | |
| 306 | #ifndef CPU_DEADLOOP |
| 307 | #define CPU_DEADLOOP() { volatile UINTN __i; __i = 1; while (__i); } |
| 308 | #endif |
| 309 | |
| 310 | #endif // _CPU_SERVICES_H_ |