AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuFeatures.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Implement general feature dispatcher.
6  *
7  * @xrefitem bom "File Content Label" "Release Content"
8  * @e project:      AGESA
9  * @e sub-project:  CPU
10  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
11  *
12  */
13 /*
14  ******************************************************************************
15  *
16  * Copyright (C) 2012 Advanced Micro Devices, Inc.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are met:
21  *     * Redistributions of source code must retain the above copyright
22  *       notice, this list of conditions and the following disclaimer.
23  *     * Redistributions in binary form must reproduce the above copyright
24  *       notice, this list of conditions and the following disclaimer in the
25  *       documentation and/or other materials provided with the distribution.
26  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
27  *       its contributors may be used to endorse or promote products derived
28  *       from this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  ******************************************************************************
42  */
43
44 /*----------------------------------------------------------------------------------------
45  *                            M O D U L E S    U S E D
46  *----------------------------------------------------------------------------------------
47  */
48 #include "AGESA.h"
49 #include "Ids.h"
50 #include "GeneralServices.h"
51 #include "cpuFeatures.h"
52 #include "cpuFamilyTranslation.h"
53 #include "Filecode.h"
54 CODE_GROUP (G1_PEICC)
55 RDATA_GROUP (G2_PEI)
56 #define FILECODE PROC_CPU_FEATURE_CPUFEATURES_FILECODE
57 /*----------------------------------------------------------------------------------------
58  *                   D E F I N I T I O N S    A N D    M A C R O S
59  *----------------------------------------------------------------------------------------
60  */
61
62 /*----------------------------------------------------------------------------------------
63  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
64  *----------------------------------------------------------------------------------------
65  */
66
67 /*----------------------------------------------------------------------------------------
68  *           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
69  *----------------------------------------------------------------------------------------
70  */
71
72 /*----------------------------------------------------------------------------------------
73  *            E X P O R T E D    F U N C T I O N S - External General Services API
74  *----------------------------------------------------------------------------------------
75  */
76 extern CONST CPU_FEATURE_DESCRIPTOR* ROMDATA SupportedCpuFeatureList[];
77
78 /**
79  * Determines if a specific feature is or will be enabled.
80  *
81  * This code traverses the feature list until a match is
82  * found, then invokes the 'IsEnabled' function of the
83  * feature.
84  *
85  * @param[in]       Feature        Indicates the desired feature.
86  * @param[in]       PlatformConfig Contains the runtime modifiable feature input data.
87  * @param[in]       StdHeader      Standard AMD configuration parameters.
88  *
89  * @retval         TRUE      Feature is or will be enabled
90  * @retval         FALSE     Feature is not enabled
91  */
92 BOOLEAN
93 IsFeatureEnabled (
94   IN       DISPATCHABLE_CPU_FEATURES Feature,
95   IN       PLATFORM_CONFIGURATION *PlatformConfig,
96   IN       AMD_CONFIG_PARAMS *StdHeader
97   )
98 {
99   UINTN i;
100
101   ASSERT (Feature < MaxCpuFeature);
102
103   for (i = 0; SupportedCpuFeatureList[i] != NULL; i++) {
104     if (SupportedCpuFeatureList[i]->Feature == Feature) {
105       return (SupportedCpuFeatureList[i]->IsEnabled (PlatformConfig, StdHeader));
106     }
107   }
108   return FALSE;
109 }
110
111 /**
112  * Dispatches all features needing to perform some initialization at
113  * this time point.
114  *
115  * This routine searches the feature table for features needing to
116  * run at this time point, and invokes them.
117  *
118  * @param[in]      EntryPoint     Timepoint designator
119  * @param[in]      PlatformConfig Contains the runtime modifiable feature input data.
120  * @param[in]      StdHeader      Standard AMD configuration parameters.
121  *
122  * @return         The most severe status of any called service.
123  */
124 AGESA_STATUS
125 DispatchCpuFeatures (
126   IN       UINT64                 EntryPoint,
127   IN       PLATFORM_CONFIGURATION *PlatformConfig,
128   IN       AMD_CONFIG_PARAMS      *StdHeader
129   )
130 {
131   UINTN i;
132   AGESA_STATUS AgesaStatus;
133   AGESA_STATUS CalledStatus;
134   AGESA_STATUS IgnoredStatus;
135
136   AgesaStatus = AGESA_SUCCESS;
137
138   if (IsBsp (StdHeader, &IgnoredStatus)) {
139     for (i = 0; SupportedCpuFeatureList[i] != NULL; i++) {
140       if ((SupportedCpuFeatureList[i]->EntryPoint & EntryPoint) != 0) {
141         IDS_SKIP_HOOK (IDS_CPU_FEAT, (CPU_FEATURE_DESCRIPTOR *) SupportedCpuFeatureList[i], StdHeader) {
142           if (SupportedCpuFeatureList[i]->IsEnabled (PlatformConfig, StdHeader)) {
143             CalledStatus = SupportedCpuFeatureList[i]->InitializeFeature (EntryPoint, PlatformConfig, StdHeader);
144             if (CalledStatus > AgesaStatus) {
145               AgesaStatus = CalledStatus;
146             }
147           }
148         }
149       }
150     }
151   }
152   return AgesaStatus;
153 }
154
155 /**
156  * This routine checks whether any non-coherent links in the system
157  * runs in HT1 mode; used to determine whether certain features
158  * should be disabled when this routine returns TRUE.
159  *
160  * @param[in]      StdHeader  Standard AMD configuration parameters.
161  *
162  * @retval         TRUE       One of the non-coherent links in the
163  *                            system runs in HT1 mode
164  * @retval         FALSE      None of the non-coherent links in the
165  *                            system is running in HT1 mode
166  */
167 BOOLEAN
168 IsNonCoherentHt1 (
169   IN       AMD_CONFIG_PARAMS *StdHeader
170   )
171 {
172   UINTN                 Link;
173   UINT32                Socket;
174   UINT32                Module;
175   PCI_ADDR              PciAddress;
176   AGESA_STATUS          AgesaStatus;
177   HT_HOST_FEATS         HtHostFeats;
178   CPU_SPECIFIC_SERVICES *CpuServices;
179
180   for (Socket = 0; Socket < GetPlatformNumberOfSockets (); Socket++) {
181     if (IsProcessorPresent (Socket, StdHeader)) {
182       GetCpuServicesOfSocket (Socket, (const CPU_SPECIFIC_SERVICES **)&CpuServices, StdHeader);
183       for (Module = 0; Module < GetPlatformNumberOfModules (); Module++) {
184         if (GetPciAddress (StdHeader, Socket, Module, &PciAddress, &AgesaStatus)) {
185           HtHostFeats.HtHostValue = 0;
186           Link = 0;
187           while (CpuServices->GetNextHtLinkFeatures (CpuServices, &Link, &PciAddress, &HtHostFeats, StdHeader)) {
188             // Return TRUE and exit routine once we find a non-coherent link in HT1
189             if ((HtHostFeats.HtHostFeatures.NonCoherent == 1) && (HtHostFeats.HtHostFeatures.Ht1 == 1)) {
190               return TRUE;
191             }
192           }
193         }
194       }
195     }
196   }
197
198   return FALSE;
199 }