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