soc/mediatek/mt8196: Correct assert conditions
[coreboot2.git] / src / vendorcode / amd / pi / Lib / imc / HwmLateService.c
blobf26dfc9be7551edf567901a3f15c541c59c7e0d4
1 /* $NoKeywords:$ */
2 /**
3 * @file
5 * Config FCH Hwm controller
7 * Init Hwm Controller features.
9 * @xrefitem bom "File Content Label" "Release Content"
10 * @e project: AGESA
11 * @e sub-project: FCH
12 * @e \$Revision: 84150 $ @e \$Date: 2012-12-12 15:46:25 -0600 (Wed, 12 Dec 2012) $
16 *****************************************************************************
18 * Copyright (c) 2008 - 2013, Advanced Micro Devices, Inc.
19 * All rights reserved.
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.
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 ****************************************************************************
44 #include "FchPlatform.h"
45 #include "Filecode.h"
46 #define FILECODE PROC_FCH_HWM_FAMILY_YANGTZE_YANGTZEHWMLATESERVICE_FILECODE
48 /**
49 * Table for Function Number
55 STATIC UINT8 FunctionNumber[] =
57 Fun_81,
58 Fun_83,
59 Fun_85,
60 Fun_89,
63 /**
64 * Table for Max Thermal Zone
70 UINT8 MaxZone[] =
79 /**
80 * Table for Max Register
86 UINT8 MaxRegister[] =
88 MSG_REG9,
89 MSG_REGB,
90 MSG_REG9,
91 MSG_REGA,
94 /*-------------------------------------------------------------------------------
95 ;Procedure: IsZoneFuncEnable
97 ;Description: This routine will check every zone support function with BitMap from user define
100 ;Exit: None
102 ;Modified: None
104 ;-----------------------------------------------------------------------------
106 STATIC BOOLEAN
107 IsZoneFuncEnable (
108 IN UINT16 Flag,
109 IN UINT8 func,
110 IN UINT8 Zone
113 return (BOOLEAN) (((Flag >> (func *4)) & 0xF) & ((UINT8 )1 << Zone));
116 /*-------------------------------------------------------------------------------
117 ;Procedure: FchECfancontrolservice
119 ;Description: This routine service EC fan policy
122 ;Exit: None
124 ;Modified: None
126 ;-----------------------------------------------------------------------------
128 VOID
129 FchECfancontrolservice (
130 IN VOID *FchDataPtr
133 UINT8 ZoneNum;
134 UINT8 FunNum;
135 UINT8 RegNum;
136 UINT8 *CurPoint;
137 UINT8 FunIndex;
138 BOOLEAN IsSendEcMsg;
139 FCH_DATA_BLOCK *LocalCfgPtr;
140 AMD_CONFIG_PARAMS *StdHeader;
142 LocalCfgPtr = (FCH_DATA_BLOCK *) FchDataPtr;
143 StdHeader = LocalCfgPtr->StdHeader;
145 if (!IsImcEnabled (StdHeader)) {
146 return; //IMC is not enabled
149 CurPoint = &LocalCfgPtr->Imc.EcStruct.MsgFun81Zone0MsgReg0 + MaxZone[0] * (MaxRegister[0] - MSG_REG0 + 1);
151 for ( FunIndex = 1; FunIndex <= 3; FunIndex++ ) {
152 FunNum = FunctionNumber[FunIndex];
153 for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {
154 IsSendEcMsg = IsZoneFuncEnable (LocalCfgPtr->Imc.EcStruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);
155 if (IsSendEcMsg) {
156 for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {
157 WriteECmsg (RegNum, AccessWidth8, CurPoint, StdHeader);
158 CurPoint += 1;
160 WriteECmsg (MSG_SYS_TO_IMC, AccessWidth8, &FunNum, StdHeader); // function number
161 WaitForEcLDN9MailboxCmdAck (StdHeader);
162 } else {
163 CurPoint += (MaxRegister[FunIndex] - MSG_REG0 + 1);
168 CurPoint = &LocalCfgPtr->Imc.EcStruct.MsgFun81Zone0MsgReg0;
169 for ( FunIndex = 0; FunIndex <= 0; FunIndex++ ) {
170 FunNum = FunctionNumber[FunIndex];
171 for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {
172 IsSendEcMsg = IsZoneFuncEnable (LocalCfgPtr->Imc.EcStruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);
173 if (IsSendEcMsg) {
174 for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {
175 if (RegNum == MSG_REG2) {
176 *CurPoint &= 0xFE;
178 WriteECmsg (RegNum, AccessWidth8, CurPoint, StdHeader);
179 CurPoint += 1;
181 WriteECmsg (MSG_SYS_TO_IMC, AccessWidth8, &FunNum, StdHeader); // function number
182 WaitForEcLDN9MailboxCmdAck (StdHeader);
183 } else {
184 CurPoint += (MaxRegister[FunIndex] - MSG_REG0 + 1);