agp_i810.c revision 1.56 1 1.56 tnn /* $NetBSD: agp_i810.c,v 1.56 2008/08/22 18:05:44 tnn Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*-
4 1.1 fvdl * Copyright (c) 2000 Doug Rabson
5 1.1 fvdl * Copyright (c) 2000 Ruslan Ermilov
6 1.1 fvdl * All rights reserved.
7 1.1 fvdl *
8 1.1 fvdl * Redistribution and use in source and binary forms, with or without
9 1.1 fvdl * modification, are permitted provided that the following conditions
10 1.1 fvdl * are met:
11 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
12 1.1 fvdl * notice, this list of conditions and the following disclaimer.
13 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
15 1.1 fvdl * documentation and/or other materials provided with the distribution.
16 1.1 fvdl *
17 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 1.1 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 1.1 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 fvdl * SUCH DAMAGE.
28 1.1 fvdl *
29 1.1 fvdl * $FreeBSD: src/sys/pci/agp_i810.c,v 1.4 2001/07/05 21:28:47 jhb Exp $
30 1.1 fvdl */
31 1.9 lukem
32 1.9 lukem #include <sys/cdefs.h>
33 1.56 tnn __KERNEL_RCSID(0, "$NetBSD: agp_i810.c,v 1.56 2008/08/22 18:05:44 tnn Exp $");
34 1.1 fvdl
35 1.1 fvdl #include <sys/param.h>
36 1.1 fvdl #include <sys/systm.h>
37 1.1 fvdl #include <sys/malloc.h>
38 1.1 fvdl #include <sys/kernel.h>
39 1.1 fvdl #include <sys/proc.h>
40 1.1 fvdl #include <sys/device.h>
41 1.1 fvdl #include <sys/conf.h>
42 1.1 fvdl
43 1.1 fvdl #include <uvm/uvm_extern.h>
44 1.1 fvdl
45 1.1 fvdl #include <dev/pci/pcivar.h>
46 1.1 fvdl #include <dev/pci/pcireg.h>
47 1.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.1 fvdl
51 1.1 fvdl #include <sys/agpio.h>
52 1.1 fvdl
53 1.43 ad #include <sys/bus.h>
54 1.1 fvdl
55 1.20 tron #include "agp_intel.h"
56 1.20 tron
57 1.1 fvdl #define READ1(off) bus_space_read_1(isc->bst, isc->bsh, off)
58 1.14 scw #define READ4(off) bus_space_read_4(isc->bst, isc->bsh, off)
59 1.1 fvdl #define WRITE4(off,v) bus_space_write_4(isc->bst, isc->bsh, off, v)
60 1.28 christos #define WRITEGTT(off, v) \
61 1.28 christos do { \
62 1.45 joerg if (isc->chiptype == CHIP_I915 || isc->chiptype == CHIP_G33) { \
63 1.28 christos bus_space_write_4(isc->gtt_bst, isc->gtt_bsh, \
64 1.28 christos (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, \
65 1.28 christos (v)); \
66 1.42 markd } else if (isc->chiptype == CHIP_I965) { \
67 1.42 markd WRITE4(AGP_I965_GTT + \
68 1.42 markd (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, \
69 1.42 markd (v)); \
70 1.28 christos } else { \
71 1.28 christos WRITE4(AGP_I810_GTT + \
72 1.28 christos (u_int32_t)((off) >> AGP_PAGE_SHIFT) * 4, \
73 1.28 christos (v)); \
74 1.28 christos } \
75 1.28 christos } while (0)
76 1.1 fvdl
77 1.14 scw #define CHIP_I810 0 /* i810/i815 */
78 1.17 hannken #define CHIP_I830 1 /* 830M/845G */
79 1.17 hannken #define CHIP_I855 2 /* 852GM/855GM/865G */
80 1.56 tnn #define CHIP_I915 3 /* 915G/915GM/945G/945GM/945GME */
81 1.45 joerg #define CHIP_I965 4 /* 965Q/965PM */
82 1.45 joerg #define CHIP_G33 5 /* G33/Q33/Q35 */
83 1.14 scw
84 1.1 fvdl struct agp_i810_softc {
85 1.1 fvdl u_int32_t initial_aperture; /* aperture size at startup */
86 1.1 fvdl struct agp_gatt *gatt;
87 1.14 scw int chiptype; /* i810-like or i830 */
88 1.14 scw u_int32_t dcache_size; /* i810 only */
89 1.14 scw u_int32_t stolen; /* number of i830/845 gtt entries
90 1.14 scw for stolen memory */
91 1.28 christos bus_space_tag_t bst; /* register bus_space tag */
92 1.28 christos bus_space_handle_t bsh; /* register bus_space handle */
93 1.28 christos bus_space_tag_t gtt_bst; /* GTT bus_space tag */
94 1.28 christos bus_space_handle_t gtt_bsh; /* GTT bus_space handle */
95 1.1 fvdl struct pci_attach_args vga_pa;
96 1.24 jmcneill
97 1.47 jmcneill u_int32_t pgtblctl;
98 1.1 fvdl };
99 1.1 fvdl
100 1.49 drochner /* XXX hack, see below */
101 1.50 drochner static bus_addr_t agp_i810_vga_regbase;
102 1.50 drochner static bus_space_handle_t agp_i810_vga_bsh;
103 1.49 drochner
104 1.1 fvdl static u_int32_t agp_i810_get_aperture(struct agp_softc *);
105 1.1 fvdl static int agp_i810_set_aperture(struct agp_softc *, u_int32_t);
106 1.1 fvdl static int agp_i810_bind_page(struct agp_softc *, off_t, bus_addr_t);
107 1.1 fvdl static int agp_i810_unbind_page(struct agp_softc *, off_t);
108 1.1 fvdl static void agp_i810_flush_tlb(struct agp_softc *);
109 1.1 fvdl static int agp_i810_enable(struct agp_softc *, u_int32_t mode);
110 1.1 fvdl static struct agp_memory *agp_i810_alloc_memory(struct agp_softc *, int,
111 1.1 fvdl vsize_t);
112 1.1 fvdl static int agp_i810_free_memory(struct agp_softc *, struct agp_memory *);
113 1.1 fvdl static int agp_i810_bind_memory(struct agp_softc *, struct agp_memory *, off_t);
114 1.1 fvdl static int agp_i810_unbind_memory(struct agp_softc *, struct agp_memory *);
115 1.47 jmcneill
116 1.51 dyoung static bool agp_i810_resume(device_t PMF_FN_PROTO);
117 1.47 jmcneill static int agp_i810_init(struct agp_softc *);
118 1.1 fvdl
119 1.45 joerg static int agp_i810_init(struct agp_softc *);
120 1.45 joerg
121 1.26 thorpej static struct agp_methods agp_i810_methods = {
122 1.1 fvdl agp_i810_get_aperture,
123 1.1 fvdl agp_i810_set_aperture,
124 1.1 fvdl agp_i810_bind_page,
125 1.1 fvdl agp_i810_unbind_page,
126 1.1 fvdl agp_i810_flush_tlb,
127 1.1 fvdl agp_i810_enable,
128 1.1 fvdl agp_i810_alloc_memory,
129 1.1 fvdl agp_i810_free_memory,
130 1.1 fvdl agp_i810_bind_memory,
131 1.1 fvdl agp_i810_unbind_memory,
132 1.1 fvdl };
133 1.1 fvdl
134 1.55 matthias /* XXXthorpej -- duplicated code (see arch/x86/pci/pchb.c) */
135 1.1 fvdl static int
136 1.1 fvdl agp_i810_vgamatch(struct pci_attach_args *pa)
137 1.1 fvdl {
138 1.6 thorpej
139 1.2 fvdl if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
140 1.2 fvdl PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
141 1.6 thorpej return (0);
142 1.6 thorpej
143 1.1 fvdl switch (PCI_PRODUCT(pa->pa_id)) {
144 1.1 fvdl case PCI_PRODUCT_INTEL_82810_GC:
145 1.1 fvdl case PCI_PRODUCT_INTEL_82810_DC100_GC:
146 1.1 fvdl case PCI_PRODUCT_INTEL_82810E_GC:
147 1.1 fvdl case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
148 1.14 scw case PCI_PRODUCT_INTEL_82830MP_IV:
149 1.14 scw case PCI_PRODUCT_INTEL_82845G_IGD:
150 1.17 hannken case PCI_PRODUCT_INTEL_82855GM_IGD:
151 1.18 tron case PCI_PRODUCT_INTEL_82865_IGD:
152 1.28 christos case PCI_PRODUCT_INTEL_82915G_IGD:
153 1.28 christos case PCI_PRODUCT_INTEL_82915GM_IGD:
154 1.32 simonb case PCI_PRODUCT_INTEL_82945P_IGD:
155 1.32 simonb case PCI_PRODUCT_INTEL_82945GM_IGD:
156 1.32 simonb case PCI_PRODUCT_INTEL_82945GM_IGD_1:
157 1.56 tnn case PCI_PRODUCT_INTEL_82945GME_IGD:
158 1.42 markd case PCI_PRODUCT_INTEL_82965Q_IGD:
159 1.42 markd case PCI_PRODUCT_INTEL_82965Q_IGD_1:
160 1.45 joerg case PCI_PRODUCT_INTEL_82965PM_IGD:
161 1.45 joerg case PCI_PRODUCT_INTEL_82965PM_IGD_1:
162 1.45 joerg case PCI_PRODUCT_INTEL_82G33_IGD:
163 1.45 joerg case PCI_PRODUCT_INTEL_82G33_IGD_1:
164 1.44 jnemeth case PCI_PRODUCT_INTEL_82965G_IGD:
165 1.44 jnemeth case PCI_PRODUCT_INTEL_82965G_IGD_1:
166 1.46 markd case PCI_PRODUCT_INTEL_82Q35_IGD:
167 1.46 markd case PCI_PRODUCT_INTEL_82Q35_IGD_1:
168 1.46 markd case PCI_PRODUCT_INTEL_82Q33_IGD:
169 1.46 markd case PCI_PRODUCT_INTEL_82Q33_IGD_1:
170 1.55 matthias case PCI_PRODUCT_INTEL_82946GZ_IGD:
171 1.6 thorpej return (1);
172 1.1 fvdl }
173 1.1 fvdl
174 1.6 thorpej return (0);
175 1.1 fvdl }
176 1.1 fvdl
177 1.42 markd static int
178 1.42 markd agp_i965_map_aperture(struct pci_attach_args *pa, struct agp_softc *sc, int reg)
179 1.42 markd {
180 1.42 markd /*
181 1.42 markd * Find the aperture. Don't map it (yet), this would
182 1.42 markd * eat KVA.
183 1.42 markd */
184 1.42 markd if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, reg,
185 1.42 markd PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_64BIT, &sc->as_apaddr, &sc->as_apsize,
186 1.42 markd &sc->as_apflags) != 0)
187 1.42 markd return ENXIO;
188 1.42 markd
189 1.42 markd sc->as_apt = pa->pa_memt;
190 1.42 markd
191 1.42 markd return 0;
192 1.42 markd }
193 1.42 markd
194 1.1 fvdl int
195 1.54 freza agp_i810_attach(device_t parent, device_t self, void *aux)
196 1.1 fvdl {
197 1.54 freza struct agp_softc *sc = device_private(self);
198 1.1 fvdl struct agp_i810_softc *isc;
199 1.1 fvdl struct agp_gatt *gatt;
200 1.28 christos int error, apbase;
201 1.49 drochner bus_addr_t mmadr;
202 1.37 drochner bus_size_t mmadrsize;
203 1.1 fvdl
204 1.10 tsutsui isc = malloc(sizeof *isc, M_AGP, M_NOWAIT|M_ZERO);
205 1.1 fvdl if (isc == NULL) {
206 1.15 thorpej aprint_error(": can't allocate chipset-specific softc\n");
207 1.1 fvdl return ENOMEM;
208 1.1 fvdl }
209 1.1 fvdl sc->as_chipc = isc;
210 1.1 fvdl sc->as_methods = &agp_i810_methods;
211 1.1 fvdl
212 1.1 fvdl if (pci_find_device(&isc->vga_pa, agp_i810_vgamatch) == 0) {
213 1.20 tron #if NAGP_INTEL > 0
214 1.19 tron const struct pci_attach_args *pa = aux;
215 1.19 tron
216 1.19 tron switch (PCI_PRODUCT(pa->pa_id)) {
217 1.19 tron case PCI_PRODUCT_INTEL_82840_HB:
218 1.19 tron case PCI_PRODUCT_INTEL_82865_HB:
219 1.21 tron case PCI_PRODUCT_INTEL_82845G_DRAM:
220 1.23 xtraeme case PCI_PRODUCT_INTEL_82815_FULL_HUB:
221 1.19 tron return agp_intel_attach(parent, self, aux);
222 1.20 tron }
223 1.20 tron #endif
224 1.15 thorpej aprint_error(": can't find internal VGA device config space\n");
225 1.1 fvdl free(isc, M_AGP);
226 1.1 fvdl return ENOENT;
227 1.1 fvdl }
228 1.1 fvdl
229 1.1 fvdl /* XXXfvdl */
230 1.1 fvdl sc->as_dmat = isc->vga_pa.pa_dmat;
231 1.1 fvdl
232 1.14 scw switch (PCI_PRODUCT(isc->vga_pa.pa_id)) {
233 1.14 scw case PCI_PRODUCT_INTEL_82810_GC:
234 1.14 scw case PCI_PRODUCT_INTEL_82810_DC100_GC:
235 1.14 scw case PCI_PRODUCT_INTEL_82810E_GC:
236 1.14 scw case PCI_PRODUCT_INTEL_82815_FULL_GRAPH:
237 1.14 scw isc->chiptype = CHIP_I810;
238 1.14 scw break;
239 1.14 scw case PCI_PRODUCT_INTEL_82830MP_IV:
240 1.14 scw case PCI_PRODUCT_INTEL_82845G_IGD:
241 1.14 scw isc->chiptype = CHIP_I830;
242 1.14 scw break;
243 1.17 hannken case PCI_PRODUCT_INTEL_82855GM_IGD:
244 1.18 tron case PCI_PRODUCT_INTEL_82865_IGD:
245 1.17 hannken isc->chiptype = CHIP_I855;
246 1.17 hannken break;
247 1.28 christos case PCI_PRODUCT_INTEL_82915G_IGD:
248 1.28 christos case PCI_PRODUCT_INTEL_82915GM_IGD:
249 1.32 simonb case PCI_PRODUCT_INTEL_82945P_IGD:
250 1.32 simonb case PCI_PRODUCT_INTEL_82945GM_IGD:
251 1.32 simonb case PCI_PRODUCT_INTEL_82945GM_IGD_1:
252 1.56 tnn case PCI_PRODUCT_INTEL_82945GME_IGD:
253 1.28 christos isc->chiptype = CHIP_I915;
254 1.28 christos break;
255 1.42 markd case PCI_PRODUCT_INTEL_82965Q_IGD:
256 1.42 markd case PCI_PRODUCT_INTEL_82965Q_IGD_1:
257 1.45 joerg case PCI_PRODUCT_INTEL_82965PM_IGD:
258 1.45 joerg case PCI_PRODUCT_INTEL_82965PM_IGD_1:
259 1.44 jnemeth case PCI_PRODUCT_INTEL_82965G_IGD:
260 1.44 jnemeth case PCI_PRODUCT_INTEL_82965G_IGD_1:
261 1.55 matthias case PCI_PRODUCT_INTEL_82946GZ_IGD:
262 1.42 markd isc->chiptype = CHIP_I965;
263 1.42 markd break;
264 1.46 markd case PCI_PRODUCT_INTEL_82Q35_IGD:
265 1.46 markd case PCI_PRODUCT_INTEL_82Q35_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.46 markd case PCI_PRODUCT_INTEL_82Q33_IGD:
269 1.46 markd case PCI_PRODUCT_INTEL_82Q33_IGD_1:
270 1.45 joerg isc->chiptype = CHIP_G33;
271 1.45 joerg break;
272 1.14 scw }
273 1.14 scw
274 1.45 joerg switch (isc->chiptype) {
275 1.45 joerg case CHIP_I915:
276 1.45 joerg case CHIP_G33:
277 1.45 joerg apbase = AGP_I915_GMADR;
278 1.45 joerg break;
279 1.45 joerg default:
280 1.45 joerg apbase = AGP_I810_GMADR;
281 1.45 joerg break;
282 1.45 joerg }
283 1.42 markd if (isc->chiptype == CHIP_I965) {
284 1.42 markd error = agp_i965_map_aperture(&isc->vga_pa, sc, AGP_I965_GMADR);
285 1.42 markd } else {
286 1.42 markd error = agp_map_aperture(&isc->vga_pa, sc, apbase);
287 1.42 markd }
288 1.1 fvdl if (error != 0) {
289 1.28 christos aprint_error(": can't map aperture\n");
290 1.28 christos free(isc, M_AGP);
291 1.1 fvdl return error;
292 1.1 fvdl }
293 1.1 fvdl
294 1.45 joerg if (isc->chiptype == CHIP_I915 || isc->chiptype == CHIP_G33) {
295 1.28 christos error = pci_mapreg_map(&isc->vga_pa, AGP_I915_MMADR,
296 1.39 drochner PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh,
297 1.49 drochner &mmadr, &mmadrsize);
298 1.28 christos if (error != 0) {
299 1.28 christos aprint_error(": can't map mmadr registers\n");
300 1.28 christos agp_generic_detach(sc);
301 1.28 christos return error;
302 1.28 christos }
303 1.28 christos error = pci_mapreg_map(&isc->vga_pa, AGP_I915_GTTADR,
304 1.28 christos PCI_MAPREG_TYPE_MEM, 0, &isc->gtt_bst, &isc->gtt_bsh,
305 1.28 christos NULL, NULL);
306 1.28 christos if (error != 0) {
307 1.28 christos aprint_error(": can't map gttadr registers\n");
308 1.28 christos /* XXX we should release mmadr here */
309 1.28 christos agp_generic_detach(sc);
310 1.28 christos return error;
311 1.28 christos }
312 1.42 markd } else if (isc->chiptype == CHIP_I965) {
313 1.42 markd error = pci_mapreg_map(&isc->vga_pa, AGP_I965_MMADR,
314 1.42 markd PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh,
315 1.49 drochner &mmadr, &mmadrsize);
316 1.42 markd if (error != 0) {
317 1.42 markd aprint_error(": can't map mmadr registers\n");
318 1.42 markd agp_generic_detach(sc);
319 1.42 markd return error;
320 1.42 markd }
321 1.28 christos } else {
322 1.28 christos error = pci_mapreg_map(&isc->vga_pa, AGP_I810_MMADR,
323 1.39 drochner PCI_MAPREG_TYPE_MEM, 0, &isc->bst, &isc->bsh,
324 1.49 drochner &mmadr, &mmadrsize);
325 1.28 christos if (error != 0) {
326 1.28 christos aprint_error(": can't map mmadr registers\n");
327 1.28 christos agp_generic_detach(sc);
328 1.28 christos return error;
329 1.28 christos }
330 1.28 christos }
331 1.28 christos
332 1.1 fvdl isc->initial_aperture = AGP_GET_APERTURE(sc);
333 1.1 fvdl
334 1.14 scw gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_NOWAIT);
335 1.14 scw if (!gatt) {
336 1.14 scw agp_generic_detach(sc);
337 1.14 scw return ENOMEM;
338 1.14 scw }
339 1.14 scw isc->gatt = gatt;
340 1.14 scw
341 1.14 scw gatt->ag_entries = AGP_GET_APERTURE(sc) >> AGP_PAGE_SHIFT;
342 1.1 fvdl
343 1.47 jmcneill if (!pmf_device_register(self, NULL, agp_i810_resume))
344 1.47 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
345 1.47 jmcneill
346 1.49 drochner /*
347 1.49 drochner * XXX horrible hack to allow drm code to use our mapping
348 1.49 drochner * of VGA chip registers
349 1.49 drochner */
350 1.49 drochner agp_i810_vga_regbase = mmadr;
351 1.49 drochner agp_i810_vga_bsh = isc->bsh;
352 1.49 drochner
353 1.45 joerg return agp_i810_init(sc);
354 1.45 joerg }
355 1.45 joerg
356 1.49 drochner /*
357 1.49 drochner * XXX horrible hack to allow drm code to use our mapping
358 1.49 drochner * of VGA chip registers
359 1.49 drochner */
360 1.49 drochner int
361 1.49 drochner agp_i810_borrow(bus_addr_t base, bus_space_handle_t *hdlp)
362 1.49 drochner {
363 1.49 drochner
364 1.49 drochner if (!agp_i810_vga_regbase || base != agp_i810_vga_regbase)
365 1.49 drochner return 0;
366 1.49 drochner *hdlp = agp_i810_vga_bsh;
367 1.49 drochner return 1;
368 1.49 drochner }
369 1.49 drochner
370 1.45 joerg static int agp_i810_init(struct agp_softc *sc)
371 1.45 joerg {
372 1.45 joerg struct agp_i810_softc *isc;
373 1.45 joerg struct agp_gatt *gatt;
374 1.45 joerg
375 1.45 joerg isc = sc->as_chipc;
376 1.45 joerg gatt = isc->gatt;
377 1.45 joerg
378 1.14 scw if (isc->chiptype == CHIP_I810) {
379 1.36 christos void *virtual;
380 1.14 scw int dummyseg;
381 1.31 tron
382 1.14 scw /* Some i810s have on-chip memory called dcache */
383 1.14 scw if (READ1(AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
384 1.14 scw isc->dcache_size = 4 * 1024 * 1024;
385 1.14 scw else
386 1.14 scw isc->dcache_size = 0;
387 1.14 scw
388 1.14 scw /* According to the specs the gatt on the i810 must be 64k */
389 1.14 scw if (agp_alloc_dmamem(sc->as_dmat, 64 * 1024,
390 1.31 tron 0, &gatt->ag_dmamap, &virtual, &gatt->ag_physical,
391 1.31 tron &gatt->ag_dmaseg, 1, &dummyseg) != 0) {
392 1.14 scw free(gatt, M_AGP);
393 1.1 fvdl agp_generic_detach(sc);
394 1.1 fvdl return ENOMEM;
395 1.1 fvdl }
396 1.31 tron gatt->ag_virtual = (uint32_t *)virtual;
397 1.14 scw gatt->ag_size = gatt->ag_entries * sizeof(u_int32_t);
398 1.14 scw memset(gatt->ag_virtual, 0, gatt->ag_size);
399 1.25 perry
400 1.14 scw agp_flush_cache();
401 1.14 scw /* Install the GATT. */
402 1.14 scw WRITE4(AGP_I810_PGTBL_CTL, gatt->ag_physical | 1);
403 1.17 hannken } else if (isc->chiptype == CHIP_I830) {
404 1.14 scw /* The i830 automatically initializes the 128k gatt on boot. */
405 1.14 scw pcireg_t reg;
406 1.14 scw u_int32_t pgtblctl;
407 1.14 scw u_int16_t gcc1;
408 1.14 scw
409 1.14 scw reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
410 1.14 scw gcc1 = (u_int16_t)(reg >> 16);
411 1.14 scw switch (gcc1 & AGP_I830_GCC1_GMS) {
412 1.14 scw case AGP_I830_GCC1_GMS_STOLEN_512:
413 1.14 scw isc->stolen = (512 - 132) * 1024 / 4096;
414 1.14 scw break;
415 1.25 perry case AGP_I830_GCC1_GMS_STOLEN_1024:
416 1.14 scw isc->stolen = (1024 - 132) * 1024 / 4096;
417 1.14 scw break;
418 1.25 perry case AGP_I830_GCC1_GMS_STOLEN_8192:
419 1.14 scw isc->stolen = (8192 - 132) * 1024 / 4096;
420 1.14 scw break;
421 1.14 scw default:
422 1.14 scw isc->stolen = 0;
423 1.15 thorpej aprint_error(
424 1.15 thorpej ": unknown memory configuration, disabling\n");
425 1.14 scw agp_generic_detach(sc);
426 1.14 scw return EINVAL;
427 1.14 scw }
428 1.45 joerg
429 1.14 scw if (isc->stolen > 0) {
430 1.53 jmcneill aprint_normal(": detected %dk stolen memory\n%s",
431 1.54 freza isc->stolen * 4, device_xname(sc->as_dev));
432 1.14 scw }
433 1.17 hannken
434 1.17 hannken /* GATT address is already in there, make sure it's enabled */
435 1.17 hannken pgtblctl = READ4(AGP_I810_PGTBL_CTL);
436 1.17 hannken pgtblctl |= 1;
437 1.17 hannken WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
438 1.17 hannken
439 1.17 hannken gatt->ag_physical = pgtblctl & ~1;
440 1.42 markd } else if (isc->chiptype == CHIP_I855 || isc->chiptype == CHIP_I915 ||
441 1.45 joerg isc->chiptype == CHIP_I965 || isc->chiptype == CHIP_G33) {
442 1.17 hannken pcireg_t reg;
443 1.42 markd u_int32_t pgtblctl, stolen;
444 1.17 hannken u_int16_t gcc1;
445 1.17 hannken
446 1.45 joerg reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I855_GCC1);
447 1.45 joerg gcc1 = (u_int16_t)(reg >> 16);
448 1.45 joerg
449 1.42 markd /* Stolen memory is set up at the beginning of the aperture by
450 1.42 markd * the BIOS, consisting of the GATT followed by 4kb for the
451 1.42 markd * BIOS display.
452 1.42 markd */
453 1.42 markd switch (isc->chiptype) {
454 1.42 markd case CHIP_I855:
455 1.42 markd stolen = 128 + 4;
456 1.42 markd break;
457 1.42 markd case CHIP_I915:
458 1.42 markd stolen = 256 + 4;
459 1.42 markd break;
460 1.42 markd case CHIP_I965:
461 1.42 markd stolen = 512 + 4;
462 1.42 markd break;
463 1.45 joerg case CHIP_G33:
464 1.45 joerg switch (gcc1 & AGP_G33_PGTBL_SIZE_MASK) {
465 1.45 joerg case AGP_G33_PGTBL_SIZE_1M:
466 1.45 joerg stolen = 1024 + 4;
467 1.45 joerg break;
468 1.45 joerg case AGP_G33_PGTBL_SIZE_2M:
469 1.45 joerg stolen = 2048 + 4;
470 1.45 joerg break;
471 1.45 joerg default:
472 1.45 joerg aprint_error(": bad gtt size\n");
473 1.45 joerg agp_generic_detach(sc);
474 1.45 joerg return EINVAL;
475 1.45 joerg }
476 1.45 joerg break;
477 1.42 markd default:
478 1.42 markd aprint_error(": bad chiptype\n");
479 1.42 markd agp_generic_detach(sc);
480 1.42 markd return EINVAL;
481 1.42 markd }
482 1.42 markd
483 1.17 hannken switch (gcc1 & AGP_I855_GCC1_GMS) {
484 1.17 hannken case AGP_I855_GCC1_GMS_STOLEN_1M:
485 1.42 markd isc->stolen = (1024 - stolen) * 1024 / 4096;
486 1.17 hannken break;
487 1.17 hannken case AGP_I855_GCC1_GMS_STOLEN_4M:
488 1.42 markd isc->stolen = (4096 - stolen) * 1024 / 4096;
489 1.17 hannken break;
490 1.17 hannken case AGP_I855_GCC1_GMS_STOLEN_8M:
491 1.42 markd isc->stolen = (8192 - stolen) * 1024 / 4096;
492 1.17 hannken break;
493 1.17 hannken case AGP_I855_GCC1_GMS_STOLEN_16M:
494 1.42 markd isc->stolen = (16384 - stolen) * 1024 / 4096;
495 1.17 hannken break;
496 1.17 hannken case AGP_I855_GCC1_GMS_STOLEN_32M:
497 1.42 markd isc->stolen = (32768 - stolen) * 1024 / 4096;
498 1.41 sborrill break;
499 1.41 sborrill case AGP_I915_GCC1_GMS_STOLEN_48M:
500 1.42 markd isc->stolen = (49152 - stolen) * 1024 / 4096;
501 1.41 sborrill break;
502 1.41 sborrill case AGP_I915_GCC1_GMS_STOLEN_64M:
503 1.42 markd isc->stolen = (65536 - stolen) * 1024 / 4096;
504 1.41 sborrill break;
505 1.46 markd case AGP_G33_GCC1_GMS_STOLEN_128M:
506 1.46 markd isc->stolen = ((128 * 1024) - stolen) * 1024 / 4096;
507 1.46 markd break;
508 1.46 markd case AGP_G33_GCC1_GMS_STOLEN_256M:
509 1.46 markd isc->stolen = ((256 * 1024) - stolen) * 1024 / 4096;
510 1.46 markd break;
511 1.28 christos default:
512 1.28 christos isc->stolen = 0;
513 1.28 christos aprint_error(
514 1.28 christos ": unknown memory configuration, disabling\n");
515 1.28 christos agp_generic_detach(sc);
516 1.28 christos return EINVAL;
517 1.28 christos }
518 1.28 christos if (isc->stolen > 0) {
519 1.53 jmcneill aprint_normal(": detected %dk stolen memory\n%s",
520 1.54 freza isc->stolen * 4, device_xname(sc->as_dev));
521 1.28 christos }
522 1.28 christos
523 1.28 christos /* GATT address is already in there, make sure it's enabled */
524 1.28 christos pgtblctl = READ4(AGP_I810_PGTBL_CTL);
525 1.28 christos pgtblctl |= 1;
526 1.28 christos WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
527 1.28 christos
528 1.28 christos gatt->ag_physical = pgtblctl & ~1;
529 1.1 fvdl }
530 1.1 fvdl
531 1.1 fvdl /*
532 1.1 fvdl * Make sure the chipset can see everything.
533 1.1 fvdl */
534 1.1 fvdl agp_flush_cache();
535 1.14 scw
536 1.1 fvdl return 0;
537 1.1 fvdl }
538 1.1 fvdl
539 1.1 fvdl #if 0
540 1.1 fvdl static int
541 1.1 fvdl agp_i810_detach(struct agp_softc *sc)
542 1.1 fvdl {
543 1.1 fvdl int error;
544 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
545 1.1 fvdl
546 1.1 fvdl error = agp_generic_detach(sc);
547 1.1 fvdl if (error)
548 1.1 fvdl return error;
549 1.1 fvdl
550 1.1 fvdl /* Clear the GATT base. */
551 1.14 scw if (sc->chiptype == CHIP_I810) {
552 1.14 scw WRITE4(AGP_I810_PGTBL_CTL, 0);
553 1.14 scw } else {
554 1.14 scw unsigned int pgtblctl;
555 1.14 scw pgtblctl = READ4(AGP_I810_PGTBL_CTL);
556 1.14 scw pgtblctl &= ~1;
557 1.14 scw WRITE4(AGP_I810_PGTBL_CTL, pgtblctl);
558 1.14 scw }
559 1.1 fvdl
560 1.1 fvdl /* Put the aperture back the way it started. */
561 1.1 fvdl AGP_SET_APERTURE(sc, isc->initial_aperture);
562 1.1 fvdl
563 1.14 scw if (sc->chiptype == CHIP_I810) {
564 1.14 scw agp_free_dmamem(sc->as_dmat, gatt->ag_size, gatt->ag_dmamap,
565 1.36 christos (void *)gatt->ag_virtual, &gatt->ag_dmaseg, 1);
566 1.14 scw }
567 1.14 scw free(sc->gatt, M_AGP);
568 1.1 fvdl
569 1.1 fvdl return 0;
570 1.1 fvdl }
571 1.1 fvdl #endif
572 1.1 fvdl
573 1.1 fvdl static u_int32_t
574 1.1 fvdl agp_i810_get_aperture(struct agp_softc *sc)
575 1.1 fvdl {
576 1.14 scw struct agp_i810_softc *isc = sc->as_chipc;
577 1.14 scw pcireg_t reg;
578 1.42 markd u_int16_t miscc, gcc1, msac;
579 1.14 scw
580 1.42 markd switch (isc->chiptype) {
581 1.42 markd case CHIP_I810:
582 1.14 scw reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
583 1.14 scw miscc = (u_int16_t)(reg >> 16);
584 1.14 scw if ((miscc & AGP_I810_MISCC_WINSIZE) ==
585 1.14 scw AGP_I810_MISCC_WINSIZE_32)
586 1.14 scw return 32 * 1024 * 1024;
587 1.14 scw else
588 1.14 scw return 64 * 1024 * 1024;
589 1.42 markd case CHIP_I830:
590 1.14 scw reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
591 1.14 scw gcc1 = (u_int16_t)(reg >> 16);
592 1.14 scw if ((gcc1 & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
593 1.14 scw return 64 * 1024 * 1024;
594 1.14 scw else
595 1.14 scw return 128 * 1024 * 1024;
596 1.42 markd case CHIP_I855:
597 1.17 hannken return 128 * 1024 * 1024;
598 1.42 markd case CHIP_I915:
599 1.45 joerg case CHIP_G33:
600 1.28 christos reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I915_MSAC);
601 1.28 christos msac = (u_int16_t)(reg >> 16);
602 1.28 christos if (msac & AGP_I915_MSAC_APER_128M)
603 1.28 christos return 128 * 1024 * 1024;
604 1.28 christos else
605 1.28 christos return 256 * 1024 * 1024;
606 1.42 markd case CHIP_I965:
607 1.42 markd return 512 * 1024 * 1024;
608 1.42 markd default:
609 1.42 markd aprint_error(": Unknown chipset\n");
610 1.14 scw }
611 1.42 markd
612 1.42 markd return 0;
613 1.1 fvdl }
614 1.1 fvdl
615 1.1 fvdl static int
616 1.1 fvdl agp_i810_set_aperture(struct agp_softc *sc, u_int32_t aperture)
617 1.1 fvdl {
618 1.14 scw struct agp_i810_softc *isc = sc->as_chipc;
619 1.14 scw pcireg_t reg;
620 1.42 markd u_int16_t miscc, gcc1;
621 1.14 scw
622 1.42 markd switch (isc->chiptype) {
623 1.42 markd case CHIP_I810:
624 1.14 scw /*
625 1.14 scw * Double check for sanity.
626 1.14 scw */
627 1.14 scw if (aperture != (32 * 1024 * 1024) &&
628 1.14 scw aperture != (64 * 1024 * 1024)) {
629 1.54 freza aprint_error_dev(sc->as_dev, "bad aperture size %d\n",
630 1.52 cegger aperture);
631 1.14 scw return EINVAL;
632 1.14 scw }
633 1.1 fvdl
634 1.14 scw reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I810_SMRAM);
635 1.14 scw miscc = (u_int16_t)(reg >> 16);
636 1.14 scw miscc &= ~AGP_I810_MISCC_WINSIZE;
637 1.14 scw if (aperture == 32 * 1024 * 1024)
638 1.14 scw miscc |= AGP_I810_MISCC_WINSIZE_32;
639 1.14 scw else
640 1.14 scw miscc |= AGP_I810_MISCC_WINSIZE_64;
641 1.14 scw
642 1.14 scw reg &= 0x0000ffff;
643 1.14 scw reg |= ((pcireg_t)miscc) << 16;
644 1.14 scw pci_conf_write(sc->as_pc, sc->as_tag, AGP_I810_SMRAM, reg);
645 1.42 markd break;
646 1.42 markd case CHIP_I830:
647 1.14 scw if (aperture != (64 * 1024 * 1024) &&
648 1.14 scw aperture != (128 * 1024 * 1024)) {
649 1.54 freza aprint_error_dev(sc->as_dev, "bad aperture size %d\n",
650 1.52 cegger aperture);
651 1.14 scw return EINVAL;
652 1.14 scw }
653 1.14 scw reg = pci_conf_read(sc->as_pc, sc->as_tag, AGP_I830_GCC0);
654 1.14 scw gcc1 = (u_int16_t)(reg >> 16);
655 1.14 scw gcc1 &= ~AGP_I830_GCC1_GMASIZE;
656 1.14 scw if (aperture == 64 * 1024 * 1024)
657 1.14 scw gcc1 |= AGP_I830_GCC1_GMASIZE_64;
658 1.14 scw else
659 1.14 scw gcc1 |= AGP_I830_GCC1_GMASIZE_128;
660 1.14 scw
661 1.14 scw reg &= 0x0000ffff;
662 1.14 scw reg |= ((pcireg_t)gcc1) << 16;
663 1.14 scw pci_conf_write(sc->as_pc, sc->as_tag, AGP_I830_GCC0, reg);
664 1.42 markd break;
665 1.42 markd case CHIP_I855:
666 1.42 markd case CHIP_I915:
667 1.28 christos if (aperture != agp_i810_get_aperture(sc)) {
668 1.54 freza aprint_error_dev(sc->as_dev, "bad aperture size %d\n",
669 1.52 cegger aperture);
670 1.17 hannken return EINVAL;
671 1.17 hannken }
672 1.42 markd break;
673 1.42 markd case CHIP_I965:
674 1.42 markd if (aperture != 512 * 1024 * 1024) {
675 1.54 freza aprint_error_dev(sc->as_dev, "bad aperture size %d\n",
676 1.52 cegger aperture);
677 1.42 markd return EINVAL;
678 1.42 markd }
679 1.42 markd break;
680 1.1 fvdl }
681 1.1 fvdl
682 1.1 fvdl return 0;
683 1.1 fvdl }
684 1.1 fvdl
685 1.1 fvdl static int
686 1.1 fvdl agp_i810_bind_page(struct agp_softc *sc, off_t offset, bus_addr_t physical)
687 1.1 fvdl {
688 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
689 1.1 fvdl
690 1.14 scw if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
691 1.29 rpaulo #ifdef AGP_DEBUG
692 1.14 scw printf("%s: failed: offset 0x%08x, shift %d, entries %d\n",
693 1.54 freza device_xname(sc->as_dev), (int)offset, AGP_PAGE_SHIFT,
694 1.14 scw isc->gatt->ag_entries);
695 1.14 scw #endif
696 1.1 fvdl return EINVAL;
697 1.14 scw }
698 1.14 scw
699 1.17 hannken if (isc->chiptype != CHIP_I830) {
700 1.14 scw if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
701 1.29 rpaulo #ifdef AGP_DEBUG
702 1.14 scw printf("%s: trying to bind into stolen memory",
703 1.54 freza device_xname(sc->as_dev));
704 1.14 scw #endif
705 1.14 scw return EINVAL;
706 1.14 scw }
707 1.14 scw }
708 1.1 fvdl
709 1.28 christos WRITEGTT(offset, physical | 1);
710 1.1 fvdl return 0;
711 1.1 fvdl }
712 1.1 fvdl
713 1.1 fvdl static int
714 1.1 fvdl agp_i810_unbind_page(struct agp_softc *sc, off_t offset)
715 1.1 fvdl {
716 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
717 1.1 fvdl
718 1.1 fvdl if (offset < 0 || offset >= (isc->gatt->ag_entries << AGP_PAGE_SHIFT))
719 1.1 fvdl return EINVAL;
720 1.1 fvdl
721 1.17 hannken if (isc->chiptype != CHIP_I810 ) {
722 1.14 scw if ((offset >> AGP_PAGE_SHIFT) < isc->stolen) {
723 1.29 rpaulo #ifdef AGP_DEBUG
724 1.14 scw printf("%s: trying to unbind from stolen memory",
725 1.54 freza device_xname(sc->as_dev));
726 1.14 scw #endif
727 1.14 scw return EINVAL;
728 1.14 scw }
729 1.14 scw }
730 1.14 scw
731 1.28 christos WRITEGTT(offset, 0);
732 1.1 fvdl return 0;
733 1.1 fvdl }
734 1.1 fvdl
735 1.1 fvdl /*
736 1.1 fvdl * Writing via memory mapped registers already flushes all TLBs.
737 1.1 fvdl */
738 1.1 fvdl static void
739 1.35 christos agp_i810_flush_tlb(struct agp_softc *sc)
740 1.1 fvdl {
741 1.1 fvdl }
742 1.1 fvdl
743 1.1 fvdl static int
744 1.35 christos agp_i810_enable(struct agp_softc *sc, u_int32_t mode)
745 1.1 fvdl {
746 1.1 fvdl
747 1.1 fvdl return 0;
748 1.1 fvdl }
749 1.1 fvdl
750 1.1 fvdl static struct agp_memory *
751 1.1 fvdl agp_i810_alloc_memory(struct agp_softc *sc, int type, vsize_t size)
752 1.1 fvdl {
753 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
754 1.1 fvdl struct agp_memory *mem;
755 1.1 fvdl
756 1.29 rpaulo #ifdef AGP_DEBUG
757 1.28 christos printf("AGP: alloc(%d, 0x%x)\n", type, (int) size);
758 1.28 christos #endif
759 1.28 christos
760 1.1 fvdl if ((size & (AGP_PAGE_SIZE - 1)) != 0)
761 1.1 fvdl return 0;
762 1.1 fvdl
763 1.1 fvdl if (sc->as_allocated + size > sc->as_maxmem)
764 1.1 fvdl return 0;
765 1.1 fvdl
766 1.1 fvdl if (type == 1) {
767 1.1 fvdl /*
768 1.1 fvdl * Mapping local DRAM into GATT.
769 1.1 fvdl */
770 1.17 hannken if (isc->chiptype != CHIP_I810 )
771 1.14 scw return 0;
772 1.1 fvdl if (size != isc->dcache_size)
773 1.1 fvdl return 0;
774 1.1 fvdl } else if (type == 2) {
775 1.1 fvdl /*
776 1.28 christos * Bogus mapping for the hardware cursor.
777 1.1 fvdl */
778 1.28 christos if (size != AGP_PAGE_SIZE && size != 4 * AGP_PAGE_SIZE)
779 1.1 fvdl return 0;
780 1.1 fvdl }
781 1.1 fvdl
782 1.10 tsutsui mem = malloc(sizeof *mem, M_AGP, M_WAITOK|M_ZERO);
783 1.1 fvdl if (mem == NULL)
784 1.1 fvdl return NULL;
785 1.1 fvdl mem->am_id = sc->as_nextid++;
786 1.1 fvdl mem->am_size = size;
787 1.1 fvdl mem->am_type = type;
788 1.1 fvdl
789 1.1 fvdl if (type == 2) {
790 1.1 fvdl /*
791 1.28 christos * Allocate and wire down the memory now so that we can
792 1.1 fvdl * get its physical address.
793 1.1 fvdl */
794 1.1 fvdl mem->am_dmaseg = malloc(sizeof *mem->am_dmaseg, M_AGP,
795 1.1 fvdl M_WAITOK);
796 1.1 fvdl if (mem->am_dmaseg == NULL) {
797 1.1 fvdl free(mem, M_AGP);
798 1.1 fvdl return NULL;
799 1.1 fvdl }
800 1.1 fvdl if (agp_alloc_dmamem(sc->as_dmat, size, 0,
801 1.1 fvdl &mem->am_dmamap, &mem->am_virtual, &mem->am_physical,
802 1.1 fvdl mem->am_dmaseg, 1, &mem->am_nseg) != 0) {
803 1.1 fvdl free(mem->am_dmaseg, M_AGP);
804 1.1 fvdl free(mem, M_AGP);
805 1.1 fvdl return NULL;
806 1.1 fvdl }
807 1.28 christos memset(mem->am_virtual, 0, size);
808 1.1 fvdl } else if (type != 1) {
809 1.4 drochner if (bus_dmamap_create(sc->as_dmat, size, size / PAGE_SIZE + 1,
810 1.4 drochner size, 0, BUS_DMA_NOWAIT,
811 1.4 drochner &mem->am_dmamap) != 0) {
812 1.1 fvdl free(mem, M_AGP);
813 1.1 fvdl return NULL;
814 1.1 fvdl }
815 1.1 fvdl }
816 1.1 fvdl
817 1.1 fvdl TAILQ_INSERT_TAIL(&sc->as_memory, mem, am_link);
818 1.1 fvdl sc->as_allocated += size;
819 1.1 fvdl
820 1.1 fvdl return mem;
821 1.1 fvdl }
822 1.1 fvdl
823 1.1 fvdl static int
824 1.1 fvdl agp_i810_free_memory(struct agp_softc *sc, struct agp_memory *mem)
825 1.1 fvdl {
826 1.1 fvdl if (mem->am_is_bound)
827 1.1 fvdl return EBUSY;
828 1.1 fvdl
829 1.1 fvdl if (mem->am_type == 2) {
830 1.1 fvdl agp_free_dmamem(sc->as_dmat, mem->am_size, mem->am_dmamap,
831 1.1 fvdl mem->am_virtual, mem->am_dmaseg, mem->am_nseg);
832 1.1 fvdl free(mem->am_dmaseg, M_AGP);
833 1.1 fvdl }
834 1.1 fvdl
835 1.1 fvdl sc->as_allocated -= mem->am_size;
836 1.1 fvdl TAILQ_REMOVE(&sc->as_memory, mem, am_link);
837 1.1 fvdl free(mem, M_AGP);
838 1.1 fvdl return 0;
839 1.1 fvdl }
840 1.1 fvdl
841 1.1 fvdl static int
842 1.1 fvdl agp_i810_bind_memory(struct agp_softc *sc, struct agp_memory *mem,
843 1.1 fvdl off_t offset)
844 1.1 fvdl {
845 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
846 1.4 drochner u_int32_t regval, i;
847 1.4 drochner
848 1.4 drochner /*
849 1.4 drochner * XXX evil hack: the PGTBL_CTL appearently gets overwritten by the
850 1.4 drochner * X server for mysterious reasons which leads to crashes if we write
851 1.4 drochner * to the GTT through the MMIO window.
852 1.4 drochner * Until the issue is solved, simply restore it.
853 1.4 drochner */
854 1.4 drochner regval = bus_space_read_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL);
855 1.4 drochner if (regval != (isc->gatt->ag_physical | 1)) {
856 1.4 drochner printf("agp_i810_bind_memory: PGTBL_CTL is 0x%x - fixing\n",
857 1.4 drochner regval);
858 1.4 drochner bus_space_write_4(isc->bst, isc->bsh, AGP_I810_PGTBL_CTL,
859 1.4 drochner isc->gatt->ag_physical | 1);
860 1.4 drochner }
861 1.1 fvdl
862 1.5 drochner if (mem->am_type == 2) {
863 1.28 christos WRITEGTT(offset, mem->am_physical | 1);
864 1.5 drochner mem->am_offset = offset;
865 1.5 drochner mem->am_is_bound = 1;
866 1.1 fvdl return 0;
867 1.5 drochner }
868 1.5 drochner
869 1.1 fvdl if (mem->am_type != 1)
870 1.1 fvdl return agp_generic_bind_memory(sc, mem, offset);
871 1.1 fvdl
872 1.17 hannken if (isc->chiptype != CHIP_I810)
873 1.14 scw return EINVAL;
874 1.14 scw
875 1.28 christos for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
876 1.28 christos WRITEGTT(offset, i | 3);
877 1.13 drochner mem->am_is_bound = 1;
878 1.1 fvdl return 0;
879 1.1 fvdl }
880 1.1 fvdl
881 1.1 fvdl static int
882 1.1 fvdl agp_i810_unbind_memory(struct agp_softc *sc, struct agp_memory *mem)
883 1.1 fvdl {
884 1.1 fvdl struct agp_i810_softc *isc = sc->as_chipc;
885 1.1 fvdl u_int32_t i;
886 1.1 fvdl
887 1.5 drochner if (mem->am_type == 2) {
888 1.28 christos WRITEGTT(mem->am_offset, 0);
889 1.5 drochner mem->am_offset = 0;
890 1.5 drochner mem->am_is_bound = 0;
891 1.1 fvdl return 0;
892 1.5 drochner }
893 1.1 fvdl
894 1.1 fvdl if (mem->am_type != 1)
895 1.1 fvdl return agp_generic_unbind_memory(sc, mem);
896 1.14 scw
897 1.17 hannken if (isc->chiptype != CHIP_I810)
898 1.14 scw return EINVAL;
899 1.1 fvdl
900 1.1 fvdl for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
901 1.28 christos WRITEGTT(i, 0);
902 1.13 drochner mem->am_is_bound = 0;
903 1.1 fvdl return 0;
904 1.1 fvdl }
905 1.24 jmcneill
906 1.47 jmcneill static bool
907 1.51 dyoung agp_i810_resume(device_t dv PMF_FN_ARGS)
908 1.24 jmcneill {
909 1.47 jmcneill struct agp_softc *sc = device_private(dv);
910 1.24 jmcneill struct agp_i810_softc *isc = sc->as_chipc;
911 1.24 jmcneill
912 1.47 jmcneill isc->pgtblctl = READ4(AGP_I810_PGTBL_CTL);
913 1.47 jmcneill agp_flush_cache();
914 1.24 jmcneill
915 1.47 jmcneill return true;
916 1.24 jmcneill }
917