]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Universal/StatusCode/Dxe/RtMemoryStatusCodeWorker.c
Code Scrub for Status Code Runtime Dxe driver.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / RtMemoryStatusCodeWorker.c
... / ...
CommitLineData
1/** @file\r
2 Runtime memory status code worker.\r
3\r
4 Copyright (c) 2006 - 2009, 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
13**/\r
14\r
15#include "DxeStatusCode.h"\r
16\r
17RUNTIME_MEMORY_STATUSCODE_HEADER *mRtMemoryStatusCodeTable;\r
18\r
19/**\r
20 Initialize runtime memory status code table as initialization for runtime memory status code worker\r
21 \r
22 @retval EFI_SUCCESS Runtime memory status code table successfully initialized.\r
23\r
24**/\r
25EFI_STATUS\r
26RtMemoryStatusCodeInitializeWorker (\r
27 VOID\r
28 )\r
29{\r
30 //\r
31 // Allocate runtime memory status code pool.\r
32 //\r
33 mRtMemoryStatusCodeTable = AllocateRuntimePool (\r
34 sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) +\r
35 PcdGet16 (PcdStatusCodeRuntimeMemorySize) *\r
36 1024\r
37 );\r
38 ASSERT (mRtMemoryStatusCodeTable != NULL);\r
39\r
40 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
41 mRtMemoryStatusCodeTable->NumberOfRecords = 0;\r
42 mRtMemoryStatusCodeTable->MaxRecordsNumber = \r
43 (PcdGet16 (PcdStatusCodeRuntimeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);\r
44\r
45 return EFI_SUCCESS;\r
46}\r
47\r
48\r
49/**\r
50 Report status code into runtime memory. If the runtime pool is full, roll back to the \r
51 first record and overwrite it.\r
52 \r
53 @param CodeType Indicates the type of status code being reported.\r
54 @param Value Describes the current status of a hardware or software entity.\r
55 This included information about the class and subclass that is used to\r
56 classify the entity as well as an operation.\r
57 @param Instance The enumeration of a hardware or software entity within\r
58 the system. Valid instance numbers start with 1.\r
59 @param CallerId This optional parameter may be used to identify the caller.\r
60 This parameter allows the status code driver to apply different rules to\r
61 different callers.\r
62 \r
63 @retval EFI_SUCCESS Status code successfully recorded in runtime memory status code table.\r
64\r
65**/\r
66EFI_STATUS\r
67RtMemoryStatusCodeReportWorker (\r
68 IN EFI_STATUS_CODE_TYPE CodeType,\r
69 IN EFI_STATUS_CODE_VALUE Value,\r
70 IN UINT32 Instance\r
71 )\r
72{\r
73 MEMORY_STATUSCODE_RECORD *Record;\r
74\r
75 //\r
76 // Locate current record buffer.\r
77 //\r
78 Record = (MEMORY_STATUSCODE_RECORD *) (mRtMemoryStatusCodeTable + 1);\r
79 Record = &Record[mRtMemoryStatusCodeTable->RecordIndex++];\r
80\r
81 //\r
82 // Save status code.\r
83 //\r
84 Record->CodeType = CodeType;\r
85 Record->Value = Value;\r
86 Record->Instance = Instance;\r
87\r
88 //\r
89 // If record index equals to max record number, then wrap around record index to zero.\r
90 //\r
91 // The reader of status code should compare the number of records with max records number,\r
92 // If it is equal to or larger than the max number, then the wrap-around had happened,\r
93 // so the first record is pointed by record index.\r
94 // If it is less then max number, index of the first record is zero.\r
95 //\r
96 mRtMemoryStatusCodeTable->NumberOfRecords++;\r
97 if (mRtMemoryStatusCodeTable->RecordIndex == mRtMemoryStatusCodeTable->MaxRecordsNumber) {\r
98 //\r
99 // Wrap around record index.\r
100 //\r
101 mRtMemoryStatusCodeTable->RecordIndex = 0;\r
102 }\r
103\r
104 return EFI_SUCCESS;\r
105}\r
106\r
107\r
108\r