unsigned long write_acpi_tables(unsigned long start) { unsigned long current; acpi_rsdp_t *rsdp; acpi_rsdt_t *rsdt; acpi_xsdt_t *xsdt; acpi_hpet_t *hpet; acpi_madt_t *madt; acpi_mcfg_t *mcfg; acpi_fadt_t *fadt; acpi_facs_t *facs; #if CONFIG_HAVE_ACPI_SLIC acpi_header_t *slic; #endif acpi_header_t *ssdt; acpi_header_t *dsdt; current = fw_cfg_acpi_tables(start); if (current) return current; current = start; /* Align ACPI tables to 16byte */ ALIGN_CURRENT; printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); /* We need at least an RSDP and an RSDT Table */ rsdp = (acpi_rsdp_t *) current; current += sizeof(acpi_rsdp_t); ALIGN_CURRENT; rsdt = (acpi_rsdt_t *) current; current += sizeof(acpi_rsdt_t); ALIGN_CURRENT; xsdt = (acpi_xsdt_t *) current; current += sizeof(acpi_xsdt_t); ALIGN_CURRENT; /* clear all table memory */ memset((void *) start, 0, current - start); acpi_write_rsdp(rsdp, rsdt, xsdt); acpi_write_rsdt(rsdt); acpi_write_xsdt(xsdt); /* * We explicitly add these tables later on: */ printk(BIOS_DEBUG, "ACPI: * HPET\n"); hpet = (acpi_hpet_t *) current; current += sizeof(acpi_hpet_t); ALIGN_CURRENT; acpi_create_hpet(hpet); acpi_add_table(rsdp, hpet); /* If we want to use HPET Timers Linux wants an MADT */ printk(BIOS_DEBUG, "ACPI: * MADT\n"); madt = (acpi_madt_t *) current; acpi_create_madt(madt); current += madt->header.length; ALIGN_CURRENT; acpi_add_table(rsdp, madt); printk(BIOS_DEBUG, "ACPI: * MCFG\n"); mcfg = (acpi_mcfg_t *) current; acpi_create_mcfg(mcfg); current += mcfg->header.length; ALIGN_CURRENT; acpi_add_table(rsdp, mcfg); printk(BIOS_DEBUG, "ACPI: * FACS\n"); facs = (acpi_facs_t *) current; current += sizeof(acpi_facs_t); ALIGN_CURRENT; acpi_create_facs(facs); dsdt = (acpi_header_t *) current; memcpy(dsdt, &AmlCode, sizeof(acpi_header_t)); current += dsdt->length; memcpy(dsdt, &AmlCode, dsdt->length); ALIGN_CURRENT; /* We patched up the DSDT, so we need to recalculate the checksum */ dsdt->checksum = 0; dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt, dsdt->length); #if CONFIG_HAVE_ACPI_SLIC printk(BIOS_DEBUG, "ACPI: * SLIC\n"); slic = (acpi_header_t *)current; current += acpi_create_slic(current); ALIGN_CURRENT; acpi_add_table(rsdp, slic); #endif printk(BIOS_DEBUG, "ACPI: * FADT\n"); fadt = (acpi_fadt_t *) current; current += sizeof(acpi_fadt_t); ALIGN_CURRENT; acpi_create_fadt(fadt, facs, dsdt); acpi_add_table(rsdp, fadt); printk(BIOS_DEBUG, "ACPI: * SSDT\n"); ssdt = (acpi_header_t *)current; acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); current += ssdt->length; acpi_add_table(rsdp, ssdt); ALIGN_CURRENT; printk(BIOS_DEBUG, "current = %lx\n", current); printk(BIOS_INFO, "ACPI: done.\n"); return current; }
unsigned long write_acpi_tables(unsigned long start) { unsigned long current; acpi_rsdp_t *rsdp; acpi_rsdt_t *rsdt; acpi_xsdt_t *xsdt; acpi_fadt_t *fadt; acpi_facs_t *facs; acpi_header_t *slic_file, *slic; acpi_header_t *ssdt; acpi_header_t *dsdt_file, *dsdt; acpi_mcfg_t *mcfg; acpi_tcpa_t *tcpa; acpi_madt_t *madt; struct device *dev; unsigned long fw; size_t slic_size, dsdt_size; char oem_id[6], oem_table_id[8]; current = start; /* Align ACPI tables to 16byte */ current = acpi_align_current(current); fw = fw_cfg_acpi_tables(current); if (fw) return fw; #if CONFIG_COMPILE_IN_DSDT extern char _binary_dsdt_aml_start; extern char _binary_dsdt_aml_end; dsdt_file = (acpi_header_t *)&_binary_dsdt_aml_start; dsdt_size = (size_t)(&_binary_dsdt_aml_end - &_binary_dsdt_aml_start); #else dsdt_file = cbfs_boot_map_with_leak( CONFIG_CBFS_PREFIX "/dsdt.aml", CBFS_TYPE_RAW, &dsdt_size); #endif if (!dsdt_file) { printk(BIOS_ERR, "No DSDT file, skipping ACPI tables\n"); return current; } if (dsdt_file->length > dsdt_size || dsdt_file->length < sizeof (acpi_header_t) || memcmp(dsdt_file->signature, "DSDT", 4) != 0) { printk(BIOS_ERR, "Invalid DSDT file, skipping ACPI tables\n"); return current; } slic_file = cbfs_boot_map_with_leak(CONFIG_CBFS_PREFIX "/slic", CBFS_TYPE_RAW, &slic_size); if (slic_file && (slic_file->length > slic_size || slic_file->length < sizeof (acpi_header_t) || memcmp(slic_file->signature, "SLIC", 4) != 0)) { slic_file = 0; } if (slic_file) { memcpy(oem_id, slic_file->oem_id, 6); memcpy(oem_table_id, slic_file->oem_table_id, 8); } else { memcpy(oem_id, OEM_ID, 6); memcpy(oem_table_id, ACPI_TABLE_CREATOR, 8); } printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", start); /* We need at least an RSDP and an RSDT Table */ rsdp = (acpi_rsdp_t *) current; current += sizeof(acpi_rsdp_t); current = acpi_align_current(current); rsdt = (acpi_rsdt_t *) current; current += sizeof(acpi_rsdt_t); current = acpi_align_current(current); xsdt = (acpi_xsdt_t *) current; current += sizeof(acpi_xsdt_t); current = acpi_align_current(current); /* clear all table memory */ memset((void *) start, 0, current - start); acpi_write_rsdp(rsdp, rsdt, xsdt, oem_id); acpi_write_rsdt(rsdt, oem_id, oem_table_id); acpi_write_xsdt(xsdt, oem_id, oem_table_id); printk(BIOS_DEBUG, "ACPI: * FACS\n"); current = (ALIGN(current, 64)); facs = (acpi_facs_t *) current; current += sizeof(acpi_facs_t); current = acpi_align_current(current); acpi_create_facs(facs); printk(BIOS_DEBUG, "ACPI: * DSDT\n"); dsdt = (acpi_header_t *) current; memcpy(dsdt, dsdt_file, sizeof(acpi_header_t)); if (dsdt->length >= sizeof(acpi_header_t)) { current += sizeof(acpi_header_t); acpigen_set_current((char *) current); for (dev = all_devices; dev; dev = dev->next) if (dev->ops && dev->ops->acpi_inject_dsdt_generator) { dev->ops->acpi_inject_dsdt_generator(dev); } current = (unsigned long) acpigen_get_current(); memcpy((char *)current, (char *)dsdt_file + sizeof(acpi_header_t), dsdt->length - sizeof(acpi_header_t)); current += dsdt->length - sizeof(acpi_header_t); /* (Re)calculate length and checksum. */ dsdt->length = current - (unsigned long)dsdt; dsdt->checksum = 0; dsdt->checksum = acpi_checksum((void *)dsdt, dsdt->length); } current = acpi_align_current(current); printk(BIOS_DEBUG, "ACPI: * FADT\n"); fadt = (acpi_fadt_t *) current; current += sizeof(acpi_fadt_t); current = acpi_align_current(current); acpi_create_fadt(fadt, facs, dsdt); acpi_add_table(rsdp, fadt); if (slic_file) { printk(BIOS_DEBUG, "ACPI: * SLIC\n"); slic = (acpi_header_t *)current; memcpy(slic, slic_file, slic_file->length); current += slic_file->length; current = acpi_align_current(current); acpi_add_table(rsdp, slic); } printk(BIOS_DEBUG, "ACPI: * SSDT\n"); ssdt = (acpi_header_t *)current; acpi_create_ssdt_generator(ssdt, ACPI_TABLE_CREATOR); if (ssdt->length > sizeof(acpi_header_t)) { current += ssdt->length; acpi_add_table(rsdp, ssdt); current = acpi_align_current(current); } printk(BIOS_DEBUG, "ACPI: * MCFG\n"); mcfg = (acpi_mcfg_t *) current; acpi_create_mcfg(mcfg); if (mcfg->header.length > sizeof(acpi_mcfg_t)) { current += mcfg->header.length; current = acpi_align_current(current); acpi_add_table(rsdp, mcfg); } printk(BIOS_DEBUG, "ACPI: * TCPA\n"); tcpa = (acpi_tcpa_t *) current; acpi_create_tcpa(tcpa); if (tcpa->header.length >= sizeof(acpi_tcpa_t)) { current += tcpa->header.length; current = acpi_align_current(current); acpi_add_table(rsdp, tcpa); } printk(BIOS_DEBUG, "ACPI: * MADT\n"); madt = (acpi_madt_t *) current; acpi_create_madt(madt); if (madt->header.length > sizeof(acpi_madt_t)) { current+=madt->header.length; acpi_add_table(rsdp,madt); } current = acpi_align_current(current); printk(BIOS_DEBUG, "current = %lx\n", current); for (dev = all_devices; dev; dev = dev->next) { if (dev->ops && dev->ops->write_acpi_tables) { current = dev->ops->write_acpi_tables(dev, current, rsdp); current = acpi_align_current(current); } } printk(BIOS_INFO, "ACPI: done.\n"); return current; }