^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Extensible Firmware Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on Extensible Firmware Interface Specification version 2.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2013 - 2015 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define pr_fmt(fmt) "efi: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/fwnode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/screen_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int __init is_memory(efi_memory_desc_t *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (md->attribute & (EFI_MEMORY_WB|EFI_MEMORY_WT|EFI_MEMORY_WC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Translate a EFI virtual address into a physical address: this is necessary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * as some data members of the EFI system table are virtually remapped after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * SetVirtualAddressMap() has been called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static phys_addr_t __init efi_to_phys(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) efi_memory_desc_t *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) for_each_efi_memory_desc(md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (!(md->attribute & EFI_MEMORY_RUNTIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (md->virt_addr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* no virtual mapping has been installed by the stub */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (md->virt_addr <= addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) (addr - md->virt_addr) < (md->num_pages << EFI_PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return md->phys_addr + addr - md->virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static __initdata unsigned long cpu_state_table = EFI_INVALID_TABLE_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static const efi_config_table_type_t arch_tables[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, &screen_info_table},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {LINUX_EFI_ARM_CPU_STATE_TABLE_GUID, &cpu_state_table},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void __init init_screen_info(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct screen_info *si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (IS_ENABLED(CONFIG_ARM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) screen_info_table != EFI_INVALID_TABLE_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) si = early_memremap_ro(screen_info_table, sizeof(*si));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!si) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) pr_err("Could not map screen_info config table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) screen_info = *si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) early_memunmap(si, sizeof(*si));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* dummycon on ARM needs non-zero values for columns/lines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) screen_info.orig_video_cols = 80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) screen_info.orig_video_lines = 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) memblock_is_map_memory(screen_info.lfb_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) memblock_mark_nomap(screen_info.lfb_base, screen_info.lfb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int __init uefi_init(u64 efi_system_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) efi_config_table_t *config_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) efi_system_table_t *systab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) size_t table_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) systab = early_memremap_ro(efi_system_table, sizeof(efi_system_table_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (systab == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) pr_warn("Unable to map EFI system table.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) set_bit(EFI_BOOT, &efi.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (IS_ENABLED(CONFIG_64BIT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) set_bit(EFI_64BIT, &efi.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) retval = efi_systab_check_header(&systab->hdr, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) efi.runtime = systab->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) efi.runtime_version = systab->hdr.revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) efi_systab_report_header(&systab->hdr, efi_to_phys(systab->fw_vendor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) table_size = sizeof(efi_config_table_t) * systab->nr_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) config_tables = early_memremap_ro(efi_to_phys(systab->tables),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) table_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (config_tables == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) pr_warn("Unable to map EFI config table array.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) retval = efi_config_parse_tables(config_tables, systab->nr_tables,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) IS_ENABLED(CONFIG_ARM) ? arch_tables
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) : NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) early_memunmap(config_tables, table_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) early_memunmap(systab, sizeof(efi_system_table_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * Return true for regions that can be used as System RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static __init int is_usable_memory(efi_memory_desc_t *md)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) switch (md->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) case EFI_LOADER_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) case EFI_LOADER_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) case EFI_ACPI_RECLAIM_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) case EFI_BOOT_SERVICES_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) case EFI_BOOT_SERVICES_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) case EFI_CONVENTIONAL_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) case EFI_PERSISTENT_MEMORY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Special purpose memory is 'soft reserved', which means it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * is set aside initially, but can be hotplugged back in or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * be assigned to the dax driver after boot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (efi_soft_reserve_enabled() &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) (md->attribute & EFI_MEMORY_SP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * According to the spec, these regions are no longer reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * after calling ExitBootServices(). However, we can only use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * them as System RAM if they can be mapped writeback cacheable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return (md->attribute & EFI_MEMORY_WB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static __init void reserve_regions(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) efi_memory_desc_t *md;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) u64 paddr, npages, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if (efi_enabled(EFI_DBG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) pr_info("Processing EFI memory map:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * Discard memblocks discovered so far: if there are any at this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * point, they originate from memory nodes in the DT, and UEFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * uses its own memory map instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) memblock_remove(0, PHYS_ADDR_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) for_each_efi_memory_desc(md) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) paddr = md->phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) npages = md->num_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (efi_enabled(EFI_DBG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) char buf[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) pr_info(" 0x%012llx-0x%012llx %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) efi_md_typeattr_format(buf, sizeof(buf), md));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) memrange_efi_to_native(&paddr, &npages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) size = npages << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (is_memory(md)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) early_init_dt_add_memory_arch(paddr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (!is_usable_memory(md))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) memblock_mark_nomap(paddr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* keep ACPI reclaim memory intact for kexec etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (md->type == EFI_ACPI_RECLAIM_MEMORY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) memblock_reserve(paddr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) void __init efi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct efi_memory_map_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) u64 efi_system_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Grab UEFI information placed in FDT by stub */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) efi_system_table = efi_get_fdt_params(&data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!efi_system_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (efi_memmap_init_early(&data) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * If we are booting via UEFI, the UEFI memory map is the only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * description of memory we have, so there is little point in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * proceeding if we cannot access it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) panic("Unable to map EFI memory map.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) WARN(efi.memmap.desc_version != 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) "Unexpected EFI_MEMORY_DESCRIPTOR version %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) efi.memmap.desc_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (uefi_init(efi_system_table) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) efi_memmap_unmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) reserve_regions();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) efi_esrt_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) efi_mokvar_table_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) memblock_reserve(data.phys_map & PAGE_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) init_screen_info();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #ifdef CONFIG_ARM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* ARM does not permit early mappings to persist across paging_init() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) efi_memmap_unmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (cpu_state_table != EFI_INVALID_TABLE_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct efi_arm_entry_state *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) bool dump_state = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) state = early_memremap_ro(cpu_state_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) sizeof(struct efi_arm_entry_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (state == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) pr_warn("Unable to map CPU entry state table.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if ((state->sctlr_before_ebs & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) pr_warn(FW_BUG "EFI stub was entered with MMU and Dcache disabled, please fix your firmware!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) else if ((state->sctlr_after_ebs & 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) pr_warn(FW_BUG "ExitBootServices() returned with MMU and Dcache disabled, please fix your firmware!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dump_state = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (dump_state || efi_enabled(EFI_DBG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) pr_info("CPSR at EFI stub entry : 0x%08x\n", state->cpsr_before_ebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pr_info("SCTLR at EFI stub entry : 0x%08x\n", state->sctlr_before_ebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) pr_info("CPSR after ExitBootServices() : 0x%08x\n", state->cpsr_after_ebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) pr_info("SCTLR after ExitBootServices(): 0x%08x\n", state->sctlr_after_ebs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) early_memunmap(state, sizeof(struct efi_arm_entry_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static bool efifb_overlaps_pci_range(const struct of_pci_range *range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) u64 fb_base = screen_info.lfb_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (screen_info.capabilities & VIDEO_CAPABILITY_64BIT_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) fb_base |= (u64)(unsigned long)screen_info.ext_lfb_base << 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return fb_base >= range->cpu_addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) fb_base < (range->cpu_addr + range->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static struct device_node *find_pci_overlap_node(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) for_each_node_by_type(np, "pci") {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct of_pci_range_parser parser;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct of_pci_range range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) err = of_pci_range_parser_init(&parser, np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) pr_warn("of_pci_range_parser_init() failed: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) for_each_of_pci_range(&parser, &range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (efifb_overlaps_pci_range(&range))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * If the efifb framebuffer is backed by a PCI graphics controller, we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * to ensure that this relation is expressed using a device link when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * running in DT mode, or the probe order may be reversed, resulting in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * resource reservation conflict on the memory window that the efifb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * framebuffer steals from the PCIe host bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static int efifb_add_links(struct fwnode_handle *fwnode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct device_node *sup_np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) sup_np = find_pci_overlap_node();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * If there's no PCI graphics controller backing the efifb, we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * done here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (!sup_np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) fwnode_link_add(fwnode, of_fwnode_handle(sup_np));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) of_node_put(sup_np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static const struct fwnode_operations efifb_fwnode_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .add_links = efifb_add_links,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static struct fwnode_handle efifb_fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int __init register_gop_device(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct platform_device *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) pd = platform_device_alloc("efi-framebuffer", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (!pd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (IS_ENABLED(CONFIG_PCI)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) fwnode_init(&efifb_fwnode, &efifb_fwnode_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) pd->dev.fwnode = &efifb_fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) err = platform_device_add_data(pd, &screen_info, sizeof(screen_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) return platform_device_add(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) subsys_initcall(register_gop_device);