agp: Remove support for pre-amd64 ALI, AMD, ATI and Nvidia chipsets
authorFrançois Tigeot <ftigeot@wolfpond.org>
Fri, 8 May 2015 12:14:01 +0000 (14:14 +0200)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Fri, 8 May 2015 12:15:14 +0000 (14:15 +0200)
These chipsets were paired with i386-only CPUs and thus have no
chance of ever being used on DragonFly anymore.

sys/conf/files
sys/dev/agp/Makefile
sys/dev/agp/agp_ali.c [deleted file]
sys/dev/agp/agp_amd.c [deleted file]
sys/dev/agp/agp_ati.c [deleted file]
sys/dev/agp/agp_nvidia.c [deleted file]

index fbdfff8..2a89cd0 100644 (file)
@@ -1572,14 +1572,10 @@ bus/pccard/pccard_cis.c         optional pccard
 bus/pccard/pccard_cis_quirks.c optional pccard
 bus/pccard/power_if.m          standard
 dev/agp/agp.c                  optional agp
-dev/agp/agp_nvidia.c           optional agp
 dev/agp/agp_via.c              optional agp
 dev/agp/agp_sis.c              optional agp
-dev/agp/agp_ali.c              optional agp
-dev/agp/agp_amd.c              optional agp
 dev/agp/agp_amd64.c            optional agp
 dev/agp/agp_i810.c             optional agp
-dev/agp/agp_ati.c              optional agp
 dev/agp/agp_if.m               optional agp
 dev/disk/amd/amd.c             optional amd
 dev/video/bktr/bktr_audio.c    optional bktr pci
index b3bb367..9a0c25e 100644 (file)
@@ -1,9 +1,6 @@
-# $FreeBSD: src/sys/modules/agp/Makefile,v 1.2.2.4 2000/09/30 02:49:36 ps Exp $
-
 KMOD   = agp
 SRCS   = agp.c 
-SRCS   += agp_i810.c agp_ali.c agp_amd.c agp_amd64.c agp_ati.c agp_nvidia.c
-SRCS   += agp_sis.c agp_via.c
+SRCS   += agp_i810.c agp_amd64.c agp_sis.c agp_via.c
 SRCS   += agp_if.c device_if.h bus_if.h agp_if.h pci_if.h pcidevs.h
 SRCS   += opt_agp.h
 
diff --git a/sys/dev/agp/agp_ali.c b/sys/dev/agp/agp_ali.c
deleted file mode 100644 (file)
index 7a18869..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     $FreeBSD: src/sys/dev/agp/agp_ali.c,v 1.20 2007/11/12 21:51:36 jhb Exp $
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-#include "agppriv.h"
-#include "agpreg.h"
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-struct agp_ali_softc {
-       struct agp_softc agp;
-       u_int32_t       initial_aperture; /* aperture size at startup */
-       struct agp_gatt *gatt;
-};
-
-static const char*
-agp_ali_match(device_t dev)
-{
-       if (pci_get_class(dev) != PCIC_BRIDGE
-           || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
-               return NULL;
-
-       if (agp_find_caps(dev) == 0)
-               return NULL;
-
-       switch (pci_get_devid(dev)) {
-       case 0x167110b9:
-               return ("Ali M1671 host to AGP bridge");
-       case 0x154110b9:
-               return ("Ali M1541 host to AGP bridge");
-       case 0x162110b9:
-               return ("Ali M1621 host to AGP bridge");
-       }
-
-       return NULL;
-}
-
-static int
-agp_ali_probe(device_t dev)
-{
-       const char *desc;
-
-       if (resource_disabled("agp", device_get_unit(dev)))
-               return (ENXIO);
-       desc = agp_ali_match(dev);
-       if (desc) {
-               device_verbose(dev);
-               device_set_desc(dev, desc);
-               return BUS_PROBE_DEFAULT;
-       }
-
-       return ENXIO;
-}
-
-static int
-agp_ali_attach(device_t dev)
-{
-       struct agp_ali_softc *sc = device_get_softc(dev);
-       struct agp_gatt *gatt;
-       int error;
-       u_int32_t attbase;
-
-       error = agp_generic_attach(dev);
-       if (error)
-               return error;
-
-       sc->initial_aperture = AGP_GET_APERTURE(dev);
-       if (sc->initial_aperture == 0) {
-               device_printf(dev, "bad initial aperture size, disabling\n");
-               agp_generic_detach(dev);
-               return ENXIO;
-       }
-
-       for (;;) {
-               gatt = agp_alloc_gatt(dev);
-               if (gatt)
-                       break;
-
-               /*
-                * Probably contigmalloc failure. Try reducing the
-                * aperture so that the gatt size reduces.
-                */
-               if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2)) {
-                       agp_generic_detach(dev);
-                       return ENOMEM;
-               }
-       }
-       sc->gatt = gatt;
-
-       /* Install the gatt. */
-       attbase = pci_read_config(dev, AGP_ALI_ATTBASE, 4);
-       pci_write_config(dev, AGP_ALI_ATTBASE, gatt->ag_physical |
-           (attbase & 0xfff), 4);
-       
-       /* Enable the TLB. */
-       pci_write_config(dev, AGP_ALI_TLBCTRL, 0x10, 1);
-
-       return 0;
-}
-
-static int
-agp_ali_detach(device_t dev)
-{
-       struct agp_ali_softc *sc = device_get_softc(dev);
-       u_int32_t attbase;
-
-       agp_free_cdev(dev);
-
-       /* Disable the TLB.. */
-       pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1);
-
-       /* Put the aperture back the way it started. */
-       AGP_SET_APERTURE(dev, sc->initial_aperture);
-       attbase = pci_read_config(dev, AGP_ALI_ATTBASE, 4);
-       pci_write_config(dev, AGP_ALI_ATTBASE, attbase & 0xfff, 4);
-
-       agp_free_gatt(sc->gatt);
-       agp_free_res(dev);
-       return 0;
-}
-
-#define M 1024*1024
-
-static u_int32_t agp_ali_table[] = {
-       0,                      /* 0 - invalid */
-       1,                      /* 1 - invalid */
-       2,                      /* 2 - invalid */
-       4*M,                    /* 3 - invalid */
-       8*M,                    /* 4 - invalid */
-       0,                      /* 5 - invalid */
-       16*M,                   /* 6 - invalid */
-       32*M,                   /* 7 - invalid */
-       64*M,                   /* 8 - invalid */
-       128*M,                  /* 9 - invalid */
-       256*M,                  /* 10 - invalid */
-};
-#define agp_ali_table_size NELEM(agp_ali_table)
-
-static u_int32_t
-agp_ali_get_aperture(device_t dev)
-{
-       /*
-        * The aperture size is derived from the low bits of attbase.
-        * I'm not sure this is correct..
-        */
-       int i = pci_read_config(dev, AGP_ALI_ATTBASE, 4) & 0xf;
-       if (i >= agp_ali_table_size)
-               return 0;
-       return agp_ali_table[i];
-}
-
-static int
-agp_ali_set_aperture(device_t dev, u_int32_t aperture)
-{
-       int i;
-       u_int32_t attbase;
-
-       for (i = 0; i < agp_ali_table_size; i++)
-               if (agp_ali_table[i] == aperture)
-                       break;
-       if (i == agp_ali_table_size)
-               return EINVAL;
-
-       attbase = pci_read_config(dev, AGP_ALI_ATTBASE, 4);
-       pci_write_config(dev, AGP_ALI_ATTBASE, (attbase & ~0xf) | i, 4);
-       return 0;
-}
-
-static int
-agp_ali_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
-{
-       struct agp_ali_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical;
-       return 0;
-}
-
-static int
-agp_ali_unbind_page(device_t dev, vm_offset_t offset)
-{
-       struct agp_ali_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
-       return 0;
-}
-
-static void
-agp_ali_flush_tlb(device_t dev)
-{
-       pci_write_config(dev, AGP_ALI_TLBCTRL, 0x90, 1);
-       pci_write_config(dev, AGP_ALI_TLBCTRL, 0x10, 1);
-}
-
-static device_method_t agp_ali_methods[] = {
-       /* Device interface */
-       DEVMETHOD(device_probe,         agp_ali_probe),
-       DEVMETHOD(device_attach,        agp_ali_attach),
-       DEVMETHOD(device_detach,        agp_ali_detach),
-       DEVMETHOD(device_shutdown,      bus_generic_shutdown),
-       DEVMETHOD(device_suspend,       bus_generic_suspend),
-       DEVMETHOD(device_resume,        bus_generic_resume),
-
-       /* AGP interface */
-       DEVMETHOD(agp_get_aperture,     agp_ali_get_aperture),
-       DEVMETHOD(agp_set_aperture,     agp_ali_set_aperture),
-       DEVMETHOD(agp_bind_page,        agp_ali_bind_page),
-       DEVMETHOD(agp_unbind_page,      agp_ali_unbind_page),
-       DEVMETHOD(agp_flush_tlb,        agp_ali_flush_tlb),
-       DEVMETHOD(agp_enable,           agp_generic_enable),
-       DEVMETHOD(agp_alloc_memory,     agp_generic_alloc_memory),
-       DEVMETHOD(agp_free_memory,      agp_generic_free_memory),
-       DEVMETHOD(agp_bind_memory,      agp_generic_bind_memory),
-       DEVMETHOD(agp_unbind_memory,    agp_generic_unbind_memory),
-
-       DEVMETHOD_END
-};
-
-static driver_t agp_ali_driver = {
-       "agp",
-       agp_ali_methods,
-       sizeof(struct agp_ali_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_ali, pci, agp_ali_driver, agp_devclass, NULL, NULL);
-MODULE_DEPEND(agp_ali, agp, 1, 1, 1);
-MODULE_DEPEND(agp_ali, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_amd.c b/sys/dev/agp/agp_amd.c
deleted file mode 100644 (file)
index 84ebb32..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-/*-
- * Copyright (c) 2000 Doug Rabson
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     $FreeBSD: src/sys/dev/agp/agp_amd.c,v 1.25 2007/11/12 21:51:36 jhb Exp $
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/rman.h>
-
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-#include "agppriv.h"
-#include "agpreg.h"
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-MALLOC_DECLARE(M_AGP);
-
-#define READ2(off)     bus_space_read_2(sc->bst, sc->bsh, off)
-#define READ4(off)     bus_space_read_4(sc->bst, sc->bsh, off)
-#define WRITE2(off,v)  bus_space_write_2(sc->bst, sc->bsh, off, v)
-#define WRITE4(off,v)  bus_space_write_4(sc->bst, sc->bsh, off, v)
-
-struct agp_amd_gatt {
-       u_int32_t       ag_entries;
-       u_int32_t      *ag_virtual;     /* virtual address of gatt */
-       vm_offset_t     ag_physical;
-       u_int32_t      *ag_vdir;        /* virtual address of page dir */
-       vm_offset_t     ag_pdir;        /* physical address of page dir */
-};
-
-struct agp_amd_softc {
-       struct agp_softc        agp;
-       struct resource        *regs;   /* memory mapped control registers */
-       bus_space_tag_t         bst;    /* bus_space tag */
-       bus_space_handle_t      bsh;    /* bus_space handle */
-       u_int32_t               initial_aperture; /* aperture size at startup */
-       struct agp_amd_gatt    *gatt;
-};
-
-static struct agp_amd_gatt *
-agp_amd_alloc_gatt(device_t dev)
-{
-       u_int32_t apsize = AGP_GET_APERTURE(dev);
-       u_int32_t entries = apsize >> AGP_PAGE_SHIFT;
-       struct agp_amd_gatt *gatt;
-       int i, npages, pdir_offset;
-
-       if (bootverbose)
-               device_printf(dev,
-                             "allocating GATT for aperture of size %dM\n",
-                             apsize / (1024*1024));
-
-       gatt = kmalloc(sizeof(struct agp_amd_gatt), M_AGP, M_INTWAIT);
-
-       /*
-        * The AMD751 uses a page directory to map a non-contiguous
-        * gatt so we don't need to use contigmalloc.
-        * Malloc individual gatt pages and map them into the page
-        * directory.
-        */
-       gatt->ag_entries = entries;
-       gatt->ag_virtual = kmalloc(entries * sizeof(u_int32_t),
-                                 M_AGP, M_INTWAIT | M_ZERO);
-
-       /*
-        * Allocate the page directory.
-        */
-       gatt->ag_vdir = kmalloc(AGP_PAGE_SIZE, M_AGP, M_INTWAIT | M_ZERO);
-
-       gatt->ag_pdir = vtophys((vm_offset_t) gatt->ag_vdir);
-       if(bootverbose)
-               device_printf(dev, "gatt -> ag_pdir %#lx\n",
-                   (u_long)gatt->ag_pdir);
-       /*
-        * Allocate the gatt pages
-        */
-       gatt->ag_entries = entries;
-       if(bootverbose)
-               device_printf(dev, "allocating GATT for %d AGP page entries\n", 
-                       gatt->ag_entries);
-
-       gatt->ag_physical = vtophys((vm_offset_t) gatt->ag_virtual);
-
-       /*
-        * Map the pages of the GATT into the page directory.
-        *
-        * The GATT page addresses are mapped into the directory offset by
-        * an amount dependent on the base address of the aperture. This
-        * is and offset into the page directory, not an offset added to
-        * the addresses of the gatt pages.
-        */
-
-       pdir_offset = pci_read_config(dev, AGP_AMD751_APBASE, 4) >> 22;
-
-       npages = ((entries * sizeof(u_int32_t) + AGP_PAGE_SIZE - 1)
-                 >> AGP_PAGE_SHIFT);
-
-       for (i = 0; i < npages; i++) {
-               vm_offset_t va;
-               vm_offset_t pa;
-
-               va = ((vm_offset_t) gatt->ag_virtual) + i * AGP_PAGE_SIZE;
-               pa = vtophys(va);
-               gatt->ag_vdir[i + pdir_offset] = pa | 1;
-       }
-
-       /*
-        * Make sure the chipset can see everything.
-        */
-       agp_flush_cache();
-
-       return gatt;
-}
-
-static void
-agp_amd_free_gatt(struct agp_amd_gatt *gatt)
-{
-       kfree(gatt->ag_virtual, M_AGP);
-       kfree(gatt->ag_vdir, M_AGP);
-       kfree(gatt, M_AGP);
-}
-
-static const char*
-agp_amd_match(device_t dev)
-{
-       if (pci_get_class(dev) != PCIC_BRIDGE
-           || pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
-               return NULL;
-
-       if (agp_find_caps(dev) == 0)
-               return NULL;
-
-       switch (pci_get_devid(dev)) {
-       case 0x70061022:
-               return ("AMD 751 host to AGP bridge");
-       case 0x700e1022:
-               return ("AMD 761 host to AGP bridge");
-       case 0x700c1022:
-               return ("AMD 762 host to AGP bridge");
-       }
-
-       return NULL;
-}
-
-static int
-agp_amd_probe(device_t dev)
-{
-       const char *desc;
-
-       if (resource_disabled("agp", device_get_unit(dev)))
-               return (ENXIO);
-       desc = agp_amd_match(dev);
-       if (desc) {
-               device_verbose(dev);
-               device_set_desc(dev, desc);
-               return BUS_PROBE_DEFAULT;
-       }
-
-       return ENXIO;
-}
-
-static int
-agp_amd_attach(device_t dev)
-{
-       struct agp_amd_softc *sc = device_get_softc(dev);
-       struct agp_amd_gatt *gatt;
-       int error, rid;
-
-       error = agp_generic_attach(dev);
-       if (error)
-               return error;
-
-       rid = AGP_AMD751_REGISTERS;
-       sc->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
-                                         RF_ACTIVE);
-       if (!sc->regs) {
-               agp_generic_detach(dev);
-               return ENOMEM;
-       }
-
-       sc->bst = rman_get_bustag(sc->regs);
-       sc->bsh = rman_get_bushandle(sc->regs);
-
-       sc->initial_aperture = AGP_GET_APERTURE(dev);
-       if (sc->initial_aperture == 0) {
-               device_printf(dev, "bad initial aperture size, disabling\n");
-               return ENXIO;
-       }
-
-       for (;;) {
-               gatt = agp_amd_alloc_gatt(dev);
-               if (gatt)
-                       break;
-
-               /*
-                * Probably contigmalloc failure. Try reducing the
-                * aperture so that the gatt size reduces.
-                */
-               if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
-                       return ENOMEM;
-       }
-       sc->gatt = gatt;
-
-       /* Install the gatt. */
-       WRITE4(AGP_AMD751_ATTBASE, gatt->ag_pdir);
-       
-       /* Enable synchronisation between host and agp. */
-       pci_write_config(dev,
-                        AGP_AMD751_MODECTRL,
-                        AGP_AMD751_MODECTRL_SYNEN, 1);
-
-       /* Set indexing mode for two-level and enable page dir cache */
-       pci_write_config(dev,
-                        AGP_AMD751_MODECTRL2,
-                        AGP_AMD751_MODECTRL2_GPDCE, 1);
-
-       /* Enable the TLB and flush */
-       WRITE2(AGP_AMD751_STATUS,
-              READ2(AGP_AMD751_STATUS) | AGP_AMD751_STATUS_GCE);
-       AGP_FLUSH_TLB(dev);
-
-       return 0;
-}
-
-static int
-agp_amd_detach(device_t dev)
-{
-       struct agp_amd_softc *sc = device_get_softc(dev);
-
-       agp_free_cdev(dev);
-
-       /* Disable the TLB.. */
-       WRITE2(AGP_AMD751_STATUS,
-              READ2(AGP_AMD751_STATUS) & ~AGP_AMD751_STATUS_GCE);
-       
-       /* Disable host-agp sync */
-       pci_write_config(dev, AGP_AMD751_MODECTRL, 0x00, 1);
-       
-       /* Clear the GATT base */
-       WRITE4(AGP_AMD751_ATTBASE, 0);
-
-       /* Put the aperture back the way it started. */
-       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);
-
-       return 0;
-}
-
-static u_int32_t
-agp_amd_get_aperture(device_t dev)
-{
-       int vas;
-
-       /*
-        * The aperture size is equal to 32M<<vas.
-        */
-       vas = (pci_read_config(dev, AGP_AMD751_APCTRL, 1) & 0x06) >> 1;
-       return (32*1024*1024) << vas;
-}
-
-static int
-agp_amd_set_aperture(device_t dev, u_int32_t aperture)
-{
-       int vas;
-
-       /*
-        * Check for a power of two and make sure its within the
-        * programmable range.
-        */
-       if (aperture & (aperture - 1)
-           || aperture < 32*1024*1024
-           || aperture > 2U*1024*1024*1024)
-               return EINVAL;
-
-       vas = ffs(aperture / 32*1024*1024) - 1;
-       
-       /* 
-        * While the size register is bits 1-3 of APCTRL, bit 0 must be
-        * set for the size value to be 'valid'
-        */
-       pci_write_config(dev, AGP_AMD751_APCTRL,
-                        (((pci_read_config(dev, AGP_AMD751_APCTRL, 1) & ~0x06)
-                         | ((vas << 1) | 1))), 1);
-
-       return 0;
-}
-
-static int
-agp_amd_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
-{
-       struct agp_amd_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 1;
-
-       /* invalidate the cache */
-       AGP_FLUSH_TLB(dev);
-       return 0;
-}
-
-static int
-agp_amd_unbind_page(device_t dev, vm_offset_t offset)
-{
-       struct agp_amd_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
-       return 0;
-}
-
-static void
-agp_amd_flush_tlb(device_t dev)
-{
-       struct agp_amd_softc *sc = device_get_softc(dev);
-
-       /* Set the cache invalidate bit and wait for the chipset to clear */
-       WRITE4(AGP_AMD751_TLBCTRL, 1);
-       do {
-               DELAY(1);
-       } while (READ4(AGP_AMD751_TLBCTRL));
-}
-
-static device_method_t agp_amd_methods[] = {
-       /* Device interface */
-       DEVMETHOD(device_probe,         agp_amd_probe),
-       DEVMETHOD(device_attach,        agp_amd_attach),
-       DEVMETHOD(device_detach,        agp_amd_detach),
-       DEVMETHOD(device_shutdown,      bus_generic_shutdown),
-       DEVMETHOD(device_suspend,       bus_generic_suspend),
-       DEVMETHOD(device_resume,        bus_generic_resume),
-
-       /* AGP interface */
-       DEVMETHOD(agp_get_aperture,     agp_amd_get_aperture),
-       DEVMETHOD(agp_set_aperture,     agp_amd_set_aperture),
-       DEVMETHOD(agp_bind_page,        agp_amd_bind_page),
-       DEVMETHOD(agp_unbind_page,      agp_amd_unbind_page),
-       DEVMETHOD(agp_flush_tlb,        agp_amd_flush_tlb),
-       DEVMETHOD(agp_enable,           agp_generic_enable),
-       DEVMETHOD(agp_alloc_memory,     agp_generic_alloc_memory),
-       DEVMETHOD(agp_free_memory,      agp_generic_free_memory),
-       DEVMETHOD(agp_bind_memory,      agp_generic_bind_memory),
-       DEVMETHOD(agp_unbind_memory,    agp_generic_unbind_memory),
-
-       DEVMETHOD_END
-};
-
-static driver_t agp_amd_driver = {
-       "agp",
-       agp_amd_methods,
-       sizeof(struct agp_amd_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_amd, pci, agp_amd_driver, agp_devclass, NULL, NULL);
-MODULE_DEPEND(agp_amd, agp, 1, 1, 1);
-MODULE_DEPEND(agp_amd, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_ati.c b/sys/dev/agp/agp_ati.c
deleted file mode 100644 (file)
index cb57dcd..0000000
+++ /dev/null
@@ -1,385 +0,0 @@
-/*-
- * Copyright (c) 2005 Eric Anholt
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * Based on reading the Linux 2.6.8.1 driver by Dave Jones.
- *
- * $FreeBSD: src/sys/dev/agp/agp_ati.c,v 1.5 2007/11/12 21:51:36 jhb Exp $
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/proc.h>
-
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-#include "agppriv.h"
-#include "agpreg.h"
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-#include <sys/rman.h>
-
-MALLOC_DECLARE(M_AGP);
-
-#define READ4(off)     bus_space_read_4(sc->bst, sc->bsh, off)
-#define WRITE4(off,v)  bus_space_write_4(sc->bst, sc->bsh, off, v)
-
-struct agp_ati_softc {
-       struct agp_softc agp;
-       struct resource *regs;  /* memory mapped control registers */
-       bus_space_tag_t bst;    /* bus_space tag */
-       bus_space_handle_t bsh; /* bus_space handle */
-       u_int32_t       initial_aperture; /* aperture size at startup */
-       char            is_rs300;
-
-       /* The GATT */
-       u_int32_t       ag_entries;
-       u_int32_t      *ag_virtual;     /* virtual address of gatt */
-       u_int32_t      *ag_vdir;        /* virtual address of page dir */
-       vm_offset_t     ag_pdir;        /* physical address of page dir */
-};
-
-
-static const char*
-agp_ati_match(device_t dev)
-{
-       if (pci_get_class(dev) != PCIC_BRIDGE ||
-           pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
-               return NULL;
-
-       if (agp_find_caps(dev) == 0)
-               return NULL;
-
-       switch (pci_get_devid(dev)) {
-       case 0xcab01002:
-               return ("ATI RS100 AGP bridge");
-       case 0xcab21002:
-               return ("ATI RS200 AGP bridge");
-       case 0xcbb21002:
-               return ("ATI RS200M AGP bridge");
-       case 0xcab31002:
-               return ("ATI RS250 AGP bridge");
-       case 0x58301002:
-               return ("ATI RS300_100 AGP bridge");
-       case 0x58311002:
-               return ("ATI RS300_133 AGP bridge");
-       case 0x58321002:
-               return ("ATI RS300_166 AGP bridge");
-       case 0x58331002:
-               return ("ATI RS300_200 AGP bridge");
-       }
-
-       return NULL;
-}
-
-static int
-agp_ati_probe(device_t dev)
-{
-       const char *desc;
-
-       desc = agp_ati_match(dev);
-       if (desc) {
-               device_verbose(dev);
-               device_set_desc(dev, desc);
-               return 0;
-       }
-
-       return ENXIO;
-}
-
-static int
-agp_ati_alloc_gatt(device_t dev)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-       u_int32_t apsize = AGP_GET_APERTURE(dev);
-       u_int32_t entries = apsize >> AGP_PAGE_SHIFT;
-       u_int32_t apbase_offset;
-       int i;
-
-       /* Alloc the GATT -- pointers to pages of AGP memory */
-       sc->ag_entries = entries;
-       sc->ag_virtual = kmalloc(entries * sizeof(u_int32_t), M_AGP,
-           M_NOWAIT | M_ZERO);
-       if (sc->ag_virtual == NULL) {
-               if (bootverbose)
-                       device_printf(dev, "aperture allocation failed\n");
-               return ENOMEM;
-       }
-
-       /* Alloc the page directory -- pointers to each page of the GATT */
-       sc->ag_vdir = kmalloc(AGP_PAGE_SIZE, M_AGP, M_NOWAIT | M_ZERO);
-       if (sc->ag_vdir == NULL) {
-               if (bootverbose)
-                       device_printf(dev, "pagedir allocation failed\n");
-               kfree(sc->ag_virtual, M_AGP);
-               return ENOMEM;
-       }
-       sc->ag_pdir = vtophys((vm_offset_t)sc->ag_vdir);
-
-       apbase_offset = pci_read_config(dev, AGP_APBASE, 4) >> 22;
-       /* Fill in the pagedir's pointers to GATT pages */
-       for (i = 0; i < sc->ag_entries / 1024; i++) {
-               vm_offset_t va;
-               vm_offset_t pa;
-
-               va = ((vm_offset_t)sc->ag_virtual) + i * AGP_PAGE_SIZE;
-               pa = vtophys(va);
-               sc->ag_vdir[apbase_offset + i] = pa | 1;
-       }
-
-       /*
-        * Make sure the chipset can see everything.
-        */
-       agp_flush_cache();
-
-       return 0;
-}
-
-
-static int
-agp_ati_attach(device_t dev)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-       int error, rid;
-       u_int32_t temp;
-       u_int32_t apsize_reg, agpmode_reg;
-
-       error = agp_generic_attach(dev);
-       if (error)
-               return error;
-
-       switch (pci_get_devid(dev)) {
-       case 0xcab01002: /* ATI RS100 AGP bridge */
-       case 0xcab21002: /* ATI RS200 AGP bridge */
-       case 0xcbb21002: /* ATI RS200M AGP bridge */
-       case 0xcab31002: /* ATI RS250 AGP bridge */
-               sc->is_rs300 = 0;
-               apsize_reg = ATI_RS100_APSIZE;
-               agpmode_reg = ATI_RS100_IG_AGPMODE;
-               break;
-       case 0x58301002: /* ATI RS300_100 AGP bridge */
-       case 0x58311002: /* ATI RS300_133 AGP bridge */
-       case 0x58321002: /* ATI RS300_166 AGP bridge */
-       case 0x58331002: /* ATI RS300_200 AGP bridge */
-               sc->is_rs300 = 1;
-               apsize_reg = ATI_RS300_APSIZE;
-               agpmode_reg = ATI_RS300_IG_AGPMODE;
-               break;
-       default:
-               /* Unknown chipset */
-               return EINVAL;
-       }
-
-       rid = ATI_GART_MMADDR;
-       sc->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
-       if (!sc->regs) {
-               agp_generic_detach(dev);
-               return ENOMEM;
-       }
-
-       sc->bst = rman_get_bustag(sc->regs);
-       sc->bsh = rman_get_bushandle(sc->regs);
-
-       sc->initial_aperture = AGP_GET_APERTURE(dev);
-       if (sc->initial_aperture == 0) {
-               device_printf(dev, "bad initial aperture size, disabling\n");
-               return ENXIO;
-       }
-
-       for (;;) {
-               if (agp_ati_alloc_gatt(dev) == 0)
-                       break;
-
-               /*
-                * Probably contigmalloc failure. Try reducing the
-                * aperture so that the gatt size reduces.
-                */
-               if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
-                       return ENOMEM;
-       }
-
-       temp = pci_read_config(dev, apsize_reg, 4);
-       pci_write_config(dev, apsize_reg, temp | 1, 4);
-
-       pci_write_config(dev, agpmode_reg, 0x20000, 4);
-
-       WRITE4(ATI_GART_FEATURE_ID, 0x00060000);
-
-       temp = pci_read_config(dev, 4, 4);      /* XXX: Magic reg# */
-       pci_write_config(dev, 4, temp | (1 << 14), 4);
-
-       WRITE4(ATI_GART_BASE, sc->ag_pdir);
-
-       AGP_FLUSH_TLB(dev);
-
-       return 0;
-}
-
-static int
-agp_ati_detach(device_t dev)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-       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;
-
-       /* Clear the GATT base */
-       WRITE4(ATI_GART_BASE, 0);
-
-       /* Put the aperture back the way it started. */
-       AGP_SET_APERTURE(dev, sc->initial_aperture);
-
-       temp = pci_read_config(dev, apsize_reg, 4);
-       pci_write_config(dev, apsize_reg, temp & ~1, 4);
-
-       kfree(sc->ag_vdir, M_AGP);
-       kfree(sc->ag_virtual, M_AGP);
-
-       bus_release_resource(dev, SYS_RES_MEMORY, ATI_GART_MMADDR, sc->regs);
-       agp_free_res(dev);
-
-       return 0;
-}
-
-static u_int32_t
-agp_ati_get_aperture(device_t dev)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-       int size_value;
-
-       if (sc->is_rs300)
-               size_value = pci_read_config(dev, ATI_RS300_APSIZE, 4);
-       else
-               size_value = pci_read_config(dev, ATI_RS100_APSIZE, 4);
-
-       size_value = (size_value & 0x0000000e) >> 1;
-       size_value = (32 * 1024 * 1024) << size_value;
-
-       return size_value;
-}
-
-static int
-agp_ati_set_aperture(device_t dev, u_int32_t aperture)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-       int size_value;
-       u_int32_t apsize_reg;
-
-       if (sc->is_rs300)
-               apsize_reg = ATI_RS300_APSIZE;
-       else
-               apsize_reg = ATI_RS100_APSIZE;
-
-       size_value = pci_read_config(dev, apsize_reg, 4);
-
-       size_value &= ~0x0000000e;
-       size_value |= (ffs(aperture / (32 * 1024 * 1024)) - 1) << 1;
-
-       pci_write_config(dev, apsize_reg, size_value, 4);
-
-       return 0;
-}
-
-static int
-agp_ati_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 1;
-
-       return 0;
-}
-
-static int
-agp_ati_unbind_page(device_t dev, vm_offset_t offset)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-
-       if (offset >= (sc->ag_entries << AGP_PAGE_SHIFT))
-               return EINVAL;
-
-       sc->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
-       return 0;
-}
-
-static void
-agp_ati_flush_tlb(device_t dev)
-{
-       struct agp_ati_softc *sc = device_get_softc(dev);
-
-       /* Set the cache invalidate bit and wait for the chipset to clear */
-       WRITE4(ATI_GART_CACHE_CNTRL, 1);
-       (void)READ4(ATI_GART_CACHE_CNTRL);
-}
-
-static device_method_t agp_ati_methods[] = {
-       /* Device interface */
-       DEVMETHOD(device_probe,         agp_ati_probe),
-       DEVMETHOD(device_attach,        agp_ati_attach),
-       DEVMETHOD(device_detach,        agp_ati_detach),
-       DEVMETHOD(device_shutdown,      bus_generic_shutdown),
-       DEVMETHOD(device_suspend,       bus_generic_suspend),
-       DEVMETHOD(device_resume,        bus_generic_resume),
-
-       /* AGP interface */
-       DEVMETHOD(agp_get_aperture,     agp_ati_get_aperture),
-       DEVMETHOD(agp_set_aperture,     agp_ati_set_aperture),
-       DEVMETHOD(agp_bind_page,        agp_ati_bind_page),
-       DEVMETHOD(agp_unbind_page,      agp_ati_unbind_page),
-       DEVMETHOD(agp_flush_tlb,        agp_ati_flush_tlb),
-       DEVMETHOD(agp_enable,           agp_generic_enable),
-       DEVMETHOD(agp_alloc_memory,     agp_generic_alloc_memory),
-       DEVMETHOD(agp_free_memory,      agp_generic_free_memory),
-       DEVMETHOD(agp_bind_memory,      agp_generic_bind_memory),
-       DEVMETHOD(agp_unbind_memory,    agp_generic_unbind_memory),
-
-       DEVMETHOD_END
-};
-
-static driver_t agp_ati_driver = {
-       "agp",
-       agp_ati_methods,
-       sizeof(struct agp_ati_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_ati, pci, agp_ati_driver, agp_devclass, NULL, NULL);
-MODULE_DEPEND(agp_ati, agp, 1, 1, 1);
-MODULE_DEPEND(agp_ati, pci, 1, 1, 1);
diff --git a/sys/dev/agp/agp_nvidia.c b/sys/dev/agp/agp_nvidia.c
deleted file mode 100644 (file)
index f0ecce8..0000000
+++ /dev/null
@@ -1,450 +0,0 @@
-/*-
- * Copyright (c) 2003 Matthew N. Dodd <winter@jurai.net>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/sys/dev/agp/agp_nvidia.c,v 1.13 2007/11/12 21:51:37 jhb Exp $
- */
-
-/*
- * Written using information gleaned from the
- * NVIDIA nForce/nForce2 AGPGART Linux Kernel Patch.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-#include <sys/bus.h>
-#include <sys/lock.h>
-#include <sys/rman.h>
-
-#include <bus/pci/pcivar.h>
-#include <bus/pci/pcireg.h>
-#include "agppriv.h"
-#include "agpreg.h"
-
-#include <vm/vm.h>
-#include <vm/vm_object.h>
-#include <vm/pmap.h>
-
-#define        NVIDIA_VENDORID         0x10de
-#define        NVIDIA_DEVICEID_NFORCE  0x01a4
-#define        NVIDIA_DEVICEID_NFORCE2 0x01e0
-
-struct agp_nvidia_softc {
-       struct agp_softc        agp;
-       u_int32_t               initial_aperture; /* aperture size at startup */
-       struct agp_gatt *       gatt;
-
-       device_t                dev;            /* AGP Controller */
-       device_t                mc1_dev;        /* Memory Controller */
-       device_t                mc2_dev;        /* Memory Controller */
-       device_t                bdev;           /* Bridge */
-
-       u_int32_t               wbc_mask;
-       int                     num_dirs;
-       int                     num_active_entries;
-       off_t                   pg_offset;
-};
-
-static const char *agp_nvidia_match(device_t dev);
-static int agp_nvidia_probe(device_t);
-static int agp_nvidia_attach(device_t);
-static int agp_nvidia_detach(device_t);
-static u_int32_t agp_nvidia_get_aperture(device_t);
-static int agp_nvidia_set_aperture(device_t, u_int32_t);
-static int agp_nvidia_bind_page(device_t, vm_offset_t, vm_offset_t);
-static int agp_nvidia_unbind_page(device_t, vm_offset_t);
-
-static int nvidia_init_iorr(u_int32_t, u_int32_t);
-
-static const char *
-agp_nvidia_match (device_t dev)
-{
-       if (pci_get_class(dev) != PCIC_BRIDGE ||
-           pci_get_subclass(dev) != PCIS_BRIDGE_HOST ||
-           pci_get_vendor(dev) != NVIDIA_VENDORID)
-               return (NULL);
-
-       switch (pci_get_device(dev)) {
-       case NVIDIA_DEVICEID_NFORCE:
-               return ("NVIDIA nForce AGP Controller");
-       case NVIDIA_DEVICEID_NFORCE2:
-               return ("NVIDIA nForce2 AGP Controller");
-       }
-       return (NULL);
-}
-
-static int
-agp_nvidia_probe (device_t dev)
-{
-       const char *desc;
-
-       if (resource_disabled("agp", device_get_unit(dev)))
-               return (ENXIO);
-       desc = agp_nvidia_match(dev);
-       if (desc) {
-               device_verbose(dev);
-               device_set_desc(dev, desc);
-               return (BUS_PROBE_DEFAULT);
-       }
-       return (ENXIO);
-}
-
-static int
-agp_nvidia_attach (device_t dev)
-{
-       struct agp_nvidia_softc *sc = device_get_softc(dev);
-       struct agp_gatt *gatt;
-       u_int32_t apbase;
-       u_int32_t aplimit;
-       u_int32_t temp;
-       int size;
-       int i;
-       int error;
-
-       switch (pci_get_device(dev)) {
-       case NVIDIA_DEVICEID_NFORCE:
-               sc->wbc_mask = 0x00010000;
-               break;
-       case NVIDIA_DEVICEID_NFORCE2:
-               sc->wbc_mask = 0x80000000;
-               break;
-       default:
-               device_printf(dev, "Bad chip id\n");
-               return (ENODEV);
-       }
-
-       /* AGP Controller */
-       sc->dev = dev;
-
-       /* Memory Controller 1 */
-       sc->mc1_dev = pci_find_bsf(pci_get_bus(dev), 0, 1);
-       if (sc->mc1_dev == NULL) {
-               device_printf(dev,
-                       "Unable to find NVIDIA Memory Controller 1.\n");
-               return (ENODEV);
-       }
-
-       /* Memory Controller 2 */
-       sc->mc2_dev = pci_find_bsf(pci_get_bus(dev), 0, 2);
-       if (sc->mc2_dev == NULL) {
-               device_printf(dev,
-                       "Unable to find NVIDIA Memory Controller 2.\n");
-               return (ENODEV);
-       }
-
-       /* AGP Host to PCI Bridge */
-       sc->bdev = pci_find_bsf(pci_get_bus(dev), 30, 0);
-       if (sc->bdev == NULL) {
-               device_printf(dev,
-                       "Unable to find NVIDIA AGP Host to PCI Bridge.\n");
-               return (ENODEV);
-       }
-
-       error = agp_generic_attach(dev);
-       if (error)
-               return (error);
-
-       sc->initial_aperture = AGP_GET_APERTURE(dev);
-       if (sc->initial_aperture == 0) {
-               device_printf(dev, "bad initial aperture size, disabling\n");
-               return ENXIO;
-       }
-
-       for (;;) {
-               gatt = agp_alloc_gatt(dev);
-               if (gatt)
-                       break;
-               /*
-                * Probably contigmalloc failure. Try reducing the
-                * aperture so that the gatt size reduces.
-                */
-               if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
-                       goto fail;
-       }
-       sc->gatt = gatt;
-
-       apbase = rman_get_start(sc->agp.as_aperture);
-       aplimit = apbase + AGP_GET_APERTURE(dev) - 1;
-       pci_write_config(sc->mc2_dev, AGP_NVIDIA_2_APBASE, apbase, 4);
-       pci_write_config(sc->mc2_dev, AGP_NVIDIA_2_APLIMIT, aplimit, 4);
-       pci_write_config(sc->bdev, AGP_NVIDIA_3_APBASE, apbase, 4);
-       pci_write_config(sc->bdev, AGP_NVIDIA_3_APLIMIT, aplimit, 4);
-
-       error = nvidia_init_iorr(apbase, AGP_GET_APERTURE(dev));
-       if (error) {
-               device_printf(dev, "Failed to setup IORRs\n");
-               goto fail;
-       }
-
-       /* directory size is 64k */
-       size = AGP_GET_APERTURE(dev) / 1024 / 1024;
-       sc->num_dirs = size / 64;
-       sc->num_active_entries = (size == 32) ? 16384 : ((size * 1024) / 4);
-       sc->pg_offset = 0;
-       if (sc->num_dirs == 0) {
-               sc->num_dirs = 1;
-               sc->num_active_entries /= (64 / size);
-               sc->pg_offset = (apbase & (64 * 1024 * 1024 - 1) &
-                                ~(AGP_GET_APERTURE(dev) - 1)) / PAGE_SIZE;
-       }
-
-       /* (G)ATT Base Address */
-       for (i = 0; i < 8; i++) {
-               pci_write_config(sc->mc2_dev, AGP_NVIDIA_2_ATTBASE(i),
-                                (sc->gatt->ag_physical +
-                                  (i % sc->num_dirs) * 64 * 1024) | 1, 4);
-       }
-
-       /* GTLB Control */
-       temp = pci_read_config(sc->mc2_dev, AGP_NVIDIA_2_GARTCTRL, 4);
-       pci_write_config(sc->mc2_dev, AGP_NVIDIA_2_GARTCTRL, temp | 0x11, 4);
-
-       /* GART Control */
-       temp = pci_read_config(sc->dev, AGP_NVIDIA_0_APSIZE, 4);
-       pci_write_config(sc->dev, AGP_NVIDIA_0_APSIZE, temp | 0x100, 4);
-
-       return (0);
-fail:
-       agp_generic_detach(dev);
-       return (ENOMEM);
-}
-
-static int
-agp_nvidia_detach (device_t dev)
-{
-       struct agp_nvidia_softc *sc = device_get_softc(dev);
-       u_int32_t temp;
-
-       agp_free_cdev(dev);
-
-       /* GART Control */
-       temp = pci_read_config(sc->dev, AGP_NVIDIA_0_APSIZE, 4);
-       pci_write_config(sc->dev, AGP_NVIDIA_0_APSIZE, temp & ~(0x100), 4);
-
-       /* GTLB Control */
-       temp = pci_read_config(sc->mc2_dev, AGP_NVIDIA_2_GARTCTRL, 4);
-       pci_write_config(sc->mc2_dev, AGP_NVIDIA_2_GARTCTRL, temp & ~(0x11), 4);
-
-       /* Put the aperture back the way it started. */
-       AGP_SET_APERTURE(dev, sc->initial_aperture);
-
-       /* restore iorr for previous aperture size */
-       nvidia_init_iorr(rman_get_start(sc->agp.as_aperture),
-                        sc->initial_aperture);
-
-       agp_free_gatt(sc->gatt);
-       agp_free_res(dev);
-
-       return (0);
-}
-
-static u_int32_t
-agp_nvidia_get_aperture(device_t dev)
-{
-       switch (pci_read_config(dev, AGP_NVIDIA_0_APSIZE, 1) & 0x0f) {
-       case 0: return (512 * 1024 * 1024); break;
-       case 8: return (256 * 1024 * 1024); break;
-       case 12: return (128 * 1024 * 1024); break;
-       case 14: return (64 * 1024 * 1024); break;
-       case 15: return (32 * 1024 * 1024); break;
-       default:
-               device_printf(dev, "Invalid aperture setting 0x%x\n",
-                   pci_read_config(dev, AGP_NVIDIA_0_APSIZE, 1));
-               return 0;
-       }
-}
-
-static int
-agp_nvidia_set_aperture(device_t dev, u_int32_t aperture)
-{
-       u_int8_t val;
-       u_int8_t key;
-
-       switch (aperture) {
-       case (512 * 1024 * 1024): key = 0; break;
-       case (256 * 1024 * 1024): key = 8; break;
-       case (128 * 1024 * 1024): key = 12; break;
-       case (64 * 1024 * 1024): key = 14; break;
-       case (32 * 1024 * 1024): key = 15; break;
-       default:
-               device_printf(dev, "Invalid aperture size (%dMb)\n",
-                               aperture / 1024 / 1024);
-               return (EINVAL);
-       }
-       val = pci_read_config(dev, AGP_NVIDIA_0_APSIZE, 1);
-       pci_write_config(dev, AGP_NVIDIA_0_APSIZE, ((val & ~0x0f) | key), 1);
-
-       return (0);
-}
-
-static int
-agp_nvidia_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
-{
-       struct agp_nvidia_softc *sc = device_get_softc(dev);
-       u_int32_t index;
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return (EINVAL);
-
-       index = (sc->pg_offset + offset) >> AGP_PAGE_SHIFT;
-       sc->gatt->ag_virtual[index] = physical | 1;
-
-       return (0);
-}
-
-static int
-agp_nvidia_unbind_page(device_t dev, vm_offset_t offset)
-{
-       struct agp_nvidia_softc *sc = device_get_softc(dev);
-       u_int32_t index;
-
-       if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
-               return (EINVAL);
-
-       index = (sc->pg_offset + offset) >> AGP_PAGE_SHIFT;
-       sc->gatt->ag_virtual[index] = 0;
-
-       return (0);
-}
-
-static void
-agp_nvidia_flush_tlb (device_t dev)
-{
-       struct agp_nvidia_softc *sc;
-       u_int32_t wbc_reg, temp;
-       volatile u_int32_t *ag_virtual;
-       int i, pages;
-
-       sc = (struct agp_nvidia_softc *)device_get_softc(dev);
-
-       if (sc->wbc_mask) {
-               wbc_reg = pci_read_config(sc->mc1_dev, AGP_NVIDIA_1_WBC, 4);
-               wbc_reg |= sc->wbc_mask;
-               pci_write_config(sc->mc1_dev, AGP_NVIDIA_1_WBC, wbc_reg, 4);
-
-               /* Wait no more than 3 seconds. */
-               for (i = 0; i < 3000; i++) {
-                       wbc_reg = pci_read_config(sc->mc1_dev,
-                                                 AGP_NVIDIA_1_WBC, 4);
-                       if ((sc->wbc_mask & wbc_reg) == 0)
-                               break;
-                       else
-                               DELAY(1000);
-               }
-               if (i == 3000)
-                       device_printf(dev,
-                               "TLB flush took more than 3 seconds.\n");
-       }
-
-       ag_virtual = (volatile u_int32_t *)sc->gatt->ag_virtual;
-
-       /* Flush TLB entries. */
-       pages = sc->gatt->ag_entries * sizeof(u_int32_t) / PAGE_SIZE;
-       for(i = 0; i < pages; i++)
-               temp = ag_virtual[i * PAGE_SIZE / sizeof(u_int32_t)];
-       for(i = 0; i < pages; i++)
-               temp = ag_virtual[i * PAGE_SIZE / sizeof(u_int32_t)];
-}
-
-#define        SYSCFG          0xC0010010
-#define        IORR_BASE0      0xC0010016
-#define        IORR_MASK0      0xC0010017
-#define        AMD_K7_NUM_IORR 2
-
-static int
-nvidia_init_iorr(u_int32_t addr, u_int32_t size)
-{
-       quad_t base, mask, sys;
-       u_int32_t iorr_addr, free_iorr_addr;
-
-       /* Find the iorr that is already used for the addr */
-       /* If not found, determine the uppermost available iorr */
-       free_iorr_addr = AMD_K7_NUM_IORR;
-       for(iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) {
-               base = rdmsr(IORR_BASE0 + 2 * iorr_addr);
-               mask = rdmsr(IORR_MASK0 + 2 * iorr_addr);
-
-               if ((base & 0xfffff000ULL) == (addr & 0xfffff000))
-                       break;
-
-               if ((mask & 0x00000800ULL) == 0)
-                       free_iorr_addr = iorr_addr;
-       }
-
-       if (iorr_addr >= AMD_K7_NUM_IORR) {
-               iorr_addr = free_iorr_addr;
-               if (iorr_addr >= AMD_K7_NUM_IORR)
-                       return (EINVAL);
-       }
-
-       base = (addr & ~0xfff) | 0x18;
-       mask = (0xfULL << 32) | ((~(size - 1)) & 0xfffff000) | 0x800;
-       wrmsr(IORR_BASE0 + 2 * iorr_addr, base);
-       wrmsr(IORR_MASK0 + 2 * iorr_addr, mask);
-
-       sys = rdmsr(SYSCFG);
-       sys |= 0x00100000ULL;
-       wrmsr(SYSCFG, sys);
-
-       return (0);
-}
-
-static device_method_t agp_nvidia_methods[] = {
-       /* Device interface */
-       DEVMETHOD(device_probe,         agp_nvidia_probe),
-       DEVMETHOD(device_attach,        agp_nvidia_attach),
-       DEVMETHOD(device_detach,        agp_nvidia_detach),
-       DEVMETHOD(device_shutdown,      bus_generic_shutdown),
-       DEVMETHOD(device_suspend,       bus_generic_suspend),
-       DEVMETHOD(device_resume,        bus_generic_resume),
-
-       /* AGP interface */
-       DEVMETHOD(agp_get_aperture,     agp_nvidia_get_aperture),
-       DEVMETHOD(agp_set_aperture,     agp_nvidia_set_aperture),
-       DEVMETHOD(agp_bind_page,        agp_nvidia_bind_page),
-       DEVMETHOD(agp_unbind_page,      agp_nvidia_unbind_page),
-       DEVMETHOD(agp_flush_tlb,        agp_nvidia_flush_tlb),
-
-       DEVMETHOD(agp_enable,           agp_generic_enable),
-       DEVMETHOD(agp_alloc_memory,     agp_generic_alloc_memory),
-       DEVMETHOD(agp_free_memory,      agp_generic_free_memory),
-       DEVMETHOD(agp_bind_memory,      agp_generic_bind_memory),
-       DEVMETHOD(agp_unbind_memory,    agp_generic_unbind_memory),
-
-       DEVMETHOD_END
-};
-
-static driver_t agp_nvidia_driver = {
-       "agp",
-       agp_nvidia_methods,
-       sizeof(struct agp_nvidia_softc),
-};
-
-static devclass_t agp_devclass;
-
-DRIVER_MODULE(agp_nvidia, pci, agp_nvidia_driver, agp_devclass, NULL, NULL);
-MODULE_DEPEND(agp_nvidia, agp, 1, 1, 1);
-MODULE_DEPEND(agp_nvidia, pci, 1, 1, 1);