diff options
author | John Baldwin <jhb@FreeBSD.org> | 2007-10-30 22:09:16 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2007-10-30 22:09:16 +0000 |
commit | f82a1d49879db9dcbfbf90328fc2e823a79a53a5 (patch) | |
tree | 4bbfaaad51fa35b2a857b9a295ba0233f3be30ff | |
parent | de8f7dcbaede5b279479ec9789b906bf85b20377 (diff) | |
download | src-f82a1d49879db9dcbfbf90328fc2e823a79a53a5.tar.gz src-f82a1d49879db9dcbfbf90328fc2e823a79a53a5.zip |
Split agp_generic_detach() up into two routines: agp_free_cdev() destroys
/dev/agpgart and agp_free_res() frees resources like the BAR for the
aperture. Splitting this up lets chipset-specific detach routines
manipulate the aperture during their detach routines without panicing.
MFC after: 1 week
Reviewed by: anholt
Notes
Notes:
svn path=/head/; revision=173203
-rw-r--r-- | sys/dev/agp/agp.c | 19 | ||||
-rw-r--r-- | sys/dev/agp/agp_ali.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_amd.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_amd64.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_ati.c | 8 | ||||
-rw-r--r-- | sys/dev/agp/agp_i810.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_intel.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_nvidia.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_sis.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agp_via.c | 6 | ||||
-rw-r--r-- | sys/dev/agp/agppriv.h | 2 | ||||
-rw-r--r-- | sys/pci/agp.c | 19 | ||||
-rw-r--r-- | sys/pci/agp_ali.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_amd.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_amd64.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_ati.c | 8 | ||||
-rw-r--r-- | sys/pci/agp_i810.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_intel.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_nvidia.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_sis.c | 6 | ||||
-rw-r--r-- | sys/pci/agp_via.c | 6 | ||||
-rw-r--r-- | sys/pci/agppriv.h | 2 |
22 files changed, 78 insertions, 76 deletions
diff --git a/sys/dev/agp/agp.c b/sys/dev/agp/agp.c index e8e8af07349e..ec0807a24cd3 100644 --- a/sys/dev/agp/agp.c +++ b/sys/dev/agp/agp.c @@ -261,16 +261,31 @@ agp_generic_attach(device_t dev) return 0; } -int -agp_generic_detach(device_t dev) +void +agp_free_cdev(device_t dev) { struct agp_softc *sc = device_get_softc(dev); destroy_dev(sc->as_devnode); +} + +void +agp_free_res(device_t dev) +{ + struct agp_softc *sc = device_get_softc(dev); + bus_release_resource(dev, SYS_RES_MEMORY, sc->as_aperture_rid, sc->as_aperture); mtx_destroy(&sc->as_lock); agp_flush_cache(); +} + +int +agp_generic_detach(device_t dev) +{ + + agp_free_cdev(dev); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agp_ali.c b/sys/dev/agp/agp_ali.c index a619547ace3a..74bd2b1a4b17 100644 --- a/sys/dev/agp/agp_ali.c +++ b/sys/dev/agp/agp_ali.c @@ -141,12 +141,9 @@ static int agp_ali_detach(device_t dev) { struct agp_ali_softc *sc = device_get_softc(dev); - int error; u_int32_t attbase; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the TLB.. */ pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1); @@ -157,6 +154,7 @@ agp_ali_detach(device_t dev) pci_write_config(dev, AGP_ALI_ATTBASE, attbase & 0xfff, 4); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agp_amd.c b/sys/dev/agp/agp_amd.c index 3c9159d4f13d..7c3bd0d4b1b0 100644 --- a/sys/dev/agp/agp_amd.c +++ b/sys/dev/agp/agp_amd.c @@ -277,11 +277,8 @@ static int agp_amd_detach(device_t dev) { struct agp_amd_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the TLB.. */ WRITE2(AGP_AMD751_STATUS, @@ -297,6 +294,7 @@ agp_amd_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_amd_free_gatt(sc->gatt); + agp_free_res(dev); bus_release_resource(dev, SYS_RES_MEMORY, AGP_AMD751_REGISTERS, sc->regs); diff --git a/sys/dev/agp/agp_amd64.c b/sys/dev/agp/agp_amd64.c index 9e5b6e26a28a..7c1a25d75886 100644 --- a/sys/dev/agp/agp_amd64.c +++ b/sys/dev/agp/agp_amd64.c @@ -250,10 +250,9 @@ static int agp_amd64_detach(device_t dev) { struct agp_amd64_softc *sc = device_get_softc(dev); - int i, error; + int i; - if ((error = agp_generic_detach(dev))) - return (error); + agp_free_cdev(dev); for (i = 0; i < sc->n_mctrl; i++) pci_cfgregwrite(0, sc->mctrl[i], 3, AGP_AMD64_APCTRL, @@ -262,6 +261,7 @@ agp_amd64_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/dev/agp/agp_ati.c b/sys/dev/agp/agp_ati.c index 0c3a1197616e..6bc60197aed8 100644 --- a/sys/dev/agp/agp_ati.c +++ b/sys/dev/agp/agp_ati.c @@ -248,18 +248,15 @@ static int agp_ati_detach(device_t dev) { struct agp_ati_softc *sc = device_get_softc(dev); - int error; u_int32_t apsize_reg, temp; + agp_free_cdev(dev); + if (sc->is_rs300) apsize_reg = ATI_RS300_APSIZE; else apsize_reg = ATI_RS100_APSIZE; - error = agp_generic_detach(dev); - if (error) - return error; - /* Clear the GATT base */ WRITE4(ATI_GART_BASE, 0); @@ -273,6 +270,7 @@ agp_ati_detach(device_t dev) free(sc->ag_virtual, M_AGP); bus_release_resource(dev, SYS_RES_MEMORY, ATI_GART_MMADDR, sc->regs); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agp_i810.c b/sys/dev/agp/agp_i810.c index bd72de5d5dee..9e081be480b2 100644 --- a/sys/dev/agp/agp_i810.c +++ b/sys/dev/agp/agp_i810.c @@ -583,11 +583,8 @@ static int agp_i810_detach(device_t dev) { struct agp_i810_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Clear the GATT base. */ if ( sc->chiptype == CHIP_I810 ) { @@ -608,6 +605,7 @@ agp_i810_detach(device_t dev) free(sc->gatt, M_AGP); bus_release_resources(dev, sc->sc_res_spec, sc->sc_res); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agp_intel.c b/sys/dev/agp/agp_intel.c index d30f0d495658..60e0e6f8ad68 100644 --- a/sys/dev/agp/agp_intel.c +++ b/sys/dev/agp/agp_intel.c @@ -262,13 +262,10 @@ agp_intel_detach(device_t dev) { struct agp_intel_softc *sc; u_int32_t reg; - int error; sc = device_get_softc(dev); - error = agp_generic_detach(dev); - if (error) - return (error); + agp_free_cdev(dev); /* Disable aperture accesses. */ switch (pci_get_devid(dev)) { @@ -305,6 +302,7 @@ agp_intel_detach(device_t dev) pci_write_config(dev, AGP_INTEL_ATTBASE, 0, 4); AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/dev/agp/agp_nvidia.c b/sys/dev/agp/agp_nvidia.c index 8e4f35ff7eb9..8e2d243425c6 100644 --- a/sys/dev/agp/agp_nvidia.c +++ b/sys/dev/agp/agp_nvidia.c @@ -247,12 +247,9 @@ static int agp_nvidia_detach (device_t dev) { struct agp_nvidia_softc *sc = device_get_softc(dev); - int error; u_int32_t temp; - error = agp_generic_detach(dev); - if (error) - return (error); + agp_free_cdev(dev); /* GART Control */ temp = pci_read_config(sc->dev, AGP_NVIDIA_0_APSIZE, 4); @@ -270,6 +267,7 @@ agp_nvidia_detach (device_t dev) sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/dev/agp/agp_sis.c b/sys/dev/agp/agp_sis.c index 3915f5d3dd0a..a51514aba561 100644 --- a/sys/dev/agp/agp_sis.c +++ b/sys/dev/agp/agp_sis.c @@ -173,11 +173,8 @@ static int agp_sis_detach(device_t dev) { struct agp_sis_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the aperture.. */ pci_write_config(dev, AGP_SIS_WINCTRL, @@ -190,6 +187,7 @@ agp_sis_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agp_via.c b/sys/dev/agp/agp_via.c index aa6d6407c702..d60f49aef64c 100644 --- a/sys/dev/agp/agp_via.c +++ b/sys/dev/agp/agp_via.c @@ -240,16 +240,14 @@ static int agp_via_detach(device_t dev) { struct agp_via_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); pci_write_config(dev, sc->regs[REG_GARTCTRL], 0, 4); pci_write_config(dev, sc->regs[REG_ATTBASE], 0, 4); AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/dev/agp/agppriv.h b/sys/dev/agp/agppriv.h index 6aa1861ca345..b4c90a053f73 100644 --- a/sys/dev/agp/agppriv.h +++ b/sys/dev/agp/agppriv.h @@ -90,7 +90,9 @@ void agp_flush_cache(void); u_int8_t agp_find_caps(device_t dev); struct agp_gatt *agp_alloc_gatt(device_t dev); void agp_set_aperture_resource(device_t dev, int rid); +void agp_free_cdev(device_t dev); void agp_free_gatt(struct agp_gatt *gatt); +void agp_free_res(device_t dev); int agp_generic_attach(device_t dev); int agp_generic_detach(device_t dev); int agp_generic_get_aperture(device_t dev); diff --git a/sys/pci/agp.c b/sys/pci/agp.c index e8e8af07349e..ec0807a24cd3 100644 --- a/sys/pci/agp.c +++ b/sys/pci/agp.c @@ -261,16 +261,31 @@ agp_generic_attach(device_t dev) return 0; } -int -agp_generic_detach(device_t dev) +void +agp_free_cdev(device_t dev) { struct agp_softc *sc = device_get_softc(dev); destroy_dev(sc->as_devnode); +} + +void +agp_free_res(device_t dev) +{ + struct agp_softc *sc = device_get_softc(dev); + bus_release_resource(dev, SYS_RES_MEMORY, sc->as_aperture_rid, sc->as_aperture); mtx_destroy(&sc->as_lock); agp_flush_cache(); +} + +int +agp_generic_detach(device_t dev) +{ + + agp_free_cdev(dev); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agp_ali.c b/sys/pci/agp_ali.c index a619547ace3a..74bd2b1a4b17 100644 --- a/sys/pci/agp_ali.c +++ b/sys/pci/agp_ali.c @@ -141,12 +141,9 @@ static int agp_ali_detach(device_t dev) { struct agp_ali_softc *sc = device_get_softc(dev); - int error; u_int32_t attbase; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the TLB.. */ pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1); @@ -157,6 +154,7 @@ agp_ali_detach(device_t dev) pci_write_config(dev, AGP_ALI_ATTBASE, attbase & 0xfff, 4); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agp_amd.c b/sys/pci/agp_amd.c index 3c9159d4f13d..7c3bd0d4b1b0 100644 --- a/sys/pci/agp_amd.c +++ b/sys/pci/agp_amd.c @@ -277,11 +277,8 @@ static int agp_amd_detach(device_t dev) { struct agp_amd_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the TLB.. */ WRITE2(AGP_AMD751_STATUS, @@ -297,6 +294,7 @@ agp_amd_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_amd_free_gatt(sc->gatt); + agp_free_res(dev); bus_release_resource(dev, SYS_RES_MEMORY, AGP_AMD751_REGISTERS, sc->regs); diff --git a/sys/pci/agp_amd64.c b/sys/pci/agp_amd64.c index 9e5b6e26a28a..7c1a25d75886 100644 --- a/sys/pci/agp_amd64.c +++ b/sys/pci/agp_amd64.c @@ -250,10 +250,9 @@ static int agp_amd64_detach(device_t dev) { struct agp_amd64_softc *sc = device_get_softc(dev); - int i, error; + int i; - if ((error = agp_generic_detach(dev))) - return (error); + agp_free_cdev(dev); for (i = 0; i < sc->n_mctrl; i++) pci_cfgregwrite(0, sc->mctrl[i], 3, AGP_AMD64_APCTRL, @@ -262,6 +261,7 @@ agp_amd64_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/pci/agp_ati.c b/sys/pci/agp_ati.c index 0c3a1197616e..6bc60197aed8 100644 --- a/sys/pci/agp_ati.c +++ b/sys/pci/agp_ati.c @@ -248,18 +248,15 @@ static int agp_ati_detach(device_t dev) { struct agp_ati_softc *sc = device_get_softc(dev); - int error; u_int32_t apsize_reg, temp; + agp_free_cdev(dev); + if (sc->is_rs300) apsize_reg = ATI_RS300_APSIZE; else apsize_reg = ATI_RS100_APSIZE; - error = agp_generic_detach(dev); - if (error) - return error; - /* Clear the GATT base */ WRITE4(ATI_GART_BASE, 0); @@ -273,6 +270,7 @@ agp_ati_detach(device_t dev) free(sc->ag_virtual, M_AGP); bus_release_resource(dev, SYS_RES_MEMORY, ATI_GART_MMADDR, sc->regs); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agp_i810.c b/sys/pci/agp_i810.c index bd72de5d5dee..9e081be480b2 100644 --- a/sys/pci/agp_i810.c +++ b/sys/pci/agp_i810.c @@ -583,11 +583,8 @@ static int agp_i810_detach(device_t dev) { struct agp_i810_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Clear the GATT base. */ if ( sc->chiptype == CHIP_I810 ) { @@ -608,6 +605,7 @@ agp_i810_detach(device_t dev) free(sc->gatt, M_AGP); bus_release_resources(dev, sc->sc_res_spec, sc->sc_res); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agp_intel.c b/sys/pci/agp_intel.c index d30f0d495658..60e0e6f8ad68 100644 --- a/sys/pci/agp_intel.c +++ b/sys/pci/agp_intel.c @@ -262,13 +262,10 @@ agp_intel_detach(device_t dev) { struct agp_intel_softc *sc; u_int32_t reg; - int error; sc = device_get_softc(dev); - error = agp_generic_detach(dev); - if (error) - return (error); + agp_free_cdev(dev); /* Disable aperture accesses. */ switch (pci_get_devid(dev)) { @@ -305,6 +302,7 @@ agp_intel_detach(device_t dev) pci_write_config(dev, AGP_INTEL_ATTBASE, 0, 4); AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/pci/agp_nvidia.c b/sys/pci/agp_nvidia.c index 8e4f35ff7eb9..8e2d243425c6 100644 --- a/sys/pci/agp_nvidia.c +++ b/sys/pci/agp_nvidia.c @@ -247,12 +247,9 @@ static int agp_nvidia_detach (device_t dev) { struct agp_nvidia_softc *sc = device_get_softc(dev); - int error; u_int32_t temp; - error = agp_generic_detach(dev); - if (error) - return (error); + agp_free_cdev(dev); /* GART Control */ temp = pci_read_config(sc->dev, AGP_NVIDIA_0_APSIZE, 4); @@ -270,6 +267,7 @@ agp_nvidia_detach (device_t dev) sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return (0); } diff --git a/sys/pci/agp_sis.c b/sys/pci/agp_sis.c index 3915f5d3dd0a..a51514aba561 100644 --- a/sys/pci/agp_sis.c +++ b/sys/pci/agp_sis.c @@ -173,11 +173,8 @@ static int agp_sis_detach(device_t dev) { struct agp_sis_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); /* Disable the aperture.. */ pci_write_config(dev, AGP_SIS_WINCTRL, @@ -190,6 +187,7 @@ agp_sis_detach(device_t dev) AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agp_via.c b/sys/pci/agp_via.c index aa6d6407c702..d60f49aef64c 100644 --- a/sys/pci/agp_via.c +++ b/sys/pci/agp_via.c @@ -240,16 +240,14 @@ static int agp_via_detach(device_t dev) { struct agp_via_softc *sc = device_get_softc(dev); - int error; - error = agp_generic_detach(dev); - if (error) - return error; + agp_free_cdev(dev); pci_write_config(dev, sc->regs[REG_GARTCTRL], 0, 4); pci_write_config(dev, sc->regs[REG_ATTBASE], 0, 4); AGP_SET_APERTURE(dev, sc->initial_aperture); agp_free_gatt(sc->gatt); + agp_free_res(dev); return 0; } diff --git a/sys/pci/agppriv.h b/sys/pci/agppriv.h index 6aa1861ca345..b4c90a053f73 100644 --- a/sys/pci/agppriv.h +++ b/sys/pci/agppriv.h @@ -90,7 +90,9 @@ void agp_flush_cache(void); u_int8_t agp_find_caps(device_t dev); struct agp_gatt *agp_alloc_gatt(device_t dev); void agp_set_aperture_resource(device_t dev, int rid); +void agp_free_cdev(device_t dev); void agp_free_gatt(struct agp_gatt *gatt); +void agp_free_res(device_t dev); int agp_generic_attach(device_t dev); int agp_generic_detach(device_t dev); int agp_generic_get_aperture(device_t dev); |