]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / StatusCodeHandler / Smm / MemoryStatusCodeWorker.c
... / ...
CommitLineData
1/** @file\r
2 Runtime memory status code worker.\r
3\r
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#include "StatusCodeHandlerMm.h"\r
11\r
12RUNTIME_MEMORY_STATUSCODE_HEADER *mMmMemoryStatusCodeTable;\r
13\r
14/**\r
15 Initialize MM memory status code table as initialization for memory status code worker\r
16\r
17 @retval EFI_SUCCESS MM memory status code table successfully initialized.\r
18 @retval others Errors from gMmst->MmInstallConfigurationTable().\r
19**/\r
20EFI_STATUS\r
21MemoryStatusCodeInitializeWorker (\r
22 VOID\r
23 )\r
24{\r
25 EFI_STATUS Status;\r
26\r
27 //\r
28 // Allocate MM memory status code pool.\r
29 //\r
30 mMmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);\r
31 ASSERT (mMmMemoryStatusCodeTable != NULL);\r
32\r
33 mMmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
34 Status = gMmst->MmInstallConfigurationTable (\r
35 gMmst,\r
36 &gMemoryStatusCodeRecordGuid,\r
37 &mMmMemoryStatusCodeTable,\r
38 sizeof (mMmMemoryStatusCodeTable)\r
39 );\r
40 return Status;\r
41}\r
42\r
43/**\r
44 Report status code into runtime memory. If the runtime pool is full, roll back to the\r
45 first record and overwrite it.\r
46\r
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
57\r
58 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
59\r
60**/\r
61EFI_STATUS\r
62EFIAPI\r
63MemoryStatusCodeReportWorker (\r
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
69 )\r
70{\r
71 MEMORY_STATUSCODE_RECORD *Record;\r
72\r
73 //\r
74 // Locate current record buffer.\r
75 //\r
76 Record = (MEMORY_STATUSCODE_RECORD *)(mMmMemoryStatusCodeTable + 1);\r
77 Record = &Record[mMmMemoryStatusCodeTable->RecordIndex++];\r
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
94 mMmMemoryStatusCodeTable->NumberOfRecords++;\r
95 if (mMmMemoryStatusCodeTable->RecordIndex == mMmMemoryStatusCodeTable->MaxRecordsNumber) {\r
96 //\r
97 // Wrap around record index.\r
98 //\r
99 mMmMemoryStatusCodeTable->RecordIndex = 0;\r
100 }\r
101\r
102 return EFI_SUCCESS;\r
103}\r