xref: /openbmc/qemu/include/hw/char/riscv_htif.h (revision 79f26b3b)
1 /*
2  * QEMU RISCV Host Target Interface (HTIF) Emulation
3  *
4  * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5  * Copyright (c) 2017-2018 SiFive, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2 or later, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef HW_RISCV_HTIF_H
21 #define HW_RISCV_HTIF_H
22 
23 #include "chardev/char.h"
24 #include "chardev/char-fe.h"
25 #include "exec/memory.h"
26 #include "target/riscv/cpu.h"
27 
28 #define TYPE_HTIF_UART "riscv.htif.uart"
29 
30 typedef struct HTIFState {
31     int allow_tohost;
32     int fromhost_inprogress;
33 
34     hwaddr tohost_offset;
35     hwaddr fromhost_offset;
36     uint64_t tohost_size;
37     uint64_t fromhost_size;
38     MemoryRegion mmio;
39     MemoryRegion *address_space;
40     MemoryRegion *main_mem;
41     void *main_mem_ram_ptr;
42 
43     CPURISCVState *env;
44     CharBackend chr;
45     uint64_t pending_read;
46 } HTIFState;
47 
48 extern const VMStateDescription vmstate_htif;
49 extern const MemoryRegionOps htif_io_ops;
50 
51 /* HTIF symbol callback */
52 void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
53     uint64_t st_size);
54 
55 /* Check if HTIF uses ELF symbols */
56 bool htif_uses_elf_symbols(void);
57 
58 /* legacy pre qom */
59 HTIFState *htif_mm_init(MemoryRegion *address_space, MemoryRegion *main_mem,
60     CPURISCVState *env, Chardev *chr, uint64_t nonelf_base);
61 
62 #endif
63