2018-03-07 21:01:19 +08:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2011 NetApp, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _VMMAPI_H_
|
|
|
|
#define _VMMAPI_H_
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include "types.h"
|
2019-07-12 06:53:03 +08:00
|
|
|
#include "macros.h"
|
2021-04-07 18:20:09 +08:00
|
|
|
#include "pm.h"
|
2021-07-07 10:15:07 +08:00
|
|
|
#include "hsm_ioctl_defs.h"
|
2018-03-07 21:01:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* API version for out-of-tree consumers for making compile time decisions.
|
|
|
|
*/
|
|
|
|
#define VMMAPI_VERSION 0103 /* 2 digit major followed by 2 digit minor */
|
|
|
|
|
2018-03-14 22:03:52 +08:00
|
|
|
#define ALIGN_UP(x, align) (((x) + ((align)-1)) & ~((align)-1))
|
|
|
|
#define ALIGN_DOWN(x, align) ((x) & ~((align)-1))
|
|
|
|
|
2018-08-03 15:29:18 +08:00
|
|
|
#define CMOS_BUF_SIZE 256
|
|
|
|
|
2018-03-07 21:01:19 +08:00
|
|
|
struct vmctx {
|
|
|
|
int fd;
|
|
|
|
int vmid;
|
|
|
|
int ioreq_client;
|
|
|
|
uint32_t lowmem_limit;
|
2019-02-25 16:28:14 +08:00
|
|
|
uint64_t highmem_gpa_base;
|
2018-03-07 21:01:19 +08:00
|
|
|
size_t lowmem;
|
2022-02-25 23:04:58 +08:00
|
|
|
size_t fbmem;
|
2018-12-12 17:39:42 +08:00
|
|
|
size_t biosmem;
|
2018-03-07 21:01:19 +08:00
|
|
|
size_t highmem;
|
|
|
|
char *baseaddr;
|
|
|
|
char *name;
|
2018-03-30 15:06:27 +08:00
|
|
|
|
|
|
|
/* fields to track virtual devices */
|
2018-04-20 17:54:07 +08:00
|
|
|
void *atkbdc_base;
|
|
|
|
void *vrtc;
|
2018-09-28 04:51:55 +08:00
|
|
|
void *vpit;
|
2018-04-20 18:04:07 +08:00
|
|
|
void *ioc_dev;
|
2018-08-14 10:02:52 +08:00
|
|
|
void *tpm_dev;
|
2022-02-25 23:04:58 +08:00
|
|
|
void *fb_base;
|
2018-09-26 11:13:33 +08:00
|
|
|
|
|
|
|
/* BSP state. guest loader needs to fill it */
|
2021-07-07 14:02:31 +08:00
|
|
|
struct acrn_vcpu_regs bsp_regs;
|
2019-11-13 03:18:50 +08:00
|
|
|
|
|
|
|
/* if gvt-g is enabled for current VM */
|
|
|
|
bool gvt_enabled;
|
2019-11-13 05:19:39 +08:00
|
|
|
|
|
|
|
void (*update_gvt_bar)(struct vmctx *ctx);
|
2018-03-07 21:01:19 +08:00
|
|
|
};
|
|
|
|
|
2018-01-30 22:58:40 +08:00
|
|
|
#define PROT_RW (PROT_READ | PROT_WRITE)
|
|
|
|
#define PROT_ALL (PROT_READ | PROT_WRITE | PROT_EXEC)
|
|
|
|
|
2018-03-07 21:01:19 +08:00
|
|
|
struct vm_lapic_msi {
|
|
|
|
uint64_t msg;
|
|
|
|
uint64_t addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vm_isa_irq {
|
|
|
|
int atpic_irq;
|
|
|
|
int ioapic_irq;
|
|
|
|
};
|
|
|
|
|
2022-04-01 10:56:47 +08:00
|
|
|
struct vm_mem_region {
|
|
|
|
uint64_t fd_offset;
|
|
|
|
int fd;
|
|
|
|
};
|
|
|
|
bool vm_find_memfd_region(struct vmctx *ctx, vm_paddr_t gpa,
|
|
|
|
struct vm_mem_region *ret_region);
|
2022-04-01 10:56:47 +08:00
|
|
|
bool vm_allow_dmabuf(struct vmctx *ctx);
|
2018-03-07 21:01:19 +08:00
|
|
|
/*
|
|
|
|
* Create a device memory segment identified by 'segid'.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the memory segment on success and MAP_FAILED otherwise.
|
|
|
|
*/
|
2019-05-21 16:13:40 +08:00
|
|
|
struct vmctx *vm_create(const char *name, uint64_t req_buf, int* vcpu_num);
|
2018-03-07 21:01:19 +08:00
|
|
|
void vm_pause(struct vmctx *ctx);
|
2018-07-16 16:15:58 +08:00
|
|
|
void vm_reset(struct vmctx *ctx);
|
2018-03-07 21:01:19 +08:00
|
|
|
int vm_create_ioreq_client(struct vmctx *ctx);
|
|
|
|
int vm_destroy_ioreq_client(struct vmctx *ctx);
|
|
|
|
int vm_attach_ioreq_client(struct vmctx *ctx);
|
|
|
|
int vm_notify_request_done(struct vmctx *ctx, int vcpu);
|
2022-11-24 13:28:23 +08:00
|
|
|
int vm_setup_asyncio(struct vmctx *ctx, uint64_t base);
|
2018-10-15 10:24:44 +08:00
|
|
|
void vm_clear_ioreq(struct vmctx *ctx);
|
2020-05-12 11:04:44 +08:00
|
|
|
const char *vm_state_to_str(enum vm_suspend_how idx);
|
2018-03-07 21:01:19 +08:00
|
|
|
void vm_set_suspend_mode(enum vm_suspend_how how);
|
2019-04-16 10:59:25 +08:00
|
|
|
#ifdef DM_DEBUG
|
2019-01-28 16:09:01 +08:00
|
|
|
void notify_vmloop_thread(void);
|
2019-04-16 10:59:25 +08:00
|
|
|
#endif
|
2018-03-07 21:01:19 +08:00
|
|
|
int vm_get_suspend_mode(void);
|
|
|
|
void vm_destroy(struct vmctx *ctx);
|
|
|
|
int vm_parse_memsize(const char *optarg, size_t *memsize);
|
2018-01-30 22:58:40 +08:00
|
|
|
int vm_map_memseg_vma(struct vmctx *ctx, size_t len, vm_paddr_t gpa,
|
|
|
|
uint64_t vma, int prot);
|
2018-06-29 11:01:17 +08:00
|
|
|
int vm_setup_memory(struct vmctx *ctx, size_t len);
|
2018-03-07 21:01:19 +08:00
|
|
|
void vm_unsetup_memory(struct vmctx *ctx);
|
2019-06-04 17:20:26 +08:00
|
|
|
bool init_hugetlb(void);
|
|
|
|
void uninit_hugetlb(void);
|
2018-03-14 22:03:52 +08:00
|
|
|
int hugetlb_setup_memory(struct vmctx *ctx);
|
|
|
|
void hugetlb_unsetup_memory(struct vmctx *ctx);
|
2018-03-07 21:01:19 +08:00
|
|
|
void *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len);
|
|
|
|
uint32_t vm_get_lowmem_limit(struct vmctx *ctx);
|
|
|
|
size_t vm_get_lowmem_size(struct vmctx *ctx);
|
|
|
|
size_t vm_get_highmem_size(struct vmctx *ctx);
|
|
|
|
int vm_run(struct vmctx *ctx);
|
|
|
|
int vm_suspend(struct vmctx *ctx, enum vm_suspend_how how);
|
|
|
|
int vm_lapic_msi(struct vmctx *ctx, uint64_t addr, uint64_t msg);
|
2018-09-27 17:34:25 +08:00
|
|
|
int vm_set_gsi_irq(struct vmctx *ctx, int gsi, uint32_t operation);
|
2021-07-07 16:34:22 +08:00
|
|
|
int vm_assign_pcidev(struct vmctx *ctx, struct acrn_pcidev *pcidev);
|
|
|
|
int vm_deassign_pcidev(struct vmctx *ctx, struct acrn_pcidev *pcidev);
|
2020-07-16 13:56:21 +08:00
|
|
|
int vm_assign_mmiodev(struct vmctx *ctx, struct acrn_mmiodev *mmiodev);
|
|
|
|
int vm_deassign_mmiodev(struct vmctx *ctx, struct acrn_mmiodev *mmiodev);
|
2018-03-07 21:01:19 +08:00
|
|
|
int vm_map_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
|
|
|
|
vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
|
2018-08-29 14:42:35 +08:00
|
|
|
int vm_unmap_ptdev_mmio(struct vmctx *ctx, int bus, int slot, int func,
|
|
|
|
vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
|
2018-03-07 21:01:19 +08:00
|
|
|
int vm_set_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf,
|
|
|
|
uint16_t phys_bdf, int virt_pin, int phys_pin, bool pic_pin);
|
2019-04-29 13:33:18 +08:00
|
|
|
int vm_reset_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf,
|
|
|
|
uint16_t phys_bdf, int virt_pin, bool pic_pin);
|
2021-07-07 17:23:40 +08:00
|
|
|
int vm_add_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev);
|
|
|
|
int vm_remove_hv_vdev(struct vmctx *ctx, struct acrn_vdev *dev);
|
2018-03-07 21:01:19 +08:00
|
|
|
|
2020-04-24 04:58:18 +08:00
|
|
|
int acrn_parse_cpu_affinity(char *arg);
|
2021-01-26 15:16:25 +08:00
|
|
|
uint64_t vm_get_cpu_affinity_dm(void);
|
2021-07-07 14:02:31 +08:00
|
|
|
int vm_set_vcpu_regs(struct vmctx *ctx, struct acrn_vcpu_regs *cpu_regs);
|
2018-04-05 04:35:04 +08:00
|
|
|
|
|
|
|
int vm_get_cpu_state(struct vmctx *ctx, void *state_buf);
|
2018-08-14 14:06:24 +08:00
|
|
|
int vm_intr_monitor(struct vmctx *ctx, void *intr_buf);
|
2018-07-24 18:07:37 +08:00
|
|
|
void vm_stop_watchdog(struct vmctx *ctx);
|
|
|
|
void vm_reset_watchdog(struct vmctx *ctx);
|
2018-07-13 15:47:18 +08:00
|
|
|
|
|
|
|
int vm_ioeventfd(struct vmctx *ctx, struct acrn_ioeventfd *args);
|
|
|
|
int vm_irqfd(struct vmctx *ctx, struct acrn_irqfd *args);
|
2022-02-09 14:09:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a string describing the meaning of the `error' code.
|
|
|
|
*/
|
|
|
|
char* errormsg(int error);
|
|
|
|
|
2018-03-07 21:01:19 +08:00
|
|
|
#endif /* _VMMAPI_H_ */
|