Module Name: src
Committed By: jmcneill
Date: Sat Feb 19 13:52:29 UTC 2011
Modified Files:
src/sys/arch/i386/conf: ALL GENERIC
src/sys/arch/i386/i386: autoconf.c
src/sys/arch/x86/conf: files.x86
src/sys/arch/x86/include: cpu.h cpuvar.h via_padlock.h
src/sys/arch/x86/x86: cpu.c identcpu.c via_padlock.c
Log Message:
modularize VIA PadLock support
- retire options VIA_PADLOCK, replace with 'padlock0 at cpu0'
- driver supports attach & detach
- support building as a module
To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.1017 -r1.1018 src/sys/arch/i386/conf/GENERIC
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/i386/i386/autoconf.c
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/x86/conf/files.x86
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/x86/include/cpuvar.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/include/via_padlock.h
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/x86/x86/via_padlock.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.288 src/sys/arch/i386/conf/ALL:1.289
--- src/sys/arch/i386/conf/ALL:1.288 Wed Feb 16 07:30:27 2011
+++ src/sys/arch/i386/conf/ALL Sat Feb 19 13:52:27 2011
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.288 2011/02/16 07:30:27 jruoho Exp $
+# $NetBSD: ALL,v 1.289 2011/02/19 13:52:27 jmcneill Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.288 $"
+#ident "ALL-$Revision: 1.289 $"
maxusers 64 # estimated number of users
@@ -40,7 +40,7 @@
options POWERNOW_K8
# VIA PadLock
-options VIA_PADLOCK
+padlock0 at cpu0
# Intel(R) On Demand Clock Modulation (aka ODCM)
options INTEL_ONDEMAND_CLOCKMOD
Index: src/sys/arch/i386/conf/GENERIC
diff -u src/sys/arch/i386/conf/GENERIC:1.1017 src/sys/arch/i386/conf/GENERIC:1.1018
--- src/sys/arch/i386/conf/GENERIC:1.1017 Sat Feb 19 00:13:55 2011
+++ src/sys/arch/i386/conf/GENERIC Sat Feb 19 13:52:27 2011
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1017 2011/02/19 00:13:55 jmcneill Exp $
+# $NetBSD: GENERIC,v 1.1018 2011/02/19 13:52:27 jmcneill Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.1017 $"
+#ident "GENERIC-$Revision: 1.1018 $"
maxusers 64 # estimated number of users
@@ -48,7 +48,7 @@
options POWERNOW_K8
# VIA PadLock
-#options VIA_PADLOCK
+#padlock0 at cpu0
# Intel(R) On Demand Clock Modulation (aka ODCM)
#options INTEL_ONDEMAND_CLOCKMOD
Index: src/sys/arch/i386/i386/autoconf.c
diff -u src/sys/arch/i386/i386/autoconf.c:1.95 src/sys/arch/i386/i386/autoconf.c:1.96
--- src/sys/arch/i386/i386/autoconf.c:1.95 Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/autoconf.c Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.95 2009/11/21 03:11:00 rmind Exp $ */
+/* $NetBSD: autoconf.c,v 1.96 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.95 2009/11/21 03:11:00 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.96 2011/02/19 13:52:28 jmcneill Exp $");
#include "opt_compat_oldboot.h"
#include "opt_intrdebug.h"
@@ -94,8 +94,6 @@
#include <machine/kvm86.h>
#endif
-#include "opt_viapadlock.h"
-
/*
* Determine i/o configuration for a machine.
*/
@@ -140,8 +138,4 @@
#if NLAPIC > 0
lapic_tpr = 0;
#endif
-
-#if defined(VIA_PADLOCK)
- via_padlock_attach();
-#endif
}
Index: src/sys/arch/x86/conf/files.x86
diff -u src/sys/arch/x86/conf/files.x86:1.57 src/sys/arch/x86/conf/files.x86:1.58
--- src/sys/arch/x86/conf/files.x86:1.57 Sat Feb 5 14:00:34 2011
+++ src/sys/arch/x86/conf/files.x86 Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-# $NetBSD: files.x86,v 1.57 2011/02/05 14:00:34 yamt Exp $
+# $NetBSD: files.x86,v 1.58 2011/02/19 13:52:28 jmcneill Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
@@ -29,24 +29,25 @@
# VIA C7 Temperature sensor
defflag opt_via_c7temp.h VIA_C7TEMP: sysmon_envsys
-# VIA PadLock support
-defflag opt_viapadlock.h VIA_PADLOCK: opencrypto
-file arch/x86/x86/via_padlock.c via_padlock
-
# To be able to test for NetBSD/xen in shared files
defflag opt_xen.h DO_NOT_DEFINE
define cpubus { [apid = -1] }
+define cpufeaturebus {}
define ioapicbus { [apid = -1] }
define ipmibus {}
#
# CPUs
#
-device cpu
+device cpu: cpufeaturebus
attach cpu at cpubus
file arch/x86/x86/cpu.c cpu
+device padlock: opencrypto
+attach padlock at cpufeaturebus
+file arch/x86/x86/via_padlock.c padlock
+
file arch/x86/x86/apic.c ioapic | lapic
file arch/x86/x86/bus_dma.c
file arch/x86/x86/bus_space.c
Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.26 src/sys/arch/x86/include/cpu.h:1.27
--- src/sys/arch/x86/include/cpu.h:1.26 Wed Dec 22 04:15:01 2010
+++ src/sys/arch/x86/include/cpu.h Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.26 2010/12/22 04:15:01 christos Exp $ */
+/* $NetBSD: cpu.h,v 1.27 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -180,7 +180,7 @@
struct evcnt ci_ipi_events[X86_NIPI];
- struct via_padlock ci_vp; /* VIA PadLock private storage */
+ device_t ci_padlock; /* VIA PadLock private storage */
struct i386tss ci_tss; /* Per-cpu TSS; shared among LWPs */
char ci_iomap[IOMAPSIZE]; /* I/O Bitmap */
Index: src/sys/arch/x86/include/cpuvar.h
diff -u src/sys/arch/x86/include/cpuvar.h:1.38 src/sys/arch/x86/include/cpuvar.h:1.39
--- src/sys/arch/x86/include/cpuvar.h:1.38 Fri Aug 20 06:34:32 2010
+++ src/sys/arch/x86/include/cpuvar.h Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuvar.h,v 1.38 2010/08/20 06:34:32 jruoho Exp $ */
+/* $NetBSD: cpuvar.h,v 1.39 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -85,6 +85,11 @@
const struct cpu_functions *cpu_func;
};
+struct cpufeature_attach_args {
+ struct cpu_info *ci;
+ const char *name;
+};
+
#ifdef _KERNEL
#if defined(_KERNEL_OPT)
Index: src/sys/arch/x86/include/via_padlock.h
diff -u src/sys/arch/x86/include/via_padlock.h:1.5 src/sys/arch/x86/include/via_padlock.h:1.6
--- src/sys/arch/x86/include/via_padlock.h:1.5 Wed Apr 1 21:15:45 2009
+++ src/sys/arch/x86/include/via_padlock.h Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: via_padlock.h,v 1.5 2009/04/01 21:15:45 drochner Exp $ */
+/* $NetBSD: via_padlock.h,v 1.6 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 2003 Jason Wright
@@ -53,6 +53,8 @@
};
struct via_padlock_softc {
+ device_t sc_dev;
+
uint32_t op_cw[4]; /* 128 bit aligned */
uint8_t op_iv[16]; /* 128 bit aligned */
void *op_buf;
@@ -60,9 +62,11 @@
int sc_rnd_hz;
struct callout sc_rnd_co;
rndsource_element_t sc_rnd_source;
+ bool sc_rnd_attached;
/* normal softc stuff */
int32_t sc_cid;
+ bool sc_cid_attached;
int sc_nsessions;
struct via_padlock_session *sc_sessions;
};
@@ -72,8 +76,6 @@
#define VIAC3_RNG_BUFSIZ 16
-void via_padlock_attach(void);
-
#endif /* _KERNEL */
#if defined(_KERNEL) || defined(_KMEMUSER)
Index: src/sys/arch/x86/x86/cpu.c
diff -u src/sys/arch/x86/x86/cpu.c:1.80 src/sys/arch/x86/x86/cpu.c:1.81
--- src/sys/arch/x86/x86/cpu.c:1.80 Wed Feb 2 12:26:42 2011
+++ src/sys/arch/x86/x86/cpu.c Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.80 2011/02/02 12:26:42 bouyer Exp $ */
+/* $NetBSD: cpu.c,v 1.81 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.80 2011/02/02 12:26:42 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.81 2011/02/19 13:52:28 jmcneill Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -119,6 +119,9 @@
int cpu_match(device_t, cfdata_t, void *);
void cpu_attach(device_t, device_t, void *);
+int cpu_rescan(device_t, const char *, const int *);
+void cpu_childdetached(device_t, device_t);
+
static bool cpu_suspend(device_t, const pmf_qual_t *);
static bool cpu_resume(device_t, const pmf_qual_t *);
@@ -136,8 +139,8 @@
mp_cpu_start_cleanup };
-CFATTACH_DECL_NEW(cpu, sizeof(struct cpu_softc),
- cpu_match, cpu_attach, NULL, NULL);
+CFATTACH_DECL2_NEW(cpu, sizeof(struct cpu_softc),
+ cpu_match, cpu_attach, NULL, NULL, cpu_rescan, cpu_childdetached);
/*
* Statically-allocated CPU info for the primary CPU (or the only
@@ -445,6 +448,39 @@
#endif
);
}
+
+ cpu_rescan(self, NULL, NULL);
+}
+
+int
+cpu_rescan(device_t self, const char *ifattr, const int *locators)
+{
+ struct cpufeature_attach_args cfaa;
+ struct cpu_softc *sc = device_private(self);
+ struct cpu_info *ci = sc->sc_info;
+
+ memset(&cfaa, 0, sizeof(cfaa));
+ cfaa.ci = ci;
+
+ if (ifattr_match(ifattr, "cpufeaturebus")) {
+ if (ci->ci_padlock == NULL) {
+ cfaa.name = "padlock";
+ ci->ci_padlock = config_found_ia(self,
+ "cpufeaturebus", &cfaa, NULL);
+ }
+ }
+
+ return 0;
+}
+
+void
+cpu_childdetached(device_t self, device_t child)
+{
+ struct cpu_softc *sc = device_private(self);
+ struct cpu_info *ci = sc->sc_info;
+
+ if (ci->ci_padlock == child)
+ ci->ci_padlock = NULL;
}
/*
Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.22 src/sys/arch/x86/x86/identcpu.c:1.23
--- src/sys/arch/x86/x86/identcpu.c:1.22 Thu Jan 27 18:44:40 2011
+++ src/sys/arch/x86/x86/identcpu.c Sat Feb 19 13:52:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: identcpu.c,v 1.22 2011/01/27 18:44:40 bouyer Exp $ */
+/* $NetBSD: identcpu.c,v 1.23 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.22 2011/01/27 18:44:40 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.23 2011/02/19 13:52:28 jmcneill Exp $");
#include "opt_enhanced_speedstep.h"
#include "opt_intel_odcm.h"
@@ -436,7 +436,7 @@
if (lfunc & CPUID_VIA_HAS_RNG) {
if (!(lfunc & CPUID_VIA_DO_RNG)) {
rng_enable++;
- ci->ci_feat_val[4] |= CPUID_VIA_HAS_RNG;
+ ci->ci_feat_val[4] |= CPUID_VIA_DO_RNG;
}
}
/* Check for and enable ACE (AES-CBC) */
Index: src/sys/arch/x86/x86/via_padlock.c
diff -u src/sys/arch/x86/x86/via_padlock.c:1.13 src/sys/arch/x86/x86/via_padlock.c:1.14
--- src/sys/arch/x86/x86/via_padlock.c:1.13 Thu Apr 22 21:47:32 2010
+++ src/sys/arch/x86/x86/via_padlock.c Sat Feb 19 13:52:28 2011
@@ -1,5 +1,5 @@
/* $OpenBSD: via.c,v 1.8 2006/11/17 07:47:56 tom Exp $ */
-/* $NetBSD: via_padlock.c,v 1.13 2010/04/22 21:47:32 jym Exp $ */
+/* $NetBSD: via_padlock.c,v 1.14 2011/02/19 13:52:28 jmcneill Exp $ */
/*-
* Copyright (c) 2003 Jason Wright
@@ -20,20 +20,21 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.13 2010/04/22 21:47:32 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: via_padlock.c,v 1.14 2011/02/19 13:52:28 jmcneill Exp $");
-#include "rnd.h"
-
-#if NRND == 0
-#error padlock requires rnd pseudo-devices
+#ifdef _KERNEL_OPT
+# include "rnd.h"
+# if NRND == 0
+# error padlock requires rnd pseudo-devices
+# endif
#endif
-#include "opt_viapadlock.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/module.h>
#include <sys/rnd.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
@@ -52,9 +53,21 @@
#include <opencrypto/cryptosoft_xform.c>
-#ifdef VIA_PADLOCK
+#include <x86/via_padlock.h>
-char xxx_via_buffer[1024];
+static int via_padlock_match(device_t, cfdata_t, void *);
+static void via_padlock_attach(device_t, device_t, void *);
+static int via_padlock_detach(device_t, int);
+static void via_padlock_attach_intr(device_t);
+
+CFATTACH_DECL_NEW(
+ padlock,
+ sizeof(struct via_padlock_softc),
+ via_padlock_match,
+ via_padlock_attach,
+ via_padlock_detach,
+ NULL
+);
int via_padlock_crypto_newsession(void *, uint32_t *, struct cryptoini *);
int via_padlock_crypto_process(void *, struct cryptop *, int);
@@ -69,7 +82,7 @@
static void
via_c3_rnd(void *arg)
{
- struct via_padlock_softc *vp_sc = arg;
+ struct via_padlock_softc *sc = arg;
unsigned int rv, creg0, len = VIAC3_RNG_BUFSIZ;
static uint32_t buffer[VIAC3_RNG_BUFSIZ + 2]; /* XXX 2? */
@@ -101,29 +114,31 @@
lcr0(creg0);
x86_enable_intr();
kpreempt_enable();
- rnd_add_data(&vp_sc->sc_rnd_source, buffer, len * sizeof(int),
+ rnd_add_data(&sc->sc_rnd_source, buffer, len * sizeof(int),
len * sizeof(int));
- callout_reset(&vp_sc->sc_rnd_co, vp_sc->sc_rnd_hz, via_c3_rnd, vp_sc);
+ callout_reset(&sc->sc_rnd_co, sc->sc_rnd_hz, via_c3_rnd, sc);
}
static void
-via_c3_rnd_init(struct via_padlock_softc *const vp_sc)
+via_c3_rnd_init(struct via_padlock_softc *sc)
{
+ sc->sc_rnd_attached = true;
+
if (hz >= 100) {
- vp_sc->sc_rnd_hz = 10 * hz / 100;
+ sc->sc_rnd_hz = 10 * hz / 100;
} else {
- vp_sc->sc_rnd_hz = 10;
+ sc->sc_rnd_hz = 10;
}
/* See hifn7751.c re use of RND_FLAG_NO_ESTIMATE */
- rnd_attach_source(&vp_sc->sc_rnd_source, "padlock",
+ rnd_attach_source(&sc->sc_rnd_source, device_xname(sc->sc_dev),
RND_TYPE_RNG, RND_FLAG_NO_ESTIMATE);
- callout_init(&vp_sc->sc_rnd_co, 0);
+ callout_init(&sc->sc_rnd_co, 0);
/* Call once to prime the pool early and set callout. */
- via_c3_rnd(vp_sc);
+ via_c3_rnd(sc);
}
static void
-via_c3_ace_init(struct via_padlock_softc *const vp_sc)
+via_c3_ace_init(struct via_padlock_softc *sc)
{
/*
* There is no reason to call into the kernel to use this
@@ -133,13 +148,15 @@
* confusing (however, consider that crypto via unprivileged
* instructions _is_ "just software" in some sense).
*/
- vp_sc->sc_cid = crypto_get_driverid(CRYPTOCAP_F_SOFTWARE);
- if (vp_sc->sc_cid < 0) {
- printf("PadLock: Could not get a crypto driver ID\n");
- free(vp_sc, M_DEVBUF);
+ sc->sc_cid = crypto_get_driverid(CRYPTOCAP_F_SOFTWARE);
+ if (sc->sc_cid < 0) {
+ aprint_error_dev(sc->sc_dev,
+ "could not get a crypto driver ID\n");
return;
}
+ sc->sc_cid_attached = true;
+
/*
* Ask the opencrypto subsystem to register ourselves. Although
* we don't support hardware offloading for various HMAC algorithms,
@@ -160,9 +177,9 @@
* XXX from _us_!
*/
#define REGISTER(alg) \
- crypto_register(vp_sc->sc_cid, alg, 0, 0, \
+ crypto_register(sc->sc_cid, alg, 0, 0, \
via_padlock_crypto_newsession, via_padlock_crypto_freesession, \
- via_padlock_crypto_process, vp_sc);
+ via_padlock_crypto_process, sc);
REGISTER(CRYPTO_AES_CBC);
REGISTER(CRYPTO_MD5_HMAC_96);
@@ -174,36 +191,6 @@
REGISTER(CRYPTO_SHA2_HMAC);
}
-void
-via_padlock_attach(void)
-{
- struct via_padlock_softc *vp_sc;
-
- printf("%s", xxx_via_buffer);
-
- if (!((cpu_feature[4] & CPUID_VIA_HAS_ACE) ||
- (cpu_feature[4] & CPUID_VIA_HAS_RNG))) {
- printf("PadLock: Nothing (%08x ! %08X ! %08X)\n",
- cpu_feature[4], CPUID_VIA_HAS_ACE,
- CPUID_VIA_HAS_RNG);
- return; /* Nothing to see here, move along. */
- }
-
- if ((vp_sc = malloc(sizeof(*vp_sc), M_DEVBUF, M_NOWAIT)) == NULL)
- return;
- memset(vp_sc, 0, sizeof(*vp_sc));
-
- if (cpu_feature[4] & CPUID_VIA_HAS_RNG) {
- via_c3_rnd_init(vp_sc);
- printf("PadLock: RNG attached\n");
- }
-
- if (cpu_feature[4] & CPUID_VIA_HAS_ACE) {
- via_c3_ace_init(vp_sc);
- printf("PadLock: AES-CBC attached\n");
- }
-}
-
int
via_padlock_crypto_newsession(void *arg, uint32_t *sidp, struct cryptoini *cri)
{
@@ -271,12 +258,8 @@
C3_CRYPT_CWLO_KEYGEN_SW |
C3_CRYPT_CWLO_NORMAL;
-#ifdef __NetBSD__
rnd_extract_data(ses->ses_iv, sizeof(ses->ses_iv),
RND_EXTRACT_ANY);
-#else
- get_random_bytes(ses->ses_iv, sizeof(ses->ses_iv));
-#endif
ses->ses_klen = c->cri_klen;
ses->ses_cw0 = cw0;
@@ -382,7 +365,7 @@
{
struct via_padlock_softc *sc = arg;
struct swcr_data *swd;
- struct auth_hash *axf;
+ const struct auth_hash *axf;
int sesn;
uint32_t sid = ((uint32_t)tid) & 0xffffffff;
@@ -597,4 +580,106 @@
return (err);
}
-#endif /* VIA_PADLOCK */
+static int
+via_padlock_match(device_t parent, cfdata_t cf, void *opaque)
+{
+ struct cpufeature_attach_args *cfaa = opaque;
+ struct cpu_info *ci = cfaa->ci;
+
+ if (strcmp(cfaa->name, "padlock") != 0)
+ return 0;
+ if ((cpu_feature[4] & (CPUID_VIA_HAS_ACE|CPUID_VIA_HAS_RNG)) == 0)
+ return 0;
+ if ((ci->ci_flags & (CPUF_BSP|CPUF_SP|CPUF_PRIMARY)) == 0)
+ return 0;
+ return 1;
+}
+
+static void
+via_padlock_attach(device_t parent, device_t self, void *opaque)
+{
+ struct via_padlock_softc *sc = device_private(self);
+
+ sc->sc_dev = self;
+
+ aprint_naive("\n");
+ aprint_normal(": VIA PadLock\n");
+
+ pmf_device_register(self, NULL, NULL);
+
+ config_interrupts(self, via_padlock_attach_intr);
+}
+
+static void
+via_padlock_attach_intr(device_t self)
+{
+ struct via_padlock_softc *sc = device_private(self);
+
+ aprint_normal("%s:", device_xname(self));
+ if (cpu_feature[4] & CPUID_VIA_HAS_RNG) {
+ via_c3_rnd_init(sc);
+ aprint_normal(" RNG");
+ }
+ if (cpu_feature[4] & CPUID_VIA_HAS_ACE) {
+ via_c3_ace_init(sc);
+ aprint_normal(" ACE");
+ }
+ aprint_normal("\n");
+}
+
+static int
+via_padlock_detach(device_t self, int flags)
+{
+ struct via_padlock_softc *sc = device_private(self);
+
+ if (sc->sc_rnd_attached) {
+ callout_stop(&sc->sc_rnd_co);
+ callout_destroy(&sc->sc_rnd_co);
+ rnd_detach_source(&sc->sc_rnd_source);
+ sc->sc_rnd_attached = false;
+ }
+ if (sc->sc_cid_attached) {
+ crypto_unregister(sc->sc_cid, CRYPTO_AES_CBC);
+ crypto_unregister(sc->sc_cid, CRYPTO_MD5_HMAC_96);
+ crypto_unregister(sc->sc_cid, CRYPTO_MD5_HMAC);
+ crypto_unregister(sc->sc_cid, CRYPTO_SHA1_HMAC_96);
+ crypto_unregister(sc->sc_cid, CRYPTO_SHA1_HMAC);
+ crypto_unregister(sc->sc_cid, CRYPTO_RIPEMD160_HMAC_96);
+ crypto_unregister(sc->sc_cid, CRYPTO_RIPEMD160_HMAC);
+ crypto_unregister(sc->sc_cid, CRYPTO_SHA2_HMAC);
+ sc->sc_cid_attached = false;
+ }
+
+ pmf_device_deregister(self);
+
+ return 0;
+}
+
+MODULE(MODULE_CLASS_DRIVER, padlock, NULL);
+
+#ifdef _MODULE
+#include "ioconf.c"
+#endif
+
+static int
+padlock_modcmd(modcmd_t cmd, void *opaque)
+{
+ int error = 0;
+
+ switch (cmd) {
+ case MODULE_CMD_INIT:
+#ifdef _MODULE
+ error = config_init_component(cfdriver_ioconf_padlock,
+ cfattach_ioconf_padlock, cfdata_ioconf_padlock);
+#endif
+ return error;
+ case MODULE_CMD_FINI:
+#ifdef _MODULE
+ error = config_fini_component(cfdriver_ioconf_padlock,
+ cfattach_ioconf_padlock, cfdata_ioconf_padlock);
+#endif
+ return error;
+ default:
+ return ENOTTY;
+ }
+}