1. add EdkSerialPortLibNull.inf
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / RtMemoryStatusCodeWorker.c
1 /** @file
2 Runtime memory status code worker in DXE.
3
4 Copyright (c) 2006, 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 Module Name: RtMemoryStatusCodeWorker.c
14
15 **/
16
17 //
18 // Include common header file for this module.
19 //
20 #include "CommonHeader.h"
21
22 #include "DxeStatusCode.h"
23
24 /**
25 Initialize runtime memory status code.
26
27 @return The function always return EFI_SUCCESS
28
29 **/
30 EFI_STATUS
31 RtMemoryStatusCodeInitializeWorker (
32 VOID
33 )
34 {
35 RUNTIME_MEMORY_STATUSCODE_HEADER *RtMemoryStatusCodeTable;
36
37 //
38 // Allocate runtime memory status code pool.
39 //
40 RtMemoryStatusCodeTable =
41 (RUNTIME_MEMORY_STATUSCODE_HEADER *) AllocatePool (
42 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +
43 PcdGet16 (PcdStatusCodeRuntimeMemorySize) *
44 1024
45 );
46
47 ASSERT (NULL != RtMemoryStatusCodeTable);
48
49 RtMemoryStatusCodeTable->RecordIndex = 0;
50 RtMemoryStatusCodeTable->NumberOfRecords = 0;
51 RtMemoryStatusCodeTable->MaxRecordsNumber =
52 (PcdGet16 (PcdStatusCodeRuntimeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
53
54 gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE] = RtMemoryStatusCodeTable;
55 return EFI_SUCCESS;
56 }
57
58
59 /**
60 Report status code into runtime memory. If the runtime pool is full, roll back to the
61 first record and overwrite it.
62
63 @param RtMemoryStatusCodeTable
64 Point to Runtime memory table header.
65
66 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
67
68 @param Value Describes the current status of a hardware or software entity.
69 This included information about the class and subclass that is used to classify the entity
70 as well as an operation. For progress codes, the operation is the current activity.
71 For error codes, it is the exception. For debug codes, it is not defined at this time.
72 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.
73 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
74
75 @param Instance The enumeration of a hardware or software entity within the system.
76 A system may contain multiple entities that match a class/subclass pairing.
77 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable,
78 not meaningful, or not relevant. Valid instance numbers start with 1.
79
80 @return The function always return EFI_SUCCESS.
81
82 **/
83 EFI_STATUS
84 RtMemoryStatusCodeReportWorker (
85 RUNTIME_MEMORY_STATUSCODE_HEADER *RtMemoryStatusCodeTable,
86 IN EFI_STATUS_CODE_TYPE CodeType,
87 IN EFI_STATUS_CODE_VALUE Value,
88 IN UINT32 Instance
89 )
90 {
91 MEMORY_STATUSCODE_RECORD *Record;
92
93 ASSERT (NULL != RtMemoryStatusCodeTable);
94
95 //
96 // Locate current record buffer.
97 //
98 Record = (MEMORY_STATUSCODE_RECORD *) (RtMemoryStatusCodeTable + 1);
99 Record = &Record[RtMemoryStatusCodeTable->RecordIndex++];
100
101 //
102 // Save status code.
103 //
104 Record->CodeType = CodeType;
105 Record->Value = Value;
106 Record->Instance = Instance;
107
108 //
109 // Record total number of records, we compare the number with max records number,
110 // if it is bigger than the max number, then the roll back had happened, the record index points to
111 // the first record. if it is less then max number, then the zero index is the first record.
112 //
113 RtMemoryStatusCodeTable->NumberOfRecords++;
114 if (RtMemoryStatusCodeTable->RecordIndex == RtMemoryStatusCodeTable->MaxRecordsNumber) {
115 //
116 // Roll back record index.
117 //
118 RtMemoryStatusCodeTable->RecordIndex = 0;
119 }
120
121 return EFI_SUCCESS;
122 }
123
124
125