]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/StatusCodeHandler/RuntimeDxe/MemoryStatusCodeWorker.c
Enable Report Status Code Router introduced in PI 1.2 for PEI and DXE.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCodeHandler / RuntimeDxe / MemoryStatusCodeWorker.c
1 /** @file
2 Runtime memory status code worker.
3
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "StatusCodeHandlerRuntimeDxe.h"
16
17 RUNTIME_MEMORY_STATUSCODE_HEADER *mRtMemoryStatusCodeTable;
18
19 /**
20 Initialize runtime memory status code table as initialization for runtime memory status code worker
21
22 @retval EFI_SUCCESS Runtime memory status code table successfully initialized.
23
24 **/
25 EFI_STATUS
26 RtMemoryStatusCodeInitializeWorker (
27 VOID
28 )
29 {
30 //
31 // Allocate runtime memory status code pool.
32 //
33 mRtMemoryStatusCodeTable = AllocateRuntimePool (
34 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +
35 PcdGet16 (PcdStatusCodeMemorySize) * 1024
36 );
37 ASSERT (mRtMemoryStatusCodeTable != NULL);
38
39 mRtMemoryStatusCodeTable->RecordIndex = 0;
40 mRtMemoryStatusCodeTable->NumberOfRecords = 0;
41 mRtMemoryStatusCodeTable->MaxRecordsNumber =
42 (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
43
44 return EFI_SUCCESS;
45 }
46
47
48 /**
49 Report status code into runtime memory. If the runtime pool is full, roll back to the
50 first record and overwrite it.
51
52 @param CodeType Indicates the type of status code being reported.
53 @param Value Describes the current status of a hardware or software entity.
54 This included information about the class and subclass that is used to
55 classify the entity as well as an operation.
56 @param Instance The enumeration of a hardware or software entity within
57 the system. Valid instance numbers start with 1.
58 @param CallerId This optional parameter may be used to identify the caller.
59 This parameter allows the status code driver to apply different rules to
60 different callers.
61 @param Data This optional parameter may be used to pass additional data.
62
63 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.
64
65 **/
66 EFI_STATUS
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