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