ShellPkg: Refactor out the searching for pipe characters

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14969 6f19259b-4bc3-4df7-8a09-765794883524
OvmfPkg: Virtio drivers: fix incorrect casts in init functions

The recent patch

  OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL

was fixed up at commit time, in order to silence warnings issued by the
Visual Studio compiler. Differences between the posted and committed
patch:

>  diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
> -index 17b9f71..96a0d9f 100644
> +index 17b9f71..f09b0d1 100644
>  --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
>  +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c
>  @@ -23,7 +23,6 @@
> @@ -994,7 +998,7 @@
>  +  // step 4c -- Report GPFN (guest-physical frame number) of queue.
>  +  //
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
>  +  if (EFI_ERROR (Status)) {
>  +    goto ReleaseQueue;
>  +  }
> @@ -1495,7 +1499,7 @@
>         goto Exit;
>       }
>  diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
> -index 6cee014..8dcf9da 100644
> +index 6cee014..4203fbd 100644
>  --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c
>  +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c
>  @@ -57,14 +57,15 @@ VirtioNetInitRing (
> @@ -1539,7 +1543,7 @@
>  -  Status = VIRTIO_CFG_WRITE (Dev, Generic.VhdrQueueAddress,
>  -             (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Ring->Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Ring->Base >> EFI_PAGE_SHIFT);
>     if (EFI_ERROR (Status)) {
>  -    VirtioRingUninit (Ring);
>  +    goto ReleaseQueue;
> @@ -1721,7 +1725,7 @@
>   Exit:
>     gBS->RestoreTPL (OldTpl);
>  diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
> -index b836fb3..bcec676 100644
> +index b836fb3..2223c9c 100644
>  --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
>  +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c
>  @@ -38,7 +38,6 @@
> @@ -1908,7 +1912,7 @@
>  +  // step 4c -- Report GPFN (guest-physical frame number) of queue.
>  +  //
>  +  Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo,
> -+      (UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
> ++      (UINT32)(UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT);
>     if (EFI_ERROR (Status)) {
>       goto ReleaseQueue;
>     }

These casts are incorrect -- they throw away address bits >=32 before
shifting, which can break the drivers in guests with more than 4GB RAM.

The bug is clearly an artifact of the edk2 coding style, which requires
cast expressions to be written as

  (type) expression

rather than the usual

  (type)expression

The latter correctly reflects that casts have one of the strongest
bindings in C. The former actively obscures that fact. Cf.

  (type) expr1 >> expr2

vs.

  (type)expr1 >> expr2

Make sure we shift before we truncate.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14970 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: typo in the last commit.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14971 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: refactor out leading and trailing space trimming

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14972 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: Refactor Alias replacement into separate function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14973 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: Refactor Variable replacement into separate function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14974 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: add API for determining operation type

There are no callers for this new API yet.  They will be added in the next commits.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14975 6f19259b-4bc3-4df7-8a09-765794883524
MdeModulePkg/XhciDxe: Fix ICC compiler build warning.

Signed-off-by: Feng Tian <feng.tian@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14976 6f19259b-4bc3-4df7-8a09-765794883524
UefiCpuPkg: S3Resume2Pei: align return stacks	explicitly

S3RestoreConfig2() can optionally stack-switch to the SMM S3 Resume Entry
Point and ask it to transfer to S3ResumeExecuteBootScript().

Similarly, S3ResumeExecuteBootScript() stack-switches explicitly to the
boot script executor, and asks it to transfer to S3ResumeBootOs().

Currently the stack pointers specified for the SMM S3 Resume Entry Point
and the boot script executor to use for returning are derived from
addresses of the first local variables in S3RestoreConfig2() and
S3ResumeExecuteBootScript(), respectively.

Since (theoretically) the stack grows down as local variables are defined
and functions are called, the idea is presumably to allow the respective
callee to overwrite the caller's local variables. (The callees in
question can never return normally, only by explicit stack switching.)

Taking the address of "Status" is less portable than optimal however.
Compilers are free to juggle local variables at build time as they
please, including order and alignment on the stack. For example, when the
code is built for 64-bit PEI with gcc-4.8.2, the address of "Status"
trips up the alignment assertion in SwitchStack().

Let's align the address of "Status" down to CPU_STACK_ALIGNMENT
explicitly. If a compiler ensures such alignment and places "Status" at
the highest address automatically, then this change has no effect.
Otherwise, we'll prepare ReturnStackPointer values that (a) are correctly
aligned, (b) preserve the same amount or more (but never less) from the
caller's local variables than before, which should be safe.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed by: Jiewen Yao <Jiewen.Yao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14977 6f19259b-4bc3-4df7-8a09-765794883524
Fix meta file issue.

Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Hesheng Chen <hesheng.chen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14978 6f19259b-4bc3-4df7-8a09-765794883524
Check Context before use it.

Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14979 6f19259b-4bc3-4df7-8a09-765794883524
ArmPlatformPkg/ArmVExpressPkg: Added the empty 'ArmFvpDxe' platform UEFI driver

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>

v5:
- For uniformity, add the empty driver to
  ArmVExpress-RTSM-AEMv8Ax4-foundation.* too in this patch, not just
  ArmVExpress-RTSM-AEMv8Ax4.*. V4 added the empty driver to
  ArmVExpress-RTSM-AEMv8Ax4-foundation.* not sooner than the next patch,
  fusing it with other (= virtio) functionality. Let's split these changes
  cleanly.

Change-Id: I7d635011c8d3ac59097c728b7c7786d8677c80cb
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14980 6f19259b-4bc3-4df7-8a09-765794883524
ArmPlatformPkg/ArmFvpDxe: Added Virtio Block support

Right now the ARM Platform driver does not do much, but
I expect to move most platform specific code into platform
specific driver in the future.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>

v5:
- ensure / document that the VIRTIO_BLK_DEVICE_PATH structure must be
  packed
- fix whitespace damage in definition of "mVirtioBlockDevicePath"
- the platform driver is added to all platform DSC and FDF files in the
  previous patch; this patch focuses on virtio only

Change-Id: I3505bfc5b31085b8017bd9e6895a155bd7a2eee9
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-By: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14981 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: Refactor Split/Pipe based command lines

This moves the initialization for handling command lines with pipe ‘|’ into a separate function.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14982 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: Refactor change to current file system

This moves the initialization for handling file system changes into a separate function.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14983 6f19259b-4bc3-4df7-8a09-765794883524
Fix the non-blocking behavior for connect.  The behavior was correct if the code polled the connect routine but was not correct when using select to complete the asynchronous request.  This change fixes the select case by moving where some of the operations performed upon the connection completion.

Signed-off-by: lpleahy  leroy.p.leahy@intel.com
Reviewed-by: Daniel Moura  oxesoft@gmail.com


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14984 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: Refactor updating command line for help use

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14985 6f19259b-4bc3-4df7-8a09-765794883524
ShellPkg: add error messages into function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14986 6f19259b-4bc3-4df7-8a09-765794883524
OvmfPkg/QemuVideoDxe: child handles should have open parent protocol BY_CHILD_CONTROLLER

The QemuVideoDxe driver creates child controller handles, so it is acting
as a hybrid bus driver. The child handles should open the parent's bus
protocol BY_CHILD_CONTROLLER to properly maintain the protocol usage count.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Ruffin <chris.ruffin@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14987 6f19259b-4bc3-4df7-8a09-765794883524
MdeModulePkg CapsuleRuntimeDxe: Get PcdMaxSizeNonPopulateCapsule and PcdMaxSizePopulateCapsule by PcdGet32 in EntryPoint.

PcdMaxSizeNonPopulateCapsule and PcdMaxSizePopulateCapsule are declared to support Dynamic, but used by FixedPcdGet32 in CapsuleRuntimeDxe.
QueryCapsuleCapabilities is a runtime interface and PCD protocol can’t be used in runtime environment.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14988 6f19259b-4bc3-4df7-8a09-765794883524