]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Smm / 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
d1102dba
LG
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
848e1472 10\r
d1102dba
LG
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
3af9b388 13\r
14**/\r
15\r
16#include "StatusCodeHandlerSmm.h"\r
17\r
18RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;\r
19\r
20/**\r
21 Initialize SMM memory status code table as initialization for memory status code worker\r
3af9b388 22\r
848e1472
CS
23 @retval EFI_SUCCESS SMM memory status code table successfully initialized.\r
24 @retval others Errors from gSmst->SmmInstallConfigurationTable().\r
3af9b388 25**/\r
26EFI_STATUS\r
27MemoryStatusCodeInitializeWorker (\r
28 VOID\r
29 )\r
30{\r
848e1472
CS
31 EFI_STATUS Status;\r
32\r
3af9b388 33 //\r
34 // Allocate SMM memory status code pool.\r
35 //\r
d3308de7 36 mSmmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);\r
3af9b388 37 ASSERT (mSmmMemoryStatusCodeTable != NULL);\r
38\r
d3308de7 39 mSmmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
848e1472
CS
40 Status = gSmst->SmmInstallConfigurationTable (\r
41 gSmst,\r
42 &gMemoryStatusCodeRecordGuid,\r
43 &mSmmMemoryStatusCodeTable,\r
44 sizeof (mSmmMemoryStatusCodeTable)\r
45 );\r
46 return Status;\r
3af9b388 47}\r
48\r
49\r
50/**\r
d1102dba 51 Report status code into runtime memory. If the runtime pool is full, roll back to the\r
3af9b388 52 first record and overwrite it.\r
848e1472 53\r
3af9b388 54 @param CodeType Indicates the type of status code being reported.\r
55 @param Value Describes the current status of a hardware or software entity.\r
56 This included information about the class and subclass that is used to\r
57 classify the entity as well as an operation.\r
58 @param Instance The enumeration of a hardware or software entity within\r
59 the system. Valid instance numbers start with 1.\r
60 @param CallerId This optional parameter may be used to identify the caller.\r
61 This parameter allows the status code driver to apply different rules to\r
62 different callers.\r
63 @param Data This optional parameter may be used to pass additional data.\r
848e1472 64\r
3af9b388 65 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
66\r
67**/\r
68EFI_STATUS\r
e798cd87 69EFIAPI\r
3af9b388 70MemoryStatusCodeReportWorker (\r
71 IN EFI_STATUS_CODE_TYPE CodeType,\r
72 IN EFI_STATUS_CODE_VALUE Value,\r
73 IN UINT32 Instance,\r
74 IN EFI_GUID *CallerId,\r
75 IN EFI_STATUS_CODE_DATA *Data OPTIONAL\r
76 )\r
77{\r
78 MEMORY_STATUSCODE_RECORD *Record;\r
79\r
80 //\r
81 // Locate current record buffer.\r
82 //\r
83 Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);\r
84 Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];\r
85\r
86 //\r
87 // Save status code.\r
88 //\r
89 Record->CodeType = CodeType;\r
90 Record->Value = Value;\r
91 Record->Instance = Instance;\r
92\r
93 //\r
94 // If record index equals to max record number, then wrap around record index to zero.\r
95 //\r
96 // The reader of status code should compare the number of records with max records number,\r
97 // If it is equal to or larger than the max number, then the wrap-around had happened,\r
98 // so the first record is pointed by record index.\r
99 // If it is less then max number, index of the first record is zero.\r
100 //\r
101 mSmmMemoryStatusCodeTable->NumberOfRecords++;\r
102 if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {\r
103 //\r
104 // Wrap around record index.\r
105 //\r
106 mSmmMemoryStatusCodeTable->RecordIndex = 0;\r
107 }\r
108\r
109 return EFI_SUCCESS;\r
110}\r
111\r
112\r
113\r