From: Anup Patel Subject: [PATCH v2 4/4] kvmtool: ARM/ARM64: Provide PSCI-0.2 to guest when KVM supports it Date: Tue, 26 Aug 2014 14:52:06 +0530 Message-ID: <1409044926-3744-5-git-send-email-anup.patel@linaro.org> References: <1409044926-3744-1-git-send-email-anup.patel@linaro.org> Cc: kvm@vger.kernel.org, patches@apm.com, will.deacon@arm.com, marc.zyngier@arm.com, penberg@kernel.org, christoffer.dall@linaro.org, pranavkumar@linaro.org, Anup Patel To: kvmarm@lists.cs.columbia.edu Return-path: Received: from mail-pa0-f49.google.com ([209.85.220.49]:49051 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755715AbaHZJWz (ORCPT ); Tue, 26 Aug 2014 05:22:55 -0400 Received: by mail-pa0-f49.google.com with SMTP id hz1so22966892pad.22 for ; Tue, 26 Aug 2014 02:22:55 -0700 (PDT) In-Reply-To: <1409044926-3744-1-git-send-email-anup.patel@linaro.org> Sender: kvm-owner@vger.kernel.org List-ID: If in-kernel KVM support PSCI-0.2 emulation then we should set KVM_ARM_VCPU_PSCI_0_2 feature for each guest VCPU and also provide "arm,psci-0.2","arm,psci" as PSCI compatible string. This patch updates kvm_cpu__arch_init() and setup_fdt() as per above. Signed-off-by: Pranavkumar Sawargaonkar Signed-off-by: Anup Patel --- tools/kvm/arm/fdt.c | 39 +++++++++++++++++++++++++++++++++------ tools/kvm/arm/kvm-cpu.c | 5 +++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tools/kvm/arm/fdt.c b/tools/kvm/arm/fdt.c index 186a718..93849cf2 100644 --- a/tools/kvm/arm/fdt.c +++ b/tools/kvm/arm/fdt.c @@ -13,6 +13,7 @@ #include #include #include +#include static char kern_cmdline[COMMAND_LINE_SIZE]; @@ -162,12 +163,38 @@ static int setup_fdt(struct kvm *kvm) /* PSCI firmware */ _FDT(fdt_begin_node(fdt, "psci")); - _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); - _FDT(fdt_property_string(fdt, "method", "hvc")); - _FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND)); - _FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF)); - _FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON)); - _FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE)); + if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) { + const char compatible[] = "arm,psci-0.2\0arm,psci"; + _FDT(fdt_property(fdt, "compatible", + compatible, sizeof(compatible))); + _FDT(fdt_property_string(fdt, "method", "hvc")); + if (kvm->cfg.arch.aarch32_guest) { + _FDT(fdt_property_cell(fdt, "cpu_suspend", + PSCI_0_2_FN_CPU_SUSPEND)); + _FDT(fdt_property_cell(fdt, "cpu_off", + PSCI_0_2_FN_CPU_OFF)); + _FDT(fdt_property_cell(fdt, "cpu_on", + PSCI_0_2_FN_CPU_ON)); + _FDT(fdt_property_cell(fdt, "migrate", + PSCI_0_2_FN_MIGRATE)); + } else { + _FDT(fdt_property_cell(fdt, "cpu_suspend", + PSCI_0_2_FN64_CPU_SUSPEND)); + _FDT(fdt_property_cell(fdt, "cpu_off", + PSCI_0_2_FN_CPU_OFF)); + _FDT(fdt_property_cell(fdt, "cpu_on", + PSCI_0_2_FN64_CPU_ON)); + _FDT(fdt_property_cell(fdt, "migrate", + PSCI_0_2_FN64_MIGRATE)); + } + } else { + _FDT(fdt_property_string(fdt, "compatible", "arm,psci")); + _FDT(fdt_property_string(fdt, "method", "hvc")); + _FDT(fdt_property_cell(fdt, "cpu_suspend", KVM_PSCI_FN_CPU_SUSPEND)); + _FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF)); + _FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON)); + _FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE)); + } _FDT(fdt_end_node(fdt)); /* Finalise. */ diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index c010e9c..0637e9a 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -56,6 +56,11 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); + /* Set KVM_ARM_VCPU_PSCI_0_2 if available */ + if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) { + vcpu_init.features[0] |= (1UL << KVM_ARM_VCPU_PSCI_0_2); + } + /* * If preferred target ioctl successful then use preferred target * else try each and every target type. -- 1.7.9.5