coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
sbi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <mcall.h>
4 #include <stdint.h>
5 #include <arch/exception.h>
6 #include <sbi.h>
7 #include <vm.h>
8 #include <console/uart.h>
9 #include <commonlib/helpers.h>
10 
12 {
13  uintptr_t mask = mprv_read_uintptr_t(pmask);
14  for (int i = 0; mask; i++) {
15  if (mask & 1) {
16  OTHER_HLS(i)->ipi_pending |= type;
17  /* send soft interrupt to target hart */
18  set_msip(i, 1);
19  }
20  mask = mask >> 1;
21  }
22  return 0;
23 }
24 
26 {
27  clear_csr(mip, MIP_STIP);
28  set_csr(mie, MIP_MTIP);
29  *(HLS()->timecmp) = when;
30  return 0;
31 }
32 
33 #if CONFIG(CONSOLE_SERIAL)
34 static uintptr_t sbi_console_putchar(uint8_t ch)
35 {
36  uart_tx_byte(CONFIG_UART_FOR_CONSOLE, ch);
37  return 0;
38 }
39 
40 static uintptr_t sbi_console_getchar(void)
41 {
42  return uart_rx_byte(CONFIG_UART_FOR_CONSOLE);
43 }
44 #endif
45 
47 {
48  clear_csr(mip, MIP_SSIP);
49  return 0;
50 }
51 
52 /*
53  * sbi is triggered by the s-mode ecall
54  * parameter : register a0 a1 a2
55  * function : register a7
56  * return : register a0
57  */
59 {
60  uintptr_t ret = 0;
61  uintptr_t arg0 = tf->gpr[10];
62  __unused uintptr_t arg1 = tf->gpr[11];
63  uintptr_t which = tf->gpr[17];
64 
65  switch (which) {
66  case SBI_SET_TIMER:
67 #if __riscv_xlen == 32
68  ret = sbi_set_timer(arg0 + ((uint64_t)arg1 << 32));
69 #else
70  ret = sbi_set_timer(arg0);
71 #endif
72  break;
73 #if CONFIG(CONSOLE_SERIAL)
75  ret = sbi_console_putchar(arg0);
76  break;
78  ret = sbi_console_getchar();
79  break;
80 #endif
81  case SBI_CLEAR_IPI:
82  ret = sbi_clear_ipi();
83  break;
84  case SBI_SEND_IPI:
85  ret = send_ipi((uintptr_t *)arg0, IPI_SOFT);
86  break;
87  case SBI_REMOTE_FENCE_I:
89  break;
92  break;
95  break;
96  case SBI_SHUTDOWN:
98  break;
99  default:
100  ret = -SBI_ENOSYS;
101  break;
102  }
103  tf->gpr[10] = ret;
104  write_csr(mepc, read_csr(mepc) + 4);
105 }
uint32_t arg0
Definition: fch.c:75
#define MIP_SSIP
Definition: encoding.h:98
#define MIP_STIP
Definition: encoding.h:101
#define MIP_MTIP
Definition: encoding.h:103
#define __unused
Definition: helpers.h:38
unsigned int type
Definition: edid.c:57
void set_msip(int hartid, int val)
Definition: clint.c:15
#define OTHER_HLS(id)
Definition: mcall.h:64
#define HLS()
Definition: mcall.h:63
static struct dramc_channel const ch[2]
unsigned char uart_rx_byte(unsigned int idx)
Definition: pl011.c:29
void uart_tx_byte(unsigned int idx, unsigned char data)
Definition: pl011.c:12
static uintptr_t send_ipi(uintptr_t *pmask, intptr_t type)
Definition: sbi.c:11
void handle_sbi(trapframe *tf)
Definition: sbi.c:58
static uintptr_t sbi_clear_ipi(void)
Definition: sbi.c:46
static uintptr_t sbi_set_timer(uint64_t when)
Definition: sbi.c:25
#define SBI_SEND_IPI
Definition: sbi.h:10
#define IPI_SHUTDOWN
Definition: sbi.h:22
#define IPI_SFENCE_VMA
Definition: sbi.h:20
#define IPI_SOFT
Definition: sbi.h:18
#define SBI_CONSOLE_PUTCHAR
Definition: sbi.h:7
#define SBI_CLEAR_IPI
Definition: sbi.h:9
#define SBI_SET_TIMER
Definition: sbi.h:6
#define SBI_REMOTE_SFENCE_VMA_ASID
Definition: sbi.h:13
#define IPI_FENCE_I
Definition: sbi.h:19
#define SBI_ENOSYS
Definition: sbi.h:16
#define IPI_SFENCE_VMA_ASID
Definition: sbi.h:21
#define SBI_SHUTDOWN
Definition: sbi.h:14
#define SBI_REMOTE_FENCE_I
Definition: sbi.h:11
#define SBI_REMOTE_SFENCE_VMA
Definition: sbi.h:12
#define SBI_CONSOLE_GETCHAR
Definition: sbi.h:8
static const int mask[4]
Definition: gpio.c:308
signed long intptr_t
Definition: stdint.h:20
unsigned long uintptr_t
Definition: stdint.h:21
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uintptr_t gpr[32]
Definition: exception.h:9