blob: 4d398c5be34834f4748396acb766415c84e16383 [file] [log] [blame]
Sunil V L1ccf8712022-01-28 20:48:44 +05301// 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 L1ccf8712022-01-28 20:48:44 +053010#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
16DECLARE_GLOBAL_DATA_PTR;
17
18static 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 */
26static efi_status_t EFIAPI
27efi_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 Schuchardt85145662023-01-11 19:08:01 +010033 return EFI_EXIT(EFI_INVALID_PARAMETER);
Sunil V L1ccf8712022-01-28 20:48:44 +053034
35 *boot_hartid = gd->arch.boot_hart;
36
37 return EFI_EXIT(EFI_SUCCESS);
38}
39
40struct 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 */
50efi_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}