]>
Commit | Line | Data |
---|---|---|
b38907a6 | 1 | /*++\r |
2 | \r | |
4b1e1121 HT |
3 | Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
b38907a6 | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | RtMemoryStatusCode.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | EFI lib to provide memory journal status code reporting routines.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include "RtMemoryStatusCode.h"\r | |
23 | \r | |
24 | //\r | |
25 | // Global variables\r | |
26 | //\r | |
27 | PEI_STATUS_CODE_MEMORY_PPI mStatusCodeMemoryPpi = { 0, 0, 0, 0 };\r | |
28 | \r | |
29 | //\r | |
30 | // Function implementations\r | |
31 | //\r | |
32 | EFI_STATUS\r | |
33 | EFIAPI\r | |
34 | RtMemoryReportStatusCode (\r | |
35 | IN EFI_STATUS_CODE_TYPE CodeType,\r | |
36 | IN EFI_STATUS_CODE_VALUE Value,\r | |
37 | IN UINT32 Instance,\r | |
38 | IN EFI_GUID * CallerId,\r | |
39 | IN EFI_STATUS_CODE_DATA * Data OPTIONAL\r | |
40 | )\r | |
41 | /*++\r | |
42 | \r | |
43 | Routine Description:\r | |
44 | \r | |
45 | Log a status code to a memory journal. If no memory journal exists, \r | |
46 | we will just return.\r | |
47 | \r | |
48 | Arguments:\r | |
49 | \r | |
50 | Same as ReportStatusCode AP\r | |
51 | \r | |
52 | Returns:\r | |
53 | \r | |
54 | EFI_SUCCESS This function always returns success\r | |
55 | \r | |
56 | --*/\r | |
57 | {\r | |
58 | EFI_STATUS_CODE_ENTRY *CurrentEntry;\r | |
59 | UINTN MaxEntry;\r | |
60 | \r | |
61 | //\r | |
62 | // We don't care to log debug codes.\r | |
63 | //\r | |
64 | if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r | |
65 | return EFI_SUCCESS;\r | |
66 | }\r | |
67 | //\r | |
68 | // Update the latest entry in the journal.\r | |
69 | //\r | |
70 | MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);\r | |
71 | if (!MaxEntry) {\r | |
72 | //\r | |
73 | // If we don't have any entries, then we can return.\r | |
74 | // This effectively means that no memory buffer was passed forward from PEI.\r | |
75 | //\r | |
76 | return EFI_SUCCESS;\r | |
77 | }\r | |
78 | \r | |
79 | CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (mStatusCodeMemoryPpi.LastEntry * sizeof (EFI_STATUS_CODE_ENTRY)));\r | |
80 | \r | |
81 | mStatusCodeMemoryPpi.LastEntry = (mStatusCodeMemoryPpi.LastEntry + 1) % MaxEntry;\r | |
82 | if (mStatusCodeMemoryPpi.LastEntry == mStatusCodeMemoryPpi.FirstEntry) {\r | |
83 | mStatusCodeMemoryPpi.FirstEntry = (mStatusCodeMemoryPpi.FirstEntry + 1) % MaxEntry;\r | |
84 | }\r | |
85 | \r | |
86 | CurrentEntry->Type = CodeType;\r | |
87 | CurrentEntry->Value = Value;\r | |
88 | CurrentEntry->Instance = Instance;\r | |
89 | \r | |
90 | return EFI_SUCCESS;\r | |
91 | }\r | |
92 | \r | |
93 | VOID\r | |
94 | EFIAPI\r | |
95 | RtMemoryInitializeStatusCode (\r | |
96 | IN EFI_HANDLE ImageHandle,\r | |
97 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
98 | )\r | |
99 | /*++\r | |
100 | \r | |
101 | Routine Description:\r | |
102 | \r | |
103 | Initialization routine.\r | |
104 | Allocates heap space for storing Status Codes.\r | |
105 | Installs a PPI to point to that heap space.\r | |
106 | Installs a callback to switch to memory.\r | |
107 | Installs a callback to \r | |
108 | \r | |
109 | Arguments: \r | |
110 | \r | |
111 | (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r | |
112 | \r | |
113 | Returns: \r | |
114 | \r | |
115 | None\r | |
116 | \r | |
117 | --*/\r | |
118 | {\r | |
119 | EFI_STATUS Status;\r | |
120 | VOID *HobList;\r | |
121 | PEI_STATUS_CODE_MEMORY_PPI **StatusCodeMemoryPpi;\r | |
122 | \r | |
123 | //\r | |
124 | // Locate the HOB that contains the PPI structure for the memory journal\r | |
125 | // We don't check for more than one.\r | |
126 | //\r | |
127 | EfiLibGetSystemConfigurationTable (\r | |
128 | &gEfiHobListGuid,\r | |
129 | &HobList\r | |
130 | );\r | |
131 | Status = GetNextGuidHob (\r | |
132 | &HobList,\r | |
133 | &gPeiStatusCodeMemoryPpiGuid,\r | |
134 | (VOID **) &StatusCodeMemoryPpi,\r | |
135 | NULL\r | |
136 | );\r | |
137 | if (EFI_ERROR (Status)) {\r | |
138 | return ;\r | |
139 | }\r | |
140 | //\r | |
141 | // Copy data to our structure since the HOB will go away at runtime\r | |
142 | //\r | |
143 | // BUGBUG: Virtualize for RT\r | |
144 | //\r | |
145 | mStatusCodeMemoryPpi.FirstEntry = (*StatusCodeMemoryPpi)->FirstEntry;\r | |
146 | mStatusCodeMemoryPpi.LastEntry = (*StatusCodeMemoryPpi)->LastEntry;\r | |
147 | mStatusCodeMemoryPpi.Address = (*StatusCodeMemoryPpi)->Address;\r | |
148 | mStatusCodeMemoryPpi.Length = (*StatusCodeMemoryPpi)->Length;\r | |
149 | }\r | |
150 | \r | |
151 | VOID\r | |
152 | EFIAPI\r | |
153 | PlaybackStatusCodes (\r | |
154 | IN EFI_REPORT_STATUS_CODE ReportStatusCode\r | |
155 | )\r | |
156 | /*++\r | |
157 | \r | |
158 | Routine Description:\r | |
159 | \r | |
160 | Call the input ReportStatusCode function with every status code recorded in\r | |
161 | the journal.\r | |
162 | \r | |
163 | Arguments: \r | |
164 | \r | |
165 | ReportStatusCode ReportStatusCode function to call.\r | |
166 | \r | |
167 | Returns: \r | |
168 | \r | |
169 | None\r | |
170 | \r | |
171 | --*/\r | |
172 | {\r | |
173 | UINTN MaxEntry;\r | |
174 | EFI_STATUS_CODE_ENTRY *CurrentEntry;\r | |
175 | UINTN Counter;\r | |
176 | \r | |
177 | if (ReportStatusCode == RtMemoryReportStatusCode) {\r | |
178 | return ;\r | |
179 | }\r | |
180 | //\r | |
181 | // Playback prior status codes to current listeners\r | |
182 | //\r | |
183 | MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);\r | |
184 | for (Counter = mStatusCodeMemoryPpi.FirstEntry; Counter != mStatusCodeMemoryPpi.LastEntry; Counter++) {\r | |
185 | //\r | |
186 | // Check if we have to roll back to beginning of queue buffer\r | |
187 | //\r | |
188 | if (Counter == MaxEntry) {\r | |
189 | Counter = 0;\r | |
190 | }\r | |
191 | //\r | |
192 | // Play current entry\r | |
193 | //\r | |
194 | CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (Counter * sizeof (EFI_STATUS_CODE_ENTRY)));\r | |
195 | ReportStatusCode (\r | |
196 | CurrentEntry->Type,\r | |
197 | CurrentEntry->Value,\r | |
198 | CurrentEntry->Instance,\r | |
199 | NULL,\r | |
200 | NULL\r | |
201 | );\r | |
202 | }\r | |
203 | }\r |