From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZg3v-0005tK-Pd for qemu-devel@nongnu.org; Wed, 09 Sep 2015 10:09:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZg3s-0005lz-IS for qemu-devel@nongnu.org; Wed, 09 Sep 2015 10:09:23 -0400 Received: from e06smtp07.uk.ibm.com ([195.75.94.103]:34230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZg3s-0005lq-A0 for qemu-devel@nongnu.org; Wed, 09 Sep 2015 10:09:20 -0400 Received: from /spool/local by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Sep 2015 15:09:19 +0100 Date: Wed, 9 Sep 2015 16:09:07 +0200 From: Greg Kurz Message-ID: <20150909160907.1a70bb36@bahia.local> In-Reply-To: <1441046762-5788-2-git-send-email-thuth@redhat.com> References: <1441046762-5788-1-git-send-email-thuth@redhat.com> <1441046762-5788-2-git-send-email-thuth@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/2] spapr: Add support for hwrng when available List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Huth Cc: armbru@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, michael@ellerman.id.au, qemu-ppc@nongnu.org, amit.shah@redhat.com, david@gibson.dropbear.id.au On Mon, 31 Aug 2015 20:46:01 +0200 Thomas Huth wrote: > From: Michael Ellerman > > 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 > [thuth: Refreshed patch so it applies to QEMU master branch] > Signed-off-by: Thomas Huth > --- > hw/ppc/spapr.c | 16 ++++++++++++++++ > include/hw/ppc/spapr.h | 1 + > target-ppc/kvm.c | 5 +++++ > target-ppc/kvm_ppc.h | 5 +++++ > 4 files changed, 27 insertions(+) > > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c > index bf0c64f..bc3a112 100644 > --- a/hw/ppc/spapr.c > +++ b/hw/ppc/spapr.c > @@ -466,6 +466,22 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base, > > _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 91a61ab..ab8906f 100644 > --- a/include/hw/ppc/spapr.h > +++ b/include/hw/ppc/spapr.h > @@ -331,6 +331,7 @@ struct sPAPRMachineState { > #define H_SET_MPP 0x2D0 > #define H_GET_MPP 0x2D4 > #define H_XIRR_X 0x2FC > +#define H_RANDOM 0x300 > #define H_SET_MODE 0x31C > #define MAX_HCALL_OPCODE H_SET_MODE > H_RANDOM isn't used in this patch, I believe the above hunk belongs to patch 2/2 actually. Cheers. -- Greg > diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c > index 110436d..7317f8f 100644 > --- a/target-ppc/kvm.c > +++ b/target-ppc/kvm.c > @@ -2484,3 +2484,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) > { > return data & 0xffff; > } > + > +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 4d30e27..62ff601 100644 > --- a/target-ppc/kvm_ppc.h > +++ b/target-ppc/kvm_ppc.h > @@ -55,6 +55,7 @@ void kvmppc_hash64_free_pteg(uint64_t token); > void kvmppc_hash64_write_pte(CPUPPCState *env, target_ulong pte_index, > target_ulong pte0, target_ulong pte1); > bool kvmppc_has_cap_fixup_hcalls(void); > +bool kvmppc_hwrng_present(void); > > #else > > @@ -248,6 +249,10 @@ static inline bool kvmppc_has_cap_fixup_hcalls(void) > abort(); > } > > +static inline bool kvmppc_hwrng_present(void) > +{ > + return false; > +} > #endif > > #ifndef CONFIG_KVM