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