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