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