From nobody Sat Apr 27 15:11:12 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+58945+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+58945+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1589006457; cv=none; d=zohomail.com; s=zohoarc; b=O1+Hh0fWrdwpxWObvLtKpQMYEVvM5DnQhRloqylDhIK2ygvezWWw1SWsEZ+h0qV+amcA/3vC49IEPJLzZw4LY1O/azVCg4lizcAmRrIyHuJwL0u5HWlsXKrbDQN1YWceK6AV62HDmw+1ru5iGdMmckjOIJvOG7D6xKyBJc3LIo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589006457; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=pX/J6s+NpeuRZnNfgN8dQvpPYU0wqxhPqyQReydDzdE=; b=I543Og4sKvWa7oRe7cyBbNyPIi3KfvCM3wTlQL2z0dMhV82WLP83wWORkDyUq4lLntnQ3ZZVarKF3GVWNk7lOFyLCum2HKfGpC6Aw+iTGzT0vwe8fRjN8d1gki7e51qz1il7o8wbVbHOa+fXQR3+isKPDtgCu6TTDANFBUaYouI= 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+58945+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 1589006457284525.2401398656297; Fri, 8 May 2020 23:40:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id U8lTYY1788612x4nMcEDiGm2; Fri, 08 May 2020 23:40:54 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web12.5827.1589006454342364750 for ; Fri, 08 May 2020 23:40:54 -0700 IronPort-SDR: cXD2SoDzCzP6eX993AJCQa4f7JovyxwySn+7n2+Dv02YGAUj4AjZdxY86PgOsKthT3pk6nBwOo S/Gj3OUWObZw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2020 23:40:53 -0700 IronPort-SDR: NiyEa2xcSIJp32Oa2hMfye1dy2KTE6khAKO4BVlmkv37GYCqm3E/eXi/dVbp1yaGHbXBO5BK5s AKXKHatZNlAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,370,1583222400"; d="scan'208";a="408348284" X-Received: from shwdejointlab96.ccr.corp.intel.com ([10.239.134.144]) by orsmga004.jf.intel.com with ESMTP; 08 May 2020 23:40:52 -0700 From: "Tan, Ming" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH] Add Features/Intel/OutOfBandManagement/SpcrFeaturePkg. Date: Sat, 9 May 2020 14:40:39 +0800 Message-Id: <20200509064039.19869-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: 9bVH76oe25Z5fSajvnhEBERqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589006454; bh=kXWFWfNczH9UZF4uHInp9/4+E8mdzG44DWVsWJVpkts=; h=Content-Type:Date:From:Reply-To:Subject:To; b=a/z5MihJbiXvYT/ZEEd/oojMhSCEQqSoWR8kA0OCsp5itvSgNqHJK7YNaGbMj7OBl7w nkob5RKmjthwOtKrVhES/6CcN2BY408/JWHm9f5VbA36avFOXToxeeESLoIZX1DC/UIp9 zO5Vsr1V2rwHf2hujdRPRbyvV2zJhz+NlnY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2710 It is used to support the Serial Port Console Redirection Table (SPCR). Signed-off-by: Ming Tan --- .../Include/Library/SpcrDeviceLib.h | 26 + .../SpcrFeaturePkg/Include/SpcrFeature.dsc | 108 ++++ .../SpcrDeviceLibNull/SpcrDeviceLibNull.c | 25 + .../SpcrDeviceLibNull/SpcrDeviceLibNull.inf | 22 + .../SpcrFeaturePkg/Readme.md | 64 +++ .../SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.c | 467 ++++++++++++++++++ .../SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.h | 81 +++ .../SpcrAcpiDxe/SpcrAcpiDxe.inf | 42 ++ .../SpcrFeaturePkg/SpcrFeaturePkg.dec | 27 + .../SpcrFeaturePkg/SpcrFeaturePkg.dsc | 30 ++ 10 files changed, 892 insertions(+) create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Inclu= de/Library/SpcrDeviceLib.h create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Inclu= de/SpcrFeature.dsc create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Libra= ry/SpcrDeviceLibNull/SpcrDeviceLibNull.c create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Libra= ry/SpcrDeviceLibNull/SpcrDeviceLibNull.inf create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readm= e.md create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrA= cpiDxe/SpcrAcpi.c create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrA= cpiDxe/SpcrAcpi.h create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrA= cpiDxe/SpcrAcpiDxe.inf create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrF= eaturePkg.dec create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrF= eaturePkg.dsc diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Libr= ary/SpcrDeviceLib.h b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Inc= lude/Library/SpcrDeviceLib.h new file mode 100644 index 0000000000..bca1b97014 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Library/Spc= rDeviceLib.h @@ -0,0 +1,26 @@ +/** @file + Header file for a library about SPCR device. + SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) de= vice. + + Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _SPCR_DEVICE_LIB_H_ +#define _SPCR_DEVICE_LIB_H_ + +/** + Get a Serial Port device used for SPCR. + The caller should call FreePool() to free the memory if return value is = not NULL. + + @retval NULL Can not get device. + @retval Others A serial port device path. + +**/ +EFI_DEVICE_PATH_PROTOCOL * +GetSpcrDevice ( + VOID + ); + +#endif // _SPCR_DEVICE_LIB_H_ diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Spcr= Feature.dsc b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Spc= rFeature.dsc new file mode 100644 index 0000000000..89ef648f31 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/SpcrFeature= .dsc @@ -0,0 +1,108 @@ +## @file +# This package provides advanced feature functionality about Serial Port C= onsole Redirection Table (SPCR). +# This file should be included into another package DSC file to build this= feature. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +##########################################################################= ###### +# +# Defines Section - statements that will be processed to create a Makefile. +# +##########################################################################= ###### +[Defines] +!ifndef $(PEI_ARCH) + !error "PEI_ARCH must be specified to build this feature!" +!endif +!ifndef $(DXE_ARCH) + !error "DXE_ARCH must be specified to build this feature!" +!endif + +##########################################################################= ###### +# +# Library Class section - list of all Library Classes needed by this featu= re. +# +##########################################################################= ###### +[LibraryClasses] + ####################################### + # Edk2 Packages + ####################################### + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf + + ####################################### + # SpcrFeaturePkg Packages + ####################################### + SpcrDeviceLib|SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull= .inf + +[LibraryClasses.common.DXE_DRIVER] + ####################################### + # Edk2 Packages + ####################################### + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf + +##########################################################################= ###### +# +# Component section - list of all components that need built for this feat= ure. +# +# Note: The EDK II DSC file is not used to specify how compiled binary ima= ges get placed +# into firmware volume images. This section is just a list of module= s to compile from +# source into UEFI-compliant binaries. +# It is the FDF file that contains information on combining binary f= iles into firmware +# volume images, whose concept is beyond UEFI and is described in PI= specification. +# There may also be modules listed in this section that are not requ= ired in the FDF file, +# When a module listed here is excluded from FDF file, then UEFI-com= pliant binary will be +# generated for it, but the binary will not be put into any firmware= volume. +# +##########################################################################= ###### + +# +# Feature DXE Components +# + +# @todo: Change below line to [Components.$(DXE_ARCH)] after https://bugzi= lla.tianocore.org/show_bug.cgi?id=3D2308 +# is completed. +[Components.X64] + ##################################### + # Spcr Feature Package + ##################################### + + # Add library instances here that are not included in package components= and should be tested + # in the package build. + + # Add components here that should be included in the package build. + SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpiDxe.inf + #{ +# +# SpcrDeviceLib|SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLi= bNull.inf +# } + +##########################################################################= ######################### +# +# BuildOptions Section - Define the module specific tool chain flags that = should be used as +# the default flags for a module. These flags are a= ppended to any +# standard flags that are defined by the build proc= ess. They can be +# applied for any modules or only those modules wit= h the specific +# module style (EDK or EDKII) specified in [Compone= nts] section. +# +# For advanced features, it is recommended to enabl= e [BuildOptions] in +# the applicable INF file so it does not affect the= whole board package +# build when this DSC file is active. +# +##########################################################################= ######################### +[BuildOptions] diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/Spcr= DeviceLibNull/SpcrDeviceLibNull.c b/Features/Intel/OutOfBandManagement/Spcr= FeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.c new file mode 100644 index 0000000000..5d282a9b0a --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceL= ibNull/SpcrDeviceLibNull.c @@ -0,0 +1,25 @@ +/** @file + Implementation for a NULL library of SpcrDeviceLib. + SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) de= vice. + + Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Get a Serial Port device used for SPCR. + + @retval NULL Can not get device. + +**/ +EFI_DEVICE_PATH_PROTOCOL* +GetSpcrDevice ( + VOID + ) +{ + return NULL; +} diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/Spcr= DeviceLibNull/SpcrDeviceLibNull.inf b/Features/Intel/OutOfBandManagement/Sp= crFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf new file mode 100644 index 0000000000..bf40dc48c3 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceL= ibNull/SpcrDeviceLibNull.inf @@ -0,0 +1,22 @@ +## @file +# Implementation for a NULL library of SpcrDeviceLib. +# SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) de= vice. +# +# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D SpcrDeviceLibNull + FILE_GUID =3D 8865739F-D0A8-4936-A457-8B3521EC60D1 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D SpcrDeviceLib + +[Packages] + MdePkg/MdePkg.dec + +[Sources] + SpcrDeviceLibNull.c diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readme.md b/= Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readme.md new file mode 100644 index 0000000000..a16835b151 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readme.md @@ -0,0 +1,64 @@ +# Overview +* **Feature Name:** Serial Port Console Redirection Table (SPCR) +* **PI Phase(s) Supported:** DXE +* **SMM Required?** No + +More Information: +* [Serial Port Console Redirection Table (SPCR)](https://docs.microsoft.co= m/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-t= able) + +## Purpose +The SPCR feature provides the functionality that select a serial port devi= ce and fill its info to ACPI table. +Windows can get this info and use this serial port as input/output device = in Microsoft=C2=AE Windows=C2=AE Emergency Management Services (EMS). + +# High-Level Theory of Operation +A dxe driver will call a library function to get the serial port device, a= nd produces the ACPI table. +Platform can implement its own library to select the serial port device. + +## Firmware Volumes +* PostMemory + +## Modules +* SpcrAcpiDxe +* SpcrDeviceLibNull + +## SpcrAcpiDxe +The main driver of convert the serial port device info to ACPI table. +It will call the function GetSpcrDevice() in the library SpcrDeviceLib to = get the serial port device path. +If the serial port device path is not NULL, then use gEfiPciIoProtocolGuid= to get the PCI info, and use the gEfiSerialIoProtocolGuid to get the seria= l port info, such as the baud rate etc. +If the serial port device is PCI device 00:16:03 (AMT serial over lan PCI = device), then will set the BaseAddress. +At last fill the ACPI table as Windows required. + +## SpcrDeviceLibNull +A NULL implemention of library SpcrDeviceLib, it return NULL for function = GetSpcrDevice(). +Platform maybe implemente its own SpcrDeviceLib. + +## Key Functions +Fill the serial port device info used for SPCR to ACPI table. + +## Configuration +There is not special configuration. +But the platform maybe implemente its own SpcrDeviceLib. + +## Data Flows +GetSpcrDevice() -> serial port device path -> get PCI info and serial port= info -> ACPI table. + +## Control Flows +GetSpcrDevice() in SpcrDeviceLib -> SpcrAcpiDxe. + +## Build Flows +There is not special build flow. + +## Test Point Results +* Check the output ACPI table. + +## Functional Exit Criteria +* Check the output ACPI table. + +## Feature Enabling Checklist +There is not special PCD to enable this feature. + +## Performance Impact +The SpcrAcpiDxe.efi with SpcrDeviceLibNull debug version size: 1.4KB, rele= ase version size: 1.12KB. + +## Common Optimizations +N/A now. diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/= SpcrAcpi.c b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/= SpcrAcpi.c new file mode 100644 index 0000000000..85ac48cfa5 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcp= i.c @@ -0,0 +1,467 @@ +/** @file + Implementation the driver used to add SPCR device info to ACPI table. + SPCR is abbreviation of Serial Port Console Redirection Table (SPCR). + + Copyright (c) 2004 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "SpcrAcpi.h" + +#define PCANSITYPE 0 +#define VT100TYPE 1 +#define VT100PLUSTYPE 2 +#define VTUTF8TYPE 3 + +#define PCI_MAX_BAR_NO 6 + +UINT8 TerminalTypeValue[4] =3D +{ + PCANSITYPE, + VT100TYPE, + VT100PLUSTYPE, + VTUTF8TYPE +}; + +/// +/// Guid for messaging path, used in Serial port setting. +/// +EFI_GUID TerminalTypeGuid[4] =3D { + DEVICE_PATH_MESSAGING_PC_ANSI, + DEVICE_PATH_MESSAGING_VT_100, + DEVICE_PATH_MESSAGING_VT_100_PLUS, + DEVICE_PATH_MESSAGING_VT_UTF8 +}; + +// +// Serial Port Console Redirection Table +// Please modify all values in Spcr.h only. +// +EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE gSpcrInfo =3D { + { + EFI_ACPI_2_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, + sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE), + EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION, + + // + // Checksum will be updated at runtime + // + 0x00, + + // + // It is expected that these values will be programmed at runtime + // + {'I', 'N', 'T', 'E', 'L', ' '}, + + SIGNATURE_64 ('S', 'P', 'C', 'R', 'T', 'a', 'b', 'l'), + 0x00, // Spcr revision, + SIGNATURE_32 ('I', 'N', 'T', 'L'), + 0x01 + }, + + // + // Beginning of SPCR specific fields + // + 0x00, //INTERFACE_TYPE, + { + 0x00, //RESERVED_BYTE, + 0x00, //RESERVED_BYTE, + 0x00 //RESERVED_BYTE, + }, + + // + // Base Address Block + // + { + EFI_ACPI_3_0_SYSTEM_IO, + 0x08, //BASE_ADDRESS_BIT_WIDTH, + 0x00, //BASE_ADDRESS_BIT_OFFSET, + 0x00, //RESERVED_BYTE, + 0x0000000000000000 //BASE_ADDRESS_ADDRESS, + }, + + 0x03, //INTERRUPT_TYPE, + 0x04, //IRQ, + 0x04, //GLOBAL_SYSTEM_INTERRUPT, + 0x07, //BAUD_RATE, + 0x00, //PARITY, + 0x01, //STOP_BITS, + 0x00, //FLOW_CONTROL, + 0x03, //TERMINAL_TYPE, + 0x00, //LANGUAGE, + 0xFFFF, //PCI_DEVICE_ID, + 0xFFFF, //PCI_VENDOR_ID, + 0x00, //PCI_BUS_NUMBER, + 0x00, //PCI_DEVICE_NUMBER, + 0x00, //PCI_FUNCTION_NUMBER, + 0x00000000, //PCI_FLAGS, + 0x00, //PCI_SEGMENT, + EFI_ACPI_RESERVED_DWORD +}; + + +/** + + Install Boot Device Selection Protocol + + @param ImageHandle The image handle. + @param SystemTable The system table. + + @retval EFI_SUCEESS BDS has finished initializing. + Return the dispatcher and recall BDS.Entry + @retval Other Return status from AllocatePool() or gBS->InstallP= rotocolInterface + +**/ +EFI_STATUS +EFIAPI +SpcrInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT ReadyToBootEvent; + // + // Install protocol interface + // + Status =3D EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + OutOfBandACPITableConstruction, + NULL, + &ReadyToBootEvent + ); + return Status; +} + +/** + Check whether the device path node is ISA Serial Node. + + @param DevicePath Device path node to be checked + + @retval TRUE It's ISA Serial Node. + @retval FALSE It's NOT ISA Serial Node. + +**/ +BOOLEAN +HasIsaSerialNode ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_DEVICE_PATH_PROTOCOL *Node; + ACPI_HID_DEVICE_PATH *Acpi; + + for (Node =3D DevicePath; !IsDevicePathEnd (Node); Node =3D NextDevicePa= thNode (Node)) { + Acpi =3D (ACPI_HID_DEVICE_PATH *) Node; + if ((DevicePathType (Acpi) =3D=3D ACPI_DEVICE_PATH) && (DevicePathSubT= ype (Acpi) =3D=3D ACPI_DP) && + (ReadUnaligned32 (&Acpi->HID) =3D=3D EISA_PNP_ID (0x0501))) { + return TRUE; + } + } + + return FALSE; +} + +/** + Get Irq and resource info from isa type console device. + + @param SavedDevicePath Device path for isa device. + +**/ +VOID +GetIsaTypeInfo ( + IN EFI_DEVICE_PATH_PROTOCOL *SavedDevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + ACPI_RESOURCE_HEADER_PTR Resources; + EFI_SIO_PROTOCOL *Sio; + EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *Irq; + EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *FixedLocation; + + // + // Try to get IRP and BaseAddress info. + // + Status =3D gBS->LocateDevicePath( + &gEfiSioProtocolGuid, + &SavedDevicePath, + &Handle + ); + if (EFI_ERROR(Status)) { + return; + } + + Status =3D gBS->HandleProtocol ( + Handle, + &gEfiSioProtocolGuid, + (VOID **) &Sio + ); + if (EFI_ERROR(Status)) { + return; + } + + Status =3D Sio->GetResources (Sio, &Resources); + if (EFI_ERROR(Status)) { + return; + } + + while (Resources.SmallHeader->Byte !=3D ACPI_END_TAG_DESCRIPTOR) { + switch (Resources.SmallHeader->Byte) { + case ACPI_IRQ_DESCRIPTOR: + case ACPI_IRQ_NOFLAG_DESCRIPTOR: + Irq =3D (EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *) Resources.SmallHeader; + gSpcrInfo.Irq =3D 0; + while (Irq->Mask > 1) { + gSpcrInfo.Irq ++; + Irq->Mask =3D Irq->Mask >> 1; + } + break; + case ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR: + FixedLocation =3D (EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *)= Resources.SmallHeader; + gSpcrInfo.BaseAddress.Address =3D FixedLocation->BaseAddress; + break; + default: + break; + } + + if (Resources.SmallHeader->Bits.Type =3D=3D 0) { + Resources.SmallHeader =3D (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *= ) Resources.SmallHeader + + Resources.SmallHeader->Bits.Length + + sizeof (*Resources.SmallHeader)); + } else { + Resources.LargeHeader =3D (ACPI_LARGE_RESOURCE_HEADER *) ((UINT8 *= ) Resources.LargeHeader + + Resources.LargeHeader->Length + + sizeof (*Resources.LargeHeader)); + } + } +} + +/** + Get Irq and resource info from Pci type console device. + + @param SavedDevicePath Device path for PCI device. + +**/ +VOID +GetPciTypeInfo ( + IN EFI_DEVICE_PATH_PROTOCOL *SavedDevicePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE PciHandle; + EFI_PCI_IO_PROTOCOL *PciIo; + UINTN Bus; + UINTN Device; + UINTN Function; + UINTN SegNum; + UINTN Irq; + UINT16 BaseAddress; + UINT8 Count; + UINT64 Supports; + UINT16 VendorId; + UINT16 DeviceId; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Resources; + + PciIo =3D NULL; + Resources =3D NULL; + Supports =3D 0x01; + Bus =3D 0; + Device =3D 0; + Function =3D 0; + SegNum =3D 0; + Irq =3D 0; + BaseAddress =3D 0; + VendorId =3D 0; + DeviceId =3D 0; + + Status =3D gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &SavedDevicePa= th, (VOID **) &PciHandle); + if (EFI_ERROR (Status)) { + Status =3D EFI_NOT_FOUND; + return; + } + + Status =3D gBS->HandleProtocol(PciHandle, &gEfiPciIoProtocolGuid, (VOID = **) &PciIo); + if (EFI_ERROR (Status) || (PciIo =3D=3D NULL)) { + Status =3D EFI_NOT_FOUND; + return; + } + + PciIo->GetLocation(PciIo, &SegNum, &Bus, &Device, &Function); + if (EFI_ERROR (Status)) { + Status =3D EFI_NOT_FOUND; + return; + } + + if (Bus =3D=3D 0x00 && Device =3D=3D 0x16 && Function =3D=3D 3) + { + for (Count =3D 0; Count < PCI_MAX_BAR_NO; Count++) { + Status =3D PciIo->GetBarAttributes (PciIo, Count, &Supports, (VOID = **) &Resources); + if (!EFI_ERROR(Status)) { + if (Resources->ResType =3D=3D 1) { // TYPE_IO + BaseAddress=3D (UINT16)Resources->AddrRangeMin; + break; + } + FreePool (Resources); + Resources =3D NULL; + } + } + } + + Status =3D PciIo->Pci.Read(PciIo, EfiPciIoWidthUint8, 0x3c, 1, &Irq); + if (EFI_ERROR(Status)) { + goto Done; + } + + Status =3D PciIo->Pci.Read(PciIo, EfiPciIoWidthUint16, 0x00, 1, &VendorI= d); + if (EFI_ERROR(Status)) { + goto Done; + } + + Status =3D PciIo->Pci.Read(PciIo, EfiPciIoWidthUint16, 0x02, 1, &DeviceI= d); + if (EFI_ERROR(Status)) { + goto Done; + } + + gSpcrInfo.BaseAddress.Address =3D BaseAddress; + gSpcrInfo.Irq =3D (UINT8) Irq; + + gSpcrInfo.PciDeviceId =3D DeviceId; + gSpcrInfo.PciVendorId =3D VendorId; + gSpcrInfo.PciBusNumber =3D (UINT8) Bus; + gSpcrInfo.PciDeviceNumber =3D (UINT8) Device; + gSpcrInfo.PciFunctionNumber =3D (UINT8) Function; + gSpcrInfo.PciSegment =3D (UINT8) SegNum; + +Done: + if (Resources !=3D NULL) { + FreePool (Resources); + } +} + +/** + Installs the Smbios Table to the System Table. This function gets called + when the EFI_EVENT_SIGNAL_READY_TO_BOOT gets signaled + + @param Event The event to signal + @param Context Event contex + +**/ +VOID +EFIAPI +OutOfBandACPITableConstruction ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_DEVICE_PATH_PROTOCOL *SavedDevicePath; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + EFI_DEVICE_PATH_PROTOCOL *Tmp2DevicePath; + EFI_ACPI_TABLE_PROTOCOL *AcpiTablProtocol; + UINTN TurnKey; + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_SERIAL_IO_PROTOCOL *SerialIo; + UINT32 FlowControl; + VENDOR_DEVICE_PATH *Vendor; + UINT8 Index; + + Handle =3D NULL; + + SavedDevicePath =3D GetSpcrDevice(); + if (SavedDevicePath =3D=3D NULL) { + return; + + } + // + // Get TerminalType info from the last device path node. + // + TmpDevicePath =3D SavedDevicePath; + Tmp2DevicePath =3D TmpDevicePath; + while (!IsDevicePathEnd (TmpDevicePath)) { + Tmp2DevicePath =3D TmpDevicePath; + TmpDevicePath =3D NextDevicePathNode(TmpDevicePath); + } + Vendor =3D (VENDOR_DEVICE_PATH *) Tmp2DevicePath; + for (Index=3D0; Index < 4; Index ++) { + if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[Index])) { + gSpcrInfo.TerminalType =3D TerminalTypeValue[Index]; + break; + } + } + SetDevicePathEndNode (Tmp2DevicePath); + TmpDevicePath =3D SavedDevicePath; + // + // Get Console attribute from the serial io protocol. + // + Status =3D gBS->LocateDevicePath( + &gEfiSerialIoProtocolGuid, + &TmpDevicePath, + &Handle + ); + if (EFI_ERROR(Status)) { + goto out; + } + + Status =3D gBS->HandleProtocol ( + Handle, + &gEfiSerialIoProtocolGuid, + (VOID **) &SerialIo + ); + if (EFI_ERROR(Status)) { + goto out; + } + + switch (SerialIo->Mode->BaudRate) { + case 9600: + gSpcrInfo.BaudRate =3D 3; + break; + case 19200: + gSpcrInfo.BaudRate =3D 4; + break; + case 57600: + gSpcrInfo.BaudRate =3D 6; + break; + case 115200: + default: + gSpcrInfo.BaudRate =3D 7; + break; + } + + gSpcrInfo.FlowControl =3D 0; + SerialIo->GetControl(SerialIo, &FlowControl); + if ((FlowControl & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) !=3D 0) { + gSpcrInfo.FlowControl =3D UART_FLOW_CONTROL_HARDWARE; + } + + if (HasIsaSerialNode(SavedDevicePath)) { + GetIsaTypeInfo (SavedDevicePath); + } else { + GetPciTypeInfo (SavedDevicePath); + } + // + // Not create before, create new Spcr ACPI table. + // + Status =3D gBS->LocateProtocol ( + &gEfiAcpiTableProtocolGuid, + NULL, + (VOID**)&AcpiTablProtocol + ); + if (EFI_ERROR (Status)) { + goto out; + } + + // + // Add table + // + Status =3D AcpiTablProtocol->InstallAcpiTable ( + AcpiTablProtocol, + &gSpcrInfo, + sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_RED= IRECTION_TABLE), + &TurnKey + ); + ASSERT_EFI_ERROR (Status); + +out: + FreePool(SavedDevicePath); +} diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/= SpcrAcpi.h b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/= SpcrAcpi.h new file mode 100644 index 0000000000..c11da439fc --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcp= i.h @@ -0,0 +1,81 @@ +/** @file + Header file for the driver used to add SPCR device info to ACPI table. + SPCR is abbreviation of Serial Port Console Redirection Table (SPCR). + + Copyright (c) 2004 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _SPCR_ACPI_H_ +#define _SPCR_ACPI_H_ + + +#include +#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#pragma pack(1) + +/// +/// HII specific Vendor Device Path definition. +/// +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; + +#pragma pack() +// +// Prototypes +// + +/** + + Install Boot Device Selection Protocol + + @param ImageHandle The image handle. + @param SystemTable The system table. + + @retval EFI_SUCEESS BDS has finished initializing. + Return the dispatcher and recall BDS.Entry + @retval Other Return status from AllocatePool() or gBS->InstallP= rotocolInterface + +**/ +EFI_STATUS +EFIAPI +SpcrInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + Installs the Smbios Table to the System Table. This function gets called + when the EFI_EVENT_SIGNAL_READY_TO_BOOT gets signaled + + @param Event The event to signal + @param Context Event contex + +**/ +VOID +EFIAPI +OutOfBandACPITableConstruction ( + IN EFI_EVENT Event, + IN VOID *Context + ); +#endif diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/= SpcrAcpiDxe.inf b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcp= iDxe/SpcrAcpiDxe.inf new file mode 100644 index 0000000000..3fc84959a0 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcp= iDxe.inf @@ -0,0 +1,42 @@ +## @file +# SPCR is abbreviation of Serial Port Console Redirection Table (SPCR). +# +# Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D SpcrAcpiDxe + FILE_GUID =3D 31740724-5F96-48ca-AA0F-332ACA6B9A75 + VERSION_STRING =3D 2.0 + MODULE_TYPE =3D DXE_DRIVER + ENTRY_POINT =3D SpcrInitialize +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC +# + +[LibraryClasses] + UefiDriverEntryPoint + UefiLib + SpcrDeviceLib + +[Packages] + MdePkg/MdePkg.dec + SpcrFeaturePkg/SpcrFeaturePkg.dec + +[Sources] + SpcrAcpi.h + SpcrAcpi.c + +[Protocols] + gEfiAcpiTableProtocolGuid ## CONSUMES + gEfiSioProtocolGuid ## SOMETIMES_CONSUMES + gEfiSerialIoProtocolGuid ## SOMETIMES_CONSUMES + gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES + +[Depex] + TRUE diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeatureP= kg.dec b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.d= ec new file mode 100644 index 0000000000..03776abf06 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dec @@ -0,0 +1,27 @@ +## @file +# This package provides advanced feature functionality about Serial Port C= onsole Redirection Table (SPCR). +# This package should only depend on EDK II Core packages, IntelSiliconPkg= , and MinPlatformPkg. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + DEC_SPECIFICATION =3D 0x00010017 + PACKAGE_NAME =3D SpcrFeaturePkg + PACKAGE_GUID =3D 20E84A8A-9008-4798-8215-697555E95B29 + PACKAGE_VERSION =3D 0.1 + +[Includes] + Include + +[LibraryClasses] + ## @libraryclass Provides an API for get SPCR device. + # + SpcrDeviceLib|Include/Library/SpcrDeviceLib.h diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeatureP= kg.dsc b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.d= sc new file mode 100644 index 0000000000..82d2d3ac73 --- /dev/null +++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dsc @@ -0,0 +1,30 @@ +## @file +# This package provides advanced feature functionality about Serial Port C= onsole Redirection Table (SPCR). +# This package should only depend on EDK II Core packages, IntelSiliconPkg= , and MinPlatformPkg. +# +# The DEC files are used by the utilities that parse DSC and +# INF files to generate AutoGen.c and AutoGen.h files +# for the build infrastructure. +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + PLATFORM_NAME =3D SpcrFeaturePkg + PLATFORM_GUID =3D 2CEB97B5-610D-440F-A2A7-6775AE2A7E89 + PLATFORM_VERSION =3D 0.1 + DSC_SPECIFICATION =3D 0x00010005 + OUTPUT_DIRECTORY =3D Build/$(PLATFORM_NAME) + SUPPORTED_ARCHITECTURES =3D IA32|X64 + BUILD_TARGETS =3D DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER =3D DEFAULT + PEI_ARCH =3D IA32 + DXE_ARCH =3D X64 + +# +# This package always builds the feature. +# +!include Include/SpcrFeature.dsc --=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 (#58945): https://edk2.groups.io/g/devel/message/58945 Mute This Topic: https://groups.io/mt/74091287/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-