2011-05-11 20:31:20 +02:00
|
|
|
/** @file
|
|
|
|
Emulator Thunk to abstract OS services from pure EFI code
|
|
|
|
|
|
|
|
Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
|
2018-08-23 07:01:06 +02:00
|
|
|
Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Uefi.h>
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
2011-06-20 23:58:05 +02:00
|
|
|
#include <Library/MemoryAllocationLib.h>
|
2011-05-11 20:31:20 +02:00
|
|
|
|
|
|
|
#include <Protocol/EmuIoThunk.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('E','m','u','T')
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
UINTN Signature;
|
|
|
|
EMU_IO_THUNK_PROTOCOL Data;
|
|
|
|
BOOLEAN EmuBusDriver;
|
|
|
|
LIST_ENTRY Link;
|
|
|
|
} EMU_IO_THUNK_PROTOCOL_DATA;
|
|
|
|
|
|
|
|
LIST_ENTRY mThunkList = INITIALIZE_LIST_HEAD_VARIABLE (mThunkList);
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
AddThunkProtocol (
|
2011-06-28 18:50:26 +02:00
|
|
|
IN EMU_IO_THUNK_PROTOCOL *ThunkIo,
|
2011-05-11 20:31:20 +02:00
|
|
|
IN CHAR16 *ConfigString,
|
|
|
|
IN BOOLEAN EmuBusDriver
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR16 *StartString;
|
|
|
|
CHAR16 *SubString;
|
|
|
|
UINTN Instance;
|
|
|
|
EMU_IO_THUNK_PROTOCOL_DATA *Private;
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
if (ThunkIo == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
Instance = 0;
|
2011-06-20 23:58:05 +02:00
|
|
|
StartString = AllocatePool (StrSize (ConfigString));
|
2011-05-11 20:31:20 +02:00
|
|
|
StrCpy (StartString, ConfigString);
|
|
|
|
while (*StartString != '\0') {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Find the end of the sub string
|
|
|
|
//
|
|
|
|
SubString = StartString;
|
|
|
|
while (*SubString != '\0' && *SubString != '!') {
|
|
|
|
SubString++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*SubString == '!') {
|
|
|
|
//
|
|
|
|
// Replace token with '\0' to make sub strings. If this is the end
|
|
|
|
// of the string SubString will already point to NULL.
|
|
|
|
//
|
|
|
|
*SubString = '\0';
|
|
|
|
SubString++;
|
|
|
|
}
|
|
|
|
|
2011-06-20 23:58:05 +02:00
|
|
|
Private = AllocatePool (sizeof (EMU_IO_THUNK_PROTOCOL_DATA));
|
2011-05-11 20:31:20 +02:00
|
|
|
if (Private == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
Private->Signature = EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE;
|
|
|
|
Private->EmuBusDriver = EmuBusDriver;
|
|
|
|
|
2011-06-28 18:50:26 +02:00
|
|
|
CopyMem (&Private->Data, ThunkIo, sizeof (EMU_IO_THUNK_PROTOCOL));
|
2018-08-23 07:01:06 +02:00
|
|
|
Private->Data.Instance = (UINT16)Instance++;
|
2011-05-11 20:31:20 +02:00
|
|
|
Private->Data.ConfigString = StartString;
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
InsertTailList (&mThunkList, &Private->Link);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Parse Next sub string. This will point to '\0' if we are at the end.
|
|
|
|
//
|
|
|
|
StartString = SubString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
GetNextThunkProtocol (
|
|
|
|
IN BOOLEAN EmuBusDriver,
|
|
|
|
OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2011-06-28 18:50:26 +02:00
|
|
|
LIST_ENTRY *Link;
|
|
|
|
EMU_IO_THUNK_PROTOCOL_DATA *Private;
|
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
if (mThunkList.ForwardLink == &mThunkList) {
|
|
|
|
// Skip parsing an empty list
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
2011-06-28 18:50:26 +02:00
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
for (Link = mThunkList.ForwardLink; Link != &mThunkList; Link = Link->ForwardLink) {
|
|
|
|
Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
|
|
|
|
if (EmuBusDriver & !Private->EmuBusDriver) {
|
|
|
|
continue;
|
|
|
|
} else if (*Instance == NULL) {
|
|
|
|
// Find 1st match in list
|
|
|
|
*Instance = &Private->Data;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
} else if (*Instance == &Private->Data) {
|
|
|
|
// Matched previous call so look for valid next entry
|
|
|
|
Link = Link->ForwardLink;
|
|
|
|
if (Link == &mThunkList) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
Private = CR (Link, EMU_IO_THUNK_PROTOCOL_DATA, Link, EMU_IO_THUNK_PROTOCOL_DATA_SIGNATURE);
|
|
|
|
*Instance = &Private->Data;
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 18:50:26 +02:00
|
|
|
|
|
|
|
|
2011-05-11 20:31:20 +02:00
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|