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