Path: blob/master/drivers/firmware/efi/libstub/loongarch.c
26483 views
// SPDX-License-Identifier: GPL-2.01/*2* Author: Yun Liu <[email protected]>3* Huacai Chen <[email protected]>4* Copyright (C) 2020-2022 Loongson Technology Corporation Limited5*/67#include <asm/efi.h>8#include <asm/addrspace.h>9#include "efistub.h"10#include "loongarch-stub.h"1112typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,13unsigned long systab);1415efi_status_t check_platform_features(void)16{17return EFI_SUCCESS;18}1920struct exit_boot_struct {21efi_memory_desc_t *runtime_map;22int runtime_entry_count;23};2425static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)26{27struct exit_boot_struct *p = priv;2829/*30* Update the memory map with virtual addresses. The function will also31* populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME32* entries so that we can pass it straight to SetVirtualAddressMap()33*/34efi_get_virtmap(map->map, map->map_size, map->desc_size,35p->runtime_map, &p->runtime_entry_count);3637return EFI_SUCCESS;38}3940unsigned long __weak kernel_entry_address(unsigned long kernel_addr,41efi_loaded_image_t *image)42{43return *(unsigned long *)(kernel_addr + 8) - PHYSADDR(VMLINUX_LOAD_ADDRESS) + kernel_addr;44}4546efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,47unsigned long kernel_addr, char *cmdline_ptr)48{49kernel_entry_t real_kernel_entry;50struct exit_boot_struct priv;51unsigned long desc_size;52efi_status_t status;53u32 desc_ver;5455status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);56if (status != EFI_SUCCESS) {57efi_err("Unable to retrieve UEFI memory map.\n");58return status;59}6061efi_info("Exiting boot services\n");6263efi_novamap = false;64status = efi_exit_boot_services(handle, &priv, exit_boot_func);65if (status != EFI_SUCCESS)66return status;6768/* Install the new virtual address map */69efi_rt_call(set_virtual_address_map,70priv.runtime_entry_count * desc_size, desc_size,71desc_ver, priv.runtime_map);7273/* Config Direct Mapping */74csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);75csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);76csr_write64(CSR_DMW2_INIT, LOONGARCH_CSR_DMWIN2);77csr_write64(CSR_DMW3_INIT, LOONGARCH_CSR_DMWIN3);7879real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image);8081real_kernel_entry(true, (unsigned long)cmdline_ptr,82(unsigned long)efi_system_table);83}848586