Skip to content

Commit 452f3d1

Browse files
committed
add gtdt tables.
1 parent 4f37401 commit 452f3d1

File tree

6 files changed

+182
-2
lines changed

6 files changed

+182
-2
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ 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;madt;dbg2;mcfg")
48+
set(ACPI_TABLE_TYPES "pptt;gtdt;madt;dbg2;mcfg")
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")
5252
set(ACPI_TABLE_pptt_SOURCE "src/dummy/pptt.c")
53+
set(ACPI_TABLE_gtdt_HEADER "gtdt.h")
54+
set(ACPI_TABLE_gtdt_SOURCE "src/dummy/gtdt.c")
5355
set(ACPI_TABLE_madt_HEADER "madt.h")
5456
set(ACPI_TABLE_madt_SOURCE "src/dummy/madt.c")
5557
set(ACPI_TABLE_mcfg_HEADER "mcfg.h")

include/common/gtdt.h

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#pragma once
2+
#include <acpi.h>
3+
#include <common.h>
4+
5+
/* Generic Timer Description Table */
6+
#define ACPI_GTDT_SIGNATURE 'G', 'T', 'D', 'T'
7+
#define ACPI_GTDT_REVISION 2
8+
// #define ACPI_GTDT_REVISION 3
9+
10+
#define ACPI_GTDT_TABLE_STRUCTURE_NAME GENERIC_TIMER_DESCRIPTION_TABLE
11+
12+
/* Extra data in header */
13+
14+
typedef struct {
15+
UINT64 CntControlBasePhyAddress;
16+
UINT32 Reserved;
17+
UINT32 SecureEL1TimerGSI;
18+
UINT32 SecureEL1TimerFlags;
19+
UINT32 NSEL1TimerGSI;
20+
UINT32 NSEL1TimerFlags;
21+
UINT32 VirtualEL1TimerGSI;
22+
UINT32 VirtualEL1TimerFlags;
23+
UINT32 EL2TimerGSI;
24+
UINT32 EL2TimerFlags;
25+
UINT64 CntReadBasePhyAddress;
26+
UINT32 PlatformTimerCount;
27+
UINT32 PlatformTimerOffset;
28+
#if ACPI_GTDT_REVISION >= 3
29+
UINT32 VirtualEL2TimerGSI;
30+
UINT32 VirtualEL2TimerFlags;
31+
#endif
32+
// Platform Timer Structures
33+
} __attribute__((packed)) GTDT_HEADER_EXTRA_DATA;
34+
#if (ACPI_GTDT_REVISION >= 3)
35+
_Static_assert(sizeof(GTDT_HEADER_EXTRA_DATA) ==
36+
104 - sizeof(ACPI_TABLE_HEADER),
37+
"GTDT_HEADER_EXTRA_DATA size incorrect");
38+
#else
39+
_Static_assert(sizeof(GTDT_HEADER_EXTRA_DATA) == 96 - sizeof(ACPI_TABLE_HEADER),
40+
"GTDT_HEADER_EXTRA_DATA size incorrect");
41+
#endif
42+
43+
/* Body Structures */
44+
#define GTDT_DEFINE_TIMER_BLOCK_STRUCTURE_TYPE(name, block_timer_cnt) \
45+
typedef struct { \
46+
UINT8 Type; \
47+
UINT16 Length; \
48+
UINT8 Reserved; \
49+
UINT64 GTBlockPhysicalAddress; \
50+
UINT32 GTBlockTimerCount; \
51+
UINT32 GTBlockTimerOffset; \
52+
GTDT_BLOCK_TIMER_STRUCTURE GTBlockTimerStructure[block_timer_cnt]; \
53+
} __attribute__((packed)) GTDT_TIMER_BLOCK_STRUCTURE_##name; \
54+
_Static_assert(sizeof(GTDT_TIMER_BLOCK_STRUCTURE_##name) == \
55+
20 + \
56+
block_timer_cnt * sizeof(GTDT_BLOCK_TIMER_STRUCTURE), \
57+
"GTDT_TIMER_BLOCK_STRUCTURE size incorrect");
58+
59+
typedef struct {
60+
UINT8 GTFrameNumber;
61+
UINT8 Reserved[3];
62+
UINT64 CNTBaseX;
63+
UINT64 CNTEL0BaseX;
64+
UINT32 PhysicalTimerGSI;
65+
UINT32 PhysicalTimerFlags;
66+
UINT32 VirtualTimerGSI;
67+
UINT32 VirtualTimerFlags;
68+
UINT32 CommonFlags;
69+
} __attribute__((packed)) GTDT_BLOCK_TIMER_STRUCTURE;
70+
_Static_assert(sizeof(GTDT_BLOCK_TIMER_STRUCTURE) == 40,
71+
"GTDT_BLOCK_TIMER_STRUCTURE size incorrect");
72+
73+
#define GTDT_BLOCK_PVT_FLAG_TIMER_INTERRUPT_MODE BIT(0)
74+
enum GTDT_BLOCK_PVT_TIMER_INTERRUPT_MODE {
75+
GTDT_BLOCK_PVT_TIMER_INTERRUPT_MODE_LVL_TRIGGERED = 0,
76+
GTDT_BLOCK_PVT_TIMER_INTERRUPT_MODE_EDGE_TRIGGERED = 1,
77+
};
78+
#define GTDT_BLOCK_PVT_FLAG_TIMER_INTERRUPT_POLARITY BIT(1)
79+
enum GTDT_BLOCK_PVT_TIMER_INTERRUPT_POLARITY {
80+
GTDT_BLOCK_PVT_TIMER_INTERRUPT_POLARITY_ACTIVE_HIGH = 0,
81+
GTDT_BLOCK_PVT_TIMER_INTERRUPT_POLARITY_ACTIVE_LOW = 1,
82+
};
83+
#define GTDT_BLOCK_PVT_FLAG_TIMER_RESERVED GEN_MSK(31, 2)
84+
85+
#define GTDT_BLOCK_COMMONT_FLAGS_TIMER_SECURE_TIMER BIT(0)
86+
#define GTDT_BLOCK_COMMONT_FLAGS_TIMER_ALWAYS_ON_CAP BIT(1)
87+
#define GTDT_BLOCK_COMMONR_FLAG_TIMER_RESERVED GEN_MSK(31, 2)
88+
89+
typedef struct {
90+
UINT8 Type; // 0x1 => WDT
91+
UINT16 Length; // 28
92+
UINT8 Reserved;
93+
UINT64 RefreshFramePhysicalAddress;
94+
UINT64 WatchdogControlFramePhysicalAddress;
95+
UINT32 WatchdogTimerGSI;
96+
UINT32 WatchdogTimerFlags;
97+
} __attribute__((packed)) ACPI_GTDT_GENERIC_WDT_STRUCTURE;
98+
_Static_assert(sizeof(ACPI_GTDT_GENERIC_WDT_STRUCTURE) == 28,
99+
"ACPI_GTDT_GENERIC_WDT_STRUCTURE size incorrect");
100+
101+
#define GTDT_WDT_FLAG_TIMER_TIMER_INTERRUPT_MODE BIT(0)
102+
#define GTDT_WDT_FLAG_TIMER_TIMER_INTERRUPT_POLARITY BIT(1)
103+
#define GTDT_WDT_FLAG_TIMER_SECURE_TIMER BIT(2)
104+
#define GTDT_WDT_FLAG_TIMER_RESERVED GEN_MSK(31, 3)
105+
106+
/* Helper macros */
107+
#define GTDT_DEFINE_TABLE(...) \
108+
typedef struct { \
109+
ACPI_TABLE_HEADER Header; \
110+
GTDT_HEADER_EXTRA_DATA GTDTHeaderExtraData; \
111+
__VA_OPT__(__VA_ARGS__) \
112+
} __attribute__((packed)) ACPI_GTDT_TABLE_STRUCTURE_NAME;
113+
114+
#define GTDT_GET_TIMER_BLOCK_STRUCTURE_NAME(name) \
115+
GTDT_TIMER_BLOCK_STRUCTURE_##name
116+
117+
#define GTDT_DEFINE_TIMER_BLOCK_IN_TABLE(name) \
118+
GTDT_GET_TIMER_BLOCK_STRUCTURE_NAME(name) name;
119+
120+
#define GTDT_DECLARE_HEADER \
121+
ACPI_DECLARE_TABLE_HEADER( \
122+
ACPI_GTDT_SIGNATURE, ACPI_GTDT_TABLE_STRUCTURE_NAME, ACPI_GTDT_REVISION)
123+
124+
/* GTDT Table with Magic */
125+
#define GTDT_DEFINE_WITH_MAGIC \
126+
ACPI_TABLE_WITH_MAGIC(ACPI_GTDT_TABLE_STRUCTURE_NAME)
127+
#define GTDT_START ACPI_TABLE_START(ACPI_GTDT_TABLE_STRUCTURE_NAME)
128+
#define GTDT_END ACPI_TABLE_END(ACPI_GTDT_TABLE_STRUCTURE_NAME)

include/vendor/qcom/sm8150/gtdt.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
#include "table_header.h"
3+
#include <common/gtdt.h>
4+
#include <stddef.h>
5+
6+
GTDT_DEFINE_TIMER_BLOCK_STRUCTURE_TYPE(GENERIC_TIMER, 1);
7+
8+
GTDT_DEFINE_TABLE(GTDT_DEFINE_TIMER_BLOCK_IN_TABLE(GENERIC_TIMER));
9+
GTDT_DEFINE_WITH_MAGIC;
10+
11+
GTDT_START{
12+
GTDT_DECLARE_HEADER,
13+
.GTDTHeaderExtraData =
14+
{
15+
.CntControlBasePhyAddress = 0xFFFFFFFFFFFFFFFFULL,
16+
.SecureEL1TimerGSI = 0x11,
17+
.NSEL1TimerGSI = 0x12,
18+
.VirtualEL1TimerGSI = 0x13,
19+
.EL2TimerGSI = 0x10,
20+
.CntReadBasePhyAddress = 0xFFFFFFFFFFFFFFFFULL,
21+
.PlatformTimerCount = 1,
22+
.PlatformTimerOffset =
23+
sizeof(GTDT_HEADER_EXTRA_DATA) + sizeof(ACPI_TABLE_HEADER),
24+
},
25+
.GENERIC_TIMER =
26+
{.Type = 0, // Generic Timer Block
27+
.Length = sizeof(GTDT_GET_TIMER_BLOCK_STRUCTURE_NAME(GENERIC_TIMER)),
28+
.GTBlockPhysicalAddress = 0x17C20000,
29+
.GTBlockTimerCount = 1,
30+
.GTBlockTimerOffset =
31+
offsetof(GTDT_GET_TIMER_BLOCK_STRUCTURE_NAME(GENERIC_TIMER),
32+
GTBlockTimerStructure),
33+
.GTBlockTimerStructure[0] =
34+
{
35+
.GTFrameNumber = 0,
36+
.CNTBaseX = 0x17C21000,
37+
.CNTEL0BaseX = 0x17C22000,
38+
.PhysicalTimerGSI = 0x28,
39+
.VirtualTimerGSI = 0x26,
40+
.CommonFlags = GTDT_BLOCK_COMMONT_FLAGS_TIMER_ALWAYS_ON_CAP,
41+
}},
42+
} GTDT_END;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#include <acpi_vendor.h>
22

33
#define ACPI_OEM_REVISION 0x8150
4+
5+
/* Platform specific configuration */
6+
#define NUM_CORES 8
7+
#define NUM_CLUSTERS 2

lib/utils.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ uint8_t *read_file_content(FileContent *fileContent) {
4444
FILE *pFile = fopen(fileContent->filePath, "rb");
4545
if (pFile == NULL)
4646
return NULL;
47-
fread(fileContent->fileBuffer, fileContent->fileSize, 1, pFile);
47+
if(fread(fileContent->fileBuffer, fileContent->fileSize, 1, pFile) != 1) {
48+
fclose(pFile);
49+
return NULL;
50+
}
4851
fclose(pFile);
4952
return fileContent->fileBuffer;
5053
}

src/dummy/gtdt.c

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

0 commit comments

Comments
 (0)