AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuSwC1e.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU SW C1e feature support code.
6  *
7  * Contains code that declares the AGESA CPU C1e related APIs
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Feature
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 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 "Ids.h"
53 #include "cpuRegisters.h"
54 #include "cpuApicUtilities.h"
55 #include "cpuServices.h"
56 #include "GeneralServices.h"
57 #include "cpuFamilyTranslation.h"
58 #include "Topology.h"
59 #include "cpuFeatures.h"
60 #include "cpuSwC1e.h"
61 #include "Filecode.h"
62 CODE_GROUP (G1_PEICC)
63 RDATA_GROUP (G2_PEI)
64
65 #define FILECODE PROC_CPU_FEATURE_CPUSWC1E_FILECODE
66 /*----------------------------------------------------------------------------------------
67  *                   D E F I N I T I O N S    A N D    M A C R O S
68  *----------------------------------------------------------------------------------------
69  */
70
71 /*----------------------------------------------------------------------------------------
72  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
73  *----------------------------------------------------------------------------------------
74  */
75
76 /*----------------------------------------------------------------------------------------
77  *           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
78  *----------------------------------------------------------------------------------------
79  */
80
81 /*----------------------------------------------------------------------------------------
82  *                          E X P O R T E D    F U N C T I O N S
83  *----------------------------------------------------------------------------------------
84  */
85 extern CPU_FAMILY_SUPPORT_TABLE SwC1eFamilyServiceTable;
86
87 /*---------------------------------------------------------------------------------------*/
88 /**
89  *  Should software C1e be enabled
90  *
91  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
92  * @param[in]    StdHeader          Config Handle for library, services.
93  *
94  * @retval       TRUE               SW C1e is supported.
95  * @retval       FALSE              SW C1e not supported.
96  *
97  */
98 BOOLEAN
99 STATIC
100 IsSwC1eFeatureEnabled (
101   IN       PLATFORM_CONFIGURATION *PlatformConfig,
102   IN       AMD_CONFIG_PARAMS      *StdHeader
103   )
104 {
105   BOOLEAN                IsEnabled;
106   BOOLEAN                IsOtherC1eEnabled;
107   AP_MAILBOXES           ApMailboxes;
108   SW_C1E_FAMILY_SERVICES *SwFamilyServices;
109
110   ASSERT (PlatformConfig->C1eMode < MaxC1eMode);
111   IsEnabled = FALSE;
112
113   // Check whether software C1e is enabled only if other C1e methods is/are not supported
114   // or if the platform specifically uses C1eModeSoftwareDeprecated.
115   IsOtherC1eEnabled = (IsFeatureEnabled (HardwareC1e, PlatformConfig, StdHeader) ||
116                        IsFeatureEnabled (MsgBasedC1e, PlatformConfig, StdHeader));
117   if ((PlatformConfig->C1eMode == C1eModeSoftwareDeprecated) ||
118      ((!IsOtherC1eEnabled) && ((PlatformConfig->C1eMode == C1eModeHardwareSoftwareDeprecated) || (PlatformConfig->C1eMode == C1eModeAuto)))) {
119     ASSERT ((PlatformConfig->C1ePlatformData1 < 0x10000) && (PlatformConfig->C1ePlatformData1 != 0));
120     ASSERT (PlatformConfig->C1ePlatformData2 < 0x100);
121     if ((PlatformConfig->C1ePlatformData1 != 0) && (PlatformConfig->C1ePlatformData1 < 0xFFFE) && (PlatformConfig->C1ePlatformData2 < 0xFF)) {
122       if (!IsNonCoherentHt1 (StdHeader)) {
123         if (GetNumberOfProcessors (StdHeader) == 1) {
124           GetApMailbox (&ApMailboxes.ApMailInfo.Info, StdHeader);
125           if (ApMailboxes.ApMailInfo.Fields.ModuleType == 0) {
126             GetFeatureServicesOfCurrentCore (&SwC1eFamilyServiceTable, (CONST VOID **)&SwFamilyServices, StdHeader);
127             if (SwFamilyServices != NULL) {
128               IsEnabled = SwFamilyServices->IsSwC1eSupported (SwFamilyServices, StdHeader);
129             }
130           }
131         }
132       }
133     }
134   }
135   return IsEnabled;
136 }
137
138 /*---------------------------------------------------------------------------------------*/
139 /**
140  *  Enable Software C1e
141  *
142  * @param[in]    EntryPoint         Timepoint designator.
143  * @param[in]    PlatformConfig     Contains the runtime modifiable feature input data.
144  * @param[in]    StdHeader          Config Handle for library, services.
145  *
146  * @return       The most severe status of any family specific service.
147  *
148  */
149 AGESA_STATUS
150 STATIC
151 InitializeSwC1eFeature (
152   IN       UINT64                 EntryPoint,
153   IN       PLATFORM_CONFIGURATION *PlatformConfig,
154   IN       AMD_CONFIG_PARAMS      *StdHeader
155   )
156 {
157   AGESA_STATUS AgesaStatus;
158   SW_C1E_FAMILY_SERVICES *FamilyServices;
159
160   AgesaStatus = AGESA_SUCCESS;
161
162   IDS_HDT_CONSOLE (CPU_TRACE, "    SW C1e is enabled\n");
163
164   if (IsWarmReset (StdHeader)) {
165     GetFeatureServicesOfCurrentCore (&SwC1eFamilyServiceTable, (CONST VOID **)&FamilyServices, StdHeader);
166     AgesaStatus = FamilyServices->InitializeSwC1e (FamilyServices, EntryPoint, PlatformConfig, StdHeader);
167   }
168
169   return AgesaStatus;
170 }
171
172 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureSwC1e =
173 {
174   SoftwareC1e,
175   CPU_FEAT_AFTER_PM_INIT,
176   IsSwC1eFeatureEnabled,
177   InitializeSwC1eFeature
178 };