Skip to content

Commit 64c5789

Browse files
committed
add spcr table.
1 parent 452f3d1 commit 64c5789

File tree

8 files changed

+179
-3
lines changed

8 files changed

+179
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ add_custom_target(tools ALL DEPENDS acpi_extractor iort_reader)
4545

4646
# Define supported ACPI table types and their corresponding source files
4747
# Format: TABLE_NAME -> (header_file, source_file)
48-
set(ACPI_TABLE_TYPES "pptt;gtdt;madt;dbg2;mcfg")
48+
set(ACPI_TABLE_TYPES "pptt;gtdt;madt;dbg2;mcfg;spcr")
4949
set(ACPI_TABLE_dbg2_HEADER "dbg2.h")
5050
set(ACPI_TABLE_dbg2_SOURCE "src/dummy/dbg2.c")
5151
set(ACPI_TABLE_pptt_HEADER "pptt.h")
@@ -56,6 +56,8 @@ set(ACPI_TABLE_madt_HEADER "madt.h")
5656
set(ACPI_TABLE_madt_SOURCE "src/dummy/madt.c")
5757
set(ACPI_TABLE_mcfg_HEADER "mcfg.h")
5858
set(ACPI_TABLE_mcfg_SOURCE "src/dummy/mcfg.c")
59+
set(ACPI_TABLE_spcr_HEADER "spcr.h")
60+
set(ACPI_TABLE_spcr_SOURCE "src/dummy/spcr.c")
5961

6062
# Scan include/vendor directory for all vendors and targets
6163
file(GLOB VENDOR_DIRS "${CMAKE_SOURCE_DIR}/include/vendor/*")

include/common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ _Static_assert(sizeof(CHAR8) == 1, "CHAR8 size incorrect");
4646
#define ACPI_TABLE_DEFINE_END UINT8 EndMagic[4];
4747
#define ACPI_TABLE_DECLARE_START .StartMagic = {ACPI_TABLE_START_MAGIC}
4848
#define ACPI_TABLE_DECLARE_END .EndMagic = {ACPI_TABLE_END_MAGIC}
49+
50+
// ARM GIC related conversion macros
51+
// x means the irq number in device tree.
52+
#define GIC_SGI(x) (x)
53+
#define GIC_PPI(x) (16ULL + (x))
54+
#define GIC_SPI(x) (32ULL + (x))
55+
#define GIC_LPI(x) (8192ULL + (x))

include/common/dbg2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct {
2929
_Static_assert(sizeof(DBG2_HEADER_EXTRA_DATA) == 8,
3030
"DBG2_HEADER_EXTRA_DATA size incorrect");
3131

32+
/* Header Extra Data */
3233
/* Body Structures */
3334
enum DBG2_DEBUG_PORT_TYPE {
3435
DBG2_DEBUG_PORT_TYPE_RESERVED = 0,

include/common/spcr.h

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#pragma once
2+
#include <acpi.h>
3+
#include <common.h>
4+
#include <common/dbg2.h>
5+
6+
/** Serial Port Console Redirection Table (SPCR)
7+
Reference:
8+
https://learn.microsoft.com/en-us/windows-hardware/drivers/bringup/serial-port-console-redirection-table
9+
*/
10+
11+
/* Table signature */
12+
#define ACPI_SPCR_SIGNATURE 'S', 'P', 'C', 'R'
13+
// #define ACPI_SPCR_REVISION 4
14+
#define ACPI_SPCR_REVISION 2
15+
16+
#define ACPI_SPCR_TABLE_STRUCTURE_NAME SERIAL_PORT_CONSOLE_REDIRECTION_TABLE
17+
18+
/* Header Extra Data */
19+
typedef struct {
20+
UINT8 InterfaceType;
21+
UINT8 Reserved[3];
22+
ACPI_GAS BaseAddress;
23+
UINT8 InterruptType;
24+
UINT8 Irq;
25+
UINT32 GlobalSystemInterrupt;
26+
UINT8 ConfiguredBaudRate;
27+
UINT8 Parity;
28+
UINT8 StopBits;
29+
UINT8 FlowControl;
30+
UINT8 TerminalType;
31+
UINT8 Language;
32+
UINT16 PciDeviceId;
33+
UINT16 PciVendorId;
34+
UINT8 PciBusNumber;
35+
UINT8 PciDeviceNumber;
36+
UINT8 PciFunctionNumber;
37+
UINT32 PciFlags; // Must be 0 if it is not a PCI device
38+
UINT8 PciSegment;
39+
#if ACPI_SPCR_REVISION == 4
40+
UINT32 UARTClockFrequency;
41+
UINT32 PreciseBaudRate;
42+
UINT16 NameSpaceStringLength;
43+
UINT16 NameSpaceStringOffset;
44+
// CHAR8 NameSpaceString[NameSpaceStringLength];
45+
// followed by Debug device info
46+
#elif ACPI_SPCR_REVISION == 2
47+
UINT8 Reserved2[4];
48+
#endif
49+
} __attribute__((packed)) SPCR_HEADER_EXTRA_DATA;
50+
#if ACPI_SPCR_REVISION == 4
51+
_Static_assert(sizeof(SPCR_HEADER_EXTRA_DATA) == 88 - sizeof(ACPI_TABLE_HEADER),
52+
"SPCR_HEADER_EXTRA_DATA size incorrect");
53+
#elif ACPI_SPCR_REVISION == 2
54+
_Static_assert(sizeof(SPCR_HEADER_EXTRA_DATA) == 80 - sizeof(ACPI_TABLE_HEADER),
55+
"SPCR_HEADER_EXTRA_DATA size incorrect");
56+
#endif
57+
58+
enum SPCR_INTERRUPT_TYPE {
59+
SPCR_INTERRUPT_TYPE_DUAL_8259_IRQ = BIT(0),
60+
SPCR_INTERRUPT_TYPE_IOAPIC_INTERRUPT = BIT(1),
61+
SPCR_INTERRUPT_TYPE_IOSAPIC_INTERRUPT = BIT(2),
62+
SPCR_INTERRUPT_TYPE_ARMH_GIC = BIT(3),
63+
SPCR_INTERRUPT_TYPE_RISCV_PLIC_APLIC = BIT(4),
64+
SPCR_INTERRUPT_TYPE_RESERVED2 = 0xFF,
65+
};
66+
67+
enum SPCR_CONFIGURED_BAUD_RATE {
68+
SPCR_CONFIGURED_BAUD_RATE_RELIES_ON_DRIVER = 0,
69+
SPCR_CONFIGURED_BAUD_RATE_9600 = 3,
70+
SPCR_CONFIGURED_BAUD_RATE_19200 = 4,
71+
SPCR_CONFIGURED_BAUD_RATE_57600 = 6,
72+
SPCR_CONFIGURED_BAUD_RATE_115200 = 7,
73+
SPCR_CONFIGURED_BAUD_RATE_RESERVED = 0xFF,
74+
};
75+
76+
enum SPCR_PARITY {
77+
SPCR_PARITY_NO_PARITY = 0,
78+
/* 1 - 255 reserved */
79+
SPCR_PARITY_RESERVED = 0xFF,
80+
};
81+
82+
enum SPCR_STOP_BITS {
83+
SPCR_STOP_BITS_ONE_STOP_BIT = 1,
84+
SPCR_STOP_BITS_RESERVED = 0xFF
85+
};
86+
87+
enum SPCR_FLOW_CONTROL {
88+
SPCR_FLOW_CONTROL_NONE = 0,
89+
SPCR_FLOW_CONTROL_DCD_REQUIRED_FOR_TRANSMIT = BIT(0),
90+
SPCR_FLOW_CONTROL_RTS_CTS_HARDWARE_FLOW_CONTROL = BIT(1),
91+
SPCR_FLOW_CONTROL_XON_XOFF_SOFTWARE_FLOW_CONTROL = BIT(2),
92+
/* BIT[3:7] reserved */
93+
SPCR_FLOW_CONTROL_RESERVED = 0xFF,
94+
};
95+
96+
enum SPCR_TERMINAL_TYPE {
97+
SPCR_TERMINAL_TYPE_VT100 = 0,
98+
SPCR_TERMINAL_TYPE_EXT_VT100 = 1,
99+
SPCR_TERMINAL_TYPE_VT_UTF8 = 2,
100+
SPCR_TERMINAL_TYPE_VT_ANSI = 3,
101+
/* 4 - 255 reserved */
102+
SPCR_TERMINAL_TYPE_RESERVED = 0xFF,
103+
};
104+
105+
/* Helper macros */
106+
#if ACPI_SPCR_REVISION == 2
107+
#define SPCR_DEFINE_TABLE \
108+
typedef struct { \
109+
ACPI_TABLE_HEADER Header; \
110+
SPCR_HEADER_EXTRA_DATA SPCRHeaderExtraData; \
111+
} __attribute__((packed)) ACPI_SPCR_TABLE_STRUCTURE_NAME;
112+
#elif ACPI_SPCR_REVISION == 4
113+
#define SPCR_DEFINE_TABLE(namespace_str) \
114+
typedef struct { \
115+
ACPI_TABLE_HEADER Header; \
116+
SPCR_HEADER_EXTRA_DATA SPCRHeaderExtraData; \
117+
CHAR8 NamespaceString[sizeof(namespace_str)]; \
118+
} __attribute__((packed)) ACPI_SPCR_TABLE_STRUCTURE_NAME;
119+
#endif
120+
121+
#define SPCR_DECLARE_HEADER \
122+
ACPI_DECLARE_TABLE_HEADER( \
123+
ACPI_SPCR_SIGNATURE, ACPI_SPCR_TABLE_STRUCTURE_NAME, ACPI_SPCR_REVISION)
124+
125+
/* SPCR Table with Magic */
126+
#define SPCR_DEFINE_WITH_MAGIC \
127+
ACPI_TABLE_WITH_MAGIC(ACPI_SPCR_TABLE_STRUCTURE_NAME)
128+
#define SPCR_START ACPI_TABLE_START(ACPI_SPCR_TABLE_STRUCTURE_NAME)
129+
#define SPCR_END ACPI_TABLE_END(ACPI_SPCR_TABLE_STRUCTURE_NAME)

include/vendor/qcom/sm8850/dbg2.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// USB
88
#define URS0_NAMESPACE_STRING "\\_SB.URS0"
99

10-
#define UARD_BASE_ADDRESS 0xA9C000ULL
1110
#define USB_OEM_DATA_SIZE 0x94
1211

1312
#define UARD_NUM_GAS 1
@@ -39,7 +38,7 @@ DBG2_DEFINE_WITH_MAGIC;
3938
/* Initialize struct */
4039
DBG2_START{
4140
DBG2_DECLARE_HEADER,
42-
DBG2_DECLARE_HEADER_EXTRA_DATA(2),
41+
DBG2_DECLARE_HEADER_EXTRA_DATA(3), // Info count
4342
/* Debug UART */
4443
DBG2_DECLARE_QCOM_SDM845_UARD(UARD, UARD_NAMESPACE_STRING,
4544
UARD_BASE_ADDRESS),

include/vendor/qcom/sm8850/spcr.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
#include "table_header.h"
3+
#include <common/spcr.h>
4+
5+
/* typedef */
6+
SPCR_DEFINE_TABLE;
7+
SPCR_DEFINE_WITH_MAGIC;
8+
9+
/* Initialize struct */
10+
SPCR_START{
11+
SPCR_DECLARE_HEADER,
12+
.SPCRHeaderExtraData =
13+
{
14+
.InterfaceType =
15+
DBG2_DEBUG_PORT_SUBTYPE_SERIAL_SDM845_7P372_MHZ_CLK,
16+
.BaseAddress =
17+
{
18+
.AddressSpaceID = 0x00, // System Memory Mapped
19+
.RegisterBitWidth = 0x20,
20+
.RegisterBitOffset = 0x00,
21+
.AccessSize = 0x20,
22+
.Address = UARD_BASE_ADDRESS,
23+
},
24+
.InterruptType = SPCR_INTERRUPT_TYPE_ARMH_GIC,
25+
.GlobalSystemInterrupt = UARD_GIC_SPI_INTERRUPT_NUMBER,
26+
.ConfiguredBaudRate = SPCR_CONFIGURED_BAUD_RATE_115200,
27+
.Parity = SPCR_PARITY_NO_PARITY,
28+
.StopBits = SPCR_STOP_BITS_ONE_STOP_BIT,
29+
.FlowControl = SPCR_FLOW_CONTROL_NONE,
30+
.TerminalType = SPCR_TERMINAL_TYPE_VT_ANSI,
31+
.PciDeviceId = 0xFFFF,
32+
.PciVendorId = 0xFFFF,
33+
},
34+
} SPCR_END;

include/vendor/qcom/sm8850/table_header.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
#define L1_CACHES_COUNT 2
1313
#define L2_CACHES_COUNT 1
1414
#define L3_CACHES_COUNT 0
15+
16+
#define UARD_BASE_ADDRESS 0xA9C000ULL
17+
#define UARD_GIC_SPI_INTERRUPT_NUMBER GIC_SPI(0x343) // GIC SPI 0x363

src/dummy/spcr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <spcr.h>

0 commit comments

Comments
 (0)