summaryrefslogtreecommitdiff
path: root/src/vendorcode/amd/agesa/Proc/CPU/cpuFamilyTranslation.c
blob: 7882c58e204644c3b9c41d4f490b6939ae9200dd (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/* $NoKeywords:$ */
/**
 * @file
 *
 * AMD CPU Family Translation functions.
 *
 *
 * @xrefitem bom "File Content Label" "Release Content"
 * @e project:      AGESA
 * @e sub-project:  CPU/Interface
 * @e \$Revision: 37150 $   @e \$Date: 2010-08-31 23:53:37 +0800 (Tue, 31 Aug 2010) $
 *
 */
/*
 *****************************************************************************
 *
 * Copyright (c) 2011, 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 "cpuRegisters.h"
#include "CommonReturns.h"
#include "GeneralServices.h"
#include "cpuFamilyTranslation.h"
#include "Filecode.h"
CODE_GROUP (G1_PEICC)
RDATA_GROUP (G1_PEICC)

#define FILECODE PROC_CPU_CPUFAMILYTRANSLATION_FILECODE

/*----------------------------------------------------------------------------------------
 *                   D E F I N I T I O N S    A N D    M A C R O S
 *----------------------------------------------------------------------------------------
 */

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

CONST CPU_SPECIFIC_SERVICES ROMDATA cpuNullServices =
{
  0,
  (PF_CPU_DISABLE_PSTATE) CommonReturnAgesaSuccess,
  (PF_CPU_TRANSITION_PSTATE) CommonReturnAgesaSuccess,
  (PF_CPU_GET_IDD_MAX) CommonReturnFalse,
  (PF_CPU_GET_TSC_RATE) CommonReturnAgesaSuccess,
  (PF_CPU_GET_NB_FREQ) CommonReturnAgesaSuccess,
  (PF_CPU_GET_NB_PSTATE_INFO) CommonReturnFalse,
  (PF_CPU_IS_NBCOF_INIT_NEEDED) CommonReturnAgesaSuccess,
  (PF_CPU_AP_INITIAL_LAUNCH) CommonReturnFalse,
  (PF_CPU_NUMBER_OF_BRANDSTRING_CORES) CommonReturnZero8,
  (PF_CPU_AMD_GET_AP_MAILBOX_FROM_HARDWARE) CommonReturnAgesaSuccess,
  (PF_CPU_SET_AP_CORE_NUMBER) CommonVoid,
  (PF_CPU_GET_AP_CORE_NUMBER) CommonReturnZero32,
  (PF_CPU_TRANSFER_AP_CORE_NUMBER) CommonVoid,
  (PF_CORE_ID_POSITION_IN_INITIAL_APIC_ID) CommonReturnAgesaSuccess,
  (PF_CPU_SAVE_FEATURES) CommonReturnAgesaSuccess,
  (PF_CPU_WRITE_FEATURES) CommonReturnAgesaSuccess,
  (PF_CPU_SET_WARM_RESET_FLAG) CommonReturnAgesaSuccess,
  (PF_CPU_GET_WARM_RESET_FLAG) CommonReturnAgesaSuccess,
  GetEmptyArray,
  GetEmptyArray,
  GetEmptyArray,
  GetEmptyArray,
  GetEmptyArray,
  GetEmptyArray,
  GetEmptyArray,
  (PF_CPU_GET_PLATFORM_TYPE_SPECIFIC_INFO) CommonReturnAgesaSuccess,
  (PF_IS_NB_PSTATE_ENABLED) CommonReturnFalse,
  (PF_NEXT_LINK_HAS_HTFPY_FEATS) CommonReturnFalse,
  (PF_SET_HT_PHY_REGISTER) CommonVoid,
  (PF_GET_NEXT_HT_LINK_FEATURES) CommonVoid,
  NULL,
  NULL,
  NULL,
  NULL,
  InitCacheDisabled,
  (PF_GET_EARLY_INIT_TABLE) CommonVoid
};

/*----------------------------------------------------------------------------------------
 *           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
 *----------------------------------------------------------------------------------------
 */
VOID
STATIC
GetCpuServices (
  IN       CPU_FAMILY_SUPPORT_TABLE *FamilyTable,
  IN       UINT64            *MatchData,
     OUT   CONST VOID        **CpuServices,
  IN       AMD_CONFIG_PARAMS *StdHeader
  );

/*----------------------------------------------------------------------------------------
 *                          E X P O R T E D    F U N C T I O N S
 *----------------------------------------------------------------------------------------
 */
extern CPU_FAMILY_SUPPORT_TABLE CpuSupportedFamiliesTable;
extern CPU_FAMILY_ID_XLAT_TABLE CpuSupportedFamilyIdTable;

/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Returns the logical ID of the desired processor. This will be obtained by
 *  reading the CPUID and converting it into a "logical ID" which is not package
 *  dependent.
 *
 *  @param[in]      Socket             Socket
 *  @param[out]     LogicalId          The Processor's Logical ID
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetLogicalIdOfSocket (
  IN       UINT32 Socket,
     OUT   CPU_LOGICAL_ID *LogicalId,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  UINT32      RawCpuid;
  PCI_ADDR    PciAddress;
  AGESA_STATUS AssumedSuccess;

  RawCpuid = 0;

  if (GetPciAddress (StdHeader, (UINT8)Socket, 0, &PciAddress, &AssumedSuccess)) {
    PciAddress.Address.Function = FUNC_3;
    PciAddress.Address.Register = CPUID_FMR;
    LibAmdPciRead (AccessWidth32, PciAddress, &RawCpuid, StdHeader);
    GetLogicalIdFromCpuid (RawCpuid, LogicalId, StdHeader);
  } else {
    LogicalId->Family = 0;
    LogicalId->Revision = 0;
    // Logical ID was not found.
    IDS_ERROR_TRAP;
  }
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Returns the logical ID of the executing core. This will be obtained by reading
 *  the CPUID and converting it into a "logical ID" which is not package dependent.
 *
 *  @param[out]     LogicalId          The Processor's Logical ID
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetLogicalIdOfCurrentCore (
     OUT   CPU_LOGICAL_ID *LogicalId,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  CPUID_DATA  CpuidDataStruct;

  LibAmdCpuidRead (AMD_CPUID_APICID_LPC_BID, &CpuidDataStruct, StdHeader);
  GetLogicalIdFromCpuid (CpuidDataStruct.EAX_Reg, LogicalId, StdHeader);
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Returns the logical ID of a processor with the given CPUID value. This
 *  will be obtained by converting it into a "logical ID" which is not package
 *  dependent.
 *
 *  @param[in]      RawCpuid           The unprocessed CPUID value to be translated
 *  @param[out]     LogicalId          The Processor's Logical ID
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services
 *
 */
VOID
GetLogicalIdFromCpuid (
  IN       UINT32 RawCpuid,
     OUT   CPU_LOGICAL_ID *LogicalId,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  UINT8       i;
  UINT8       k;
  UINT8       NumberOfFamiliesSupported;
  UINT8       NumberOfLogicalSubFamilies;
  UINT8       LogicalIdEntries;
  UINT32      j;
  UINT32      RawFamily;
  UINT32      CpuModelAndExtendedModel;
  UINT64      LogicalFamily;
  BOOLEAN     IdNotFound;
  BOOLEAN     FamilyNotFound;
  CONST PF_CPU_GET_SUBFAMILY_ID_ARRAY *SubFamilyIdPtr;
  CPU_LOGICAL_ID_XLAT *CpuLogicalIdAndRevPtr;
  CONST CPU_LOGICAL_ID_FAMILY_XLAT *ImageSupportedId;

  IdNotFound = TRUE;
  FamilyNotFound = TRUE;
  CpuLogicalIdAndRevPtr = NULL;
  ImageSupportedId = CpuSupportedFamilyIdTable.FamilyIdTable;
  NumberOfFamiliesSupported = CpuSupportedFamilyIdTable.Elements;

  RawFamily = ((RawCpuid & 0xF00) >> 8) + ((RawCpuid & 0xFF00000) >> 20);
  RawCpuid &= (UINT32) CPU_FMS_MASK;
  CpuModelAndExtendedModel = (UINT16) ((RawCpuid >> 8) | RawCpuid);

  LogicalId->Family = 0;
  LogicalId->Revision = 0;

  for (i = 0; i < NumberOfFamiliesSupported && FamilyNotFound; i++) {
    if (ImageSupportedId[i].Family == RawFamily) {
      FamilyNotFound = FALSE;
      LogicalId->Family = ImageSupportedId[i].UnknownRevision.Family;
      LogicalId->Revision = ImageSupportedId[i].UnknownRevision.Revision;

      NumberOfLogicalSubFamilies = ImageSupportedId[i].Elements;
      SubFamilyIdPtr = ImageSupportedId[i].SubFamilyIdTable;
      for (j = 0; j < NumberOfLogicalSubFamilies && IdNotFound; j++) {
        SubFamilyIdPtr[j] (&CpuLogicalIdAndRevPtr, &LogicalIdEntries, &LogicalFamily, StdHeader);
        ASSERT (CpuLogicalIdAndRevPtr != NULL);
        for (k = 0; k < LogicalIdEntries; k++) {
          if (CpuLogicalIdAndRevPtr[k].RawId == CpuModelAndExtendedModel) {
            IdNotFound = FALSE;
            LogicalId->Family = LogicalFamily;
            LogicalId->Revision = CpuLogicalIdAndRevPtr[k].LogicalId;
            break;
          }
        }
      }
    }
  }
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the desired processor's family specific services structure.
 *
 *  @param[in]      Socket             The Processor in this Socket.
 *  @param[out]     FunctionTable      The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetCpuServicesOfSocket (
  IN       UINT32 Socket,
     OUT   CONST CPU_SPECIFIC_SERVICES **FunctionTable,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  GetFeatureServicesOfSocket (&CpuSupportedFamiliesTable,
                              Socket,
                              FunctionTable,
                              StdHeader);
  if (*FunctionTable == NULL) {
    *FunctionTable = &cpuNullServices;
  }
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the desired processor's family specific services structure.
 *
 *  @param[in]      FamilyTable        The table to search in.
 *  @param[in]      Socket             The Processor in this Socket.
 *  @param[out]     CpuServices        The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetFeatureServicesOfSocket (
  IN       CPU_FAMILY_SUPPORT_TABLE *FamilyTable,
  IN       UINT32            Socket,
     OUT   CONST VOID        **CpuServices,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  CPU_LOGICAL_ID CpuFamilyRevision;

  GetLogicalIdOfSocket (Socket, &CpuFamilyRevision, StdHeader);
  GetFeatureServicesFromLogicalId (FamilyTable, &CpuFamilyRevision, CpuServices, StdHeader);
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the executing core's family specific services structure.
 *
 *  @param[out]     FunctionTable      The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetCpuServicesOfCurrentCore (
     OUT   CONST CPU_SPECIFIC_SERVICES **FunctionTable,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  GetFeatureServicesOfCurrentCore (&CpuSupportedFamiliesTable,
                                   FunctionTable,
                                   StdHeader);
  if (*FunctionTable == NULL) {
    *FunctionTable = &cpuNullServices;
  }
}

/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the family specific services structure for a processor
 *  with the given logical ID.
 *
 *  @param[in]      FamilyTable        The table to search in.
 *  @param[out]     CpuServices        The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetFeatureServicesOfCurrentCore (
  IN       CPU_FAMILY_SUPPORT_TABLE *FamilyTable,
     OUT   CONST VOID        **CpuServices,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  CPU_LOGICAL_ID CpuFamilyRevision;

  GetLogicalIdOfCurrentCore (&CpuFamilyRevision, StdHeader);
  GetFeatureServicesFromLogicalId (FamilyTable, &CpuFamilyRevision, CpuServices, StdHeader);
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the family specific services structure for a processor
 *  with the given logical ID.
 *
 *  @param[in]      LogicalId          The Processor's logical ID.
 *  @param[out]     FunctionTable      The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetCpuServicesFromLogicalId (
  IN       CPU_LOGICAL_ID *LogicalId,
     OUT   CONST CPU_SPECIFIC_SERVICES **FunctionTable,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  GetFeatureServicesFromLogicalId (&CpuSupportedFamiliesTable,
                                   LogicalId,
                                   FunctionTable,
                                   StdHeader);
  if (*FunctionTable == NULL) {
    *FunctionTable = &cpuNullServices;
  }
}

/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Retrieves a pointer to the family specific services structure for a processor
 *  with the given logical ID.
 *
 *  @param[in]      FamilyTable        The table to search in.
 *  @param[in]      LogicalId          The Processor's logical ID.
 *  @param[out]     CpuServices        The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
GetFeatureServicesFromLogicalId (
  IN       CPU_FAMILY_SUPPORT_TABLE *FamilyTable,
  IN       CPU_LOGICAL_ID    *LogicalId,
     OUT   CONST VOID        **CpuServices,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  GetCpuServices (FamilyTable, &LogicalId->Family, CpuServices, StdHeader);
}


/*---------------------------------------------------------------------------------------*/
/**
 *
 *  Finds a family match in the given table, and returns the pointer to the
 *  appropriate table.  If no match is found in the table, NULL will be returned.
 *
 *  @param[in]      FamilyTable        The table to search in.
 *  @param[in]      MatchData          Family data that must match.
 *  @param[out]     CpuServices        The Processor's Family Specific services.
 *  @param[in]      StdHeader          Handle of Header for calling lib functions and services.
 *
 */
VOID
STATIC
GetCpuServices (
  IN       CPU_FAMILY_SUPPORT_TABLE *FamilyTable,
  IN       UINT64            *MatchData,
     OUT   CONST VOID        **CpuServices,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  BOOLEAN IsFamily;
  UINT8   i;
  UINT8   NumberOfFamiliesSupported;
  CONST CPU_SPECIFIC_SERVICES_XLAT *ImageSupportedFamiliesPtr;

  ImageSupportedFamiliesPtr = FamilyTable->FamilyTable;
  NumberOfFamiliesSupported = FamilyTable->Elements;
  IsFamily = FALSE;
  for (i = 0; i < NumberOfFamiliesSupported; i++) {
    if ((ImageSupportedFamiliesPtr[i].Family & *MatchData) != 0) {
      IsFamily = TRUE;
      break;
    }
  }
  if (IsFamily) {
    *CpuServices = ImageSupportedFamiliesPtr[i].TablePtr;
  } else {
    *CpuServices = NULL;
  }
}


/*---------------------------------------------------------------------------------------*/
/**
 *  Used to stub out various family specific tables of information.
 *
 *  @param[in]      FamilySpecificServices  The current Family Specific Services.
 *  @param[in]      Empty                   NULL, to indicate no data.
 *  @param[out]     NumberOfElements        Zero, to indicate no data.
 *  @param[in]      StdHeader               Handle of Header for calling lib functions and services.
 *
 */
VOID
GetEmptyArray (
  IN       CPU_SPECIFIC_SERVICES  *FamilySpecificServices,
     OUT   CONST VOID **Empty,
     OUT   UINT8 *NumberOfElements,
  IN       AMD_CONFIG_PARAMS *StdHeader
  )
{
  *NumberOfElements = 0;
  *Empty = NULL;
}