From ea662e6d49fd4edb0a3a76a5512fa0bc820e0a43 Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Thu, 5 Apr 2018 04:49:56 +0800 Subject: [PATCH] DM: add function of get px count and data The px count and data is per-cpu so we should query them for specific vm and specific vcpu, for px data we need to specify px num also. Signed-off-by: Victor Sun Acked-by: Kevin Tian --- devicemodel/Makefile | 1 + devicemodel/hw/acpi/acpi_pm.c | 84 +++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 devicemodel/hw/acpi/acpi_pm.c diff --git a/devicemodel/Makefile b/devicemodel/Makefile index e0b3303f7..0b6603f17 100644 --- a/devicemodel/Makefile +++ b/devicemodel/Makefile @@ -78,6 +78,7 @@ SRCS += hw/pci/virtio/virtio_hyper_dmabuf.c SRCS += hw/pci/irq.c SRCS += hw/pci/uart.c SRCS += hw/acpi/acpi.c +SRCS += hw/acpi/acpi_pm.c # core #SRCS += core/bootrom.c diff --git a/devicemodel/hw/acpi/acpi_pm.c b/devicemodel/hw/acpi/acpi_pm.c new file mode 100644 index 000000000..dc093b4bd --- /dev/null +++ b/devicemodel/hw/acpi/acpi_pm.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2018 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 THE COPYRIGHT + * OWNER 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. + * + */ + +#include +#include +#include + +#include "vmm.h" +#include "vmmapi.h" +#include "dm.h" +#include "acpi.h" + +uint8_t get_vcpu_px_cnt(struct vmctx *ctx, int vcpu_id) +{ + uint64_t pm_ioctl_buf = 0; + enum pm_cmd_type cmd_type = PMCMD_GET_PX_CNT; + + pm_ioctl_buf = ((ctx->vmid << PMCMD_VMID_SHIFT) & PMCMD_VMID_MASK) + | ((vcpu_id << PMCMD_VCPUID_SHIFT) & PMCMD_VCPUID_MASK) + | cmd_type; + + if (vm_get_cpu_state(ctx, &pm_ioctl_buf)) { + return 0; + } + + return (uint8_t)pm_ioctl_buf; +} + +int get_vcpu_px_data(struct vmctx *ctx, int vcpu_id, + int px_num, struct cpu_px_data *vcpu_px_data) +{ + uint64_t *pm_ioctl_buf; + enum pm_cmd_type cmd_type = PMCMD_GET_PX_DATA; + + pm_ioctl_buf = malloc(sizeof(struct cpu_px_data)); + if (!pm_ioctl_buf) { + return -1; + } + + *pm_ioctl_buf = ((ctx->vmid << PMCMD_VMID_SHIFT) & PMCMD_VMID_MASK) + | ((vcpu_id << PMCMD_VCPUID_SHIFT) & PMCMD_VCPUID_MASK) + | ((px_num << PMCMD_STATE_NUM_SHIFT) & PMCMD_STATE_NUM_MASK) + | cmd_type; + + /* get and validate px data */ + if (vm_get_cpu_state(ctx, pm_ioctl_buf)) { + free(pm_ioctl_buf); + return -1; + } + + memcpy(vcpu_px_data, pm_ioctl_buf, + sizeof(struct cpu_px_data)); + + free(pm_ioctl_buf); + return 0; +}