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