TianoCore EDK2 master
Loading...
Searching...
No Matches
ThunkProtocolList.c
Go to the documentation of this file.
1
11#include <Uefi.h>
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
16
17#include <Protocol/EmuIoThunk.h>
18
19#define EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('E','m','u','T')
20
21typedef struct {
22 UINTN Signature;
24 BOOLEAN EmuBusDriver;
25 LIST_ENTRY Link;
27
28LIST_ENTRY mThunkList = INITIALIZE_LIST_HEAD_VARIABLE (mThunkList);
29
31EFIAPI
32AddThunkProtocol (
34 IN CHAR16 *ConfigString,
35 IN BOOLEAN EmuBusDriver
36 )
37{
38 UINTN Size;
39 CHAR16 *StartString;
40 CHAR16 *SubString;
41 UINTN Instance;
43
44 if (ThunkIo == NULL) {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 Instance = 0;
49 Size = StrSize (ConfigString);
50 StartString = AllocatePool (Size);
51 if (StartString == NULL) {
52 return EFI_OUT_OF_RESOURCES;
53 }
54
55 StrCpyS (StartString, Size / sizeof (CHAR16), ConfigString);
56 while (*StartString != '\0') {
57 //
58 // Find the end of the sub string
59 //
60 SubString = StartString;
61 while (*SubString != '\0' && *SubString != '!') {
62 SubString++;
63 }
64
65 if (*SubString == '!') {
66 //
67 // Replace token with '\0' to make sub strings. If this is the end
68 // of the string SubString will already point to NULL.
69 //
70 *SubString = '\0';
71 SubString++;
72 }
73
74 Private = AllocatePool (sizeof (EMU_IO_THUNK_PROTOCOL_DATA));
75 if (Private == NULL) {
76 return EFI_OUT_OF_RESOURCES;
77 }
78
79 Private->Signature = EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE;
80 Private->EmuBusDriver = EmuBusDriver;
81
82 CopyMem (&Private->Data, ThunkIo, sizeof (EMU_IO_THUNK_PROTOCOL));
83 Private->Data.Instance = (UINT16)Instance++;
84 Private->Data.ConfigString = StartString;
85
86 InsertTailList (&mThunkList, &Private->Link);
87
88 //
89 // Parse Next sub string. This will point to '\0' if we are at the end.
90 //
91 StartString = SubString;
92 }
93
94 return EFI_SUCCESS;
95}
96
98EFIAPI
99GetNextThunkProtocol (
100 IN BOOLEAN EmuBusDriver,
101 OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
102 )
103{
104 LIST_ENTRY *Link;
106
107 if (mThunkList.ForwardLink == &mThunkList) {
108 // Skip parsing an empty list
109 return EFI_NOT_FOUND;
110 }
111
112 for (Link = mThunkList.ForwardLink; Link != &mThunkList; Link = Link->ForwardLink) {
113 Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
114 if (EmuBusDriver & !Private->EmuBusDriver) {
115 continue;
116 } else if (*Instance == NULL) {
117 // Find 1st match in list
118 *Instance = &Private->Data;
119 return EFI_SUCCESS;
120 } else if (*Instance == &Private->Data) {
121 // Matched previous call so look for valid next entry
122 Link = Link->ForwardLink;
123 if (Link == &mThunkList) {
124 return EFI_NOT_FOUND;
125 }
126
127 Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
128 *Instance = &Private->Data;
129 return EFI_SUCCESS;
130 }
131 }
132
133 return EFI_NOT_FOUND;
134}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
Definition: BaseLib.h:2904
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
CHAR16 * ConfigString
Only be valid after Open() is called.
Definition: EmuIoThunk.h:33