.../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/Include/Library/SpcrDeviceLib.h create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/SpcrFeature.dsc create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.c create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readme.md create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.c create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.h create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpiDxe.inf create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dec create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dsc
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2710
It is used to support the Serial Port Console Redirection Table (SPCR).
Signed-off-by: Ming Tan <ming.tan@intel.com>
---
.../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/Include/Library/SpcrDeviceLib.h
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/SpcrFeature.dsc
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.c
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Readme.md
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.c
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpi.h
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpiDxe.inf
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dec
create mode 100644 Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dsc
diff --git a/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Library/SpcrDeviceLib.h b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Library/SpcrDeviceLib.h
new file mode 100644
index 0000000000..bca1b97014
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/Library/SpcrDeviceLib.h
@@ -0,0 +1,26 @@
+/** @file
+ Header file for a library about SPCR device.
+ SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) device.
+
+ Copyright (c) 2011 - 2020, Intel Corporation. All rights reserved.<BR>
+ 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/SpcrFeature.dsc b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Include/SpcrFeature.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 Console 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.<BR>
+#
+# 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 feature.
+#
+################################################################################
+[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/UefiDriverEntryPoint.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+
+ #######################################
+ # SpcrFeaturePkg Packages
+ #######################################
+ SpcrDeviceLib|SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf
+
+[LibraryClasses.common.DXE_DRIVER]
+ #######################################
+ # Edk2 Packages
+ #######################################
+ MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+
+################################################################################
+#
+# Component section - list of all components that need built for this feature.
+#
+# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
+# into firmware volume images. This section is just a list of modules to compile from
+# source into UEFI-compliant binaries.
+# It is the FDF file that contains information on combining binary files 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 required in the FDF file,
+# When a module listed here is excluded from FDF file, then UEFI-compliant 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://bugzilla.tianocore.org/show_bug.cgi?id=2308
+# 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
+ #{
+# <LibraryClasses>
+# SpcrDeviceLib|SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf
+# }
+
+###################################################################################################
+#
+# BuildOptions Section - Define the module specific tool chain flags that should be used as
+# the default flags for a module. These flags are appended to any
+# standard flags that are defined by the build process. They can be
+# applied for any modules or only those modules with the specific
+# module style (EDK or EDKII) specified in [Components] section.
+#
+# For advanced features, it is recommended to enable [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/SpcrDeviceLibNull/SpcrDeviceLibNull.c b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.c
new file mode 100644
index 0000000000..5d282a9b0a
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.c
@@ -0,0 +1,25 @@
+/** @file
+ Implementation for a NULL library of SpcrDeviceLib.
+ SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) device.
+
+ Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Include/Uefi.h>
+#include <Protocol/DevicePath.h>
+
+/**
+ 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/SpcrDeviceLibNull/SpcrDeviceLibNull.inf b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf
new file mode 100644
index 0000000000..bf40dc48c3
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/Library/SpcrDeviceLibNull/SpcrDeviceLibNull.inf
@@ -0,0 +1,22 @@
+## @file
+# Implementation for a NULL library of SpcrDeviceLib.
+# SpcrDeviceLib is usd for Serial Port Console Redirection Table (SPCR) device.
+#
+# Copyright (c) 2017 - 2020, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = SpcrDeviceLibNull
+ FILE_GUID = 8865739F-D0A8-4936-A457-8B3521EC60D1
+ VERSION_STRING = 1.0
+ MODULE_TYPE = BASE
+ LIBRARY_CLASS = 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.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table)
+
+## Purpose
+The SPCR feature provides the functionality that select a serial port device and fill its info to ACPI table.
+Windows can get this info and use this serial port as input/output device in Microsoft® Windows® Emergency Management Services (EMS).
+
+# High-Level Theory of Operation
+A dxe driver will call a library function to get the serial port device, and 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 serial 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, release 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/SpcrAcpi.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.<BR>
+ 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] =
+{
+ PCANSITYPE,
+ VT100TYPE,
+ VT100PLUSTYPE,
+ VTUTF8TYPE
+};
+
+///
+/// Guid for messaging path, used in Serial port setting.
+///
+EFI_GUID TerminalTypeGuid[4] = {
+ 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 = {
+ {
+ 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->InstallProtocolInterface
+
+**/
+EFI_STATUS
+EFIAPI
+SpcrInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_EVENT ReadyToBootEvent;
+ //
+ // Install protocol interface
+ //
+ Status = 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 = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
+ Acpi = (ACPI_HID_DEVICE_PATH *) Node;
+ if ((DevicePathType (Acpi) == ACPI_DEVICE_PATH) && (DevicePathSubType (Acpi) == ACPI_DP) &&
+ (ReadUnaligned32 (&Acpi->HID) == 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 = gBS->LocateDevicePath(
+ &gEfiSioProtocolGuid,
+ &SavedDevicePath,
+ &Handle
+ );
+ if (EFI_ERROR(Status)) {
+ return;
+ }
+
+ Status = gBS->HandleProtocol (
+ Handle,
+ &gEfiSioProtocolGuid,
+ (VOID **) &Sio
+ );
+ if (EFI_ERROR(Status)) {
+ return;
+ }
+
+ Status = Sio->GetResources (Sio, &Resources);
+ if (EFI_ERROR(Status)) {
+ return;
+ }
+
+ while (Resources.SmallHeader->Byte != ACPI_END_TAG_DESCRIPTOR) {
+ switch (Resources.SmallHeader->Byte) {
+ case ACPI_IRQ_DESCRIPTOR:
+ case ACPI_IRQ_NOFLAG_DESCRIPTOR:
+ Irq = (EFI_ACPI_IRQ_NOFLAG_DESCRIPTOR *) Resources.SmallHeader;
+ gSpcrInfo.Irq = 0;
+ while (Irq->Mask > 1) {
+ gSpcrInfo.Irq ++;
+ Irq->Mask = Irq->Mask >> 1;
+ }
+ break;
+ case ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR:
+ FixedLocation = (EFI_ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR *)Resources.SmallHeader;
+ gSpcrInfo.BaseAddress.Address = FixedLocation->BaseAddress;
+ break;
+ default:
+ break;
+ }
+
+ if (Resources.SmallHeader->Bits.Type == 0) {
+ Resources.SmallHeader = (ACPI_SMALL_RESOURCE_HEADER *) ((UINT8 *) Resources.SmallHeader
+ + Resources.SmallHeader->Bits.Length
+ + sizeof (*Resources.SmallHeader));
+ } else {
+ Resources.LargeHeader = (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 = NULL;
+ Resources = NULL;
+ Supports = 0x01;
+ Bus = 0;
+ Device = 0;
+ Function = 0;
+ SegNum = 0;
+ Irq = 0;
+ BaseAddress = 0;
+ VendorId = 0;
+ DeviceId = 0;
+
+ Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &SavedDevicePath, (VOID **) &PciHandle);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_NOT_FOUND;
+ return;
+ }
+
+ Status = gBS->HandleProtocol(PciHandle, &gEfiPciIoProtocolGuid, (VOID **) &PciIo);
+ if (EFI_ERROR (Status) || (PciIo == NULL)) {
+ Status = EFI_NOT_FOUND;
+ return;
+ }
+
+ PciIo->GetLocation(PciIo, &SegNum, &Bus, &Device, &Function);
+ if (EFI_ERROR (Status)) {
+ Status = EFI_NOT_FOUND;
+ return;
+ }
+
+ if (Bus == 0x00 && Device == 0x16 && Function == 3)
+ {
+ for (Count = 0; Count < PCI_MAX_BAR_NO; Count++) {
+ Status = PciIo->GetBarAttributes (PciIo, Count, &Supports, (VOID **) &Resources);
+ if (!EFI_ERROR(Status)) {
+ if (Resources->ResType == 1) { // TYPE_IO
+ BaseAddress= (UINT16)Resources->AddrRangeMin;
+ break;
+ }
+ FreePool (Resources);
+ Resources = NULL;
+ }
+ }
+ }
+
+ Status = PciIo->Pci.Read(PciIo, EfiPciIoWidthUint8, 0x3c, 1, &Irq);
+ if (EFI_ERROR(Status)) {
+ goto Done;
+ }
+
+ Status = PciIo->Pci.Read(PciIo, EfiPciIoWidthUint16, 0x00, 1, &VendorId);
+ if (EFI_ERROR(Status)) {
+ goto Done;
+ }
+
+ Status = PciIo->Pci.Read(PciIo, EfiPciIoWidthUint16, 0x02, 1, &DeviceId);
+ if (EFI_ERROR(Status)) {
+ goto Done;
+ }
+
+ gSpcrInfo.BaseAddress.Address = BaseAddress;
+ gSpcrInfo.Irq = (UINT8) Irq;
+
+ gSpcrInfo.PciDeviceId = DeviceId;
+ gSpcrInfo.PciVendorId = VendorId;
+ gSpcrInfo.PciBusNumber = (UINT8) Bus;
+ gSpcrInfo.PciDeviceNumber = (UINT8) Device;
+ gSpcrInfo.PciFunctionNumber = (UINT8) Function;
+ gSpcrInfo.PciSegment = (UINT8) SegNum;
+
+Done:
+ if (Resources != 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 = NULL;
+
+ SavedDevicePath = GetSpcrDevice();
+ if (SavedDevicePath == NULL) {
+ return;
+
+ }
+ //
+ // Get TerminalType info from the last device path node.
+ //
+ TmpDevicePath = SavedDevicePath;
+ Tmp2DevicePath = TmpDevicePath;
+ while (!IsDevicePathEnd (TmpDevicePath)) {
+ Tmp2DevicePath = TmpDevicePath;
+ TmpDevicePath = NextDevicePathNode(TmpDevicePath);
+ }
+ Vendor = (VENDOR_DEVICE_PATH *) Tmp2DevicePath;
+ for (Index=0; Index < 4; Index ++) {
+ if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[Index])) {
+ gSpcrInfo.TerminalType = TerminalTypeValue[Index];
+ break;
+ }
+ }
+ SetDevicePathEndNode (Tmp2DevicePath);
+ TmpDevicePath = SavedDevicePath;
+ //
+ // Get Console attribute from the serial io protocol.
+ //
+ Status = gBS->LocateDevicePath(
+ &gEfiSerialIoProtocolGuid,
+ &TmpDevicePath,
+ &Handle
+ );
+ if (EFI_ERROR(Status)) {
+ goto out;
+ }
+
+ Status = gBS->HandleProtocol (
+ Handle,
+ &gEfiSerialIoProtocolGuid,
+ (VOID **) &SerialIo
+ );
+ if (EFI_ERROR(Status)) {
+ goto out;
+ }
+
+ switch (SerialIo->Mode->BaudRate) {
+ case 9600:
+ gSpcrInfo.BaudRate = 3;
+ break;
+ case 19200:
+ gSpcrInfo.BaudRate = 4;
+ break;
+ case 57600:
+ gSpcrInfo.BaudRate = 6;
+ break;
+ case 115200:
+ default:
+ gSpcrInfo.BaudRate = 7;
+ break;
+ }
+
+ gSpcrInfo.FlowControl = 0;
+ SerialIo->GetControl(SerialIo, &FlowControl);
+ if ((FlowControl & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) != 0) {
+ gSpcrInfo.FlowControl = UART_FLOW_CONTROL_HARDWARE;
+ }
+
+ if (HasIsaSerialNode(SavedDevicePath)) {
+ GetIsaTypeInfo (SavedDevicePath);
+ } else {
+ GetPciTypeInfo (SavedDevicePath);
+ }
+ //
+ // Not create before, create new Spcr ACPI table.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiAcpiTableProtocolGuid,
+ NULL,
+ (VOID**)&AcpiTablProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ goto out;
+ }
+
+ //
+ // Add table
+ //
+ Status = AcpiTablProtocol->InstallAcpiTable (
+ AcpiTablProtocol,
+ &gSpcrInfo,
+ sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_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/SpcrAcpi.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.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _SPCR_ACPI_H_
+#define _SPCR_ACPI_H_
+
+
+#include <IndustryStandard/Acpi30.h>
+#include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
+//#include <Guid/GlobalVariable.h>
+
+#include <Library/UefiLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/SpcrDeviceLib.h>
+
+#include <Protocol/AcpiTable.h>
+#include <Protocol/SerialIo.h>
+#include <Protocol/SuperIo.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/PciIo.h>
+
+#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->InstallProtocolInterface
+
+**/
+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/SpcrAcpiDxe/SpcrAcpiDxe.inf
new file mode 100644
index 0000000000..3fc84959a0
--- /dev/null
+++ b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrAcpiDxe/SpcrAcpiDxe.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.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = SpcrAcpiDxe
+ FILE_GUID = 31740724-5F96-48ca-AA0F-332ACA6B9A75
+ VERSION_STRING = 2.0
+ MODULE_TYPE = DXE_DRIVER
+ ENTRY_POINT = SpcrInitialize
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = 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/SpcrFeaturePkg.dec b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dec
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 Console 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.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ DEC_SPECIFICATION = 0x00010017
+ PACKAGE_NAME = SpcrFeaturePkg
+ PACKAGE_GUID = 20E84A8A-9008-4798-8215-697555E95B29
+ PACKAGE_VERSION = 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/SpcrFeaturePkg.dsc b/Features/Intel/OutOfBandManagement/SpcrFeaturePkg/SpcrFeaturePkg.dsc
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 Console 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.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ PLATFORM_NAME = SpcrFeaturePkg
+ PLATFORM_GUID = 2CEB97B5-610D-440F-A2A7-6775AE2A7E89
+ PLATFORM_VERSION = 0.1
+ DSC_SPECIFICATION = 0x00010005
+ OUTPUT_DIRECTORY = Build/$(PLATFORM_NAME)
+ SUPPORTED_ARCHITECTURES = IA32|X64
+ BUILD_TARGETS = DEBUG|RELEASE|NOOPT
+ SKUID_IDENTIFIER = DEFAULT
+ PEI_ARCH = IA32
+ DXE_ARCH = X64
+
+#
+# This package always builds the feature.
+#
+!include Include/SpcrFeature.dsc
--
2.24.0.windows.2
-=-=-=-=-=-=-=-=-=-=-=-
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]
-=-=-=-=-=-=-=-=-=-=-=-
> +EFI_DEVICE_PATH_PROTOCOL * EFIAPI should be added for library public functions. > +GetSpcrDevice ( > + VOID > + ); -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#58950): https://edk2.groups.io/g/devel/message/58950 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] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.