From nobody Fri May 3 15:17:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61161+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61161+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1591887322; cv=none; d=zohomail.com; s=zohoarc; b=YMUQ0qYeM1LCRXl84ka4Ktd6jJtUESJt0ik5kkpay1GceXNYa9IlNiRm7mVI8BEP7vc07ZJhevPQnnOsUxZyR3M0g/IUL5x+HG5WorVUKO1KEw680SBrniC2Z0RBrNXoVv1/Yrfl9whql5nYeIfDCwKY/ff1h8goprvxy8RB82k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591887322; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=PoaSAtVbiTcBttPErhqwAetxEL/bV0EqCi3wuPYyxKE=; b=jEoFR7Wgmcb0mnTxAn82O95lmLphDJorobzSdsozMXDuMd7CcNkOIK9mZOr/dBUANSRl+T3e3vH3ZeHTVwkmBKkqWFEvav5Wc27dhLGdWiOFp/lARifieYQLHrsJgIFMb44R+WgucFAt7XzS5smQ8mqiLjWj0+FDGx6o0ztmSP4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61161+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159188732212822.851288739758274; Thu, 11 Jun 2020 07:55:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q5zhYY1788612xIaRzsMj4UN; Thu, 11 Jun 2020 07:55:21 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.9266.1591887318578558543 for ; Thu, 11 Jun 2020 07:55:19 -0700 IronPort-SDR: iRzuE3GM25GQqI6zKFvVmehK7YS/OApzX3sksmvMRWujEoF44vx3SqHchMTdI6W6ZnD3GK6UOU DHcc70vazaDA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2020 07:55:04 -0700 IronPort-SDR: tUR3P+pbB++RUIDiksQdWuZjCU1y0KVnQ7/0TJjx0pT92Bc2p8A4vDFqTMXea65fzERcg1GSxK 523UJ2Ln28ow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,499,1583222400"; d="scan'208";a="271603475" X-Received: from shwdejointlab96.ccr.corp.intel.com ([10.239.134.144]) by orsmga003.jf.intel.com with ESMTP; 11 Jun 2020 07:55:01 -0700 From: "Tan, Ming" To: devel@edk2.groups.io Cc: Eric Dong , Liming Gao Subject: [edk2-devel] [PATCH] Features/Intel: Add Usb3StatusCodeHandlerLib in Usb3DebugFeaturePkg Date: Thu, 11 Jun 2020 22:54:58 +0800 Message-Id: <20200611145458.32422-1-ming.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ming.tan@intel.com X-Gm-Message-State: 670YBCpdeSVTQyW4R5sGGd8Fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591887321; bh=8c1FummBmrwF/rrsShHjLdvul3sV6kmT5Fcqqf/u8Uk=; h=Cc:Date:From:Reply-To:Subject:To; b=CYB6yo5V0fJq+CSoGVASHrq1gMQFzEMJ+n6EI63iHlK1fSki+TZ3e6Q6Rh9aF1xMd0G sgNJ9+86mRspc1dnVGMIFkzPA+dy9DZUy0FYZBqD3+j3EY9h9QBnlOfZvXju2NAI2un0w XuyrFvG1C663Y/tQwEIxVasyXpwmOEAQ5qo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2794 In Features/Intel/Debugging/Usb3DebugFeaturePkg/Library, add Usb3StatusCodeHandlerLib, used for output status code through USB3. Also remove the prefix directory path of Debugging/ in .dsc file. Cc: Eric Dong Cc: Liming Gao Signed-off-by: Ming Tan --- .../Include/Usb3DebugFeature.dsc | 68 +++- .../Usb3DebugPortParamLibCmos.c | 100 ++++++ .../Usb3DebugPortParamLibCmos.inf | 65 ++++ .../PeiUsb3StatusCodeHandlerLib.c | 216 +++++++++++++ .../PeiUsb3StatusCodeHandlerLib.inf | 52 +++ .../RuntimeDxeUsb3StatusCodeHandlerLib.c | 297 ++++++++++++++++++ .../RuntimeDxeUsb3StatusCodeHandlerLib.inf | 54 ++++ .../SmmUsb3StatusCodeHandlerLib.c | 250 +++++++++++++++ .../SmmUsb3StatusCodeHandlerLib.inf | 53 ++++ .../Debugging/Usb3DebugFeaturePkg/Readme.md | 174 ++++++---- .../Usb3DebugFeaturePkg.dec | 2 + 11 files changed, 1262 insertions(+), 69 deletions(-) create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3DebugPortParamLibCmos/Usb3DebugPortParamLibCmos.c create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3DebugPortParamLibCmos/Usb3DebugPortParamLibCmos.inf create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/PeiUsb3StatusCodeHandlerLib.c create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/PeiUsb3StatusCodeHandlerLib.inf create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.c create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.inf create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/SmmUsb3StatusCodeHandlerLib.c create mode 100644 Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Us= b3StatusCodeHandlerLib/SmmUsb3StatusCodeHandlerLib.inf diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3Debug= Feature.dsc b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3Debu= gFeature.dsc index 494dd7a342..548edc6182 100644 --- a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFeature= .dsc +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Include/Usb3DebugFeature= .dsc @@ -25,6 +25,16 @@ !error "DXE_ARCH must be specified to build this feature!" !endif =20 +##########################################################################= ###### +# +# PCD Section - list of PCD Entries modified by the feature. +# +##########################################################################= ###### + +# Unmark the following and StatusCodeHandler.efi to build the .dsc file di= rectly +#[PcdsDynamicDefault] +# gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3|TRUE + ##########################################################################= ###### # # Library Class section - list of all Library Classes needed by this featu= re. @@ -48,6 +58,9 @@ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf UefiLib|MdePkg/Library/UefiLib/UefiLib.inf UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHo= okStatusCodeLibNull.inf + SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull= .inf =20 [LibraryClasses.common.PEIM] ####################################### @@ -57,6 +70,9 @@ MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAlloc= ationLib.inf PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/= PeiServicesTablePointerLibIdt.inf =20 +[LibraryClasses.IA32.PEIM,LibraryClasses.IA32.PEI_CORE,LibraryClasses.IA32= .SEC] + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiRepor= tStatusCodeLib.inf + [LibraryClasses.common.DXE_DRIVER] ####################################### # Edk2 Packages @@ -71,6 +87,7 @@ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/R= untimeDxeReportStatusCodeLib.inf =20 [LibraryClasses.common.UEFI_DRIVER] ####################################### @@ -79,6 +96,17 @@ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf =20 +[LibraryClasses.X64.DXE_SMM_DRIVER] + ####################################### + # Edk2 Packages + ####################################### + SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf + MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAlloc= ationLib.inf + SmmIoLib|MdePkg/Library/SmmIoLib/SmmIoLib.inf + SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmRepor= tStatusCodeLib.inf + + ##########################################################################= ###### # # Component section - list of all components that need built for this feat= ure. @@ -106,10 +134,18 @@ =20 # Add library instances here that are not included in package components= and should be tested # in the package build. - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibN= ull.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3Debug= PortParamLibPcd.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibP= ei.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibP= eiIoMmu.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibNull.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3DebugPortParamL= ibPcd.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibPei.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibPeiIoMmu.inf + Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/PeiUsb3StatusCodeHa= ndlerLib.inf + + # The following is an example for used with StatusCodeHandler: +# MdeModulePkg/Universal/StatusCodeHandler/Pei/StatusCodeHandlerPei.inf { +# +# Usb3DebugPortLib|Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3De= bugPortLibNull.inf +# NULL|Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/PeiUsb3Sta= tusCodeHandlerLib.inf +# } =20 # Add components here that should be included in the package build. =20 @@ -126,10 +162,26 @@ =20 # Add library instances here that are not included in package components= and should be tested # in the package build. - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibN= ull.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3Debug= PortParamLibPcd.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibD= xe.inf - Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibD= xeIoMmu.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibNull.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortParamLibPcd/Usb3DebugPortParamL= ibPcd.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibDxe.inf + Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3DebugPortLibDxeIoMmu.inf + + Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/RuntimeDxeUsb3Statu= sCodeHandlerLib.inf + Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/SmmUsb3StatusCodeHa= ndlerLib.inf + + # The following is an example for used with StatusCodeHandler: +# MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRun= timeDxe.inf { +# +# Usb3DebugPortLib|Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3De= bugPortLibNull.inf +# NULL|Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/RuntimeDxe= Usb3StatusCodeHandlerLib.inf +# } + +# MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf { +# +# Usb3DebugPortLib|Usb3DebugFeaturePkg/Library/Usb3DebugPortLib/Usb3De= bugPortLibNull.inf +# NULL|Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/SmmUsb3Sta= tusCodeHandlerLib.inf +# } =20 # Add components here that should be included in the package build. =20 diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Debug= PortParamLibCmos/Usb3DebugPortParamLibCmos.c b/Features/Intel/Debugging/Usb= 3DebugFeaturePkg/Library/Usb3DebugPortParamLibCmos/Usb3DebugPortParamLibCmo= s.c new file mode 100644 index 0000000000..41172eb89c --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortPar= amLibCmos/Usb3DebugPortParamLibCmos.c @@ -0,0 +1,100 @@ +/** @file + USB debug Port Parameter library instance based on PCD. + + @copyright + INTEL CONFIDENTIAL + Copyright 2011 - 2016 Intel Corporation. + + The source code contained or described herein and all documents related = to the + source code ("Material") are owned by Intel Corporation or its suppliers= or + licensors. Title to the Material remains with Intel Corporation or its s= uppliers + and licensors. The Material may contain trade secrets and proprietary and + confidential information of Intel Corporation and its suppliers and lice= nsors, + and is protected by worldwide copyright and trade secret laws and treaty + provisions. No part of the Material may be used, copied, reproduced, mod= ified, + published, uploaded, posted, transmitted, distributed, or disclosed in a= ny way + without Intel's prior express written permission. + + No license under any patent, copyright, trade secret or other intellectu= al + property right is granted to or conferred upon you by disclosure or deli= very + of the Materials, either expressly, by implication, inducement, estoppel= or + otherwise. Any license under such intellectual property rights must be + express and approved by Intel in writing. + + Unless otherwise agreed by Intel in writing, you may not remove or alter + this notice or any other notice embedded in Materials by Intel or + Intel's suppliers or licensors in any way. + + This file contains 'Framework Code' and is licensed as such under the te= rms + of your license agreement with Intel or your vendor. This file may not b= e=20 + modified, except as allowed by additional terms of your license agreemen= t. + +@par Specification Reference: +**/ + +#include +#include +#include +#include +#include + +/** + Returns the USB3 debug port controller. + bit: 0~ 7: Function + bit: 8~15: Device + bit: 16~24: Bus + =20 + @return Controller information of USB debug port. + +**/ +UINT32 +EFIAPI +GetUsb3DebugPortController ( + VOID + ) +{ + USB3_DEBUG_PORT_CONTROLLER UsbDebugPort; + + UsbDebugPort.Controller =3D 0; + UsbDebugPort.PciAddress.Bus =3D CmosRead8 (PcdGet8 (PcdUsb3DebugPortBusI= ndex)); + UsbDebugPort.PciAddress.Device =3D CmosRead8 (PcdGet8 (PcdUsb3DebugPortD= eviceIndex)); + UsbDebugPort.PciAddress.Function =3D CmosRead8 (PcdGet8 (PcdUsb3DebugPor= tFunctionIndex)); + if (UsbDebugPort.Controller =3D=3D 0) { + // Just in case CMOS cleared + UsbDebugPort.PciAddress.Bus =3D PcdGet8(PcdUsbSerialXhciBus); + UsbDebugPort.PciAddress.Device =3D PcdGet8(PcdUsbSerialXhciDev); + UsbDebugPort.PciAddress.Function =3D PcdGet8(PcdUsbSerialXhciFunc); + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortBusIndex), UsbDebugPort.PciAddres= s.Bus); + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortDeviceIndex), UsbDebugPort.PciAdd= ress.Device); + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortFunctionIndex), UsbDebugPort.PciA= ddress.Function); + } + + return UsbDebugPort.Controller; +} + +/** + Sets the USB3 debug port controller. + bit: 0~ 7: Function + bit: 8~15: Device + bit: 16~24: Bus + =20 + @param[in] Controller information of USB debug port value to be set. + + @retval TRUE The controller of USB debug port was sucessfully= set. + @retval FALSE The controller of USB debug port could not be se= t. + +**/ +BOOLEAN +EFIAPI +SetUsb3DebugPortController ( + UINT32 Controller + ) +{ + USB3_DEBUG_PORT_CONTROLLER UsbDebugPort; + + UsbDebugPort.Controller =3D Controller; + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortBusIndex), UsbDebugPort.PciAddress.= Bus); + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortDeviceIndex), UsbDebugPort.PciAddre= ss.Device); + CmosWrite8 (PcdGet8 (PcdUsb3DebugPortFunctionIndex), UsbDebugPort.PciAdd= ress.Function); + return TRUE; +} diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Debug= PortParamLibCmos/Usb3DebugPortParamLibCmos.inf b/Features/Intel/Debugging/U= sb3DebugFeaturePkg/Library/Usb3DebugPortParamLibCmos/Usb3DebugPortParamLibC= mos.inf new file mode 100644 index 0000000000..0dd614e645 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3DebugPortPar= amLibCmos/Usb3DebugPortParamLibCmos.inf @@ -0,0 +1,65 @@ +### @file +# Get and/or set USB 3 debug port controller based on PCD. +# +# @copyright +# INTEL CONFIDENTIAL +# Copyright 2013 - 2020 Intel Corporation. +# +# The source code contained or described herein and all documents related= to the +# source code ("Material") are owned by Intel Corporation or its supplier= s or +# licensors. Title to the Material remains with Intel Corporation or its = suppliers +# and licensors. The Material may contain trade secrets and proprietary a= nd +# confidential information of Intel Corporation and its suppliers and lic= ensors, +# and is protected by worldwide copyright and trade secret laws and treaty +# provisions. No part of the Material may be used, copied, reproduced, mo= dified, +# published, uploaded, posted, transmitted, distributed, or disclosed in = any way +# without Intel's prior express written permission. +# +# No license under any patent, copyright, trade secret or other intellect= ual +# property right is granted to or conferred upon you by disclosure or del= ivery +# of the Materials, either expressly, by implication, inducement, estoppe= l or +# otherwise. Any license under such intellectual property rights must be +# express and approved by Intel in writing. +# +# Unless otherwise agreed by Intel in writing, you may not remove or alter +# this notice or any other notice embedded in Materials by Intel or +# Intel's suppliers or licensors in any way. +# +# This file contains 'Framework Code' and is licensed as such under the t= erms +# of your license agreement with Intel or your vendor. This file may not = be +# modified, except as allowed by additional terms of your license agreeme= nt. +# +# @par Specification Reference: +# +# @par Glossary: +### + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D Usb3DebugPortParamLibCmos + FILE_GUID =3D 45837D7D-C4AB-4f77-8D51-F9355EB93139 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D Usb3DebugPortParamLib + +[LibraryClasses] + BaseLib + DebugLib + CmosAccessLib + +[Packages] + MdePkg/MdePkg.dec + BoardModulePkg/BoardModulePkg.dec + Debugging/Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec + +[Pcd] + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsbSerialXhciBus + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsbSerialXhciDev + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsbSerialXhciFunc + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugPortBusIndex + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugPortDeviceIndex + gAcpiDebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugPortFunctionIndex + +[Sources] + Usb3DebugPortParamLibCmos.c + diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/PeiUsb3StatusCodeHandlerLib.c b/Features/Intel/Debugging/Us= b3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/PeiUsb3StatusCodeHandler= Lib.c new file mode 100644 index 0000000000..d144312301 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/PeiUsb3StatusCodeHandlerLib.c @@ -0,0 +1,216 @@ +/** @file + Usb3 status code implementation. + + Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +/** + Convert status code value and extended data to readable ASCII string, se= nd string to Usb3 device. + + @param PeiServices An indirect pointer to the EFI_PEI_SERVICES tab= le published by the PEI Foundation. + @param CodeType Indicates the type of status code being reporte= d. + @param Value Describes the current status of a hardware or + software entity. This includes information abou= t the class and + subclass that is used to classify the entity as= well as an operation. + For progress codes, the operation is the curren= t activity. + For error codes, it is the exception.For debug = codes,it is not defined at this time. + @param Instance The enumeration of a hardware or software entit= y within + the system. A system may contain multiple entit= ies that match a class/subclass + pairing. The instance differentiates between th= em. An instance of 0 indicates + that instance information is unavailable, not m= eaningful, or not relevant. + Valid instance numbers start with 1. + @param CallerId This optional parameter may be used to identify= the caller. + This parameter allows the status code driver to= apply different rules to + different callers. + @param Data This optional parameter may be used to pass add= itional data. + + @retval EFI_SUCCESS Status code reported to Usb3 successfully. + +**/ +EFI_STATUS +EFIAPI +Usb3StatusCodeReportWorker ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN CONST EFI_GUID *CallerId, + IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL + ) +{ + CHAR8 *Filename; + CHAR8 *Description; + CHAR8 *Format; + CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; + UINT32 ErrorLevel; + UINT32 LineNumber; + UINTN CharCount; + BASE_LIST Marker; + + Buffer[0] =3D '\0'; + + if (Data !=3D NULL && + CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) && + ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType =3D=3D EfiStringA= scii) { + // + // Print String Data. + // + Usb3DebugPortWrite ( + (UINT8 *) (((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii), + ((EFI_STATUS_CODE_STRING_DATA *) Data)->DataHeader.Size + ); + return EFI_SUCCESS; + } else if (Data !=3D NULL && + ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Fi= lename, &Description, &LineNumber)) { + // + // Print ASSERT() information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "\n\rPEI_ASSERT!: %a (%d): %a\n\r", + Filename, + LineNumber, + Description + ); + } else if (Data !=3D NULL && + ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker,= &Format)) { + // + // Print DEBUG() information into output buffer. + // + CharCount =3D AsciiBSPrint ( + Buffer, + sizeof (Buffer), + Format, + Marker + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_ERROR_CODE)= { + // + // Print ERROR information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "ERROR: C%08x:V%08x I%x", + CodeType, + Value, + Instance + ); + + ASSERT(CharCount > 0); + + if (CallerId !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %g", + CallerId + ); + } + + if (Data !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %x", + Data + ); + } + + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + "\n\r" + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_PROGRESS_CO= DE) { + // + // Print PROGRESS information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "PROGRESS CODE: V%08x I%x\n\r", + Value, + Instance + ); + } else { + // + // Code type is not defined. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "Undefined: C%08x:V%08x I%x\n\r", + CodeType, + Value, + Instance + ); + } + + // + // Call Usb3DebugPortLib function to do print. + // + Usb3DebugPortWrite ((UINT8 *) Buffer, CharCount); + + return EFI_SUCCESS; +} + +/** + Constructor function of PeiUsb3StatusCodeHandlerLib. + + This function is the constructor function of this USB3 Status Code Handl= er Library for PEI Phase. + It check whether need beep, and register it to gEfiPeiRscHandlerPpiGuid. + + @param FileHandle Handle of the file being invoked. + @param PeiServices Describes the list of possible PEI Services. + + @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfull= y. + +**/ +RETURN_STATUS +EFIAPI +PeiUsb3StatusCodeHandlerLibConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + EFI_PEI_RSC_HANDLER_PPI *RscHandlerPpi; + + if (!PcdGetBool (PcdStatusCodeUseUsb3)) { + return RETURN_SUCCESS; + } + + Status =3D PeiServicesLocatePpi ( + &gEfiPeiRscHandlerPpiGuid, + 0, + NULL, + (VOID **) &RscHandlerPpi + ); + ASSERT_EFI_ERROR (Status); + + Status =3D Usb3DebugPortInitialize (); + ASSERT_EFI_ERROR (Status); + + Status =3D RscHandlerPpi->Register (Usb3StatusCodeReportWorker); + ASSERT_EFI_ERROR (Status); + + return RETURN_SUCCESS; +} diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/PeiUsb3StatusCodeHandlerLib.inf b/Features/Intel/Debugging/= Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/PeiUsb3StatusCodeHandl= erLib.inf new file mode 100644 index 0000000000..7315ea5bf4 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/PeiUsb3StatusCodeHandlerLib.inf @@ -0,0 +1,52 @@ +## @file +# USB3 status code implementation. +# +# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# vendor. This file may not be modified, except as allowed by +# additional terms of your license agreement. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PeiUsb3StatusCodeHandlerLib + FILE_GUID =3D 4FC1BF4D-0FC4-4B0A-B02E-302705076C6A + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + CONSTRUCTOR =3D PeiUsb3StatusCodeHandlerLibConstructor + LIBRARY_CLASS =3D StatusCodeHandlerLib|SEC PEIM PEI_COR + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC (EBC is only for bui= ld) +# + +[Sources] + PeiUsb3StatusCodeHandlerLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec + +[LibraryClasses] + PeiServicesLib + PcdLib + DebugLib + ReportStatusCodeLib + Usb3DebugPortLib + +[Guids] + gEfiStatusCodeDataTypeStringGuid ## SOMETIMES_CONSUMES ## G= UID + +[Pcd] + gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3 ##= CONSUMES + +[Ppis] + gEfiPeiRscHandlerPpiGuid ## CONSUMES + +[Depex] + TRUE diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.c b/Features/Intel/Debug= ging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/RuntimeDxeUsb3Sta= tusCodeHandlerLib.c new file mode 100644 index 0000000000..25c991d195 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.c @@ -0,0 +1,297 @@ +/** @file + Usb3 status code implementation. + + Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + + +EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol =3D NULL; +EFI_EVENT mExitBootServicesEvent =3D NULL; +BOOLEAN mRegistered =3D FALSE; + +/** + Convert status code value and extended data to readable ASCII string, se= nd string to Usb3 device. + + @param CodeType Indicates the type of status code being reporte= d. + @param Value Describes the current status of a hardware or s= oftware entity. + This included information about the class and s= ubclass that is used to + classify the entity as well as an operation. + @param Instance The enumeration of a hardware or software entit= y within + the system. Valid instance numbers start with 1. + @param CallerId This optional parameter may be used to identify= the caller. + This parameter allows the status code driver to= apply different rules to + different callers. + @param Data This optional parameter may be used to pass add= itional data. + + @retval EFI_SUCCESS Status code reported to Usb3 successfully. + @retval EFI_DEVICE_ERROR Usb3 device cannot work after ExitBootService()= is called. + @retval EFI_DEVICE_ERROR Usb3 device cannot work with TPL higher than TP= L_CALLBACK. + +**/ +EFI_STATUS +EFIAPI +Usb3StatusCodeReportWorker ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data OPTIONAL + ) +{ + CHAR8 *Filename; + CHAR8 *Description; + CHAR8 *Format; + CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; + UINT32 ErrorLevel; + UINT32 LineNumber; + UINTN CharCount; + BASE_LIST Marker; + + Buffer[0] =3D '\0'; + + if (Data !=3D NULL && + CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) && + ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType =3D=3D EfiStringA= scii) { + // + // Print String Data. + // + Usb3DebugPortWrite ( + (UINT8 *) (((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii), + ((EFI_STATUS_CODE_STRING_DATA *) Data)->DataHeader.Size + ); + return EFI_SUCCESS; + } else if (Data !=3D NULL && + ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename,= &Description, &LineNumber)) { + // + // Print ASSERT() information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "\n\rDXE_ASSERT!: %a (%d): %a\n\r", + Filename, + LineNumber, + Description + ); + } else if (Data !=3D NULL && + ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker,= &Format)) { + // + // Print DEBUG() information into output buffer. + // + CharCount =3D AsciiBSPrint ( + Buffer, + sizeof (Buffer), + Format, + Marker + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_ERROR_CODE)= { + // + // Print ERROR information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "ERROR: C%08x:V%08x I%x", + CodeType, + Value, + Instance + ); + ASSERT (CharCount > 0); + + if (CallerId !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %g", + CallerId + ); + } + + if (Data !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %x", + Data + ); + } + + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + "\n\r" + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_PROGRESS_CO= DE) { + // + // Print PROGRESS information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "PROGRESS CODE: V%08x I%x\n\r", + Value, + Instance + ); + } else { + // + // Code type is not defined. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "Undefined: C%08x:V%08x I%x\n\r", + CodeType, + Value, + Instance + ); + } + + // + // Call Usb3DebugPortLib function to do print. + // + Usb3DebugPortWrite ((UINT8 *) Buffer, CharCount); + + return EFI_SUCCESS; +} + +/** + Unregister status code callback functions only available at boot time fr= om + report status code router when exiting boot services. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context, wh= ich is + always zero in current implementation. + +**/ +VOID +EFIAPI +UnregisterUsb3BootTimeHandlers ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + if (mRegistered) { + mRscHandlerProtocol->Unregister (Usb3StatusCodeReportWorker); + } +} + +/** + Register status code callback function only when Report Status Code prot= ocol + is installed. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context, wh= ich is + always zero in current implementation. + +**/ +VOID +EFIAPI +RegisterUsb3BootTimeHandlers ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + Status =3D gBS->LocateProtocol ( + &gEfiRscHandlerProtocolGuid, + NULL, + (VOID **) &mRscHandlerProtocol + ); + ASSERT_EFI_ERROR (Status); + + Status =3D Usb3DebugPortInitialize (); + ASSERT_EFI_ERROR (Status); + + mRscHandlerProtocol->Register (Usb3StatusCodeReportWorker, TPL_HIGH_LEVE= L); + ASSERT_EFI_ERROR (Status); + mRegistered =3D TRUE; + + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + UnregisterUsb3BootTimeHandlers, + NULL, + &gEfiEventExitBootServicesGuid, + &mExitBootServicesEvent + ); + ASSERT_EFI_ERROR (Status); +} + +/** + Constructor function of RuntimeDxeUsb3StatusCodeHandlerLib. + + This function allocates memory for extended status code data, caches + the report status code service, and registers events. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +RuntimeDxeUsb3StatusCodeHandlerLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT RegisterStatusCodeHandlerEvent; + VOID *Registration; + + if (!PcdGetBool (PcdStatusCodeUseUsb3)) { + return EFI_SUCCESS; + } + + Status =3D gBS->LocateProtocol ( + &gEfiRscHandlerProtocolGuid, + NULL, + (VOID **) &mRscHandlerProtocol + ); + + if (!EFI_ERROR (Status)) { + RegisterUsb3BootTimeHandlers (NULL, NULL); + } else { + Status =3D gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + RegisterUsb3BootTimeHandlers, + NULL, + &RegisterStatusCodeHandlerEvent + ); + ASSERT_EFI_ERROR (Status); + + // + // Register for protocol notifications on this event + // + Status =3D gBS->RegisterProtocolNotify ( + &gEfiRscHandlerProtocolGuid, + RegisterStatusCodeHandlerEvent, + &Registration + ); + ASSERT_EFI_ERROR (Status); + } + + return EFI_SUCCESS; +} diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.inf b/Features/Intel/Deb= ugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/RuntimeDxeUsb3S= tatusCodeHandlerLib.inf new file mode 100644 index 0000000000..0819f97a1f --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/RuntimeDxeUsb3StatusCodeHandlerLib.inf @@ -0,0 +1,54 @@ +## @file +# USB3 status code implementation. +# +# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# vendor. This file may not be modified, except as allowed by +# additional terms of your license agreement. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D RuntimeDxeUsb3StatusCodeHandlerLib + FILE_GUID =3D 146052EF-0462-4F06-BFDB-EAB90B4519A7 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + CONSTRUCTOR =3D RuntimeDxeUsb3StatusCodeHandlerLibCon= structor + LIBRARY_CLASS =3D StatusCodeHandlerLib|DXE_RUNTIME_DRIV= ER + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC (EBC is only for bui= ld) +# + +[Sources] + RuntimeDxeUsb3StatusCodeHandlerLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + UefiRuntimeLib + PcdLib + DebugLib + BaseMemoryLib + ReportStatusCodeLib + Usb3DebugPortLib + +[Guids] + gEfiStatusCodeDataTypeStringGuid ## SOMETIMES_CONSUMES ## G= UID + +[Pcd] + gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3 ##= CONSUMES + +[Protocols] + gEfiRscHandlerProtocolGuid ## CONSUMES + +[Depex] + TRUE diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/SmmUsb3StatusCodeHandlerLib.c b/Features/Intel/Debugging/Us= b3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/SmmUsb3StatusCodeHandler= Lib.c new file mode 100644 index 0000000000..c6b3b9aac5 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/SmmUsb3StatusCodeHandlerLib.c @@ -0,0 +1,250 @@ +/** @file + Usb3 status code implementation. + + Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + + +/** + Convert status code value and extended data to readable ASCII string, se= nd string to Usb3 device. + + @param CodeType Indicates the type of status code being reporte= d. + @param Value Describes the current status of a hardware or s= oftware entity. + This included information about the class and s= ubclass that is used to + classify the entity as well as an operation. + @param Instance The enumeration of a hardware or software entit= y within + the system. Valid instance numbers start with 1. + @param CallerId This optional parameter may be used to identify= the caller. + This parameter allows the status code driver to= apply different rules to + different callers. + @param Data This optional parameter may be used to pass add= itional data. + + @retval EFI_SUCCESS Status code reported to Usb3 successfully. + @retval EFI_DEVICE_ERROR Usb3 device cannot work after ExitBootService()= is called. + @retval EFI_DEVICE_ERROR Usb3 device cannot work with TPL higher than TP= L_CALLBACK. + +**/ +EFI_STATUS +EFIAPI +Usb3StatusCodeReportWorker ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data OPTIONAL + ) +{ + CHAR8 *Filename; + CHAR8 *Description; + CHAR8 *Format; + CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE]; + UINT32 ErrorLevel; + UINT32 LineNumber; + UINTN CharCount; + BASE_LIST Marker; + + Buffer[0] =3D '\0'; + + if (Data !=3D NULL && + ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename,= &Description, &LineNumber)) { + // + // Print ASSERT() information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "\n\rSMM_ASSERT!: %a (%d): %a\n\r", + Filename, + LineNumber, + Description + ); + } else if (Data !=3D NULL && + ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker,= &Format)) { + // + // Print DEBUG() information into output buffer. + // + CharCount =3D AsciiBSPrint ( + Buffer, + sizeof (Buffer), + Format, + Marker + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_ERROR_CODE)= { + // + // Print ERROR information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "ERROR: C%08x:V%08x I%x", + CodeType, + Value, + Instance + ); + ASSERT (CharCount > 0); + + if (CallerId !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %g", + CallerId + ); + } + + if (Data !=3D NULL) { + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + " %x", + Data + ); + } + + CharCount +=3D AsciiSPrint ( + &Buffer[CharCount], + (sizeof (Buffer) - (sizeof (Buffer[0]) * CharCount)), + "\n\r" + ); + } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) =3D=3D EFI_PROGRESS_CO= DE) { + // + // Print PROGRESS information into output buffer. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "PROGRESS CODE: V%08x I%x\n\r", + Value, + Instance + ); + } else if (Data !=3D NULL && + CompareGuid (&Data->Type, &gEfiStatusCodeDataTypeStringGuid) = && + ((EFI_STATUS_CODE_STRING_DATA *) Data)->StringType =3D=3D Efi= StringAscii) { + // + // EFI_STATUS_CODE_STRING_DATA + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "%a", + ((EFI_STATUS_CODE_STRING_DATA *) Data)->String.Ascii + ); + } else { + // + // Code type is not defined. + // + CharCount =3D AsciiSPrint ( + Buffer, + sizeof (Buffer), + "Undefined: C%08x:V%08x I%x\n\r", + CodeType, + Value, + Instance + ); + } + + // + // Call Usb3DebugPortLib function to do print. + // + Usb3DebugPortWrite ((UINT8 *) Buffer, CharCount); + + return EFI_SUCCESS; +} + +/** + Register status code callback function only when Report Status Code prot= ocol + is installed. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context, wh= ich is + always zero in current implementation. + +**/ +EFI_STATUS +EFIAPI +RegisterUsb3BootTimeHandlers ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + EFI_SMM_RSC_HANDLER_PROTOCOL *RscHandlerProtocol; + + Status =3D gSmst->SmmLocateProtocol ( + &gEfiSmmRscHandlerProtocolGuid, + NULL, + (VOID **) &RscHandlerProtocol + ); + ASSERT_EFI_ERROR (Status); + + Status =3D Usb3DebugPortInitialize (); + ASSERT_EFI_ERROR (Status); + + RscHandlerProtocol->Register (Usb3StatusCodeReportWorker); + + return EFI_SUCCESS; +} + +/** + Constructor function of SmmUsb3StatusCodeHandlerLib. + + This function allocates memory for extended status code data, caches + the report status code service, and registers events. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +SmmUsb3StatusCodeHandlerLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *Registration; + EFI_SMM_RSC_HANDLER_PROTOCOL *RscHandlerProtocol; + + if (!PcdGetBool (PcdStatusCodeUseUsb3)) { + return EFI_SUCCESS; + } + + Status =3D gSmst->SmmLocateProtocol ( + &gEfiSmmRscHandlerProtocolGuid, + NULL, + (VOID **) &RscHandlerProtocol + ); + if (!EFI_ERROR (Status)) { + RegisterUsb3BootTimeHandlers (NULL, NULL, NULL); + } else { + gSmst->SmmRegisterProtocolNotify ( + &gEfiSmmRscHandlerProtocolGuid, + RegisterUsb3BootTimeHandlers, + &Registration + ); + } + + return EFI_SUCCESS; +} diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3Statu= sCodeHandlerLib/SmmUsb3StatusCodeHandlerLib.inf b/Features/Intel/Debugging/= Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/SmmUsb3StatusCodeHandl= erLib.inf new file mode 100644 index 0000000000..1ea7c4d913 --- /dev/null +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Library/Usb3StatusCodeHa= ndlerLib/SmmUsb3StatusCodeHandlerLib.inf @@ -0,0 +1,53 @@ +## @file +# USB3 status code implementation. +# +# Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# vendor. This file may not be modified, except as allowed by +# additional terms of your license agreement. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmUsb3StatusCodeHandlerLib + FILE_GUID =3D 23C08AC3-130A-4E68-A1D5-A9FA8950677A + MODULE_TYPE =3D DXE_SMM_DRIVER + VERSION_STRING =3D 1.0 + CONSTRUCTOR =3D SmmUsb3StatusCodeHandlerLibConstructor + LIBRARY_CLASS =3D StatusCodeHandlerLib|DXE_SMM_DRIVER + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC (EBC is only for bui= ld) +# + +[Sources] + SmmUsb3StatusCodeHandlerLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec + +[LibraryClasses] + SmmServicesTableLib + PcdLib + DebugLib + BaseMemoryLib + ReportStatusCodeLib + Usb3DebugPortLib + +[Guids] + gEfiStatusCodeDataTypeStringGuid ## SOMETIMES_CONSUMES ## G= UID + +[Pcd] + gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3 ##= CONSUMES + +[Protocols] + gEfiSmmRscHandlerProtocolGuid ## CONSUMES + +[Depex] + TRUE diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Readme.md b/Featu= res/Intel/Debugging/Usb3DebugFeaturePkg/Readme.md index dc92f108ff..83d5b3606b 100644 --- a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Readme.md +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Readme.md @@ -1,7 +1,7 @@ # Overview * **Feature Name:** USB3 Debug -* **PI Phase(s) Supported:** PEI, DXE -* **SMM Required?** No +* **PI Phase(s) Supported:** PEI, DXE, SMM +* **SMM Required?** Yes =20 More Information: * [USB 3.1 Device-Class Specification for Debug Devices](https://www.usb.o= rg/sites/default/files/documents/usb_debug_class_rev_1_0_final_0.pdf) @@ -21,88 +21,140 @@ The Intel® UDK Debugger Tool can be used in a Linu= x or Windows host environm and provide runtime debug control via GNU Project Debugger (GDB) or the Mi= crosoft Windows Debug Tool (WinDbg) respectively. =20 +This feature also include a library used with StatusCodeHandler, it can ge= t output status code through USB. + # High-Level Theory of Operation -*_TODO_* -A description of how the device works at a high-level. +It provide a library Usb3StatusCodeHandlerLib used by edk2 StatusCodeHandl= er.efi, used to output status code through USB3. + +In the library contstructor function, Usb3StatusCodeHandlerLib register th= e call back function for ReportStatusCode. +When called, it call convert data from status code, and call Usb3DebugPort= Write() in Usb3DebugPortLib to output through USB3. =20 -The description should not be constrained to implementation details but pr= ovide a simple mental model of how the -feature is supposed to work. +Usb3StatusCodeHandlerLib include 3 libraries for PEI, RuntimeDxe, SMM: +* PeiUsb3StatusCodeHandlerLib +* RuntimeDxeUsb3StatusCodeHandlerLib +* SmmUsb3StatusCodeHandlerLib =20 ## Firmware Volumes -*_TODO_* -A bulleted list of the firmware volumes that feature module(s) are placed = in. +Linked with StatusCodeHandler.efi, and make sure put the StatusCodeHandler= .efi after the ReportStatusCodeRouter.efi. =20 ## Modules -*_TODO_* -A bulleted list of the modules that make up the feature. +* Usb3StatusCodeHandlerLib +* Usb3DebugPortLib +* Usb3DebugPortParamLibPcd =20 -## -*_TODO_* -Each module in the feature should have a section that describes the module= in a level of detail that is useful -to better understand the module source code. +## Usb3StatusCodeHandlerLib +This library register the call back function for ReportStatusCode, and out= put status code through USB3. =20 -## -*_TODO_* -Each library in the feature should have a section that describes the libra= ry in a level of detail that is useful -to better understand the library source code. +## Usb3DebugPortLib +The library provide the Usb3DebugPortWrite function to do the real write. =20 -## Key Functions -*_TODO_* -A bulleted list of key functions for interacting with the feature. +## Usb3DebugPortParamLibPcd +The library provide some functions to get the parameters of USB3 debug por= t from PCDs. =20 -Not all features need to be listed. Only functions exposed through externa= l interfaces that are important for feature -users to be aware of. +## Key Functions +* In PeiUsb3StatusCodeHandlerLib: + EFI_STATUS + EFIAPI + Usb3StatusCodeReportWorker ( + IN CONST EFI_PEI_SERVICES **PeiServices, + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN CONST EFI_GUID *CallerId, + IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL + ) + +* In RuntimeDxeUsb3StatusCodeHandlerLib: + EFI_STATUS + EFIAPI + Usb3StatusCodeReportWorker ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data OPTIONAL + ) + +* In SmmUsb3StatusCodeHandlerLib: + EFI_STATUS + EFIAPI + Usb3StatusCodeReportWorker ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data OPTIONAL + ) + +* In Usb3DebugPortLib: + RETURN_STATUS + EFIAPI + Usb3DebugPortInitialize ( + VOID + ) + + UINTN + EFIAPI + Usb3DebugPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) + + BOOLEAN + EFIAPI + Usb3DebugPortPoll ( + VOID + ) + + +* In Usb3DebugPortParamLibPcd: + UINT32 + EFIAPI + GetUsb3DebugPortController ( + VOID + ) + + BOOLEAN + EFIAPI + SetUsb3DebugPortController ( + UINT32 Controller + ) =20 ## Configuration -*_TODO_* -Information that is useful for configuring the feature. - -Not all configuration options need to be listed. This section is used to p= rovide more background on configuration -options than possible elsewhere. +** Link the library to StatusCodeHandler.efi. + Example: + MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerR= untimeDxe.inf { + + NULL|Usb3DebugFeaturePkg/Library/Usb3StatusCodeHandlerLib/RuntimeDxe= Usb3StatusCodeHandlerLib.inf + } + Refer to Usb3DebugFeature.dsc for other example. +* Config PCD gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3. + In platform .dsc file, need to config the type of gUsb3DebugFeaturePkgTo= kenSpaceGuid.PcdStatusCodeUseUsb3. + Use PcdsFixedAtBuild to save binary size, and use PcdsDynamic if want to= enable/disable in runtime. +* Select library used Usb3DebugPortLib and Usb3DebugPortParamLib, or provi= de the platform's special library. +* If select use Usb3DebugPortParamLibPcd, then config the PCDs. +* Make sure put the StatusCodeHandler.efi after the ReportStatusCodeRouter= .efi. =20 ## Data Flows -*_TODO_* -Architecturally defined data structures and flows for the feature. +Status Code (ReportStatusCode) -> USB3 data. =20 ## Control Flows -*_TODO_* -Key control flows for the feature. +ReportStatusCode() -> Usb3StatusCodeReportWorker() -> Usb3DebugPortWrite() =20 ## Build Flows -*_TODO_* -Any special build flows should be described in this section. - -This is particularly useful for features that use custom build tools or re= quire non-standard tool configuration. If the -standard flow in the feature package template is used, this section may be= empty. +There is not special build flows. =20 ## Test Point Results -*_TODO_* -The test(s) that can verify porting is complete for the feature. - -Each feature must describe at least one test point to verify the feature i= s successful. If the test point is not -implemented, this should be stated. +Verify the status code can output through USB3. =20 ## Functional Exit Criteria -*_TODO_* -The testable functionality for the feature. - -This section should provide an ordered list of criteria that a board integ= rator can reference to ensure the feature is -functional on their board. +N/A =20 ## Feature Enabling Checklist -*_TODO_* -An ordered list of required activities to achieve desired functionality fo= r the feature. - -## Performance Impact -A general expectation for the impact on overall boot performance due to us= ing this feature. - -This section is expected to provide guidance on: -* How to estimate performance impact due to the feature -* How to measure performance impact of the feature -* How to manage performance impact of the feature +* Set the PCD gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3 to T= RUE. +* Connect the device and host with a USB3 debug cable and use the USB port= as configured. +* Config the host OS or tools. +* Check the status code can output through USB3. =20 ## Common Optimizations -*_TODO_* -Common size or performance tuning options for this feature. - -This section is recommended but not required. If not used, the contents sh= ould be left empty. +Provide platform special Usb3DebugPortLib or Usb3DebugPortParamLib if need= ed. diff --git a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Usb3DebugFeatureP= kg.dec b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.d= ec index 2b19e48491..fc4092ffe1 100644 --- a/Features/Intel/Debugging/Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec +++ b/Features/Intel/Debugging/Usb3DebugFeaturePkg/Usb3DebugFeaturePkg.dec @@ -55,3 +55,5 @@ ## This PCD sepcifies the start index in CMOS, it will occupy 1 bytes sp= ace. gUsb3DebugFeaturePkgTokenSpaceGuid.PcdUsb3DebugPortFunctionIndex|0x5B|UI= NT8|0xF0000008 =20 +[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] + gUsb3DebugFeaturePkgTokenSpaceGuid.PcdStatusCodeUseUsb3|FALSE|BOOLEAN|0x= FF000001 --=20 2.24.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61161): https://edk2.groups.io/g/devel/message/61161 Mute This Topic: https://groups.io/mt/74819951/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-