Home | History | Annotate | Line # | Download | only in pci
      1  1.126  riastrad /*	$NetBSD: agp_i810.c,v 1.126 2024/01/29 01:05:55 riastradh 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.74  riastrad  *	$FreeBSD$
     30    1.1      fvdl  */
     31    1.9     lukem 
     32    1.9     lukem #include <sys/cdefs.h>
     33  1.126  riastrad __KERNEL_RCSID(0, "$NetBSD: agp_i810.c,v 1.126 2024/01/29 01:05:55 riastradh Exp $");
     34    1.1      fvdl 
     35    1.1      fvdl #include <sys/param.h>
     36    1.1      fvdl #include <sys/systm.h>
     37  1.116  riastrad #include <sys/atomic.h>
     38    1.1      fvdl #include <sys/malloc.h>
     39    1.1      fvdl #include <sys/kernel.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.75  riastrad #include <sys/xcall.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.1      fvdl #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.74  riastrad #include <dev/pci/agp_i810var.h>
     51    1.1      fvdl 
     52    1.1      fvdl #include <sys/agpio.h>
     53    1.1      fvdl 
     54   1.43        ad #include <sys/bus.h>
     55    1.1      fvdl 
     56   1.20      tron #include "agp_intel.h"
     57   1.20      tron 
     58  1.106  riastrad #ifdef AGP_DEBUG
     59  1.106  riastrad #define	DPRINTF(sc, fmt, ...)						      \
     60  1.106  riastrad 	device_printf((sc)->as_dev, "%s: " fmt, __func__, ##__VA_ARGS__)
     61  1.106  riastrad #else
     62  1.106  riastrad #define	DPRINTF(sc, fmt, ...)	do {} while (0)
     63  1.106  riastrad #endif
     64  1.106  riastrad 
     65   1.74  riastrad struct agp_softc *agp_i810_sc = NULL;
     66   1.74  riastrad 
     67    1.1      fvdl #define READ1(off)	bus_space_read_1(isc->bst, isc->bsh, off)
     68   1.14       scw #define READ4(off)	bus_space_read_4(isc->bst, isc->bsh, off)
     69    1.1      fvdl #define WRITE4(off,v)	bus_space_write_4(isc->bst, isc->bsh, off, v)
     70    1.1      fvdl 
     71  1.122    nonaka #define CHIP_I810	0	/* i810/i815 */
     72  1.122    nonaka #define CHIP_I830	1	/* 830M/845G */
     73  1.122    nonaka #define CHIP_I855	2	/* 852GM/855GM/865G */
     74  1.122    nonaka #define CHIP_I915	3	/* 915G/915GM/945G/945GM/945GME */
     75  1.122    nonaka #define CHIP_I965	4	/* 965Q/965PM */
     76  1.122    nonaka #define CHIP_G33	5	/* G33/Q33/Q35 */
     77  1.122    nonaka #define CHIP_G4X	6	/* G45/Q45 */
     78  1.122    nonaka #define CHIP_PINEVIEW	7	/* Pineview */
     79   1.14       scw 
     80   1.49  drochner /* XXX hack, see below */
     81   1.50  drochner static bus_addr_t agp_i810_vga_regbase;
     82   1.99  riastrad static bus_size_t agp_i810_vga_regsize;
     83   1.99  riastrad static bus_space_tag_t agp_i810_vga_bst;
     84   1.50  drochner static bus_space_handle_t agp_i810_vga_bsh;
     85   1.49  drochner 
     86    1.1      fvdl static u_int32_t agp_i810_get_aperture(struct agp_softc *);
     87    1.1      fvdl static int agp_i810_set_aperture(struct agp_softc *, u_int32_t);
     88    1.1      fvdl static int agp_i810_bind_page(struct agp_softc *, off_t, bus_addr_t);
     89    1.1      fvdl static int agp_i810_unbind_page(struct agp_softc *, off_t);
     90    1.1      fvdl static void agp_i810_flush_tlb(struct agp_softc *);
     91    1.1      fvdl static int agp_i810_enable(struct agp_softc *, u_int32_t mode);
     92    1.1      fvdl static struct agp_memory *agp_i810_alloc_memory(struct agp_softc *, int,
     93    1.1      fvdl 						vsize_t);
     94    1.1      fvdl static int agp_i810_free_memory(struct agp_softc *, struct agp_memory *);
     95   1.86  riastrad static int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *,
     96   1.86  riastrad 		off_t);
     97   1.86  riastrad static int agp_i810_bind_memory_dcache(struct agp_softc *, struct agp_memory *,
     98   1.86  riastrad 		off_t);
     99   1.86  riastrad static int agp_i810_bind_memory_hwcursor(struct agp_softc *,
    100   1.86  riastrad 		struct agp_memory *, off_t);
    101    1.1      fvdl static int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *);
    102   1.47  jmcneill 
    103   1.66    dyoung static bool agp_i810_resume(device_t, const pmf_qual_t *);
    104   1.47  jmcneill static int agp_i810_init(struct agp_softc *);
    105    1.1      fvdl 
    106   1.75  riastrad static int agp_i810_setup_chipset_flush_page(struct agp_softc *);
    107   1.79  riastrad static void agp_i810_teardown_chipset_flush_page(struct agp_softc *);
    108   1.45     joerg static int agp_i810_init(struct agp_softc *);
    109   1.45     joerg 
    110   1.26   thorpej static struct agp_methods agp_i810_methods = {
    111    1.1      fvdl 	agp_i810_get_aperture,
    112    1.1      fvdl 	agp_i810_set_aperture,
    113    1.1      fvdl 	agp_i810_bind_page,
    114    1.1      fvdl 	agp_i810_unbind_page,
    115    1.1      fvdl 	agp_i810_flush_tlb,
    116    1.1      fvdl 	agp_i810_enable,
    117    1.1      fvdl 	agp_i810_alloc_memory,
    118    1.1      fvdl 	agp_i810_free_memory,
    119    1.1      fvdl 	agp_i810_bind_memory,
    120    1.1      fvdl 	agp_i810_unbind_memory,
    121    1.1      fvdl };
    122    1.1      fvdl 
    123   1.74  riastrad int
    124  1.117  riastrad agp_i810_write_gtt_entry(struct agp_i810_softc *isc, off_t off,
    125  1.117  riastrad     bus_addr_t addr, int flags)
    126   1.58  christos {
    127   1.71    gsutre 	u_int32_t pte;
    128   1.71    gsutre 
    129  1.117  riastrad 	/*
    130  1.117  riastrad 	 * Bits 11:4 (physical start address extension) should be zero.
    131  1.117  riastrad 	 * Flag bits 3:0 should be zero too.
    132  1.117  riastrad 	 *
    133  1.117  riastrad 	 * XXX This should be a kassert -- no reason for this routine
    134  1.117  riastrad 	 * to allow failure.
    135  1.117  riastrad 	 */
    136  1.117  riastrad 	if ((addr & 0xfff) != 0)
    137   1.71    gsutre 		return EINVAL;
    138  1.117  riastrad 	KASSERT(flags == (flags & 0x7));
    139   1.71    gsutre 
    140  1.117  riastrad 	pte = (u_int32_t)addr;
    141   1.71    gsutre 	/*
    142   1.71    gsutre 	 * We need to massage the pte if bus_addr_t is wider than 32 bits.
    143   1.71    gsutre 	 * The compiler isn't smart enough, hence the casts to uintmax_t.
    144   1.71    gsutre 	 */
    145   1.71    gsutre 	if (sizeof(bus_addr_t) > sizeof(u_int32_t)) {
    146   1.71    gsutre 		/* 965+ can do 36-bit addressing, add in the extra bits. */
    147   1.71    gsutre 		if (isc->chiptype == CHIP_I965 ||
    148   1.71    gsutre 		    isc->chiptype == CHIP_G33 ||
    149  1.122    nonaka 		    isc->chiptype == CHIP_PINEVIEW ||
    150   1.71    gsutre 		    isc->chiptype == CHIP_G4X) {
    151  1.117  riastrad 			if (((uintmax_t)addr >> 36) != 0)
    152   1.71    gsutre 				return EINVAL;
    153  1.117  riastrad 			pte |= (addr >> 28) & 0xf0;
    154   1.71    gsutre 		} else {
    155  1.117  riastrad 			if (((uintmax_t)addr >> 32) != 0)
    156   1.71    gsutre 				return EINVAL;
    157   1.71    gsutre 		}
    158   1.71    gsutre 	}
    159   1.58  christos 
    160   1.79  riastrad 	bus_space_write_4(isc->gtt_bst, isc->gtt_bsh,
    161  1.117  riastrad 	    4*(off >> AGP_PAGE_SHIFT), pte | flags);
    162   1.58  christos 
    163   1.71    gsutre 	return 0;
    164   1.58  christos }
    165   1.58  christos 
    166   1.74  riastrad void
    167   1.74  riastrad agp_i810_post_gtt_entry(struct agp_i810_softc *isc, off_t off)
    168   1.74  riastrad {
    169   1.74  riastrad 
    170  1.115  riastrad 	/*
    171  1.115  riastrad 	 * See <https://bugs.freedesktop.org/show_bug.cgi?id=88191>.
    172  1.115  riastrad 	 * Out of paranoia, let's do the write barrier and posting
    173  1.115  riastrad 	 * read, because I don't have enough time or hardware to
    174  1.115  riastrad 	 * conduct conclusive tests.
    175  1.115  riastrad 	 */
    176  1.125  riastrad 	bus_space_barrier(isc->gtt_bst, isc->gtt_bsh, 0, isc->gtt_size,
    177  1.125  riastrad 	    BUS_SPACE_BARRIER_WRITE);
    178   1.79  riastrad 	(void)bus_space_read_4(isc->gtt_bst, isc->gtt_bsh,
    179   1.79  riastrad 	    4*(off >> AGP_PAGE_SHIFT));
    180   1.74  riastrad }
    181   1.74  riastrad 
    182   1.75  riastrad static void
    183  1.126  riastrad agp_flush_cache_ipi(void *cookie __unused)
    184   1.75  riastrad {
    185   1.75  riastrad 
    186   1.75  riastrad 	agp_flush_cache();
    187   1.75  riastrad }
    188   1.75  riastrad 
    189   1.75  riastrad void
    190   1.75  riastrad agp_i810_chipset_flush(struct agp_i810_softc *isc)
    191   1.75  riastrad {
    192   1.75  riastrad 	unsigned int timo = 20000; /* * 50 us = 1 s */
    193   1.75  riastrad 
    194   1.75  riastrad 	switch (isc->chiptype) {
    195   1.75  riastrad 	case CHIP_I810:
    196   1.75  riastrad 		break;
    197   1.75  riastrad 	case CHIP_I830:
    198   1.75  riastrad 	case CHIP_I855:
    199   1.77  riastrad 		/*
    200   1.77  riastrad 		 * Flush all CPU caches.  If we're cold, we can't run
    201   1.77  riastrad 		 * xcalls, but there should be only one CPU up, so
    202   1.77  riastrad 		 * flushing only the local CPU's cache should suffice.
    203   1.77  riastrad 		 *
    204   1.77  riastrad 		 * XXX Come to think of it, do these chipsets appear in
    205   1.77  riastrad 		 * any multi-CPU systems?
    206   1.77  riastrad 		 */
    207  1.126  riastrad 		if (cold) {
    208   1.77  riastrad 			agp_flush_cache();
    209  1.126  riastrad 		} else {
    210  1.126  riastrad 			/*
    211  1.126  riastrad 			 * Caller may hold a spin lock, so use ipi(9)
    212  1.126  riastrad 			 * rather than xcall(9) here.
    213  1.126  riastrad 			 */
    214  1.126  riastrad 			ipi_msg_t msg = { .func = agp_flush_cache_ipi };
    215  1.126  riastrad 			kpreempt_disable();
    216  1.126  riastrad 			ipi_broadcast(&msg, /*skip_self*/false);
    217  1.126  riastrad 			ipi_wait(&msg);
    218  1.126  riastrad 			kpreempt_enable();
    219  1.126  riastrad 		}
    220   1.75  riastrad 		WRITE4(AGP_I830_HIC, READ4(AGP_I830_HIC) | __BIT(31));
    221   1.75  riastrad 		while (ISSET(READ4(AGP_I830_HIC), __BIT(31))) {
    222   1.75  riastrad 			if (timo-- == 0)
    223   1.75  riastrad 				break;
    224   1.75  riastrad 			DELAY(50);
    225   1.75  riastrad 		}
    226   1.75  riastrad 		break;
    227   1.75  riastrad 	case CHIP_I915:
    228   1.75  riastrad 	case CHIP_I965:
    229   1.75  riastrad 	case CHIP_G33:
    230  1.122    nonaka 	case CHIP_PINEVIEW:
    231   1.75  riastrad 	case CHIP_G4X:
    232   1.75  riastrad 		bus_space_write_4(isc->flush_bst, isc->flush_bsh, 0, 1);
    233   1.75  riastrad 		break;
    234   1.75  riastrad 	}
    235   1.75  riastrad }
    236   1.75  riastrad 
    237   1.55  matthias /* XXXthorpej -- duplicated code (see arch/x86/pci/pchb.c) */
    238    1.1      fvdl static int
    239   1.73    dyoung agp_i810_vgamatch(const struct pci_attach_args *pa)
    240    1.1      fvdl {
    241    1.6   thorpej 
    242    1.2      fvdl 	if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
    243    1.2      fvdl 	    PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
    244    1.6   thorpej 		return (0);
    245    1.6   thorpej 
    246    1.1      fvdl 	switch (PCI_PRODUCT(pa->pa_id)) {
    247    1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_GC:
    248    1.1      fvdl 	case PCI_PRODUCT_INTEL_82810_DC100_GC:
    249    1.1      fvdl 	case PCI_PRODUCT_INTEL_82810E_GC:
    250    1.1      fvdl 	case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
    251   1.14       scw 	case PCI_PRODUCT_INTEL_82830MP_IV:
    252   1.14       scw 	case PCI_PRODUCT_INTEL_82845G_IGD:
    253   1.17   hannken 	case PCI_PRODUCT_INTEL_82855GM_IGD:
    254   1.18      tron 	case PCI_PRODUCT_INTEL_82865_IGD:
    255   1.28  christos 	case PCI_PRODUCT_INTEL_82915G_IGD:
    256   1.28  christos 	case PCI_PRODUCT_INTEL_82915GM_IGD:
    257   1.32    simonb 	case PCI_PRODUCT_INTEL_82945P_IGD:
    258   1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD:
    259   1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD_1:
    260   1.56       tnn 	case PCI_PRODUCT_INTEL_82945GME_IGD:
    261   1.68       riz 	case PCI_PRODUCT_INTEL_E7221_IGD:
    262   1.42     markd 	case PCI_PRODUCT_INTEL_82965Q_IGD:
    263   1.42     markd 	case PCI_PRODUCT_INTEL_82965Q_IGD_1:
    264   1.45     joerg 	case PCI_PRODUCT_INTEL_82965PM_IGD:
    265   1.45     joerg 	case PCI_PRODUCT_INTEL_82965PM_IGD_1:
    266   1.45     joerg 	case PCI_PRODUCT_INTEL_82G33_IGD:
    267   1.45     joerg 	case PCI_PRODUCT_INTEL_82G33_IGD_1:
    268   1.44   jnemeth 	case PCI_PRODUCT_INTEL_82965G_IGD:
    269   1.44   jnemeth 	case PCI_PRODUCT_INTEL_82965G_IGD_1:
    270   1.68       riz 	case PCI_PRODUCT_INTEL_82965GME_IGD:
    271   1.46     markd 	case PCI_PRODUCT_INTEL_82Q35_IGD:
    272   1.46     markd 	case PCI_PRODUCT_INTEL_82Q35_IGD_1:
    273   1.46     markd 	case PCI_PRODUCT_INTEL_82Q33_IGD:
    274   1.46     markd 	case PCI_PRODUCT_INTEL_82Q33_IGD_1:
    275   1.57  christos 	case PCI_PRODUCT_INTEL_82G35_IGD:
    276   1.57  christos 	case PCI_PRODUCT_INTEL_82G35_IGD_1:
    277   1.55  matthias 	case PCI_PRODUCT_INTEL_82946GZ_IGD:
    278   1.58  christos 	case PCI_PRODUCT_INTEL_82GM45_IGD:
    279   1.58  christos 	case PCI_PRODUCT_INTEL_82GM45_IGD_1:
    280   1.62     markd 	case PCI_PRODUCT_INTEL_82IGD_E_IGD:
    281   1.62     markd 	case PCI_PRODUCT_INTEL_82Q45_IGD:
    282   1.62     markd 	case PCI_PRODUCT_INTEL_82G45_IGD:
    283   1.68       riz 	case PCI_PRODUCT_INTEL_82G41_IGD:
    284   1.68       riz 	case PCI_PRODUCT_INTEL_82B43_IGD:
    285   1.68       riz 	case PCI_PRODUCT_INTEL_IRONLAKE_D_IGD:
    286   1.68       riz 	case PCI_PRODUCT_INTEL_IRONLAKE_M_IGD:
    287   1.72      matt 	case PCI_PRODUCT_INTEL_PINEVIEW_IGD:
    288   1.72      matt 	case PCI_PRODUCT_INTEL_PINEVIEW_M_IGD:
    289    1.6   thorpej 		return (1);
    290    1.1      fvdl 	}
    291    1.1      fvdl 
    292    1.6   thorpej 	return (0);
    293    1.1      fvdl }
    294    1.1      fvdl 
    295   1.42     markd static int
    296   1.42     markd agp_i965_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc, int reg)
    297   1.42     markd {
    298   1.42     markd         /*
    299   1.42     markd          * Find the aperture. Don't map it (yet), this would
    300   1.42     markd          * eat KVA.
    301   1.42     markd          */
    302   1.42     markd         if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, reg,
    303   1.42     markd             PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_64BIT, &sc->as_apaddr, &sc->as_apsize,
    304   1.42     markd             &sc->as_apflags) != 0)
    305   1.42     markd                 return ENXIO;
    306   1.42     markd 
    307   1.42     markd         sc->as_apt = pa->pa_memt;
    308   1.42     markd 
    309   1.42     markd         return 0;
    310   1.42     markd }
    311   1.42     markd 
    312    1.1      fvdl int
    313   1.54     freza agp_i810_attach(device_t parent, device_t self, void *aux)
    314    1.1      fvdl {
    315   1.54     freza 	struct agp_softc *sc = device_private(self);
    316    1.1      fvdl 	struct agp_i810_softc *isc;
    317   1.79  riastrad 	int apbase, mmadr_bar, gtt_bar;
    318   1.79  riastrad 	int mmadr_type, mmadr_flags;
    319   1.98  riastrad 	bus_addr_t mmadr;
    320   1.98  riastrad 	bus_size_t mmadr_size, gtt_off;
    321   1.79  riastrad 	int error;
    322    1.1      fvdl 
    323  1.124       chs 	isc = malloc(sizeof *isc, M_AGP, M_WAITOK|M_ZERO);
    324    1.1      fvdl 	sc->as_chipc = isc;
    325    1.1      fvdl 	sc->as_methods = &agp_i810_methods;
    326    1.1      fvdl 
    327    1.1      fvdl 	if (pci_find_device(&isc->vga_pa, agp_i810_vgamatch) == 0) {
    328   1.20      tron #if NAGP_INTEL > 0
    329   1.19      tron 		const struct pci_attach_args *pa = aux;
    330   1.19      tron 
    331   1.19      tron 		switch (PCI_PRODUCT(pa->pa_id)) {
    332   1.19      tron 		case PCI_PRODUCT_INTEL_82840_HB:
    333   1.19      tron 		case PCI_PRODUCT_INTEL_82865_HB:
    334   1.21      tron 		case PCI_PRODUCT_INTEL_82845G_DRAM:
    335   1.23   xtraeme 		case PCI_PRODUCT_INTEL_82815_FULL_HUB:
    336   1.67  jakllsch 		case PCI_PRODUCT_INTEL_82855GM_MCH:
    337   1.79  riastrad 			free(isc, M_AGP);
    338   1.19      tron 			return agp_intel_attach(parent, self, aux);
    339   1.20      tron 		}
    340   1.20      tron #endif
    341   1.83  riastrad 		aprint_error(": can't find internal VGA"
    342   1.83  riastrad 		    " config space\n");
    343   1.79  riastrad 		error = ENOENT;
    344   1.79  riastrad 		goto fail1;
    345    1.1      fvdl 	}
    346    1.1      fvdl 
    347    1.1      fvdl 	/* XXXfvdl */
    348    1.1      fvdl 	sc->as_dmat = isc->vga_pa.pa_dmat;
    349    1.1      fvdl 
    350   1.14       scw 	switch (PCI_PRODUCT(isc->vga_pa.pa_id)) {
    351   1.14       scw 	case PCI_PRODUCT_INTEL_82810_GC:
    352   1.14       scw 	case PCI_PRODUCT_INTEL_82810_DC100_GC:
    353   1.14       scw 	case PCI_PRODUCT_INTEL_82810E_GC:
    354   1.14       scw 	case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
    355   1.14       scw 		isc->chiptype = CHIP_I810;
    356   1.82  riastrad 		aprint_normal(": i810-family chipset\n");
    357   1.14       scw 		break;
    358   1.14       scw 	case PCI_PRODUCT_INTEL_82830MP_IV:
    359   1.14       scw 	case PCI_PRODUCT_INTEL_82845G_IGD:
    360   1.14       scw 		isc->chiptype = CHIP_I830;
    361   1.82  riastrad 		aprint_normal(": i830-family chipset\n");
    362   1.14       scw 		break;
    363   1.17   hannken 	case PCI_PRODUCT_INTEL_82855GM_IGD:
    364   1.18      tron 	case PCI_PRODUCT_INTEL_82865_IGD:
    365   1.17   hannken 		isc->chiptype = CHIP_I855;
    366   1.82  riastrad 		aprint_normal(": i855-family chipset\n");
    367   1.17   hannken 		break;
    368   1.28  christos 	case PCI_PRODUCT_INTEL_82915G_IGD:
    369   1.28  christos 	case PCI_PRODUCT_INTEL_82915GM_IGD:
    370   1.32    simonb 	case PCI_PRODUCT_INTEL_82945P_IGD:
    371   1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD:
    372   1.32    simonb 	case PCI_PRODUCT_INTEL_82945GM_IGD_1:
    373   1.56       tnn 	case PCI_PRODUCT_INTEL_82945GME_IGD:
    374   1.68       riz 	case PCI_PRODUCT_INTEL_E7221_IGD:
    375   1.28  christos 		isc->chiptype = CHIP_I915;
    376   1.82  riastrad 		aprint_normal(": i915-family chipset\n");
    377   1.28  christos 		break;
    378   1.42     markd 	case PCI_PRODUCT_INTEL_82965Q_IGD:
    379   1.42     markd 	case PCI_PRODUCT_INTEL_82965Q_IGD_1:
    380   1.45     joerg 	case PCI_PRODUCT_INTEL_82965PM_IGD:
    381   1.45     joerg 	case PCI_PRODUCT_INTEL_82965PM_IGD_1:
    382   1.44   jnemeth 	case PCI_PRODUCT_INTEL_82965G_IGD:
    383   1.44   jnemeth 	case PCI_PRODUCT_INTEL_82965G_IGD_1:
    384   1.68       riz 	case PCI_PRODUCT_INTEL_82965GME_IGD:
    385   1.55  matthias 	case PCI_PRODUCT_INTEL_82946GZ_IGD:
    386   1.57  christos 	case PCI_PRODUCT_INTEL_82G35_IGD:
    387   1.57  christos 	case PCI_PRODUCT_INTEL_82G35_IGD_1:
    388   1.42     markd 		isc->chiptype = CHIP_I965;
    389   1.82  riastrad 		aprint_normal(": i965-family chipset\n");
    390   1.42     markd 		break;
    391   1.46     markd 	case PCI_PRODUCT_INTEL_82Q35_IGD:
    392   1.46     markd 	case PCI_PRODUCT_INTEL_82Q35_IGD_1:
    393   1.45     joerg 	case PCI_PRODUCT_INTEL_82G33_IGD:
    394   1.45     joerg 	case PCI_PRODUCT_INTEL_82G33_IGD_1:
    395   1.46     markd 	case PCI_PRODUCT_INTEL_82Q33_IGD:
    396   1.46     markd 	case PCI_PRODUCT_INTEL_82Q33_IGD_1:
    397   1.45     joerg 		isc->chiptype = CHIP_G33;
    398   1.82  riastrad 		aprint_normal(": G33-family chipset\n");
    399   1.63     markd 		break;
    400  1.122    nonaka 	case PCI_PRODUCT_INTEL_PINEVIEW_IGD:
    401  1.122    nonaka 	case PCI_PRODUCT_INTEL_PINEVIEW_M_IGD:
    402  1.122    nonaka 		isc->chiptype = CHIP_PINEVIEW;
    403  1.122    nonaka 		aprint_normal(": Pineview chipset\n");
    404  1.122    nonaka 		break;
    405   1.58  christos 	case PCI_PRODUCT_INTEL_82GM45_IGD:
    406   1.58  christos 	case PCI_PRODUCT_INTEL_82GM45_IGD_1:
    407   1.62     markd 	case PCI_PRODUCT_INTEL_82IGD_E_IGD:
    408   1.62     markd 	case PCI_PRODUCT_INTEL_82Q45_IGD:
    409   1.62     markd 	case PCI_PRODUCT_INTEL_82G45_IGD:
    410   1.68       riz 	case PCI_PRODUCT_INTEL_82G41_IGD:
    411   1.68       riz 	case PCI_PRODUCT_INTEL_82B43_IGD:
    412   1.68       riz 	case PCI_PRODUCT_INTEL_IRONLAKE_D_IGD:
    413   1.68       riz 	case PCI_PRODUCT_INTEL_IRONLAKE_M_IGD:
    414   1.58  christos 		isc->chiptype = CHIP_G4X;
    415   1.82  riastrad 		aprint_normal(": G4X-family chipset\n");
    416   1.45     joerg 		break;
    417   1.14       scw 	}
    418   1.82  riastrad 	aprint_naive("\n");
    419   1.14       scw 
    420  1.119  riastrad 	/* Discriminate on the chipset to choose the relevant BARs.  */
    421   1.45     joerg 	switch (isc->chiptype) {
    422   1.45     joerg 	case CHIP_I915:
    423   1.45     joerg 	case CHIP_G33:
    424  1.122    nonaka 	case CHIP_PINEVIEW:
    425   1.45     joerg 		apbase = AGP_I915_GMADR;
    426   1.79  riastrad 		mmadr_bar = AGP_I915_MMADR;
    427   1.79  riastrad 		gtt_bar = AGP_I915_GTTADR;
    428  1.100  riastrad 		gtt_off = ~(bus_size_t)0; /* XXXGCC */
    429   1.45     joerg 		break;
    430   1.58  christos 	case CHIP_I965:
    431   1.79  riastrad 		apbase = AGP_I965_GMADR;
    432   1.79  riastrad 		mmadr_bar = AGP_I965_MMADR;
    433   1.79  riastrad 		gtt_bar = 0;
    434   1.79  riastrad 		gtt_off = AGP_I965_GTT;
    435   1.79  riastrad 		break;
    436   1.58  christos 	case CHIP_G4X:
    437   1.58  christos 		apbase = AGP_I965_GMADR;
    438   1.79  riastrad 		mmadr_bar = AGP_I965_MMADR;
    439   1.79  riastrad 		gtt_bar = 0;
    440   1.79  riastrad 		gtt_off = AGP_G4X_GTT;
    441   1.58  christos 		break;
    442   1.45     joerg 	default:
    443   1.45     joerg 		apbase = AGP_I810_GMADR;
    444   1.79  riastrad 		mmadr_bar = AGP_I810_MMADR;
    445   1.79  riastrad 		gtt_bar = 0;
    446   1.79  riastrad 		gtt_off = AGP_I810_GTT;
    447   1.45     joerg 		break;
    448   1.45     joerg 	}
    449   1.58  christos 
    450  1.119  riastrad 	/*
    451  1.119  riastrad 	 * Ensure the MMIO BAR is, in fact, a memory BAR.
    452  1.119  riastrad 	 *
    453  1.119  riastrad 	 * XXX This is required because we use pa_memt below.  It is
    454  1.119  riastrad 	 * not a priori clear to me there is any other reason to
    455  1.119  riastrad 	 * require this.
    456  1.119  riastrad 	 */
    457  1.119  riastrad 	mmadr_type = pci_mapreg_type(isc->vga_pa.pa_pc, isc->vga_pa.pa_tag,
    458  1.119  riastrad 	    mmadr_bar);
    459  1.121  christos 	if (PCI_MAPREG_TYPE(mmadr_type) != PCI_MAPREG_TYPE_MEM) {
    460  1.119  riastrad 		aprint_error_dev(self, "non-memory device MMIO registers\n");
    461  1.119  riastrad 		error = ENXIO;
    462  1.119  riastrad 		goto fail1;
    463  1.119  riastrad 	}
    464  1.119  riastrad 
    465  1.119  riastrad 	/*
    466  1.119  riastrad 	 * Determine the size of the MMIO registers.
    467  1.119  riastrad 	 *
    468  1.119  riastrad 	 * XXX The size of the MMIO registers we use is statically
    469  1.119  riastrad 	 * determined, as a function of the chipset, by the driver's
    470  1.119  riastrad 	 * implementation.
    471  1.119  riastrad 	 *
    472  1.119  riastrad 	 * On some chipsets, the GTT is part of the MMIO register BAR.
    473  1.119  riastrad 	 * We would like to map the GTT separately, so that we can map
    474  1.119  riastrad 	 * it prefetchable, which we can't do with the MMIO registers.
    475  1.119  riastrad 	 * Consequently, we would especially like to map a fixed size
    476  1.119  riastrad 	 * of MMIO registers, not just whatever size the BAR says.
    477  1.119  riastrad 	 *
    478  1.119  riastrad 	 * However, old drm assumes that the combined GTT/MMIO register
    479  1.119  riastrad 	 * space is a single bus space mapping, so mapping them
    480  1.119  riastrad 	 * separately breaks that.  Once we rip out old drm, we can
    481  1.119  riastrad 	 * replace the pci_mapreg_info call by the chipset switch.
    482  1.119  riastrad 	 */
    483  1.119  riastrad #if notyet
    484  1.119  riastrad 	switch (isc->chiptype) {
    485  1.119  riastrad 	case CHIP_I810:
    486  1.119  riastrad 	case CHIP_I830:
    487  1.119  riastrad 	case CHIP_I855:
    488  1.119  riastrad 	case CHIP_I915:
    489  1.122    nonaka 	case CHIP_I965:
    490  1.119  riastrad 	case CHIP_G33:
    491  1.122    nonaka 	case CHIP_PINEVIEW:
    492  1.119  riastrad 	case CHIP_G4X:
    493  1.119  riastrad 		isc->size = 512*1024;
    494  1.119  riastrad 		break;
    495  1.119  riastrad 	case CHIP_SANDYBRIDGE:
    496  1.119  riastrad 	case CHIP_IVYBRIDGE:
    497  1.119  riastrad 	case CHIP_HASWELL:
    498  1.119  riastrad 		isc->size = 2*1024*1024;
    499  1.119  riastrad 		break;
    500  1.119  riastrad 	}
    501  1.119  riastrad #else
    502  1.119  riastrad 	if (pci_mapreg_info(isc->vga_pa.pa_pc, isc->vga_pa.pa_tag,
    503  1.119  riastrad 		mmadr_bar, mmadr_type, NULL, &isc->size, NULL))
    504  1.119  riastrad 		isc->size = 512*1024;
    505  1.119  riastrad #endif	/* notyet */
    506  1.119  riastrad 
    507   1.79  riastrad 	/* Map (or, rather, find the address and size of) the aperture.  */
    508   1.79  riastrad 	if (isc->chiptype == CHIP_I965 || isc->chiptype == CHIP_G4X)
    509   1.58  christos 		error = agp_i965_map_aperture(&isc->vga_pa, sc, apbase);
    510   1.79  riastrad 	else
    511   1.42     markd 		error = agp_map_aperture(&isc->vga_pa, sc, apbase);
    512   1.79  riastrad 	if (error) {
    513   1.82  riastrad 		aprint_error_dev(self, "can't map aperture: %d\n", error);
    514   1.79  riastrad 		goto fail1;
    515    1.1      fvdl 	}
    516    1.1      fvdl 
    517   1.79  riastrad 	/* Map the memory-mapped I/O registers, or the non-GTT part.  */
    518   1.79  riastrad 	if (pci_mapreg_info(isc->vga_pa.pa_pc, isc->vga_pa.pa_tag, mmadr_bar,
    519   1.79  riastrad 		mmadr_type, &mmadr, &mmadr_size, &mmadr_flags)) {
    520   1.79  riastrad 		aprint_error_dev(self, "can't find MMIO registers\n");
    521   1.79  riastrad 		error = ENXIO;
    522   1.79  riastrad 		goto fail1;
    523   1.79  riastrad 	}
    524   1.97  riastrad 	if (mmadr_size < isc->size) {
    525   1.97  riastrad 		aprint_error_dev(self, "MMIO registers too small"
    526   1.97  riastrad 		    ": %"PRIuMAX" < %"PRIuMAX"\n",
    527   1.97  riastrad 		    (uintmax_t)mmadr_size, (uintmax_t)isc->size);
    528   1.97  riastrad 		error = ENXIO;
    529   1.97  riastrad 		goto fail1;
    530   1.79  riastrad 	}
    531   1.79  riastrad 	isc->bst = isc->vga_pa.pa_memt;
    532   1.79  riastrad 	error = bus_space_map(isc->bst, mmadr, isc->size, mmadr_flags,
    533   1.79  riastrad 	    &isc->bsh);
    534   1.79  riastrad 	if (error) {
    535   1.83  riastrad 		aprint_error_dev(self, "can't map MMIO registers: %d\n",
    536   1.83  riastrad 		    error);
    537   1.79  riastrad 		error = ENXIO;
    538   1.79  riastrad 		goto fail1;
    539   1.79  riastrad 	}
    540   1.79  riastrad 
    541   1.85  riastrad 	/* Set up a chipset flush page if necessary.  */
    542   1.85  riastrad 	switch (isc->chiptype) {
    543   1.85  riastrad 	case CHIP_I915:
    544   1.85  riastrad 	case CHIP_I965:
    545   1.85  riastrad 	case CHIP_G33:
    546  1.122    nonaka 	case CHIP_PINEVIEW:
    547   1.85  riastrad 	case CHIP_G4X:
    548   1.85  riastrad 		error = agp_i810_setup_chipset_flush_page(sc);
    549   1.85  riastrad 		if (error) {
    550   1.85  riastrad 			aprint_error_dev(self,
    551   1.85  riastrad 			    "can't set up chipset flush page: %d\n", error);
    552   1.85  riastrad 			goto fail2;
    553   1.85  riastrad 		}
    554   1.85  riastrad 		break;
    555   1.85  riastrad 	}
    556   1.85  riastrad 
    557   1.85  riastrad 	/*
    558   1.85  riastrad 	 * XXX horrible hack to allow drm code to use our mapping
    559   1.85  riastrad 	 * of VGA chip registers
    560   1.85  riastrad 	 */
    561   1.85  riastrad 	agp_i810_vga_regbase = mmadr;
    562   1.99  riastrad 	agp_i810_vga_regsize = isc->size;
    563   1.99  riastrad 	agp_i810_vga_bst = isc->bst;
    564   1.85  riastrad 	agp_i810_vga_bsh = isc->bsh;
    565   1.85  riastrad 
    566   1.85  riastrad 	/* Initialize the chipset.  */
    567   1.85  riastrad 	error = agp_i810_init(sc);
    568   1.85  riastrad 	if (error)
    569   1.85  riastrad 		goto fail3;
    570   1.85  riastrad 
    571   1.79  riastrad 	/* Map the GTT, from either part of the MMIO region or its own BAR.  */
    572   1.79  riastrad 	if (gtt_bar == 0) {
    573   1.79  riastrad 		isc->gtt_bst = isc->bst;
    574   1.87  riastrad 		if ((mmadr_size - gtt_off) < isc->gtt_size) {
    575   1.85  riastrad 			aprint_error_dev(self, "GTTMMADR too small for GTT"
    576   1.87  riastrad 			    ": (%"PRIxMAX" - %"PRIxMAX") < %"PRIxMAX"\n",
    577   1.85  riastrad 			    (uintmax_t)mmadr_size,
    578   1.87  riastrad 			    (uintmax_t)gtt_off,
    579   1.87  riastrad 			    (uintmax_t)isc->gtt_size);
    580   1.85  riastrad 			error = ENXIO;
    581   1.85  riastrad 			goto fail4;
    582   1.85  riastrad 		}
    583   1.97  riastrad 		/*
    584   1.97  riastrad 		 * Map the GTT separately if we can, so that we can map
    585   1.97  riastrad 		 * it prefetchable, but in early models, there are MMIO
    586   1.97  riastrad 		 * registers before and after the GTT, so we can only
    587   1.97  riastrad 		 * take a subregion.
    588   1.97  riastrad 		 */
    589   1.97  riastrad 		if (isc->size < gtt_off)
    590   1.97  riastrad 			error = bus_space_map(isc->gtt_bst, (mmadr + gtt_off),
    591   1.97  riastrad 			    isc->gtt_size, mmadr_flags, &isc->gtt_bsh);
    592   1.97  riastrad 		else
    593   1.97  riastrad 			error = bus_space_subregion(isc->bst, isc->bsh,
    594   1.97  riastrad 			    gtt_off, isc->gtt_size, &isc->gtt_bsh);
    595   1.79  riastrad 		if (error) {
    596   1.79  riastrad 			aprint_error_dev(self, "can't map GTT: %d\n", error);
    597   1.79  riastrad 			error = ENXIO;
    598   1.85  riastrad 			goto fail4;
    599   1.28  christos 		}
    600   1.79  riastrad 	} else {
    601   1.85  riastrad 		bus_size_t gtt_bar_size;
    602   1.79  riastrad 		/*
    603   1.79  riastrad 		 * All chipsets with a separate BAR for the GTT, namely
    604   1.79  riastrad 		 * the i915 and G33 families, have 32-bit GTT BARs.
    605   1.79  riastrad 		 *
    606   1.79  riastrad 		 * XXX [citation needed]
    607   1.79  riastrad 		 */
    608   1.79  riastrad 		if (pci_mapreg_map(&isc->vga_pa, gtt_bar, PCI_MAPREG_TYPE_MEM,
    609   1.79  riastrad 			0,
    610   1.85  riastrad 			&isc->gtt_bst, &isc->gtt_bsh, NULL, &gtt_bar_size)) {
    611   1.79  riastrad 			aprint_error_dev(self, "can't map GTT\n");
    612   1.79  riastrad 			error = ENXIO;
    613   1.85  riastrad 			goto fail4;
    614   1.42     markd 		}
    615   1.85  riastrad 		if (gtt_bar_size != isc->gtt_size) {
    616   1.83  riastrad 			aprint_error_dev(self,
    617   1.85  riastrad 			    "BAR size %"PRIxMAX
    618   1.85  riastrad 			    " mismatches detected GTT size %"PRIxMAX
    619   1.85  riastrad 			    "; trusting BAR\n",
    620   1.85  riastrad 			    (uintmax_t)gtt_bar_size,
    621   1.85  riastrad 			    (uintmax_t)isc->gtt_size);
    622   1.85  riastrad 			isc->gtt_size = gtt_bar_size;
    623   1.28  christos 		}
    624   1.28  christos 	}
    625   1.28  christos 
    626   1.79  riastrad 	/* Power management.  (XXX Nothing to save on suspend?  Fishy...)  */
    627   1.47  jmcneill 	if (!pmf_device_register(self, NULL, agp_i810_resume))
    628   1.82  riastrad 		aprint_error_dev(self, "can't establish power handler\n");
    629   1.47  jmcneill 
    630   1.82  riastrad 	/* Match the generic AGP code's autoconf output format.  */
    631   1.82  riastrad 	aprint_normal("%s", device_xname(self));
    632   1.82  riastrad 
    633   1.79  riastrad 	/* Success!  */
    634   1.79  riastrad 	return 0;
    635   1.79  riastrad 
    636   1.85  riastrad fail5: __unused
    637   1.85  riastrad 	pmf_device_deregister(self);
    638   1.97  riastrad 	if ((gtt_bar != 0) || (isc->size < gtt_off))
    639   1.97  riastrad 		bus_space_unmap(isc->gtt_bst, isc->gtt_bsh, isc->gtt_size);
    640   1.85  riastrad 	isc->gtt_size = 0;
    641   1.85  riastrad fail4:
    642   1.79  riastrad #if notyet
    643   1.79  riastrad 	agp_i810_fini(sc);
    644   1.79  riastrad #endif
    645   1.85  riastrad fail3:	switch (isc->chiptype) {
    646   1.75  riastrad 	case CHIP_I915:
    647   1.75  riastrad 	case CHIP_I965:
    648   1.75  riastrad 	case CHIP_G33:
    649  1.122    nonaka 	case CHIP_PINEVIEW:
    650   1.75  riastrad 	case CHIP_G4X:
    651   1.79  riastrad 		agp_i810_teardown_chipset_flush_page(sc);
    652   1.75  riastrad 		break;
    653   1.75  riastrad 	}
    654   1.79  riastrad fail2:	bus_space_unmap(isc->bst, isc->bsh, isc->size);
    655   1.79  riastrad 	isc->size = 0;
    656   1.79  riastrad fail1:	free(isc, M_AGP);
    657   1.79  riastrad 	sc->as_chipc = NULL;
    658  1.124       chs 	agp_generic_detach(sc);
    659   1.79  riastrad 	KASSERT(error);
    660   1.79  riastrad 	return error;
    661   1.45     joerg }
    662   1.45     joerg 
    663  1.118  riastrad /*
    664  1.118  riastrad  * Skip pages reserved by the BIOS.  Notably, skip 0xa0000-0xfffff,
    665  1.118  riastrad  * which includes the video BIOS at 0xc0000-0xdffff which the display
    666  1.118  riastrad  * drivers need for video mode detection.
    667  1.118  riastrad  *
    668  1.118  riastrad  * XXX Is there an MI name for this, or a conventional x86 name?  Or
    669  1.118  riastrad  * should we really use bus_dma instead?
    670  1.118  riastrad  */
    671  1.118  riastrad #define	PCIBIOS_MIN_MEM		0x100000
    672  1.118  riastrad 
    673   1.75  riastrad static int
    674   1.75  riastrad agp_i810_setup_chipset_flush_page(struct agp_softc *sc)
    675   1.75  riastrad {
    676   1.75  riastrad 	struct agp_i810_softc *const isc = sc->as_chipc;
    677   1.84  riastrad 	const pci_chipset_tag_t pc = sc->as_pc;
    678   1.84  riastrad 	const pcitag_t tag = sc->as_tag;
    679   1.83  riastrad 	pcireg_t lo, hi;
    680   1.75  riastrad 	bus_addr_t addr, minaddr, maxaddr;
    681   1.75  riastrad 	int error;
    682   1.75  riastrad 
    683   1.75  riastrad 	/* We always use memory-mapped I/O.  */
    684   1.75  riastrad 	isc->flush_bst = isc->vga_pa.pa_memt;
    685   1.75  riastrad 
    686   1.75  riastrad 	/* No page allocated yet.  */
    687   1.75  riastrad 	isc->flush_addr = 0;
    688   1.75  riastrad 
    689   1.75  riastrad 	/* Read the PCI config register: 4-byte on gen3, 8-byte on gen>=4.  */
    690   1.75  riastrad 	if (isc->chiptype == CHIP_I915) {
    691   1.83  riastrad 		addr = pci_conf_read(pc, tag, AGP_I915_IFPADDR);
    692  1.118  riastrad 		minaddr = PCIBIOS_MIN_MEM;
    693   1.75  riastrad 		maxaddr = UINT32_MAX;
    694   1.75  riastrad 	} else {
    695   1.83  riastrad 		hi = pci_conf_read(pc, tag, AGP_I965_IFPADDR+4);
    696   1.83  riastrad 		lo = pci_conf_read(pc, tag, AGP_I965_IFPADDR);
    697   1.76  riastrad 		/*
    698   1.76  riastrad 		 * Convert to uint64_t, rather than bus_addr_t which
    699   1.76  riastrad 		 * may be 32-bit, to avoid undefined behaviour with a
    700   1.76  riastrad 		 * too-wide shift.  Since the BIOS doesn't know whether
    701   1.76  riastrad 		 * the OS will run 64-bit or with PAE, it ought to
    702   1.76  riastrad 		 * configure at most a 32-bit physical address, so
    703   1.76  riastrad 		 * let's print a warning in case that happens.
    704   1.76  riastrad 		 */
    705   1.76  riastrad 		addr = ((uint64_t)hi << 32) | lo;
    706   1.76  riastrad 		if (hi) {
    707   1.76  riastrad 			aprint_error_dev(sc->as_dev,
    708   1.76  riastrad 			    "BIOS configured >32-bit flush page address"
    709   1.76  riastrad 			    ": %"PRIx64"\n", ((uint64_t)hi << 32) | lo);
    710   1.76  riastrad #if __i386__ && !PAE
    711   1.76  riastrad 			return EIO;
    712   1.76  riastrad #endif
    713   1.76  riastrad 		}
    714  1.118  riastrad 		minaddr = PCIBIOS_MIN_MEM;
    715   1.76  riastrad 		maxaddr = MIN(UINT64_MAX, ~(bus_addr_t)0);
    716   1.75  riastrad 	}
    717   1.75  riastrad 
    718   1.75  riastrad 	/* Allocate or map a pre-allocated a page for it.  */
    719   1.75  riastrad 	if (ISSET(addr, 1)) {
    720   1.75  riastrad 		/* BIOS allocated it for us.  Use that.  */
    721   1.75  riastrad 		error = bus_space_map(isc->flush_bst, addr & ~1, PAGE_SIZE, 0,
    722   1.75  riastrad 		    &isc->flush_bsh);
    723   1.75  riastrad 		if (error)
    724   1.75  riastrad 			return error;
    725   1.75  riastrad 	} else {
    726   1.75  riastrad 		/* None allocated.  Allocate one.  */
    727   1.75  riastrad 		error = bus_space_alloc(isc->flush_bst, minaddr, maxaddr,
    728   1.75  riastrad 		    PAGE_SIZE, PAGE_SIZE, 0, 0,
    729   1.75  riastrad 		    &isc->flush_addr, &isc->flush_bsh);
    730   1.75  riastrad 		if (error)
    731   1.75  riastrad 			return error;
    732   1.75  riastrad 		KASSERT(isc->flush_addr != 0);
    733   1.75  riastrad 		/* Write it into the PCI config register.  */
    734   1.75  riastrad 		addr = isc->flush_addr | 1;
    735   1.75  riastrad 		if (isc->chiptype == CHIP_I915) {
    736   1.83  riastrad 			pci_conf_write(pc, tag, AGP_I915_IFPADDR, addr);
    737   1.75  riastrad 		} else {
    738   1.83  riastrad 			hi = __SHIFTOUT(addr, __BITS(63, 32));
    739   1.84  riastrad 			lo = __SHIFTOUT(addr, __BITS(31, 0));
    740   1.83  riastrad 			pci_conf_write(pc, tag, AGP_I965_IFPADDR+4, hi);
    741   1.83  riastrad 			pci_conf_write(pc, tag, AGP_I965_IFPADDR, lo);
    742   1.75  riastrad 		}
    743   1.75  riastrad 	}
    744   1.75  riastrad 
    745   1.75  riastrad 	/* Success!  */
    746   1.75  riastrad 	return 0;
    747   1.75  riastrad }
    748   1.75  riastrad 
    749   1.79  riastrad static void
    750   1.79  riastrad agp_i810_teardown_chipset_flush_page(struct agp_softc *sc)
    751   1.79  riastrad {
    752   1.79  riastrad 	struct agp_i810_softc *const isc = sc->as_chipc;
    753   1.79  riastrad 
    754   1.79  riastrad 	if (isc->flush_addr) {
    755   1.79  riastrad 		/* If we allocated a page, clear it.  */
    756   1.79  riastrad 		if (isc->chiptype == CHIP_I915) {
    757   1.79  riastrad 			pci_conf_write(sc->as_pc, sc->as_tag, AGP_I915_IFPADDR,
    758   1.79  riastrad 			    0);
    759   1.79  riastrad 		} else {
    760   1.79  riastrad 			pci_conf_write(sc->as_pc, sc->as_tag,
    761   1.79  riastrad 			    AGP_I965_IFPADDR, 0);
    762   1.79  riastrad 			pci_conf_write(sc->as_pc, sc->as_tag,
    763   1.79  riastrad 			    AGP_I965_IFPADDR + 4, 0);
    764   1.79  riastrad 		}
    765   1.79  riastrad 		isc->flush_addr = 0;
    766  1.118  riastrad 		bus_space_free(isc->flush_bst, isc->flush_bsh, PAGE_SIZE);
    767   1.79  riastrad 	} else {
    768   1.79  riastrad 		/* Otherwise, just unmap the pre-allocated page.  */
    769   1.79  riastrad 		bus_space_unmap(isc->flush_bst, isc->flush_bsh, PAGE_SIZE);
    770   1.79  riastrad 	}
    771   1.79  riastrad }
    772   1.79  riastrad 
    773   1.49  drochner /*
    774   1.49  drochner  * XXX horrible hack to allow drm code to use our mapping
    775   1.49  drochner  * of VGA chip registers
    776   1.49  drochner  */
    777   1.49  drochner int
    778   1.99  riastrad agp_i810_borrow(bus_addr_t base, bus_size_t size, bus_space_handle_t *hdlp)
    779   1.49  drochner {
    780   1.49  drochner 
    781   1.99  riastrad 	if (agp_i810_vga_regbase == 0)
    782   1.99  riastrad 		return 0;
    783   1.99  riastrad 	if (base < agp_i810_vga_regbase)
    784   1.99  riastrad 		return 0;
    785   1.99  riastrad 	if (agp_i810_vga_regsize < size)
    786   1.99  riastrad 		return 0;
    787   1.99  riastrad 	if ((base - agp_i810_vga_regbase) > (agp_i810_vga_regsize - size))
    788   1.99  riastrad 		return 0;
    789   1.99  riastrad 	if (bus_space_subregion(agp_i810_vga_bst, agp_i810_vga_bsh,
    790   1.99  riastrad 		(base - agp_i810_vga_regbase), (agp_i810_vga_regsize - size),
    791   1.99  riastrad 		hdlp))
    792   1.49  drochner 		return 0;
    793   1.49  drochner 	return 1;
    794   1.49  drochner }
    795   1.49  drochner 
    796   1.82  riastrad static int
    797   1.82  riastrad agp_i810_init(struct agp_softc *sc)
    798   1.45     joerg {
    799   1.45     joerg 	struct agp_i810_softc *isc;
    800   1.82  riastrad 	int error;
    801   1.45     joerg 
    802   1.45     joerg 	isc = sc->as_chipc;
    803   1.45     joerg 
    804   1.14       scw 	if (isc->chiptype == CHIP_I810) {
    805   1.85  riastrad 		struct agp_gatt *gatt;
    806   1.36  christos 		void *virtual;
    807   1.14       scw 		int dummyseg;
    808   1.31      tron 
    809   1.14       scw 		/* Some i810s have on-chip memory called dcache */
    810   1.14       scw 		if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
    811   1.14       scw 			isc->dcache_size = 4 * 1024 * 1024;
    812   1.14       scw 		else
    813   1.14       scw 			isc->dcache_size = 0;
    814   1.14       scw 
    815   1.14       scw 		/* According to the specs the gatt on the i810 must be 64k */
    816   1.85  riastrad 		isc->gtt_size = 64 * 1024;
    817  1.124       chs 		gatt = malloc(sizeof(*gatt), M_AGP, M_WAITOK);
    818   1.85  riastrad 		gatt->ag_entries = isc->gtt_size / sizeof(uint32_t);
    819   1.85  riastrad 		error = agp_alloc_dmamem(sc->as_dmat, isc->gtt_size,
    820   1.31      tron 		    0, &gatt->ag_dmamap, &virtual, &gatt->ag_physical,
    821   1.82  riastrad 		    &gatt->ag_dmaseg, 1, &dummyseg);
    822   1.82  riastrad 		if (error) {
    823   1.82  riastrad 			aprint_error_dev(sc->as_dev,
    824   1.82  riastrad 			    "can't allocate memory for GTT: %d\n", error);
    825   1.85  riastrad 			free(gatt, M_AGP);
    826   1.82  riastrad 			goto fail0;
    827    1.1      fvdl 		}
    828   1.82  riastrad 
    829   1.31      tron 		gatt->ag_virtual = (uint32_t *)virtual;
    830   1.85  riastrad 		gatt->ag_size = gatt->ag_entries * sizeof(uint32_t);
    831   1.14       scw 		memset(gatt->ag_virtual, 0, gatt->ag_size);
    832   1.85  riastrad 		agp_flush_cache();
    833   1.25     perry 
    834   1.14       scw 		/* Install the GATT. */
    835   1.85  riastrad 		isc->pgtblctl = gatt->ag_physical | 1;
    836   1.85  riastrad 		WRITE4(AGP_I810_PGTBL_CTL, isc->pgtblctl);
    837   1.85  riastrad 		isc->gatt = gatt;
    838   1.17   hannken 	} else if (isc->chiptype == CHIP_I830) {
    839   1.14       scw 		/* The i830 automatically initializes the 128k gatt on boot. */
    840   1.85  riastrad 		/* XXX [citation needed] */
    841   1.14       scw 		pcireg_t reg;
    842   1.14       scw 		u_int16_t gcc1;
    843   1.14       scw 
    844   1.85  riastrad 		isc->gtt_size = 128 * 1024;
    845   1.85  riastrad 
    846   1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
    847   1.14       scw 		gcc1 = (u_int16_t)(reg >> 16);
    848   1.14       scw 		switch (gcc1 & AGP_I830_GCC1_GMS) {
    849   1.14       scw 		case AGP_I830_GCC1_GMS_STOLEN_512:
    850   1.14       scw 			isc->stolen = (512 - 132) * 1024 / 4096;
    851   1.14       scw 			break;
    852   1.25     perry 		case AGP_I830_GCC1_GMS_STOLEN_1024:
    853   1.14       scw 			isc->stolen = (1024 - 132) * 1024 / 4096;
    854   1.14       scw 			break;
    855   1.25     perry 		case AGP_I830_GCC1_GMS_STOLEN_8192:
    856   1.14       scw 			isc->stolen = (8192 - 132) * 1024 / 4096;
    857   1.14       scw 			break;
    858   1.14       scw 		default:
    859   1.14       scw 			isc->stolen = 0;
    860   1.82  riastrad 			aprint_error_dev(sc->as_dev,
    861   1.82  riastrad 			    "unknown memory configuration, disabling\n");
    862   1.82  riastrad 			error = ENXIO;
    863   1.82  riastrad 			goto fail0;
    864   1.14       scw 		}
    865   1.45     joerg 
    866   1.14       scw 		if (isc->stolen > 0) {
    867   1.82  riastrad 			aprint_normal_dev(sc->as_dev,
    868   1.82  riastrad 			    "detected %dk stolen memory\n",
    869   1.82  riastrad 			    isc->stolen * 4);
    870   1.14       scw 		}
    871   1.17   hannken 
    872   1.17   hannken 		/* GATT address is already in there, make sure it's enabled */
    873   1.85  riastrad 		isc->pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    874   1.85  riastrad 		isc->pgtblctl |= 1;
    875   1.85  riastrad 		WRITE4(AGP_I810_PGTBL_CTL, isc->pgtblctl);
    876   1.42     markd 	} else if (isc->chiptype == CHIP_I855 || isc->chiptype == CHIP_I915 ||
    877   1.58  christos 		   isc->chiptype == CHIP_I965 || isc->chiptype == CHIP_G33 ||
    878  1.122    nonaka 		   isc->chiptype == CHIP_PINEVIEW ||
    879   1.58  christos 		   isc->chiptype == CHIP_G4X) {
    880   1.17   hannken 		pcireg_t reg;
    881   1.85  riastrad 		u_int32_t gtt_size, stolen;	/* XXX kilobytes */
    882   1.17   hannken 		u_int16_t gcc1;
    883   1.17   hannken 
    884   1.45     joerg 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I855_GCC1);
    885   1.45     joerg 		gcc1 = (u_int16_t)(reg >> 16);
    886   1.45     joerg 
    887   1.85  riastrad 		isc->pgtblctl = READ4(AGP_I810_PGTBL_CTL);
    888   1.58  christos 
    889   1.42     markd 		/* Stolen memory is set up at the beginning of the aperture by
    890   1.42     markd                  * the BIOS, consisting of the GATT followed by 4kb for the
    891   1.42     markd 		 * BIOS display.
    892   1.42     markd                  */
    893   1.42     markd                 switch (isc->chiptype) {
    894   1.42     markd 		case CHIP_I855:
    895   1.58  christos 			gtt_size = 128;
    896   1.42     markd 			break;
    897   1.42     markd                 case CHIP_I915:
    898   1.58  christos 			gtt_size = 256;
    899   1.42     markd 			break;
    900   1.42     markd 		case CHIP_I965:
    901   1.85  riastrad 			switch (isc->pgtblctl & AGP_I810_PGTBL_SIZE_MASK) {
    902   1.58  christos 			case AGP_I810_PGTBL_SIZE_128KB:
    903   1.58  christos 			case AGP_I810_PGTBL_SIZE_512KB:
    904   1.58  christos 				gtt_size = 512;
    905   1.58  christos 				break;
    906   1.58  christos 			case AGP_I965_PGTBL_SIZE_1MB:
    907   1.58  christos 				gtt_size = 1024;
    908   1.58  christos 				break;
    909   1.58  christos 			case AGP_I965_PGTBL_SIZE_2MB:
    910   1.61    sketch 				gtt_size = 2048;
    911   1.58  christos 				break;
    912   1.58  christos 			case AGP_I965_PGTBL_SIZE_1_5MB:
    913   1.61    sketch 				gtt_size = 1024 + 512;
    914   1.58  christos 				break;
    915   1.58  christos 			default:
    916   1.82  riastrad 				aprint_error_dev(sc->as_dev,
    917   1.82  riastrad 				    "bad PGTBL size\n");
    918   1.82  riastrad 				error = ENXIO;
    919   1.82  riastrad 				goto fail0;
    920   1.58  christos 			}
    921   1.42     markd 			break;
    922   1.45     joerg 		case CHIP_G33:
    923   1.45     joerg 			switch (gcc1 & AGP_G33_PGTBL_SIZE_MASK) {
    924   1.45     joerg 			case AGP_G33_PGTBL_SIZE_1M:
    925   1.58  christos 				gtt_size = 1024;
    926   1.45     joerg 				break;
    927   1.45     joerg 			case AGP_G33_PGTBL_SIZE_2M:
    928   1.58  christos 				gtt_size = 2048;
    929   1.45     joerg 				break;
    930   1.45     joerg 			default:
    931   1.82  riastrad 				aprint_error_dev(sc->as_dev,
    932   1.82  riastrad 				    "bad PGTBL size\n");
    933   1.82  riastrad 				error = ENXIO;
    934   1.82  riastrad 				goto fail0;
    935   1.45     joerg 			}
    936   1.45     joerg 			break;
    937  1.122    nonaka 		case CHIP_PINEVIEW:
    938  1.122    nonaka 			switch (gcc1 & AGP_PINEVIEW_PGTBL_SIZE_MASK) {
    939  1.122    nonaka 			case AGP_PINEVIEW_PGTBL_SIZE_1M:
    940  1.122    nonaka 				gtt_size = 1024;
    941  1.122    nonaka 				break;
    942  1.122    nonaka 			default:
    943  1.122    nonaka 				aprint_error_dev(sc->as_dev,
    944  1.122    nonaka 				    "bad PGTBL size\n");
    945  1.122    nonaka 				error = ENXIO;
    946  1.122    nonaka 				goto fail0;
    947  1.122    nonaka 			}
    948  1.122    nonaka 			break;
    949   1.58  christos 		case CHIP_G4X:
    950  1.103  riastrad 			switch (isc->pgtblctl & AGP_G4X_PGTBL_SIZE_MASK) {
    951  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_512K:
    952  1.103  riastrad 				gtt_size = 512;
    953  1.103  riastrad 				break;
    954  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_256K:
    955  1.103  riastrad 				gtt_size = 256;
    956  1.103  riastrad 				break;
    957  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_128K:
    958  1.103  riastrad 				gtt_size = 128;
    959  1.103  riastrad 				break;
    960  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_1M:
    961  1.103  riastrad 				gtt_size = 1*1024;
    962  1.103  riastrad 				break;
    963  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_2M:
    964  1.103  riastrad 				gtt_size = 2*1024;
    965  1.103  riastrad 				break;
    966  1.103  riastrad 			case AGP_G4X_PGTBL_SIZE_1_5M:
    967  1.103  riastrad 				gtt_size = 1*1024 + 512;
    968  1.103  riastrad 				break;
    969  1.103  riastrad 			default:
    970  1.103  riastrad 				aprint_error_dev(sc->as_dev,
    971  1.103  riastrad 				    "bad PGTBL size\n");
    972  1.103  riastrad 				error = ENXIO;
    973  1.103  riastrad 				goto fail0;
    974  1.103  riastrad 			}
    975   1.58  christos 			break;
    976   1.42     markd 		default:
    977   1.82  riastrad 			panic("impossible chiptype %d", isc->chiptype);
    978   1.58  christos 		}
    979   1.42     markd 
    980   1.85  riastrad 		/*
    981   1.85  riastrad 		 * XXX If I'm reading the datasheets right, this stolen
    982   1.85  riastrad 		 * memory detection logic is totally wrong.
    983   1.85  riastrad 		 */
    984   1.17   hannken 		switch (gcc1 & AGP_I855_GCC1_GMS) {
    985   1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_1M:
    986   1.58  christos 			stolen = 1024;
    987   1.17   hannken 			break;
    988   1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_4M:
    989   1.58  christos 			stolen = 4 * 1024;
    990   1.17   hannken 			break;
    991   1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_8M:
    992   1.58  christos 			stolen = 8 * 1024;
    993   1.17   hannken 			break;
    994   1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_16M:
    995   1.58  christos 			stolen = 16 * 1024;
    996   1.17   hannken 			break;
    997   1.17   hannken 		case AGP_I855_GCC1_GMS_STOLEN_32M:
    998   1.58  christos 			stolen = 32 * 1024;
    999   1.41  sborrill 			break;
   1000   1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_48M:
   1001   1.58  christos 			stolen = 48 * 1024;
   1002   1.41  sborrill 			break;
   1003   1.41  sborrill 		case AGP_I915_GCC1_GMS_STOLEN_64M:
   1004   1.58  christos 			stolen = 64 * 1024;
   1005   1.41  sborrill 			break;
   1006   1.46     markd 		case AGP_G33_GCC1_GMS_STOLEN_128M:
   1007   1.58  christos 			stolen = 128 * 1024;
   1008   1.46     markd 			break;
   1009   1.46     markd 		case AGP_G33_GCC1_GMS_STOLEN_256M:
   1010   1.58  christos 			stolen = 256 * 1024;
   1011   1.58  christos 			break;
   1012   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_96M:
   1013   1.58  christos 			stolen = 96 * 1024;
   1014   1.58  christos 			break;
   1015   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_160M:
   1016   1.58  christos 			stolen = 160 * 1024;
   1017   1.58  christos 			break;
   1018   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_224M:
   1019   1.58  christos 			stolen = 224 * 1024;
   1020   1.58  christos 			break;
   1021   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_352M:
   1022   1.58  christos 			stolen = 352 * 1024;
   1023   1.46     markd 			break;
   1024   1.28  christos 		default:
   1025   1.82  riastrad 			aprint_error_dev(sc->as_dev,
   1026   1.82  riastrad 			    "unknown memory configuration, disabling\n");
   1027   1.82  riastrad 			error = ENXIO;
   1028   1.82  riastrad 			goto fail0;
   1029   1.28  christos 		}
   1030   1.58  christos 
   1031   1.58  christos 		switch (gcc1 & AGP_I855_GCC1_GMS) {
   1032   1.58  christos 		case AGP_I915_GCC1_GMS_STOLEN_48M:
   1033   1.58  christos 		case AGP_I915_GCC1_GMS_STOLEN_64M:
   1034   1.58  christos 			if (isc->chiptype != CHIP_I915 &&
   1035   1.58  christos 			    isc->chiptype != CHIP_I965 &&
   1036   1.58  christos 			    isc->chiptype != CHIP_G33 &&
   1037  1.122    nonaka 			    isc->chiptype != CHIP_PINEVIEW &&
   1038   1.58  christos 			    isc->chiptype != CHIP_G4X)
   1039   1.58  christos 				stolen = 0;
   1040   1.58  christos 			break;
   1041   1.58  christos 		case AGP_G33_GCC1_GMS_STOLEN_128M:
   1042   1.58  christos 		case AGP_G33_GCC1_GMS_STOLEN_256M:
   1043   1.58  christos 			if (isc->chiptype != CHIP_I965 &&
   1044   1.58  christos 			    isc->chiptype != CHIP_G33 &&
   1045  1.122    nonaka 			    isc->chiptype != CHIP_PINEVIEW &&
   1046   1.58  christos 			    isc->chiptype != CHIP_G4X)
   1047   1.58  christos 				stolen = 0;
   1048   1.58  christos 			break;
   1049   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_96M:
   1050   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_160M:
   1051   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_224M:
   1052   1.58  christos 		case AGP_G4X_GCC1_GMS_STOLEN_352M:
   1053   1.58  christos 			if (isc->chiptype != CHIP_I965 &&
   1054   1.58  christos 			    isc->chiptype != CHIP_G4X)
   1055   1.58  christos 				stolen = 0;
   1056   1.58  christos 			break;
   1057   1.58  christos 		}
   1058   1.58  christos 
   1059   1.85  riastrad 		isc->gtt_size = gtt_size * 1024;
   1060   1.85  riastrad 
   1061   1.58  christos 		/* BIOS space */
   1062   1.85  riastrad 		/* XXX [citation needed] */
   1063   1.62     markd 		gtt_size += 4;
   1064   1.58  christos 
   1065   1.85  riastrad 		/* XXX [citation needed] for this subtraction */
   1066   1.58  christos 		isc->stolen = (stolen - gtt_size) * 1024 / 4096;
   1067   1.58  christos 
   1068   1.28  christos 		if (isc->stolen > 0) {
   1069   1.82  riastrad 			aprint_normal_dev(sc->as_dev,
   1070   1.82  riastrad 			    "detected %dk stolen memory\n",
   1071   1.82  riastrad 			    isc->stolen * 4);
   1072   1.28  christos 		}
   1073   1.28  christos 
   1074   1.28  christos 		/* GATT address is already in there, make sure it's enabled */
   1075   1.85  riastrad 		isc->pgtblctl |= 1;
   1076   1.85  riastrad 		WRITE4(AGP_I810_PGTBL_CTL, isc->pgtblctl);
   1077    1.1      fvdl 	}
   1078    1.1      fvdl 
   1079    1.1      fvdl 	/*
   1080    1.1      fvdl 	 * Make sure the chipset can see everything.
   1081    1.1      fvdl 	 */
   1082    1.1      fvdl 	agp_flush_cache();
   1083   1.14       scw 
   1084   1.74  riastrad 	/*
   1085   1.74  riastrad 	 * Publish what we found for kludgey drivers (I'm looking at
   1086   1.74  riastrad 	 * you, drm).
   1087   1.74  riastrad 	 */
   1088   1.74  riastrad 	if (agp_i810_sc == NULL)
   1089   1.74  riastrad 		agp_i810_sc = sc;
   1090   1.74  riastrad 	else
   1091   1.82  riastrad 		aprint_error_dev(sc->as_dev, "agp already attached\n");
   1092   1.74  riastrad 
   1093   1.82  riastrad 	/* Success!  */
   1094    1.1      fvdl 	return 0;
   1095   1.82  riastrad 
   1096   1.82  riastrad fail0:	KASSERT(error);
   1097   1.82  riastrad 	return error;
   1098    1.1      fvdl }
   1099    1.1      fvdl 
   1100    1.1      fvdl #if 0
   1101    1.1      fvdl static int
   1102    1.1      fvdl agp_i810_detach(struct agp_softc *sc)
   1103    1.1      fvdl {
   1104    1.1      fvdl 	int error;
   1105    1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
   1106    1.1      fvdl 
   1107    1.1      fvdl 	error = agp_generic_detach(sc);
   1108    1.1      fvdl 	if (error)
   1109    1.1      fvdl 		return error;
   1110    1.1      fvdl 
   1111   1.75  riastrad 	switch (isc->chiptype) {
   1112   1.75  riastrad 	case CHIP_I915:
   1113   1.75  riastrad 	case CHIP_I965:
   1114   1.75  riastrad 	case CHIP_G33:
   1115  1.122    nonaka 	case CHIP_PINEVIEW:
   1116   1.75  riastrad 	case CHIP_G4X:
   1117   1.79  riastrad 		agp_i810_teardown_chipset_flush_page(sc);
   1118   1.75  riastrad 		break;
   1119   1.75  riastrad 	}
   1120   1.75  riastrad 
   1121    1.1      fvdl 	/* Clear the GATT base. */
   1122   1.14       scw 	if (sc->chiptype == CHIP_I810) {
   1123   1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, 0);
   1124   1.14       scw 	} else {
   1125   1.14       scw 		unsigned int pgtblctl;
   1126   1.14       scw 		pgtblctl = READ4(AGP_I810_PGTBL_CTL);
   1127   1.14       scw 		pgtblctl &= ~1;
   1128   1.14       scw 		WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
   1129   1.14       scw 	}
   1130    1.1      fvdl 
   1131   1.14       scw 	if (sc->chiptype == CHIP_I810) {
   1132   1.14       scw 		agp_free_dmamem(sc->as_dmat, gatt->ag_size, gatt->ag_dmamap,
   1133   1.36  christos 		    (void *)gatt->ag_virtual, &gatt->ag_dmaseg, 1);
   1134   1.85  riastrad 		free(isc->gatt, M_AGP);
   1135   1.14       scw 	}
   1136    1.1      fvdl 
   1137    1.1      fvdl 	return 0;
   1138    1.1      fvdl }
   1139    1.1      fvdl #endif
   1140    1.1      fvdl 
   1141    1.1      fvdl static u_int32_t
   1142    1.1      fvdl agp_i810_get_aperture(struct agp_softc *sc)
   1143    1.1      fvdl {
   1144   1.14       scw 	struct agp_i810_softc *isc = sc->as_chipc;
   1145   1.14       scw 	pcireg_t reg;
   1146   1.58  christos 	u_int32_t size;
   1147   1.88  riastrad 	u_int16_t miscc, gcc1;
   1148   1.14       scw 
   1149   1.58  christos 	size = 0;
   1150   1.58  christos 
   1151   1.42     markd 	switch (isc->chiptype) {
   1152   1.42     markd 	case CHIP_I810:
   1153   1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
   1154   1.14       scw 		miscc = (u_int16_t)(reg >> 16);
   1155   1.14       scw 		if ((miscc & AGP_I810_MISCC_WINSIZE) ==
   1156   1.14       scw 		    AGP_I810_MISCC_WINSIZE_32)
   1157   1.58  christos 			size = 32 * 1024 * 1024;
   1158   1.14       scw 		else
   1159   1.58  christos 			size = 64 * 1024 * 1024;
   1160   1.58  christos 		break;
   1161   1.42     markd 	case CHIP_I830:
   1162   1.14       scw 		reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
   1163   1.14       scw 		gcc1 = (u_int16_t)(reg >> 16);
   1164   1.14       scw 		if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
   1165   1.58  christos 			size = 64 * 1024 * 1024;
   1166   1.14       scw 		else
   1167   1.58  christos 			size = 128 * 1024 * 1024;
   1168   1.58  christos 		break;
   1169   1.42     markd 	case CHIP_I855:
   1170   1.58  christos 		size = 128 * 1024 * 1024;
   1171   1.58  christos 		break;
   1172   1.42     markd 	case CHIP_I915:
   1173   1.45     joerg 	case CHIP_G33:
   1174  1.122    nonaka 	case CHIP_PINEVIEW:
   1175   1.64     markd 	case CHIP_G4X:
   1176   1.88  riastrad 		size = sc->as_apsize;
   1177   1.58  christos 		break;
   1178   1.42     markd 	case CHIP_I965:
   1179   1.58  christos 		size = 512 * 1024 * 1024;
   1180   1.58  christos 		break;
   1181   1.42     markd 	default:
   1182   1.42     markd 		aprint_error(": Unknown chipset\n");
   1183   1.14       scw 	}
   1184   1.42     markd 
   1185   1.58  christos 	return size;
   1186    1.1      fvdl }
   1187    1.1      fvdl 
   1188    1.1      fvdl static int
   1189   1.86  riastrad agp_i810_set_aperture(struct agp_softc *sc __unused,
   1190   1.86  riastrad     uint32_t aperture __unused)
   1191    1.1      fvdl {
   1192   1.14       scw 
   1193   1.86  riastrad 	return ENOSYS;
   1194    1.1      fvdl }
   1195    1.1      fvdl 
   1196    1.1      fvdl static int
   1197    1.1      fvdl agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical)
   1198    1.1      fvdl {
   1199    1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
   1200    1.1      fvdl 
   1201   1.85  riastrad 	if (offset < 0 || offset >= ((isc->gtt_size/4) << AGP_PAGE_SHIFT)) {
   1202  1.106  riastrad 		DPRINTF(sc, "failed"
   1203  1.107  riastrad 		    ": offset 0x%"PRIxMAX", shift %u, entries %"PRIuMAX"\n",
   1204  1.107  riastrad 		    (uintmax_t)offset,
   1205  1.107  riastrad 		    (unsigned)AGP_PAGE_SHIFT,
   1206  1.104  riastrad 		    (uintmax_t)isc->gtt_size/4);
   1207    1.1      fvdl 		return EINVAL;
   1208   1.14       scw 	}
   1209   1.14       scw 
   1210   1.70    gsutre 	if (isc->chiptype != CHIP_I810) {
   1211   1.14       scw 		if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
   1212  1.106  riastrad 			DPRINTF(sc, "trying to bind into stolen memory\n");
   1213   1.14       scw 			return EINVAL;
   1214   1.14       scw 		}
   1215   1.14       scw 	}
   1216    1.1      fvdl 
   1217  1.117  riastrad 	return agp_i810_write_gtt_entry(isc, offset, physical,
   1218  1.117  riastrad 	    AGP_I810_GTT_VALID);
   1219    1.1      fvdl }
   1220    1.1      fvdl 
   1221    1.1      fvdl static int
   1222    1.1      fvdl agp_i810_unbind_page(struct agp_softc *sc, off_t offset)
   1223    1.1      fvdl {
   1224    1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
   1225    1.1      fvdl 
   1226   1.85  riastrad 	if (offset < 0 || offset >= ((isc->gtt_size/4) << AGP_PAGE_SHIFT))
   1227    1.1      fvdl 		return EINVAL;
   1228    1.1      fvdl 
   1229   1.17   hannken 	if (isc->chiptype != CHIP_I810 ) {
   1230   1.14       scw 		if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
   1231  1.106  riastrad 			DPRINTF(sc, "trying to unbind from stolen memory\n");
   1232   1.14       scw 			return EINVAL;
   1233   1.14       scw 		}
   1234   1.14       scw 	}
   1235   1.14       scw 
   1236  1.117  riastrad 	return agp_i810_write_gtt_entry(isc, offset, 0, 0);
   1237    1.1      fvdl }
   1238    1.1      fvdl 
   1239    1.1      fvdl /*
   1240    1.1      fvdl  * Writing via memory mapped registers already flushes all TLBs.
   1241    1.1      fvdl  */
   1242    1.1      fvdl static void
   1243   1.35  christos agp_i810_flush_tlb(struct agp_softc *sc)
   1244    1.1      fvdl {
   1245    1.1      fvdl }
   1246    1.1      fvdl 
   1247    1.1      fvdl static int
   1248   1.35  christos agp_i810_enable(struct agp_softc *sc, u_int32_t mode)
   1249    1.1      fvdl {
   1250    1.1      fvdl 
   1251    1.1      fvdl 	return 0;
   1252    1.1      fvdl }
   1253    1.1      fvdl 
   1254   1.86  riastrad #define	AGP_I810_MEMTYPE_MAIN		0
   1255   1.86  riastrad #define	AGP_I810_MEMTYPE_DCACHE		1
   1256   1.86  riastrad #define	AGP_I810_MEMTYPE_HWCURSOR	2
   1257   1.86  riastrad 
   1258    1.1      fvdl static struct agp_memory *
   1259    1.1      fvdl agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size)
   1260    1.1      fvdl {
   1261    1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
   1262    1.1      fvdl 	struct agp_memory *mem;
   1263   1.86  riastrad 	int error;
   1264    1.1      fvdl 
   1265  1.107  riastrad 	DPRINTF(sc, "AGP: alloc(%d, 0x%"PRIxMAX")\n", type, (uintmax_t)size);
   1266   1.28  christos 
   1267   1.86  riastrad 	if (size <= 0)
   1268   1.86  riastrad 		return NULL;
   1269    1.1      fvdl 	if ((size & (AGP_PAGE_SIZE - 1)) != 0)
   1270   1.86  riastrad 		return NULL;
   1271   1.89  riastrad 	KASSERT(sc->as_allocated <= sc->as_maxmem);
   1272   1.89  riastrad 	if (size > (sc->as_maxmem - sc->as_allocated))
   1273   1.86  riastrad 		return NULL;
   1274  1.101  riastrad 	if (size > ((isc->gtt_size/4) << AGP_PAGE_SHIFT))
   1275  1.101  riastrad 		return NULL;
   1276  1.101  riastrad 
   1277   1.86  riastrad 	switch (type) {
   1278   1.86  riastrad 	case AGP_I810_MEMTYPE_MAIN:
   1279   1.86  riastrad 		break;
   1280   1.86  riastrad 	case AGP_I810_MEMTYPE_DCACHE:
   1281   1.86  riastrad 		if (isc->chiptype != CHIP_I810)
   1282   1.86  riastrad 			return NULL;
   1283    1.1      fvdl 		if (size != isc->dcache_size)
   1284   1.86  riastrad 			return NULL;
   1285   1.86  riastrad 		break;
   1286   1.86  riastrad 	case AGP_I810_MEMTYPE_HWCURSOR:
   1287   1.86  riastrad 		if ((size != AGP_PAGE_SIZE) &&
   1288   1.86  riastrad 		    (size != AGP_PAGE_SIZE*4))
   1289   1.86  riastrad 			return NULL;
   1290   1.86  riastrad 		break;
   1291   1.86  riastrad 	default:
   1292   1.86  riastrad 		return NULL;
   1293    1.1      fvdl 	}
   1294    1.1      fvdl 
   1295   1.86  riastrad 	mem = malloc(sizeof(*mem), M_AGP, M_WAITOK|M_ZERO);
   1296    1.1      fvdl 	if (mem == NULL)
   1297   1.86  riastrad 		goto fail0;
   1298    1.1      fvdl 	mem->am_id = sc->as_nextid++;
   1299    1.1      fvdl 	mem->am_size = size;
   1300    1.1      fvdl 	mem->am_type = type;
   1301    1.1      fvdl 
   1302   1.86  riastrad 	switch (type) {
   1303   1.86  riastrad 	case AGP_I810_MEMTYPE_MAIN:
   1304   1.86  riastrad 		error = bus_dmamap_create(sc->as_dmat, size,
   1305   1.86  riastrad 		    (size >> AGP_PAGE_SHIFT) + 1, size, 0, BUS_DMA_WAITOK,
   1306   1.86  riastrad 		    &mem->am_dmamap);
   1307   1.86  riastrad 		if (error)
   1308   1.86  riastrad 			goto fail1;
   1309   1.86  riastrad 		break;
   1310   1.86  riastrad 	case AGP_I810_MEMTYPE_DCACHE:
   1311   1.86  riastrad 		break;
   1312   1.86  riastrad 	case AGP_I810_MEMTYPE_HWCURSOR:
   1313   1.86  riastrad 		mem->am_dmaseg = malloc(sizeof(*mem->am_dmaseg), M_AGP,
   1314    1.1      fvdl 		    M_WAITOK);
   1315   1.86  riastrad 		error = agp_alloc_dmamem(sc->as_dmat, size, 0, &mem->am_dmamap,
   1316   1.86  riastrad 		    &mem->am_virtual, &mem->am_physical, mem->am_dmaseg, 1,
   1317   1.86  riastrad 		    &mem->am_nseg);
   1318   1.86  riastrad 		if (error) {
   1319    1.1      fvdl 			free(mem->am_dmaseg, M_AGP);
   1320   1.86  riastrad 			goto fail1;
   1321    1.1      fvdl 		}
   1322   1.86  riastrad 		(void)memset(mem->am_virtual, 0, size);
   1323   1.86  riastrad 		break;
   1324   1.86  riastrad 	default:
   1325   1.86  riastrad 		panic("invalid agp memory type: %d", type);
   1326    1.1      fvdl 	}
   1327    1.1      fvdl 
   1328    1.1      fvdl 	TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link);
   1329    1.1      fvdl 	sc->as_allocated += size;
   1330    1.1      fvdl 
   1331    1.1      fvdl 	return mem;
   1332   1.86  riastrad 
   1333   1.86  riastrad fail1:	free(mem, M_AGP);
   1334   1.86  riastrad fail0:	return NULL;
   1335    1.1      fvdl }
   1336    1.1      fvdl 
   1337    1.1      fvdl static int
   1338    1.1      fvdl agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem)
   1339    1.1      fvdl {
   1340   1.86  riastrad 
   1341    1.1      fvdl 	if (mem->am_is_bound)
   1342    1.1      fvdl 		return EBUSY;
   1343    1.1      fvdl 
   1344   1.86  riastrad 	switch (mem->am_type) {
   1345   1.86  riastrad 	case AGP_I810_MEMTYPE_MAIN:
   1346   1.90  riastrad 		bus_dmamap_destroy(sc->as_dmat, mem->am_dmamap);
   1347   1.90  riastrad 		break;
   1348   1.86  riastrad 	case AGP_I810_MEMTYPE_DCACHE:
   1349   1.86  riastrad 		break;
   1350   1.86  riastrad 	case AGP_I810_MEMTYPE_HWCURSOR:
   1351    1.1      fvdl 		agp_free_dmamem(sc->as_dmat, mem->am_size, mem->am_dmamap,
   1352    1.1      fvdl 		    mem->am_virtual, mem->am_dmaseg, mem->am_nseg);
   1353    1.1      fvdl 		free(mem->am_dmaseg, M_AGP);
   1354   1.86  riastrad 		break;
   1355   1.86  riastrad 	default:
   1356   1.86  riastrad 		panic("invalid agp i810 memory type: %d", mem->am_type);
   1357    1.1      fvdl 	}
   1358    1.1      fvdl 
   1359    1.1      fvdl 	sc->as_allocated -= mem->am_size;
   1360    1.1      fvdl 	TAILQ_REMOVE(&sc->as_memory, mem, am_link);
   1361    1.1      fvdl 	free(mem, M_AGP);
   1362   1.86  riastrad 
   1363    1.1      fvdl 	return 0;
   1364    1.1      fvdl }
   1365    1.1      fvdl 
   1366    1.1      fvdl static int
   1367    1.1      fvdl agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
   1368   1.86  riastrad     off_t offset)
   1369    1.1      fvdl {
   1370    1.1      fvdl 	struct agp_i810_softc *isc = sc->as_chipc;
   1371   1.86  riastrad 	uint32_t pgtblctl;
   1372   1.86  riastrad 	int error;
   1373    1.4  drochner 
   1374   1.86  riastrad 	if (mem->am_is_bound)
   1375   1.70    gsutre 		return EINVAL;
   1376   1.70    gsutre 
   1377    1.4  drochner 	/*
   1378    1.4  drochner 	 * XXX evil hack: the PGTBL_CTL appearently gets overwritten by the
   1379    1.4  drochner 	 * X server for mysterious reasons which leads to crashes if we write
   1380    1.4  drochner 	 * to the GTT through the MMIO window.
   1381    1.4  drochner 	 * Until the issue is solved, simply restore it.
   1382    1.4  drochner 	 */
   1383   1.86  riastrad 	pgtblctl = bus_space_read_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL);
   1384   1.86  riastrad 	if (pgtblctl != isc->pgtblctl) {
   1385   1.86  riastrad 		printf("agp_i810_bind_memory: PGTBL_CTL is 0x%"PRIx32
   1386   1.86  riastrad 		    " - fixing\n", pgtblctl);
   1387    1.4  drochner 		bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL,
   1388   1.85  riastrad 		    isc->pgtblctl);
   1389    1.4  drochner 	}
   1390    1.1      fvdl 
   1391   1.86  riastrad 	switch (mem->am_type) {
   1392   1.86  riastrad 	case AGP_I810_MEMTYPE_MAIN:
   1393  1.101  riastrad 		return agp_generic_bind_memory_bounded(sc, mem, offset,
   1394  1.101  riastrad 		    0, (isc->gtt_size/4) << AGP_PAGE_SHIFT);
   1395   1.86  riastrad 	case AGP_I810_MEMTYPE_DCACHE:
   1396   1.86  riastrad 		error = agp_i810_bind_memory_dcache(sc, mem, offset);
   1397   1.86  riastrad 		break;
   1398   1.86  riastrad 	case AGP_I810_MEMTYPE_HWCURSOR:
   1399   1.86  riastrad 		error = agp_i810_bind_memory_hwcursor(sc, mem, offset);
   1400   1.86  riastrad 		break;
   1401   1.86  riastrad 	default:
   1402   1.86  riastrad 		panic("invalid agp i810 memory type: %d", mem->am_type);
   1403    1.5  drochner 	}
   1404   1.86  riastrad 	if (error)
   1405   1.86  riastrad 		return error;
   1406    1.5  drochner 
   1407   1.86  riastrad 	/* Success!  */
   1408   1.86  riastrad 	mem->am_is_bound = 1;
   1409   1.86  riastrad 	return 0;
   1410   1.86  riastrad }
   1411   1.86  riastrad 
   1412   1.86  riastrad static int
   1413   1.86  riastrad agp_i810_bind_memory_dcache(struct agp_softc *sc, struct agp_memory *mem,
   1414   1.86  riastrad     off_t offset)
   1415   1.86  riastrad {
   1416   1.86  riastrad 	struct agp_i810_softc *const isc __diagused = sc->as_chipc;
   1417   1.86  riastrad 	uint32_t i, j;
   1418   1.86  riastrad 	int error;
   1419   1.86  riastrad 
   1420   1.86  riastrad 	KASSERT(isc->chiptype == CHIP_I810);
   1421   1.86  riastrad 
   1422   1.86  riastrad 	KASSERT((mem->am_size & (AGP_PAGE_SIZE - 1)) == 0);
   1423   1.86  riastrad 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
   1424  1.108  riastrad 		error = agp_i810_write_gtt_entry(isc, offset + i,
   1425  1.117  riastrad 		    i, AGP_I810_GTT_VALID | AGP_I810_GTT_I810_DCACHE);
   1426   1.86  riastrad 		if (error)
   1427   1.86  riastrad 			goto fail0;
   1428   1.86  riastrad 	}
   1429   1.86  riastrad 
   1430   1.86  riastrad 	/* Success!  */
   1431  1.111  riastrad 	mem->am_offset = offset;
   1432   1.86  riastrad 	return 0;
   1433   1.14       scw 
   1434   1.86  riastrad fail0:	for (j = 0; j < i; j += AGP_PAGE_SIZE)
   1435   1.86  riastrad 		(void)agp_i810_unbind_page(sc, offset + j);
   1436   1.86  riastrad 	return error;
   1437   1.86  riastrad }
   1438   1.86  riastrad 
   1439   1.86  riastrad static int
   1440   1.86  riastrad agp_i810_bind_memory_hwcursor(struct agp_softc *sc, struct agp_memory *mem,
   1441   1.86  riastrad     off_t offset)
   1442   1.86  riastrad {
   1443   1.86  riastrad 	const bus_addr_t pa = mem->am_physical;
   1444   1.86  riastrad 	uint32_t i, j;
   1445   1.86  riastrad 	int error;
   1446   1.86  riastrad 
   1447   1.86  riastrad 	KASSERT((mem->am_size & (AGP_PAGE_SIZE - 1)) == 0);
   1448   1.86  riastrad 	for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
   1449   1.86  riastrad 		error = agp_i810_bind_page(sc, offset + i, pa + i);
   1450   1.86  riastrad 		if (error)
   1451   1.86  riastrad 			goto fail0;
   1452   1.86  riastrad 	}
   1453   1.86  riastrad 
   1454   1.86  riastrad 	/* Success!  */
   1455   1.86  riastrad 	mem->am_offset = offset;
   1456    1.1      fvdl 	return 0;
   1457   1.86  riastrad 
   1458   1.86  riastrad fail0:	for (j = 0; j < i; j += AGP_PAGE_SIZE)
   1459   1.86  riastrad 		(void)agp_i810_unbind_page(sc, offset + j);
   1460   1.86  riastrad 	return error;
   1461    1.1      fvdl }
   1462    1.1      fvdl 
   1463    1.1      fvdl static int
   1464    1.1      fvdl agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem)
   1465    1.1      fvdl {
   1466  1.112  riastrad 	struct agp_i810_softc *isc __diagused = sc->as_chipc;
   1467    1.1      fvdl 	u_int32_t i;
   1468    1.1      fvdl 
   1469   1.86  riastrad 	if (!mem->am_is_bound)
   1470   1.70    gsutre 		return EINVAL;
   1471   1.70    gsutre 
   1472   1.86  riastrad 	switch (mem->am_type) {
   1473   1.86  riastrad 	case AGP_I810_MEMTYPE_MAIN:
   1474  1.101  riastrad 		return agp_generic_unbind_memory(sc, mem);
   1475   1.86  riastrad 	case AGP_I810_MEMTYPE_DCACHE:
   1476   1.86  riastrad 		KASSERT(isc->chiptype == CHIP_I810);
   1477  1.111  riastrad 		/* FALLTHROUGH */
   1478   1.94  riastrad 	case AGP_I810_MEMTYPE_HWCURSOR:
   1479   1.94  riastrad 		for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
   1480   1.94  riastrad 			(void)agp_i810_unbind_page(sc, mem->am_offset + i);
   1481   1.94  riastrad 		mem->am_offset = 0;
   1482   1.94  riastrad 		break;
   1483   1.86  riastrad 	default:
   1484   1.86  riastrad 		panic("invalid agp i810 memory type: %d", mem->am_type);
   1485    1.5  drochner 	}
   1486    1.1      fvdl 
   1487   1.13  drochner 	mem->am_is_bound = 0;
   1488    1.1      fvdl 	return 0;
   1489    1.1      fvdl }
   1490   1.24  jmcneill 
   1491  1.123  riastrad void
   1492  1.123  riastrad agp_i810_reset(struct agp_i810_softc *isc)
   1493  1.123  riastrad {
   1494  1.123  riastrad 
   1495  1.123  riastrad 	/* Restore the page table control register.  */
   1496  1.123  riastrad 	bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL,
   1497  1.123  riastrad 	    isc->pgtblctl);
   1498  1.123  riastrad 
   1499  1.123  riastrad 	agp_flush_cache();
   1500  1.123  riastrad }
   1501  1.123  riastrad 
   1502   1.47  jmcneill static bool
   1503   1.66    dyoung agp_i810_resume(device_t dv, const pmf_qual_t *qual)
   1504   1.24  jmcneill {
   1505   1.47  jmcneill 	struct agp_softc *sc = device_private(dv);
   1506   1.24  jmcneill 	struct agp_i810_softc *isc = sc->as_chipc;
   1507   1.24  jmcneill 
   1508  1.123  riastrad 	agp_i810_reset(isc);
   1509   1.24  jmcneill 
   1510   1.47  jmcneill 	return true;
   1511   1.24  jmcneill }
   1512