]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/StatusCode/Dxe/RtMemoryStatusCodeWorker.c
Bug fix for the runtime memory status code.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / RtMemoryStatusCodeWorker.c
CommitLineData
ad1a1798 1/** @file\r
2 Runtime memory status code worker in DXE.\r
3\r
4 Copyright (c) 2006, Intel Corporation \r
5 All rights reserved. This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php \r
9 \r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
ad1a1798 13**/\r
14\r
ad1a1798 15#include "DxeStatusCode.h"\r
16\r
17/**\r
18 Initialize runtime memory status code.\r
19 \r
20 @return The function always return EFI_SUCCESS\r
21\r
22**/\r
23EFI_STATUS\r
24RtMemoryStatusCodeInitializeWorker (\r
25 VOID\r
26 )\r
27{\r
28 RUNTIME_MEMORY_STATUSCODE_HEADER *RtMemoryStatusCodeTable;\r
29\r
30 //\r
31 // Allocate runtime memory status code pool.\r
32 //\r
33 RtMemoryStatusCodeTable = \r
d940d5e5 34 (RUNTIME_MEMORY_STATUSCODE_HEADER *) AllocateRuntimePool (\r
ad1a1798 35 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +\r
36 PcdGet16 (PcdStatusCodeRuntimeMemorySize) *\r
37 1024\r
38 );\r
39\r
40 ASSERT (NULL != RtMemoryStatusCodeTable);\r
41\r
42 RtMemoryStatusCodeTable->RecordIndex = 0;\r
43 RtMemoryStatusCodeTable->NumberOfRecords = 0;\r
44 RtMemoryStatusCodeTable->MaxRecordsNumber = \r
45 (PcdGet16 (PcdStatusCodeRuntimeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
46\r
47 gDxeStatusCode.RtMemoryStatusCodeTable[PHYSICAL_MODE] = RtMemoryStatusCodeTable;\r
48 return EFI_SUCCESS;\r
49}\r
50\r
51\r
52/**\r
53 Report status code into runtime memory. If the runtime pool is full, roll back to the \r
54 first record and overwrite it.\r
55 \r
56 @param RtMemoryStatusCodeTable \r
57 Point to Runtime memory table header.\r
58\r
59 @param CodeType Indicates the type of status code being reported. Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
60 \r
61 @param Value Describes the current status of a hardware or software entity. \r
62 This included information about the class and subclass that is used to classify the entity \r
63 as well as an operation. For progress codes, the operation is the current activity. \r
64 For error codes, it is the exception. For debug codes, it is not defined at this time. \r
65 Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below. \r
66 Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
67 \r
68 @param Instance The enumeration of a hardware or software entity within the system. \r
69 A system may contain multiple entities that match a class/subclass pairing. \r
70 The instance differentiates between them. An instance of 0 indicates that instance information is unavailable, \r
71 not meaningful, or not relevant. Valid instance numbers start with 1.\r
72 \r
73 @return The function always return EFI_SUCCESS.\r
74\r
75**/\r
76EFI_STATUS\r
77RtMemoryStatusCodeReportWorker (\r
78 RUNTIME_MEMORY_STATUSCODE_HEADER *RtMemoryStatusCodeTable,\r
79 IN EFI_STATUS_CODE_TYPE CodeType,\r
80 IN EFI_STATUS_CODE_VALUE Value,\r
81 IN UINT32 Instance\r
82 )\r
83{\r
84 MEMORY_STATUSCODE_RECORD *Record;\r
85\r
86 ASSERT (NULL != RtMemoryStatusCodeTable);\r
87\r
88 //\r
89 // Locate current record buffer.\r
90 //\r
91 Record = (MEMORY_STATUSCODE_RECORD *) (RtMemoryStatusCodeTable + 1);\r
92 Record = &Record[RtMemoryStatusCodeTable->RecordIndex++];\r
93\r
94 //\r
95 // Save status code.\r
96 //\r
97 Record->CodeType = CodeType;\r
98 Record->Value = Value;\r
99 Record->Instance = Instance;\r
100\r
101 //\r
102 // Record total number of records, we compare the number with max records number,\r
103 // if it is bigger than the max number, then the roll back had happened, the record index points to \r
104 // the first record. if it is less then max number, then the zero index is the first record.\r
105 //\r
106 RtMemoryStatusCodeTable->NumberOfRecords++;\r
107 if (RtMemoryStatusCodeTable->RecordIndex == RtMemoryStatusCodeTable->MaxRecordsNumber) {\r
108 //\r
109 // Roll back record index.\r
110 //\r
111 RtMemoryStatusCodeTable->RecordIndex = 0;\r
112 }\r
113\r
114 return EFI_SUCCESS;\r
115}\r
116\r
117\r
118\r