summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cosgrove <tom@cvs.openbsd.org>2006-10-26 08:37:15 +0000
committerTom Cosgrove <tom@cvs.openbsd.org>2006-10-26 08:37:15 +0000
commitab1eba7ede322f6bbea366ce24d7ea103d703d23 (patch)
tree4d2dfbf5921c9d2b22b9d657e94f5bf932cdbf49
parent6cd44b05b739b43cf54f14cbd77d1b935a9157b1 (diff)
Driver for the AMD Geode LX series processor security block.
Currently just uses the RNG; AES support to be added later. ok deraadt@
-rw-r--r--share/man/man4/man4.i386/Makefile4
-rw-r--r--share/man/man4/man4.i386/glxsb.455
-rw-r--r--share/man/man4/random.43
-rw-r--r--sys/arch/i386/conf/GENERIC3
-rw-r--r--sys/arch/i386/conf/files.i3867
-rw-r--r--sys/arch/i386/pci/glxsb.c184
6 files changed, 251 insertions, 5 deletions
diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile
index 5b2c0d55829..e0488e57bc9 100644
--- a/share/man/man4/man4.i386/Makefile
+++ b/share/man/man4/man4.i386/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.57 2006/09/21 14:13:37 jmc Exp $
+# $OpenBSD: Makefile,v 1.58 2006/10/26 08:37:14 tom Exp $
# from: @(#)Makefile 5.1 (Berkeley) 2/12/91
# Id: Makefile,v 1.4 1995/12/14 05:41:38 deraadt Exp $
MAN= apm.4 autoconf.4 bios.4 cpu.4 elansc.4 esm.4 \
- geodesc.4 gscpcib.4 gscpm.4 gus.4 ie.4 \
+ geodesc.4 glxsb.4 gscpcib.4 gscpm.4 gus.4 ie.4 \
ichpcib.4 intro.4 \
joy.4 le.4 lms.4 mcd.4 mem.4 mms.4 mtrr.4 npx.4 nvram.4 pas.4 \
pcibios.4 pctr.4 pss.4 sb.4 \
diff --git a/share/man/man4/man4.i386/glxsb.4 b/share/man/man4/man4.i386/glxsb.4
new file mode 100644
index 00000000000..cb9cb59557e
--- /dev/null
+++ b/share/man/man4/man4.i386/glxsb.4
@@ -0,0 +1,55 @@
+.\" $OpenBSD: glxsb.4,v 1.1 2006/10/26 08:37:14 tom Exp $
+.\"
+.\"Copyright (c) 2006 Tom Cosgrove <tom@openbsd.org>
+.\"
+.\"Permission to use, copy, modify, and distribute this software for any
+.\"purpose with or without fee is hereby granted, provided that the above
+.\"copyright notice and this permission notice appear in all copies.
+.\"
+.\"THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\"WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\"MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\"ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\"WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\"ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\"OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\"
+.Dd October 25, 2006
+.Dt GLXSB 4 i386
+.Os
+.Sh NAME
+.Nm glxsb
+.Nd Geode LX Security Block device
+.Sh SYNOPSIS
+.Cd "glxsb* at pci?"
+.Sh DESCRIPTION
+The
+.Nm
+driver supports the security block of the Geode LX series processors.
+.Pp
+The Geode LX is a member of the AMD Geode family
+of integrated x86 system chips.
+.Pp
+Driven by periodic checks for available data from the generator,
+.Nm
+supplies entropy to the
+.Xr random 4
+driver for common usage.
+.Sh SEE ALSO
+.Xr random 4
+.Sh HISTORY
+Support for the
+.Nm
+was added in
+.Ox 4.1 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Tom Cosgrove .
+.Sh BUGS
+The
+.Nm
+driver does not yet use the AES acceleration provided by the security block;
+it only uses the random number generator.
diff --git a/share/man/man4/random.4 b/share/man/man4/random.4
index afb3ea870b5..ed7207a4d1b 100644
--- a/share/man/man4/random.4
+++ b/share/man/man4/random.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: random.4,v 1.18 2003/06/06 10:29:41 jmc Exp $
+.\" $OpenBSD: random.4,v 1.19 2006/10/26 08:37:14 tom Exp $
.\"
.\" Copyright (c) 1996, 1997 Michael Shalayeff
.\"
@@ -84,6 +84,7 @@ providing a second level of ARC4 hashed data.
.Xr md5 3 ,
.Xr random 3 ,
.Xr amdpm 4 ,
+.Xr glxsb 4 ,
.Xr pchb 4 ,
.Xr md5 9 ,
.Xr random 9
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index b8071a70879..ab4495da49d 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.529 2006/10/26 04:14:09 jsg Exp $
+# $OpenBSD: GENERIC,v 1.530 2006/10/26 08:37:14 tom Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -670,6 +670,7 @@ nofn* at pci? # Hi/fn 7814/7851/7854 crypto card
ubsec* at pci? # Bluesteel Networks 5xxx crypto card
safe* at pci? # SafeNet SafeXcel 1141/1741
#ises* at pci? # Pijnenburg PCC-ISES
+glxsb* at pci? # AMD Geode LX series processor security block
# I2O
iop* at pci? # I2O processor
diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386
index b8f1c34462b..f353786e83d 100644
--- a/sys/arch/i386/conf/files.i386
+++ b/sys/arch/i386/conf/files.i386
@@ -1,4 +1,4 @@
-# $OpenBSD: files.i386,v 1.150 2006/07/25 19:16:51 kettenis Exp $
+# $OpenBSD: files.i386,v 1.151 2006/10/26 08:37:14 tom Exp $
#
# new style config file for i386 architecture
#
@@ -123,6 +123,11 @@ device geodesc
attach geodesc at pci
file arch/i386/pci/geodesc.c geodesc
+# AMD Geode LX series processor security block
+device glxsb
+attach glxsb at pci
+file arch/i386/pci/glxsb.c glxsb
+
# National Semiconductor Geode SC1100 SMI/ACPI module
device gscpm
attach gscpm at pci
diff --git a/sys/arch/i386/pci/glxsb.c b/sys/arch/i386/pci/glxsb.c
new file mode 100644
index 00000000000..077eec4b6dc
--- /dev/null
+++ b/sys/arch/i386/pci/glxsb.c
@@ -0,0 +1,184 @@
+/* $OpenBSD: glxsb.c,v 1.1 2006/10/26 08:37:14 tom Exp $ */
+
+/*
+ * Copyright (c) 2006 Tom Cosgrove <tom@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Driver for the security block on the AMD Geode LX processors
+ * http://www.amd.com/files/connectivitysolutions/geode/geode_lx/33234d_lx_ds.pdf
+ */
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/types.h>
+#include <sys/timeout.h>
+
+#include <machine/bus.h>
+#include <machine/pctr.h>
+
+#include <dev/rndvar.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#define SB_GLD_MSR_CAP 0x58002000 /* RO - Capabilities */
+#define SB_GLD_MSR_CONFIG 0x58002001 /* RW - Master Config */
+#define SB_GLD_MSR_SMI 0x58002002 /* RW - SMI */
+#define SB_GLD_MSR_ERROR 0x58002003 /* RW - Error */
+#define SB_GLD_MSR_PM 0x58002004 /* RW - Power Mgmt */
+#define SB_GLD_MSR_DIAG 0x58002005 /* RW - Diagnostic */
+#define SB_GLD_MSR_CTRL 0x58002006 /* RW - Security Block Cntrl */
+
+ /* For GLD_MSR_CTRL: */
+#define SB_GMC_DIV0 0x0000 /* AES update divisor values */
+#define SB_GMC_DIV1 0x0001
+#define SB_GMC_DIV2 0x0002
+#define SB_GMC_DIV3 0x0003
+#define SB_GMC_DIV_MASK 0x0003
+#define SB_GMC_SBI 0x0004 /* AES swap bits */
+#define SB_GMC_SBY 0x0008 /* AES swap bytes */
+#define SB_GMC_TW 0x0010 /* Time write (EEPROM) */
+#define SB_GMC_T_SEL0 0x0000 /* RNG post-proc: none */
+#define SB_GMC_T_SEL1 0x0100 /* RNG post-proc: LFSR */
+#define SB_GMC_T_SEL2 0x0200 /* RNG post-proc: whitener */
+#define SB_GMC_T_SEL3 0x0300 /* RNG LFSR+whitener */
+#define SB_GMC_T_SEL_MASK 0x0300
+#define SB_GMC_T_NE 0x0400 /* Noise (generator) Enable */
+#define SB_GMC_T_TM 0x0800 /* RNG test mode */
+ /* (deterministic) */
+
+/* Security Block configuration/control registers (offsets from base) */
+
+#define SB_CTL_A 0x0000 /* RW - SB Control A */
+#define SB_CTL_B 0x0004 /* RW - SB Control B */
+#define SB_AES_INT 0x0008 /* RW - SB AES Interrupt */
+#define SB_SOURCE_A 0x0010 /* RW - Source A */
+#define SB_DEST_A 0x0014 /* RW - Destination A */
+#define SB_LENGTH_A 0x0018 /* RW - Length A */
+#define SB_SOURCE_B 0x0020 /* RW - Source B */
+#define SB_DEST_B 0x0024 /* RW - Destination B */
+#define SB_LENGTH_B 0x0028 /* RW - Length B */
+#define SB_WKEY_0 0x0030 /* WO - Writable Key 0 */
+#define SB_WKEY_1 0x0034 /* WO - Writable Key 1 */
+#define SB_WKEY_2 0x0038 /* WO - Writable Key 2 */
+#define SB_WKEY_3 0x003C /* WO - Writable Key 3 */
+#define SB_CBC_IV_0 0x0040 /* RW - CBC IV 0 */
+#define SB_CBC_IV_1 0x0044 /* RW - CBC IV 1 */
+#define SB_CBC_IV_2 0x0048 /* RW - CBC IV 2 */
+#define SB_CBC_IV_3 0x004C /* RW - CBC IV 3 */
+#define SB_RANDOM_NUM 0x0050 /* RW - Random Number */
+#define SB_RANDOM_NUM_STATUS 0x0054 /* RW - Random Number Status */
+#define SB_EEPROM_COMM 0x0800 /* RW - EEPROM Command */
+#define SB_EEPROM_ADDR 0x0804 /* RW - EEPROM Address */
+#define SB_EEPROM_DATA 0x0808 /* RW - EEPROM Data */
+#define SB_EEPROM_SEC_STATE 0x080C /* RW - EEPROM Security State */
+
+#define SB_RNS_TRNG_VALID 0x0001 /* in SB_RANDOM_NUM_STATUS */
+
+#define SB_MEM_SIZE 0x0810 /* Size of memory block */
+
+struct glxsb_softc {
+ struct device sc_dev;
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+ struct timeout sc_to;
+};
+
+int glxsb_match(struct device *, void *, void *);
+void glxsb_attach(struct device *, struct device *, void *);
+void glxsb_rnd(void *);
+
+struct cfattach glxsb_ca = {
+ sizeof(struct glxsb_softc), glxsb_match, glxsb_attach
+};
+
+struct cfdriver glxsb_cd = {
+ NULL, "glxsb", DV_DULL
+};
+
+
+int
+glxsb_match(struct device *parent, void *match, void *aux)
+{
+ struct pci_attach_args *pa = aux;
+
+ if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_GEODE_LX_CRYPTO)
+ return (1);
+
+ return (0);
+}
+
+void
+glxsb_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct glxsb_softc *sc = (void *) self;
+ struct pci_attach_args *pa = aux;
+ bus_addr_t membase;
+ bus_size_t memsize;
+ uint64_t msr;
+
+ msr = rdmsr(SB_GLD_MSR_CAP);
+ if ((msr & 0xFFFF00) != 0x130400) {
+ printf(": unknown ID 0x%x\n", (int) ((msr & 0xFFFF00) >> 16));
+ return;
+ }
+
+ /* printf(": revision %d", (int) (msr & 0xFF)); */
+
+ /* Map in the security block configuration/control registers */
+ if (pci_mapreg_map(pa, PCI_MAPREG_START,
+ PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0, &sc->sc_iot,
+ &sc->sc_ioh, &membase, &memsize, SB_MEM_SIZE)) {
+ printf(": can't find mem space\n");
+ return;
+ }
+
+ /*
+ * Configure the Security Block.
+ *
+ * We want to enable the noise generator (T_NE), and enable the
+ * linear feedback shift register and whitener post-processing
+ * (T_SEL = 3). Also ensure that test mode (deterministic values)
+ * is disabled.
+ */
+ msr = rdmsr(SB_GLD_MSR_CTRL);
+ msr &= ~(SB_GMC_T_TM | SB_GMC_T_SEL_MASK);
+ msr |= SB_GMC_T_NE | SB_GMC_T_SEL3;
+ wrmsr(SB_GLD_MSR_CTRL, msr);
+
+ /* Install a periodic collector for the "true" (AMD's word) RNG */
+ timeout_set(&sc->sc_to, glxsb_rnd, sc);
+ glxsb_rnd(sc);
+ printf(": RNG\n");
+}
+
+void
+glxsb_rnd(void *v)
+{
+ struct glxsb_softc *sc = v;
+ uint32_t status, value;
+ extern int hz;
+
+ status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SB_RANDOM_NUM_STATUS);
+ if (status & SB_RNS_TRNG_VALID) {
+ value = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SB_RANDOM_NUM);
+ add_true_randomness(value);
+ }
+
+ timeout_add(&sc->sc_to, (hz > 100) ? (hz / 100) : 1);
+}