Home | History | Annotate | Line # | Download | only in pci
agp_i810.c revision 1.41.6.2
      1  1.41.6.2  jmcneill /*	$NetBSD: agp_i810.c,v 1.41.6.2 2007/08/06 19:49:35 jmcneill 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.41.6.2  jmcneill __KERNEL_RCSID(0, "$NetBSD: agp_i810.c,v 1.41.6.2 2007/08/06 19:49:35 jmcneill 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.20      tron #include "agp_intel.h"
     57      1.20      tron 
     58       1.1      fvdl #define READ1(off)	bus_space_read_1(isc->bst, isc->bsh, off)
     59      1.14       scw #define READ4(off)	bus_space_read_4(isc->bst, isc->bsh, off)
     60       1.1      fvdl #define WRITE4(off,v)	bus_space_write_4(isc->bst, isc->bsh, off, v)
     61      1.28  christos #define WRITEGTT(off, v)						\
     62      1.28  christos 	do {								\
     63      1.28  christos 		if (isc->chiptype == CHIP_I915) {			\
     64      1.28  christos 			bus_space_write_4(isc->gtt_bst, isc->gtt_bsh,	\
     65      1.28  christos 			    (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4,	\
     66      1.28  christos 			    (v));					\
     67      1.28  christos 		} else {						\
     68      1.28  christos 			WRITE4(AGP_I810_GTT +				\
     69      1.28  christos 			    (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4,	\
     70      1.28  christos 			    (v));					\
     71      1.28  christos 		}							\
     72      1.28  christos 	} while (0)
     73       1.1      fvdl 
     74      1.14       scw #define CHIP_I810 0	/* i810/i815 */
     75      1.17   hannken #define CHIP_I830 1	/* 830M/845G */
     76      1.17   hannken #define CHIP_I855 2	/* 852GM/855GM/865G */
     77      1.32    simonb #define CHIP_I915 3	/* 915G/915GM/945G/945GM */
     78      1.14       scw 
     79       1.1      fvdl struct agp_i810_softc {
     80       1.1      fvdl 	u_int32_t initial_aperture;	/* aperture size at startup */
     81       1.1      fvdl 	struct agp_gatt *gatt;
     82      1.14       scw 	int chiptype;			/* i810-like or i830 */
     83      1.14       scw 	u_int32_t dcache_size;		/* i810 only */
     84      1.14       scw 	u_int32_t stolen;		/* number of i830/845 gtt entries
     85      1.14       scw 					   for stolen memory */
     86      1.28  christos 	bus_space_tag_t bst;		/* register bus_space tag */
     87      1.28  christos 	bus_space_handle_t bsh;		/* register bus_space handle */
     88      1.28  christos 	bus_space_tag_t gtt_bst;	/* GTT bus_space tag */
     89      1.28  christos 	bus_space_handle_t gtt_bsh;	/* GTT bus_space handle */
     90       1.1      fvdl 	struct pci_attach_args vga_pa;
     91      1.24  jmcneill 
     92      1.24  jmcneill 	struct pci_conf_state sc_pciconf;
     93       1.1      fvdl };
     94       1.1      fvdl 
     95       1.1      fvdl static u_int32_t agp_i810_get_aperture(struct agp_softc *);
     96       1.1      fvdl static int agp_i810_set_aperture(struct agp_softc *, u_int32_t);
     97       1.1      fvdl static int agp_i810_bind_page(struct agp_softc *, off_t, bus_addr_t);
     98       1.1      fvdl static int agp_i810_unbind_page(struct agp_softc *, off_t);
     99       1.1      fvdl static void agp_i810_flush_tlb(struct agp_softc *);
    100       1.1      fvdl static int agp_i810_enable(struct agp_softc *, u_int32_t mode);
    101       1.1      fvdl static struct agp_memory *agp_i810_alloc_memory(struct agp_softc *, int,
    102       1.1      fvdl 						vsize_t);
    103       1.1      fvdl static int agp_i810_free_memory(struct agp_softc *, struct agp_memory *);
    104       1.1      fvdl static int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *, off_t);
    105       1.1      fvdl static int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *);
    106       1.1      fvdl 
    107      1.26   thorpej static struct agp_methods agp_i810_methods = {
    108       1.1      fvdl 	agp_i810_get_aperture,
    109       1.1      fvdl 	agp_i810_set_aperture,
    110       1.1      fvdl 	agp_i810_bind_page,
    111       1.1      fvdl 	agp_i810_unbind_page,
    112       1.1      fvdl 	agp_i810_flush_tlb,
    113       1.1      fvdl 	agp_i810_enable,
    114       1.1      fvdl 	agp_i810_alloc_memory,
    115       1.1      fvdl 	agp_i810_free_memory,
    116       1.1      fvdl 	agp_i810_bind_memory,
    117       1.1      fvdl 	agp_i810_unbind_memory,
    118       1.1      fvdl };
    119       1.1      fvdl 
    120       1.6   thorpej /* XXXthorpej -- duplicated code (see arch/i386/pci/pchb.c) */
    121       1.1      fvdl static int
    122       1.1      fvdl agp_i810_vgamatch(struct pci_attach_args *pa)
    123       1.1      fvdl {
    124       1.6   thorpej 
    125       1.2      fvdl 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
    126       1.2      fvdl 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    127       1.6   thorpej 		return (0);
    128       1.6   thorpej 
    129       1.1      fvdl 	switch (PCI_PRODUCT(pa->pa_id)) {
    130       1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_GC:
    131       1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_DC100_GC:
    132       1.1      fvdl 	case PCI_PRODUCT_INTEL_82810E_GC:
    133       1.1      fvdl 	case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
    134      1.14       scw 	case PCI_PRODUCT_INTEL_82830MP_IV:
    135      1.14       scw 	case PCI_PRODUCT_INTEL_82845G_IGD:
    136      1.17   hannken 	case PCI_PRODUCT_INTEL_82855GM_IGD:
    137      1.18      tron 	case PCI_PRODUCT_INTEL_82865_IGD:
    138      1.28  christos 	case PCI_PRODUCT_INTEL_82915G_IGD:
    139      1.28  christos 	case PCI_PRODUCT_INTEL_82915GM_IGD:
    140      1.32    simonb 	case PCI_PRODUCT_INTEL_82945P_IGD:
    141      1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD:
    142      1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD_1:
    143       1.6   thorpej 		return (1);
    144       1.1      fvdl 	}
    145       1.1      fvdl 
    146       1.6   thorpej 	return (0);
    147       1.1      fvdl }
    148       1.1      fvdl 
    149       1.1      fvdl int
    150       1.1      fvdl agp_i810_attach(struct device *parent, struct device *self, void *aux)
    151       1.1      fvdl {
    152       1.1      fvdl 	struct agp_softc *sc = (void *)self;
    153       1.1      fvdl 	struct agp_i810_softc *isc;
    154       1.1      fvdl 	struct agp_gatt *gatt;
    155      1.28  christos 	int error, apbase;
    156      1.37  drochner 	bus_size_t mmadrsize;
    157       1.1      fvdl 
    158      1.10   tsutsui 	isc = malloc(sizeof *isc, M_AGP, M_NOWAIT|M_ZERO);
    159       1.1      fvdl 	if (isc == NULL) {
    160      1.15   thorpej 		aprint_error(": can't allocate chipset-specific softc\n");
    161       1.1      fvdl 		return ENOMEM;
    162       1.1      fvdl 	}
    163       1.1      fvdl 	sc->as_chipc = isc;
    164       1.1      fvdl 	sc->as_methods = &agp_i810_methods;
    165       1.1      fvdl 
    166       1.1      fvdl 	if (pci_find_device(&isc->vga_pa, agp_i810_vgamatch) == 0) {
    167      1.20      tron #if NAGP_INTEL > 0
    168      1.19      tron 		const struct pci_attach_args *pa = aux;
    169      1.19      tron 
    170      1.19      tron 		switch (PCI_PRODUCT(pa->pa_id)) {
    171      1.19      tron 		case PCI_PRODUCT_INTEL_82840_HB:
    172      1.19      tron 		case PCI_PRODUCT_INTEL_82865_HB:
    173      1.21      tron 		case PCI_PRODUCT_INTEL_82845G_DRAM:
    174      1.23   xtraeme 		case PCI_PRODUCT_INTEL_82815_FULL_HUB:
    175      1.19      tron 			return agp_intel_attach(parent, self, aux);
    176      1.20      tron 		}
    177      1.20      tron #endif
    178      1.15   thorpej 		aprint_error(": can't find internal VGA device config space\n");
    179       1.1      fvdl 		free(isc, M_AGP);
    180       1.1      fvdl 		return ENOENT;
    181       1.1      fvdl 	}
    182       1.1      fvdl 
    183       1.1      fvdl 	/* XXXfvdl */
    184       1.1      fvdl 	sc->as_dmat = isc->vga_pa.pa_dmat;
    185       1.1      fvdl 
    186      1.14       scw 	switch (PCI_PRODUCT(isc->vga_pa.pa_id)) {
    187      1.14       scw 	case PCI_PRODUCT_INTEL_82810_GC:
    188      1.14       scw 	case PCI_PRODUCT_INTEL_82810_DC100_GC:
    189      1.14       scw 	case PCI_PRODUCT_INTEL_82810E_GC:
    190      1.14       scw 	case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
    191      1.14       scw 		isc->chiptype = CHIP_I810;
    192      1.14       scw 		break;
    193      1.14       scw 	case PCI_PRODUCT_INTEL_82830MP_IV:
    194      1.14       scw 	case PCI_PRODUCT_INTEL_82845G_IGD:
    195      1.14       scw 		isc->chiptype = CHIP_I830;
    196      1.14       scw 		break;
    197      1.17   hannken 	case PCI_PRODUCT_INTEL_82855GM_IGD:
    198      1.18      tron 	case PCI_PRODUCT_INTEL_82865_IGD:
    199      1.17   hannken 		isc->chiptype = CHIP_I855;
    200      1.17   hannken 		break;
    201      1.28  christos 	case PCI_PRODUCT_INTEL_82915G_IGD:
    202      1.28  christos 	case PCI_PRODUCT_INTEL_82915GM_IGD:
    203      1.32    simonb 	case PCI_PRODUCT_INTEL_82945P_IGD:
    204      1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD:
    205      1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD_1:
    206      1.28  christos 		isc->chiptype = CHIP_I915;
    207      1.28  christos 		break;
    208      1.14       scw 	}
    209      1.14       scw 
    210      1.28  christos 	apbase = isc->chiptype == CHIP_I915 ? AGP_I915_GMADR : AGP_I810_GMADR;
    211      1.28  christos 	error = agp_map_aperture(&isc->vga_pa, sc, apbase);
    212       1.1      fvdl 	if (error != 0) {
    213      1.28  christos 		aprint_error(": can't map aperture\n");
    214      1.28  christos 		free(isc, M_AGP);
    215       1.1      fvdl 		return error;
    216       1.1      fvdl 	}
    217       1.1      fvdl 
    218      1.28  christos 	if (isc->chiptype == CHIP_I915) {
    219      1.28  christos 		error = pci_mapreg_map(&isc->vga_pa, AGP_I915_MMADR,
    220      1.39  drochner 		    PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh,
    221      1.39  drochner 		    NULL, &mmadrsize);
    222      1.28  christos 		if (error != 0) {
    223      1.28  christos 			aprint_error(": can't map mmadr registers\n");
    224      1.28  christos 			agp_generic_detach(sc);
    225      1.28  christos 			return error;
    226      1.28  christos 		}
    227      1.28  christos 		error = pci_mapreg_map(&isc->vga_pa, AGP_I915_GTTADR,
    228      1.28  christos 		    PCI_MAPREG_TYPE_MEM, 0, &isc->gtt_bst, &isc->gtt_bsh,
    229      1.28  christos 		    NULL, NULL);
    230      1.28  christos 		if (error != 0) {
    231      1.28  christos 			aprint_error(": can't map gttadr registers\n");
    232      1.28  christos 			/* XXX we should release mmadr here */
    233      1.28  christos 			agp_generic_detach(sc);
    234      1.28  christos 			return error;
    235      1.28  christos 		}
    236      1.28  christos 	} else {
    237      1.28  christos 		error = pci_mapreg_map(&isc->vga_pa, AGP_I810_MMADR,
    238      1.39  drochner 		    PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh,
    239      1.39  drochner 		    NULL, &mmadrsize);
    240      1.28  christos 		if (error != 0) {
    241      1.28  christos 			aprint_error(": can't map mmadr registers\n");
    242      1.28  christos 			agp_generic_detach(sc);
    243      1.28  christos 			return error;
    244      1.28  christos 		}
    245      1.28  christos 	}
    246      1.28  christos 
    247       1.1      fvdl 	isc->initial_aperture = AGP_GET_APERTURE(sc);
    248       1.1      fvdl 
    249      1.14       scw 	gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_NOWAIT);
    250      1.14       scw 	if (!gatt) {
    251      1.14       scw  		agp_generic_detach(sc);
    252      1.14       scw  		return ENOMEM;
    253      1.14       scw 	}
    254      1.14       scw 	isc->gatt = gatt;
    255      1.14       scw 
    256      1.14       scw 	gatt->ag_entries = AGP_GET_APERTURE(sc) >> AGP_PAGE_SHIFT;
    257       1.1      fvdl 
    258      1.14       scw 	if (isc->chiptype == CHIP_I810) {
    259      1.36  christos 		void *virtual;
    260      1.14       scw 		int dummyseg;
    261      1.31      tron 
    262      1.14       scw 		/* Some i810s have on-chip memory called dcache */
    263      1.14       scw 		if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
    264      1.14       scw 			isc->dcache_size = 4 * 1024 * 1024;
    265      1.14       scw 		else
    266      1.14       scw 			isc->dcache_size = 0;
    267      1.14       scw 
    268      1.14       scw 		/* According to the specs the gatt on the i810 must be 64k */
    269      1.14       scw 		if (agp_alloc_dmamem(sc->as_dmat, 64 * 1024,
    270      1.31      tron 		    0, &gatt->ag_dmamap, &virtual, &gatt->ag_physical,
    271      1.31      tron 		    &gatt->ag_dmaseg, 1, &dummyseg) != 0) {
    272      1.14       scw 			free(gatt, M_AGP);
    273       1.1      fvdl 			agp_generic_detach(sc);
    274       1.1      fvdl 			return ENOMEM;
    275       1.1      fvdl 		}
    276      1.31      tron 		gatt->ag_virtual = (uint32_t *)virtual;
    277      1.14       scw 
    278      1.14       scw 		gatt->ag_size = gatt->ag_entries * sizeof(u_int32_t);
    279      1.14       scw 		memset(gatt->ag_virtual, 0, gatt->ag_size);
    280      1.25     perry 
    281      1.14       scw 		agp_flush_cache();
    282      1.14       scw 		/* Install the GATT. */
    283      1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1);
    284      1.17   hannken 	} else if (isc->chiptype == CHIP_I830) {
    285      1.14       scw 		/* The i830 automatically initializes the 128k gatt on boot. */
    286      1.14       scw 		pcireg_t reg;
    287      1.14       scw 		u_int32_t pgtblctl;
    288      1.14       scw 		u_int16_t gcc1;
    289      1.14       scw 
    290      1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
    291      1.14       scw 		gcc1 = (u_int16_t)(reg >> 16);
    292      1.14       scw 		switch (gcc1 & AGP_I830_GCC1_GMS) {
    293      1.14       scw 		case AGP_I830_GCC1_GMS_STOLEN_512:
    294      1.14       scw 			isc->stolen = (512 - 132) * 1024 / 4096;
    295      1.14       scw 			break;
    296      1.25     perry 		case AGP_I830_GCC1_GMS_STOLEN_1024:
    297      1.14       scw 			isc->stolen = (1024 - 132) * 1024 / 4096;
    298      1.14       scw 			break;
    299      1.25     perry 		case AGP_I830_GCC1_GMS_STOLEN_8192:
    300      1.14       scw 			isc->stolen = (8192 - 132) * 1024 / 4096;
    301      1.14       scw 			break;
    302      1.14       scw 		default:
    303      1.14       scw 			isc->stolen = 0;
    304      1.15   thorpej 			aprint_error(
    305      1.15   thorpej 			    ": unknown memory configuration, disabling\n");
    306      1.14       scw 			agp_generic_detach(sc);
    307      1.14       scw 			return EINVAL;
    308      1.14       scw 		}
    309      1.14       scw 		if (isc->stolen > 0) {
    310      1.17   hannken 			aprint_error(": detected %dk stolen memory\n%s",
    311      1.17   hannken 			    isc->stolen * 4, sc->as_dev.dv_xname);
    312      1.14       scw 		}
    313      1.17   hannken 
    314      1.17   hannken 		/* GATT address is already in there, make sure it's enabled */
    315      1.17   hannken 		pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    316      1.17   hannken 		pgtblctl |= 1;
    317      1.17   hannken 		WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
    318      1.17   hannken 
    319      1.17   hannken 		gatt->ag_physical = pgtblctl & ~1;
    320      1.28  christos 	} else if (isc->chiptype == CHIP_I855) {
    321      1.17   hannken 		/* The 855GM automatically initializes the 128k gatt on boot. */
    322      1.17   hannken 		pcireg_t reg;
    323      1.17   hannken 		u_int32_t pgtblctl;
    324      1.17   hannken 		u_int16_t gcc1;
    325      1.17   hannken 
    326      1.17   hannken 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I855_GCC1);
    327      1.17   hannken 		gcc1 = (u_int16_t)(reg >> 16);
    328      1.17   hannken 		switch (gcc1 & AGP_I855_GCC1_GMS) {
    329      1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_1M:
    330      1.17   hannken 			isc->stolen = (1024 - 132) * 1024 / 4096;
    331      1.17   hannken 			break;
    332      1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_4M:
    333      1.17   hannken 			isc->stolen = (4096 - 132) * 1024 / 4096;
    334      1.17   hannken 			break;
    335      1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_8M:
    336      1.17   hannken 			isc->stolen = (8192 - 132) * 1024 / 4096;
    337      1.17   hannken 			break;
    338      1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_16M:
    339      1.17   hannken 			isc->stolen = (16384 - 132) * 1024 / 4096;
    340      1.17   hannken 			break;
    341      1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_32M:
    342      1.17   hannken 			isc->stolen = (32768 - 132) * 1024 / 4096;
    343      1.17   hannken 			break;
    344      1.17   hannken 		default:
    345      1.17   hannken 			isc->stolen = 0;
    346      1.17   hannken 			aprint_error(
    347      1.17   hannken 			    ": unknown memory configuration, disabling\n");
    348      1.17   hannken 			agp_generic_detach(sc);
    349      1.17   hannken 			return EINVAL;
    350      1.17   hannken 		}
    351      1.17   hannken 		if (isc->stolen > 0) {
    352      1.17   hannken 			aprint_error(": detected %dk stolen memory\n%s",
    353      1.17   hannken 			    isc->stolen * 4, sc->as_dev.dv_xname);
    354      1.17   hannken 		}
    355      1.14       scw 
    356      1.14       scw 		/* GATT address is already in there, make sure it's enabled */
    357      1.14       scw 		pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    358      1.14       scw 		pgtblctl |= 1;
    359      1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
    360      1.14       scw 
    361      1.14       scw 		gatt->ag_physical = pgtblctl & ~1;
    362      1.28  christos 	} else {	/* CHIP_I915 */
    363      1.28  christos 		/* The 915G automatically initializes the 256k gatt on boot. */
    364      1.28  christos 		pcireg_t reg;
    365      1.28  christos 		u_int32_t pgtblctl;
    366      1.28  christos 		u_int16_t gcc1;
    367      1.28  christos 
    368      1.28  christos 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I915_GCC1);
    369      1.28  christos 		gcc1 = (u_int16_t)(reg >> 16);
    370      1.28  christos 		switch (gcc1 & AGP_I915_GCC1_GMS) {
    371      1.28  christos 		case AGP_I915_GCC1_GMS_STOLEN_0M:
    372      1.28  christos 			isc->stolen = 0;
    373      1.28  christos 			break;
    374      1.28  christos 		case AGP_I915_GCC1_GMS_STOLEN_1M:
    375      1.28  christos 			isc->stolen = (1024 - 260) * 1024 / 4096;
    376      1.28  christos 			break;
    377      1.28  christos 		case AGP_I915_GCC1_GMS_STOLEN_8M:
    378      1.28  christos 			isc->stolen = (8192 - 260) * 1024 / 4096;
    379      1.28  christos 			break;
    380      1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_16M:
    381      1.41  sborrill 			isc->stolen = (16384 - 260) * 1024 / 4096;
    382      1.41  sborrill 			break;
    383      1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_32M:
    384      1.41  sborrill 			isc->stolen = (32768 - 260) * 1024 / 4096;
    385      1.41  sborrill 			break;
    386      1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_48M:
    387      1.41  sborrill 			isc->stolen = (49152 - 260) * 1024 / 4096;
    388      1.41  sborrill 			break;
    389      1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_64M:
    390      1.41  sborrill 			isc->stolen = (65536 - 260) * 1024 / 4096;
    391      1.41  sborrill 			break;
    392      1.28  christos 		default:
    393      1.28  christos 			isc->stolen = 0;
    394      1.28  christos 			aprint_error(
    395      1.28  christos 			    ": unknown memory configuration, disabling\n");
    396      1.28  christos 			agp_generic_detach(sc);
    397      1.28  christos 			return EINVAL;
    398      1.28  christos 		}
    399      1.28  christos 		if (isc->stolen > 0) {
    400      1.28  christos 			aprint_error(": detected %dk stolen memory\n%s",
    401      1.28  christos 			    isc->stolen * 4, sc->as_dev.dv_xname);
    402      1.28  christos 		}
    403      1.28  christos 
    404      1.28  christos 		/* GATT address is already in there, make sure it's enabled */
    405      1.28  christos 		pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    406      1.28  christos 		pgtblctl |= 1;
    407      1.28  christos 		WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
    408      1.28  christos 
    409      1.28  christos 		gatt->ag_physical = pgtblctl & ~1;
    410       1.1      fvdl 	}
    411       1.1      fvdl 
    412       1.1      fvdl 	/*
    413       1.1      fvdl 	 * Make sure the chipset can see everything.
    414       1.1      fvdl 	 */
    415       1.1      fvdl 	agp_flush_cache();
    416      1.14       scw 
    417      1.40  christos #if 0
    418      1.37  drochner 	/*
    419      1.37  drochner 	 * another device (drm) may need access to this region
    420      1.37  drochner 	 * we do not need it anymore
    421      1.37  drochner 	 */
    422      1.37  drochner 	bus_space_unmap(isc->bst, isc->bsh, mmadrsize);
    423      1.40  christos #endif
    424      1.37  drochner 
    425       1.1      fvdl 	return 0;
    426       1.1      fvdl }
    427       1.1      fvdl 
    428       1.1      fvdl #if 0
    429       1.1      fvdl static int
    430       1.1      fvdl agp_i810_detach(struct agp_softc *sc)
    431       1.1      fvdl {
    432       1.1      fvdl 	int error;
    433       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    434       1.1      fvdl 
    435       1.1      fvdl 	error = agp_generic_detach(sc);
    436       1.1      fvdl 	if (error)
    437       1.1      fvdl 		return error;
    438       1.1      fvdl 
    439       1.1      fvdl 	/* Clear the GATT base. */
    440      1.14       scw 	if (sc->chiptype == CHIP_I810) {
    441      1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, 0);
    442      1.14       scw 	} else {
    443      1.14       scw 		unsigned int pgtblctl;
    444      1.14       scw 		pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    445      1.14       scw 		pgtblctl &= ~1;
    446      1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
    447      1.14       scw 	}
    448       1.1      fvdl 
    449       1.1      fvdl 	/* Put the aperture back the way it started. */
    450       1.1      fvdl 	AGP_SET_APERTURE(sc, isc->initial_aperture);
    451       1.1      fvdl 
    452      1.14       scw 	if (sc->chiptype == CHIP_I810) {
    453      1.14       scw 		agp_free_dmamem(sc->as_dmat, gatt->ag_size, gatt->ag_dmamap,
    454      1.36  christos 		    (void *)gatt->ag_virtual, &gatt->ag_dmaseg, 1);
    455      1.14       scw 	}
    456      1.14       scw 	free(sc->gatt, M_AGP);
    457       1.1      fvdl 
    458       1.1      fvdl 	return 0;
    459       1.1      fvdl }
    460       1.1      fvdl #endif
    461       1.1      fvdl 
    462       1.1      fvdl static u_int32_t
    463       1.1      fvdl agp_i810_get_aperture(struct agp_softc *sc)
    464       1.1      fvdl {
    465      1.14       scw 	struct agp_i810_softc *isc = sc->as_chipc;
    466      1.14       scw 	pcireg_t reg;
    467      1.14       scw 
    468      1.14       scw 	if (isc->chiptype == CHIP_I810) {
    469      1.14       scw 		u_int16_t miscc;
    470       1.1      fvdl 
    471      1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
    472      1.14       scw 		miscc = (u_int16_t)(reg >> 16);
    473      1.14       scw 		if ((miscc & AGP_I810_MISCC_WINSIZE) ==
    474      1.14       scw 		    AGP_I810_MISCC_WINSIZE_32)
    475      1.14       scw 			return 32 * 1024 * 1024;
    476      1.14       scw 		else
    477      1.14       scw 			return 64 * 1024 * 1024;
    478      1.17   hannken 	} else if (isc->chiptype == CHIP_I830) {
    479      1.14       scw 		u_int16_t gcc1;
    480      1.14       scw 
    481      1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
    482      1.14       scw 		gcc1 = (u_int16_t)(reg >> 16);
    483      1.14       scw 		if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
    484      1.14       scw 			return 64 * 1024 * 1024;
    485      1.14       scw 		else
    486      1.14       scw 			return 128 * 1024 * 1024;
    487      1.28  christos 	} else if (isc->chiptype == CHIP_I855) {
    488      1.17   hannken 		return 128 * 1024 * 1024;
    489      1.28  christos 	} else {	/* CHIP_I915 */
    490      1.28  christos 		u_int16_t msac;
    491      1.28  christos 
    492      1.28  christos 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I915_MSAC);
    493      1.28  christos 		msac = (u_int16_t)(reg >> 16);
    494      1.28  christos 		if (msac & AGP_I915_MSAC_APER_128M)
    495      1.28  christos 			return 128 * 1024 * 1024;
    496      1.28  christos 		else
    497      1.28  christos 			return 256 * 1024 * 1024;
    498      1.14       scw 	}
    499       1.1      fvdl }
    500       1.1      fvdl 
    501       1.1      fvdl static int
    502       1.1      fvdl agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture)
    503       1.1      fvdl {
    504      1.14       scw 	struct agp_i810_softc *isc = sc->as_chipc;
    505      1.14       scw 	pcireg_t reg;
    506      1.14       scw 
    507      1.14       scw 	if (isc->chiptype == CHIP_I810) {
    508      1.14       scw 		u_int16_t miscc;
    509      1.14       scw 
    510      1.14       scw 		/*
    511      1.14       scw 		 * Double check for sanity.
    512      1.14       scw 		 */
    513      1.14       scw 		if (aperture != (32 * 1024 * 1024) &&
    514      1.14       scw 		    aperture != (64 * 1024 * 1024)) {
    515      1.14       scw 			printf("%s: bad aperture size %d\n",
    516      1.14       scw 			    sc->as_dev.dv_xname, aperture);
    517      1.14       scw 			return EINVAL;
    518      1.14       scw 		}
    519       1.1      fvdl 
    520      1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
    521      1.14       scw 		miscc = (u_int16_t)(reg >> 16);
    522      1.14       scw 		miscc &= ~AGP_I810_MISCC_WINSIZE;
    523      1.14       scw 		if (aperture == 32 * 1024 * 1024)
    524      1.14       scw 			miscc |= AGP_I810_MISCC_WINSIZE_32;
    525      1.14       scw 		else
    526      1.14       scw 			miscc |= AGP_I810_MISCC_WINSIZE_64;
    527      1.14       scw 
    528      1.14       scw 		reg &= 0x0000ffff;
    529      1.14       scw 		reg |= ((pcireg_t)miscc) << 16;
    530      1.14       scw 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_I810_SMRAM, reg);
    531      1.28  christos 	} else if (isc->chiptype == CHIP_I830) {
    532      1.14       scw 		u_int16_t gcc1;
    533      1.14       scw 
    534      1.14       scw 		if (aperture != (64 * 1024 * 1024) &&
    535      1.14       scw 		    aperture != (128 * 1024 * 1024)) {
    536      1.14       scw 			printf("%s: bad aperture size %d\n",
    537      1.14       scw 			    sc->as_dev.dv_xname, aperture);
    538      1.14       scw 			return EINVAL;
    539      1.14       scw 		}
    540      1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
    541      1.14       scw 		gcc1 = (u_int16_t)(reg >> 16);
    542      1.14       scw 		gcc1 &= ~AGP_I830_GCC1_GMASIZE;
    543      1.14       scw 		if (aperture == 64 * 1024 * 1024)
    544      1.14       scw 			gcc1 |= AGP_I830_GCC1_GMASIZE_64;
    545      1.14       scw 		else
    546      1.14       scw 			gcc1 |= AGP_I830_GCC1_GMASIZE_128;
    547      1.14       scw 
    548      1.14       scw 		reg &= 0x0000ffff;
    549      1.14       scw 		reg |= ((pcireg_t)gcc1) << 16;
    550      1.14       scw 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_I830_GCC0, reg);
    551      1.28  christos 	} else {	/* CHIP_I855 or CHIP_I915 */
    552      1.28  christos 		if (aperture != agp_i810_get_aperture(sc)) {
    553      1.17   hannken 			printf("%s: bad aperture size %d\n",
    554      1.17   hannken 			    sc->as_dev.dv_xname, aperture);
    555      1.17   hannken 			return EINVAL;
    556      1.17   hannken 		}
    557       1.1      fvdl 	}
    558       1.1      fvdl 
    559       1.1      fvdl 	return 0;
    560       1.1      fvdl }
    561       1.1      fvdl 
    562       1.1      fvdl static int
    563       1.1      fvdl agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical)
    564       1.1      fvdl {
    565       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    566       1.1      fvdl 
    567      1.14       scw 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
    568      1.29    rpaulo #ifdef AGP_DEBUG
    569      1.14       scw 		printf("%s: failed: offset 0x%08x, shift %d, entries %d\n",
    570      1.14       scw 		    sc->as_dev.dv_xname, (int)offset, AGP_PAGE_SHIFT,
    571      1.14       scw 		    isc->gatt->ag_entries);
    572      1.14       scw #endif
    573       1.1      fvdl 		return EINVAL;
    574      1.14       scw 	}
    575      1.14       scw 
    576      1.17   hannken 	if (isc->chiptype != CHIP_I830) {
    577      1.14       scw 		if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
    578      1.29    rpaulo #ifdef AGP_DEBUG
    579      1.14       scw 			printf("%s: trying to bind into stolen memory",
    580      1.14       scw 			    sc->as_dev.dv_xname);
    581      1.14       scw #endif
    582      1.14       scw 			return EINVAL;
    583      1.14       scw 		}
    584      1.14       scw 	}
    585       1.1      fvdl 
    586      1.28  christos 	WRITEGTT(offset, physical | 1);
    587       1.1      fvdl 	return 0;
    588       1.1      fvdl }
    589       1.1      fvdl 
    590       1.1      fvdl static int
    591       1.1      fvdl agp_i810_unbind_page(struct agp_softc *sc, off_t offset)
    592       1.1      fvdl {
    593       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    594       1.1      fvdl 
    595       1.1      fvdl 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
    596       1.1      fvdl 		return EINVAL;
    597       1.1      fvdl 
    598      1.17   hannken 	if (isc->chiptype != CHIP_I810 ) {
    599      1.14       scw 		if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
    600      1.29    rpaulo #ifdef AGP_DEBUG
    601      1.14       scw 			printf("%s: trying to unbind from stolen memory",
    602      1.14       scw 			    sc->as_dev.dv_xname);
    603      1.14       scw #endif
    604      1.14       scw 			return EINVAL;
    605      1.14       scw 		}
    606      1.14       scw 	}
    607      1.14       scw 
    608      1.28  christos 	WRITEGTT(offset, 0);
    609       1.1      fvdl 	return 0;
    610       1.1      fvdl }
    611       1.1      fvdl 
    612       1.1      fvdl /*
    613       1.1      fvdl  * Writing via memory mapped registers already flushes all TLBs.
    614       1.1      fvdl  */
    615       1.1      fvdl static void
    616      1.35  christos agp_i810_flush_tlb(struct agp_softc *sc)
    617       1.1      fvdl {
    618       1.1      fvdl }
    619       1.1      fvdl 
    620       1.1      fvdl static int
    621      1.35  christos agp_i810_enable(struct agp_softc *sc, u_int32_t mode)
    622       1.1      fvdl {
    623       1.1      fvdl 
    624       1.1      fvdl 	return 0;
    625       1.1      fvdl }
    626       1.1      fvdl 
    627       1.1      fvdl static struct agp_memory *
    628       1.1      fvdl agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size)
    629       1.1      fvdl {
    630       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    631       1.1      fvdl 	struct agp_memory *mem;
    632       1.1      fvdl 
    633      1.29    rpaulo #ifdef AGP_DEBUG
    634      1.28  christos 	printf("AGP: alloc(%d, 0x%x)\n", type, (int) size);
    635      1.28  christos #endif
    636      1.28  christos 
    637       1.1      fvdl 	if ((size & (AGP_PAGE_SIZE - 1)) != 0)
    638       1.1      fvdl 		return 0;
    639       1.1      fvdl 
    640       1.1      fvdl 	if (sc->as_allocated + size > sc->as_maxmem)
    641       1.1      fvdl 		return 0;
    642       1.1      fvdl 
    643       1.1      fvdl 	if (type == 1) {
    644       1.1      fvdl 		/*
    645       1.1      fvdl 		 * Mapping local DRAM into GATT.
    646       1.1      fvdl 		 */
    647      1.17   hannken 		if (isc->chiptype != CHIP_I810 )
    648      1.14       scw 			return 0;
    649       1.1      fvdl 		if (size != isc->dcache_size)
    650       1.1      fvdl 			return 0;
    651       1.1      fvdl 	} else if (type == 2) {
    652       1.1      fvdl 		/*
    653      1.28  christos 		 * Bogus mapping for the hardware cursor.
    654       1.1      fvdl 		 */
    655      1.28  christos 		if (size != AGP_PAGE_SIZE && size != 4 * AGP_PAGE_SIZE)
    656       1.1      fvdl 			return 0;
    657       1.1      fvdl 	}
    658       1.1      fvdl 
    659      1.10   tsutsui 	mem = malloc(sizeof *mem, M_AGP, M_WAITOK|M_ZERO);
    660       1.1      fvdl 	if (mem == NULL)
    661       1.1      fvdl 		return NULL;
    662       1.1      fvdl 	mem->am_id = sc->as_nextid++;
    663       1.1      fvdl 	mem->am_size = size;
    664       1.1      fvdl 	mem->am_type = type;
    665       1.1      fvdl 
    666       1.1      fvdl 	if (type == 2) {
    667       1.1      fvdl 		/*
    668      1.28  christos 		 * Allocate and wire down the memory now so that we can
    669       1.1      fvdl 		 * get its physical address.
    670       1.1      fvdl 		 */
    671       1.1      fvdl 		mem->am_dmaseg = malloc(sizeof *mem->am_dmaseg, M_AGP,
    672       1.1      fvdl 		    M_WAITOK);
    673       1.1      fvdl 		if (mem->am_dmaseg == NULL) {
    674       1.1      fvdl 			free(mem, M_AGP);
    675       1.1      fvdl 			return NULL;
    676       1.1      fvdl 		}
    677       1.1      fvdl 		if (agp_alloc_dmamem(sc->as_dmat, size, 0,
    678       1.1      fvdl 		    &mem->am_dmamap, &mem->am_virtual, &mem->am_physical,
    679       1.1      fvdl 		    mem->am_dmaseg, 1, &mem->am_nseg) != 0) {
    680       1.1      fvdl 			free(mem->am_dmaseg, M_AGP);
    681       1.1      fvdl 			free(mem, M_AGP);
    682       1.1      fvdl 			return NULL;
    683       1.1      fvdl 		}
    684      1.28  christos 		memset(mem->am_virtual, 0, size);
    685       1.1      fvdl 	} else if (type != 1) {
    686       1.4  drochner 		if (bus_dmamap_create(sc->as_dmat, size, size / PAGE_SIZE + 1,
    687       1.4  drochner 				      size, 0, BUS_DMA_NOWAIT,
    688       1.4  drochner 				      &mem->am_dmamap) != 0) {
    689       1.1      fvdl 			free(mem, M_AGP);
    690       1.1      fvdl 			return NULL;
    691       1.1      fvdl 		}
    692       1.1      fvdl 	}
    693       1.1      fvdl 
    694       1.1      fvdl 	TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link);
    695       1.1      fvdl 	sc->as_allocated += size;
    696       1.1      fvdl 
    697       1.1      fvdl 	return mem;
    698       1.1      fvdl }
    699       1.1      fvdl 
    700       1.1      fvdl static int
    701       1.1      fvdl agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem)
    702       1.1      fvdl {
    703       1.1      fvdl 	if (mem->am_is_bound)
    704       1.1      fvdl 		return EBUSY;
    705       1.1      fvdl 
    706       1.1      fvdl 	if (mem->am_type == 2) {
    707       1.1      fvdl 		agp_free_dmamem(sc->as_dmat, mem->am_size, mem->am_dmamap,
    708       1.1      fvdl 		    mem->am_virtual, mem->am_dmaseg, mem->am_nseg);
    709       1.1      fvdl 		free(mem->am_dmaseg, M_AGP);
    710       1.1      fvdl 	}
    711       1.1      fvdl 
    712       1.1      fvdl 	sc->as_allocated -= mem->am_size;
    713       1.1      fvdl 	TAILQ_REMOVE(&sc->as_memory, mem, am_link);
    714       1.1      fvdl 	free(mem, M_AGP);
    715       1.1      fvdl 	return 0;
    716       1.1      fvdl }
    717       1.1      fvdl 
    718       1.1      fvdl static int
    719       1.1      fvdl agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
    720       1.1      fvdl 		     off_t offset)
    721       1.1      fvdl {
    722       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    723       1.4  drochner 	u_int32_t regval, i;
    724       1.4  drochner 
    725       1.4  drochner 	/*
    726       1.4  drochner 	 * XXX evil hack: the PGTBL_CTL appearently gets overwritten by the
    727       1.4  drochner 	 * X server for mysterious reasons which leads to crashes if we write
    728       1.4  drochner 	 * to the GTT through the MMIO window.
    729       1.4  drochner 	 * Until the issue is solved, simply restore it.
    730       1.4  drochner 	 */
    731      1.37  drochner 
    732      1.37  drochner #if 0
    733       1.4  drochner 	regval = bus_space_read_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL);
    734       1.4  drochner 	if (regval != (isc->gatt->ag_physical | 1)) {
    735       1.4  drochner 		printf("agp_i810_bind_memory: PGTBL_CTL is 0x%x - fixing\n",
    736       1.4  drochner 		       regval);
    737       1.4  drochner 		bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL,
    738       1.4  drochner 				  isc->gatt->ag_physical | 1);
    739       1.4  drochner 	}
    740      1.37  drochner #endif
    741      1.37  drochner 	regval = 0;
    742       1.1      fvdl 
    743       1.5  drochner 	if (mem->am_type == 2) {
    744      1.28  christos 		WRITEGTT(offset, mem->am_physical | 1);
    745       1.5  drochner 		mem->am_offset = offset;
    746       1.5  drochner 		mem->am_is_bound = 1;
    747       1.1      fvdl 		return 0;
    748       1.5  drochner 	}
    749       1.5  drochner 
    750       1.1      fvdl 	if (mem->am_type != 1)
    751       1.1      fvdl 		return agp_generic_bind_memory(sc, mem, offset);
    752       1.1      fvdl 
    753      1.17   hannken 	if (isc->chiptype != CHIP_I810)
    754      1.14       scw 		return EINVAL;
    755      1.14       scw 
    756      1.28  christos 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
    757      1.28  christos 		WRITEGTT(offset, i | 3);
    758      1.13  drochner 	mem->am_is_bound = 1;
    759       1.1      fvdl 	return 0;
    760       1.1      fvdl }
    761       1.1      fvdl 
    762       1.1      fvdl static int
    763       1.1      fvdl agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem)
    764       1.1      fvdl {
    765       1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
    766       1.1      fvdl 	u_int32_t i;
    767       1.1      fvdl 
    768       1.5  drochner 	if (mem->am_type == 2) {
    769      1.28  christos 		WRITEGTT(mem->am_offset, 0);
    770       1.5  drochner 		mem->am_offset = 0;
    771       1.5  drochner 		mem->am_is_bound = 0;
    772       1.1      fvdl 		return 0;
    773       1.5  drochner 	}
    774       1.1      fvdl 
    775       1.1      fvdl 	if (mem->am_type != 1)
    776       1.1      fvdl 		return agp_generic_unbind_memory(sc, mem);
    777      1.14       scw 
    778      1.17   hannken 	if (isc->chiptype != CHIP_I810)
    779      1.14       scw 		return EINVAL;
    780       1.1      fvdl 
    781       1.1      fvdl 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
    782      1.28  christos 		WRITEGTT(i, 0);
    783      1.13  drochner 	mem->am_is_bound = 0;
    784       1.1      fvdl 	return 0;
    785       1.1      fvdl }
    786