AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / CPU / Family / 0x10 / cpuF10CacheFlushOnHalt.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * AMD CPU Cache Flush On Halt Function.
6  *
7  * Contains code to initialize Cache Flush On Halt feature for Family 10h.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  CPU/Family/0x10
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
48 /*
49  *----------------------------------------------------------------------------
50  *                                MODULES USED
51  *
52  *----------------------------------------------------------------------------
53  */
54 #include "AGESA.h"
55 #include "amdlib.h"
56 #include "cpuRegisters.h"
57 #include "cpuServices.h"
58 #include "cpuFamilyTranslation.h"
59 #include "cpuPostInit.h"
60 #include "cpuFeatures.h"
61 #include "OptionMultiSocket.h"
62 #include "cpuF10PowerMgmt.h"
63 #include "Filecode.h"
64 CODE_GROUP (G1_PEICC)
65 RDATA_GROUP (G2_PEI)
66 #define FILECODE PROC_CPU_FAMILY_0X10_CPUF10CACHEFLUSHONHALT_FILECODE
67 /*----------------------------------------------------------------------------
68  *                          DEFINITIONS AND MACROS
69  *
70  *----------------------------------------------------------------------------
71  */
72
73
74 /*----------------------------------------------------------------------------
75  *                           TYPEDEFS AND STRUCTURES
76  *
77  *----------------------------------------------------------------------------
78  */
79
80 /*----------------------------------------------------------------------------------------
81  *                          E X P O R T E D    F U N C T I O N S
82  *----------------------------------------------------------------------------------------
83  */
84 extern OPTION_MULTISOCKET_CONFIGURATION OptionMultiSocketConfiguration;
85 /*----------------------------------------------------------------------------
86  *                        PROTOTYPES OF LOCAL FUNCTIONS
87  *
88  *----------------------------------------------------------------------------
89  */
90
91 VOID
92 SetF10CacheFlushOnHaltRegister (
93   IN       CPU_CFOH_FAMILY_SERVICES     *FamilySpecificServices,
94   IN       UINT64                       EntryPoint,
95   IN       PLATFORM_CONFIGURATION       *PlatformConfig,
96   IN       AMD_CONFIG_PARAMS            *StdHeader
97   );
98
99 /*----------------------------------------------------------------------------------------
100  *                          P U B L I C     F U N C T I O N S
101  *----------------------------------------------------------------------------------------
102  */
103
104 /* -----------------------------------------------------------------------------*/
105 /**
106  *    Enable Cpu Cache Flush On Halt Function
107  *
108  *    @param[in]       FamilySpecificServices   The current Family Specific Services.
109  *    @param[in]       EntryPoint               Timepoint designator.
110  *    @param[in]       PlatformConfig           Contains the runtime modifiable feature input data.
111  *    @param[in]       StdHeader                Config Handle for library, services.
112  */
113 VOID
114 SetF10CacheFlushOnHaltRegister (
115   IN       CPU_CFOH_FAMILY_SERVICES     *FamilySpecificServices,
116   IN       UINT64                       EntryPoint,
117   IN       PLATFORM_CONFIGURATION       *PlatformConfig,
118   IN       AMD_CONFIG_PARAMS            *StdHeader
119   )
120 {
121   UINT32       AndMask;
122   UINT32       OrMask;
123   UINT32     CoreCount;
124   UINT32       CpbControl;
125   CPU_LOGICAL_ID LogicalId;
126   PCI_ADDR     PciAddress;
127   PCI_ADDR     CpbCtrlRegister;
128
129   if ((EntryPoint & (CPU_FEAT_AFTER_POST_MTRR_SYNC | CPU_FEAT_AFTER_RESUME_MTRR_SYNC)) != 0) {
130     // Initialize F3xDC
131     // bits[25:19] CacheFlushOnHaltTmr = 28h
132     // bits[18:16] CacheFlushOnHaltCtl = 111b
133     PciAddress.Address.Function = FUNC_3;
134     PciAddress.Address.Register = CLOCK_POWER_TIMING_CTRL2_REG;
135     AndMask = 0xFC00FFFF;
136     OrMask = 0x01470000;
137
138     GetLogicalIdOfCurrentCore (&LogicalId, StdHeader);
139     if ((LogicalId.Revision & AMD_F10_C2) != 0) {
140       //For F10_C2 single Core, F3xDC[18:16] = 0
141       GetActiveCoresInCurrentSocket (&CoreCount, StdHeader);
142       if (CoreCount == 1) {
143         OrMask = 0x01400000;
144       }
145     }
146
147     if ((LogicalId.Revision & AMD_F10_PH_ALL) != 0) {
148       // If Revision E and CPB is enabled
149       // F3xDC[25:19] CacheFlushOnHaltTmr = Ch
150       CpbCtrlRegister.AddressValue = CPB_CTRL_PCI_ADDR;
151       LibAmdPciRead (AccessWidth32, CpbCtrlRegister, &CpbControl, StdHeader);
152
153       if (((CPB_CTRL_REGISTER *) (&CpbControl))->BoostSrc == 3) {
154         OrMask = 0x00670000;
155       }
156     }
157
158     IDS_OPTION_HOOK (IDS_CACHE_FLUSH_HLT, &OrMask, StdHeader);
159     OptionMultiSocketConfiguration.ModifyCurrSocketPci (&PciAddress, AndMask, OrMask, StdHeader); //F3xDC
160   }
161 }
162
163 CONST CPU_CFOH_FAMILY_SERVICES ROMDATA F10CacheFlushOnHalt =
164 {
165   0,
166   SetF10CacheFlushOnHaltRegister
167 };