summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/i386/conf/GENERIC5
-rw-r--r--sys/dev/pci/amdpm.c171
-rw-r--r--sys/dev/pci/amdpmreg.h58
-rw-r--r--sys/dev/pci/files.pci8
-rw-r--r--sys/dev/pci/pcidevs55
5 files changed, 271 insertions, 26 deletions
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index bb206dee270..723e71fc250 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.301 2002/06/03 16:13:16 mickey Exp $
+# $OpenBSD: GENERIC,v 1.302 2002/06/05 22:35:16 mickey Exp $
# $NetBSD: GENERIC,v 1.48 1996/05/20 18:17:23 mrg Exp $
#
# GENERIC -- everything that's currently supported
@@ -57,6 +57,9 @@ pci* at ppb? bus ?
pci* at pchb? bus ?
pcib* at pci? dev ? function ? # PCI-ISA bridge
+# power management and other environmental stuff
+#amdpm* at pci? dev ? function ? # AMD768MPX
+
# ISA PCMCIA controllers
#option PCMCIAVERBOSE
pcic0 at isa? port 0x3e0 iomem 0xd0000 iosiz 0x10000
diff --git a/sys/dev/pci/amdpm.c b/sys/dev/pci/amdpm.c
new file mode 100644
index 00000000000..6c5e5f3ed0e
--- /dev/null
+++ b/sys/dev/pci/amdpm.c
@@ -0,0 +1,171 @@
+/* $OpenBSD: amdpm.c,v 1.1 2002/06/05 22:35:16 mickey Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Enami Tsugutomo.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/timeout.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/rndvar.h>
+#include <dev/pci/amdpmreg.h>
+
+struct amdpm_softc {
+ struct device sc_dev;
+
+ pci_chipset_tag_t sc_pc;
+ pcitag_t sc_tag;
+
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh; /* PMxx space */
+
+ struct timeout sc_rnd_ch;
+#ifdef AMDPM_RND_COUNTERS
+ struct evcnt sc_rnd_hits;
+ struct evcnt sc_rnd_miss;
+ struct evcnt sc_rnd_data[256];
+#endif
+};
+
+int amdpm_match(struct device *, void *, void *);
+void amdpm_attach(struct device *, struct device *, void *);
+void amdpm_rnd_callout(void *);
+
+struct cfattach amdpm_ca = {
+ sizeof(struct amdpm_softc), amdpm_match, amdpm_attach
+};
+
+#ifdef AMDPM_RND_COUNTERS
+#define AMDPM_RNDCNT_INCR(ev) (ev)->ev_count++
+#else
+#define AMDPM_RNDCNT_INCR(ev) /* nothing */
+#endif
+
+int
+amdpm_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_PBC768_PMC)
+ return (1);
+ return (0);
+}
+
+void
+amdpm_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct amdpm_softc *sc = (struct amdpm_softc *) self;
+ struct pci_attach_args *pa = aux;
+ pcireg_t reg;
+ u_int32_t pmreg;
+ int i;
+
+ sc->sc_pc = pa->pa_pc;
+ sc->sc_tag = pa->pa_tag;
+ sc->sc_iot = pa->pa_iot;
+
+ reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMDPM_CONFREG);
+ if ((reg & AMDPM_PMIOEN) == 0) {
+ printf(": PMxx space isn't enabled\n");
+ return;
+ }
+ reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMDPM_PMPTR);
+ if (bus_space_map(sc->sc_iot, AMDPM_PMBASE(reg), AMDPM_PMSIZE,
+ 0, &sc->sc_ioh)) {
+ printf(": failed to map PMxx space\n");
+ return;
+ }
+
+ reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AMDPM_CONFREG);
+ if (reg & AMDPM_RNGEN) {
+ /* Check to see if we can read data from the RNG. */
+ (void) bus_space_read_4(sc->sc_iot, sc->sc_ioh,
+ AMDPM_RNGDATA);
+ for (i = 0; i < 1000; i++) {
+ pmreg = bus_space_read_4(sc->sc_iot,
+ sc->sc_ioh, AMDPM_RNGSTAT);
+ if (pmreg & AMDPM_RNGDONE)
+ break;
+ delay(1);
+ }
+ if ((pmreg & AMDPM_RNGDONE) != 0) {
+ printf(": rng active (apprx. %dms)\n", i);
+ timeout_set(&sc->sc_rnd_ch, amdpm_rnd_callout, sc);
+#ifdef AMDPM_RND_COUNTERS
+ evcnt_attach_dynamic(&sc->sc_rnd_hits, EVCNT_TYPE_MISC,
+ NULL, sc->sc_dev.dv_xname, "rnd hits");
+ evcnt_attach_dynamic(&sc->sc_rnd_miss, EVCNT_TYPE_MISC,
+ NULL, sc->sc_dev.dv_xname, "rnd miss");
+ for (i = 0; i < 256; i++) {
+ evcnt_attach_dynamic(&sc->sc_rnd_data[i],
+ EVCNT_TYPE_MISC, NULL, sc->sc_dev.dv_xname,
+ "rnd data");
+ }
+#endif
+ amdpm_rnd_callout(sc);
+ }
+ }
+}
+
+void
+amdpm_rnd_callout(void *v)
+{
+ struct amdpm_softc *sc = v;
+ u_int32_t reg;
+#ifdef AMDPM_RND_COUNTERS
+ int i;
+#endif
+
+ if ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, AMDPM_RNGSTAT) &
+ AMDPM_RNGDONE) != 0) {
+ reg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, AMDPM_RNGDATA);
+ add_true_randomness(reg);
+#ifdef AMDPM_RND_COUNTERS
+ AMDPM_RNDCNT_INCR(&sc->sc_rnd_hits);
+ for (i = 0; i < sizeof(reg); i++, reg >>= NBBY)
+ AMDPM_RNDCNT_INCR(&sc->sc_rnd_data[reg & 0xff]);
+#endif
+ } else
+ AMDPM_RNDCNT_INCR(&sc->sc_rnd_miss);
+ timeout_add(&sc->sc_rnd_ch, 1);
+}
diff --git a/sys/dev/pci/amdpmreg.h b/sys/dev/pci/amdpmreg.h
new file mode 100644
index 00000000000..f44a2db31c4
--- /dev/null
+++ b/sys/dev/pci/amdpmreg.h
@@ -0,0 +1,58 @@
+/* $NetBSD$ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Enami Tsugutomo.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define AMDPM_CONFREG 0x40
+
+/* 0x40: General Configuration 1 Register */
+#define AMDPM_RNGEN 0x00000080 /* random number generator enable */
+
+/* 0x41: General Configuration 2 Register */
+#define AMDPM_PMIOEN 0x00008000 /* system management IO space enable */
+
+/* 0x42: SCI Interrupt Configuration Register */
+/* 0x43: Previous Power State Register */
+
+#define AMDPM_PMPTR 0x58 /* PMxx System Management IO space
+ Pointer */
+#define AMDPM_PMBASE(x) ((x) & 0xff00) /* PMxx base address */
+#define AMDPM_PMSIZE 256 /* PMxx space size */
+
+/* Registers in PMxx space */
+#define AMDPM_RNGDATA 0xf0 /* 32 bit random data register */
+#define AMDPM_RNGSTAT 0xf4 /* RNG status register */
+#define AMDPM_RNGDONE 0x00000001 /* Random number generation complete */
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci
index e0e00ec18ca..be283d5efa6 100644
--- a/sys/dev/pci/files.pci
+++ b/sys/dev/pci/files.pci
@@ -1,4 +1,4 @@
-# $OpenBSD: files.pci,v 1.136 2002/06/03 16:13:21 mickey Exp $
+# $OpenBSD: files.pci,v 1.137 2002/06/05 22:35:16 mickey Exp $
# $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $
#
# Config file and device description for machine-independent PCI code.
@@ -441,3 +441,9 @@ file dev/pci/if_stge.c stge
device gx: ether, ifnet, mii, ifmedia, mii_phy
attach gx at pci
file dev/pci/if_gx.c gx
+
+# AMD 768MPX power management controller
+device amdpm {}
+attach amdpm at pci
+file dev/pci/amdpm.c amdpm
+
diff --git a/sys/dev/pci/pcidevs b/sys/dev/pci/pcidevs
index 4cad621f57a..8b12051b49e 100644
--- a/sys/dev/pci/pcidevs
+++ b/sys/dev/pci/pcidevs
@@ -1,4 +1,4 @@
- $OpenBSD: pcidevs,v 1.516 2002/06/03 21:48:31 mickey Exp $
+ $OpenBSD: pcidevs,v 1.517 2002/06/05 22:35:16 mickey Exp $
/* $NetBSD: pcidevs,v 1.30 1997/06/24 06:20:24 thorpej Exp $ */
/*
@@ -780,32 +780,39 @@ product ALTEON BCM5701 0x0004 BCM5701 (Broadcom)
product ALTIMA AC100X 0x03e8 AC100X
/* AMD products */
-product AMD PCNET_PCI 0x2000 79c970 PCnet-PCI LANCE
-product AMD PCHOME_PCI 0x2001 79c978 PChome-PCI LANCE
-product AMD PCSCSI_PCI 0x2020 53c974 PCscsi-PCI SCSI
-product AMD PCNETS_PCI 0x2040 79C974 PCnet-PCI Ether+SCSI
-product AMD ELANSC520 0x3000 ElanSC520 Host-PCI
+product AMD PCNET_PCI 0x2000 79c970 PCnet-PCI LANCE
+product AMD PCHOME_PCI 0x2001 79c978 PChome-PCI LANCE
+product AMD PCSCSI_PCI 0x2020 53c974 PCscsi-PCI SCSI
+product AMD PCNETS_PCI 0x2040 79C974 PCnet-PCI Ether+SCSI
+product AMD ELANSC520 0x3000 ElanSC520 Host-PCI
/* http://www.amd.com/products/cpg/athlon/techdocs/pdf/21910.pdf */
-product AMD SC751_SC 0x7006 751 System Controller
-product AMD SC751_PPB 0x7007 751 PCI-PCI
+product AMD SC751_SC 0x7006 751 System Controller
+product AMD SC751_PPB 0x7007 751 PCI-PCI
/* http://www.amd.com/products/cpg/athlon/techdocs/pdf/24462.pdf */
-product AMD 762_PCHB 0x700c 762 Host-PCI
-product AMD 762_PPB 0x700d 762 PCI-PCI
-product AMD 761_PCHB 0x700e 761 Host-PCI
-product AMD 761_PPB 0x700f 761 PCI-PCI
-product AMD 755_ISA 0x7400 755 PCI-ISA
-product AMD 755_IDE 0x7401 755 IDE
-product AMD 755_PMC 0x7403 755 Power Mgmt
-product AMD 755_USB 0x7404 755 USB
+product AMD 762_PCHB 0x700c 762 Host-PCI
+product AMD 762_PPB 0x700d 762 PCI-PCI
+product AMD 761_PCHB 0x700e 761 Host-PCI
+product AMD 761_PPB 0x700f 761 PCI-PCI
+product AMD 755_ISA 0x7400 755 PCI-ISA
+product AMD 755_IDE 0x7401 755 IDE
+product AMD 755_PMC 0x7403 755 Power Mgmt
+product AMD 755_USB 0x7404 755 USB
/* http://www.amd.com/products/cpg/athlon/techdocs/pdf/22548.pdf */
-product AMD PBC756_ISA 0x7408 756 PCI-ISA
-product AMD PBC756_IDE 0x7409 756 IDE
-product AMD PBC756_PMC 0x740b 756 Power Mgmt
-product AMD PBC756_USB 0x740c 756 USB Host
-product AMD 766_ISA 0x7410 766 PCI-ISA
-product AMD 766_IDE 0x7411 766 IDE
-product AMD 766_USB 0x7412 766 USB
-product AMD 766_PMC 0x7413 766 Power Mgmt
+product AMD PBC756_ISA 0x7408 756 PCI-ISA
+product AMD PBC756_IDE 0x7409 756 IDE
+product AMD PBC756_PMC 0x740b 756 Power Mgmt
+product AMD PBC756_USB 0x740c 756 USB Host
+product AMD 766_ISA 0x7410 766 PCI-ISA
+product AMD 766_IDE 0x7411 766 IDE
+product AMD 766_USB 0x7412 766 USB
+product AMD 766_PMC 0x7413 766 Power Mgmt
+product AMD PBC768_ISA 0x7440 768 PCI-ISA
+product AMD PBC768_IDE 0x7441 768 IDE
+product AMD PBC768_PMC 0x7443 768 Power Mgmt
+product AMD PBC768_AC 0x7445 768 AC97 Audio
+product AMD PBC768_MD 0x7446 768 AC97 Modem
+product AMD PBC768_PPB 0x7448 768 PCI-PCI
+product AMD PBC768_USB 0x7449 768 USB
/* AMI */
product AMI MEGARAID 0x1960 MegaRAID