2 Section Extraction Protocol implementation.
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
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().
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.
15 If a GUIDed encapsulation is encountered, there are three possiblilites.
17 1) A support protocol is found, in which the stream is simply processed with
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.
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.
30 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
31 All rights reserved. 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
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.
41 #ifndef _SECION_EXTRACTION_H_
42 #define _SECION_EXTRACTION_H_
44 #include <FrameworkDxe.h>
46 #include <Protocol/SectionExtraction.h>
48 #include <Library/BaseLib.h>
49 #include <Library/DebugLib.h>
50 #include <Library/UefiLib.h>
51 #include <Library/UefiBootServicesTableLib.h>
52 #include <Library/MemoryAllocationLib.h>
53 #include <Library/BaseMemoryLib.h>
54 #include <Protocol/Decompress.h>
55 #include <Protocol/GuidedSectionExtraction.h>
58 // Local defines and typedefs
60 #define CORE_SECTION_CHILD_SIGNATURE SIGNATURE_32('S','X','C','S')
61 #define CHILD_SECTION_NODE_FROM_LINK(Node) \
62 CR (Node, CORE_SECTION_CHILD_NODE, Link, CORE_SECTION_CHILD_SIGNATURE)
70 // StreamBase + OffsetInStream == pointer to section header in stream. The
71 // stream base is always known when walking the sections within.
73 UINT32 OffsetInStream
;
75 // Then EncapsulatedStreamHandle below is always 0 if the section is NOT an
76 // encapsulating section. Otherwise, it contains the stream handle
77 // of the encapsulated stream. This handle is ALWAYS produced any time an
78 // encapsulating child is encountered, irrespective of whether the
79 // encapsulated stream is processed further.
81 UINTN EncapsulatedStreamHandle
;
82 EFI_GUID
*EncapsulationGuid
;
83 } CORE_SECTION_CHILD_NODE
;
85 #define CORE_SECTION_STREAM_SIGNATURE SIGNATURE_32('S','X','S','S')
86 #define STREAM_NODE_FROM_LINK(Node) \
87 CR (Node, CORE_SECTION_STREAM_NODE, Link, CORE_SECTION_STREAM_SIGNATURE)
97 // Authentication status is from GUIDed encapsulations.
99 UINT32 AuthenticationStatus
;
100 } CORE_SECTION_STREAM_NODE
;
102 #define NULL_STREAM_HANDLE 0
105 CORE_SECTION_CHILD_NODE
*ChildNode
;
106 CORE_SECTION_STREAM_NODE
*ParentStream
;
113 Create a protocol notification event and return it.
115 @param ProtocolGuid Protocol to register notification event on.
116 @param NotifyTpl Maximum TPL to signal the NotifyFunction.
117 @param NotifyFunction EFI notification routine.
118 @param NotifyContext Context passed into Event when it is created.
119 @param Registration Registration key returned from RegisterProtocolNotify().
120 @param SignalFlag Boolean value to decide whether kick the event after register or not.
122 @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
123 is added to the system.
127 CoreCreateProtocolNotifyEvent (
128 IN EFI_GUID
*ProtocolGuid
,
129 IN EFI_TPL NotifyTpl
,
130 IN EFI_EVENT_NOTIFY NotifyFunction
,
131 IN VOID
*NotifyContext
,
132 OUT VOID
**Registration
,
133 IN BOOLEAN SignalFlag
141 Worker function. Determine if the input stream:child matches the input type.
143 @param Stream Indicates the section stream associated with the child
144 @param Child Indicates the child to check
145 @param SearchType Indicates the type of section to check against for
146 @param SectionDefinitionGuid Indicates the GUID to check against if the type is
147 EFI_SECTION_GUID_DEFINED
149 @retval TRUE The child matches
150 @retval FALSE The child doesn't match
155 IN CORE_SECTION_STREAM_NODE
*Stream
,
156 IN CORE_SECTION_CHILD_NODE
*Child
,
157 IN EFI_SECTION_TYPE SearchType
,
158 IN EFI_GUID
*SectionDefinitionGuid
162 RPN callback function. Removes a stale section stream and re-initializes it
163 with an updated AuthenticationStatus.
165 @param Event The event that fired
166 @param RpnContext A pointer to the context that allows us to identify
167 the relevent encapsulation.
172 NotifyGuidedExtraction (
178 Worker function. Constructor for RPN event if needed to keep AuthenticationStatus
179 cache correct when a missing GUIDED_SECTION_EXTRACTION_PROTOCOL appears...
181 @param ParentStream Indicates the parent of the ecnapsulation section (child)
182 @param ChildNode Indicates the child node that is the encapsulation section.
186 CreateGuidedExtractionRpnEvent (
187 IN CORE_SECTION_STREAM_NODE
*ParentStream
,
188 IN CORE_SECTION_CHILD_NODE
*ChildNode
192 SEP member function. This function creates and returns a new section stream
193 handle to represent the new section stream.
195 @param This Indicates the calling context.
196 @param SectionStreamLength Size in bytes of the section stream.
197 @param SectionStream Buffer containing the new section stream.
198 @param SectionStreamHandle A pointer to a caller allocated UINTN that on output
199 contains the new section stream handle.
201 @retval EFI_SUCCESS Section wase opened successfully.
202 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
203 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
210 IN EFI_SECTION_EXTRACTION_PROTOCOL
*This
,
211 IN UINTN SectionStreamLength
,
212 IN VOID
*SectionStream
,
213 OUT UINTN
*SectionStreamHandle
217 SEP member function. Retrieves requested section from section stream.
219 @param This Pointer to SEP instance.
220 @param SectionStreamHandle The section stream from which to extract the requested
222 @param SectionType A pointer to the type of section to search for.
223 @param SectionDefinitionGuid If the section type is EFI_SECTION_GUID_DEFINED, then
224 SectionDefinitionGuid indicates which of these types
225 of sections to search for.
226 @param SectionInstance Indicates which instance of the requested section to
228 @param Buffer Double indirection to buffer. If *Buffer is non-null on
229 input, then the buffer is caller allocated. If
230 *Buffer is NULL, then the buffer is callee allocated.
231 In either case, the requried buffer size is returned
233 @param BufferSize On input, indicates the size of *Buffer if *Buffer is
234 non-null on input. On output, indicates the required
235 size (allocated size if callee allocated) of *Buffer.
236 @param AuthenticationStatus Indicates the authentication status of the retrieved
240 @retval EFI_SUCCESS Section was retrieved successfully
241 @retval EFI_PROTOCOL_ERROR A GUID defined section was encountered in the section
242 stream with its EFI_GUIDED_SECTION_PROCESSING_REQUIRED
243 bit set, but there was no corresponding GUIDed Section
244 Extraction Protocol in the handle database. *Buffer is
246 @retval EFI_NOT_FOUND An error was encountered when parsing the SectionStream.
247 This indicates the SectionStream is not correctly
249 @retval EFI_NOT_FOUND The requested section does not exist.
250 @retval EFI_OUT_OF_RESOURCES The system has insufficient resources to process the
252 @retval EFI_INVALID_PARAMETER The SectionStreamHandle does not exist.
253 @retval EFI_WARN_TOO_SMALL The size of the caller allocated input buffer is
254 insufficient to contain the requested section. The
255 input buffer is filled and contents are section contents
262 IN EFI_SECTION_EXTRACTION_PROTOCOL
*This
,
263 IN UINTN SectionStreamHandle
,
264 IN EFI_SECTION_TYPE
*SectionType
,
265 IN EFI_GUID
*SectionDefinitionGuid
,
266 IN UINTN SectionInstance
,
268 IN OUT UINTN
*BufferSize
,
269 OUT UINT32
*AuthenticationStatus
273 SEP member function. Deletes an existing section stream
275 @param This Indicates the calling context.
276 @param StreamHandleToClose Indicates the stream to close
278 @retval EFI_SUCCESS Section stream was closed successfully.
279 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
280 @retval EFI_INVALID_PARAMETER Section stream does not end concident with end of
287 IN EFI_SECTION_EXTRACTION_PROTOCOL
*This
,
288 IN UINTN StreamHandleToClose
292 Worker function. Search stream database for requested stream handle.
294 @param SearchHandle Indicates which stream to look for.
295 @param FoundStream Output pointer to the found stream.
297 @retval EFI_SUCCESS StreamHandle was found and *FoundStream contains
299 @retval EFI_NOT_FOUND SearchHandle was not found in the stream database.
304 IN UINTN SearchHandle
,
305 OUT CORE_SECTION_STREAM_NODE
**FoundStream
309 Worker function Recursively searches / builds section stream database
310 looking for requested section.
313 @param SourceStream Indicates the section stream in which to do the search.
314 @param SearchType Indicates the type of section to search for.
315 @param SectionInstance Indicates which instance of section to find. This is
316 an in/out parameter to deal with recursions.
317 @param SectionDefinitionGuid Guid of section definition
318 @param FoundChild Output indicating the child node that is found.
319 @param FoundStream Output indicating which section stream the child was
320 found in. If this stream was generated as a result of
321 an encapsulation section, the streamhandle is visible
322 within the SEP driver only.
323 @param AuthenticationStatus Indicates the authentication status of the found section.
325 @retval EFI_SUCCESS Child node was found and returned.
326 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
327 @retval EFI_NOT_FOUND Requested child node does not exist.
328 @retval EFI_PROTOCOL_ERROR A required GUIDED section extraction protocol does not
334 IN CORE_SECTION_STREAM_NODE
*SourceStream
,
335 IN EFI_SECTION_TYPE SearchType
,
336 IN OUT UINTN
*SectionInstance
,
337 IN EFI_GUID
*SectionDefinitionGuid
,
338 OUT CORE_SECTION_CHILD_NODE
**FoundChild
,
339 OUT CORE_SECTION_STREAM_NODE
**FoundStream
,
340 OUT UINT32
*AuthenticationStatus
344 Worker function. Constructor for new child nodes.
346 @param Stream Indicates the section stream in which to add the child.
347 @param ChildOffset Indicates the offset in Stream that is the beginning
348 of the child section.
349 @param ChildNode Indicates the Callee allocated and initialized child.
351 @retval EFI_SUCCESS Child node was found and returned.
352 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
353 @retval EFI_PROTOCOL_ERROR Encapsulation sections produce new stream handles when
354 the child node is created. If the section type is GUID
355 defined, and the extraction GUID does not exist, and
356 producing the stream requires the GUID, then a protocol
357 error is generated and no child is produced.
358 Values returned by OpenSectionStreamEx.
363 IN CORE_SECTION_STREAM_NODE
*Stream
,
364 IN UINT32 ChildOffset
,
365 OUT CORE_SECTION_CHILD_NODE
**ChildNode
369 Worker function. Destructor for child nodes.
371 @param ChildNode Indicates the node to destroy
376 IN CORE_SECTION_CHILD_NODE
*ChildNode
380 Worker function. Constructor for section streams.
382 @param SectionStreamLength Size in bytes of the section stream.
383 @param SectionStream Buffer containing the new section stream.
384 @param AllocateBuffer Indicates whether the stream buffer is to be copied
385 or the input buffer is to be used in place.
386 @param AuthenticationStatus Indicates the default authentication status for the
388 @param SectionStreamHandle A pointer to a caller allocated section stream handle.
390 @retval EFI_SUCCESS Stream was added to stream database.
391 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
395 OpenSectionStreamEx (
396 IN UINTN SectionStreamLength
,
397 IN VOID
*SectionStream
,
398 IN BOOLEAN AllocateBuffer
,
399 IN UINT32 AuthenticationStatus
,
400 OUT UINTN
*SectionStreamHandle
405 Check if a stream is valid.
407 @param SectionStream The section stream to be checked
408 @param SectionStreamLength The length of section stream
410 @return The validness of a stream.
414 IsValidSectionStream (
415 IN VOID
*SectionStream
,
416 IN UINTN SectionStreamLength
419 #endif // _SECTION_EXTRACTION_H_