Sunil V L | 279d1c8 | 2022-01-28 20:48:44 +0530 | [diff] [blame] | 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 |
Sunil V L | 279d1c8 | 2022-01-28 20:48:44 +0530 | [diff] [blame] | 10 | #include <efi_loader.h> |
| 11 | #include <efi_variable.h> |
| 12 | #include <log.h> |
| 13 | #include <asm/global_data.h> |
| 14 | #include <efi_riscv.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID; |
| 19 | |
| 20 | /** |
| 21 | * efi_riscv_get_boot_hartid() - return boot hart ID |
| 22 | * @this: RISCV_EFI_BOOT_PROTOCOL instance |
| 23 | * @boot_hartid: caller allocated memory to return boot hart id |
| 24 | * Return: status code |
| 25 | */ |
| 26 | static efi_status_t EFIAPI |
| 27 | efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this, |
| 28 | efi_uintn_t *boot_hartid) |
| 29 | { |
| 30 | EFI_ENTRY("%p, %p", this, boot_hartid); |
| 31 | |
| 32 | if (this != &riscv_efi_boot_prot || !boot_hartid) |
Heinrich Schuchardt | ff3d37b | 2023-01-11 19:08:01 +0100 | [diff] [blame] | 33 | return EFI_EXIT(EFI_INVALID_PARAMETER); |
Sunil V L | 279d1c8 | 2022-01-28 20:48:44 +0530 | [diff] [blame] | 34 | |
| 35 | *boot_hartid = gd->arch.boot_hart; |
| 36 | |
| 37 | return EFI_EXIT(EFI_SUCCESS); |
| 38 | } |
| 39 | |
| 40 | struct riscv_efi_boot_protocol riscv_efi_boot_prot = { |
| 41 | .revision = RISCV_EFI_BOOT_PROTOCOL_REVISION, |
| 42 | .get_boot_hartid = efi_riscv_get_boot_hartid |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL |
| 47 | * |
| 48 | * Return: status code |
| 49 | */ |
| 50 | efi_status_t efi_riscv_register(void) |
| 51 | { |
| 52 | efi_status_t ret = EFI_SUCCESS; |
| 53 | |
| 54 | ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol, |
| 55 | (void *)&riscv_efi_boot_prot); |
| 56 | if (ret != EFI_SUCCESS) |
| 57 | log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n"); |
| 58 | return ret; |
| 59 | } |