Improve code probing for the Intel hardware RNG to avoid false detections.

See http://home.comcast.net/~andrex/hardware-RNG/doihave.html for details.
Problem pointed on by Thor Lancelot Simon on port-amd64 mailing list.
This commit is contained in:
tron 2006-02-19 23:10:16 +00:00
parent c892ebfd2b
commit 28fb66b731
1 changed files with 19 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pchb_rnd.c,v 1.1 2006/02/12 18:16:01 tron Exp $ */
/* $NetBSD: pchb_rnd.c,v 1.2 2006/02/19 23:10:16 tron Exp $ */
/*
* Copyright (c) 2000 Michael Shalayeff
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pchb_rnd.c,v 1.1 2006/02/12 18:16:01 tron Exp $");
__KERNEL_RCSID(0, "$NetBSD: pchb_rnd.c,v 1.2 2006/02/19 23:10:16 tron Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -50,7 +50,9 @@ __KERNEL_RCSID(0, "$NetBSD: pchb_rnd.c,v 1.1 2006/02/12 18:16:01 tron Exp $");
#include <arch/x86/pci/i82802reg.h>
#include <arch/x86/pci/pchbvar.h>
void pchb_rnd_callout(void *v);
static void pchb_rnd_callout(void *v);
#define PCHB_RNG_RETRIES 1000
void
pchb_attach_rnd(struct pchb_softc *sc, struct pci_attach_args *pa)
@ -120,20 +122,27 @@ pchb_attach_rnd(struct pchb_softc *sc, struct pci_attach_args *pa)
}
/* Check to see if we can read data from the RNG. */
for (i = 0; i < 1000; i++) {
for (i = 0; i < PCHB_RNG_RETRIES; i++) {
reg8 = bus_space_read_1(sc->sc_st, sc->sc_sh,
I82802_RNG_RNGST);
if (reg8 & I82802_RNG_RNGST_DATAV)
break;
if (!(reg8 & I82802_RNG_RNGST_DATAV)) {
delay(10);
continue;
}
if (bus_space_read_1(sc->sc_st, sc->sc_sh,
I82802_RNG_DATA) != 0xff) {
break;
}
}
if ((reg8 & I82802_RNG_RNGST_DATAV) == 0) {
if (i == PCHB_RNG_RETRIES) {
bus_space_unmap(sc->sc_st, sc->sc_sh,
I82802_IOSIZE);
printf("%s: unable to read from random "
"number generator.\n",
#ifdef DIAGNOSTIC
aprint_verbose("%s: unable to read from "
"random number generator.\n",
sc->sc_dev.dv_xname);
#endif
return;
}
@ -166,7 +175,7 @@ pchb_attach_rnd(struct pchb_softc *sc, struct pci_attach_args *pa)
}
}
void
static void
pchb_rnd_callout(void *v)
{
struct pchb_softc *sc = v;