Other than intagp, pretty much every agp driver is almost identical,
with only small details differing. Unlike intagp, the ptes are not in a
BAR, but in dma memory. so this diff just repeats every register setting
that we do on attach at resume (including aperture size ones incase this
was reset by PSS, calling that twice on attach is the only functional
change for attach time).

sthen@ has tested this on an x31 (or was it a t31... an old thinkpad
with a radeon and a 855 agp chipset), and it helped out. For one thing
it fixes the ``no X started, suspend, resume, startx, crash'' problem
for him.  All other agp bridges still need testing though.

This diff is NOT in snapshots and will not make release unless it gets a
decent amount of testing, so please test it and let me know what your
results are.

Cheers,
-0-

Index: dev/pci/agp_ali.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_ali.c,v
retrieving revision 1.11
diff -u -p -r1.11 agp_ali.c
--- dev/pci/agp_ali.c   8 Apr 2010 00:23:53 -0000       1.11
+++ dev/pci/agp_ali.c   4 Aug 2010 20:44:40 -0000
@@ -59,6 +59,8 @@ struct agp_ali_softc {
 };
 
 void   agp_ali_attach(struct device *, struct device *, void *);
+int    agp_ali_activate(struct device *, int);
+void   agp_ali_configure(struct agp_ali_softc *);
 int    agp_ali_probe(struct device *, void *, void *);
 bus_size_t agp_ali_get_aperture(void *);
 int    agp_ali_set_aperture(void *sc, bus_size_t);
@@ -67,7 +69,8 @@ void  agp_ali_unbind_page(void *, bus_add
 void   agp_ali_flush_tlb(void *);
 
 struct cfattach aliagp_ca = {
-        sizeof(struct agp_ali_softc), agp_ali_probe, agp_ali_attach
+        sizeof(struct agp_ali_softc), agp_ali_probe, agp_ali_attach,
+            NULL, agp_ali_activate
 };
 
 struct cfdriver aliagp_cd = {
@@ -100,7 +103,6 @@ agp_ali_attach(struct device *parent, st
        struct agp_gatt         *gatt;
        struct agp_attach_args  *aa = aux;
        struct pci_attach_args  *pa = aa->aa_pa;
-       pcireg_t                 reg;
 
        asc->asc_tag = pa->pa_tag;
        asc->asc_pc = pa->pa_pc;
@@ -128,16 +130,7 @@ agp_ali_attach(struct device *parent, st
        }
        asc->gatt = gatt;
 
-       /* Install the gatt. */
-       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE);
-       reg = (reg & 0xff) | gatt->ag_physical;
-       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE, reg);
-       
-       /* Enable the TLB. */
-       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL);
-       reg = (reg & ~0xff) | 0x10;
-       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg);
-
+       agp_ali_configure(asc);
        asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_ali_methods,
            asc->asc_apaddr, asc->asc_apsize, &asc->dev);
        return;
@@ -171,6 +164,46 @@ agp_ali_detach(struct agp_softc *sc)
        return (0);
 }
 #endif
+
+int
+agp_ali_activate(struct device *arg, int act)
+{
+       struct agp_ali_softc *asc = (struct agp_ali_softc *)arg;
+
+       switch (act) {
+       case DVACT_RESUME:
+               /*
+                * all the pte state is in dma memory, so we just need to
+                * put the information back.
+                */
+               agp_ali_configure(asc);
+               break;
+       }
+
+       return (0);
+}
+
+void
+agp_ali_configure(struct agp_ali_softc *asc)
+{
+       pcireg_t                 reg;
+
+       /*
+        * reset size now just in case, if it worked before then sanity
+        * checking will not fail
+        */
+       (void)agp_ali_set_aperture(asc, asc->asc_apsize);
+
+       /* Install the gatt. */
+       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE);
+       reg = (reg & 0xff) | asc->gatt->ag_physical;
+       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_ATTBASE, reg);
+       
+       /* Enable the TLB. */
+       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL);
+       reg = (reg & ~0xff) | 0x10;
+       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_ALI_TLBCTRL, reg);
+}
 
 #define M 1024*1024
 
Index: dev/pci/agp_amd.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_amd.c,v
retrieving revision 1.15
diff -u -p -r1.15 agp_amd.c
--- dev/pci/agp_amd.c   8 Apr 2010 00:23:53 -0000       1.15
+++ dev/pci/agp_amd.c   4 Aug 2010 20:44:34 -0000
@@ -76,6 +76,8 @@ struct agp_amd_softc {
 };
 
 void   agp_amd_attach(struct device *, struct device *, void *);
+int    agp_amd_activate(struct device *, int);
+void   agp_amd_configure(struct agp_amd_softc *);
 int    agp_amd_probe(struct device *, void *, void *);
 bus_size_t agp_amd_get_aperture(void *);
 struct agp_amd_gatt *agp_amd_alloc_gatt(bus_dma_tag_t, bus_size_t);
@@ -85,7 +87,8 @@ void  agp_amd_unbind_page(void *, bus_siz
 void   agp_amd_flush_tlb(void *);
 
 struct cfattach amdagp_ca = {
-       sizeof(struct agp_amd_softc), agp_amd_probe, agp_amd_attach
+       sizeof(struct agp_amd_softc), agp_amd_probe, agp_amd_attach, NULL,
+       agp_amd_activate
 };
 
 struct cfdriver amdagp_cd = {
@@ -183,7 +186,6 @@ agp_amd_attach(struct device *parent, st
        struct agp_attach_args  *aa = aux;
        struct pci_attach_args  *pa = aa->aa_pa;
        struct agp_amd_gatt     *gatt;
-       pcireg_t                 reg;
        int                      error;
 
        asc->asc_pc = pa->pa_pc;
@@ -221,19 +223,7 @@ agp_amd_attach(struct device *parent, st
        }
        asc->gatt = gatt;
 
-       /* Install the gatt. */
-       WRITE4(AGP_AMD751_ATTBASE, gatt->ag_physical);
-
-       /* Enable synchronisation between host and agp. */
-       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL);
-       reg &= ~0x00ff00ff;
-       reg |= (AGP_AMD751_MODECTRL_SYNEN) | (AGP_AMD751_MODECTRL2_GPDCE << 16);
-       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL, reg);
-       /* Enable the TLB and flush */
-       WRITE2(AGP_AMD751_STATUS,
-           READ2(AGP_AMD751_STATUS) | AGP_AMD751_STATUS_GCE);
-       agp_amd_flush_tlb(asc);
-
+       agp_amd_configure(asc);
        asc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_amd_methods,
            asc->asc_apaddr, asc->asc_apsize, &asc->dev);
        return;
@@ -268,6 +258,49 @@ agp_amd_detach(void *sc)
        return (0);
 }
 #endif
+
+int
+agp_amd_activate(struct device *arg, int act)
+{
+       struct agp_amd_softc *asc = (struct agp_amd_softc *)arg;
+
+       switch (act) {
+       case DVACT_RESUME:
+               /*
+                * all the pte state is in dma memory, so we just need to
+                * put the information back.
+                */
+               agp_amd_configure(asc);
+               break;
+       }
+
+       return (0);
+}
+
+void
+agp_amd_configure(struct agp_amd_softc *asc)
+{
+       pcireg_t                 reg;
+
+       /*
+        * reset size now just in case, if it worked before then sanity
+        * checking will not fail
+        */
+       (void)agp_amd_set_aperture(asc, asc->asc_apsize);
+
+       /* Install the gatt. */
+       WRITE4(AGP_AMD751_ATTBASE, asc->gatt->ag_physical);
+
+       /* Enable synchronisation between host and agp. */
+       reg = pci_conf_read(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL);
+       reg &= ~0x00ff00ff;
+       reg |= (AGP_AMD751_MODECTRL_SYNEN) | (AGP_AMD751_MODECTRL2_GPDCE << 16);
+       pci_conf_write(asc->asc_pc, asc->asc_tag, AGP_AMD751_MODECTRL, reg);
+       /* Enable the TLB and flush */
+       WRITE2(AGP_AMD751_STATUS,
+           READ2(AGP_AMD751_STATUS) | AGP_AMD751_STATUS_GCE);
+       agp_amd_flush_tlb(asc);
+}
 
 bus_size_t
 agp_amd_get_aperture(void *sc)
Index: dev/pci/agp_i810.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_i810.c,v
retrieving revision 1.66
diff -u -p -r1.66 agp_i810.c
--- dev/pci/agp_i810.c  27 Jul 2010 21:56:11 -0000      1.66
+++ dev/pci/agp_i810.c  4 Aug 2010 20:17:18 -0000
@@ -90,7 +90,7 @@ struct agp_i810_softc {
 };
 
 void   agp_i810_attach(struct device *, struct device *, void *);
-int    agp_i810_activate(struct device *arg, int act);
+int    agp_i810_activate(struct device *, int);
 void   agp_i810_configure(struct agp_i810_softc *);
 int    agp_i810_probe(struct device *, void *, void *);
 int    agp_i810_get_chiptype(struct pci_attach_args *);
Index: dev/pci/agp_intel.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_intel.c,v
retrieving revision 1.16
diff -u -p -r1.16 agp_intel.c
--- dev/pci/agp_intel.c 8 Apr 2010 00:23:53 -0000       1.16
+++ dev/pci/agp_intel.c 4 Aug 2010 20:45:05 -0000
@@ -67,6 +67,8 @@ struct agp_intel_softc {
 
 
 void   agp_intel_attach(struct device *, struct device *, void *);
+int    agp_intel_activate(struct device *, int);
+void   agp_intel_configure(struct agp_intel_softc *);
 int    agp_intel_probe(struct device *, void *, void *);
 bus_size_t agp_intel_get_aperture(void *);
 int    agp_intel_set_aperture(void *, bus_size_t);
@@ -75,7 +77,8 @@ void  agp_intel_unbind_page(void *, bus_a
 void   agp_intel_flush_tlb(void *);
 
 struct cfattach intelagp_ca = {
-       sizeof(struct agp_intel_softc), agp_intel_probe, agp_intel_attach
+       sizeof(struct agp_intel_softc), agp_intel_probe, agp_intel_attach,
+       NULL, agp_intel_activate
 };
 
 struct cfdriver intelagp_cd = {
@@ -129,7 +132,6 @@ agp_intel_attach(struct device *parent, 
        struct agp_attach_args  *aa = aux;
        struct pci_attach_args  *pa = aa->aa_pa;
        struct agp_gatt         *gatt;
-       pcireg_t                 reg;
        u_int32_t                value;
 
        isc->isc_pc = pa->pa_pc;
@@ -193,9 +195,71 @@ agp_intel_attach(struct device *parent, 
        }
        isc->gatt = gatt;
 
+       agp_intel_configure(isc);
+       
+       isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_intel_methods,
+           isc->isc_apaddr, isc->isc_apsize, &isc->dev);
+       return;
+}
+
+#if 0
+int
+agp_intel_detach(struct agp_softc *sc)
+{
+       int error;
+       pcireg_t reg;
+       struct agp_intel_softc *isc = sc->sc_chipc;
+
+       error = agp_generic_detach(sc);
+       if (error)
+               return (error);
+
+       /* XXX i845/i855PM/i840/i850E */
+       reg = pci_conf_read(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG);
+       reg &= ~(1 << 9);
+       printf("%s: set NBXCFG to %x\n", __FUNCTION__, reg);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG, reg);
+       pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_ATTBASE, 0);
+       AGP_SET_APERTURE(sc, isc->initial_aperture);
+       agp_free_gatt(sc, isc->gatt);
+
+       return (0);
+}
+#endif
+
+int
+agp_intel_activate(struct device *arg, int act)
+{
+       struct agp_intel_softc *isc = (struct agp_intel_softc *)arg;
+
+       switch (act) {
+       case DVACT_RESUME:
+               /*
+                * all the pte state is in dma memory, so we just need to
+                * put the information back.
+                */
+               agp_intel_configure(isc);
+               break;
+       }
+
+       return (0);
+}
+
+
+void
+agp_intel_configure(struct agp_intel_softc *isc)
+{
+       pcireg_t                 reg;
+
+       /*
+        * reset size now just in case, if it worked before then sanity
+        * checking will not fail
+        */
+       (void)agp_intel_set_aperture(isc, isc->isc_apsize);
+
        /* Install the gatt. */
-       pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_ATTBASE,
-           gatt->ag_physical);
+       pci_conf_write(isc->isc_pc, isc->isc_tag, AGP_INTEL_ATTBASE,
+           isc->gatt->ag_physical);
        
        /* Enable the GLTB and setup the control register. */
        switch (isc->chiptype) {
@@ -213,32 +277,38 @@ agp_intel_attach(struct device *parent, 
        switch (isc->chiptype) {
        case CHIP_I845:
        case CHIP_I865:
-               reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG);
+               reg = pci_conf_read(isc->isc_pc, isc->isc_tag,
+                   AGP_I840_MCHCFG);
                reg |= MCHCFG_AAGN;
-               pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG, reg);
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
+                   AGP_I840_MCHCFG, reg);
                break;
        case CHIP_I840:
        case CHIP_I850:
-               reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_AGPCMD);
+               reg = pci_conf_read(isc->isc_pc, isc->isc_tag,
+                   AGP_INTEL_AGPCMD);
                reg |= AGPCMD_AGPEN;
-               pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_AGPCMD,
-                   reg);
-               reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG);
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
+                   AGP_INTEL_AGPCMD, reg);
+               reg = pci_conf_read(isc->isc_pc, isc->isc_tag,
+                   AGP_I840_MCHCFG);
                reg |= MCHCFG_AAGN;
-               pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_I840_MCHCFG,
-                   reg);
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
+                   AGP_I840_MCHCFG, reg);
                break;
        default:
-               reg = pci_conf_read(pa->pa_pc, pa->pa_tag, AGP_INTEL_NBXCFG);
+               reg = pci_conf_read(isc->isc_pc, isc->isc_tag,
+                   AGP_INTEL_NBXCFG);
                reg &= ~NBXCFG_APAE;
                reg |=  NBXCFG_AAGN;
-               pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_NBXCFG, reg);
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
+                   AGP_INTEL_NBXCFG, reg);
        }
 
        /* Clear Error status */
        switch (isc->chiptype) {
        case CHIP_I840:
-               pci_conf_write(pa->pa_pc, pa->pa_tag,
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
                    AGP_INTEL_I8XX_ERRSTS, 0xc000);
                break;
        case CHIP_I845:
@@ -249,38 +319,10 @@ agp_intel_attach(struct device *parent, 
                break;
 
        default:
-               pci_conf_write(pa->pa_pc, pa->pa_tag, AGP_INTEL_ERRSTS, 0x70);
+               pci_conf_write(isc->isc_pc, isc->isc_tag,
+                   AGP_INTEL_ERRSTS, 0x70);
        }
-       
-       isc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_intel_methods,
-           isc->isc_apaddr, isc->isc_apsize, &isc->dev);
-       return;
-}
-
-#if 0
-int
-agp_intel_detach(struct agp_softc *sc)
-{
-       int error;
-       pcireg_t reg;
-       struct agp_intel_softc *isc = sc->sc_chipc;
-
-       error = agp_generic_detach(sc);
-       if (error)
-               return (error);
-
-       /* XXX i845/i855PM/i840/i850E */
-       reg = pci_conf_read(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG);
-       reg &= ~(1 << 9);
-       printf("%s: set NBXCFG to %x\n", __FUNCTION__, reg);
-       pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_NBXCFG, reg);
-       pci_conf_write(sc->sc_pc, sc->sc_tag, AGP_INTEL_ATTBASE, 0);
-       AGP_SET_APERTURE(sc, isc->initial_aperture);
-       agp_free_gatt(sc, isc->gatt);
-
-       return (0);
 }
-#endif
 
 bus_size_t
 agp_intel_get_aperture(void *sc)
Index: dev/pci/agp_sis.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_sis.c,v
retrieving revision 1.14
diff -u -p -r1.14 agp_sis.c
--- dev/pci/agp_sis.c   8 Apr 2010 00:23:53 -0000       1.14
+++ dev/pci/agp_sis.c   4 Aug 2010 20:45:23 -0000
@@ -58,6 +58,8 @@ struct agp_sis_softc {
 };
 
 void   agp_sis_attach(struct device *, struct device *, void *);
+int    agp_sis_activate(struct device *, int);
+void   agp_sis_configure(struct agp_sis_softc *);
 int    agp_sis_probe(struct device *, void *, void *);
 bus_size_t agp_sis_get_aperture(void *);
 int    agp_sis_set_aperture(void *, bus_size_t);
@@ -66,7 +68,8 @@ void  agp_sis_unbind_page(void *, bus_add
 void   agp_sis_flush_tlb(void *);
 
 struct cfattach sisagp_ca = {
-        sizeof(struct agp_sis_softc), agp_sis_probe, agp_sis_attach
+        sizeof(struct agp_sis_softc), agp_sis_probe, agp_sis_attach,
+       NULL, agp_sis_activate
 };
 
 struct cfdriver sisagp_cd = {
@@ -101,7 +104,6 @@ agp_sis_attach(struct device *parent, st
        struct agp_attach_args  *aa = aux;
        struct pci_attach_args  *pa = aa->aa_pa;
        struct agp_gatt         *gatt;
-       pcireg_t                 reg;
 
        if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, AGP_APBASE,
            PCI_MAPREG_TYPE_MEM, &ssc->ssc_apaddr, NULL, NULL) != 0) {
@@ -130,15 +132,7 @@ agp_sis_attach(struct device *parent, st
        }
        ssc->gatt = gatt;
 
-       /* Install the gatt. */
-       pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_ATTBASE,
-           gatt->ag_physical);
-       
-       /* Enable the aperture and auto-tlb-inval */
-       reg = pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL);
-       reg |= (0x05 << 24) | 3;
-       pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL, reg);
-
+       agp_sis_configure(ssc);
        ssc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_sis_methods,
            ssc->ssc_apaddr, ssc->ssc_apsize, &ssc->dev);
        return;
@@ -168,6 +162,46 @@ agp_sis_detach(struct agp_softc *sc)
        return (0);
 }
 #endif
+
+int
+agp_sis_activate(struct device *arg, int act)
+{
+       struct agp_sis_softc *ssc = (struct agp_sis_softc *)arg;
+
+       switch (act) {
+       case DVACT_RESUME:
+               /*
+                * all the pte state is in dma memory, so we just need to
+                * put the information back.
+                */
+               agp_sis_configure(ssc);
+               break;
+       }
+
+       return (0);
+}
+
+void
+agp_sis_configure(struct agp_sis_softc *ssc)
+{
+       pcireg_t                 reg;
+
+       /*
+        * reset size now just in case, if it worked before then sanity
+        * checking will not fail
+        */
+       (void)agp_sis_set_aperture(ssc, ssc->ssc_apsize);
+
+       /* Install the gatt. */
+       pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_ATTBASE,
+           ssc->gatt->ag_physical);
+       
+       /* Enable the aperture and auto-tlb-inval */
+       reg = pci_conf_read(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL);
+       reg |= (0x05 << 24) | 3;
+       pci_conf_write(ssc->ssc_pc, ssc->ssc_tag, AGP_SIS_WINCTRL, reg);
+}
+
 
 bus_size_t
 agp_sis_get_aperture(void *sc)
Index: dev/pci/agp_via.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/agp_via.c,v
retrieving revision 1.15
diff -u -p -r1.15 agp_via.c
--- dev/pci/agp_via.c   8 Apr 2010 00:23:53 -0000       1.15
+++ dev/pci/agp_via.c   4 Aug 2010 20:46:14 -0000
@@ -47,7 +47,20 @@
 
 #include <machine/bus.h>
 
+struct agp_via_softc {
+       struct device            dev;
+       struct agp_softc        *agpdev;
+       struct agp_gatt         *gatt;
+       int                     *regs;
+       pci_chipset_tag_t        vsc_pc;
+       pcitag_t                 vsc_tag;
+       bus_addr_t               vsc_apaddr;
+       bus_size_t               vsc_apsize;
+};
+
 void   agp_via_attach(struct device *, struct device *, void *);
+int    agp_via_activate(struct device *, int);
+void   agp_via_configure(struct agp_via_softc *);
 int    agp_via_probe(struct device *, void *, void *);
 bus_size_t agp_via_get_aperture(void *);
 int    agp_via_set_aperture(void *, bus_size_t);
@@ -61,19 +74,9 @@ const struct agp_methods agp_via_methods
        agp_via_flush_tlb,
 };
 
-struct agp_via_softc {
-       struct device            dev;
-       struct agp_softc        *agpdev;
-       struct agp_gatt         *gatt;
-       int                     *regs;
-       pci_chipset_tag_t        vsc_pc;
-       pcitag_t                 vsc_tag;
-       bus_addr_t               vsc_apaddr;
-       bus_size_t               vsc_apsize;
-};
-
 struct cfattach viaagp_ca = {
-        sizeof(struct agp_via_softc), agp_via_probe, agp_via_attach
+        sizeof(struct agp_via_softc), agp_via_probe, agp_via_attach,
+       NULL, agp_via_activate
 };
 
 struct cfdriver viaagp_cd = {
@@ -159,24 +162,7 @@ agp_via_attach(struct device *parent, st
        }
        vsc->gatt = gatt;
 
-       if (vsc->regs == via_v2_regs) {
-               /* Install the gatt. */
-               pci_conf_write(pa->pa_pc, pa->pa_tag, vsc->regs[REG_ATTBASE],
-                   gatt->ag_physical | 3);
-               /* Enable the aperture. */
-               pci_conf_write(pa->pa_pc, pa->pa_tag, vsc->regs[REG_GARTCTRL],
-                   0x0000000f);
-       } else {
-               pcireg_t gartctrl;
-               /* Install the gatt. */
-               pci_conf_write(pa->pa_pc, pa->pa_tag, vsc->regs[REG_ATTBASE],
-                   gatt->ag_physical);
-               /* Enable the aperture. */
-               gartctrl = pci_conf_read(pa->pa_pc, pa->pa_tag,
-                   vsc->regs[REG_ATTBASE]);
-               pci_conf_write(pa->pa_pc, pa->pa_tag, vsc->regs[REG_GARTCTRL],
-                   gartctrl | (3 << 7));
-       }
+       agp_via_configure(vsc);
        vsc->agpdev = (struct agp_softc *)agp_attach_bus(pa, &agp_via_methods,
            vsc->vsc_apaddr, vsc->vsc_apsize, &vsc->dev);
 
@@ -202,6 +188,54 @@ agp_via_detach(struct agp_softc *sc)
        return (0);
 }
 #endif
+
+int
+agp_via_activate(struct device *arg, int act)
+{
+       struct agp_via_softc *vsc = (struct agp_via_softc *)arg;
+
+       switch (act) {
+       case DVACT_RESUME:
+               /*
+                * all the pte state is in dma memory, so we just need to
+                * put the information back.
+                */
+               agp_via_configure(vsc);
+               break;
+       }
+
+       return (0);
+}
+
+void
+agp_via_configure(struct agp_via_softc *vsc)
+{
+
+       /*
+        * reset size now just in case, if it worked before then sanity
+        * checking will not fail
+        */
+       (void)agp_via_set_aperture(vsc, vsc->vsc_apsize);
+
+       if (vsc->regs == via_v2_regs) {
+               /* Install the gatt. */
+               pci_conf_write(vsc->vsc_pc, vsc->vsc_tag,
+                   vsc->regs[REG_ATTBASE], vsc->gatt->ag_physical | 3);
+               /* Enable the aperture. */
+               pci_conf_write(vsc->vsc_pc, vsc->vsc_tag,
+                   vsc->regs[REG_GARTCTRL], 0x0000000f);
+       } else {
+               pcireg_t gartctrl;
+               /* Install the gatt. */
+               pci_conf_write(vsc->vsc_pc, vsc->vsc_tag,
+                   vsc->regs[REG_ATTBASE], vsc->gatt->ag_physical);
+               /* Enable the aperture. */
+               gartctrl = pci_conf_read(vsc->vsc_pc, vsc->vsc_tag,
+                   vsc->regs[REG_ATTBASE]);
+               pci_conf_write(vsc->vsc_pc, vsc->vsc_tag,
+                   vsc->regs[REG_GARTCTRL], gartctrl | (3 << 7));
+       }
+}
 
 bus_size_t
 agp_via_get_aperture(void *sc)

Reply via email to