Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic tco(4): Use a subregion of the PMC registers for ...



details:   https://anonhg.NetBSD.org/src/rev/3e3888d46ce3
branches:  trunk
changeset: 370645:3e3888d46ce3
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Sep 22 14:42:47 2022 +0000

description:
tco(4): Use a subregion of the PMC registers for TCO registers.

This is an intermediate step that will let us decouple it from access
via PMBASE.

diffstat:

 sys/arch/x86/pci/tco.c    |  62 ++++++++++++++++++++++++++++++++--------------
 sys/dev/ic/i82801lpcreg.h |   3 +-
 2 files changed, 45 insertions(+), 20 deletions(-)

diffs (169 lines):

diff -r 1cb4df49b726 -r 3e3888d46ce3 sys/arch/x86/pci/tco.c
--- a/sys/arch/x86/pci/tco.c    Thu Sep 22 14:42:29 2022 +0000
+++ b/sys/arch/x86/pci/tco.c    Thu Sep 22 14:42:47 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tco.c,v 1.7 2022/09/22 14:42:29 riastradh Exp $        */
+/*     $NetBSD: tco.c,v 1.8 2022/09/22 14:42:47 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tco.c,v 1.7 2022/09/22 14:42:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tco.c,v 1.8 2022/09/22 14:42:47 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -60,10 +60,13 @@
        bus_space_tag_t         sc_rcbat;
        bus_space_handle_t      sc_rcbah;
        struct pcib_softc *     sc_pcib;
+       bus_space_tag_t         sc_tcot;
+       bus_space_handle_t      sc_tcoh;
        int                     sc_armed;
        unsigned int            sc_min_t;
        unsigned int            sc_max_t;
        int                     sc_version;
+       bool                    sc_attached;
 };
 
 static int tco_match(device_t, cfdata_t, void *);
@@ -122,6 +125,13 @@
        aprint_normal(": TCO (watchdog) timer configured.\n");
        aprint_naive("\n");
 
+       sc->sc_tcot = sc->sc_pmt;
+       if (bus_space_subregion(sc->sc_pmt, sc->sc_pmh, PMC_TCO_BASE,
+               TCO_REGSIZE, &sc->sc_tcoh)) {
+               aprint_error_dev(self, "failed to map TCO registers\n");
+               return;
+       }
+
        /* Explicitly stop the TCO timer. */
        tcotimer_stop(sc);
 
@@ -183,6 +193,8 @@
 
        if (!pmf_device_register(self, tco_suspend, NULL))
                aprint_error_dev(self, "unable to register with pmf\n");
+
+       sc->sc_attached = true;
 }
 
 static int
@@ -191,6 +203,9 @@
        struct tco_softc *sc = device_private(self);
        int rc;
 
+       if (!sc->sc_attached)
+               return 0;
+
        if ((rc = sysmon_wdog_unregister(&sc->sc_smw)) != 0) {
                if (rc == ERESTART)
                        rc = EINTR;
@@ -243,19 +258,19 @@
                switch (sc->sc_version) {
                case TCO_VERSION_RCBA:
                        /* ICH6 or newer */
-                       ich6period = bus_space_read_2(sc->sc_pmt, sc->sc_pmh,
-                           PMC_TCO_TMR2);
+                       ich6period = bus_space_read_2(sc->sc_tcot, sc->sc_tcoh,
+                           PMC_TCO_TMR2 - PMC_TCO_BASE);
                        ich6period &= 0xfc00;
-                       bus_space_write_2(sc->sc_pmt, sc->sc_pmh,
-                           PMC_TCO_TMR2, ich6period | period);
+                       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+                           PMC_TCO_TMR2 - PMC_TCO_BASE, ich6period | period);
                        break;
                case TCO_VERSION_PCIB:
                        /* ICH5 or older */
-                       ich5period = bus_space_read_1(sc->sc_pmt, sc->sc_pmh,
-                           PMC_TCO_TMR);
+                       ich5period = bus_space_read_1(sc->sc_tcot, sc->sc_tcoh,
+                           PMC_TCO_TMR - PMC_TCO_BASE);
                        ich5period &= 0xc0;
-                       bus_space_write_1(sc->sc_pmt, sc->sc_pmh,
-                           PMC_TCO_TMR, ich5period | period);
+                       bus_space_write_1(sc->sc_tcot, sc->sc_tcoh,
+                           PMC_TCO_TMR - PMC_TCO_BASE, ich5period | period);
                        break;
                }
 
@@ -275,10 +290,12 @@
        /* any value is allowed */
        switch (sc->sc_version) {
        case TCO_VERSION_RCBA:
-               bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO_RLD, 1);
+               bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+                   PMC_TCO_RLD - PMC_TCO_BASE, 1);
                break;
        case TCO_VERSION_PCIB:
-               bus_space_write_1(sc->sc_pmt, sc->sc_pmh, PMC_TCO_RLD, 1);
+               bus_space_write_1(sc->sc_tcot, sc->sc_tcoh,
+                   PMC_TCO_RLD - PMC_TCO_BASE, 1);
                break;
        }
 
@@ -290,9 +307,11 @@
 {
        uint16_t ioreg;
 
-       ioreg = bus_space_read_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO1_CNT);
+       ioreg = bus_space_read_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO1_CNT - PMC_TCO_BASE);
        ioreg |= PMC_TCO1_CNT_TCO_TMR_HLT;
-       bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO1_CNT, ioreg);
+       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO1_CNT - PMC_TCO_BASE, ioreg);
 }
 
 static void
@@ -300,19 +319,24 @@
 {
        uint16_t ioreg;
 
-       ioreg = bus_space_read_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO1_CNT);
+       ioreg = bus_space_read_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO1_CNT - PMC_TCO_BASE);
        ioreg &= ~PMC_TCO1_CNT_TCO_TMR_HLT;
-       bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO1_CNT, ioreg);
+       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO1_CNT - PMC_TCO_BASE, ioreg);
 }
 
 static void
 tcotimer_status_reset(struct tco_softc *sc)
 {
-       bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO1_STS,
+       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO1_STS - PMC_TCO_BASE,
            PMC_TCO1_STS_TIMEOUT);
-       bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO2_STS,
+       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO2_STS - PMC_TCO_BASE,
            PMC_TCO2_STS_BOOT_STS);
-       bus_space_write_2(sc->sc_pmt, sc->sc_pmh, PMC_TCO2_STS,
+       bus_space_write_2(sc->sc_tcot, sc->sc_tcoh,
+           PMC_TCO2_STS - PMC_TCO_BASE,
            PMC_TCO2_STS_SECONDS_TO_STS);
 }
 
diff -r 1cb4df49b726 -r 3e3888d46ce3 sys/dev/ic/i82801lpcreg.h
--- a/sys/dev/ic/i82801lpcreg.h Thu Sep 22 14:42:29 2022 +0000
+++ b/sys/dev/ic/i82801lpcreg.h Thu Sep 22 14:42:47 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i82801lpcreg.h,v 1.13 2022/09/22 14:42:09 riastradh Exp $      */
+/*     $NetBSD: i82801lpcreg.h,v 1.14 2022/09/22 14:42:47 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -278,6 +278,7 @@
 #define PMC_TCO_MESSAGE2       (PMC_TCO_BASE+0x0d)
 #define PMC_TCO_WDSTATUS       (PMC_TCO_BASE+0x0e)
 #define PMC_SW_IRQ_GEN         (PMC_TCO_BASE+0x10)
+#define        TCO_REGSIZE             0x20
 
 /*
  * TCO timer tick.  ICH datasheets say:



Home | Main Index | Thread Index | Old Index