ecc: Implement detach and shutdown methods
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 19 Jan 2015 13:30:04 +0000 (21:30 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 20 Jan 2015 01:56:48 +0000 (09:56 +0800)
While I'm here, clean up indentation.

sys/dev/misc/ecc/ecc_amd8000.c
sys/dev/misc/ecc/ecc_e31200.c
sys/dev/misc/ecc/ecc_x3400.c

index f8acf3f..2263b87 100644 (file)
@@ -63,8 +63,12 @@ struct ecc_amd8000_softc {
        device_printf((sc)->ecc_mydev, fmt , ##arg)
 
 static void    ecc_amd8000_callout(void *);
+static void    ecc_amd8000_stop(device_t);
+
 static int     ecc_amd8000_probe(device_t);
 static int     ecc_amd8000_attach(device_t);
+static int     ecc_amd8000_detach(device_t);
+static void    ecc_amd8000_shutdown(device_t);
 
 static const struct ecc_amd8000_memctrl ecc_memctrls[] = {
        { 0x1022, 0x1100, "AMD 8000 memory controller" },
@@ -76,7 +80,8 @@ static device_method_t ecc_amd8000_methods[] = {
         /* Device interface */
        DEVMETHOD(device_probe,         ecc_amd8000_probe),
        DEVMETHOD(device_attach,        ecc_amd8000_attach),
-       DEVMETHOD(device_shutdown,      bus_generic_shutdown),
+       DEVMETHOD(device_detach,        ecc_amd8000_detach),
+       DEVMETHOD(device_shutdown,      ecc_amd8000_shutdown),
        DEVMETHOD(device_suspend,       bus_generic_suspend),
        DEVMETHOD(device_resume,        bus_generic_resume),
        DEVMETHOD_END
@@ -120,6 +125,8 @@ ecc_amd8000_attach(device_t dev)
        uint32_t draminfo, eccinfo;
        int bus, slot, poll = 0;
 
+       callout_init_mp(&sc->ecc_callout);
+
        dev = sc->ecc_device; /* XXX */
 
        bus = pci_get_bus(dev);
@@ -167,7 +174,6 @@ ecc_amd8000_attach(device_t dev)
                v32 &= 0x7F801EFC;
                pcib_write_config(dev, bus, slot, 3, 0x4C, v32, 4);
 
-               callout_init_mp(&sc->ecc_callout);
                callout_reset(&sc->ecc_callout, hz, ecc_amd8000_callout, sc);
        }
        return (0);
@@ -200,3 +206,24 @@ ecc_amd8000_callout(void *xsc)
        }
        callout_reset(&sc->ecc_callout, hz, ecc_amd8000_callout, sc);
 }
+
+static void
+ecc_amd8000_stop(device_t dev)
+{
+       struct ecc_amd8000_softc *sc = device_get_softc(dev);
+
+       callout_stop_sync(&sc->ecc_callout);
+}
+
+static int
+ecc_amd8000_detach(device_t dev)
+{
+       ecc_amd8000_stop(dev);
+       return 0;
+}
+
+static void
+ecc_amd8000_shutdown(device_t dev)
+{
+       ecc_amd8000_stop(dev);
+}
index f90b8aa..4db3d2c 100644 (file)
@@ -77,6 +77,8 @@ struct ecc_e31200_softc {
 
 static int     ecc_e31200_probe(device_t);
 static int     ecc_e31200_attach(device_t);
+static int     ecc_e31200_detach(device_t);
+static void    ecc_e31200_shutdown(device_t);
 
 static void    ecc_e31200_chaninfo(struct ecc_e31200_softc *, uint32_t,
                    const char *);
@@ -97,13 +99,14 @@ static const struct ecc_e31200_memctrl ecc_memctrls[] = {
 };
 
 static device_method_t ecc_e31200_methods[] = {
-        /* Device interface */
-        DEVMETHOD(device_probe,                ecc_e31200_probe),
-        DEVMETHOD(device_attach,       ecc_e31200_attach),
-        DEVMETHOD(device_shutdown,     bus_generic_shutdown),
-        DEVMETHOD(device_suspend,      bus_generic_suspend),
-        DEVMETHOD(device_resume,       bus_generic_resume),
-        DEVMETHOD_END
+       /* Device interface */
+       DEVMETHOD(device_probe,         ecc_e31200_probe),
+       DEVMETHOD(device_attach,        ecc_e31200_attach),
+       DEVMETHOD(device_detach,        ecc_e31200_detach),
+       DEVMETHOD(device_shutdown,      ecc_e31200_shutdown),
+       DEVMETHOD(device_suspend,       bus_generic_suspend),
+       DEVMETHOD(device_resume,        bus_generic_resume),
+       DEVMETHOD_END
 };
 
 static driver_t ecc_e31200_driver = {
@@ -146,6 +149,8 @@ ecc_e31200_attach(device_t dev)
        uint64_t mch_bar;
        int bus, slot, dmfc_parsed = 1;
 
+       callout_init_mp(&sc->ecc_callout);
+
        dev = sc->ecc_device; /* XXX */
 
        bus = pci_get_bus(dev);
@@ -275,6 +280,7 @@ ecc_e31200_attach(device_t dev)
                if (!ecc_active) {
                        pmap_unmapdev((vm_offset_t)sc->ecc_addr,
                            MCH_E31200_SIZE);
+                       sc->ecc_addr = NULL;
                        return 0;
                }
        } else {
@@ -282,7 +288,6 @@ ecc_e31200_attach(device_t dev)
        }
 
        ecc_e31200_status(sc);
-       callout_init_mp(&sc->ecc_callout);
        callout_reset(&sc->ecc_callout, hz, ecc_e31200_callout, sc);
 
        return 0;
@@ -417,3 +422,22 @@ ecc_e31200_errlog_ch(struct ecc_e31200_softc *sc,
            __SHIFTOUT(err1, MCH_E31200_ERRLOG1_ERRROW),
            __SHIFTOUT(err1, MCH_E31200_ERRLOG1_ERRCOL));
 }
+
+static int
+ecc_e31200_detach(device_t dev)
+{
+       struct ecc_e31200_softc *sc = device_get_softc(dev);
+
+       callout_stop_sync(&sc->ecc_callout);
+       if (sc->ecc_addr != NULL)
+               pmap_unmapdev((vm_offset_t)sc->ecc_addr, MCH_E31200_SIZE);
+       return 0;
+}
+
+static void
+ecc_e31200_shutdown(device_t dev)
+{
+       struct ecc_e31200_softc *sc = device_get_softc(dev);
+
+       callout_stop_sync(&sc->ecc_callout);
+}
index 9b00080..070e50e 100644 (file)
@@ -85,10 +85,13 @@ struct ecc_x3400_softc {
 
 static int     ecc_x3400_probe(device_t);
 static int     ecc_x3400_attach(device_t);
+static int     ecc_x3400_detach(device_t);
+static void    ecc_x3400_shutdown(device_t);
 
 static void    ecc_x3400_status(struct ecc_x3400_softc *);
 static void    ecc_x3400_status_ch(struct ecc_x3400_softc *, int, int);
 static void    ecc_x3400_callout(void *);
+static void    ecc_x3400_stop(device_t);
 
 static const struct ecc_x3400_memctrl ecc_memctrls[] = {
        { 0x8086, 0xd130, "Intel X3400 memory controller" },
@@ -96,13 +99,14 @@ static const struct ecc_x3400_memctrl ecc_memctrls[] = {
 };
 
 static device_method_t ecc_x3400_methods[] = {
-        /* Device interface */
-        DEVMETHOD(device_probe,                ecc_x3400_probe),
-        DEVMETHOD(device_attach,       ecc_x3400_attach),
-        DEVMETHOD(device_shutdown,     bus_generic_shutdown),
-        DEVMETHOD(device_suspend,      bus_generic_suspend),
-        DEVMETHOD(device_resume,       bus_generic_resume),
-        DEVMETHOD_END
+       /* Device interface */
+       DEVMETHOD(device_probe,         ecc_x3400_probe),
+       DEVMETHOD(device_attach,        ecc_x3400_attach),
+       DEVMETHOD(device_detach,        ecc_x3400_detach),
+       DEVMETHOD(device_shutdown,      ecc_x3400_shutdown),
+       DEVMETHOD(device_suspend,       bus_generic_suspend),
+       DEVMETHOD(device_resume,        bus_generic_resume),
+       DEVMETHOD_END
 };
 
 static driver_t ecc_x3400_driver = {
@@ -150,6 +154,8 @@ ecc_x3400_attach(device_t dev)
        struct ecc_x3400_softc *sc = device_get_softc(dev);
        uint32_t val, dimms;
 
+       callout_init_mp(&sc->ecc_callout);
+
        val = MC_READ_4(PCI_X3400UC_MC_CTRL);
        if ((val & PCI_X3400UC_MC_CTRL_ECCEN) == 0) {
                device_printf(dev, "ECC checking is not enabled\n");
@@ -167,7 +173,6 @@ ecc_x3400_attach(device_t dev)
        sc->ecc_dimms = dimms + 1;
        device_printf(dev, "max dimms %d\n", sc->ecc_dimms);
 
-       callout_init_mp(&sc->ecc_callout);
        callout_reset(&sc->ecc_callout, hz, ecc_x3400_callout, sc);
 
        return 0;
@@ -267,3 +272,24 @@ ecc_x3400_status_ch(struct ecc_x3400_softc *sc, int ofs, int idx)
 
        MCT2_WRITE_4(ofs, 0);
 }
+
+static void
+ecc_x3400_stop(device_t dev)
+{
+       struct ecc_x3400_softc *sc = device_get_softc(dev);
+
+       callout_stop_sync(&sc->ecc_callout);
+}
+
+static int
+ecc_x3400_detach(device_t dev)
+{
+       ecc_x3400_stop(dev);
+       return 0;
+}
+
+static void
+ecc_x3400_shutdown(device_t dev)
+{
+       ecc_x3400_stop(dev);
+}