diff --git a/core/vmmapi.c b/core/vmmapi.c index 8fdae6c30..ffc3dc750 100644 --- a/core/vmmapi.c +++ b/core/vmmapi.c @@ -720,3 +720,9 @@ vm_get_device_fd(struct vmctx *ctx) { return ctx->fd; } + +int +vm_get_cpu_state(struct vmctx *ctx, void *state_buf) +{ + return ioctl(ctx->fd, IC_PM_GET_CPU_STATE, state_buf); +} diff --git a/include/public/acrn_common.h b/include/public/acrn_common.h index 1fbfd3ded..0993641e3 100644 --- a/include/public/acrn_common.h +++ b/include/public/acrn_common.h @@ -302,6 +302,39 @@ struct acrn_vm_pci_msix_remap { */ #define GUEST_CFG_OFFSET 0xd0000 +/** + * @brief Info The power state data of a VCPU. + * + */ +struct cpu_px_data { + uint64_t core_frequency; /* megahertz */ + uint64_t power; /* milliWatts */ + uint64_t transition_latency; /* microseconds */ + uint64_t bus_master_latency; /* microseconds */ + uint64_t control; /* control value */ + uint64_t status; /* success indicator */ +} __attribute__((aligned(8))); + +/** + * @brief Info PM command from DM/VHM. + * + * The command would specify request type(i.e. get px count or data) for + * specific VM and specific VCPU with specific state number.like P(n). + */ +#define PMCMD_VMID_MASK 0xff000000 +#define PMCMD_VCPUID_MASK 0x00ff0000 +#define PMCMD_STATE_NUM_MASK 0x0000ff00 +#define PMCMD_TYPE_MASK 0x000000ff + +#define PMCMD_VMID_SHIFT 24 +#define PMCMD_VCPUID_SHIFT 16 +#define PMCMD_STATE_NUM_SHIFT 8 + +enum pm_cmd_type { + PMCMD_GET_PX_CNT, + PMCMD_GET_PX_DATA, +}; + /** * @} */ diff --git a/include/public/vhm_ioctl_defs.h b/include/public/vhm_ioctl_defs.h index 5bc7c666f..069b732b9 100644 --- a/include/public/vhm_ioctl_defs.h +++ b/include/public/vhm_ioctl_defs.h @@ -101,6 +101,10 @@ #define IC_SET_PTDEV_INTR_INFO _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x03) #define IC_RESET_PTDEV_INTR_INFO _IC_ID(IC_ID, IC_ID_PCI_BASE + 0x04) +/* Power management */ +#define IC_ID_PM_BASE 0x60UL +#define IC_PM_GET_CPU_STATE _IC_ID(IC_ID, IC_ID_PM_BASE + 0x00) + /** * struct vm_memseg - memory segment info for guest * diff --git a/include/vmmapi.h b/include/vmmapi.h index 06aef07c2..3ce62261a 100644 --- a/include/vmmapi.h +++ b/include/vmmapi.h @@ -147,4 +147,7 @@ int vm_set_ptdev_intx_info(struct vmctx *ctx, uint16_t virt_bdf, int vm_reset_ptdev_intx_info(struct vmctx *ctx, int virt_pin, bool pic_pin); int vm_create_vcpu(struct vmctx *ctx, int vcpu_id); + +int vm_get_cpu_state(struct vmctx *ctx, void *state_buf); + #endif /* _VMMAPI_H_ */