Home | History | Annotate | Line # | Download | only in pci
agp_i810.c revision 1.10
      1  1.10   tsutsui /*	$NetBSD: agp_i810.c,v 1.10 2002/01/12 16:17:05 tsutsui Exp $	*/
      2   1.1      fvdl 
      3   1.1      fvdl /*-
      4   1.1      fvdl  * Copyright (c) 2000 Doug Rabson
      5   1.1      fvdl  * Copyright (c) 2000 Ruslan Ermilov
      6   1.1      fvdl  * All rights reserved.
      7   1.1      fvdl  *
      8   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
      9   1.1      fvdl  * modification, are permitted provided that the following conditions
     10   1.1      fvdl  * are met:
     11   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     12   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     13   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     15   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     16   1.1      fvdl  *
     17   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     18   1.1      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19   1.1      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20   1.1      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     21   1.1      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22   1.1      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23   1.1      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24   1.1      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25   1.1      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26   1.1      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27   1.1      fvdl  * SUCH DAMAGE.
     28   1.1      fvdl  *
     29   1.1      fvdl  *	$FreeBSD: src/sys/pci/agp_i810.c,v 1.4 2001/07/05 21:28:47 jhb Exp $
     30   1.1      fvdl  */
     31   1.9     lukem 
     32   1.9     lukem #include <sys/cdefs.h>
     33  1.10   tsutsui __KERNEL_RCSID(0, "$NetBSD: agp_i810.c,v 1.10 2002/01/12 16:17:05 tsutsui Exp $");
     34   1.1      fvdl 
     35   1.1      fvdl #include <sys/param.h>
     36   1.1      fvdl #include <sys/systm.h>
     37   1.1      fvdl #include <sys/malloc.h>
     38   1.1      fvdl #include <sys/kernel.h>
     39   1.1      fvdl #include <sys/lock.h>
     40   1.1      fvdl #include <sys/proc.h>
     41   1.1      fvdl #include <sys/device.h>
     42   1.1      fvdl #include <sys/conf.h>
     43   1.1      fvdl 
     44   1.1      fvdl #include <uvm/uvm_extern.h>
     45   1.1      fvdl 
     46   1.1      fvdl #include <dev/pci/pcivar.h>
     47   1.1      fvdl #include <dev/pci/pcireg.h>
     48   1.1      fvdl #include <dev/pci/pcidevs.h>
     49   1.1      fvdl #include <dev/pci/agpvar.h>
     50   1.1      fvdl #include <dev/pci/agpreg.h>
     51   1.1      fvdl 
     52   1.1      fvdl #include <sys/agpio.h>
     53   1.1      fvdl 
     54   1.1      fvdl #include <machine/bus.h>
     55   1.1      fvdl 
     56   1.1      fvdl #define READ1(off)	bus_space_read_1(isc->bst, isc->bsh, off)
     57   1.1      fvdl #define WRITE4(off,v)	bus_space_write_4(isc->bst, isc->bsh, off, v)
     58   1.1      fvdl 
     59   1.1      fvdl struct agp_i810_softc {
     60   1.1      fvdl 	u_int32_t initial_aperture;	/* aperture size at startup */
     61   1.1      fvdl 	struct agp_gatt *gatt;
     62   1.1      fvdl 	u_int32_t dcache_size;
     63   1.1      fvdl 	bus_space_tag_t bst;		/* bus_space tag */
     64   1.1      fvdl 	bus_space_handle_t bsh;		/* bus_space handle */
     65   1.1      fvdl 	struct pci_attach_args vga_pa;
     66   1.1      fvdl };
     67   1.1      fvdl 
     68   1.1      fvdl static u_int32_t agp_i810_get_aperture(struct agp_softc *);
     69   1.1      fvdl static int agp_i810_set_aperture(struct agp_softc *, u_int32_t);
     70   1.1      fvdl static int agp_i810_bind_page(struct agp_softc *, off_t, bus_addr_t);
     71   1.1      fvdl static int agp_i810_unbind_page(struct agp_softc *, off_t);
     72   1.1      fvdl static void agp_i810_flush_tlb(struct agp_softc *);
     73   1.1      fvdl static int agp_i810_enable(struct agp_softc *, u_int32_t mode);
     74   1.1      fvdl static struct agp_memory *agp_i810_alloc_memory(struct agp_softc *, int,
     75   1.1      fvdl 						vsize_t);
     76   1.1      fvdl static int agp_i810_free_memory(struct agp_softc *, struct agp_memory *);
     77   1.1      fvdl static int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *, off_t);
     78   1.1      fvdl static int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *);
     79   1.1      fvdl 
     80   1.1      fvdl struct agp_methods agp_i810_methods = {
     81   1.1      fvdl 	agp_i810_get_aperture,
     82   1.1      fvdl 	agp_i810_set_aperture,
     83   1.1      fvdl 	agp_i810_bind_page,
     84   1.1      fvdl 	agp_i810_unbind_page,
     85   1.1      fvdl 	agp_i810_flush_tlb,
     86   1.1      fvdl 	agp_i810_enable,
     87   1.1      fvdl 	agp_i810_alloc_memory,
     88   1.1      fvdl 	agp_i810_free_memory,
     89   1.1      fvdl 	agp_i810_bind_memory,
     90   1.1      fvdl 	agp_i810_unbind_memory,
     91   1.1      fvdl };
     92   1.1      fvdl 
     93   1.6   thorpej /* XXXthorpej -- duplicated code (see arch/i386/pci/pchb.c) */
     94   1.1      fvdl static int
     95   1.1      fvdl agp_i810_vgamatch(struct pci_attach_args *pa)
     96   1.1      fvdl {
     97   1.6   thorpej 
     98   1.2      fvdl 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
     99   1.2      fvdl 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    100   1.6   thorpej 		return (0);
    101   1.6   thorpej 
    102   1.1      fvdl 	switch (PCI_PRODUCT(pa->pa_id)) {
    103   1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_GC:
    104   1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_DC100_GC:
    105   1.1      fvdl 	case PCI_PRODUCT_INTEL_82810E_GC:
    106   1.1      fvdl 	case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
    107   1.6   thorpej 		return (1);
    108   1.1      fvdl 	}
    109   1.1      fvdl 
    110   1.6   thorpej 	return (0);
    111   1.1      fvdl }
    112   1.1      fvdl 
    113   1.1      fvdl int
    114   1.1      fvdl agp_i810_attach(struct device *parent, struct device *self, void *aux)
    115   1.1      fvdl {
    116   1.1      fvdl 	struct agp_softc *sc = (void *)self;
    117   1.1      fvdl 	struct agp_i810_softc *isc;
    118   1.1      fvdl 	struct agp_gatt *gatt;
    119   1.1      fvdl 	int error;
    120   1.1      fvdl 
    121  1.10   tsutsui 	isc = malloc(sizeof *isc, M_AGP, M_NOWAIT|M_ZERO);
    122   1.1      fvdl 	if (isc == NULL) {
    123   1.1      fvdl 		printf(": can't allocate chipset-specific softc\n");
    124   1.1      fvdl 		return ENOMEM;
    125   1.1      fvdl 	}
    126   1.1      fvdl 	sc->as_chipc = isc;
    127   1.1      fvdl 	sc->as_methods = &agp_i810_methods;
    128   1.1      fvdl 
    129   1.1      fvdl 	if (pci_find_device(&isc->vga_pa, agp_i810_vgamatch) == 0) {
    130   1.8      fvdl 		printf(": can't find internal VGA device config space\n");
    131   1.1      fvdl 		free(isc, M_AGP);
    132   1.1      fvdl 		return ENOENT;
    133   1.1      fvdl 	}
    134   1.1      fvdl 
    135   1.1      fvdl 	/* XXXfvdl */
    136   1.1      fvdl 	sc->as_dmat = isc->vga_pa.pa_dmat;
    137   1.1      fvdl 
    138   1.1      fvdl 	error = agp_map_aperture(&isc->vga_pa, sc);
    139   1.1      fvdl 	if (error != 0) {
    140   1.7  drochner 		printf(": can't map aperture\n");
    141   1.1      fvdl 		free(isc, M_AGP);
    142   1.1      fvdl 		return error;
    143   1.1      fvdl 	}
    144   1.1      fvdl 
    145   1.1      fvdl 	error = pci_mapreg_map(&isc->vga_pa, AGP_I810_MMADR,
    146   1.1      fvdl 	    PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh, NULL, NULL);
    147   1.1      fvdl 	if (error != 0) {
    148   1.1      fvdl 		printf(": can't map mmadr registers\n");
    149   1.1      fvdl 		return error;
    150   1.1      fvdl 	}
    151   1.1      fvdl 
    152   1.1      fvdl 	isc->initial_aperture = AGP_GET_APERTURE(sc);
    153   1.1      fvdl 
    154   1.1      fvdl 	if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
    155   1.1      fvdl 		isc->dcache_size = 4 * 1024 * 1024;
    156   1.1      fvdl 	else
    157   1.1      fvdl 		isc->dcache_size = 0;
    158   1.1      fvdl 
    159   1.1      fvdl 	for (;;) {
    160   1.1      fvdl 		gatt = agp_alloc_gatt(sc);
    161   1.1      fvdl 		if (gatt)
    162   1.1      fvdl 			break;
    163   1.1      fvdl 
    164   1.1      fvdl 		/*
    165   1.1      fvdl 		 * Probably contigmalloc failure. Try reducing the
    166   1.1      fvdl 		 * aperture so that the gatt size reduces.
    167   1.1      fvdl 		 */
    168   1.1      fvdl 		if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) {
    169   1.1      fvdl 			agp_generic_detach(sc);
    170   1.1      fvdl 			return ENOMEM;
    171   1.1      fvdl 		}
    172   1.1      fvdl 	}
    173   1.1      fvdl 	isc->gatt = gatt;
    174   1.1      fvdl 
    175   1.1      fvdl 	/* Install the GATT. */
    176   1.1      fvdl 	WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1);
    177   1.1      fvdl 
    178   1.1      fvdl 	/*
    179   1.1      fvdl 	 * Make sure the chipset can see everything.
    180   1.1      fvdl 	 */
    181   1.1      fvdl 	agp_flush_cache();
    182   1.1      fvdl 
    183   1.1      fvdl 	return 0;
    184   1.1      fvdl }
    185   1.1      fvdl 
    186   1.1      fvdl #if 0
    187   1.1      fvdl static int
    188   1.1      fvdl agp_i810_detach(struct agp_softc *sc)
    189   1.1      fvdl {
    190   1.1      fvdl 	int error;
    191   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    192   1.1      fvdl 
    193   1.1      fvdl 	error = agp_generic_detach(sc);
    194   1.1      fvdl 	if (error)
    195   1.1      fvdl 		return error;
    196   1.1      fvdl 
    197   1.1      fvdl 	/* Clear the GATT base. */
    198   1.1      fvdl 	WRITE4(AGP_I810_PGTBL_CTL, 0);
    199   1.1      fvdl 
    200   1.1      fvdl 	/* Put the aperture back the way it started. */
    201   1.1      fvdl 	AGP_SET_APERTURE(sc, isc->initial_aperture);
    202   1.1      fvdl 
    203   1.1      fvdl 	agp_free_gatt(sc, isc->gatt);
    204   1.1      fvdl 
    205   1.1      fvdl 	return 0;
    206   1.1      fvdl }
    207   1.1      fvdl #endif
    208   1.1      fvdl 
    209   1.1      fvdl static u_int32_t
    210   1.1      fvdl agp_i810_get_aperture(struct agp_softc *sc)
    211   1.1      fvdl {
    212   1.1      fvdl 	u_int16_t miscc;
    213   1.1      fvdl 
    214   1.1      fvdl 	miscc = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM) >> 16;
    215   1.1      fvdl 	if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
    216   1.1      fvdl 		return 32 * 1024 * 1024;
    217   1.1      fvdl 	else
    218   1.1      fvdl 		return 64 * 1024 * 1024;
    219   1.1      fvdl }
    220   1.1      fvdl 
    221   1.1      fvdl static int
    222   1.1      fvdl agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture)
    223   1.1      fvdl {
    224   1.1      fvdl 	pcireg_t reg, miscc;
    225   1.1      fvdl 
    226   1.1      fvdl 	/*
    227   1.1      fvdl 	 * Double check for sanity.
    228   1.1      fvdl 	 */
    229   1.1      fvdl 	if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
    230   1.1      fvdl 		printf("%s: bad aperture size %d\n", sc->as_dev.dv_xname,
    231   1.1      fvdl 		       aperture);
    232   1.1      fvdl 		return EINVAL;
    233   1.1      fvdl 	}
    234   1.1      fvdl 
    235   1.1      fvdl 	reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
    236   1.1      fvdl 	miscc = reg >> 16;
    237   1.1      fvdl 	miscc &= ~AGP_I810_MISCC_WINSIZE;
    238   1.1      fvdl 	if (aperture == 32 * 1024 * 1024)
    239   1.1      fvdl 		miscc |= AGP_I810_MISCC_WINSIZE_32;
    240   1.1      fvdl 	else
    241   1.1      fvdl 		miscc |= AGP_I810_MISCC_WINSIZE_64;
    242   1.1      fvdl 
    243   1.1      fvdl 	reg &= 0x0000ffff;
    244   1.1      fvdl 	reg |= (miscc << 16);
    245   1.1      fvdl 	pci_conf_write(sc->as_pc, sc->as_tag, AGP_I810_SMRAM, miscc);
    246   1.1      fvdl 
    247   1.1      fvdl 	return 0;
    248   1.1      fvdl }
    249   1.1      fvdl 
    250   1.1      fvdl static int
    251   1.1      fvdl agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical)
    252   1.1      fvdl {
    253   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    254   1.1      fvdl 
    255   1.1      fvdl 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
    256   1.1      fvdl 		return EINVAL;
    257   1.1      fvdl 
    258   1.1      fvdl 	WRITE4(AGP_I810_GTT + (u_int32_t)(offset >> AGP_PAGE_SHIFT) * 4,
    259   1.1      fvdl 	    physical | 1);
    260   1.1      fvdl 	return 0;
    261   1.1      fvdl }
    262   1.1      fvdl 
    263   1.1      fvdl static int
    264   1.1      fvdl agp_i810_unbind_page(struct agp_softc *sc, off_t offset)
    265   1.1      fvdl {
    266   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    267   1.1      fvdl 
    268   1.1      fvdl 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
    269   1.1      fvdl 		return EINVAL;
    270   1.1      fvdl 
    271   1.1      fvdl 	WRITE4(AGP_I810_GTT + (u_int32_t)(offset >> AGP_PAGE_SHIFT) * 4, 0);
    272   1.1      fvdl 	return 0;
    273   1.1      fvdl }
    274   1.1      fvdl 
    275   1.1      fvdl /*
    276   1.1      fvdl  * Writing via memory mapped registers already flushes all TLBs.
    277   1.1      fvdl  */
    278   1.1      fvdl static void
    279   1.1      fvdl agp_i810_flush_tlb(struct agp_softc *sc)
    280   1.1      fvdl {
    281   1.1      fvdl }
    282   1.1      fvdl 
    283   1.1      fvdl static int
    284   1.1      fvdl agp_i810_enable(struct agp_softc *sc, u_int32_t mode)
    285   1.1      fvdl {
    286   1.1      fvdl 
    287   1.1      fvdl 	return 0;
    288   1.1      fvdl }
    289   1.1      fvdl 
    290   1.1      fvdl static struct agp_memory *
    291   1.1      fvdl agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size)
    292   1.1      fvdl {
    293   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    294   1.1      fvdl 	struct agp_memory *mem;
    295   1.1      fvdl 
    296   1.1      fvdl 	if ((size & (AGP_PAGE_SIZE - 1)) != 0)
    297   1.1      fvdl 		return 0;
    298   1.1      fvdl 
    299   1.1      fvdl 	if (sc->as_allocated + size > sc->as_maxmem)
    300   1.1      fvdl 		return 0;
    301   1.1      fvdl 
    302   1.1      fvdl 	if (type == 1) {
    303   1.1      fvdl 		/*
    304   1.1      fvdl 		 * Mapping local DRAM into GATT.
    305   1.1      fvdl 		 */
    306   1.1      fvdl 		if (size != isc->dcache_size)
    307   1.1      fvdl 			return 0;
    308   1.1      fvdl 	} else if (type == 2) {
    309   1.1      fvdl 		/*
    310   1.1      fvdl 		 * Bogus mapping of a single page for the hardware cursor.
    311   1.1      fvdl 		 */
    312   1.1      fvdl 		if (size != AGP_PAGE_SIZE)
    313   1.1      fvdl 			return 0;
    314   1.1      fvdl 	}
    315   1.1      fvdl 
    316  1.10   tsutsui 	mem = malloc(sizeof *mem, M_AGP, M_WAITOK|M_ZERO);
    317   1.1      fvdl 	if (mem == NULL)
    318   1.1      fvdl 		return NULL;
    319   1.1      fvdl 	mem->am_id = sc->as_nextid++;
    320   1.1      fvdl 	mem->am_size = size;
    321   1.1      fvdl 	mem->am_type = type;
    322   1.1      fvdl 
    323   1.1      fvdl 	if (type == 2) {
    324   1.1      fvdl 		/*
    325   1.1      fvdl 		 * Allocate and wire down the page now so that we can
    326   1.1      fvdl 		 * get its physical address.
    327   1.1      fvdl 		 */
    328   1.1      fvdl 		mem->am_dmaseg = malloc(sizeof *mem->am_dmaseg, M_AGP,
    329   1.1      fvdl 		    M_WAITOK);
    330   1.1      fvdl 		if (mem->am_dmaseg == NULL) {
    331   1.1      fvdl 			free(mem, M_AGP);
    332   1.1      fvdl 			return NULL;
    333   1.1      fvdl 		}
    334   1.1      fvdl 		if (agp_alloc_dmamem(sc->as_dmat, size, 0,
    335   1.1      fvdl 		    &mem->am_dmamap, &mem->am_virtual, &mem->am_physical,
    336   1.1      fvdl 		    mem->am_dmaseg, 1, &mem->am_nseg) != 0) {
    337   1.1      fvdl 			free(mem->am_dmaseg, M_AGP);
    338   1.1      fvdl 			free(mem, M_AGP);
    339   1.1      fvdl 			return NULL;
    340   1.1      fvdl 		}
    341   1.1      fvdl 	} else if (type != 1) {
    342   1.4  drochner 		if (bus_dmamap_create(sc->as_dmat, size, size / PAGE_SIZE + 1,
    343   1.4  drochner 				      size, 0, BUS_DMA_NOWAIT,
    344   1.4  drochner 				      &mem->am_dmamap) != 0) {
    345   1.1      fvdl 			free(mem, M_AGP);
    346   1.1      fvdl 			return NULL;
    347   1.1      fvdl 		}
    348   1.1      fvdl 	}
    349   1.1      fvdl 
    350   1.1      fvdl 	TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link);
    351   1.1      fvdl 	sc->as_allocated += size;
    352   1.1      fvdl 
    353   1.1      fvdl 	return mem;
    354   1.1      fvdl }
    355   1.1      fvdl 
    356   1.1      fvdl static int
    357   1.1      fvdl agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem)
    358   1.1      fvdl {
    359   1.1      fvdl 	if (mem->am_is_bound)
    360   1.1      fvdl 		return EBUSY;
    361   1.1      fvdl 
    362   1.1      fvdl 	if (mem->am_type == 2) {
    363   1.1      fvdl 		agp_free_dmamem(sc->as_dmat, mem->am_size, mem->am_dmamap,
    364   1.1      fvdl 		    mem->am_virtual, mem->am_dmaseg, mem->am_nseg);
    365   1.1      fvdl 		free(mem->am_dmaseg, M_AGP);
    366   1.1      fvdl 	}
    367   1.1      fvdl 
    368   1.1      fvdl 	sc->as_allocated -= mem->am_size;
    369   1.1      fvdl 	TAILQ_REMOVE(&sc->as_memory, mem, am_link);
    370   1.1      fvdl 	free(mem, M_AGP);
    371   1.1      fvdl 	return 0;
    372   1.1      fvdl }
    373   1.1      fvdl 
    374   1.1      fvdl static int
    375   1.1      fvdl agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
    376   1.1      fvdl 		     off_t offset)
    377   1.1      fvdl {
    378   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    379   1.4  drochner 	u_int32_t regval, i;
    380   1.4  drochner 
    381   1.4  drochner 	/*
    382   1.4  drochner 	 * XXX evil hack: the PGTBL_CTL appearently gets overwritten by the
    383   1.4  drochner 	 * X server for mysterious reasons which leads to crashes if we write
    384   1.4  drochner 	 * to the GTT through the MMIO window.
    385   1.4  drochner 	 * Until the issue is solved, simply restore it.
    386   1.4  drochner 	 */
    387   1.4  drochner 	regval = bus_space_read_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL);
    388   1.4  drochner 	if (regval != (isc->gatt->ag_physical | 1)) {
    389   1.4  drochner 		printf("agp_i810_bind_memory: PGTBL_CTL is 0x%x - fixing\n",
    390   1.4  drochner 		       regval);
    391   1.4  drochner 		bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL,
    392   1.4  drochner 				  isc->gatt->ag_physical | 1);
    393   1.4  drochner 	}
    394   1.1      fvdl 
    395   1.5  drochner 	if (mem->am_type == 2) {
    396   1.5  drochner 		WRITE4(AGP_I810_GTT + (u_int32_t)(offset >> AGP_PAGE_SHIFT) * 4,
    397   1.5  drochner 		       mem->am_physical | 1);
    398   1.5  drochner 		mem->am_offset = offset;
    399   1.5  drochner 		mem->am_is_bound = 1;
    400   1.1      fvdl 		return 0;
    401   1.5  drochner 	}
    402   1.5  drochner 
    403   1.1      fvdl 	if (mem->am_type != 1)
    404   1.1      fvdl 		return agp_generic_bind_memory(sc, mem, offset);
    405   1.1      fvdl 
    406   1.1      fvdl 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
    407   1.1      fvdl 		WRITE4(AGP_I810_GTT + (u_int32_t)(offset >> AGP_PAGE_SHIFT) * 4,
    408   1.1      fvdl 		       i | 3);
    409   1.1      fvdl 	}
    410   1.1      fvdl 
    411   1.1      fvdl 	return 0;
    412   1.1      fvdl }
    413   1.1      fvdl 
    414   1.1      fvdl static int
    415   1.1      fvdl agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem)
    416   1.1      fvdl {
    417   1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    418   1.1      fvdl 	u_int32_t i;
    419   1.1      fvdl 
    420   1.5  drochner 	if (mem->am_type == 2) {
    421   1.5  drochner 		WRITE4(AGP_I810_GTT +
    422   1.5  drochner 		       (u_int32_t)(mem->am_offset >> AGP_PAGE_SHIFT) * 4,
    423   1.5  drochner 		       0);
    424   1.5  drochner 		mem->am_offset = 0;
    425   1.5  drochner 		mem->am_is_bound = 0;
    426   1.1      fvdl 		return 0;
    427   1.5  drochner 	}
    428   1.1      fvdl 
    429   1.1      fvdl 	if (mem->am_type != 1)
    430   1.1      fvdl 		return agp_generic_unbind_memory(sc, mem);
    431   1.1      fvdl 
    432   1.1      fvdl 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
    433   1.1      fvdl 		WRITE4(AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, 0);
    434   1.1      fvdl 
    435   1.1      fvdl 	return 0;
    436   1.1      fvdl }
    437