From 677472aae4923fedd82249021e872219389542f5 Mon Sep 17 00:00:00 2001 From: xli24 Date: Sat, 25 Oct 2008 16:03:02 +0000 Subject: 1. Rename following library instances according to MDE Library Spec: 1) SerialPortLibNull => BaseSerialPortLibNull 2) DxeMemoryLib => UefiMemoryLib 3) DxeMemoryAllocationLib => UefiMemoryAllocationLib 4) CpuLib => BaseCpuLib 5) HiiLib => UefiHiiLib 6) IfrSupportLib => UefiIfrSupportLib 7) PeiPalCallLib => PeiPalLib 2. Add library instances to MDE package 1) DxePalLib 2) FvbServiceLib 3) GraphicsLib git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6221 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BaseCpuLib/BaseCpuLib.inf | 64 ++ MdePkg/Library/BaseCpuLib/Ebc/CpuSleepFlushTlb.c | 43 + MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.S | 35 + MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.asm | 40 + MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.c | 32 + MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.S | 34 + MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.asm | 39 + MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.c | 34 + MdePkg/Library/BaseCpuLib/Ipf/CpuFlushTlb.s | 58 ++ MdePkg/Library/BaseCpuLib/Ipf/CpuSleep.c | 32 + MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.S | 35 + MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.asm | 38 + MdePkg/Library/BaseCpuLib/X64/CpuSleep.S | 34 + MdePkg/Library/BaseCpuLib/X64/CpuSleep.asm | 37 + .../BaseSerialPortLibNull/BaseSerialPortLibNull.c | 111 +++ .../BaseSerialPortLibNull.inf | 37 + MdePkg/Library/CpuLib/CpuLib.inf | 64 -- MdePkg/Library/CpuLib/Ebc/CpuSleepFlushTlb.c | 43 - MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.S | 35 - MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.asm | 40 - MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.c | 32 - MdePkg/Library/CpuLib/Ia32/CpuSleep.S | 34 - MdePkg/Library/CpuLib/Ia32/CpuSleep.asm | 39 - MdePkg/Library/CpuLib/Ia32/CpuSleep.c | 34 - MdePkg/Library/CpuLib/Ipf/CpuFlushTlb.s | 58 -- MdePkg/Library/CpuLib/Ipf/CpuSleep.c | 32 - MdePkg/Library/CpuLib/X64/CpuFlushTlb.S | 35 - MdePkg/Library/CpuLib/X64/CpuFlushTlb.asm | 38 - MdePkg/Library/CpuLib/X64/CpuSleep.S | 34 - MdePkg/Library/CpuLib/X64/CpuSleep.asm | 37 - .../DxeMemoryAllocationLib.inf | 45 - .../DxeMemoryAllocationLib/MemoryAllocationLib.c | 689 --------------- MdePkg/Library/DxeMemoryLib/CompareMemWrapper.c | 67 -- MdePkg/Library/DxeMemoryLib/CopyMemWrapper.c | 62 -- MdePkg/Library/DxeMemoryLib/DxeMemoryLib.inf | 59 -- MdePkg/Library/DxeMemoryLib/MemLib.c | 63 -- MdePkg/Library/DxeMemoryLib/MemLibGeneric.c | 261 ------ MdePkg/Library/DxeMemoryLib/MemLibGuid.c | 139 --- MdePkg/Library/DxeMemoryLib/MemLibInternals.h | 241 ------ MdePkg/Library/DxeMemoryLib/ScanMem16Wrapper.c | 67 -- MdePkg/Library/DxeMemoryLib/ScanMem32Wrapper.c | 66 -- MdePkg/Library/DxeMemoryLib/ScanMem64Wrapper.c | 66 -- MdePkg/Library/DxeMemoryLib/ScanMem8Wrapper.c | 62 -- MdePkg/Library/DxeMemoryLib/SetMem16Wrapper.c | 65 -- MdePkg/Library/DxeMemoryLib/SetMem32Wrapper.c | 66 -- MdePkg/Library/DxeMemoryLib/SetMem64Wrapper.c | 66 -- MdePkg/Library/DxeMemoryLib/SetMemWrapper.c | 56 -- MdePkg/Library/DxeMemoryLib/ZeroMemWrapper.c | 52 -- MdePkg/Library/DxePalLib/DxePalCallLib.c | 116 +++ MdePkg/Library/DxePalLib/DxePalLib.inf | 54 ++ MdePkg/Library/FvbServiceLib/Fvb.c | 726 ++++++++++++++++ MdePkg/Library/FvbServiceLib/Fvb.h | 44 + MdePkg/Library/FvbServiceLib/FvbServiceLib.inf | 57 ++ MdePkg/Library/GraphicsLib/Graphics.c | 917 ++++++++++++++++++++ MdePkg/Library/GraphicsLib/GraphicsLib.inf | 63 ++ MdePkg/Library/HiiLib/HiiLanguage.c | 206 ----- MdePkg/Library/HiiLib/HiiLib.c | 698 --------------- MdePkg/Library/HiiLib/HiiLib.inf | 59 -- MdePkg/Library/HiiLib/HiiString.c | 600 ------------- MdePkg/Library/HiiLib/InternalHiiLib.h | 53 -- MdePkg/Library/IfrSupportLib/IfrSupportLib.inf | 55 -- MdePkg/Library/IfrSupportLib/UefiIfrForm.c | 943 --------------------- .../Library/IfrSupportLib/UefiIfrLibraryInternal.h | 35 - .../Library/IfrSupportLib/UefiIfrOpCodeCreation.c | 891 ------------------- MdePkg/Library/PeiPalCallLib/PalCallLib.c | 101 --- MdePkg/Library/PeiPalCallLib/PeiPalCallLib.inf | 52 -- MdePkg/Library/PeiPalLib/PeiPalLib.c | 101 +++ MdePkg/Library/PeiPalLib/PeiPalLib.inf | 52 ++ .../Library/SerialPortLibNull/SerialPortLibNull.c | 111 --- .../SerialPortLibNull/SerialPortLibNull.inf | 37 - MdePkg/Library/UefiHiiLib/HiiLanguage.c | 206 +++++ MdePkg/Library/UefiHiiLib/HiiLib.c | 698 +++++++++++++++ MdePkg/Library/UefiHiiLib/HiiString.c | 600 +++++++++++++ MdePkg/Library/UefiHiiLib/InternalHiiLib.h | 53 ++ MdePkg/Library/UefiHiiLib/UefiHiiLib.inf | 59 ++ MdePkg/Library/UefiIfrSupportLib/UefiIfrForm.c | 943 +++++++++++++++++++++ .../UefiIfrSupportLib/UefiIfrLibraryInternal.h | 35 + .../UefiIfrSupportLib/UefiIfrOpCodeCreation.c | 891 +++++++++++++++++++ .../UefiIfrSupportLib/UefiIfrSupportLib.inf | 55 ++ .../UefiMemoryAllocationLib/MemoryAllocationLib.c | 689 +++++++++++++++ .../UefiMemoryAllocationLib.inf | 45 + MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c | 67 ++ MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c | 62 ++ MdePkg/Library/UefiMemoryLib/MemLib.c | 63 ++ MdePkg/Library/UefiMemoryLib/MemLibGeneric.c | 261 ++++++ MdePkg/Library/UefiMemoryLib/MemLibGuid.c | 139 +++ MdePkg/Library/UefiMemoryLib/MemLibInternals.h | 241 ++++++ MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c | 67 ++ MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c | 66 ++ MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c | 66 ++ MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c | 62 ++ MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c | 65 ++ MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c | 66 ++ MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c | 66 ++ MdePkg/Library/UefiMemoryLib/SetMemWrapper.c | 56 ++ MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf | 59 ++ MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c | 52 ++ 97 files changed, 8565 insertions(+), 6588 deletions(-) create mode 100644 MdePkg/Library/BaseCpuLib/BaseCpuLib.inf create mode 100644 MdePkg/Library/BaseCpuLib/Ebc/CpuSleepFlushTlb.c create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.S create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.asm create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.c create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.S create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.asm create mode 100644 MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.c create mode 100644 MdePkg/Library/BaseCpuLib/Ipf/CpuFlushTlb.s create mode 100644 MdePkg/Library/BaseCpuLib/Ipf/CpuSleep.c create mode 100644 MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.S create mode 100644 MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.asm create mode 100644 MdePkg/Library/BaseCpuLib/X64/CpuSleep.S create mode 100644 MdePkg/Library/BaseCpuLib/X64/CpuSleep.asm create mode 100644 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.c create mode 100644 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf delete mode 100644 MdePkg/Library/CpuLib/CpuLib.inf delete mode 100644 MdePkg/Library/CpuLib/Ebc/CpuSleepFlushTlb.c delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.S delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.asm delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.c delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuSleep.S delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuSleep.asm delete mode 100644 MdePkg/Library/CpuLib/Ia32/CpuSleep.c delete mode 100644 MdePkg/Library/CpuLib/Ipf/CpuFlushTlb.s delete mode 100644 MdePkg/Library/CpuLib/Ipf/CpuSleep.c delete mode 100644 MdePkg/Library/CpuLib/X64/CpuFlushTlb.S delete mode 100644 MdePkg/Library/CpuLib/X64/CpuFlushTlb.asm delete mode 100644 MdePkg/Library/CpuLib/X64/CpuSleep.S delete mode 100644 MdePkg/Library/CpuLib/X64/CpuSleep.asm delete mode 100644 MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf delete mode 100644 MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c delete mode 100644 MdePkg/Library/DxeMemoryLib/CompareMemWrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/CopyMemWrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/DxeMemoryLib.inf delete mode 100644 MdePkg/Library/DxeMemoryLib/MemLib.c delete mode 100644 MdePkg/Library/DxeMemoryLib/MemLibGeneric.c delete mode 100644 MdePkg/Library/DxeMemoryLib/MemLibGuid.c delete mode 100644 MdePkg/Library/DxeMemoryLib/MemLibInternals.h delete mode 100644 MdePkg/Library/DxeMemoryLib/ScanMem16Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/ScanMem32Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/ScanMem64Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/ScanMem8Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/SetMem16Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/SetMem32Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/SetMem64Wrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/SetMemWrapper.c delete mode 100644 MdePkg/Library/DxeMemoryLib/ZeroMemWrapper.c create mode 100644 MdePkg/Library/DxePalLib/DxePalCallLib.c create mode 100644 MdePkg/Library/DxePalLib/DxePalLib.inf create mode 100644 MdePkg/Library/FvbServiceLib/Fvb.c create mode 100644 MdePkg/Library/FvbServiceLib/Fvb.h create mode 100644 MdePkg/Library/FvbServiceLib/FvbServiceLib.inf create mode 100644 MdePkg/Library/GraphicsLib/Graphics.c create mode 100644 MdePkg/Library/GraphicsLib/GraphicsLib.inf delete mode 100644 MdePkg/Library/HiiLib/HiiLanguage.c delete mode 100644 MdePkg/Library/HiiLib/HiiLib.c delete mode 100644 MdePkg/Library/HiiLib/HiiLib.inf delete mode 100644 MdePkg/Library/HiiLib/HiiString.c delete mode 100644 MdePkg/Library/HiiLib/InternalHiiLib.h delete mode 100644 MdePkg/Library/IfrSupportLib/IfrSupportLib.inf delete mode 100644 MdePkg/Library/IfrSupportLib/UefiIfrForm.c delete mode 100644 MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h delete mode 100644 MdePkg/Library/IfrSupportLib/UefiIfrOpCodeCreation.c delete mode 100644 MdePkg/Library/PeiPalCallLib/PalCallLib.c delete mode 100644 MdePkg/Library/PeiPalCallLib/PeiPalCallLib.inf create mode 100644 MdePkg/Library/PeiPalLib/PeiPalLib.c create mode 100644 MdePkg/Library/PeiPalLib/PeiPalLib.inf delete mode 100644 MdePkg/Library/SerialPortLibNull/SerialPortLibNull.c delete mode 100644 MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf create mode 100644 MdePkg/Library/UefiHiiLib/HiiLanguage.c create mode 100644 MdePkg/Library/UefiHiiLib/HiiLib.c create mode 100644 MdePkg/Library/UefiHiiLib/HiiString.c create mode 100644 MdePkg/Library/UefiHiiLib/InternalHiiLib.h create mode 100644 MdePkg/Library/UefiHiiLib/UefiHiiLib.inf create mode 100644 MdePkg/Library/UefiIfrSupportLib/UefiIfrForm.c create mode 100644 MdePkg/Library/UefiIfrSupportLib/UefiIfrLibraryInternal.h create mode 100644 MdePkg/Library/UefiIfrSupportLib/UefiIfrOpCodeCreation.c create mode 100644 MdePkg/Library/UefiIfrSupportLib/UefiIfrSupportLib.inf create mode 100644 MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c create mode 100644 MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf create mode 100644 MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/MemLib.c create mode 100644 MdePkg/Library/UefiMemoryLib/MemLibGeneric.c create mode 100644 MdePkg/Library/UefiMemoryLib/MemLibGuid.c create mode 100644 MdePkg/Library/UefiMemoryLib/MemLibInternals.h create mode 100644 MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/SetMemWrapper.c create mode 100644 MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf create mode 100644 MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c (limited to 'MdePkg/Library') diff --git a/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf new file mode 100644 index 0000000000..a58b198723 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/BaseCpuLib.inf @@ -0,0 +1,64 @@ +#/** @file +# Component description file for Base Cpu Library +# +# Base Library implementation. +# Copyright (c) 2007, Intel Corporation. +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseCpuLib + FILE_GUID = 4FBD2538-249C-4b50-8F4A-A9E66609CBF6 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = CpuLib + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + +[Sources.Ia32] + Ia32/CpuSleep.c | MSFT + Ia32/CpuFlushTlb.c | MSFT + + Ia32/CpuSleep.asm | INTEL + Ia32/CpuFlushTlb.asm | INTEL + + Ia32/CpuSleep.S | GCC + Ia32/CpuFlushTlb.S | GCC + +[Sources.X64] + X64/CpuFlushTlb.asm + X64/CpuSleep.asm + + X64/CpuSleep.S | GCC + X64/CpuFlushTlb.S | GCC + +[Sources.IPF] + Ipf/CpuFlushTlb.s + Ipf/CpuSleep.c + +[Sources.EBC] + Ebc/CpuSleepFlushTlb.c + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses.Ipf] +PalCallLib diff --git a/MdePkg/Library/BaseCpuLib/Ebc/CpuSleepFlushTlb.c b/MdePkg/Library/BaseCpuLib/Ebc/CpuSleepFlushTlb.c new file mode 100644 index 0000000000..d6346131db --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ebc/CpuSleepFlushTlb.c @@ -0,0 +1,43 @@ +/** @file + Base Library CPU Functions for EBC + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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 +#include + +/** + Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU. +**/ +VOID +EFIAPI +CpuFlushTlb ( + VOID + ) +{ + ASSERT (FALSE); +} + +/** + Places the CPU in a sleep state until an interrupt is received. + + Places the CPU in a sleep state until an interrupt is received. If interrupts + are disabled prior to calling this function, then the CPU will be placed in a + sleep state indefinitely. + +**/ +VOID +EFIAPI +CpuSleep ( + VOID + ) +{ +} diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.S b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.S new file mode 100644 index 0000000000..f8b1cdc7ee --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.S @@ -0,0 +1,35 @@ +#------------------------------------------------------------------------------ ; +# Copyright (c) 2006, Intel Corporation +# All rights reserved. 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. +# +# Module Name: +# +# CpuFlushTlb.Asm +# +# Abstract: +# +# CpuFlushTlb function +# +# Notes: +# +#------------------------------------------------------------------------------ + +.globl ASM_PFX(CpuFlushTlb) + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# CpuFlushTlb ( +# VOID +# ); +#------------------------------------------------------------------------------ +ASM_PFX(CpuFlushTlb): + movl %cr3, %eax + movl %eax, %cr3 + ret diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.asm b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.asm new file mode 100644 index 0000000000..4f0c4f9944 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.asm @@ -0,0 +1,40 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. 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. +; +; Module Name: +; +; CpuFlushTlb.Asm +; +; Abstract: +; +; CpuFlushTlb function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .386p + .model flat,C + .code + +;------------------------------------------------------------------------------ +; VOID +; EFIAPI +; CpuFlushTlb ( +; VOID +; ); +;------------------------------------------------------------------------------ +CpuFlushTlb PROC + mov eax, cr3 + mov cr3, eax ; moving to CR3 flushes TLB + ret +CpuFlushTlb ENDP + + END diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.c b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.c new file mode 100644 index 0000000000..ff3cf82172 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuFlushTlb.c @@ -0,0 +1,32 @@ +/** @file + CpuFlushTlb function. + + Copyright (c) 2006 - 2007, Intel Corporation
+ All rights reserved. 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. + +**/ + + + +/** + Flush TLB of current processor. + +**/ +VOID +EFIAPI +CpuFlushTlb ( + VOID + ) +{ + _asm { + mov eax, cr3 + mov cr3, eax + } +} + diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.S b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.S new file mode 100644 index 0000000000..ac39e8fcba --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.S @@ -0,0 +1,34 @@ +#------------------------------------------------------------------------------ ; +# Copyright (c) 2006, Intel Corporation +# All rights reserved. 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. +# +# Module Name: +# +# CpuSleep.Asm +# +# Abstract: +# +# CpuSleep function +# +# Notes: +# +#------------------------------------------------------------------------------ + +.globl ASM_PFX(CpuSleep) + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# CpuSleep ( +# VOID +# ); +#------------------------------------------------------------------------------ +ASM_PFX(CpuSleep): + hlt + ret diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.asm b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.asm new file mode 100644 index 0000000000..8a779f7017 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.asm @@ -0,0 +1,39 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. 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. +; +; Module Name: +; +; CpuSleep.Asm +; +; Abstract: +; +; CpuSleep function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .386 + .model flat,C + .code + +;------------------------------------------------------------------------------ +; VOID +; EFIAPI +; CpuSleep ( +; VOID +; ); +;------------------------------------------------------------------------------ +CpuSleep PROC + hlt + ret +CpuSleep ENDP + + END diff --git a/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.c b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.c new file mode 100644 index 0000000000..a39ad22064 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ia32/CpuSleep.c @@ -0,0 +1,34 @@ +/** @file + CpuSleep function. + + Copyright (c) 2006 - 2007, Intel Corporation
+ All rights reserved. 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. + +**/ + + +/** + Places the CPU in a sleep state until an interrupt is received. + + Places the CPU in a sleep state until an interrupt is received. If interrupts + are disabled prior to calling this function, then the CPU will be placed in a + sleep state indefinitely. + +**/ +VOID +EFIAPI +CpuSleep ( + VOID + ) +{ + _asm { + hlt + } +} + diff --git a/MdePkg/Library/BaseCpuLib/Ipf/CpuFlushTlb.s b/MdePkg/Library/BaseCpuLib/Ipf/CpuFlushTlb.s new file mode 100644 index 0000000000..5546990992 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ipf/CpuFlushTlb.s @@ -0,0 +1,58 @@ +/// @file +/// CpuFlushTlb() function for Itanium-based architecture. +/// +/// Copyright (c) 2006, Intel Corporation +/// All rights reserved. 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. +/// +/// Module Name: CpuFlushTlb.s +/// +/// + +.auto +.text + +.globl PalCall +.type PalCall, @function + +.proc CpuFlushTlb +.type CpuFlushTlb, @function +CpuFlushTlb:: + alloc loc0 = ar.pfs, 0, 3, 5, 0 + mov out0 = 0 + mov out1 = 6 + mov out2 = 0 + mov out3 = 0 + mov loc1 = b0 + mov out4 = 0 + brl.call.sptk b0 = PalCall + mov loc2 = psr // save PSR + mov ar.pfs = loc0 + extr.u r14 = r10, 32, 32 // r14 <- count1 + rsm 1 << 14 // Disable interrupts + extr.u r15 = r11, 32, 32 // r15 <- stride1 + extr.u r10 = r10, 0, 32 // r10 <- count2 + add r10 = -1, r10 + extr.u r11 = r11, 0, 32 // r11 <- stride2 + br.cond.sptk LoopPredicate +LoopOuter: + mov ar.lc = r10 // LC <- count2 + mov ar.ec = r0 // EC <- 0 +Loop: + ptc.e r9 + add r9 = r11, r9 // r9 += stride2 + br.ctop.sptk Loop + add r9 = r15, r9 // r9 += stride1 +LoopPredicate: + cmp.ne p6 = r0, r14 // count1 == 0? + add r14 = -1, r14 +(p6) br.cond.sptk LoopOuter + mov psr.l = loc2 + mov b0 = loc1 + br.ret.sptk.many b0 +.endp diff --git a/MdePkg/Library/BaseCpuLib/Ipf/CpuSleep.c b/MdePkg/Library/BaseCpuLib/Ipf/CpuSleep.c new file mode 100644 index 0000000000..5ad64a5cf4 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/Ipf/CpuSleep.c @@ -0,0 +1,32 @@ +/** @file + Base Library CPU functions for Itanium + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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 + +/** + Places the CPU in a sleep state until an interrupt is received. + + Places the CPU in a sleep state until an interrupt is received. If interrupts + are disabled prior to calling this function, then the CPU will be placed in a + sleep state indefinitely. + +**/ +VOID +EFIAPI +CpuSleep ( + VOID + ) +{ + PalCall (29, 0, 0, 0); +} diff --git a/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.S b/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.S new file mode 100644 index 0000000000..3c799b735f --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.S @@ -0,0 +1,35 @@ +#------------------------------------------------------------------------------ +# Copyright (c) 2006, Intel Corporation +# All rights reserved. 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. +# +# Module Name: +# +# CpuFlushTlb.Asm +# +# Abstract: +# +# CpuFlushTlb function +# +# Notes: +# +#------------------------------------------------------------------------------ + +.global ASM_PFX(CpuFlushTlb) + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# CpuFlushTlb ( +# VOID +# ); +#------------------------------------------------------------------------------ +ASM_PFX(CpuFlushTlb): + mov %cr3, %rax + mov %rax, %cr3 + ret diff --git a/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.asm b/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.asm new file mode 100644 index 0000000000..c2c4490e9d --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/X64/CpuFlushTlb.asm @@ -0,0 +1,38 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. 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. +; +; Module Name: +; +; CpuFlushTlb.Asm +; +; Abstract: +; +; CpuFlushTlb function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID +; EFIAPI +; CpuFlushTlb ( +; VOID +; ); +;------------------------------------------------------------------------------ +CpuFlushTlb PROC + mov rax, cr3 + mov cr3, rax + ret +CpuFlushTlb ENDP + + END diff --git a/MdePkg/Library/BaseCpuLib/X64/CpuSleep.S b/MdePkg/Library/BaseCpuLib/X64/CpuSleep.S new file mode 100644 index 0000000000..658cb1aeff --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/X64/CpuSleep.S @@ -0,0 +1,34 @@ +#------------------------------------------------------------------------------ ; +# Copyright (c) 2006, Intel Corporation +# All rights reserved. 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. +# +# Module Name: +# +# CpuSleep.S +# +# Abstract: +# +# CpuSleep function +# +# Notes: +# +#------------------------------------------------------------------------------ + + +#------------------------------------------------------------------------------ +# VOID +# EFIAPI +# CpuSleep ( +# VOID +# ); +#------------------------------------------------------------------------------ +.global ASM_PFX(CpuSleep) +ASM_PFX(CpuSleep): + hlt + ret diff --git a/MdePkg/Library/BaseCpuLib/X64/CpuSleep.asm b/MdePkg/Library/BaseCpuLib/X64/CpuSleep.asm new file mode 100644 index 0000000000..b2c4907032 --- /dev/null +++ b/MdePkg/Library/BaseCpuLib/X64/CpuSleep.asm @@ -0,0 +1,37 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2006, Intel Corporation +; All rights reserved. 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. +; +; Module Name: +; +; CpuSleep.Asm +; +; Abstract: +; +; CpuSleep function +; +; Notes: +; +;------------------------------------------------------------------------------ + + .code + +;------------------------------------------------------------------------------ +; VOID +; EFIAPI +; CpuSleep ( +; VOID +; ); +;------------------------------------------------------------------------------ +CpuSleep PROC + hlt + ret +CpuSleep ENDP + + END diff --git a/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.c b/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.c new file mode 100644 index 0000000000..ff1d14baba --- /dev/null +++ b/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.c @@ -0,0 +1,111 @@ +/** @file + Null Serial Port library instance with empty functions. + + Copyright (c) 2006 - 2008, Intel Corporation + All rights reserved. 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 + + +#include + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfuly initialized, then return RETURN_SUCCESS. + If the serial device could not be initialized, then return RETURN_DEVICE_ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serail device could not be initialized. + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + return RETURN_UNSUPPORTED; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation failed. + + If Buffer is NULL, then ASSERT(). + + If NumberOfBytes is zero, then return 0. + + @param Buffer Pointer to the data buffer to be written. + @param NumberOfBytes Number of bytes to written to the serial device. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial device. + If this value is less than NumberOfBytes, then the read operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes +) +{ + return 0; +} + + +/** + Reads data from a serial device into a buffer. + + @param Buffer Pointer to the data buffer to store the data read from the serial device. + @param NumberOfBytes Number of bytes to read from the serial device. + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes read from the serial device. + If this value is less than NumberOfBytes, then the read operation failed. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes +) +{ + return 0; +} + +/** + Polls a serial device to see if there is any data waiting to be read. + + Polls aserial device to see if there is any data waiting to be read. + If there is data waiting to be read from the serial device, then TRUE is returned. + If there is no data waiting to be read from the serial device, then FALSE is returned. + + @retval TRUE Data is waiting to be read from the serial device. + @retval FALSE There is no data waiting to be read from the serial device. + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + return FALSE; +} + diff --git a/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf b/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf new file mode 100644 index 0000000000..b1e33c56d3 --- /dev/null +++ b/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf @@ -0,0 +1,37 @@ +#/** @file +# Null Serial Port library instance with empty functions +# +# Copyright (c) 2006 - 2008, Intel Corporation. +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = BaseSerialPortLibNull + FILE_GUID = E4541241-8897-411a-91F8-7D7E45837146 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SerialPortLib + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + BaseSerialPortLibNull.c + + +[Packages] + MdePkg/MdePkg.dec + diff --git a/MdePkg/Library/CpuLib/CpuLib.inf b/MdePkg/Library/CpuLib/CpuLib.inf deleted file mode 100644 index 952983e7dc..0000000000 --- a/MdePkg/Library/CpuLib/CpuLib.inf +++ /dev/null @@ -1,64 +0,0 @@ -#/** @file -# Component description file for Base Cpu Library -# -# Base Library implementation. -# Copyright (c) 2007, Intel Corporation. -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = CpuLib - FILE_GUID = 4FBD2538-249C-4b50-8F4A-A9E66609CBF6 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = CpuLib - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - -[Sources.Ia32] - Ia32/CpuSleep.c | MSFT - Ia32/CpuFlushTlb.c | MSFT - - Ia32/CpuSleep.asm | INTEL - Ia32/CpuFlushTlb.asm | INTEL - - Ia32/CpuSleep.S | GCC - Ia32/CpuFlushTlb.S | GCC - -[Sources.X64] - X64/CpuFlushTlb.asm - X64/CpuSleep.asm - - X64/CpuSleep.S | GCC - X64/CpuFlushTlb.S | GCC - -[Sources.IPF] - Ipf/CpuFlushTlb.s - Ipf/CpuSleep.c - -[Sources.EBC] - Ebc/CpuSleepFlushTlb.c - -[Packages] - MdePkg/MdePkg.dec - - -[LibraryClasses.Ipf] -PalCallLib diff --git a/MdePkg/Library/CpuLib/Ebc/CpuSleepFlushTlb.c b/MdePkg/Library/CpuLib/Ebc/CpuSleepFlushTlb.c deleted file mode 100644 index d6346131db..0000000000 --- a/MdePkg/Library/CpuLib/Ebc/CpuSleepFlushTlb.c +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - Base Library CPU Functions for EBC - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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 -#include - -/** - Flushes all the Translation Lookaside Buffers(TLB) entries in a CPU. -**/ -VOID -EFIAPI -CpuFlushTlb ( - VOID - ) -{ - ASSERT (FALSE); -} - -/** - Places the CPU in a sleep state until an interrupt is received. - - Places the CPU in a sleep state until an interrupt is received. If interrupts - are disabled prior to calling this function, then the CPU will be placed in a - sleep state indefinitely. - -**/ -VOID -EFIAPI -CpuSleep ( - VOID - ) -{ -} diff --git a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.S b/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.S deleted file mode 100644 index f8b1cdc7ee..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.S +++ /dev/null @@ -1,35 +0,0 @@ -#------------------------------------------------------------------------------ ; -# Copyright (c) 2006, Intel Corporation -# All rights reserved. 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. -# -# Module Name: -# -# CpuFlushTlb.Asm -# -# Abstract: -# -# CpuFlushTlb function -# -# Notes: -# -#------------------------------------------------------------------------------ - -.globl ASM_PFX(CpuFlushTlb) - -#------------------------------------------------------------------------------ -# VOID -# EFIAPI -# CpuFlushTlb ( -# VOID -# ); -#------------------------------------------------------------------------------ -ASM_PFX(CpuFlushTlb): - movl %cr3, %eax - movl %eax, %cr3 - ret diff --git a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.asm b/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.asm deleted file mode 100644 index 4f0c4f9944..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.asm +++ /dev/null @@ -1,40 +0,0 @@ -;------------------------------------------------------------------------------ ; -; Copyright (c) 2006, Intel Corporation -; All rights reserved. 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. -; -; Module Name: -; -; CpuFlushTlb.Asm -; -; Abstract: -; -; CpuFlushTlb function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .386p - .model flat,C - .code - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; CpuFlushTlb ( -; VOID -; ); -;------------------------------------------------------------------------------ -CpuFlushTlb PROC - mov eax, cr3 - mov cr3, eax ; moving to CR3 flushes TLB - ret -CpuFlushTlb ENDP - - END diff --git a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.c b/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.c deleted file mode 100644 index ff3cf82172..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuFlushTlb.c +++ /dev/null @@ -1,32 +0,0 @@ -/** @file - CpuFlushTlb function. - - Copyright (c) 2006 - 2007, Intel Corporation
- All rights reserved. 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. - -**/ - - - -/** - Flush TLB of current processor. - -**/ -VOID -EFIAPI -CpuFlushTlb ( - VOID - ) -{ - _asm { - mov eax, cr3 - mov cr3, eax - } -} - diff --git a/MdePkg/Library/CpuLib/Ia32/CpuSleep.S b/MdePkg/Library/CpuLib/Ia32/CpuSleep.S deleted file mode 100644 index ac39e8fcba..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuSleep.S +++ /dev/null @@ -1,34 +0,0 @@ -#------------------------------------------------------------------------------ ; -# Copyright (c) 2006, Intel Corporation -# All rights reserved. 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. -# -# Module Name: -# -# CpuSleep.Asm -# -# Abstract: -# -# CpuSleep function -# -# Notes: -# -#------------------------------------------------------------------------------ - -.globl ASM_PFX(CpuSleep) - -#------------------------------------------------------------------------------ -# VOID -# EFIAPI -# CpuSleep ( -# VOID -# ); -#------------------------------------------------------------------------------ -ASM_PFX(CpuSleep): - hlt - ret diff --git a/MdePkg/Library/CpuLib/Ia32/CpuSleep.asm b/MdePkg/Library/CpuLib/Ia32/CpuSleep.asm deleted file mode 100644 index 8a779f7017..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuSleep.asm +++ /dev/null @@ -1,39 +0,0 @@ -;------------------------------------------------------------------------------ ; -; Copyright (c) 2006, Intel Corporation -; All rights reserved. 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. -; -; Module Name: -; -; CpuSleep.Asm -; -; Abstract: -; -; CpuSleep function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .386 - .model flat,C - .code - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; CpuSleep ( -; VOID -; ); -;------------------------------------------------------------------------------ -CpuSleep PROC - hlt - ret -CpuSleep ENDP - - END diff --git a/MdePkg/Library/CpuLib/Ia32/CpuSleep.c b/MdePkg/Library/CpuLib/Ia32/CpuSleep.c deleted file mode 100644 index a39ad22064..0000000000 --- a/MdePkg/Library/CpuLib/Ia32/CpuSleep.c +++ /dev/null @@ -1,34 +0,0 @@ -/** @file - CpuSleep function. - - Copyright (c) 2006 - 2007, Intel Corporation
- All rights reserved. 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. - -**/ - - -/** - Places the CPU in a sleep state until an interrupt is received. - - Places the CPU in a sleep state until an interrupt is received. If interrupts - are disabled prior to calling this function, then the CPU will be placed in a - sleep state indefinitely. - -**/ -VOID -EFIAPI -CpuSleep ( - VOID - ) -{ - _asm { - hlt - } -} - diff --git a/MdePkg/Library/CpuLib/Ipf/CpuFlushTlb.s b/MdePkg/Library/CpuLib/Ipf/CpuFlushTlb.s deleted file mode 100644 index 5546990992..0000000000 --- a/MdePkg/Library/CpuLib/Ipf/CpuFlushTlb.s +++ /dev/null @@ -1,58 +0,0 @@ -/// @file -/// CpuFlushTlb() function for Itanium-based architecture. -/// -/// Copyright (c) 2006, Intel Corporation -/// All rights reserved. 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. -/// -/// Module Name: CpuFlushTlb.s -/// -/// - -.auto -.text - -.globl PalCall -.type PalCall, @function - -.proc CpuFlushTlb -.type CpuFlushTlb, @function -CpuFlushTlb:: - alloc loc0 = ar.pfs, 0, 3, 5, 0 - mov out0 = 0 - mov out1 = 6 - mov out2 = 0 - mov out3 = 0 - mov loc1 = b0 - mov out4 = 0 - brl.call.sptk b0 = PalCall - mov loc2 = psr // save PSR - mov ar.pfs = loc0 - extr.u r14 = r10, 32, 32 // r14 <- count1 - rsm 1 << 14 // Disable interrupts - extr.u r15 = r11, 32, 32 // r15 <- stride1 - extr.u r10 = r10, 0, 32 // r10 <- count2 - add r10 = -1, r10 - extr.u r11 = r11, 0, 32 // r11 <- stride2 - br.cond.sptk LoopPredicate -LoopOuter: - mov ar.lc = r10 // LC <- count2 - mov ar.ec = r0 // EC <- 0 -Loop: - ptc.e r9 - add r9 = r11, r9 // r9 += stride2 - br.ctop.sptk Loop - add r9 = r15, r9 // r9 += stride1 -LoopPredicate: - cmp.ne p6 = r0, r14 // count1 == 0? - add r14 = -1, r14 -(p6) br.cond.sptk LoopOuter - mov psr.l = loc2 - mov b0 = loc1 - br.ret.sptk.many b0 -.endp diff --git a/MdePkg/Library/CpuLib/Ipf/CpuSleep.c b/MdePkg/Library/CpuLib/Ipf/CpuSleep.c deleted file mode 100644 index 5ad64a5cf4..0000000000 --- a/MdePkg/Library/CpuLib/Ipf/CpuSleep.c +++ /dev/null @@ -1,32 +0,0 @@ -/** @file - Base Library CPU functions for Itanium - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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 - -/** - Places the CPU in a sleep state until an interrupt is received. - - Places the CPU in a sleep state until an interrupt is received. If interrupts - are disabled prior to calling this function, then the CPU will be placed in a - sleep state indefinitely. - -**/ -VOID -EFIAPI -CpuSleep ( - VOID - ) -{ - PalCall (29, 0, 0, 0); -} diff --git a/MdePkg/Library/CpuLib/X64/CpuFlushTlb.S b/MdePkg/Library/CpuLib/X64/CpuFlushTlb.S deleted file mode 100644 index 3c799b735f..0000000000 --- a/MdePkg/Library/CpuLib/X64/CpuFlushTlb.S +++ /dev/null @@ -1,35 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright (c) 2006, Intel Corporation -# All rights reserved. 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. -# -# Module Name: -# -# CpuFlushTlb.Asm -# -# Abstract: -# -# CpuFlushTlb function -# -# Notes: -# -#------------------------------------------------------------------------------ - -.global ASM_PFX(CpuFlushTlb) - -#------------------------------------------------------------------------------ -# VOID -# EFIAPI -# CpuFlushTlb ( -# VOID -# ); -#------------------------------------------------------------------------------ -ASM_PFX(CpuFlushTlb): - mov %cr3, %rax - mov %rax, %cr3 - ret diff --git a/MdePkg/Library/CpuLib/X64/CpuFlushTlb.asm b/MdePkg/Library/CpuLib/X64/CpuFlushTlb.asm deleted file mode 100644 index c2c4490e9d..0000000000 --- a/MdePkg/Library/CpuLib/X64/CpuFlushTlb.asm +++ /dev/null @@ -1,38 +0,0 @@ -;------------------------------------------------------------------------------ ; -; Copyright (c) 2006, Intel Corporation -; All rights reserved. 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. -; -; Module Name: -; -; CpuFlushTlb.Asm -; -; Abstract: -; -; CpuFlushTlb function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; CpuFlushTlb ( -; VOID -; ); -;------------------------------------------------------------------------------ -CpuFlushTlb PROC - mov rax, cr3 - mov cr3, rax - ret -CpuFlushTlb ENDP - - END diff --git a/MdePkg/Library/CpuLib/X64/CpuSleep.S b/MdePkg/Library/CpuLib/X64/CpuSleep.S deleted file mode 100644 index 658cb1aeff..0000000000 --- a/MdePkg/Library/CpuLib/X64/CpuSleep.S +++ /dev/null @@ -1,34 +0,0 @@ -#------------------------------------------------------------------------------ ; -# Copyright (c) 2006, Intel Corporation -# All rights reserved. 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. -# -# Module Name: -# -# CpuSleep.S -# -# Abstract: -# -# CpuSleep function -# -# Notes: -# -#------------------------------------------------------------------------------ - - -#------------------------------------------------------------------------------ -# VOID -# EFIAPI -# CpuSleep ( -# VOID -# ); -#------------------------------------------------------------------------------ -.global ASM_PFX(CpuSleep) -ASM_PFX(CpuSleep): - hlt - ret diff --git a/MdePkg/Library/CpuLib/X64/CpuSleep.asm b/MdePkg/Library/CpuLib/X64/CpuSleep.asm deleted file mode 100644 index b2c4907032..0000000000 --- a/MdePkg/Library/CpuLib/X64/CpuSleep.asm +++ /dev/null @@ -1,37 +0,0 @@ -;------------------------------------------------------------------------------ ; -; Copyright (c) 2006, Intel Corporation -; All rights reserved. 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. -; -; Module Name: -; -; CpuSleep.Asm -; -; Abstract: -; -; CpuSleep function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; VOID -; EFIAPI -; CpuSleep ( -; VOID -; ); -;------------------------------------------------------------------------------ -CpuSleep PROC - hlt - ret -CpuSleep ENDP - - END diff --git a/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf b/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf deleted file mode 100644 index 8ab92503c6..0000000000 --- a/MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf +++ /dev/null @@ -1,45 +0,0 @@ -#/** @file -# Component description file for Dxe Memory Allocation Library -# -# Memory Allocation Library that uses EFI Boot Services to allocate -# and free memory. -# Copyright (c) 2007 - 2008, Intel Corporation -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DxeMemoryAllocationLib - FILE_GUID = 4674739d-3195-4fb2-8094-ac1d22d00194 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = MemoryAllocationLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - MemoryAllocationLib.c - - -[Packages] - MdePkg/MdePkg.dec - - -[LibraryClasses] - DebugLib - BaseMemoryLib - UefiBootServicesTableLib - diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c deleted file mode 100644 index 1c1c879a5f..0000000000 --- a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c +++ /dev/null @@ -1,689 +0,0 @@ -/** @file - Support routines for memory allocation routines based - on boot services for Dxe phase drivers. - - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. 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 - - -#include -#include -#include -#include - -/** - Allocates one or more 4KB pages of a certain memory type. - - Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated - buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. - If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param MemoryType The type of memory to allocate. - @param Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -InternalAllocatePages ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Pages - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Memory; - - if (Pages == 0) { - return NULL; - } - - Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory); - if (EFI_ERROR (Status)) { - return NULL; - } - return (VOID *) (UINTN) Memory; -} - -/** - Allocates one or more 4KB pages of type EfiBootServicesData. - - Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the - allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL - is returned. If there is not enough memory remaining to satisfy the request, then NULL is - returned. - - @param Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocatePages ( - IN UINTN Pages - ) -{ - return InternalAllocatePages (EfiBootServicesData, Pages); -} - -/** - Allocates one or more 4KB pages of type EfiRuntimeServicesData. - - Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the - allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL - is returned. If there is not enough memory remaining to satisfy the request, then NULL is - returned. - - @param Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateRuntimePages ( - IN UINTN Pages - ) -{ - return InternalAllocatePages (EfiRuntimeServicesData, Pages); -} - -/** - Allocates one or more 4KB pages of type EfiReservedMemoryType. - - Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the - allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL - is returned. If there is not enough memory remaining to satisfy the request, then NULL is - returned. - - @param Pages The number of 4 KB pages to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateReservedPages ( - IN UINTN Pages - ) -{ - return InternalAllocatePages (EfiReservedMemoryType, Pages); -} - -/** - Frees one or more 4KB pages that were previously allocated with one of the page allocation - functions in the Memory Allocation Library. - - Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer - must have been allocated on a previous call to the page allocation services of the Memory - Allocation Library. - If Buffer was not allocated with a page allocation function in the Memory Allocation Library, - then ASSERT(). - If Pages is zero, then ASSERT(). - - @param Buffer Pointer to the buffer of pages to free. - @param Pages The number of 4 KB pages to free. - -**/ -VOID -EFIAPI -FreePages ( - IN VOID *Buffer, - IN UINTN Pages - ) -{ - EFI_STATUS Status; - - ASSERT (Pages != 0); - Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); - ASSERT_EFI_ERROR (Status); -} - -/** - Allocates one or more 4KB pages of a certain memory type at a specified alignment. - - Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment - specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. - If there is not enough memory at the specified alignment remaining to satisfy the request, then - NULL is returned. - If Alignment is not a power of two and Alignment is not zero, then ASSERT(). - - @param MemoryType The type of memory to allocate. - @param Pages The number of 4 KB pages to allocate. - @param Alignment The requested alignment of the allocation. Must be a power of two. - If Alignment is zero, then byte alignment is used. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -InternalAllocateAlignedPages ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN Pages, - IN UINTN Alignment - ) -{ - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS Memory; - UINTN AlignedMemory; - UINTN AlignmentMask; - UINTN UnalignedPages; - UINTN RealPages; - - // - // Alignment must be a power of two or zero. - // - ASSERT ((Alignment & (Alignment - 1)) == 0); - - if (Pages == 0) { - return NULL; - } - if (Alignment > EFI_PAGE_SIZE) { - // - // Caculate the total number of pages since alignment is larger than page size. - // - AlignmentMask = Alignment - 1; - RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment); - // - // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. - // - ASSERT (RealPages > Pages); - - Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory); - if (EFI_ERROR (Status)) { - return NULL; - } - AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask; - UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory); - if (UnalignedPages > 0) { - // - // Free first unaligned page(s). - // - Status = gBS->FreePages (Memory, UnalignedPages); - ASSERT_EFI_ERROR (Status); - } - Memory = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages)); - UnalignedPages = RealPages - Pages - UnalignedPages; - if (UnalignedPages > 0) { - // - // Free last unaligned page(s). - // - Status = gBS->FreePages (Memory, UnalignedPages); - ASSERT_EFI_ERROR (Status); - } - } else { - // - // Do not over-allocate pages in this case. - // - Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory); - if (EFI_ERROR (Status)) { - return NULL; - } - AlignedMemory = (UINTN) Memory; - } - return (VOID *) AlignedMemory; -} - -/** - Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. - - Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an - alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is - returned. If there is not enough memory at the specified alignment remaining to satisfy the - request, then NULL is returned. - If Alignment is not a power of two and Alignment is not zero, then ASSERT(). - - @param Pages The number of 4 KB pages to allocate. - @param Alignment The requested alignment of the allocation. Must be a power of two. - If Alignment is zero, then byte alignment is used. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAlignedPages ( - IN UINTN Pages, - IN UINTN Alignment - ) -{ - return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment); -} - -/** - Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment. - - Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an - alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is - returned. If there is not enough memory at the specified alignment remaining to satisfy the - request, then NULL is returned. - If Alignment is not a power of two and Alignment is not zero, then ASSERT(). - - @param Pages The number of 4 KB pages to allocate. - @param Alignment The requested alignment of the allocation. Must be a power of two. - If Alignment is zero, then byte alignment is used. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAlignedRuntimePages ( - IN UINTN Pages, - IN UINTN Alignment - ) -{ - return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment); -} - -/** - Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment. - - Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an - alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is - returned. If there is not enough memory at the specified alignment remaining to satisfy the - request, then NULL is returned. - If Alignment is not a power of two and Alignment is not zero, then ASSERT(). - - @param Pages The number of 4 KB pages to allocate. - @param Alignment The requested alignment of the allocation. Must be a power of two. - If Alignment is zero, then byte alignment is used. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateAlignedReservedPages ( - IN UINTN Pages, - IN UINTN Alignment - ) -{ - return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment); -} - -/** - Frees one or more 4KB pages that were previously allocated with one of the aligned page - allocation functions in the Memory Allocation Library. - - Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer - must have been allocated on a previous call to the aligned page allocation services of the Memory - Allocation Library. - If Buffer was not allocated with an aligned page allocation function in the Memory Allocation - Library, then ASSERT(). - If Pages is zero, then ASSERT(). - - @param Buffer Pointer to the buffer of pages to free. - @param Pages The number of 4 KB pages to free. - -**/ -VOID -EFIAPI -FreeAlignedPages ( - IN VOID *Buffer, - IN UINTN Pages - ) -{ - EFI_STATUS Status; - - ASSERT (Pages != 0); - Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); - ASSERT_EFI_ERROR (Status); -} - -/** - Allocates a buffer of a certain pool type. - - Allocates the number bytes specified by AllocationSize of a certain pool type and returns a - pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param MemoryType The type of memory to allocate. - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -InternalAllocatePool ( - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN AllocationSize - ) -{ - EFI_STATUS Status; - VOID *Memory; - - Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory); - if (EFI_ERROR (Status)) { - Memory = NULL; - } - return Memory; -} - -/** - Allocates a buffer of type EfiBootServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a - pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocatePool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocatePool (EfiBootServicesData, AllocationSize); -} - -/** - Allocates a buffer of type EfiRuntimeServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns - a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateRuntimePool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize); -} - -/** - Allocates a buffer of type EfieservedMemoryType. - - Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns - a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is - returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateReservedPool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocatePool (EfiReservedMemoryType, AllocationSize); -} - -/** - Allocates and zeros a buffer of a certian pool type. - - Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer - with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid - buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, - then NULL is returned. - - @param PoolType The type of memory to allocate. - @param AllocationSize The number of bytes to allocate and zero. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -InternalAllocateZeroPool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN AllocationSize - ) -{ - VOID *Memory; - - Memory = InternalAllocatePool (PoolType, AllocationSize); - if (Memory != NULL) { - Memory = ZeroMem (Memory, AllocationSize); - } - return Memory; -} - -/** - Allocates and zeros a buffer of type EfiBootServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the - buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a - valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the - request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate and zero. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateZeroPool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize); -} - -/** - Allocates and zeros a buffer of type EfiRuntimeServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the - buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a - valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the - request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate and zero. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateRuntimeZeroPool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize); -} - -/** - Allocates and zeros a buffer of type EfiReservedMemoryType. - - Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the - buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a - valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the - request, then NULL is returned. - - @param AllocationSize The number of bytes to allocate and zero. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateReservedZeroPool ( - IN UINTN AllocationSize - ) -{ - return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize); -} - -/** - Copies a buffer to an allocated buffer of a certian pool type. - - Allocates the number bytes specified by AllocationSize of a certian pool type, copies - AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the - allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there - is not enough memory remaining to satisfy the request, then NULL is returned. - If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param PoolType The type of pool to allocate. - @param AllocationSize The number of bytes to allocate and zero. - @param Buffer The buffer to copy to the allocated buffer. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -InternalAllocateCopyPool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN AllocationSize, - IN CONST VOID *Buffer - ) -{ - VOID *Memory; - - ASSERT (Buffer != NULL); - ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1)); - - Memory = InternalAllocatePool (PoolType, AllocationSize); - if (Memory != NULL) { - Memory = CopyMem (Memory, Buffer, AllocationSize); - } - return Memory; -} - -/** - Copies a buffer to an allocated buffer of type EfiBootServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies - AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the - allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there - is not enough memory remaining to satisfy the request, then NULL is returned. - If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param AllocationSize The number of bytes to allocate and zero. - @param Buffer The buffer to copy to the allocated buffer. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateCopyPool ( - IN UINTN AllocationSize, - IN CONST VOID *Buffer - ) -{ - return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer); -} - -/** - Copies a buffer to an allocated buffer of type EfiRuntimeServicesData. - - Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies - AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the - allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there - is not enough memory remaining to satisfy the request, then NULL is returned. - If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param AllocationSize The number of bytes to allocate and zero. - @param Buffer The buffer to copy to the allocated buffer. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateRuntimeCopyPool ( - IN UINTN AllocationSize, - IN CONST VOID *Buffer - ) -{ - return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer); -} - -/** - Copies a buffer to an allocated buffer of type EfiReservedMemoryType. - - Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies - AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the - allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there - is not enough memory remaining to satisfy the request, then NULL is returned. - If Buffer is NULL, then ASSERT(). - If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param AllocationSize The number of bytes to allocate and zero. - @param Buffer The buffer to copy to the allocated buffer. - - @return A pointer to the allocated buffer or NULL if allocation fails. - -**/ -VOID * -EFIAPI -AllocateReservedCopyPool ( - IN UINTN AllocationSize, - IN CONST VOID *Buffer - ) -{ - return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer); -} - -/** - Frees a buffer that was previously allocated with one of the pool allocation functions in the - Memory Allocation Library. - - Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the - pool allocation services of the Memory Allocation Library. - If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, - then ASSERT(). - - @param Buffer Pointer to the buffer to free. - -**/ -VOID -EFIAPI -FreePool ( - IN VOID *Buffer - ) -{ - EFI_STATUS Status; - - Status = gBS->FreePool (Buffer); - ASSERT_EFI_ERROR (Status); -} - - -/** - Frees buffer that were previously allocated with one of the - memory allocation functions in the Memory Allocation Library. - - @param Buffer Pointer to the buffer of pages - to free. - -**/ -VOID -EFIAPI -SafeFreePool ( - IN VOID *Buffer - ) -{ - if (Buffer != NULL) { - FreePool (Buffer); - } -} - diff --git a/MdePkg/Library/DxeMemoryLib/CompareMemWrapper.c b/MdePkg/Library/DxeMemoryLib/CompareMemWrapper.c deleted file mode 100644 index 466a10eb41..0000000000 --- a/MdePkg/Library/DxeMemoryLib/CompareMemWrapper.c +++ /dev/null @@ -1,67 +0,0 @@ -/** @file - CompareMem() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Compares the contents of two buffers. - - This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. - If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the - value returned is the first mismatched byte in SourceBuffer subtracted from the first - mismatched byte in DestinationBuffer. - If Length > 0 and DestinationBuffer is NULL, then ASSERT(). - If Length > 0 and SourceBuffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - - - @param DestinationBuffer Pointer to the destination buffer to compare. - @param SourceBuffer Pointer to the source buffer to compare. - @param Length Number of bytes to compare. - - @return 0 All Length bytes of the two buffers are identical. - @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first - mismatched byte in DestinationBuffer. - -**/ -INTN -EFIAPI -CompareMem ( - IN CONST VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ) -{ - if (Length == 0 || DestinationBuffer == SourceBuffer) { - return 0; - } - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); - - return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); -} diff --git a/MdePkg/Library/DxeMemoryLib/CopyMemWrapper.c b/MdePkg/Library/DxeMemoryLib/CopyMemWrapper.c deleted file mode 100644 index 99870bcc83..0000000000 --- a/MdePkg/Library/DxeMemoryLib/CopyMemWrapper.c +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - CopyMem() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Copies a source buffer to a destination buffer, and returns the destination buffer. - - This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns - DestinationBuffer. The implementation must be reentrant, and it must handle the case - where SourceBuffer overlaps DestinationBuffer. - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - - @param DestinationBuffer Pointer to the destination buffer of the memory copy. - @param SourceBuffer Pointer to the source buffer of the memory copy. - @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer. - - @return DestinationBuffer. - -**/ -VOID * -EFIAPI -CopyMem ( - OUT VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ) -{ - if (Length == 0) { - return DestinationBuffer; - } - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); - - if (DestinationBuffer == SourceBuffer) { - return DestinationBuffer; - } - return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length); -} diff --git a/MdePkg/Library/DxeMemoryLib/DxeMemoryLib.inf b/MdePkg/Library/DxeMemoryLib/DxeMemoryLib.inf deleted file mode 100644 index 91132be6bc..0000000000 --- a/MdePkg/Library/DxeMemoryLib/DxeMemoryLib.inf +++ /dev/null @@ -1,59 +0,0 @@ -#/** @file -# Component description file for Dxe Memory Library. -# -# Base Memory Library implementation that uses EFI Boot Services -# where possible for size reduction. -# Copyright (c) 2006, Intel Corporation. -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = DxeMemoryLib - FILE_GUID = f1bbe03d-2f28-4dee-bec7-d98d7a30c36a - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = BaseMemoryLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - ScanMem64Wrapper.c - ScanMem32Wrapper.c - ScanMem16Wrapper.c - ScanMem8Wrapper.c - ZeroMemWrapper.c - CompareMemWrapper.c - SetMem64Wrapper.c - SetMem32Wrapper.c - SetMem16Wrapper.c - SetMemWrapper.c - CopyMemWrapper.c - MemLibGeneric.c - MemLibGuid.c - MemLib.c - MemLibInternals.h - - -[Packages] - MdePkg/MdePkg.dec - - -[LibraryClasses] - BaseLib - UefiBootServicesTableLib - DebugLib - diff --git a/MdePkg/Library/DxeMemoryLib/MemLib.c b/MdePkg/Library/DxeMemoryLib/MemLib.c deleted file mode 100644 index 5489fd0f08..0000000000 --- a/MdePkg/Library/DxeMemoryLib/MemLib.c +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - Base Memory Library functions implementation bases on Uefi Boot Service. - - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. 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 "MemLibInternals.h" - -/** - Copies a source buffer to a destination buffer, and returns the destination buffer. - - This function wraps the gBS->CopyMem(). - - @param DestinationBuffer Pointer to the destination buffer of the memory copy. - @param SourceBuffer Pointer to the source buffer of the memory copy. - @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer. - - @return DestinationBuffer. - -**/ -VOID * -EFIAPI -InternalMemCopyMem ( - OUT VOID *Destination, - IN CONST VOID *Source, - IN UINTN Length - ) -{ - gBS->CopyMem (Destination, (VOID*)Source, Length); - return Destination; -} - -/** - Fills a target buffer with a byte value, and returns the target buffer. - - This function wraps the gBS->SetMem(). - - @param Buffer Memory to set. - @param Size Number of bytes to set. - @param Value Value of the set operation. - - @return Buffer. - -**/ -VOID * -EFIAPI -InternalMemSetMem ( - OUT VOID *Buffer, - IN UINTN Size, - IN UINT8 Value - ) -{ - gBS->SetMem (Buffer, Size, Value); - return Buffer; -} diff --git a/MdePkg/Library/DxeMemoryLib/MemLibGeneric.c b/MdePkg/Library/DxeMemoryLib/MemLibGeneric.c deleted file mode 100644 index 3ae0387883..0000000000 --- a/MdePkg/Library/DxeMemoryLib/MemLibGeneric.c +++ /dev/null @@ -1,261 +0,0 @@ -/** @file - Architecture Independent Base Memory Library Implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Fills a target buffer with a 16-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem16 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ) -{ - do { - ((UINT16*)Buffer)[--Length] = Value; - } while (Length != 0); - return Buffer; -} - -/** - Fills a target buffer with a 32-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem32 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ) -{ - do { - ((UINT32*)Buffer)[--Length] = Value; - } while (Length != 0); - return Buffer; -} - -/** - Fills a target buffer with a 64-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem64 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ) -{ - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); - return Buffer; -} - -/** - Set Buffer to 0 for Size bytes. - - @param Buffer Memory to set. - @param Length Number of bytes to set - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemZeroMem ( - OUT VOID *Buffer, - IN UINTN Length - ) -{ - return InternalMemSetMem (Buffer, Length, 0); -} - -/** - Compares two memory buffers of a given length. - - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare. Must be non-zero. - - @return 0 All Length bytes of the two buffers are identical. - @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first - mismatched byte in DestinationBuffer. - -**/ -INTN -EFIAPI -InternalMemCompareMem ( - IN CONST VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ) -{ - while ((--Length != 0) && - (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { - DestinationBuffer = (INT8*)DestinationBuffer + 1; - SourceBuffer = (INT8*)SourceBuffer + 1; - } - return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer; -} - -/** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem8 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ) -{ - CONST UINT8 *Pointer; - - Pointer = (CONST UINT8*)Buffer; - do { - if (*(Pointer++) == Value) { - return Pointer; - } - } while (--Length != 0); - return NULL; -} - -/** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem16 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ) -{ - CONST UINT16 *Pointer; - - Pointer = (CONST UINT16*)Buffer; - do { - if (*(Pointer++) == Value) { - return Pointer; - } - } while (--Length != 0); - return NULL; -} - -/** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem32 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ) -{ - CONST UINT32 *Pointer; - - Pointer = (CONST UINT32*)Buffer; - do { - if (*(Pointer++) == Value) { - return Pointer; - } - } while (--Length != 0); - return NULL; -} - -/** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem64 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ) -{ - CONST UINT64 *Pointer; - - Pointer = (CONST UINT64*)Buffer; - do { - if (*(Pointer++) == Value) { - return Pointer; - } - } while (--Length != 0); - return NULL; -} diff --git a/MdePkg/Library/DxeMemoryLib/MemLibGuid.c b/MdePkg/Library/DxeMemoryLib/MemLibGuid.c deleted file mode 100644 index 4c6c615aa3..0000000000 --- a/MdePkg/Library/DxeMemoryLib/MemLibGuid.c +++ /dev/null @@ -1,139 +0,0 @@ -/** @file - Implementation of GUID functions. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Copies a source GUID to a destination GUID. - - This function copies the contents of the 128-bit GUID specified by SourceGuid to - DestinationGuid, and returns DestinationGuid. - If DestinationGuid is NULL, then ASSERT(). - If SourceGuid is NULL, then ASSERT(). - - @param DestinationGuid Pointer to the destination GUID. - @param SourceGuid Pointer to the source GUID. - - @return DestinationGuid. - -**/ -GUID * -EFIAPI -CopyGuid ( - OUT GUID *DestinationGuid, - IN CONST GUID *SourceGuid - ) -{ - WriteUnaligned64 ( - (UINT64*)DestinationGuid, - ReadUnaligned64 ((CONST UINT64*)SourceGuid) - ); - WriteUnaligned64 ( - (UINT64*)DestinationGuid + 1, - ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1) - ); - return DestinationGuid; -} - -/** - Compares two GUIDs. - - This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned. - If there are any bit differences in the two GUIDs, then FALSE is returned. - If Guid1 is NULL, then ASSERT(). - If Guid2 is NULL, then ASSERT(). - - @param Guid1 A pointer to a 128 bit GUID. - @param Guid2 A pointer to a 128 bit GUID. - - @retval TRUE Guid1 and Guid2 are identical. - @retval FALSE Guid1 and Guid2 are not identical. - -**/ -BOOLEAN -EFIAPI -CompareGuid ( - IN CONST GUID *Guid1, - IN CONST GUID *Guid2 - ) -{ - UINT64 LowPartOfGuid1; - UINT64 LowPartOfGuid2; - UINT64 HighPartOfGuid1; - UINT64 HighPartOfGuid2; - - LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1); - LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2); - HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1); - HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1); - - return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2); -} - -/** - Scans a target buffer for a GUID, and returns a pointer to the matching GUID - in the target buffer. - - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 128-bit increments for the 128-bit - GUID value that matches Guid. If a match is found, then a pointer to the matching - GUID in the target buffer is returned. If no match is found, then NULL is returned. - If Length is 0, then NULL is returned. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is not aligned on a 128-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Guid Value to search for in the target buffer. - - @return A pointer to the matching Guid in the target buffer or NULL otherwise. - -**/ -VOID * -EFIAPI -ScanGuid ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN CONST GUID *Guid - ) -{ - CONST GUID *GuidPtr; - - ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0); - ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); - ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0); - - GuidPtr = (GUID*)Buffer; - Buffer = GuidPtr + Length / sizeof (*GuidPtr); - while (GuidPtr < (CONST GUID*)Buffer) { - if (CompareGuid (GuidPtr, Guid)) { - return (VOID*)GuidPtr; - } - GuidPtr++; - } - return NULL; -} diff --git a/MdePkg/Library/DxeMemoryLib/MemLibInternals.h b/MdePkg/Library/DxeMemoryLib/MemLibInternals.h deleted file mode 100644 index 27c3c71851..0000000000 --- a/MdePkg/Library/DxeMemoryLib/MemLibInternals.h +++ /dev/null @@ -1,241 +0,0 @@ -/** @file - Declaration of internal functions for Base Memory Library. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#ifndef __MEM_LIB_INTERNALS__ -#define __MEM_LIB_INTERNALS__ - - -#include - - -#include -#include -#include -#include - -/** - Copy Length bytes from Source to Destination. - - @param DestinationBuffer Target of copy - @param SourceBuffer Place to copy from - @param Length Number of bytes to copy - - @return Destination - -**/ -VOID * -EFIAPI -InternalMemCopyMem ( - OUT VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ); - -/** - Set Buffer to Value for Size bytes. - - @param Buffer Memory to set. - @param Length Number of bytes to set - @param Value Value of the set operation. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ); - -/** - Fills a target buffer with a 16-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem16 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ); - -/** - Fills a target buffer with a 32-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem32 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ); - -/** - Fills a target buffer with a 64-bit value, and returns the target buffer. - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem64 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ); - -/** - Set Buffer to 0 for Size bytes. - - @param Buffer Memory to set. - @param Length Number of bytes to set - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemZeroMem ( - OUT VOID *Buffer, - IN UINTN Length - ); - -/** - Compares two memory buffers of a given length. - - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare. Must be non-zero. - - @return 0 All Length bytes of the two buffers are identical. - @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first - mismatched byte in DestinationBuffer. - -**/ -INTN -EFIAPI -InternalMemCompareMem ( - IN CONST VOID *DestinationBuffer, - IN CONST VOID *SourceBuffer, - IN UINTN Length - ); - -/** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem8 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ); - -/** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem16 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ); - -/** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem32 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ); - -/** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. Must be non-zero. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - -**/ -CONST VOID * -EFIAPI -InternalMemScanMem64 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ); - -#endif diff --git a/MdePkg/Library/DxeMemoryLib/ScanMem16Wrapper.c b/MdePkg/Library/DxeMemoryLib/ScanMem16Wrapper.c deleted file mode 100644 index e11c4844b7..0000000000 --- a/MdePkg/Library/DxeMemoryLib/ScanMem16Wrapper.c +++ /dev/null @@ -1,67 +0,0 @@ -/** @file - ScanMem16() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - - -#include "MemLibInternals.h" - -/** - Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value - in the target buffer. - - This function searches target the buffer specified by Buffer and Length from the lowest - address to the highest address for a 16-bit value that matches Value. If a match is found, - then a pointer to the matching byte in the target buffer is returned. If no match is found, - then NULL is returned. If Length is 0, then NULL is returned. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return A pointer to the matching byte in the target buffer or NULL otherwise. - -**/ -VOID * -EFIAPI -ScanMem16 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ) -{ - if (Length == 0) { - return NULL; - } - - ASSERT (Buffer != NULL); - ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/ScanMem32Wrapper.c b/MdePkg/Library/DxeMemoryLib/ScanMem32Wrapper.c deleted file mode 100644 index 52f2d2d603..0000000000 --- a/MdePkg/Library/DxeMemoryLib/ScanMem32Wrapper.c +++ /dev/null @@ -1,66 +0,0 @@ -/** @file - ScanMem32() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value - in the target buffer. - - This function searches target the buffer specified by Buffer and Length from the lowest - address to the highest address for a 32-bit value that matches Value. If a match is found, - then a pointer to the matching byte in the target buffer is returned. If no match is found, - then NULL is returned. If Length is 0, then NULL is returned. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return A pointer to the matching byte in the target buffer or NULL otherwise. - -**/ -VOID * -EFIAPI -ScanMem32 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ) -{ - if (Length == 0) { - return NULL; - } - - ASSERT (Buffer != NULL); - ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/ScanMem64Wrapper.c b/MdePkg/Library/DxeMemoryLib/ScanMem64Wrapper.c deleted file mode 100644 index 642420b1c9..0000000000 --- a/MdePkg/Library/DxeMemoryLib/ScanMem64Wrapper.c +++ /dev/null @@ -1,66 +0,0 @@ -/** @file - ScanMem64() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value - in the target buffer. - - This function searches target the buffer specified by Buffer and Length from the lowest - address to the highest address for a 64-bit value that matches Value. If a match is found, - then a pointer to the matching byte in the target buffer is returned. If no match is found, - then NULL is returned. If Length is 0, then NULL is returned. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return A pointer to the matching byte in the target buffer or NULL otherwise. - -**/ -VOID * -EFIAPI -ScanMem64 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ) -{ - if (Length == 0) { - return NULL; - } - - ASSERT (Buffer != NULL); - ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/ScanMem8Wrapper.c b/MdePkg/Library/DxeMemoryLib/ScanMem8Wrapper.c deleted file mode 100644 index 9dc9343eb2..0000000000 --- a/MdePkg/Library/DxeMemoryLib/ScanMem8Wrapper.c +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - ScanMem8() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - - -#include "MemLibInternals.h" - -/** - Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value - in the target buffer. - - This function searches target the buffer specified by Buffer and Length from the lowest - address to the highest address for an 8-bit value that matches Value. If a match is found, - then a pointer to the matching byte in the target buffer is returned. If no match is found, - then NULL is returned. If Length is 0, then NULL is returned. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return A pointer to the matching byte in the target buffer or NULL otherwise. - -**/ -VOID * -EFIAPI -ScanMem8 ( - IN CONST VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ) -{ - if (Length == 0) { - return NULL; - } - ASSERT (Buffer != NULL); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/SetMem16Wrapper.c b/MdePkg/Library/DxeMemoryLib/SetMem16Wrapper.c deleted file mode 100644 index c5a6f8f7dc..0000000000 --- a/MdePkg/Library/DxeMemoryLib/SetMem16Wrapper.c +++ /dev/null @@ -1,65 +0,0 @@ -/** @file - SetMem16() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Fills a target buffer with a 16-bit value, and returns the target buffer. - - This function fills Length bytes of Buffer with the 16-bit value specified by - Value, and returns Buffer. Value is repeated every 16-bits in for Length - bytes of Buffer. - - If Length > 0 and Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is not aligned on a 16-bit boundary, then ASSERT(). - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer. - -**/ -VOID * -EFIAPI -SetMem16 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT16 Value - ) -{ - if (Length == 0) { - return Buffer; - } - - ASSERT (Buffer != NULL); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/SetMem32Wrapper.c b/MdePkg/Library/DxeMemoryLib/SetMem32Wrapper.c deleted file mode 100644 index c5da3d6941..0000000000 --- a/MdePkg/Library/DxeMemoryLib/SetMem32Wrapper.c +++ /dev/null @@ -1,66 +0,0 @@ -/** @file - SetMem32() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - - -#include "MemLibInternals.h" - -/** - Fills a target buffer with a 32-bit value, and returns the target buffer. - - This function fills Length bytes of Buffer with the 32-bit value specified by - Value, and returns Buffer. Value is repeated every 32-bits in for Length - bytes of Buffer. - - If Length > 0 and Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is not aligned on a 32-bit boundary, then ASSERT(). - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer. - -**/ -VOID * -EFIAPI -SetMem32 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT32 Value - ) -{ - if (Length == 0) { - return Buffer; - } - - ASSERT (Buffer != NULL); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/SetMem64Wrapper.c b/MdePkg/Library/DxeMemoryLib/SetMem64Wrapper.c deleted file mode 100644 index 129a38ec8d..0000000000 --- a/MdePkg/Library/DxeMemoryLib/SetMem64Wrapper.c +++ /dev/null @@ -1,66 +0,0 @@ -/** @file - SetMem64() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - - -#include "MemLibInternals.h" - -/** - Fills a target buffer with a 64-bit value, and returns the target buffer. - - This function fills Length bytes of Buffer with the 64-bit value specified by - Value, and returns Buffer. Value is repeated every 64-bits in for Length - bytes of Buffer. - - If Length > 0 and Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is not aligned on a 64-bit boundary, then ASSERT(). - - @param Buffer Pointer to the target buffer to fill. - @param Length Number of bytes in Buffer to fill. - @param Value Value with which to fill Length bytes of Buffer. - - @return Buffer. - -**/ -VOID * -EFIAPI -SetMem64 ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT64 Value - ) -{ - if (Length == 0) { - return Buffer; - } - - ASSERT (Buffer != NULL); - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); - ASSERT ((Length & (sizeof (Value) - 1)) == 0); - - return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/SetMemWrapper.c b/MdePkg/Library/DxeMemoryLib/SetMemWrapper.c deleted file mode 100644 index 2b25f5fb35..0000000000 --- a/MdePkg/Library/DxeMemoryLib/SetMemWrapper.c +++ /dev/null @@ -1,56 +0,0 @@ -/** @file - SetMem() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - -#include "MemLibInternals.h" - -/** - Fills a target buffer with a byte value, and returns the target buffer. - - This function fills Length bytes of Buffer with Value, and returns Buffer. - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Memory to set. - @param Length Number of bytes to set. - @param Value Value of the set operation. - - @return Buffer. - -**/ -VOID * -EFIAPI -SetMem ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ) -{ - if (Length == 0) { - return Buffer; - } - - ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - - return InternalMemSetMem (Buffer, Length, Value); -} diff --git a/MdePkg/Library/DxeMemoryLib/ZeroMemWrapper.c b/MdePkg/Library/DxeMemoryLib/ZeroMemWrapper.c deleted file mode 100644 index 30c848a46d..0000000000 --- a/MdePkg/Library/DxeMemoryLib/ZeroMemWrapper.c +++ /dev/null @@ -1,52 +0,0 @@ -/** @file - ZeroMem() implementation. - - Copyright (c) 2006, Intel Corporation
- All rights reserved. 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. - - The following BaseMemoryLib instances contain the same copy of this file: - - BaseMemoryLib - BaseMemoryLibMmx - BaseMemoryLibSse2 - BaseMemoryLibRepStr - BaseMemoryLibOptDxe - BaseMemoryLibOptPei - PeiMemoryLib - DxeMemoryLib - -**/ - - -#include "MemLibInternals.h" - -/** - Fills a target buffer with zeros, and returns the target buffer. - - This function fills Length bytes of Buffer with zeros, and returns Buffer. - If Length > 0 and Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). - - @param Buffer Pointer to the target buffer to fill with zeros. - @param Length Number of bytes in Buffer to fill with zeros. - - @return Buffer. - -**/ -VOID * -EFIAPI -ZeroMem ( - OUT VOID *Buffer, - IN UINTN Length - ) -{ - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); - return InternalMemZeroMem (Buffer, Length); -} diff --git a/MdePkg/Library/DxePalLib/DxePalCallLib.c b/MdePkg/Library/DxePalLib/DxePalCallLib.c new file mode 100644 index 0000000000..61a2146ee1 --- /dev/null +++ b/MdePkg/Library/DxePalLib/DxePalCallLib.c @@ -0,0 +1,116 @@ +/** @file + PAL Library Class implementation whose PAL entry is collected + from HOB or SAL System Table. + + Copyright (c) 2007 - 2008 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + Module Name: DxePalCallLib.c + +**/ + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + + +BOOLEAN mPalCallAddressHob = FALSE; +BOOLEAN mPalCallAddressSal = FALSE; +UINT64 mPalCallAddress; + +/** + Makes a PAL procedure call. + + This is a wrapper function to make a PAL procedure call. Based on the Index value, + this API will make static or stacked PAL call. Architected procedures may be designated + as required or optional. If a PAL procedure is specified as optional, a unique return + code of 0xFFFFFFFFFFFFFFFF is returned in the Status field of the PAL_CALL_RETURN structure. + This indicates that the procedure is not present in this PAL implementation. It is the + caller's responsibility to check for this return code after calling any optional PAL + procedure. No parameter checking is performed on the 4 input parameters, but there are + some common rules that the caller should follow when making a PAL call. Any address + passed to PAL as buffers for return parameters must be 8-byte aligned. Unaligned addresses + may cause undefined results. For those parameters defined as reserved or some fields + defined as reserved must be zero filled or the invalid argument return value may be + returned or undefined result may occur during the execution of the procedure. + This function is only available on IPF. + + @param Index The PAL procedure Index number. + @param Arg2 The 2nd parameter for PAL procedure calls. + @param Arg3 The 3rd parameter for PAL procedure calls. + @param Arg4 The 4th parameter for PAL procedure calls. + + @return Structure returned from the PAL Call procedure, including the status and return value. + +**/ +PAL_CALL_RETURN +EFIAPI +PalCall ( + IN UINT64 Index, + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4 + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + EFI_STATUS Status; + SAL_ST_ENTRY_POINT_DESCRIPTOR *SalStEntryDes; + SAL_SYSTEM_TABLE_HEADER *SalSystemTable; + + + if (!mPalCallAddressHob) { + // + // Collect PAL entry from HOBs + // + GuidHob = GetFirstGuidHob (&gPalEntryHobGuid); + ASSERT (GuidHob != NULL); + + mPalCallAddress = *((EFI_PHYSICAL_ADDRESS *) GET_GUID_HOB_DATA (GuidHob)); + ASSERT (mPalCallAddress != 0); + + mPalCallAddressHob = TRUE; + } + + if (!mPalCallAddressSal) { + Status = EfiGetSystemConfigurationTable ( + &gEfiSalSystemTableGuid, + (VOID **) &SalSystemTable + ); + + if (!EFI_ERROR (Status)) { + // + // Move the SAL System Table point to the first Entry + // Due to the SAL Entry is in ascending order with the Entry type, + // the type 0 Entry should be the first if exist. + // + SalStEntryDes = (SAL_ST_ENTRY_POINT_DESCRIPTOR *)(SalSystemTable + 1); + + // + // Assure the SAL ENTRY Type is 0 + // + ASSERT (SalStEntryDes->Type == EFI_SAL_ST_ENTRY_POINT); + + if (SalStEntryDes->PalProcEntry != 0) { + mPalCallAddress = SalStEntryDes->PalProcEntry; + mPalCallAddressSal = TRUE; + } + } + } + + return AsmPalCall (mPalCallAddress, Index, Arg2, Arg3, Arg4); +} diff --git a/MdePkg/Library/DxePalLib/DxePalLib.inf b/MdePkg/Library/DxePalLib/DxePalLib.inf new file mode 100644 index 0000000000..cd9431245b --- /dev/null +++ b/MdePkg/Library/DxePalLib/DxePalLib.inf @@ -0,0 +1,54 @@ +# @file +# Instance of PAL Library Class +# +# This library implements the PAL Library Class for the early dxe drivers that need PAL calls before the +# Extended SAL PAL services are available +# Copyright (c) 2007, Intel Corporation. All rights reserved. +# +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# +# + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DxePalLib + FILE_GUID = B05D4251-5BA5-46f2-A011-46CC46D9A590 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = PalCallLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IPF +# + +[Sources.IPF] + DxePalCallLib.c + +[Packages] + MdePkg/MdePkg.dec + IntelFrameworkPkg/IntelFrameworkPkg.dec + ItaniumFamilyCpuPkg/ItaniumFamilyCpuPkg.dec + ItaniumPlatformPkg/ItaniumPlatformPkg.dec + +[LibraryClasses] + BaseLib + HobLib + UefiLib + DebugLib + +[Guids] + gEfiHobListGuid # ALWAYS_CONSUMED + gPalEntryHobGuid # ALWAYS_CONSUMED + gEfiSalSystemTableGuid # ALWAYS_CONSUMED diff --git a/MdePkg/Library/FvbServiceLib/Fvb.c b/MdePkg/Library/FvbServiceLib/Fvb.c new file mode 100644 index 0000000000..d1aa6041dd --- /dev/null +++ b/MdePkg/Library/FvbServiceLib/Fvb.c @@ -0,0 +1,726 @@ +/**@file + + Firmware Volume Block Protocol Runtime Interface Abstraction + And FVB Extension protocol Runtime Interface Abstraction + + mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the + index in the mFvbEntry array. This should be the same sequence as the FVB's + were described in the HOB. We have to remember the handle so we can tell if + the protocol has been reinstalled and it needs updateing. + + If you are using any of these lib functions.you must first call FvbInitialize (). + +Copyright (c) 2006 - 2008, Intel Corporation +All rights reserved. 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 "Fvb.h" + +// +// Event for Set Virtual Map Changed Event +// +STATIC EFI_EVENT mSetVirtualMapChangedEvent = NULL; + +// +// Lib will ASSERT if more FVB devices than this are added to the system. +// +STATIC FVB_ENTRY *mFvbEntry; +STATIC EFI_EVENT mFvbRegistration; +STATIC UINTN mFvbCount; + +/** + Check whether an address is runtime memory or not. + + @param Address The Address being checked. + + @retval TRUE The address is runtime memory. + @retval FALSE The address is not runtime memory. +**/ +BOOLEAN +IsRuntimeMemory ( + IN VOID *Address + ) +{ + EFI_STATUS Status; + UINT8 TmpMemoryMap[1]; + UINTN MapKey; + UINTN DescriptorSize; + UINT32 DescriptorVersion; + UINTN MemoryMapSize; + EFI_MEMORY_DESCRIPTOR *MemoryMap; + EFI_MEMORY_DESCRIPTOR *MemoryMapPtr; + BOOLEAN IsRuntime; + UINTN Index; + + IsRuntime = FALSE; + + // + // Get System MemoryMapSize + // + MemoryMapSize = 1; + Status = gBS->GetMemoryMap ( + &MemoryMapSize, + (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + ASSERT (Status == EFI_BUFFER_TOO_SMALL); + // + // Enlarge space here, because we will allocate pool now. + // + MemoryMapSize += EFI_PAGE_SIZE; + Status = gBS->AllocatePool ( + EfiBootServicesData, + MemoryMapSize, + (VOID**)&MemoryMap + ); + ASSERT_EFI_ERROR (Status); + + // + // Get System MemoryMap + // + Status = gBS->GetMemoryMap ( + &MemoryMapSize, + MemoryMap, + &MapKey, + &DescriptorSize, + &DescriptorVersion + ); + ASSERT_EFI_ERROR (Status); + + MemoryMapPtr = MemoryMap; + // + // Search the request Address + // + for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) { + if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) && + ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart + + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) { + // + // Found it + // + if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) { + IsRuntime = TRUE; + } + break; + } + // + // Get next item + // + MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize); + } + + // + // Done + // + gBS->FreePool (MemoryMapPtr); + + return IsRuntime; +} + +/** + Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is + reinstalled. + + @param Event The Event that is being processed + @param Context Event Context + +**/ +STATIC +VOID +EFIAPI +FvbNotificationEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HANDLE Handle; + UINTN Index; + UINTN UpdateIndex; + + while (TRUE) { + BufferSize = sizeof (Handle); + Status = gBS->LocateHandle ( + ByRegisterNotify, + &gEfiFirmwareVolumeBlockProtocolGuid, + mFvbRegistration, + &BufferSize, + &Handle + ); + if (EFI_ERROR (Status)) { + // + // Exit Path of While Loop.... + // + break; + } + + UpdateIndex = MAX_FVB_COUNT; + for (Index = 0; Index < mFvbCount; Index++) { + if (mFvbEntry[Index].Handle == Handle) { + // + // If the handle is already in the table just update the protocol + // + UpdateIndex = Index; + break; + } + } + + if (UpdateIndex == MAX_FVB_COUNT) { + // + // Use the next free slot for a new entry + // + UpdateIndex = mFvbCount++; + // + // Check the UpdateIndex whether exceed the maximum value. + // + ASSERT (UpdateIndex < MAX_FVB_COUNT); + mFvbEntry[UpdateIndex].Handle = Handle; + } + // + // The array does not have enough entries + // + ASSERT (UpdateIndex < MAX_FVB_COUNT); + + // + // Get the interface pointer and if it's ours, skip it + // + Status = gBS->HandleProtocol ( + Handle, + &gEfiFirmwareVolumeBlockProtocolGuid, + (VOID **) &mFvbEntry[UpdateIndex].Fvb + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->HandleProtocol ( + Handle, + &gEfiFvbExtensionProtocolGuid, + (VOID **) &mFvbEntry[UpdateIndex].FvbExtension + ); + if (Status != EFI_SUCCESS) { + mFvbEntry[UpdateIndex].FvbExtension = NULL; + } + + // + // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes + // from two way: + // 1) Dxe Core. (FVB information is transferred from FV HOB). + // 2) FVB driver. + // The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These + // FVBs can only be accessed in boot time. + // FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime. + // The FVB itself produced by FVB driver is allocated in runtime memory. So we can + // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated + // in RUNTIME memory. + // + mFvbEntry[UpdateIndex].IsRuntimeAccess = IsRuntimeMemory (mFvbEntry[UpdateIndex].Fvb); + } +} + +/** + Convert all pointers in mFvbEntry after ExitBootServices. + + @param Event The Event that is being processed + @param Context Event Context + +**/ +VOID +EFIAPI +FvbVirtualAddressChangeNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINTN Index; + if (mFvbEntry != NULL) { + for (Index = 0; Index < MAX_FVB_COUNT; Index++) { + if (!mFvbEntry[Index].IsRuntimeAccess) { + continue; + } + + if (NULL != mFvbEntry[Index].Fvb) { + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->SetAttributes); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Read); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Write); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb); + } + + if (NULL != mFvbEntry[Index].FvbExtension) { + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock); + EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension); + } + } + + EfiConvertPointer (0x0, (VOID **) &mFvbEntry); + } +} + +/** + Library constructor function entry. + + @param ImageHandle The handle of image who call this libary. + @param SystemTable The point of System Table. + + @retval EFI_SUCESS Sucess construct this library. + @retval Others Fail to contruct this libary. +**/ +EFI_STATUS +EFIAPI +FvbLibInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINTN Status; + mFvbCount = 0; + + Status = gBS->AllocatePool ( + EfiRuntimeServicesData, + (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT, + (VOID *) &mFvbEntry + ); + + if (EFI_ERROR (Status)) { + return Status; + } + + ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT); + + EfiCreateProtocolNotifyEvent ( + &gEfiFirmwareVolumeBlockProtocolGuid, + TPL_CALLBACK, + FvbNotificationEvent, + NULL, + &mFvbRegistration + ); + + // + // Register SetVirtualAddressMap () notify function + // + Status = gBS->CreateEvent ( + EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE, + TPL_NOTIFY, + FvbVirtualAddressChangeNotifyEvent, + NULL, + &mSetVirtualMapChangedEvent + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +// +// ============================================================================= +// The following functions wrap Fvb protocol in the Runtime Lib functions. +// The Instance translates into Fvb instance. The Fvb order defined by HOBs and +// thus the sequence of FVB protocol addition define Instance. +// +// EfiFvbInitialize () must be called before any of the following functions +// must be called. +// ============================================================================= +// + +/** + Reads specified number of bytes into a buffer from the specified block. + + The EfiFvbReadBlock() function reads the requested number of bytes from + the requested block in the specified firmware volume and stores them in + the provided buffer. Implementations should be mindful that the firmware + volume might be in the ReadDisabled state. If it is in this state, the + EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED + without modifying the contents of the buffer. + + The EfiFvbReadBlock() function must also prevent spanning block boundaries. + If a read is requested that would span a block boundary, the read must read + up to the boundary but not beyond. The output parameter NumBytes must be + set to correctly indicate the number of bytes actually read. + The caller must be aware that a read may be partially completed. + + If NumBytes is NULL, then ASSERT(). + + If Buffer is NULL, then ASSERT(). + + @param[in] Instance The FV instance to be read from. + @param[in] Lba The logical block address to be read from + @param[in] Offset The offset relative to the block, at which to begin reading. + @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total + size of the buffer. On output, it contains the actual number + of bytes read. + @param[out] Buffer Pointer to a caller allocated buffer that will be + used to hold the data read. + + @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer. + @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer. + @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state. + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read. + @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index is larger than the last block of the firmware volume. Offset is larger than the block size. + +**/ +EFI_STATUS +EfiFvbReadBlock ( + IN UINTN Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + OUT UINT8 *Buffer + ) +{ + ASSERT (NumBytes != NULL); + ASSERT (Buffer != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer); +} + +/** + Writes specified number of bytes from the input buffer to the block + + The EfiFvbWriteBlock() function writes the specified number of bytes + from the provided buffer to the specified block and offset in the + requested firmware volume. + + If the firmware volume is sticky write, the caller must ensure that + all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY + state before calling the EfiFvbWriteBlock() function, or else the + result will be unpredictable. This unpredictability arises because, + for a sticky-write firmware volume, a write may negate a bit in the + EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In + general, before calling the EfiFvbWriteBlock() function, the caller + should call the EfiFvbEraseBlock() function first to erase the specified + block to write. A block erase cycle will transition bits from the + (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state. + Implementations should be mindful that the firmware volume might be + in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock() + function must return the status code EFI_ACCESS_DENIED without modifying + the contents of the firmware volume. + + The EfiFvbWriteBlock() function must also prevent spanning block boundaries. + If a write is requested that spans a block boundary, the write must store + up to the boundary but not beyond. The output parameter NumBytes must be + set to correctly indicate the number of bytes actually written. The caller + must be aware that a write may be partially completed. + All writes, partial or otherwise, must be fully flushed to the hardware + before the EfiFvbWriteBlock() function returns. + + If NumBytes is NULL, then ASSERT(). + + @param Instance The FV instance to be written to + @param Lba The starting logical block index to write to + @param Offset The offset relative to the block, at which to begin writting. + @param NumBytes Pointer to a UINTN. On input, *NumBytes contains + the total size of the buffer. On output, it contains + the actual number of bytes written. + @param Buffer Pointer to a caller allocated buffer that contains + the source for the write + + @retval EFI_SUCCESS The firmware volume was written successfully. + @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary. + On output, NumBytes contains the total number of bytes actually written. + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state. + @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written. + @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. + Lba index is larger than the last block of the firmware volume. + Offset is larger than the block size. +**/ +EFI_STATUS +EfiFvbWriteBlock ( + IN UINTN Instance, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + ASSERT (NumBytes != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer); +} + +/** + Erases and initializes a firmware volume block. + + The EfiFvbEraseBlock() function erases one block specified by Lba. + Implementations should be mindful that the firmware volume might + be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock() + function must return the status code EFI_ACCESS_DENIED without + modifying the contents of the firmware volume. If Instance is + larger than the max FVB number, or Lba index is larger than the + last block of the firmware volume, this function return the status + code EFI_INVALID_PARAMETER. + + All calls to EfiFvbEraseBlock() must be fully flushed to the + hardware before this function returns. + + @param[in] Instance The FV instance to be erased. + @param[in] Lba The logical block index to be erased from. + + @retval EFI_SUCCESS The erase request was successfully completed. + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state. + @retval EFI_DEVICE_ERROR The block device is not functioning correctly and + could not be written. The firmware device may + have been partially erased. + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max + FVB number. Lba index is larger than the last block + of the firmware volume. + +**/ +EFI_STATUS +EfiFvbEraseBlock ( + IN UINTN Instance, + IN EFI_LBA Lba + ) +{ + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR); +} + +/** + Retrieves the attributes and current settings of the specified block, + returns resulting attributes in output parameter. + + The EfiFvbGetAttributes() function retrieves the attributes and current + settings of the block specified by Instance. If Instance is larger than + the max FVB number, this function returns the status code EFI_INVALID_PARAMETER. + + If Attributes is NULL, then ASSERT(). + + @param[in] Instance The FV instance to be operated. + @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the + attributes and current settings are returned. + + @retval EFI_EFI_SUCCESS The firmware volume attributes were returned. + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. +**/ +EFI_STATUS +EfiFvbGetVolumeAttributes ( + IN UINTN Instance, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + ASSERT (Attributes != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes); +} + +/** + Modify the attributes and current settings of the specified block + according to the input parameter. + + The EfiFvbSetAttributes() function sets configurable firmware volume + attributes and returns the new settings of the firmware volume specified + by Instance. If Instance is larger than the max FVB number, this function + returns the status code EFI_INVALID_PARAMETER. + + If Attributes is NULL, then ASSERT(). + + @param[in] Instance The FV instance to be operated. + @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2 + that contains the desired firmware volume settings. + On successful return, it contains the new settings of the firmware volume. + + @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully. + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. + +**/ +EFI_STATUS +EfiFvbSetVolumeAttributes ( + IN UINTN Instance, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + ASSERT (Attributes != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes); +} + +/** + Retrieves the physical address of the specified memory mapped FV. + + Retrieve the base address of a memory-mapped firmware volume specified by Instance. + If Instance is larger than the max FVB number, this function returns the status + code EFI_INVALID_PARAMETER. + + If BaseAddress is NULL, then ASSERT(). + + @param[in] Instance The FV instance to be operated. + @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS + that on successful return, contains the base address + of the firmware volume. + + @retval EFI_EFI_SUCCESS The firmware volume base address is returned. + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. + +**/ +EFI_STATUS +EfiFvbGetPhysicalAddress ( + IN UINTN Instance, + OUT EFI_PHYSICAL_ADDRESS *BaseAddress + ) +{ + ASSERT (BaseAddress != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress); +} + +/** + Retrieve the block size of the specified fv. + + The EfiFvbGetBlockSize() function retrieves the size of the requested block. + It also returns the number of additional blocks with the identical size. + If Instance is larger than the max FVB number, or Lba index is larger than + the last block of the firmware volume, this function return the status code + EFI_INVALID_PARAMETER. + + If BlockSize is NULL, then ASSERT(). + + If NumOfBlocks is NULL, then ASSERT(). + + @param[in] Instance The FV instance to be operated. + @param[in] Lba Indicates which block to return the size for. + @param[out] BlockSize Pointer to a caller-allocated UINTN in which the + size of the block is returned. + @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the + number of consecutive blocks, starting with Lba, + is returned. All blocks in this range have a size of BlockSize. + + @retval EFI_EFI_SUCCESS The firmware volume base address is returned. + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. + Lba index is larger than the last block of the firmware volume. + +**/ +EFI_STATUS +EfiFvbGetBlockSize ( + IN UINTN Instance, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumOfBlocks + ) +{ + ASSERT (BlockSize != NULL); + ASSERT (NumOfBlocks != NULL); + + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks); +} + +/** + Erases and initializes a specified range of a firmware volume. + + The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware + volume index by Instance. If Instance is larger than the max FVB number, StartLba or + LastLba index is larger than the last block of the firmware volume, StartLba > LastLba + or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return + the status code EFI_INVALID_PARAMETER. + + @param[in] Instance The FV instance to be operated. + @param[in] StartLba The starting logical block index to be erased. + @param[in] OffsetStartLba Offset into the starting block at which to + begin erasing. + @param[in] LastLba The last logical block index to be erased. + @param[in] OffsetLastLba Offset into the last block at which to end erasing. + + @retval EFI_EFI_SUCCESS Successfully erase custom block range + @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. + @retval EFI_UNSUPPORTED Firmware volume block device has no this capability. + +**/ +EFI_STATUS +EfiFvbEraseCustomBlockRange ( + IN UINTN Instance, + IN EFI_LBA StartLba, + IN UINTN OffsetStartLba, + IN EFI_LBA LastLba, + IN UINTN OffsetLastLba + ) +{ + if (Instance >= mFvbCount) { + return EFI_INVALID_PARAMETER; + } + + if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) { + return EFI_INVALID_PARAMETER; + } + + if (!(mFvbEntry[Instance].FvbExtension)) { + return EFI_UNSUPPORTED; + } + + if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) { + return EFI_UNSUPPORTED; + } + + return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock ( + mFvbEntry[Instance].FvbExtension, + StartLba, + OffsetStartLba, + LastLba, + OffsetLastLba + ); +} diff --git a/MdePkg/Library/FvbServiceLib/Fvb.h b/MdePkg/Library/FvbServiceLib/Fvb.h new file mode 100644 index 0000000000..5d54fd18c9 --- /dev/null +++ b/MdePkg/Library/FvbServiceLib/Fvb.h @@ -0,0 +1,44 @@ +/** @file + The internal header file includes the common header files, defines + internal structure FVB_ENTRY. + +Copyright (c) 2006 - 2008, Intel Corporation.
+ +All rights reserved. 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. + +**/ + +#ifndef __FVB_H__ +#define __FVB_H__ + + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MAX_FVB_COUNT 16 + +typedef struct { + EFI_HANDLE Handle; + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; + EFI_FVB_EXTENSION_PROTOCOL *FvbExtension; + BOOLEAN IsRuntimeAccess; +} FVB_ENTRY; + +#endif diff --git a/MdePkg/Library/FvbServiceLib/FvbServiceLib.inf b/MdePkg/Library/FvbServiceLib/FvbServiceLib.inf new file mode 100644 index 0000000000..54bddcb0e6 --- /dev/null +++ b/MdePkg/Library/FvbServiceLib/FvbServiceLib.inf @@ -0,0 +1,57 @@ +#/** @file +# FvbService Library for UEFI drivers +# +# This library instance provide sevice functions to access Firmware Volume Block protocol. +# Copyright (c) 2006 - 2007, Intel Corporation +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = FvbServiceLib + FILE_GUID = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67 + MODULE_TYPE = DXE_RUNTIME_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + CONSTRUCTOR = FvbLibInitialize + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# +# VIRTUAL_ADDRESS_MAP_CALLBACK = FvbVirtualAddressChangeNotifyEvent +# + +[Sources] + Fvb.h + Fvb.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + UefiRuntimeLib + BaseMemoryLib + DebugLib + BaseLib + UefiLib + +[Protocols] + gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED + gEfiFvbExtensionProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_CONSUMED + diff --git a/MdePkg/Library/GraphicsLib/Graphics.c b/MdePkg/Library/GraphicsLib/Graphics.c new file mode 100644 index 0000000000..75aa91dc6c --- /dev/null +++ b/MdePkg/Library/GraphicsLib/Graphics.c @@ -0,0 +1,917 @@ +/** @file + Library supports diplaying graphical splash screen, + locking of keyboard input and printing character on + screen. These basic graphics operations are based on UEFI HII, + Graphics Output protocol or UGA Draw protocol. + +Copyright (c) 2006 - 2008, Intel Corporation +All rights reserved. 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 + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = { + { 0x00, 0x00, 0x00, 0x00 }, + { 0x98, 0x00, 0x00, 0x00 }, + { 0x00, 0x98, 0x00, 0x00 }, + { 0x98, 0x98, 0x00, 0x00 }, + { 0x00, 0x00, 0x98, 0x00 }, + { 0x98, 0x00, 0x98, 0x00 }, + { 0x00, 0x98, 0x98, 0x00 }, + { 0x98, 0x98, 0x98, 0x00 }, + { 0x10, 0x10, 0x10, 0x00 }, + { 0xff, 0x10, 0x10, 0x00 }, + { 0x10, 0xff, 0x10, 0x00 }, + { 0xff, 0xff, 0x10, 0x00 }, + { 0x10, 0x10, 0xff, 0x00 }, + { 0xf0, 0x10, 0xff, 0x00 }, + { 0x10, 0xff, 0xff, 0x00 }, + { 0xff, 0xff, 0xff, 0x00 } +}; + + +/** + Return the graphics image file named FileNameGuid into Image and return it's + size in ImageSize. All Firmware Volumes (FV) in the system are searched for the + file name. + + @param FileNameGuid File Name of graphics file in the FV(s). + @param Image Pointer to pointer to return graphics image. If NULL, a + buffer will be allocated. + @param ImageSize Size of the graphics Image in bytes. Zero if no image found. + + @retval EFI_SUCCESS Image and ImageSize are valid. + @retval EFI_BUFFER_TOO_SMALL Image not big enough. ImageSize has required size + @retval EFI_NOT_FOUND FileNameGuid not found + +**/ +EFI_STATUS +EFIAPI +GetGraphicsBitMapFromFV ( + IN EFI_GUID *FileNameGuid, + OUT VOID **Image, + OUT UINTN *ImageSize + ) +{ + return GetGraphicsBitMapFromFVEx (NULL, FileNameGuid, Image, ImageSize); +} + +/** + Return the graphics image file named FileNameGuid into Image and return it's + size in ImageSize. All Firmware Volumes (FV) in the system are searched for the + file name. + + @param ImageHandle The driver image handle of the caller. The parameter is used to + optimize the loading of the image file so that the FV from which + the driver image is loaded will be tried first. + @param FileNameGuid File Name of graphics file in the FV(s). + @param Image Pointer to pointer to return graphics image. If NULL, a + buffer will be allocated. + @param ImageSize Size of the graphics Image in bytes. Zero if no image found. + + @retval EFI_SUCCESS Image and ImageSize are valid. + @retval EFI_BUFFER_TOO_SMALL Image not big enough. ImageSize has required size + @retval EFI_NOT_FOUND FileNameGuid not found + +**/ +EFI_STATUS +EFIAPI +GetGraphicsBitMapFromFVEx ( + IN EFI_HANDLE ImageHandle, + IN EFI_GUID *FileNameGuid, + OUT VOID **Image, + OUT UINTN *ImageSize + ) +{ + return PiLibGetSectionFromAnyFv ( + FileNameGuid, + EFI_SECTION_RAW, + 0, + Image, + ImageSize + ); +} + +/** + Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer + is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt + buffer is passed in it will be used if it is big enough. + + @param BmpImage Pointer to BMP file + @param BmpImageSize Number of bytes in BmpImage + @param GopBlt Buffer containing GOP version of BmpImage. + @param GopBltSize Size of GopBlt in bytes. + @param PixelHeight Height of GopBlt/BmpImage in pixels + @param PixelWidth Width of GopBlt/BmpImage in pixels + + @retval EFI_SUCCESS GopBlt and GopBltSize are returned. + @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image + @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough. + GopBltSize will contain the required size. + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate. + +**/ +EFI_STATUS +EFIAPI +ConvertBmpToGopBlt ( + IN VOID *BmpImage, + IN UINTN BmpImageSize, + IN OUT VOID **GopBlt, + IN OUT UINTN *GopBltSize, + OUT UINTN *PixelHeight, + OUT UINTN *PixelWidth + ) +{ + UINT8 *Image; + UINT8 *ImageHeader; + BMP_IMAGE_HEADER *BmpHeader; + BMP_COLOR_MAP *BmpColorMap; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; + UINTN BltBufferSize; + UINTN Index; + UINTN Height; + UINTN Width; + UINTN ImageIndex; + BOOLEAN IsAllocated; + + BmpHeader = (BMP_IMAGE_HEADER *) BmpImage; + + if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') { + return EFI_UNSUPPORTED; + } + + // + // Doesn't support compress. + // + if (BmpHeader->CompressionType != 0) { + return EFI_UNSUPPORTED; + } + + // + // Calculate Color Map offset in the image. + // + Image = BmpImage; + BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER)); + + // + // Calculate graphics image data address in the image + // + Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset; + ImageHeader = Image; + + // + // Calculate the BltBuffer needed size. + // + BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + IsAllocated = FALSE; + if (*GopBlt == NULL) { + // + // GopBlt is not allocated by caller. + // + *GopBltSize = BltBufferSize; + *GopBlt = AllocatePool (*GopBltSize); + IsAllocated = TRUE; + if (*GopBlt == NULL) { + return EFI_OUT_OF_RESOURCES; + } + } else { + // + // GopBlt has been allocated by caller. + // + if (*GopBltSize < BltBufferSize) { + *GopBltSize = BltBufferSize; + return EFI_BUFFER_TOO_SMALL; + } + } + + *PixelWidth = BmpHeader->PixelWidth; + *PixelHeight = BmpHeader->PixelHeight; + + // + // Convert image from BMP to Blt buffer format + // + BltBuffer = *GopBlt; + for (Height = 0; Height < BmpHeader->PixelHeight; Height++) { + Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth]; + for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) { + switch (BmpHeader->BitPerPixel) { + case 1: + // + // Convert 1-bit (2 colors) BMP to 24-bit color + // + for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) { + Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red; + Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green; + Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue; + Blt++; + Width++; + } + + Blt --; + Width --; + break; + + case 4: + // + // Convert 4-bit (16 colors) BMP Palette to 24-bit color + // + Index = (*Image) >> 4; + Blt->Red = BmpColorMap[Index].Red; + Blt->Green = BmpColorMap[Index].Green; + Blt->Blue = BmpColorMap[Index].Blue; + if (Width < (BmpHeader->PixelWidth - 1)) { + Blt++; + Width++; + Index = (*Image) & 0x0f; + Blt->Red = BmpColorMap[Index].Red; + Blt->Green = BmpColorMap[Index].Green; + Blt->Blue = BmpColorMap[Index].Blue; + } + break; + + case 8: + // + // Convert 8-bit (256 colors) BMP Palette to 24-bit color + // + Blt->Red = BmpColorMap[*Image].Red; + Blt->Green = BmpColorMap[*Image].Green; + Blt->Blue = BmpColorMap[*Image].Blue; + break; + + case 24: + // + // It is 24-bit BMP. + // + Blt->Blue = *Image++; + Blt->Green = *Image++; + Blt->Red = *Image; + break; + + default: + // + // Other bit format BMP is not supported. + // + if (IsAllocated) { + FreePool (*GopBlt); + *GopBlt = NULL; + } + return EFI_UNSUPPORTED; + break; + }; + + } + + ImageIndex = (UINTN) (Image - ImageHeader); + if ((ImageIndex % 4) != 0) { + // + // Bmp Image starts each row on a 32-bit boundary! + // + Image = Image + (4 - (ImageIndex % 4)); + } + } + + return EFI_SUCCESS; +} + + +/** + Use Console Control Protocol to lock the Console In Spliter virtual handle. + This is the ConInHandle and ConIn handle in the EFI system table. All key + presses will be ignored until the Password is typed in. The only way to + disable the password is to type it in to a ConIn device. + + @param Password Password used to lock ConIn device. + + @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully. + @retval EFI_UNSUPPORTED Password not found. + +**/ +EFI_STATUS +EFIAPI +LockKeyboards ( + IN CHAR16 *Password + ) +{ + EFI_STATUS Status; + EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; + + Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + Status = ConsoleControl->LockStdIn (ConsoleControl, Password); + return Status; +} + + +/** + Use Console Control to turn off UGA based Simple Text Out consoles from going + to the UGA device. Put up LogoFile on every UGA device that is a console. + + @param LogoFile File name of logo to display on the center of the screen. + + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. + @retval EFI_UNSUPPORTED Logo not found. + +**/ +EFI_STATUS +EFIAPI +EnableQuietBoot ( + IN EFI_GUID *LogoFile + ) +{ + return EnableQuietBootEx (LogoFile, NULL); +} + +/** + Use Console Control to turn off UGA based Simple Text Out consoles from going + to the UGA device. Put up LogoFile on every UGA device that is a console + + @param LogoFile File name of logo to display on the center of the screen. + @param ImageHandle The driver image handle of the caller. The parameter is used to + optimize the loading of the logo file so that the FV from which + the driver image is loaded will be tried first. + + @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed. + @retval EFI_UNSUPPORTED Logo not found. + +**/ +EFI_STATUS +EFIAPI +EnableQuietBootEx ( + IN EFI_GUID *LogoFile, + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; + EFI_OEM_BADGING_PROTOCOL *Badging; + UINT32 SizeOfX; + UINT32 SizeOfY; + INTN DestX; + INTN DestY; + UINT8 *ImageData; + UINTN ImageSize; + UINTN BltSize; + UINT32 Instance; + EFI_BADGING_FORMAT Format; + EFI_BADGING_DISPLAY_ATTRIBUTE Attribute; + UINTN CoordinateX; + UINTN CoordinateY; + UINTN Height; + UINTN Width; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt; + EFI_UGA_DRAW_PROTOCOL *UgaDraw; + UINT32 ColorDepth; + UINT32 RefreshRate; + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + + Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + UgaDraw = NULL; + // + // Try to open GOP first + // + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { + GraphicsOutput = NULL; + // + // Open GOP failed, try to open UGA + // + Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw); + } + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + Badging = NULL; + Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging); + + // + // Set console control to graphics mode. + // + Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + if (GraphicsOutput != NULL) { + SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution; + SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution; + } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + } else { + return EFI_UNSUPPORTED; + } + + Instance = 0; + while (1) { + ImageData = NULL; + ImageSize = 0; + + if (Badging != NULL) { + // + // Get image from OEMBadging protocol. + // + Status = Badging->GetImage ( + Badging, + &Instance, + &Format, + &ImageData, + &ImageSize, + &Attribute, + &CoordinateX, + &CoordinateY + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Currently only support BMP format. + // + if (Format != EfiBadgingFormatBMP) { + SafeFreePool (ImageData); + continue; + } + } else { + // + // Get the specified image from FV. + // + Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, (VOID **) &ImageData, &ImageSize); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + CoordinateX = 0; + CoordinateY = 0; + Attribute = EfiBadgingDisplayAttributeCenter; + } + + Blt = NULL; + Status = ConvertBmpToGopBlt ( + ImageData, + ImageSize, + (VOID **) &Blt, + &BltSize, + &Height, + &Width + ); + if (EFI_ERROR (Status)) { + SafeFreePool (ImageData); + if (Badging == NULL) { + return Status; + } else { + continue; + } + } + + // + // Caculate the display position according to Attribute. + // + switch (Attribute) { + case EfiBadgingDisplayAttributeLeftTop: + DestX = CoordinateX; + DestY = CoordinateY; + break; + + case EfiBadgingDisplayAttributeCenterTop: + DestX = (SizeOfX - Width) / 2; + DestY = CoordinateY; + break; + + case EfiBadgingDisplayAttributeRightTop: + DestX = (SizeOfX - Width - CoordinateX); + DestY = CoordinateY;; + break; + + case EfiBadgingDisplayAttributeCenterRight: + DestX = (SizeOfX - Width - CoordinateX); + DestY = (SizeOfY - Height) / 2; + break; + + case EfiBadgingDisplayAttributeRightBottom: + DestX = (SizeOfX - Width - CoordinateX); + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeCenterBottom: + DestX = (SizeOfX - Width) / 2; + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeLeftBottom: + DestX = CoordinateX; + DestY = (SizeOfY - Height - CoordinateY); + break; + + case EfiBadgingDisplayAttributeCenterLeft: + DestX = CoordinateX; + DestY = (SizeOfY - Height) / 2; + break; + + case EfiBadgingDisplayAttributeCenter: + DestX = (SizeOfX - Width) / 2; + DestY = (SizeOfY - Height) / 2; + break; + + default: + DestX = CoordinateX; + DestY = CoordinateY; + break; + } + + if ((DestX >= 0) && (DestY >= 0)) { + if (GraphicsOutput != NULL) { + Status = GraphicsOutput->Blt ( + GraphicsOutput, + Blt, + EfiBltBufferToVideo, + 0, + 0, + (UINTN) DestX, + (UINTN) DestY, + Width, + Height, + Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + Status = UgaDraw->Blt ( + UgaDraw, + (EFI_UGA_PIXEL *) Blt, + EfiUgaBltBufferToVideo, + 0, + 0, + (UINTN) DestX, + (UINTN) DestY, + Width, + Height, + Width * sizeof (EFI_UGA_PIXEL) + ); + } else { + Status = EFI_UNSUPPORTED; + } + } + + SafeFreePool (ImageData); + SafeFreePool (Blt); + + if (Badging == NULL) { + break; + } + } + + return Status; +} + +/** + Use Console Control to turn on UGA based Simple Text Out consoles. The UGA + Simple Text Out screens will now be synced up with all non UGA output devices + + @retval EFI_SUCCESS UGA devices are back in text mode and synced up. + @retval EFI_UNSUPPORTED Logo not found + +**/ +EFI_STATUS +EFIAPI +DisableQuietBoot ( + VOID + ) +{ + EFI_STATUS Status; + EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl; + + Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Set console control to text mode. + // + return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText); +} + +/** + Internal display string worker function. + + @param GraphicsOutput Graphics output protocol interface. + @param UgaDraw UGA draw protocol interface. + @param Sto Simple text out protocol interface. + @param X X coordinate to start printing. + @param Y Y coordinate to start printing. + @param Foreground Foreground color. + @param Background Background color. + @param fmt Format string. + @param args Print arguments. + + @return Number of Characters printed. Zero means no any character + displayed successfully. + +**/ +UINTN +Print ( + IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput, + IN EFI_UGA_DRAW_PROTOCOL *UgaDraw, + IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto, + IN UINTN X, + IN UINTN Y, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background, + IN CHAR16 *fmt, + IN VA_LIST args + ) +{ + VOID *Buffer; + EFI_STATUS Status; + UINTN Index; + CHAR16 *UnicodeWeight; + UINT32 HorizontalResolution; + UINT32 VerticalResolution; + UINT32 ColorDepth; + UINT32 RefreshRate; + UINTN BufferLen; + UINTN LineBufferLen; + EFI_HII_FONT_PROTOCOL *HiiFont; + EFI_IMAGE_OUTPUT *Blt; + EFI_FONT_DISPLAY_INFO *FontInfo; + EFI_HII_ROW_INFO *RowInfoArray; + UINTN RowInfoArraySize; + UINTN PrintNum; + + // + // For now, allocate an arbitrarily long buffer + // + Buffer = AllocateZeroPool (0x10000); + if (Buffer == NULL) { + return 0; + } + + HorizontalResolution = 0; + VerticalResolution = 0; + Blt = NULL; + FontInfo = NULL; + PrintNum = 0; + + if (GraphicsOutput != NULL) { + HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution; + VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution; + } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate); + } else { + Status = EFI_UNSUPPORTED; + goto Error; + } + + ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0)); + + Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont); + if (EFI_ERROR (Status)) { + goto Error; + } + + PrintNum = UnicodeVSPrint (Buffer, 0x10000, fmt, args); + + UnicodeWeight = (CHAR16 *) Buffer; + + for (Index = 0; UnicodeWeight[Index] != 0; Index++) { + if (UnicodeWeight[Index] == CHAR_BACKSPACE || + UnicodeWeight[Index] == CHAR_LINEFEED || + UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) { + UnicodeWeight[Index] = 0; + } + } + + BufferLen = StrLen (Buffer); + + LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * EFI_GLYPH_HEIGHT; + if (EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) { + Status = EFI_INVALID_PARAMETER; + goto Error; + } + + Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT)); + if (Blt == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Error; + } + + Blt->Width = (UINT16) (HorizontalResolution); + Blt->Height = (UINT16) (VerticalResolution); + + FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO)); + if (FontInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Error; + } + if (Foreground != NULL) { + CopyMem (&FontInfo->ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + } else { + CopyMem ( + &FontInfo->ForegroundColor, + &mEfiColors[Sto->Mode->Attribute & 0x0f], + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } + if (Background != NULL) { + CopyMem (&FontInfo->BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + } else { + CopyMem ( + &FontInfo->BackgroundColor, + &mEfiColors[Sto->Mode->Attribute >> 4], + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } + + if (GraphicsOutput != NULL) { + Blt->Image.Screen = GraphicsOutput; + + Status = HiiFont->StringToImage ( + HiiFont, + EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN, + Buffer, + FontInfo, + &Blt, + X, + Y, + NULL, + NULL, + NULL + ); + + } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + ASSERT (UgaDraw!= NULL); + + Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + if (Blt->Image.Bitmap == NULL) { + SafeFreePool (Blt); + SafeFreePool (Buffer); + return EFI_OUT_OF_RESOURCES; + } + + RowInfoArray = NULL; + // + // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform, + // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw. + // + Status = HiiFont->StringToImage ( + HiiFont, + EFI_HII_IGNORE_IF_NO_GLYPH, + Buffer, + FontInfo, + &Blt, + X, + Y, + &RowInfoArray, + &RowInfoArraySize, + NULL + ); + + if (!EFI_ERROR (Status)) { + // + // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will + // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure. + // + ASSERT (RowInfoArraySize <= 1); + + Status = UgaDraw->Blt ( + UgaDraw, + (EFI_UGA_PIXEL *) Blt->Image.Bitmap, + EfiUgaBltBufferToVideo, + X, + Y, + X, + Y, + RowInfoArray[0].LineWidth, + RowInfoArray[0].LineHeight, + Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ); + } + + SafeFreePool (RowInfoArray); + SafeFreePool (Blt->Image.Bitmap); + } else { + Status = EFI_UNSUPPORTED; + } + +Error: + SafeFreePool (Blt); + SafeFreePool (FontInfo); + FreePool (Buffer); + + if (EFI_ERROR (Status)) { + return PrintNum; + } else { + return 0; + } +} + +/** + Print Unicode string to graphics screen at the given X,Y coordinates of the graphics screen. + see definition of Print to find rules for constructing Fmt. + + @param X Row to start printing at. + @param Y Column to start printing at. + @param ForeGround Foreground color. + @param BackGround background color. + @param Fmt Print format sting. See definition of Print. + @param ... Argumnet stream defined by Fmt string. + + @return Number of Characters printed. Zero means no any character + displayed successfully. + +**/ +UINTN +EFIAPI +PrintXY ( + IN UINTN X, + IN UINTN Y, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL + IN CHAR16 *Fmt, + ... + ) +{ + EFI_HANDLE Handle; + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_UGA_DRAW_PROTOCOL *UgaDraw; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto; + EFI_STATUS Status; + VA_LIST Args; + + VA_START (Args, Fmt); + + Handle = gST->ConsoleOutHandle; + + Status = gBS->HandleProtocol ( + Handle, + &gEfiGraphicsOutputProtocolGuid, + (VOID **) &GraphicsOutput + ); + + UgaDraw = NULL; + if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) { + // + // If no GOP available, try to open UGA Draw protocol if supported. + // + GraphicsOutput = NULL; + + Status = gBS->HandleProtocol ( + Handle, + &gEfiUgaDrawProtocolGuid, + (VOID **) &UgaDraw + ); + } + if (EFI_ERROR (Status)) { + return 0; + } + + Status = gBS->HandleProtocol ( + Handle, + &gEfiSimpleTextOutProtocolGuid, + (VOID **) &Sto + ); + + if (EFI_ERROR (Status)) { + return 0; + } + + return Print (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args); +} + diff --git a/MdePkg/Library/GraphicsLib/GraphicsLib.inf b/MdePkg/Library/GraphicsLib/GraphicsLib.inf new file mode 100644 index 0000000000..34d568daca --- /dev/null +++ b/MdePkg/Library/GraphicsLib/GraphicsLib.inf @@ -0,0 +1,63 @@ +#/** @file +# Library supports diplaying graphical splash screen, +# locking of keyboard input and printing character on +# screen. +# +# This library provides supports for basic graphic functions. +# Copyright (c) 2006 - 2007, Intel Corporation. +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiGraphicsLib + FILE_GUID = 08c1a0e4-1208-47f8-a2c5-f42eabee653a + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = GraphicsLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + Graphics.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + MemoryAllocationLib + BaseLib + PrintLib + DebugLib + DxePiLib + BaseMemoryLib + PcdLib + +[Protocols] + gEfiSimpleTextOutProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiGraphicsOutputProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiUgaDrawProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiConsoleControlProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiFirmwareVolume2ProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiOEMBadgingProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiHiiFontProtocolGuid # PROTOCOL ALWAYS_CONSUMED + +[FeaturePcd.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdUgaConsumeSupport diff --git a/MdePkg/Library/HiiLib/HiiLanguage.c b/MdePkg/Library/HiiLib/HiiLanguage.c deleted file mode 100644 index 147e5a3942..0000000000 --- a/MdePkg/Library/HiiLib/HiiLanguage.c +++ /dev/null @@ -1,206 +0,0 @@ -/** @file - Language related HII Library implementation. - - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. 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 "InternalHiiLib.h" - -/** - Get next language from language code list (with separator ';'). - - If LangCode is NULL, then ASSERT. - If Lang is NULL, then ASSERT. - - @param LangCode On input: point to first language in the list. On - output: point to next language in the list, or - NULL if no more language in the list. - @param Lang The first language in the list. - -**/ -VOID -EFIAPI -HiiLibGetNextLanguage ( - IN OUT CHAR8 **LangCode, - OUT CHAR8 *Lang - ) -{ - UINTN Index; - CHAR8 *StringPtr; - - ASSERT (LangCode != NULL); - ASSERT (*LangCode != NULL); - ASSERT (Lang != NULL); - - Index = 0; - StringPtr = *LangCode; - while (StringPtr[Index] != 0 && StringPtr[Index] != ';') { - Index++; - } - - CopyMem (Lang, StringPtr, Index); - Lang[Index] = 0; - - if (StringPtr[Index] == ';') { - Index++; - } - *LangCode = StringPtr + Index; -} - - -/** - This function returns the list of supported languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - - @param HiiHandle The HII package list handle. - - @retval !NULL The supported languages. - @retval NULL If Supported Languages can not be retrived. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedLanguages ( - IN EFI_HII_HANDLE HiiHandle - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; - - ASSERT (IsHiiHandleRegistered (HiiHandle)); - // - // Collect current supported Languages for given HII handle - // First try allocate 4K buffer to store the current supported languages. - // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); - } - - if (EFI_ERROR (Status)) { - LanguageString = NULL; - } - - return LanguageString; -} - - -/** - This function returns the number of supported languages on HiiHandle. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - - @return The number of supported languages. - -**/ -UINT16 -EFIAPI -HiiLibGetSupportedLanguageNumber ( - IN EFI_HII_HANDLE HiiHandle - ) -{ - CHAR8 *Languages; - CHAR8 *LanguageString; - UINT16 LangNumber; - CHAR8 Lang[RFC_3066_ENTRY_SIZE]; - - Languages = HiiLibGetSupportedLanguages (HiiHandle); - if (Languages == NULL) { - return 0; - } - - LangNumber = 0; - LanguageString = Languages; - while (*LanguageString != 0) { - HiiLibGetNextLanguage (&LanguageString, Lang); - LangNumber++; - } - FreePool (Languages); - - return LangNumber; -} - -/** - This function returns the list of supported 2nd languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - @param FirstLanguage Pointer to language name buffer. - - @return The supported languages. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedSecondaryLanguages ( - IN EFI_HII_HANDLE HiiHandle, - IN CONST CHAR8 *FirstLanguage - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; - - ASSERT (HiiHandle != NULL); - ASSERT (IsHiiHandleRegistered (HiiHandle)); - // - // Collect current supported 2nd Languages for given HII handle - // First try allocate 4K buffer to store the current supported 2nd languages. - // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); - } - - if (EFI_ERROR (Status)) { - LanguageString = NULL; - } - - return LanguageString; -} - - diff --git a/MdePkg/Library/HiiLib/HiiLib.c b/MdePkg/Library/HiiLib/HiiLib.c deleted file mode 100644 index 975a064a39..0000000000 --- a/MdePkg/Library/HiiLib/HiiLib.c +++ /dev/null @@ -1,698 +0,0 @@ -/** @file - HII Library implementation that uses DXE protocols and services. - - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. 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 "InternalHiiLib.h" - -CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt = NULL; -CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt = NULL; - -/** - This function locate Hii relative protocols for later usage. - - The constructor function caches the protocol pointer of HII Database Protocol - and Hii String Protocol. - - It will ASSERT() if either of the protocol can't be located. - - @param ImageHandle The firmware allocated handle for the EFI image. - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. - -**/ -EFI_STATUS -EFIAPI -HiiLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - - Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabaseProt); - ASSERT_EFI_ERROR (Status); - - Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &mHiiStringProt); - ASSERT_EFI_ERROR (Status); - - return EFI_SUCCESS; -} - - - -/** - This funciton build the package list based on the package number, - the GUID of the package list and the list of pointer which point to - package header that defined by UEFI VFR compiler and StringGather - tool. - - #pragma pack (push, 1) - typedef struct { - UINT32 BinaryLength; - EFI_HII_PACKAGE_HEADER PackageHeader; - } EDKII_AUTOGEN_PACKAGES_HEADER; - #pragma pack (pop) - - If there is not enough resource for the new package list, - the function will ASSERT. - - @param NumberOfPackages The number of packages be - @param GuidId The GUID for the package list to be generated. - @param Marker The variable argument list. Each entry represent a specific package header that is - generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value - that indicate the overall length of the package. - - @return The pointer to the package list header. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -InternalHiiLibPreparePackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN VA_LIST Marker - ) -{ - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - UINT8 *PackageListData; - UINT32 PackageListLength; - UINT32 PackageLength; - EFI_HII_PACKAGE_HEADER PackageHeader; - UINT8 *PackageArray; - UINTN Index; - VA_LIST MarkerBackup; - - PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - - MarkerBackup = Marker; - - // - // Count the lenth of the final package list. - // - for (Index = 0; Index < NumberOfPackages; Index++) { - CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32)); - // - // Do not count the BinaryLength field. - // - PackageListLength += (PackageLength - sizeof (UINT32)); - } - - // - // Include the lenght of EFI_HII_PACKAGE_END - // - PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER); - PackageListHeader = AllocateZeroPool (PackageListLength); - ASSERT (PackageListHeader != NULL); - - CopyGuid (&PackageListHeader->PackageListGuid, GuidId); - PackageListHeader->PackageLength = PackageListLength; - - PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER); - - Marker = MarkerBackup; - // - // Prepare the final package list. - // - for (Index = 0; Index < NumberOfPackages; Index++) { - PackageArray = (UINT8 *) VA_ARG (Marker, VOID *); - // - // CopyMem is used for UINT32 to cover the unaligned address access. - // - CopyMem (&PackageLength, PackageArray, sizeof (UINT32)); - PackageLength -= sizeof (UINT32); - PackageArray += sizeof (UINT32); - CopyMem (PackageListData, PackageArray, PackageLength); - PackageListData += PackageLength; - } - - // - // Append EFI_HII_PACKAGE_END - // - PackageHeader.Type = EFI_HII_PACKAGE_END; - PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER); - CopyMem (PackageListData, &PackageHeader, PackageHeader.Length); - - return PackageListHeader; -} - -/** - Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. - - If GuidId is NULL, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param NumberOfPackages Number of packages. - @param GuidId Package GUID. - @param ... Variable argument list for packages to be assembled. - - @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -EFIAPI -HiiLibPreparePackageList ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - ... - ) -{ - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - VA_LIST Marker; - - ASSERT (GuidId != NULL); - - VA_START (Marker, GuidId); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker); - VA_END (Marker); - - return PackageListHeader; -} - - -/** - This function allocates pool for an EFI_HII_PACKAGE_LIST structure - with additional space that is big enough to host all packages described by the variable - argument list of package pointers. The allocated structure is initialized using NumberOfPackages, - GuidId, and the variable length argument list of package pointers. - - Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The - Handle to the newly registered Package List is returned throught HiiHandle. - - If HiiHandle is NULL, then ASSERT. - - @param NumberOfPackages The number of HII packages to register. - @param GuidId Package List GUID ID. - @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. - This DriverHandle uniquely defines the device that the added packages are associated with. - @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package - List later. If the functions failed to add the package to the default HII database, this value will - be set to NULL. - @param ... The variable argument list describing all HII Package. - - @return EFI_SUCCESS If the packages are successfully added to the default HII database. - @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. - -**/ -EFI_STATUS -EFIAPI -HiiLibAddPackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN EFI_HANDLE DriverHandle, OPTIONAL - OUT EFI_HII_HANDLE *HiiHandle, - ... - ) -{ - VA_LIST Args; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - EFI_STATUS Status; - - ASSERT (HiiHandle != NULL); - - VA_START (Args, HiiHandle); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args); - - Status = mHiiDatabaseProt->NewPackageList (mHiiDatabaseProt, PackageListHeader, DriverHandle, HiiHandle); - if (HiiHandle != NULL) { - if (EFI_ERROR (Status)) { - *HiiHandle = NULL; - } - } - - FreePool (PackageListHeader); - VA_END (Args); - - return Status; -} - -/** - Removes a package list from the default HII database. - - If HiiHandle is NULL, then ASSERT. - If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. - - @param HiiHandle The handle that was previously registered to the data base that is requested for removal. - List later. - -**/ -VOID -EFIAPI -HiiLibRemovePackages ( - IN EFI_HII_HANDLE HiiHandle - ) -{ - EFI_STATUS Status; - ASSERT (IsHiiHandleRegistered (HiiHandle)); - - Status = mHiiDatabaseProt->RemovePackageList (mHiiDatabaseProt, HiiHandle); - ASSERT_EFI_ERROR (Status); -} - - -/** - Determines the handles that are currently active in the database. - It's the caller's responsibility to free handle buffer. - - If HandleBufferLength is NULL, then ASSERT. - If HiiHandleBuffer is NULL, then ASSERT. - - @param HandleBufferLength On input, a pointer to the length of the handle - buffer. On output, the length of the handle buffer - that is required for the handles found. - @param HiiHandleBuffer Pointer to an array of Hii Handles returned. - - @retval EFI_SUCCESS Get an array of Hii Handles successfully. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetHiiHandles ( - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HiiHandleBuffer - ) -{ - UINTN BufferLength; - EFI_STATUS Status; - - ASSERT (HandleBufferLength != NULL); - ASSERT (HiiHandleBuffer != NULL); - - BufferLength = 0; - - // - // Try to find the actual buffer size for HiiHandle Buffer. - // - Status = mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferLength, - *HiiHandleBuffer - ); - - if (Status == EFI_BUFFER_TOO_SMALL) { - *HiiHandleBuffer = AllocateZeroPool (BufferLength); - ASSERT (*HiiHandleBuffer != NULL); - Status = mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferLength, - *HiiHandleBuffer - ); - // - // we should not fail here. - // - ASSERT_EFI_ERROR (Status); - } - - *HandleBufferLength = BufferLength; - - return Status; -} - -/** - Extract Hii package list GUID for given HII handle. - - If HiiHandle could not be found in the default HII database, then ASSERT. - If Guid is NULL, then ASSERT. - - @param Handle Hii handle - @param Guid Package list GUID - - @retval EFI_SUCCESS Successfully extract GUID from Hii database. - -**/ -EFI_STATUS -EFIAPI -HiiLibExtractGuidFromHiiHandle ( - IN EFI_HII_HANDLE Handle, - OUT EFI_GUID *Guid - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - - ASSERT (Guid != NULL); - ASSERT (IsHiiHandleRegistered (Handle)); - - // - // Get HII PackageList - // - BufferSize = 0; - HiiPackageList = NULL; - - Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList); - ASSERT (Status != EFI_NOT_FOUND); - - if (Status == EFI_BUFFER_TOO_SMALL) { - HiiPackageList = AllocatePool (BufferSize); - ASSERT (HiiPackageList != NULL); - - Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList); - } - if (EFI_ERROR (Status)) { - FreePool (HiiPackageList); - return Status; - } - - // - // Extract GUID - // - CopyGuid (Guid, &HiiPackageList->PackageListGuid); - - FreePool (HiiPackageList); - - return EFI_SUCCESS; -} - -/** - Find HII Handle in the default HII database associated with given Device Path. - - If DevicePath is NULL, then ASSERT. - - @param DevicePath Device Path associated with the HII package list - handle. - - @retval Handle HII package list Handle associated with the Device - Path. - @retval NULL Hii Package list handle is not found. - -**/ -EFI_HII_HANDLE -EFIAPI -HiiLibDevicePathToHiiHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; - UINTN BufferSize; - UINTN HandleCount; - UINTN Index; - EFI_HANDLE *Handles; - EFI_HANDLE Handle; - UINTN Size; - EFI_HANDLE DriverHandle; - EFI_HII_HANDLE *HiiHandles; - EFI_HII_HANDLE HiiHandle; - - ASSERT (DevicePath != NULL); - - // - // Locate Device Path Protocol handle buffer - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiDevicePathProtocolGuid, - NULL, - &HandleCount, - &Handles - ); - if (EFI_ERROR (Status)) { - return NULL; - } - - // - // Search Driver Handle by Device Path - // - DriverHandle = NULL; - BufferSize = GetDevicePathSize (DevicePath); - for(Index = 0; Index < HandleCount; Index++) { - Handle = Handles[Index]; - gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath); - - // - // Check whether DevicePath match - // - Size = GetDevicePathSize (TmpDevicePath); - if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) { - DriverHandle = Handle; - break; - } - } - FreePool (Handles); - - if (DriverHandle == NULL) { - return NULL; - } - - // - // Retrieve all Hii Handles from HII database - // - BufferSize = 0x1000; - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - Status = mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (HiiHandles); - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - - Status = mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - } - - if (EFI_ERROR (Status)) { - FreePool (HiiHandles); - return NULL; - } - - // - // Search Hii Handle by Driver Handle - // - HiiHandle = NULL; - HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); - for (Index = 0; Index < HandleCount; Index++) { - Status = mHiiDatabaseProt->GetPackageListHandle ( - mHiiDatabaseProt, - HiiHandles[Index], - &Handle - ); - if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { - HiiHandle = HiiHandles[Index]; - break; - } - } - - FreePool (HiiHandles); - return HiiHandle; -} - -/** - Exports the contents of one or all package lists in the HII database into a buffer. - - If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, - then ASSERT. - If PackageListHeader is NULL, then ASSERT. - If PackageListSize is NULL, then ASSERT. - - @param Handle The HII Handle. - @param PackageListHeader A pointer to a buffer that will contain the results of - the export function. - @param PackageListSize On output, the length of the buffer that is required for the exported data. - - @retval EFI_SUCCESS Package exported. - - @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. - -**/ -EFI_STATUS -EFIAPI -HiiLibExportPackageLists ( - IN EFI_HII_HANDLE Handle, - OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, - OUT UINTN *PackageListSize - ) -{ - EFI_STATUS Status; - UINTN Size; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr; - - ASSERT (PackageListSize != NULL); - ASSERT (PackageListHeader != NULL); - - if (Handle != NULL) { - ASSERT (IsHiiHandleRegistered (Handle)); - } - - Size = 0; - PackageListHdr = NULL; - Status = mHiiDatabaseProt->ExportPackageLists ( - mHiiDatabaseProt, - Handle, - &Size, - PackageListHdr - ); - ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL); - - if (Status == EFI_BUFFER_TOO_SMALL) { - PackageListHdr = AllocateZeroPool (Size); - - if (PackageListHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } else { - Status = mHiiDatabaseProt->ExportPackageLists ( - mHiiDatabaseProt, - Handle, - &Size, - PackageListHdr - ); - } - } - - if (!EFI_ERROR (Status)) { - *PackageListHeader = PackageListHdr; - *PackageListSize = Size; - } else { - FreePool (PackageListHdr); - } - - return Status; -} - -/** - - This function returns a list of the package handles of the - specified type that are currently active in the HII database. The - pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package - handles to be listed. - - If HandleBufferLength is NULL, then ASSERT. - If HandleBuffer is NULL, the ASSERT. - If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is - NULL, then ASSERT. - If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not - NULL, then ASSERT. - - - @param PackageType Specifies the package type of the packages - to list or EFI_HII_PACKAGE_TYPE_ALL for - all packages to be listed. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID which must match - the Guid field of - EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it - must be NULL. - - @param HandleBufferLength On output, the length of the handle buffer - that is required for the handles found. - - @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. - The caller is responcible to free this pointer allocated. - - @retval EFI_SUCCESS The matching handles are outputed successfully. - HandleBufferLength is updated with the actual length. - @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. - @retval EFI_NOT_FOUND No matching handle could not be found in database. -**/ -EFI_STATUS -EFIAPI -HiiLibListPackageLists ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HandleBuffer - ) -{ - EFI_STATUS Status; - - ASSERT (HandleBufferLength != NULL); - ASSERT (HandleBuffer != NULL); - - *HandleBufferLength = 0; - *HandleBuffer = NULL; - - if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) { - ASSERT (PackageGuid != NULL); - } else { - ASSERT (PackageGuid == NULL); - } - - Status = mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { - // - // No packages is registered to UEFI HII Database, just return. - // - // - return Status; - } - - *HandleBuffer = AllocateZeroPool (*HandleBufferLength); - - if (*HandleBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - return mHiiDatabaseProt->ListPackageLists ( - mHiiDatabaseProt, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - -} -/** - This function check if the Hii Handle is a valid handle registered - in the HII database. - - @param HiiHandle The HII Handle. - - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. -**/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - - ASSERT (HiiHandle != NULL); - - HiiPackageList = NULL; - BufferSize = 0; - - Status = mHiiDatabaseProt->ExportPackageLists ( - mHiiDatabaseProt, - HiiHandle, - &BufferSize, - HiiPackageList - ); - - return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL); -} - diff --git a/MdePkg/Library/HiiLib/HiiLib.inf b/MdePkg/Library/HiiLib/HiiLib.inf deleted file mode 100644 index 422d67d1b3..0000000000 --- a/MdePkg/Library/HiiLib/HiiLib.inf +++ /dev/null @@ -1,59 +0,0 @@ -#/** @file -# Library instance for HII common routines. -# -# This library instance implements the common HII routines. -# Copyright (c) 2006, Intel Corporation -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = HiiLib - FILE_GUID = 3143687A-7C80-404e-B5FE-2D88980E1B1C - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = HiiLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - CONSTRUCTOR = HiiLibConstructor - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - HiiLib.c - HiiString.c - HiiLanguage.c - InternalHiiLib.h - -[Packages] - MdePkg/MdePkg.dec - -[LibraryClasses] - MemoryAllocationLib - BaseMemoryLib - BaseLib - DebugLib - UefiBootServicesTableLib - DevicePathLib - UefiLib - -[Protocols] - gEfiHiiDatabaseProtocolGuid # ALWAYS_CONSUMED - gEfiHiiStringProtocolGuid # ALWAYS_CONSUMED - gEfiDevicePathProtocolGuid - -[Depex] - gEfiHiiDatabaseProtocolGuid AND - gEfiHiiStringProtocolGuid - diff --git a/MdePkg/Library/HiiLib/HiiString.c b/MdePkg/Library/HiiLib/HiiString.c deleted file mode 100644 index 2f44fabfd3..0000000000 --- a/MdePkg/Library/HiiLib/HiiString.c +++ /dev/null @@ -1,600 +0,0 @@ -/** @file - HII Library implementation that uses DXE protocols and services. - - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. 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 "InternalHiiLib.h" - -/** - This function adds the string into String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If StringId is NULL, the ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId On return, contains the new strings id, which is - unique within PackageList. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibNewString ( - IN EFI_HII_HANDLE PackageList, - OUT EFI_STRING_ID *StringId, - IN CONST EFI_STRING String - ) -{ - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 Lang[RFC_3066_ENTRY_SIZE]; - - ASSERT (String != NULL); - ASSERT (StringId != NULL); - - Status = EFI_SUCCESS; - - Languages = HiiLibGetSupportedLanguages (PackageList); - - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); - - // - // For each language supported by the package, - // a string token is created. - // - Status = mHiiStringProt->NewString ( - mHiiStringProt, - PackageList, - StringId, - Lang, - NULL, - String, - NULL - ); - if (EFI_ERROR (Status)) { - break; - } - } - - FreePool (Languages); - - return Status; - -} - - -/** - This function update the specified string in String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId Ths String Id to be updated. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibSetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST EFI_STRING String - ) -{ - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 Lang[RFC_3066_ENTRY_SIZE]; - - ASSERT (IsHiiHandleRegistered (PackageList)); - - Status = EFI_SUCCESS; - - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); - - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); - - // - // For each language supported by the package, - // the string is updated. - // - Status = mHiiStringProt->SetString ( - mHiiStringProt, - PackageList, - StringId, - Lang, - String, - NULL - ); - if (EFI_ERROR (Status)) { - break; - } - } - - FreePool (Languages); - - return Status; -} - - -/** - Get the string given the StringId and String package Producer's Guid. The caller - is responsible to free the *String. - - If PackageList with the matching ProducerGuid is not found, then ASSERT. - If PackageList with the matching ProducerGuid is found but no String is - specified by StringId is found, then ASSERT. - - @param ProducerGuid The Guid of String package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromToken ( - IN EFI_GUID *ProducerGuid, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -{ - EFI_STATUS Status; - UINTN Index; - UINTN HandleBufferLen; - EFI_HII_HANDLE *HiiHandleBuffer; - EFI_GUID Guid; - - Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer); - if (EFI_ERROR(Status)) { - return Status; - } - for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) { - Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); - if (EFI_ERROR(Status)) { - return Status; - } - if (CompareGuid (&Guid, ProducerGuid)) { - break; - } - } - - if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) { - // - // If PackageList with the matching ProducerGuid is not found, then ASSERT. - // - ASSERT (FALSE); - Status = EFI_NOT_FOUND; - goto Out; - } - - Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String); - -Out: - if (HiiHandleBuffer != NULL) { - FreePool (HiiHandleBuffer); - } - return Status; -} - -/** - This function try to retrieve string from String package of current language. - If fails, it try to retrieve string from String package of first language it support. - - If StringSize is NULL, then ASSERT. - If String is NULL and *StringSize is not 0, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList The package list in the HII database to search for - the specified string. - @param StringId The string's id, which is unique within - PackageList. - @param String Points to the new null-terminated string. - @param StringSize On entry, points to the size of the buffer pointed - to by String, in bytes. On return, points to the - length of the string, in bytes. - - @retval EFI_SUCCESS The string was returned successfully. - @retval EFI_NOT_FOUND The string specified by StringId is not available. - @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small - to hold the string. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - OUT EFI_STRING String, - IN OUT UINTN *StringSize - ) -{ - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 Lang[RFC_3066_ENTRY_SIZE]; - CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE]; - - ASSERT (StringSize != NULL); - ASSERT (!(*StringSize != 0 && String == NULL)); - ASSERT (IsHiiHandleRegistered (PackageList)); - - GetCurrentLanguage (CurrentLang); - - Status = mHiiStringProt->GetString ( - mHiiStringProt, - CurrentLang, - PackageList, - StringId, - String, - StringSize, - NULL - ); - - if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); - - LangStrings = Languages; - HiiLibGetNextLanguage (&LangStrings, Lang); - FreePool (Languages); - - Status = mHiiStringProt->GetString ( - mHiiStringProt, - Lang, - PackageList, - StringId, - String, - StringSize, - NULL - ); - } - - return Status; -} - - -/** - Get string specified by StringId form the HiiHandle. The caller - is responsible to free the *String. - - If String is NULL, then ASSERT. - If HiiHandle could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param HiiHandle The HII handle of package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_NOT_FOUND String is not found. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromHandle ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -{ - EFI_STATUS Status; - UINTN StringSize; - - ASSERT (String != NULL); - - StringSize = HII_LIB_DEFAULT_STRING_SIZE; - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (*String); - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); - } - - return Status; -} - - - -// -// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes -// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code. -// The last 2 CHAR8 values are the ISO 639-1 code. -// -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] = -"\ -aaraa\ -abkab\ -afraf\ -amham\ -araar\ -asmas\ -aymay\ -azeaz\ -bakba\ -belbe\ -benbn\ -bihbh\ -bisbi\ -bodbo\ -brebr\ -bulbg\ -catca\ -cescs\ -corkw\ -cosco\ -cymcy\ -danda\ -deude\ -dzodz\ -ellel\ -engen\ -epoeo\ -estet\ -euseu\ -faofo\ -fasfa\ -fijfj\ -finfi\ -frafr\ -fryfy\ -gaiga\ -gdhgd\ -glggl\ -grngn\ -gujgu\ -hauha\ -hebhe\ -hinhi\ -hrvhr\ -hunhu\ -hyehy\ -ikuiu\ -ileie\ -inaia\ -indid\ -ipkik\ -islis\ -itait\ -jawjw\ -jpnja\ -kalkl\ -kankn\ -kasks\ -katka\ -kazkk\ -khmkm\ -kinrw\ -kirky\ -korko\ -kurku\ -laolo\ -latla\ -lavlv\ -linln\ -litlt\ -ltzlb\ -malml\ -marmr\ -mkdmk\ -mlgmg\ -mltmt\ -molmo\ -monmn\ -mrimi\ -msams\ -myamy\ -nauna\ -nepne\ -nldnl\ -norno\ -ocioc\ -ormom\ -panpa\ -polpl\ -porpt\ -pusps\ -quequ\ -rohrm\ -ronro\ -runrn\ -rusru\ -sagsg\ -sansa\ -sinsi\ -slksk\ -slvsl\ -smise\ -smosm\ -snasn\ -sndsd\ -somso\ -sotst\ -spaes\ -sqisq\ -srpsr\ -sswss\ -sunsu\ -swasw\ -swesv\ -tamta\ -tattt\ -telte\ -tgktg\ -tgltl\ -thath\ -tsnts\ -tuktk\ -twitw\ -uigug\ -ukruk\ -urdur\ -uzbuz\ -vievi\ -volvo\ -wolwo\ -xhoxh\ -yidyi\ -zhaza\ -zhozh\ -zulzu\ -"; - - -/** - Convert language code from RFC3066 to ISO639-2. - - @param LanguageRfc3066 RFC3066 language code. - @param LanguageIso639 ISO639-2 language code. - - @retval EFI_SUCCESS Language code converted. - @retval EFI_NOT_FOUND Language code not found. - -**/ -EFI_STATUS -EFIAPI -ConvertRfc3066LanguageToIso639Language ( - IN CHAR8 *LanguageRfc3066, - OUT CHAR8 *LanguageIso639 - ) -{ - UINTN Index; - - if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) { - CopyMem (LanguageIso639, LanguageRfc3066, 3); - return EFI_SUCCESS; - } - - for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) { - CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - - -/** - Convert language code from ISO639-2 to RFC3066. - - LanguageIso639 contain a single ISO639-2 code such as - "eng" or "fra". - - The LanguageRfc3066 must be a buffer large enough - for RFC_3066_ENTRY_SIZE characters. - - If LanguageIso639 is NULL, then ASSERT. - If LanguageRfc3066 is NULL, then ASSERT. - - @param LanguageIso639 ISO639-2 language code. - @param LanguageRfc3066 RFC3066 language code. - - @retval EFI_SUCCESS Language code converted. - @retval EFI_NOT_FOUND Language code not found. - -**/ -EFI_STATUS -EFIAPI -ConvertIso639LanguageToRfc3066Language ( - IN CONST CHAR8 *LanguageIso639, - OUT CHAR8 *LanguageRfc3066 - ) -{ - UINTN Index; - - for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) { - CopyMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - -/** - Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will - be converted to "engfra". - - @param SupportedLanguages The RFC3066 language list. - - @return The ISO639-2 language list. - -**/ -CHAR8 * -EFIAPI -Rfc3066ToIso639 ( - CHAR8 *SupportedLanguages - ) -{ - CHAR8 *Languages; - CHAR8 *ReturnValue; - CHAR8 *LangCodes; - CHAR8 LangRfc3066[RFC_3066_ENTRY_SIZE]; - CHAR8 LangIso639[ISO_639_2_ENTRY_SIZE]; - EFI_STATUS Status; - - ReturnValue = AllocateZeroPool (AsciiStrSize (SupportedLanguages)); - if (ReturnValue == NULL) { - return ReturnValue; - } - - Languages = ReturnValue; - LangCodes = SupportedLanguages; - while (*LangCodes != 0) { - HiiLibGetNextLanguage (&LangCodes, LangRfc3066); - - Status = ConvertRfc3066LanguageToIso639Language (LangRfc3066, LangIso639); - if (!EFI_ERROR (Status)) { - CopyMem (Languages, LangIso639, 3); - Languages = Languages + 3; - } - } - - return ReturnValue; -} - - diff --git a/MdePkg/Library/HiiLib/InternalHiiLib.h b/MdePkg/Library/HiiLib/InternalHiiLib.h deleted file mode 100644 index 18d168ec70..0000000000 --- a/MdePkg/Library/HiiLib/InternalHiiLib.h +++ /dev/null @@ -1,53 +0,0 @@ -/** @file - Internal include file for the HII Library instance. - - Copyright (c) 2007, Intel Corporation - All rights reserved. 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. - -**/ - -#ifndef __INTERNAL_HII_LIB_H__ -#define __INTERNAL_HII_LIB_H__ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define HII_LIB_DEFAULT_STRING_SIZE 0x200 - - -extern CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt; -extern CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt; - -/** - This function check if the Hii Handle is a valid handle registered - in the HII database. - - @param HiiHandle The HII Handle. - - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. -**/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ); - -#endif diff --git a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf b/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf deleted file mode 100644 index 8bf96caff9..0000000000 --- a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf +++ /dev/null @@ -1,55 +0,0 @@ -#/** @file -#Utility functions which helps in opcode creation, HII configuration string manipulations, -#pop up window creations, setup browser persistence data set and get. -# -# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved. -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = IfrSupportLib - FILE_GUID = bf38668e-e231-4baa-99e4-8c0e4c35dca6 - MODULE_TYPE = UEFI_DRIVER - VERSION_STRING = 1.0 - LIBRARY_CLASS = IfrSupportLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - UefiIfrForm.c - UefiIfrLibraryInternal.h - UefiIfrOpCodeCreation.c - - -[Packages] - MdePkg/MdePkg.dec - - -[LibraryClasses] - MemoryAllocationLib - DevicePathLib - BaseLib - UefiBootServicesTableLib - BaseMemoryLib - DebugLib - -[Protocols] - gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED - gEfiHiiConfigRoutingProtocolGuid - gEfiFormBrowser2ProtocolGuid diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c b/MdePkg/Library/IfrSupportLib/UefiIfrForm.c deleted file mode 100644 index ee981c93ff..0000000000 --- a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c +++ /dev/null @@ -1,943 +0,0 @@ -/** @file -Utility functions which helps in opcode creation, HII configuration string manipulations, -pop up window creations, setup browser persistence data set and get. - -Copyright (c) 2007- 2008, Intel Corporation -All rights reserved. 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 "UefiIfrLibraryInternal.h" - -STATIC CONST EFI_FORM_BROWSER2_PROTOCOL *mFormBrowser2 = NULL; -STATIC CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL; - -/** - This function locate FormBrowser2 protocols for later usage. - - @return Status the status to locate protocol. -**/ -EFI_STATUS -LocateFormBrowser2Protocols ( - VOID - ) -{ - EFI_STATUS Status; - // - // Locate protocols for later usage - // - if (mFormBrowser2 == NULL) { - Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mFormBrowser2); - if (EFI_ERROR (Status)) { - return Status; - } - } - - if (mHiiConfigRouting == NULL) { - Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting); - if (EFI_ERROR (Status)) { - return Status; - } - } - - return EFI_SUCCESS; -} - -// -// Fake -// -GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=0"; - -/** - Draw a dialog and return the selected key. - - @param NumberOfLines The number of lines for the dialog box - @param KeyValue The EFI_KEY value returned if HotKey is TRUE.. - @param Marker A series of (quantity == NumberOfLines - 1) text - strings which will be used to construct the dialog - box - - @retval EFI_SUCCESS Displayed dialog and received user interaction - @retval EFI_INVALID_PARAMETER One of the parameters was invalid. - @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. - -**/ -EFI_STATUS -EFIAPI -IfrLibCreatePopUp2 ( - IN UINTN NumberOfLines, - OUT EFI_INPUT_KEY *KeyValue, - IN VA_LIST Marker - ) -{ - UINTN Index; - UINTN Count; - UINTN Start; - UINTN Top; - CHAR16 *StringPtr; - UINTN LeftColumn; - UINTN RightColumn; - UINTN TopRow; - UINTN BottomRow; - UINTN DimensionsWidth; - UINTN DimensionsHeight; - EFI_INPUT_KEY Key; - UINTN LargestString; - CHAR16 *StackString; - EFI_STATUS Status; - UINTN StringLen; - CHAR16 *LineBuffer; - CHAR16 **StringArray; - EFI_EVENT TimerEvent; - EFI_EVENT WaitList[2]; - UINTN CurrentAttribute; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; - CHAR16 *String; - - String = VA_ARG (Marker, CHAR16 *); - - if ((KeyValue == NULL) || (String == NULL)) { - return EFI_INVALID_PARAMETER; - } - - TopRow = 0; - BottomRow = 0; - LeftColumn = 0; - RightColumn = 0; - - ConOut = gST->ConOut; - ConOut->QueryMode (ConOut, ConOut->Mode->Mode, &RightColumn, &BottomRow); - - DimensionsWidth = RightColumn - LeftColumn; - DimensionsHeight = BottomRow - TopRow; - - CurrentAttribute = ConOut->Mode->Attribute; - - LineBuffer = AllocateZeroPool (DimensionsWidth * sizeof (CHAR16)); - if (LineBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Determine the largest string in the dialog box - // Notice we are starting with 1 since String is the first string - // - StringArray = AllocateZeroPool (NumberOfLines * sizeof (CHAR16 *)); - if (StringArray == NULL) { - FreePool (LineBuffer); - return EFI_OUT_OF_RESOURCES; - } - LargestString = StrLen (String); - StringArray[0] = String; - - for (Index = 1; Index < NumberOfLines; Index++) { - StackString = VA_ARG (Marker, CHAR16 *); - - if (StackString == NULL) { - FreePool (LineBuffer); - FreePool (StringArray); - return EFI_INVALID_PARAMETER; - } - - StringArray[Index] = StackString; - StringLen = StrLen (StackString); - if (StringLen > LargestString) { - LargestString = StringLen; - } - } - - if ((LargestString + 2) > DimensionsWidth) { - LargestString = DimensionsWidth - 2; - } - - // - // Subtract the PopUp width from total Columns, allow for one space extra on - // each end plus a border. - // - Start = (DimensionsWidth - LargestString - 2) / 2 + LeftColumn + 1; - - Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + TopRow - 1; - - // - // Disable cursor - // - ConOut->EnableCursor (ConOut, FALSE); - ConOut->SetAttribute (ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE); - - StringPtr = &LineBuffer[0]; - *StringPtr++ = BOXDRAW_DOWN_RIGHT; - for (Index = 0; Index < LargestString; Index++) { - *StringPtr++ = BOXDRAW_HORIZONTAL; - } - *StringPtr++ = BOXDRAW_DOWN_LEFT; - *StringPtr = L'\0'; - - ConOut->SetCursorPosition (ConOut, Start, Top); - ConOut->OutputString (ConOut, LineBuffer); - - for (Index = 0; Index < NumberOfLines; Index++) { - StringPtr = &LineBuffer[0]; - *StringPtr++ = BOXDRAW_VERTICAL; - - for (Count = 0; Count < LargestString; Count++) { - StringPtr[Count] = L' '; - } - - StringLen = StrLen (StringArray[Index]); - if (StringLen > LargestString) { - StringLen = LargestString; - } - CopyMem ( - StringPtr + ((LargestString - StringLen) / 2), - StringArray[Index], - StringLen * sizeof (CHAR16) - ); - StringPtr += LargestString; - - *StringPtr++ = BOXDRAW_VERTICAL; - *StringPtr = L'\0'; - - ConOut->SetCursorPosition (ConOut, Start, Top + 1 + Index); - ConOut->OutputString (ConOut, LineBuffer); - } - - StringPtr = &LineBuffer[0]; - *StringPtr++ = BOXDRAW_UP_RIGHT; - for (Index = 0; Index < LargestString; Index++) { - *StringPtr++ = BOXDRAW_HORIZONTAL; - } - *StringPtr++ = BOXDRAW_UP_LEFT; - *StringPtr = L'\0'; - - ConOut->SetCursorPosition (ConOut, Start, Top + NumberOfLines + 1); - ConOut->OutputString (ConOut, LineBuffer); - - do { - Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent); - - // - // Set a timer event of 1 second expiration - // - gBS->SetTimer ( - TimerEvent, - TimerRelative, - 10000000 - ); - - // - // Wait for the keystroke event or the timer - // - WaitList[0] = gST->ConIn->WaitForKey; - WaitList[1] = TimerEvent; - Status = gBS->WaitForEvent (2, WaitList, &Index); - - // - // Check for the timer expiration - // - if (!EFI_ERROR (Status) && Index == 1) { - Status = EFI_TIMEOUT; - } - - gBS->CloseEvent (TimerEvent); - } while (Status == EFI_TIMEOUT); - - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY)); - - ConOut->SetAttribute (ConOut, CurrentAttribute); - ConOut->EnableCursor (ConOut, TRUE); - - FreePool (LineBuffer); - FreePool (StringArray); - - return Status; -} - - -/** - Draw a dialog and return the selected key. - - @param NumberOfLines The number of lines for the dialog box - @param KeyValue The EFI_KEY value returned if HotKey is TRUE.. - @param String Pointer to the first string in the list - @param ... A series of (quantity == NumberOfLines - 1) text - strings which will be used to construct the dialog - box - - @retval EFI_SUCCESS Displayed dialog and received user interaction - @retval EFI_INVALID_PARAMETER One of the parameters was invalid. - -**/ -EFI_STATUS -EFIAPI -IfrLibCreatePopUp ( - IN UINTN NumberOfLines, - OUT EFI_INPUT_KEY *KeyValue, - IN CHAR16 *String, - ... - ) -{ - EFI_STATUS Status; - VA_LIST Marker; - - VA_START (Marker, KeyValue); - - Status = IfrLibCreatePopUp2 (NumberOfLines, KeyValue, Marker); - - VA_END (Marker); - - return Status; -} - -/** - Swap bytes in the buffer. This is a internal function. - - @param Buffer Binary buffer. - @param BufferSize Size of the buffer in bytes. - - @return None. - -**/ -VOID -SwapBuffer ( - IN OUT UINT8 *Buffer, - IN UINTN BufferSize - ) -{ - UINTN Index; - UINT8 Temp; - UINTN SwapCount; - - SwapCount = BufferSize / 2; - for (Index = 0; Index < SwapCount; Index++) { - Temp = Buffer[Index]; - Buffer[Index] = Buffer[BufferSize - 1 - Index]; - Buffer[BufferSize - 1 - Index] = Temp; - } -} - -/** - Converts the unicode character of the string from uppercase to lowercase. - This is a internal function. - - @param Str String to be converted - -**/ -VOID -EFIAPI -ToLower ( - IN OUT CHAR16 *Str - ) -{ - CHAR16 *Ptr; - - for (Ptr = Str; *Ptr != L'\0'; Ptr++) { - if (*Ptr >= L'A' && *Ptr <= L'Z') { - *Ptr = (CHAR16) (*Ptr - L'A' + L'a'); - } - } -} - - -/** - Converts binary buffer to Unicode string in reversed byte order from BufToHexString(). - - @param Str String for output - @param Buffer Binary buffer. - @param BufferSize Size of the buffer in bytes. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. - -**/ -EFI_STATUS -EFIAPI -BufInReverseOrderToHexString ( - IN OUT CHAR16 *Str, - IN UINT8 *Buffer, - IN UINTN BufferSize - ) -{ - EFI_STATUS Status; - UINT8 *NewBuffer; - UINTN StrBufferLen; - - NewBuffer = AllocateCopyPool (BufferSize, Buffer); - if (NewBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - SwapBuffer (NewBuffer, BufferSize); - - StrBufferLen = BufferSize * sizeof (CHAR16) + 1; - Status = BufToHexString (Str, &StrBufferLen, NewBuffer, BufferSize); - - FreePool (NewBuffer); - // - // Convert the uppercase to lowercase since is defined in lowercase format. - // - ToLower (Str); - - return Status; -} - - -/** - Converts Hex String to binary buffer in reversed byte order from HexStringToBuf(). - - @param Buffer Pointer to buffer that receives the data. - @param BufferSize Length in bytes of the buffer to hold converted - data. If routine return with EFI_SUCCESS, - containing length of converted data. If routine - return with EFI_BUFFER_TOO_SMALL, containg length - of buffer desired. - @param Str String to be converted from. - - @retval EFI_SUCCESS The function completed successfully. - @retval RETURN_BUFFER_TOO_SMALL The input BufferSize is too small to hold the output. BufferSize - will be updated to the size required for the converstion. - -**/ -EFI_STATUS -EFIAPI -HexStringToBufInReverseOrder ( - IN OUT UINT8 *Buffer, - IN OUT UINTN *BufferSize, - IN CHAR16 *Str - ) -{ - EFI_STATUS Status; - UINTN ConvertedStrLen; - - ConvertedStrLen = 0; - Status = HexStringToBuf (Buffer, BufferSize, Str, &ConvertedStrLen); - if (!EFI_ERROR (Status)) { - SwapBuffer (Buffer, ConvertedStrLen); - } - - return Status; -} - -/** - Convert binary representation Config string (e.g. "0041004200430044") to the - original string (e.g. "ABCD"). Config string appears in (i.e. - "&NAME="), or Name/Value pair in (i.e. "label="). - - @param UnicodeString Original Unicode string. - @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string. - Includes tailing '\0' character. - On output: - If return EFI_SUCCESS, containing length of Unicode string buffer. - If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired. - @param ConfigString Binary representation of Unicode String, := (4)+ - - @retval EFI_SUCCESS Operation completes successfully. - @retval EFI_BUFFER_TOO_SMALL The string buffer is too small. - -**/ -EFI_STATUS -EFIAPI -ConfigStringToUnicode ( - IN OUT CHAR16 *UnicodeString, - IN OUT UINTN *StrBufferLen, - IN CHAR16 *ConfigString - ) -{ - UINTN Index; - UINTN Len; - UINTN BufferSize; - CHAR16 BackupChar; - - Len = StrLen (ConfigString) / 4; - BufferSize = (Len + 1) * sizeof (CHAR16); - - if (*StrBufferLen < BufferSize) { - *StrBufferLen = BufferSize; - return EFI_BUFFER_TOO_SMALL; - } - - *StrBufferLen = BufferSize; - - for (Index = 0; Index < Len; Index++) { - BackupChar = ConfigString[4]; - ConfigString[4] = L'\0'; - - HexStringToBuf ((UINT8 *) UnicodeString, &BufferSize, ConfigString, NULL); - - ConfigString[4] = BackupChar; - - ConfigString += 4; - UnicodeString += 1; - } - - // - // Add tailing '\0' character - // - *UnicodeString = L'\0'; - - return EFI_SUCCESS; -} - -/** - Convert Unicode string to binary representation Config string, e.g. - "ABCD" => "0041004200430044". Config string appears in (i.e. - "&NAME="), or Name/Value pair in (i.e. "label="). - - @param ConfigString Binary representation of Unicode String, := (4)+ - @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string. - Includes tailing '\0' character. - On output: - If return EFI_SUCCESS, containing length of Unicode string buffer. - If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired. - @param UnicodeString Original Unicode string. - - @retval EFI_SUCCESS Operation completes successfully. - @retval EFI_BUFFER_TOO_SMALL The string buffer is too small. - -**/ -EFI_STATUS -EFIAPI -UnicodeToConfigString ( - IN OUT CHAR16 *ConfigString, - IN OUT UINTN *StrBufferLen, - IN CHAR16 *UnicodeString - ) -{ - UINTN Index; - UINTN Len; - UINTN BufferSize; - CHAR16 *String; - - Len = StrLen (UnicodeString); - BufferSize = (Len * 4 + 1) * sizeof (CHAR16); - - if (*StrBufferLen < BufferSize) { - *StrBufferLen = BufferSize; - return EFI_BUFFER_TOO_SMALL; - } - - *StrBufferLen = BufferSize; - String = ConfigString; - - for (Index = 0; Index < Len; Index++) { - BufToHexString (ConfigString, &BufferSize, (UINT8 *) UnicodeString, 2); - - ConfigString += 4; - UnicodeString += 1; - } - - // - // Add tailing '\0' character - // - *ConfigString = L'\0'; - - // - // Convert the uppercase to lowercase since is defined in lowercase format. - // - ToLower (String); - return EFI_SUCCESS; -} - -/** - Construct using routing information GUID/NAME/PATH. - - @param ConfigHdr Pointer to the ConfigHdr string. - @param StrBufferLen On input: Length in bytes of buffer to hold the - ConfigHdr string. Includes tailing '\0' character. - On output: If return EFI_SUCCESS, containing - length of ConfigHdr string buffer. If return - EFI_BUFFER_TOO_SMALL, containg length of string - buffer desired. - @param Guid Routing information: GUID. - @param Name Routing information: NAME. - @param DriverHandle Driver handle which contains the routing - information: PATH. - - @retval EFI_SUCCESS Operation completes successfully. - @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small. - -**/ -EFI_STATUS -EFIAPI -ConstructConfigHdr ( - IN OUT CHAR16 *ConfigHdr, - IN OUT UINTN *StrBufferLen, - IN CONST EFI_GUID *Guid, - IN CHAR16 *Name, OPTIONAL - IN EFI_HANDLE *DriverHandle - ) -{ - EFI_STATUS Status; - UINTN NameStrLen; - UINTN DevicePathSize; - UINTN BufferSize; - CHAR16 *StrPtr; - EFI_DEVICE_PATH_PROTOCOL *DevicePath; - - if (Name == NULL) { - // - // There will be no "NAME" in for Name/Value storage - // - NameStrLen = 0; - } else { - // - // For buffer storage - // - NameStrLen = StrLen (Name); - } - - // - // Retrieve DevicePath Protocol associated with this HiiPackageList - // - Status = gBS->HandleProtocol ( - DriverHandle, - &gEfiDevicePathProtocolGuid, - (VOID **) &DevicePath - ); - if (EFI_ERROR (Status)) { - return Status; - } - - DevicePathSize = GetDevicePathSize (DevicePath); - - // - // GUID=32&NAME=NameStrLen&PATH=DevicePathStrLen - // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 | - // - BufferSize = (5 + 32 + 6 + NameStrLen * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16); - if (*StrBufferLen < BufferSize) { - *StrBufferLen = BufferSize; - return EFI_BUFFER_TOO_SMALL; - } - - *StrBufferLen = BufferSize; - - StrPtr = ConfigHdr; - - StrCpy (StrPtr, L"GUID="); - StrPtr += 5; - BufInReverseOrderToHexString (StrPtr, (UINT8 *) Guid, sizeof (EFI_GUID)); - StrPtr += 32; - - // - // Convert name string, e.g. name "ABCD" => "&NAME=0041004200430044" - // - StrCpy (StrPtr, L"&NAME="); - StrPtr += 6; - if (Name != NULL) { - BufferSize = (NameStrLen * 4 + 1) * sizeof (CHAR16); - UnicodeToConfigString (StrPtr, &BufferSize, Name); - StrPtr += (NameStrLen * 4); - } - - StrCpy (StrPtr, L"&PATH="); - StrPtr += 6; - BufInReverseOrderToHexString (StrPtr, (UINT8 *) DevicePath, DevicePathSize); - - return EFI_SUCCESS; -} - - -/** - Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string. - - @param String The string to be searched in. - @param Offset Offset in BlockName. - @param Width Width in BlockName. - - @retval TRUE Block name found. - @retval FALSE Block name not found. - -**/ -BOOLEAN -EFIAPI -FindBlockName ( - IN OUT CHAR16 *String, - IN UINTN Offset, - IN UINTN Width - ) -{ - EFI_STATUS Status; - UINTN Data; - UINTN BufferSize; - UINTN ConvertedStrLen; - - while ((String = StrStr (String, L"&OFFSET=")) != NULL) { - // - // Skip '&OFFSET=' - // - String = String + 8; - - Data = 0; - BufferSize = sizeof (UINTN); - Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen); - if (EFI_ERROR (Status)) { - return FALSE; - } - String = String + ConvertedStrLen; - - if (Data != Offset) { - continue; - } - - if (StrnCmp (String, L"&WIDTH=", 7) != 0) { - return FALSE; - } - String = String + 7; - - Data = 0; - BufferSize = sizeof (UINTN); - Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen); - if (EFI_ERROR (Status)) { - return FALSE; - } - if (Data == Width) { - return TRUE; - } - - String = String + ConvertedStrLen; - } - - return FALSE; -} - - -/** - This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser. - - @param VariableGuid An optional field to indicate the target variable - GUID name to use. - @param VariableName An optional field to indicate the target - human-readable variable name. - @param BufferSize On input: Length in bytes of buffer to hold - retrived data. On output: If return - EFI_BUFFER_TOO_SMALL, containg length of buffer - desired. - @param Buffer Buffer to hold retrived data. - - @retval EFI_SUCCESS Operation completes successfully. - @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small. - @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. - -**/ -EFI_STATUS -EFIAPI -GetBrowserData ( - IN CONST EFI_GUID *VariableGuid, OPTIONAL - IN CONST CHAR16 *VariableName, OPTIONAL - IN OUT UINTN *BufferSize, - IN OUT UINT8 *Buffer - ) -{ - EFI_STATUS Status; - CONST CHAR16 *ConfigHdr; - CHAR16 *ConfigResp; - CHAR16 *StringPtr; - UINTN HeaderLen; - UINTN BufferLen; - CHAR16 *Progress; - - // - // Locate protocols for use - // - Status = LocateFormBrowser2Protocols (); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Retrive formset storage data from Form Browser - // - ConfigHdr = mFakeConfigHdr; - HeaderLen = StrLen (ConfigHdr); - - // - // First try allocate 0x4000 buffer for the formet storage data. - // - BufferLen = 0x4000; - ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); - if (ConfigResp == NULL) { - BufferLen = 0; - } - - StringPtr = ConfigResp + HeaderLen; - *StringPtr = L'&'; - StringPtr++; - - Status = mFormBrowser2->BrowserCallback ( - mFormBrowser2, - &BufferLen, - StringPtr, - TRUE, - VariableGuid, - VariableName - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - if (ConfigResp != NULL) { - FreePool (ConfigResp); - } - - ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); - if (ConfigResp == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - StringPtr = ConfigResp + HeaderLen; - *StringPtr = L'&'; - StringPtr++; - - Status = mFormBrowser2->BrowserCallback ( - mFormBrowser2, - &BufferLen, - StringPtr, - TRUE, - VariableGuid, - VariableName - ); - } - if (EFI_ERROR (Status)) { - FreePool (ConfigResp); - return Status; - } - CopyMem (ConfigResp, ConfigHdr, HeaderLen * sizeof (UINT16)); - - // - // Convert to buffer data - // - Status = mHiiConfigRouting->ConfigToBlock ( - mHiiConfigRouting, - ConfigResp, - Buffer, - BufferSize, - &Progress - ); - FreePool (ConfigResp); - - return Status; -} - - -/** - This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser. - - @param VariableGuid An optional field to indicate the target variable - GUID name to use. - @param VariableName An optional field to indicate the target - human-readable variable name. - @param BufferSize Length in bytes of buffer to hold retrived data. - @param Buffer Buffer to hold retrived data. - @param RequestElement An optional field to specify which part of the - buffer data will be send back to Browser. If NULL, - the whole buffer of data will be committed to - Browser. ::= - &OFFSET=&WIDTH=* - - @retval EFI_SUCCESS Operation completes successfully. - @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. - @retval Other Updating Browser uncommitted data failed. - -**/ -EFI_STATUS -EFIAPI -SetBrowserData ( - IN CONST EFI_GUID *VariableGuid, OPTIONAL - IN CONST CHAR16 *VariableName, OPTIONAL - IN UINTN BufferSize, - IN CONST UINT8 *Buffer, - IN CONST CHAR16 *RequestElement OPTIONAL - ) -{ - EFI_STATUS Status; - CONST CHAR16 *ConfigHdr; - CHAR16 *ConfigResp; - CHAR16 *StringPtr; - UINTN HeaderLen; - UINTN BufferLen; - CHAR16 *Progress; - CHAR16 BlockName[33]; - CHAR16 *ConfigRequest; - CONST CHAR16 *Request; - - // - // Locate protocols for use - // - Status = LocateFormBrowser2Protocols (); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Prepare - // - ConfigHdr = mFakeConfigHdr; - HeaderLen = StrLen (ConfigHdr); - - if (RequestElement == NULL) { - // - // RequestElement not specified, use "&OFFSET=0&WIDTH=" as - // - BlockName[0] = L'\0'; - StrCpy (BlockName, L"&OFFSET=0&WIDTH="); - - // - // String lenghth of L"&OFFSET=0&WIDTH=" is 16 - // - StringPtr = BlockName + 16; - BufferLen = sizeof (BlockName) - (16 * sizeof (CHAR16)); - BufToHexString (StringPtr, &BufferLen, (UINT8 *) &BufferSize, sizeof (UINTN)); - - Request = BlockName; - } else { - Request = RequestElement; - } - - BufferLen = HeaderLen * sizeof (CHAR16) + StrSize (Request); - ConfigRequest = AllocateZeroPool (BufferLen); - if (ConfigRequest == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CopyMem (ConfigRequest, ConfigHdr, HeaderLen * sizeof (CHAR16)); - StringPtr = ConfigRequest + HeaderLen; - StrCpy (StringPtr, Request); - - // - // Convert buffer to - // - Status = mHiiConfigRouting->BlockToConfig ( - mHiiConfigRouting, - ConfigRequest, - Buffer, - BufferSize, - &ConfigResp, - &Progress - ); - if (EFI_ERROR (Status)) { - FreePool (ConfigRequest); - return Status; - } - - // - // Skip and '&' - // - StringPtr = ConfigResp + HeaderLen + 1; - - // - // Change uncommitted data in Browser - // - Status = mFormBrowser2->BrowserCallback ( - mFormBrowser2, - &BufferSize, - StringPtr, - FALSE, - NULL, - NULL - ); - FreePool (ConfigRequest); - return Status; -} diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h b/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h deleted file mode 100644 index d5fcb669f6..0000000000 --- a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h +++ /dev/null @@ -1,35 +0,0 @@ -/** @file -Utility functions which helps in opcode creation, HII configuration string manipulations, -pop up window creations, setup browser persistence data set and get. - -Copyright (c) 2007 - 2008, Intel Corporation -All rights reserved. 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. - - -**/ - -#ifndef _IFRLIBRARY_INTERNAL_H_ -#define _IFRLIBRARY_INTERNAL_H_ - - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - - -#endif - diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrOpCodeCreation.c b/MdePkg/Library/IfrSupportLib/UefiIfrOpCodeCreation.c deleted file mode 100644 index d79e254aae..0000000000 --- a/MdePkg/Library/IfrSupportLib/UefiIfrOpCodeCreation.c +++ /dev/null @@ -1,891 +0,0 @@ -/** @file - Library Routines to create IFR independent of string data - assume tokens already exist - Primarily to be used for exporting op-codes at a label in pre-defined forms. - - -Copyright (c) 2007, Intel Corporation -All rights reserved. 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 "UefiIfrLibraryInternal.h" - -/** - Check if the input question flags is a valid value. - The valid combination of question flags includes - EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY. - - @param Flags The question flags to check. - - @retval TRUE If the question flag is a valid combination. - @retval FALSE If the question flag is an invalid combination. - -**/ -BOOLEAN -IsValidQuestionFlags ( - IN UINT8 Flags - ) -{ - return (BOOLEAN) (((Flags & (~QUESTION_FLAGS)) != 0) ? FALSE : TRUE); -} - -/** - Check if the input value type is a valid type. - The valid value type is smaller or equal than EFI_IFR_TYPE_OTHER. - - @param Type The value type to check. - - @retval TRUE If the value type is valid. - @retval FALSE If the value type is invalid. - -**/ -BOOLEAN -IsValidValueType ( - IN UINT8 Type - ) -{ - return (BOOLEAN) ((Type <= EFI_IFR_TYPE_OTHER) ? TRUE : FALSE); -} - -/** - Check if the input numeric flags is a valid value. - - @param Flags The numeric flags to check. - - @retval TRUE If the numeric flags is valid. - @retval FALSE If the numeric flags is invalid. - -**/ -BOOLEAN -IsValidNumricFlags ( - IN UINT8 Flags - ) -{ - if ((Flags & ~(EFI_IFR_NUMERIC_SIZE | EFI_IFR_DISPLAY)) != 0) { - return FALSE; - } - - if ((Flags & EFI_IFR_DISPLAY) > EFI_IFR_DISPLAY_UINT_HEX) { - return FALSE; - } - - return TRUE; -} - -/** - Check if the checkbox flags is a valid value. - - @param Flags The checkbox flags to check. - - @retval TRUE If the checkbox flags is valid. - @retval FALSE If the checkbox flags is invalid. - -**/ -BOOLEAN -IsValidCheckboxFlags ( - IN UINT8 Flags - ) -{ - return (BOOLEAN) ((Flags <= EFI_IFR_CHECKBOX_DEFAULT_MFG) ? TRUE : FALSE); -} - -/** - Create EFI_IFR_END_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - -**/ -EFI_STATUS -EFIAPI -CreateEndOpCode ( - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_END End; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (Data->Offset + sizeof (EFI_IFR_END) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - End.Header.Length = sizeof (EFI_IFR_END); - End.Header.OpCode = EFI_IFR_END_OP; - End.Header.Scope = 0; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_END to cover the unaligned address access. - // - CopyMem (LocalBuffer, &End, sizeof (EFI_IFR_END)); - Data->Offset += sizeof (EFI_IFR_END); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_DEFAULT_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param Value Value for the default - @param Type Type for the default - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER The type is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateDefaultOpCode ( - IN EFI_IFR_TYPE_VALUE *Value, - IN UINT8 Type, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_DEFAULT Default; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if ((Value == NULL) || !IsValidValueType (Type)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_DEFAULT) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Default.Header.OpCode = EFI_IFR_DEFAULT_OP; - Default.Header.Length = sizeof (EFI_IFR_DEFAULT); - Default.Header.Scope = 0; - Default.Type = Type; - Default.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; - CopyMem (&Default.Value, Value, sizeof(EFI_IFR_TYPE_VALUE)); - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_DEFAULT to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Default, sizeof (EFI_IFR_DEFAULT)); - Data->Offset += sizeof (EFI_IFR_DEFAULT); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_ACTION_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param QuestionConfig String ID for configuration - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateActionOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN EFI_STRING_ID QuestionConfig, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_ACTION Action; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_ACTION) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Action.Header.OpCode = EFI_IFR_ACTION_OP; - Action.Header.Length = sizeof (EFI_IFR_ACTION); - Action.Header.Scope = 0; - Action.Question.QuestionId = QuestionId; - Action.Question.Header.Prompt = Prompt; - Action.Question.Header.Help = Help; - Action.Question.VarStoreId = INVALID_VARSTORE_ID; - Action.Question.Flags = QuestionFlags; - Action.QuestionConfig = QuestionConfig; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_ACTION to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Action, sizeof (EFI_IFR_ACTION)); - Data->Offset += sizeof (EFI_IFR_ACTION); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_SUBTITLE_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param Prompt String ID for Prompt - @param Help String ID for Help - @param Flags Subtitle opcode flags - @param Scope Subtitle Scope bit - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - -**/ -EFI_STATUS -EFIAPI -CreateSubTitleOpCode ( - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 Flags, - IN UINT8 Scope, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_SUBTITLE Subtitle; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (Data->Offset + sizeof (EFI_IFR_SUBTITLE) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP; - Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE); - Subtitle.Header.Scope = Scope; - Subtitle.Statement.Prompt = Prompt; - Subtitle.Statement.Help = Help; - Subtitle.Flags = Flags; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_SUBTITLE to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE)); - Data->Offset += sizeof (EFI_IFR_SUBTITLE); - - return EFI_SUCCESS; -} - - -/** - Create EFI_IFR_TEXT_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param Prompt String ID for Prompt - @param Help String ID for Help - @param TextTwo String ID for text two - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - -**/ -EFI_STATUS -EFIAPI -CreateTextOpCode ( - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN EFI_STRING_ID TextTwo, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_TEXT Text; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (Data->Offset + sizeof (EFI_IFR_TEXT) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Text.Header.OpCode = EFI_IFR_TEXT_OP; - Text.Header.Length = sizeof (EFI_IFR_TEXT); - Text.Header.Scope = 0; - Text.Statement.Prompt = Prompt; - Text.Statement.Help = Help; - Text.TextTwo = TextTwo; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_TEXT to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Text, sizeof (EFI_IFR_TEXT)); - Data->Offset += sizeof (EFI_IFR_TEXT); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_REF_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param FormId Destination Form ID - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param QuestionId Question ID - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateGotoOpCode ( - IN EFI_FORM_ID FormId, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN EFI_QUESTION_ID QuestionId, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_REF Goto; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_REF) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Goto.Header.OpCode = EFI_IFR_REF_OP; - Goto.Header.Length = sizeof (EFI_IFR_REF); - Goto.Header.Scope = 0; - Goto.Question.Header.Prompt = Prompt; - Goto.Question.Header.Help = Help; - Goto.Question.VarStoreId = INVALID_VARSTORE_ID; - Goto.Question.QuestionId = QuestionId; - Goto.Question.Flags = QuestionFlags; - Goto.FormId = FormId; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_REF to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Goto, sizeof (EFI_IFR_REF)); - Data->Offset += sizeof (EFI_IFR_REF); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_ONE_OF_OPTION_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param OptionCount The number of options. - @param OptionsList The list of Options. - @param Type The data type. - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If OptionCount is not zero but OptionsList is NULL. - -**/ -EFI_STATUS -EFIAPI -CreateOneOfOptionOpCode ( - IN UINTN OptionCount, - IN IFR_OPTION *OptionsList, - IN UINT8 Type, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - UINTN Index; - UINT8 *LocalBuffer; - EFI_IFR_ONE_OF_OPTION OneOfOption; - - ASSERT (Data != NULL && Data->Data != NULL); - - if ((OptionCount != 0) && (OptionsList == NULL)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - for (Index = 0; Index < OptionCount; Index++) { - OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP; - OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION); - OneOfOption.Header.Scope = 0; - - OneOfOption.Option = OptionsList[Index].StringToken; - OneOfOption.Value = OptionsList[Index].Value; - OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG)); - OneOfOption.Type = Type; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_ONF_OF_OPTION to cover the unaligned address access. - // - CopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION)); - Data->Offset += sizeof (EFI_IFR_ONE_OF_OPTION); - } - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_ONE_OF_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param VarStoreId Storage ID - @param VarOffset Offset in Storage - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param OneOfFlags Flags for oneof opcode - @param OptionsList List of options - @param OptionCount Number of options in option list - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateOneOfOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_VARSTORE_ID VarStoreId, - IN UINT16 VarOffset, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN UINT8 OneOfFlags, - IN IFR_OPTION *OptionsList, - IN UINTN OptionCount, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - UINTN Length; - EFI_IFR_ONE_OF OneOf; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidNumricFlags (OneOfFlags) || - !IsValidQuestionFlags (QuestionFlags) || - ((OptionCount != 0) && (OptionsList == NULL))) { - return EFI_INVALID_PARAMETER; - } - - Length = sizeof (EFI_IFR_ONE_OF) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); - if (Data->Offset + Length > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP; - OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF); - OneOf.Header.Scope = 1; - OneOf.Question.Header.Prompt = Prompt; - OneOf.Question.Header.Help = Help; - OneOf.Question.QuestionId = QuestionId; - OneOf.Question.VarStoreId = VarStoreId; - OneOf.Question.VarStoreInfo.VarOffset = VarOffset; - OneOf.Question.Flags = QuestionFlags; - OneOf.Flags = OneOfFlags; - ZeroMem ((VOID *) &OneOf.data, sizeof (MINMAXSTEP_DATA)); - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_ONF_OF to cover the unaligned address access. - // - CopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF)); - Data->Offset += sizeof (EFI_IFR_ONE_OF); - - CreateOneOfOptionOpCode (OptionCount, OptionsList, (UINT8) (OneOfFlags & EFI_IFR_NUMERIC_SIZE), Data); - - CreateEndOpCode (Data); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_ORDERED_LIST_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param VarStoreId Storage ID - @param VarOffset Offset in Storage - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param OrderedListFlags Flags for ordered list opcode - @param DataType Type for option value - @param MaxContainers Maximum count for options in this ordered list - @param OptionsList List of options - @param OptionCount Number of options in option list - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateOrderedListOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_VARSTORE_ID VarStoreId, - IN UINT16 VarOffset, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN UINT8 OrderedListFlags, - IN UINT8 DataType, - IN UINT8 MaxContainers, - IN IFR_OPTION *OptionsList, - IN UINTN OptionCount, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - UINTN Length; - EFI_IFR_ORDERED_LIST OrderedList; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags) || - ((OptionCount != 0) && (OptionsList == NULL))) { - return EFI_INVALID_PARAMETER; - } - - if ((OrderedListFlags != 0) && - (OrderedListFlags != EFI_IFR_UNIQUE_SET) && - (OrderedListFlags != EFI_IFR_NO_EMPTY_SET)) { - return EFI_INVALID_PARAMETER; - } - - Length = sizeof (EFI_IFR_ORDERED_LIST) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); - if (Data->Offset + Length > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP; - OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST); - OrderedList.Header.Scope = 1; - OrderedList.Question.Header.Prompt = Prompt; - OrderedList.Question.Header.Help = Help; - OrderedList.Question.QuestionId = QuestionId; - OrderedList.Question.VarStoreId = VarStoreId; - OrderedList.Question.VarStoreInfo.VarOffset = VarOffset; - OrderedList.Question.Flags = QuestionFlags; - OrderedList.MaxContainers = MaxContainers; - OrderedList.Flags = OrderedListFlags; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_ORDERED_LIST to cover the unaligned address access. - // - CopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST)); - Data->Offset += sizeof (EFI_IFR_ORDERED_LIST); - - CreateOneOfOptionOpCode (OptionCount, OptionsList, DataType, Data); - - CreateEndOpCode (Data); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_CHECKBOX_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param VarStoreId Storage ID - @param VarOffset Offset in Storage - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param CheckBoxFlags Flags for checkbox opcode - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateCheckBoxOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_VARSTORE_ID VarStoreId, - IN UINT16 VarOffset, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN UINT8 CheckBoxFlags, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_CHECKBOX CheckBox; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags) || !IsValidCheckboxFlags (CheckBoxFlags)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_CHECKBOX) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP; - CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX); - CheckBox.Header.Scope = 0; - CheckBox.Question.QuestionId = QuestionId; - CheckBox.Question.VarStoreId = VarStoreId; - CheckBox.Question.VarStoreInfo.VarOffset = VarOffset; - CheckBox.Question.Header.Prompt = Prompt; - CheckBox.Question.Header.Help = Help; - CheckBox.Question.Flags = QuestionFlags; - CheckBox.Flags = CheckBoxFlags; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_CHECKBOX to cover the unaligned address access. - // - CopyMem (LocalBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX)); - Data->Offset += sizeof (EFI_IFR_CHECKBOX); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_NUMERIC_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param VarStoreId Storage ID - @param VarOffset Offset in Storage - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param NumericFlags Flags for numeric opcode - @param Minimum Numeric minimum value - @param Maximum Numeric maximum value - @param Step Numeric step for edit - @param Default Numeric default value - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateNumericOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_VARSTORE_ID VarStoreId, - IN UINT16 VarOffset, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN UINT8 NumericFlags, - IN UINT64 Minimum, - IN UINT64 Maximum, - IN UINT64 Step, - IN UINT64 Default, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_STATUS Status; - EFI_IFR_NUMERIC Numeric; - MINMAXSTEP_DATA MinMaxStep; - EFI_IFR_TYPE_VALUE DefaultValue; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags) || !IsValidNumricFlags (NumericFlags)) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_CHECKBOX) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP; - Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC); - Numeric.Header.Scope = 1; - Numeric.Question.QuestionId = QuestionId; - Numeric.Question.VarStoreId = VarStoreId; - Numeric.Question.VarStoreInfo.VarOffset = VarOffset; - Numeric.Question.Header.Prompt = Prompt; - Numeric.Question.Header.Help = Help; - Numeric.Question.Flags = QuestionFlags; - Numeric.Flags = NumericFlags; - - switch (NumericFlags & EFI_IFR_NUMERIC_SIZE) { - case EFI_IFR_NUMERIC_SIZE_1: - MinMaxStep.u8.MinValue = (UINT8) Minimum; - MinMaxStep.u8.MaxValue = (UINT8) Maximum; - MinMaxStep.u8.Step = (UINT8) Step; - break; - - case EFI_IFR_NUMERIC_SIZE_2: - MinMaxStep.u16.MinValue = (UINT16) Minimum; - MinMaxStep.u16.MaxValue = (UINT16) Maximum; - MinMaxStep.u16.Step = (UINT16) Step; - break; - - case EFI_IFR_NUMERIC_SIZE_4: - MinMaxStep.u32.MinValue = (UINT32) Minimum; - MinMaxStep.u32.MaxValue = (UINT32) Maximum; - MinMaxStep.u32.Step = (UINT32) Step; - break; - - case EFI_IFR_NUMERIC_SIZE_8: - MinMaxStep.u64.MinValue = Minimum; - MinMaxStep.u64.MaxValue = Maximum; - MinMaxStep.u64.Step = Step; - break; - } - - CopyMem (&Numeric.data, &MinMaxStep, sizeof (MINMAXSTEP_DATA)); - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_NUMERIC to cover the unaligned address access. - // - CopyMem (LocalBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC)); - Data->Offset += sizeof (EFI_IFR_NUMERIC); - - DefaultValue.u64 = Default; - Status = CreateDefaultOpCode (&DefaultValue, (UINT8) (NumericFlags & EFI_IFR_NUMERIC_SIZE), Data); - if (EFI_ERROR(Status)) { - return Status; - } - - CreateEndOpCode (Data); - - return EFI_SUCCESS; -} - -/** - Create EFI_IFR_STRING_OP opcode. - - If Data is NULL or Data->Data is NULL, then ASSERT. - - @param QuestionId Question ID - @param VarStoreId Storage ID - @param VarOffset Offset in Storage - @param Prompt String ID for Prompt - @param Help String ID for Help - @param QuestionFlags Flags in Question Header - @param StringFlags Flags for string opcode - @param MinSize String minimum length - @param MaxSize String maximum length - @param Data Destination for the created opcode binary - - @retval EFI_SUCCESS Opcode is created successfully. - @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. - @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. - -**/ -EFI_STATUS -EFIAPI -CreateStringOpCode ( - IN EFI_QUESTION_ID QuestionId, - IN EFI_VARSTORE_ID VarStoreId, - IN UINT16 VarOffset, - IN EFI_STRING_ID Prompt, - IN EFI_STRING_ID Help, - IN UINT8 QuestionFlags, - IN UINT8 StringFlags, - IN UINT8 MinSize, - IN UINT8 MaxSize, - IN OUT EFI_HII_UPDATE_DATA *Data - ) -{ - EFI_IFR_STRING String; - UINT8 *LocalBuffer; - - ASSERT (Data != NULL && Data->Data != NULL); - - if (!IsValidQuestionFlags (QuestionFlags) || (StringFlags & ~EFI_IFR_STRING_MULTI_LINE) != 0) { - return EFI_INVALID_PARAMETER; - } - - if (Data->Offset + sizeof (EFI_IFR_STRING) > Data->BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - String.Header.OpCode = EFI_IFR_STRING_OP; - String.Header.Length = sizeof (EFI_IFR_STRING); - String.Header.Scope = 0; - String.Question.Header.Prompt = Prompt; - String.Question.Header.Help = Help; - String.Question.QuestionId = QuestionId; - String.Question.VarStoreId = VarStoreId; - String.Question.VarStoreInfo.VarOffset = VarOffset; - String.Question.Flags = QuestionFlags; - String.MinSize = MinSize; - String.MaxSize = MaxSize; - String.Flags = StringFlags; - - LocalBuffer = (UINT8 *) Data->Data + Data->Offset; - // - // CopyMem is used for EFI_IFR_STRING to cover the unaligned address access. - // - CopyMem (LocalBuffer, &String, sizeof (EFI_IFR_STRING)); - Data->Offset += sizeof (EFI_IFR_STRING); - - return EFI_SUCCESS; -} - - diff --git a/MdePkg/Library/PeiPalCallLib/PalCallLib.c b/MdePkg/Library/PeiPalCallLib/PalCallLib.c deleted file mode 100644 index 07f9f38ad0..0000000000 --- a/MdePkg/Library/PeiPalCallLib/PalCallLib.c +++ /dev/null @@ -1,101 +0,0 @@ -/** @file - PAL Call Services Function. - - Copyright (c) 2006 - 2008 Intel Corporation. All rights reserved - This software and associated documentation (if any) is furnished - under a license and may only be used or copied in accordance - with the terms of the license. Except as permitted by such - license, no part of this software or documentation may be - reproduced, stored in a retrieval system, or transmitted in any - form or by any means without the express written consent of - Intel Corporation. - - Module Name: PalCallLib.c - -**/ - - -#include - -#include - -#include -#include -#include -#include -#include - -/** - Makes a PAL procedure call. - - This is a wrapper function to make a PAL procedure call. Based on the Index value, - this API will make static or stacked PAL call. Architected procedures may be designated - as required or optional. If a PAL procedure is specified as optional, a unique return - code of 0xFFFFFFFFFFFFFFFF is returned in the Status field of the PAL_CALL_RETURN structure. - This indicates that the procedure is not present in this PAL implementation. It is the - caller's responsibility to check for this return code after calling any optional PAL - procedure. No parameter checking is performed on the 4 input parameters, but there are - some common rules that the caller should follow when making a PAL call. Any address - passed to PAL as buffers for return parameters must be 8-byte aligned. Unaligned addresses - may cause undefined results. For those parameters defined as reserved or some fields - defined as reserved must be zero filled or the invalid argument return value may be - returned or undefined result may occur during the execution of the procedure. - This function is only available on IPF. - - @param Index The PAL procedure Index number. - @param Arg2 The 2nd parameter for PAL procedure calls. - @param Arg3 The 3rd parameter for PAL procedure calls. - @param Arg4 The 4th parameter for PAL procedure calls. - - @return Structure returned from the PAL Call procedure, including the status and return value. - -**/ -PAL_CALL_RETURN -EFIAPI -PalCall ( - IN UINT64 Index, - IN UINT64 Arg2, - IN UINT64 Arg3, - IN UINT64 Arg4 - ) -{ - UINT64 PalCallAddress; - PAL_CALL_RETURN ReturnVal; - CONST EFI_PEI_SERVICES **PeiServices; - EFI_STATUS Status; - EFI_SEC_PLATFORM_INFORMATION_PPI *SecPlatformPpi; - IPF_HANDOFF_STATUS IpfStatus; - UINT64 RecordSize; - - // - // Get PEI Service Table Pointer - // - PeiServices = GetPeiServicesTablePointer (); - - // - // Locate SEC Platform Information PPI - // - Status = PeiServicesLocatePpi ( - &gEfiSecPlatformInformationPpiGuid, - 0, - NULL, - (VOID **)&SecPlatformPpi - ); - ASSERT_EFI_ERROR (Status); - - // - // Retrieve PAL call address from platform information reported by the PPI - // - RecordSize = sizeof (IpfStatus); - SecPlatformPpi->PlatformInformation ( - PeiServices, - &RecordSize, - (EFI_SEC_PLATFORM_INFORMATION_RECORD *) &IpfStatus - ); - PalCallAddress = IpfStatus.PalCallAddress; - - ReturnVal = AsmPalCall (PalCallAddress, Index, Arg2, Arg3, Arg4); - - return ReturnVal; -} - diff --git a/MdePkg/Library/PeiPalCallLib/PeiPalCallLib.inf b/MdePkg/Library/PeiPalCallLib/PeiPalCallLib.inf deleted file mode 100644 index b3632564dd..0000000000 --- a/MdePkg/Library/PeiPalCallLib/PeiPalCallLib.inf +++ /dev/null @@ -1,52 +0,0 @@ -#/** @file -# Component description file for Pei PAL call Library -# -# PAL Call Library implementation to wrap the PAL call in PEI. -# Copyright (c) 2006, Intel Corporation -# -# All rights reserved. -# This software and associated documentation (if any) is furnished -# under a license and may only be used or copied in accordance -# with the terms of the license. Except as permitted by such -# license, no part of this software or documentation may be -# reproduced, stored in a retrieval system, or transmitted in any -# form or by any means without the express written consent of -# Intel Corporation. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = PeiPalCallLib - FILE_GUID = B53DC524-6B98-4584-940B-8F1363DEF09E - MODULE_TYPE = PEIM - VERSION_STRING = 1.0 - LIBRARY_CLASS = PalCallLib|PEI_CORE PEIM SEC - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IPF -# - -[Sources.common] - PalCallLib.c - - -[Packages] - MdePkg/MdePkg.dec - - -[LibraryClasses] - BaseLib - PeiServicesLib - PeiServicesTablePointerLib - - -[Ppis] - gEfiSecPlatformInformationPpiGuid # PPI ALWAYS_CONSUMED - diff --git a/MdePkg/Library/PeiPalLib/PeiPalLib.c b/MdePkg/Library/PeiPalLib/PeiPalLib.c new file mode 100644 index 0000000000..07f9f38ad0 --- /dev/null +++ b/MdePkg/Library/PeiPalLib/PeiPalLib.c @@ -0,0 +1,101 @@ +/** @file + PAL Call Services Function. + + Copyright (c) 2006 - 2008 Intel Corporation. All rights reserved + This software and associated documentation (if any) is furnished + under a license and may only be used or copied in accordance + with the terms of the license. Except as permitted by such + license, no part of this software or documentation may be + reproduced, stored in a retrieval system, or transmitted in any + form or by any means without the express written consent of + Intel Corporation. + + Module Name: PalCallLib.c + +**/ + + +#include + +#include + +#include +#include +#include +#include +#include + +/** + Makes a PAL procedure call. + + This is a wrapper function to make a PAL procedure call. Based on the Index value, + this API will make static or stacked PAL call. Architected procedures may be designated + as required or optional. If a PAL procedure is specified as optional, a unique return + code of 0xFFFFFFFFFFFFFFFF is returned in the Status field of the PAL_CALL_RETURN structure. + This indicates that the procedure is not present in this PAL implementation. It is the + caller's responsibility to check for this return code after calling any optional PAL + procedure. No parameter checking is performed on the 4 input parameters, but there are + some common rules that the caller should follow when making a PAL call. Any address + passed to PAL as buffers for return parameters must be 8-byte aligned. Unaligned addresses + may cause undefined results. For those parameters defined as reserved or some fields + defined as reserved must be zero filled or the invalid argument return value may be + returned or undefined result may occur during the execution of the procedure. + This function is only available on IPF. + + @param Index The PAL procedure Index number. + @param Arg2 The 2nd parameter for PAL procedure calls. + @param Arg3 The 3rd parameter for PAL procedure calls. + @param Arg4 The 4th parameter for PAL procedure calls. + + @return Structure returned from the PAL Call procedure, including the status and return value. + +**/ +PAL_CALL_RETURN +EFIAPI +PalCall ( + IN UINT64 Index, + IN UINT64 Arg2, + IN UINT64 Arg3, + IN UINT64 Arg4 + ) +{ + UINT64 PalCallAddress; + PAL_CALL_RETURN ReturnVal; + CONST EFI_PEI_SERVICES **PeiServices; + EFI_STATUS Status; + EFI_SEC_PLATFORM_INFORMATION_PPI *SecPlatformPpi; + IPF_HANDOFF_STATUS IpfStatus; + UINT64 RecordSize; + + // + // Get PEI Service Table Pointer + // + PeiServices = GetPeiServicesTablePointer (); + + // + // Locate SEC Platform Information PPI + // + Status = PeiServicesLocatePpi ( + &gEfiSecPlatformInformationPpiGuid, + 0, + NULL, + (VOID **)&SecPlatformPpi + ); + ASSERT_EFI_ERROR (Status); + + // + // Retrieve PAL call address from platform information reported by the PPI + // + RecordSize = sizeof (IpfStatus); + SecPlatformPpi->PlatformInformation ( + PeiServices, + &RecordSize, + (EFI_SEC_PLATFORM_INFORMATION_RECORD *) &IpfStatus + ); + PalCallAddress = IpfStatus.PalCallAddress; + + ReturnVal = AsmPalCall (PalCallAddress, Index, Arg2, Arg3, Arg4); + + return ReturnVal; +} + diff --git a/MdePkg/Library/PeiPalLib/PeiPalLib.inf b/MdePkg/Library/PeiPalLib/PeiPalLib.inf new file mode 100644 index 0000000000..08f164cbd4 --- /dev/null +++ b/MdePkg/Library/PeiPalLib/PeiPalLib.inf @@ -0,0 +1,52 @@ +#/** @file +# Component description file for Pei PAL call Library +# +# PAL Call Library implementation to wrap the PAL call in PEI. +# Copyright (c) 2006 - 2008, Intel Corporation +# +# All rights reserved. +# This software and associated documentation (if any) is furnished +# under a license and may only be used or copied in accordance +# with the terms of the license. Except as permitted by such +# license, no part of this software or documentation may be +# reproduced, stored in a retrieval system, or transmitted in any +# form or by any means without the express written consent of +# Intel Corporation. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PeiPalLib + FILE_GUID = B53DC524-6B98-4584-940B-8F1363DEF09E + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = PalCallLib|PEI_CORE PEIM SEC + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IPF +# + +[Sources.common] + PeiPalLib.c + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + BaseLib + PeiServicesLib + PeiServicesTablePointerLib + + +[Ppis] + gEfiSecPlatformInformationPpiGuid # PPI ALWAYS_CONSUMED + diff --git a/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.c b/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.c deleted file mode 100644 index ff1d14baba..0000000000 --- a/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.c +++ /dev/null @@ -1,111 +0,0 @@ -/** @file - Null Serial Port library instance with empty functions. - - Copyright (c) 2006 - 2008, Intel Corporation - All rights reserved. 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 - - -#include - -/** - Initialize the serial device hardware. - - If no initialization is required, then return RETURN_SUCCESS. - If the serial device was successfuly initialized, then return RETURN_SUCCESS. - If the serial device could not be initialized, then return RETURN_DEVICE_ERROR. - - @retval RETURN_SUCCESS The serial device was initialized. - @retval RETURN_DEVICE_ERROR The serail device could not be initialized. - -**/ -RETURN_STATUS -EFIAPI -SerialPortInitialize ( - VOID - ) -{ - return RETURN_UNSUPPORTED; -} - -/** - Write data from buffer to serial device. - - Writes NumberOfBytes data bytes from Buffer to the serial device. - The number of bytes actually written to the serial device is returned. - If the return value is less than NumberOfBytes, then the write operation failed. - - If Buffer is NULL, then ASSERT(). - - If NumberOfBytes is zero, then return 0. - - @param Buffer Pointer to the data buffer to be written. - @param NumberOfBytes Number of bytes to written to the serial device. - - @retval 0 NumberOfBytes is 0. - @retval >0 The number of bytes written to the serial device. - If this value is less than NumberOfBytes, then the read operation failed. - -**/ -UINTN -EFIAPI -SerialPortWrite ( - IN UINT8 *Buffer, - IN UINTN NumberOfBytes -) -{ - return 0; -} - - -/** - Reads data from a serial device into a buffer. - - @param Buffer Pointer to the data buffer to store the data read from the serial device. - @param NumberOfBytes Number of bytes to read from the serial device. - - @retval 0 NumberOfBytes is 0. - @retval >0 The number of bytes read from the serial device. - If this value is less than NumberOfBytes, then the read operation failed. - -**/ -UINTN -EFIAPI -SerialPortRead ( - OUT UINT8 *Buffer, - IN UINTN NumberOfBytes -) -{ - return 0; -} - -/** - Polls a serial device to see if there is any data waiting to be read. - - Polls aserial device to see if there is any data waiting to be read. - If there is data waiting to be read from the serial device, then TRUE is returned. - If there is no data waiting to be read from the serial device, then FALSE is returned. - - @retval TRUE Data is waiting to be read from the serial device. - @retval FALSE There is no data waiting to be read from the serial device. - -**/ -BOOLEAN -EFIAPI -SerialPortPoll ( - VOID - ) -{ - return FALSE; -} - diff --git a/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf b/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf deleted file mode 100644 index a6d436c8df..0000000000 --- a/MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf +++ /dev/null @@ -1,37 +0,0 @@ -#/** @file -# Null Serial Port library instance with empty functions -# -# Copyright (c) 2006 - 2008, Intel Corporation. -# -# All rights reserved. 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. -# -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = SerialPortLibNull - FILE_GUID = E4541241-8897-411a-91F8-7D7E45837146 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = SerialPortLib - EDK_RELEASE_VERSION = 0x00020000 - EFI_SPECIFICATION_VERSION = 0x00020000 - - -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources.common] - SerialPortLibNull.c - - -[Packages] - MdePkg/MdePkg.dec - diff --git a/MdePkg/Library/UefiHiiLib/HiiLanguage.c b/MdePkg/Library/UefiHiiLib/HiiLanguage.c new file mode 100644 index 0000000000..147e5a3942 --- /dev/null +++ b/MdePkg/Library/UefiHiiLib/HiiLanguage.c @@ -0,0 +1,206 @@ +/** @file + Language related HII Library implementation. + + Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. 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 "InternalHiiLib.h" + +/** + Get next language from language code list (with separator ';'). + + If LangCode is NULL, then ASSERT. + If Lang is NULL, then ASSERT. + + @param LangCode On input: point to first language in the list. On + output: point to next language in the list, or + NULL if no more language in the list. + @param Lang The first language in the list. + +**/ +VOID +EFIAPI +HiiLibGetNextLanguage ( + IN OUT CHAR8 **LangCode, + OUT CHAR8 *Lang + ) +{ + UINTN Index; + CHAR8 *StringPtr; + + ASSERT (LangCode != NULL); + ASSERT (*LangCode != NULL); + ASSERT (Lang != NULL); + + Index = 0; + StringPtr = *LangCode; + while (StringPtr[Index] != 0 && StringPtr[Index] != ';') { + Index++; + } + + CopyMem (Lang, StringPtr, Index); + Lang[Index] = 0; + + if (StringPtr[Index] == ';') { + Index++; + } + *LangCode = StringPtr + Index; +} + + +/** + This function returns the list of supported languages, in the format specified + in UEFI specification Appendix M. + + If HiiHandle is not a valid Handle in the default HII database, then ASSERT. + + @param HiiHandle The HII package list handle. + + @retval !NULL The supported languages. + @retval NULL If Supported Languages can not be retrived. + +**/ +CHAR8 * +EFIAPI +HiiLibGetSupportedLanguages ( + IN EFI_HII_HANDLE HiiHandle + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + CHAR8 *LanguageString; + + ASSERT (IsHiiHandleRegistered (HiiHandle)); + // + // Collect current supported Languages for given HII handle + // First try allocate 4K buffer to store the current supported languages. + // + BufferSize = 0x1000; + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); + + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (LanguageString); + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); + } + + if (EFI_ERROR (Status)) { + LanguageString = NULL; + } + + return LanguageString; +} + + +/** + This function returns the number of supported languages on HiiHandle. + + If HiiHandle is not a valid Handle in the default HII database, then ASSERT. + If not enough resource to complete the operation, then ASSERT. + + @param HiiHandle The HII package list handle. + + @return The number of supported languages. + +**/ +UINT16 +EFIAPI +HiiLibGetSupportedLanguageNumber ( + IN EFI_HII_HANDLE HiiHandle + ) +{ + CHAR8 *Languages; + CHAR8 *LanguageString; + UINT16 LangNumber; + CHAR8 Lang[RFC_3066_ENTRY_SIZE]; + + Languages = HiiLibGetSupportedLanguages (HiiHandle); + if (Languages == NULL) { + return 0; + } + + LangNumber = 0; + LanguageString = Languages; + while (*LanguageString != 0) { + HiiLibGetNextLanguage (&LanguageString, Lang); + LangNumber++; + } + FreePool (Languages); + + return LangNumber; +} + +/** + This function returns the list of supported 2nd languages, in the format specified + in UEFI specification Appendix M. + + If HiiHandle is not a valid Handle in the default HII database, then ASSERT. + If not enough resource to complete the operation, then ASSERT. + + @param HiiHandle The HII package list handle. + @param FirstLanguage Pointer to language name buffer. + + @return The supported languages. + +**/ +CHAR8 * +EFIAPI +HiiLibGetSupportedSecondaryLanguages ( + IN EFI_HII_HANDLE HiiHandle, + IN CONST CHAR8 *FirstLanguage + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + CHAR8 *LanguageString; + + ASSERT (HiiHandle != NULL); + ASSERT (IsHiiHandleRegistered (HiiHandle)); + // + // Collect current supported 2nd Languages for given HII handle + // First try allocate 4K buffer to store the current supported 2nd languages. + // + BufferSize = 0x1000; + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (LanguageString); + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + } + + if (EFI_ERROR (Status)) { + LanguageString = NULL; + } + + return LanguageString; +} + + diff --git a/MdePkg/Library/UefiHiiLib/HiiLib.c b/MdePkg/Library/UefiHiiLib/HiiLib.c new file mode 100644 index 0000000000..975a064a39 --- /dev/null +++ b/MdePkg/Library/UefiHiiLib/HiiLib.c @@ -0,0 +1,698 @@ +/** @file + HII Library implementation that uses DXE protocols and services. + + Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. 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 "InternalHiiLib.h" + +CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt = NULL; +CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt = NULL; + +/** + This function locate Hii relative protocols for later usage. + + The constructor function caches the protocol pointer of HII Database Protocol + and Hii String Protocol. + + It will ASSERT() if either of the protocol can't be located. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +HiiLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabaseProt); + ASSERT_EFI_ERROR (Status); + + Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &mHiiStringProt); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + + + +/** + This funciton build the package list based on the package number, + the GUID of the package list and the list of pointer which point to + package header that defined by UEFI VFR compiler and StringGather + tool. + + #pragma pack (push, 1) + typedef struct { + UINT32 BinaryLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + } EDKII_AUTOGEN_PACKAGES_HEADER; + #pragma pack (pop) + + If there is not enough resource for the new package list, + the function will ASSERT. + + @param NumberOfPackages The number of packages be + @param GuidId The GUID for the package list to be generated. + @param Marker The variable argument list. Each entry represent a specific package header that is + generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value + that indicate the overall length of the package. + + @return The pointer to the package list header. + +**/ +EFI_HII_PACKAGE_LIST_HEADER * +InternalHiiLibPreparePackages ( + IN UINTN NumberOfPackages, + IN CONST EFI_GUID *GuidId, + IN VA_LIST Marker + ) +{ + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + UINT8 *PackageListData; + UINT32 PackageListLength; + UINT32 PackageLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + UINT8 *PackageArray; + UINTN Index; + VA_LIST MarkerBackup; + + PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + + MarkerBackup = Marker; + + // + // Count the lenth of the final package list. + // + for (Index = 0; Index < NumberOfPackages; Index++) { + CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32)); + // + // Do not count the BinaryLength field. + // + PackageListLength += (PackageLength - sizeof (UINT32)); + } + + // + // Include the lenght of EFI_HII_PACKAGE_END + // + PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER); + PackageListHeader = AllocateZeroPool (PackageListLength); + ASSERT (PackageListHeader != NULL); + + CopyGuid (&PackageListHeader->PackageListGuid, GuidId); + PackageListHeader->PackageLength = PackageListLength; + + PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER); + + Marker = MarkerBackup; + // + // Prepare the final package list. + // + for (Index = 0; Index < NumberOfPackages; Index++) { + PackageArray = (UINT8 *) VA_ARG (Marker, VOID *); + // + // CopyMem is used for UINT32 to cover the unaligned address access. + // + CopyMem (&PackageLength, PackageArray, sizeof (UINT32)); + PackageLength -= sizeof (UINT32); + PackageArray += sizeof (UINT32); + CopyMem (PackageListData, PackageArray, PackageLength); + PackageListData += PackageLength; + } + + // + // Append EFI_HII_PACKAGE_END + // + PackageHeader.Type = EFI_HII_PACKAGE_END; + PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER); + CopyMem (PackageListData, &PackageHeader, PackageHeader.Length); + + return PackageListHeader; +} + +/** + Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. + + If GuidId is NULL, then ASSERT. + If not enough resource to complete the operation, then ASSERT. + + @param NumberOfPackages Number of packages. + @param GuidId Package GUID. + @param ... Variable argument list for packages to be assembled. + + @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. + +**/ +EFI_HII_PACKAGE_LIST_HEADER * +EFIAPI +HiiLibPreparePackageList ( + IN UINTN NumberOfPackages, + IN CONST EFI_GUID *GuidId, + ... + ) +{ + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + VA_LIST Marker; + + ASSERT (GuidId != NULL); + + VA_START (Marker, GuidId); + PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker); + VA_END (Marker); + + return PackageListHeader; +} + + +/** + This function allocates pool for an EFI_HII_PACKAGE_LIST structure + with additional space that is big enough to host all packages described by the variable + argument list of package pointers. The allocated structure is initialized using NumberOfPackages, + GuidId, and the variable length argument list of package pointers. + + Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The + Handle to the newly registered Package List is returned throught HiiHandle. + + If HiiHandle is NULL, then ASSERT. + + @param NumberOfPackages The number of HII packages to register. + @param GuidId Package List GUID ID. + @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. + This DriverHandle uniquely defines the device that the added packages are associated with. + @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package + List later. If the functions failed to add the package to the default HII database, this value will + be set to NULL. + @param ... The variable argument list describing all HII Package. + + @return EFI_SUCCESS If the packages are successfully added to the default HII database. + @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. + +**/ +EFI_STATUS +EFIAPI +HiiLibAddPackages ( + IN UINTN NumberOfPackages, + IN CONST EFI_GUID *GuidId, + IN EFI_HANDLE DriverHandle, OPTIONAL + OUT EFI_HII_HANDLE *HiiHandle, + ... + ) +{ + VA_LIST Args; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + EFI_STATUS Status; + + ASSERT (HiiHandle != NULL); + + VA_START (Args, HiiHandle); + PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args); + + Status = mHiiDatabaseProt->NewPackageList (mHiiDatabaseProt, PackageListHeader, DriverHandle, HiiHandle); + if (HiiHandle != NULL) { + if (EFI_ERROR (Status)) { + *HiiHandle = NULL; + } + } + + FreePool (PackageListHeader); + VA_END (Args); + + return Status; +} + +/** + Removes a package list from the default HII database. + + If HiiHandle is NULL, then ASSERT. + If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. + + @param HiiHandle The handle that was previously registered to the data base that is requested for removal. + List later. + +**/ +VOID +EFIAPI +HiiLibRemovePackages ( + IN EFI_HII_HANDLE HiiHandle + ) +{ + EFI_STATUS Status; + ASSERT (IsHiiHandleRegistered (HiiHandle)); + + Status = mHiiDatabaseProt->RemovePackageList (mHiiDatabaseProt, HiiHandle); + ASSERT_EFI_ERROR (Status); +} + + +/** + Determines the handles that are currently active in the database. + It's the caller's responsibility to free handle buffer. + + If HandleBufferLength is NULL, then ASSERT. + If HiiHandleBuffer is NULL, then ASSERT. + + @param HandleBufferLength On input, a pointer to the length of the handle + buffer. On output, the length of the handle buffer + that is required for the handles found. + @param HiiHandleBuffer Pointer to an array of Hii Handles returned. + + @retval EFI_SUCCESS Get an array of Hii Handles successfully. + +**/ +EFI_STATUS +EFIAPI +HiiLibGetHiiHandles ( + IN OUT UINTN *HandleBufferLength, + OUT EFI_HII_HANDLE **HiiHandleBuffer + ) +{ + UINTN BufferLength; + EFI_STATUS Status; + + ASSERT (HandleBufferLength != NULL); + ASSERT (HiiHandleBuffer != NULL); + + BufferLength = 0; + + // + // Try to find the actual buffer size for HiiHandle Buffer. + // + Status = mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferLength, + *HiiHandleBuffer + ); + + if (Status == EFI_BUFFER_TOO_SMALL) { + *HiiHandleBuffer = AllocateZeroPool (BufferLength); + ASSERT (*HiiHandleBuffer != NULL); + Status = mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferLength, + *HiiHandleBuffer + ); + // + // we should not fail here. + // + ASSERT_EFI_ERROR (Status); + } + + *HandleBufferLength = BufferLength; + + return Status; +} + +/** + Extract Hii package list GUID for given HII handle. + + If HiiHandle could not be found in the default HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + +**/ +EFI_STATUS +EFIAPI +HiiLibExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + + ASSERT (Guid != NULL); + ASSERT (IsHiiHandleRegistered (Handle)); + + // + // Get HII PackageList + // + BufferSize = 0; + HiiPackageList = NULL; + + Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList); + ASSERT (Status != EFI_NOT_FOUND); + + if (Status == EFI_BUFFER_TOO_SMALL) { + HiiPackageList = AllocatePool (BufferSize); + ASSERT (HiiPackageList != NULL); + + Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList); + } + if (EFI_ERROR (Status)) { + FreePool (HiiPackageList); + return Status; + } + + // + // Extract GUID + // + CopyGuid (Guid, &HiiPackageList->PackageListGuid); + + FreePool (HiiPackageList); + + return EFI_SUCCESS; +} + +/** + Find HII Handle in the default HII database associated with given Device Path. + + If DevicePath is NULL, then ASSERT. + + @param DevicePath Device Path associated with the HII package list + handle. + + @retval Handle HII package list Handle associated with the Device + Path. + @retval NULL Hii Package list handle is not found. + +**/ +EFI_HII_HANDLE +EFIAPI +HiiLibDevicePathToHiiHandle ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + UINTN BufferSize; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE *Handles; + EFI_HANDLE Handle; + UINTN Size; + EFI_HANDLE DriverHandle; + EFI_HII_HANDLE *HiiHandles; + EFI_HII_HANDLE HiiHandle; + + ASSERT (DevicePath != NULL); + + // + // Locate Device Path Protocol handle buffer + // + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiDevicePathProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + // + // Search Driver Handle by Device Path + // + DriverHandle = NULL; + BufferSize = GetDevicePathSize (DevicePath); + for(Index = 0; Index < HandleCount; Index++) { + Handle = Handles[Index]; + gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath); + + // + // Check whether DevicePath match + // + Size = GetDevicePathSize (TmpDevicePath); + if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) { + DriverHandle = Handle; + break; + } + } + FreePool (Handles); + + if (DriverHandle == NULL) { + return NULL; + } + + // + // Retrieve all Hii Handles from HII database + // + BufferSize = 0x1000; + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + Status = mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (HiiHandles); + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + + Status = mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + } + + if (EFI_ERROR (Status)) { + FreePool (HiiHandles); + return NULL; + } + + // + // Search Hii Handle by Driver Handle + // + HiiHandle = NULL; + HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); + for (Index = 0; Index < HandleCount; Index++) { + Status = mHiiDatabaseProt->GetPackageListHandle ( + mHiiDatabaseProt, + HiiHandles[Index], + &Handle + ); + if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { + HiiHandle = HiiHandles[Index]; + break; + } + } + + FreePool (HiiHandles); + return HiiHandle; +} + +/** + Exports the contents of one or all package lists in the HII database into a buffer. + + If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, + then ASSERT. + If PackageListHeader is NULL, then ASSERT. + If PackageListSize is NULL, then ASSERT. + + @param Handle The HII Handle. + @param PackageListHeader A pointer to a buffer that will contain the results of + the export function. + @param PackageListSize On output, the length of the buffer that is required for the exported data. + + @retval EFI_SUCCESS Package exported. + + @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. + +**/ +EFI_STATUS +EFIAPI +HiiLibExportPackageLists ( + IN EFI_HII_HANDLE Handle, + OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, + OUT UINTN *PackageListSize + ) +{ + EFI_STATUS Status; + UINTN Size; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr; + + ASSERT (PackageListSize != NULL); + ASSERT (PackageListHeader != NULL); + + if (Handle != NULL) { + ASSERT (IsHiiHandleRegistered (Handle)); + } + + Size = 0; + PackageListHdr = NULL; + Status = mHiiDatabaseProt->ExportPackageLists ( + mHiiDatabaseProt, + Handle, + &Size, + PackageListHdr + ); + ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL); + + if (Status == EFI_BUFFER_TOO_SMALL) { + PackageListHdr = AllocateZeroPool (Size); + + if (PackageListHeader == NULL) { + return EFI_OUT_OF_RESOURCES; + } else { + Status = mHiiDatabaseProt->ExportPackageLists ( + mHiiDatabaseProt, + Handle, + &Size, + PackageListHdr + ); + } + } + + if (!EFI_ERROR (Status)) { + *PackageListHeader = PackageListHdr; + *PackageListSize = Size; + } else { + FreePool (PackageListHdr); + } + + return Status; +} + +/** + + This function returns a list of the package handles of the + specified type that are currently active in the HII database. The + pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package + handles to be listed. + + If HandleBufferLength is NULL, then ASSERT. + If HandleBuffer is NULL, the ASSERT. + If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is + NULL, then ASSERT. + If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not + NULL, then ASSERT. + + + @param PackageType Specifies the package type of the packages + to list or EFI_HII_PACKAGE_TYPE_ALL for + all packages to be listed. + + @param PackageGuid If PackageType is + EFI_HII_PACKAGE_TYPE_GUID, then this is + the pointer to the GUID which must match + the Guid field of + EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it + must be NULL. + + @param HandleBufferLength On output, the length of the handle buffer + that is required for the handles found. + + @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. + The caller is responcible to free this pointer allocated. + + @retval EFI_SUCCESS The matching handles are outputed successfully. + HandleBufferLength is updated with the actual length. + @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. + @retval EFI_NOT_FOUND No matching handle could not be found in database. +**/ +EFI_STATUS +EFIAPI +HiiLibListPackageLists ( + IN UINT8 PackageType, + IN CONST EFI_GUID *PackageGuid, + IN OUT UINTN *HandleBufferLength, + OUT EFI_HII_HANDLE **HandleBuffer + ) +{ + EFI_STATUS Status; + + ASSERT (HandleBufferLength != NULL); + ASSERT (HandleBuffer != NULL); + + *HandleBufferLength = 0; + *HandleBuffer = NULL; + + if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) { + ASSERT (PackageGuid != NULL); + } else { + ASSERT (PackageGuid == NULL); + } + + Status = mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + PackageType, + PackageGuid, + HandleBufferLength, + *HandleBuffer + ); + if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { + // + // No packages is registered to UEFI HII Database, just return. + // + // + return Status; + } + + *HandleBuffer = AllocateZeroPool (*HandleBufferLength); + + if (*HandleBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return mHiiDatabaseProt->ListPackageLists ( + mHiiDatabaseProt, + PackageType, + PackageGuid, + HandleBufferLength, + *HandleBuffer + ); + +} +/** + This function check if the Hii Handle is a valid handle registered + in the HII database. + + @param HiiHandle The HII Handle. + + @retval TRUE If it is a valid HII handle. + @retval FALSE If it is a invalid HII handle. +**/ +BOOLEAN +IsHiiHandleRegistered ( + EFI_HII_HANDLE HiiHandle + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + + ASSERT (HiiHandle != NULL); + + HiiPackageList = NULL; + BufferSize = 0; + + Status = mHiiDatabaseProt->ExportPackageLists ( + mHiiDatabaseProt, + HiiHandle, + &BufferSize, + HiiPackageList + ); + + return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL); +} + diff --git a/MdePkg/Library/UefiHiiLib/HiiString.c b/MdePkg/Library/UefiHiiLib/HiiString.c new file mode 100644 index 0000000000..2f44fabfd3 --- /dev/null +++ b/MdePkg/Library/UefiHiiLib/HiiString.c @@ -0,0 +1,600 @@ +/** @file + HII Library implementation that uses DXE protocols and services. + + Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. 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 "InternalHiiLib.h" + +/** + This function adds the string into String Package of each language + supported by the package list. + + If String is NULL, then ASSERT. + If StringId is NULL, the ASSERT. + If PackageList could not be found in the default HII database, then ASSERT. + + @param PackageList Handle of the package list where this string will + be added. + @param StringId On return, contains the new strings id, which is + unique within PackageList. + @param String Points to the new null-terminated string. + + @retval EFI_SUCCESS The new string was added successfully. + @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. + +**/ +EFI_STATUS +EFIAPI +HiiLibNewString ( + IN EFI_HII_HANDLE PackageList, + OUT EFI_STRING_ID *StringId, + IN CONST EFI_STRING String + ) +{ + EFI_STATUS Status; + CHAR8 *Languages; + CHAR8 *LangStrings; + CHAR8 Lang[RFC_3066_ENTRY_SIZE]; + + ASSERT (String != NULL); + ASSERT (StringId != NULL); + + Status = EFI_SUCCESS; + + Languages = HiiLibGetSupportedLanguages (PackageList); + + LangStrings = Languages; + while (*LangStrings != 0) { + HiiLibGetNextLanguage (&LangStrings, Lang); + + // + // For each language supported by the package, + // a string token is created. + // + Status = mHiiStringProt->NewString ( + mHiiStringProt, + PackageList, + StringId, + Lang, + NULL, + String, + NULL + ); + if (EFI_ERROR (Status)) { + break; + } + } + + FreePool (Languages); + + return Status; + +} + + +/** + This function update the specified string in String Package of each language + supported by the package list. + + If String is NULL, then ASSERT. + If PackageList could not be found in the default HII database, then ASSERT. + If StringId is not found in PackageList, then ASSERT. + + @param PackageList Handle of the package list where this string will + be added. + @param StringId Ths String Id to be updated. + @param String Points to the new null-terminated string. + + @retval EFI_SUCCESS The new string was added successfully. + @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. + +**/ +EFI_STATUS +EFIAPI +HiiLibSetString ( + IN EFI_HII_HANDLE PackageList, + IN EFI_STRING_ID StringId, + IN CONST EFI_STRING String + ) +{ + EFI_STATUS Status; + CHAR8 *Languages; + CHAR8 *LangStrings; + CHAR8 Lang[RFC_3066_ENTRY_SIZE]; + + ASSERT (IsHiiHandleRegistered (PackageList)); + + Status = EFI_SUCCESS; + + Languages = HiiLibGetSupportedLanguages (PackageList); + ASSERT (Languages != NULL); + + LangStrings = Languages; + while (*LangStrings != 0) { + HiiLibGetNextLanguage (&LangStrings, Lang); + + // + // For each language supported by the package, + // the string is updated. + // + Status = mHiiStringProt->SetString ( + mHiiStringProt, + PackageList, + StringId, + Lang, + String, + NULL + ); + if (EFI_ERROR (Status)) { + break; + } + } + + FreePool (Languages); + + return Status; +} + + +/** + Get the string given the StringId and String package Producer's Guid. The caller + is responsible to free the *String. + + If PackageList with the matching ProducerGuid is not found, then ASSERT. + If PackageList with the matching ProducerGuid is found but no String is + specified by StringId is found, then ASSERT. + + @param ProducerGuid The Guid of String package list. + @param StringId The String ID. + @param String The output string. + + @retval EFI_SUCCESS Operation is successful. + @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + +**/ +EFI_STATUS +EFIAPI +HiiLibGetStringFromToken ( + IN EFI_GUID *ProducerGuid, + IN EFI_STRING_ID StringId, + OUT EFI_STRING *String + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN HandleBufferLen; + EFI_HII_HANDLE *HiiHandleBuffer; + EFI_GUID Guid; + + Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer); + if (EFI_ERROR(Status)) { + return Status; + } + for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) { + Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); + if (EFI_ERROR(Status)) { + return Status; + } + if (CompareGuid (&Guid, ProducerGuid)) { + break; + } + } + + if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) { + // + // If PackageList with the matching ProducerGuid is not found, then ASSERT. + // + ASSERT (FALSE); + Status = EFI_NOT_FOUND; + goto Out; + } + + Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String); + +Out: + if (HiiHandleBuffer != NULL) { + FreePool (HiiHandleBuffer); + } + return Status; +} + +/** + This function try to retrieve string from String package of current language. + If fails, it try to retrieve string from String package of first language it support. + + If StringSize is NULL, then ASSERT. + If String is NULL and *StringSize is not 0, then ASSERT. + If PackageList could not be found in the default HII database, then ASSERT. + If StringId is not found in PackageList, then ASSERT. + + @param PackageList The package list in the HII database to search for + the specified string. + @param StringId The string's id, which is unique within + PackageList. + @param String Points to the new null-terminated string. + @param StringSize On entry, points to the size of the buffer pointed + to by String, in bytes. On return, points to the + length of the string, in bytes. + + @retval EFI_SUCCESS The string was returned successfully. + @retval EFI_NOT_FOUND The string specified by StringId is not available. + @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small + to hold the string. + +**/ +EFI_STATUS +EFIAPI +HiiLibGetString ( + IN EFI_HII_HANDLE PackageList, + IN EFI_STRING_ID StringId, + OUT EFI_STRING String, + IN OUT UINTN *StringSize + ) +{ + EFI_STATUS Status; + CHAR8 *Languages; + CHAR8 *LangStrings; + CHAR8 Lang[RFC_3066_ENTRY_SIZE]; + CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE]; + + ASSERT (StringSize != NULL); + ASSERT (!(*StringSize != 0 && String == NULL)); + ASSERT (IsHiiHandleRegistered (PackageList)); + + GetCurrentLanguage (CurrentLang); + + Status = mHiiStringProt->GetString ( + mHiiStringProt, + CurrentLang, + PackageList, + StringId, + String, + StringSize, + NULL + ); + + if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { + Languages = HiiLibGetSupportedLanguages (PackageList); + ASSERT (Languages != NULL); + + LangStrings = Languages; + HiiLibGetNextLanguage (&LangStrings, Lang); + FreePool (Languages); + + Status = mHiiStringProt->GetString ( + mHiiStringProt, + Lang, + PackageList, + StringId, + String, + StringSize, + NULL + ); + } + + return Status; +} + + +/** + Get string specified by StringId form the HiiHandle. The caller + is responsible to free the *String. + + If String is NULL, then ASSERT. + If HiiHandle could not be found in the default HII database, then ASSERT. + If StringId is not found in PackageList, then ASSERT. + + @param HiiHandle The HII handle of package list. + @param StringId The String ID. + @param String The output string. + + @retval EFI_NOT_FOUND String is not found. + @retval EFI_SUCCESS Operation is successful. + @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + +**/ +EFI_STATUS +EFIAPI +HiiLibGetStringFromHandle ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + OUT EFI_STRING *String + ) +{ + EFI_STATUS Status; + UINTN StringSize; + + ASSERT (String != NULL); + + StringSize = HII_LIB_DEFAULT_STRING_SIZE; + *String = AllocateZeroPool (StringSize); + if (*String == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (*String); + *String = AllocateZeroPool (StringSize); + if (*String == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); + } + + return Status; +} + + + +// +// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes +// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code. +// The last 2 CHAR8 values are the ISO 639-1 code. +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] = +"\ +aaraa\ +abkab\ +afraf\ +amham\ +araar\ +asmas\ +aymay\ +azeaz\ +bakba\ +belbe\ +benbn\ +bihbh\ +bisbi\ +bodbo\ +brebr\ +bulbg\ +catca\ +cescs\ +corkw\ +cosco\ +cymcy\ +danda\ +deude\ +dzodz\ +ellel\ +engen\ +epoeo\ +estet\ +euseu\ +faofo\ +fasfa\ +fijfj\ +finfi\ +frafr\ +fryfy\ +gaiga\ +gdhgd\ +glggl\ +grngn\ +gujgu\ +hauha\ +hebhe\ +hinhi\ +hrvhr\ +hunhu\ +hyehy\ +ikuiu\ +ileie\ +inaia\ +indid\ +ipkik\ +islis\ +itait\ +jawjw\ +jpnja\ +kalkl\ +kankn\ +kasks\ +katka\ +kazkk\ +khmkm\ +kinrw\ +kirky\ +korko\ +kurku\ +laolo\ +latla\ +lavlv\ +linln\ +litlt\ +ltzlb\ +malml\ +marmr\ +mkdmk\ +mlgmg\ +mltmt\ +molmo\ +monmn\ +mrimi\ +msams\ +myamy\ +nauna\ +nepne\ +nldnl\ +norno\ +ocioc\ +ormom\ +panpa\ +polpl\ +porpt\ +pusps\ +quequ\ +rohrm\ +ronro\ +runrn\ +rusru\ +sagsg\ +sansa\ +sinsi\ +slksk\ +slvsl\ +smise\ +smosm\ +snasn\ +sndsd\ +somso\ +sotst\ +spaes\ +sqisq\ +srpsr\ +sswss\ +sunsu\ +swasw\ +swesv\ +tamta\ +tattt\ +telte\ +tgktg\ +tgltl\ +thath\ +tsnts\ +tuktk\ +twitw\ +uigug\ +ukruk\ +urdur\ +uzbuz\ +vievi\ +volvo\ +wolwo\ +xhoxh\ +yidyi\ +zhaza\ +zhozh\ +zulzu\ +"; + + +/** + Convert language code from RFC3066 to ISO639-2. + + @param LanguageRfc3066 RFC3066 language code. + @param LanguageIso639 ISO639-2 language code. + + @retval EFI_SUCCESS Language code converted. + @retval EFI_NOT_FOUND Language code not found. + +**/ +EFI_STATUS +EFIAPI +ConvertRfc3066LanguageToIso639Language ( + IN CHAR8 *LanguageRfc3066, + OUT CHAR8 *LanguageIso639 + ) +{ + UINTN Index; + + if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) { + CopyMem (LanguageIso639, LanguageRfc3066, 3); + return EFI_SUCCESS; + } + + for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { + if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) { + CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + + +/** + Convert language code from ISO639-2 to RFC3066. + + LanguageIso639 contain a single ISO639-2 code such as + "eng" or "fra". + + The LanguageRfc3066 must be a buffer large enough + for RFC_3066_ENTRY_SIZE characters. + + If LanguageIso639 is NULL, then ASSERT. + If LanguageRfc3066 is NULL, then ASSERT. + + @param LanguageIso639 ISO639-2 language code. + @param LanguageRfc3066 RFC3066 language code. + + @retval EFI_SUCCESS Language code converted. + @retval EFI_NOT_FOUND Language code not found. + +**/ +EFI_STATUS +EFIAPI +ConvertIso639LanguageToRfc3066Language ( + IN CONST CHAR8 *LanguageIso639, + OUT CHAR8 *LanguageRfc3066 + ) +{ + UINTN Index; + + for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { + if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) { + CopyMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will + be converted to "engfra". + + @param SupportedLanguages The RFC3066 language list. + + @return The ISO639-2 language list. + +**/ +CHAR8 * +EFIAPI +Rfc3066ToIso639 ( + CHAR8 *SupportedLanguages + ) +{ + CHAR8 *Languages; + CHAR8 *ReturnValue; + CHAR8 *LangCodes; + CHAR8 LangRfc3066[RFC_3066_ENTRY_SIZE]; + CHAR8 LangIso639[ISO_639_2_ENTRY_SIZE]; + EFI_STATUS Status; + + ReturnValue = AllocateZeroPool (AsciiStrSize (SupportedLanguages)); + if (ReturnValue == NULL) { + return ReturnValue; + } + + Languages = ReturnValue; + LangCodes = SupportedLanguages; + while (*LangCodes != 0) { + HiiLibGetNextLanguage (&LangCodes, LangRfc3066); + + Status = ConvertRfc3066LanguageToIso639Language (LangRfc3066, LangIso639); + if (!EFI_ERROR (Status)) { + CopyMem (Languages, LangIso639, 3); + Languages = Languages + 3; + } + } + + return ReturnValue; +} + + diff --git a/MdePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdePkg/Library/UefiHiiLib/InternalHiiLib.h new file mode 100644 index 0000000000..18d168ec70 --- /dev/null +++ b/MdePkg/Library/UefiHiiLib/InternalHiiLib.h @@ -0,0 +1,53 @@ +/** @file + Internal include file for the HII Library instance. + + Copyright (c) 2007, Intel Corporation + All rights reserved. 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. + +**/ + +#ifndef __INTERNAL_HII_LIB_H__ +#define __INTERNAL_HII_LIB_H__ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define HII_LIB_DEFAULT_STRING_SIZE 0x200 + + +extern CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt; +extern CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt; + +/** + This function check if the Hii Handle is a valid handle registered + in the HII database. + + @param HiiHandle The HII Handle. + + @retval TRUE If it is a valid HII handle. + @retval FALSE If it is a invalid HII handle. +**/ +BOOLEAN +IsHiiHandleRegistered ( + EFI_HII_HANDLE HiiHandle + ); + +#endif diff --git a/MdePkg/Library/UefiHiiLib/UefiHiiLib.inf b/MdePkg/Library/UefiHiiLib/UefiHiiLib.inf new file mode 100644 index 0000000000..b8f998bd50 --- /dev/null +++ b/MdePkg/Library/UefiHiiLib/UefiHiiLib.inf @@ -0,0 +1,59 @@ +#/** @file +# Library instance for HII common routines. +# +# This library instance implements the common HII routines. +# Copyright (c) 2006, Intel Corporation +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiHiiLib + FILE_GUID = 3143687A-7C80-404e-B5FE-2D88980E1B1C + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = HiiLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + CONSTRUCTOR = HiiLibConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + HiiLib.c + HiiString.c + HiiLanguage.c + InternalHiiLib.h + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + MemoryAllocationLib + BaseMemoryLib + BaseLib + DebugLib + UefiBootServicesTableLib + DevicePathLib + UefiLib + +[Protocols] + gEfiHiiDatabaseProtocolGuid # ALWAYS_CONSUMED + gEfiHiiStringProtocolGuid # ALWAYS_CONSUMED + gEfiDevicePathProtocolGuid + +[Depex] + gEfiHiiDatabaseProtocolGuid AND + gEfiHiiStringProtocolGuid + diff --git a/MdePkg/Library/UefiIfrSupportLib/UefiIfrForm.c b/MdePkg/Library/UefiIfrSupportLib/UefiIfrForm.c new file mode 100644 index 0000000000..ee981c93ff --- /dev/null +++ b/MdePkg/Library/UefiIfrSupportLib/UefiIfrForm.c @@ -0,0 +1,943 @@ +/** @file +Utility functions which helps in opcode creation, HII configuration string manipulations, +pop up window creations, setup browser persistence data set and get. + +Copyright (c) 2007- 2008, Intel Corporation +All rights reserved. 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 "UefiIfrLibraryInternal.h" + +STATIC CONST EFI_FORM_BROWSER2_PROTOCOL *mFormBrowser2 = NULL; +STATIC CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL; + +/** + This function locate FormBrowser2 protocols for later usage. + + @return Status the status to locate protocol. +**/ +EFI_STATUS +LocateFormBrowser2Protocols ( + VOID + ) +{ + EFI_STATUS Status; + // + // Locate protocols for later usage + // + if (mFormBrowser2 == NULL) { + Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mFormBrowser2); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (mHiiConfigRouting == NULL) { + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting); + if (EFI_ERROR (Status)) { + return Status; + } + } + + return EFI_SUCCESS; +} + +// +// Fake +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=0"; + +/** + Draw a dialog and return the selected key. + + @param NumberOfLines The number of lines for the dialog box + @param KeyValue The EFI_KEY value returned if HotKey is TRUE.. + @param Marker A series of (quantity == NumberOfLines - 1) text + strings which will be used to construct the dialog + box + + @retval EFI_SUCCESS Displayed dialog and received user interaction + @retval EFI_INVALID_PARAMETER One of the parameters was invalid. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. + +**/ +EFI_STATUS +EFIAPI +IfrLibCreatePopUp2 ( + IN UINTN NumberOfLines, + OUT EFI_INPUT_KEY *KeyValue, + IN VA_LIST Marker + ) +{ + UINTN Index; + UINTN Count; + UINTN Start; + UINTN Top; + CHAR16 *StringPtr; + UINTN LeftColumn; + UINTN RightColumn; + UINTN TopRow; + UINTN BottomRow; + UINTN DimensionsWidth; + UINTN DimensionsHeight; + EFI_INPUT_KEY Key; + UINTN LargestString; + CHAR16 *StackString; + EFI_STATUS Status; + UINTN StringLen; + CHAR16 *LineBuffer; + CHAR16 **StringArray; + EFI_EVENT TimerEvent; + EFI_EVENT WaitList[2]; + UINTN CurrentAttribute; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; + CHAR16 *String; + + String = VA_ARG (Marker, CHAR16 *); + + if ((KeyValue == NULL) || (String == NULL)) { + return EFI_INVALID_PARAMETER; + } + + TopRow = 0; + BottomRow = 0; + LeftColumn = 0; + RightColumn = 0; + + ConOut = gST->ConOut; + ConOut->QueryMode (ConOut, ConOut->Mode->Mode, &RightColumn, &BottomRow); + + DimensionsWidth = RightColumn - LeftColumn; + DimensionsHeight = BottomRow - TopRow; + + CurrentAttribute = ConOut->Mode->Attribute; + + LineBuffer = AllocateZeroPool (DimensionsWidth * sizeof (CHAR16)); + if (LineBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Determine the largest string in the dialog box + // Notice we are starting with 1 since String is the first string + // + StringArray = AllocateZeroPool (NumberOfLines * sizeof (CHAR16 *)); + if (StringArray == NULL) { + FreePool (LineBuffer); + return EFI_OUT_OF_RESOURCES; + } + LargestString = StrLen (String); + StringArray[0] = String; + + for (Index = 1; Index < NumberOfLines; Index++) { + StackString = VA_ARG (Marker, CHAR16 *); + + if (StackString == NULL) { + FreePool (LineBuffer); + FreePool (StringArray); + return EFI_INVALID_PARAMETER; + } + + StringArray[Index] = StackString; + StringLen = StrLen (StackString); + if (StringLen > LargestString) { + LargestString = StringLen; + } + } + + if ((LargestString + 2) > DimensionsWidth) { + LargestString = DimensionsWidth - 2; + } + + // + // Subtract the PopUp width from total Columns, allow for one space extra on + // each end plus a border. + // + Start = (DimensionsWidth - LargestString - 2) / 2 + LeftColumn + 1; + + Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + TopRow - 1; + + // + // Disable cursor + // + ConOut->EnableCursor (ConOut, FALSE); + ConOut->SetAttribute (ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE); + + StringPtr = &LineBuffer[0]; + *StringPtr++ = BOXDRAW_DOWN_RIGHT; + for (Index = 0; Index < LargestString; Index++) { + *StringPtr++ = BOXDRAW_HORIZONTAL; + } + *StringPtr++ = BOXDRAW_DOWN_LEFT; + *StringPtr = L'\0'; + + ConOut->SetCursorPosition (ConOut, Start, Top); + ConOut->OutputString (ConOut, LineBuffer); + + for (Index = 0; Index < NumberOfLines; Index++) { + StringPtr = &LineBuffer[0]; + *StringPtr++ = BOXDRAW_VERTICAL; + + for (Count = 0; Count < LargestString; Count++) { + StringPtr[Count] = L' '; + } + + StringLen = StrLen (StringArray[Index]); + if (StringLen > LargestString) { + StringLen = LargestString; + } + CopyMem ( + StringPtr + ((LargestString - StringLen) / 2), + StringArray[Index], + StringLen * sizeof (CHAR16) + ); + StringPtr += LargestString; + + *StringPtr++ = BOXDRAW_VERTICAL; + *StringPtr = L'\0'; + + ConOut->SetCursorPosition (ConOut, Start, Top + 1 + Index); + ConOut->OutputString (ConOut, LineBuffer); + } + + StringPtr = &LineBuffer[0]; + *StringPtr++ = BOXDRAW_UP_RIGHT; + for (Index = 0; Index < LargestString; Index++) { + *StringPtr++ = BOXDRAW_HORIZONTAL; + } + *StringPtr++ = BOXDRAW_UP_LEFT; + *StringPtr = L'\0'; + + ConOut->SetCursorPosition (ConOut, Start, Top + NumberOfLines + 1); + ConOut->OutputString (ConOut, LineBuffer); + + do { + Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent); + + // + // Set a timer event of 1 second expiration + // + gBS->SetTimer ( + TimerEvent, + TimerRelative, + 10000000 + ); + + // + // Wait for the keystroke event or the timer + // + WaitList[0] = gST->ConIn->WaitForKey; + WaitList[1] = TimerEvent; + Status = gBS->WaitForEvent (2, WaitList, &Index); + + // + // Check for the timer expiration + // + if (!EFI_ERROR (Status) && Index == 1) { + Status = EFI_TIMEOUT; + } + + gBS->CloseEvent (TimerEvent); + } while (Status == EFI_TIMEOUT); + + Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY)); + + ConOut->SetAttribute (ConOut, CurrentAttribute); + ConOut->EnableCursor (ConOut, TRUE); + + FreePool (LineBuffer); + FreePool (StringArray); + + return Status; +} + + +/** + Draw a dialog and return the selected key. + + @param NumberOfLines The number of lines for the dialog box + @param KeyValue The EFI_KEY value returned if HotKey is TRUE.. + @param String Pointer to the first string in the list + @param ... A series of (quantity == NumberOfLines - 1) text + strings which will be used to construct the dialog + box + + @retval EFI_SUCCESS Displayed dialog and received user interaction + @retval EFI_INVALID_PARAMETER One of the parameters was invalid. + +**/ +EFI_STATUS +EFIAPI +IfrLibCreatePopUp ( + IN UINTN NumberOfLines, + OUT EFI_INPUT_KEY *KeyValue, + IN CHAR16 *String, + ... + ) +{ + EFI_STATUS Status; + VA_LIST Marker; + + VA_START (Marker, KeyValue); + + Status = IfrLibCreatePopUp2 (NumberOfLines, KeyValue, Marker); + + VA_END (Marker); + + return Status; +} + +/** + Swap bytes in the buffer. This is a internal function. + + @param Buffer Binary buffer. + @param BufferSize Size of the buffer in bytes. + + @return None. + +**/ +VOID +SwapBuffer ( + IN OUT UINT8 *Buffer, + IN UINTN BufferSize + ) +{ + UINTN Index; + UINT8 Temp; + UINTN SwapCount; + + SwapCount = BufferSize / 2; + for (Index = 0; Index < SwapCount; Index++) { + Temp = Buffer[Index]; + Buffer[Index] = Buffer[BufferSize - 1 - Index]; + Buffer[BufferSize - 1 - Index] = Temp; + } +} + +/** + Converts the unicode character of the string from uppercase to lowercase. + This is a internal function. + + @param Str String to be converted + +**/ +VOID +EFIAPI +ToLower ( + IN OUT CHAR16 *Str + ) +{ + CHAR16 *Ptr; + + for (Ptr = Str; *Ptr != L'\0'; Ptr++) { + if (*Ptr >= L'A' && *Ptr <= L'Z') { + *Ptr = (CHAR16) (*Ptr - L'A' + L'a'); + } + } +} + + +/** + Converts binary buffer to Unicode string in reversed byte order from BufToHexString(). + + @param Str String for output + @param Buffer Binary buffer. + @param BufferSize Size of the buffer in bytes. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. + +**/ +EFI_STATUS +EFIAPI +BufInReverseOrderToHexString ( + IN OUT CHAR16 *Str, + IN UINT8 *Buffer, + IN UINTN BufferSize + ) +{ + EFI_STATUS Status; + UINT8 *NewBuffer; + UINTN StrBufferLen; + + NewBuffer = AllocateCopyPool (BufferSize, Buffer); + if (NewBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + SwapBuffer (NewBuffer, BufferSize); + + StrBufferLen = BufferSize * sizeof (CHAR16) + 1; + Status = BufToHexString (Str, &StrBufferLen, NewBuffer, BufferSize); + + FreePool (NewBuffer); + // + // Convert the uppercase to lowercase since is defined in lowercase format. + // + ToLower (Str); + + return Status; +} + + +/** + Converts Hex String to binary buffer in reversed byte order from HexStringToBuf(). + + @param Buffer Pointer to buffer that receives the data. + @param BufferSize Length in bytes of the buffer to hold converted + data. If routine return with EFI_SUCCESS, + containing length of converted data. If routine + return with EFI_BUFFER_TOO_SMALL, containg length + of buffer desired. + @param Str String to be converted from. + + @retval EFI_SUCCESS The function completed successfully. + @retval RETURN_BUFFER_TOO_SMALL The input BufferSize is too small to hold the output. BufferSize + will be updated to the size required for the converstion. + +**/ +EFI_STATUS +EFIAPI +HexStringToBufInReverseOrder ( + IN OUT UINT8 *Buffer, + IN OUT UINTN *BufferSize, + IN CHAR16 *Str + ) +{ + EFI_STATUS Status; + UINTN ConvertedStrLen; + + ConvertedStrLen = 0; + Status = HexStringToBuf (Buffer, BufferSize, Str, &ConvertedStrLen); + if (!EFI_ERROR (Status)) { + SwapBuffer (Buffer, ConvertedStrLen); + } + + return Status; +} + +/** + Convert binary representation Config string (e.g. "0041004200430044") to the + original string (e.g. "ABCD"). Config string appears in (i.e. + "&NAME="), or Name/Value pair in (i.e. "label="). + + @param UnicodeString Original Unicode string. + @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string. + Includes tailing '\0' character. + On output: + If return EFI_SUCCESS, containing length of Unicode string buffer. + If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired. + @param ConfigString Binary representation of Unicode String, := (4)+ + + @retval EFI_SUCCESS Operation completes successfully. + @retval EFI_BUFFER_TOO_SMALL The string buffer is too small. + +**/ +EFI_STATUS +EFIAPI +ConfigStringToUnicode ( + IN OUT CHAR16 *UnicodeString, + IN OUT UINTN *StrBufferLen, + IN CHAR16 *ConfigString + ) +{ + UINTN Index; + UINTN Len; + UINTN BufferSize; + CHAR16 BackupChar; + + Len = StrLen (ConfigString) / 4; + BufferSize = (Len + 1) * sizeof (CHAR16); + + if (*StrBufferLen < BufferSize) { + *StrBufferLen = BufferSize; + return EFI_BUFFER_TOO_SMALL; + } + + *StrBufferLen = BufferSize; + + for (Index = 0; Index < Len; Index++) { + BackupChar = ConfigString[4]; + ConfigString[4] = L'\0'; + + HexStringToBuf ((UINT8 *) UnicodeString, &BufferSize, ConfigString, NULL); + + ConfigString[4] = BackupChar; + + ConfigString += 4; + UnicodeString += 1; + } + + // + // Add tailing '\0' character + // + *UnicodeString = L'\0'; + + return EFI_SUCCESS; +} + +/** + Convert Unicode string to binary representation Config string, e.g. + "ABCD" => "0041004200430044". Config string appears in (i.e. + "&NAME="), or Name/Value pair in (i.e. "label="). + + @param ConfigString Binary representation of Unicode String, := (4)+ + @param StrBufferLen On input: Length in bytes of buffer to hold the Unicode string. + Includes tailing '\0' character. + On output: + If return EFI_SUCCESS, containing length of Unicode string buffer. + If return EFI_BUFFER_TOO_SMALL, containg length of string buffer desired. + @param UnicodeString Original Unicode string. + + @retval EFI_SUCCESS Operation completes successfully. + @retval EFI_BUFFER_TOO_SMALL The string buffer is too small. + +**/ +EFI_STATUS +EFIAPI +UnicodeToConfigString ( + IN OUT CHAR16 *ConfigString, + IN OUT UINTN *StrBufferLen, + IN CHAR16 *UnicodeString + ) +{ + UINTN Index; + UINTN Len; + UINTN BufferSize; + CHAR16 *String; + + Len = StrLen (UnicodeString); + BufferSize = (Len * 4 + 1) * sizeof (CHAR16); + + if (*StrBufferLen < BufferSize) { + *StrBufferLen = BufferSize; + return EFI_BUFFER_TOO_SMALL; + } + + *StrBufferLen = BufferSize; + String = ConfigString; + + for (Index = 0; Index < Len; Index++) { + BufToHexString (ConfigString, &BufferSize, (UINT8 *) UnicodeString, 2); + + ConfigString += 4; + UnicodeString += 1; + } + + // + // Add tailing '\0' character + // + *ConfigString = L'\0'; + + // + // Convert the uppercase to lowercase since is defined in lowercase format. + // + ToLower (String); + return EFI_SUCCESS; +} + +/** + Construct using routing information GUID/NAME/PATH. + + @param ConfigHdr Pointer to the ConfigHdr string. + @param StrBufferLen On input: Length in bytes of buffer to hold the + ConfigHdr string. Includes tailing '\0' character. + On output: If return EFI_SUCCESS, containing + length of ConfigHdr string buffer. If return + EFI_BUFFER_TOO_SMALL, containg length of string + buffer desired. + @param Guid Routing information: GUID. + @param Name Routing information: NAME. + @param DriverHandle Driver handle which contains the routing + information: PATH. + + @retval EFI_SUCCESS Operation completes successfully. + @retval EFI_BUFFER_TOO_SMALL The ConfigHdr string buffer is too small. + +**/ +EFI_STATUS +EFIAPI +ConstructConfigHdr ( + IN OUT CHAR16 *ConfigHdr, + IN OUT UINTN *StrBufferLen, + IN CONST EFI_GUID *Guid, + IN CHAR16 *Name, OPTIONAL + IN EFI_HANDLE *DriverHandle + ) +{ + EFI_STATUS Status; + UINTN NameStrLen; + UINTN DevicePathSize; + UINTN BufferSize; + CHAR16 *StrPtr; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + if (Name == NULL) { + // + // There will be no "NAME" in for Name/Value storage + // + NameStrLen = 0; + } else { + // + // For buffer storage + // + NameStrLen = StrLen (Name); + } + + // + // Retrieve DevicePath Protocol associated with this HiiPackageList + // + Status = gBS->HandleProtocol ( + DriverHandle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath + ); + if (EFI_ERROR (Status)) { + return Status; + } + + DevicePathSize = GetDevicePathSize (DevicePath); + + // + // GUID=32&NAME=NameStrLen&PATH=DevicePathStrLen + // | 5 | 32 | 6 | NameStrLen*4 | 6 | DevicePathStrLen | 1 | + // + BufferSize = (5 + 32 + 6 + NameStrLen * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16); + if (*StrBufferLen < BufferSize) { + *StrBufferLen = BufferSize; + return EFI_BUFFER_TOO_SMALL; + } + + *StrBufferLen = BufferSize; + + StrPtr = ConfigHdr; + + StrCpy (StrPtr, L"GUID="); + StrPtr += 5; + BufInReverseOrderToHexString (StrPtr, (UINT8 *) Guid, sizeof (EFI_GUID)); + StrPtr += 32; + + // + // Convert name string, e.g. name "ABCD" => "&NAME=0041004200430044" + // + StrCpy (StrPtr, L"&NAME="); + StrPtr += 6; + if (Name != NULL) { + BufferSize = (NameStrLen * 4 + 1) * sizeof (CHAR16); + UnicodeToConfigString (StrPtr, &BufferSize, Name); + StrPtr += (NameStrLen * 4); + } + + StrCpy (StrPtr, L"&PATH="); + StrPtr += 6; + BufInReverseOrderToHexString (StrPtr, (UINT8 *) DevicePath, DevicePathSize); + + return EFI_SUCCESS; +} + + +/** + Search BlockName "&OFFSET=Offset&WIDTH=Width" in a string. + + @param String The string to be searched in. + @param Offset Offset in BlockName. + @param Width Width in BlockName. + + @retval TRUE Block name found. + @retval FALSE Block name not found. + +**/ +BOOLEAN +EFIAPI +FindBlockName ( + IN OUT CHAR16 *String, + IN UINTN Offset, + IN UINTN Width + ) +{ + EFI_STATUS Status; + UINTN Data; + UINTN BufferSize; + UINTN ConvertedStrLen; + + while ((String = StrStr (String, L"&OFFSET=")) != NULL) { + // + // Skip '&OFFSET=' + // + String = String + 8; + + Data = 0; + BufferSize = sizeof (UINTN); + Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen); + if (EFI_ERROR (Status)) { + return FALSE; + } + String = String + ConvertedStrLen; + + if (Data != Offset) { + continue; + } + + if (StrnCmp (String, L"&WIDTH=", 7) != 0) { + return FALSE; + } + String = String + 7; + + Data = 0; + BufferSize = sizeof (UINTN); + Status = HexStringToBuf ((UINT8 *) &Data, &BufferSize, String, &ConvertedStrLen); + if (EFI_ERROR (Status)) { + return FALSE; + } + if (Data == Width) { + return TRUE; + } + + String = String + ConvertedStrLen; + } + + return FALSE; +} + + +/** + This routine is invoked by ConfigAccess.Callback() to retrived uncommitted data from Form Browser. + + @param VariableGuid An optional field to indicate the target variable + GUID name to use. + @param VariableName An optional field to indicate the target + human-readable variable name. + @param BufferSize On input: Length in bytes of buffer to hold + retrived data. On output: If return + EFI_BUFFER_TOO_SMALL, containg length of buffer + desired. + @param Buffer Buffer to hold retrived data. + + @retval EFI_SUCCESS Operation completes successfully. + @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. + +**/ +EFI_STATUS +EFIAPI +GetBrowserData ( + IN CONST EFI_GUID *VariableGuid, OPTIONAL + IN CONST CHAR16 *VariableName, OPTIONAL + IN OUT UINTN *BufferSize, + IN OUT UINT8 *Buffer + ) +{ + EFI_STATUS Status; + CONST CHAR16 *ConfigHdr; + CHAR16 *ConfigResp; + CHAR16 *StringPtr; + UINTN HeaderLen; + UINTN BufferLen; + CHAR16 *Progress; + + // + // Locate protocols for use + // + Status = LocateFormBrowser2Protocols (); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Retrive formset storage data from Form Browser + // + ConfigHdr = mFakeConfigHdr; + HeaderLen = StrLen (ConfigHdr); + + // + // First try allocate 0x4000 buffer for the formet storage data. + // + BufferLen = 0x4000; + ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); + if (ConfigResp == NULL) { + BufferLen = 0; + } + + StringPtr = ConfigResp + HeaderLen; + *StringPtr = L'&'; + StringPtr++; + + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, + &BufferLen, + StringPtr, + TRUE, + VariableGuid, + VariableName + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + if (ConfigResp != NULL) { + FreePool (ConfigResp); + } + + ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); + if (ConfigResp == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + StringPtr = ConfigResp + HeaderLen; + *StringPtr = L'&'; + StringPtr++; + + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, + &BufferLen, + StringPtr, + TRUE, + VariableGuid, + VariableName + ); + } + if (EFI_ERROR (Status)) { + FreePool (ConfigResp); + return Status; + } + CopyMem (ConfigResp, ConfigHdr, HeaderLen * sizeof (UINT16)); + + // + // Convert to buffer data + // + Status = mHiiConfigRouting->ConfigToBlock ( + mHiiConfigRouting, + ConfigResp, + Buffer, + BufferSize, + &Progress + ); + FreePool (ConfigResp); + + return Status; +} + + +/** + This routine is invoked by ConfigAccess.Callback() to update uncommitted data of Form Browser. + + @param VariableGuid An optional field to indicate the target variable + GUID name to use. + @param VariableName An optional field to indicate the target + human-readable variable name. + @param BufferSize Length in bytes of buffer to hold retrived data. + @param Buffer Buffer to hold retrived data. + @param RequestElement An optional field to specify which part of the + buffer data will be send back to Browser. If NULL, + the whole buffer of data will be committed to + Browser. ::= + &OFFSET=&WIDTH=* + + @retval EFI_SUCCESS Operation completes successfully. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. + @retval Other Updating Browser uncommitted data failed. + +**/ +EFI_STATUS +EFIAPI +SetBrowserData ( + IN CONST EFI_GUID *VariableGuid, OPTIONAL + IN CONST CHAR16 *VariableName, OPTIONAL + IN UINTN BufferSize, + IN CONST UINT8 *Buffer, + IN CONST CHAR16 *RequestElement OPTIONAL + ) +{ + EFI_STATUS Status; + CONST CHAR16 *ConfigHdr; + CHAR16 *ConfigResp; + CHAR16 *StringPtr; + UINTN HeaderLen; + UINTN BufferLen; + CHAR16 *Progress; + CHAR16 BlockName[33]; + CHAR16 *ConfigRequest; + CONST CHAR16 *Request; + + // + // Locate protocols for use + // + Status = LocateFormBrowser2Protocols (); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Prepare + // + ConfigHdr = mFakeConfigHdr; + HeaderLen = StrLen (ConfigHdr); + + if (RequestElement == NULL) { + // + // RequestElement not specified, use "&OFFSET=0&WIDTH=" as + // + BlockName[0] = L'\0'; + StrCpy (BlockName, L"&OFFSET=0&WIDTH="); + + // + // String lenghth of L"&OFFSET=0&WIDTH=" is 16 + // + StringPtr = BlockName + 16; + BufferLen = sizeof (BlockName) - (16 * sizeof (CHAR16)); + BufToHexString (StringPtr, &BufferLen, (UINT8 *) &BufferSize, sizeof (UINTN)); + + Request = BlockName; + } else { + Request = RequestElement; + } + + BufferLen = HeaderLen * sizeof (CHAR16) + StrSize (Request); + ConfigRequest = AllocateZeroPool (BufferLen); + if (ConfigRequest == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem (ConfigRequest, ConfigHdr, HeaderLen * sizeof (CHAR16)); + StringPtr = ConfigRequest + HeaderLen; + StrCpy (StringPtr, Request); + + // + // Convert buffer to + // + Status = mHiiConfigRouting->BlockToConfig ( + mHiiConfigRouting, + ConfigRequest, + Buffer, + BufferSize, + &ConfigResp, + &Progress + ); + if (EFI_ERROR (Status)) { + FreePool (ConfigRequest); + return Status; + } + + // + // Skip and '&' + // + StringPtr = ConfigResp + HeaderLen + 1; + + // + // Change uncommitted data in Browser + // + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, + &BufferSize, + StringPtr, + FALSE, + NULL, + NULL + ); + FreePool (ConfigRequest); + return Status; +} diff --git a/MdePkg/Library/UefiIfrSupportLib/UefiIfrLibraryInternal.h b/MdePkg/Library/UefiIfrSupportLib/UefiIfrLibraryInternal.h new file mode 100644 index 0000000000..d5fcb669f6 --- /dev/null +++ b/MdePkg/Library/UefiIfrSupportLib/UefiIfrLibraryInternal.h @@ -0,0 +1,35 @@ +/** @file +Utility functions which helps in opcode creation, HII configuration string manipulations, +pop up window creations, setup browser persistence data set and get. + +Copyright (c) 2007 - 2008, Intel Corporation +All rights reserved. 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. + + +**/ + +#ifndef _IFRLIBRARY_INTERNAL_H_ +#define _IFRLIBRARY_INTERNAL_H_ + + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + +#endif + diff --git a/MdePkg/Library/UefiIfrSupportLib/UefiIfrOpCodeCreation.c b/MdePkg/Library/UefiIfrSupportLib/UefiIfrOpCodeCreation.c new file mode 100644 index 0000000000..d79e254aae --- /dev/null +++ b/MdePkg/Library/UefiIfrSupportLib/UefiIfrOpCodeCreation.c @@ -0,0 +1,891 @@ +/** @file + Library Routines to create IFR independent of string data - assume tokens already exist + Primarily to be used for exporting op-codes at a label in pre-defined forms. + + +Copyright (c) 2007, Intel Corporation +All rights reserved. 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 "UefiIfrLibraryInternal.h" + +/** + Check if the input question flags is a valid value. + The valid combination of question flags includes + EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY. + + @param Flags The question flags to check. + + @retval TRUE If the question flag is a valid combination. + @retval FALSE If the question flag is an invalid combination. + +**/ +BOOLEAN +IsValidQuestionFlags ( + IN UINT8 Flags + ) +{ + return (BOOLEAN) (((Flags & (~QUESTION_FLAGS)) != 0) ? FALSE : TRUE); +} + +/** + Check if the input value type is a valid type. + The valid value type is smaller or equal than EFI_IFR_TYPE_OTHER. + + @param Type The value type to check. + + @retval TRUE If the value type is valid. + @retval FALSE If the value type is invalid. + +**/ +BOOLEAN +IsValidValueType ( + IN UINT8 Type + ) +{ + return (BOOLEAN) ((Type <= EFI_IFR_TYPE_OTHER) ? TRUE : FALSE); +} + +/** + Check if the input numeric flags is a valid value. + + @param Flags The numeric flags to check. + + @retval TRUE If the numeric flags is valid. + @retval FALSE If the numeric flags is invalid. + +**/ +BOOLEAN +IsValidNumricFlags ( + IN UINT8 Flags + ) +{ + if ((Flags & ~(EFI_IFR_NUMERIC_SIZE | EFI_IFR_DISPLAY)) != 0) { + return FALSE; + } + + if ((Flags & EFI_IFR_DISPLAY) > EFI_IFR_DISPLAY_UINT_HEX) { + return FALSE; + } + + return TRUE; +} + +/** + Check if the checkbox flags is a valid value. + + @param Flags The checkbox flags to check. + + @retval TRUE If the checkbox flags is valid. + @retval FALSE If the checkbox flags is invalid. + +**/ +BOOLEAN +IsValidCheckboxFlags ( + IN UINT8 Flags + ) +{ + return (BOOLEAN) ((Flags <= EFI_IFR_CHECKBOX_DEFAULT_MFG) ? TRUE : FALSE); +} + +/** + Create EFI_IFR_END_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + +**/ +EFI_STATUS +EFIAPI +CreateEndOpCode ( + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_END End; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (Data->Offset + sizeof (EFI_IFR_END) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + End.Header.Length = sizeof (EFI_IFR_END); + End.Header.OpCode = EFI_IFR_END_OP; + End.Header.Scope = 0; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_END to cover the unaligned address access. + // + CopyMem (LocalBuffer, &End, sizeof (EFI_IFR_END)); + Data->Offset += sizeof (EFI_IFR_END); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_DEFAULT_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param Value Value for the default + @param Type Type for the default + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER The type is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateDefaultOpCode ( + IN EFI_IFR_TYPE_VALUE *Value, + IN UINT8 Type, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_DEFAULT Default; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if ((Value == NULL) || !IsValidValueType (Type)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_DEFAULT) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Default.Header.OpCode = EFI_IFR_DEFAULT_OP; + Default.Header.Length = sizeof (EFI_IFR_DEFAULT); + Default.Header.Scope = 0; + Default.Type = Type; + Default.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; + CopyMem (&Default.Value, Value, sizeof(EFI_IFR_TYPE_VALUE)); + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_DEFAULT to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Default, sizeof (EFI_IFR_DEFAULT)); + Data->Offset += sizeof (EFI_IFR_DEFAULT); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_ACTION_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param QuestionConfig String ID for configuration + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateActionOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN EFI_STRING_ID QuestionConfig, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_ACTION Action; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_ACTION) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Action.Header.OpCode = EFI_IFR_ACTION_OP; + Action.Header.Length = sizeof (EFI_IFR_ACTION); + Action.Header.Scope = 0; + Action.Question.QuestionId = QuestionId; + Action.Question.Header.Prompt = Prompt; + Action.Question.Header.Help = Help; + Action.Question.VarStoreId = INVALID_VARSTORE_ID; + Action.Question.Flags = QuestionFlags; + Action.QuestionConfig = QuestionConfig; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_ACTION to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Action, sizeof (EFI_IFR_ACTION)); + Data->Offset += sizeof (EFI_IFR_ACTION); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_SUBTITLE_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param Prompt String ID for Prompt + @param Help String ID for Help + @param Flags Subtitle opcode flags + @param Scope Subtitle Scope bit + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + +**/ +EFI_STATUS +EFIAPI +CreateSubTitleOpCode ( + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 Flags, + IN UINT8 Scope, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_SUBTITLE Subtitle; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (Data->Offset + sizeof (EFI_IFR_SUBTITLE) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP; + Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE); + Subtitle.Header.Scope = Scope; + Subtitle.Statement.Prompt = Prompt; + Subtitle.Statement.Help = Help; + Subtitle.Flags = Flags; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_SUBTITLE to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE)); + Data->Offset += sizeof (EFI_IFR_SUBTITLE); + + return EFI_SUCCESS; +} + + +/** + Create EFI_IFR_TEXT_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param Prompt String ID for Prompt + @param Help String ID for Help + @param TextTwo String ID for text two + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + +**/ +EFI_STATUS +EFIAPI +CreateTextOpCode ( + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN EFI_STRING_ID TextTwo, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_TEXT Text; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (Data->Offset + sizeof (EFI_IFR_TEXT) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Text.Header.OpCode = EFI_IFR_TEXT_OP; + Text.Header.Length = sizeof (EFI_IFR_TEXT); + Text.Header.Scope = 0; + Text.Statement.Prompt = Prompt; + Text.Statement.Help = Help; + Text.TextTwo = TextTwo; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_TEXT to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Text, sizeof (EFI_IFR_TEXT)); + Data->Offset += sizeof (EFI_IFR_TEXT); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_REF_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param FormId Destination Form ID + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param QuestionId Question ID + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateGotoOpCode ( + IN EFI_FORM_ID FormId, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN EFI_QUESTION_ID QuestionId, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_REF Goto; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_REF) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Goto.Header.OpCode = EFI_IFR_REF_OP; + Goto.Header.Length = sizeof (EFI_IFR_REF); + Goto.Header.Scope = 0; + Goto.Question.Header.Prompt = Prompt; + Goto.Question.Header.Help = Help; + Goto.Question.VarStoreId = INVALID_VARSTORE_ID; + Goto.Question.QuestionId = QuestionId; + Goto.Question.Flags = QuestionFlags; + Goto.FormId = FormId; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_REF to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Goto, sizeof (EFI_IFR_REF)); + Data->Offset += sizeof (EFI_IFR_REF); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_ONE_OF_OPTION_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param OptionCount The number of options. + @param OptionsList The list of Options. + @param Type The data type. + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If OptionCount is not zero but OptionsList is NULL. + +**/ +EFI_STATUS +EFIAPI +CreateOneOfOptionOpCode ( + IN UINTN OptionCount, + IN IFR_OPTION *OptionsList, + IN UINT8 Type, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + UINTN Index; + UINT8 *LocalBuffer; + EFI_IFR_ONE_OF_OPTION OneOfOption; + + ASSERT (Data != NULL && Data->Data != NULL); + + if ((OptionCount != 0) && (OptionsList == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + for (Index = 0; Index < OptionCount; Index++) { + OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP; + OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION); + OneOfOption.Header.Scope = 0; + + OneOfOption.Option = OptionsList[Index].StringToken; + OneOfOption.Value = OptionsList[Index].Value; + OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags & (EFI_IFR_OPTION_DEFAULT | EFI_IFR_OPTION_DEFAULT_MFG)); + OneOfOption.Type = Type; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_ONF_OF_OPTION to cover the unaligned address access. + // + CopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION)); + Data->Offset += sizeof (EFI_IFR_ONE_OF_OPTION); + } + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_ONE_OF_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param VarStoreId Storage ID + @param VarOffset Offset in Storage + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param OneOfFlags Flags for oneof opcode + @param OptionsList List of options + @param OptionCount Number of options in option list + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateOneOfOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, + IN UINT16 VarOffset, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 OneOfFlags, + IN IFR_OPTION *OptionsList, + IN UINTN OptionCount, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + UINTN Length; + EFI_IFR_ONE_OF OneOf; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidNumricFlags (OneOfFlags) || + !IsValidQuestionFlags (QuestionFlags) || + ((OptionCount != 0) && (OptionsList == NULL))) { + return EFI_INVALID_PARAMETER; + } + + Length = sizeof (EFI_IFR_ONE_OF) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); + if (Data->Offset + Length > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP; + OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF); + OneOf.Header.Scope = 1; + OneOf.Question.Header.Prompt = Prompt; + OneOf.Question.Header.Help = Help; + OneOf.Question.QuestionId = QuestionId; + OneOf.Question.VarStoreId = VarStoreId; + OneOf.Question.VarStoreInfo.VarOffset = VarOffset; + OneOf.Question.Flags = QuestionFlags; + OneOf.Flags = OneOfFlags; + ZeroMem ((VOID *) &OneOf.data, sizeof (MINMAXSTEP_DATA)); + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_ONF_OF to cover the unaligned address access. + // + CopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF)); + Data->Offset += sizeof (EFI_IFR_ONE_OF); + + CreateOneOfOptionOpCode (OptionCount, OptionsList, (UINT8) (OneOfFlags & EFI_IFR_NUMERIC_SIZE), Data); + + CreateEndOpCode (Data); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_ORDERED_LIST_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param VarStoreId Storage ID + @param VarOffset Offset in Storage + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param OrderedListFlags Flags for ordered list opcode + @param DataType Type for option value + @param MaxContainers Maximum count for options in this ordered list + @param OptionsList List of options + @param OptionCount Number of options in option list + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateOrderedListOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, + IN UINT16 VarOffset, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 OrderedListFlags, + IN UINT8 DataType, + IN UINT8 MaxContainers, + IN IFR_OPTION *OptionsList, + IN UINTN OptionCount, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + UINTN Length; + EFI_IFR_ORDERED_LIST OrderedList; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags) || + ((OptionCount != 0) && (OptionsList == NULL))) { + return EFI_INVALID_PARAMETER; + } + + if ((OrderedListFlags != 0) && + (OrderedListFlags != EFI_IFR_UNIQUE_SET) && + (OrderedListFlags != EFI_IFR_NO_EMPTY_SET)) { + return EFI_INVALID_PARAMETER; + } + + Length = sizeof (EFI_IFR_ORDERED_LIST) + OptionCount * sizeof (EFI_IFR_ONE_OF_OPTION) + sizeof (EFI_IFR_END); + if (Data->Offset + Length > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP; + OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST); + OrderedList.Header.Scope = 1; + OrderedList.Question.Header.Prompt = Prompt; + OrderedList.Question.Header.Help = Help; + OrderedList.Question.QuestionId = QuestionId; + OrderedList.Question.VarStoreId = VarStoreId; + OrderedList.Question.VarStoreInfo.VarOffset = VarOffset; + OrderedList.Question.Flags = QuestionFlags; + OrderedList.MaxContainers = MaxContainers; + OrderedList.Flags = OrderedListFlags; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_ORDERED_LIST to cover the unaligned address access. + // + CopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST)); + Data->Offset += sizeof (EFI_IFR_ORDERED_LIST); + + CreateOneOfOptionOpCode (OptionCount, OptionsList, DataType, Data); + + CreateEndOpCode (Data); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_CHECKBOX_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param VarStoreId Storage ID + @param VarOffset Offset in Storage + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param CheckBoxFlags Flags for checkbox opcode + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateCheckBoxOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, + IN UINT16 VarOffset, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 CheckBoxFlags, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_CHECKBOX CheckBox; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags) || !IsValidCheckboxFlags (CheckBoxFlags)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_CHECKBOX) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP; + CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX); + CheckBox.Header.Scope = 0; + CheckBox.Question.QuestionId = QuestionId; + CheckBox.Question.VarStoreId = VarStoreId; + CheckBox.Question.VarStoreInfo.VarOffset = VarOffset; + CheckBox.Question.Header.Prompt = Prompt; + CheckBox.Question.Header.Help = Help; + CheckBox.Question.Flags = QuestionFlags; + CheckBox.Flags = CheckBoxFlags; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_CHECKBOX to cover the unaligned address access. + // + CopyMem (LocalBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX)); + Data->Offset += sizeof (EFI_IFR_CHECKBOX); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_NUMERIC_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param VarStoreId Storage ID + @param VarOffset Offset in Storage + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param NumericFlags Flags for numeric opcode + @param Minimum Numeric minimum value + @param Maximum Numeric maximum value + @param Step Numeric step for edit + @param Default Numeric default value + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateNumericOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, + IN UINT16 VarOffset, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 NumericFlags, + IN UINT64 Minimum, + IN UINT64 Maximum, + IN UINT64 Step, + IN UINT64 Default, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_STATUS Status; + EFI_IFR_NUMERIC Numeric; + MINMAXSTEP_DATA MinMaxStep; + EFI_IFR_TYPE_VALUE DefaultValue; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags) || !IsValidNumricFlags (NumericFlags)) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_CHECKBOX) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP; + Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC); + Numeric.Header.Scope = 1; + Numeric.Question.QuestionId = QuestionId; + Numeric.Question.VarStoreId = VarStoreId; + Numeric.Question.VarStoreInfo.VarOffset = VarOffset; + Numeric.Question.Header.Prompt = Prompt; + Numeric.Question.Header.Help = Help; + Numeric.Question.Flags = QuestionFlags; + Numeric.Flags = NumericFlags; + + switch (NumericFlags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + MinMaxStep.u8.MinValue = (UINT8) Minimum; + MinMaxStep.u8.MaxValue = (UINT8) Maximum; + MinMaxStep.u8.Step = (UINT8) Step; + break; + + case EFI_IFR_NUMERIC_SIZE_2: + MinMaxStep.u16.MinValue = (UINT16) Minimum; + MinMaxStep.u16.MaxValue = (UINT16) Maximum; + MinMaxStep.u16.Step = (UINT16) Step; + break; + + case EFI_IFR_NUMERIC_SIZE_4: + MinMaxStep.u32.MinValue = (UINT32) Minimum; + MinMaxStep.u32.MaxValue = (UINT32) Maximum; + MinMaxStep.u32.Step = (UINT32) Step; + break; + + case EFI_IFR_NUMERIC_SIZE_8: + MinMaxStep.u64.MinValue = Minimum; + MinMaxStep.u64.MaxValue = Maximum; + MinMaxStep.u64.Step = Step; + break; + } + + CopyMem (&Numeric.data, &MinMaxStep, sizeof (MINMAXSTEP_DATA)); + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_NUMERIC to cover the unaligned address access. + // + CopyMem (LocalBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC)); + Data->Offset += sizeof (EFI_IFR_NUMERIC); + + DefaultValue.u64 = Default; + Status = CreateDefaultOpCode (&DefaultValue, (UINT8) (NumericFlags & EFI_IFR_NUMERIC_SIZE), Data); + if (EFI_ERROR(Status)) { + return Status; + } + + CreateEndOpCode (Data); + + return EFI_SUCCESS; +} + +/** + Create EFI_IFR_STRING_OP opcode. + + If Data is NULL or Data->Data is NULL, then ASSERT. + + @param QuestionId Question ID + @param VarStoreId Storage ID + @param VarOffset Offset in Storage + @param Prompt String ID for Prompt + @param Help String ID for Help + @param QuestionFlags Flags in Question Header + @param StringFlags Flags for string opcode + @param MinSize String minimum length + @param MaxSize String maximum length + @param Data Destination for the created opcode binary + + @retval EFI_SUCCESS Opcode is created successfully. + @retval EFI_BUFFER_TOO_SMALL The space reserved in Data field is too small. + @retval EFI_INVALID_PARAMETER If QuestionFlags is not valid. + +**/ +EFI_STATUS +EFIAPI +CreateStringOpCode ( + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, + IN UINT16 VarOffset, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 StringFlags, + IN UINT8 MinSize, + IN UINT8 MaxSize, + IN OUT EFI_HII_UPDATE_DATA *Data + ) +{ + EFI_IFR_STRING String; + UINT8 *LocalBuffer; + + ASSERT (Data != NULL && Data->Data != NULL); + + if (!IsValidQuestionFlags (QuestionFlags) || (StringFlags & ~EFI_IFR_STRING_MULTI_LINE) != 0) { + return EFI_INVALID_PARAMETER; + } + + if (Data->Offset + sizeof (EFI_IFR_STRING) > Data->BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + String.Header.OpCode = EFI_IFR_STRING_OP; + String.Header.Length = sizeof (EFI_IFR_STRING); + String.Header.Scope = 0; + String.Question.Header.Prompt = Prompt; + String.Question.Header.Help = Help; + String.Question.QuestionId = QuestionId; + String.Question.VarStoreId = VarStoreId; + String.Question.VarStoreInfo.VarOffset = VarOffset; + String.Question.Flags = QuestionFlags; + String.MinSize = MinSize; + String.MaxSize = MaxSize; + String.Flags = StringFlags; + + LocalBuffer = (UINT8 *) Data->Data + Data->Offset; + // + // CopyMem is used for EFI_IFR_STRING to cover the unaligned address access. + // + CopyMem (LocalBuffer, &String, sizeof (EFI_IFR_STRING)); + Data->Offset += sizeof (EFI_IFR_STRING); + + return EFI_SUCCESS; +} + + diff --git a/MdePkg/Library/UefiIfrSupportLib/UefiIfrSupportLib.inf b/MdePkg/Library/UefiIfrSupportLib/UefiIfrSupportLib.inf new file mode 100644 index 0000000000..50b1ffedbf --- /dev/null +++ b/MdePkg/Library/UefiIfrSupportLib/UefiIfrSupportLib.inf @@ -0,0 +1,55 @@ +#/** @file +#Utility functions which helps in opcode creation, HII configuration string manipulations, +#pop up window creations, setup browser persistence data set and get. +# +# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved. +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiIfrSupportLib + FILE_GUID = bf38668e-e231-4baa-99e4-8c0e4c35dca6 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = IfrSupportLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + UefiIfrForm.c + UefiIfrLibraryInternal.h + UefiIfrOpCodeCreation.c + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + MemoryAllocationLib + DevicePathLib + BaseLib + UefiBootServicesTableLib + BaseMemoryLib + DebugLib + +[Protocols] + gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiHiiConfigRoutingProtocolGuid + gEfiFormBrowser2ProtocolGuid diff --git a/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c new file mode 100644 index 0000000000..1c1c879a5f --- /dev/null +++ b/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c @@ -0,0 +1,689 @@ +/** @file + Support routines for memory allocation routines based + on boot services for Dxe phase drivers. + + Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. 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 + + +#include +#include +#include +#include + +/** + Allocates one or more 4KB pages of a certain memory type. + + Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated + buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned. + If there is not enough memory remaining to satisfy the request, then NULL is returned. + + @param MemoryType The type of memory to allocate. + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocatePages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Memory; + + if (Pages == 0) { + return NULL; + } + + Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory); + if (EFI_ERROR (Status)) { + return NULL; + } + return (VOID *) (UINTN) Memory; +} + +/** + Allocates one or more 4KB pages of type EfiBootServicesData. + + Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the + allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL + is returned. If there is not enough memory remaining to satisfy the request, then NULL is + returned. + + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocatePages ( + IN UINTN Pages + ) +{ + return InternalAllocatePages (EfiBootServicesData, Pages); +} + +/** + Allocates one or more 4KB pages of type EfiRuntimeServicesData. + + Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the + allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL + is returned. If there is not enough memory remaining to satisfy the request, then NULL is + returned. + + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimePages ( + IN UINTN Pages + ) +{ + return InternalAllocatePages (EfiRuntimeServicesData, Pages); +} + +/** + Allocates one or more 4KB pages of type EfiReservedMemoryType. + + Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the + allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL + is returned. If there is not enough memory remaining to satisfy the request, then NULL is + returned. + + @param Pages The number of 4 KB pages to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateReservedPages ( + IN UINTN Pages + ) +{ + return InternalAllocatePages (EfiReservedMemoryType, Pages); +} + +/** + Frees one or more 4KB pages that were previously allocated with one of the page allocation + functions in the Memory Allocation Library. + + Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer + must have been allocated on a previous call to the page allocation services of the Memory + Allocation Library. + If Buffer was not allocated with a page allocation function in the Memory Allocation Library, + then ASSERT(). + If Pages is zero, then ASSERT(). + + @param Buffer Pointer to the buffer of pages to free. + @param Pages The number of 4 KB pages to free. + +**/ +VOID +EFIAPI +FreePages ( + IN VOID *Buffer, + IN UINTN Pages + ) +{ + EFI_STATUS Status; + + ASSERT (Pages != 0); + Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); + ASSERT_EFI_ERROR (Status); +} + +/** + Allocates one or more 4KB pages of a certain memory type at a specified alignment. + + Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment + specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned. + If there is not enough memory at the specified alignment remaining to satisfy the request, then + NULL is returned. + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). + + @param MemoryType The type of memory to allocate. + @param Pages The number of 4 KB pages to allocate. + @param Alignment The requested alignment of the allocation. Must be a power of two. + If Alignment is zero, then byte alignment is used. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocateAlignedPages ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, + IN UINTN Alignment + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Memory; + UINTN AlignedMemory; + UINTN AlignmentMask; + UINTN UnalignedPages; + UINTN RealPages; + + // + // Alignment must be a power of two or zero. + // + ASSERT ((Alignment & (Alignment - 1)) == 0); + + if (Pages == 0) { + return NULL; + } + if (Alignment > EFI_PAGE_SIZE) { + // + // Caculate the total number of pages since alignment is larger than page size. + // + AlignmentMask = Alignment - 1; + RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment); + // + // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. + // + ASSERT (RealPages > Pages); + + Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory); + if (EFI_ERROR (Status)) { + return NULL; + } + AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask; + UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory); + if (UnalignedPages > 0) { + // + // Free first unaligned page(s). + // + Status = gBS->FreePages (Memory, UnalignedPages); + ASSERT_EFI_ERROR (Status); + } + Memory = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages)); + UnalignedPages = RealPages - Pages - UnalignedPages; + if (UnalignedPages > 0) { + // + // Free last unaligned page(s). + // + Status = gBS->FreePages (Memory, UnalignedPages); + ASSERT_EFI_ERROR (Status); + } + } else { + // + // Do not over-allocate pages in this case. + // + Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory); + if (EFI_ERROR (Status)) { + return NULL; + } + AlignedMemory = (UINTN) Memory; + } + return (VOID *) AlignedMemory; +} + +/** + Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. + + Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an + alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is + returned. If there is not enough memory at the specified alignment remaining to satisfy the + request, then NULL is returned. + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). + + @param Pages The number of 4 KB pages to allocate. + @param Alignment The requested alignment of the allocation. Must be a power of two. + If Alignment is zero, then byte alignment is used. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateAlignedPages ( + IN UINTN Pages, + IN UINTN Alignment + ) +{ + return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment); +} + +/** + Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment. + + Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an + alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is + returned. If there is not enough memory at the specified alignment remaining to satisfy the + request, then NULL is returned. + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). + + @param Pages The number of 4 KB pages to allocate. + @param Alignment The requested alignment of the allocation. Must be a power of two. + If Alignment is zero, then byte alignment is used. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateAlignedRuntimePages ( + IN UINTN Pages, + IN UINTN Alignment + ) +{ + return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment); +} + +/** + Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment. + + Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an + alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is + returned. If there is not enough memory at the specified alignment remaining to satisfy the + request, then NULL is returned. + If Alignment is not a power of two and Alignment is not zero, then ASSERT(). + + @param Pages The number of 4 KB pages to allocate. + @param Alignment The requested alignment of the allocation. Must be a power of two. + If Alignment is zero, then byte alignment is used. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateAlignedReservedPages ( + IN UINTN Pages, + IN UINTN Alignment + ) +{ + return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment); +} + +/** + Frees one or more 4KB pages that were previously allocated with one of the aligned page + allocation functions in the Memory Allocation Library. + + Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer + must have been allocated on a previous call to the aligned page allocation services of the Memory + Allocation Library. + If Buffer was not allocated with an aligned page allocation function in the Memory Allocation + Library, then ASSERT(). + If Pages is zero, then ASSERT(). + + @param Buffer Pointer to the buffer of pages to free. + @param Pages The number of 4 KB pages to free. + +**/ +VOID +EFIAPI +FreeAlignedPages ( + IN VOID *Buffer, + IN UINTN Pages + ) +{ + EFI_STATUS Status; + + ASSERT (Pages != 0); + Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages); + ASSERT_EFI_ERROR (Status); +} + +/** + Allocates a buffer of a certain pool type. + + Allocates the number bytes specified by AllocationSize of a certain pool type and returns a + pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is + returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. + + @param MemoryType The type of memory to allocate. + @param AllocationSize The number of bytes to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocatePool ( + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN AllocationSize + ) +{ + EFI_STATUS Status; + VOID *Memory; + + Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory); + if (EFI_ERROR (Status)) { + Memory = NULL; + } + return Memory; +} + +/** + Allocates a buffer of type EfiBootServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a + pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is + returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocatePool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocatePool (EfiBootServicesData, AllocationSize); +} + +/** + Allocates a buffer of type EfiRuntimeServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns + a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is + returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimePool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize); +} + +/** + Allocates a buffer of type EfieservedMemoryType. + + Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns + a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is + returned. If there is not enough memory remaining to satisfy the request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateReservedPool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocatePool (EfiReservedMemoryType, AllocationSize); +} + +/** + Allocates and zeros a buffer of a certian pool type. + + Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer + with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid + buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request, + then NULL is returned. + + @param PoolType The type of memory to allocate. + @param AllocationSize The number of bytes to allocate and zero. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocateZeroPool ( + IN EFI_MEMORY_TYPE PoolType, + IN UINTN AllocationSize + ) +{ + VOID *Memory; + + Memory = InternalAllocatePool (PoolType, AllocationSize); + if (Memory != NULL) { + Memory = ZeroMem (Memory, AllocationSize); + } + return Memory; +} + +/** + Allocates and zeros a buffer of type EfiBootServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the + buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a + valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the + request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate and zero. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateZeroPool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize); +} + +/** + Allocates and zeros a buffer of type EfiRuntimeServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the + buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a + valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the + request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate and zero. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimeZeroPool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize); +} + +/** + Allocates and zeros a buffer of type EfiReservedMemoryType. + + Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the + buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a + valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the + request, then NULL is returned. + + @param AllocationSize The number of bytes to allocate and zero. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateReservedZeroPool ( + IN UINTN AllocationSize + ) +{ + return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize); +} + +/** + Copies a buffer to an allocated buffer of a certian pool type. + + Allocates the number bytes specified by AllocationSize of a certian pool type, copies + AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the + allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there + is not enough memory remaining to satisfy the request, then NULL is returned. + If Buffer is NULL, then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param PoolType The type of pool to allocate. + @param AllocationSize The number of bytes to allocate and zero. + @param Buffer The buffer to copy to the allocated buffer. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +InternalAllocateCopyPool ( + IN EFI_MEMORY_TYPE PoolType, + IN UINTN AllocationSize, + IN CONST VOID *Buffer + ) +{ + VOID *Memory; + + ASSERT (Buffer != NULL); + ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1)); + + Memory = InternalAllocatePool (PoolType, AllocationSize); + if (Memory != NULL) { + Memory = CopyMem (Memory, Buffer, AllocationSize); + } + return Memory; +} + +/** + Copies a buffer to an allocated buffer of type EfiBootServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies + AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the + allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there + is not enough memory remaining to satisfy the request, then NULL is returned. + If Buffer is NULL, then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param AllocationSize The number of bytes to allocate and zero. + @param Buffer The buffer to copy to the allocated buffer. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateCopyPool ( + IN UINTN AllocationSize, + IN CONST VOID *Buffer + ) +{ + return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer); +} + +/** + Copies a buffer to an allocated buffer of type EfiRuntimeServicesData. + + Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies + AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the + allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there + is not enough memory remaining to satisfy the request, then NULL is returned. + If Buffer is NULL, then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param AllocationSize The number of bytes to allocate and zero. + @param Buffer The buffer to copy to the allocated buffer. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateRuntimeCopyPool ( + IN UINTN AllocationSize, + IN CONST VOID *Buffer + ) +{ + return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer); +} + +/** + Copies a buffer to an allocated buffer of type EfiReservedMemoryType. + + Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies + AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the + allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there + is not enough memory remaining to satisfy the request, then NULL is returned. + If Buffer is NULL, then ASSERT(). + If AllocationSize is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param AllocationSize The number of bytes to allocate and zero. + @param Buffer The buffer to copy to the allocated buffer. + + @return A pointer to the allocated buffer or NULL if allocation fails. + +**/ +VOID * +EFIAPI +AllocateReservedCopyPool ( + IN UINTN AllocationSize, + IN CONST VOID *Buffer + ) +{ + return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer); +} + +/** + Frees a buffer that was previously allocated with one of the pool allocation functions in the + Memory Allocation Library. + + Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the + pool allocation services of the Memory Allocation Library. + If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, + then ASSERT(). + + @param Buffer Pointer to the buffer to free. + +**/ +VOID +EFIAPI +FreePool ( + IN VOID *Buffer + ) +{ + EFI_STATUS Status; + + Status = gBS->FreePool (Buffer); + ASSERT_EFI_ERROR (Status); +} + + +/** + Frees buffer that were previously allocated with one of the + memory allocation functions in the Memory Allocation Library. + + @param Buffer Pointer to the buffer of pages + to free. + +**/ +VOID +EFIAPI +SafeFreePool ( + IN VOID *Buffer + ) +{ + if (Buffer != NULL) { + FreePool (Buffer); + } +} + diff --git a/MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf b/MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf new file mode 100644 index 0000000000..4b51c808d4 --- /dev/null +++ b/MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf @@ -0,0 +1,45 @@ +#/** @file +# Component description file for Dxe Memory Allocation Library +# +# Memory Allocation Library that uses EFI Boot Services to allocate +# and free memory. +# Copyright (c) 2007 - 2008, Intel Corporation +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiMemoryAllocationLib + FILE_GUID = 4674739d-3195-4fb2-8094-ac1d22d00194 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = MemoryAllocationLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + MemoryAllocationLib.c + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + DebugLib + BaseMemoryLib + UefiBootServicesTableLib + diff --git a/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c b/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c new file mode 100644 index 0000000000..466a10eb41 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c @@ -0,0 +1,67 @@ +/** @file + CompareMem() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Compares the contents of two buffers. + + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL, then ASSERT(). + If Length > 0 and SourceBuffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). + + + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. + + @return 0 All Length bytes of the two buffers are identical. + @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + +**/ +INTN +EFIAPI +CompareMem ( + IN CONST VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ) +{ + if (Length == 0 || DestinationBuffer == SourceBuffer) { + return 0; + } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); +} diff --git a/MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c b/MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c new file mode 100644 index 0000000000..99870bcc83 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/CopyMemWrapper.c @@ -0,0 +1,62 @@ +/** @file + CopyMem() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Copies a source buffer to a destination buffer, and returns the destination buffer. + + This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns + DestinationBuffer. The implementation must be reentrant, and it must handle the case + where SourceBuffer overlaps DestinationBuffer. + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). + + @param DestinationBuffer Pointer to the destination buffer of the memory copy. + @param SourceBuffer Pointer to the source buffer of the memory copy. + @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer. + + @return DestinationBuffer. + +**/ +VOID * +EFIAPI +CopyMem ( + OUT VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ) +{ + if (Length == 0) { + return DestinationBuffer; + } + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + + if (DestinationBuffer == SourceBuffer) { + return DestinationBuffer; + } + return InternalMemCopyMem (DestinationBuffer, SourceBuffer, Length); +} diff --git a/MdePkg/Library/UefiMemoryLib/MemLib.c b/MdePkg/Library/UefiMemoryLib/MemLib.c new file mode 100644 index 0000000000..5489fd0f08 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/MemLib.c @@ -0,0 +1,63 @@ +/** @file + Base Memory Library functions implementation bases on Uefi Boot Service. + + Copyright (c) 2006 - 2008, Intel Corporation
+ All rights reserved. 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 "MemLibInternals.h" + +/** + Copies a source buffer to a destination buffer, and returns the destination buffer. + + This function wraps the gBS->CopyMem(). + + @param DestinationBuffer Pointer to the destination buffer of the memory copy. + @param SourceBuffer Pointer to the source buffer of the memory copy. + @param Length Number of bytes to copy from SourceBuffer to DestinationBuffer. + + @return DestinationBuffer. + +**/ +VOID * +EFIAPI +InternalMemCopyMem ( + OUT VOID *Destination, + IN CONST VOID *Source, + IN UINTN Length + ) +{ + gBS->CopyMem (Destination, (VOID*)Source, Length); + return Destination; +} + +/** + Fills a target buffer with a byte value, and returns the target buffer. + + This function wraps the gBS->SetMem(). + + @param Buffer Memory to set. + @param Size Number of bytes to set. + @param Value Value of the set operation. + + @return Buffer. + +**/ +VOID * +EFIAPI +InternalMemSetMem ( + OUT VOID *Buffer, + IN UINTN Size, + IN UINT8 Value + ) +{ + gBS->SetMem (Buffer, Size, Value); + return Buffer; +} diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c new file mode 100644 index 0000000000..3ae0387883 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c @@ -0,0 +1,261 @@ +/** @file + Architecture Independent Base Memory Library Implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Fills a target buffer with a 16-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem16 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ) +{ + do { + ((UINT16*)Buffer)[--Length] = Value; + } while (Length != 0); + return Buffer; +} + +/** + Fills a target buffer with a 32-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem32 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ) +{ + do { + ((UINT32*)Buffer)[--Length] = Value; + } while (Length != 0); + return Buffer; +} + +/** + Fills a target buffer with a 64-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem64 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ) +{ + do { + ((UINT64*)Buffer)[--Length] = Value; + } while (Length != 0); + return Buffer; +} + +/** + Set Buffer to 0 for Size bytes. + + @param Buffer Memory to set. + @param Length Number of bytes to set + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemZeroMem ( + OUT VOID *Buffer, + IN UINTN Length + ) +{ + return InternalMemSetMem (Buffer, Length, 0); +} + +/** + Compares two memory buffers of a given length. + + @param DestinationBuffer First memory buffer + @param SourceBuffer Second memory buffer + @param Length Length of DestinationBuffer and SourceBuffer memory + regions to compare. Must be non-zero. + + @return 0 All Length bytes of the two buffers are identical. + @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + +**/ +INTN +EFIAPI +InternalMemCompareMem ( + IN CONST VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ) +{ + while ((--Length != 0) && + (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { + DestinationBuffer = (INT8*)DestinationBuffer + 1; + SourceBuffer = (INT8*)SourceBuffer + 1; + } + return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer; +} + +/** + Scans a target buffer for an 8-bit value, and returns a pointer to the + matching 8-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem8 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT8 Value + ) +{ + CONST UINT8 *Pointer; + + Pointer = (CONST UINT8*)Buffer; + do { + if (*(Pointer++) == Value) { + return Pointer; + } + } while (--Length != 0); + return NULL; +} + +/** + Scans a target buffer for a 16-bit value, and returns a pointer to the + matching 16-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem16 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ) +{ + CONST UINT16 *Pointer; + + Pointer = (CONST UINT16*)Buffer; + do { + if (*(Pointer++) == Value) { + return Pointer; + } + } while (--Length != 0); + return NULL; +} + +/** + Scans a target buffer for a 32-bit value, and returns a pointer to the + matching 32-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem32 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ) +{ + CONST UINT32 *Pointer; + + Pointer = (CONST UINT32*)Buffer; + do { + if (*(Pointer++) == Value) { + return Pointer; + } + } while (--Length != 0); + return NULL; +} + +/** + Scans a target buffer for a 64-bit value, and returns a pointer to the + matching 64-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem64 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ) +{ + CONST UINT64 *Pointer; + + Pointer = (CONST UINT64*)Buffer; + do { + if (*(Pointer++) == Value) { + return Pointer; + } + } while (--Length != 0); + return NULL; +} diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGuid.c b/MdePkg/Library/UefiMemoryLib/MemLibGuid.c new file mode 100644 index 0000000000..4c6c615aa3 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/MemLibGuid.c @@ -0,0 +1,139 @@ +/** @file + Implementation of GUID functions. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Copies a source GUID to a destination GUID. + + This function copies the contents of the 128-bit GUID specified by SourceGuid to + DestinationGuid, and returns DestinationGuid. + If DestinationGuid is NULL, then ASSERT(). + If SourceGuid is NULL, then ASSERT(). + + @param DestinationGuid Pointer to the destination GUID. + @param SourceGuid Pointer to the source GUID. + + @return DestinationGuid. + +**/ +GUID * +EFIAPI +CopyGuid ( + OUT GUID *DestinationGuid, + IN CONST GUID *SourceGuid + ) +{ + WriteUnaligned64 ( + (UINT64*)DestinationGuid, + ReadUnaligned64 ((CONST UINT64*)SourceGuid) + ); + WriteUnaligned64 ( + (UINT64*)DestinationGuid + 1, + ReadUnaligned64 ((CONST UINT64*)SourceGuid + 1) + ); + return DestinationGuid; +} + +/** + Compares two GUIDs. + + This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned. + If there are any bit differences in the two GUIDs, then FALSE is returned. + If Guid1 is NULL, then ASSERT(). + If Guid2 is NULL, then ASSERT(). + + @param Guid1 A pointer to a 128 bit GUID. + @param Guid2 A pointer to a 128 bit GUID. + + @retval TRUE Guid1 and Guid2 are identical. + @retval FALSE Guid1 and Guid2 are not identical. + +**/ +BOOLEAN +EFIAPI +CompareGuid ( + IN CONST GUID *Guid1, + IN CONST GUID *Guid2 + ) +{ + UINT64 LowPartOfGuid1; + UINT64 LowPartOfGuid2; + UINT64 HighPartOfGuid1; + UINT64 HighPartOfGuid2; + + LowPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1); + LowPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2); + HighPartOfGuid1 = ReadUnaligned64 ((CONST UINT64*) Guid1 + 1); + HighPartOfGuid2 = ReadUnaligned64 ((CONST UINT64*) Guid2 + 1); + + return (BOOLEAN) (LowPartOfGuid1 == LowPartOfGuid2 && HighPartOfGuid1 == HighPartOfGuid2); +} + +/** + Scans a target buffer for a GUID, and returns a pointer to the matching GUID + in the target buffer. + + This function searches target the buffer specified by Buffer and Length from + the lowest address to the highest address at 128-bit increments for the 128-bit + GUID value that matches Guid. If a match is found, then a pointer to the matching + GUID in the target buffer is returned. If no match is found, then NULL is returned. + If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Buffer is not aligned on a 32-bit boundary, then ASSERT(). + If Length is not aligned on a 128-bit boundary, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Guid Value to search for in the target buffer. + + @return A pointer to the matching Guid in the target buffer or NULL otherwise. + +**/ +VOID * +EFIAPI +ScanGuid ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN CONST GUID *Guid + ) +{ + CONST GUID *GuidPtr; + + ASSERT (((UINTN)Buffer & (sizeof (Guid->Data1) - 1)) == 0); + ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); + ASSERT ((Length & (sizeof (*GuidPtr) - 1)) == 0); + + GuidPtr = (GUID*)Buffer; + Buffer = GuidPtr + Length / sizeof (*GuidPtr); + while (GuidPtr < (CONST GUID*)Buffer) { + if (CompareGuid (GuidPtr, Guid)) { + return (VOID*)GuidPtr; + } + GuidPtr++; + } + return NULL; +} diff --git a/MdePkg/Library/UefiMemoryLib/MemLibInternals.h b/MdePkg/Library/UefiMemoryLib/MemLibInternals.h new file mode 100644 index 0000000000..27c3c71851 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/MemLibInternals.h @@ -0,0 +1,241 @@ +/** @file + Declaration of internal functions for Base Memory Library. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#ifndef __MEM_LIB_INTERNALS__ +#define __MEM_LIB_INTERNALS__ + + +#include + + +#include +#include +#include +#include + +/** + Copy Length bytes from Source to Destination. + + @param DestinationBuffer Target of copy + @param SourceBuffer Place to copy from + @param Length Number of bytes to copy + + @return Destination + +**/ +VOID * +EFIAPI +InternalMemCopyMem ( + OUT VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ); + +/** + Set Buffer to Value for Size bytes. + + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT8 Value + ); + +/** + Fills a target buffer with a 16-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem16 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ); + +/** + Fills a target buffer with a 32-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem32 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ); + +/** + Fills a target buffer with a 64-bit value, and returns the target buffer. + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemSetMem64 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ); + +/** + Set Buffer to 0 for Size bytes. + + @param Buffer Memory to set. + @param Length Number of bytes to set + + @return Buffer + +**/ +VOID * +EFIAPI +InternalMemZeroMem ( + OUT VOID *Buffer, + IN UINTN Length + ); + +/** + Compares two memory buffers of a given length. + + @param DestinationBuffer First memory buffer + @param SourceBuffer Second memory buffer + @param Length Length of DestinationBuffer and SourceBuffer memory + regions to compare. Must be non-zero. + + @return 0 All Length bytes of the two buffers are identical. + @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + +**/ +INTN +EFIAPI +InternalMemCompareMem ( + IN CONST VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ); + +/** + Scans a target buffer for an 8-bit value, and returns a pointer to the + matching 8-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem8 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT8 Value + ); + +/** + Scans a target buffer for a 16-bit value, and returns a pointer to the + matching 16-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem16 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ); + +/** + Scans a target buffer for a 32-bit value, and returns a pointer to the + matching 32-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem32 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ); + +/** + Scans a target buffer for a 64-bit value, and returns a pointer to the + matching 64-bit value in the target buffer. + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. Must be non-zero. + @param Value Value to search for in the target buffer. + + @return Pointer to the first occurrence or NULL if not found. + +**/ +CONST VOID * +EFIAPI +InternalMemScanMem64 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ); + +#endif diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c new file mode 100644 index 0000000000..e11c4844b7 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c @@ -0,0 +1,67 @@ +/** @file + ScanMem16() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + + +#include "MemLibInternals.h" + +/** + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. + + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Buffer is not aligned on a 16-bit boundary, then ASSERT(). + If Length is not aligned on a 16-bit boundary, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. + + @return A pointer to the matching byte in the target buffer or NULL otherwise. + +**/ +VOID * +EFIAPI +ScanMem16 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ) +{ + if (Length == 0) { + return NULL; + } + + ASSERT (Buffer != NULL); + ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c new file mode 100644 index 0000000000..52f2d2d603 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c @@ -0,0 +1,66 @@ +/** @file + ScanMem32() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. + + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Buffer is not aligned on a 32-bit boundary, then ASSERT(). + If Length is not aligned on a 32-bit boundary, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. + + @return A pointer to the matching byte in the target buffer or NULL otherwise. + +**/ +VOID * +EFIAPI +ScanMem32 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ) +{ + if (Length == 0) { + return NULL; + } + + ASSERT (Buffer != NULL); + ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c new file mode 100644 index 0000000000..642420b1c9 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c @@ -0,0 +1,66 @@ +/** @file + ScanMem64() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. + + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Buffer is not aligned on a 64-bit boundary, then ASSERT(). + If Length is not aligned on a 64-bit boundary, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. + + @return A pointer to the matching byte in the target buffer or NULL otherwise. + +**/ +VOID * +EFIAPI +ScanMem64 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ) +{ + if (Length == 0) { + return NULL; + } + + ASSERT (Buffer != NULL); + ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c new file mode 100644 index 0000000000..9dc9343eb2 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c @@ -0,0 +1,62 @@ +/** @file + ScanMem8() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + + +#include "MemLibInternals.h" + +/** + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. + + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. + + @return A pointer to the matching byte in the target buffer or NULL otherwise. + +**/ +VOID * +EFIAPI +ScanMem8 ( + IN CONST VOID *Buffer, + IN UINTN Length, + IN UINT8 Value + ) +{ + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c new file mode 100644 index 0000000000..c5a6f8f7dc --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c @@ -0,0 +1,65 @@ +/** @file + SetMem16() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Fills a target buffer with a 16-bit value, and returns the target buffer. + + This function fills Length bytes of Buffer with the 16-bit value specified by + Value, and returns Buffer. Value is repeated every 16-bits in for Length + bytes of Buffer. + + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Buffer is not aligned on a 16-bit boundary, then ASSERT(). + If Length is not aligned on a 16-bit boundary, then ASSERT(). + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer. + +**/ +VOID * +EFIAPI +SetMem16 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT16 Value + ) +{ + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c new file mode 100644 index 0000000000..c5da3d6941 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c @@ -0,0 +1,66 @@ +/** @file + SetMem32() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + + +#include "MemLibInternals.h" + +/** + Fills a target buffer with a 32-bit value, and returns the target buffer. + + This function fills Length bytes of Buffer with the 32-bit value specified by + Value, and returns Buffer. Value is repeated every 32-bits in for Length + bytes of Buffer. + + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Buffer is not aligned on a 32-bit boundary, then ASSERT(). + If Length is not aligned on a 32-bit boundary, then ASSERT(). + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer. + +**/ +VOID * +EFIAPI +SetMem32 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT32 Value + ) +{ + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c new file mode 100644 index 0000000000..129a38ec8d --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c @@ -0,0 +1,66 @@ +/** @file + SetMem64() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + + +#include "MemLibInternals.h" + +/** + Fills a target buffer with a 64-bit value, and returns the target buffer. + + This function fills Length bytes of Buffer with the 64-bit value specified by + Value, and returns Buffer. Value is repeated every 64-bits in for Length + bytes of Buffer. + + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Buffer is not aligned on a 64-bit boundary, then ASSERT(). + If Length is not aligned on a 64-bit boundary, then ASSERT(). + + @param Buffer Pointer to the target buffer to fill. + @param Length Number of bytes in Buffer to fill. + @param Value Value with which to fill Length bytes of Buffer. + + @return Buffer. + +**/ +VOID * +EFIAPI +SetMem64 ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT64 Value + ) +{ + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); + ASSERT ((Length & (sizeof (Value) - 1)) == 0); + + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c b/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c new file mode 100644 index 0000000000..2b25f5fb35 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c @@ -0,0 +1,56 @@ +/** @file + SetMem() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + +#include "MemLibInternals.h" + +/** + Fills a target buffer with a byte value, and returns the target buffer. + + This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Memory to set. + @param Length Number of bytes to set. + @param Value Value of the set operation. + + @return Buffer. + +**/ +VOID * +EFIAPI +SetMem ( + OUT VOID *Buffer, + IN UINTN Length, + IN UINT8 Value + ) +{ + if (Length == 0) { + return Buffer; + } + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); +} diff --git a/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf new file mode 100644 index 0000000000..648a69dd17 --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf @@ -0,0 +1,59 @@ +#/** @file +# Component description file for Dxe Memory Library. +# +# Base Memory Library implementation that uses EFI Boot Services +# where possible for size reduction. +# Copyright (c) 2006, Intel Corporation. +# +# All rights reserved. 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. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiMemoryLib + FILE_GUID = f1bbe03d-2f28-4dee-bec7-d98d7a30c36a + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = BaseMemoryLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources.common] + ScanMem64Wrapper.c + ScanMem32Wrapper.c + ScanMem16Wrapper.c + ScanMem8Wrapper.c + ZeroMemWrapper.c + CompareMemWrapper.c + SetMem64Wrapper.c + SetMem32Wrapper.c + SetMem16Wrapper.c + SetMemWrapper.c + CopyMemWrapper.c + MemLibGeneric.c + MemLibGuid.c + MemLib.c + MemLibInternals.h + + +[Packages] + MdePkg/MdePkg.dec + + +[LibraryClasses] + BaseLib + UefiBootServicesTableLib + DebugLib + diff --git a/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c b/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c new file mode 100644 index 0000000000..30c848a46d --- /dev/null +++ b/MdePkg/Library/UefiMemoryLib/ZeroMemWrapper.c @@ -0,0 +1,52 @@ +/** @file + ZeroMem() implementation. + + Copyright (c) 2006, Intel Corporation
+ All rights reserved. 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. + + The following BaseMemoryLib instances contain the same copy of this file: + + BaseMemoryLib + BaseMemoryLibMmx + BaseMemoryLibSse2 + BaseMemoryLibRepStr + BaseMemoryLibOptDxe + BaseMemoryLibOptPei + PeiMemoryLib + DxeMemoryLib + +**/ + + +#include "MemLibInternals.h" + +/** + Fills a target buffer with zeros, and returns the target buffer. + + This function fills Length bytes of Buffer with zeros, and returns Buffer. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer Pointer to the target buffer to fill with zeros. + @param Length Number of bytes in Buffer to fill with zeros. + + @return Buffer. + +**/ +VOID * +EFIAPI +ZeroMem ( + OUT VOID *Buffer, + IN UINTN Length + ) +{ + ASSERT (!(Buffer == NULL && Length > 0)); + ASSERT (Length <= (MAX_ADDRESS - (UINTN)Buffer + 1)); + return InternalMemZeroMem (Buffer, Length); +} -- cgit v1.2.3