1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Defines APIs that allow an OS to interact with UEFI firmware to query 4 * information about the boot hart ID. 5 * 6 * Copyright (c) 2022, Ventana Micro Systems Inc 7 */ 8 9 #define LOG_CATEGORY LOGC_EFI 10 #include <common.h> 11 #include <efi_loader.h> 12 #include <efi_variable.h> 13 #include <log.h> 14 #include <asm/global_data.h> 15 #include <efi_riscv.h> 16 17 DECLARE_GLOBAL_DATA_PTR; 18 19 static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID; 20 21 /** 22 * efi_riscv_get_boot_hartid() - return boot hart ID 23 * @this: RISCV_EFI_BOOT_PROTOCOL instance 24 * @boot_hartid: caller allocated memory to return boot hart id 25 * Return: status code 26 */ 27 static efi_status_t EFIAPI efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol * this,efi_uintn_t * boot_hartid)28efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this, 29 efi_uintn_t *boot_hartid) 30 { 31 EFI_ENTRY("%p, %p", this, boot_hartid); 32 33 if (this != &riscv_efi_boot_prot || !boot_hartid) 34 return EFI_EXIT(EFI_INVALID_PARAMETER); 35 36 *boot_hartid = gd->arch.boot_hart; 37 38 return EFI_EXIT(EFI_SUCCESS); 39 } 40 41 struct riscv_efi_boot_protocol riscv_efi_boot_prot = { 42 .revision = RISCV_EFI_BOOT_PROTOCOL_REVISION, 43 .get_boot_hartid = efi_riscv_get_boot_hartid 44 }; 45 46 /** 47 * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL 48 * 49 * Return: status code 50 */ efi_riscv_register(void)51efi_status_t efi_riscv_register(void) 52 { 53 efi_status_t ret = EFI_SUCCESS; 54 55 ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol, 56 (void *)&riscv_efi_boot_prot); 57 if (ret != EFI_SUCCESS) 58 log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n"); 59 return ret; 60 } 61