summaryrefslogtreecommitdiffstats
path: root/src/vendorcode/amd/agesa/f15tn/Proc/Common/CreateStruct.c
blob: f99bd66ff618abfabc410b2bf554b6f2b3488243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* $NoKeywords:$ */
/**
 * @file
 *
 * AMD AGESA Input Structure Creation
 *
 * Contains AGESA input structure creation support.
 *
 * @xrefitem bom "File Content Label" "Release Content"
 * @e project:      AGESA
 * @e sub-project:  Common
 * @e \$Revision: 63425 $   @e \$Date: 2011-12-22 11:24:10 -0600 (Thu, 22 Dec 2011) $
 *
 */
/*
 ******************************************************************************
 *
 * Copyright (c) 2008 - 2012, Advanced Micro Devices, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
 *       its contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ******************************************************************************
 */

/*----------------------------------------------------------------------------------------
 *                             M O D U L E S    U S E D
 *----------------------------------------------------------------------------------------
 */
#include "AGESA.h"
#include "amdlib.h"
#include "Ids.h"
#include "GeneralServices.h"
#include "heapManager.h"
#include "CreateStruct.h"
#include "cpuFamilyTranslation.h"
#include "Filecode.h"
CODE_GROUP (G1_PEICC)
RDATA_GROUP (G1_PEICC)

#define FILECODE PROC_COMMON_CREATESTRUCT_FILECODE
/*----------------------------------------------------------------------------------------
 *                   D E F I N I T I O N S    A N D    M A C R O S
 *----------------------------------------------------------------------------------------
 */
extern CONST FUNCTION_PARAMS_INFO FuncParamsInfo[];
extern CONST UINTN InitializerCount;

/*----------------------------------------------------------------------------------------
 *                  T Y P E D E F S     A N D     S T R U C T U  R E S
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------
 *           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
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------
 *                          E X P O R T E D    F U N C T I O N S
 *----------------------------------------------------------------------------------------
 */
extern BUILD_OPT_CFG UserOptions;

/*---------------------------------------------------------------------------------------*/
/**
 * Allocate and initialize Config headers and Service Interface structures.
 *
 * This function will be called for each AGESA public APIs.
 * This function will do the following:
 * -# Locate the AGESA API structure parameters initializer function information.
 * -# Find the size of the structure that gets passed to each public APIs as
 *    the entry parameter. Allocate heap space using the size for PreMemHeap, callout for
 *    memory allocation for PostMemDram, and just set the config and service interface
 *    pointers for ByHost.
 * -# If the allocation is not ByHost, copy the AmdConfigParams into the newly created AmdConfigParams.
 *    For ByHost, we're using the caller's existing config params.
 * -# Call the initializer function, and pass a reference to the Config params and to
 *    the Service Interface struct.  On return the constructor will have filled the
 *    remaining structure with default values.
 * -# Fill the remaining info in the newly created structure on heap in AMD_CONFIG_PARAMS
 *    area (i.e. Fill *newStructPtr with the pointer to the newly created structure)
 * -# Set the appropriate AGESA function number in the StdHeader member of the input
 *    parameter structure.
 *
 * @param[in,out]  InterfaceParams         Pointer to structure containing the function call
 *                                         whose parameter structure is to be created, the
 *                                         allocation method, and a pointer to the newly
 *                                         created structure.
 *
 * @retval         AGESA_SUCCESS           The interface struct is allocated and initialized.
 * @retval         AGESA_UNSUPPORTED       The Service is not supported.
 *
 */
AGESA_STATUS
AmdCreateStruct (
  IN OUT   AMD_INTERFACE_PARAMS *InterfaceParams
  )
{
  UINTN                     ServiceIndex;
  ALLOCATE_HEAP_PARAMS      AllocHeapParams;
  AMD_CONFIG_PARAMS         *NewlyCreatedConfig;
  VOID                      *NewlyCreatedServiceInterface;
  AGESA_STATUS              AgesaStatus;
  AGESA_STATUS              TempStatus;
  AGESA_STATUS              IgnoredSts;
  CPU_SPECIFIC_SERVICES     *FamilySpecificServices;

  AgesaStatus = AGESA_SUCCESS;

  ASSERT (InterfaceParams != NULL);

  switch (InterfaceParams->AgesaFunctionName) {
  case AMD_INIT_RESET:
    if (!IsBsp (&InterfaceParams->StdHeader, &IgnoredSts)) {
      // APs must transfer their system core number from the mailbox to
      // a local register while it is still valid.
      GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, &InterfaceParams->StdHeader);
      FamilySpecificServices->TransferApCoreNumber (FamilySpecificServices, &InterfaceParams->StdHeader);
    }
    InterfaceParams->StdHeader.HeapStatus = HEAP_DO_NOT_EXIST_YET;
    break;
  case AMD_INIT_EARLY:
  case AMD_INIT_RECOVERY:
  case AMD_INIT_RESUME:
  case AMD_INIT_POST:
    InterfaceParams->StdHeader.HeapStatus = HEAP_LOCAL_CACHE;
    break;
  case AMD_INIT_ENV:
    InterfaceParams->StdHeader.HeapStatus = HEAP_TEMP_MEM;
    break;
  case AMD_INIT_LATE:
  case AMD_INIT_MID:
  case AMD_S3_SAVE:
  case AMD_LATE_RUN_AP_TASK:
    InterfaceParams->StdHeader.HeapStatus = HEAP_SYSTEM_MEM;
    break;
  case AMD_S3LATE_RESTORE:
    InterfaceParams->StdHeader.HeapStatus = HEAP_S3_RESUME;
    break;
  default:
    ASSERT (FALSE);
    InterfaceParams->StdHeader.HeapStatus = HEAP_LOCAL_CACHE;
    break;
  }

  InterfaceParams->StdHeader.HeapBasePtr = HeapGetBaseAddress (&InterfaceParams->StdHeader);

  if (InterfaceParams->AgesaFunctionName == AMD_INIT_RESET) {
    AgesaStatus = HeapManagerInit (&InterfaceParams->StdHeader);
  }

  // Step 1
  for (ServiceIndex = 0; ServiceIndex < InitializerCount; ServiceIndex++) {
    if (FuncParamsInfo[ServiceIndex].AgesaFunctionName == InterfaceParams->AgesaFunctionName) {
      break;
    }
  }
  if (ServiceIndex >= InitializerCount) {
    // A call was made to AGESA with an invalid function number.  This wrapper error may be due to the build target
    // not containing the desired entry point.
    return AGESA_UNSUPPORTED;
  }

  // Step 2
  LibAmdMemFill (&AllocHeapParams, 0, (UINTN) (sizeof (ALLOCATE_HEAP_PARAMS)), &InterfaceParams->StdHeader);

  if (InterfaceParams->AllocationMethod < ByHost) {
    // Allocate one buffer to contain the config params and the service struct.
    // The service struct begins immediately after the config params.
    AllocHeapParams.RequestedBufferSize = FuncParamsInfo[ServiceIndex].CreateStructSize + sizeof (AMD_CONFIG_PARAMS);
    AllocHeapParams.BufferHandle = FuncParamsInfo[ServiceIndex].BufferHandle;
    AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
    TempStatus = HeapAllocateBuffer (&AllocHeapParams, &(InterfaceParams->StdHeader));
    AgesaStatus = ((AgesaStatus > TempStatus) ? AgesaStatus : TempStatus);
    NewlyCreatedConfig = (AMD_CONFIG_PARAMS *)AllocHeapParams.BufferPtr;
    NewlyCreatedConfig++;
    NewlyCreatedServiceInterface =  NewlyCreatedConfig;
    NewlyCreatedConfig = (AMD_CONFIG_PARAMS *)AllocHeapParams.BufferPtr;
  } else {
    // The caller (example, agesa basic interface implementation) already has a buffer to use.
    NewlyCreatedConfig = (AMD_CONFIG_PARAMS *)InterfaceParams;
    NewlyCreatedServiceInterface = InterfaceParams->NewStructPtr;
    ASSERT (InterfaceParams->NewStructSize >= FuncParamsInfo[ServiceIndex].CreateStructSize);
  }
  ASSERT (NewlyCreatedConfig != NULL);
  ASSERT (NewlyCreatedServiceInterface != NULL);

  // Step 3
  if (InterfaceParams->AllocationMethod != ByHost) {
    *NewlyCreatedConfig = InterfaceParams->StdHeader;
  }

  // Step 4
  TempStatus = FuncParamsInfo[ServiceIndex].AgesaFunction (NewlyCreatedConfig, NewlyCreatedServiceInterface);
  AgesaStatus = ((AgesaStatus > TempStatus) ? AgesaStatus : TempStatus);

  // Step 5
  if (InterfaceParams->AllocationMethod != ByHost) {
    InterfaceParams->NewStructPtr = (VOID *) NewlyCreatedServiceInterface;
    InterfaceParams->NewStructSize = FuncParamsInfo[ServiceIndex].CreateStructSize;
  }

  // Step 6
  ((AMD_CONFIG_PARAMS *) InterfaceParams->NewStructPtr)->Func = InterfaceParams->AgesaFunctionName;
  return AgesaStatus;
}


/*---------------------------------------------------------------------------------------*/
/**
 *  Clears storage space from allocation for a parameter block of an
 *  AGESA software call entry.
 *
 *  @param[in,out]  InterfaceParams         Pointer to structure containing the function call
 *                                          whose parameter structure is to be deallocated.
 *
 *  @retval         AGESA_STATUS
 *
 *---------------------------------------------------------------------------------------
 **/
AGESA_STATUS
AmdReleaseStruct (
  IN OUT   AMD_INTERFACE_PARAMS *InterfaceParams
  )
{
  UINT8 i;
  UINT8 *BufferPtr;
  VOID  *ServicePtr;
  AGESA_STATUS  AgesaStatus;
  AGESA_STATUS  TempStatus;
  LOCATE_HEAP_PTR LocHeap;

  AgesaStatus = AGESA_SUCCESS;

  switch (InterfaceParams->AgesaFunctionName) {
  case AMD_INIT_RESET:
  case AMD_INIT_EARLY:
  case AMD_INIT_RECOVERY:
  case AMD_INIT_RESUME:
    InterfaceParams->StdHeader.HeapStatus = HEAP_LOCAL_CACHE;
    break;
  case AMD_INIT_POST:
    InterfaceParams->StdHeader.HeapStatus = HEAP_TEMP_MEM;
    break;
  case AMD_INIT_ENV:
  case AMD_INIT_LATE:
  case AMD_INIT_MID:
  case AMD_S3_SAVE:
  case AMD_LATE_RUN_AP_TASK:
    InterfaceParams->StdHeader.HeapStatus = HEAP_SYSTEM_MEM;
    break;
  case AMD_S3LATE_RESTORE:
    InterfaceParams->StdHeader.HeapStatus = HEAP_S3_RESUME;
    break;
  default:
    ASSERT (FALSE);
    InterfaceParams->StdHeader.HeapStatus = HEAP_LOCAL_CACHE;
    break;
  }

  InterfaceParams->StdHeader.HeapBasePtr = HeapGetBaseAddress (&InterfaceParams->StdHeader);

// Step 1
  for (i = 0; i < InitializerCount; i++) {
    if (FuncParamsInfo[i].AgesaFunctionName == InterfaceParams->AgesaFunctionName) {
      break;
    }
  }
  if (i >= InitializerCount) {
    return AGESA_BOUNDS_CHK;
  }

  // Step 2
  if (InterfaceParams->AllocationMethod < ByHost) {
    LocHeap.BufferHandle = FuncParamsInfo[i].BufferHandle;
    if (HeapLocateBuffer (&LocHeap, &(InterfaceParams->StdHeader)) == AGESA_SUCCESS) {
      BufferPtr = (UINT8 *) LocHeap.BufferPtr;
      ServicePtr = &BufferPtr[sizeof (AMD_CONFIG_PARAMS)];
      TempStatus = FuncParamsInfo[i].AgesaDestructor (&(InterfaceParams->StdHeader), ServicePtr);
      AgesaStatus = ((AgesaStatus > TempStatus) ? AgesaStatus : TempStatus);
    }
  }

  // Step 3
  if (InterfaceParams->AllocationMethod < ByHost) {
    TempStatus = HeapDeallocateBuffer (FuncParamsInfo[i].BufferHandle, &(InterfaceParams->StdHeader));
    AgesaStatus = ((AgesaStatus > TempStatus) ? AgesaStatus : TempStatus);
  } else {
    // Unless we define service specific destructors, nothing to do for ByHost.
    return AGESA_SUCCESS;
  }
  return AgesaStatus;
}
OpenPOWER on IntegriCloud