~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 064172755b95018a5b49af3e2211462348a3cab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: GPL-2.0+
/*
 * Defines APIs that allow an OS to interact with UEFI firmware to query
 * information about the boot hart ID.
 *
 * Copyright (c) 2022, Ventana Micro Systems Inc
 */

#define LOG_CATEGORY LOGC_EFI
#include <common.h>
#include <efi_loader.h>
#include <efi_variable.h>
#include <log.h>
#include <asm/global_data.h>
#include <efi_riscv.h>

DECLARE_GLOBAL_DATA_PTR;

static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID;

/**
 * efi_riscv_get_boot_hartid() - return boot hart ID
 * @this:		RISCV_EFI_BOOT_PROTOCOL instance
 * @boot_hartid:	caller allocated memory to return boot hart id
 * Return:		status code
 */
static efi_status_t EFIAPI
efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this,
			  efi_uintn_t *boot_hartid)
{
	EFI_ENTRY("%p, %p",  this, boot_hartid);

	if (this != &riscv_efi_boot_prot || !boot_hartid)
		return EFI_EXIT(EFI_INVALID_PARAMETER);

	*boot_hartid = gd->arch.boot_hart;

	return EFI_EXIT(EFI_SUCCESS);
}

struct riscv_efi_boot_protocol riscv_efi_boot_prot = {
	.revision = RISCV_EFI_BOOT_PROTOCOL_REVISION,
	.get_boot_hartid = efi_riscv_get_boot_hartid
};

/**
 * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL
 *
 * Return:	status code
 */
efi_status_t efi_riscv_register(void)
{
	efi_status_t ret = EFI_SUCCESS;

	ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol,
			       (void *)&riscv_efi_boot_prot);
	if (ret != EFI_SUCCESS)
		log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n");
	return ret;
}