Skip to contentSkip to conversation

hw/ppc/spapr_rng: Introduce CONFIG_SPAPR_RNG switch for spapr_rng.c

PATCH Superseded Thomas Huth 2 participants 5 messages Oct 4, 2018 – Oct 8, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/ppc/spapr_rng: Introduce CONFIG_SPAPR_RNG switch for spapr_rng.c

The spapr-rng device is suboptimal when compared to virtio-rng, so users might want to disable it in their builds. Thus let's introduce a proper CONFIG switch to allow us to compile QEMU without this device.

---
 default-configs/ppc64-softmmu.mak |  1 +
 hw/ppc/Makefile.objs              |  3 ++-
 hw/ppc/spapr.c                    |  3 ++-
 hw/ppc/spapr_rng.c                | 24 +-------------------
 hw/ppc/spapr_rng.h                | 48 +++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h            |  4 ----
 6 files changed, 54 insertions(+), 29 deletions(-)
 create mode 100644 hw/ppc/spapr_rng.h
default-configs/ppc64-softmmu.mak +1 -0
index b94af6c..24d4717 100644
@@ -17,3 +17,4 @@ CONFIG_XICS=$(CONFIG_PSERIES)
 CONFIG_XICS_SPAPR=$(CONFIG_PSERIES)
 CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM))
 CONFIG_MEM_HOTPLUG=y
+CONFIG_SPAPR_RNG=y
hw/ppc/Makefile.objs +2 -1
index 4ab5564..4e0c1c0 100644
@@ -3,8 +3,9 @@ obj-y += ppc.o ppc_booke.o fdt.o
 # IBM pSeries (sPAPR)
 obj-$(CONFIG_PSERIES) += spapr.o spapr_caps.o spapr_vio.o spapr_events.o
 obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
-obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
+obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o
 obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o spapr_irq.o
+obj-$(CONFIG_SPAPR_RNG) +=  spapr_rng.o
 # IBM PowerNV
 obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o pnv_bmc.o
 ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
hw/ppc/spapr.c +2 -1
index 98868d8..ba40c85 100644
@@ -53,9 +53,10 @@
 #include "hw/ppc/fdt.h"
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "spapr_rng.h"
+
 #include "hw/pci-host/spapr.h"
 #include "hw/pci/msi.h"
-
 #include "hw/pci/pci.h"
 #include "hw/scsi/scsi.h"
 #include "hw/virtio/virtio-scsi.h"
hw/ppc/spapr_rng.c +1 -23
index d2acd61..dec8434 100644
@@ -27,6 +27,7 @@
 #include "sysemu/rng.h"
 #include "hw/ppc/spapr.h"
 #include "kvm_ppc.h"
+#include "spapr_rng.h"
 
 #define SPAPR_RNG(obj) \
     OBJECT_CHECK(sPAPRRngState, (obj), TYPE_SPAPR_RNG)
@@ -132,29 +133,6 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp)
     }
 }
 
-int spapr_rng_populate_dt(void *fdt)
-{
-    int node;
-    int ret;
-
-    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
-    if (node <= 0) {
-        return -1;
-    }
-    ret = fdt_setprop_string(fdt, node, "device_type",
-                             "ibm,platform-facilities");
-    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
-    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);
-
-    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
-    if (node <= 0) {
-        return -1;
-    }
-    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
-
-    return ret ? -1 : 0;
-}
-
 static Property spapr_rng_properties[] = {
     DEFINE_PROP_BOOL("use-kvm", sPAPRRngState, use_kvm, false),
     DEFINE_PROP_LINK("rng", sPAPRRngState, backend, TYPE_RNG_BACKEND,
hw/ppc/spapr_rng.h new file +48 -0

48 lines not on this page · raw message

include/hw/ppc/spapr.h +0 -4
index ad4d7cf..9460c46 100644
@@ -743,10 +743,6 @@ void spapr_lmb_release(DeviceState *dev);
 void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns);
 int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t legacy_offset);
 
-#define TYPE_SPAPR_RNG "spapr-rng"
-
-int spapr_rng_populate_dt(void *fdt);
-
 #define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */
 
 /*
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Thomas Huth

The spapr-rng device is suboptimal when compared to virtio-rng, so users might want to disable it in their builds. Thus let's introduce a proper CONFIG switch to allow us to compile QEMU without this device.

Uh, sure, I guess so.

Quoted 79 lines
---
 default-configs/ppc64-softmmu.mak |  1 +
 hw/ppc/Makefile.objs              |  3 ++-
 hw/ppc/spapr.c                    |  3 ++-
 hw/ppc/spapr_rng.c                | 24 +-------------------
 hw/ppc/spapr_rng.h                | 48 +++++++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr.h            |  4 ----
 6 files changed, 54 insertions(+), 29 deletions(-)
 create mode 100644 hw/ppc/spapr_rng.h
default-configs/ppc64-softmmu.mak +1 -0
index b94af6c..24d4717 100644
@@ -17,3 +17,4 @@ CONFIG_XICS=$(CONFIG_PSERIES)
 CONFIG_XICS_SPAPR=$(CONFIG_PSERIES)
 CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM))
 CONFIG_MEM_HOTPLUG=y
+CONFIG_SPAPR_RNG=y
hw/ppc/Makefile.objs +2 -1
index 4ab5564..4e0c1c0 100644
@@ -3,8 +3,9 @@ obj-y += ppc.o ppc_booke.o fdt.o
 # IBM pSeries (sPAPR)
 obj-$(CONFIG_PSERIES) += spapr.o spapr_caps.o spapr_vio.o spapr_events.o
 obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o
-obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o spapr_rng.o
+obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o
 obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o spapr_irq.o
+obj-$(CONFIG_SPAPR_RNG) +=  spapr_rng.o
 # IBM PowerNV
 obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o pnv_bmc.o
 ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
hw/ppc/spapr.c +2 -1
index 98868d8..ba40c85 100644
@@ -53,9 +53,10 @@
 #include "hw/ppc/fdt.h"
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "spapr_rng.h"
+
 #include "hw/pci-host/spapr.h"
 #include "hw/pci/msi.h"
-
 #include "hw/pci/pci.h"
 #include "hw/scsi/scsi.h"
 #include "hw/virtio/virtio-scsi.h"
hw/ppc/spapr_rng.c +1 -13
index d2acd61..dec8434 100644
@@ -27,6 +27,7 @@
 #include "sysemu/rng.h"
 #include "hw/ppc/spapr.h"
 #include "kvm_ppc.h"
+#include "spapr_rng.h"
 
 #define SPAPR_RNG(obj) \
     OBJECT_CHECK(sPAPRRngState, (obj), TYPE_SPAPR_RNG)
@@ -132,29 +133,6 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp)
     }
 }
 
-int spapr_rng_populate_dt(void *fdt)
-{
-    int node;
-    int ret;
-
-    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
-    if (node <= 0) {
-        return -1;
-    }
-    ret = fdt_setprop_string(fdt, node, "device_type",
-                             "ibm,platform-facilities");
-    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
-    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);

hw/ppc/spapr_rng.c static void spapr_rng_realize(DeviceState *dev, Error **errp) · line 157

Quoted 10 lines
hw/ppc/spapr_rng.c +0 -10
-
-    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
-    if (node <= 0) {
-        return -1;
-    }
-    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
-
-    return ret ? -1 : 0;
-}
-

Moving this to an inline doesn't seem right to me though - it's a more complex function that we usually want in a .h inline, and I don't really see a good reason for it to be there (rather than an #ifdeffed stub).

Quoted 72 lines
hw/ppc/spapr_rng.c +0 -0
 static Property spapr_rng_properties[] = {
     DEFINE_PROP_BOOL("use-kvm", sPAPRRngState, use_kvm, false),
     DEFINE_PROP_LINK("rng", sPAPRRngState, backend, TYPE_RNG_BACKEND,
hw/ppc/spapr_rng.h new file +48 -0
new file mode 100644
index 0000000..1d5fdcb
@@ -0,0 +1,48 @@
+/*
+ * QEMU sPAPR random number generator "device" for H_RANDOM hypercall
+ *
+ * Copyright 2015 Thomas Huth, Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SPAPR_RNG_H
+#define SPAPR_RNG_H
+
+#define TYPE_SPAPR_RNG "spapr-rng"
+
+static inline int spapr_rng_populate_dt(void *fdt)
+{
+    int node;
+    int ret;
+
+    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
+    if (node <= 0) {
+        return -1;
+    }
+    ret = fdt_setprop_string(fdt, node, "device_type",
+                             "ibm,platform-facilities");
+    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
+    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);
+
+    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
+    if (node <= 0) {
+        return -1;
+    }
+    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
+
+    return ret ? -1 : 0;
+}
+
+#endif
include/hw/ppc/spapr.h +0 -4
index ad4d7cf..9460c46 100644
@@ -743,10 +743,6 @@ void spapr_lmb_release(DeviceState *dev);
 void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns);
 int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t legacy_offset);
 
-#define TYPE_SPAPR_RNG "spapr-rng"
-
-int spapr_rng_populate_dt(void *fdt);
-
 #define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */
 
 /*
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 8 lines · David Gibson
Quoted 5 lines · Thomas Huth

The spapr-rng device is suboptimal when compared to virtio-rng, so users might want to disable it in their builds. Thus let's introduce a proper CONFIG switch to allow us to compile QEMU without this device.

Uh, sure, I guess so.

Yes, we definitely want this for the QEMU in RHEL :-)

Quoted 36 lines
Quoted 36 lines
hw/ppc/spapr_rng.c +1 -20
index d2acd61..dec8434 100644
@@ -27,6 +27,7 @@
 #include "sysemu/rng.h"
 #include "hw/ppc/spapr.h"
 #include "kvm_ppc.h"
+#include "spapr_rng.h"
 
 #define SPAPR_RNG(obj) \
     OBJECT_CHECK(sPAPRRngState, (obj), TYPE_SPAPR_RNG)
@@ -132,29 +133,6 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp)
     }
 }
 
-int spapr_rng_populate_dt(void *fdt)
-{
-    int node;
-    int ret;
-
-    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
-    if (node <= 0) {
-        return -1;
-    }
-    ret = fdt_setprop_string(fdt, node, "device_type",
-                             "ibm,platform-facilities");
-    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
-    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);
-
-    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
-    if (node <= 0) {
-        return -1;
-    }
-    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
-
Quoted 8 lines

hw/ppc/spapr_rng.c static void spapr_rng_realize(DeviceState *dev, Error **errp) · line 157

Quoted 3 lines
hw/ppc/spapr_rng.c +0 -3
-    return ret ? -1 : 0;
-}
-

Moving this to an inline doesn't seem right to me though - it's a more complex function that we usually want in a .h inline, and I don't really see a good reason for it to be there (rather than an #ifdeffed stub).

An #ifdef is not possible here - the CONFIG switches for the targets are *not* turned into pre-processor macros, only the CONFIG switches for the host settings. So putting this function as static inline into a separate header seems to be the best option to me right now. Alternatively, I could also put it directly into spapr.c directly, but that file is already very big... well, I don't mind, let me know what you prefer.

Thomas

#3 lore raw
Quoted 57 lines · Thomas Huth
Quoted 8 lines · David Gibson
Quoted 5 lines · Thomas Huth

The spapr-rng device is suboptimal when compared to virtio-rng, so users might want to disable it in their builds. Thus let's introduce a proper CONFIG switch to allow us to compile QEMU without this device.

Uh, sure, I guess so.

Yes, we definitely want this for the QEMU in RHEL :-)

Quoted 36 lines
Quoted 36 lines
hw/ppc/spapr_rng.c +1 -20
index d2acd61..dec8434 100644
@@ -27,6 +27,7 @@
 #include "sysemu/rng.h"
 #include "hw/ppc/spapr.h"
 #include "kvm_ppc.h"
+#include "spapr_rng.h"
 
 #define SPAPR_RNG(obj) \
     OBJECT_CHECK(sPAPRRngState, (obj), TYPE_SPAPR_RNG)
@@ -132,29 +133,6 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp)
     }
 }
 
-int spapr_rng_populate_dt(void *fdt)
-{
-    int node;
-    int ret;
-
-    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
-    if (node <= 0) {
-        return -1;
-    }
-    ret = fdt_setprop_string(fdt, node, "device_type",
-                             "ibm,platform-facilities");
-    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
-    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);
-
-    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
-    if (node <= 0) {
-        return -1;
-    }
-    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
-
Quoted 8 lines

hw/ppc/spapr_rng.c static void spapr_rng_realize(DeviceState *dev, Error **errp) · line 157

Quoted 3 lines
hw/ppc/spapr_rng.c +0 -3
-    return ret ? -1 : 0;
-}
-

Moving this to an inline doesn't seem right to me though - it's a more complex function that we usually want in a .h inline, and I don't really see a good reason for it to be there (rather than an #ifdeffed stub).

Quoted 3 lines

An #ifdef is not possible here - the CONFIG switches for the targets are *not* turned into pre-processor macros, only the CONFIG switches for the host settings.

Ah, right.

Quoted 4 lines

So putting this function as static inline into a separate header seems to be the best option to me right now. Alternatively, I could also put it directly into spapr.c directly, but that file is already very big... well, I don't mind, let me know what you prefer.

I'd prefer spapr.c to the inline.

But.. couldn't you put a stub version in stubs? That would make a weak symbol that would be overridden when SPAPR_RNG is compiled in.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw
Quoted 69 lines · David Gibson
Quoted 57 lines · Thomas Huth
Quoted 8 lines · David Gibson
Quoted 5 lines · Thomas Huth

The spapr-rng device is suboptimal when compared to virtio-rng, so users might want to disable it in their builds. Thus let's introduce a proper CONFIG switch to allow us to compile QEMU without this device.

Uh, sure, I guess so.

Yes, we definitely want this for the QEMU in RHEL :-)

Quoted 36 lines
Quoted 36 lines
hw/ppc/spapr_rng.c +1 -20
index d2acd61..dec8434 100644
@@ -27,6 +27,7 @@
 #include "sysemu/rng.h"
 #include "hw/ppc/spapr.h"
 #include "kvm_ppc.h"
+#include "spapr_rng.h"
 
 #define SPAPR_RNG(obj) \
     OBJECT_CHECK(sPAPRRngState, (obj), TYPE_SPAPR_RNG)
@@ -132,29 +133,6 @@ static void spapr_rng_realize(DeviceState *dev, Error **errp)
     }
 }
 
-int spapr_rng_populate_dt(void *fdt)
-{
-    int node;
-    int ret;
-
-    node = qemu_fdt_add_subnode(fdt, "/ibm,platform-facilities");
-    if (node <= 0) {
-        return -1;
-    }
-    ret = fdt_setprop_string(fdt, node, "device_type",
-                             "ibm,platform-facilities");
-    ret |= fdt_setprop_cell(fdt, node, "#address-cells", 0x1);
-    ret |= fdt_setprop_cell(fdt, node, "#size-cells", 0x0);
-
-    node = fdt_add_subnode(fdt, node, "ibm,random-v1");
-    if (node <= 0) {
-        return -1;
-    }
-    ret |= fdt_setprop_string(fdt, node, "compatible", "ibm,random");
-
Quoted 8 lines

hw/ppc/spapr_rng.c static void spapr_rng_realize(DeviceState *dev, Error **errp) · line 157

Quoted 3 lines
hw/ppc/spapr_rng.c +0 -3
-    return ret ? -1 : 0;
-}
-

Moving this to an inline doesn't seem right to me though - it's a more complex function that we usually want in a .h inline, and I don't really see a good reason for it to be there (rather than an #ifdeffed stub).

Quoted 3 lines

An #ifdef is not possible here - the CONFIG switches for the targets are *not* turned into pre-processor macros, only the CONFIG switches for the host settings.

Ah, right.

Quoted 4 lines

So putting this function as static inline into a separate header seems to be the best option to me right now. Alternatively, I could also put it directly into spapr.c directly, but that file is already very big... well, I don't mind, let me know what you prefer.

Quoted 4 lines

I'd prefer spapr.c to the inline.

But.. couldn't you put a stub version in stubs? That would make a weak symbol that would be overridden when SPAPR_RNG is compiled in.

We could ... but stubs should IMHO only be used if there is no other good solution. In this case, it's perfectly fine if we just move the spapr_rng_populate_dt() function to another location. So I'll have a try with spapr.c instead.

Thomas