2 Emulator Thunk to abstract OS services from pure EFI code
4 Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/BaseLib.h>
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/MemoryAllocationLib.h>
23 #include <Protocol/EmuIoThunk.h>
26 #define EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('E','m','u','T')
30 EMU_IO_THUNK_PROTOCOL Data
;
33 } EMU_IO_THUNK_PROTOCOL_DATA
;
35 LIST_ENTRY mThunkList
= INITIALIZE_LIST_HEAD_VARIABLE (mThunkList
);
41 IN EMU_IO_THUNK_PROTOCOL
*ThunkIo
,
42 IN CHAR16
*ConfigString
,
43 IN BOOLEAN EmuBusDriver
49 EMU_IO_THUNK_PROTOCOL_DATA
*Private
;
51 if (ThunkIo
== NULL
) {
52 return EFI_INVALID_PARAMETER
;
56 StartString
= AllocatePool (StrSize (ConfigString
));
57 StrCpy (StartString
, ConfigString
);
58 while (*StartString
!= '\0') {
61 // Find the end of the sub string
63 SubString
= StartString
;
64 while (*SubString
!= '\0' && *SubString
!= '!') {
68 if (*SubString
== '!') {
70 // Replace token with '\0' to make sub strings. If this is the end
71 // of the string SubString will already point to NULL.
77 Private
= AllocatePool (sizeof (EMU_IO_THUNK_PROTOCOL_DATA
));
78 if (Private
== NULL
) {
79 return EFI_OUT_OF_RESOURCES
;
81 Private
->Signature
= EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE
;
82 Private
->EmuBusDriver
= EmuBusDriver
;
84 CopyMem (&Private
->Data
, ThunkIo
, sizeof (EMU_IO_THUNK_PROTOCOL
));
85 Private
->Data
.Instance
= (UINT16
)Instance
++;
86 Private
->Data
.ConfigString
= StartString
;
88 InsertTailList (&mThunkList
, &Private
->Link
);
91 // Parse Next sub string. This will point to '\0' if we are at the end.
93 StartString
= SubString
;
102 GetNextThunkProtocol (
103 IN BOOLEAN EmuBusDriver
,
104 OUT EMU_IO_THUNK_PROTOCOL
**Instance OPTIONAL
108 EMU_IO_THUNK_PROTOCOL_DATA
*Private
;
110 if (mThunkList
.ForwardLink
== &mThunkList
) {
111 // Skip parsing an empty list
112 return EFI_NOT_FOUND
;
115 for (Link
= mThunkList
.ForwardLink
; Link
!= &mThunkList
; Link
= Link
->ForwardLink
) {
116 Private
= CR (Link
, EMU_IO_THUNK_PROTOCOL_DATA
, Link
, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE
);
117 if (EmuBusDriver
& !Private
->EmuBusDriver
) {
119 } else if (*Instance
== NULL
) {
120 // Find 1st match in list
121 *Instance
= &Private
->Data
;
123 } else if (*Instance
== &Private
->Data
) {
124 // Matched previous call so look for valid next entry
125 Link
= Link
->ForwardLink
;
126 if (Link
== &mThunkList
) {
127 return EFI_NOT_FOUND
;
129 Private
= CR (Link
, EMU_IO_THUNK_PROTOCOL_DATA
, Link
, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE
);
130 *Instance
= &Private
->Data
;
136 return EFI_NOT_FOUND
;