Skip to content

Commit

Permalink
DynamicTablesPkg: AcpiSpcrLib: Add support for SPCR revision 4
Browse files Browse the repository at this point in the history
Revision 4 adds fields for UART clock frequency, precise baud raud and ACPI
object namespace string.

Signed-off-by: Sarah Walker <[email protected]>
  • Loading branch information
sarah-walker-arm committed Jan 31, 2025
1 parent fbe1984 commit 5f721ef
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions DynamicTablesPkg/Library/Acpi/Common/AcpiSpcrLib/SpcrGenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <IndustryStandard/DebugPort2Table.h>
#include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
#include <Library/AcpiLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Protocol/AcpiTable.h>
Expand Down Expand Up @@ -60,11 +61,11 @@ NOTE: This implementation ignores the possibility that the Serial settings may
Note: fields marked "{Template}" will be updated dynamically.
*/
STATIC
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE AcpiSpcr = {
EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE AcpiSpcr = {
ACPI_HEADER (
EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE,
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE,
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION
EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE,
EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION
),
0, // {Template}: Serial Port Subtype
{
Expand All @@ -89,7 +90,10 @@ EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE AcpiSpcr = {
0x00,
0x00000000,
0x00,
EFI_ACPI_RESERVED_DWORD
0, // {Template}: UART Clock Frequency
0, // {Template}: Precise Baud Rate
sizeof (NAME_STR_SPCR_PORT),
OFFSET_OF (EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE, NameSpaceString)
};

#pragma pack()
Expand Down Expand Up @@ -204,6 +208,7 @@ BuildSpcrTableEx (
CM_ARCH_COMMON_SERIAL_PORT_INFO *SerialPortInfo;
UINT32 SerialPortCount;
EFI_ACPI_DESCRIPTION_HEADER **TableList;
UINT32 Size;

ASSERT (This != NULL);
ASSERT (AcpiTableInfo != NULL);
Expand Down Expand Up @@ -280,13 +285,19 @@ BuildSpcrTableEx (
return Status;
}

if (AcpiTableInfo->AcpiTableRevision < EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION) {
Size = sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE);
} else {
Size = sizeof (EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE) + sizeof (NAME_STR_SPCR_PORT);
}

// Build SPCR table.
Status = AddAcpiHeader (
CfgMgrProtocol,
This,
(EFI_ACPI_DESCRIPTION_HEADER *)&AcpiSpcr,
AcpiTableInfo,
sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE)
Size
);
if (EFI_ERROR (Status)) {
DEBUG ((
Expand All @@ -297,6 +308,9 @@ BuildSpcrTableEx (
goto error_handler;
}

AcpiSpcr.Header.Length = Size;
AcpiSpcr.Header.Revision = AcpiTableInfo->AcpiTableRevision;

// The SPCR InterfaceType uses the same encoding as that of the
// DBG2 table Port Subtype field. However InterfaceType is 8-bit
// while the Port Subtype field in the DBG2 table is 16-bit.
Expand Down Expand Up @@ -357,16 +371,28 @@ BuildSpcrTableEx (
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_BAUD_RATE_115200;
break;
default:
Status = EFI_UNSUPPORTED;
DEBUG ((
DEBUG_ERROR,
"ERROR: SPCR: Invalid Baud Rate %ld, Status = %r\n",
SerialPortInfo->BaudRate,
Status
));
goto error_handler;
if (AcpiTableInfo->AcpiTableRevision < EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION) {
Status = EFI_UNSUPPORTED;
DEBUG ((
DEBUG_ERROR,
"ERROR: SPCR: Invalid Baud Rate %ld, Status = %r\n",
SerialPortInfo->BaudRate,
Status
));
goto error_handler;
}

AcpiSpcr.BaudRate = 0;
AcpiSpcr.PreciseBaudRate = SerialPortInfo->BaudRate;
break;
} // switch

if (AcpiTableInfo->AcpiTableRevision >= EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION) {
AcpiSpcr.UartClockFrequency = SerialPortInfo->Clock;

AsciiStrCpyS (AcpiSpcr.NameSpaceString, sizeof (NAME_STR_SPCR_PORT), NAME_STR_SPCR_PORT);
}

TableList[0] = (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiSpcr;

// Build a SSDT table describing the serial port.
Expand Down Expand Up @@ -415,7 +441,7 @@ ACPI_TABLE_GENERATOR SpcrGenerator = {
// ACPI Table Signature
EFI_ACPI_6_3_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE,
// ACPI Table Revision supported by this Generator
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION,
EFI_ACPI_4_0_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION,
// Minimum supported ACPI Table Revision
EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_REVISION,
// Creator ID
Expand Down

0 comments on commit 5f721ef

Please sign in to comment.