]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/MemoryStatusCodeWorker.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / RuntimeDxe / MemoryStatusCodeWorker.c
CommitLineData
3af9b388 1/** @file\r
2 Runtime memory status code worker.\r
3\r
d1102dba 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
848e1472 5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
9d510e61 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
3af9b388 7\r
8**/\r
9\r
10#include "StatusCodeHandlerRuntimeDxe.h"\r
11\r
12RUNTIME_MEMORY_STATUSCODE_HEADER *mRtMemoryStatusCodeTable;\r
13\r
14/**\r
15 Initialize runtime memory status code table as initialization for runtime memory status code worker\r
848e1472 16\r
3af9b388 17 @retval EFI_SUCCESS Runtime memory status code table successfully initialized.\r
848e1472 18 @retval others Errors from gBS->InstallConfigurationTable().\r
3af9b388 19\r
20**/\r
21EFI_STATUS\r
22RtMemoryStatusCodeInitializeWorker (\r
23 VOID\r
24 )\r
25{\r
1436aea4 26 EFI_STATUS Status;\r
848e1472 27\r
3af9b388 28 //\r
29 // Allocate runtime memory status code pool.\r
30 //\r
31 mRtMemoryStatusCodeTable = AllocateRuntimePool (\r
32 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +\r
33 PcdGet16 (PcdStatusCodeMemorySize) * 1024\r
34 );\r
35 ASSERT (mRtMemoryStatusCodeTable != NULL);\r
36\r
37 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
38 mRtMemoryStatusCodeTable->NumberOfRecords = 0;\r
d1102dba 39 mRtMemoryStatusCodeTable->MaxRecordsNumber =\r
3af9b388 40 (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
848e1472 41 Status = gBS->InstallConfigurationTable (&gMemoryStatusCodeRecordGuid, mRtMemoryStatusCodeTable);\r
3af9b388 42\r
848e1472 43 return Status;\r
3af9b388 44}\r
45\r
3af9b388 46/**\r
d1102dba 47 Report status code into runtime memory. If the runtime pool is full, roll back to the\r
3af9b388 48 first record and overwrite it.\r
848e1472 49\r
3af9b388 50 @param CodeType Indicates the type of status code being reported.\r
51 @param Value Describes the current status of a hardware or software entity.\r
52 This included information about the class and subclass that is used to\r
53 classify the entity as well as an operation.\r
54 @param Instance The enumeration of a hardware or software entity within\r
55 the system. Valid instance numbers start with 1.\r
56 @param CallerId This optional parameter may be used to identify the caller.\r
57 This parameter allows the status code driver to apply different rules to\r
58 different callers.\r
59 @param Data This optional parameter may be used to pass additional data.\r
848e1472 60\r
3af9b388 61 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
62\r
63**/\r
64EFI_STATUS\r
e798cd87 65EFIAPI\r
3af9b388 66RtMemoryStatusCodeReportWorker (\r
1436aea4
MK
67 IN EFI_STATUS_CODE_TYPE CodeType,\r
68 IN EFI_STATUS_CODE_VALUE Value,\r
69 IN UINT32 Instance,\r
70 IN EFI_GUID *CallerId,\r
71 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
3af9b388 72 )\r
73{\r
1436aea4 74 MEMORY_STATUSCODE_RECORD *Record;\r
3af9b388 75\r
76 //\r
77 // Locate current record buffer.\r
78 //\r
1436aea4 79 Record = (MEMORY_STATUSCODE_RECORD *)(mRtMemoryStatusCodeTable + 1);\r
3af9b388 80 Record = &Record[mRtMemoryStatusCodeTable->RecordIndex++];\r
81\r
82 //\r
83 // Save status code.\r
84 //\r
85 Record->CodeType = CodeType;\r
86 Record->Value = Value;\r
87 Record->Instance = Instance;\r
88\r
89 //\r
90 // If record index equals to max record number, then wrap around record index to zero.\r
91 //\r
92 // The reader of status code should compare the number of records with max records number,\r
93 // If it is equal to or larger than the max number, then the wrap-around had happened,\r
94 // so the first record is pointed by record index.\r
95 // If it is less then max number, index of the first record is zero.\r
96 //\r
97 mRtMemoryStatusCodeTable->NumberOfRecords++;\r
98 if (mRtMemoryStatusCodeTable->RecordIndex == mRtMemoryStatusCodeTable->MaxRecordsNumber) {\r
99 //\r
100 // Wrap around record index.\r
101 //\r
102 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
103 }\r
104\r
105 return EFI_SUCCESS;\r
106}\r