AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Feature / cpuHwC1e.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD AGESA CPU HW 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 "cpuHwC1e.h"
61 #include "Filecode.h"
62 CODE_GROUP (G1_PEICC)
63 RDATA_GROUP (G2_PEI)
64
65 #define FILECODE PROC_CPU_FEATURE_CPUHWC1E_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 HwC1eFamilyServiceTable;
86
87 /*---------------------------------------------------------------------------------------*/
88 /**
89  *  Should hardware 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               HW C1e is supported.
95  * @retval       FALSE              HW C1e cannot be enabled.
96  *
97  */
98 BOOLEAN
99 STATIC
100 IsHwC1eFeatureEnabled (
101   IN       PLATFORM_CONFIGURATION *PlatformConfig,
102   IN       AMD_CONFIG_PARAMS      *StdHeader
103   )
104 {
105   UINT32           C1eData;
106   BOOLEAN          IsEnabled;
107   AP_MAILBOXES     ApMailboxes;
108   HW_C1E_FAMILY_SERVICES *FamilyServices;
109
110   ASSERT (PlatformConfig->C1eMode < MaxC1eMode);
111   IsEnabled = FALSE;
112   C1eData   = PlatformConfig->C1ePlatformData;
113   if ((PlatformConfig->C1eMode == C1eModeHardware) || (PlatformConfig->C1eMode == C1eModeHardwareSoftwareDeprecated) ||
114       (PlatformConfig->C1eMode == C1eModeAuto)) {
115     // If C1eMode is Auto, C1ePlatformData3 specifies the P_LVL3 I/O port of the platform for HW C1e
116     if (PlatformConfig->C1eMode == C1eModeAuto) {
117       C1eData = PlatformConfig->C1ePlatformData3;
118     }
119     ASSERT (C1eData < 0x10000);
120     ASSERT (C1eData != 0);
121     if ((C1eData != 0) && (C1eData < 0xFFFE)) {
122       if (!IsNonCoherentHt1 (StdHeader)) {
123         if (GetNumberOfProcessors (StdHeader) == 1) {
124           GetApMailbox (&ApMailboxes.ApMailInfo.Info, StdHeader);
125           if (ApMailboxes.ApMailInfo.Fields.ModuleType == 0) {
126             GetFeatureServicesOfCurrentCore (&HwC1eFamilyServiceTable, (CONST VOID **)&FamilyServices, StdHeader);
127             if (FamilyServices != NULL) {
128               IsEnabled = FamilyServices->IsHwC1eSupported (FamilyServices, StdHeader);
129             }
130           }
131         }
132       }
133     }
134   }
135   return IsEnabled;
136 }
137
138 /*---------------------------------------------------------------------------------------*/
139 /**
140  *  Enable Hardware 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 InitializeHwC1eFeature (
152   IN       UINT64                 EntryPoint,
153   IN       PLATFORM_CONFIGURATION *PlatformConfig,
154   IN       AMD_CONFIG_PARAMS      *StdHeader
155   )
156 {
157   AGESA_STATUS CalledStatus;
158   AGESA_STATUS AgesaStatus;
159   HW_C1E_FAMILY_SERVICES *FamilyServices;
160
161   AgesaStatus = AGESA_SUCCESS;
162
163   IDS_HDT_CONSOLE (CPU_TRACE, "    HW C1e is enabled\n");
164
165   if (IsWarmReset (StdHeader)) {
166     GetFeatureServicesOfCurrentCore (&HwC1eFamilyServiceTable, (CONST VOID **)&FamilyServices, StdHeader);
167     CalledStatus = FamilyServices->InitializeHwC1e (FamilyServices, EntryPoint, PlatformConfig, StdHeader);
168     if (CalledStatus > AgesaStatus) {
169       AgesaStatus = CalledStatus;
170     }
171   }
172   return AgesaStatus;
173 }
174
175 CONST CPU_FEATURE_DESCRIPTOR ROMDATA CpuFeatureHwC1e =
176 {
177   HardwareC1e,
178   CPU_FEAT_AFTER_PM_INIT,
179   IsHwC1eFeatureEnabled,
180   InitializeHwC1eFeature
181 };