static void __init __map_region(efi_memory_desc_t *md, u64 va) { pgd_t *pgd = (pgd_t *)__va(real_mode_header->trampoline_pgd); unsigned long pf = 0; if (!(md->attribute & EFI_MEMORY_WB)) pf |= _PAGE_PCD; if (kernel_map_pages_in_pgd(pgd, md->phys_addr, va, md->num_pages, pf)) pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n", md->phys_addr, va); }
static int __init efi_update_mappings(efi_memory_desc_t *md, unsigned long pf) { unsigned long pfn; pgd_t *pgd = efi_pgd; int err1, err2; /* Update the 1:1 mapping */ pfn = md->phys_addr >> PAGE_SHIFT; err1 = kernel_map_pages_in_pgd(pgd, pfn, md->phys_addr, md->num_pages, pf); if (err1) { pr_err("Error while updating 1:1 mapping PA 0x%llx -> VA 0x%llx!\n", md->phys_addr, md->virt_addr); } err2 = kernel_map_pages_in_pgd(pgd, pfn, md->virt_addr, md->num_pages, pf); if (err2) { pr_err("Error while updating VA mapping PA 0x%llx -> VA 0x%llx!\n", md->phys_addr, md->virt_addr); } return err1 || err2; }
static void __init __map_region(efi_memory_desc_t *md, u64 va) { unsigned long flags = _PAGE_RW; unsigned long pfn; pgd_t *pgd = efi_pgd; if (!(md->attribute & EFI_MEMORY_WB)) flags |= _PAGE_PCD; pfn = md->phys_addr >> PAGE_SHIFT; if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags)) pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n", md->phys_addr, va); }
int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) { unsigned long pfn, text; struct page *page; unsigned npages; pgd_t *pgd; if (efi_enabled(EFI_OLD_MEMMAP)) return 0; efi_scratch.efi_pgt = (pgd_t *)__pa(efi_pgd); pgd = efi_pgd; /* * It can happen that the physical address of new_memmap lands in memory * which is not mapped in the EFI page table. Therefore we need to go * and ident-map those pages containing the map before calling * phys_efi_set_virtual_address_map(). */ pfn = pa_memmap >> PAGE_SHIFT; if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX | _PAGE_RW)) { pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap); return 1; } efi_scratch.use_pgd = true; /* * Certain firmware versions are way too sentimential and still believe * they are exclusive and unquestionable owners of the first physical page, * even though they explicitly mark it as EFI_CONVENTIONAL_MEMORY * (but then write-access it later during SetVirtualAddressMap()). * * Create a 1:1 mapping for this page, to avoid triple faults during early * boot with such firmware. We are free to hand this page to the BIOS, * as trim_bios_range() will reserve the first page and isolate it away * from memory allocators anyway. */ if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, _PAGE_RW)) { pr_err("Failed to create 1:1 mapping for the first page!\n"); return 1; } /* * When making calls to the firmware everything needs to be 1:1 * mapped and addressable with 32-bit pointers. Map the kernel * text and allocate a new stack because we can't rely on the * stack pointer being < 4GB. */ if (!IS_ENABLED(CONFIG_EFI_MIXED) || efi_is_native()) return 0; page = alloc_page(GFP_KERNEL|__GFP_DMA32); if (!page) panic("Unable to allocate EFI runtime stack < 4GB\n"); efi_scratch.phys_stack = virt_to_phys(page_address(page)); efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */ npages = (_etext - _text) >> PAGE_SHIFT; text = __pa(_text); pfn = text >> PAGE_SHIFT; if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) { pr_err("Failed to map kernel text 1:1\n"); return 1; } return 0; }