[edk2] [patch] MdeModulePkg/SdMmc: Add break to avoid dead loop when polling OCR Reg

2017-03-12 Thread Feng Tian
At worst case, OCR register may always not set BIT31. It will cause
original code enter to dead loop. Adding a break for such case.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c | 9 -
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c   | 8 
 MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c| 9 -
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c| 9 -
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
index 9dbec10..6653a87 100755
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
@@ -1109,6 +1109,7 @@ EmmcIdentification (
   EFI_SD_MMC_PASS_THRU_PROTOCOL  *PassThru;
   UINT32 Ocr;
   UINT16 Rca;
+  UINTN  Retry;
 
   PciIo= Private->PciIo;
   PassThru = >PassThru;
@@ -1119,7 +1120,8 @@ EmmcIdentification (
 return Status;
   }
 
-  Ocr = 0;
+  Ocr   = 0;
+  Retry = 0;
   do {
 Status = EmmcGetOcr (PassThru, Slot, );
 if (EFI_ERROR (Status)) {
@@ -1127,6 +1129,11 @@ EmmcIdentification (
   return Status;
 }
 Ocr |= BIT30;
+
+if (Retry++ == 100) {
+  return EFI_DEVICE_ERROR; 
+}
+gBS->Stall(10 * 1000);
   } while ((Ocr & BIT31) == 0);
 
   Status = EmmcGetAllCid (PassThru, Slot);
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 9122848..1da0849 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1017,6 +1017,7 @@ SdCardIdentification (
   UINT8  PowerCtrl;
   UINT32 PresentState;
   UINT8  HostCtrl2;
+  UINTN  Retry;
 
   PciIo= Private->PciIo;
   PassThru = >PassThru;
@@ -1097,12 +1098,19 @@ SdCardIdentification (
   //Note here we only support the cards complied with SD physical
   //layer simplified spec version 2.0 and version 3.0 and above.
   //
+  Ocr   = 0;
+  Retry = 0;
   do {
 Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, );
 if (EFI_ERROR (Status)) {
   DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with 
%r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
   return EFI_DEVICE_ERROR;
 }
+
+if (Retry++ == 100) {
+  return EFI_DEVICE_ERROR; 
+}
+gBS->Stall(10 * 1000);
   } while ((Ocr & BIT31) == 0);
 
   //
diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c 
b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
index 2c0baca..5cb20a3 100644
--- a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
+++ b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
@@ -2827,6 +2827,7 @@ EmmcPeimIdentification (
   EFI_STATUS Status;
   UINT32 Ocr;
   UINT32 Rca;
+  UINTN  Retry;
 
   Status = EmmcPeimReset (Slot);
   if (EFI_ERROR (Status)) {
@@ -2834,13 +2835,19 @@ EmmcPeimIdentification (
 return Status;
   }
 
-  Ocr = 0;
+  Ocr   = 0;
+  Retry = 0;
   do {
 Status = EmmcPeimGetOcr (Slot, );
 if (EFI_ERROR (Status)) {
   DEBUG ((EFI_D_ERROR, "EmmcPeimIdentification: EmmcPeimGetOcr fails with 
%r\n", Status));
   return Status;
 }
+
+if (Retry++ == 100) {
+  return EFI_DEVICE_ERROR; 
+}
+MicroSecondDelay (10 * 1000);
   } while ((Ocr & BIT31) == 0);
 
   Status = EmmcPeimGetAllCid (Slot);
diff --git a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c 
b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
index 23e6563..81076ba 100644
--- a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
+++ b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
@@ -2754,7 +2754,7 @@ SdPeimIdentification (
   UINT32 PresentState;
   UINT8  HostCtrl2;
   SD_HC_SLOT_CAP Capability;
-
+  UINTN  Retry;
   //
   // 1. Send Cmd0 to the device
   //
@@ -2842,12 +2842,19 @@ SdPeimIdentification (
   //Note here we only support the cards complied with SD physical
   //layer simplified spec version 2.0 and version 3.0 and above.
   //
+  Ocr   = 0;
+  Retry = 0;
   do {
 Status = SdPeimSendOpCond (Slot, 0, Ocr, S18r, Xpc, TRUE, );
 if (EFI_ERROR (Status)) {
   DEBUG ((EFI_D_ERROR, "SdPeimIdentification: SdPeimSendOpCond fails with 
%r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
   return EFI_DEVICE_ERROR;
 }
+
+if (Retry++ == 100) {
+  return EFI_DEVICE_ERROR; 
+}
+MicroSecondDelay (10 * 1000);
   } while ((Ocr & BIT31) == 0);
 
   //
-- 
2.7.1.windows.2

_

[edk2] [patch 3/4] UefiCpuPkg/SmmCpuFeaturesLib: Split into two files

2016-12-15 Thread Feng Tian
From: Michael Kinney <michael.d.kin...@intel.com>

Split the default implementation of the SmmCpuFeaturesLib
into two files to prepare for the addition of the STM
specific SmmCpuFeaturesLib implementation.  The STM
specific implementation installs a different SMI entry
handler and initialize the MSEG specific MSR at the end
of SmmCpuFeaturesInitializeProcessor().

This patch does not introduce any functional changes
to the default implementation of the SmmCpuFeaturesLib.

Cc: Jiewen Yao <jiewen@intel.com>
Cc: Jeff Fan <jeff@intel.com>
Cc: Feng Tian <feng.t...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kin...@intel.com>
---
 .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  | 77 ---
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf|  3 +-
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c | 89 ++
 3 files changed, 107 insertions(+), 62 deletions(-)
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
index 1754f2d..31d73cd 100644
--- a/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
@@ -41,6 +41,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 #define SMM_FEATURES_LIB_IA32_MCA_CAP  0x17D
 #define   SMM_CODE_ACCESS_CHK_BIT  BIT58
 
+/**
+  Internal worker function that is called to complete CPU initialization at the
+  end of SmmCpuFeaturesInitializeProcessor()
+
+**/
+VOID
+FinishSmmCpuFeaturesInitializeProcessor (
+  VOID
+  );
+
 //
 // Set default value to assume SMRR is not supported
 //
@@ -257,7 +267,7 @@ SmmCpuFeaturesInitializeProcessor (
   // Print message and halt if CPU is Monarch
   //
   if (IsMonarch) {
-DEBUG ((EFI_D_ERROR, "SMM Base/Size does not meet alignment/size 
requirement!\n"));
+DEBUG ((DEBUG_ERROR, "SMM Base/Size does not meet alignment/size 
requirement!\n"));
 CpuDeadLoop ();
   }
 } else {
@@ -296,6 +306,11 @@ SmmCpuFeaturesInitializeProcessor (
   }
 }
   }
+
+  //
+  //  Call internal worker function that completes the CPU initialization
+  //
+  FinishSmmCpuFeaturesInitializeProcessor ();
 }
 
 /**
@@ -357,66 +372,6 @@ SmmCpuFeaturesSmmRelocationComplete (
 }
 
 /**
-  Return the size, in bytes, of a custom SMI Handler in bytes.  If 0 is
-  returned, then a custom SMI handler is not provided by this library,
-  and the default SMI handler must be used.
-
-  @retval 0Use the default SMI handler.
-  @retval > 0  Use the SMI handler installed by 
SmmCpuFeaturesInstallSmiHandler()
-   The caller is required to allocate enough SMRAM for each CPU to
-   support the size of the custom SMI handler.
-**/
-UINTN
-EFIAPI
-SmmCpuFeaturesGetSmiHandlerSize (
-  VOID
-  )
-{
-  return 0;
-}
-
-/**
-  Install a custom SMI handler for the CPU specified by CpuIndex.  This 
function
-  is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is greater
-  than zero and is called by the CPU that was elected as monarch during System
-  Management Mode initialization.
-
-  @param[in] CpuIndex   The index of the CPU to install the custom SMI handler.
-The value must be between 0 and the NumberOfCpus field
-in the System Management System Table (SMST).
-  @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.
-  @param[in] SmiStack   The stack to use when an SMI is processed by the
-the CPU specified by CpuIndex.
-  @param[in] StackSize  The size, in bytes, if the stack used when an SMI is
-processed by the CPU specified by CpuIndex.
-  @param[in] GdtBaseThe base address of the GDT to use when an SMI is
-processed by the CPU specified by CpuIndex.
-  @param[in] GdtSizeThe size, in bytes, of the GDT used when an SMI is
-processed by the CPU specified by CpuIndex.
-  @param[in] IdtBaseThe base address of the IDT to use when an SMI is
-processed by the CPU specified by CpuIndex.
-  @param[in] IdtSizeThe size, in bytes, of the IDT used when an SMI is
-processed by the CPU specified by CpuIndex.
-  @param[in] Cr3The base address of the page tables to use when an SMI
-is processed by the CPU specified by CpuIndex.
-**/
-VOID
-EFIAPI
-SmmCpuFeaturesInstallSmiHandler (
-  IN UINTN   CpuIndex,
-  IN UINT32  SmBase,
-  IN VOID*SmiStack,
-  IN UINTN   StackSize,
-  IN UINTN   GdtBase,
-  IN UINTN   GdtSize,
-  IN UINTN   IdtBase,
-  IN UINTN   IdtSize,
-  IN UINT32  Cr3
-  )
-{
-}
-
-/**
   Determines if

[edk2] [patch 4/4] UefiCpuPkg/SmmCpuFeaturesLibStm: Add STM library instance

2016-12-15 Thread Feng Tian
From: Michael Kinney <michael.d.kin...@intel.com>

Add a new instances of the SmmCpuFeaturesLib that is used by
platforms to enable the SMI Transfer Monitor(STM) feature.
This new instance is in the same directory as the default
SmmCpuFeaturesLib instance in order to share source files.

The DSC file is updated to build both SmmCpuFeatureLib
instances and to build two versions of the PiSmmCpuDxeSmm
module using each of the SmmCpuFeatureLib instances.

Cc: Jiewen Yao <jiewen@intel.com>
Cc: Jeff Fan <jeff@intel.com>
Cc: Feng Tian <feng.t...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kin...@intel.com>
---
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S  |  278 +
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm|  285 +
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm   |  271 
 .../Library/SmmCpuFeaturesLib/Ia32/SmiException.S  |  174 +++
 .../SmmCpuFeaturesLib/Ia32/SmiException.asm|  170 +++
 .../SmmCpuFeaturesLib/Ia32/SmiException.nasm   |  176 +++
 .../Library/SmmCpuFeaturesLib/Ia32/SmmStmSupport.c |   83 ++
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf |   88 ++
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c  | 1299 
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.h  |  176 +++
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.S   |  282 +
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.asm |  281 +
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm|  263 
 .../Library/SmmCpuFeaturesLib/X64/SmiException.S   |  178 +++
 .../Library/SmmCpuFeaturesLib/X64/SmiException.asm |  178 +++
 .../SmmCpuFeaturesLib/X64/SmiException.nasm|  179 +++
 .../Library/SmmCpuFeaturesLib/X64/SmmStmSupport.c  |   95 ++
 UefiCpuPkg/UefiCpuPkg.dsc  |8 +
 18 files changed, 4464 insertions(+)
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmmStmSupport.c
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.h
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmmStmSupport.c

diff --git a/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S 
b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S
new file mode 100644
index 000..4c0f8c8
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S
@@ -0,0 +1,278 @@
+#--
+#
+# Copyright (c) 2009 - 2016, 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:
+#
+#   SmiEntry.S
+#
+# Abstract:
+#
+#   Code template of the SMI handler for a particular processor
+#
+#--
+
+ASM_GLOBAL  ASM_PFX(gcStmSmiHandlerTemplate)
+ASM_GLOBAL  ASM_PFX(gcStmSmiHandlerSize)
+ASM_GLOBAL  ASM_PFX(gcStmSmiHandlerOffset)
+ASM_GLOBAL  ASM_PFX(gStmSmiCr3)
+ASM_GLOBAL  ASM_PFX(gStmSmiStack)
+ASM_GLOBAL  ASM_PFX(gStmSmbase)
+ASM_GLOBAL  ASM_PFX(gStmXdSupported)
+ASM_GLOBAL  ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))
+ASM_GLOBAL  ASM_PFX(gStmSmiHandlerIdtr)
+
+.equMSR_IA32_MISC_ENABLE, 0x1A0
+.equMSR_EFER, 0xc080
+.equMSR_EFER_XD, 0x800
+
+#
+# Constants relating to TXT_PROCESSOR_SMM_DESCRIPTOR
+#
+.equDSC_OFFSET, 0xfb00
+.equDSC_GDTPTR, 0x48
+.equDSC_GDTSIZ, 0x50
+.equDSC_CS, 0x14
+.equDSC_DS, 0x16
+.equDSC_SS, 

[edk2] [patch 0/4] Add STM (Smi Tranfer Monitor) support

2016-12-15 Thread Feng Tian
This patch series is used to add STM support to UefiCpuPkg.

More details about STM are described in:
http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-manual-325462.pdf
https://firmware.intel.com/sites/default/files/STM_User_Guide-001.pdf
https://firmware.intel.com/sites/default/files/A_Tour_Beyond_BIOS_Launching_STM_to_Monitor_SMM_in_EFI_Developer_Kit_II.pdf

Michael Kinney (4):
  UefiCpuPkg/Include: Update MSEG structure comments
  UefiCpuPkg: Add STM GUIDs, Protocols, and PCDs
  UefiCpuPkg/SmmCpuFeaturesLib: Split into two files
  UefiCpuPkg/SmmCpuFeaturesLibStm: Add STM library instance

 UefiCpuPkg/Include/Guid/MsegSmram.h|   30 +
 UefiCpuPkg/Include/Protocol/SmMonitorInit.h|  141 +++
 UefiCpuPkg/Include/Register/ArchitecturalMsr.h |   25 +-
 UefiCpuPkg/Include/Register/StmApi.h   |  954 ++
 .../Include/Register/StmResourceDescriptor.h   |  228 
 UefiCpuPkg/Include/Register/StmStatusCode.h|   78 ++
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S  |  278 +
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm|  285 +
 .../Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm   |  271 
 .../Library/SmmCpuFeaturesLib/Ia32/SmiException.S  |  174 +++
 .../SmmCpuFeaturesLib/Ia32/SmiException.asm|  170 +++
 .../SmmCpuFeaturesLib/Ia32/SmiException.nasm   |  176 +++
 .../Library/SmmCpuFeaturesLib/Ia32/SmmStmSupport.c |   83 ++
 .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c  |   77 +-
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf|3 +-
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c |   89 ++
 .../SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf |   88 ++
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c  | 1299 
 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.h  |  176 +++
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.S   |  282 +
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.asm |  281 +
 .../Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm|  263 
 .../Library/SmmCpuFeaturesLib/X64/SmiException.S   |  178 +++
 .../Library/SmmCpuFeaturesLib/X64/SmiException.asm |  178 +++
 .../SmmCpuFeaturesLib/X64/SmiException.nasm|  179 +++
 .../Library/SmmCpuFeaturesLib/X64/SmmStmSupport.c  |   95 ++
 UefiCpuPkg/UefiCpuPkg.dec  |   12 +
 UefiCpuPkg/UefiCpuPkg.dsc  |8 +
 28 files changed, 6036 insertions(+), 65 deletions(-)
 create mode 100644 UefiCpuPkg/Include/Guid/MsegSmram.h
 create mode 100644 UefiCpuPkg/Include/Protocol/SmMonitorInit.h
 create mode 100644 UefiCpuPkg/Include/Register/StmApi.h
 create mode 100644 UefiCpuPkg/Include/Register/StmResourceDescriptor.h
 create mode 100644 UefiCpuPkg/Include/Register/StmStatusCode.h
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiEntry.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmiException.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/Ia32/SmmStmSupport.c
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibNoStm.c
 create mode 100644 
UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.c
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmStm.h
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiEntry.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.S
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.asm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmiException.nasm
 create mode 100644 UefiCpuPkg/Library/SmmCpuFeaturesLib/X64/SmmStmSupport.c

-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 1/4] UefiCpuPkg/Include: Update MSEG structure comments

2016-12-15 Thread Feng Tian
From: Michael Kinney <michael.d.kin...@intel.com>

Add comments to describe fields of MSEG_HEADER and
add define values for the MonitorFeatures field.

Cc: Jiewen Yao <jiewen@intel.com>
Cc: Jeff Fan <jeff@intel.com>
Cc: Feng Tian <feng.t...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kin...@intel.com>
---
 UefiCpuPkg/Include/Register/ArchitecturalMsr.h | 25 ++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/Include/Register/ArchitecturalMsr.h 
b/UefiCpuPkg/Include/Register/ArchitecturalMsr.h
index a7a221d..a74ea51 100644
--- a/UefiCpuPkg/Include/Register/ArchitecturalMsr.h
+++ b/UefiCpuPkg/Include/Register/ArchitecturalMsr.h
@@ -484,7 +484,19 @@ typedef union {
   field of #MSR_IA32_SMM_MONITOR_CTL_REGISTER.
 **/
 typedef struct {
+  ///
+  /// Different processors may use different MSEG revision identifiers. These
+  /// identifiers enable software to avoid using an MSEG header formatted for
+  /// one processor on a processor that uses a different format. Software can
+  /// discover the MSEG revision identifier that a processor uses by reading
+  /// the VMX capability MSR IA32_VMX_MISC.
+  //
   UINT32  MsegHeaderRevision;
+  ///
+  /// Bits 31:1 of this field are reserved and must be zero. Bit 0 of the field
+  /// is the IA-32e mode SMM feature bit. It indicates whether the logical
+  /// processor will be in IA-32e mode after the STM is activated.
+  ///
   UINT32  MonitorFeatures;
   UINT32  GdtrLimit;
   UINT32  GdtrBaseOffset;
@@ -492,12 +504,19 @@ typedef struct {
   UINT32  EipOffset;
   UINT32  EspOffset;
   UINT32  Cr3Offset;
-  //
-  // Pad header so total size is 2KB
-  //
+  ///
+  /// Pad header so total size is 2KB
+  ///
   UINT8   Reserved[SIZE_2KB - 8 * sizeof (UINT32)];
 } MSEG_HEADER;
 
+///
+/// @{ Define values for the MonitorFeatures field of #MSEG_HEADER
+///
+#define STM_FEATURES_IA32E 0x1
+///
+/// @}
+///
 
 /**
   Base address of the logical processor's SMRAM image (RO, SMM only). If
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 2/4] UefiCpuPkg: Add STM GUIDs, Protocols, and PCDs

2016-12-15 Thread Feng Tian
From: Michael Kinney <michael.d.kin...@intel.com>

* Add GUIDed HOB that described MSEG region in SMRAM
* Add SM Monitor Init Protocol
* Add PCD to configure size of SMM exception stack
* Add PCD to configure MSEG region size if it is not
  described by the gMsegSmramGuid GUIDed HOB.

Cc: Jiewen Yao <jiewen@intel.com>
Cc: Jeff Fan <jeff@intel.com>
Cc: Feng Tian <feng.t...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kin...@intel.com>
---
 UefiCpuPkg/Include/Guid/MsegSmram.h|  30 +
 UefiCpuPkg/Include/Protocol/SmMonitorInit.h| 141 +++
 UefiCpuPkg/Include/Register/StmApi.h   | 954 +
 .../Include/Register/StmResourceDescriptor.h   | 228 +
 UefiCpuPkg/Include/Register/StmStatusCode.h|  78 ++
 UefiCpuPkg/UefiCpuPkg.dec  |  12 +
 6 files changed, 1443 insertions(+)
 create mode 100644 UefiCpuPkg/Include/Guid/MsegSmram.h
 create mode 100644 UefiCpuPkg/Include/Protocol/SmMonitorInit.h
 create mode 100644 UefiCpuPkg/Include/Register/StmApi.h
 create mode 100644 UefiCpuPkg/Include/Register/StmResourceDescriptor.h
 create mode 100644 UefiCpuPkg/Include/Register/StmStatusCode.h

diff --git a/UefiCpuPkg/Include/Guid/MsegSmram.h 
b/UefiCpuPkg/Include/Guid/MsegSmram.h
new file mode 100644
index 000..ab337c4
--- /dev/null
+++ b/UefiCpuPkg/Include/Guid/MsegSmram.h
@@ -0,0 +1,30 @@
+/** @file
+
+  Defines the HOB GUID used to describe the MSEG memory region allocated in 
PEI.
+
+  Copyright (c) 2015 - 2016, 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 _MSEG_SMRAM_H_
+#define _MSEG_SMRAM_H_
+
+#define MSEG_SMRAM_GUID \
+  { \
+0x5802bce4, 0x, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 
0x39 } \
+  }
+
+extern EFI_GUID gMsegSmramGuid;
+
+//
+// The data portion of this HOB is type EFI_SMRAM_DESCRIPTOR
+//
+
+#endif
diff --git a/UefiCpuPkg/Include/Protocol/SmMonitorInit.h 
b/UefiCpuPkg/Include/Protocol/SmMonitorInit.h
new file mode 100644
index 000..7b0aab0
--- /dev/null
+++ b/UefiCpuPkg/Include/Protocol/SmMonitorInit.h
@@ -0,0 +1,141 @@
+/** @file
+  STM service protocol definition
+
+  Copyright (c) 2015 - 2016, 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 _SM_MONITOR_INIT_PROTOCOL_H_
+#define _SM_MONITOR_INIT_PROTOCOL_H_
+
+#include 
+#include 
+
+#define EFI_SM_MONITOR_INIT_PROTOCOL_GUID \
+{ 0x228f344d, 0xb3de, 0x43bb, 0xa4, 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 
0x82}
+
+//
+// STM service
+//
+
+/**
+
+  Load STM image to MSEG.
+
+  @param StmImage  STM image
+  @param StmImageSize  STM image size
+
+  @retval EFI_SUCCESSLoad STM to MSEG successfully
+  @retval EFI_ALREADY_STARTEDSTM image is already loaded to MSEG
+  @retval EFI_BUFFER_TOO_SMALL   MSEG is smaller than minimal requirement of 
STM image
+  @retval EFI_UNSUPPORTEDMSEG is not enabled
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_SM_MONITOR_LOAD_MONITOR) (
+  IN EFI_PHYSICAL_ADDRESS StmImage,
+  IN UINTNStmImageSize
+  );
+
+/**
+
+  Add resources in list to database.
+
+  @param ResourceList  A pointer to resource list to be added
+  @param NumEntriesOptional number of entries.
+   If 0, list must be terminated by END_OF_RESOURCES.
+
+  @retval EFI_SUCCESSIf resources are added
+  @retval EFI_INVALID_PARAMETER  If nested procedure detected resource failer
+  @retval EFI_OUT_OF_RESOURCES   If nested procedure returned it and we cannot 
allocate more areas.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_SM_MONITOR_ADD_PI_RESOURCE) (
+  IN STM_RSC *ResourceList,
+  IN UINT32   NumEntries OPTIONAL
+  );
+
+/**
+
+  Delete resources in list to database.
+
+  @param ResourceList  A pointer to resource list to be deleted
+   NULL means delete all resources.
+  @param NumEntriesOptional number of entries.
+   If 0, list must be terminated by END_OF_RESOURCES.
+
+  @retval EFI_SUCCESSIf resources are deleted
+  @retval EFI_INVALID_PARAM

[edk2] [patch] UefiCpuPkg/PiSmmCpuDxeSmm: Fix .S & .asm build failure

2016-12-14 Thread Feng Tian
Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Jeff Fan <jeff@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S   | 1 +
 UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm | 2 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S| 2 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm  | 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S 
b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S
index 378e065..62f1697 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.S
@@ -28,6 +28,7 @@ ASM_GLOBAL  ASM_PFX(mXdSupported)
 ASM_GLOBAL  ASM_PFX(FeaturePcdGet (PcdCpuSmmStackGuard))
 ASM_GLOBAL  ASM_PFX(gSmiHandlerIdtr)
 
+.equMSR_IA32_MISC_ENABLE, 0x1A0
 .equMSR_EFER, 0xc080
 .equMSR_EFER_XD, 0x800
 
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm 
b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm
index a4f4dcb..8296f36 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiEntry.asm
@@ -202,7 +202,7 @@ _SmiHandler PROC
 calleax
 add esp, 4
 
-mov eax, mXdSupported
+mov eax, offset mXdSupported
 mov al, [eax]
 cmp al, 0
 jz  @f
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S 
b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S
index f4761b0..600d862 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.S
@@ -158,7 +158,7 @@ L13:
 rdmsr
 orw $MSR_EFER_XD,%ax# enable NXE
 wrmsr
-jmp @NxeDone
+jmp NxeDone
 SkipNxe:
 subl$8, %esp
 NxeDone:
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm 
b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm
index e2fcb6f..c74f82a 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmiEntry.asm
@@ -222,7 +222,7 @@ _SmiHandler:
 
 add rsp, 200h
 
-mov rax, ASM_PFX(mXdSupported)
+mov rax, offset ASM_PFX(mXdSupported)
 mov al, [rax]
 cmp al, 0
 jz  @f
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/SdMmc: Fix build failure caused by last check-in

2016-12-01 Thread Feng Tian
The commit e27cca has a typo on DEBUG level macro. And this debug
message should be DEBUG_INFO rather than DEBUG_ERROR.

Cc: Jan Dabros <j...@semihalf.com>
Cc: Marcin Wojtas <m...@semihalf.com>
Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index 4c1b5c8..23faec5 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -638,7 +638,7 @@ SdMmcPciHcDriverBindingStart (
 if (EFI_ERROR (Status) && (Status != EFI_MEDIA_CHANGED)) {
   continue;
 } else if (!MediaPresent) {
-  DEBUG ((EFI_ERROR, "SdMmcHcCardDetect: No device attached in 
Slot[%d]!!!\n", Slot));
+  DEBUG ((DEBUG_INFO, "SdMmcHcCardDetect: No device attached in 
Slot[%d]!!!\n", Slot));
   continue;
 }
 
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Ehci: don't clear port status bits during init

2016-11-29 Thread Feng Tian
Port status bits are clear in original code, so no enumeration
takes place.
Changing this to prevent the status bits from being cleared
allows enumeration to proceed normally.

Cc: Star Zeng <star.z...@intel.com>
Cc: Mike Turner <michael.tur...@microsoft.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Mike Turner <michael.tur...@microsoft.com>
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c | 10 +-
 MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c | 18 +-
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c 
b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
index 88a66ae..3a6ed02 100644
--- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
+++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c
@@ -591,6 +591,7 @@ EhcInitHC (
 {
   EFI_STATUS  Status;
   UINT32  Index;
+  UINT32  RegVal;
 
   // This ASSERT crashes the BeagleBoard. There is some issue in the USB stack.
   // This ASSERT needs to be removed so the BeagleBoard will boot. When we fix
@@ -626,7 +627,14 @@ EhcInitHC (
   //
   if (Ehc->HcStructParams & HCSP_PPC) {
 for (Index = 0; Index < (UINT8) (Ehc->HcStructParams & HCSP_NPORTS); 
Index++) {
-  EhcSetOpRegBit (Ehc, (UINT32) (EHC_PORT_STAT_OFFSET + (4 * Index)), 
PORTSC_POWER);
+  //
+  // Do not clear port status bits on initialization.  Otherwise devices 
will
+  // not enumerate properly at startup.
+  //
+  RegVal  = EhcReadOpReg(Ehc, (UINT32)(EHC_PORT_STAT_OFFSET + (4 * 
Index)));
+  RegVal &= ~PORTSC_CHANGE_MASK;
+  RegVal |= PORTSC_POWER;
+  EhcWriteOpReg (Ehc, (UINT32) (EHC_PORT_STAT_OFFSET + (4 * Index)), 
RegVal);
 }
   }
 
diff --git a/MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c 
b/MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c
index 09769ea..31647ff 100644
--- a/MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c
+++ b/MdeModulePkg/Bus/Pci/EhciPei/EhcPeim.c
@@ -2,7 +2,7 @@
 PEIM to produce gPeiUsb2HostControllerPpiGuid based on gPeiUsbControllerPpiGuid
 which is used to enable recovery function from USB Drivers.
 
-Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
   
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -411,12 +411,20 @@ EhcPowerOnAllPorts (
   IN PEI_USB2_HC_DEV  *Ehc
   )
 {
-  UINT8 PortNumber;
-  UINT8 Index;
-
+  UINT8 PortNumber;
+  UINT8 Index;
+  UINT32RegVal;
+  
   PortNumber = (UINT8)(Ehc->HcStructParams & HCSP_NPORTS);
   for (Index = 0; Index < PortNumber; Index++) {
-EhcSetOpRegBit (Ehc, EHC_PORT_STAT_OFFSET + 4 * Index, PORTSC_POWER);
+//
+// Do not clear port status bits on initialization.  Otherwise devices will
+// not enumerate properly at startup.
+//
+RegVal  = EhcReadOpReg(Ehc, EHC_PORT_STAT_OFFSET + 4 * Index);
+RegVal &= ~PORTSC_CHANGE_MASK;
+RegVal |= PORTSC_POWER;
+EhcWriteOpReg (Ehc, EHC_PORT_STAT_OFFSET + 4 * Index, RegVal);
   }
 }
 
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Xhci: Add 10ms delay before sending SendAddr cmd to dev

2016-11-22 Thread Feng Tian
We send ADDRESS DEVICE CMD in XhcInitializeDeviceSlot(), which will
cause XHC issue a USB SET_ADDRESS request to the USB Device.

According to USB spec, there should have a 10ms delay before this
operation after resetting a given port.

But in original code, there is a possible path which may have no such
10ms delay:
UsbHubResetPort()->UsbHubSetPortFeature()->Stall(20)->UsbHubGetPortSt
atus()->XhcPollPortStatusChange()->(if RESET_C bit is set)->
XhcInitializeDeviceSlot()->(if RESET_C bit is set)->Stall(10)

So this patch is used to fix above issue.

Cc: Star Zeng <star.z...@intel.com>
Cc: Baraneedharan Anbazhagan <anbazha...@hp.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
Tested-by: Baraneedharan Anbazhagan <anbazha...@hp.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h  |  7 ++-
 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 10 +-
 MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h   |  8 +++-
 MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 10 +-
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h 
b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
index 06cc73c..28e2402 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h
@@ -2,7 +2,7 @@
 
   Provides some data structure definitions used by the XHCI host controller 
driver.
 
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2016, 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
@@ -61,6 +61,11 @@ typedef struct _USB_DEV_CONTEXT  USB_DEV_CONTEXT;
 //
 #define XHC_RESET_TIMEOUT(1000)
 //
+// TRSTRCY delay requirement in usb 2.0 spec chapter 7.1.7.5.
+// The unit is microsecond, setting it as 10ms.
+//
+#define XHC_RESET_RECOVERY_DELAY (10 * 1000)
+//
 // XHC async transfer timer interval, set by experience.
 // The unit is 100us, takes 1ms as interval.
 //
diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index e37f674..4bec76a 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -2,7 +2,7 @@
 
   XHCI transfer scheduling routines.
 
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2016, 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
@@ -2115,6 +2115,10 @@ XhcInitializeDeviceSlot (
   // 8) Issue an Address Device Command for the Device Slot, where the command 
points to the Input
   //Context data structure described above.
   //
+  // Delay 10ms to meet TRSTRCY delay requirement in usb 2.0 spec chapter 
7.1.7.5 before sending SetAddress() request
+  // to device.
+  //
+  gBS->Stall (XHC_RESET_RECOVERY_DELAY);
   ZeroMem (, sizeof (CmdTrbAddr));
   PhyAddr = UsbHcGetPciAddrForHostAddr (Xhc->MemPool, 
Xhc->UsbDevContext[SlotId].InputContext, sizeof (INPUT_CONTEXT));
   CmdTrbAddr.PtrLo= XHC_LOW_32BIT (PhyAddr);
@@ -2321,6 +2325,10 @@ XhcInitializeDeviceSlot64 (
   // 8) Issue an Address Device Command for the Device Slot, where the command 
points to the Input
   //Context data structure described above.
   //
+  // Delay 10ms to meet TRSTRCY delay requirement in usb 2.0 spec chapter 
7.1.7.5 before sending SetAddress() request
+  // to device.
+  //
+  gBS->Stall (XHC_RESET_RECOVERY_DELAY);
   ZeroMem (, sizeof (CmdTrbAddr));
   PhyAddr = UsbHcGetPciAddrForHostAddr (Xhc->MemPool, 
Xhc->UsbDevContext[SlotId].InputContext, sizeof (INPUT_CONTEXT_64));
   CmdTrbAddr.PtrLo= XHC_LOW_32BIT (PhyAddr);
diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h 
b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h
index ccf4dc2..99f0396 100644
--- a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h
+++ b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.h
@@ -1,7 +1,7 @@
 /** @file
 Private Header file for Usb Host Controller PEIM
 
-Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -53,6 +53,12 @@ typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT;
 #define XHC_RESET_TIMEOUT   (1000)
 
 //
+// TRSTRCY delay requirement in usb 2.0 spec chapter 7.1.7.5.
+// The unit is microsecond, setting it as 10ms.
+//
+#define XHC_RESET_RECOVERY_DELAY (10 * 1000)
+
+//
 // Wait for root port state stable.
 //
 #define XHC_ROOT_PORT_STATE_STABLE  (200 * XHC_1_MILLISECOND)
diff --git a/MdeMod

[edk2] [patch] MdeModulePkg/Emmc: coding style update to not use pointer as boolean

2016-11-14 Thread Feng Tian
Non-Boolean comparisons should use a compare operator.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
index fc705e1..80e3d9a 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
@@ -1,7 +1,7 @@
 /** @file
   The helper functions for BlockIo and BlockIo2 protocol.
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2016, 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
@@ -901,7 +901,7 @@ EmmcReadWrite (
 if (EFI_ERROR (Status)) {
   return Status;
 }
-DEBUG ((EFI_D_INFO, "Emmc%a(): Part %d Lba 0x%x BlkNo 0x%x Event %p with 
%r\n", IsRead ? "Read " : "Write", Partition->PartitionType, Lba, BlockNum, 
Token ? Token->Event : NULL, Status));
+DEBUG ((EFI_D_INFO, "Emmc%a(): Part %d Lba 0x%x BlkNo 0x%x Event %p with 
%r\n", IsRead ? "Read " : "Write", Partition->PartitionType, Lba, BlockNum, 
(Token != NULL) ? Token->Event : NULL, Status));
 
 Lba   += BlockNum;
 Buffer = (UINT8*)Buffer + BufferSize;
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdePkg: Fix spec mismatch in string representation of EMMC dev node

2016-11-09 Thread Feng Tian
Cc: Eric Jin <eric@intel.com>
Cc: Liming Gao <liming@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c | 2 +-
 MdePkg/Library/UefiDevicePathLib/DevicePathToText.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index c167b4c..8a3a470 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -3529,7 +3529,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE 
mUefiDevicePathLibDevP
   {L"NVMe",DevPathFromTextNVMe},
   {L"UFS", DevPathFromTextUfs },
   {L"SD",  DevPathFromTextSd  },
-  {L"Emmc",DevPathFromTextEmmc},
+  {L"eMMC",DevPathFromTextEmmc},
   {L"DebugPort",   DevPathFromTextDebugPort   },
   {L"MAC", DevPathFromTextMAC },
   {L"IPv4",DevPathFromTextIPv4},
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
index 5922dee..87eca23 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
@@ -850,7 +850,7 @@ DevPathToTextEmmc (
   Emmc = DevPath;
   UefiDevicePathLibCatPrint (
 Str,
-L"Emmc(0x%x)",
+L"eMMC(0x%x)",
 Emmc->SlotNumber
 );
 }
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/UsbMass: Revert changes of removing retry logic

2016-11-06 Thread Feng Tian
This patch is used to revert changes done in commit 17f3e942
bc527fbd75068d2d5752b6af54917487 - "MdeModulePkg/UsbMass: Not
retry if usb bot transfer execution fail"

It's because Usb Floppy will report DEVICE_ERROR for the first
several cmds when it need spin up. so retry logic makes sense.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 7 +--
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c  | 8 ++--
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
index d5de1ac..0c46f88 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
@@ -189,11 +189,6 @@ UsbBootExecCmd (
 return EFI_TIMEOUT;
   }
 
-  if (Status == EFI_DEVICE_ERROR) {
-DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Device Error to Exec 0x%x Cmd\n", 
*(UINT8 *)Cmd));
-return EFI_DEVICE_ERROR;
-  }
-
   //
   // If ExecCommand() returns no error and CmdResult is success,
   // then the commnad transfer is successful.
@@ -276,7 +271,7 @@ UsbBootExecCmdWithRetry (
DataLen,
Timeout
);
-if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA || Status == EFI_DEVICE_ERROR) {
+if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA) {
   break;
 }
 //
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
index 4c29b61..4bb7222 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
@@ -2,7 +2,7 @@
   Implementation of the USB mass storage Bulk-Only Transport protocol,
   according to USB Mass Storage Class Bulk-Only Transport, Revision 1.0.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2011, 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
@@ -432,11 +432,7 @@ UsbBotExecCommand (
   // whether it succeeds or fails.
   //
   TransLen = (UINTN) DataLen;
-  Status   = UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
-  if (Status == EFI_DEVICE_ERROR) {
-DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotDataTransfer (%r)\n", 
Status));
-return Status;
-  }
+  UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
 
   //
   // Get the status, if that succeeds, interpret the result
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch v2] MdeModulePkg/Xhci: Change short packet debug message to verbose level

2016-10-30 Thread Feng Tian
Short Packet case is a normal case, we shouldn't print it as an error

compared with v1, this patch addes the same fix in XhciPei.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 2 +-
 MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index b6078b1..e37f674 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -1167,7 +1167,7 @@ XhcCheckUrbResult (
   case TRB_COMPLETION_SHORT_PACKET:
   case TRB_COMPLETION_SUCCESS:
 if (EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) {
-  DEBUG ((EFI_D_ERROR, "XhcCheckUrbResult: short packet happens!\n"));
+  DEBUG ((EFI_D_VERBOSE, "XhcCheckUrbResult: short packet 
happens!\n"));
 }
 
 TRBType = (UINT8) (TRBPtr->Type);
diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c 
b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
index 3632e8a..7f554f5 100644
--- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
@@ -683,7 +683,7 @@ XhcPeiCheckUrbResult (
   case TRB_COMPLETION_SHORT_PACKET:
   case TRB_COMPLETION_SUCCESS:
 if (EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) {
-  DEBUG ((EFI_D_ERROR, "XhcPeiCheckUrbResult: short packet 
happens!\n"));
+  DEBUG ((EFI_D_VERBOSE, "XhcPeiCheckUrbResult: short packet 
happens!\n"));
 }
 
 TRBType = (UINT8) (TRBPtr->Type);
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Xhci: Change short packet debug message to verbose level

2016-10-30 Thread Feng Tian
Short Packet case is a normal case, we shouldn't print it as an error

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index b6078b1..e37f674 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -1167,7 +1167,7 @@ XhcCheckUrbResult (
   case TRB_COMPLETION_SHORT_PACKET:
   case TRB_COMPLETION_SUCCESS:
 if (EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) {
-  DEBUG ((EFI_D_ERROR, "XhcCheckUrbResult: short packet happens!\n"));
+  DEBUG ((EFI_D_VERBOSE, "XhcCheckUrbResult: short packet 
happens!\n"));
 }
 
 TRBType = (UINT8) (TRBPtr->Type);
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Ufs: ensure the DBC field of UTP PRDT is dword-aligned

2016-10-17 Thread Feng Tian
According to UFS Host Controller Spec(JESD223), the bits 1:0 of this
DataByteCount field shall be 11b to indicate Dword granularity.

But the size of UFS Request Sense Data Response defined in UFS Spec
(JESD220C) is 18 which is not Dword aligned, we would have to round
down to the multiple of 4 to fill the DBC field to avoid bring issue
on some UFS HCs.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c 
b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index 26986cb..a854264 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -399,6 +399,11 @@ UfsInitUtpPrdt (
   UINT32 RemainingLen;
   UINT8  *Remaining;
   UINTN  PrdtNumber;
+  
+  if ((BufferSize & (BIT0 | BIT1)) != 0) {
+BufferSize &= ~(BIT0 | BIT1);
+DEBUG ((EFI_D_WARN, "UfsInitUtpPrdt: The BufferSize [%d] is not 
dword-aligned!\n", BufferSize));
+  }
 
   if (BufferSize == 0) {
 return EFI_SUCCESS;
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/XhciPei: 1ms delay before accessing MMIO reg in reset

2016-09-13 Thread Feng Tian
Some XHCI HCs require to have 1ms delay before accessing any MMIO
register in reset.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c 
b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
index a58739f..cd5c5cd 100644
--- a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
+++ b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
@@ -407,6 +407,7 @@ XhcPeiResetHC (
   }
 
   XhcPeiSetOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET);
+  MicroSecondDelay (1000);
   Status = XhcPeiWaitOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET, 
FALSE, Timeout);
 ON_EXIT:
   DEBUG ((EFI_D_INFO, "XhcPeiResetHC: %r\n", Status));
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Xhci: add 1ms delay before access MMIO reg during reset

2016-09-13 Thread Feng Tian
Some XHCI host controllers require to have extra 1ms delay before
accessing any MMIO register during HC reset.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
index d0f2205..cb822a6 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c
@@ -2,7 +2,7 @@
 
   The XHCI register operation routines.
 
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2016, 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
@@ -687,6 +687,10 @@ XhcResetHC (
   if ((Xhc->DebugCapSupOffset == 0x) || ((XhcReadExtCapReg (Xhc, 
Xhc->DebugCapSupOffset) & 0xFF) != XHC_CAP_USB_DEBUG) ||
   ((XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset + XHC_DC_DCCTRL) & BIT0) 
== 0)) {
 XhcSetOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET);
+//
+// some XHCI host controllers require to have extra 1ms delay before 
accessing any MMIO register during reset.
+//
+gBS->Stall (XHC_1_MILLISECOND);
 Status = XhcWaitOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET, FALSE, 
Timeout);
   }
 
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/AtaAtapiPassThru: update AtaStatusBlock after cmd exec

2016-08-09 Thread Feng Tian
AhciDumpPortStatus doesn't fully populate all the fields of
AtaStatusBlock after completing command execution, which may bring
issue if someone depends on the return status.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c | 39 ++--
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c 
b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
index 469a40a..f4dbc92 100644
--- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
+++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
@@ -371,6 +371,7 @@ AhciClearPortStatus (
   in the Status Register, the Error Register's value is also be dumped.
 
   @param  PciIoThe PCI IO protocol instance.
+  @param  AhciRegistersThe pointer to the EFI_AHCI_REGISTERS.
   @param  Port The number of port.
   @param  AtaStatusBlock   A pointer to EFI_ATA_STATUS_BLOCK data structure.
 
@@ -379,24 +380,42 @@ VOID
 EFIAPI
 AhciDumpPortStatus (
   IN EFI_PCI_IO_PROTOCOL*PciIo,
+  IN EFI_AHCI_REGISTERS *AhciRegisters,
   IN UINT8  Port,
   IN OUT EFI_ATA_STATUS_BLOCK   *AtaStatusBlock
   )
 {
-  UINT32   Offset;
+  UINTNOffset;
   UINT32   Data;
+  UINTNFisBaseAddr;
+  EFI_STATUS   Status;
 
   ASSERT (PciIo != NULL);
 
-  Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + 
EFI_AHCI_PORT_TFD;
-  Data   = AhciReadReg (PciIo, Offset);
-
   if (AtaStatusBlock != NULL) {
 ZeroMem (AtaStatusBlock, sizeof (EFI_ATA_STATUS_BLOCK));
 
-AtaStatusBlock->AtaStatus  = (UINT8)Data;
-if ((AtaStatusBlock->AtaStatus & BIT0) != 0) {
-  AtaStatusBlock->AtaError = (UINT8)(Data >> 8);
+FisBaseAddr = (UINTN)AhciRegisters->AhciRFis + Port * sizeof 
(EFI_AHCI_RECEIVED_FIS);
+Offset  = FisBaseAddr + EFI_AHCI_D2H_FIS_OFFSET;
+
+Status = AhciCheckMemSet (Offset, EFI_AHCI_FIS_TYPE_MASK, 
EFI_AHCI_FIS_REGISTER_D2H, NULL);
+if (!EFI_ERROR (Status)) {
+  //
+  // If D2H FIS is received, update StatusBlock with its content.
+  //
+  CopyMem (AtaStatusBlock, (UINT8 *)Offset, sizeof (EFI_ATA_STATUS_BLOCK));
+} else {
+  //
+  // If D2H FIS is not received, only update Status & Error field through 
PxTFD
+  // as there is no other way to get the content of the Shadow Register 
Block.
+  //
+  Offset = EFI_AHCI_PORT_START + Port * EFI_AHCI_PORT_REG_WIDTH + 
EFI_AHCI_PORT_TFD;
+  Data   = AhciReadReg (PciIo, (UINT32)Offset);
+
+  AtaStatusBlock->AtaStatus  = (UINT8)Data;
+  if ((AtaStatusBlock->AtaStatus & BIT0) != 0) {
+AtaStatusBlock->AtaError = (UINT8)(Data >> 8);
+  }
 }
   }
 }
@@ -866,7 +885,7 @@ Exit:
 Map
 );
 
-  AhciDumpPortStatus (PciIo, Port, AtaStatusBlock);
+  AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);
 
   return Status;
 }
@@ -1085,7 +1104,7 @@ Exit:
 }
   }
 
-  AhciDumpPortStatus (PciIo, Port, AtaStatusBlock);
+  AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);
   return Status;
 }
 
@@ -1201,7 +1220,7 @@ Exit:
 Timeout
 );
 
-  AhciDumpPortStatus (PciIo, Port, AtaStatusBlock);
+  AhciDumpPortStatus (PciIo, AhciRegisters, Port, AtaStatusBlock);
 
   return Status;
 }
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/UsbMass: Not retry if usb bot transfer execution fail

2016-08-02 Thread Feng Tian
[Sorry, this patch was pushed into EDKII trunk by wrong operation.

If the review mail could pass review, I would prefer to not do a roll-back.
Sorry again for that.

If there is other opinions, please let me know.]

The retry mechanism will bring issue if the usb device is unplugged
from XHCI HC but s/w is trying to access it through BlockIo. The
current cmd will get device error return status, but the sequential
cmds will be timeout. This behavior will cause system unresponsive
for a long while and bring bad user experience.

So we break the retry loop if found device error.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c | 9 +++--
 MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c  | 8 ++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
index 9f99650..96c3622 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
@@ -2,7 +2,7 @@
   Implementation of the command set of USB Mass Storage Specification
   for Bootability, Revision 1.0.
 
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, 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
@@ -189,6 +189,11 @@ UsbBootExecCmd (
 return EFI_TIMEOUT;
   }
 
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBootExecCmd: Device Error to Exec 0x%x Cmd\n", 
*(UINT8 *)Cmd));
+return EFI_DEVICE_ERROR;
+  }
+
   //
   // If ExecCommand() returns no error and CmdResult is success,
   // then the commnad transfer is successful.
@@ -271,7 +276,7 @@ UsbBootExecCmdWithRetry (
DataLen,
Timeout
);
-if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA) {
+if (Status == EFI_SUCCESS || Status == EFI_MEDIA_CHANGED || Status == 
EFI_NO_MEDIA || Status == EFI_DEVICE_ERROR) {
   break;
 }
 //
diff --git a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c 
b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
index dd83540..0767ff0 100644
--- a/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
+++ b/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBot.c
@@ -2,7 +2,7 @@
   Implementation of the USB mass storage Bulk-Only Transport protocol,
   according to USB Mass Storage Class Bulk-Only Transport, Revision 1.0.
 
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, 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
@@ -432,7 +432,11 @@ UsbBotExecCommand (
   // whether it succeeds or fails.
   //
   TransLen = (UINTN) DataLen;
-  UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  Status   = UsbBotDataTransfer (UsbBot, DataDir, Data, , Timeout);
+  if (Status == EFI_DEVICE_ERROR) {
+DEBUG ((EFI_D_ERROR, "UsbBotExecCommand: UsbBotDataTransfer (%r)\n", 
Status));
+return Status;
+  }
 
   //
   // Get the status, if that succeeds, interpret the result
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg: add generic SataController driver.

2016-07-19 Thread Feng Tian
This SataController driver is used to provide a generic solution
for those IDE/SATA/AHCI spec compliance host controllers. 

If there is special reqirement on timing setting or something else,
user could override this driver to customize a specific one.

Cc: Michael Kinney <michael.d.kin...@intel.com>
Cc: Amy Chan <amy.c...@intel.com>
Cc: Giri P Mudusuru <giri.p.mudus...@intel.com> 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 .../Bus/Pci/SataControllerDxe/ComponentName.c  |  177 
 .../Bus/Pci/SataControllerDxe/SataController.c | 1021 
 .../Bus/Pci/SataControllerDxe/SataController.h |  536 ++
 .../Pci/SataControllerDxe/SataControllerDxe.inf|   58 ++
 .../Pci/SataControllerDxe/SataControllerDxe.uni|   22 +
 .../SataControllerDxe/SataControllerDxeExtra.uni   |   20 +
 MdeModulePkg/MdeModulePkg.dsc  |1 +
 7 files changed, 1835 insertions(+)
 create mode 100644 MdeModulePkg/Bus/Pci/SataControllerDxe/ComponentName.c
 create mode 100644 MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c
 create mode 100644 MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h
 create mode 100644 MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.inf
 create mode 100644 MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxe.uni
 create mode 100644 
MdeModulePkg/Bus/Pci/SataControllerDxe/SataControllerDxeExtra.uni

diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/ComponentName.c 
b/MdeModulePkg/Bus/Pci/SataControllerDxe/ComponentName.c
new file mode 100644
index 000..467ad11
--- /dev/null
+++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/ComponentName.c
@@ -0,0 +1,177 @@
+/** @file
+  UEFI Component Name(2) protocol implementation for Sata Controller driver.
+
+  Copyright (c) 2011 - 2016, 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 "SataController.h"
+
+//
+/// EFI Component Name Protocol
+///
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  
gSataControllerComponentName = {
+  SataControllerComponentNameGetDriverName,
+  SataControllerComponentNameGetControllerName,
+  "eng"
+};
+
+//
+/// EFI Component Name 2 Protocol
+///
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL 
gSataControllerComponentName2 = {
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) 
SataControllerComponentNameGetDriverName,
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) 
SataControllerComponentNameGetControllerName,
+  "en"
+};
+
+//
+/// Driver Name Strings
+///
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE 
mSataControllerDriverNameTable[] = {
+  {
+"eng;en",
+(CHAR16 *)L"Sata Controller Init Driver"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+///
+/// Controller Name Strings
+///
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE 
mSataControllerControllerNameTable[] = {
+  {
+"eng;en",
+(CHAR16 *)L"Sata Controller"
+  },
+  {
+NULL,
+NULL
+  }
+};
+
+/**
+  Retrieves a Unicode string that is the user readable name of the UEFI Driver.
+
+  @param This   A pointer to the EFI_COMPONENT_NAME_PROTOCOL 
instance.
+  @param Language   A pointer to a three character ISO 639-2 
language identifier.
+This is the language of the driver name that 
that the caller
+is requesting, and it must match one of the 
languages specified
+in SupportedLanguages.  The number of 
languages supported by a
+driver is up to the driver writer.
+  @param DriverName A pointer to the Unicode string to return.  
This Unicode string
+is the name of the driver specified by This in 
the language
+specified by Language.
+  
+  @retval EFI_SUCCESS   The Unicode string for the Driver specified by 
This
+and the language specified by Language was 
returned
+in DriverName.
+  @retval EFI_INVALID_PARAMETER Language is NULL.
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.
+  @retval EFI_UNSUPPORTED   The driver specified by This does not support 
the
+language specified by Language.
+**/
+EFI_STATUS
+EFIAPI
+SataControllerComponentNameGetDriverName (
+  IN EFI_COMPONENT_NAME_PROTOCOL*This,
+  IN CHAR8

[edk2] [patch 3/3] MdeModulePkg/XhciDxe: fix a bug on TRB check in async int transfer

2016-07-10 Thread Feng Tian
The last TRB in transfer ring is a LINK type TRB, which shouldn't
be accounted as a valid item in IsAsyncIntTrb().

Without this fix, the original algo will bring issue on those URBs
whose TRBs crosses the transfer ring.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
index 1130b6a..b6078b1 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
@@ -1009,7 +1009,11 @@ IsAsyncIntTrb (
 return TRUE;
   }
   CheckedTrb++;
-  if ((UINTN)CheckedTrb >= ((UINTN) CheckedUrb->Ring->RingSeg0 + sizeof 
(TRB_TEMPLATE) * CheckedUrb->Ring->TrbNumber)) {
+  //
+  // If the checked TRB is the link TRB at the end of the transfer ring,
+  // recircle it to the head of the ring.
+  //
+  if (CheckedTrb->Type == TRB_TYPE_LINK) {
 CheckedTrb = (TRB_TEMPLATE*) CheckedUrb->Ring->RingSeg0;
   }
 }
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 2/3] MdeModulePkg/UsbBus: reduce the port status polling before port reset

2016-07-10 Thread Feng Tian
This change is used to remove the port status polling in port reset
functions.

Why it's needed is because:
1) The same polling on same port has taken place prior to this removed
one. See UsbEnumeratePort()->GetPortStatus(). So this polling in
UsbEnumerateNewDev()->ResetPort() is redundant.
2) EDKII Xhci driver hooks all GetPortStatus() operations. If we don't
remove this one, XHCI driver's XhcPollPortStatusChange() may enter twice
in reset process and wrongly think the device is unplugged.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 28 ++--
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c| 20 +---
 2 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
index 79453fe..90a8b8c 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c
@@ -643,6 +643,7 @@ UsbFindChild (
 
   @param  HubIf The HUB that has the device connected.
   @param  Port  The port index of the hub (started with zero).
+  @param  Reset The boolean to control whether skip the reset 
of the port.
 
   @retval EFI_SUCCESS   The device is enumerated (added or removed).
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate resource for the device.
@@ -652,7 +653,8 @@ UsbFindChild (
 EFI_STATUS
 UsbEnumerateNewDev (
   IN USB_INTERFACE*HubIf,
-  IN UINT8Port
+  IN UINT8Port,
+  IN BOOLEAN  Reset
   )
 {
   USB_BUS *Bus;
@@ -677,16 +679,18 @@ UsbEnumerateNewDev (
   // and the hub is a EHCI root hub, ResetPort will release
   // the device to its companion UHCI and return an error.
   //
-  Status = HubApi->ResetPort (HubIf, Port);
-
-  if (EFI_ERROR (Status)) {
-DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", 
Port, Status));
-
-return Status;
+  if (Reset) {
+Status = HubApi->ResetPort (HubIf, Port);
+if (EFI_ERROR (Status)) {
+  DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - 
%r\n", Port, Status));
+  
+  return Status;
+}
+DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));
+  } else {
+DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d reset is skipped\n", 
Port));
   }
 
-  DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));
-
   Child = UsbCreateDevice (HubIf, Port);
 
   if (Child == NULL) {
@@ -964,7 +968,11 @@ UsbEnumeratePort (
 // Now, new device connected, enumerate and configure the device 
 //
 DEBUG (( EFI_D_INFO, "UsbEnumeratePort: new device connected at port 
%d\n", Port));
-Status = UsbEnumerateNewDev (HubIf, Port);
+if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_RESET)) {
+  Status = UsbEnumerateNewDev (HubIf, Port, FALSE);
+} else {
+  Status = UsbEnumerateNewDev (HubIf, Port, TRUE);
+}
   
   } else {
 DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device disconnected event on port 
%d\n", Port));
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
index e3752d1..f51a51f 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c
@@ -2,7 +2,7 @@
 
 Unified interface for RootHub and Hub.
 
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved. 
+Copyright (c) 2007 - 2016, 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
@@ -968,15 +968,6 @@ UsbHubResetPort (
   UINTN   Index;
   EFI_STATUS  Status;
 
-  Status = UsbHubGetPortStatus (HubIf, Port, );
-
-  if (EFI_ERROR (Status)) {
-return Status;
-  } else if (USB_BIT_IS_SET (PortState.PortChangeStatus, 
USB_PORT_STAT_C_RESET)) {
-DEBUG (( EFI_D_INFO, "UsbHubResetPort: skip reset on hub %p port %d\n", 
HubIf, Port));
-return EFI_SUCCESS;
-  }
-
   Status  = UsbHubSetPortFeature (HubIf, Port, (EFI_USB_PORT_FEATURE) 
USB_HUB_PORT_RESET);
 
   if (EFI_ERROR (Status)) {
@@ -1282,15 +1273,6 @@ UsbRootHubResetPort (
   //
   Bus = RootIf->Device->Bus;
 
-  Status = UsbHcGetRootHubPortStatus (Bus, Port, );
-
-  if (EFI_ERROR (Status)) {
-return Status;
-  } else if (USB_BIT_IS_SET (PortState.PortChangeStatus, 
USB_PORT_STAT_C_RESET)) {
-DEBUG (( EFI_D_INFO, "UsbRootHubResetPort: skip reset on root port %d\n", 
Port));
-return EFI_SUCCESS;
-  }
-

[edk2] [patch 1/3] MdeModulePkg/UsbBus: remove redundant host controller reset in UsbBus

2016-07-10 Thread Feng Tian
The Host Controller reset has been done at EDKII UHCI/EHCI/XHCI, The
original code will do twice host controller initialization which is
unnecessary. It also bring issues on some USB HCs.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index ef002f5..7822022 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -2,7 +2,7 @@
 
 Usb Bus Driver Binding and Bus IO Protocol.
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, 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
@@ -976,9 +976,6 @@ UsbBusBuildProtocol (
 }
   }
 
-  UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);
-  UsbHcSetState (UsbBus, EfiUsbHcStateOperational);
-
   //
   // Install an EFI_USB_BUS_PROTOCOL to host controller to identify it.
   //
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 0/3] Fix issues in Usb stack

2016-07-10 Thread Feng Tian
1. remove redudant host controller reset
2. tune the enumeration process by removing redudant port status polling.
3. fix a bug in async interrupt transfer TRB check logic.

Feng Tian (3):
  MdeModulePkg/UsbBus: remove redundant host controller reset in UsbBus
  MdeModulePkg/UsbBus: reduce the port status polling before port reset
  MdeModulePkg/XhciDxe: fix a bug on TRB check in async int transfer

 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c   |  6 +-
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c|  5 +
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 28 ++--
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.c| 20 +---
 4 files changed, 25 insertions(+), 34 deletions(-)

-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/EmmcDxe: Don't expose BlockIo interface for RPMB partition

2016-06-28 Thread Feng Tian
This change is to avoid UEFI SCT failure as UEFI SCT has no knowledge
about how to accessing a EMMC RPMB partition.

The user needs to access RPMB partition should get access through
EFI_SD_MMC_PASS_THRU protocol with authentication key & mac.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c | 138 +++---
 1 file changed, 45 insertions(+), 93 deletions(-)

diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
index d3602a5..5040882 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
@@ -443,77 +443,60 @@ InstallProtocolOnPartition (
 //
 // Install BlkIo/BlkIo2/Ssp for the specified partition
 //
-Status = gBS->InstallMultipleProtocolInterfaces (
->Handle,
-,
-Partition->DevicePath,
-,
->BlockIo,
-,
->BlockIo2,
-NULL
-);
-if (EFI_ERROR (Status)) {
-  goto Error;
-}
-
 if (Partition->PartitionType != EmmcPartitionRPMB) {
-  Status = gBS->InstallProtocolInterface (
+  Status = gBS->InstallMultipleProtocolInterfaces (
   >Handle,
+  ,
+  Partition->DevicePath,
+  ,
+  >BlockIo,
+  ,
+  >BlockIo2,
   ,
-  EFI_NATIVE_INTERFACE,
-  >EraseBlock
+  >EraseBlock,
+  NULL
   );
   if (EFI_ERROR (Status)) {
-gBS->UninstallMultipleProtocolInterfaces (
-   >Handle,
-   ,
-   Partition->DevicePath,
-   ,
-   >BlockIo,
-   ,
-   >BlockIo2,
-   NULL
-   );
 goto Error;
   }
-}
 
-if (((Partition->PartitionType == EmmcPartitionUserData) ||
-(Partition->PartitionType == EmmcPartitionBoot1) ||
-(Partition->PartitionType == EmmcPartitionBoot2)) &&
-((Device->Csd.Ccc & BIT10) != 0)) {
-  Status = gBS->InstallProtocolInterface (
-  >Handle,
-  ,
-  EFI_NATIVE_INTERFACE,
-  >StorageSecurity
-  );
-  if (EFI_ERROR (Status)) {
-gBS->UninstallMultipleProtocolInterfaces (
-   >Handle,
-   ,
-   Partition->DevicePath,
-   ,
-   >BlockIo,
-   ,
-   >BlockIo2,
-   ,
-   >EraseBlock,
-   NULL
-   );
-goto Error;
+  if (((Partition->PartitionType == EmmcPartitionUserData) ||
+  (Partition->PartitionType == EmmcPartitionBoot1) ||
+  (Partition->PartitionType == EmmcPartitionBoot2)) &&
+  ((Device->Csd.Ccc & BIT10) != 0)) {
+Status = gBS->InstallProtocolInterface (
+>Handle,
+,
+EFI_NATIVE_INTERFACE,
+>StorageSecurity
+);
+if (EFI_ERROR (Status)) {
+  gBS->UninstallMultipleProtocolInterfaces (
+ >Handle,
+ ,
+ Partition->DevicePath,
+ ,
+ >BlockIo,
+ ,
+ >BlockIo2,
+ ,
+ >EraseBlock,
+ NULL
+ );
+  goto Error;
+}
   }
+
+  gBS->OpenProtocol (
+ Device->Private->Controller,
+ ,
+ (VOID **) &(Device->Private->PassThru),
+ Device->Private->DriverBindingHandle,
+ Partition->Handle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
 }
 
-gBS->OpenProtocol (
-   Device->Private->Controller,
-   ,
-   (VOID **) &(Device->Private->PassThru),
-   Device->Private->DriverBindingHandle,
-   Partition->Handle,
-   EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
-   );
   } else {
 Status = EFI_INVALID_PARAMETER;
   }
@@ -993,7 +976,6 @@ EmmcDxeDriverBindingStop (
   EFI_BLOCK_IO_PROTOCOL  *BlockIo;
   EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
   EFI_STORAGE_SECURITY_COMMAND_PROTOCOL  *StorageSecurity;
-  EFI_ERASE_BLOCK_PROTOCOL   *EraseBlock;
 

[edk2] [patch] MdePkg/IndustryStandard: fix build break due to latest Atapi.h change

2016-06-28 Thread Feng Tian
Update the new introduced ATA_CMD_SEEK to ATA_CMD_ATAPI_SEEK.

Cc: Liming Gao <liming@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdePkg/Include/IndustryStandard/Atapi.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/IndustryStandard/Atapi.h 
b/MdePkg/Include/IndustryStandard/Atapi.h
index 088e914..0df802e 100644
--- a/MdePkg/Include/IndustryStandard/Atapi.h
+++ b/MdePkg/Include/IndustryStandard/Atapi.h
@@ -2,7 +2,7 @@
   This file contains just some basic definitions that are needed by drivers
   that dealing with ATA/ATAPI interface.
 
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, 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 that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -502,7 +502,7 @@ typedef union {
 #define ATA_CMD_READ_CAPACITY   0x25   ///< defined in 
ATAPI Removable Rewritable Media Devcies
 #define ATA_CMD_READ_10 0x28   ///< defined in 
ATAPI Removable Rewritable Media Devcies
 #define ATA_CMD_WRITE_100x2A   ///< defined in 
ATAPI Removable Rewritable Media Devcies
-#define ATA_CMD_SEEK0x2B   ///< defined in 
ATAPI Removable Rewritable Media Devcies
+#define ATA_CMD_ATAPI_SEEK  0x2B   ///< defined in 
ATAPI Removable Rewritable Media Devcies
 #define ATA_CMD_WRITE_AND_VERIFY0x2E   ///< defined in 
ATAPI Removable Rewritable Media Devcies
 #define ATA_CMD_VERIFY  0x2F   ///< defined in 
ATAPI Removable Rewritable Media Devcies
 #define ATA_CMD_READ_12 0xA8   ///< defined in 
ATAPI Removable Rewritable Media Devcies
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch v3] MdeModulePkg/SdMmc: update TPL to notify to fix UEFI SCT hang

2016-06-24 Thread Feng Tian
Compared with v2, we add missing critical region protection to error handling
path of SdRwSingleBlock & SdRwMultiBlocks functions.

We also fix an issue found at v1 & v2, in which the enumeration timer should
work at TPL_CALLBACK level as DiskIo is required to be <= TPL_CALLBACK.

Compared with v1, we added critical region protection on queue access made
in EraseBlock support.

We have to upgrade the TPL level used by SdMmc stack because the
following flow:

DiskIo2ReadWriteDisk() in logical partition -> PartitionReadBlocksEx()
in logical partition at TPL callback level -> ProbeMediaStatusEx()
with sync request -> DiskIo2ReadWriteDisk() in physical partition ->
 waiting for async task completion.

if the low layer driver doesn't run at TPL_NOTIFY level, it will have
no time to trigger async task and cause system hang.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c |  9 ++--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   |  2 +-
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c  | 60 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c  | 42 +++
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.c  |  2 +-
 5 files changed, 75 insertions(+), 40 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index ed6b557..0be081d 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -238,6 +238,7 @@ SdMmcPciHcEnumerateDevice (
   LIST_ENTRY  *Link;
   LIST_ENTRY  *NextLink;
   SD_MMC_HC_TRB   *Trb;
+  EFI_TPL OldTpl;
 
   Private = (SD_MMC_HC_PRIVATE_DATA*)Context;
 
@@ -251,6 +252,7 @@ SdMmcPciHcEnumerateDevice (
 //
 // Signal all async task events at the slot with EFI_NO_MEDIA status.
 //
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 for (Link = GetFirstNode (>Queue);
  !IsNull (>Queue, Link);
  Link = NextLink) {
@@ -263,6 +265,7 @@ SdMmcPciHcEnumerateDevice (
 SdMmcFreeTrb (Trb);
   }
 }
+gBS->RestoreTPL (OldTpl);
 //
 // Notify the upper layer the connect state change through 
ReinstallProtocolInterface.
 //
@@ -665,7 +668,7 @@ SdMmcPciHcDriverBindingStart (
   //
   Status = gBS->CreateEvent (
   EVT_TIMER | EVT_NOTIFY_SIGNAL,
-  TPL_CALLBACK,
+  TPL_NOTIFY,
   ProcessAsyncTaskList,
   Private,
   >TimerEvent
@@ -961,7 +964,7 @@ SdMmcPassThruPassThru (
   // Wait async I/O list is empty before execute sync I/O operation.
   //
   while (TRUE) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 if (IsListEmpty (>Queue)) {
   gBS->RestoreTPL (OldTpl);
   break;
@@ -1273,7 +1276,7 @@ SdMmcPassThruResetDevice (
   //
   // Free all async I/O requests in the queue
   //
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 
   for (Link = GetFirstNode (>Queue);
!IsNull (>Queue, Link);
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 8978182..b4ff2af 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1315,7 +1315,7 @@ SdMmcCreateTrb (
   }
 
   if (Event != NULL) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 InsertTailList (>Queue, >TrbList);
 gBS->RestoreTPL (OldTpl);
   }
diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
index 5fe710d..fc705e1 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
@@ -339,7 +339,7 @@ EmmcSetExtCsd (
   }
 
   SetExtCsdReq->Signature = EMMC_REQUEST_SIGNATURE;
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   InsertTailList (>Queue, >Link);
   gBS->RestoreTPL (OldTpl);
   SetExtCsdReq->Packet.SdMmcCmdBlk= >SdMmcCmdBlk;
@@ -361,7 +361,7 @@ EmmcSetExtCsd (
   if ((Token != NULL) && (Token->Event != NULL)) {
 Status = gBS->CreateEvent (
 EVT_NOTIFY_SIGNAL,
-TPL_CALLBACK,
+TPL_NOTIFY,
 AsyncIoCallback,
 SetExtCsdReq,
 >Event
@@ -382,7 +382,7 @@ Error:
 // The request and event will be freed in asynchronous callback for 
success case.
 //
 if (EFI_ERROR (Status) && (Set

[edk2] [patch v2] MdeModulePkg/SdMmc: update TPL to notify to fix UEFI SCT hang

2016-06-23 Thread Feng Tian
Compared with v1, we added critical region protection on queue access made
in EraseBlock support.

We have to upgrade the TPL level used by SdMmc stack because the
following flow:

DiskIo2ReadWriteDisk() in logical partition -> PartitionReadBlocksEx()
in logical partition at TPL callback level -> ProbeMediaStatusEx()
with sync request -> DiskIo2ReadWriteDisk() in physical partition ->
 waiting for async task completion.

if the low layer driver doesn't run at TPL_NOTIFY level, it will have
no time to trigger async task and cause system hang.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c |  8 +--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   |  2 +-
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c  | 60 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c  | 34 
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.c  |  2 +-
 5 files changed, 65 insertions(+), 41 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index ed6b557..8716fcd 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -665,7 +665,7 @@ SdMmcPciHcDriverBindingStart (
   //
   Status = gBS->CreateEvent (
   EVT_TIMER | EVT_NOTIFY_SIGNAL,
-  TPL_CALLBACK,
+  TPL_NOTIFY,
   ProcessAsyncTaskList,
   Private,
   >TimerEvent
@@ -684,7 +684,7 @@ SdMmcPciHcDriverBindingStart (
   //
   Status = gBS->CreateEvent (
   EVT_TIMER | EVT_NOTIFY_SIGNAL,
-  TPL_CALLBACK,
+  TPL_NOTIFY,
   SdMmcPciHcEnumerateDevice,
   Private,
   >ConnectEvent
@@ -961,7 +961,7 @@ SdMmcPassThruPassThru (
   // Wait async I/O list is empty before execute sync I/O operation.
   //
   while (TRUE) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 if (IsListEmpty (>Queue)) {
   gBS->RestoreTPL (OldTpl);
   break;
@@ -1273,7 +1273,7 @@ SdMmcPassThruResetDevice (
   //
   // Free all async I/O requests in the queue
   //
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 
   for (Link = GetFirstNode (>Queue);
!IsNull (>Queue, Link);
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 8978182..b4ff2af 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1315,7 +1315,7 @@ SdMmcCreateTrb (
   }
 
   if (Event != NULL) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 InsertTailList (>Queue, >TrbList);
 gBS->RestoreTPL (OldTpl);
   }
diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
index 5fe710d..fc705e1 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
@@ -339,7 +339,7 @@ EmmcSetExtCsd (
   }
 
   SetExtCsdReq->Signature = EMMC_REQUEST_SIGNATURE;
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   InsertTailList (>Queue, >Link);
   gBS->RestoreTPL (OldTpl);
   SetExtCsdReq->Packet.SdMmcCmdBlk= >SdMmcCmdBlk;
@@ -361,7 +361,7 @@ EmmcSetExtCsd (
   if ((Token != NULL) && (Token->Event != NULL)) {
 Status = gBS->CreateEvent (
 EVT_NOTIFY_SIGNAL,
-TPL_CALLBACK,
+TPL_NOTIFY,
 AsyncIoCallback,
 SetExtCsdReq,
 >Event
@@ -382,7 +382,7 @@ Error:
 // The request and event will be freed in asynchronous callback for 
success case.
 //
 if (EFI_ERROR (Status) && (SetExtCsdReq != NULL)) {
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   RemoveEntryList (>Link);
   gBS->RestoreTPL (OldTpl);
   if (SetExtCsdReq->Event != NULL) {
@@ -395,7 +395,7 @@ Error:
 // For synchronous operation, free request whatever the execution result 
is.
 //
 if (SetExtCsdReq != NULL) {
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   RemoveEntryList (>Link);
   gBS->RestoreTPL (OldTpl);
   FreePool (SetExtCsdReq);
@@ -445,7 +445,7 @@ EmmcSetBlkCount (
   }
 
   SetBlkCntReq->Signature = EMMC_REQUEST_SIGNATURE;
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   InsertTailList (>Queue, >Link);
   gBS->RestoreTPL (OldTpl);
   Set

[edk2] [patch] MdeModulePkg/SdMmc: update TPL to notify to fix UEFI SCT hang

2016-06-23 Thread Feng Tian
We have to upgrade the TPL level used by SdMmc stack because the
following flow:

DiskIo2ReadWriteDisk() in logical partition -> PartitionReadBlocksEx()
in logical partition at TPL callback level -> ProbeMediaStatusEx()
with sync request -> DiskIo2ReadWriteDisk() in physical partition ->
 waiting for async task completion.

if the low layer driver doesn't run at TPL_NOTIFY level, it will have
no time to trigger async task and cause system hang.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c |  8 ++--
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   |  2 +-
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c  | 48 +++---
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c  | 22 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.c  |  2 +-
 5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index ed6b557..8716fcd 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -665,7 +665,7 @@ SdMmcPciHcDriverBindingStart (
   //
   Status = gBS->CreateEvent (
   EVT_TIMER | EVT_NOTIFY_SIGNAL,
-  TPL_CALLBACK,
+  TPL_NOTIFY,
   ProcessAsyncTaskList,
   Private,
   >TimerEvent
@@ -684,7 +684,7 @@ SdMmcPciHcDriverBindingStart (
   //
   Status = gBS->CreateEvent (
   EVT_TIMER | EVT_NOTIFY_SIGNAL,
-  TPL_CALLBACK,
+  TPL_NOTIFY,
   SdMmcPciHcEnumerateDevice,
   Private,
   >ConnectEvent
@@ -961,7 +961,7 @@ SdMmcPassThruPassThru (
   // Wait async I/O list is empty before execute sync I/O operation.
   //
   while (TRUE) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 if (IsListEmpty (>Queue)) {
   gBS->RestoreTPL (OldTpl);
   break;
@@ -1273,7 +1273,7 @@ SdMmcPassThruResetDevice (
   //
   // Free all async I/O requests in the queue
   //
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 
   for (Link = GetFirstNode (>Queue);
!IsNull (>Queue, Link);
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
index 8978182..b4ff2af 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
@@ -1315,7 +1315,7 @@ SdMmcCreateTrb (
   }
 
   if (Event != NULL) {
-OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
 InsertTailList (>Queue, >TrbList);
 gBS->RestoreTPL (OldTpl);
   }
diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
index 5fe710d..a4c6053 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
@@ -339,7 +339,7 @@ EmmcSetExtCsd (
   }
 
   SetExtCsdReq->Signature = EMMC_REQUEST_SIGNATURE;
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   InsertTailList (>Queue, >Link);
   gBS->RestoreTPL (OldTpl);
   SetExtCsdReq->Packet.SdMmcCmdBlk= >SdMmcCmdBlk;
@@ -361,7 +361,7 @@ EmmcSetExtCsd (
   if ((Token != NULL) && (Token->Event != NULL)) {
 Status = gBS->CreateEvent (
 EVT_NOTIFY_SIGNAL,
-TPL_CALLBACK,
+TPL_NOTIFY,
 AsyncIoCallback,
 SetExtCsdReq,
 >Event
@@ -382,7 +382,7 @@ Error:
 // The request and event will be freed in asynchronous callback for 
success case.
 //
 if (EFI_ERROR (Status) && (SetExtCsdReq != NULL)) {
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   RemoveEntryList (>Link);
   gBS->RestoreTPL (OldTpl);
   if (SetExtCsdReq->Event != NULL) {
@@ -395,7 +395,7 @@ Error:
 // For synchronous operation, free request whatever the execution result 
is.
 //
 if (SetExtCsdReq != NULL) {
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   RemoveEntryList (>Link);
   gBS->RestoreTPL (OldTpl);
   FreePool (SetExtCsdReq);
@@ -445,7 +445,7 @@ EmmcSetBlkCount (
   }
 
   SetBlkCntReq->Signature = EMMC_REQUEST_SIGNATURE;
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
   InsertTailList (>Queue, >Link);
   gBS->RestoreTPL (OldTpl);
   SetBlkCntReq->Packet.SdMmcCmdBlk= >SdMmcCmdBlk;
@@ -463,7 +463,7 @@ EmmcSetBlkCount (
   if ((Token !=

[edk2] [patch] MdeModulePkg/UsbMouseAbsolutePointerDxe: fix VS2015 NOOPT build error

2016-05-10 Thread Feng Tian
Cc: Shumin Qiu <shumin@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 .../Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c  | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c 
b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
index bf3d853..9fe9244 100644
--- a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
+++ b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
@@ -678,9 +678,9 @@ InitializeUsbMouseDevice (
   // Let the cursor's starting position is in the center of the screen.
   //
   UsbMouseAbsolutePointerDev->State.CurrentX =
-(UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxX + 
UsbMouseAbsolutePointerDev->Mode.AbsoluteMinX) / 2;
+DivU64x32 (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxX + 
UsbMouseAbsolutePointerDev->Mode.AbsoluteMinX, 2);
   UsbMouseAbsolutePointerDev->State.CurrentY =
-(UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxY + 
UsbMouseAbsolutePointerDev->Mode.AbsoluteMinY) / 2;
+DivU64x32 (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxY + 
UsbMouseAbsolutePointerDev->Mode.AbsoluteMinY, 2);
 
   //
   // Set boot protocol for the USB mouse.
@@ -942,9 +942,9 @@ UsbMouseAbsolutePointerReset (
   // Let the cursor's starting position is in the center of the screen.
   //
   UsbMouseAbsolutePointerDevice->State.CurrentX =
-(UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxX + 
UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinX) / 2;
+DivU64x32 (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxX + 
UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinX, 2);
   UsbMouseAbsolutePointerDevice->State.CurrentY =
-(UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxY + 
UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinY) / 2;
+DivU64x32 (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxY + 
UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinY, 2);
 
   UsbMouseAbsolutePointerDevice->StateChanged = FALSE;
 
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Sd: add Erase Block support on sd/emmc device

2016-05-03 Thread Feng Tian
It's done by producing EFI_ERASE_BLOCK_PROTOCOL protocol instance.

Cc: Wu, Hao A <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c | 411 ++
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.h |  39 ++-
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c |  74 +-
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h |   5 +
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf   |   3 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c | 384 
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.h |  39 ++-
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.c |  15 ++
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.h |   7 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf   |   3 +-
 10 files changed, 974 insertions(+), 6 deletions(-)

diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
index edb438b..a12cd63 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c
@@ -47,6 +47,8 @@ AsyncIoCallback (
 
   if (EFI_ERROR (Request->Packet.TransactionStatus)) {
 Request->Token->TransactionStatus = Request->Packet.TransactionStatus;
+  } else {
+Request->Token->TransactionStatus = EFI_SUCCESS;
   }
 
   RemoveEntryList (>Link);
@@ -1589,3 +1591,412 @@ EmmcSecurityProtocolOut (
   return Status;
 }
 
+/**
+  Set the erase start address through sync or async I/O request.
+
+  @param[in]  Partition A pointer to the EMMC_PARTITION instance.
+  @param[in]  StartLba  The starting logical block address to be 
erased.
+  @param[in]  Token A pointer to the token associated with the 
transaction.
+  @param[in]  IsEnd A boolean to show whether it's the last cmd in 
a series of cmds.
+This parameter is only meaningful in async I/O 
request.
+
+  @retval EFI_SUCCESS   The request is executed successfully.
+  @retval EFI_OUT_OF_RESOURCES  The request could not be executed due to a 
lack of resources.
+  @retval OthersThe request could not be executed successfully.
+
+**/
+EFI_STATUS
+EmmcEraseBlockStart (
+  IN  EMMC_PARTITION*Partition,
+  IN  EFI_LBA   StartLba,
+  IN  EFI_BLOCK_IO2_TOKEN   *Token,
+  IN  BOOLEAN   IsEnd
+  )
+{
+  EFI_STATUS   Status;
+  EFI_SD_MMC_PASS_THRU_PROTOCOL*PassThru;
+  EMMC_DEVICE  *Device;
+  EMMC_REQUEST *EraseBlockStart;
+  EFI_TPL  OldTpl;
+
+  EraseBlockStart = NULL;
+
+  Device   = Partition->Device;
+  PassThru = Device->Private->PassThru;
+
+  EraseBlockStart = AllocateZeroPool (sizeof (EMMC_REQUEST));
+  if (EraseBlockStart == NULL) {
+Status = EFI_OUT_OF_RESOURCES;
+goto Error;
+  }
+
+  EraseBlockStart->Signature = EMMC_REQUEST_SIGNATURE;
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+  InsertTailList (>Queue, >Link);
+  gBS->RestoreTPL (OldTpl);
+  EraseBlockStart->Packet.SdMmcCmdBlk= >SdMmcCmdBlk;
+  EraseBlockStart->Packet.SdMmcStatusBlk = >SdMmcStatusBlk;
+  EraseBlockStart->Packet.Timeout= EMMC_GENERIC_TIMEOUT;
+
+  EraseBlockStart->SdMmcCmdBlk.CommandIndex = EMMC_ERASE_GROUP_START;
+  EraseBlockStart->SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
+  EraseBlockStart->SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
+
+  if (Device->SectorAddressing) {
+EraseBlockStart->SdMmcCmdBlk.CommandArgument = (UINT32)StartLba;
+  } else {
+EraseBlockStart->SdMmcCmdBlk.CommandArgument = (UINT32)MultU64x32 
(StartLba, Partition->BlockMedia.BlockSize);
+  }
+
+  EraseBlockStart->IsEnd = IsEnd;
+  EraseBlockStart->Token = Token;
+
+  if ((Token != NULL) && (Token->Event != NULL)) {
+Status = gBS->CreateEvent (
+EVT_NOTIFY_SIGNAL,
+TPL_CALLBACK,
+AsyncIoCallback,
+EraseBlockStart,
+>Event
+);
+if (EFI_ERROR (Status)) {
+  goto Error;
+}
+  } else {
+EraseBlockStart->Event = NULL;
+  }
+
+  Status = PassThru->PassThru (PassThru, Device->Slot, 
>Packet, EraseBlockStart->Event);
+
+Error:
+  if ((Token != NULL) && (Token->Event != NULL)) {
+//
+// For asynchronous operation, only free request and event in error case.
+// The request and event will be freed in asynchronous callback for 
success case.
+//
+if (EFI_ERROR (Status) && (EraseBlockStart != NULL)) {
+  RemoveEntryList (>Link);
+  if (EraseBlockStart->Event != NULL) {
+gBS->CloseEvent (EraseBlockStart->Event);
+  }
+  FreePool (EraseBlockStart);
+}
+  } else {
+//
+// For synchronous operation, free request whatever the e

[edk2] [patch] MdeModulePkg/NvmExpressDxe: comments update to meet implementation

2016-04-26 Thread Feng Tian
Cc: Simon (Xiang) Lian-SSI <simon.l...@ssi.samsung.com>
Cc: Wu, Hao A <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h 
b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
index 21c6255..6cbef3e 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
@@ -2,7 +2,7 @@
   NvmExpressDxe driver is used to manage non-volatile memory subsystem which 
follows
   NVM Express specification.
 
-  Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2013 - 2016, 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
@@ -101,13 +101,11 @@ struct _NVME_CONTROLLER_PRIVATE_DATA {
   NVME_ADMIN_CONTROLLER_DATA  *ControllerData;
 
   //
-  // 6 x 4kB aligned buffers will be carved out of this buffer.
+  // 4 x 4kB aligned buffers will be carved out of this buffer.
   // 1st 4kB boundary is the start of the admin submission queue.
-  // 2nd 4kB boundary is the start of the I/O submission queue #1.
-  // 3rd 4kB boundary is the start of the admin completion queue.
-  // 4th 4kB boundary is the start of the I/O completion queue #1.
-  // 5th 4kB boundary is the start of the first PRP list page.
-  // 6th 4kB boundary is the start of the second PRP list page.
+  // 2nd 4kB boundary is the start of the admin completion queue.
+  // 3rd 4kB boundary is the start of I/O submission queue #1.
+  // 4th 4kB boundary is the start of I/O completion queue #1.
   //
   UINT8   *Buffer;
   UINT8   *BufferPciAddr;
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 0/4] Fix coding style issue in SdMmc modules

2016-04-21 Thread Feng Tian
it includes:
1. Add SD related PCD description to MdeModulePkg.uni
2. Not explicitly compare BOOLEAN type with TRUE/FALSE
3. Fix typo on function comments
4. Fix wrong coding style on close brace

Feng Tian (4):
  MdeModulePkg/MdeModulePkg.uni: Add SD related PCD description
  MdeModulePkg/Sd: Not explicitly compare BOOLEAN type with TRUE/FALSE
  MdeModulePkg/EmmcDxe: Fix wrong typo on function comments
  MdeModulePkg/EmmcDxe: Fix wrong coding style on close brace

 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 8 
 MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c| 5 +++--
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c  | 1 +
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h  | 4 ++--
 MdeModulePkg/MdeModulePkg.uni  | 3 +++
 5 files changed, 13 insertions(+), 8 deletions(-)

-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 3/4] MdeModulePkg/EmmcDxe: Fix wrong typo on function comments

2016-04-21 Thread Feng Tian
Cc: Qiu Shumin <shumin@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c | 1 +
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
index b88d55d..2dd2981 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c
@@ -492,6 +492,7 @@ Error:
 
   @param[in]  Private The EMMC driver private data structure.
   @param[in]  SlotThe slot number to check device present.
+  @param[in]  RemainingDevicePath The pointer to the remaining device path.
 
   @retval EFI_SUCCESS Successfully to discover the device and 
attach
   SdMmcIoProtocol to it.
diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h 
b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h
index a463e34..0c50d62 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h
@@ -4,7 +4,7 @@
   This file defines common data structures, macro definitions and some module
   internal function header files.
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2016, 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
@@ -460,7 +460,7 @@ EmmcGetCsd (
 
   @param[in]  DeviceA pointer to the EMMC_DEVICE instance.
   @param[in]  Rca   The relative device address to use.
-  @param[out] Csd   The buffer to store the EMMC_CSD register data.
+  @param[out] Cid   The buffer to store the EMMC_CID register data.
 
   @retval EFI_SUCCESS   The request is executed successfully.
   @retval EFI_OUT_OF_RESOURCES  The request could not be executed due to a 
lack of resources.
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 4/4] MdeModulePkg/EmmcDxe: Fix wrong coding style on close brace

2016-04-21 Thread Feng Tian
The close brace of EmmcDxeComponentNameGetControllerName should be
at the beginning of a line.

Cc: Qiu Shumin <shumin@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c 
b/MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c
index c9e9d08..c6545b6 100644
--- a/MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c
+++ b/MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c
@@ -1,7 +1,7 @@
 /** @file
   UEFI Component Name(2) protocol implementation for EmmcDxe driver.
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2016, 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
@@ -237,5 +237,6 @@ EmmcDxeComponentNameGetControllerName (
ControllerNameTable,
ControllerName,
(BOOLEAN)(This == )
-   );}
+   );
+}
 
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/UsbKbDxe: don't assert when the key read is invalid

2016-04-13 Thread Feng Tian
The GetKeyDescriptor() may return NULL when the KeyData is invalid.
For such case, we should go to error handling path rather than assert

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c 
b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
index 86dd99d..fef1449 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
@@ -1,7 +1,7 @@
 /** @file
   Helper functions for USB Keyboard Driver.
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, 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
@@ -1195,7 +1195,9 @@ KeyboardHandler (
   // Handle repeat key
   //
   KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 
CurKeyCodeBuffer[Index]);
-  ASSERT (KeyDescriptor != NULL);
+  if (KeyDescriptor == NULL) {
+continue;
+  }
 
   if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || 
KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) {
 //
@@ -1272,8 +1274,9 @@ USBParseKey (
 Dequeue (>UsbKeyQueue, , sizeof (UsbKey));
 
 KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);
-ASSERT (KeyDescriptor != NULL);
-
+if (KeyDescriptor == NULL) {
+  continue;
+}
 if (!UsbKey.Down) {
   //
   // Key is released.
@@ -1513,7 +1516,9 @@ UsbKeyCodeToEfiInputKey (
   // KeyCode must in the range of  [0x4, 0x65] or [0xe0, 0xe7].
   //
   KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
-  ASSERT (KeyDescriptor != NULL);
+  if (KeyDescriptor == NULL) {
+return EFI_DEVICE_ERROR;
+  }
 
   if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {
 //
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 1/3] MdeModulePkg/Sd: Fix wrong response type of SD Deselect cmd

2016-04-12 Thread Feng Tian
The SD CMD7 deselect cmd have no response according to SD
physical layer simplified spec.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 6 --
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c | 6 --
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 07bd07a..d05eb9e 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1,7 +1,7 @@
 /** @file
   This file provides some helper functions which are specific for SD card 
device.
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2016, 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
@@ -464,7 +464,9 @@ SdCardSelect (
 
   SdMmcCmdBlk.CommandIndex = SD_SELECT_DESELECT_CARD;
   SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
-  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  if (Rca != 0) {
+SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  }
   SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
 
   Status = SdMmcPassThruPassThru (PassThru, Slot, , NULL);
diff --git a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c 
b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
index 341d788..b7a5fe4 100644
--- a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
@@ -1,7 +1,7 @@
 /** @file
   The helper functions for BlockIo and BlockIo2 protocol.
 
-  Copyright (c) 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2015 - 2016, 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
@@ -133,7 +133,9 @@ SdSelect (
 
   SdMmcCmdBlk.CommandIndex = SD_SELECT_DESELECT_CARD;
   SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
-  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  if (Rca != 0) {
+SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  }
   SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
 
   Status = PassThru->PassThru (PassThru, Device->Slot, , NULL);
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 2/3] MdeModulePkg/SdMmcPciHc: Reset the slot when sd device is connected

2016-04-12 Thread Feng Tian
The original code doesn't reset the slot when there is device change.
It may bring issue on device identification procedure of some SD cards.

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
index a841f47..053a80f 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c
@@ -275,6 +275,13 @@ SdMmcPciHcEnumerateDevice (
   if ((Status == EFI_MEDIA_CHANGED) && (MediaPresent == TRUE)) {
 DEBUG ((EFI_D_INFO, "SdMmcPciHcEnumerateDevice: device connected at 
slot %d of pci %p\n", Slot, Private->PciIo));
 //
+// Reset the specified slot of the SD/MMC Pci Host Controller
+//
+Status = SdMmcHcReset (Private->PciIo, Slot);
+if (EFI_ERROR (Status)) {
+  continue;
+}
+//
 // Reinitialize slot and restart identification process for the new 
attached device
 //
 Status = SdMmcHcInitHost (Private->PciIo, Slot, 
Private->Capability[Slot]);
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 3/3] MdeModulePkg/Sd: wait 1ms before check DATA line in voltage switch proc

2016-04-12 Thread Feng Tian
According to SD Host Controller 3.0 spec figure 3-10, we have to wait
1ms before checking DAT[3:0] in voltage switch proc

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 2 +-
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c 
b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index d05eb9e..b2a0857 100644
--- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
+++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
@@ -1123,7 +1123,7 @@ SdCardIdentification (
 
   SdMmcHcInitClockFreq (PciIo, Slot, Private->Capability[Slot]);
 
-  gBS->Stall (1);
+  gBS->Stall (1000);
 
   SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof 
(PresentState), );
   if (((PresentState >> 20) & 0xF) != 0xF) {
diff --git a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c 
b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
index 8f7ecf9..cbee947 100644
--- a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
+++ b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c
@@ -2832,7 +2832,7 @@ SdPeimIdentification (
 
   SdPeimHcInitClockFreq (Slot->SdHcBase);
 
-  MicroSecondDelay (1);
+  MicroSecondDelay (1000);
 
   SdPeimHcRwMmio (Slot->SdHcBase + SD_HC_PRESENT_STATE, TRUE, sizeof 
(PresentState), );
   if (((PresentState >> 20) & 0xF) != 0xF) {
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 0/3] Fix some bugs found in EDKII SD/MMC stack

2016-04-12 Thread Feng Tian
this series is used to fix some bugs found with some sd cards

Feng Tian (3):
  MdeModulePkg/Sd: Fix wrong response type of SD Deselect cmd
  MdeModulePkg/SdMmcPciHc: Reset the slot when sd device is connected
  MdeModulePkg/Sd: wait 1ms before check DATA line in voltage switch
proc

 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c  | 8 +---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 7 +++
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c   | 2 +-
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c  | 6 --
 4 files changed, 17 insertions(+), 6 deletions(-)

-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch] MdeModulePkg/Usb: Fix wrong condition judgment to support usb3.1 dev

2016-04-07 Thread Feng Tian
The bcdUSB value of usb3.1 is 0x0310, we update the condition judgment
to get correct max packet size for usb3.1 dev.

Cc: Star Zeng <star.z...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 4 ++--
 MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c   | 4 ++--
 MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 4 ++--
 MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c 
b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index 39c28ab..4798bea 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -1,7 +1,7 @@
 /** @file
   The XHCI controller driver.
 
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2016, 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
@@ -955,7 +955,7 @@ XhcControlTransfer (
 // Store a copy of device scriptor as hub device need this info to 
configure endpoint.
 //
 CopyMem (>UsbDevContext[SlotId].DevDesc, Data, *DataLength);
-if (Xhc->UsbDevContext[SlotId].DevDesc.BcdUSB == 0x0300) {
+if (Xhc->UsbDevContext[SlotId].DevDesc.BcdUSB >= 0x0300) {
   //
   // If it's a usb3.0 device, then its max packet size is a 2^n.
   //
diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c 
b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
index eaea38d..a58739f 100644
--- a/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
+++ b/MdeModulePkg/Bus/Pci/XhciPei/XhcPeim.c
@@ -2,7 +2,7 @@
 PEIM to produce gPeiUsb2HostControllerPpiGuid based on gPeiUsbControllerPpiGuid
 which is used to enable recovery function from USB Drivers.
 
-Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -687,7 +687,7 @@ XhcPeiControlTransfer (
   // Store a copy of device scriptor as hub device need this info to 
configure endpoint.
   //
   CopyMem (>UsbDevContext[SlotId].DevDesc, Data, *DataLength);
-  if (Xhc->UsbDevContext[SlotId].DevDesc.BcdUSB == 0x0300) {
+  if (Xhc->UsbDevContext[SlotId].DevDesc.BcdUSB >= 0x0300) {
 //
 // If it's a usb3.0 device, then its max packet size is a 2^n.
 //
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
index 9687eb0..5b8b1aa 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
@@ -2,7 +2,7 @@
 
 Manage Usb Descriptor List
 
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, 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
@@ -539,7 +539,7 @@ UsbGetMaxPacketSize0 (
 Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_DEVICE, 0, 0, , 8);
 
 if (!EFI_ERROR (Status)) {
-  if ((DevDesc.BcdUSB == 0x0300) && (DevDesc.MaxPacketSize0 == 9)) {
+  if ((DevDesc.BcdUSB >= 0x0300) && (DevDesc.MaxPacketSize0 == 9)) {
 UsbDev->MaxPacket0 = 1 << 9;
 return EFI_SUCCESS;
   }
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c 
b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
index f350021..a4bb4d7 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
@@ -1,7 +1,7 @@
 /** @file
 The module to produce Usb Bus PPI.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
   
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -702,7 +702,7 @@ PeiConfigureUsbDevice (
 return Status;
   }
 
-  if ((DeviceDescriptor.BcdUSB == 0x0300) && (DeviceDescriptor.MaxPacketSize0 
== 9)) {
+  if ((DeviceDescriptor.BcdUSB >= 0x0300) && (DeviceDescriptor.MaxPacketSize0 
== 9)) {
 PeiUsbDevice->MaxPacketSize0 = 1 << 9;
   } else {
 PeiUsbDevice->MaxPacketSize0 = DeviceDescriptor.MaxPacketSize0;
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 0/4] Add EDKII SD/MMC stack to manage SD/EMMC device

2016-03-22 Thread Feng Tian
The EDKII SD/MMC stack includes:
1. Dxe phase support by:
   i.  SdMmcPciHcDxe driver to consume PciIo and produce SdMmcPassThru
   ii. SdDxe driver to consume SdMmcPassThru to produce BlkIo1/BlkIo2
   iii.EmmcDxe driver to consume SdMmcPassThru to produce BlkIo1/BlkIo2/SSP

2. Pei phase support
   i.  SdBlockIoPei driver to consume SdMmcHostController Ppi and produce 
VirutalBlkIo1&2
   ii. EmmcBlockIoPei driver to consume SdMmcHostController Ppi and produce 
VirutalBlkIo1&2
   iii.SdMmcPciHcPei driver to produce SdMmcHostController Ppi

Feng Tian (4):
  MdePkg: Add EFI_SD_MMC_PASS_THRU_PROTOCOL definition
  MdePkg/DevicePath: Add EMMC device path definition
  MdePkg/IndustryStandard: Add SD/EMMC common definitions
  MdeModulePkg/SdMmc: Add EDKII SD/MMC stack

 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/ComponentName.c |  211 ++
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c| 1096 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c  | 1166 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 1154 
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h |  775 ++
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf|   72 +
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.uni|  Bin 0 -> 2216 bytes
 .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxeExtra.uni   |  Bin 0 -> 1348 bytes
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c   | 1879 +
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.h   |  544 
 MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c |  175 ++
 MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h |   86 +
 .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf|   56 +
 .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.uni|  Bin 0 -> 2096 bytes
 .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPeiExtra.uni   |  Bin 0 -> 1378 bytes
 .../Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.c |  779 ++
 .../Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.h |  381 +++
 .../Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.inf   |   62 +
 .../Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPei.uni   |  Bin 0 -> 1696 bytes
 .../Bus/Sd/EmmcBlockIoPei/EmmcBlockIoPeiExtra.uni  |  Bin 0 -> 1362 bytes
 MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c |  455 
 MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.h |   61 +
 MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c   | 2780 +++
 MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.h   |  345 +++
 MdeModulePkg/Bus/Sd/EmmcDxe/ComponentName.c|  241 ++
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.c  | 1591 +++
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcBlockIo.h  |  466 
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.c  | 1176 
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.h  |  495 
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.inf|   66 +
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxe.uni|  Bin 0 -> 2020 bytes
 MdeModulePkg/Bus/Sd/EmmcDxe/EmmcDxeExtra.uni   |  Bin 0 -> 1306 bytes
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdBlockIoPei.c|  610 +
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdBlockIoPei.h|  377 +++
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdBlockIoPei.inf  |   62 +
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdBlockIoPei.uni  |  Bin 0 -> 1748 bytes
 .../Bus/Sd/SdBlockIoPei/SdBlockIoPeiExtra.uni  |  Bin 0 -> 1354 bytes
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c |  455 
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.h |   61 +
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.c   | 2869 
 MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHci.h   |  354 +++
 MdeModulePkg/Bus/Sd/SdDxe/ComponentName.c  |  240 ++
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c  |  971 +++
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.h  |  221 ++
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.c  |  883 ++
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.h  |  469 
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.inf|   65 +
 MdeModulePkg/Bus/Sd/SdDxe/SdDxe.uni|  Bin 0 -> 2024 bytes
 MdeModulePkg/Bus/Sd/SdDxe/SdDxeExtra.uni   |  Bin 0 -> 2036 bytes
 MdeModulePkg/Include/Ppi/SdMmcHostController.h |   64 +
 MdeModulePkg/MdeModulePkg.dec  |9 +
 MdeModulePkg/MdeModulePkg.dsc  |6 +
 MdePkg/Include/IndustryStandard/Emmc.h |  297 ++
 MdePkg/Include/IndustryStandard/Sd.h   |  181 ++
 MdePkg/Include/Protocol/DevicePath.h   |   11 +
 MdePkg/Include/Protocol/SdMmcPassThru.h|  264 ++
 .../Library/UefiDevicePathLib/DevicePathFromText.c |   29 +
 .../Library/UefiDevicePathLib/DevicePathToText.c   |   32 +
 MdePkg/MdePkg.dec  |3 +
 59 files changed, 24645 insertions(+)
 create mode 100644 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/ComponentName.c
 create mode 100644 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
 create mode 100644 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
 create mo

[edk2] [patch 2/4] MdePkg/DevicePath: Add EMMC device path definition

2016-03-22 Thread Feng Tian
This device path node is introduced in UEFI2.6 spec.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdePkg/Include/Protocol/DevicePath.h   | 11 
 .../Library/UefiDevicePathLib/DevicePathFromText.c | 29 
 .../Library/UefiDevicePathLib/DevicePathToText.c   | 32 ++
 3 files changed, 72 insertions(+)

diff --git a/MdePkg/Include/Protocol/DevicePath.h 
b/MdePkg/Include/Protocol/DevicePath.h
index 631136be..9a9ad2c 100644
--- a/MdePkg/Include/Protocol/DevicePath.h
+++ b/MdePkg/Include/Protocol/DevicePath.h
@@ -855,6 +855,15 @@ typedef struct {
 } SD_DEVICE_PATH;
 
 ///
+/// EMMC (Embedded MMC) Device Path SubType.
+///
+#define MSG_EMMC_DP 0x1D
+typedef struct {
+  EFI_DEVICE_PATH_PROTOCOLHeader;
+  UINT8   SlotNumber;
+} EMMC_DEVICE_PATH;
+
+///
 /// iSCSI Device Path SubType
 ///
 #define MSG_ISCSI_DP  0x13
@@ -1239,6 +1248,7 @@ typedef union {
   WIFI_DEVICE_PATH   WiFi;
   UFS_DEVICE_PATHUfs;
   SD_DEVICE_PATH Sd;
+  EMMC_DEVICE_PATH   Emmc;
   HARDDRIVE_DEVICE_PATH  HardDrive;
   CDROM_DEVICE_PATH  CD;
 
@@ -1295,6 +1305,7 @@ typedef union {
   WIFI_DEVICE_PATH   *WiFi;
   UFS_DEVICE_PATH*Ufs;
   SD_DEVICE_PATH *Sd;
+  EMMC_DEVICE_PATH   *Emmc;
   HARDDRIVE_DEVICE_PATH  *HardDrive;
   CDROM_DEVICE_PATH  *CD;
 
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index 6a9b389..961ccb5 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -1903,6 +1903,34 @@ DevPathFromTextSd (
 }
 
 /**
+  Converts a text device path node to EMMC (Embedded MMC) device path 
structure.
+
+  @param TextDeviceNode  The input Text device path node.
+
+  @return A pointer to the newly-created EMMC device path structure.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+DevPathFromTextEmmc (
+  IN CHAR16 *TextDeviceNode
+  )
+{
+  CHAR16*SlotNumberStr;
+  EMMC_DEVICE_PATH  *Emmc;
+
+  SlotNumberStr = GetNextParamStr ();
+  Emmc  = (EMMC_DEVICE_PATH *) CreateDeviceNode (
+   MESSAGING_DEVICE_PATH,
+   MSG_EMMC_DP,
+   (UINT16) sizeof (EMMC_DEVICE_PATH)
+   );
+
+  Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);
+
+  return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;
+}
+
+/**
   Converts a text device path node to Debug Port device path structure.
 
   @param TextDeviceNode  The input Text device path node.
@@ -3501,6 +3529,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE 
mUefiDevicePathLibDevP
   {L"NVMe",DevPathFromTextNVMe},
   {L"UFS", DevPathFromTextUfs },
   {L"SD",  DevPathFromTextSd  },
+  {L"Emmc",DevPathFromTextEmmc},
   {L"DebugPort",   DevPathFromTextDebugPort   },
   {L"MAC", DevPathFromTextMAC },
   {L"IPv4",DevPathFromTextIPv4},
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c 
b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
index 363830b..92db3b1 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
@@ -823,6 +823,37 @@ DevPathToTextSd (
 }
 
 /**
+  Converts a EMMC (Embedded MMC) device path structure to its string 
representative.
+
+  @param Str The string representative of input device.
+  @param DevPath The input device path structure.
+  @param DisplayOnly If DisplayOnly is TRUE, then the shorter text 
representation
+ of the display node is used, where applicable. If 
DisplayOnly
+ is FALSE, then the longer text representation of the 
display node
+ is used.
+  @param AllowShortcuts  If AllowShortcuts is TRUE, then the shortcut forms of 
text
+ representation for a device node can be used, where 
applicable.
+
+**/
+VOID
+DevPathToTextEmmc (
+  IN OUT POOL_PRINT  *Str,
+  IN VOID*DevPath,
+  IN BOOLEAN DisplayOnly,
+  IN BOOLEAN AllowShortcuts
+  )
+{
+  EMMC_DEVICE_PATH *Emmc;
+
+  Emmc = DevPath;
+  UefiDevicePathLibCatPrint (
+Str,
+L"

[edk2] [patch v2 2/2] MdeModulePkg/UfsPassThru: Fix uninitialized field in QueryReqest UPIU

2016-02-29 Thread Feng Tian
The DataSegmentLength field of Query Request UPIU doesn't set correctly, which 
causes a 0 value rather than right data length is set to this field

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c 
b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
index a9fde30..75970d6 100644
--- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c
@@ -2,7 +2,7 @@
   UfsPassThruDxe driver is used to produce EFI_EXT_SCSI_PASS_THRU protocol 
interface
   for upper layer application to execute UFS-supported SCSI cmds.
 
-  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 2016, 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
@@ -455,8 +455,11 @@ UfsInitQueryRequestUpiu (
 {
   ASSERT (QueryReq != NULL);
 
-  QueryReq->TransCode = 0x16;
-  QueryReq->TaskTag   = TaskTag;
+  QueryReq->TransCode  = 0x16;
+  QueryReq->TaskTag= TaskTag;
+  QueryReq->DataSegLen = (UINT16)DataSize;
+  SwapLittleEndianToBigEndian ((UINT8*)>DataSegLen, sizeof 
(QueryReq->DataSegLen));
+
   if ((Opcode == UtpQueryFuncOpcodeRdDesc) || (Opcode == 
UtpQueryFuncOpcodeRdFlag) || (Opcode == UtpQueryFuncOpcodeRdAttr)) {
 QueryReq->QueryFunc = QUERY_FUNC_STD_READ_REQ;
   } else {
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch v2 0/2] Fix uninitialized field in QueryRequest UPIU in EDKII UFS stack

2016-02-29 Thread Feng Tian
Changes made compared with v1 of the patch:
1. Fix the same bug in UfsBlockIoPei

Feng Tian (2):
  MdeModulePkg/UfsBlockIoPei: Fix uninitialized field in QueryRequest
UPIU
  MdeModulePkg/UfsPassThru: Fix uninitialized field in QueryReqest UPIU

 MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c  | 9 ++---
 MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 9 ++---
 2 files changed, 12 insertions(+), 6 deletions(-)

-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch v2 1/2] MdeModulePkg/UfsBlockIoPei: Fix uninitialized field in QueryRequest UPIU

2016-02-29 Thread Feng Tian
The DataSegmentLength field of Query Request UPIU doesn't set correctly, which 
causes a 0 value rather than right data length is set to this field

Cc: Hao Wu <hao.a...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.t...@intel.com>
---
 MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c 
b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
index 6880057..8e028bd 100644
--- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
+++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014, Intel Corporation. All rights reserved.
+  Copyright (c) 2014 - 2016, 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
@@ -384,8 +384,11 @@ UfsInitQueryRequestUpiu (
 {
   ASSERT (QueryReq != NULL);
 
-  QueryReq->TransCode = 0x16;
-  QueryReq->TaskTag   = TaskTag;
+  QueryReq->TransCode  = 0x16;
+  QueryReq->TaskTag= TaskTag;
+  QueryReq->DataSegLen = (UINT16)DataSize;
+  SwapLittleEndianToBigEndian ((UINT8*)>DataSegLen, sizeof 
(QueryReq->DataSegLen));
+
   if ((Opcode == UtpQueryFuncOpcodeRdDesc) || (Opcode == 
UtpQueryFuncOpcodeRdFlag) || (Opcode == UtpQueryFuncOpcodeRdAttr)) {
 QueryReq->QueryFunc = QUERY_FUNC_STD_READ_REQ;
   } else {
-- 
2.7.1.windows.2

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel