TianoCore EDK2 master
Loading...
Searching...
No Matches
AmlStream.h File Reference
#include <AmlInclude.h>

Go to the source code of this file.

Data Structures

struct  AmlStream
 

Macros

#define IS_STREAM(Stream)
 
#define IS_END_OF_STREAM(Stream)
 
#define IS_STREAM_FORWARD(Stream)
 
#define IS_STREAM_BACKWARD(Stream)
 

Typedefs

typedef enum EAmlStreamDirection EAML_STREAM_DIRECTION
 
typedef struct AmlStream AML_STREAM
 

Enumerations

enum  EAmlStreamDirection { EAmlStreamDirectionInvalid , EAmlStreamDirectionForward , EAmlStreamDirectionBackward , EAmlStreamDirectionMax }
 

Functions

EFI_STATUS EFIAPI AmlStreamInit (IN OUT AML_STREAM *Stream, IN UINT8 *Buffer, IN UINT32 MaxBufferSize, IN EAML_STREAM_DIRECTION Direction)
 
EFI_STATUS EFIAPI AmlStreamClone (IN CONST AML_STREAM *Stream, OUT AML_STREAM *ClonedStream)
 
EFI_STATUS EFIAPI AmlStreamInitSubStream (IN CONST AML_STREAM *Stream, OUT AML_STREAM *SubStream)
 
UINT8 *EFIAPI AmlStreamGetBuffer (IN CONST AML_STREAM *Stream)
 
UINT32 EFIAPI AmlStreamGetMaxBufferSize (IN CONST AML_STREAM *Stream)
 
EFI_STATUS EFIAPI AmlStreamReduceMaxBufferSize (IN AML_STREAM *Stream, IN UINT32 Diff)
 
UINT32 EFIAPI AmlStreamGetIndex (IN CONST AML_STREAM *Stream)
 
EAML_STREAM_DIRECTION EFIAPI AmlStreamGetDirection (IN CONST AML_STREAM *Stream)
 
UINT8 *EFIAPI AmlStreamGetCurrPos (IN CONST AML_STREAM *Stream)
 
UINT32 EFIAPI AmlStreamGetFreeSpace (IN CONST AML_STREAM *Stream)
 
EFI_STATUS EFIAPI AmlStreamProgress (IN AML_STREAM *Stream, IN UINT32 Offset)
 
EFI_STATUS EFIAPI AmlStreamRewind (IN AML_STREAM *Stream, IN UINT32 Offset)
 
EFI_STATUS EFIAPI AmlStreamReset (IN AML_STREAM *Stream)
 
EFI_STATUS EFIAPI AmlStreamPeekByte (IN AML_STREAM *Stream, OUT UINT8 *OutByte)
 
EFI_STATUS EFIAPI AmlStreamReadByte (IN AML_STREAM *Stream, OUT UINT8 *OutByte)
 
EFI_STATUS EFIAPI AmlStreamWrite (IN AML_STREAM *Stream, IN CONST UINT8 *Buffer, IN UINT32 Size)
 
BOOLEAN EFIAPI AmlStreamCmp (IN CONST AML_STREAM *Stream1, IN CONST AML_STREAM *Stream2, IN UINT32 Size)
 
EFI_STATUS EFIAPI AmlStreamCpyS (OUT CHAR8 *DstBuffer, IN UINT32 MaxDstBufferSize, IN AML_STREAM *Stream, IN UINT32 Size)
 

Detailed Description

AML Stream.

Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file AmlStream.h.

Macro Definition Documentation

◆ IS_END_OF_STREAM

#define IS_END_OF_STREAM (   Stream)
Value:
( \
(((AML_STREAM*)Stream)->Index == \
((AML_STREAM*)Stream)->MaxBufferSize))

Check whether a Stream is at the end of its buffer.

Parameters
[in]StreamPointer to a stream.
Return values
TRUEStream is a pointer to a non-full stream.
FALSEOtherwise.

Definition at line 80 of file AmlStream.h.

◆ IS_STREAM

#define IS_STREAM (   Stream)
Value:
( \
(((AML_STREAM*)Stream) != NULL) && \
(((AML_STREAM*)Stream)->Buffer != NULL))
#define NULL
Definition: Base.h:319

Check whether a StreamPtr is a valid Stream.

Parameters
[in]StreamPointer to a stream.
Return values
TRUEStream is a pointer to a stream.
FALSEOtherwise.

Definition at line 69 of file AmlStream.h.

◆ IS_STREAM_BACKWARD

#define IS_STREAM_BACKWARD (   Stream)
Value:
( \
((AML_STREAM*)Stream)->Direction == EAmlStreamDirectionBackward)
@ EAmlStreamDirectionBackward
Definition: AmlStream.h:22

Check Stream goes backward.

Parameters
[in]StreamPointer to a stream.
Return values
TRUEStream goes backward.
FALSEOtherwise.

Definition at line 101 of file AmlStream.h.

◆ IS_STREAM_FORWARD

#define IS_STREAM_FORWARD (   Stream)
Value:
( \
((AML_STREAM*)Stream)->Direction == EAmlStreamDirectionForward)
@ EAmlStreamDirectionForward
Definition: AmlStream.h:20

Check Stream goes forward.

Parameters
[in]StreamPointer to a stream.
Return values
TRUEStream goes forward.
FALSEOtherwise.

Definition at line 91 of file AmlStream.h.

Typedef Documentation

◆ AML_STREAM

typedef struct AmlStream AML_STREAM

Stream.

This structure is used as a wrapper around a buffer. It allows to do common buffer manipulations (read, write, etc.) while preventing buffer overflows.

◆ EAML_STREAM_DIRECTION

Stream direction.

Enum to choose the direction the stream is progressing.

Enumeration Type Documentation

◆ EAmlStreamDirection

Stream direction.

Enum to choose the direction the stream is progressing.

Enumerator
EAmlStreamDirectionInvalid 

Invalid AML Stream direction.

EAmlStreamDirectionForward 

Forward direction. The Stream goes toward higher addresses.

EAmlStreamDirectionBackward 

Forward direction. The Stream goes toward lower addresses.

EAmlStreamDirectionMax 

Max enum.

Definition at line 18 of file AmlStream.h.

Function Documentation

◆ AmlStreamClone()

EFI_STATUS EFIAPI AmlStreamClone ( IN CONST AML_STREAM Stream,
OUT AML_STREAM ClonedStream 
)

Clone a stream.

Cloning a stream means copying all the values of the input Stream in the ClonedStream.

Parameters
[in]StreamPointer to the stream to clone.
[in]ClonedStreamPointer to the stream to initialize.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Clone a stream.

Cloning a stream means copying all the values of the input Stream in the ClonedStream.

Parameters
[in]StreamPointer to the stream to clone.
[out]ClonedStreamPointer to the stream to initialize.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 63 of file AmlStream.c.

◆ AmlStreamCmp()

BOOLEAN EFIAPI AmlStreamCmp ( IN CONST AML_STREAM Stream1,
IN CONST AML_STREAM Stream2,
IN UINT32  Size 
)

Compare Size bytes between Stream1 and Stream2 from their respective current position.

Stream1 and Stream2 must go in the same direction. Stream1 and Stream2 are left unchanged.

Parameters
[in]Stream1First stream to compare. The stream must not be at its end.
[in]Stream2Second stream to compare. The stream must not be at its end.
[in]SizeNumber of bytes to compare. Must be lower than the minimum remaining space of Stream1 and Stream2. Must be non-zero.
Return values
TRUEIf Stream1 and Stream2 have Size bytes equal, from their respective current position. The function completed successfully.
FALSEOtherwise.

Definition at line 569 of file AmlStream.c.

◆ AmlStreamCpyS()

EFI_STATUS EFIAPI AmlStreamCpyS ( OUT CHAR8 *  DstBuffer,
IN UINT32  MaxDstBufferSize,
IN AML_STREAM Stream,
IN UINT32  Size 
)

Copy Size bytes of the stream's data to DstBuffer.

For a backward stream, the bytes are copied starting from the current stream position.

Parameters
[out]DstBufferDestination Buffer to copy the data to.
[in]MaxDstBufferSizeMaximum size of DstBuffer. Must be non-zero.
[in]StreamPointer to the stream to copy the data from.
[in]SizeNumber of bytes to copy from the stream buffer. Must be lower than MaxDstBufferSize. Must be lower than Stream's MaxBufferSize. Return success if zero.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 650 of file AmlStream.c.

◆ AmlStreamGetBuffer()

UINT8 *EFIAPI AmlStreamGetBuffer ( IN CONST AML_STREAM Stream)

Get the buffer of a stream.

Parameters
[in]StreamPointer to a stream.
Returns
The stream's Buffer. NULL otherwise.

Definition at line 146 of file AmlStream.c.

◆ AmlStreamGetCurrPos()

UINT8 *EFIAPI AmlStreamGetCurrPos ( IN CONST AML_STREAM Stream)

Return a pointer to the current position in the stream.

Parameters
[in]StreamPointer to a stream.
Returns
The current position in the stream. Return NULL if error.

Definition at line 264 of file AmlStream.c.

◆ AmlStreamGetDirection()

EAML_STREAM_DIRECTION EFIAPI AmlStreamGetDirection ( IN CONST AML_STREAM Stream)

Get Stream's Direction.

Parameters
[in]StreamPointer to a stream.
Returns
Stream's Direction. Return EAmlStreamDirectionUnknown if Stream is invalid.

Definition at line 243 of file AmlStream.c.

◆ AmlStreamGetFreeSpace()

UINT32 EFIAPI AmlStreamGetFreeSpace ( IN CONST AML_STREAM Stream)

Get the space available in the stream.

Parameters
[in]StreamPointer to a stream.
Returns
Remaining space available in the stream. Zero in case of error or if the stream is at its end.

Definition at line 292 of file AmlStream.c.

◆ AmlStreamGetIndex()

UINT32 EFIAPI AmlStreamGetIndex ( IN CONST AML_STREAM Stream)

Get Stream's Index.

Stream's Index is incremented when writing data, reading data, or moving the position in the Stream. It can be seen as an index:

  • starting at the beginning of Stream's Buffer if the stream goes forward;
  • starting at the end of Stream's Buffer if the stream goes backward.
Parameters
[in]StreamPointer to a stream.
Returns
Stream's Index. Return 0 if Stream is invalid.

Definition at line 222 of file AmlStream.c.

◆ AmlStreamGetMaxBufferSize()

UINT32 EFIAPI AmlStreamGetMaxBufferSize ( IN CONST AML_STREAM Stream)

Get the size of Stream's Buffer.

Parameters
[in]StreamPointer to a stream.
Returns
The Size of Stream's Buffer. Return 0 if Stream is invalid.

Definition at line 167 of file AmlStream.c.

◆ AmlStreamInit()

EFI_STATUS EFIAPI AmlStreamInit ( IN OUT AML_STREAM Stream,
IN UINT8 *  Buffer,
IN UINT32  MaxBufferSize,
IN EAML_STREAM_DIRECTION  Direction 
)

Initialize a stream.

Parameters
[in,out]StreamPointer to the stream to initialize.
[in]BufferBuffer to initialize Stream with. Point to the beginning of the Buffer.
[in]MaxBufferSizeMaximum size of Buffer.
[in]DirectionDirection Stream is progressing (forward, backward).
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 25 of file AmlStream.c.

◆ AmlStreamInitSubStream()

EFI_STATUS EFIAPI AmlStreamInitSubStream ( IN CONST AML_STREAM Stream,
OUT AML_STREAM SubStream 
)

Initialize a sub-stream from a stream.

A sub-stream is a stream initialized at the current position of the input stream:

  • the Buffer field points to the current position of the input stream;
  • the Index field is set to 0;
  • the MaxBufferSize field is set to the remaining size of the input stream;
  • the direction is conserved;

E.g.: For a forward stream: +-------------—+-------------—+ |ABCD.........XYZ| Free Space | +-------------—+-------------—+ ^ ^ ^ Stream: Buffer CurrPos EndOfBuff Sub-stream: Buffer/CurrPos EndOfBuff

Parameters
[in]StreamPointer to the stream from which a sub-stream is created.
[in]SubStreamPointer to the stream to initialize.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Initialize a sub-stream from a stream.

A sub-stream is a stream initialized at the current position of the input stream:

  • the Buffer field points to the current position of the input stream;
  • the Index field is set to 0;
  • the MaxBufferSize field is set to the remaining size of the input stream;
  • the direction is conserved;

E.g.: For a forward stream: +-------------—+-------------—+ |ABCD.........XYZ| Free Space | +-------------—+-------------—+ ^ ^ ^ Stream: Buffer CurrPos EndOfBuff Sub-stream: Buffer/CurrPos EndOfBuff

Parameters
[in]StreamPointer to the stream from which a sub-stream is created.
[out]SubStreamPointer to the stream to initialize.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 109 of file AmlStream.c.

◆ AmlStreamPeekByte()

EFI_STATUS EFIAPI AmlStreamPeekByte ( IN AML_STREAM Stream,
OUT UINT8 *  OutByte 
)

Peek one byte at Stream's current position.

Stream's position is not moved when peeking.

Parameters
[in]StreamPointer to a stream. The stream must not be at its end.
[out]OutBytePointer holding the byte value of the stream current position.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.

Definition at line 421 of file AmlStream.c.

◆ AmlStreamProgress()

EFI_STATUS EFIAPI AmlStreamProgress ( IN AML_STREAM Stream,
IN UINT32  Offset 
)

Move Stream by Offset bytes.

The stream current position is moved according to the stream direction (forward, backward).

Parameters
[in]StreamPointer to a stream. The stream must not be at its end.
[in]OffsetOffset to move the stream of.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.

Definition at line 324 of file AmlStream.c.

◆ AmlStreamReadByte()

EFI_STATUS EFIAPI AmlStreamReadByte ( IN AML_STREAM Stream,
OUT UINT8 *  OutByte 
)

Read one byte at Stream's current position.

The stream current position is moved when reading.

Parameters
[in]StreamPointer to a stream. The stream must not be at its end.
[out]OutBytePointer holding the byte value of the stream current position.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.

Definition at line 461 of file AmlStream.c.

◆ AmlStreamReduceMaxBufferSize()

EFI_STATUS EFIAPI AmlStreamReduceMaxBufferSize ( IN AML_STREAM Stream,
IN UINT32  Diff 
)

Reduce the maximal size of Stream's Buffer (MaxBufferSize field).

Parameters
[in]StreamPointer to a stream.
[in]DiffValue to subtract to the Stream's MaxBufferSize. 0 < x < MaxBufferSize - Index.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 190 of file AmlStream.c.

◆ AmlStreamReset()

EFI_STATUS EFIAPI AmlStreamReset ( IN AML_STREAM Stream)

Reset the Stream (move the current position to the initial position).

Parameters
[in]StreamPointer to a stream.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.

Definition at line 392 of file AmlStream.c.

◆ AmlStreamRewind()

EFI_STATUS EFIAPI AmlStreamRewind ( IN AML_STREAM Stream,
IN UINT32  Offset 
)

Rewind Stream of Offset bytes.

The stream current position is rewound according to the stream direction (forward, backward). A stream going forward will be rewound backward.

Parameters
[in]StreamPointer to a stream.
[in]OffsetOffset to rewind the stream of.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.

Definition at line 361 of file AmlStream.c.

◆ AmlStreamWrite()

EFI_STATUS EFIAPI AmlStreamWrite ( IN AML_STREAM Stream,
IN CONST UINT8 *  Buffer,
IN UINT32  Size 
)

Write Size bytes in the stream.

If the stream goes backward (toward lower addresses), the bytes written to the stream are not reverted. In the example below, writing "Hello" to the stream will not revert the string. The end of the stream buffer will contain "Hello world!". Stream buffer: +------------—+--—+--—+--—+--—+--—+--—+-— +---—+ | ..... | ' ' | 'w' | 'o' | 'r' | 'l' | 'd' | '!' | '\0' | +------------—+--—+--—+--—+--—+--—+--—+-— +---—+ ^ Current position.

Parameters
[in]StreamPointer to a stream. The stream must not be at its end.
[in]BufferPointer to the data to write.
[in]SizeNumber of bytes to write.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_BUFFER_TOO_SMALLNo space left in the buffer.

Definition at line 512 of file AmlStream.c.