]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkRuntimeStatusCodeLib/RtMemoryStatusCode/RtMemoryStatusCode.c
1. Updated function headers in all assembly files.
[mirror_edk2.git] / EdkModulePkg / Library / EdkRuntimeStatusCodeLib / RtMemoryStatusCode / RtMemoryStatusCode.c
1 /*++
2
3 Copyright (c) 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
8
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.
11
12 Module Name:
13
14 RtMemoryStatusCode.c
15
16 Abstract:
17
18 EFI lib to provide memory journal status code reporting routines.
19
20 --*/
21
22 #include <Ppi/StatusCodeMemory.h>
23
24 //
25 // Global variables
26 //
27 PEI_STATUS_CODE_MEMORY_PPI mStatusCodeMemoryPpi = { 0, 0, 0, 0 };
28
29 //
30 // Function implementations
31 //
32 EFI_STATUS
33 RtMemoryReportStatusCode (
34 IN EFI_STATUS_CODE_TYPE CodeType,
35 IN EFI_STATUS_CODE_VALUE Value,
36 IN UINT32 Instance,
37 IN EFI_GUID * CallerId,
38 IN EFI_STATUS_CODE_DATA * Data OPTIONAL
39 )
40 /*++
41
42 Routine Description:
43
44 Log a status code to a memory journal. If no memory journal exists,
45 we will just return.
46
47 Arguments:
48
49 Same as ReportStatusCode AP
50
51 Returns:
52
53 EFI_SUCCESS This function always returns success
54
55 --*/
56 {
57 EFI_STATUS_CODE_ENTRY *CurrentEntry;
58 UINT32 MaxEntry;
59
60 //
61 // We don't care to log debug codes.
62 //
63 if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
64 return EFI_SUCCESS;
65 }
66 //
67 // Update the latest entry in the journal.
68 //
69 MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);
70 if (!MaxEntry) {
71 //
72 // If we don't have any entries, then we can return.
73 // This effectively means that no memory buffer was passed forward from PEI.
74 //
75 return EFI_SUCCESS;
76 }
77
78 CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (mStatusCodeMemoryPpi.LastEntry * sizeof (EFI_STATUS_CODE_ENTRY)));
79
80 mStatusCodeMemoryPpi.LastEntry = (mStatusCodeMemoryPpi.LastEntry + 1) % MaxEntry;
81 if (mStatusCodeMemoryPpi.LastEntry == mStatusCodeMemoryPpi.FirstEntry) {
82 mStatusCodeMemoryPpi.FirstEntry = (mStatusCodeMemoryPpi.FirstEntry + 1) % MaxEntry;
83 }
84
85 CurrentEntry->Type = CodeType;
86 CurrentEntry->Value = Value;
87 CurrentEntry->Instance = Instance;
88
89 return EFI_SUCCESS;
90 }
91
92 VOID
93 RtMemoryStatusCodeInitialize (
94 VOID
95 )
96 /*++
97
98 Routine Description:
99
100 Initialization routine.
101 Allocates heap space for storing Status Codes.
102 Installs a PPI to point to that heap space.
103 Installs a callback to switch to memory.
104 Installs a callback to
105
106 Arguments:
107
108 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
109
110 Returns:
111
112 None
113
114 --*/
115 {
116 EFI_HOB_GUID_TYPE *GuidHob;
117 PEI_STATUS_CODE_MEMORY_PPI **StatusCodeMemoryPpi;
118
119 GuidHob = GetFirstGuidHob (&gPeiStatusCodeMemoryPpiGuid);
120 if (GuidHob == NULL) {
121 return;
122 }
123
124 StatusCodeMemoryPpi = GET_GUID_HOB_DATA (GuidHob);
125
126 //
127 // Copy data to our structure since the HOB will go away at runtime
128 //
129 // BUGBUG: Virtualize for RT
130 //
131 mStatusCodeMemoryPpi.FirstEntry = (*StatusCodeMemoryPpi)->FirstEntry;
132 mStatusCodeMemoryPpi.LastEntry = (*StatusCodeMemoryPpi)->LastEntry;
133 mStatusCodeMemoryPpi.Address = (*StatusCodeMemoryPpi)->Address;
134 mStatusCodeMemoryPpi.Length = (*StatusCodeMemoryPpi)->Length;
135 }
136
137 VOID
138 PlaybackStatusCodes (
139 IN EFI_REPORT_STATUS_CODE ReportStatusCodeFunc
140 )
141 /*++
142
143 Routine Description:
144
145 Call the input ReportStatusCode function with every status code recorded in
146 the journal.
147
148 Arguments:
149
150 ReportStatusCode ReportStatusCode function to call.
151
152 Returns:
153
154 None
155
156 --*/
157 {
158 UINTN MaxEntry;
159 EFI_STATUS_CODE_ENTRY *CurrentEntry;
160 UINTN Counter;
161
162 if (ReportStatusCodeFunc == RtMemoryReportStatusCode) {
163 return ;
164 }
165 //
166 // Playback prior status codes to current listeners
167 //
168 MaxEntry = mStatusCodeMemoryPpi.Length / sizeof (EFI_STATUS_CODE_ENTRY);
169 for (Counter = mStatusCodeMemoryPpi.FirstEntry; Counter != mStatusCodeMemoryPpi.LastEntry; Counter++) {
170 //
171 // Check if we have to roll back to beginning of queue buffer
172 //
173 if (Counter == MaxEntry) {
174 Counter = 0;
175 }
176 //
177 // Play current entry
178 //
179 CurrentEntry = (EFI_STATUS_CODE_ENTRY *) (UINTN) (mStatusCodeMemoryPpi.Address + (Counter * sizeof (EFI_STATUS_CODE_ENTRY)));
180 ReportStatusCodeFunc (
181 CurrentEntry->Type,
182 CurrentEntry->Value,
183 CurrentEntry->Instance,
184 NULL,
185 NULL
186 );
187 }
188 }