dm: add function to get VM-config information
This patch add function 'vm_get_config()' to get configuration information for current VM from hypervisor. Tracked-On: #5649 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Fei Li <fei1.li@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
4ac1205b29
commit
3005d074f0
|
@ -704,3 +704,48 @@ vm_irqfd(struct vmctx *ctx, struct acrn_irqfd *args)
|
|||
{
|
||||
return ioctl(ctx->fd, IC_EVENT_IRQFD, args);
|
||||
}
|
||||
|
||||
int
|
||||
vm_get_config(struct vmctx *ctx, struct acrn_vm_config *vm_cfg)
|
||||
{
|
||||
#define VM_CFG_BUFF_SIZE 0x4000
|
||||
int i, err = 0;
|
||||
uint8_t *configs_buff;
|
||||
struct acrn_vm_config *pcfg;
|
||||
struct platform_info platform_info;
|
||||
|
||||
if ((ctx == NULL) || (vm_cfg == NULL))
|
||||
return -1;
|
||||
|
||||
configs_buff = calloc(1, VM_CFG_BUFF_SIZE);
|
||||
if (configs_buff == NULL) {
|
||||
pr_err("%s, Allocate memory fail.\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bzero(&platform_info, sizeof(platform_info));
|
||||
platform_info.vm_configs_addr = (uint64_t)configs_buff;
|
||||
err = ioctl(ctx->fd, IC_GET_PLATFORM_INFO, &platform_info);
|
||||
if (err) {
|
||||
pr_err("%s, failed: get platform info.\n", __func__);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < platform_info.max_vms; i++) {
|
||||
pcfg = (struct acrn_vm_config *)(configs_buff + (i * platform_info.vm_config_entry_size));
|
||||
if (!uuid_compare(ctx->vm_uuid, pcfg->uuid))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == platform_info.max_vms) {
|
||||
pr_err("%s, Not found target VM.\n", __func__);
|
||||
err = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
memcpy((void *)vm_cfg, (void *)pcfg, sizeof(struct acrn_vm_config));
|
||||
|
||||
exit:
|
||||
free(configs_buff);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -292,6 +292,29 @@ struct api_version {
|
|||
uint32_t minor_version;
|
||||
};
|
||||
|
||||
enum acrn_vm_load_order {
|
||||
PRE_LAUNCHED_VM = 0,
|
||||
SOS_VM,
|
||||
POST_LAUNCHED_VM,
|
||||
MAX_LOAD_ORDER
|
||||
};
|
||||
|
||||
#define MAX_VM_OS_NAME_LEN 32U
|
||||
|
||||
struct acrn_vm_config {
|
||||
enum acrn_vm_load_order load_order;
|
||||
char name[MAX_VM_OS_NAME_LEN];
|
||||
const uint8_t uuid[16];
|
||||
uint8_t reserved[2];
|
||||
uint8_t severity;
|
||||
uint64_t cpu_affinity;
|
||||
uint64_t guest_flags;
|
||||
/*
|
||||
* The following are hv-specific members and are thus opaque.
|
||||
* vm_config_entry_size determines the real size of this structure.
|
||||
*/
|
||||
} __aligned(8);
|
||||
|
||||
/**
|
||||
* @brief data structure to track VHM platform information
|
||||
*/
|
||||
|
@ -300,15 +323,43 @@ struct platform_info {
|
|||
/** Physical CPU number */
|
||||
uint16_t cpu_num;
|
||||
|
||||
/** version of this structure */
|
||||
uint16_t version;
|
||||
|
||||
/** Align the size of version & hardware info to 128Bytes. */
|
||||
uint8_t reserved0[126];
|
||||
uint8_t reserved0[124];
|
||||
|
||||
/** Configuration Information */
|
||||
/** Maximum vCPU number for one VM. */
|
||||
uint16_t max_vcpus_per_vm;
|
||||
|
||||
/** Maximum Kata container number in SOS VM */
|
||||
uint8_t max_kata_containers;
|
||||
|
||||
uint8_t reserved1[7];
|
||||
|
||||
/** Number of configured VMs */
|
||||
uint16_t max_vms;
|
||||
|
||||
/**
|
||||
* The size of acrn_vm_config is various on different platforms.
|
||||
* This is the size of this struct which is used by the caller
|
||||
* to parse the vm_configs array.
|
||||
*/
|
||||
uint32_t vm_config_entry_size;
|
||||
|
||||
/**
|
||||
* Address to an array of struct acrn_vm_config, containing all
|
||||
* the configurations of all VMs. VHM treats it as an opague data
|
||||
* structure.
|
||||
*
|
||||
* The size of one array element is vm_config_entry_size while
|
||||
* the number of elements is max_vms.
|
||||
*/
|
||||
uint64_t vm_configs_addr;
|
||||
|
||||
/** Align the size of Configuration info to 128Bytes. */
|
||||
uint8_t reserved1[126];
|
||||
uint8_t reserved2[104];
|
||||
} __aligned(8);
|
||||
|
||||
struct acrn_ioeventfd {
|
||||
|
|
|
@ -150,4 +150,5 @@ void vm_reset_watchdog(struct vmctx *ctx);
|
|||
|
||||
int vm_ioeventfd(struct vmctx *ctx, struct acrn_ioeventfd *args);
|
||||
int vm_irqfd(struct vmctx *ctx, struct acrn_irqfd *args);
|
||||
int vm_get_config(struct vmctx *ctx, struct acrn_vm_config *vm_cfg);
|
||||
#endif /* _VMMAPI_H_ */
|
||||
|
|
Loading…
Reference in New Issue