efi.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * EFI initialization
  4. *
  5. * Author: Jianmin Lv <[email protected]>
  6. * Huacai Chen <[email protected]>
  7. *
  8. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  9. */
  10. #include <linux/acpi.h>
  11. #include <linux/efi.h>
  12. #include <linux/efi-bgrt.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/export.h>
  16. #include <linux/io.h>
  17. #include <linux/kobject.h>
  18. #include <linux/memblock.h>
  19. #include <linux/reboot.h>
  20. #include <linux/uaccess.h>
  21. #include <asm/early_ioremap.h>
  22. #include <asm/efi.h>
  23. #include <asm/loongson.h>
  24. static unsigned long efi_nr_tables;
  25. static unsigned long efi_config_table;
  26. static unsigned long __initdata boot_memmap = EFI_INVALID_TABLE_ADDR;
  27. static efi_system_table_t *efi_systab;
  28. static efi_config_table_type_t arch_tables[] __initdata = {
  29. {LINUX_EFI_BOOT_MEMMAP_GUID, &boot_memmap, "MEMMAP" },
  30. {},
  31. };
  32. void __init efi_runtime_init(void)
  33. {
  34. if (!efi_enabled(EFI_BOOT))
  35. return;
  36. if (efi_runtime_disabled()) {
  37. pr_info("EFI runtime services will be disabled.\n");
  38. return;
  39. }
  40. efi.runtime = (efi_runtime_services_t *)efi_systab->runtime;
  41. efi.runtime_version = (unsigned int)efi.runtime->hdr.revision;
  42. efi_native_runtime_setup();
  43. set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
  44. }
  45. void __init efi_init(void)
  46. {
  47. int size;
  48. void *config_tables;
  49. struct efi_boot_memmap *tbl;
  50. if (!efi_system_table)
  51. return;
  52. efi_systab = (efi_system_table_t *)early_memremap_ro(efi_system_table, sizeof(*efi_systab));
  53. if (!efi_systab) {
  54. pr_err("Can't find EFI system table.\n");
  55. return;
  56. }
  57. efi_systab_report_header(&efi_systab->hdr, efi_systab->fw_vendor);
  58. set_bit(EFI_64BIT, &efi.flags);
  59. efi_nr_tables = efi_systab->nr_tables;
  60. efi_config_table = (unsigned long)efi_systab->tables;
  61. size = sizeof(efi_config_table_t);
  62. config_tables = early_memremap(efi_config_table, efi_nr_tables * size);
  63. efi_config_parse_tables(config_tables, efi_systab->nr_tables, arch_tables);
  64. early_memunmap(config_tables, efi_nr_tables * size);
  65. set_bit(EFI_CONFIG_TABLES, &efi.flags);
  66. if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI)
  67. memblock_reserve(screen_info.lfb_base, screen_info.lfb_size);
  68. if (boot_memmap == EFI_INVALID_TABLE_ADDR)
  69. return;
  70. tbl = early_memremap_ro(boot_memmap, sizeof(*tbl));
  71. if (tbl) {
  72. struct efi_memory_map_data data;
  73. data.phys_map = boot_memmap + sizeof(*tbl);
  74. data.size = tbl->map_size;
  75. data.desc_size = tbl->desc_size;
  76. data.desc_version = tbl->desc_ver;
  77. if (efi_memmap_init_early(&data) < 0)
  78. panic("Unable to map EFI memory map.\n");
  79. early_memunmap(tbl, sizeof(*tbl));
  80. }
  81. }