summaryrefslogtreecommitdiff
path: root/sys/arch/sparc64
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-01-17 19:24:52 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-01-17 19:24:52 +0000
commit6731af8521c92a2a71fb0e38be5055a4703fc8fc (patch)
tree71b5e13f1aef453dd3137c5ff09d5ea1c5aea18b /sys/arch/sparc64
parent32db964d7294e9e842e4d03b6b32b3ddcd9ffd16 (diff)
Make this work in guest domains.
Diffstat (limited to 'sys/arch/sparc64')
-rw-r--r--sys/arch/sparc64/dev/vrng.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/sys/arch/sparc64/dev/vrng.c b/sys/arch/sparc64/dev/vrng.c
index a847e6b9117..c654cbe2e1f 100644
--- a/sys/arch/sparc64/dev/vrng.c
+++ b/sys/arch/sparc64/dev/vrng.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vrng.c,v 1.1 2008/08/13 19:30:02 kettenis Exp $ */
+/* $OpenBSD: vrng.c,v 1.2 2009/01/17 19:24:51 kettenis Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
*
@@ -89,35 +89,42 @@ vrng_attach(struct device *parent, struct device *self, void *aux)
printf(": unsupported hypervisor\n");
err = hv_rng_get_diag_control();
- if (err != H_EOK)
+ if (err != H_EOK && err != H_ENOACCESS)
printf(": hv_rng_get_diag_control %d\n", err);
- bzero(ctl, sizeof(ctl));
+ /*
+ * If we're not the Trusted Domain, the hypervisor call above
+ * will fails with H_ENOACCESS. In that case we hope that the
+ * RNG has been properly initialized.
+ */
+ if (err == H_EOK) {
+ bzero(ctl, sizeof(ctl));
- ctl[0].rng_ctl1 = 1;
- ctl[0].rng_vcoctl_sel = 0;
- ctl[0].rng_wait_cnt = 0x3e;
+ ctl[0].rng_ctl1 = 1;
+ ctl[0].rng_vcoctl_sel = 0;
+ ctl[0].rng_wait_cnt = 0x3e;
- ctl[1].rng_ctl2 = 1;
- ctl[1].rng_vcoctl_sel = 1;
- ctl[1].rng_wait_cnt = 0x3e;
+ ctl[1].rng_ctl2 = 1;
+ ctl[1].rng_vcoctl_sel = 1;
+ ctl[1].rng_wait_cnt = 0x3e;
- ctl[2].rng_ctl3 = 1;
- ctl[2].rng_vcoctl_sel = 2;
- ctl[2].rng_wait_cnt = 0x3e;
+ ctl[2].rng_ctl3 = 1;
+ ctl[2].rng_vcoctl_sel = 2;
+ ctl[2].rng_wait_cnt = 0x3e;
- ctl[3].rng_ctl1 = 1;
- ctl[3].rng_ctl2 = 1;
- ctl[3].rng_ctl3 = 1;
- ctl[3].rng_ctl4 = 1;
- ctl[3].rng_wait_cnt = 0x3e;
+ ctl[3].rng_ctl1 = 1;
+ ctl[3].rng_ctl2 = 1;
+ ctl[3].rng_ctl3 = 1;
+ ctl[3].rng_ctl4 = 1;
+ ctl[3].rng_wait_cnt = 0x3e;
- if (!pmap_extract(pmap_kernel(), (vaddr_t)&ctl, &addr))
- panic("vrng_attach: pmap_extract failed\n");
+ if (!pmap_extract(pmap_kernel(), (vaddr_t)&ctl, &addr))
+ panic("vrng_attach: pmap_extract failed\n");
- err = hv_rng_ctl_write(addr, RNG_STATE_CONFIGURED, 0, &delta);
- if (err != H_EOK)
- printf(": hv_rng_ctl_write %d\n", err);
+ err = hv_rng_ctl_write(addr, RNG_STATE_CONFIGURED, 0, &delta);
+ if (err != H_EOK)
+ printf(": hv_rng_ctl_write %d\n", err);
+ }
printf("\n");