From patchwork Thu Sep 26 06:37:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 278115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 610222C0090 for ; Thu, 26 Sep 2013 16:38:05 +1000 (EST) Received: from localhost ([::1]:56458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VP5D8-0000Y7-AD for incoming@patchwork.ozlabs.org; Thu, 26 Sep 2013 02:38:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VP5Cm-0000Wp-NG for qemu-devel@nongnu.org; Thu, 26 Sep 2013 02:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VP5Ch-0005fQ-Mk for qemu-devel@nongnu.org; Thu, 26 Sep 2013 02:37:40 -0400 Received: from ozlabs.org ([203.10.76.45]:36752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VP5Ch-0005f6-BG for qemu-devel@nongnu.org; Thu, 26 Sep 2013 02:37:35 -0400 Received: by ozlabs.org (Postfix, from userid 1034) id 197CD2C00B9; Thu, 26 Sep 2013 16:37:27 +1000 (EST) From: Michael Ellerman To: qemu-devel@nongnu.org Date: Thu, 26 Sep 2013 16:37:24 +1000 Message-Id: <1380177444-4961-1-git-send-email-michael@ellerman.id.au> X-Mailer: git-send-email 1.8.1.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 203.10.76.45 Cc: Paul Mackerras Subject: [Qemu-devel] [PATCH] spapr: Add support for hwrng when available X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Some powerpc systems have support for a hardware random number generator (hwrng). If such a hwrng is present the host kernel can provide access to it via the H_RANDOM hcall. The kernel advertises the presence of a hwrng with the KVM_CAP_PPC_HWRNG capability. If this is detected we add the appropriate device tree bits to advertise the presence of the hwrng to the guest kernel. Signed-off-by: Michael Ellerman --- hw/ppc/spapr.c | 16 ++++++++++++++++ include/hw/ppc/spapr.h | 1 + linux-headers/linux/kvm.h | 1 + target-ppc/kvm.c | 5 +++++ target-ppc/kvm_ppc.h | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 004184d..5909df1 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -497,6 +497,22 @@ static void *spapr_create_fdt_skel(const char *cpu_model, _FDT((fdt_end_node(fdt))); + if (kvmppc_hwrng_present()) { + _FDT(fdt_begin_node(fdt, "ibm,platform-facilities")); + + _FDT(fdt_property_string(fdt, "name", "ibm,platform-facilities")); + _FDT(fdt_property_string(fdt, "device_type", + "ibm,platform-facilities")); + _FDT(fdt_property_cell(fdt, "#address-cells", 0x1)); + _FDT(fdt_property_cell(fdt, "#size-cells", 0x0)); + _FDT(fdt_begin_node(fdt, "ibm,random-v1")); + _FDT(fdt_property_string(fdt, "name", "ibm,random-v1")); + _FDT(fdt_property_string(fdt, "compatible", "ibm,random")); + _FDT((fdt_end_node(fdt))); + } + + _FDT((fdt_end_node(fdt))); + /* event-sources */ spapr_events_fdt_skel(fdt, epow_irq); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index e37b419..c509500 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -283,6 +283,7 @@ typedef struct sPAPREnvironment { #define H_GET_EM_PARMS 0x2B8 #define H_SET_MPP 0x2D0 #define H_GET_MPP 0x2D4 +#define H_RANDOM 0x300 #define H_SET_MODE 0x31C #define MAX_HCALL_OPCODE H_SET_MODE diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index c614070..7be746c 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -666,6 +666,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_IRQ_MPIC 90 #define KVM_CAP_PPC_RTAS 91 #define KVM_CAP_IRQ_XICS 92 +#define KVM_CAP_PPC_HWRNG 95 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 8a196c6..faf5dae 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -1875,3 +1875,8 @@ int kvm_arch_on_sigbus(int code, void *addr) void kvm_arch_init_irq_routing(KVMState *s) { } + +bool kvmppc_hwrng_present(void) +{ + return kvm_enabled() && kvm_check_extension(kvm_state, KVM_CAP_PPC_HWRNG); +} diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index 4ae7bf2..b7b898b 100644 --- a/target-ppc/kvm_ppc.h +++ b/target-ppc/kvm_ppc.h @@ -42,6 +42,7 @@ int kvmppc_get_htab_fd(bool write); int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns); int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, uint16_t n_valid, uint16_t n_invalid); +bool kvmppc_hwrng_present(void); #else @@ -181,6 +182,10 @@ static inline int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index, abort(); } +static inline bool kvmppc_hwrng_present(void) +{ + return false; +} #endif #ifndef CONFIG_KVM