diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c index 138fe4505ab2..a93805575609 100644 --- a/sys/dev/agp/agp.c +++ b/sys/dev/agp/agp.c @@ -531,7 +531,6 @@ static int agp_release_helper(device_t dev, enum agp_acquire_state state) { struct agp_softc *sc = device_get_softc(dev); - struct agp_memory *mem; if (sc->as_state == AGP_ACQUIRE_FREE) return 0; @@ -539,15 +538,6 @@ agp_release_helper(device_t dev, enum agp_acquire_state state) if (sc->as_state != state) return EBUSY; - /* - * Clear out the aperture and free any outstanding memory blocks. - */ - while ((mem = TAILQ_FIRST(&sc->as_memory)) != 0) { - if (mem->am_is_bound) - AGP_UNBIND_MEMORY(dev, mem); - AGP_FREE_MEMORY(dev, mem); - } - sc->as_state = AGP_ACQUIRE_FREE; return 0; } @@ -663,10 +653,16 @@ agp_close(dev_t kdev, int fflag, int devtype, struct thread *td) { device_t dev = KDEV2DEV(kdev); struct agp_softc *sc = device_get_softc(dev); + struct agp_memory *mem; /* * Clear the GATT and force release on last close */ + while ((mem = TAILQ_FIRST(&sc->as_memory)) != 0) { + if (mem->am_is_bound) + AGP_UNBIND_MEMORY(dev, mem); + AGP_FREE_MEMORY(dev, mem); + } if (sc->as_state == AGP_ACQUIRE_USER) agp_release_helper(dev, AGP_ACQUIRE_USER); sc->as_isopen = 0; diff --git a/sys/pci/agp.c b/sys/pci/agp.c index 138fe4505ab2..a93805575609 100644 --- a/sys/pci/agp.c +++ b/sys/pci/agp.c @@ -531,7 +531,6 @@ static int agp_release_helper(device_t dev, enum agp_acquire_state state) { struct agp_softc *sc = device_get_softc(dev); - struct agp_memory *mem; if (sc->as_state == AGP_ACQUIRE_FREE) return 0; @@ -539,15 +538,6 @@ agp_release_helper(device_t dev, enum agp_acquire_state state) if (sc->as_state != state) return EBUSY; - /* - * Clear out the aperture and free any outstanding memory blocks. - */ - while ((mem = TAILQ_FIRST(&sc->as_memory)) != 0) { - if (mem->am_is_bound) - AGP_UNBIND_MEMORY(dev, mem); - AGP_FREE_MEMORY(dev, mem); - } - sc->as_state = AGP_ACQUIRE_FREE; return 0; } @@ -663,10 +653,16 @@ agp_close(dev_t kdev, int fflag, int devtype, struct thread *td) { device_t dev = KDEV2DEV(kdev); struct agp_softc *sc = device_get_softc(dev); + struct agp_memory *mem; /* * Clear the GATT and force release on last close */ + while ((mem = TAILQ_FIRST(&sc->as_memory)) != 0) { + if (mem->am_is_bound) + AGP_UNBIND_MEMORY(dev, mem); + AGP_FREE_MEMORY(dev, mem); + } if (sc->as_state == AGP_ACQUIRE_USER) agp_release_helper(dev, AGP_ACQUIRE_USER); sc->as_isopen = 0;