From b1bb2511d86ae7350d82e3da1865621404d921f9 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 26 Jan 2011 22:14:20 +0100 Subject: [PATCH] ACPI: Fixing pointer arithmetic Several adjustements were necessary ;o) --- com32/gplinclude/acpi/dsdt.h | 2 +- com32/gplinclude/acpi/ecdt.h | 2 +- com32/gplinclude/acpi/facs.h | 2 +- com32/gplinclude/acpi/fadt.h | 10 +++++----- com32/gplinclude/acpi/madt.h | 2 +- com32/gplinclude/acpi/sbst.h | 2 +- com32/gplinclude/acpi/ssdt.h | 2 +- com32/gplinclude/acpi/xsdt.h | 2 +- com32/gpllib/acpi/acpi.c | 1 + com32/gpllib/acpi/dsdt.c | 5 +++-- com32/gpllib/acpi/ecdt.c | 3 ++- com32/gpllib/acpi/facs.c | 4 +++- com32/gpllib/acpi/fadt.c | 5 ++++- com32/gpllib/acpi/madt.c | 12 ++++++++---- com32/gpllib/acpi/sbst.c | 3 ++- com32/gpllib/acpi/xsdt.c | 46 ++++++++++++++++++++++++++------------------ 16 files changed, 62 insertions(+), 41 deletions(-) diff --git a/com32/gplinclude/acpi/dsdt.h b/com32/gplinclude/acpi/dsdt.h index a90b5ad..84c23c0 100644 --- a/com32/gplinclude/acpi/dsdt.h +++ b/com32/gplinclude/acpi/dsdt.h @@ -18,7 +18,7 @@ #define DSDT "DSDT" typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; uint8_t *definition_block; bool valid; diff --git a/com32/gplinclude/acpi/ecdt.h b/com32/gplinclude/acpi/ecdt.h index e2a486a..57d46b9 100644 --- a/com32/gplinclude/acpi/ecdt.h +++ b/com32/gplinclude/acpi/ecdt.h @@ -21,7 +21,7 @@ #define EC_ID_OFFSET 65 typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; bool valid; uint32_t warning_energy_level; diff --git a/com32/gplinclude/acpi/facs.h b/com32/gplinclude/acpi/facs.h index 0601f1f..b1f06a9 100644 --- a/com32/gplinclude/acpi/facs.h +++ b/com32/gplinclude/acpi/facs.h @@ -25,7 +25,7 @@ #define OWNED 1<<1 typedef struct { - uint8_t *address; + uint64_t *address; uint8_t signature[4+1]; uint8_t length; uint32_t hardware_signature; diff --git a/com32/gplinclude/acpi/fadt.h b/com32/gplinclude/acpi/fadt.h index e71f255..b645710 100644 --- a/com32/gplinclude/acpi/fadt.h +++ b/com32/gplinclude/acpi/fadt.h @@ -61,11 +61,11 @@ enum { PM_UNSPECIFIED = 0, #define FORCE_APIC_PHYSICAL_DESTINATION_MODE 1<<19 typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; bool valid; - uint8_t *firmware_ctrl; - uint8_t *dsdt_address; + uint32_t *firmware_ctrl; + uint32_t *dsdt_address; uint8_t reserved; uint8_t prefered_pm_profile; uint16_t sci_int; @@ -105,8 +105,8 @@ typedef struct { s_gas reset_reg; uint8_t reset_value; uint8_t reserved_3[3]; - uint8_t *x_firmware_ctrl; - uint8_t *x_dsdt; + uint64_t *x_firmware_ctrl; + uint64_t *x_dsdt; s_gas x_pm1a_evt_blk; s_gas x_pm1b_evt_blk; s_gas x_pm1a_cnt_blk; diff --git a/com32/gplinclude/acpi/madt.h b/com32/gplinclude/acpi/madt.h index 39c25a7..bf46425 100644 --- a/com32/gplinclude/acpi/madt.h +++ b/com32/gplinclude/acpi/madt.h @@ -129,7 +129,7 @@ typedef struct { } __attribute__ ((packed)) s_local_sapic; typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; uint32_t local_apic_address; uint32_t flags; diff --git a/com32/gplinclude/acpi/sbst.h b/com32/gplinclude/acpi/sbst.h index 4ae785b..2fe24d6 100644 --- a/com32/gplinclude/acpi/sbst.h +++ b/com32/gplinclude/acpi/sbst.h @@ -18,7 +18,7 @@ #define SBST "SBST" typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; bool valid; uint32_t warning_energy_level; diff --git a/com32/gplinclude/acpi/ssdt.h b/com32/gplinclude/acpi/ssdt.h index 93eb020..436caef 100644 --- a/com32/gplinclude/acpi/ssdt.h +++ b/com32/gplinclude/acpi/ssdt.h @@ -19,7 +19,7 @@ #define PSDT "PSDT" typedef struct { - uint8_t *address; + uint64_t *address; s_acpi_description_header header; uint8_t *definition_block; bool valid; diff --git a/com32/gplinclude/acpi/xsdt.h b/com32/gplinclude/acpi/xsdt.h index 4d4ca0c..b23cbc8 100644 --- a/com32/gplinclude/acpi/xsdt.h +++ b/com32/gplinclude/acpi/xsdt.h @@ -22,7 +22,7 @@ enum { XSDT_TABLE_FOUND }; typedef struct { uint8_t *address; s_acpi_description_header header; - uint8_t *entry[255]; + uint64_t *entry[255]; uint8_t entry_count; bool valid; } s_xsdt; diff --git a/com32/gpllib/acpi/acpi.c b/com32/gpllib/acpi/acpi.c index 2f8f7da..d6b1690 100644 --- a/com32/gpllib/acpi/acpi.c +++ b/com32/gpllib/acpi/acpi.c @@ -73,4 +73,5 @@ void get_acpi_description_header(uint8_t * q, s_acpi_description_header * adh) cp_struct(&adh->oem_revision); cp_str_struct(adh->creator_id); cp_struct(&adh->creator_revision); + DEBUG_PRINT(("acpi_header at %p = %s | %s | %s\n", q, adh->signature,adh->oem_id, adh->creator_id )); } diff --git a/com32/gpllib/acpi/dsdt.c b/com32/gpllib/acpi/dsdt.c index 7117422..dbade35 100644 --- a/com32/gpllib/acpi/dsdt.c +++ b/com32/gpllib/acpi/dsdt.c @@ -36,12 +36,13 @@ void parse_dsdt(s_dsdt * d) { uint8_t *q; - q = (d->address+ACPI_HEADER_SIZE); + q = (uint8_t *)d->address; + q += ACPI_HEADER_SIZE; /* Searching how much definition blocks we must copy */ uint32_t definition_block_size=d->header.length-ACPI_HEADER_SIZE; if ((d->definition_block=malloc(definition_block_size)) != NULL) { - memcpy(d->definition_block,(d->address+ACPI_HEADER_SIZE),definition_block_size); + memcpy(d->definition_block,q,definition_block_size); } } diff --git a/com32/gpllib/acpi/ecdt.c b/com32/gpllib/acpi/ecdt.c index 41f92e3..ecd42f7 100644 --- a/com32/gpllib/acpi/ecdt.c +++ b/com32/gpllib/acpi/ecdt.c @@ -36,7 +36,8 @@ void parse_ecdt(s_ecdt * e) { uint8_t *q; - q = (e->address + ACPI_HEADER_SIZE); + q = (uint8_t *)e->address; + q += ACPI_HEADER_SIZE; /* Copying remaining structs */ cp_struct(&e->ec_control); diff --git a/com32/gpllib/acpi/facs.c b/com32/gpllib/acpi/facs.c index 3cb5637..f3e9525 100644 --- a/com32/gpllib/acpi/facs.c +++ b/com32/gpllib/acpi/facs.c @@ -35,7 +35,9 @@ void parse_facs(s_facs * f) { uint8_t *q; - q = (f->address + ACPI_HEADER_SIZE); + q = (uint8_t *) f->address; + + DEBUG_PRINT(("Searching FACS at %p\n",q)); if (memcmp(q, FACS, sizeof(FACS) - 1) == 0) { f->valid = true; cp_str_struct(f->signature); diff --git a/com32/gpllib/acpi/fadt.c b/com32/gpllib/acpi/fadt.c index fafc524..35cdb8e 100644 --- a/com32/gpllib/acpi/fadt.c +++ b/com32/gpllib/acpi/fadt.c @@ -41,7 +41,10 @@ void parse_fadt(s_fadt * f) memcpy(f->header.signature,FADT,sizeof(FADT)); /* Copying remaining structs */ - q = (f->address+ACPI_HEADER_SIZE); + q = (uint8_t *)f->address; + q += ACPI_HEADER_SIZE; + DEBUG_PRINT(("- Parsing FADT at %p\n",q)); + cp_struct(&f->firmware_ctrl); cp_struct(&f->dsdt_address); cp_struct(&f->reserved); diff --git a/com32/gpllib/acpi/madt.c b/com32/gpllib/acpi/madt.c index fa5772a..d93e4be 100644 --- a/com32/gpllib/acpi/madt.c +++ b/com32/gpllib/acpi/madt.c @@ -140,7 +140,7 @@ static uint8_t *add_apic_structure(s_acpi * acpi, uint8_t * q) madt->local_sapic_count++; break; default: - printf("APIC structure type %u, size=%u \n", type, length); + printf("Unkown APIC structure type %u, size=%u \n", type, length); q += length - 2; break; } @@ -150,19 +150,23 @@ static uint8_t *add_apic_structure(s_acpi * acpi, uint8_t * q) void parse_madt(s_acpi * acpi) { /* Let's seach for FADT table */ - uint8_t *q; + uint8_t *q, *max_address; s_madt *m = &acpi->madt; /* Fixing table name */ memcpy(m->header.signature, MADT, sizeof(MADT)); /* Copying remaining structs */ - q = (m->address + ACPI_HEADER_SIZE); + q = (uint8_t *)m->address; + q += ACPI_HEADER_SIZE; + + max_address = (uint8_t *)m->address; + max_address += m->header.length; cp_struct(&m->local_apic_address); cp_struct(&m->flags); - while (q < (m->address + m->header.length)) { + while (q < max_address) { q = add_apic_structure(acpi, q); } } diff --git a/com32/gpllib/acpi/sbst.c b/com32/gpllib/acpi/sbst.c index 016b953..036a5a9 100644 --- a/com32/gpllib/acpi/sbst.c +++ b/com32/gpllib/acpi/sbst.c @@ -35,7 +35,8 @@ void parse_sbst(s_sbst * s) { uint8_t *q; - q = (s->address+ACPI_HEADER_SIZE); + q = (uint8_t *)s->address; + q += ACPI_HEADER_SIZE; /* Copying remaining structs */ cp_struct(&s->warning_energy_level); diff --git a/com32/gpllib/acpi/xsdt.c b/com32/gpllib/acpi/xsdt.c index 698874a..3ccc514 100644 --- a/com32/gpllib/acpi/xsdt.c +++ b/com32/gpllib/acpi/xsdt.c @@ -42,21 +42,28 @@ int parse_xsdt(s_acpi * acpi) /* Searching for MADT with APIC signature */ if (memcmp(q, XSDT, sizeof(XSDT) - 1) == 0) { - DEBUG_PRINT(("XSDT table found\n")); s_xsdt *x = &acpi->xsdt; x->valid = true; get_acpi_description_header(q, &x->header); + DEBUG_PRINT(("XSDT table found at %p : length=%d\n",x->address,x->header.length)); + DEBUG_PRINT(("Expected Tables = %d\n",(x->header.length-ACPI_HEADER_SIZE)/8)); /* We now have a set of pointers to some tables */ - uint8_t *p = NULL; - for (p = (x->address + ACPI_HEADER_SIZE); - p < (x->address + x->header.length); p++) { + uint64_t *p = NULL; + for (p = ((uint64_t *)(x->address + ACPI_HEADER_SIZE)); + p < ((uint64_t *)(x->address + x->header.length)); p++) { + DEBUG_PRINT((" Looking for HEADER at %p = %x\n",p,*p)); + s_acpi_description_header adh; memset(&adh, 0, sizeof(adh)); - x->entry[x->entry_count] = p; /* Let's grab the pointed table header */ - get_acpi_description_header(p, &adh); + char address[16] = { 0 }; + sprintf(address, "%llx", *p); + uint64_t *pointed_address = (uint64_t *)strtoul(address, NULL, 16); + + x->entry[x->entry_count] = pointed_address; + get_acpi_description_header((uint8_t *)pointed_address, &adh); /* Trying to determine the pointed table */ /* Looking for FADT */ @@ -67,18 +74,18 @@ int parse_xsdt(s_acpi * acpi) s_dsdt *d = &acpi->dsdt; /* This structure is valid, let's fill it */ f->valid = true; - f->address = p; + f->address = pointed_address; memcpy(&f->header, &adh, sizeof(adh)); parse_fadt(f); /* FACS wasn't already detected * FADT points to it, let's try to detect it */ if (fa->valid == false) { - fa->address = f->x_firmware_ctrl; + fa->address = (uint64_t *)f->x_firmware_ctrl; parse_facs(fa); if (fa->valid == false) { /* Let's try again */ - fa->address = f->firmware_ctrl; + fa->address = (uint64_t *)f->firmware_ctrl; parse_facs(fa); } } @@ -87,22 +94,23 @@ int parse_xsdt(s_acpi * acpi) * FADT points to it, let's try to detect it */ if (d->valid == false) { s_acpi_description_header new_adh; - get_acpi_description_header(f->x_dsdt, + get_acpi_description_header((uint8_t *)f->x_dsdt, &new_adh); if (memcmp(new_adh.signature, DSDT, sizeof(DSDT) - 1) == 0) { - DEBUG_PRINT(("DSDT table found\n")); + DEBUG_PRINT(("DSDT table found via x_dsdt\n")); d->valid = true; - d->address = f->x_dsdt; + d->address = (uint64_t *)f->x_dsdt; memcpy(&d->header, &new_adh, sizeof(new_adh)); parse_dsdt(d); } else { /* Let's try again */ - get_acpi_description_header(f->dsdt_address, + get_acpi_description_header((uint8_t *)f->dsdt_address, &new_adh); if (memcmp(new_adh.signature, DSDT, sizeof(DSDT) - 1) == 0) { + DEBUG_PRINT(("DSDT table found via dsdt_address\n")); d->valid = true; - d->address = f->dsdt_address; + d->address = (uint64_t *)f->dsdt_address; memcpy(&d->header, &new_adh, sizeof(new_adh)); parse_dsdt(d); } @@ -114,7 +122,7 @@ int parse_xsdt(s_acpi * acpi) s_madt *m = &acpi->madt; /* This structure is valid, let's fill it */ m->valid = true; - m->address = p; + m->address = pointed_address; memcpy(&m->header, &adh, sizeof(adh)); parse_madt(acpi); } else if (memcmp(adh.signature, DSDT, sizeof(DSDT) - 1) == 0) { @@ -122,7 +130,7 @@ int parse_xsdt(s_acpi * acpi) s_dsdt *d = &acpi->dsdt; /* This structure is valid, let's fill it */ d->valid = true; - d->address = p; + d->address = pointed_address; memcpy(&d->header, &adh, sizeof(adh)); parse_dsdt(d); /* PSDT have to be considered as SSDT. Intel ACPI Spec @ 5.2.11.3 */ @@ -142,7 +150,7 @@ int parse_xsdt(s_acpi * acpi) /* This structure is valid, let's fill it */ s->valid = true; - s->address = p; + s->address = pointed_address; memcpy(&s->header, &adh, sizeof(adh)); /* Searching how much definition blocks we must copy */ @@ -160,7 +168,7 @@ int parse_xsdt(s_acpi * acpi) s_sbst *s = &acpi->sbst; /* This structure is valid, let's fill it */ s->valid = true; - s->address = p; + s->address = pointed_address; memcpy(&s->header, &adh, sizeof(adh)); parse_sbst(s); } else if (memcmp(adh.signature, ECDT, sizeof(ECDT) - 1) == 0) { @@ -168,7 +176,7 @@ int parse_xsdt(s_acpi * acpi) s_ecdt *e = &acpi->ecdt; /* This structure is valid, let's fill it */ e->valid = true; - e->address = p; + e->address = pointed_address; memcpy(&e->header, &adh, sizeof(adh)); parse_ecdt(e); } -- 2.7.4