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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
/* $NoKeywords:$ */
/**
* @file
*
* mfs3.c
*
* Main S3 resume memory Entrypoint file
*
* @xrefitem bom "File Content Label" "Release Content"
* @e project: AGESA
* @e sub-project: (Mem/FEAT/S3)
* @e \$Revision: 54775 $ @e \$Date: 2011-06-12 21:05:26 -0600 (Sun, 12 Jun 2011) $
*
**/
/*****************************************************************************
*
* Copyright (C) 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.
*
* ***************************************************************************
*
*/
/*
*----------------------------------------------------------------------------
* MODULES USED
*
*----------------------------------------------------------------------------
*/
#include "AGESA.h"
#include "Ids.h"
#include "cpuRegisters.h"
#include "OptionMemory.h"
#include "mm.h"
#include "mn.h"
#include "S3.h"
#include "mfs3.h"
#include "heapManager.h"
#include "amdlib.h"
#include "GeneralServices.h"
#include "cpuFamilyTranslation.h"
#include "Filecode.h"
CODE_GROUP (G2_PEI)
RDATA_GROUP (G2_PEI)
#define FILECODE PROC_MEM_FEAT_S3_MFS3_FILECODE
extern MEM_NB_SUPPORT memNBInstalled[];
/*----------------------------------------------------------------------------
* DEFINITIONS AND MACROS
*
*----------------------------------------------------------------------------
*/
/*----------------------------------------------------------------------------
* TYPEDEFS AND STRUCTURES
*
*----------------------------------------------------------------------------
*/
/*----------------------------------------------------------------------------
* PROTOTYPES OF LOCAL FUNCTIONS
*
*----------------------------------------------------------------------------
*/
/*----------------------------------------------------------------------------
* EXPORTED FUNCTIONS
*
*----------------------------------------------------------------------------
*/
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function is the main memory entry point for the S3 resume sequence
* Requirements:
*
* Run-Time Requirements:
* 1. Complete Hypertransport Bus Configuration
* 4. BSP in Big Real Mode
* 5. Stack available
*
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
AmdMemS3Resume (
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
MEM_MAIN_DATA_BLOCK mmData;
S3_MEM_NB_BLOCK *S3NBPtr;
MEM_DATA_STRUCT *MemData;
UINT8 Die;
UINT8 DieCount;
//---------------------------------------------
// Creation of NB Block for S3 resume
//---------------------------------------------
RetVal = MemS3InitNB (&S3NBPtr, &MemData, &mmData, StdHeader);
if (RetVal == AGESA_FATAL) {
return RetVal;
}
DieCount = mmData.DieCount;
//---------------------------------------------
//1. Errata Before resume sequence
//2. S3 Resume sequence
//3. Errata After resume sequence
//---------------------------------------------
for (Die = 0; Die < DieCount; Die ++) {
if (!S3NBPtr[Die].MemS3Resume (&S3NBPtr[Die], Die)) {
return AGESA_FATAL;
}
S3NBPtr[Die].MemS3RestoreScrub (S3NBPtr[Die].NBPtr, Die);
}
HeapDeallocateBuffer (AMD_MEM_S3_DATA_HANDLE, StdHeader);
return AGESA_SUCCESS;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function deallocates heap space allocated in memory S3 resume.
*
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemS3Deallocate (
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
AGESA_STATUS tempRetVal;
UINT8 Tab;
RetVal = AGESA_SUCCESS;
for (Tab = 0; Tab < NumberOfNbRegTables; Tab++) {
HeapDeallocateBuffer (GENERATE_MEM_HANDLE (ALLOC_NB_REG_TABLE, Tab, 0, 0), StdHeader);
}
tempRetVal = HeapDeallocateBuffer (GENERATE_MEM_HANDLE (ALLOC_DIE_STRUCT_HANDLE, 0, 0, 0), StdHeader);
if (tempRetVal > RetVal) {
RetVal = tempRetVal;
}
tempRetVal = HeapDeallocateBuffer (AMD_MEM_AUTO_HANDLE, StdHeader);
if (tempRetVal > RetVal) {
RetVal = tempRetVal;
}
RetVal = HeapDeallocateBuffer (AMD_MEM_S3_NB_HANDLE, StdHeader);
if (tempRetVal > RetVal) {
RetVal = tempRetVal;
}
RetVal = HeapDeallocateBuffer (AMD_MEM_DATA_HANDLE, StdHeader);
if (tempRetVal > RetVal) {
RetVal = tempRetVal;
}
return RetVal;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function is the entrance to get device list for memory registers.
*
* @param[in, out] **DeviceBlockHdrPtr - Pointer to the memory containing the
* device descriptor list
* @param[in] *StdHeader - Config handle for library and services
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemFS3GetDeviceList (
IN OUT DEVICE_BLOCK_HEADER **DeviceBlockHdrPtr,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
UINT8 i;
UINT16 BufferSize;
UINT64 BufferOffset;
S3_MEM_NB_BLOCK *S3NBPtr;
MEM_DATA_STRUCT *MemData;
MEM_MAIN_DATA_BLOCK mmData;
UINT8 Die;
UINT8 DieCount;
AGESA_STATUS RetVal;
ALLOCATE_HEAP_PARAMS AllocHeapParams;
DESCRIPTOR_GROUP DeviceDescript[MAX_NODES_SUPPORTED];
BufferSize = 0;
//---------------------------------------------
// Creation of NB Block for S3 resume
//---------------------------------------------
RetVal = MemS3InitNB (&S3NBPtr, &MemData, &mmData, StdHeader);
if (RetVal == AGESA_FATAL) {
return RetVal;
}
DieCount = mmData.DieCount;
// Get the mask bit and the register list for node that presents
for (Die = 0; Die < DieCount; Die ++) {
S3NBPtr->MemS3GetConPCIMask (S3NBPtr[Die].NBPtr, (VOID *)&DeviceDescript[Die]);
S3NBPtr->MemS3GetConMSRMask (S3NBPtr[Die].NBPtr, (VOID *)&DeviceDescript[Die]);
BufferSize = BufferSize + S3NBPtr->MemS3GetRegLstPtr (S3NBPtr[Die].NBPtr, (VOID *)&DeviceDescript[Die]);
}
// Base on the size of the device list, apply for a buffer for it.
AllocHeapParams.RequestedBufferSize = BufferSize + sizeof (DEVICE_BLOCK_HEADER);
AllocHeapParams.BufferHandle = AMD_S3_NB_INFO_BUFFER_HANDLE;
AllocHeapParams.Persist = HEAP_S3_RESUME;
AGESA_TESTPOINT (TpIfBeforeAllocateMemoryS3SaveBuffer, StdHeader);
if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) != AGESA_SUCCESS) {
return AGESA_FATAL;
}
AGESA_TESTPOINT (TpIfAfterAllocateMemoryS3SaveBuffer, StdHeader);
*DeviceBlockHdrPtr = (DEVICE_BLOCK_HEADER *) AllocHeapParams.BufferPtr;
(*DeviceBlockHdrPtr)->RelativeOrMaskOffset = (UINT16) AllocHeapParams.RequestedBufferSize;
// Copy device list on the stack to the heap.
BufferOffset = sizeof (DEVICE_BLOCK_HEADER) + (UINT64) AllocHeapParams.BufferPtr;
for (Die = 0; Die < DieCount; Die ++) {
for (i = PRESELFREF; i <= POSTSELFREF; i ++) {
// Copy PCI device descriptor to the heap if it exists.
if (DeviceDescript[Die].PCIDevice[i].RegisterListID != 0xFFFFFFFF) {
LibAmdMemCopy ((VOID *) BufferOffset, &(DeviceDescript[Die].PCIDevice[i]), sizeof (PCI_DEVICE_DESCRIPTOR), StdHeader);
(*DeviceBlockHdrPtr)->NumDevices ++;
BufferOffset += sizeof (PCI_DEVICE_DESCRIPTOR);
}
// Copy conditional PCI device descriptor to the heap if it exists.
if (DeviceDescript[Die].CPCIDevice[i].RegisterListID != 0xFFFFFFFF) {
LibAmdMemCopy ((VOID *) BufferOffset, &(DeviceDescript[Die].CPCIDevice[i]), sizeof (CONDITIONAL_PCI_DEVICE_DESCRIPTOR), StdHeader);
(*DeviceBlockHdrPtr)->NumDevices ++;
BufferOffset += sizeof (CONDITIONAL_PCI_DEVICE_DESCRIPTOR);
}
// Copy MSR device descriptor to the heap if it exists.
if (DeviceDescript[Die].MSRDevice[i].RegisterListID != 0xFFFFFFFF) {
LibAmdMemCopy ((VOID *) BufferOffset, &(DeviceDescript[Die].MSRDevice[i]), sizeof (MSR_DEVICE_DESCRIPTOR), StdHeader);
(*DeviceBlockHdrPtr)->NumDevices ++;
BufferOffset += sizeof (MSR_DEVICE_DESCRIPTOR);
}
// Copy conditional MSR device descriptor to the heap if it exists.
if (DeviceDescript[Die].CMSRDevice[i].RegisterListID != 0xFFFFFFFF) {
LibAmdMemCopy ((VOID *) BufferOffset, &(DeviceDescript[Die].PCIDevice[i]), sizeof (CONDITIONAL_MSR_DEVICE_DESCRIPTOR), StdHeader);
(*DeviceBlockHdrPtr)->NumDevices ++;
BufferOffset += sizeof (CONDITIONAL_MSR_DEVICE_DESCRIPTOR);
}
}
}
return RetVal;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function initialize the northbridge block and apply for heap space
* before any function call is made to memory component during S3 resume.
*
* @param[in] *StdHeader - Config handle for library and services
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemS3ResumeInitNB (
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
MEM_MAIN_DATA_BLOCK mmData;
S3_MEM_NB_BLOCK *S3NBPtr;
MEM_DATA_STRUCT *MemData;
UINT8 Die;
UINT8 DieCount;
UINT8 SpecialCaseHeapSize;
ALLOCATE_HEAP_PARAMS AllocHeapParams;
S3_SPECIAL_CASE_HEAP_HEADER SpecialHeapHeader[MAX_NODES_SUPPORTED];
SpecialCaseHeapSize = 0;
//---------------------------------------------
// Creation of NB Block for S3 resume
//---------------------------------------------
RetVal = MemS3InitNB (&S3NBPtr, &MemData, &mmData, StdHeader);
if (RetVal == AGESA_FATAL) {
return RetVal;
}
DieCount = mmData.DieCount;
//--------------------------------------------------
// Apply for heap space for special case registers
//--------------------------------------------------
for (Die = 0; Die < DieCount; Die ++) {
// Construct the header for the special case heap.
SpecialHeapHeader[Die].Node = S3NBPtr[Die].NBPtr->Node;
SpecialHeapHeader[Die].Offset = SpecialCaseHeapSize + (DieCount * (sizeof (S3_SPECIAL_CASE_HEAP_HEADER)));
SpecialCaseHeapSize = SpecialCaseHeapSize + S3NBPtr->MemS3SpecialCaseHeapSize;
}
AllocHeapParams.RequestedBufferSize = (DieCount * (sizeof (S3_SPECIAL_CASE_HEAP_HEADER))) + SpecialCaseHeapSize;
AllocHeapParams.BufferHandle = AMD_MEM_S3_DATA_HANDLE;
AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) != AGESA_SUCCESS) {
PutEventLog (AGESA_FATAL, MEM_ERROR_HEAP_ALLOCATE_FOR_S3_SPECIAL_CASE_REGISTERS, S3NBPtr[Die].NBPtr->Node, 0, 0, 0, StdHeader);
SetMemError (AGESA_FATAL, S3NBPtr[Die].NBPtr->MCTPtr);
ASSERT(FALSE); // Could not allocate heap space for "S3_SPECIAL_CASE_HEAP_HEADER"
return AGESA_FATAL;
}
LibAmdMemCopy ((VOID *) AllocHeapParams.BufferPtr, (VOID *) SpecialHeapHeader, (sizeof (S3_SPECIAL_CASE_HEAP_HEADER) * DieCount), StdHeader);
return AGESA_SUCCESS;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function returns the PCI device register list according to the register
* list ID.
*
* @param[in] *Device - pointer to the PCI_DEVICE_DESCRIPTOR
* @param[out] **RegisterHdr - pointer to the address of the register list
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemFS3GetPciDeviceRegisterList (
IN PCI_DEVICE_DESCRIPTOR *Device,
OUT PCI_REGISTER_BLOCK_HEADER **RegisterHdr,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
S3_MEM_NB_BLOCK *S3NBPtr;
VOID *RegisterHeader;
LOCATE_HEAP_PTR LocHeap;
AGESA_BUFFER_PARAMS LocBufferParams;
LocHeap.BufferHandle = AMD_MEM_S3_NB_HANDLE;
LibAmdMemCopy (&LocBufferParams.StdHeader, StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
LocBufferParams.BufferHandle = AMD_MEM_S3_NB_HANDLE;
AGESA_TESTPOINT (TpIfBeforeLocateS3PciBuffer, StdHeader);
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
S3NBPtr = (S3_MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
ASSERT(FALSE) ; // No match for heap status, but could not locate "AMD_MEM_S3_NB_HANDLE" in heap for S3GetMsr
return AGESA_FATAL;
}
AGESA_TESTPOINT (TpIfAfterLocateS3PciBuffer, StdHeader);
// NB block has already been constructed by main block.
// No need to construct it here.
RetVal = S3NBPtr[Device->Node].MemS3GetDeviceRegLst (Device->RegisterListID, &RegisterHeader);
*RegisterHdr = (PCI_REGISTER_BLOCK_HEADER *)RegisterHeader;
return RetVal;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function returns the conditional PCI device register list according
* to the register list ID.
*
* @param[in] *Device - pointer to the CONDITIONAL_PCI_DEVICE_DESCRIPTOR
* @param[out] **RegisterHdr - pointer to the address of the register list
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemFS3GetCPciDeviceRegisterList (
IN CONDITIONAL_PCI_DEVICE_DESCRIPTOR *Device,
OUT CPCI_REGISTER_BLOCK_HEADER **RegisterHdr,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
S3_MEM_NB_BLOCK *S3NBPtr;
VOID *RegisterHeader;
LOCATE_HEAP_PTR LocHeap;
AGESA_BUFFER_PARAMS LocBufferParams;
LibAmdMemCopy (&LocBufferParams.StdHeader, StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
LocHeap.BufferHandle = AMD_MEM_S3_NB_HANDLE;
LocBufferParams.BufferHandle = AMD_MEM_S3_NB_HANDLE;
AGESA_TESTPOINT (TpIfBeforeLocateS3CPciBuffer, StdHeader);
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
S3NBPtr = (S3_MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
ASSERT(FALSE) ; // No match for heap status, but could not locate "AMD_MEM_S3_NB_HANDLE" in heap for S3GetMsr
return AGESA_FATAL;
}
AGESA_TESTPOINT (TpIfAfterLocateS3CPciBuffer, StdHeader);
// NB block has already been constructed by main block.
// No need to construct it here.
RetVal = S3NBPtr[Device->Node].MemS3GetDeviceRegLst (Device->RegisterListID, &RegisterHeader);
*RegisterHdr = (CPCI_REGISTER_BLOCK_HEADER *)RegisterHeader;
return RetVal;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function returns the MSR device register list according to the register
* list ID.
*
* @param[in] *Device - pointer to the MSR_DEVICE_DESCRIPTOR
* @param[out] **RegisterHdr - pointer to the address of the register list
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemFS3GetMsrDeviceRegisterList (
IN MSR_DEVICE_DESCRIPTOR *Device,
OUT MSR_REGISTER_BLOCK_HEADER **RegisterHdr,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
S3_MEM_NB_BLOCK *S3NBPtr;
VOID *RegisterHeader;
LOCATE_HEAP_PTR LocHeap;
AGESA_BUFFER_PARAMS LocBufferParams;
LibAmdMemCopy (&LocBufferParams.StdHeader, StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
LocHeap.BufferHandle = AMD_MEM_S3_NB_HANDLE;
LocBufferParams.BufferHandle = AMD_MEM_S3_NB_HANDLE;
AGESA_TESTPOINT (TpIfBeforeLocateS3MsrBuffer, StdHeader);
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
S3NBPtr = (S3_MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
ASSERT(FALSE) ; // No match for heap status, but could not locate "AMD_MEM_S3_NB_HANDLE" in heap for S3GetMsr
return AGESA_FATAL;
}
AGESA_TESTPOINT (TpIfAfterLocateS3MsrBuffer, StdHeader);
// NB block has already been constructed by main block.
// No need to construct it here.
RetVal = S3NBPtr[BSP_DIE].MemS3GetDeviceRegLst (Device->RegisterListID, &RegisterHeader);
*RegisterHdr = (MSR_REGISTER_BLOCK_HEADER *)RegisterHeader;
return RetVal;
}
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function returns the conditional MSR device register list according
* to the register list ID.
*
* @param[in] *Device - pointer to the CONDITIONAL_PCI_DEVICE_DESCRIPTOR
* @param[out] **RegisterHdr - pointer to the address of the register list
* @param[in] *StdHeader - Config handle for library and services
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemFS3GetCMsrDeviceRegisterList (
IN CONDITIONAL_MSR_DEVICE_DESCRIPTOR *Device,
OUT CMSR_REGISTER_BLOCK_HEADER **RegisterHdr,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
AGESA_STATUS RetVal;
S3_MEM_NB_BLOCK *S3NBPtr;
VOID *RegisterHeader;
LOCATE_HEAP_PTR LocHeap;
AGESA_BUFFER_PARAMS LocBufferParams;
LibAmdMemCopy (&LocBufferParams.StdHeader, StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
LocHeap.BufferHandle = AMD_MEM_S3_NB_HANDLE;
LocBufferParams.BufferHandle = AMD_MEM_S3_NB_HANDLE;
AGESA_TESTPOINT (TpIfBeforeLocateS3CMsrBuffer, StdHeader);
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
S3NBPtr = (S3_MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
ASSERT(FALSE) ; // No match for heap status, but could not locate "AMD_MEM_S3_NB_HANDLE" in heap for S3GetMsr
return AGESA_FATAL;
}
AGESA_TESTPOINT (TpIfAfterLocateS3CMsrBuffer, StdHeader);
// NB block has already been constructed by main block.
// No need to construct it here.
RetVal = S3NBPtr[BSP_DIE].MemS3GetDeviceRegLst (Device->RegisterListID, &RegisterHeader);
*RegisterHdr = (CMSR_REGISTER_BLOCK_HEADER *)RegisterHeader;
return RetVal;
}
/*----------------------------------------------------------------------------
* LOCAL FUNCTIONS
*
*----------------------------------------------------------------------------
*/
/* -----------------------------------------------------------------------------*/
/**
*
*
* This function initialize needed data structures for S3 resume.
*
* @param[in, out] **S3NBPtr - Pointer to the pointer of northbridge block.
* @param[in, out] *MemPtr - Pointer to MEM_DATA_STRUCT.
* @param[in, out] *mmData - Pointer to MEM_MAIN_DATA_BLOCK.
* @param[in] *StdHeader - Config handle for library and services.
*
* @return AGESA_STATUS
* - AGESA_ALERT
* - AGESA_FATAL
* - AGESA_SUCCESS
* - AGESA_WARNING
*/
AGESA_STATUS
MemS3InitNB (
IN OUT S3_MEM_NB_BLOCK **S3NBPtr,
IN OUT MEM_DATA_STRUCT **MemPtr,
IN OUT MEM_MAIN_DATA_BLOCK *mmData,
IN AMD_CONFIG_PARAMS *StdHeader
)
{
UINT8 i;
AGESA_STATUS RetVal;
LOCATE_HEAP_PTR LocHeap;
MEM_NB_BLOCK *NBPtr;
ALLOCATE_HEAP_PARAMS AllocHeapParams;
UINT8 Die;
UINT8 DieCount;
BOOLEAN SkipScan;
CPU_SPECIFIC_SERVICES *FamilySpecificServices;
SkipScan = FALSE;
LocHeap.BufferHandle = AMD_MEM_DATA_HANDLE;
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
// NB block has already been constructed by main block.
// No need to construct it here.
*MemPtr = (MEM_DATA_STRUCT *)LocHeap.BufferPtr;
SkipScan = TRUE;
} else {
AllocHeapParams.RequestedBufferSize = sizeof (MEM_DATA_STRUCT);
AllocHeapParams.BufferHandle = AMD_MEM_DATA_HANDLE;
AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) != AGESA_SUCCESS) {
ASSERT(FALSE); // Allocate failed for MEM_DATA_STRUCT
return AGESA_FATAL;
}
*MemPtr = (MEM_DATA_STRUCT *)AllocHeapParams.BufferPtr;
LibAmdMemCopy (&(*MemPtr)->StdHeader, StdHeader, sizeof (AMD_CONFIG_PARAMS), StdHeader);
GetCpuServicesOfCurrentCore ((CONST CPU_SPECIFIC_SERVICES **)&FamilySpecificServices, &(*MemPtr)->StdHeader);
FamilySpecificServices->GetTscRate (FamilySpecificServices, &(*MemPtr)->TscRate, &(*MemPtr)->StdHeader);
}
mmData->MemPtr = *MemPtr;
if (!SkipScan) {
RetVal = MemSocketScan (mmData);
if (RetVal == AGESA_FATAL) {
return RetVal;
}
} else {
// We already have initialize data block, no need to do it again.
mmData->DieCount = mmData->MemPtr->DieCount;
}
DieCount = mmData->DieCount;
//---------------------------------------------
// Creation of NB Block for S3 resume
//---------------------------------------------
// Search for AMD_MEM_AUTO_HANDLE on the heap first.
// Only apply for space on the heap if cannot find AMD_MEM_AUTO_HANDLE on the heap.
LocHeap.BufferHandle = AMD_MEM_S3_NB_HANDLE;
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
// NB block has already been constructed by main block.
// No need to construct it here.
*S3NBPtr = (S3_MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
AllocHeapParams.RequestedBufferSize = (DieCount * (sizeof (S3_MEM_NB_BLOCK)));
AllocHeapParams.BufferHandle = AMD_MEM_S3_NB_HANDLE;
AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) != AGESA_SUCCESS) {
ASSERT(FALSE); // Could not allocate space for "S3_MEM_NB_BLOCK"
return AGESA_FATAL;
}
*S3NBPtr = (S3_MEM_NB_BLOCK *)AllocHeapParams.BufferPtr;
LocHeap.BufferHandle = AMD_MEM_AUTO_HANDLE;
if (HeapLocateBuffer (&LocHeap, StdHeader) == AGESA_SUCCESS) {
// NB block has already been constructed by main block.
// No need to construct it here.
NBPtr = (MEM_NB_BLOCK *)LocHeap.BufferPtr;
} else {
AllocHeapParams.RequestedBufferSize = (DieCount * (sizeof (MEM_NB_BLOCK)));
AllocHeapParams.BufferHandle = AMD_MEM_AUTO_HANDLE;
AllocHeapParams.Persist = HEAP_SYSTEM_MEM;
if (HeapAllocateBuffer (&AllocHeapParams, StdHeader) != AGESA_SUCCESS) {
ASSERT(FALSE); // Allocate failed for "MEM_NB_BLOCK"
return AGESA_FATAL;
}
NBPtr = (MEM_NB_BLOCK *)AllocHeapParams.BufferPtr;
}
// Construct each die.
for (Die = 0; Die < DieCount; Die ++) {
i = 0;
((*S3NBPtr)[Die]).NBPtr = &NBPtr[Die];
while (memNBInstalled[i].MemS3ResumeConstructNBBlock != 0) {
if (memNBInstalled[i].MemS3ResumeConstructNBBlock ((VOID *)&((*S3NBPtr)[Die]), *MemPtr, Die)) {
break;
}
i++;
};
if (memNBInstalled[i].MemS3ResumeConstructNBBlock == 0) {
ASSERT(FALSE); // S3 resume NB constructor not found
return AGESA_FATAL;
}
}
}
return AGESA_SUCCESS;
}
/* -----------------------------------------------------------------------------*/
/**
*
* Waits specified number of 10ns cycles
* @param[in,out] MemPtr - pointer to MEM_DATA_STRUCTURE
* @param[in] Count - Number of 10ns cycles to wait
*
* ----------------------------------------------------------------------------
*/
VOID
MemFS3Wait10ns (
IN UINT32 Count,
IN OUT MEM_DATA_STRUCT *MemPtr
)
{
UINT64 TargetTsc;
UINT64 CurrentTsc;
ASSERT (Count <= 1000000);
LibAmdMsrRead (TSC, &CurrentTsc, &MemPtr->StdHeader);
TargetTsc = CurrentTsc + ((Count * MemPtr->TscRate + 99) / 100);
do {
LibAmdMsrRead (TSC, &CurrentTsc, &MemPtr->StdHeader);
} while (CurrentTsc < TargetTsc);
}
|