int parse_xsdt(s_acpi * acpi) { /* Let's seach for XSDT table */ uint8_t *q; /* Let's start for the base address */ q = acpi->xsdt.address; /* If address is null return an error */ if (q == 0 ) { DEBUG_PRINT(("XSDT is null, exiting\n")); return -XSDT_TABLE_FOUND; } DEBUG_PRINT(("Searching XSDT at %p",q)); /* Searching for MADT with APIC signature */ if (memcmp(q, XSDT, sizeof(XSDT) - 1) == 0) { 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 */ 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)); /* Let's grab the pointed table header */ char address[16] = { 0 }; sprintf(address, "%" PRIx64 "x", *p); uint64_t *pointed_address = (uint64_t *)strtoul(address, NULL, 16); x->entry[x->entry_count] = pointed_address; if (parse_header(pointed_address, acpi)) { x->entry_count++; } } return XSDT_TABLE_FOUND; } return -XSDT_TABLE_FOUND; }
bool parse_header(uint64_t *address, s_acpi *acpi) { s_acpi_description_header adh; memset(&adh, 0, sizeof(adh)); get_acpi_description_header((uint8_t *)address, &adh); /* Trying to determine the pointed table */ /* Looking for FADT */ if (memcmp(adh.signature, FACP, sizeof(FACP) - 1) == 0) { DEBUG_PRINT(("FACP table found\n")); s_fadt *f = &acpi->fadt; s_facs *fa = &acpi->facs; s_dsdt *d = &acpi->dsdt; /* This structure is valid, let's fill it */ f->valid = true; f->address = 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 = (uint64_t *)f->x_firmware_ctrl; parse_facs(fa); if (fa->valid == false) { /* Let's try again */ fa->address = (uint64_t *)f->firmware_ctrl; parse_facs(fa); } } /* DSDT wasn't already detected * FADT points to it, let's try to detect it */ if (d->valid == false) { s_acpi_description_header new_adh; 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 via x_dsdt\n")); d->valid = true; 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((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 = (uint64_t *)f->dsdt_address; memcpy(&d->header, &new_adh, sizeof(new_adh)); parse_dsdt(d); } } } } /* Looking for MADT */ else if (memcmp(adh.signature, APIC, sizeof(APIC) - 1) == 0) { DEBUG_PRINT(("MADT table found\n")); s_madt *m = &acpi->madt; /* This structure is valid, let's fill it */ m->valid = true; m->address =address; memcpy(&m->header, &adh, sizeof(adh)); parse_madt(acpi); } else if (memcmp(adh.signature, DSDT, sizeof(DSDT) - 1) == 0) { DEBUG_PRINT(("DSDT table found\n")); s_dsdt *d = &acpi->dsdt; /* This structure is valid, let's fill it */ d->valid = true; d->address = address; memcpy(&d->header, &adh, sizeof(adh)); parse_dsdt(d); /* PSDT have to be considered as SSDT. Intel ACPI Spec @ 5.2.11.3 */ } else if ((memcmp(adh.signature, SSDT, sizeof(SSDT) - 1) == 0) || (memcmp(adh.signature, PSDT, sizeof(PSDT) - 1) == 0)) { DEBUG_PRINT(("SSDT table found with %s \n",adh.signature)); if ((acpi->ssdt_count >= MAX_SSDT - 1)) return false; /* We can have many SSDT, so let's allocate a new one */ if ((acpi->ssdt[acpi->ssdt_count] = malloc(sizeof(s_ssdt))) == NULL) return false; s_ssdt *s = acpi->ssdt[acpi->ssdt_count]; /* This structure is valid, let's fill it */ s->valid = true; s->address = address; memcpy(&s->header, &adh, sizeof(adh)); /* Searching how much definition blocks we must copy */ uint32_t definition_block_size = adh.length - ACPI_HEADER_SIZE; if ((s->definition_block = malloc(definition_block_size)) != NULL) { memcpy(s->definition_block, (s->address + ACPI_HEADER_SIZE), definition_block_size); } /* Increment the number of ssdt we have */ acpi->ssdt_count++; } else if (memcmp(adh.signature, SBST, sizeof(SBST) - 1) == 0) { DEBUG_PRINT(("SBST table found\n")); s_sbst *s = &acpi->sbst; /* This structure is valid, let's fill it */ s->valid = true; s->address = address; memcpy(&s->header, &adh, sizeof(adh)); parse_sbst(s); } else if (memcmp(adh.signature, ECDT, sizeof(ECDT) - 1) == 0) { DEBUG_PRINT(("ECDT table found\n")); s_ecdt *e = &acpi->ecdt; /* This structure is valid, let's fill it */ e->valid = true; e->address = address; memcpy(&e->header, &adh, sizeof(adh)); parse_ecdt(e); } else if (memcmp(adh.signature, HPET, sizeof(HPET) - 1) == 0) { DEBUG_PRINT(("HPET table found\n")); s_hpet *h = &acpi->hpet; /* This structure is valid, let's fill it */ h->valid = true; h->address = address; memcpy(&h->header, &adh, sizeof(adh)); } else if (memcmp(adh.signature, TCPA, sizeof(TCPA) - 1) == 0) { DEBUG_PRINT(("TCPA table found\n")); s_tcpa *t = &acpi->tcpa; /* This structure is valid, let's fill it */ t->valid = true; t->address = address; memcpy(&t->header, &adh, sizeof(adh)); } else if (memcmp(adh.signature, MCFG, sizeof(MCFG) - 1) == 0) { DEBUG_PRINT(("MCFG table found\n")); s_mcfg *m = &acpi->mcfg; /* This structure is valid, let's fill it */ m->valid = true; m->address = address; memcpy(&m->header, &adh, sizeof(adh)); } else if (memcmp(adh.signature, SLIC, sizeof(SLIC) - 1) == 0) { DEBUG_PRINT(("SLIC table found\n")); s_slic *s = &acpi->slic; /* This structure is valid, let's fill it */ s->valid = true; s->address = address; memcpy(&s->header, &adh, sizeof(adh)); } else if (memcmp(adh.signature, BOOT, sizeof(BOOT) - 1) == 0) { DEBUG_PRINT(("BOOT table found\n")); s_boot *b = &acpi->boot; /* This structure is valid, let's fill it */ b->valid = true; b->address = address; memcpy(&b->header, &adh, sizeof(adh)); } return true; }