AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / Mem / NB / C32 / mnParTrainc32.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * mnParTrainc32.c
6  *
7  * Feature which performs Memory DQS training on each node with each node training
8  * its own memory through code running on a core in the associated processor.
9  * This way memory can be trained in parallel by more than one processor.
10  *
11  * This file contains the C32 specific parallel training function.
12  *
13  * @xrefitem bom "File Content Label" "Release Content"
14  * @e project: AGESA
15  * @e sub-project: (Mem/NB/C32)
16  * @e \$Revision: 54775 $ @e \$Date: 2011-06-12 21:05:26 -0600 (Sun, 12 Jun 2011) $
17  *
18  **/
19 /*****************************************************************************
20   *
21  * Copyright (C) 2012 Advanced Micro Devices, Inc.
22  * All rights reserved.
23   *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions are met:
26  *     * Redistributions of source code must retain the above copyright
27  *       notice, this list of conditions and the following disclaimer.
28  *     * Redistributions in binary form must reproduce the above copyright
29  *       notice, this list of conditions and the following disclaimer in the
30  *       documentation and/or other materials provided with the distribution.
31  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
32  *       its contributors may be used to endorse or promote products derived
33  *       from this software without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
36  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
39  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45   *
46   * ***************************************************************************
47   *
48  */
49
50
51
52
53 #include "AGESA.h"
54 #include "AdvancedApi.h"
55 #include "amdlib.h"
56 #include "OptionMemory.h"
57 #include "mm.h"
58 #include "mn.h"
59 #include "mnc32.h"
60 #include "Ids.h"
61 #include "cpuRegisters.h"
62 #include "cpuServices.h"
63 #include "GeneralServices.h"
64 #include "cpuFamilyTranslation.h"
65 #include "cpuApicUtilities.h"
66 #include "mfParallelTraining.h"
67 #include "heapManager.h"
68 #include "Filecode.h"
69 CODE_GROUP (G2_PEI)
70 RDATA_GROUP (G2_PEI)
71
72 #define FILECODE PROC_MEM_NB_C32_MNPARTRAINC32_FILECODE
73 /*-----------------------------------------------------------------------------
74 *                                EXPORTED FUNCTIONS
75 *
76 *-----------------------------------------------------------------------------
77 */
78 BOOLEAN
79 MemFParallelTrainingC32 (
80   IN OUT   MEM_NB_BLOCK *NBPtr
81   );
82
83 BOOLEAN
84 STATIC
85 MemConstructRemoteNBBlockC32 (
86   IN OUT   MEM_NB_BLOCK *NBPtr,
87   IN       DIE_STRUCT *MCTPtr,
88   IN       MEM_FEAT_BLOCK_NB *FeatPtr
89 );
90 /* -----------------------------------------------------------------------------*/
91 /**
92  *
93  *
94  *       This is the training function which set up the environment for remote
95  * training on the ap and launches the remote routine.
96  *
97  *     @param[in,out]   *NBPtr   - Pointer to the MEM_NB_BLOCK
98  *
99  *     @return          TRUE -  Launch training on AP successfully.
100  *     @return          FALSE - Fail to launch training on AP.
101  */
102 BOOLEAN
103 MemFParallelTrainingC32 (
104   IN OUT   MEM_NB_BLOCK *NBPtr
105   )
106 {
107   AMD_CONFIG_PARAMS *StdHeader;
108   DIE_STRUCT *MCTPtr;
109   REMOTE_TRAINING_ENV *EnvPtr;
110   AP_TASK TrainingTask;
111   UINT8 Socket;
112   UINT8 Module;
113   UINT8 APCore;
114   UINT8 p;
115   UINT32 LowCore;
116   UINT32 HighCore;
117   UINT32 BspSocket;
118   UINT32 BspModule;
119   UINT32 BspCore;
120   AGESA_STATUS Status;
121   ALLOCATE_HEAP_PARAMS AllocHeapParams;
122   UINT16 MctDataSize;
123   StdHeader = &(NBPtr->MemPtr->StdHeader);
124   MCTPtr = NBPtr->MCTPtr;
125   Socket = MCTPtr->SocketId;
126   Module = MCTPtr->DieId;
127
128   //
129   // Allocate buffer for REMOTE_TRAINING_ENV
130   //
131   MctDataSize = MAX_DCTS_PER_NODE_C32 * (
132                   sizeof (DCT_STRUCT) + (
133                     MAX_CHANNELS_PER_DCT_C32 * (sizeof (CH_DEF_STRUCT) + sizeof (MEM_PS_BLOCK))
134                   )
135                 );
136   AllocHeapParams.RequestedBufferSize = MctDataSize + sizeof (REMOTE_TRAINING_ENV);
137   AllocHeapParams.BufferHandle = GENERATE_MEM_HANDLE (ALLOC_PAR_TRN_HANDLE, Socket, Module, 0);
138   AllocHeapParams.Persist = HEAP_LOCAL_CACHE;
139   if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) == AGESA_SUCCESS) {
140     EnvPtr = (REMOTE_TRAINING_ENV *) AllocHeapParams.BufferPtr;
141     AllocHeapParams.BufferPtr += sizeof (REMOTE_TRAINING_ENV);
142
143     //
144     // Setup Remote training environment
145     //
146     LibAmdMemCopy (&(EnvPtr->StdHeader), StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
147     LibAmdMemCopy (&(EnvPtr->DieStruct), MCTPtr, sizeof (DIE_STRUCT), StdHeader);
148     for (p = 0; p < MAX_PLATFORM_TYPES; p++) {
149       EnvPtr->GetPlatformCfg[p] = NBPtr->MemPtr->GetPlatformCfg[p];
150     }
151     EnvPtr->ErrorHandling = NBPtr->MemPtr->ErrorHandling;
152     EnvPtr->NBBlockCtor = MemConstructRemoteNBBlockC32;
153     EnvPtr->FeatPtr = NBPtr->FeatPtr;
154     EnvPtr->HoleBase = NBPtr->RefPtr->HoleBase;
155     EnvPtr->BottomIo = NBPtr->RefPtr->BottomIo;
156     EnvPtr->UmaSize = NBPtr->RefPtr->UmaSize;
157     EnvPtr->SysLimit = NBPtr->RefPtr->SysLimit;
158     EnvPtr->TableBasedAlterations = NBPtr->RefPtr->TableBasedAlterations;
159     EnvPtr->PlatformMemoryConfiguration = NBPtr->RefPtr->PlatformMemoryConfiguration;
160
161     LibAmdMemCopy (AllocHeapParams.BufferPtr, MCTPtr->DctData, MctDataSize, StdHeader);
162
163     //
164     // Get Socket, Core of the BSP
165     //
166     IdentifyCore (StdHeader, &BspSocket, &BspModule, &BspCore, &Status);
167     EnvPtr->BspSocket = ((UINT8)BspSocket & 0x000000FF);
168     EnvPtr->BspCore = ((UINT8)BspCore & 0x000000FF);
169
170     //
171     // Set up the remote task structure
172     //
173     TrainingTask.DataTransfer.DataPtr = EnvPtr;
174     TrainingTask.DataTransfer.DataSizeInDwords = (UINT16) (AllocHeapParams.RequestedBufferSize + 3) / 4;
175     TrainingTask.DataTransfer.DataTransferFlags = 0;
176     TrainingTask.ExeFlags = 0;
177     TrainingTask.FuncAddress.PfApTaskI = (PF_AP_TASK_I)MemFParallelTraining;
178
179     //
180     // Get Target AP Core
181     //
182     GetGivenModuleCoreRange (Socket, Module, &LowCore, &HighCore, StdHeader);
183     APCore = (UINT8) (LowCore & 0x000000FF);
184
185     //
186     // Launch Remote Training
187     //
188     ApUtilRunCodeOnSocketCore (Socket, APCore, &TrainingTask, StdHeader);
189
190     HeapDeallocateBuffer (AllocHeapParams.BufferHandle, StdHeader);
191
192     return TRUE;
193   } else {
194     PutEventLog (AGESA_FATAL, MEM_ERROR_HEAP_ALLOCATE_FOR_REMOTE_TRAINING_ENV, NBPtr->Node, 0, 0, 0, StdHeader);
195     SetMemError (AGESA_FATAL, MCTPtr);
196     ASSERT(FALSE); // Could not allocated heap space for "REMOTE_TRAINING_ENV"
197     return FALSE;
198   }
199 }
200
201 BOOLEAN
202 STATIC
203 MemConstructRemoteNBBlockC32 (
204   IN OUT   MEM_NB_BLOCK *NBPtr,
205   IN       DIE_STRUCT *MCTPtr,
206   IN       MEM_FEAT_BLOCK_NB *FeatPtr
207   )
208 {
209   CPU_SPECIFIC_SERVICES *FamilySpecificServices;
210
211   NBPtr->MCTPtr = MCTPtr;
212   NBPtr->PciAddr.AddressValue = MCTPtr->PciAddr.AddressValue;
213
214   MemNInitNBDataC32 (NBPtr);
215
216   FeatPtr->InitCPG (NBPtr);
217   NBPtr->FeatPtr = FeatPtr;
218   FeatPtr->InitHwRxEn (NBPtr);
219   MemNSwitchDCTNb (NBPtr, 0);
220
221   //----------------------------------------------------------------------------
222   // Get TSC rate of the this AP
223   //----------------------------------------------------------------------------
224   GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, &NBPtr->MemPtr->StdHeader);
225   FamilySpecificServices->GetTscRate (FamilySpecificServices, &NBPtr->MemPtr->TscRate, &NBPtr->MemPtr->StdHeader);
226
227   return TRUE;
228 }