m5a99x-evo: grml, strange romstage ld warning... dunno why :/
[coreboot.git] / src / vendorcode / amd / cimx / sb900 / Dispatcher.c
1 /**
2  * @file
3  *
4  *  Function dispatcher.
5  *
6  *
7  *
8  * @xrefitem bom "File Content Label" "Release Content"
9  * @e project:      CIMx-SB
10  * @e sub-project:
11  * @e \$Revision:$   @e \$Date:$
12  *
13  */
14
15 /*;********************************************************************************
16 ;
17 ; Copyright (c) 2011, 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  *                             M O D U L E S    U S E D
45  *----------------------------------------------------------------------------------------
46  */
47
48 #include "SbPlatform.h"
49 #include "cbtypes.h"
50 #include "AmdSbLib.h"
51
52 /*----------------------------------------------------------------------------------------
53  *           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
54  *----------------------------------------------------------------------------------------
55 */
56
57
58 //
59 // Declaration of local functions
60 //
61
62 VOID  saveConfigPointer (IN AMDSBCFG* pConfig);
63 VOID* VerifyImage (IN UINT64 Signature, IN VOID* ImagePtr);
64 VOID* LocateImage (IN UINT64 Signature);
65
66 /*----------------------------------------------------------------------------------------
67  *                  T Y P E D E F S     A N D     S T R U C T U  R E S
68  *----------------------------------------------------------------------------------------
69  */
70
71 /*----------------------------------------------------------------------------------------
72  *                          E X P O R T E D    F U N C T I O N S
73  *----------------------------------------------------------------------------------------
74  */
75
76 /**
77  * AmdSbDispatcher - Dispatch Southbridge function
78  *
79  *
80  *
81  * @param[in] pConfig   Southbridge configuration structure pointer.
82  *
83  */
84 AGESA_STATUS
85 AmdSbDispatcher (
86   IN       VOID *pConfig
87   )
88 {
89   AGESA_STATUS      Status;
90   UINT64            tdValue;
91
92 #ifdef B1_IMAGE
93   VOID              *pAltImagePtr;
94   CIM_IMAGE_ENTRY   AltImageEntry;
95
96   pAltImagePtr = NULL;
97 #endif
98
99   Status = AGESA_UNSUPPORTED;
100   tdValue = 0x313141324E4448ull;
101
102 //#if CIM_DEBUG
103 //  InitSerialOut ();
104 //#endif
105
106   Status = AGESA_UNSUPPORTED;
107   TRACE ((DMSG_SB_TRACE, "CIM - Hudson-2 Entry\n"));
108
109 #ifdef B1_IMAGE
110   if ((UINT32) (UINTN) (((AMD_CONFIG_PARAMS*)pConfig)->AltImageBasePtr) != 0xffffffff ) {
111     if ( ((AMD_CONFIG_PARAMS*)pConfig)->AltImageBasePtr ) {
112       pAltImagePtr = VerifyImage ( tdValue, (VOID*) (UINTN) ((AMD_CONFIG_PARAMS*)pConfig)->AltImageBasePtr);
113     }
114     if ( pAltImagePtr == NULL ) {
115       pAltImagePtr = LocateImage ( tdValue );
116     }
117     if ( pAltImagePtr != NULL ) {
118       ((AMD_CONFIG_PARAMS*)pConfig)->ImageBasePtr = (UINT32) (UINTN) pAltImagePtr;
119       AltImageEntry = (CIM_IMAGE_ENTRY) (UINTN) ((UINT32) (UINTN) pAltImagePtr + (UINT32) (((AMD_IMAGE_HEADER*) (UINTN) pAltImagePtr)->EntryPointAddress));
120       (*AltImageEntry) (pConfig);
121       return Status;
122     }
123   }
124 #endif
125   saveConfigPointer (pConfig);
126
127   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_POWERON_INIT ) {
128     sbPowerOnInit ((AMDSBCFG*) pConfig);
129   }
130
131 #ifndef B1_IMAGE
132   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_BEFORE_PCI_INIT ) {
133     sbBeforePciInit ((AMDSBCFG*)pConfig);
134   }
135
136   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_AFTER_PCI_INIT ) {
137     sbAfterPciInit ((AMDSBCFG*)pConfig);
138   }
139
140   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_MID_POST_INIT ) {
141     sbMidPostInit ((AMDSBCFG*)pConfig);
142   }
143
144   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_LATE_POST_INIT ) {
145     sbLatePost ((AMDSBCFG*)pConfig);
146   }
147
148   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_BEFORE_PCI_RESTORE_INIT ) {
149     sbBeforePciRestoreInit ((AMDSBCFG*)pConfig);
150   }
151
152   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_AFTER_PCI_RESTORE_INIT ) {
153     sbAfterPciRestoreInit ((AMDSBCFG*)pConfig);
154   }
155
156   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_SMM_SERVICE ) {
157     sbSmmService ((AMDSBCFG*)pConfig);
158   }
159
160   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_SMM_ACPION ) {
161     sbSmmAcpiOn ((AMDSBCFG*)pConfig);
162   }
163
164   if ( ((AMD_CONFIG_PARAMS*)pConfig)->Func == SB_EC_FANCONTROL ) {
165     sbECfancontrolservice ((AMDSBCFG*)pConfig);
166   }
167 #endif
168   TRACE ((DMSG_SB_TRACE, "CIMx - SB Exit\n"));
169   return Status;
170 }
171
172 /**
173  * LocateImage - Locate Southbridge CIMx module
174  *
175  *
176  *
177  * @param[in] Signature   Southbridge CIMx image signature.
178  *
179  */
180 VOID*
181 LocateImage (
182   IN       UINT64 Signature
183   )
184 {
185   VOID  *Result;
186   UINT32   ImagePtr;
187   ImagePtr = 0xffffffff - (IMAGE_ALIGN - 1);
188
189   while ( ImagePtr >= (0xfffffff - (NUM_IMAGE_LOCATION * IMAGE_ALIGN - 1)) ) {
190 #ifdef x64
191     12346789
192 #else
193     Result = VerifyImage (Signature, (VOID *) ImagePtr);
194 #endif
195     if ( Result != NULL ) {
196       return Result;
197     }
198     ImagePtr -= IMAGE_ALIGN;
199   }
200   return NULL;
201 }
202
203 /**
204  * VerifyImage - Verify Southbridge CIMx module
205  *
206  *
207  * @param[in] Signature   Southbridge CIMx image signature.
208  * @param[in] ImagePtr    Southbridge CIMx image address.
209  *
210  */
211 VOID*
212 VerifyImage (
213   IN       UINT64 Signature,
214   IN       VOID* ImagePtr
215   )
216 {
217   UINT16 *TempImagePtr;
218   UINT16 Sum;
219   UINT32  i;
220   Sum = 0;
221 //  if ( (*((UINT32*)ImagePtr) == 'DMA$' && ((CIMFILEHEADER*)ImagePtr)->CreatorID == Signature) ) {
222   if ( (*((UINT32*)ImagePtr) == Int32FromChar('D', 'M', 'A', '$') && ((CIMFILEHEADER*)ImagePtr)->CreatorID == Signature) ) {
223     //GetImage Image size
224     TempImagePtr = (UINT16*)ImagePtr;
225     for ( i = 0; i < (((CIMFILEHEADER*)ImagePtr)->ImageSize); i += 2 ) {
226       Sum = Sum + *TempImagePtr;
227       TempImagePtr++;
228     }
229     if ( Sum == 0 ) {
230       return ImagePtr;
231     }
232   }
233   return NULL;
234 }
235
236 /**
237  * saveConfigPointer - Verify Southbridge CIMx module
238  *
239  *
240  * @param[in] pConfig   Southbridge configuration structure pointer.
241  *
242  */
243 VOID
244 saveConfigPointer (
245   IN       AMDSBCFG* pConfig
246   )
247 {
248   UINT8   dbReg;
249   UINT8   i;
250   UINT32   ddValue;
251
252   ddValue =  (UINT32) (UINTN)pConfig;
253   dbReg = SB_ECMOS_REG08;
254
255   for ( i = 0; i <= 3; i++ ) {
256     WriteIO (SB_IOMAP_REG72, AccWidthUint8, &dbReg);
257     WriteIO (SB_IOMAP_REG73, AccWidthUint8, (UINT8*)&ddValue);
258     ddValue = (ddValue >> 8);
259     dbReg++;
260   }
261 }