Skip to content

Commit d31ccb6

Browse files
committed
修正 NeoACPI 日志系统格式问题, 增加 FADT 模式检查与 FACT 表获取.
1 parent 06b1e01 commit d31ccb6

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

src/include/lib/neoacpi/neoacpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct neo_acpi_handle {
1818
size_t entries_length;
1919
aml_context_t *aml_context;
2020
struct acpi_fadt global_fadt;
21+
acpi_table_facs_t *global_facs;
2122
bool reduced_hardware;
2223
} neo_acpi_handle_t;
2324

src/include/lib/neoacpi/neotable.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,19 @@ typedef struct acpi_generic_address {
192192
uint64_t address; /* 64-bit address of struct or register */
193193
} acpi_generic_address_t;
194194

195+
typedef struct acpi_table_facs {
196+
char signature[4]; /* ASCII table signature */
197+
uint32_t length; /* Length of structure, in bytes */
198+
uint32_t hard_signature; /* Hardware configuration signature */
199+
uint32_t firm_waking_vector; /* 32-bit physical address of the Firmware Waking Vector */
200+
uint32_t global_lock; /* Global Lock for shared hardware resources */
201+
uint32_t flags;
202+
uint64_t x_firm_waking_vector; /* 64-bit version of the Firmware Waking Vector (ACPI 2.0+) */
203+
uint8_t version; /* Version of this table (ACPI 2.0+) */
204+
uint8_t _reserved[3]; /* Reserved, must be zero */
205+
uint32_t ospm_flags; /* Flags to be set by OSPM (ACPI 4.0) */
206+
uint8_t _reserved1[24]; /* Reserved, must be zero */
207+
} __attribute__((packed)) acpi_table_facs_t;
208+
195209
void dump_table_header(neo_acpi_phys_addr phys_addr, void *hdr);
196210
bool verify_table_checksum(void *table, size_t size);

src/lib/neoacpi/fadt.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,16 @@ static void acpi_gas_init_system_io(struct acpi_gas *gas, uint64_t address, uint
6464
gas->access_size = 0;
6565
}
6666

67-
static void acpi_fixup_fadt(struct acpi_fadt *fadt) {
67+
static void acpi_fixup_fadt(neo_acpi_handle_t *handle, struct acpi_fadt *fadt) {
6868
size_t i;
6969

7070
if (!fadt->x_dsdt) { fadt->x_dsdt = fadt->dsdt; }
7171
if (fadt->firmware_ctrl) { fadt->x_firmware_ctrl = fadt->firmware_ctrl; }
72+
if (fadt->hdr.revision >= 5 && fadt->hdr.length >= 116 && fadt->flags & ACPI_FADT_HW_REDUCED) {
73+
return;
74+
}
7275

73-
if (fadt->flags & ACPI_FADT_HW_REDUCED) { return; }
76+
log_info("legacy ACPI model, acpi enabling...");
7477

7578
for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
7679
const acpi_fadt_info_t *info = &fadt_info_table[i];
@@ -121,9 +124,9 @@ neo_acpi_handle_t *acpi_load_fadt(neo_acpi_handle_t *handle) {
121124
}
122125

123126
fadt->hdr.length = sizeof(struct acpi_fadt);
124-
fadt->x_dsdt = neo_acpi_fadt_select("DSDT", fadt->dsdt, fadt->x_dsdt);
127+
fadt->x_dsdt = neo_acpi_fadt_select(ACPI_DSDT_SIGNATURE, fadt->dsdt, fadt->x_dsdt);
125128

126-
acpi_fixup_fadt(fadt);
129+
acpi_fixup_fadt(handle, fadt);
127130

128131
handle->aml_context = neo_acpi_malloc(sizeof(aml_context_t));
129132
struct acpi_dsdt *dsdt =
@@ -135,6 +138,17 @@ neo_acpi_handle_t *acpi_load_fadt(neo_acpi_handle_t *handle) {
135138
size_t dsdt_length = dsdt->hdr.length;
136139
neo_acpi_kernel_unmap(dsdt, sizeof(struct acpi_sdt_hdr));
137140

141+
uintptr_t phys_addr =
142+
neo_acpi_fadt_select(ACPI_FACS_SIGNATURE, fadt->firmware_ctrl, fadt->x_firmware_ctrl);
143+
struct acpi_sdt_hdr *hdr = neo_acpi_kernel_map(phys_addr, sizeof(struct acpi_sdt_hdr));
144+
145+
size_t facs_length = hdr->length;
146+
neo_acpi_kernel_unmap(hdr, sizeof(struct acpi_sdt_hdr));
147+
handle->global_facs = neo_acpi_kernel_map(phys_addr, facs_length);
148+
if (handle->global_facs == NULL) {
149+
log_error("cannot mmap dsdt header table.");
150+
return NULL;
151+
}
138152
dsdt = neo_acpi_kernel_map(handle->global_fadt.x_dsdt, dsdt_length);
139153
if (!verify_table_checksum(dsdt, dsdt->hdr.length)) { return NULL; }
140154
aml_context_initialize(handle, dsdt);

src/lib/neoacpi/neo_logger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void neo_acpi_logger_failed(const char *str, ...) {
4040
neo_acpi_va_list vlist;
4141
neo_acpi_va_start(vlist, str);
4242

43-
ret = neo_acpi_vsnprintf(buf + 11, sizeof(buf), str, vlist);
43+
ret = neo_acpi_vsnprintf(buf, sizeof(buf), str, vlist);
4444
if (ret < 0) return;
4545

4646
neo_acpi_kernel_logger(FAILED, buf);

src/lib/neoacpi/neo_table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static bool check_table_signature(void *table, const char *expect) {
6161
if (!signatures_match(table, expect)) {
6262
struct acpi_sdt_hdr *hdr = table;
6363
log_error("invalid table '%.4s' (OEM ID '%.6s' OEM Table ID '%.8s') signature (expected "
64-
"'%.4s')\n",
64+
"'%.4s')",
6565
hdr->signature, hdr->oemid, hdr->oem_table_id, expect);
6666
return false;
6767
}
@@ -73,7 +73,7 @@ bool verify_table_checksum(void *table, size_t size) {
7373

7474
if (csum != 0) {
7575
struct acpi_sdt_hdr *hdr = table;
76-
log_error("invalid table '%.4s' (OEM ID '%.6s' OEM Table ID '%.8s') checksum %d!\n",
76+
log_error("invalid table '%.4s' (OEM ID '%.6s' OEM Table ID '%.8s') checksum %d!",
7777
(hdr)->signature, (hdr)->oemid, (hdr)->oem_table_id, csum);
7878
return false;
7979
}

0 commit comments

Comments
 (0)