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