Home | History | Annotate | Line # | Download | only in pci
agp_intel.c revision 1.24
      1  1.24     joerg /*	$NetBSD: agp_intel.c,v 1.24 2007/11/12 20:00:17 joerg Exp $	*/
      2   1.1      fvdl 
      3   1.1      fvdl /*-
      4   1.1      fvdl  * Copyright (c) 2000 Doug Rabson
      5   1.1      fvdl  * All rights reserved.
      6   1.1      fvdl  *
      7   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
      8   1.1      fvdl  * modification, are permitted provided that the following conditions
      9   1.1      fvdl  * are met:
     10   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     11   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     12   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     15   1.1      fvdl  *
     16   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17   1.1      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18   1.1      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19   1.1      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20   1.1      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21   1.1      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22   1.1      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23   1.1      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24   1.1      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25   1.1      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26   1.1      fvdl  * SUCH DAMAGE.
     27   1.1      fvdl  *
     28   1.1      fvdl  *	$FreeBSD: src/sys/pci/agp_intel.c,v 1.4 2001/07/05 21:28:47 jhb Exp $
     29   1.1      fvdl  */
     30   1.4     lukem 
     31   1.4     lukem #include <sys/cdefs.h>
     32  1.24     joerg __KERNEL_RCSID(0, "$NetBSD: agp_intel.c,v 1.24 2007/11/12 20:00:17 joerg Exp $");
     33   1.1      fvdl 
     34   1.1      fvdl #include <sys/param.h>
     35   1.1      fvdl #include <sys/systm.h>
     36   1.1      fvdl #include <sys/malloc.h>
     37   1.1      fvdl #include <sys/kernel.h>
     38   1.1      fvdl #include <sys/lock.h>
     39   1.1      fvdl #include <sys/proc.h>
     40   1.1      fvdl #include <sys/agpio.h>
     41   1.1      fvdl #include <sys/device.h>
     42   1.1      fvdl 
     43   1.1      fvdl #include <uvm/uvm_extern.h>
     44   1.1      fvdl 
     45   1.1      fvdl #include <dev/pci/pcivar.h>
     46   1.1      fvdl #include <dev/pci/pcireg.h>
     47   1.7    ichiro #include <dev/pci/pcidevs.h>
     48   1.1      fvdl #include <dev/pci/agpvar.h>
     49   1.1      fvdl #include <dev/pci/agpreg.h>
     50   1.1      fvdl 
     51  1.23        ad #include <sys/bus.h>
     52   1.1      fvdl 
     53   1.1      fvdl struct agp_intel_softc {
     54   1.7    ichiro 	u_int32_t		initial_aperture;
     55   1.7    ichiro 					/* aperture size at startup */
     56   1.7    ichiro 	struct agp_gatt		*gatt;
     57  1.10    ichiro 	struct pci_attach_args	vga_pa;
     58  1.10    ichiro 	u_int			aperture_mask;
     59  1.10    ichiro 	int			chiptype; /* Chip type */
     60   1.8    ichiro #define	CHIP_INTEL	0x0
     61   1.8    ichiro #define	CHIP_I443	0x1
     62   1.8    ichiro #define	CHIP_I840	0x2
     63   1.8    ichiro #define	CHIP_I845	0x3
     64   1.8    ichiro #define	CHIP_I850	0x4
     65  1.14      tron #define	CHIP_I865	0x5
     66  1.18  jmcneill 
     67  1.18  jmcneill 	void			*sc_powerhook;
     68  1.18  jmcneill 	struct pci_conf_state	sc_pciconf;
     69   1.1      fvdl };
     70   1.1      fvdl 
     71   1.1      fvdl static u_int32_t agp_intel_get_aperture(struct agp_softc *);
     72   1.1      fvdl static int agp_intel_set_aperture(struct agp_softc *, u_int32_t);
     73   1.1      fvdl static int agp_intel_bind_page(struct agp_softc *, off_t, bus_addr_t);
     74   1.1      fvdl static int agp_intel_unbind_page(struct agp_softc *, off_t);
     75   1.1      fvdl static void agp_intel_flush_tlb(struct agp_softc *);
     76  1.18  jmcneill static void agp_intel_powerhook(int, void *);
     77  1.24     joerg static int agp_intel_init(struct agp_softc *);
     78   1.1      fvdl 
     79  1.15   thorpej static struct agp_methods agp_intel_methods = {
     80   1.1      fvdl 	agp_intel_get_aperture,
     81   1.1      fvdl 	agp_intel_set_aperture,
     82   1.1      fvdl 	agp_intel_bind_page,
     83   1.1      fvdl 	agp_intel_unbind_page,
     84   1.1      fvdl 	agp_intel_flush_tlb,
     85   1.1      fvdl 	agp_generic_enable,
     86   1.1      fvdl 	agp_generic_alloc_memory,
     87   1.1      fvdl 	agp_generic_free_memory,
     88   1.1      fvdl 	agp_generic_bind_memory,
     89   1.1      fvdl 	agp_generic_unbind_memory,
     90   1.1      fvdl };
     91   1.1      fvdl 
     92   1.7    ichiro static int
     93   1.7    ichiro agp_intel_vgamatch(struct pci_attach_args *pa)
     94   1.7    ichiro {
     95   1.7    ichiro 	switch (PCI_PRODUCT(pa->pa_id)) {
     96   1.7    ichiro 	case PCI_PRODUCT_INTEL_82855PM_AGP:
     97   1.7    ichiro 	case PCI_PRODUCT_INTEL_82443LX_AGP:
     98   1.7    ichiro 	case PCI_PRODUCT_INTEL_82443BX_AGP:
     99   1.7    ichiro 	case PCI_PRODUCT_INTEL_82443GX_AGP:
    100  1.10    ichiro 	case PCI_PRODUCT_INTEL_82850_AGP:	/* i850/i860 */
    101   1.7    ichiro 	case PCI_PRODUCT_INTEL_82845_AGP:
    102   1.7    ichiro 	case PCI_PRODUCT_INTEL_82840_AGP:
    103  1.11      tron 	case PCI_PRODUCT_INTEL_82865_AGP:
    104  1.11      tron 	case PCI_PRODUCT_INTEL_82875P_AGP:
    105   1.7    ichiro 		return (1);
    106   1.7    ichiro 	}
    107   1.7    ichiro 
    108   1.7    ichiro 	return (0);
    109   1.7    ichiro }
    110   1.7    ichiro 
    111   1.1      fvdl int
    112  1.21  christos agp_intel_attach(struct device *parent, struct device *self, void *aux)
    113   1.1      fvdl {
    114   1.1      fvdl 	struct agp_softc *sc = (struct agp_softc *)self;
    115   1.1      fvdl 	struct pci_attach_args *pa= aux;
    116   1.1      fvdl 	struct agp_intel_softc *isc;
    117   1.1      fvdl 	struct agp_gatt *gatt;
    118  1.10    ichiro 	u_int32_t value;
    119   1.1      fvdl 
    120   1.5   tsutsui 	isc = malloc(sizeof *isc, M_AGP, M_NOWAIT|M_ZERO);
    121   1.1      fvdl 	if (isc == NULL) {
    122   1.6   thorpej 		aprint_error(": can't allocate chipset-specific softc\n");
    123   1.1      fvdl 		return ENOMEM;
    124   1.1      fvdl 	}
    125   1.2      fvdl 
    126   1.1      fvdl 	sc->as_methods = &agp_intel_methods;
    127   1.2      fvdl 	sc->as_chipc = isc;
    128   1.2      fvdl 
    129   1.7    ichiro 	if (pci_find_device(&isc->vga_pa, agp_intel_vgamatch) == 0) {
    130  1.10    ichiro 		aprint_normal(": using generic initialization for Intel AGP\n");
    131  1.12    simonb 		aprint_normal("%s", sc->as_dev.dv_xname);
    132  1.10    ichiro 		isc->chiptype = CHIP_INTEL;
    133   1.7    ichiro 	}
    134   1.7    ichiro 
    135   1.1      fvdl 	pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_AGP, &sc->as_capoff,
    136   1.1      fvdl 	    NULL);
    137   1.1      fvdl 
    138  1.17  christos 	if (agp_map_aperture(pa, sc, AGP_APBASE) != 0) {
    139   1.6   thorpej 		aprint_error(": can't map aperture\n");
    140   1.1      fvdl 		free(isc, M_AGP);
    141   1.2      fvdl 		sc->as_chipc = NULL;
    142   1.1      fvdl 		return ENXIO;
    143   1.1      fvdl 	}
    144   1.1      fvdl 
    145   1.7    ichiro 	switch (PCI_PRODUCT(isc->vga_pa.pa_id)) {
    146  1.14      tron 	case PCI_PRODUCT_INTEL_82443LX_AGP:
    147  1.14      tron 	case PCI_PRODUCT_INTEL_82443BX_AGP:
    148  1.14      tron 	case PCI_PRODUCT_INTEL_82443GX_AGP:
    149  1.14      tron 		isc->chiptype = CHIP_I443;
    150  1.14      tron 		break;
    151  1.14      tron 	case PCI_PRODUCT_INTEL_82840_AGP:
    152  1.14      tron 		isc->chiptype = CHIP_I840;
    153  1.14      tron 		break;
    154   1.7    ichiro 	case PCI_PRODUCT_INTEL_82855PM_AGP:
    155   1.7    ichiro 	case PCI_PRODUCT_INTEL_82845_AGP:
    156   1.7    ichiro 		isc->chiptype = CHIP_I845;
    157   1.7    ichiro 		break;
    158   1.7    ichiro 	case PCI_PRODUCT_INTEL_82850_AGP:
    159   1.8    ichiro 		isc->chiptype = CHIP_I850;
    160   1.7    ichiro 		break;
    161  1.14      tron 	case PCI_PRODUCT_INTEL_82865_AGP:
    162  1.14      tron 	case PCI_PRODUCT_INTEL_82875P_AGP:
    163  1.14      tron 		isc->chiptype = CHIP_I865;
    164   1.7    ichiro 		break;
    165   1.7    ichiro 	}
    166   1.7    ichiro 
    167  1.10    ichiro 	/* Determine maximum supported aperture size. */
    168  1.10    ichiro 	value = pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_APSIZE);
    169  1.10    ichiro 	pci_conf_write(sc->as_pc, sc->as_tag,
    170  1.10    ichiro 		AGP_INTEL_APSIZE, APSIZE_MASK);
    171  1.10    ichiro 	isc->aperture_mask = pci_conf_read(sc->as_pc, sc->as_tag,
    172  1.10    ichiro 		AGP_INTEL_APSIZE) & APSIZE_MASK;
    173  1.10    ichiro 	pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_APSIZE, value);
    174   1.1      fvdl 	isc->initial_aperture = AGP_GET_APERTURE(sc);
    175   1.1      fvdl 
    176   1.1      fvdl 	for (;;) {
    177   1.1      fvdl 		gatt = agp_alloc_gatt(sc);
    178   1.1      fvdl 		if (gatt)
    179   1.1      fvdl 			break;
    180   1.1      fvdl 
    181   1.1      fvdl 		/*
    182   1.1      fvdl 		 * Probably contigmalloc failure. Try reducing the
    183   1.1      fvdl 		 * aperture so that the gatt size reduces.
    184   1.1      fvdl 		 */
    185   1.1      fvdl 		if (AGP_SET_APERTURE(sc, AGP_GET_APERTURE(sc) / 2)) {
    186   1.1      fvdl 			agp_generic_detach(sc);
    187   1.6   thorpej 			aprint_error(": failed to set aperture\n");
    188   1.1      fvdl 			return ENOMEM;
    189   1.1      fvdl 		}
    190   1.1      fvdl 	}
    191   1.1      fvdl 	isc->gatt = gatt;
    192   1.1      fvdl 
    193  1.24     joerg 	return agp_intel_init(sc);
    194  1.24     joerg }
    195  1.24     joerg 
    196  1.24     joerg static int
    197  1.24     joerg agp_intel_init(struct agp_softc *sc)
    198  1.24     joerg {
    199  1.24     joerg 	struct agp_intel_softc *isc = sc->as_chipc;
    200  1.24     joerg 	struct agp_gatt *gatt = isc->gatt;
    201  1.24     joerg 	pcireg_t reg;
    202  1.24     joerg 
    203   1.1      fvdl 	/* Install the gatt. */
    204   1.1      fvdl 	pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_ATTBASE,
    205   1.1      fvdl 	    gatt->ag_physical);
    206   1.8    ichiro 
    207   1.8    ichiro 	/* Enable the GLTB and setup the control register. */
    208   1.8    ichiro 	switch (isc->chiptype) {
    209   1.8    ichiro 	case CHIP_I443:
    210   1.8    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    211   1.8    ichiro 		    AGPCTRL_AGPRSE | AGPCTRL_GTLB);
    212   1.8    ichiro 
    213   1.8    ichiro 	default:
    214   1.8    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    215   1.9    ichiro 		    pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL)
    216   1.9    ichiro 			| AGPCTRL_GTLB);
    217   1.8    ichiro 	}
    218  1.10    ichiro 
    219   1.1      fvdl 	/* Enable things, clear errors etc. */
    220   1.7    ichiro 	switch (isc->chiptype) {
    221   1.7    ichiro 	case CHIP_I845:
    222  1.14      tron 	case CHIP_I865:
    223   1.7    ichiro 		{
    224  1.14      tron 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I840_MCHCFG);
    225  1.14      tron 		reg |= MCHCFG_AAGN;
    226  1.14      tron 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_I840_MCHCFG, reg);
    227   1.7    ichiro 		break;
    228   1.7    ichiro 		}
    229   1.7    ichiro 	case CHIP_I840:
    230   1.8    ichiro 	case CHIP_I850:
    231   1.7    ichiro 		{
    232  1.10    ichiro 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCMD);
    233  1.10    ichiro 		reg |= AGPCMD_AGPEN;
    234   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCMD,
    235  1.10    ichiro 			reg);
    236  1.10    ichiro 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I840_MCHCFG);
    237  1.10    ichiro 		reg |= MCHCFG_AAGN;
    238   1.8    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_I840_MCHCFG,
    239  1.10    ichiro 			reg);
    240   1.7    ichiro 		break;
    241   1.7    ichiro 		}
    242   1.8    ichiro 	default:
    243   1.7    ichiro 		{
    244   1.7    ichiro 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_NBXCFG);
    245   1.7    ichiro 		reg &= ~NBXCFG_APAE;
    246   1.7    ichiro 		reg |=  NBXCFG_AAGN;
    247   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_NBXCFG, reg);
    248   1.8    ichiro 		}
    249   1.8    ichiro 	}
    250   1.7    ichiro 
    251   1.8    ichiro 	/* Clear Error status */
    252   1.9    ichiro 	switch (isc->chiptype) {
    253   1.8    ichiro 	case CHIP_I840:
    254   1.9    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag,
    255   1.9    ichiro 			AGP_INTEL_I8XX_ERRSTS, 0xc000);
    256   1.8    ichiro 		break;
    257   1.1      fvdl 
    258  1.14      tron 	case CHIP_I845:
    259  1.10    ichiro 	case CHIP_I850:
    260  1.14      tron 	case CHIP_I865:
    261   1.9    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag,
    262   1.9    ichiro 			AGP_INTEL_I8XX_ERRSTS, 0x00ff);
    263   1.7    ichiro 		break;
    264   1.8    ichiro 
    265   1.8    ichiro 	default:
    266   1.9    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag,
    267   1.9    ichiro 			AGP_INTEL_ERRSTS, 0x70);
    268   1.7    ichiro 	}
    269   1.1      fvdl 
    270  1.19  jmcneill 	isc->sc_powerhook = powerhook_establish(sc->as_dev.dv_xname,
    271  1.19  jmcneill 	    agp_intel_powerhook, sc);
    272  1.18  jmcneill 	if (isc->sc_powerhook == NULL)
    273  1.18  jmcneill 		aprint_error("%s: couldn't establish powerhook\n",
    274  1.18  jmcneill 		    sc->as_dev.dv_xname);
    275  1.18  jmcneill 
    276  1.10    ichiro 	return (0);
    277   1.1      fvdl }
    278   1.1      fvdl 
    279   1.1      fvdl #if 0
    280   1.1      fvdl static int
    281   1.1      fvdl agp_intel_detach(struct agp_softc *sc)
    282   1.1      fvdl {
    283   1.1      fvdl 	int error;
    284   1.1      fvdl 	pcireg_t reg;
    285   1.1      fvdl 	struct agp_intel_softc *isc = sc->as_chipc;
    286   1.1      fvdl 
    287  1.18  jmcneill 	if (isc->sc_powerhook)
    288  1.18  jmcneill 		powerhook_disestablish(isc->sc_powerhook);
    289  1.18  jmcneill 
    290   1.1      fvdl 	error = agp_generic_detach(sc);
    291   1.1      fvdl 	if (error)
    292   1.1      fvdl 		return error;
    293   1.1      fvdl 
    294   1.7    ichiro 	/* XXX i845/i855PM/i840/i850E */
    295   1.1      fvdl 	reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_NBXCFG);
    296   1.1      fvdl 	reg &= ~(1 << 9);
    297   1.1      fvdl 	printf("%s: set NBXCFG to %x\n", __FUNCTION__, reg);
    298   1.1      fvdl 	pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_NBXCFG, reg);
    299   1.1      fvdl 	pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_ATTBASE, 0);
    300   1.1      fvdl 	AGP_SET_APERTURE(sc, isc->initial_aperture);
    301   1.1      fvdl 	agp_free_gatt(sc, isc->gatt);
    302   1.1      fvdl 
    303   1.1      fvdl 	return 0;
    304   1.1      fvdl }
    305   1.1      fvdl #endif
    306   1.1      fvdl 
    307   1.1      fvdl static u_int32_t
    308   1.1      fvdl agp_intel_get_aperture(struct agp_softc *sc)
    309   1.1      fvdl {
    310  1.10    ichiro 	struct agp_intel_softc *isc = sc->as_chipc;
    311   1.1      fvdl 	u_int32_t apsize;
    312   1.1      fvdl 
    313   1.7    ichiro 	apsize = pci_conf_read(sc->as_pc, sc->as_tag,
    314  1.10    ichiro 			AGP_INTEL_APSIZE) & isc->aperture_mask;
    315   1.1      fvdl 
    316   1.1      fvdl 	/*
    317   1.1      fvdl 	 * The size is determined by the number of low bits of
    318   1.1      fvdl 	 * register APBASE which are forced to zero. The low 22 bits
    319   1.1      fvdl 	 * are always forced to zero and each zero bit in the apsize
    320   1.1      fvdl 	 * field just read forces the corresponding bit in the 27:22
    321   1.1      fvdl 	 * to be zero. We calculate the aperture size accordingly.
    322   1.1      fvdl 	 */
    323  1.10    ichiro 	return (((apsize ^ isc->aperture_mask) << 22) | ((1 << 22) - 1)) + 1;
    324   1.1      fvdl }
    325   1.1      fvdl 
    326   1.1      fvdl static int
    327   1.1      fvdl agp_intel_set_aperture(struct agp_softc *sc, u_int32_t aperture)
    328   1.1      fvdl {
    329  1.10    ichiro 	struct agp_intel_softc *isc = sc->as_chipc;
    330   1.1      fvdl 	u_int32_t apsize;
    331   1.1      fvdl 
    332   1.1      fvdl 	/*
    333   1.1      fvdl 	 * Reverse the magic from get_aperture.
    334   1.1      fvdl 	 */
    335  1.10    ichiro 	apsize = ((aperture - 1) >> 22) ^ isc->aperture_mask;
    336   1.1      fvdl 
    337   1.1      fvdl 	/*
    338   1.1      fvdl 	 * Double check for sanity.
    339   1.1      fvdl 	 */
    340  1.10    ichiro 	if ((((apsize ^ isc->aperture_mask) << 22) |
    341   1.7    ichiro 			((1 << 22) - 1)) + 1 != aperture)
    342   1.1      fvdl 		return EINVAL;
    343   1.1      fvdl 
    344  1.10    ichiro 	pci_conf_write(sc->as_pc, sc->as_tag,
    345  1.10    ichiro 		AGP_INTEL_APSIZE, apsize);
    346   1.1      fvdl 
    347   1.1      fvdl 	return 0;
    348   1.1      fvdl }
    349   1.1      fvdl 
    350   1.1      fvdl static int
    351   1.1      fvdl agp_intel_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical)
    352   1.1      fvdl {
    353   1.1      fvdl 	struct agp_intel_softc *isc = sc->as_chipc;
    354   1.1      fvdl 
    355   1.1      fvdl 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
    356   1.1      fvdl 		return EINVAL;
    357   1.1      fvdl 
    358   1.1      fvdl 	isc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 0x17;
    359   1.1      fvdl 	return 0;
    360   1.1      fvdl }
    361   1.1      fvdl 
    362   1.1      fvdl static int
    363   1.1      fvdl agp_intel_unbind_page(struct agp_softc *sc, off_t offset)
    364   1.1      fvdl {
    365   1.1      fvdl 	struct agp_intel_softc *isc = sc->as_chipc;
    366   1.1      fvdl 
    367   1.1      fvdl 	if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
    368   1.1      fvdl 		return EINVAL;
    369   1.1      fvdl 
    370   1.1      fvdl 	isc->gatt->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
    371   1.1      fvdl 	return 0;
    372   1.1      fvdl }
    373   1.1      fvdl 
    374   1.1      fvdl static void
    375   1.1      fvdl agp_intel_flush_tlb(struct agp_softc *sc)
    376   1.1      fvdl {
    377   1.7    ichiro 	struct agp_intel_softc *isc = sc->as_chipc;
    378  1.10    ichiro 	pcireg_t reg;
    379   1.7    ichiro 
    380   1.7    ichiro 	switch (isc->chiptype) {
    381  1.14      tron 	case CHIP_I865:
    382  1.13      tron 	case CHIP_I850:
    383  1.13      tron 	case CHIP_I845:
    384  1.13      tron 	case CHIP_I840:
    385  1.10    ichiro 	case CHIP_I443:
    386  1.10    ichiro 		{
    387  1.10    ichiro 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL);
    388  1.13      tron 		reg &= ~AGPCTRL_GTLB;
    389   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    390  1.10    ichiro 			reg);
    391   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    392  1.10    ichiro 			reg | AGPCTRL_GTLB);
    393   1.7    ichiro 		break;
    394  1.10    ichiro 		}
    395  1.10    ichiro 	default: /* XXX */
    396  1.10    ichiro 		{
    397   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    398  1.10    ichiro 			0x2200);
    399   1.7    ichiro 		pci_conf_write(sc->as_pc, sc->as_tag, AGP_INTEL_AGPCTRL,
    400  1.10    ichiro 			0x2280);
    401  1.10    ichiro 		}
    402   1.7    ichiro 	}
    403   1.1      fvdl }
    404  1.18  jmcneill 
    405  1.18  jmcneill static void
    406  1.18  jmcneill agp_intel_powerhook(int why, void *opaque)
    407  1.18  jmcneill {
    408  1.18  jmcneill 	struct agp_softc *sc;
    409  1.18  jmcneill 	struct agp_intel_softc *isc;
    410  1.18  jmcneill 
    411  1.18  jmcneill 	sc = (struct agp_softc *)opaque;
    412  1.18  jmcneill 	isc = (struct agp_intel_softc *)sc->as_chipc;
    413  1.18  jmcneill 
    414  1.18  jmcneill 	switch (why) {
    415  1.18  jmcneill 	case PWR_SUSPEND:
    416  1.18  jmcneill 	case PWR_STANDBY:
    417  1.18  jmcneill 		pci_conf_capture(sc->as_pc, sc->as_tag, &isc->sc_pciconf);
    418  1.18  jmcneill 		break;
    419  1.18  jmcneill 	case PWR_RESUME:
    420  1.18  jmcneill 		pci_conf_restore(sc->as_pc, sc->as_tag, &isc->sc_pciconf);
    421  1.18  jmcneill 		agp_flush_cache();
    422  1.18  jmcneill 		break;
    423  1.18  jmcneill 	case PWR_SOFTSUSPEND:
    424  1.18  jmcneill 	case PWR_SOFTSTANDBY:
    425  1.18  jmcneill 	case PWR_SOFTRESUME:
    426  1.18  jmcneill 		break;
    427  1.18  jmcneill 	}
    428  1.18  jmcneill 
    429  1.18  jmcneill 	return;
    430  1.18  jmcneill }
    431