1// See LICENSE for license details.
2
3#ifndef _RISCV_HTIF_H
4#define _RISCV_HTIF_H
5
6#include <stdint.h>
7
8#if __riscv_xlen == 64
9# define TOHOST_CMD(dev, cmd, payload) \
10  (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
11#else
12# define TOHOST_CMD(dev, cmd, payload) ({ \
13  if ((dev) || (cmd)) __builtin_trap(); \
14  (payload); })
15#endif
16#define FROMHOST_DEV(fromhost_value) ((uint64_t)(fromhost_value) >> 56)
17#define FROMHOST_CMD(fromhost_value) ((uint64_t)(fromhost_value) << 8 >> 56)
18#define FROMHOST_DATA(fromhost_value) ((uint64_t)(fromhost_value) << 16 >> 16)
19
20extern uintptr_t htif;
21void query_htif(uintptr_t dtb);
22void htif_console_putchar(uint8_t);
23int htif_console_getchar();
24void htif_poweroff() __attribute__((noreturn));
25void htif_syscall(uintptr_t);
26
27#endif
28