AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Feat / ODTHERMAL / mfodthermal.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mfodthermal.c
6  *
7  * On Dimm thermal management.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Feat)
12  * @e \$Revision: 44324 $ @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
13  *
14  **/
15 /*****************************************************************************
16 *
17 * Copyright (C) 2012 Advanced Micro Devices, Inc.
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
22 *     * Redistributions of source code must retain the above copyright
23 *       notice, this list of conditions and the following disclaimer.
24 *     * Redistributions in binary form must reproduce the above copyright
25 *       notice, this list of conditions and the following disclaimer in the
26 *       documentation and/or other materials provided with the distribution.
27 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
28 *       its contributors may be used to endorse or promote products derived
29 *       from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
32 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
35 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * ***************************************************************************
43 *
44 */
45
46 /*
47  *----------------------------------------------------------------------------
48  *                                MODULES USED
49  *
50  *----------------------------------------------------------------------------
51  */
52
53
54
55 #include "AGESA.h"
56 #include "mm.h"
57 #include "mn.h"
58 #include "mt.h"
59 #include "Ids.h"
60 #include "mfodthermal.h"
61 #include "Filecode.h"
62 CODE_GROUP (G2_PEI)
63 RDATA_GROUP (G2_PEI)
64
65 #define FILECODE PROC_MEM_FEAT_ODTHERMAL_MFODTHERMAL_FILECODE
66
67 /*----------------------------------------------------------------------------
68  *                          DEFINITIONS AND MACROS
69  *
70  *----------------------------------------------------------------------------
71  */
72
73 /*----------------------------------------------------------------------------
74  *                           TYPEDEFS AND STRUCTURES
75  *
76  *----------------------------------------------------------------------------
77  */
78
79 /*----------------------------------------------------------------------------
80  *                        PROTOTYPES OF LOCAL FUNCTIONS
81  *
82  *----------------------------------------------------------------------------
83  */
84
85 /*----------------------------------------------------------------------------
86  *                            EXPORTED FUNCTIONS
87  *
88  *----------------------------------------------------------------------------
89  */
90 /*-----------------------------------------------------------------------------*/
91 /**
92  *
93  *   This function does On-Dimm thermal management.
94  *
95  *   @param[in, out]   *NBPtr - Pointer to the MEM_NB_BLOCK.
96  *
97  *     @return          TRUE -  This feature is enabled.
98  *     @return          FALSE - This feature is not enabled.
99  */
100
101 BOOLEAN
102 MemFOnDimmThermal (
103   IN OUT   MEM_NB_BLOCK *NBPtr
104   )
105 {
106   UINT8 i;
107   UINT8 Dct;
108   CH_DEF_STRUCT *ChannelPtr;
109   MEM_DATA_STRUCT *MemPtr;
110   UINT8 *SpdBufferPtr;
111   UINT8 ThermalOp;
112   BOOLEAN ODTSEn;
113   BOOLEAN ExtendTmp;
114
115   ODTSEn = FALSE;
116   ExtendTmp = FALSE;
117
118   ASSERT (NBPtr != NULL);
119   MemPtr = NBPtr->MemPtr;
120   AGESA_TESTPOINT (TpProcMemOnDimmThermal, &MemPtr->StdHeader);
121   if (NBPtr->MCTPtr->NodeMemSize != 0) {
122     for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
123       NBPtr->SwitchDCT (NBPtr, Dct);
124       // Only go through the DCT if it is not disabled.
125       if (NBPtr->GetBitField (NBPtr, BFDisDramInterface) == 0) {
126         ChannelPtr = NBPtr->ChannelPtr;
127         // If Ganged mode is enabled, need to go through all dram devices on both DCTs.
128         if (!NBPtr->Ganged || (NBPtr->Dct != 1)) {
129           if (!(NBPtr->IsSupported[CheckSetSameDctODTsEn]) || (NBPtr->IsSupported[CheckSetSameDctODTsEn] && (NBPtr->Dct != 1))) {
130             ODTSEn = TRUE;
131             ExtendTmp = TRUE;
132           }
133         }
134         for (i = 0; i < MAX_DIMMS_PER_CHANNEL; i ++) {
135           if (NBPtr->TechPtr->GetDimmSpdBuffer (NBPtr->TechPtr, &SpdBufferPtr, i)) {
136             // Check byte 31: thermal and refresh option.
137             ThermalOp = SpdBufferPtr[THERMAL_OPT];
138             // Bit 3: ODTS readout
139             if (!((ThermalOp >> 3) & 1)) {
140               ODTSEn = FALSE;
141             }
142             // Bit 0: Extended Temperature Range.
143             if (!(ThermalOp & 1)) {
144               ExtendTmp = FALSE;
145             }
146           }
147         }
148
149         if (!NBPtr->Ganged || (NBPtr->Dct == 1)) {
150           // If in ganged mode, need to switch back to DCT0 to set the registers.
151           if (NBPtr->Ganged || NBPtr->IsSupported[CheckSetSameDctODTsEn]) {
152             NBPtr->SwitchDCT (NBPtr, 0);
153             ChannelPtr = NBPtr->ChannelPtr;
154           }
155           // If all dram devices on a DCT support ODTS
156           if (ODTSEn) {
157             NBPtr->SetBitField (NBPtr, BFODTSEn, 1);
158           }
159           ChannelPtr->ExtendTmp = ExtendTmp;
160         }
161       }
162       IDS_HDT_CONSOLE (MEM_FLOW, "\tDct %d\n", Dct);
163       IDS_HDT_CONSOLE (MEM_FLOW, "\t\tODTSEn = %d\n", ODTSEn);
164       IDS_HDT_CONSOLE (MEM_FLOW, "\t\tExtendTmp = %d\n", ExtendTmp);
165     }
166   }
167   return TRUE;
168 }
169
170
171 /*----------------------------------------------------------------------------
172  *                              LOCAL FUNCTIONS
173  *
174  *----------------------------------------------------------------------------
175  */