]>
Commit | Line | Data |
---|---|---|
2ab23929 | 1 | /** @file\r |
83f6d1a0 | 2 | This code produces the Data Hub protocol. It preloads the data hub\r |
3 | with status information copied in from PEI HOBs.\r | |
4 | \r | |
13314ba3 | 5 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
180a5a35 | 6 | This program and the accompanying materials \r |
3db51098 | 7 | are licensed and made available under the terms and conditions of the BSD License \r |
8 | which accompanies this distribution. The full text of the license may be found at \r | |
9 | http://opensource.org/licenses/bsd-license.php \r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
13 | \r | |
14 | **/\r | |
83f6d1a0 | 15 | \r |
16 | #include "DataHub.h"\r | |
17 | \r | |
18 | CONST EFI_GUID gZeroGuid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };\r | |
19 | \r | |
9f6531d1 | 20 | //\r |
9f6531d1 | 21 | // Since this driver will only ever produce one instance of the Logging Hub\r |
22 | // protocol you are not required to dynamically allocate the PrivateData.\r | |
23 | //\r | |
24 | DATA_HUB_INSTANCE mPrivateData;\r | |
25 | \r | |
a73d0c74 | 26 | /**\r |
a73d0c74 | 27 | Log data record into the data logging hub\r |
28 | \r | |
2ab23929 | 29 | @param This Protocol instance structure\r |
30 | @param DataRecordGuid GUID that defines record contents\r | |
31 | @param ProducerName GUID that defines the name of the producer of the data\r | |
32 | @param DataRecordClass Class that defines generic record type\r | |
33 | @param RawData Data Log record as defined by DataRecordGuid\r | |
34 | @param RawDataSize Size of Data Log data in bytes\r | |
a73d0c74 | 35 | \r |
2ab23929 | 36 | @retval EFI_SUCCESS If data was logged\r |
37 | @retval EFI_OUT_OF_RESOURCES If data was not logged due to lack of system \r | |
38 | resources.\r | |
a73d0c74 | 39 | **/\r |
83f6d1a0 | 40 | EFI_STATUS\r |
41 | EFIAPI\r | |
42 | DataHubLogData (\r | |
43 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
44 | IN EFI_GUID *DataRecordGuid,\r | |
45 | IN EFI_GUID *ProducerName,\r | |
46 | IN UINT64 DataRecordClass,\r | |
47 | IN VOID *RawData,\r | |
48 | IN UINT32 RawDataSize\r | |
49 | )\r | |
83f6d1a0 | 50 | {\r |
51 | EFI_STATUS Status;\r | |
52 | DATA_HUB_INSTANCE *Private;\r | |
53 | EFI_DATA_ENTRY *LogEntry;\r | |
54 | UINT32 TotalSize;\r | |
55 | UINT32 RecordSize;\r | |
56 | EFI_DATA_RECORD_HEADER *Record;\r | |
57 | VOID *Raw;\r | |
58 | DATA_HUB_FILTER_DRIVER *FilterEntry;\r | |
59 | LIST_ENTRY *Link;\r | |
60 | LIST_ENTRY *Head;\r | |
b4c90058 | 61 | EFI_TIME LogTime;\r |
83f6d1a0 | 62 | \r |
63 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
64 | \r | |
65 | //\r | |
66 | // Combine the storage for the internal structs and a copy of the log record.\r | |
67 | // Record follows PrivateLogEntry. The consumer will be returned a pointer\r | |
68 | // to Record so we don't what it to be the thing that was allocated from\r | |
69 | // pool, so the consumer can't free an data record by mistake.\r | |
70 | //\r | |
71 | RecordSize = sizeof (EFI_DATA_RECORD_HEADER) + RawDataSize;\r | |
72 | TotalSize = sizeof (EFI_DATA_ENTRY) + RecordSize;\r | |
b4c90058 LG |
73 | \r |
74 | //\r | |
75 | // First try to get log time at TPL level <= TPL_CALLBACK.\r | |
76 | //\r | |
77 | ZeroMem (&LogTime, sizeof (LogTime));\r | |
78 | if (EfiGetCurrentTpl() <= TPL_CALLBACK) {\r | |
79 | gRT->GetTime (&LogTime, NULL);\r | |
80 | }\r | |
83f6d1a0 | 81 | \r |
82 | //\r | |
83 | // The Logging action is the critical section, so it is locked.\r | |
b4c90058 | 84 | // The MTC asignment & update and logging must be an\r |
83f6d1a0 | 85 | // atomic operation, so use the lock.\r |
86 | //\r | |
87 | Status = EfiAcquireLockOrFail (&Private->DataLock);\r | |
88 | if (EFI_ERROR (Status)) {\r | |
89 | //\r | |
90 | // Reentrancy detected so exit!\r | |
91 | //\r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
95 | LogEntry = AllocatePool (TotalSize);\r | |
96 | \r | |
97 | if (LogEntry == NULL) {\r | |
98 | EfiReleaseLock (&Private->DataLock);\r | |
99 | return EFI_OUT_OF_RESOURCES;\r | |
100 | }\r | |
101 | \r | |
102 | ZeroMem (LogEntry, TotalSize);\r | |
103 | \r | |
104 | Record = (EFI_DATA_RECORD_HEADER *) (LogEntry + 1);\r | |
105 | Raw = (VOID *) (Record + 1);\r | |
106 | \r | |
107 | //\r | |
108 | // Build Standard Log Header\r | |
109 | //\r | |
110 | Record->Version = EFI_DATA_RECORD_HEADER_VERSION;\r | |
13314ba3 | 111 | Record->HeaderSize = (UINT16) sizeof (EFI_DATA_RECORD_HEADER);\r |
83f6d1a0 | 112 | Record->RecordSize = RecordSize;\r |
113 | CopyMem (&Record->DataRecordGuid, DataRecordGuid, sizeof (EFI_GUID));\r | |
114 | CopyMem (&Record->ProducerName, ProducerName, sizeof (EFI_GUID));\r | |
115 | Record->DataRecordClass = DataRecordClass;\r | |
116 | \r | |
41e4912f | 117 | //\r |
118 | // Ensure LogMonotonicCount is not zero\r | |
119 | //\r | |
120 | Record->LogMonotonicCount = ++Private->GlobalMonotonicCount;\r | |
83f6d1a0 | 121 | \r |
b4c90058 | 122 | CopyMem (&Record->LogTime, &LogTime, sizeof (LogTime));\r |
83f6d1a0 | 123 | \r |
124 | //\r | |
125 | // Insert log into the internal linked list.\r | |
126 | //\r | |
127 | LogEntry->Signature = EFI_DATA_ENTRY_SIGNATURE;\r | |
128 | LogEntry->Record = Record;\r | |
129 | LogEntry->RecordSize = sizeof (EFI_DATA_ENTRY) + RawDataSize;\r | |
130 | InsertTailList (&Private->DataListHead, &LogEntry->Link);\r | |
131 | \r | |
132 | CopyMem (Raw, RawData, RawDataSize);\r | |
133 | \r | |
134 | EfiReleaseLock (&Private->DataLock);\r | |
135 | \r | |
136 | //\r | |
137 | // Send Signal to all the filter drivers which are interested\r | |
138 | // in the record's class and guid.\r | |
139 | //\r | |
140 | Head = &Private->FilterDriverListHead;\r | |
2ab23929 | 141 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r |
83f6d1a0 | 142 | FilterEntry = FILTER_ENTRY_FROM_LINK (Link);\r |
143 | if (((FilterEntry->ClassFilter & DataRecordClass) != 0) &&\r | |
144 | (CompareGuid (&FilterEntry->FilterDataRecordGuid, &gZeroGuid) || \r | |
145 | CompareGuid (&FilterEntry->FilterDataRecordGuid, DataRecordGuid))) {\r | |
146 | gBS->SignalEvent (FilterEntry->Event);\r | |
147 | }\r | |
148 | }\r | |
149 | \r | |
150 | return EFI_SUCCESS;\r | |
151 | }\r | |
152 | \r | |
8b7a3578 | 153 | /**\r |
154 | Search the Head doubly linked list for the passed in MTC. Return the \r | |
155 | matching element in Head and the MTC on the next entry.\r | |
156 | \r | |
157 | @param Head Head of Data Log linked list.\r | |
158 | @param ClassFilter Only match the MTC if it is in the same Class as the\r | |
159 | ClassFilter.\r | |
160 | @param PtrCurrentMTC On IN contians MTC to search for. On OUT contians next\r | |
161 | MTC in the data log list or zero if at end of the list.\r | |
162 | \r | |
163 | @retval EFI_DATA_LOG_ENTRY Return pointer to data log data from Head list.\r | |
164 | @retval NULL If no data record exists.\r | |
165 | \r | |
166 | **/\r | |
167 | EFI_DATA_RECORD_HEADER *\r | |
168 | GetNextDataRecord (\r | |
169 | IN LIST_ENTRY *Head,\r | |
170 | IN UINT64 ClassFilter,\r | |
171 | IN OUT UINT64 *PtrCurrentMTC\r | |
172 | )\r | |
173 | \r | |
174 | {\r | |
175 | EFI_DATA_ENTRY *LogEntry;\r | |
176 | LIST_ENTRY *Link;\r | |
177 | BOOLEAN ReturnFirstEntry;\r | |
178 | EFI_DATA_RECORD_HEADER *Record;\r | |
179 | EFI_DATA_ENTRY *NextLogEntry;\r | |
180 | \r | |
181 | //\r | |
182 | // If MonotonicCount == 0 just return the first one\r | |
183 | //\r | |
184 | ReturnFirstEntry = (BOOLEAN) (*PtrCurrentMTC == 0);\r | |
185 | \r | |
186 | Record = NULL;\r | |
187 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r | |
188 | LogEntry = DATA_ENTRY_FROM_LINK (Link);\r | |
189 | if ((LogEntry->Record->DataRecordClass & ClassFilter) == 0) {\r | |
190 | //\r | |
191 | // Skip any entry that does not have the correct ClassFilter\r | |
192 | //\r | |
193 | continue;\r | |
194 | }\r | |
195 | \r | |
196 | if ((LogEntry->Record->LogMonotonicCount == *PtrCurrentMTC) || ReturnFirstEntry) {\r | |
197 | //\r | |
198 | // Return record to the user\r | |
199 | //\r | |
200 | Record = LogEntry->Record;\r | |
201 | \r | |
202 | //\r | |
203 | // Calculate the next MTC value. If there is no next entry set\r | |
204 | // MTC to zero.\r | |
205 | //\r | |
206 | *PtrCurrentMTC = 0;\r | |
207 | for (Link = GetNextNode(Head, Link); Link != Head; Link = GetNextNode(Head, Link)) {\r | |
208 | NextLogEntry = DATA_ENTRY_FROM_LINK (Link);\r | |
209 | if ((NextLogEntry->Record->DataRecordClass & ClassFilter) != 0) {\r | |
210 | //\r | |
211 | // Return the MTC of the next thing to search for if found\r | |
212 | //\r | |
213 | *PtrCurrentMTC = NextLogEntry->Record->LogMonotonicCount;\r | |
214 | break;\r | |
215 | }\r | |
216 | }\r | |
217 | //\r | |
218 | // Record found exit loop and return\r | |
219 | //\r | |
220 | break;\r | |
221 | }\r | |
222 | }\r | |
223 | \r | |
224 | return Record;\r | |
225 | }\r | |
226 | \r | |
227 | /**\r | |
228 | Search the Head list for a EFI_DATA_HUB_FILTER_DRIVER member that\r | |
229 | represents Event and return it.\r | |
230 | \r | |
231 | @param Head Pointer to head of dual linked list of EFI_DATA_HUB_FILTER_DRIVER structures.\r | |
232 | @param Event Event to be search for in the Head list.\r | |
233 | \r | |
234 | @retval EFI_DATA_HUB_FILTER_DRIVER Returned if Event stored in the Head doubly linked list.\r | |
235 | @retval NULL If Event is not in the list\r | |
236 | \r | |
237 | **/\r | |
238 | DATA_HUB_FILTER_DRIVER *\r | |
239 | FindFilterDriverByEvent (\r | |
240 | IN LIST_ENTRY *Head,\r | |
241 | IN EFI_EVENT Event\r | |
242 | )\r | |
243 | {\r | |
244 | DATA_HUB_FILTER_DRIVER *FilterEntry;\r | |
245 | LIST_ENTRY *Link;\r | |
246 | \r | |
247 | for (Link = GetFirstNode(Head); Link != Head; Link = GetNextNode(Head, Link)) {\r | |
248 | FilterEntry = FILTER_ENTRY_FROM_LINK (Link);\r | |
249 | if (FilterEntry->Event == Event) {\r | |
250 | return FilterEntry;\r | |
251 | }\r | |
252 | }\r | |
253 | \r | |
254 | return NULL;\r | |
255 | }\r | |
256 | \r | |
a73d0c74 | 257 | /**\r |
83f6d1a0 | 258 | \r |
259 | Get a previously logged data record and the MonotonicCount for the next\r | |
260 | availible Record. This allows all records or all records later \r | |
261 | than a give MonotonicCount to be returned. If an optional FilterDriverEvent\r | |
262 | is passed in with a MonotonicCout of zero return the first record \r | |
263 | not yet read by the filter driver. If FilterDriverEvent is NULL and \r | |
264 | MonotonicCount is zero return the first data record.\r | |
265 | \r | |
2ab23929 | 266 | @param This Pointer to the EFI_DATA_HUB_PROTOCOL instance.\r |
267 | @param MonotonicCount Specifies the Record to return. On input, zero means\r | |
268 | return the first record. On output, contains the next\r | |
269 | record to availible. Zero indicates no more records.\r | |
270 | @param FilterDriverEvent If FilterDriverEvent is not passed in a MonotonicCount \r | |
271 | of zero, it means to return the first data record. \r | |
272 | If FilterDriverEvent is passed in, then a MonotonicCount \r | |
273 | of zero means to return the first data not yet read by \r | |
274 | FilterDriverEvent.\r | |
275 | @param Record Returns a dynamically allocated memory buffer with a data \r | |
276 | record that matches MonotonicCount.\r | |
277 | \r | |
278 | @retval EFI_SUCCESS Data was returned in Record.\r | |
279 | @retval EFI_INVALID_PARAMETER FilterDriverEvent was passed in but does not exist.\r | |
280 | @retval EFI_NOT_FOUND MonotonicCount does not match any data record in the\r | |
281 | system. If a MonotonicCount of zero was passed in, then\r | |
282 | no data records exist in the system.\r | |
283 | @retval EFI_OUT_OF_RESOURCES Record was not returned due to lack of system resources.\r | |
83f6d1a0 | 284 | \r |
a73d0c74 | 285 | **/\r |
a73d0c74 | 286 | EFI_STATUS\r |
287 | EFIAPI\r | |
288 | DataHubGetNextRecord (\r | |
289 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
290 | IN OUT UINT64 *MonotonicCount,\r | |
291 | IN EFI_EVENT *FilterDriverEvent, OPTIONAL\r | |
292 | OUT EFI_DATA_RECORD_HEADER **Record\r | |
293 | )\r | |
83f6d1a0 | 294 | {\r |
295 | DATA_HUB_INSTANCE *Private;\r | |
296 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
297 | UINT64 ClassFilter;\r | |
83f6d1a0 | 298 | \r |
299 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
300 | \r | |
301 | FilterDriver = NULL;\r | |
83f6d1a0 | 302 | ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |\r |
303 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
304 | EFI_DATA_RECORD_CLASS_DATA |\r | |
305 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
306 | \r | |
d2720e0c | 307 | //\r |
308 | // If FilterDriverEvent is NULL, then return the next record\r | |
309 | //\r | |
310 | if (FilterDriverEvent == NULL) {\r | |
311 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r | |
312 | if (*Record == NULL) {\r | |
313 | return EFI_NOT_FOUND;\r | |
83f6d1a0 | 314 | }\r |
d2720e0c | 315 | return EFI_SUCCESS;\r |
316 | }\r | |
317 | \r | |
318 | //\r | |
319 | // For events the beginning is the last unread record. This info is\r | |
320 | // stored in the instance structure, so we must look up the event\r | |
321 | // to get the data.\r | |
322 | //\r | |
323 | FilterDriver = FindFilterDriverByEvent (\r | |
324 | &Private->FilterDriverListHead,\r | |
325 | *FilterDriverEvent\r | |
326 | );\r | |
327 | if (FilterDriver == NULL) {\r | |
328 | return EFI_INVALID_PARAMETER;\r | |
329 | }\r | |
330 | //\r | |
331 | // Use the Class filter the event was created with.\r | |
332 | //\r | |
333 | ClassFilter = FilterDriver->ClassFilter;\r | |
83f6d1a0 | 334 | \r |
d2720e0c | 335 | //\r |
336 | // Retrieve the next record or the first record.\r | |
337 | // \r | |
338 | if (*MonotonicCount != 0 || FilterDriver->GetNextMonotonicCount == 0) { \r | |
339 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r | |
340 | if (*Record == NULL) {\r | |
341 | return EFI_NOT_FOUND;\r | |
342 | }\r | |
343 | \r | |
344 | if (*MonotonicCount != 0) {\r | |
83f6d1a0 | 345 | //\r |
d2720e0c | 346 | // If this was not the last record then update the count associated with the filter \r |
83f6d1a0 | 347 | //\r |
d2720e0c | 348 | FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r |
349 | } else {\r | |
2ebbe08c | 350 | //\r |
d2720e0c | 351 | // Save the MonotonicCount of the last record which has been read\r |
2ebbe08c | 352 | //\r |
d2720e0c | 353 | FilterDriver->GetNextMonotonicCount = (*Record)->LogMonotonicCount;\r |
83f6d1a0 | 354 | }\r |
d2720e0c | 355 | return EFI_SUCCESS;\r |
83f6d1a0 | 356 | }\r |
d2720e0c | 357 | \r |
358 | //\r | |
359 | // This is a request to read the first record that has not been read yet. \r | |
360 | // Set MonotoicCount to the last record successfuly read\r | |
361 | //\r | |
362 | *MonotonicCount = FilterDriver->GetNextMonotonicCount;\r | |
363 | \r | |
83f6d1a0 | 364 | //\r |
d2720e0c | 365 | // Retrieve the last record successfuly read again, but do not return it since\r |
366 | // it has already been returned before.\r | |
83f6d1a0 | 367 | //\r |
368 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r | |
369 | if (*Record == NULL) {\r | |
370 | return EFI_NOT_FOUND;\r | |
371 | }\r | |
d2720e0c | 372 | \r |
373 | if (*MonotonicCount != 0) {\r | |
83f6d1a0 | 374 | //\r |
d2720e0c | 375 | // Update the count associated with the filter \r |
83f6d1a0 | 376 | //\r |
d2720e0c | 377 | FilterDriver->GetNextMonotonicCount = *MonotonicCount;\r |
378 | \r | |
379 | //\r | |
380 | // Retrieve the record after the last record successfuly read \r | |
381 | // \r | |
382 | *Record = GetNextDataRecord (&Private->DataListHead, ClassFilter, MonotonicCount);\r | |
383 | if (*Record == NULL) {\r | |
384 | return EFI_NOT_FOUND;\r | |
83f6d1a0 | 385 | }\r |
386 | }\r | |
d2720e0c | 387 | \r |
83f6d1a0 | 388 | return EFI_SUCCESS;\r |
389 | }\r | |
390 | \r | |
a73d0c74 | 391 | /**\r |
83f6d1a0 | 392 | This function registers the data hub filter driver that is represented \r |
393 | by FilterEvent. Only one instance of each FilterEvent can be registered.\r | |
394 | After the FilterEvent is registered, it will be signaled so it can sync \r | |
395 | with data records that have been recorded prior to the FilterEvent being \r | |
396 | registered.\r | |
397 | \r | |
2ab23929 | 398 | @param This Pointer to The EFI_DATA_HUB_PROTOCOL instance.\r |
399 | @param FilterEvent The EFI_EVENT to signal whenever data that matches \r | |
400 | FilterClass is logged in the system.\r | |
401 | @param FilterTpl The maximum EFI_TPL at which FilterEvent can be \r | |
402 | signaled. It is strongly recommended that you use the \r | |
403 | lowest EFI_TPL possible.\r | |
404 | @param FilterClass FilterEvent will be signaled whenever a bit in \r | |
405 | EFI_DATA_RECORD_HEADER.DataRecordClass is also set in \r | |
406 | FilterClass. If FilterClass is zero, no class-based \r | |
407 | filtering will be performed.\r | |
408 | @param FilterDataRecordGuid FilterEvent will be signaled whenever FilterDataRecordGuid \r | |
409 | matches EFI_DATA_RECORD_HEADER.DataRecordGuid. If \r | |
410 | FilterDataRecordGuid is NULL, then no GUID-based filtering \r | |
411 | will be performed. \r | |
412 | \r | |
413 | @retval EFI_SUCCESS The filter driver event was registered.\r | |
414 | @retval EFI_ALREADY_STARTED FilterEvent was previously registered and cannot be \r | |
415 | registered again.\r | |
416 | @retval EFI_OUT_OF_RESOURCES The filter driver event was not registered due to lack of \r | |
417 | system resources.\r | |
83f6d1a0 | 418 | \r |
a73d0c74 | 419 | **/\r |
a73d0c74 | 420 | EFI_STATUS\r |
421 | EFIAPI\r | |
422 | DataHubRegisterFilterDriver (\r | |
423 | IN EFI_DATA_HUB_PROTOCOL * This,\r | |
424 | IN EFI_EVENT FilterEvent,\r | |
425 | IN EFI_TPL FilterTpl,\r | |
426 | IN UINT64 FilterClass,\r | |
427 | IN EFI_GUID * FilterDataRecordGuid OPTIONAL\r | |
428 | )\r | |
429 | \r | |
83f6d1a0 | 430 | {\r |
431 | DATA_HUB_INSTANCE *Private;\r | |
432 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
433 | \r | |
434 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
435 | \r | |
436 | FilterDriver = (DATA_HUB_FILTER_DRIVER *) AllocateZeroPool (sizeof (DATA_HUB_FILTER_DRIVER));\r | |
437 | if (FilterDriver == NULL) {\r | |
438 | return EFI_OUT_OF_RESOURCES;\r | |
439 | }\r | |
440 | //\r | |
441 | // Initialize filter driver info\r | |
442 | //\r | |
443 | FilterDriver->Signature = EFI_DATA_HUB_FILTER_DRIVER_SIGNATURE;\r | |
444 | FilterDriver->Event = FilterEvent;\r | |
445 | FilterDriver->Tpl = FilterTpl;\r | |
446 | FilterDriver->GetNextMonotonicCount = 0;\r | |
447 | if (FilterClass == 0) {\r | |
448 | FilterDriver->ClassFilter = EFI_DATA_RECORD_CLASS_DEBUG |\r | |
449 | EFI_DATA_RECORD_CLASS_ERROR |\r | |
450 | EFI_DATA_RECORD_CLASS_DATA |\r | |
451 | EFI_DATA_RECORD_CLASS_PROGRESS_CODE;\r | |
452 | } else {\r | |
453 | FilterDriver->ClassFilter = FilterClass;\r | |
454 | }\r | |
455 | \r | |
456 | if (FilterDataRecordGuid != NULL) {\r | |
457 | CopyMem (&FilterDriver->FilterDataRecordGuid, FilterDataRecordGuid, sizeof (EFI_GUID));\r | |
458 | }\r | |
459 | //\r | |
460 | // Search for duplicate entries\r | |
461 | //\r | |
462 | if (FindFilterDriverByEvent (&Private->FilterDriverListHead, FilterEvent) != NULL) {\r | |
463 | FreePool (FilterDriver);\r | |
464 | return EFI_ALREADY_STARTED;\r | |
465 | }\r | |
466 | //\r | |
467 | // Make insertion an atomic operation with the lock.\r | |
468 | //\r | |
469 | EfiAcquireLock (&Private->DataLock);\r | |
470 | InsertTailList (&Private->FilterDriverListHead, &FilterDriver->Link);\r | |
471 | EfiReleaseLock (&Private->DataLock);\r | |
472 | \r | |
473 | //\r | |
474 | // Signal the Filter driver we just loaded so they will recieve all the\r | |
475 | // previous history. If we did not signal here we would have to wait until\r | |
476 | // the next data was logged to get the history. In a case where no next\r | |
477 | // data was logged we would never get synced up.\r | |
478 | //\r | |
479 | gBS->SignalEvent (FilterEvent);\r | |
480 | \r | |
481 | return EFI_SUCCESS;\r | |
482 | }\r | |
483 | \r | |
a73d0c74 | 484 | /**\r |
83f6d1a0 | 485 | Remove a Filter Driver, so it no longer gets called when data \r |
486 | information is logged.\r | |
487 | \r | |
2ab23929 | 488 | @param This Protocol instance structure\r |
83f6d1a0 | 489 | \r |
2ab23929 | 490 | @param FilterEvent Event that represents a filter driver that is to be \r |
491 | Unregistered.\r | |
83f6d1a0 | 492 | \r |
2ab23929 | 493 | @retval EFI_SUCCESS If FilterEvent was unregistered\r |
494 | @retval EFI_NOT_FOUND If FilterEvent does not exist\r | |
a73d0c74 | 495 | **/\r |
a73d0c74 | 496 | EFI_STATUS\r |
497 | EFIAPI\r | |
498 | DataHubUnregisterFilterDriver (\r | |
499 | IN EFI_DATA_HUB_PROTOCOL *This,\r | |
500 | IN EFI_EVENT FilterEvent\r | |
501 | )\r | |
83f6d1a0 | 502 | {\r |
503 | DATA_HUB_INSTANCE *Private;\r | |
504 | DATA_HUB_FILTER_DRIVER *FilterDriver;\r | |
505 | \r | |
506 | Private = DATA_HUB_INSTANCE_FROM_THIS (This);\r | |
507 | \r | |
508 | //\r | |
509 | // Search for duplicate entries\r | |
510 | //\r | |
511 | FilterDriver = FindFilterDriverByEvent (\r | |
512 | &Private->FilterDriverListHead,\r | |
513 | FilterEvent\r | |
514 | );\r | |
515 | if (FilterDriver == NULL) {\r | |
516 | return EFI_NOT_FOUND;\r | |
517 | }\r | |
518 | //\r | |
519 | // Make removal an atomic operation with the lock\r | |
520 | //\r | |
521 | EfiAcquireLock (&Private->DataLock);\r | |
522 | RemoveEntryList (&FilterDriver->Link);\r | |
523 | EfiReleaseLock (&Private->DataLock);\r | |
524 | \r | |
525 | return EFI_SUCCESS;\r | |
526 | }\r | |
83f6d1a0 | 527 | \r |
83f6d1a0 | 528 | \r |
83f6d1a0 | 529 | \r |
a73d0c74 | 530 | /**\r |
2ab23929 | 531 | Driver's Entry point routine that install Driver to produce Data Hub protocol. \r |
83f6d1a0 | 532 | \r |
2ab23929 | 533 | @param ImageHandle Module's image handle\r |
534 | @param SystemTable Pointer of EFI_SYSTEM_TABLE\r | |
83f6d1a0 | 535 | \r |
2ab23929 | 536 | @retval EFI_SUCCESS Logging Hub protocol installed\r |
537 | @retval Other No protocol installed, unload driver.\r | |
83f6d1a0 | 538 | \r |
a73d0c74 | 539 | **/\r |
540 | EFI_STATUS\r | |
541 | EFIAPI\r | |
542 | DataHubInstall (\r | |
543 | IN EFI_HANDLE ImageHandle,\r | |
544 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
545 | )\r | |
83f6d1a0 | 546 | {\r |
547 | EFI_STATUS Status;\r | |
548 | UINT32 HighMontonicCount;\r | |
549 | \r | |
550 | mPrivateData.Signature = DATA_HUB_INSTANCE_SIGNATURE;\r | |
551 | mPrivateData.DataHub.LogData = DataHubLogData;\r | |
552 | mPrivateData.DataHub.GetNextRecord = DataHubGetNextRecord;\r | |
553 | mPrivateData.DataHub.RegisterFilterDriver = DataHubRegisterFilterDriver;\r | |
554 | mPrivateData.DataHub.UnregisterFilterDriver = DataHubUnregisterFilterDriver;\r | |
555 | \r | |
556 | //\r | |
557 | // Initialize Private Data in CORE_LOGGING_HUB_INSTANCE that is\r | |
2ab23929 | 558 | // required by this protocol\r |
83f6d1a0 | 559 | //\r |
560 | InitializeListHead (&mPrivateData.DataListHead);\r | |
561 | InitializeListHead (&mPrivateData.FilterDriverListHead);\r | |
562 | \r | |
b4c90058 | 563 | EfiInitializeLock (&mPrivateData.DataLock, TPL_NOTIFY);\r |
83f6d1a0 | 564 | \r |
565 | //\r | |
566 | // Make sure we get a bigger MTC number on every boot!\r | |
567 | //\r | |
568 | Status = gRT->GetNextHighMonotonicCount (&HighMontonicCount);\r | |
569 | if (EFI_ERROR (Status)) {\r | |
570 | //\r | |
571 | // if system service fails pick a sane value.\r | |
572 | //\r | |
573 | mPrivateData.GlobalMonotonicCount = 0;\r | |
574 | } else {\r | |
575 | mPrivateData.GlobalMonotonicCount = LShiftU64 ((UINT64) HighMontonicCount, 32);\r | |
576 | }\r | |
577 | //\r | |
578 | // Make a new handle and install the protocol\r | |
579 | //\r | |
580 | mPrivateData.Handle = NULL;\r | |
581 | Status = gBS->InstallProtocolInterface (\r | |
582 | &mPrivateData.Handle,\r | |
583 | &gEfiDataHubProtocolGuid,\r | |
584 | EFI_NATIVE_INTERFACE,\r | |
585 | &mPrivateData.DataHub\r | |
586 | );\r | |
587 | return Status;\r | |
588 | }\r | |
a73d0c74 | 589 | \r |