]> git.proxmox.com Git - mirror_edk2.git/log
mirror_edk2.git
6 years agoMdeModulePkg/DxeIpl: Enable paging for Stack Guard
Jian J Wang [Thu, 7 Dec 2017 12:17:49 +0000 (20:17 +0800)]
MdeModulePkg/DxeIpl: Enable paging for Stack Guard

Stack guard feature makes use of paging mechanism to monitor if there's a
stack overflow occurred during boot.

This patch will check setting of PCD PcdCpuStackGuard. If it's TRUE, DxeIpl
will setup page table and set the page at which the stack base locates to be
NOT PRESENT. If stack is used up and memory access cross into the last page
of it, #PF exception will be triggered.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoMdeModulePkg/Core/Dxe: Call new API InitializeCpuExceptionHandlersEx instead
Jian J Wang [Thu, 7 Dec 2017 12:17:32 +0000 (20:17 +0800)]
MdeModulePkg/Core/Dxe: Call new API InitializeCpuExceptionHandlersEx instead

Original API InitializeCpuExceptionHandlers is used in DxeMain to initialize
exception handlers but it does not support setting up stack switch required
by Stack Guard feature. Using the new API instead to make sure Stack Guard
feature is applicable to most part of code.

Since this API is called before memory service initialization, there's no
way to call AllocateXxx API to reserve memory. Global variables are used
for this special case. GDT table is reserved at least 2KB which should be
big enough for all current use cases.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoUefiCpuPkg/CpuDxe: Initialize stack switch for MP
Jian J Wang [Thu, 7 Dec 2017 12:17:05 +0000 (20:17 +0800)]
UefiCpuPkg/CpuDxe: Initialize stack switch for MP

In current MP implementation, BSP and AP shares the same exception
configuration. Stack switch required by Stack Guard feature needs that BSP
and AP have their own configuration. This patch adds code to ask BSP and AP
to do exception handler initialization separately.

Since AP is not supposed to do memory allocation, all memory needed to
setup stack switch will be reserved in BSP and pass to AP via new API

  EFI_STATUS
  EFIAPI
  InitializeCpuExceptionHandlersEx (
    IN EFI_VECTOR_HANDOFF_INFO            *VectorInfo OPTIONAL,
    IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL
    );

Following two new PCDs are introduced to configure how to setup new stack
for specified exception handlers.

  gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
  gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize

Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoUefiCpuPkg/MpLib: Add GDTR, IDTR and TR in saved AP data
Jian J Wang [Thu, 7 Dec 2017 12:16:29 +0000 (20:16 +0800)]
UefiCpuPkg/MpLib: Add GDTR, IDTR and TR in saved AP data

In current implementation of CPU MP service, AP is initialized with data
copied from BSP. Stack switch required by Stack Guard feature needs different
GDT, IDT table and task gates for each logic processor. This patch adds GDTR,
IDTR and TR into structure CPU_VOLATILE_REGISTERS and related code in save
and restore methods. This can make sure that any changes to GDT, IDT and task
gate for an AP will be kept from overwritten by BSP settings.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoArmPkg/ArmExceptionLib: Add implementation of new API
Jian J Wang [Thu, 7 Dec 2017 12:16:04 +0000 (20:16 +0800)]
ArmPkg/ArmExceptionLib: Add implementation of new API

This patch add implementation of following new API introduced into
CpuExceptionHandlerLib. Since this lib hasn't support Stack Guard
and stack switch, the new method just calls original
InitializeCpuExceptionHandlers.

  EFI_STATUS
  EFIAPI
  InitializeCpuExceptionHandlersEx (
    IN EFI_VECTOR_HANDOFF_INFO            *VectorInfo OPTIONAL,
    IN CPU_EXCEPTION_INIT_DATA            *InitDataEx OPTIONAL
    );

Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoMdeModulePkg/CpuExceptionHandlerLibNull: Add new API implementation
Jian J Wang [Thu, 7 Dec 2017 12:15:30 +0000 (20:15 +0800)]
MdeModulePkg/CpuExceptionHandlerLibNull: Add new API implementation

This patch add implementation of new API InitializeCpuExceptionHandlersEx
introduced into CpuExceptionHandlerLib on behalf of Stack Guard feature.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoUefiCpuPkg/CpuExceptionHandlerLib: Add stack switch support
Jian J Wang [Thu, 7 Dec 2017 12:15:12 +0000 (20:15 +0800)]
UefiCpuPkg/CpuExceptionHandlerLib: Add stack switch support

If Stack Guard is enabled and there's really a stack overflow happened during
boot, a Page Fault exception will be triggered. Because the stack is out of
usage, the exception handler, which shares the stack with normal UEFI driver,
cannot be executed and cannot dump the processor information.

Without those information, it's very difficult for the BIOS developers locate
the root cause of stack overflow. And without a workable stack, the developer
cannot event use single step to debug the UEFI driver with JTAG debugger.

In order to make sure the exception handler to execute normally after stack
overflow. We need separate stacks for exception handlers in case of unusable
stack.

IA processor allows to switch to a new stack during handling interrupt and
exception. But X64 and IA32 provides different ways to make it. X64 provides
interrupt stack table (IST) to allow maximum 7 different exceptions to have
new stack for its handler. IA32 doesn't have IST mechanism and can only use
task gate to do it since task switch allows to load a new stack through its
task-state segment (TSS).

The new API, InitializeCpuExceptionHandlersEx, is implemented to complete
extra initialization for stack switch of exception handler. Since setting
up stack switch needs allocating new memory for new stack, new GDT table
and task-state segment but the initialization method will be called in
different phases which have no consistent way to reserve those memory, this
new API is allowed to pass the reserved resources to complete the extra
works. This is cannot be done by original InitializeCpuExceptionHandlers.

Considering exception handler initialization for MP situation, this new API
is also necessary, because AP is not supposed to allocate memory. So the
memory needed for stack switch have to be reserved in BSP before waking up
AP and then pass them to InitializeCpuExceptionHandlersEx afterwards.

Since Stack Guard feature is available only for DXE phase at this time, the
new API is fully implemented for DXE only. Other phases implement a dummy
one which just calls InitializeCpuExceptionHandlers().

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoMdePkg/BaseLib: Add stack switch related definitions for IA32
Jian J Wang [Thu, 7 Dec 2017 12:14:35 +0000 (20:14 +0800)]
MdePkg/BaseLib: Add stack switch related definitions for IA32

The new definitions include two structures

  IA32_TASK_STATE_SEGMENT
  IA32_TSS_DESCRIPTOR

two macros

  IA32_GDT_TYPE_TSS
  IA32_GDT_ALIGNMENT

and one API

  VOID
  EFIAPI
  AsmWriteTr (
    IN UINT16 Selector
    );

They're needed to setup task gate and interrupt stack table for stack switch.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoMdeModulePkg/CpuExceptionHandlerLib.h: Add a new API InitializeCpuExceptionHandlersEx
Jian J Wang [Thu, 7 Dec 2017 12:14:10 +0000 (20:14 +0800)]
MdeModulePkg/CpuExceptionHandlerLib.h: Add a new API InitializeCpuExceptionHandlersEx

A new API InitializeCpuExceptionHandlersEx() is introduced to support
initializing exception handlers with extra functionalities which need
extra init data, such as stack switch for Stack Guard feature.

EFI_STATUS
  EFIAPI
  InitializeCpuExceptionHandlersEx (
    IN EFI_VECTOR_HANDOFF_INFO            *VectorInfo OPTIONAL,
    IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL
    );

By default, this method should include all functionalities implemented by
InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
This is could be done by calling InitializeCpuExceptionHandlers() directly
in this method besides the extra works.

InitData is optional and its use and content are processor arch dependent.
The typical usage of it is to convey resources which have to be reserved
elsewhere and are necessary for the extra initialization of exception.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoUefiCpuPkg/UefiCpuPkg.dec: Add two new PCDs for stack switch
Jian J Wang [Thu, 7 Dec 2017 12:13:30 +0000 (20:13 +0800)]
UefiCpuPkg/UefiCpuPkg.dec: Add two new PCDs for stack switch

Stack switch is required by Stack Guard feature. Following two PCDs are
introduced to simplify the resource allocation for initializing stack switch.

  gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
  gUefiCpuPkgTokenSpaceGuid.PcdCpuKnownGoodStackSize

PcdCpuStackSwitchExceptionList is used to specify which exception will
have separate stack for its handler. For Stack Guard feature, #PF must
be specified at least.

PcdCpuKnownGoodStackSize is used to specify the size of knwon good stack for an
exception handler. Cpu driver or other drivers should use this PCD to reserve
new stack memory for exceptions specified by above PCD.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoMdeModulePkg/metafile: Add PCD PcdCpuStackGuard
Jian J Wang [Thu, 12 Oct 2017 04:28:47 +0000 (12:28 +0800)]
MdeModulePkg/metafile: Add PCD PcdCpuStackGuard

PcdCpuStackGuard is introduced to enable/disable Stack Guard feature.
Its value is FALSE by default. This feature is suggested to be enabled
only if the cpu driver and CpuExceptionHandlerLib have supported stack
switch for the processor used in platform. Otherwise the exception dump
message won't be printed out when there's a stack overflow happened.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Suggested-by: Ayellet Wolman <ayellet.wolman@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jeff Fan <vanjeff_919@hotmail.com>
Reviewed-by: Jiewen.yao@intel.com
6 years agoIntelFrameworkModulePkg/KeyboardDxe: Use macro to enable/disable page 0
Jian J Wang [Thu, 7 Dec 2017 09:00:50 +0000 (17:00 +0800)]
IntelFrameworkModulePkg/KeyboardDxe: Use macro to enable/disable page 0

Current implementation uses following two methods

    EnableNullDetection()
    DisableNullDetection()

to enable/disable page 0. These two methods will check PCD
PcdNullPointerDetectionPropertyMask to know if the page 0 is disabled or not.
This is due to the fact that old GCD service doesn't provide paging related
attributes of memory block. Since this issue has been fixed, GCD services
can be used to determine the paging status of page 0. This is also make it
possible to just use a new macro

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

to replace above methods to do the same job, which also makes code more
readability.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
6 years agoIntelFrameworkModulePkg/LegacyBios: Use macro to enable/disable page 0
Jian J Wang [Thu, 7 Dec 2017 09:00:23 +0000 (17:00 +0800)]
IntelFrameworkModulePkg/LegacyBios: Use macro to enable/disable page 0

Current implementation uses following two methods

    EnableNullDetection()
    DisableNullDetection()

to enable/disable page 0. These two methods will check PCD
PcdNullPointerDetectionPropertyMask to know if the page 0 is disabled or not.
This is due to the fact that old GCD service doesn't provide paging related
attributes of memory block. Since this issue has been fixed, GCD services
can be used to determine the paging status of page 0. This is also make it
possible to just use a new macro

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

to replace above methods to do the same job, which also makes code more
readability.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
6 years agoIntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access
Jian J Wang [Tue, 5 Dec 2017 07:57:38 +0000 (15:57 +0800)]
IntelFrameworkPkg/LegacyBios.h: Add a macro to guarantee page 0 access

Due to the introduction of NULL pointer detection feature, page 0 will be
disabled if the feature is enabled, which will cause legacy code failed to
update legacy data in page 0. This macro is introduced to make sure the
page 0 is enabled before those code and restore the original status of it
afterwards.

Another reason to introduce this macro is to eliminate the dependency on
the PcdNullPointerDetectionPropertyMask. Because this is a new PCD, it
could cause some backward compatibility issue for some old packages.

This macro will simply check if the page 0 is disabled or not. If it's
disabled, it will enable it before code updating page 0 and disable it
afterwards. Otherwise, this macro will do nothing to page 0.

The usage of the macro will be look like (similar to DEBUG_CODE macro):

    ACCESS_PAGE0_CODE(
      <code accessing page 0>
    );

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
6 years agoSourceLevelDebugPkg/SecPeiDebugAgentLib: Fix duplicate symbol
Michael Kinney [Tue, 23 May 2017 23:21:13 +0000 (07:21 +0800)]
SourceLevelDebugPkg/SecPeiDebugAgentLib: Fix duplicate symbol

https://bugzilla.tianocore.org/show_bug.cgi?id=573
https://bugzilla.tianocore.org/show_bug.cgi?id=796

The same issue is reported again by GCC. Resend this patch again.
This patch renames the duplicated function name to fix it.

The SecPeiDebugAgentLib uses the global variable
mMemoryDiscoveredNotifyList for a PPI notification on
the Memory Discovered PPI.  This same variable name is
used in the DxeIplPeim for the same PPI notification.

The XCODE5 tool chain detects this duplicate symbol
when the OVMF platform is built with the flag
-D SOURCE_DEBUG_ENABLE.

The fix is to rename this global variable in the
SecPeiDebugAgentLib library.

Cc: Andrew Fish <afish@apple.com>
Cc: Jeff Fan <jeff.fan@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoSignedCapsulePkg: Update EdkiiSystemCapsuleLib to check PCD value
Liming Gao [Tue, 28 Nov 2017 03:26:34 +0000 (11:26 +0800)]
SignedCapsulePkg: Update EdkiiSystemCapsuleLib to check PCD value

If PCD value is not set, register PcdCallBack to hook PCD value set

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
6 years agoUefiCpuPkg: Update SecCore to get BFV size based on BFV header FvLength
Liming Gao [Wed, 6 Dec 2017 08:02:28 +0000 (16:02 +0800)]
UefiCpuPkg: Update SecCore to get BFV size based on BFV header FvLength

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoUefiCpuPkg: SmmCpuFeaturesLib Add the missing ASM_PFX in nasm code
Liming Gao [Thu, 7 Dec 2017 03:42:10 +0000 (11:42 +0800)]
UefiCpuPkg: SmmCpuFeaturesLib Add the missing ASM_PFX in nasm code

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
6 years agoUefiCpuPkg: PiSmmCpuDxeSmm Add the missing ASM_PFX in nasm code
Liming Gao [Thu, 30 Nov 2017 07:24:19 +0000 (15:24 +0800)]
UefiCpuPkg: PiSmmCpuDxeSmm Add the missing ASM_PFX in nasm code

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
6 years agoUefiCpuPkg PiSmmCpuDxeSmm: SMM profile and static paging mutual exclusion
Star Zeng [Thu, 7 Dec 2017 09:00:48 +0000 (17:00 +0800)]
UefiCpuPkg PiSmmCpuDxeSmm: SMM profile and static paging mutual exclusion

SMM profile and static paging could not be enabled at the same time,
this patch is to add check and comments to make sure it.

Similar comments are also added for the case of static paging and
heap guard for SMM.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/NetLib: Fix an error when AIP doesn't support network media state detection
fanwang2 [Fri, 8 Dec 2017 01:08:24 +0000 (09:08 +0800)]
MdeModulePkg/NetLib: Fix an error when AIP doesn't support network media state detection

AIP may not support detecting network media state, in this case,
should call NetLibDetectMedia to get media state. This patch is to
fix this issue.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan <fan.wang@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
6 years agoUefiCpuPkg PiSmmCpuDxeSmm: Only DumpCpuContext in error case
Star Zeng [Wed, 6 Dec 2017 11:02:04 +0000 (19:02 +0800)]
UefiCpuPkg PiSmmCpuDxeSmm: Only DumpCpuContext in error case

Only DumpCpuContext in error case, otherwise there will be too many
debug messages from DumpCpuContext() when SmmProfile feature is enabled
by setting PcdCpuSmmProfileEnable to TRUE. Those debug messages are not
needed for SmmProfile feature as it will record those information to
buffer for further dump.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
6 years agoBaseTools: Fix GenSec can't found the depex file
Yunhua Feng [Thu, 7 Dec 2017 03:35:16 +0000 (11:35 +0800)]
BaseTools: Fix GenSec can't found the depex file

Filter the FileList when multiple genfds thread options is not enabled.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdePkg: Arm/AArch64 - filter #pragma pack() when __ASSEMBLER__
Leif Lindholm [Wed, 6 Dec 2017 16:57:55 +0000 (16:57 +0000)]
MdePkg: Arm/AArch64 - filter #pragma pack() when __ASSEMBLER__

clang, when used as a preprocessor for dtc, does not discard #pragma
statements although -x assembler-with-cpp is specified. This causes dtc
to barf at a #pragma pack() statement that is already filtered out for
__GNUC__. So add a check to also filter this out if __ASSEMBLER__.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg PiSmmIpl: Handle CommSize OPTIONAL case
Star Zeng [Tue, 7 Nov 2017 05:42:21 +0000 (13:42 +0800)]
MdeModulePkg PiSmmIpl: Handle CommSize OPTIONAL case

Handle CommSize OPTIONAL case for SmmCommunicate.
And return EFI_ACCESS_DENIED when CommunicationBuffer
is not valid for SMM to access.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
6 years agoMdePkg MmCommunication.h: Follow PI spec to update EFI_MM_COMMUNICATE
Star Zeng [Tue, 5 Dec 2017 03:23:18 +0000 (11:23 +0800)]
MdePkg MmCommunication.h: Follow PI spec to update EFI_MM_COMMUNICATE

Follow PI spec (>= 1.5) to add new return status code description
and make CommSize OPTIONAL.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
6 years agoEmulatorPkg: Fix build failure due to Tftp library removal
Ruiyu Ni [Tue, 28 Nov 2017 07:51:17 +0000 (15:51 +0800)]
EmulatorPkg: Fix build failure due to Tftp library removal

The TFTP command was converted from a NULL class library instance to
a dynamic shell command in commit 0961002352e9.

The ShellLib and FileHandleLib resolutions are moved from
Shell app <LibraryClasses> to [LibraryClasses.common]
because dynamic shell commands implemented as DXE_DRIVER modules
also depend on these libraries.

PcdShellLibAutoInitialize must be set to FALSE for both the shell app
itself and the dynamic shell command modules.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
6 years agoEmbeddedPkg: AndroidBootApp: fix clang compilation
Leif Lindholm [Wed, 6 Dec 2017 17:29:26 +0000 (17:29 +0000)]
EmbeddedPkg: AndroidBootApp: fix clang compilation

Address an incorrect function prototype (using ; instead of ,)
in AndroidBootImg.h.

Also restructure code slightly to avoid a "may be used uninitialized"
warning.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoArmVirtPkg: add NOOPT target to platform .DSCs
Ard Biesheuvel [Wed, 6 Dec 2017 11:35:15 +0000 (11:35 +0000)]
ArmVirtPkg: add NOOPT target to platform .DSCs

In order to allow the ArmVirtPkg platforms to be built using the
NOOPT target, add it explicitly to the BUILD_TARGETS define.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY...
fanwang2 [Wed, 6 Dec 2017 05:00:21 +0000 (13:00 +0800)]
MdeModulePkg/NetLib: Add NetLibDetectMediaWaitTimeout() API to support EFI_NOT_READY media state detection

In wireless connection, connecting state needs to be cared more
about. ECR 1772 redefined the state EFI_NOT_READY to represent
connecting state and can be retrieved from Aip protocol. This
patch adds a new API to check media state at a specified time
interval when network is connecting until the connection process
finishes or timeout.

V2:
  * Return error status code directly when Aip protocol falied to detect
    media rather than wait for another time's check.
  * Set media state default value to EFI_SUCCESS since some platforms may
    not support retrieving media state from Aip protocol.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wang Fan <fan.wang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
6 years agoBaseTools: Fix GenSec GCC make failure
Yonghong Zhu [Tue, 5 Dec 2017 13:52:40 +0000 (21:52 +0800)]
BaseTools: Fix GenSec GCC make failure

It is a regression bug introduced by the patch b37b108, it cause GenSec
make failure on GCC Env.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Tested-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg/DisplayEngineDxe: Remove unnecessary parentheses in 'if'
Hao Wu [Tue, 5 Dec 2017 05:13:07 +0000 (13:13 +0800)]
MdeModulePkg/DisplayEngineDxe: Remove unnecessary parentheses in 'if'

This commit removes unnecessary parentheses in 'if' statements to
resolve the build failures by the XCODE5 tool chain.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg/PartitionDxe: Remove unnecessary parentheses in 'if'
Hao Wu [Mon, 4 Dec 2017 05:19:28 +0000 (13:19 +0800)]
MdeModulePkg/PartitionDxe: Remove unnecessary parentheses in 'if'

This commit removes unnecessary parentheses in 'if' statements to
resolve the build failures by the XCODE5 tool chain.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg/Core/Dxe: log informative memprotect msgs at DEBUG_INFO level
Laszlo Ersek [Mon, 4 Dec 2017 19:21:56 +0000 (20:21 +0100)]
MdeModulePkg/Core/Dxe: log informative memprotect msgs at DEBUG_INFO level

In commit 7eb927db3e25 ("MdeModulePkg/DxeCore: implement memory protection
policy", 2017-02-24), we added two informative messages with the
InitializeDxeNxMemoryProtectionPolicy() function:

> InitializeDxeNxMemoryProtectionPolicy: applying strict permissions to
> active memory regions

and

> InitializeDxeNxMemoryProtectionPolicy: applying strict permissions to
> inactive memory regions

The messages don't report errors or warnings, thus downgrade their log
masks from DEBUG_ERROR to DEBUG_INFO.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1520485
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoNetworkPkg: Update IScsiDxe to pass XCODE build
Liming Gao [Tue, 28 Nov 2017 03:19:23 +0000 (11:19 +0800)]
NetworkPkg: Update IScsiDxe to pass XCODE build

Fix the warning equality comparison with extraneous parentheses
[-Werror,-Wparentheses-equality].

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liang Vincent <vincent.liang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
6 years agoMdeModulePkg: Update PeiCore to pass XCODE tool chain
Liming Gao [Tue, 28 Nov 2017 03:19:58 +0000 (11:19 +0800)]
MdeModulePkg: Update PeiCore to pass XCODE tool chain

It fixes the warning for loop has empty body [-Werror,-Wempty-body].

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liang Vincent <vincent.liang@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoMdeModulePkg CapsulePei: Sort and merge memory resource entries
Star Zeng [Fri, 17 Nov 2017 05:56:37 +0000 (13:56 +0800)]
MdeModulePkg CapsulePei: Sort and merge memory resource entries

Sort and merge memory resource entries to handle the case that
the memory resource HOBs are reported differently between
BOOT_ON_FLASH_UPDATE boot mode and normal boot mode, and the
capsule buffer from UpdateCapsule at normal boot sits across
two memory resource descriptors at BOOT_ON_FLASH_UPDATE boot mode.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Dakota Chiang <dakota.chiang@intel.com>
Tested-by: Dakota Chiang <dakota.chiang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
6 years agoBaseTools: Update Makefile to support FFS file generation
Yonghong Zhu [Wed, 22 Nov 2017 07:42:25 +0000 (15:42 +0800)]
BaseTools: Update Makefile to support FFS file generation

Update Makefile to support FFS file generation with new build option
--genfds-multi-thread.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoBaseTools: Update Gensec to set PROCESSING_REQUIRED value
Yonghong Zhu [Wed, 29 Nov 2017 03:45:22 +0000 (11:45 +0800)]
BaseTools: Update Gensec to set PROCESSING_REQUIRED value

This patch add new option --dummy file, and we compare the dummpy file
with input file to decide whether we need to set PROCESSING_REQUIRED
value.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoBaseTools: Update Trim to generate VfrBinOffset Binary
Yonghong Zhu [Thu, 28 Sep 2017 23:54:12 +0000 (07:54 +0800)]
BaseTools: Update Trim to generate VfrBinOffset Binary

Its usage is
"Trim --Vfr-Uni-Offset -o $(OUTPUT_DIR)(+)$(MODULE_NAME)VfrOffset.sec
--ModuleName=$(MODULE_NAME) --DebugDir=$(DEBUG_DIR)"

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoBaseTools: GenFfs support to get alignment value from SectionFile
Yonghong Zhu [Thu, 28 Sep 2017 23:53:30 +0000 (07:53 +0800)]
BaseTools: GenFfs support to get alignment value from SectionFile

Update GenFfs tool to get alignment value from SectionFile when use
the new option -n 0.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg/NvmExpressDxe: fix error status override
Heyi Guo [Mon, 4 Dec 2017 02:27:54 +0000 (10:27 +0800)]
MdeModulePkg/NvmExpressDxe: fix error status override

Commit f6b139b added return status handling to PciIo->Mem.Write.
However, the second status handling will override EFI_DEVICE_ERROR
returned in this branch:

  //
  // Check the NVMe cmd execution result
  //
  if (Status != EFI_TIMEOUT) {
    if ((Cq->Sct == 0) && (Cq->Sc == 0)) {
      Status = EFI_SUCCESS;
    } else {
      Status = EFI_DEVICE_ERROR;
               ^^^^^^^^^^^^^^^^

Since PciIo->Mem.Write will probably return SUCCESS, it causes
NvmExpressPassThru to return SUCCESS even when DEVICE_ERROR occurs.
Callers of NvmExpressPassThru will then continue executing which may
cause further unexpected results, e.g. DiscoverAllNamespaces couldn't
break out the loop.

So we save previous status before calling PciIo->Mem.Write and restore
the previous one if it already contains error.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoArmPlatformPkg/LcdGraphicsOutputDxe: remove VExpressPkg dependency
Ard Biesheuvel [Mon, 4 Dec 2017 20:46:57 +0000 (20:46 +0000)]
ArmPlatformPkg/LcdGraphicsOutputDxe: remove VExpressPkg dependency

The two instantiations of LcdGraphicsOutputDxe reference VExpressPkg.dec
without actually relying on anything it defines. In preparation of
moving out VExpressPkg into edk2-platforms, drop these references so we
can keep LcdGraphicsOutputDxe in EDK2.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: remove PlatformIntelBdsLib
Ard Biesheuvel [Mon, 4 Dec 2017 16:15:35 +0000 (16:15 +0000)]
ArmPlatformPkg: remove PlatformIntelBdsLib

Now that the last user has switched to the generic BDS, the
PlatformIntelBdsLib code in ArmPlatformPkg is no longer used, so
remove it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmVirtPkg/ArmVirtXen: move from Intel to generic BDS
Ard Biesheuvel [Thu, 30 Nov 2017 20:28:23 +0000 (20:28 +0000)]
ArmVirtPkg/ArmVirtXen: move from Intel to generic BDS

ArmVirtXen is the only remaining consumer of ArmPlatformPkg's
PlatformIntelBdsLib implementation, which is tightly coupled to the
deprecated Intel BDS. So move ArmVirtXen to the generic BDS as well,
allowing us to get rid of PlatformIntelBdsLib entirely.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Julien Grall <julien.grall@linaro.org>
6 years agoShellPkg/ShellPkg.dec: Change comments for PcdShellLibAutoInitialize
Ruiyu Ni [Wed, 29 Nov 2017 08:21:46 +0000 (16:21 +0800)]
ShellPkg/ShellPkg.dec: Change comments for PcdShellLibAutoInitialize

When Dynamic command drivers links to ShellLib, the ShellLib
constructor shouldn't be called because the Shell and ShellParameters
protocols don't exist when the driver starts.
So it's required to set PcdShellLibAutoInitialize to FALSE for
dynamic command drivers.
Update the comments in DEC file to describe such requirement
for this PCD.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
6 years agoQuarkPlatformPkg: Use DpDynamicCommand to replace PerformancePkg/dp
Ruiyu Ni [Wed, 29 Nov 2017 08:12:40 +0000 (16:12 +0800)]
QuarkPlatformPkg: Use DpDynamicCommand to replace PerformancePkg/dp

Remove FvSimpleFileSystemDxe from Quark.dsc/fdf because it's not
needed by using DpDynamicCommand driver.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Kelly Steele <kelly.steele@intel.com>
6 years agoVlv2TbltDevicePkg: Use DpDynamicCommand to replace PerformancePkg/dp
Ruiyu Ni [Wed, 29 Nov 2017 05:36:37 +0000 (13:36 +0800)]
Vlv2TbltDevicePkg: Use DpDynamicCommand to replace PerformancePkg/dp

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: David David <david.wei@intel.com>
6 years agoMdeModulePkg DxeCore: Support USED_SIZE FV_EXT_TYPE
Star Zeng [Tue, 28 Nov 2017 09:04:23 +0000 (17:04 +0800)]
MdeModulePkg DxeCore: Support USED_SIZE FV_EXT_TYPE

The USED_SIZE FV_EXT_TYPE is introduced by PI 1.6 spec.

The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find
out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV.

When the FV gets shadowed into memory you only need to copy the used
bytes into memory and fill the rest of the memory buffer with the
erase value.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg DxeCore: Check FvImage alignment
Star Zeng [Tue, 28 Nov 2017 02:47:19 +0000 (10:47 +0800)]
MdeModulePkg DxeCore: Check FvImage alignment

No need to allocate aligned buffer if FvImage has been
at required alignment.

Then the code logic will be aligned with ProcessFvFile() in
MdeModulePkg/Core/Pei/FwVol/FwVol.c.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdeModulePkg PeiCore: Support USED_SIZE FV_EXT_TYPE
Star Zeng [Wed, 22 Nov 2017 08:13:09 +0000 (16:13 +0800)]
MdeModulePkg PeiCore: Support USED_SIZE FV_EXT_TYPE

The USED_SIZE FV_EXT_TYPE is introduced by PI 1.6 spec.

The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find
out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV.

When the FV gets shadowed into memory you only need to copy the used
bytes into memory and fill the rest of the memory buffer with the
erase value.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoMdePkg PiFirmwareVolume.h: Add USED_SIZE FV_EXT_TYPE definitions
Star Zeng [Tue, 21 Nov 2017 10:51:19 +0000 (18:51 +0800)]
MdePkg PiFirmwareVolume.h: Add USED_SIZE FV_EXT_TYPE definitions

The definitions are introduced by PI 1.6 spec.

The EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE can be used to find
out how many EFI_FVB2_ERASE_POLARITY bytes are at the end of the FV.

When the FV gets shadowed into memory you only need to copy the used
bytes into memory and fill the rest of the memory buffer with the
erase value.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
6 years agoIntelSiliconPkg: Update MicrocodeUpdate build path in dsc
Star Zeng [Fri, 1 Dec 2017 01:19:19 +0000 (09:19 +0800)]
IntelSiliconPkg: Update MicrocodeUpdate build path in dsc

That was missed in 43e12eeac8b125165b8a93c3501925a8893544ef.

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
6 years agoArmPlatformPkg/PrePi: remove bogus IntelFrameworkModulePkg reference
Ard Biesheuvel [Thu, 30 Nov 2017 15:11:45 +0000 (15:11 +0000)]
ArmPlatformPkg/PrePi: remove bogus IntelFrameworkModulePkg reference

PrePi does not use anything from IntelFrameworkModulePkg so remove
the reference from its [Packages] sections.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg/MemoryInitPeiLib: don't reserve primary FV in memory
Meenakshi Aggarwal [Tue, 19 Sep 2017 12:32:09 +0000 (18:02 +0530)]
ArmPlatformPkg/MemoryInitPeiLib: don't reserve primary FV in memory

Now that PrePi no longer exposes its internal code via special HOBs,
we can remove the special handling of the primary FV, which needed to
be reserved so that DXE core could call into the PE/COFF and LZMA
libraries in the PrePi module.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Udit Kumar <udit.kumar@nxp.com>
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
[ardb: updated commit log]
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg/PrePi: don't expose PE/COFF and LZMA libraries via HOBs
Ard Biesheuvel [Thu, 30 Nov 2017 15:18:39 +0000 (15:18 +0000)]
ArmPlatformPkg/PrePi: don't expose PE/COFF and LZMA libraries via HOBs

Avoid the need to preserve all memory exposed by PrePi indefinitely
by removing the 'feature' that exposes the PE/COFF and LZMA libraries
via special HOBs to other modules that may want to reuse the code.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoBeagleBoardPkg: clone MemoryInitPeiLib
Ard Biesheuvel [Thu, 30 Nov 2017 15:00:23 +0000 (15:00 +0000)]
BeagleBoardPkg: clone MemoryInitPeiLib

The common MemoryInitPeiLib implementation preserves the primary FV
holding the PrePi module and the compressed secondary FV, and removes
the memory it occupies from the memory map, hiding it from the OS.

The only platform that actual requires this is BeagleBoardPkg, since
it exposes the PeCoff and LZMA libraries in PrePi to DXE core via
special HOBs. So let's give BeagleBoard its own MemoryInitPeiLib, so
that we can clean up the generic version.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoBeagleBoardPkg: create private PrePi implementation
Ard Biesheuvel [Thu, 30 Nov 2017 14:52:31 +0000 (14:52 +0000)]
BeagleBoardPkg: create private PrePi implementation

Clone the PrePi implementation for BeagleBoardPkg, so we can start
removing some of the awkward optimizations that we'd rather not keep
in reference code. Note that we only clone the unicore ARM flavor,
which is all we need for BeagleBoard.

In the case of PrePi, it involves libraries included by the SEC
startup code that are exposed to DXE core via HOBs containing function
pointers, which forces us to keep the primary FV reserved in memory.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg/PrePi: call all constructors by hand
Ard Biesheuvel [Thu, 30 Nov 2017 15:09:48 +0000 (15:09 +0000)]
ArmPlatformPkg/PrePi: call all constructors by hand

Call ProcessLibraryConstructorList () to invoke all library constructors
by hand rather than calling only some of them explicitly.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoEmbeddedPkg BeagleBoardPkg: move special HOB reuse libraries into platform
Ard Biesheuvel [Thu, 30 Nov 2017 14:41:07 +0000 (14:41 +0000)]
EmbeddedPkg BeagleBoardPkg: move special HOB reuse libraries into platform

The BeagleBoard platform uses PeCoffLib and CustomDecompressLib
implementations that invoke the library code that resides in the PrePi
module via pointers exposed via special GUIDed HOBs. This is a nice hack,
but not necessarily something we want to carry in reference code.

So as a first step, move the libraries that expose this reused code into
BeagleBoardPkg, and remove it from EmbeddedPkg.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: move internal PL031 header into driver directory
Ard Biesheuvel [Thu, 16 Nov 2017 16:34:49 +0000 (16:34 +0000)]
ArmPlatformPkg: move internal PL031 header into driver directory

Move the internal PL031 RTC header file into the driver directory.
It shouldn't be referenced directly by other modules anyway.

While at it, sort the includes as well.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: move internal SP805 header into driver directory
Ard Biesheuvel [Thu, 16 Nov 2017 16:33:06 +0000 (16:33 +0000)]
ArmPlatformPkg: move internal SP805 header into driver directory

Move the internal SP805 watchdog header file into the driver directory.
It shouldn't be referenced directly by other modules anyway.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: move internal PL061 header into driver directory
Ard Biesheuvel [Thu, 16 Nov 2017 16:30:55 +0000 (16:30 +0000)]
ArmPlatformPkg: move internal PL061 header into driver directory

Move the internal PL061 GPIO header file into the driver directory.
It shouldn't be referenced directly by other modules anyway.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: remove ArmPlatformInitializeSystemMemory
Ard Biesheuvel [Thu, 30 Nov 2017 14:00:28 +0000 (14:00 +0000)]
ArmPlatformPkg: remove ArmPlatformInitializeSystemMemory

The function ArmPlatformInitializeSystemMemory() is defined by
ArmPlatformLib, but is only ever called when using the PrePeiCore
flavor of the startup code. Also, none of the remaining upstream
platforms actually implement anything in that function in the first
place. So let's just remove it altogether.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg/ArmPlatformLib: remove ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
Ard Biesheuvel [Thu, 30 Nov 2017 13:54:15 +0000 (13:54 +0000)]
ArmPlatformPkg/ArmPlatformLib: remove ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR

The ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR struct type is defined but
never used anywhere. So remove it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg: remove unused ArmVExpressLibCTA9x4 code
Ard Biesheuvel [Thu, 30 Nov 2017 13:52:03 +0000 (13:52 +0000)]
ArmPlatformPkg: remove unused ArmVExpressLibCTA9x4 code

ArmVExpressLibCTA9x4 is unused, and rather outdated, given that it is
the last ArmPlatformLib implementation that executes both in the secure
and non-secure worlds, which is a model we no longer support for ARM
systems. So remove it.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmPlatformPkg/Documentation: remove outdated porting manual
Ard Biesheuvel [Thu, 30 Nov 2017 13:44:02 +0000 (13:44 +0000)]
ArmPlatformPkg/Documentation: remove outdated porting manual

Having a special porting manual for ARM platforms in general suggests
that ARM platforms are fundamentally different from ones based on other
architectures that are supported by UEFI. There may be some truth to
that, but the porting manual in Documentation/ArmPlatformPkg.txt is
hopelessly outdated, and did not give the best advice in the first
place*. So remove it.

* ArmPlatformLib as the mother of all platform abstractions is rather
  unwieldy, and using ArmVExpressLibCTA9x4 as a template is not that
  great an idea either.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoBeagleBoardPkg: add CapsuleLib resolution
Leif Lindholm [Thu, 30 Nov 2017 13:59:32 +0000 (13:59 +0000)]
BeagleBoardPkg: add CapsuleLib resolution

Commit 4bbcc285d5f7 ("ArmPkg/PlatformBootManagerLib: process pending
capsules") added a dependency on CapsuleLib. Add DxeCapsuleLibNull
resolution to BeagleBoardPkg.dsc to resolve this.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoOmap35xxPkg: add GetTimeInNanoSecond implementation
Leif Lindholm [Thu, 30 Nov 2017 13:55:59 +0000 (13:55 +0000)]
Omap35xxPkg: add GetTimeInNanoSecond implementation

Commit a63be426f8e3 ("ArmPlatformPkg: Store initial timer value") caused
BeagleBoard to stop building, due to Omap35xxTimerLib lacking an
implementation of GetTimeInNanoSecond (). So add one.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoBeagleBoardPkg: Fix build failure due to Tftp library removal
Ruiyu Ni [Wed, 29 Nov 2017 10:15:00 +0000 (18:15 +0800)]
BeagleBoardPkg: Fix build failure due to Tftp library removal

The TFTP command was converted from a NULL class library
instance to a dynamic shell command in commit 0961002352e9.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
6 years agoArmVirtPkg: Fix build failure due to Tftp library removal
Ruiyu Ni [Wed, 29 Nov 2017 10:14:59 +0000 (18:14 +0800)]
ArmVirtPkg: Fix build failure due to Tftp library removal

The TFTP command was converted from a NULL class library instance to a
dynamic shell command in commit 0961002352e9.

The ShellLib and FileHandleLib resolutions are moved from
[LibraryClasses.common.UEFI_APPLICATION] to [LibraryClasses.common]
because dynamic shell commands are implemented as DXE_DRIVER modules.

PcdShellLibAutoInitialize must be set to FALSE for both the shell app
itself and the dynamic shell command modules.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
[lersek@redhat.com: extend commit message]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Build-tested-by: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Julien Grall <julien.grall@linaro.org>
6 years agoEmbeddedPkg: remove nonexistent FLASH_DEFINITION from package .dsc
Leif Lindholm [Thu, 30 Nov 2017 10:14:39 +0000 (10:14 +0000)]
EmbeddedPkg: remove nonexistent FLASH_DEFINITION from package .dsc

For whatever reason, EmbeddedPkg.dsc included a FLASH_DEFINITION entry
pointing to a nonexistent EmbeddedPkg.fdf.

This used to be silently ignored, but recent BaseTools changes
5e9256cd7f54 ("BaseTools: Guid.xref contain information from FILE statements in FDF")
now caused builds against EmbeddedPkg.dsc to fail.
So delete the redundant entry.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoBaseTools: Update C tools top GNUMakefile to adjust tool order
Liming Gao [Tue, 28 Nov 2017 03:18:52 +0000 (11:18 +0800)]
BaseTools: Update C tools top GNUMakefile to adjust tool order

Place the tool that takes much build time at the first. This can improve
build performance when make -j N used.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoBaseTools: Update BaseTools top GNUMakefile with the clear dependency
Liming Gao [Tue, 28 Nov 2017 03:18:51 +0000 (11:18 +0800)]
BaseTools: Update BaseTools top GNUMakefile with the clear dependency

https://bugzilla.tianocore.org/show_bug.cgi?id=786

After GNUmakefile dependency is fixed up, it can make with -j N to enable
multiple thread build in base tools C source and save build time.

In my linux host machine, make -j 4 to compile BaseTools and save ~60% time.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoBaseTools: Replace ARCH with HOST_ARCH in C Makefile to avoid conflict
Liming Gao [Tue, 28 Nov 2017 03:18:50 +0000 (11:18 +0800)]
BaseTools: Replace ARCH with HOST_ARCH in C Makefile to avoid conflict

https://bugzilla.tianocore.org/show_bug.cgi?id=793

ARCH is too generic. It may cause confuse of target arch or host arch.
To be clarified, replace it with HOST_ARCH in BaseTools C Makefile.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoIntelSiliconPkg: Update MicrocodeUpdate to build with the package
Star Zeng [Tue, 21 Nov 2017 10:32:50 +0000 (18:32 +0800)]
IntelSiliconPkg: Update MicrocodeUpdate to build with the package

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=540

This is after patch
"IntelSiliconPkg: Move MicrocodeUpdate from UefiCpuPkg".

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Regression-tested-by: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
6 years agoIntelSiliconPkg: Move MicrocodeUpdate from UefiCpuPkg
Star Zeng [Fri, 17 Nov 2017 06:28:25 +0000 (14:28 +0800)]
IntelSiliconPkg: Move MicrocodeUpdate from UefiCpuPkg

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=540

To consume FIT table for Microcode update,
UefiCpuPkg/Feature/Capsule/MicrocodeUpdateDxe
needs to be updated to consume
IntelSiliconPkg/Include/IndustryStandard/FirmwareInterfaceTable.h,
but UefiCpuPkg could not depend on IntelSiliconPkg.

Since the Microcode update feature is specific to Intel,
we can first move the Microcode update feature code from
UefiCpuPkg to IntelSiliconPkg [first step], then update
the code to consume FIT table [second step].

This patch series is for the first step.

Note: No any code change in this patch, just move.
Next patch will update MicrocodeUpdate to build with the package.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Regression-tested-by: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/SerialDxe: Do not fail reset when SetAttributes is not supported
Julien Grall [Wed, 29 Nov 2017 17:28:23 +0000 (01:28 +0800)]
MdeModulePkg/SerialDxe: Do not fail reset when SetAttributes is not supported

After commit 91cc526b15 "MdeModulePkg/SerialDxe: Fix not able to change
serial attributes", serial is initialized using the reset method that
will call SetAttributes.

However, SetAttributes may return EFI_INVALID_PARAMETER when a driver
does not support some parameters. This will be propagated by the reset
function and lead to UEFI failing to get the console setup.

For instance, this is the case when using the Xen console driver.

Fix it by introspecting the result and return EFI_SUCCESS when the
SetAttributes report an invalid parameter (i.e EFI_INVALID_PARAMETER).

Contributed-under: Tianocore Contribution Agreement 1.1
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/SerialDxe: Fix return valued in SerialSetAttributes
Julien Grall [Wed, 29 Nov 2017 17:28:22 +0000 (01:28 +0800)]
MdeModulePkg/SerialDxe: Fix return valued in SerialSetAttributes

SerialSetAttributes is meant to match the behavior of the function
EFI_SERIAL_IO_PROTOCOL.SetAttributes() in the UEFI spec (v2.7). This
means the function can only return:
    - EFI_SUCCESS
    - EFI_INVALID_PARAMETER
    - EFI_DEVICE_ERROR

However the function SerialPortSetAttributes may also validly return
EFI_UNSUPPORTED. For instance this is the case of the Xen Console
driver.

EFI_UNSUPPORTED could be also interpreted as "One or more of the attributes
has an unsupported value". So return EFI_INVALID_PARAMETER in that case.

Lastly, to prevent another return slipping in the future, all the errors
but EFI_INVALID_PARAMETER and EFI_UNSUPPORTED will return
EFI_DEVICE_ERROR.

Contributed-under: Tianocore Contribution Agreement 1.1
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/SerialDxe: Describe correctly EFI_DEVICE_ERROR for SetAttributes
Julien Grall [Wed, 29 Nov 2017 17:28:21 +0000 (01:28 +0800)]
MdeModulePkg/SerialDxe: Describe correctly EFI_DEVICE_ERROR for SetAttributes

Per the UEFIv2.7 spec, EFI_DEVICE_ERROR is returned when the serial
device is not functioning correctly. Update the description to avoid
confusion.

Contributed-under: Tianocore Contribution Agreement 1.1
Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoMdeModulePkg/DxeCorePerformanceLib: add lock protection
Heyi Guo [Mon, 27 Nov 2017 03:31:44 +0000 (11:31 +0800)]
MdeModulePkg/DxeCorePerformanceLib: add lock protection

DXE performance gauge record access functions might be reentered since
we are supporting something like USB hot-plug, which is a timer event
where gBS->ConnectController might be called and then PERF will be
called in CoreConnectSingleController.

When StartGaugeEx is being reentered, not only the gauge record might
be overwritten, more serious situation will be caused if gauge data
buffer reallocation procedure is interrupted, between line 180 and 187
in DxeCorePerformanceLib.c specifically. There, mMaxGaugeRecords will
be doubled twice (denoted as 4X), but mGaugeData only points to a
buffer of size 2X, which will probably cause the following 2X memory
to be overflowed when gauge records are increased.

So we add EFI lock with TPL_NOTIFY in StartGaugeEx/EndGaugeEx/GetGaugeEx
to avoid memory overflow and gauge data corruption.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoInclude libraries, header files for MdeModulePkg/.../Network maintainer
Star Zeng [Mon, 27 Nov 2017 06:41:05 +0000 (14:41 +0800)]
Include libraries, header files for MdeModulePkg/.../Network maintainer

Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Siyuan Fu <siyuan.fu@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
6 years agoAdd Ruiyu as MdeModulePkg reviewer
Star Zeng [Mon, 27 Nov 2017 06:37:24 +0000 (14:37 +0800)]
Add Ruiyu as MdeModulePkg reviewer

Add Ruiyu as MdeModulePkg reviewer,
especially for some Domains.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
6 years agoNt32Pkg: Add VS2017 support in SecMain
Liming Gao [Wed, 22 Nov 2017 16:26:10 +0000 (00:26 +0800)]
Nt32Pkg: Add VS2017 support in SecMain

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoBaseTools: Update VS batch file to auto detect VS2017
Liming Gao [Wed, 22 Nov 2017 16:26:09 +0000 (00:26 +0800)]
BaseTools: Update VS batch file to auto detect VS2017

This way depends on VS vswhere.exe to find VS2017 installed directory.
vswhere.exe starts in Visual Studio 2017 version 15.2.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoBaseTools: Add VS2017 tool chain in BaseTools tools_def.template
Liming Gao [Wed, 22 Nov 2017 16:26:08 +0000 (00:26 +0800)]
BaseTools: Add VS2017 tool chain in BaseTools tools_def.template

VS2017 tool chain enables /WHOLEARCHIVE linker option
Split host-related and arch-related elements

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoMdePkg: Disable VS warning 4701 & 4703 for VS2017
Liming Gao [Wed, 22 Nov 2017 16:26:07 +0000 (00:26 +0800)]
MdePkg: Disable VS warning 4701 & 4703 for VS2017

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
6 years agoPcAtChipsetPkg: Add description for new added PCD in commit e78aab9d2
Dandan Bi [Tue, 28 Nov 2017 03:44:34 +0000 (11:44 +0800)]
PcAtChipsetPkg: Add description for new added PCD in commit e78aab9d2

Cc: Leo Duran <leo.duran@amd.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
6 years agoIntelFsp2WrapperPkg: Support UPD allocation outside FspWrapper
Chasel, Chiu [Thu, 23 Nov 2017 02:22:45 +0000 (10:22 +0800)]
IntelFsp2WrapperPkg: Support UPD allocation outside FspWrapper

UPD allocation and patching can be done outside FspWrapper
as implementation choice so adding a PCD to select between
original FspWrapper allocation model or outside model

Cc: Jiewen Yao <Jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
6 years agoOvmfPkg: Add tftp dynamic command
Ruiyu Ni [Tue, 28 Nov 2017 08:35:06 +0000 (16:35 +0800)]
OvmfPkg: Add tftp dynamic command

The TFTP command was converted from a NULL class library instance
to a dynamic shell command in commit 0961002352e9.
This patch complements commit f9bc2f876326, which only removed the
old library, but didn't add the new dynamic command。

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien.grall@linaro.org>
6 years agoCorebootPayloadPkg: Fix build failure due to Tftp/Dp library removal
Ruiyu Ni [Tue, 28 Nov 2017 08:27:43 +0000 (16:27 +0800)]
CorebootPayloadPkg: Fix build failure due to Tftp/Dp library removal

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
Reviewed-by: Benjamin You <benjamin.you@intel.com>
6 years agoShellPkg/tftp: Correct file comments header of Tftp.uni
Ruiyu Ni [Tue, 28 Nov 2017 07:46:43 +0000 (15:46 +0800)]
ShellPkg/tftp: Correct file comments header of Tftp.uni

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
6 years agoOvmfPkg/Sec: Fix 64bit SEC build failure
Ruiyu Ni [Mon, 27 Nov 2017 01:38:08 +0000 (09:38 +0800)]
OvmfPkg/Sec: Fix 64bit SEC build failure

Original code breaks a single assembly code to multiple lines.
But, when VS CL.exe preprocesses the FixedPcdGet32() macro
invocation to the replacement text, it loses '\', and causes
NASM to fail.

Changing the multiple lines to one line to resolve the build failure.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
6 years agoShellPkg/DynamicCommand: Fix bug that cannot start in boot
Ruiyu Ni [Tue, 28 Nov 2017 11:43:16 +0000 (19:43 +0800)]
ShellPkg/DynamicCommand: Fix bug that cannot start in boot

When dynamic command drivers are built into FV and start during
boot, they fails. Because Shell protocol doesn't exist during boot.
The patch sets Shell protocol and also set PcdShellLibAutoInitialize
to FALSE to ensure that
1. Shell protocol check doesn't happen in driver's entry point.
2. Driver can get the Shell protocol in DynamicCommand.Handler().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
6 years agoShellPkg/ShellLib: Fix dynamic command fails to start during boot
Ruiyu Ni [Tue, 28 Nov 2017 11:38:39 +0000 (19:38 +0800)]
ShellPkg/ShellLib: Fix dynamic command fails to start during boot

The previous change in ShellLib: "commit
3d29f8c5e361525a0d2accfa7f5bb0a7210b8927
* ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters"
resolved the issue when loading dynamic command driver from Shell
environment.
But when dynamic command driver is built into FV and started during
boot, the driver still fails to start because Shell protocol doesn't
exist at that time.

The patch changes ShellLib to:
1. Do not look for Shell and ShellParameters protocol when they are
   non-NULL in ShellLibConstructorWorker();
   The two protocols are assumed to be set by DynamicCommand.Handler.
   When ShellInitialize() is called in DynamicCommand.Handler, this
   change can prevent the two protocols to be changed to NULL by
   the locating logic.
2. Do not reset the Shell and ShellParameters protocol to NULL in
   ShellLibDestructor() when CloseProtocol() fails;
   Dynamic command driver needs to set the PcdShellLibAutoInitialize
   to FALSE in order to skip the constructor.
   Current logic calls ShellLibDestructor() when the PCD is FALSE when
   ShellInitialize() is called. The change prevent the two protocols
   to be changed to NULL.

The two changes don't impact existing usage case so they are backward
compatible.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
6 years agoShellPkg: Fix the bug that handling Ctrl-C improperly
Ruiyu Ni [Tue, 28 Nov 2017 09:06:32 +0000 (17:06 +0800)]
ShellPkg: Fix the bug that handling Ctrl-C improperly

Current implementation resets the CTRL-C event early when printing
the shell prompt, when user types "<CTRL-C>ls<ENTER>", "ls" command
is terminated immediately when starts.
It's not an expected behavior from users' perspective.
Correct way is to reset the CTRL-C event just before running the
command, which is a bit later than current point.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
6 years agoMdeModulePkg/AtaAtapiPassThru: Revert patch to disable PCI attributes
Ruiyu Ni [Mon, 27 Nov 2017 01:17:24 +0000 (09:17 +0800)]
MdeModulePkg/AtaAtapiPassThru: Revert patch to disable PCI attributes

This patch caused Windows 10 S4 resume failure.
Considering the similar changes are reverted from PciBus driver,
revert the patch from AtaAtapiPassThru as well.

Revert "MdeModulePkg/AtaAtapiPassThru: disable the device
at ExitBootServices()"

This reverts commit 6fb8ddd36bde45614b0a069528cdc97077835a74.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoMdeModulePkg/AtaAtapiPassThru: Revert patch to disable Bus Master
Ruiyu Ni [Mon, 27 Nov 2017 01:13:51 +0000 (09:13 +0800)]
MdeModulePkg/AtaAtapiPassThru: Revert patch to disable Bus Master

This patch caused Windows 10 S4 resume failure.
Considering the similar changes are reverted from PciBus driver,
revert the patch from AtaAtapiPassThru as well.

Revert "MdeModulePkg/AtaAtapiPassThru: disable only BM-DMA at
ExitBootServices()"
This reverts commit 76fd5a660d704538a1b14a58d03a4eef9682b01c.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
6 years agoOvmfPkg/QemuBootOrderLib: let an OFW devpath match multiple UEFI boot opts
Laszlo Ersek [Thu, 23 Nov 2017 21:32:19 +0000 (22:32 +0100)]
OvmfPkg/QemuBootOrderLib: let an OFW devpath match multiple UEFI boot opts

This means that SetBootOrderFromQemu() will preserve all UEFI boot options
matched by any given OFW devpath, such as PXEv4, HTTPv4, PXEv6 and HTTPv6
boot options for the same NIC. Currently we stop the matching / appending
for the OFW devpath coming from the outer loop whenever we find the first
UEFI boot option match in the inner loop.

(The previous patch was about multiple OFW devpaths matching a single UEFI
boot option (which should never happen). This patch is about a single OFW
devpath matching multiple UEFI boot options. With the "break" statement
removed here, the small optimization from the last patch becomes a bit
more relevant, because now the inner loop always counts up to
ActiveCount.)

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
6 years agoOvmfPkg/QemuBootOrderLib: skip already matched / appended UEFI boot opts
Laszlo Ersek [Mon, 27 Nov 2017 17:16:27 +0000 (18:16 +0100)]
OvmfPkg/QemuBootOrderLib: skip already matched / appended UEFI boot opts

The SetBootOrderFromQemu() function implements a nested loop where

- the outer loop iterates over all OpenFirmware (OFW) device paths in the
  QEMU boot order, and translates each to a UEFI device path prefix;

- the inner loop matches the current (translated) prefix against all
  active UEFI boot options in turn;

- if the UEFI boot option is matched by the translated prefix, the UEFI
  boot option is appended to the "new" UEFI boot order, and marked as
  "has been appended".

This patch adds a micro-optimization where already matched / appended UEFI
boot options are skipped in the inner loop. This is not a functional
change. A functional change would be if, as a consequence of the patch,
some UEFI boot options would no longer be *doubly* matched.

For a UEFI boot option to be matched by two translated prefixes, one of
those prefixes would have to be a (proper, or equal) prefix of the other
prefix. The PCI and MMIO OFW translation routines output such only in the
following cases:

- When the original OFW device paths are prefixes of each other. This is
  not possible from the QEMU side. (Only leaf devices are bootable.)

- When the translation rules in the routines are incomplete, and don't
  look at the OFW device paths for sufficient length (i.e., at nodes where
  they would already differ, and the difference would show up in the
  translation output).

  This would be a shortcoming of the translation routines and should be
  fixed in TranslatePciOfwNodes() and TranslateMmioOfwNodes(), whenever
  identified.

Even in the second case, this patch would replace the double appending of
a single UEFI boot option (matched by two different OFW device paths) with
a correct, or cross-, matching of two different UEFI boot options. Again,
this is not expected, but arguably it would be more correct than duplicate
boot option appending, should it occur due to any (unexpected, unknown)
lack of detail in the translation routines.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>