3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI lib to provide memory journal status code reporting routines.
22 #include "RtMemoryStatusCode.h"
27 PEI_STATUS_CODE_MEMORY_PPI mStatusCodeMemoryPpi
= { 0, 0, 0, 0 };
30 // Function implementations
34 RtMemoryReportStatusCode (
35 IN EFI_STATUS_CODE_TYPE CodeType
,
36 IN EFI_STATUS_CODE_VALUE Value
,
38 IN EFI_GUID
* CallerId
,
39 IN EFI_STATUS_CODE_DATA
* Data OPTIONAL
45 Log a status code to a memory journal. If no memory journal exists,
50 Same as ReportStatusCode AP
54 EFI_SUCCESS This function always returns success
58 EFI_STATUS_CODE_ENTRY
*CurrentEntry
;
62 // We don't care to log debug codes.
64 if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) == EFI_DEBUG_CODE
) {
68 // Update the latest entry in the journal.
70 MaxEntry
= mStatusCodeMemoryPpi
.Length
/ sizeof (EFI_STATUS_CODE_ENTRY
);
73 // If we don't have any entries, then we can return.
74 // This effectively means that no memory buffer was passed forward from PEI.
79 CurrentEntry
= (EFI_STATUS_CODE_ENTRY
*) (UINTN
) (mStatusCodeMemoryPpi
.Address
+ (mStatusCodeMemoryPpi
.LastEntry
* sizeof (EFI_STATUS_CODE_ENTRY
)));
81 mStatusCodeMemoryPpi
.LastEntry
= (mStatusCodeMemoryPpi
.LastEntry
+ 1) % MaxEntry
;
82 if (mStatusCodeMemoryPpi
.LastEntry
== mStatusCodeMemoryPpi
.FirstEntry
) {
83 mStatusCodeMemoryPpi
.FirstEntry
= (mStatusCodeMemoryPpi
.FirstEntry
+ 1) % MaxEntry
;
86 CurrentEntry
->Type
= CodeType
;
87 CurrentEntry
->Value
= Value
;
88 CurrentEntry
->Instance
= Instance
;
95 RtMemoryInitializeStatusCode (
96 IN EFI_HANDLE ImageHandle
,
97 IN EFI_SYSTEM_TABLE
*SystemTable
103 Initialization routine.
104 Allocates heap space for storing Status Codes.
105 Installs a PPI to point to that heap space.
106 Installs a callback to switch to memory.
107 Installs a callback to
111 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
121 PEI_STATUS_CODE_MEMORY_PPI
**StatusCodeMemoryPpi
;
124 // Locate the HOB that contains the PPI structure for the memory journal
125 // We don't check for more than one.
127 EfiLibGetSystemConfigurationTable (
131 Status
= GetNextGuidHob (
133 &gPeiStatusCodeMemoryPpiGuid
,
134 (VOID
**) &StatusCodeMemoryPpi
,
137 if (EFI_ERROR (Status
)) {
141 // Copy data to our structure since the HOB will go away at runtime
143 // BUGBUG: Virtualize for RT
145 mStatusCodeMemoryPpi
.FirstEntry
= (*StatusCodeMemoryPpi
)->FirstEntry
;
146 mStatusCodeMemoryPpi
.LastEntry
= (*StatusCodeMemoryPpi
)->LastEntry
;
147 mStatusCodeMemoryPpi
.Address
= (*StatusCodeMemoryPpi
)->Address
;
148 mStatusCodeMemoryPpi
.Length
= (*StatusCodeMemoryPpi
)->Length
;
153 PlaybackStatusCodes (
154 IN EFI_REPORT_STATUS_CODE ReportStatusCode
160 Call the input ReportStatusCode function with every status code recorded in
165 ReportStatusCode ReportStatusCode function to call.
174 EFI_STATUS_CODE_ENTRY
*CurrentEntry
;
177 if (ReportStatusCode
== RtMemoryReportStatusCode
) {
181 // Playback prior status codes to current listeners
183 MaxEntry
= mStatusCodeMemoryPpi
.Length
/ sizeof (EFI_STATUS_CODE_ENTRY
);
184 for (Counter
= mStatusCodeMemoryPpi
.FirstEntry
; Counter
!= mStatusCodeMemoryPpi
.LastEntry
; Counter
++) {
186 // Check if we have to roll back to beginning of queue buffer
188 if (Counter
== MaxEntry
) {
192 // Play current entry
194 CurrentEntry
= (EFI_STATUS_CODE_ENTRY
*) (UINTN
) (mStatusCodeMemoryPpi
.Address
+ (Counter
* sizeof (EFI_STATUS_CODE_ENTRY
)));
198 CurrentEntry
->Instance
,