2021-05-01 10:05:21 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#ifndef HV_H
|
|
|
|
#define HV_H
|
|
|
|
|
2021-09-21 12:09:23 +00:00
|
|
|
#include "exception.h"
|
2021-05-14 20:47:43 +00:00
|
|
|
#include "iodev.h"
|
2021-05-01 10:05:21 +00:00
|
|
|
#include "types.h"
|
2021-05-15 14:55:34 +00:00
|
|
|
#include "uartproxy.h"
|
2021-05-01 10:05:21 +00:00
|
|
|
|
2021-09-21 12:10:44 +00:00
|
|
|
typedef bool(hv_hook_t)(struct exc_info *ctx, u64 addr, u64 *val, bool write, int width);
|
2021-05-04 18:29:11 +00:00
|
|
|
|
2022-10-12 12:03:50 +00:00
|
|
|
#define MMIO_EVT_ATTR GENMASK(31, 24)
|
2021-09-15 14:22:42 +00:00
|
|
|
#define MMIO_EVT_CPU GENMASK(23, 16)
|
2022-10-12 12:03:50 +00:00
|
|
|
#define MMIO_EVT_SH GENMASK(15, 14)
|
2021-05-27 12:17:01 +00:00
|
|
|
#define MMIO_EVT_MULTI BIT(6)
|
2021-09-15 14:22:42 +00:00
|
|
|
#define MMIO_EVT_WRITE BIT(5)
|
|
|
|
#define MMIO_EVT_WIDTH GENMASK(4, 0)
|
2021-05-15 13:03:29 +00:00
|
|
|
|
|
|
|
struct hv_evt_mmiotrace {
|
|
|
|
u32 flags;
|
|
|
|
u32 reserved;
|
|
|
|
u64 pc;
|
|
|
|
u64 addr;
|
|
|
|
u64 data;
|
|
|
|
};
|
|
|
|
|
2021-06-05 20:05:17 +00:00
|
|
|
struct hv_evt_irqtrace {
|
|
|
|
u32 flags;
|
|
|
|
u16 type;
|
|
|
|
u16 num;
|
|
|
|
};
|
|
|
|
|
2022-04-16 10:01:54 +00:00
|
|
|
#define HV_MAX_RW_SIZE 64
|
|
|
|
#define HV_MAX_RW_WORDS (HV_MAX_RW_SIZE >> 3)
|
|
|
|
|
2021-05-15 14:55:34 +00:00
|
|
|
struct hv_vm_proxy_hook_data {
|
|
|
|
u32 flags;
|
|
|
|
u32 id;
|
|
|
|
u64 addr;
|
2022-04-16 10:01:54 +00:00
|
|
|
u64 data[HV_MAX_RW_WORDS];
|
2021-05-15 14:55:34 +00:00
|
|
|
};
|
|
|
|
|
2021-05-25 10:53:41 +00:00
|
|
|
typedef enum _hv_entry_type {
|
2021-05-15 14:55:34 +00:00
|
|
|
HV_HOOK_VM = 1,
|
2021-05-25 11:04:20 +00:00
|
|
|
HV_VTIMER,
|
2021-05-25 11:07:02 +00:00
|
|
|
HV_USER_INTERRUPT,
|
2021-05-27 12:16:17 +00:00
|
|
|
HV_WDT_BARK,
|
2022-05-30 11:01:04 +00:00
|
|
|
HV_CPU_SWITCH,
|
2022-06-27 14:38:32 +00:00
|
|
|
HV_VIRTIO,
|
2023-06-02 11:19:48 +00:00
|
|
|
HV_PANIC,
|
2021-05-25 10:53:41 +00:00
|
|
|
} hv_entry_type;
|
2021-05-15 14:55:34 +00:00
|
|
|
|
2021-05-04 06:38:17 +00:00
|
|
|
/* VM */
|
|
|
|
void hv_pt_init(void);
|
2021-05-01 10:05:21 +00:00
|
|
|
int hv_map(u64 from, u64 to, u64 size, u64 incr);
|
|
|
|
int hv_unmap(u64 from, u64 size);
|
|
|
|
int hv_map_hw(u64 from, u64 to, u64 size);
|
|
|
|
int hv_map_sw(u64 from, u64 to, u64 size);
|
2021-05-04 18:29:11 +00:00
|
|
|
int hv_map_hook(u64 from, hv_hook_t *hook, u64 size);
|
2022-10-12 12:03:50 +00:00
|
|
|
u64 hv_translate(u64 addr, bool s1only, bool w, u64 *par_out);
|
2021-05-04 18:29:11 +00:00
|
|
|
u64 hv_pt_walk(u64 addr);
|
2021-09-21 12:09:23 +00:00
|
|
|
bool hv_handle_dabort(struct exc_info *ctx);
|
2021-09-21 12:10:44 +00:00
|
|
|
bool hv_pa_write(struct exc_info *ctx, u64 addr, u64 *val, int width);
|
|
|
|
bool hv_pa_read(struct exc_info *ctx, u64 addr, u64 *val, int width);
|
|
|
|
bool hv_pa_rw(struct exc_info *ctx, u64 addr, u64 *val, bool write, int width);
|
2021-06-05 20:05:17 +00:00
|
|
|
|
|
|
|
/* AIC events through tracing the MMIO event address */
|
|
|
|
bool hv_trace_irq(u32 type, u32 num, u32 count, u32 flags);
|
2021-05-04 06:38:17 +00:00
|
|
|
|
2021-05-04 18:30:07 +00:00
|
|
|
/* Virtual peripherals */
|
2021-08-23 08:02:28 +00:00
|
|
|
void hv_vuart_poll(void);
|
|
|
|
void hv_map_vuart(u64 base, int irq, iodev_id_t iodev);
|
2022-06-27 14:38:32 +00:00
|
|
|
struct virtio_conf;
|
|
|
|
void hv_map_virtio(u64 base, struct virtio_conf *conf);
|
|
|
|
void virtio_put_buffer(u64 base, int qu, u32 id, u32 len);
|
2021-05-04 18:30:07 +00:00
|
|
|
|
2021-05-15 14:55:34 +00:00
|
|
|
/* Exceptions */
|
2021-11-08 04:37:39 +00:00
|
|
|
void hv_exc_proxy(struct exc_info *ctx, uartproxy_boot_reason_t reason, u32 type, void *extra);
|
2022-08-17 05:01:49 +00:00
|
|
|
void hv_set_time_stealing(bool enabled, bool reset);
|
2023-04-25 15:45:31 +00:00
|
|
|
void hv_add_time(s64 time);
|
2021-05-15 14:55:34 +00:00
|
|
|
|
2021-05-27 12:16:17 +00:00
|
|
|
/* WDT */
|
|
|
|
void hv_wdt_pet(void);
|
|
|
|
void hv_wdt_suspend(void);
|
|
|
|
void hv_wdt_resume(void);
|
|
|
|
void hv_wdt_init(void);
|
2021-09-15 13:08:35 +00:00
|
|
|
void hv_wdt_start(int cpu);
|
2021-05-27 12:16:17 +00:00
|
|
|
void hv_wdt_stop(void);
|
|
|
|
void hv_wdt_breadcrumb(char c);
|
2023-06-02 11:19:48 +00:00
|
|
|
void hv_do_panic(void);
|
|
|
|
|
|
|
|
#define hv_panic(fmt, ...) \
|
|
|
|
do { \
|
|
|
|
debug_printf("HV panic:" fmt, ##__VA_ARGS__); \
|
|
|
|
hv_do_panic(); \
|
|
|
|
flush_and_reboot(); \
|
|
|
|
} while (0)
|
2021-05-27 12:16:17 +00:00
|
|
|
|
2021-05-27 12:11:49 +00:00
|
|
|
/* Utilities */
|
2021-05-25 11:05:10 +00:00
|
|
|
void hv_write_hcr(u64 val);
|
2021-05-27 12:11:49 +00:00
|
|
|
u64 hv_get_spsr(void);
|
|
|
|
void hv_set_spsr(u64 val);
|
|
|
|
u64 hv_get_esr(void);
|
|
|
|
u64 hv_get_far(void);
|
|
|
|
u64 hv_get_elr(void);
|
2021-05-29 18:29:52 +00:00
|
|
|
u64 hv_get_afsr1(void);
|
2021-05-27 12:11:49 +00:00
|
|
|
void hv_set_elr(u64 val);
|
2021-05-25 11:05:10 +00:00
|
|
|
|
2021-05-04 06:38:17 +00:00
|
|
|
/* HV main */
|
|
|
|
void hv_init(void);
|
2021-05-01 10:05:21 +00:00
|
|
|
void hv_start(void *entry, u64 regs[4]);
|
2021-09-15 14:31:33 +00:00
|
|
|
void hv_start_secondary(int cpu, void *entry, u64 regs[4]);
|
2023-04-18 16:00:59 +00:00
|
|
|
void hv_exit_cpu(int cpu);
|
2021-09-21 04:17:00 +00:00
|
|
|
void hv_rendezvous(void);
|
2022-05-30 11:01:04 +00:00
|
|
|
bool hv_switch_cpu(int cpu);
|
2022-04-18 03:08:02 +00:00
|
|
|
void hv_pin_cpu(int cpu);
|
2023-04-18 14:37:18 +00:00
|
|
|
void hv_arm_tick(bool secondary);
|
2021-09-21 04:18:06 +00:00
|
|
|
void hv_rearm(void);
|
2022-04-19 15:16:00 +00:00
|
|
|
void hv_maybe_exit(void);
|
2021-09-21 12:09:23 +00:00
|
|
|
void hv_tick(struct exc_info *ctx);
|
2021-05-01 10:05:21 +00:00
|
|
|
|
|
|
|
#endif
|