AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x15 / cpuF15BrandId.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU BrandId related functions and structures.
6  *
7  * Contains code that provides CPU BrandId information
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Family/0x15
12  * @e \$Revision: 55600 $   @e \$Date: 2011-06-23 12:39:18 -0600 (Thu, 23 Jun 2011) $
13  *
14  */
15 /*
16  ******************************************************************************
17  *
18  * Copyright (C) 2012 Advanced Micro Devices, Inc.
19  * All rights reserved.
20  *
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.
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
30  *       from this software without specific prior written permission.
31  *
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.
42  *
43  ******************************************************************************
44  */
45
46 /*----------------------------------------------------------------------------------------
47  *                             M O D U L E S    U S E D
48  *----------------------------------------------------------------------------------------
49  */
50 #include "AGESA.h"
51 #include "amdlib.h"
52 #include "cpuRegisters.h"
53 #include "cpuFamilyTranslation.h"
54 #include "cpuEarlyInit.h"
55 #include "cpuServices.h"
56 #include "GeneralServices.h"
57 #include "OptionMultiSocket.h"
58 #include "Filecode.h"
59 CODE_GROUP (G3_DXE)
60 RDATA_GROUP (G3_DXE)
61
62 #define FILECODE PROC_CPU_FAMILY_0X15_CPUF15BRANDID_FILECODE
63
64
65 /*----------------------------------------------------------------------------------------
66  *                   D E F I N I T I O N S    A N D    M A C R O S
67  *----------------------------------------------------------------------------------------
68  */
69 #define NAME_STRING_ADDRESS_PORT 0x194
70 #define NAME_STRING_DATA_PORT 0x198
71
72 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
73 /*----------------------------------------------------------------------------------------
74  *                  T Y P E D E F S     A N D     S T R U C T U R E S
75  *----------------------------------------------------------------------------------------
76  */
77 /// A structure containing brand string
78 typedef struct {
79   CONST CHAR8 *Stringstart;  ///< The literal string
80 } CPU_F15_EXCEPTION_BRAND;
81
82 /// FAM15_BRAND_STRING_MSR
83 typedef struct _PROCESSOR_NAME_STRING {
84   UINT32 lo;                 ///< lower 32-bits of 64-bit value
85   UINT32 hi;                 ///< highest 32-bits of 64-bit value
86 } PROCESSOR_NAME_STRING;
87
88 /*----------------------------------------------------------------------------------------
89  *           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
90  *----------------------------------------------------------------------------------------
91  */
92 BOOLEAN
93 STATIC
94 IsException (
95      OUT   UINT32             *ExceptionId,
96   IN       AMD_CONFIG_PARAMS      *StdHeader
97   );
98
99 VOID
100 F15SetBrandIdRegistersAtEarly (
101   IN       CPU_SPECIFIC_SERVICES  *FamilyServices,
102   IN       AMD_CPU_EARLY_PARAMS   *EarlyParams,
103   IN       AMD_CONFIG_PARAMS      *StdHeader
104   );
105 /*----------------------------------------------------------------------------------------
106  *                          E X P O R T E D    F U N C T I O N S
107  *----------------------------------------------------------------------------------------
108  */
109 // This is an example, need to be updated once Processor Revision Guide define brand string exception
110 // Brand string is always 48 bytes
111 CONST CHAR8 ROMDATA str_Exception_0[48] = "AMD Phenom(tm) Octal-Core";
112 CONST CHAR8 ROMDATA str_Unprogrammed_Sample[48] = "AMD Unprogrammed Engineering Sample";
113 /*---------------------------------------------------------------------------------------
114  *               T Y P E D E F S,   S T R U C T U R E S,    E N U M S
115  *---------------------------------------------------------------------------------------
116  */
117 CONST CPU_F15_EXCEPTION_BRAND ROMDATA CpuF15ExceptionBrandIdString[] =
118 {
119   {str_Exception_0}
120 };
121
122 /*---------------------------------------------------------------------------------------*/
123 /**
124  * Set the Processor Name String register based on F5x194/198
125  *
126  * This function copies F5x198_x[B:0] to MSR_C001_00[35:30]
127  *
128  *  @param[in]   FamilyServices      The current Family Specific Services.
129  *  @param[in]   EarlyParams         Service parameters.
130  *  @param[in]   StdHeader           Config handle for library and services.
131  *
132  */
133 VOID
134 F15SetBrandIdRegistersAtEarly (
135   IN       CPU_SPECIFIC_SERVICES  *FamilyServices,
136   IN       AMD_CPU_EARLY_PARAMS   *EarlyParams,
137   IN       AMD_CONFIG_PARAMS      *StdHeader
138   )
139 {
140   UINT32 PciData;
141   UINT32 ExceptionId;
142   UINT32 MsrIndex;
143   UINT64 MsrData;
144   UINT64 *MsrNameStringPtrPtr;
145   PCI_ADDR PciAddress;
146
147   if (IsCorePairPrimary (FirstCoreIsComputeUnitPrimary, StdHeader)) {
148     if (IsException (&ExceptionId, StdHeader)) {
149       ASSERT (ExceptionId < (sizeof (CpuF15ExceptionBrandIdString) / sizeof (CpuF15ExceptionBrandIdString[0])));
150
151       MsrNameStringPtrPtr = (UINT64 *) CpuF15ExceptionBrandIdString[ExceptionId].Stringstart;
152     } else {
153       OptionMultiSocketConfiguration.GetCurrPciAddr (&PciAddress, StdHeader);
154       PciAddress.Address.Function = FUNC_5;
155       PciAddress.Address.Register = NAME_STRING_ADDRESS_PORT;
156       // check if D18F5x198_x0 is 00000000h.
157       PciData = 0;
158       LibAmdPciWrite (AccessWidth32, PciAddress, &PciData, StdHeader);
159       PciAddress.Address.Register = NAME_STRING_DATA_PORT;
160       LibAmdPciRead (AccessWidth32, PciAddress, &PciData, StdHeader);
161       if (PciData != 0) {
162         for (MsrIndex = 0; MsrIndex <= (MSR_CPUID_NAME_STRING5 - MSR_CPUID_NAME_STRING0); MsrIndex++) {
163           PciAddress.Address.Register = NAME_STRING_ADDRESS_PORT;
164           PciData = MsrIndex * 2;
165           LibAmdPciWrite (AccessWidth32, PciAddress, &PciData, StdHeader);
166           PciAddress.Address.Register = NAME_STRING_DATA_PORT;
167           LibAmdPciRead (AccessWidth32, PciAddress, &PciData, StdHeader);
168           ((PROCESSOR_NAME_STRING *) (&MsrData))->lo = PciData;
169
170           PciAddress.Address.Register = NAME_STRING_ADDRESS_PORT;
171           PciData = (MsrIndex * 2) + 1;
172           LibAmdPciWrite (AccessWidth32, PciAddress, &PciData, StdHeader);
173           PciAddress.Address.Register = NAME_STRING_DATA_PORT;
174           LibAmdPciRead (AccessWidth32, PciAddress, &PciData, StdHeader);
175           ((PROCESSOR_NAME_STRING *) (&MsrData))->hi = PciData;
176
177           LibAmdMsrWrite ((MsrIndex + MSR_CPUID_NAME_STRING0), &MsrData, StdHeader);
178         }
179         return;
180       } else {
181         // It is unprogrammed (unfused) parts and use a name string of "AMD Unprogrammed Engineering Sample"
182         MsrNameStringPtrPtr = (UINT64 *) str_Unprogrammed_Sample;
183       }
184     }
185     // Put values into name MSRs,  Always write the full 48 bytes
186     for (MsrIndex = MSR_CPUID_NAME_STRING0; MsrIndex <= MSR_CPUID_NAME_STRING5; MsrIndex++) {
187       LibAmdMsrWrite (MsrIndex, MsrNameStringPtrPtr, StdHeader);
188       MsrNameStringPtrPtr++;
189     }
190   }
191 }
192
193 /*---------------------------------------------------------------------------------------
194  *                          L O C A L    F U N C T I O N S
195  *---------------------------------------------------------------------------------------
196  */
197
198 /*---------------------------------------------------------------------------------------*/
199 /**
200  * Check if it's an exception
201  *
202  * For family 15h, brand string is obtained from F5x198_x[B:0], but there may be exceptions.
203  * This function checks if it's an exception.
204  *
205  *  @param[out]  ExceptionId         Id of exception
206  *  @param[in]   StdHeader           Config handle for library and services.
207  *
208  *  @retval      TRUE                It's an exception
209  *  @retval      FALSE               It's NOT an exception
210  */
211 BOOLEAN
212 STATIC
213 IsException (
214      OUT   UINT32                 *ExceptionId,
215   IN       AMD_CONFIG_PARAMS      *StdHeader
216   )
217 {
218   // This function will be updated, once Processor Revision Guide defines Fam15 brand string exception
219   *ExceptionId = 0xFFFF;
220
221   return FALSE;
222 }
223