loongarch-stub.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Author: Yun Liu <[email protected]>
  4. * Huacai Chen <[email protected]>
  5. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  6. */
  7. #include <asm/efi.h>
  8. #include <asm/addrspace.h>
  9. #include "efistub.h"
  10. typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
  11. unsigned long systab);
  12. extern int kernel_asize;
  13. extern int kernel_fsize;
  14. extern int kernel_offset;
  15. extern kernel_entry_t kernel_entry;
  16. efi_status_t check_platform_features(void)
  17. {
  18. return EFI_SUCCESS;
  19. }
  20. efi_status_t handle_kernel_image(unsigned long *image_addr,
  21. unsigned long *image_size,
  22. unsigned long *reserve_addr,
  23. unsigned long *reserve_size,
  24. efi_loaded_image_t *image,
  25. efi_handle_t image_handle)
  26. {
  27. efi_status_t status;
  28. unsigned long kernel_addr = 0;
  29. kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
  30. status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
  31. PHYSADDR(VMLINUX_LOAD_ADDRESS), SZ_2M, 0x0);
  32. *image_addr = kernel_addr;
  33. *image_size = kernel_asize;
  34. return status;
  35. }
  36. struct exit_boot_struct {
  37. efi_memory_desc_t *runtime_map;
  38. int runtime_entry_count;
  39. };
  40. static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
  41. {
  42. struct exit_boot_struct *p = priv;
  43. /*
  44. * Update the memory map with virtual addresses. The function will also
  45. * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
  46. * entries so that we can pass it straight to SetVirtualAddressMap()
  47. */
  48. efi_get_virtmap(map->map, map->map_size, map->desc_size,
  49. p->runtime_map, &p->runtime_entry_count);
  50. return EFI_SUCCESS;
  51. }
  52. efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
  53. unsigned long kernel_addr, char *cmdline_ptr)
  54. {
  55. kernel_entry_t real_kernel_entry;
  56. struct exit_boot_struct priv;
  57. unsigned long desc_size;
  58. efi_status_t status;
  59. u32 desc_ver;
  60. status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);
  61. if (status != EFI_SUCCESS) {
  62. efi_err("Unable to retrieve UEFI memory map.\n");
  63. return status;
  64. }
  65. efi_info("Exiting boot services\n");
  66. efi_novamap = false;
  67. status = efi_exit_boot_services(handle, &priv, exit_boot_func);
  68. if (status != EFI_SUCCESS)
  69. return status;
  70. /* Install the new virtual address map */
  71. efi_rt_call(set_virtual_address_map,
  72. priv.runtime_entry_count * desc_size, desc_size,
  73. desc_ver, priv.runtime_map);
  74. /* Config Direct Mapping */
  75. csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
  76. csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
  77. real_kernel_entry = (kernel_entry_t)
  78. ((unsigned long)&kernel_entry - kernel_addr + VMLINUX_LOAD_ADDRESS);
  79. real_kernel_entry(true, (unsigned long)cmdline_ptr,
  80. (unsigned long)efi_system_table);
  81. }