Skip to content

Commit a1ef0ab

Browse files
donshengwenlingz
authored andcommitted
hv: move ACPI related defines/structs to acpi.h
Currently ACPI related defines/structs are scattered across multiple C source files, move them into acpi.h so that they can be shared and used by vacpi code (to be added in subsequent commits). Tracked-On: #3601 Signed-off-by: dongshen <dongsheng.x.zhang@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com>
1 parent 6ca4095 commit a1ef0ab

File tree

4 files changed

+154
-150
lines changed

4 files changed

+154
-150
lines changed

hypervisor/acpi_parser/acpi_ext.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,6 @@
5151
* When ACRN go FuSa, the platform ACPI data should be fixed and this file is not needed.
5252
*/
5353

54-
#define ACPI_SIG_FACS 0x53434146U /* "FACS" */
55-
#define ACPI_SIG_FADT "FACP" /* Fixed ACPI Description Table */
56-
57-
/* FACP field offsets */
58-
#define OFFSET_FACS_ADDR 36U
59-
#define OFFSET_RESET_REGISTER 116U
60-
#define OFFSET_RESET_VALUE 128U
61-
#define OFFSET_FACS_X_ADDR 132U
62-
#define OFFSET_PM1A_EVT 148U
63-
#define OFFSET_PM1A_CNT 172U
64-
65-
/* FACS field offsets */
66-
#define OFFSET_FACS_SIGNATURE 0U
67-
#define OFFSET_FACS_LENGTH 4U
68-
#define OFFSET_WAKE_VECTOR_32 12U
69-
#define OFFSET_WAKE_VECTOR_64 24U
70-
7154
/* get a dword value from given table and its offset */
7255
static inline uint32_t get_acpi_dt_dword(const uint8_t *dt_addr, uint32_t dt_offset)
7356
{
@@ -80,14 +63,6 @@ static inline uint64_t get_acpi_dt_qword(const uint8_t *dt_addr, uint32_t dt_off
8063
return *(uint64_t *)(dt_addr + dt_offset);
8164
}
8265

83-
struct packed_gas {
84-
uint8_t space_id;
85-
uint8_t bit_width;
86-
uint8_t bit_offset;
87-
uint8_t access_size;
88-
uint64_t address;
89-
} __attribute__((packed));
90-
9166
/* get a GAS struct from given table and its offset.
9267
* ACPI table stores packed gas, but it is not guaranteed that
9368
* struct acpi_generic_address is packed, so do not use memcpy in function.

hypervisor/acpi_parser/dmar_parse.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,12 @@
1212
#include "vtd.h"
1313
#include "acpi.h"
1414

15-
#define ACPI_SIG_DMAR "DMAR"
16-
17-
enum acpi_dmar_type {
18-
ACPI_DMAR_TYPE_HARDWARE_UNIT = 0,
19-
ACPI_DMAR_TYPE_RESERVED_MEMORY = 1,
20-
ACPI_DMAR_TYPE_ROOT_ATS = 2,
21-
ACPI_DMAR_TYPE_HARDWARE_AFFINITY = 3,
22-
ACPI_DMAR_TYPE_NAMESPACE = 4,
23-
ACPI_DMAR_TYPE_RESERVED = 5
24-
};
25-
26-
struct acpi_table_dmar {
27-
/* Common ACPI table header */
28-
struct acpi_table_header header;
29-
/* Host address Width */
30-
uint8_t width;
31-
uint8_t flags;
32-
uint8_t reserved[10];
33-
};
34-
35-
/* DMAR subtable header */
36-
struct acpi_dmar_header {
37-
uint16_t type;
38-
uint16_t length;
39-
};
40-
41-
struct acpi_dmar_hardware_unit {
42-
struct acpi_dmar_header header;
43-
uint8_t flags;
44-
uint8_t reserved;
45-
uint16_t segment;
46-
/* register base address */
47-
uint64_t address;
48-
};
4915

5016
struct find_iter_args {
5117
int32_t i;
5218
struct acpi_dmar_hardware_unit *res;
5319
};
5420

55-
struct acpi_dmar_pci_path {
56-
uint8_t device;
57-
uint8_t function;
58-
};
59-
60-
struct acpi_dmar_device_scope {
61-
uint8_t entry_type;
62-
uint8_t length;
63-
uint16_t reserved;
64-
uint8_t enumeration_id;
65-
uint8_t bus;
66-
};
67-
6821
typedef int32_t (*dmar_iter_t)(struct acpi_dmar_header*, void*);
6922

7023
static int32_t dmar_unit_cnt;

hypervisor/boot/acpi_base.c

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -35,85 +35,9 @@
3535
#include <logmsg.h>
3636
#include <acrn_common.h>
3737

38-
#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */
39-
#define ACPI_OEM_ID_SIZE 6
40-
#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */
41-
#define RSDP_CHECKSUM_LENGTH 20
42-
#define ACPI_NAME_SIZE 4U
43-
#define ACPI_MADT_TYPE_LOCAL_APIC 0U
44-
#define ACPI_MADT_TYPE_IOAPIC 1U
45-
#define ACPI_MADT_ENABLED 1U
46-
#define ACPI_OEM_TABLE_ID_SIZE 8
47-
48-
struct acpi_table_rsdp {
49-
/* ACPI signature, contains "RSD PTR " */
50-
char signature[8];
51-
/* ACPI 1.0 checksum */
52-
uint8_t checksum;
53-
/* OEM identification */
54-
char oem_id[ACPI_OEM_ID_SIZE];
55-
/* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
56-
uint8_t revision;
57-
/* 32-bit physical address of the RSDT */
58-
uint32_t rsdt_physical_address;
59-
/* Table length in bytes, including header (ACPI 2.0+) */
60-
uint32_t length;
61-
/* 64-bit physical address of the XSDT (ACPI 2.0+) */
62-
uint64_t xsdt_physical_address;
63-
/* Checksum of entire table (ACPI 2.0+) */
64-
uint8_t extended_checksum;
65-
/* Reserved, must be zero */
66-
uint8_t reserved[3];
67-
};
68-
69-
struct acpi_table_rsdt {
70-
/* Common ACPI table header */
71-
struct acpi_table_header header;
72-
/* Array of pointers to ACPI tables */
73-
uint32_t table_offset_entry[1];
74-
} __packed;
75-
76-
struct acpi_table_xsdt {
77-
/* Common ACPI table header */
78-
struct acpi_table_header header;
79-
/* Array of pointers to ACPI tables */
80-
uint64_t table_offset_entry[1];
81-
} __packed;
82-
83-
struct acpi_subtable_header {
84-
uint8_t type;
85-
uint8_t length;
86-
};
87-
88-
struct acpi_table_madt {
89-
/* Common ACPI table header */
90-
struct acpi_table_header header;
91-
/* Physical address of local APIC */
92-
uint32_t address;
93-
uint32_t flags;
94-
};
95-
96-
struct acpi_madt_local_apic {
97-
struct acpi_subtable_header header;
98-
/* ACPI processor id */
99-
uint8_t processor_id;
100-
/* Processor's local APIC id */
101-
uint8_t id;
102-
uint32_t lapic_flags;
103-
};
104-
10538
static struct acpi_table_rsdp *acpi_rsdp;
106-
struct acpi_madt_ioapic {
107-
struct acpi_subtable_header header;
108-
/* IOAPIC id */
109-
uint8_t id;
110-
uint8_t rsvd;
111-
uint32_t addr;
112-
uint32_t gsi_base;
113-
};
114-
115-
static struct acpi_table_rsdp*
116-
found_rsdp(char *base, int32_t length)
39+
40+
static struct acpi_table_rsdp *found_rsdp(char *base, int32_t length)
11741
{
11842
struct acpi_table_rsdp *rsdp, *ret = NULL;
11943
uint8_t *cp, sum;

hypervisor/boot/include/acpi.h

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@
99

1010
#include <vm_configurations.h>
1111

12+
#define ACPI_OEM_ID_SIZE 6
13+
14+
#define RSDP_CHECKSUM_LENGTH 20
15+
#define ACPI_NAME_SIZE 4U
16+
#define ACPI_MADT_TYPE_LOCAL_APIC 0U
17+
#define ACPI_MADT_TYPE_IOAPIC 1U
18+
#define ACPI_MADT_ENABLED 1U
19+
#define ACPI_OEM_TABLE_ID_SIZE 8
20+
21+
22+
/* FACP field offsets */
23+
#define OFFSET_FACS_ADDR 36U
24+
#define OFFSET_RESET_REGISTER 116U
25+
#define OFFSET_RESET_VALUE 128U
26+
#define OFFSET_FACS_X_ADDR 132U
27+
#define OFFSET_PM1A_EVT 148U
28+
#define OFFSET_PM1A_CNT 172U
29+
30+
/* FACS field offsets */
31+
#define OFFSET_FACS_SIGNATURE 0U
32+
#define OFFSET_FACS_LENGTH 4U
33+
#define OFFSET_WAKE_VECTOR_32 12U
34+
#define OFFSET_WAKE_VECTOR_64 24U
35+
36+
#define ACPI_SIG_FADT "FACP" /* Fixed ACPI Description Table */
37+
#define ACPI_SIG_FACS 0x53434146U /* "FACS" */
38+
#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */
39+
#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */
40+
#define ACPI_SIG_DMAR "DMAR"
41+
42+
43+
struct packed_gas {
44+
uint8_t space_id;
45+
uint8_t bit_width;
46+
uint8_t bit_offset;
47+
uint8_t access_size;
48+
uint64_t address;
49+
} __attribute__((packed));
50+
1251
struct acpi_table_header {
1352
/* ASCII table signature */
1453
char signature[4];
@@ -30,6 +69,119 @@ struct acpi_table_header {
3069
uint32_t asl_compiler_revision;
3170
};
3271

72+
struct acpi_table_rsdp {
73+
/* ACPI signature, contains "RSD PTR " */
74+
char signature[8];
75+
/* ACPI 1.0 checksum */
76+
uint8_t checksum;
77+
/* OEM identification */
78+
char oem_id[ACPI_OEM_ID_SIZE];
79+
/* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
80+
uint8_t revision;
81+
/* 32-bit physical address of the RSDT */
82+
uint32_t rsdt_physical_address;
83+
/* Table length in bytes, including header (ACPI 2.0+) */
84+
uint32_t length;
85+
/* 64-bit physical address of the XSDT (ACPI 2.0+) */
86+
uint64_t xsdt_physical_address;
87+
/* Checksum of entire table (ACPI 2.0+) */
88+
uint8_t extended_checksum;
89+
/* Reserved, must be zero */
90+
uint8_t reserved[3];
91+
};
92+
93+
struct acpi_table_rsdt {
94+
/* Common ACPI table header */
95+
struct acpi_table_header header;
96+
/* Array of pointers to ACPI tables */
97+
uint32_t table_offset_entry[1];
98+
} __packed;
99+
100+
struct acpi_table_xsdt {
101+
/* Common ACPI table header */
102+
struct acpi_table_header header;
103+
/* Array of pointers to ACPI tables */
104+
uint64_t table_offset_entry[1];
105+
} __packed;
106+
107+
struct acpi_table_madt {
108+
/* Common ACPI table header */
109+
struct acpi_table_header header;
110+
/* Physical address of local APIC */
111+
uint32_t address;
112+
uint32_t flags;
113+
};
114+
115+
struct acpi_subtable_header {
116+
uint8_t type;
117+
uint8_t length;
118+
};
119+
120+
struct acpi_madt_local_apic {
121+
struct acpi_subtable_header header;
122+
/* ACPI processor id */
123+
uint8_t processor_id;
124+
/* Processor's local APIC id */
125+
uint8_t id;
126+
uint32_t lapic_flags;
127+
};
128+
129+
struct acpi_madt_ioapic {
130+
struct acpi_subtable_header header;
131+
/* IOAPIC id */
132+
uint8_t id;
133+
uint8_t rsvd;
134+
uint32_t addr;
135+
uint32_t gsi_base;
136+
};
137+
138+
enum acpi_dmar_type {
139+
ACPI_DMAR_TYPE_HARDWARE_UNIT = 0,
140+
ACPI_DMAR_TYPE_RESERVED_MEMORY = 1,
141+
ACPI_DMAR_TYPE_ROOT_ATS = 2,
142+
ACPI_DMAR_TYPE_HARDWARE_AFFINITY = 3,
143+
ACPI_DMAR_TYPE_NAMESPACE = 4,
144+
ACPI_DMAR_TYPE_RESERVED = 5
145+
};
146+
147+
struct acpi_table_dmar {
148+
/* Common ACPI table header */
149+
struct acpi_table_header header;
150+
/* Host address Width */
151+
uint8_t width;
152+
uint8_t flags;
153+
uint8_t reserved[10];
154+
};
155+
156+
/* DMAR subtable header */
157+
struct acpi_dmar_header {
158+
uint16_t type;
159+
uint16_t length;
160+
};
161+
162+
struct acpi_dmar_hardware_unit {
163+
struct acpi_dmar_header header;
164+
uint8_t flags;
165+
uint8_t reserved;
166+
uint16_t segment;
167+
/* register base address */
168+
uint64_t address;
169+
};
170+
171+
struct acpi_dmar_pci_path {
172+
uint8_t device;
173+
uint8_t function;
174+
};
175+
176+
struct acpi_dmar_device_scope {
177+
uint8_t entry_type;
178+
uint8_t length;
179+
uint16_t reserved;
180+
uint8_t enumeration_id;
181+
uint8_t bus;
182+
};
183+
184+
33185
void *get_acpi_tbl(const char *signature);
34186

35187
struct ioapic_info;

0 commit comments

Comments
 (0)