]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/StatusCode/RuntimeDxe/RtMemoryStatusCodeWorker.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / RuntimeDxe / RtMemoryStatusCodeWorker.c
CommitLineData
ad1a1798 1/** @file\r
a8cbf345 2 Runtime memory status code worker.\r
ad1a1798 3\r
0a6f4824 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
c0a00b14 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
ad1a1798 6\r
ad1a1798 7**/\r
8\r
20e7a774 9#include "StatusCodeRuntimeDxe.h"\r
ad1a1798 10\r
a8cbf345 11RUNTIME_MEMORY_STATUSCODE_HEADER *mRtMemoryStatusCodeTable;\r
12\r
ad1a1798 13/**\r
a8cbf345 14 Initialize runtime memory status code table as initialization for runtime memory status code worker\r
0a6f4824 15\r
a8cbf345 16 @retval EFI_SUCCESS Runtime memory status code table successfully initialized.\r
ad1a1798 17\r
18**/\r
19EFI_STATUS\r
20RtMemoryStatusCodeInitializeWorker (\r
21 VOID\r
22 )\r
23{\r
ad1a1798 24 //\r
25 // Allocate runtime memory status code pool.\r
26 //\r
a8cbf345 27 mRtMemoryStatusCodeTable = AllocateRuntimePool (\r
28 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +\r
d2c315e6 29 PcdGet16 (PcdStatusCodeMemorySize) * 1024\r
a8cbf345 30 );\r
31 ASSERT (mRtMemoryStatusCodeTable != NULL);\r
32\r
33 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
34 mRtMemoryStatusCodeTable->NumberOfRecords = 0;\r
0a6f4824 35 mRtMemoryStatusCodeTable->MaxRecordsNumber =\r
d2c315e6 36 (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
ad1a1798 37\r
ad1a1798 38 return EFI_SUCCESS;\r
39}\r
40\r
41\r
42/**\r
0a6f4824 43 Report status code into runtime memory. If the runtime pool is full, roll back to the\r
ad1a1798 44 first record and overwrite it.\r
0a6f4824 45\r
a8cbf345 46 @param CodeType Indicates the type of status code being reported.\r
47 @param Value Describes the current status of a hardware or software entity.\r
48 This included information about the class and subclass that is used to\r
49 classify the entity as well as an operation.\r
50 @param Instance The enumeration of a hardware or software entity within\r
51 the system. Valid instance numbers start with 1.\r
0a6f4824 52\r
a8cbf345 53 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
ad1a1798 54\r
55**/\r
56EFI_STATUS\r
57RtMemoryStatusCodeReportWorker (\r
ad1a1798 58 IN EFI_STATUS_CODE_TYPE CodeType,\r
59 IN EFI_STATUS_CODE_VALUE Value,\r
60 IN UINT32 Instance\r
61 )\r
62{\r
63 MEMORY_STATUSCODE_RECORD *Record;\r
64\r
ad1a1798 65 //\r
66 // Locate current record buffer.\r
67 //\r
a8cbf345 68 Record = (MEMORY_STATUSCODE_RECORD *) (mRtMemoryStatusCodeTable + 1);\r
69 Record = &Record[mRtMemoryStatusCodeTable->RecordIndex++];\r
ad1a1798 70\r
71 //\r
72 // Save status code.\r
73 //\r
a8cbf345 74 Record->CodeType = CodeType;\r
75 Record->Value = Value;\r
76 Record->Instance = Instance;\r
ad1a1798 77\r
78 //\r
a8cbf345 79 // If record index equals to max record number, then wrap around record index to zero.\r
80 //\r
81 // The reader of status code should compare the number of records with max records number,\r
82 // If it is equal to or larger than the max number, then the wrap-around had happened,\r
83 // so the first record is pointed by record index.\r
84 // If it is less then max number, index of the first record is zero.\r
ad1a1798 85 //\r
a8cbf345 86 mRtMemoryStatusCodeTable->NumberOfRecords++;\r
87 if (mRtMemoryStatusCodeTable->RecordIndex == mRtMemoryStatusCodeTable->MaxRecordsNumber) {\r
ad1a1798 88 //\r
a8cbf345 89 // Wrap around record index.\r
ad1a1798 90 //\r
a8cbf345 91 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
ad1a1798 92 }\r
93\r
94 return EFI_SUCCESS;\r
95}\r
96\r
97\r
98\r