AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / Tech / DDR3 / mt3.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mt3.c
6  *
7  * Common Technology  functions for DDR3
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project: AGESA
11  * @e sub-project: (Mem/Tech/DDR3)
12  * @e \$Revision: 56279 $ @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
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 "Ids.h"
57 #include "mm.h"
58 #include "mn.h"
59 #include "mu.h"
60 #include "mt.h"
61 #include "mt3.h"
62 #include "mtspd3.h"
63 #include "mtot3.h"
64 #include "OptionMemory.h"
65 #include "PlatformMemoryConfiguration.h"
66 #include "Filecode.h"
67 CODE_GROUP (G1_PEICC)
68 RDATA_GROUP (G2_PEI)
69
70 /* features */
71 #define FILECODE PROC_MEM_TECH_DDR3_MT3_FILECODE
72 /*----------------------------------------------------------------------------
73  *                          DEFINITIONS AND MACROS
74  *
75  *----------------------------------------------------------------------------
76  */
77
78 /*----------------------------------------------------------------------------
79  *                           TYPEDEFS AND STRUCTURES
80  *
81  *----------------------------------------------------------------------------
82  */
83
84 /*----------------------------------------------------------------------------
85  *                        PROTOTYPES OF LOCAL FUNCTIONS
86  *
87  *----------------------------------------------------------------------------
88  */
89
90 /*----------------------------------------------------------------------------
91  *                            EXPORTED FUNCTIONS
92  *
93  *----------------------------------------------------------------------------
94  */
95 /* -----------------------------------------------------------------------------*/
96 /**
97  *
98  *   This function Constructs the technology block
99  *
100  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
101  *     @param[in,out]   *TechPtr   - Pointer to the MEM_TECH_BLOCK
102  *
103  */
104
105 BOOLEAN
106 MemConstructTechBlock3 (
107   IN OUT   MEM_TECH_BLOCK *TechPtr,
108   IN OUT   MEM_NB_BLOCK *NBPtr
109   )
110 {
111   TECHNOLOGY_TYPE *TechTypePtr;
112   UINT8 Dct;
113   UINT8 Channel;
114   UINT8 i;
115   DIE_STRUCT *MCTPtr;
116   DCT_STRUCT *DCTPtr;
117   CH_DEF_STRUCT *ChannelPtr;
118   UINT8 DimmSlots;
119
120
121   TechTypePtr = (TECHNOLOGY_TYPE *) FindPSOverrideEntry (NBPtr->RefPtr->PlatformMemoryConfiguration, PSO_MEM_TECH, NBPtr->MCTPtr->SocketId, 0, 0, NULL, NULL);
122   if (TechTypePtr != NULL) {
123     // Ensure the platform override value is valid
124     ASSERT ((*TechTypePtr == DDR3_TECHNOLOGY) || (*TechTypePtr == DDR2_TECHNOLOGY));
125     if (*TechTypePtr != DDR3_TECHNOLOGY) {
126       return FALSE;
127     }
128   }
129
130   TechPtr->NBPtr = NBPtr;
131   TechPtr->RefPtr = NBPtr->RefPtr;
132   MCTPtr = NBPtr->MCTPtr;
133
134   TechPtr->SendAllMRCmds = MemTSendAllMRCmds3;
135   TechPtr->FreqChgCtrlWrd = FreqChgCtrlWrd3;
136   TechPtr->SetDramMode = MemTSetDramMode3;
137   TechPtr->DimmPresence = MemTDIMMPresence3;
138   TechPtr->SpdCalcWidth = MemTSPDCalcWidth3;
139   TechPtr->SpdGetTargetSpeed = MemTSPDGetTargetSpeed3;
140   TechPtr->AutoCycTiming = MemTAutoCycTiming3;
141   TechPtr->SpdSetBanks = MemTSPDSetBanks3;
142   TechPtr->SetDqsEccTmgs = MemTSetDQSEccTmgs;
143   TechPtr->GetCSIntLvAddr = MemTGetCSIntLvAddr3;
144   TechPtr->AdjustTwrwr = MemTAdjustTwrwr3;
145   TechPtr->AdjustTwrrd = MemTAdjustTwrrd3;
146   TechPtr->GetDimmSpdBuffer = MemTGetDimmSpdBuffer3;
147   TechPtr->GetLD = MemTGetLD3;
148   TechPtr->MaxFilterDly = 0;
149
150   //
151   // Map the Logical Dimms on this channel to the SPD that should be used for that logical DIMM.
152   // The pointers to the DIMM SPD information is as follows (2 Dimm/Ch and 3 Dimm/Ch examples).
153   //
154   //    DIMM Spd Buffer                          Current Channel DimmSpdPtr[MAX_DIMMS_PER_CHANNEL] array
155   //    (Number of dimms varies by platform)     (Array size is determined in AGESA.H) Dimm operations loop
156   //                                              on this array only)
157   //    2 DIMMS PER CHANNEL
158   //
159   //    Socket N  Channel N Dimm 0 SR/DR DIMM <--------------DimmSpdPtr[0]
160   //                        Dimm 1 SR/DR DIMM <--------------DimmSpdPtr[1]
161   //                                                         DimmSpdPtr[2]------->NULL
162   //                                                         DimmSpdPtr[3]------->NULL
163   //
164   //    Socket N  Channel N Dimm 0 SR/DR DIMM <--------------DimmSpdPtr[0]
165   //                        Dimm 1    QR DIMM <---------+----DimmSpdPtr[1]
166   //                                                    |    DimmSpdPtr[2]------->NULL
167   //                                                    +----DimmSpdPtr[3]
168   //
169   //    Socket N  Channel N Dimm 0    QR DIMM <-----+--------DimmSpdPtr[0]
170   //                        Dimm 1    QR DIMM <-----|---+----DimmSpdPtr[1]
171   //                                                +-- | ---DimmSpdPtr[2]
172   //                                                    +----DimmSpdPtr[3]
173   //
174   //    3 DIMMS PER CHANNEL
175   //
176   //    Socket N  Channel N Dimm 0 SR/DR DIMM <--------------DimmSpdPtr[0]
177   //                        Dimm 1 SR/DR DIMM <--------------DimmSpdPtr[1]
178   //                        Dimm 3 SR/DR DIMM <--------------DimmSpdPtr[2]
179   //                                                         DimmSpdPtr[3]------->NULL
180   //
181   //    Socket N  Channel N Dimm 0 SR/DR DIMM <--------------DimmSpdPtr[0]
182   //                        Dimm 1    QR DIMM <---------+----DimmSpdPtr[1]
183   //                        Dimm 3 SR/DR DIMM <-------- | ---DimmSpdPtr[2]
184   //                                                    +----DimmSpdPtr[3]
185   //
186   //
187   //    FOR LRDIMMS
188   //
189   //    This code will assign SPD pointers on the basis of Physical ranks, even though
190   //    an LRDIMM may only use one or two logical ranks, that determination will have to
191   //    be made from downstream code.  An LRDIMM with greater than 2 Physical ranks will have
192   //    its DimmSpdPtr[] mapped as if it were a QR in the above diagrams.
193
194   for (Dct = 0; Dct < NBPtr->DctCount; Dct++) {
195     NBPtr->SwitchDCT (NBPtr, Dct);
196     DCTPtr = NBPtr->DCTPtr;
197     for (Channel = 0; Channel < NBPtr->ChannelCount; Channel++) {
198       NBPtr->SwitchChannel (NBPtr, Channel);
199       ChannelPtr = NBPtr->ChannelPtr;
200       ChannelPtr->TechType = DDR3_TECHNOLOGY;
201       ChannelPtr->MCTPtr = MCTPtr;
202       ChannelPtr->DCTPtr = DCTPtr;
203
204       DimmSlots = GetMaxDimmsPerChannel (NBPtr->RefPtr->PlatformMemoryConfiguration,
205                                          MCTPtr->SocketId,
206                                          NBPtr->GetSocketRelativeChannel (NBPtr, Dct, Channel)
207                                         );
208       //
209       // Initialize the SPD pointers for each Dimm
210       //
211       for (i = 0 ; i < (sizeof (ChannelPtr->DimmSpdPtr) / sizeof (ChannelPtr->DimmSpdPtr[0])) ; i++) {
212         ChannelPtr->DimmSpdPtr[i] = NULL;
213       }
214       for (i = 0 ; i < DimmSlots; i++) {
215         ChannelPtr->DimmSpdPtr[i] = &(ChannelPtr->SpdPtr[i]);
216         if ( (i + 2) < (sizeof (ChannelPtr->DimmSpdPtr) / sizeof (ChannelPtr->DimmSpdPtr[0]))) {
217           if (ChannelPtr->DimmSpdPtr[i]->DimmPresent) {
218             if ((((ChannelPtr->DimmSpdPtr[i]->Data[SPD_RANKS] >> 3) & 0x07) + 1) > 2) {
219               ChannelPtr->DimmSpdPtr[i + 2] = &(ChannelPtr->SpdPtr[i]);
220             }
221           }
222         }
223       }
224     }
225   }
226   // Initialize Common technology functions
227   MemTCommonTechInit (TechPtr);
228
229   return TRUE;
230 }
231
232 /*----------------------------------------------------------------------------
233  *                              LOCAL FUNCTIONS
234  *
235  *----------------------------------------------------------------------------
236  */