summaryrefslogtreecommitdiff
path: root/MdePkg/Include/Library/BaseRiscVSbiLib.h
blob: c2aa9b9cae0371fca1c5d971da5a0615126958b0 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/** @file
  Library to call the RISC-V SBI ecalls

  Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights reserved.<BR>
  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Glossary:
    - Hart - Hardware Thread, similar to a CPU core

  Currently, EDK2 needs to call SBI only to set the time and to do system reset.

**/

#pragma once

#include <Uefi.h>

/* SBI Extension IDs */
#define SBI_EXT_0_1_CONSOLE_PUTCHAR  0x1
#define SBI_EXT_0_1_CONSOLE_GETCHAR  0x2
#define SBI_EXT_BASE                 0x10
#define SBI_EXT_DBCN                 0x4442434E
#define SBI_EXT_MPXY                 0x4D505859
#define SBI_EXT_SRST                 0x53525354
#define SBI_EXT_TIME                 0x54494D45

/* SBI function IDs for base extension */
#define SBI_EXT_BASE_SPEC_VERSION   0x0
#define SBI_EXT_BASE_IMPL_ID        0x1
#define SBI_EXT_BASE_IMPL_VERSION   0x2
#define SBI_EXT_BASE_PROBE_EXT      0x3
#define SBI_EXT_BASE_GET_MVENDORID  0x4
#define SBI_EXT_BASE_GET_MARCHID    0x5
#define SBI_EXT_BASE_GET_MIMPID     0x6

/* SBI function IDs for DBCN extension */
#define SBI_EXT_DBCN_WRITE       0x0
#define SBI_EXT_DBCN_READ        0x1
#define SBI_EXT_DBCN_WRITE_BYTE  0x2

/* SBI function IDs for TIME extension */
#define SBI_EXT_TIME_SET_TIMER  0x0

/* SBI function IDs for SRST extension */
#define SBI_EXT_SRST_RESET  0x0

/* SBI function IDs. for MPXY extension */
#define SBI_EXT_MPXY_GET_SHMEM_SIZE           0x0
#define SBI_EXT_MPXY_SET_SHMEM                0x1
#define SBI_EXT_MPXY_GET_CHANNEL_IDS          0x2
#define SBI_EXT_MPXY_READ_ATTRS               0x3
#define SBI_EXT_MPXY_WRITE_ATTRS              0x4
#define SBI_EXT_MPXY_SEND_MSG_WITH_RESP       0x5
#define SBI_EXT_MPXY_SEND_MSG_NO_RESP         0x6
#define SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS  0x7

/* SBI flags for MPXY Set Shared Memory operation */
#define SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE         0x0
#define SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN  0x1

#define SBI_SRST_RESET_TYPE_SHUTDOWN     0x0
#define SBI_SRST_RESET_TYPE_COLD_REBOOT  0x1
#define SBI_SRST_RESET_TYPE_WARM_REBOOT  0x2

#define SBI_SRST_RESET_REASON_NONE     0x0
#define SBI_SRST_RESET_REASON_SYSFAIL  0x1

/* SBI return error codes */
#define SBI_SUCCESS                0
#define SBI_ERR_FAILED             -1
#define SBI_ERR_NOT_SUPPORTED      -2
#define SBI_ERR_INVALID_PARAM      -3
#define SBI_ERR_DENIED             -4
#define SBI_ERR_INVALID_ADDRESS    -5
#define SBI_ERR_ALREADY_AVAILABLE  -6
#define SBI_ERR_ALREADY_STARTED    -7
#define SBI_ERR_ALREADY_STOPPED    -8
#define SBI_ERR_NO_SHMEM           -9
#define SBI_ERR_INVALID_STATE      -10
#define SBI_ERR_BAD_RANGE          -11
#define SBI_ERR_NOT_IMPLEMENTED    -12
#define SBI_ERR_TIMEOUT            -13
#define SBI_ERR_IO                 -14

//
// EDK2 OpenSBI firmware extension return status.
//
typedef struct {
  UINTN    Error; ///< SBI status code
  UINTN    Value; ///< Value returned
} SBI_RET;

SBI_RET
EFIAPI
SbiCall (
  IN  UINTN  ExtId,
  IN  UINTN  FuncId,
  IN  UINTN  NumArgs,
  ...
  );

EFI_STATUS
EFIAPI
TranslateError (
  IN  UINTN  SbiError
  );

VOID
EFIAPI
SbiSetTimer (
  IN  UINT64  Time
  );

EFI_STATUS
EFIAPI
SbiSystemReset (
  IN  UINTN  ResetType,
  IN  UINTN  ResetReason
  );

/**
  Make ECALL in assembly

  Switch to M-mode

  @param[in,out]   Arg0
  @param[in,out]   Arg1
  @param[in]       Arg2
  @param[in]       Arg3
  @param[in]       Arg4
  @param[in]       Arg5
  @param[in]       FID
  @param[in]       EXT
**/
VOID
EFIAPI
RiscVSbiEcall (
  IN OUT UINTN  *Arg0,
  IN OUT UINTN  *Arg1,
  IN UINTN      Arg2,
  IN UINTN      Arg3,
  IN UINTN      Arg4,
  IN UINTN      Arg5,
  IN UINTN      Fid,
  IN UINTN      Ext
  );

EFI_STATUS
EFIAPI
SbiProbeExtension (
  IN UINTN  Extension
  );