]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/SectionExtractionDxe/SectionExtraction.c
Refine all R9 call back function to return EFI_UNSUPPORTED for all unsupported call...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / SectionExtractionDxe / SectionExtraction.c
1 /** @file
2 Section Extraction Protocol implementation.
3
4 Stream database is implemented as a linked list of section streams,
5 where each stream contains a linked list of children, which may be leaves or
6 encapsulations.
7
8 Children that are encapsulations generate new stream entries
9 when they are created. Streams can also be created by calls to
10 SEP->OpenSectionStream().
11
12 The database is only created far enough to return the requested data from
13 any given stream, or to determine that the requested data is not found.
14
15 If a GUIDed encapsulation is encountered, there are three possiblilites.
16
17 1) A support protocol is found, in which the stream is simply processed with
18 the support protocol.
19
20 2) A support protocol is not found, but the data is available to be read
21 without processing. In this case, the database is built up through the
22 recursions to return the data, and a RPN event is set that will enable
23 the stream in question to be refreshed if and when the required section
24 extraction protocol is published.This insures the AuthenticationStatus
25 does not become stale in the cache.
26
27 3) A support protocol is not found, and the data is not available to be read
28 without it. This results in EFI_PROTOCOL_ERROR.
29
30 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
31 This program and the accompanying materials
32 are licensed and made available under the terms and conditions of the BSD License
33 which accompanies this distribution. The full text of the license may be found at
34 http://opensource.org/licenses/bsd-license.php
35
36 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
37 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
38
39 **/
40
41 #include <FrameworkDxe.h>
42
43 #include <Library/BaseLib.h>
44 #include <Library/DebugLib.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/MemoryAllocationLib.h>
47 #include <Library/BaseMemoryLib.h>
48 #include <Protocol/Decompress.h>
49 #include <Protocol/GuidedSectionExtraction.h>
50 #include <Protocol/SectionExtraction.h>
51
52 //
53 // Local defines and typedefs
54 //
55 #define FRAMEWORK_SECTION_CHILD_SIGNATURE SIGNATURE_32('S','X','F','S')
56 #define CHILD_SECTION_NODE_FROM_LINK(Node) \
57 CR (Node, FRAMEWORK_SECTION_CHILD_NODE, Link, FRAMEWORK_SECTION_CHILD_SIGNATURE)
58
59 typedef struct {
60 UINT32 Signature;
61 LIST_ENTRY Link;
62 UINT32 Type;
63 UINT32 Size;
64 //
65 // StreamBase + OffsetInStream == pointer to section header in stream. The
66 // stream base is always known when walking the sections within.
67 //
68 UINT32 OffsetInStream;
69 //
70 // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
71 // encapsulating section. Otherwise, it contains the stream handle
72 // of the encapsulated stream. This handle is ALWAYS produced any time an
73 // encapsulating child is encountered, irrespective of whether the
74 // encapsulated stream is processed further.
75 //
76 UINTN EncapsulatedStreamHandle;
77 EFI_GUID *EncapsulationGuid;
78 } FRAMEWORK_SECTION_CHILD_NODE;
79
80 #define FRAMEWORK_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
81 #define STREAM_NODE_FROM_LINK(Node) \
82 CR (Node, FRAMEWORK_SECTION_STREAM_NODE, Link, FRAMEWORK_SECTION_STREAM_SIGNATURE)
83
84 typedef struct {
85 UINT32 Signature;
86 LIST_ENTRY Link;
87 UINTN StreamHandle;
88 UINT8 *StreamBuffer;
89 UINTN StreamLength;
90 LIST_ENTRY Children;
91 //
92 // Authentication status is from GUIDed encapsulations.
93 //
94 UINT32 AuthenticationStatus;
95 } FRAMEWORK_SECTION_STREAM_NODE;
96
97 #define NULL_STREAM_HANDLE 0
98
99 typedef struct {
100 FRAMEWORK_SECTION_CHILD_NODE *ChildNode;
101 FRAMEWORK_SECTION_STREAM_NODE *ParentStream;
102 VOID *Registration;
103 EFI_EVENT Event;
104 } RPN_EVENT_CONTEXT;
105
106 /**
107 SEP member function. This function creates and returns a new section stream
108 handle to represent the new section stream.
109
110 @param This Indicates the calling context.
111 @param SectionStreamLength Size in bytes of the section stream.
112 @param SectionStream Buffer containing the new section stream.
113 @param SectionStreamHandle A pointer to a caller allocated UINTN that on output
114 contains the new section stream handle.
115
116 @retval EFI_SUCCESS Section wase opened successfully.
117 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
118 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
119 last section.
120
121 **/
122 EFI_STATUS
123 EFIAPI
124 OpenSectionStream (
125 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
126 IN UINTN SectionStreamLength,
127 IN VOID *SectionStream,
128 OUT UINTN *SectionStreamHandle
129 )
130 ;
131
132 /**
133 SEP member function. Retrieves requested section from section stream.
134
135 @param This Pointer to SEP instance.
136 @param SectionStreamHandle The section stream from which to extract the requested
137 section.
138 @param SectionType A pointer to the type of section to search for.
139 @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED, then
140 SectionDefinitionGuid indicates which of these types
141 of sections to search for.
142 @param SectionInstance Indicates which instance of the requested section to
143 return.
144 @param Buffer Double indirection to buffer. If *Buffer is non-null on
145 input, then the buffer is caller allocated. If
146 *Buffer is NULL, then the buffer is callee allocated.
147 In either case, the requried buffer size is returned
148 in *BufferSize.
149 @param BufferSize On input, indicates the size of *Buffer if *Buffer is
150 non-null on input. On output, indicates the required
151 size (allocated size if callee allocated) of *Buffer.
152 @param AuthenticationStatus Indicates the authentication status of the retrieved
153 section.
154
155
156 @retval EFI_SUCCESS Section was retrieved successfully
157 @retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the section
158 stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED
159 bit set, but there was no corresponding GUIDed Section
160 Extraction Protocol in the handle database. *Buffer is
161 unmodified.
162 @retval EFI_NOT_FOUND An error was encountered when parsing the SectionStream.
163 This indicates the SectionStream is not correctly
164 formatted.
165 @retval EFI_NOT_FOUND The requested section does not exist.
166 @retval EFI_OUT_OF_RESOURCES The system has insufficient resources to process the
167 request.
168 @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
169 @retval EFI_WARN_TOO_SMALL The size of the caller allocated input buffer is
170 insufficient to contain the requested section. The
171 input buffer is filled and contents are section contents
172 are truncated.
173
174 **/
175 EFI_STATUS
176 EFIAPI
177 GetSection (
178 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
179 IN UINTN SectionStreamHandle,
180 IN EFI_SECTION_TYPE *SectionType,
181 IN EFI_GUID *SectionDefinitionGuid,
182 IN UINTN SectionInstance,
183 IN VOID **Buffer,
184 IN OUT UINTN *BufferSize,
185 OUT UINT32 *AuthenticationStatus
186 )
187 ;
188
189 /**
190 SEP member function. Deletes an existing section stream
191
192 @param This Indicates the calling context.
193 @param StreamHandleToClose Indicates the stream to close
194
195 @retval EFI_SUCCESS Section stream was closed successfully.
196 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
197 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
198 last section.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 CloseSectionStream (
204 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
205 IN UINTN StreamHandleToClose
206 )
207 ;
208
209 //
210 // Module globals
211 //
212 LIST_ENTRY mStreamRoot = INITIALIZE_LIST_HEAD_VARIABLE (mStreamRoot);
213
214 EFI_HANDLE mSectionExtractionHandle = NULL;
215
216 EFI_SECTION_EXTRACTION_PROTOCOL mSectionExtraction = {
217 OpenSectionStream,
218 GetSection,
219 CloseSectionStream
220 };
221
222 /**
223 Entry point of the section extraction code. Initializes an instance of the
224 section extraction interface and installs it on a new handle.
225
226 @param ImageHandle A handle for the image that is initializing this driver
227 @param SystemTable A pointer to the EFI system table
228
229 @retval EFI_SUCCESS Driver initialized successfully
230 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
231
232 **/
233 EFI_STATUS
234 EFIAPI
235 SectionExtractionEntryPoint (
236 IN EFI_HANDLE ImageHandle,
237 IN EFI_SYSTEM_TABLE *SystemTable
238 )
239 {
240 EFI_STATUS Status;
241
242 //
243 // Install SEP to a new handle
244 //
245 Status = gBS->InstallProtocolInterface (
246 &mSectionExtractionHandle,
247 &gEfiSectionExtractionProtocolGuid,
248 EFI_NATIVE_INTERFACE,
249 &mSectionExtraction
250 );
251 ASSERT_EFI_ERROR (Status);
252
253 return Status;
254 }
255
256 /**
257
258 Check if a stream is valid.
259
260 @param SectionStream The section stream to be checked
261 @param SectionStreamLength The length of section stream
262
263 @return A boolean value indicating the validness of the section stream.
264
265 **/
266 BOOLEAN
267 IsValidSectionStream (
268 IN VOID *SectionStream,
269 IN UINTN SectionStreamLength
270 )
271 {
272 UINTN TotalLength;
273 UINTN SectionLength;
274 EFI_COMMON_SECTION_HEADER *SectionHeader;
275 EFI_COMMON_SECTION_HEADER *NextSectionHeader;
276
277 TotalLength = 0;
278 SectionHeader = (EFI_COMMON_SECTION_HEADER *)SectionStream;
279
280 while (TotalLength < SectionStreamLength) {
281 SectionLength = SECTION_SIZE (SectionHeader);
282 TotalLength += SectionLength;
283
284 if (TotalLength == SectionStreamLength) {
285 return TRUE;
286 }
287
288 //
289 // Move to the next byte following the section...
290 //
291 SectionHeader = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) SectionHeader + SectionLength);
292
293 //
294 // Figure out where the next section begins
295 //
296 NextSectionHeader = ALIGN_POINTER(SectionHeader, 4);
297 TotalLength += (UINTN) NextSectionHeader - (UINTN) SectionHeader;
298 SectionHeader = NextSectionHeader;
299 }
300
301 ASSERT (FALSE);
302 return FALSE;
303 }
304
305 /**
306 Worker function. Constructor for section streams.
307
308 @param SectionStreamLength Size in bytes of the section stream.
309 @param SectionStream Buffer containing the new section stream.
310 @param AllocateBuffer Indicates whether the stream buffer is to be copied
311 or the input buffer is to be used in place.
312 @param AuthenticationStatus Indicates the default authentication status for the
313 new stream.
314 @param SectionStreamHandle A pointer to a caller allocated section stream handle.
315
316 @retval EFI_SUCCESS Stream was added to stream database.
317 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
318
319 **/
320 EFI_STATUS
321 OpenSectionStreamEx (
322 IN UINTN SectionStreamLength,
323 IN VOID *SectionStream,
324 IN BOOLEAN AllocateBuffer,
325 IN UINT32 AuthenticationStatus,
326 OUT UINTN *SectionStreamHandle
327 )
328 {
329 FRAMEWORK_SECTION_STREAM_NODE *NewStream;
330 EFI_TPL OldTpl;
331
332 //
333 // Allocate a new stream
334 //
335 NewStream = AllocatePool (sizeof (FRAMEWORK_SECTION_STREAM_NODE));
336 if (NewStream == NULL) {
337 return EFI_OUT_OF_RESOURCES;
338 }
339
340 if (AllocateBuffer) {
341 //
342 // if we're here, we're double buffering, allocate the buffer and copy the
343 // data in
344 //
345 if (SectionStreamLength > 0) {
346 NewStream->StreamBuffer = AllocatePool (SectionStreamLength);
347 if (NewStream->StreamBuffer == NULL) {
348 FreePool (NewStream);
349 return EFI_OUT_OF_RESOURCES;
350 }
351 //
352 // Copy in stream data
353 //
354 CopyMem (NewStream->StreamBuffer, SectionStream, SectionStreamLength);
355 } else {
356 //
357 // It's possible to have a zero length section stream.
358 //
359 NewStream->StreamBuffer = NULL;
360 }
361 } else {
362 //
363 // If were here, the caller has supplied the buffer (it's an internal call)
364 // so just assign the buffer. This happens when we open section streams
365 // as a result of expanding an encapsulating section.
366 //
367 NewStream->StreamBuffer = SectionStream;
368 }
369
370 //
371 // Initialize the rest of the section stream
372 //
373 NewStream->Signature = FRAMEWORK_SECTION_STREAM_SIGNATURE;
374 NewStream->StreamHandle = (UINTN) NewStream;
375 NewStream->StreamLength = SectionStreamLength;
376 InitializeListHead (&NewStream->Children);
377 NewStream->AuthenticationStatus = AuthenticationStatus;
378
379 //
380 // Add new stream to stream list
381 //
382 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
383 InsertTailList (&mStreamRoot, &NewStream->Link);
384 gBS->RestoreTPL (OldTpl);
385
386 *SectionStreamHandle = NewStream->StreamHandle;
387
388 return EFI_SUCCESS;
389 }
390
391 /**
392 SEP member function. This function creates and returns a new section stream
393 handle to represent the new section stream.
394
395 @param This Indicates the calling context.
396 @param SectionStreamLength Size in bytes of the section stream.
397 @param SectionStream Buffer containing the new section stream.
398 @param SectionStreamHandle A pointer to a caller allocated UINTN that on output
399 contains the new section stream handle.
400
401 @retval EFI_SUCCESS Section wase opened successfully.
402 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
403 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
404 last section.
405
406 **/
407 EFI_STATUS
408 EFIAPI
409 OpenSectionStream (
410 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
411 IN UINTN SectionStreamLength,
412 IN VOID *SectionStream,
413 OUT UINTN *SectionStreamHandle
414 )
415 {
416 //
417 // Check to see section stream looks good...
418 //
419 if (!IsValidSectionStream (SectionStream, SectionStreamLength)) {
420 return EFI_INVALID_PARAMETER;
421 }
422
423 return OpenSectionStreamEx (
424 SectionStreamLength,
425 SectionStream,
426 TRUE,
427 0,
428 SectionStreamHandle
429 );
430 }
431
432 /**
433 Worker function. Determine if the input stream:child matches the input type.
434
435 @param Stream Indicates the section stream associated with the child
436 @param Child Indicates the child to check
437 @param SearchType Indicates the type of section to check against for
438 @param SectionDefinitionGuid Indicates the GUID to check against if the type is
439 EFI_SECTION_GUID_DEFINED
440
441 @retval TRUE The child matches
442 @retval FALSE The child doesn't match
443
444 **/
445 BOOLEAN
446 ChildIsType (
447 IN FRAMEWORK_SECTION_STREAM_NODE *Stream,
448 IN FRAMEWORK_SECTION_CHILD_NODE *Child,
449 IN EFI_SECTION_TYPE SearchType,
450 IN EFI_GUID *SectionDefinitionGuid
451 )
452 {
453 EFI_GUID_DEFINED_SECTION *GuidedSection;
454
455 if (SearchType == EFI_SECTION_ALL) {
456 return TRUE;
457 }
458 if (Child->Type != SearchType) {
459 return FALSE;
460 }
461 if ((SearchType != EFI_SECTION_GUID_DEFINED) || (SectionDefinitionGuid == NULL)) {
462 return TRUE;
463 }
464 GuidedSection = (EFI_GUID_DEFINED_SECTION * )(Stream->StreamBuffer + Child->OffsetInStream);
465 return CompareGuid (&GuidedSection->SectionDefinitionGuid, SectionDefinitionGuid);
466 }
467
468 /**
469 Create a protocol notification event and return it.
470
471 @param ProtocolGuid Protocol to register notification event on.
472 @param NotifyTpl Maximum TPL to signal the NotifyFunction.
473 @param NotifyFunction EFI notification routine.
474 @param NotifyContext Context passed into Event when it is created.
475 @param Registration Registration key returned from RegisterProtocolNotify().
476 @param SignalFlag Boolean value to decide whether kick the event after register or not.
477
478 @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
479 is added to the system.
480
481 **/
482 EFI_EVENT
483 CreateProtocolNotifyEvent (
484 IN EFI_GUID *ProtocolGuid,
485 IN EFI_TPL NotifyTpl,
486 IN EFI_EVENT_NOTIFY NotifyFunction,
487 IN VOID *NotifyContext,
488 OUT VOID **Registration,
489 IN BOOLEAN SignalFlag
490 )
491 {
492 EFI_STATUS Status;
493 EFI_EVENT Event;
494
495 //
496 // Create the event
497 //
498
499 Status = gBS->CreateEvent (
500 EVT_NOTIFY_SIGNAL,
501 NotifyTpl,
502 NotifyFunction,
503 NotifyContext,
504 &Event
505 );
506 ASSERT_EFI_ERROR (Status);
507
508 //
509 // Register for protocol notifactions on this event
510 //
511
512 Status = gBS->RegisterProtocolNotify (
513 ProtocolGuid,
514 Event,
515 Registration
516 );
517 ASSERT_EFI_ERROR (Status);
518
519 if (SignalFlag) {
520 //
521 // Kick the event so we will perform an initial pass of
522 // current installed drivers
523 //
524 gBS->SignalEvent (Event);
525 }
526
527 return Event;
528 }
529
530 /**
531 RPN callback function.
532 1. Initialize the section stream when the GUIDED_SECTION_EXTRACTION_PROTOCOL is installed.
533 2. Removes a stale section stream and re-initializes it with an updated AuthenticationStatus.
534
535 @param Event The event that fired
536 @param RpnContext A pointer to the context that allows us to identify
537 the relevent encapsulation.
538
539 **/
540 VOID
541 EFIAPI
542 NotifyGuidedExtraction (
543 IN EFI_EVENT Event,
544 IN VOID *RpnContext
545 )
546 {
547 EFI_STATUS Status;
548 EFI_GUID_DEFINED_SECTION *GuidedHeader;
549 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
550 VOID *NewStreamBuffer;
551 UINTN NewStreamBufferSize;
552 UINT32 AuthenticationStatus;
553 RPN_EVENT_CONTEXT *Context;
554
555 Context = RpnContext;
556 Status = EFI_SUCCESS;
557 if (Context->ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {
558 Status = CloseSectionStream (&mSectionExtraction, Context->ChildNode->EncapsulatedStreamHandle);
559 }
560 if (!EFI_ERROR (Status)) {
561 //
562 // The stream is not initialized, open it.
563 // Or the stream closed successfully, so re-open the stream with correct AuthenticationStatus.
564 //
565
566 GuidedHeader = (EFI_GUID_DEFINED_SECTION *)
567 (Context->ParentStream->StreamBuffer + Context->ChildNode->OffsetInStream);
568 ASSERT (GuidedHeader->CommonHeader.Type == EFI_SECTION_GUID_DEFINED);
569
570 Status = gBS->LocateProtocol (Context->ChildNode->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);
571 ASSERT_EFI_ERROR (Status);
572
573
574 Status = GuidedExtraction->ExtractSection (
575 GuidedExtraction,
576 GuidedHeader,
577 &NewStreamBuffer,
578 &NewStreamBufferSize,
579 &AuthenticationStatus
580 );
581 ASSERT_EFI_ERROR (Status);
582 //
583 // OR in the parent stream's aggregagate status.
584 //
585 AuthenticationStatus |= Context->ParentStream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;
586 Status = OpenSectionStreamEx (
587 NewStreamBufferSize,
588 NewStreamBuffer,
589 FALSE,
590 AuthenticationStatus,
591 &Context->ChildNode->EncapsulatedStreamHandle
592 );
593 ASSERT_EFI_ERROR (Status);
594 }
595
596 //
597 // If above, the stream did not close successfully, it indicates it's
598 // alread been closed by someone, so just destroy the event and be done with
599 // it.
600 //
601
602 gBS->CloseEvent (Event);
603 FreePool (Context);
604 }
605
606 /**
607 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus
608 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...
609
610 @param ParentStream Indicates the parent of the ecnapsulation section (child)
611 @param ChildNode Indicates the child node that is the encapsulation section.
612
613 **/
614 VOID
615 CreateGuidedExtractionRpnEvent (
616 IN FRAMEWORK_SECTION_STREAM_NODE *ParentStream,
617 IN FRAMEWORK_SECTION_CHILD_NODE *ChildNode
618 )
619 {
620 RPN_EVENT_CONTEXT *Context;
621
622 //
623 // Allocate new event structure and context
624 //
625 Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT));
626 ASSERT (Context != NULL);
627
628 Context->ChildNode = ChildNode;
629 Context->ParentStream = ParentStream;
630
631 Context->Event = CreateProtocolNotifyEvent (
632 Context->ChildNode->EncapsulationGuid,
633 TPL_NOTIFY,
634 NotifyGuidedExtraction,
635 Context,
636 &Context->Registration,
637 FALSE
638 );
639 }
640
641 /**
642 Worker function. Constructor for new child nodes.
643
644 @param Stream Indicates the section stream in which to add the child.
645 @param ChildOffset Indicates the offset in Stream that is the beginning
646 of the child section.
647 @param ChildNode Indicates the Callee allocated and initialized child.
648
649 @retval EFI_SUCCESS Child node was found and returned.
650 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
651 @retval EFI_PROTOCOL_ERROR Encapsulation sections produce new stream handles when
652 the child node is created. If the section type is GUID
653 defined, and the extraction GUID does not exist, and
654 producing the stream requires the GUID, then a protocol
655 error is generated and no child is produced.
656 Values returned by OpenSectionStreamEx.
657
658 **/
659 EFI_STATUS
660 CreateChildNode (
661 IN FRAMEWORK_SECTION_STREAM_NODE *Stream,
662 IN UINT32 ChildOffset,
663 OUT FRAMEWORK_SECTION_CHILD_NODE **ChildNode
664 )
665 {
666 EFI_STATUS Status;
667 EFI_COMMON_SECTION_HEADER *SectionHeader;
668 EFI_COMPRESSION_SECTION *CompressionHeader;
669 EFI_GUID_DEFINED_SECTION *GuidedHeader;
670 EFI_DECOMPRESS_PROTOCOL *Decompress;
671 EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL *GuidedExtraction;
672 VOID *NewStreamBuffer;
673 VOID *ScratchBuffer;
674 UINT32 ScratchSize;
675 UINTN NewStreamBufferSize;
676 UINT32 AuthenticationStatus;
677 UINT32 SectionLength;
678
679 FRAMEWORK_SECTION_CHILD_NODE *Node;
680
681 SectionHeader = (EFI_COMMON_SECTION_HEADER *) (Stream->StreamBuffer + ChildOffset);
682
683 //
684 // Allocate a new node
685 //
686 *ChildNode = AllocatePool (sizeof (FRAMEWORK_SECTION_CHILD_NODE));
687 Node = *ChildNode;
688 if (Node == NULL) {
689 return EFI_OUT_OF_RESOURCES;
690 }
691
692 //
693 // Now initialize it
694 //
695 Node->Signature = FRAMEWORK_SECTION_CHILD_SIGNATURE;
696 Node->Type = SectionHeader->Type;
697 Node->Size = SECTION_SIZE (SectionHeader);
698 Node->OffsetInStream = ChildOffset;
699 Node->EncapsulatedStreamHandle = NULL_STREAM_HANDLE;
700 Node->EncapsulationGuid = NULL;
701
702 //
703 // If it's an encapsulating section, then create the new section stream also
704 //
705 switch (Node->Type) {
706 case EFI_SECTION_COMPRESSION:
707 //
708 // Get the CompressionSectionHeader
709 //
710 ASSERT (Node->Size >= sizeof (EFI_COMPRESSION_SECTION));
711
712 CompressionHeader = (EFI_COMPRESSION_SECTION *) SectionHeader;
713
714 //
715 // Allocate space for the new stream
716 //
717 if (CompressionHeader->UncompressedLength > 0) {
718 NewStreamBufferSize = CompressionHeader->UncompressedLength;
719 NewStreamBuffer = AllocatePool (NewStreamBufferSize);
720 if (NewStreamBuffer == NULL) {
721 FreePool (Node);
722 return EFI_OUT_OF_RESOURCES;
723 }
724
725 if (CompressionHeader->CompressionType == EFI_NOT_COMPRESSED) {
726 //
727 // stream is not actually compressed, just encapsulated. So just copy it.
728 //
729 CopyMem (NewStreamBuffer, CompressionHeader + 1, NewStreamBufferSize);
730 } else if (CompressionHeader->CompressionType == EFI_STANDARD_COMPRESSION) {
731 //
732 // Only support the EFI_SATNDARD_COMPRESSION algorithm.
733 //
734
735 //
736 // Decompress the stream
737 //
738 Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);
739
740 ASSERT_EFI_ERROR (Status);
741
742 Status = Decompress->GetInfo (
743 Decompress,
744 CompressionHeader + 1,
745 Node->Size - sizeof (EFI_COMPRESSION_SECTION),
746 (UINT32 *)&NewStreamBufferSize,
747 &ScratchSize
748 );
749 ASSERT_EFI_ERROR (Status);
750 ASSERT (NewStreamBufferSize == CompressionHeader->UncompressedLength);
751
752 ScratchBuffer = AllocatePool (ScratchSize);
753 if (ScratchBuffer == NULL) {
754 FreePool (Node);
755 FreePool (NewStreamBuffer);
756 return EFI_OUT_OF_RESOURCES;
757 }
758
759 Status = Decompress->Decompress (
760 Decompress,
761 CompressionHeader + 1,
762 Node->Size - sizeof (EFI_COMPRESSION_SECTION),
763 NewStreamBuffer,
764 (UINT32)NewStreamBufferSize,
765 ScratchBuffer,
766 ScratchSize
767 );
768 ASSERT_EFI_ERROR (Status);
769 FreePool (ScratchBuffer);
770 }
771 } else {
772 NewStreamBuffer = NULL;
773 NewStreamBufferSize = 0;
774 }
775
776 Status = OpenSectionStreamEx (
777 NewStreamBufferSize,
778 NewStreamBuffer,
779 FALSE,
780 Stream->AuthenticationStatus,
781 &Node->EncapsulatedStreamHandle
782 );
783 if (EFI_ERROR (Status)) {
784 FreePool (Node);
785 FreePool (NewStreamBuffer);
786 return Status;
787 }
788 break;
789
790 case EFI_SECTION_GUID_DEFINED:
791 GuidedHeader = (EFI_GUID_DEFINED_SECTION *) SectionHeader;
792 Node->EncapsulationGuid = &GuidedHeader->SectionDefinitionGuid;
793 Status = gBS->LocateProtocol (Node->EncapsulationGuid, NULL, (VOID **)&GuidedExtraction);
794 if (!EFI_ERROR (Status)) {
795 //
796 // NewStreamBuffer is always allocated by ExtractSection... No caller
797 // allocation here.
798 //
799 Status = GuidedExtraction->ExtractSection (
800 GuidedExtraction,
801 GuidedHeader,
802 &NewStreamBuffer,
803 &NewStreamBufferSize,
804 &AuthenticationStatus
805 );
806 if (EFI_ERROR (Status)) {
807 FreePool (*ChildNode);
808 return EFI_PROTOCOL_ERROR;
809 }
810
811 //
812 // Make sure we initialize the new stream with the correct
813 // authentication status for both aggregate and local status fields.
814 //
815 if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {
816 //
817 // OR in the parent stream's aggregate status.
818 //
819 AuthenticationStatus |= Stream->AuthenticationStatus & EFI_AGGREGATE_AUTH_STATUS_ALL;
820 } else {
821 //
822 // since there's no authentication data contributed by the section,
823 // just inherit the full value from our immediate parent.
824 //
825 AuthenticationStatus = Stream->AuthenticationStatus;
826 }
827
828 Status = OpenSectionStreamEx (
829 NewStreamBufferSize,
830 NewStreamBuffer,
831 FALSE,
832 AuthenticationStatus,
833 &Node->EncapsulatedStreamHandle
834 );
835 if (EFI_ERROR (Status)) {
836 FreePool (*ChildNode);
837 FreePool (NewStreamBuffer);
838 return Status;
839 }
840 } else {
841 //
842 // There's no GUIDed section extraction protocol available.
843 //
844 if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) == EFI_GUIDED_SECTION_PROCESSING_REQUIRED) {
845 //
846 // If the section REQUIRES an extraction protocol, register for RPN
847 // when the required GUIDed extraction protocol becomes available.
848 //
849 AuthenticationStatus = 0;
850 CreateGuidedExtractionRpnEvent (Stream, Node);
851 } else {
852 //
853 // Figure out the proper authentication status
854 //
855 AuthenticationStatus = Stream->AuthenticationStatus;
856 if ((GuidedHeader->Attributes & EFI_GUIDED_SECTION_AUTH_STATUS_VALID) == EFI_GUIDED_SECTION_AUTH_STATUS_VALID) {
857 //
858 // The local status of the new stream is contained in
859 // AuthenticaionStatus. This value needs to be ORed into the
860 // Aggregate bits also...
861 //
862
863 //
864 // Clear out and initialize the local status
865 //
866 AuthenticationStatus &= ~EFI_LOCAL_AUTH_STATUS_ALL;
867 AuthenticationStatus |= EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED;
868 //
869 // OR local status into aggregate status
870 //
871 AuthenticationStatus |= AuthenticationStatus >> 16;
872 }
873
874 SectionLength = SECTION_SIZE (GuidedHeader);
875 Status = OpenSectionStreamEx (
876 SectionLength - GuidedHeader->DataOffset,
877 (UINT8 *) GuidedHeader + GuidedHeader->DataOffset,
878 TRUE,
879 AuthenticationStatus,
880 &Node->EncapsulatedStreamHandle
881 );
882 if (EFI_ERROR (Status)) {
883 FreePool (Node);
884 return Status;
885 }
886 }
887 }
888
889 if ((AuthenticationStatus & EFI_LOCAL_AUTH_STATUS_ALL) ==
890 (EFI_LOCAL_AUTH_STATUS_IMAGE_SIGNED | EFI_LOCAL_AUTH_STATUS_NOT_TESTED)) {
891 //
892 // Need to register for RPN for when the required GUIDed extraction
893 // protocol becomes available. This will enable us to refresh the
894 // AuthenticationStatus cached in the Stream if it's ever requested
895 // again.
896 //
897 CreateGuidedExtractionRpnEvent (Stream, Node);
898 }
899
900 break;
901
902 default:
903
904 //
905 // Nothing to do if it's a leaf
906 //
907 break;
908 }
909
910 //
911 // Last, add the new child node to the stream
912 //
913 InsertTailList (&Stream->Children, &Node->Link);
914
915 return EFI_SUCCESS;
916 }
917
918 /**
919 Worker function Recursively searches / builds section stream database
920 looking for requested section.
921
922
923 @param SourceStream Indicates the section stream in which to do the search.
924 @param SearchType Indicates the type of section to search for.
925 @param SectionInstance Indicates which instance of section to find. This is
926 an in/out parameter to deal with recursions.
927 @param SectionDefinitionGuid Guid of section definition
928 @param FoundChild Output indicating the child node that is found.
929 @param FoundStream Output indicating which section stream the child was
930 found in. If this stream was generated as a result of
931 an encapsulation section, the streamhandle is visible
932 within the SEP driver only.
933 @param AuthenticationStatus Indicates the authentication status of the found section.
934
935 @retval EFI_SUCCESS Child node was found and returned.
936 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
937 @retval EFI_NOT_FOUND Requested child node does not exist.
938 @retval EFI_PROTOCOL_ERROR A required GUIDED section extraction protocol does not
939 exist
940
941 **/
942 EFI_STATUS
943 FindChildNode (
944 IN FRAMEWORK_SECTION_STREAM_NODE *SourceStream,
945 IN EFI_SECTION_TYPE SearchType,
946 IN OUT UINTN *SectionInstance,
947 IN EFI_GUID *SectionDefinitionGuid,
948 OUT FRAMEWORK_SECTION_CHILD_NODE **FoundChild,
949 OUT FRAMEWORK_SECTION_STREAM_NODE **FoundStream,
950 OUT UINT32 *AuthenticationStatus
951 )
952 {
953 FRAMEWORK_SECTION_CHILD_NODE *CurrentChildNode;
954 FRAMEWORK_SECTION_CHILD_NODE *RecursedChildNode;
955 FRAMEWORK_SECTION_STREAM_NODE *RecursedFoundStream;
956 UINT32 NextChildOffset;
957 EFI_STATUS ErrorStatus;
958 EFI_STATUS Status;
959
960 CurrentChildNode = NULL;
961 ErrorStatus = EFI_NOT_FOUND;
962
963 if (SourceStream->StreamLength == 0) {
964 return EFI_NOT_FOUND;
965 }
966
967 if (IsListEmpty (&SourceStream->Children) &&
968 SourceStream->StreamLength >= sizeof (EFI_COMMON_SECTION_HEADER)) {
969 //
970 // This occurs when a section stream exists, but no child sections
971 // have been parsed out yet. Therefore, extract the first child and add it
972 // to the list of children so we can get started.
973 // Section stream may contain an array of zero or more bytes.
974 // So, its size should be >= the size of commen section header.
975 //
976 Status = CreateChildNode (SourceStream, 0, &CurrentChildNode);
977 if (EFI_ERROR (Status)) {
978 return Status;
979 }
980 }
981
982 //
983 // At least one child has been parsed out of the section stream. So, walk
984 // through the sections that have already been parsed out looking for the
985 // requested section, if necessary, continue parsing section stream and
986 // adding children until either the requested section is found, or we run
987 // out of data
988 //
989 CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetFirstNode(&SourceStream->Children));
990
991 for (;;) {
992 if (ChildIsType (SourceStream, CurrentChildNode, SearchType, SectionDefinitionGuid)) {
993 //
994 // The type matches, so check the instance count to see if it's the one we want
995 //
996 (*SectionInstance)--;
997 if (*SectionInstance == 0) {
998 //
999 // Got it!
1000 //
1001 *FoundChild = CurrentChildNode;
1002 *FoundStream = SourceStream;
1003 *AuthenticationStatus = SourceStream->AuthenticationStatus;
1004 return EFI_SUCCESS;
1005 }
1006 }
1007
1008 ASSERT (CurrentChildNode != NULL);
1009 if (CurrentChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {
1010 //
1011 // If the current node is an encapsulating node, recurse into it...
1012 //
1013 Status = FindChildNode (
1014 (FRAMEWORK_SECTION_STREAM_NODE *)CurrentChildNode->EncapsulatedStreamHandle,
1015 SearchType,
1016 SectionInstance,
1017 SectionDefinitionGuid,
1018 &RecursedChildNode,
1019 &RecursedFoundStream,
1020 AuthenticationStatus
1021 );
1022 //
1023 // If the status is not EFI_SUCCESS, just save the error code and continue
1024 // to find the request child node in the rest stream.
1025 //
1026 if (*SectionInstance == 0) {
1027 ASSERT_EFI_ERROR (Status);
1028 *FoundChild = RecursedChildNode;
1029 *FoundStream = RecursedFoundStream;
1030 return EFI_SUCCESS;
1031 } else {
1032 ErrorStatus = Status;
1033 }
1034 } else if ((CurrentChildNode->Type == EFI_SECTION_GUID_DEFINED) && (SearchType != EFI_SECTION_GUID_DEFINED)) {
1035 //
1036 // When Node Type is GUIDED section, but Node has no encapsulated data, Node data should not be parsed
1037 // because a required GUIDED section extraction protocol does not exist.
1038 // If SearchType is not GUIDED section, EFI_PROTOCOL_ERROR should return.
1039 //
1040 ErrorStatus = EFI_PROTOCOL_ERROR;
1041 }
1042
1043 if (!IsNodeAtEnd (&SourceStream->Children, &CurrentChildNode->Link)) {
1044 //
1045 // We haven't found the child node we're interested in yet, but there's
1046 // still more nodes that have already been parsed so get the next one
1047 // and continue searching..
1048 //
1049 CurrentChildNode = CHILD_SECTION_NODE_FROM_LINK (GetNextNode (&SourceStream->Children, &CurrentChildNode->Link));
1050 } else {
1051 //
1052 // We've exhausted children that have already been parsed, so see if
1053 // there's any more data and continue parsing out more children if there
1054 // is.
1055 //
1056 NextChildOffset = CurrentChildNode->OffsetInStream + CurrentChildNode->Size;
1057 //
1058 // Round up to 4 byte boundary
1059 //
1060 NextChildOffset += 3;
1061 NextChildOffset &= ~(UINTN)3;
1062 if (NextChildOffset <= SourceStream->StreamLength - sizeof (EFI_COMMON_SECTION_HEADER)) {
1063 //
1064 // There's an unparsed child remaining in the stream, so create a new child node
1065 //
1066 Status = CreateChildNode (SourceStream, NextChildOffset, &CurrentChildNode);
1067 if (EFI_ERROR (Status)) {
1068 return Status;
1069 }
1070 } else {
1071 ASSERT (EFI_ERROR (ErrorStatus));
1072 return ErrorStatus;
1073 }
1074 }
1075 }
1076 }
1077
1078 /**
1079 Worker function. Search stream database for requested stream handle.
1080
1081 @param SearchHandle Indicates which stream to look for.
1082 @param FoundStream Output pointer to the found stream.
1083
1084 @retval EFI_SUCCESS StreamHandle was found and *FoundStream contains
1085 the stream node.
1086 @retval EFI_NOT_FOUND SearchHandle was not found in the stream database.
1087
1088 **/
1089 EFI_STATUS
1090 FindStreamNode (
1091 IN UINTN SearchHandle,
1092 OUT FRAMEWORK_SECTION_STREAM_NODE **FoundStream
1093 )
1094 {
1095 FRAMEWORK_SECTION_STREAM_NODE *StreamNode;
1096
1097 if (!IsListEmpty (&mStreamRoot)) {
1098 StreamNode = STREAM_NODE_FROM_LINK (GetFirstNode (&mStreamRoot));
1099 for (;;) {
1100 if (StreamNode->StreamHandle == SearchHandle) {
1101 *FoundStream = StreamNode;
1102 return EFI_SUCCESS;
1103 } else if (IsNodeAtEnd (&mStreamRoot, &StreamNode->Link)) {
1104 break;
1105 } else {
1106 StreamNode = STREAM_NODE_FROM_LINK (GetNextNode (&mStreamRoot, &StreamNode->Link));
1107 }
1108 }
1109 }
1110
1111 return EFI_NOT_FOUND;
1112 }
1113
1114 /**
1115 SEP member function. Retrieves requested section from section stream.
1116
1117 @param This Pointer to SEP instance.
1118 @param SectionStreamHandle The section stream from which to extract the requested
1119 section.
1120 @param SectionType A pointer to the type of section to search for.
1121 @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED, then
1122 SectionDefinitionGuid indicates which of these types
1123 of sections to search for.
1124 @param SectionInstance Indicates which instance of the requested section to
1125 return.
1126 @param Buffer Double indirection to buffer. If *Buffer is non-null on
1127 input, then the buffer is caller allocated. If
1128 *Buffer is NULL, then the buffer is callee allocated.
1129 In either case, the requried buffer size is returned
1130 in *BufferSize.
1131 @param BufferSize On input, indicates the size of *Buffer if *Buffer is
1132 non-null on input. On output, indicates the required
1133 size (allocated size if callee allocated) of *Buffer.
1134 @param AuthenticationStatus Indicates the authentication status of the retrieved
1135 section.
1136
1137
1138 @retval EFI_SUCCESS Section was retrieved successfully
1139 @retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the section
1140 stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED
1141 bit set, but there was no corresponding GUIDed Section
1142 Extraction Protocol in the handle database. *Buffer is
1143 unmodified.
1144 @retval EFI_NOT_FOUND An error was encountered when parsing the SectionStream.
1145 This indicates the SectionStream is not correctly
1146 formatted.
1147 @retval EFI_NOT_FOUND The requested section does not exist.
1148 @retval EFI_OUT_OF_RESOURCES The system has insufficient resources to process the
1149 request.
1150 @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
1151 @retval EFI_WARN_TOO_SMALL The size of the caller allocated input buffer is
1152 insufficient to contain the requested section. The
1153 input buffer is filled and contents are section contents
1154 are truncated.
1155
1156 **/
1157 EFI_STATUS
1158 EFIAPI
1159 GetSection (
1160 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
1161 IN UINTN SectionStreamHandle,
1162 IN EFI_SECTION_TYPE *SectionType,
1163 IN EFI_GUID *SectionDefinitionGuid,
1164 IN UINTN SectionInstance,
1165 IN VOID **Buffer,
1166 IN OUT UINTN *BufferSize,
1167 OUT UINT32 *AuthenticationStatus
1168 )
1169 {
1170 FRAMEWORK_SECTION_STREAM_NODE *StreamNode;
1171 EFI_TPL OldTpl;
1172 EFI_STATUS Status;
1173 FRAMEWORK_SECTION_CHILD_NODE *ChildNode;
1174 FRAMEWORK_SECTION_STREAM_NODE *ChildStreamNode;
1175 UINTN CopySize;
1176 UINT32 ExtractedAuthenticationStatus;
1177 UINTN Instance;
1178 UINT8 *CopyBuffer;
1179 UINTN SectionSize;
1180
1181
1182 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1183 Instance = SectionInstance + 1;
1184
1185 //
1186 // Locate target stream
1187 //
1188 Status = FindStreamNode (SectionStreamHandle, &StreamNode);
1189 if (EFI_ERROR (Status)) {
1190 Status = EFI_INVALID_PARAMETER;
1191 goto GetSection_Done;
1192 }
1193
1194 //
1195 // Found the stream, now locate and return the appropriate section
1196 //
1197 if (SectionType == NULL) {
1198 //
1199 // SectionType == NULL means return the WHOLE section stream...
1200 //
1201 CopySize = StreamNode->StreamLength;
1202 CopyBuffer = StreamNode->StreamBuffer;
1203 *AuthenticationStatus = StreamNode->AuthenticationStatus;
1204 } else {
1205 //
1206 // There's a requested section type, so go find it and return it...
1207 //
1208 Status = FindChildNode (
1209 StreamNode,
1210 *SectionType,
1211 &Instance,
1212 SectionDefinitionGuid,
1213 &ChildNode,
1214 &ChildStreamNode,
1215 &ExtractedAuthenticationStatus
1216 );
1217 if (EFI_ERROR (Status)) {
1218 goto GetSection_Done;
1219 }
1220 ASSERT (ChildNode != NULL);
1221 ASSERT (ChildStreamNode != NULL);
1222 CopySize = ChildNode->Size - sizeof (EFI_COMMON_SECTION_HEADER);
1223 CopyBuffer = ChildStreamNode->StreamBuffer + ChildNode->OffsetInStream + sizeof (EFI_COMMON_SECTION_HEADER);
1224 *AuthenticationStatus = ExtractedAuthenticationStatus;
1225 }
1226
1227 SectionSize = CopySize;
1228 if (*Buffer != NULL) {
1229 //
1230 // Caller allocated buffer. Fill to size and return required size...
1231 //
1232 if (*BufferSize < CopySize) {
1233 Status = EFI_WARN_BUFFER_TOO_SMALL;
1234 CopySize = *BufferSize;
1235 }
1236 } else {
1237 //
1238 // Callee allocated buffer. Allocate buffer and return size.
1239 //
1240 *Buffer = AllocatePool (CopySize);
1241 if (*Buffer == NULL) {
1242 Status = EFI_OUT_OF_RESOURCES;
1243 goto GetSection_Done;
1244 }
1245 }
1246 CopyMem (*Buffer, CopyBuffer, CopySize);
1247 *BufferSize = SectionSize;
1248
1249 GetSection_Done:
1250 gBS->RestoreTPL (OldTpl);
1251 return Status;
1252 }
1253
1254 /**
1255 Worker function. Destructor for child nodes.
1256
1257 @param ChildNode Indicates the node to destroy
1258
1259 **/
1260 VOID
1261 FreeChildNode (
1262 IN FRAMEWORK_SECTION_CHILD_NODE *ChildNode
1263 )
1264 {
1265 ASSERT (ChildNode->Signature == FRAMEWORK_SECTION_CHILD_SIGNATURE);
1266 //
1267 // Remove the child from it's list
1268 //
1269 RemoveEntryList (&ChildNode->Link);
1270
1271 if (ChildNode->EncapsulatedStreamHandle != NULL_STREAM_HANDLE) {
1272 //
1273 // If it's an encapsulating section, we close the resulting section stream.
1274 // CloseSectionStream will free all memory associated with the stream.
1275 //
1276 CloseSectionStream (&mSectionExtraction, ChildNode->EncapsulatedStreamHandle);
1277 }
1278 //
1279 // Last, free the child node itself
1280 //
1281 FreePool (ChildNode);
1282 }
1283
1284 /**
1285 SEP member function. Deletes an existing section stream
1286
1287 @param This Indicates the calling context.
1288 @param StreamHandleToClose Indicates the stream to close
1289
1290 @retval EFI_SUCCESS Section stream was closed successfully.
1291 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
1292 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
1293 last section.
1294
1295 **/
1296 EFI_STATUS
1297 EFIAPI
1298 CloseSectionStream (
1299 IN EFI_SECTION_EXTRACTION_PROTOCOL *This,
1300 IN UINTN StreamHandleToClose
1301 )
1302 {
1303 FRAMEWORK_SECTION_STREAM_NODE *StreamNode;
1304 EFI_TPL OldTpl;
1305 EFI_STATUS Status;
1306 LIST_ENTRY *Link;
1307 FRAMEWORK_SECTION_CHILD_NODE *ChildNode;
1308
1309 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1310
1311 //
1312 // Locate target stream
1313 //
1314 Status = FindStreamNode (StreamHandleToClose, &StreamNode);
1315 if (!EFI_ERROR (Status)) {
1316 //
1317 // Found the stream, so close it
1318 //
1319 RemoveEntryList (&StreamNode->Link);
1320 while (!IsListEmpty (&StreamNode->Children)) {
1321 Link = GetFirstNode (&StreamNode->Children);
1322 ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
1323 FreeChildNode (ChildNode);
1324 }
1325 FreePool (StreamNode->StreamBuffer);
1326 FreePool (StreamNode);
1327 Status = EFI_SUCCESS;
1328 } else {
1329 Status = EFI_INVALID_PARAMETER;
1330 }
1331
1332 gBS->RestoreTPL (OldTpl);
1333 return Status;
1334 }