static struct cpio_data __init find_ucode_in_initrd(void) { long offset = 0; char *path; void *start; size_t size; #ifdef CONFIG_X86_32 struct boot_params *p; /* * On 32-bit, early load occurs before paging is turned on so we need * to use physical addresses. */ p = (struct boot_params *)__pa_nodebug(&boot_params); path = (char *)__pa_nodebug(ucode_path); start = (void *)p->hdr.ramdisk_image; size = p->hdr.ramdisk_size; #else path = ucode_path; start = (void *)(boot_params.hdr.ramdisk_image + PAGE_OFFSET); size = boot_params.hdr.ramdisk_size; #endif return find_cpio_data(path, start, size, &offset); }
void __init microcode_scan_module( unsigned long *module_map, const multiboot_info_t *mbi, void *(*bootmap)(const module_t *)) { module_t *mod = (module_t *)__va(mbi->mods_addr); uint64_t *_blob_start; unsigned long _blob_size; struct cpio_data cd; long offset; const char *p = NULL; int i; ucode_blob.size = 0; if ( !ucode_scan ) return; if ( boot_cpu_data.x86_vendor == X86_VENDOR_AMD ) p = "kernel/x86/microcode/AuthenticAMD.bin"; else if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ) p = "kernel/x86/microcode/GenuineIntel.bin"; else return; /* * Try all modules and see whichever could be the microcode blob. */ for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ ) { if ( !test_bit(i, module_map) ) continue; _blob_start = bootmap(&mod[i]); _blob_size = mod[i].mod_end; if ( !_blob_start ) { printk("Could not map multiboot module #%d (size: %ld)\n", i, _blob_size); continue; } cd.data = NULL; cd.size = 0; cd = find_cpio_data(p, _blob_start, _blob_size, &offset /* ignore */); if ( cd.data ) { /* * This is an arbitrary check - it would be sad if the blob * consumed most of the memory and did not allow guests * to launch. */ if ( cd.size > MAX_EARLY_CPIO_MICROCODE ) { printk("Multiboot %d microcode payload too big! (%ld, we can do %d)\n", i, cd.size, MAX_EARLY_CPIO_MICROCODE); goto err; } ucode_blob.size = cd.size; ucode_blob.data = xmalloc_bytes(cd.size); if ( !ucode_blob.data ) cd.data = NULL; else memcpy(ucode_blob.data, cd.data, cd.size); } bootmap(NULL); if ( cd.data ) break; } return; err: bootmap(NULL); }
void __init acpi_initrd_override(void *data, size_t size) { int sig, no, table_nr = 0, total_offset = 0; long offset = 0; struct acpi_table_header *table; char cpio_path[32] = "kernel/firmware/acpi/"; struct cpio_data file; if (data == NULL || size == 0) return; for (no = 0; no < ACPI_OVERRIDE_TABLES; no++) { file = find_cpio_data(cpio_path, data, size, &offset); if (!file.data) break; data += offset; size -= offset; if (file.size < sizeof(struct acpi_table_header)) { pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n", cpio_path, file.name); continue; } table = file.data; for (sig = 0; table_sigs[sig]; sig++) if (!memcmp(table->signature, table_sigs[sig], 4)) break; if (!table_sigs[sig]) { pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n", cpio_path, file.name); continue; } if (file.size != table->length) { pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n", cpio_path, file.name); continue; } if (acpi_table_checksum(file.data, table->length)) { pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n", cpio_path, file.name); continue; } pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n", table->signature, cpio_path, file.name, table->length); all_tables_size += table->length; acpi_initrd_files[table_nr].data = file.data; acpi_initrd_files[table_nr].size = file.size; table_nr++; } if (table_nr == 0) return; acpi_tables_addr = memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT, all_tables_size, PAGE_SIZE); if (!acpi_tables_addr) { WARN_ON(1); return; } /* * Only calling e820_add_reserve does not work and the * tables are invalid (memory got used) later. * memblock_reserve works as expected and the tables won't get modified. * But it's not enough on X86 because ioremap will * complain later (used by acpi_os_map_memory) that the pages * that should get mapped are not marked "reserved". * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area) * works fine. */ memblock_reserve(acpi_tables_addr, all_tables_size); arch_reserve_mem_area(acpi_tables_addr, all_tables_size); /* * early_ioremap only can remap 256k one time. If we map all * tables one time, we will hit the limit. Need to map chunks * one by one during copying the same as that in relocate_initrd(). */ for (no = 0; no < table_nr; no++) { unsigned char *src_p = acpi_initrd_files[no].data; phys_addr_t size = acpi_initrd_files[no].size; phys_addr_t dest_addr = acpi_tables_addr + total_offset; phys_addr_t slop, clen; char *dest_p; total_offset += size; while (size) { slop = dest_addr & ~PAGE_MASK; clen = size; if (clen > MAP_CHUNK_SIZE - slop) clen = MAP_CHUNK_SIZE - slop; dest_p = early_ioremap(dest_addr & PAGE_MASK, clen + slop); memcpy(dest_p + slop, src_p, clen); early_iounmap(dest_p, clen + slop); src_p += clen; dest_addr += clen; size -= clen; } } }
void __init acpi_initrd_override(void *data, size_t size) { int sig, no, table_nr = 0, total_offset = 0; long offset = 0; struct acpi_table_header *table; char cpio_path[32] = "kernel/firmware/acpi/"; struct cpio_data file; struct cpio_data early_initrd_files[ACPI_OVERRIDE_TABLES]; char *p; if (data == NULL || size == 0) return; for (no = 0; no < ACPI_OVERRIDE_TABLES; no++) { file = find_cpio_data(cpio_path, data, size, &offset); if (!file.data) break; data += offset; size -= offset; if (file.size < sizeof(struct acpi_table_header)) INVALID_TABLE("Table smaller than ACPI header", cpio_path, file.name); table = file.data; for (sig = 0; table_sigs[sig]; sig++) if (!memcmp(table->signature, table_sigs[sig], 4)) break; if (!table_sigs[sig]) INVALID_TABLE("Unknown signature", cpio_path, file.name); if (file.size != table->length) INVALID_TABLE("File length does not match table length", cpio_path, file.name); if (acpi_table_checksum(file.data, table->length)) INVALID_TABLE("Bad table checksum", cpio_path, file.name); pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n", table->signature, cpio_path, file.name, table->length); all_tables_size += table->length; early_initrd_files[table_nr].data = file.data; early_initrd_files[table_nr].size = file.size; table_nr++; } if (table_nr == 0) return; acpi_tables_addr = memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT, all_tables_size, PAGE_SIZE); if (!acpi_tables_addr) { WARN_ON(1); return; } /* * Only calling e820_add_reserve does not work and the * tables are invalid (memory got used) later. * memblock_reserve works as expected and the tables won't get modified. * But it's not enough on X86 because ioremap will * complain later (used by acpi_os_map_memory) that the pages * that should get mapped are not marked "reserved". * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area) * works fine. */ memblock_reserve(acpi_tables_addr, acpi_tables_addr + all_tables_size); arch_reserve_mem_area(acpi_tables_addr, all_tables_size); p = early_ioremap(acpi_tables_addr, all_tables_size); for (no = 0; no < table_nr; no++) { memcpy(p + total_offset, early_initrd_files[no].data, early_initrd_files[no].size); total_offset += early_initrd_files[no].size; } early_iounmap(p, all_tables_size); }