xref: /freebsd/sys/dev/agp/agp_ati.c (revision fdafd315)
1e3e1ac86SEric Anholt /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4e3e1ac86SEric Anholt  * Copyright (c) 2005 Eric Anholt
5e3e1ac86SEric Anholt  * All rights reserved.
6e3e1ac86SEric Anholt  *
7e3e1ac86SEric Anholt  * Redistribution and use in source and binary forms, with or without
8e3e1ac86SEric Anholt  * modification, are permitted provided that the following conditions
9e3e1ac86SEric Anholt  * are met:
10e3e1ac86SEric Anholt  * 1. Redistributions of source code must retain the above copyright
11e3e1ac86SEric Anholt  *    notice, this list of conditions and the following disclaimer.
12e3e1ac86SEric Anholt  * 2. Redistributions in binary form must reproduce the above copyright
13e3e1ac86SEric Anholt  *    notice, this list of conditions and the following disclaimer in the
14e3e1ac86SEric Anholt  *    documentation and/or other materials provided with the distribution.
15e3e1ac86SEric Anholt  *
16e3e1ac86SEric Anholt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17e3e1ac86SEric Anholt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18e3e1ac86SEric Anholt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19e3e1ac86SEric Anholt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20e3e1ac86SEric Anholt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21e3e1ac86SEric Anholt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22e3e1ac86SEric Anholt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23e3e1ac86SEric Anholt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24e3e1ac86SEric Anholt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25e3e1ac86SEric Anholt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26e3e1ac86SEric Anholt  * SUCH DAMAGE.
27e3e1ac86SEric Anholt  *
28e3e1ac86SEric Anholt  * Based on reading the Linux 2.6.8.1 driver by Dave Jones.
29e3e1ac86SEric Anholt  */
30e3e1ac86SEric Anholt 
31e3e1ac86SEric Anholt #include <sys/param.h>
32e3e1ac86SEric Anholt #include <sys/systm.h>
33e3e1ac86SEric Anholt #include <sys/malloc.h>
34e3e1ac86SEric Anholt #include <sys/kernel.h>
35e3e1ac86SEric Anholt #include <sys/module.h>
36e3e1ac86SEric Anholt #include <sys/bus.h>
37e3e1ac86SEric Anholt #include <sys/lock.h>
38e3e1ac86SEric Anholt #include <sys/mutex.h>
39e3e1ac86SEric Anholt #include <sys/proc.h>
40e3e1ac86SEric Anholt 
41dbac8ff4SJohn Baldwin #include <dev/agp/agppriv.h>
42dbac8ff4SJohn Baldwin #include <dev/agp/agpreg.h>
43e3e1ac86SEric Anholt #include <dev/pci/pcivar.h>
44e3e1ac86SEric Anholt #include <dev/pci/pcireg.h>
45e3e1ac86SEric Anholt 
46e3e1ac86SEric Anholt #include <vm/vm.h>
474e612cddSTijl Coosemans #include <vm/vm_extern.h>
484e612cddSTijl Coosemans #include <vm/vm_kern.h>
49e3e1ac86SEric Anholt #include <vm/vm_object.h>
50e3e1ac86SEric Anholt #include <vm/pmap.h>
51e3e1ac86SEric Anholt #include <machine/bus.h>
52e3e1ac86SEric Anholt #include <machine/resource.h>
53e3e1ac86SEric Anholt #include <sys/rman.h>
54e3e1ac86SEric Anholt 
55e3e1ac86SEric Anholt MALLOC_DECLARE(M_AGP);
56e3e1ac86SEric Anholt 
57e3e1ac86SEric Anholt #define READ4(off)	bus_space_read_4(sc->bst, sc->bsh, off)
58e3e1ac86SEric Anholt #define WRITE4(off,v)	bus_space_write_4(sc->bst, sc->bsh, off, v)
59e3e1ac86SEric Anholt 
60e3e1ac86SEric Anholt struct agp_ati_softc {
61e3e1ac86SEric Anholt 	struct agp_softc agp;
62e3e1ac86SEric Anholt 	struct resource *regs;	/* memory mapped control registers */
63e3e1ac86SEric Anholt 	bus_space_tag_t bst;	/* bus_space tag */
64e3e1ac86SEric Anholt 	bus_space_handle_t bsh;	/* bus_space handle */
65e3e1ac86SEric Anholt 	u_int32_t	initial_aperture; /* aperture size at startup */
66e3e1ac86SEric Anholt 	char		is_rs300;
67e3e1ac86SEric Anholt 
68e3e1ac86SEric Anholt 	/* The GATT */
69e3e1ac86SEric Anholt 	u_int32_t	ag_entries;
70e3e1ac86SEric Anholt 	u_int32_t      *ag_virtual;	/* virtual address of gatt */
71e3e1ac86SEric Anholt 	u_int32_t      *ag_vdir;	/* virtual address of page dir */
72e3e1ac86SEric Anholt 	vm_offset_t	ag_pdir;	/* physical address of page dir */
73e3e1ac86SEric Anholt };
74e3e1ac86SEric Anholt 
75e3e1ac86SEric Anholt static const char*
agp_ati_match(device_t dev)76e3e1ac86SEric Anholt agp_ati_match(device_t dev)
77e3e1ac86SEric Anholt {
78e3e1ac86SEric Anholt 	if (pci_get_class(dev) != PCIC_BRIDGE ||
79e3e1ac86SEric Anholt 	    pci_get_subclass(dev) != PCIS_BRIDGE_HOST)
80e3e1ac86SEric Anholt 		return NULL;
81e3e1ac86SEric Anholt 
82e3e1ac86SEric Anholt 	if (agp_find_caps(dev) == 0)
83e3e1ac86SEric Anholt 		return NULL;
84e3e1ac86SEric Anholt 
85e3e1ac86SEric Anholt 	switch (pci_get_devid(dev)) {
86e3e1ac86SEric Anholt 	case 0xcab01002:
87e3e1ac86SEric Anholt 		return ("ATI RS100 AGP bridge");
88e3e1ac86SEric Anholt 	case 0xcab21002:
89e3e1ac86SEric Anholt 		return ("ATI RS200 AGP bridge");
90c88bc907SEric Anholt 	case 0xcbb21002:
91c88bc907SEric Anholt 		return ("ATI RS200M AGP bridge");
92e3e1ac86SEric Anholt 	case 0xcab31002:
93e3e1ac86SEric Anholt 		return ("ATI RS250 AGP bridge");
94e3e1ac86SEric Anholt 	case 0x58301002:
95e3e1ac86SEric Anholt 		return ("ATI RS300_100 AGP bridge");
96e3e1ac86SEric Anholt 	case 0x58311002:
97e3e1ac86SEric Anholt 		return ("ATI RS300_133 AGP bridge");
98e3e1ac86SEric Anholt 	case 0x58321002:
99e3e1ac86SEric Anholt 		return ("ATI RS300_166 AGP bridge");
100e3e1ac86SEric Anholt 	case 0x58331002:
101e3e1ac86SEric Anholt 		return ("ATI RS300_200 AGP bridge");
102dfa4d7fdSAntoine Brodin 	}
103e3e1ac86SEric Anholt 
104e3e1ac86SEric Anholt 	return NULL;
105e3e1ac86SEric Anholt }
106e3e1ac86SEric Anholt 
107e3e1ac86SEric Anholt static int
agp_ati_probe(device_t dev)108e3e1ac86SEric Anholt agp_ati_probe(device_t dev)
109e3e1ac86SEric Anholt {
110e3e1ac86SEric Anholt 	const char *desc;
111e3e1ac86SEric Anholt 
112e3e1ac86SEric Anholt 	desc = agp_ati_match(dev);
113e3e1ac86SEric Anholt 	if (desc) {
114e3e1ac86SEric Anholt 		device_set_desc(dev, desc);
115e3e1ac86SEric Anholt 		return 0;
116e3e1ac86SEric Anholt 	}
117e3e1ac86SEric Anholt 
118e3e1ac86SEric Anholt 	return ENXIO;
119e3e1ac86SEric Anholt }
120e3e1ac86SEric Anholt 
121e3e1ac86SEric Anholt static int
agp_ati_alloc_gatt(device_t dev)122e3e1ac86SEric Anholt agp_ati_alloc_gatt(device_t dev)
123e3e1ac86SEric Anholt {
124e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
125e3e1ac86SEric Anholt 	u_int32_t apsize = AGP_GET_APERTURE(dev);
126e3e1ac86SEric Anholt 	u_int32_t entries = apsize >> AGP_PAGE_SHIFT;
127e3e1ac86SEric Anholt 	u_int32_t apbase_offset;
128e3e1ac86SEric Anholt 	int i;
129e3e1ac86SEric Anholt 
130e3e1ac86SEric Anholt 	/* Alloc the GATT -- pointers to pages of AGP memory */
131e3e1ac86SEric Anholt 	sc->ag_entries = entries;
132f49fd63aSJohn Baldwin 	sc->ag_virtual = kmem_alloc_attr(entries * sizeof(uint32_t),
13394d0f087SAlan Cox 	    M_NOWAIT | M_ZERO, 0, ~0, VM_MEMATTR_WRITE_COMBINING);
134e3e1ac86SEric Anholt 	if (sc->ag_virtual == NULL) {
135e3e1ac86SEric Anholt 		if (bootverbose)
1364e612cddSTijl Coosemans 			device_printf(dev, "GATT allocation failed\n");
137e3e1ac86SEric Anholt 		return ENOMEM;
138e3e1ac86SEric Anholt 	}
139e3e1ac86SEric Anholt 
140e3e1ac86SEric Anholt 	/* Alloc the page directory -- pointers to each page of the GATT */
141f49fd63aSJohn Baldwin 	sc->ag_vdir = kmem_alloc_attr(AGP_PAGE_SIZE, M_NOWAIT | M_ZERO,
14294d0f087SAlan Cox 	    0, ~0, VM_MEMATTR_WRITE_COMBINING);
143e3e1ac86SEric Anholt 	if (sc->ag_vdir == NULL) {
144e3e1ac86SEric Anholt 		if (bootverbose)
145e3e1ac86SEric Anholt 			device_printf(dev, "pagedir allocation failed\n");
146f49fd63aSJohn Baldwin 		kmem_free(sc->ag_virtual, entries * sizeof(uint32_t));
147e3e1ac86SEric Anholt 		return ENOMEM;
148e3e1ac86SEric Anholt 	}
149e3e1ac86SEric Anholt 	sc->ag_pdir = vtophys((vm_offset_t)sc->ag_vdir);
150e3e1ac86SEric Anholt 
151e3e1ac86SEric Anholt 	apbase_offset = pci_read_config(dev, AGP_APBASE, 4) >> 22;
152e3e1ac86SEric Anholt 	/* Fill in the pagedir's pointers to GATT pages */
153e3e1ac86SEric Anholt 	for (i = 0; i < sc->ag_entries / 1024; i++) {
154e3e1ac86SEric Anholt 		vm_offset_t va;
155e3e1ac86SEric Anholt 		vm_offset_t pa;
156e3e1ac86SEric Anholt 
157e3e1ac86SEric Anholt 		va = ((vm_offset_t)sc->ag_virtual) + i * AGP_PAGE_SIZE;
158e3e1ac86SEric Anholt 		pa = vtophys(va);
159e3e1ac86SEric Anholt 		sc->ag_vdir[apbase_offset + i] = pa | 1;
160e3e1ac86SEric Anholt 	}
161e3e1ac86SEric Anholt 
162e3e1ac86SEric Anholt 	return 0;
163e3e1ac86SEric Anholt }
164e3e1ac86SEric Anholt 
165e3e1ac86SEric Anholt static int
agp_ati_attach(device_t dev)166e3e1ac86SEric Anholt agp_ati_attach(device_t dev)
167e3e1ac86SEric Anholt {
168e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
169e3e1ac86SEric Anholt 	int error, rid;
170e3e1ac86SEric Anholt 	u_int32_t temp;
171e3e1ac86SEric Anholt 	u_int32_t apsize_reg, agpmode_reg;
172e3e1ac86SEric Anholt 
173e3e1ac86SEric Anholt 	error = agp_generic_attach(dev);
174e3e1ac86SEric Anholt 	if (error)
175e3e1ac86SEric Anholt 		return error;
176e3e1ac86SEric Anholt 
177e3e1ac86SEric Anholt 	switch (pci_get_devid(dev)) {
178e3e1ac86SEric Anholt 	case 0xcab01002: /* ATI RS100 AGP bridge */
179e3e1ac86SEric Anholt 	case 0xcab21002: /* ATI RS200 AGP bridge */
180c88bc907SEric Anholt 	case 0xcbb21002: /* ATI RS200M AGP bridge */
181e3e1ac86SEric Anholt 	case 0xcab31002: /* ATI RS250 AGP bridge */
182e3e1ac86SEric Anholt 		sc->is_rs300 = 0;
183e3e1ac86SEric Anholt 		apsize_reg = ATI_RS100_APSIZE;
184e3e1ac86SEric Anholt 		agpmode_reg = ATI_RS100_IG_AGPMODE;
185e3e1ac86SEric Anholt 		break;
186e3e1ac86SEric Anholt 	case 0x58301002: /* ATI RS300_100 AGP bridge */
187e3e1ac86SEric Anholt 	case 0x58311002: /* ATI RS300_133 AGP bridge */
188e3e1ac86SEric Anholt 	case 0x58321002: /* ATI RS300_166 AGP bridge */
189e3e1ac86SEric Anholt 	case 0x58331002: /* ATI RS300_200 AGP bridge */
190e3e1ac86SEric Anholt 		sc->is_rs300 = 1;
191e3e1ac86SEric Anholt 		apsize_reg = ATI_RS300_APSIZE;
192e3e1ac86SEric Anholt 		agpmode_reg = ATI_RS300_IG_AGPMODE;
193e3e1ac86SEric Anholt 		break;
194e3e1ac86SEric Anholt 	default:
195e3e1ac86SEric Anholt 		/* Unknown chipset */
196e3e1ac86SEric Anholt 		return EINVAL;
197dfa4d7fdSAntoine Brodin 	}
198e3e1ac86SEric Anholt 
199e3e1ac86SEric Anholt 	rid = ATI_GART_MMADDR;
200e3e1ac86SEric Anholt 	sc->regs = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
201e3e1ac86SEric Anholt 	if (!sc->regs) {
202e3e1ac86SEric Anholt 		agp_generic_detach(dev);
203e3e1ac86SEric Anholt 		return ENOMEM;
204e3e1ac86SEric Anholt 	}
205e3e1ac86SEric Anholt 
206e3e1ac86SEric Anholt 	sc->bst = rman_get_bustag(sc->regs);
207e3e1ac86SEric Anholt 	sc->bsh = rman_get_bushandle(sc->regs);
208e3e1ac86SEric Anholt 
209e3e1ac86SEric Anholt 	sc->initial_aperture = AGP_GET_APERTURE(dev);
210e3e1ac86SEric Anholt 
211e3e1ac86SEric Anholt 	for (;;) {
212e3e1ac86SEric Anholt 		if (agp_ati_alloc_gatt(dev) == 0)
213e3e1ac86SEric Anholt 			break;
214e3e1ac86SEric Anholt 
215e3e1ac86SEric Anholt 		/*
216e3e1ac86SEric Anholt 		 * Probably contigmalloc failure. Try reducing the
217e3e1ac86SEric Anholt 		 * aperture so that the gatt size reduces.
218e3e1ac86SEric Anholt 		 */
219e3e1ac86SEric Anholt 		if (AGP_SET_APERTURE(dev, AGP_GET_APERTURE(dev) / 2))
220e3e1ac86SEric Anholt 			return ENOMEM;
221e3e1ac86SEric Anholt 	}
222e3e1ac86SEric Anholt 
223e3e1ac86SEric Anholt 	temp = pci_read_config(dev, apsize_reg, 4);
224e3e1ac86SEric Anholt 	pci_write_config(dev, apsize_reg, temp | 1, 4);
225e3e1ac86SEric Anholt 
226e3e1ac86SEric Anholt 	pci_write_config(dev, agpmode_reg, 0x20000, 4);
227e3e1ac86SEric Anholt 
228e3e1ac86SEric Anholt 	WRITE4(ATI_GART_FEATURE_ID, 0x00060000);
229e3e1ac86SEric Anholt 
230e3e1ac86SEric Anholt 	temp = pci_read_config(dev, 4, 4);	/* XXX: Magic reg# */
231e3e1ac86SEric Anholt 	pci_write_config(dev, 4, temp | (1 << 14), 4);
232e3e1ac86SEric Anholt 
233e3e1ac86SEric Anholt 	WRITE4(ATI_GART_BASE, sc->ag_pdir);
234e3e1ac86SEric Anholt 
235e3e1ac86SEric Anholt 	AGP_FLUSH_TLB(dev);
236e3e1ac86SEric Anholt 
237e3e1ac86SEric Anholt 	return 0;
238e3e1ac86SEric Anholt }
239e3e1ac86SEric Anholt 
240e3e1ac86SEric Anholt static int
agp_ati_detach(device_t dev)241e3e1ac86SEric Anholt agp_ati_detach(device_t dev)
242e3e1ac86SEric Anholt {
243e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
244e3e1ac86SEric Anholt 	u_int32_t apsize_reg, temp;
245e3e1ac86SEric Anholt 
246f82a1d49SJohn Baldwin 	agp_free_cdev(dev);
247f82a1d49SJohn Baldwin 
248e3e1ac86SEric Anholt 	if (sc->is_rs300)
249e3e1ac86SEric Anholt 		apsize_reg = ATI_RS300_APSIZE;
250e3e1ac86SEric Anholt 	else
251e3e1ac86SEric Anholt 		apsize_reg = ATI_RS100_APSIZE;
252e3e1ac86SEric Anholt 
253e3e1ac86SEric Anholt 	/* Clear the GATT base */
254e3e1ac86SEric Anholt 	WRITE4(ATI_GART_BASE, 0);
255e3e1ac86SEric Anholt 
256e3e1ac86SEric Anholt 	/* Put the aperture back the way it started. */
257e3e1ac86SEric Anholt 	AGP_SET_APERTURE(dev, sc->initial_aperture);
258e3e1ac86SEric Anholt 
259e3e1ac86SEric Anholt 	temp = pci_read_config(dev, apsize_reg, 4);
260e3e1ac86SEric Anholt 	pci_write_config(dev, apsize_reg, temp & ~1, 4);
261e3e1ac86SEric Anholt 
262f49fd63aSJohn Baldwin 	kmem_free(sc->ag_vdir, AGP_PAGE_SIZE);
263f49fd63aSJohn Baldwin 	kmem_free(sc->ag_virtual, sc->ag_entries * sizeof(uint32_t));
264e3e1ac86SEric Anholt 
265e3e1ac86SEric Anholt 	bus_release_resource(dev, SYS_RES_MEMORY, ATI_GART_MMADDR, sc->regs);
266f82a1d49SJohn Baldwin 	agp_free_res(dev);
267e3e1ac86SEric Anholt 
268e3e1ac86SEric Anholt 	return 0;
269e3e1ac86SEric Anholt }
270e3e1ac86SEric Anholt 
271e3e1ac86SEric Anholt static u_int32_t
agp_ati_get_aperture(device_t dev)272e3e1ac86SEric Anholt agp_ati_get_aperture(device_t dev)
273e3e1ac86SEric Anholt {
274e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
275e3e1ac86SEric Anholt 	int size_value;
276e3e1ac86SEric Anholt 
277e3e1ac86SEric Anholt 	if (sc->is_rs300)
278e3e1ac86SEric Anholt 		size_value = pci_read_config(dev, ATI_RS300_APSIZE, 4);
279e3e1ac86SEric Anholt 	else
280e3e1ac86SEric Anholt 		size_value = pci_read_config(dev, ATI_RS100_APSIZE, 4);
281e3e1ac86SEric Anholt 
282e3e1ac86SEric Anholt 	size_value = (size_value & 0x0000000e) >> 1;
283e3e1ac86SEric Anholt 	size_value = (32 * 1024 * 1024) << size_value;
284e3e1ac86SEric Anholt 
285e3e1ac86SEric Anholt 	return size_value;
286e3e1ac86SEric Anholt }
287e3e1ac86SEric Anholt 
288e3e1ac86SEric Anholt static int
agp_ati_set_aperture(device_t dev,u_int32_t aperture)289e3e1ac86SEric Anholt agp_ati_set_aperture(device_t dev, u_int32_t aperture)
290e3e1ac86SEric Anholt {
291e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
292e3e1ac86SEric Anholt 	int size_value;
293e3e1ac86SEric Anholt 	u_int32_t apsize_reg;
294e3e1ac86SEric Anholt 
295e3e1ac86SEric Anholt 	if (sc->is_rs300)
296e3e1ac86SEric Anholt 		apsize_reg = ATI_RS300_APSIZE;
297e3e1ac86SEric Anholt 	else
298e3e1ac86SEric Anholt 		apsize_reg = ATI_RS100_APSIZE;
299e3e1ac86SEric Anholt 
300e3e1ac86SEric Anholt 	size_value = pci_read_config(dev, apsize_reg, 4);
301e3e1ac86SEric Anholt 
302e3e1ac86SEric Anholt 	size_value &= ~0x0000000e;
303e3e1ac86SEric Anholt 	size_value |= (ffs(aperture / (32 * 1024 * 1024)) - 1) << 1;
304e3e1ac86SEric Anholt 
305e3e1ac86SEric Anholt 	pci_write_config(dev, apsize_reg, size_value, 4);
306e3e1ac86SEric Anholt 
307e3e1ac86SEric Anholt 	return 0;
308e3e1ac86SEric Anholt }
309e3e1ac86SEric Anholt 
310e3e1ac86SEric Anholt static int
agp_ati_bind_page(device_t dev,vm_offset_t offset,vm_offset_t physical)311446188d1SAndriy Gapon agp_ati_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
312e3e1ac86SEric Anholt {
313e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
314e3e1ac86SEric Anholt 
315446188d1SAndriy Gapon 	if (offset >= (sc->ag_entries << AGP_PAGE_SHIFT))
316e3e1ac86SEric Anholt 		return EINVAL;
317e3e1ac86SEric Anholt 
318e3e1ac86SEric Anholt 	sc->ag_virtual[offset >> AGP_PAGE_SHIFT] = physical | 1;
319e3e1ac86SEric Anholt 
320e3e1ac86SEric Anholt 	return 0;
321e3e1ac86SEric Anholt }
322e3e1ac86SEric Anholt 
323e3e1ac86SEric Anholt static int
agp_ati_unbind_page(device_t dev,vm_offset_t offset)324446188d1SAndriy Gapon agp_ati_unbind_page(device_t dev, vm_offset_t offset)
325e3e1ac86SEric Anholt {
326e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
327e3e1ac86SEric Anholt 
328446188d1SAndriy Gapon 	if (offset >= (sc->ag_entries << AGP_PAGE_SHIFT))
329e3e1ac86SEric Anholt 		return EINVAL;
330e3e1ac86SEric Anholt 
331e3e1ac86SEric Anholt 	sc->ag_virtual[offset >> AGP_PAGE_SHIFT] = 0;
332e3e1ac86SEric Anholt 	return 0;
333e3e1ac86SEric Anholt }
334e3e1ac86SEric Anholt 
335e3e1ac86SEric Anholt static void
agp_ati_flush_tlb(device_t dev)336e3e1ac86SEric Anholt agp_ati_flush_tlb(device_t dev)
337e3e1ac86SEric Anholt {
338e3e1ac86SEric Anholt 	struct agp_ati_softc *sc = device_get_softc(dev);
339e3e1ac86SEric Anholt 
340e3e1ac86SEric Anholt 	/* Set the cache invalidate bit and wait for the chipset to clear */
341e3e1ac86SEric Anholt 	WRITE4(ATI_GART_CACHE_CNTRL, 1);
342e3e1ac86SEric Anholt 	(void)READ4(ATI_GART_CACHE_CNTRL);
343e3e1ac86SEric Anholt }
344e3e1ac86SEric Anholt 
345e3e1ac86SEric Anholt static device_method_t agp_ati_methods[] = {
346e3e1ac86SEric Anholt 	/* Device interface */
347e3e1ac86SEric Anholt 	DEVMETHOD(device_probe,		agp_ati_probe),
348e3e1ac86SEric Anholt 	DEVMETHOD(device_attach,	agp_ati_attach),
349e3e1ac86SEric Anholt 	DEVMETHOD(device_detach,	agp_ati_detach),
350e3e1ac86SEric Anholt 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
351e3e1ac86SEric Anholt 	DEVMETHOD(device_suspend,	bus_generic_suspend),
352e3e1ac86SEric Anholt 	DEVMETHOD(device_resume,	bus_generic_resume),
353e3e1ac86SEric Anholt 
354e3e1ac86SEric Anholt 	/* AGP interface */
355e3e1ac86SEric Anholt 	DEVMETHOD(agp_get_aperture,	agp_ati_get_aperture),
356e3e1ac86SEric Anholt 	DEVMETHOD(agp_set_aperture,	agp_ati_set_aperture),
357e3e1ac86SEric Anholt 	DEVMETHOD(agp_bind_page,	agp_ati_bind_page),
358e3e1ac86SEric Anholt 	DEVMETHOD(agp_unbind_page,	agp_ati_unbind_page),
359e3e1ac86SEric Anholt 	DEVMETHOD(agp_flush_tlb,	agp_ati_flush_tlb),
360e3e1ac86SEric Anholt 	DEVMETHOD(agp_enable,		agp_generic_enable),
361e3e1ac86SEric Anholt 	DEVMETHOD(agp_alloc_memory,	agp_generic_alloc_memory),
362e3e1ac86SEric Anholt 	DEVMETHOD(agp_free_memory,	agp_generic_free_memory),
363e3e1ac86SEric Anholt 	DEVMETHOD(agp_bind_memory,	agp_generic_bind_memory),
364e3e1ac86SEric Anholt 	DEVMETHOD(agp_unbind_memory,	agp_generic_unbind_memory),
365e3e1ac86SEric Anholt 	{ 0, 0 }
366e3e1ac86SEric Anholt };
367e3e1ac86SEric Anholt 
368e3e1ac86SEric Anholt static driver_t agp_ati_driver = {
369e3e1ac86SEric Anholt 	"agp",
370e3e1ac86SEric Anholt 	agp_ati_methods,
371e3e1ac86SEric Anholt 	sizeof(struct agp_ati_softc),
372e3e1ac86SEric Anholt };
373e3e1ac86SEric Anholt 
37474f84981SJohn Baldwin DRIVER_MODULE(agp_ati, hostb, agp_ati_driver, 0, 0);
375e3e1ac86SEric Anholt MODULE_DEPEND(agp_ati, agp, 1, 1, 1);
376e3e1ac86SEric Anholt MODULE_DEPEND(agp_ati, pci, 1, 1, 1);
377