2 * Copyright (c) 2000 Doug Rabson
3 * Copyright (c) 2000 Ruslan Ermilov
4 * Copyright (c) 2011 The FreeBSD Foundation
7 * Portions of this software were developed by Konstantin Belousov
8 * under sponsorship from the FreeBSD Foundation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Fixes for 830/845G support: David Dawes <dawes@xfree86.org>
34 * 852GM/855GM/865G support added by David Dawes <dawes@xfree86.org>
36 * This is generic Intel GTT handling code, morphed from the AGP
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
44 #define KTR_AGP_I810 KTR_DEV
46 #define KTR_AGP_I810 0
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
52 #include <sys/kernel.h>
54 #include <sys/module.h>
57 #include <sys/mutex.h>
59 #include <sys/rwlock.h>
61 #include <dev/agp/agppriv.h>
62 #include <dev/agp/agpreg.h>
63 #include <dev/agp/agp_i810.h>
64 #include <dev/pci/pcivar.h>
65 #include <dev/pci/pcireg.h>
66 #include <dev/pci/pci_private.h>
69 #include <vm/vm_extern.h>
70 #include <vm/vm_kern.h>
71 #include <vm/vm_param.h>
72 #include <vm/vm_object.h>
73 #include <vm/vm_page.h>
74 #include <vm/vm_pageout.h>
77 #include <machine/bus.h>
78 #include <machine/resource.h>
79 #include <machine/md_var.h>
82 MALLOC_DECLARE(M_AGP);
84 struct agp_i810_match;
86 static int agp_i810_check_active(device_t bridge_dev);
87 static int agp_i830_check_active(device_t bridge_dev);
88 static int agp_i915_check_active(device_t bridge_dev);
90 static void agp_82852_set_desc(device_t dev,
91 const struct agp_i810_match *match);
92 static void agp_i810_set_desc(device_t dev, const struct agp_i810_match *match);
94 static void agp_i810_dump_regs(device_t dev);
95 static void agp_i830_dump_regs(device_t dev);
96 static void agp_i855_dump_regs(device_t dev);
97 static void agp_i915_dump_regs(device_t dev);
98 static void agp_i965_dump_regs(device_t dev);
100 static int agp_i810_get_stolen_size(device_t dev);
101 static int agp_i830_get_stolen_size(device_t dev);
102 static int agp_i915_get_stolen_size(device_t dev);
104 static int agp_i810_get_gtt_mappable_entries(device_t dev);
105 static int agp_i830_get_gtt_mappable_entries(device_t dev);
106 static int agp_i915_get_gtt_mappable_entries(device_t dev);
108 static int agp_i810_get_gtt_total_entries(device_t dev);
109 static int agp_i965_get_gtt_total_entries(device_t dev);
110 static int agp_gen5_get_gtt_total_entries(device_t dev);
112 static int agp_i810_install_gatt(device_t dev);
113 static int agp_i830_install_gatt(device_t dev);
114 static int agp_i965_install_gatt(device_t dev);
115 static int agp_g4x_install_gatt(device_t dev);
117 static void agp_i810_deinstall_gatt(device_t dev);
118 static void agp_i830_deinstall_gatt(device_t dev);
120 static void agp_i810_install_gtt_pte(device_t dev, u_int index,
121 vm_offset_t physical, int flags);
122 static void agp_i830_install_gtt_pte(device_t dev, u_int index,
123 vm_offset_t physical, int flags);
124 static void agp_i915_install_gtt_pte(device_t dev, u_int index,
125 vm_offset_t physical, int flags);
126 static void agp_i965_install_gtt_pte(device_t dev, u_int index,
127 vm_offset_t physical, int flags);
128 static void agp_g4x_install_gtt_pte(device_t dev, u_int index,
129 vm_offset_t physical, int flags);
131 static void agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte);
132 static void agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte);
133 static void agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte);
134 static void agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte);
136 static u_int32_t agp_i810_read_gtt_pte(device_t dev, u_int index);
137 static u_int32_t agp_i915_read_gtt_pte(device_t dev, u_int index);
138 static u_int32_t agp_i965_read_gtt_pte(device_t dev, u_int index);
139 static u_int32_t agp_g4x_read_gtt_pte(device_t dev, u_int index);
141 static vm_paddr_t agp_i810_read_gtt_pte_paddr(device_t dev, u_int index);
142 static vm_paddr_t agp_i915_read_gtt_pte_paddr(device_t dev, u_int index);
144 static int agp_i810_set_aperture(device_t dev, u_int32_t aperture);
145 static int agp_i830_set_aperture(device_t dev, u_int32_t aperture);
146 static int agp_i915_set_aperture(device_t dev, u_int32_t aperture);
148 static int agp_i810_chipset_flush_setup(device_t dev);
149 static int agp_i915_chipset_flush_setup(device_t dev);
150 static int agp_i965_chipset_flush_setup(device_t dev);
152 static void agp_i810_chipset_flush_teardown(device_t dev);
153 static void agp_i915_chipset_flush_teardown(device_t dev);
154 static void agp_i965_chipset_flush_teardown(device_t dev);
156 static void agp_i810_chipset_flush(device_t dev);
157 static void agp_i830_chipset_flush(device_t dev);
158 static void agp_i915_chipset_flush(device_t dev);
161 CHIP_I810, /* i810/i815 */
162 CHIP_I830, /* 830M/845G */
163 CHIP_I855, /* 852GM/855GM/865G */
164 CHIP_I915, /* 915G/915GM */
165 CHIP_I965, /* G965 */
166 CHIP_G33, /* G33/Q33/Q35 */
167 CHIP_IGD, /* Pineview */
168 CHIP_G4X, /* G45/Q45 */
171 /* The i810 through i855 have the registers at BAR 1, and the GATT gets
172 * allocated by us. The i915 has registers in BAR 0 and the GATT is at the
173 * start of the stolen memory, and should only be accessed by the OS through
174 * BAR 3. The G965 has registers and GATT in the same BAR (0) -- first 512KB
175 * is registers, second 512KB is GATT.
177 static struct resource_spec agp_i810_res_spec[] = {
178 { SYS_RES_MEMORY, AGP_I810_MMADR, RF_ACTIVE | RF_SHAREABLE },
182 static struct resource_spec agp_i915_res_spec[] = {
183 { SYS_RES_MEMORY, AGP_I915_MMADR, RF_ACTIVE | RF_SHAREABLE },
184 { SYS_RES_MEMORY, AGP_I915_GTTADR, RF_ACTIVE | RF_SHAREABLE },
188 static struct resource_spec agp_i965_res_spec[] = {
189 { SYS_RES_MEMORY, AGP_I965_GTTMMADR, RF_ACTIVE | RF_SHAREABLE },
190 { SYS_RES_MEMORY, AGP_I965_APBASE, RF_ACTIVE | RF_SHAREABLE },
194 struct agp_i810_softc {
195 struct agp_softc agp;
196 u_int32_t initial_aperture; /* aperture size at startup */
197 struct agp_gatt *gatt;
198 u_int32_t dcache_size; /* i810 only */
199 u_int32_t stolen; /* number of i830/845 gtt
200 entries for stolen memory */
201 u_int stolen_size; /* BIOS-reserved graphics memory */
202 u_int gtt_total_entries; /* Total number of gtt ptes */
203 u_int gtt_mappable_entries; /* Number of gtt ptes mappable by CPU */
204 device_t bdev; /* bridge device */
205 void *argb_cursor; /* contigmalloc area for ARGB cursor */
206 struct resource *sc_res[2];
207 const struct agp_i810_match *match;
208 int sc_flush_page_rid;
209 struct resource *sc_flush_page_res;
210 void *sc_flush_page_vaddr;
211 int sc_bios_allocated_flush_page;
214 static device_t intel_agp;
216 struct agp_i810_driver {
219 int busdma_addr_mask_sz;
220 struct resource_spec *res_spec;
221 int (*check_active)(device_t);
222 void (*set_desc)(device_t, const struct agp_i810_match *);
223 void (*dump_regs)(device_t);
224 int (*get_stolen_size)(device_t);
225 int (*get_gtt_total_entries)(device_t);
226 int (*get_gtt_mappable_entries)(device_t);
227 int (*install_gatt)(device_t);
228 void (*deinstall_gatt)(device_t);
229 void (*write_gtt)(device_t, u_int, uint32_t);
230 void (*install_gtt_pte)(device_t, u_int, vm_offset_t, int);
231 u_int32_t (*read_gtt_pte)(device_t, u_int);
232 vm_paddr_t (*read_gtt_pte_paddr)(device_t , u_int);
233 int (*set_aperture)(device_t, u_int32_t);
234 int (*chipset_flush_setup)(device_t);
235 void (*chipset_flush_teardown)(device_t);
236 void (*chipset_flush)(device_t);
240 struct intel_gtt base;
243 static const struct agp_i810_driver agp_i810_i810_driver = {
244 .chiptype = CHIP_I810,
246 .busdma_addr_mask_sz = 32,
247 .res_spec = agp_i810_res_spec,
248 .check_active = agp_i810_check_active,
249 .set_desc = agp_i810_set_desc,
250 .dump_regs = agp_i810_dump_regs,
251 .get_stolen_size = agp_i810_get_stolen_size,
252 .get_gtt_mappable_entries = agp_i810_get_gtt_mappable_entries,
253 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
254 .install_gatt = agp_i810_install_gatt,
255 .deinstall_gatt = agp_i810_deinstall_gatt,
256 .write_gtt = agp_i810_write_gtt,
257 .install_gtt_pte = agp_i810_install_gtt_pte,
258 .read_gtt_pte = agp_i810_read_gtt_pte,
259 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
260 .set_aperture = agp_i810_set_aperture,
261 .chipset_flush_setup = agp_i810_chipset_flush_setup,
262 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
263 .chipset_flush = agp_i810_chipset_flush,
266 static const struct agp_i810_driver agp_i810_i815_driver = {
267 .chiptype = CHIP_I810,
269 .busdma_addr_mask_sz = 32,
270 .res_spec = agp_i810_res_spec,
271 .check_active = agp_i810_check_active,
272 .set_desc = agp_i810_set_desc,
273 .dump_regs = agp_i810_dump_regs,
274 .get_stolen_size = agp_i810_get_stolen_size,
275 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
276 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
277 .install_gatt = agp_i810_install_gatt,
278 .deinstall_gatt = agp_i810_deinstall_gatt,
279 .write_gtt = agp_i810_write_gtt,
280 .install_gtt_pte = agp_i810_install_gtt_pte,
281 .read_gtt_pte = agp_i810_read_gtt_pte,
282 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
283 .set_aperture = agp_i810_set_aperture,
284 .chipset_flush_setup = agp_i810_chipset_flush_setup,
285 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
286 .chipset_flush = agp_i830_chipset_flush,
289 static const struct agp_i810_driver agp_i810_i830_driver = {
290 .chiptype = CHIP_I830,
292 .busdma_addr_mask_sz = 32,
293 .res_spec = agp_i810_res_spec,
294 .check_active = agp_i830_check_active,
295 .set_desc = agp_i810_set_desc,
296 .dump_regs = agp_i830_dump_regs,
297 .get_stolen_size = agp_i830_get_stolen_size,
298 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
299 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
300 .install_gatt = agp_i830_install_gatt,
301 .deinstall_gatt = agp_i830_deinstall_gatt,
302 .write_gtt = agp_i810_write_gtt,
303 .install_gtt_pte = agp_i830_install_gtt_pte,
304 .read_gtt_pte = agp_i810_read_gtt_pte,
305 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
306 .set_aperture = agp_i830_set_aperture,
307 .chipset_flush_setup = agp_i810_chipset_flush_setup,
308 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
309 .chipset_flush = agp_i830_chipset_flush,
312 static const struct agp_i810_driver agp_i810_i855_driver = {
313 .chiptype = CHIP_I855,
315 .busdma_addr_mask_sz = 32,
316 .res_spec = agp_i810_res_spec,
317 .check_active = agp_i830_check_active,
318 .set_desc = agp_82852_set_desc,
319 .dump_regs = agp_i855_dump_regs,
320 .get_stolen_size = agp_i915_get_stolen_size,
321 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
322 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
323 .install_gatt = agp_i830_install_gatt,
324 .deinstall_gatt = agp_i830_deinstall_gatt,
325 .write_gtt = agp_i810_write_gtt,
326 .install_gtt_pte = agp_i830_install_gtt_pte,
327 .read_gtt_pte = agp_i810_read_gtt_pte,
328 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
329 .set_aperture = agp_i830_set_aperture,
330 .chipset_flush_setup = agp_i810_chipset_flush_setup,
331 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
332 .chipset_flush = agp_i830_chipset_flush,
335 static const struct agp_i810_driver agp_i810_i865_driver = {
336 .chiptype = CHIP_I855,
338 .busdma_addr_mask_sz = 32,
339 .res_spec = agp_i810_res_spec,
340 .check_active = agp_i830_check_active,
341 .set_desc = agp_i810_set_desc,
342 .dump_regs = agp_i855_dump_regs,
343 .get_stolen_size = agp_i915_get_stolen_size,
344 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
345 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
346 .install_gatt = agp_i830_install_gatt,
347 .deinstall_gatt = agp_i830_deinstall_gatt,
348 .write_gtt = agp_i810_write_gtt,
349 .install_gtt_pte = agp_i830_install_gtt_pte,
350 .read_gtt_pte = agp_i810_read_gtt_pte,
351 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
352 .set_aperture = agp_i915_set_aperture,
353 .chipset_flush_setup = agp_i810_chipset_flush_setup,
354 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
355 .chipset_flush = agp_i830_chipset_flush,
358 static const struct agp_i810_driver agp_i810_i915_driver = {
359 .chiptype = CHIP_I915,
361 .busdma_addr_mask_sz = 32,
362 .res_spec = agp_i915_res_spec,
363 .check_active = agp_i915_check_active,
364 .set_desc = agp_i810_set_desc,
365 .dump_regs = agp_i915_dump_regs,
366 .get_stolen_size = agp_i915_get_stolen_size,
367 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
368 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
369 .install_gatt = agp_i830_install_gatt,
370 .deinstall_gatt = agp_i830_deinstall_gatt,
371 .write_gtt = agp_i915_write_gtt,
372 .install_gtt_pte = agp_i915_install_gtt_pte,
373 .read_gtt_pte = agp_i915_read_gtt_pte,
374 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
375 .set_aperture = agp_i915_set_aperture,
376 .chipset_flush_setup = agp_i915_chipset_flush_setup,
377 .chipset_flush_teardown = agp_i915_chipset_flush_teardown,
378 .chipset_flush = agp_i915_chipset_flush,
381 static const struct agp_i810_driver agp_i810_g33_driver = {
382 .chiptype = CHIP_G33,
384 .busdma_addr_mask_sz = 36,
385 .res_spec = agp_i915_res_spec,
386 .check_active = agp_i915_check_active,
387 .set_desc = agp_i810_set_desc,
388 .dump_regs = agp_i965_dump_regs,
389 .get_stolen_size = agp_i915_get_stolen_size,
390 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
391 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
392 .install_gatt = agp_i830_install_gatt,
393 .deinstall_gatt = agp_i830_deinstall_gatt,
394 .write_gtt = agp_i915_write_gtt,
395 .install_gtt_pte = agp_i915_install_gtt_pte,
396 .read_gtt_pte = agp_i915_read_gtt_pte,
397 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
398 .set_aperture = agp_i915_set_aperture,
399 .chipset_flush_setup = agp_i965_chipset_flush_setup,
400 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
401 .chipset_flush = agp_i915_chipset_flush,
404 static const struct agp_i810_driver agp_i810_igd_driver = {
405 .chiptype = CHIP_IGD,
407 .busdma_addr_mask_sz = 36,
408 .res_spec = agp_i915_res_spec,
409 .check_active = agp_i915_check_active,
410 .set_desc = agp_i810_set_desc,
411 .dump_regs = agp_i915_dump_regs,
412 .get_stolen_size = agp_i915_get_stolen_size,
413 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
414 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
415 .install_gatt = agp_i830_install_gatt,
416 .deinstall_gatt = agp_i830_deinstall_gatt,
417 .write_gtt = agp_i915_write_gtt,
418 .install_gtt_pte = agp_i915_install_gtt_pte,
419 .read_gtt_pte = agp_i915_read_gtt_pte,
420 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
421 .set_aperture = agp_i915_set_aperture,
422 .chipset_flush_setup = agp_i965_chipset_flush_setup,
423 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
424 .chipset_flush = agp_i915_chipset_flush,
427 static const struct agp_i810_driver agp_i810_g965_driver = {
428 .chiptype = CHIP_I965,
430 .busdma_addr_mask_sz = 36,
431 .res_spec = agp_i965_res_spec,
432 .check_active = agp_i915_check_active,
433 .set_desc = agp_i810_set_desc,
434 .dump_regs = agp_i965_dump_regs,
435 .get_stolen_size = agp_i915_get_stolen_size,
436 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
437 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
438 .install_gatt = agp_i965_install_gatt,
439 .deinstall_gatt = agp_i830_deinstall_gatt,
440 .write_gtt = agp_i965_write_gtt,
441 .install_gtt_pte = agp_i965_install_gtt_pte,
442 .read_gtt_pte = agp_i965_read_gtt_pte,
443 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
444 .set_aperture = agp_i915_set_aperture,
445 .chipset_flush_setup = agp_i965_chipset_flush_setup,
446 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
447 .chipset_flush = agp_i915_chipset_flush,
450 static const struct agp_i810_driver agp_i810_g4x_driver = {
451 .chiptype = CHIP_G4X,
453 .busdma_addr_mask_sz = 36,
454 .res_spec = agp_i965_res_spec,
455 .check_active = agp_i915_check_active,
456 .set_desc = agp_i810_set_desc,
457 .dump_regs = agp_i965_dump_regs,
458 .get_stolen_size = agp_i915_get_stolen_size,
459 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
460 .get_gtt_total_entries = agp_gen5_get_gtt_total_entries,
461 .install_gatt = agp_g4x_install_gatt,
462 .deinstall_gatt = agp_i830_deinstall_gatt,
463 .write_gtt = agp_g4x_write_gtt,
464 .install_gtt_pte = agp_g4x_install_gtt_pte,
465 .read_gtt_pte = agp_g4x_read_gtt_pte,
466 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
467 .set_aperture = agp_i915_set_aperture,
468 .chipset_flush_setup = agp_i965_chipset_flush_setup,
469 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
470 .chipset_flush = agp_i915_chipset_flush,
473 /* For adding new devices, devid is the id of the graphics controller
474 * (pci:0:2:0, for example). The placeholder (usually at pci:0:2:1) for the
475 * second head should never be added. The bridge_offset is the offset to
476 * subtract from devid to get the id of the hostb that the device is on.
478 static const struct agp_i810_match {
481 const struct agp_i810_driver *driver;
482 } agp_i810_matches[] = {
485 .name = "Intel 82810 (i810 GMCH) SVGA controller",
486 .driver = &agp_i810_i810_driver
490 .name = "Intel 82810-DC100 (i810-DC100 GMCH) SVGA controller",
491 .driver = &agp_i810_i810_driver
495 .name = "Intel 82810E (i810E GMCH) SVGA controller",
496 .driver = &agp_i810_i810_driver
500 .name = "Intel 82815 (i815 GMCH) SVGA controller",
501 .driver = &agp_i810_i815_driver
505 .name = "Intel 82830M (830M GMCH) SVGA controller",
506 .driver = &agp_i810_i830_driver
510 .name = "Intel 82845M (845M GMCH) SVGA controller",
511 .driver = &agp_i810_i830_driver
515 .name = "Intel 82852/855GM SVGA controller",
516 .driver = &agp_i810_i855_driver
520 .name = "Intel 82865G (865G GMCH) SVGA controller",
521 .driver = &agp_i810_i865_driver
525 .name = "Intel 82915G (915G GMCH) SVGA controller",
526 .driver = &agp_i810_i915_driver
530 .name = "Intel E7221 SVGA controller",
531 .driver = &agp_i810_i915_driver
535 .name = "Intel 82915GM (915GM GMCH) SVGA controller",
536 .driver = &agp_i810_i915_driver
540 .name = "Intel 82945G (945G GMCH) SVGA controller",
541 .driver = &agp_i810_i915_driver
545 .name = "Intel 82945GM (945GM GMCH) SVGA controller",
546 .driver = &agp_i810_i915_driver
550 .name = "Intel 945GME SVGA controller",
551 .driver = &agp_i810_i915_driver
555 .name = "Intel 946GZ SVGA controller",
556 .driver = &agp_i810_g965_driver
560 .name = "Intel G965 SVGA controller",
561 .driver = &agp_i810_g965_driver
565 .name = "Intel Q965 SVGA controller",
566 .driver = &agp_i810_g965_driver
570 .name = "Intel G965 SVGA controller",
571 .driver = &agp_i810_g965_driver
575 .name = "Intel Q35 SVGA controller",
576 .driver = &agp_i810_g33_driver
580 .name = "Intel G33 SVGA controller",
581 .driver = &agp_i810_g33_driver
585 .name = "Intel Q33 SVGA controller",
586 .driver = &agp_i810_g33_driver
590 .name = "Intel Pineview SVGA controller",
591 .driver = &agp_i810_igd_driver
595 .name = "Intel Pineview (M) SVGA controller",
596 .driver = &agp_i810_igd_driver
600 .name = "Intel GM965 SVGA controller",
601 .driver = &agp_i810_g965_driver
605 .name = "Intel GME965 SVGA controller",
606 .driver = &agp_i810_g965_driver
610 .name = "Intel GM45 SVGA controller",
611 .driver = &agp_i810_g4x_driver
615 .name = "Intel Eaglelake SVGA controller",
616 .driver = &agp_i810_g4x_driver
620 .name = "Intel Q45 SVGA controller",
621 .driver = &agp_i810_g4x_driver
625 .name = "Intel G45 SVGA controller",
626 .driver = &agp_i810_g4x_driver
630 .name = "Intel G41 SVGA controller",
631 .driver = &agp_i810_g4x_driver
635 .name = "Intel Ironlake (D) SVGA controller",
636 .driver = &agp_i810_g4x_driver
640 .name = "Intel Ironlake (M) SVGA controller",
641 .driver = &agp_i810_g4x_driver
648 static const struct agp_i810_match*
649 agp_i810_match(device_t dev)
653 if (pci_get_class(dev) != PCIC_DISPLAY
654 || (pci_get_subclass(dev) != PCIS_DISPLAY_VGA &&
655 pci_get_subclass(dev) != PCIS_DISPLAY_OTHER))
658 devid = pci_get_devid(dev);
659 for (i = 0; agp_i810_matches[i].devid != 0; i++) {
660 if (agp_i810_matches[i].devid == devid)
663 if (agp_i810_matches[i].devid == 0)
666 return (&agp_i810_matches[i]);
670 * Find bridge device.
673 agp_i810_find_bridge(device_t dev)
676 return (pci_find_dbsf(0, 0, 0, 0));
680 agp_i810_identify(driver_t *driver, device_t parent)
683 if (device_find_child(parent, "agp", -1) == NULL &&
684 agp_i810_match(parent))
685 device_add_child(parent, "agp", -1);
689 agp_i810_check_active(device_t bridge_dev)
693 smram = pci_read_config(bridge_dev, AGP_I810_SMRAM, 1);
694 if ((smram & AGP_I810_SMRAM_GMS) == AGP_I810_SMRAM_GMS_DISABLED)
700 agp_i830_check_active(device_t bridge_dev)
704 gcc1 = pci_read_config(bridge_dev, AGP_I830_GCC1, 1);
705 if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED)
711 agp_i915_check_active(device_t bridge_dev)
715 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
716 if ((deven & AGP_I915_DEVEN_D2F0) == AGP_I915_DEVEN_D2F0_DISABLED)
722 agp_82852_set_desc(device_t dev, const struct agp_i810_match *match)
725 switch (pci_read_config(dev, AGP_I85X_CAPID, 1)) {
728 "Intel 82855GME (855GME GMCH) SVGA controller");
732 "Intel 82855GM (855GM GMCH) SVGA controller");
736 "Intel 82852GME (852GME GMCH) SVGA controller");
740 "Intel 82852GM (852GM GMCH) SVGA controller");
744 "Intel 8285xM (85xGM GMCH) SVGA controller");
750 agp_i810_set_desc(device_t dev, const struct agp_i810_match *match)
753 device_set_desc(dev, match->name);
757 agp_i810_probe(device_t dev)
760 const struct agp_i810_match *match;
763 if (resource_disabled("agp", device_get_unit(dev)))
765 match = agp_i810_match(dev);
769 bdev = agp_i810_find_bridge(dev);
772 printf("I810: can't find bridge device\n");
777 * checking whether internal graphics device has been activated.
779 err = match->driver->check_active(bdev);
782 printf("i810: disabled, not probing\n");
786 match->driver->set_desc(dev, match);
787 return (BUS_PROBE_DEFAULT);
791 agp_i810_dump_regs(device_t dev)
793 struct agp_i810_softc *sc = device_get_softc(dev);
795 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
796 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
797 device_printf(dev, "AGP_I810_MISCC: 0x%04x\n",
798 pci_read_config(sc->bdev, AGP_I810_MISCC, 2));
802 agp_i830_dump_regs(device_t dev)
804 struct agp_i810_softc *sc = device_get_softc(dev);
806 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
807 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
808 device_printf(dev, "AGP_I830_GCC1: 0x%02x\n",
809 pci_read_config(sc->bdev, AGP_I830_GCC1, 1));
813 agp_i855_dump_regs(device_t dev)
815 struct agp_i810_softc *sc = device_get_softc(dev);
817 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
818 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
819 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
820 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
824 agp_i915_dump_regs(device_t dev)
826 struct agp_i810_softc *sc = device_get_softc(dev);
828 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
829 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
830 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
831 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
832 device_printf(dev, "AGP_I915_MSAC: 0x%02x\n",
833 pci_read_config(sc->bdev, AGP_I915_MSAC, 1));
837 agp_i965_dump_regs(device_t dev)
839 struct agp_i810_softc *sc = device_get_softc(dev);
841 device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
842 bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
843 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
844 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
845 device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
846 pci_read_config(sc->bdev, AGP_I965_MSAC, 1));
850 agp_i810_get_stolen_size(device_t dev)
852 struct agp_i810_softc *sc;
854 sc = device_get_softc(dev);
861 agp_i830_get_stolen_size(device_t dev)
863 struct agp_i810_softc *sc;
866 sc = device_get_softc(dev);
868 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1);
869 switch (gcc1 & AGP_I830_GCC1_GMS) {
870 case AGP_I830_GCC1_GMS_STOLEN_512:
871 sc->stolen = (512 - 132) * 1024 / 4096;
872 sc->stolen_size = 512 * 1024;
874 case AGP_I830_GCC1_GMS_STOLEN_1024:
875 sc->stolen = (1024 - 132) * 1024 / 4096;
876 sc->stolen_size = 1024 * 1024;
878 case AGP_I830_GCC1_GMS_STOLEN_8192:
879 sc->stolen = (8192 - 132) * 1024 / 4096;
880 sc->stolen_size = 8192 * 1024;
885 "unknown memory configuration, disabling (GCC1 %x)\n",
893 agp_i915_get_stolen_size(device_t dev)
895 struct agp_i810_softc *sc;
896 unsigned int gcc1, stolen, gtt_size;
898 sc = device_get_softc(dev);
901 * Stolen memory is set up at the beginning of the aperture by
902 * the BIOS, consisting of the GATT followed by 4kb for the
905 switch (sc->match->driver->chiptype) {
913 switch (bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL) &
914 AGP_I810_PGTBL_SIZE_MASK) {
915 case AGP_I810_PGTBL_SIZE_128KB:
918 case AGP_I810_PGTBL_SIZE_256KB:
921 case AGP_I810_PGTBL_SIZE_512KB:
924 case AGP_I965_PGTBL_SIZE_1MB:
927 case AGP_I965_PGTBL_SIZE_2MB:
930 case AGP_I965_PGTBL_SIZE_1_5MB:
931 gtt_size = 1024 + 512;
934 device_printf(dev, "Bad PGTBL size\n");
939 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 2);
940 switch (gcc1 & AGP_G33_MGGC_GGMS_MASK) {
941 case AGP_G33_MGGC_GGMS_SIZE_1M:
944 case AGP_G33_MGGC_GGMS_SIZE_2M:
948 device_printf(dev, "Bad PGTBL size\n");
957 device_printf(dev, "Bad chiptype\n");
961 /* GCC1 is called MGGC on i915+ */
962 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
963 switch (gcc1 & AGP_I855_GCC1_GMS) {
964 case AGP_I855_GCC1_GMS_STOLEN_1M:
967 case AGP_I855_GCC1_GMS_STOLEN_4M:
970 case AGP_I855_GCC1_GMS_STOLEN_8M:
973 case AGP_I855_GCC1_GMS_STOLEN_16M:
976 case AGP_I855_GCC1_GMS_STOLEN_32M:
979 case AGP_I915_GCC1_GMS_STOLEN_48M:
980 stolen = sc->match->driver->gen > 2 ? 48 * 1024 : 0;
982 case AGP_I915_GCC1_GMS_STOLEN_64M:
983 stolen = sc->match->driver->gen > 2 ? 64 * 1024 : 0;
985 case AGP_G33_GCC1_GMS_STOLEN_128M:
986 stolen = sc->match->driver->gen > 2 ? 128 * 1024 : 0;
988 case AGP_G33_GCC1_GMS_STOLEN_256M:
989 stolen = sc->match->driver->gen > 2 ? 256 * 1024 : 0;
991 case AGP_G4X_GCC1_GMS_STOLEN_96M:
992 if (sc->match->driver->chiptype == CHIP_I965 ||
993 sc->match->driver->chiptype == CHIP_G4X)
998 case AGP_G4X_GCC1_GMS_STOLEN_160M:
999 if (sc->match->driver->chiptype == CHIP_I965 ||
1000 sc->match->driver->chiptype == CHIP_G4X)
1001 stolen = 160 * 1024;
1005 case AGP_G4X_GCC1_GMS_STOLEN_224M:
1006 if (sc->match->driver->chiptype == CHIP_I965 ||
1007 sc->match->driver->chiptype == CHIP_G4X)
1008 stolen = 224 * 1024;
1012 case AGP_G4X_GCC1_GMS_STOLEN_352M:
1013 if (sc->match->driver->chiptype == CHIP_I965 ||
1014 sc->match->driver->chiptype == CHIP_G4X)
1015 stolen = 352 * 1024;
1021 "unknown memory configuration, disabling (GCC1 %x)\n",
1027 sc->stolen_size = stolen * 1024;
1028 sc->stolen = (stolen - gtt_size) * 1024 / 4096;
1034 agp_i810_get_gtt_mappable_entries(device_t dev)
1036 struct agp_i810_softc *sc;
1040 sc = device_get_softc(dev);
1041 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1042 if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
1046 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1051 agp_i830_get_gtt_mappable_entries(device_t dev)
1053 struct agp_i810_softc *sc;
1057 sc = device_get_softc(dev);
1058 gmch_ctl = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1059 if ((gmch_ctl & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
1063 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1068 agp_i915_get_gtt_mappable_entries(device_t dev)
1070 struct agp_i810_softc *sc;
1073 sc = device_get_softc(dev);
1074 ap = AGP_GET_APERTURE(dev);
1075 sc->gtt_mappable_entries = ap >> AGP_PAGE_SHIFT;
1080 agp_i810_get_gtt_total_entries(device_t dev)
1082 struct agp_i810_softc *sc;
1084 sc = device_get_softc(dev);
1085 sc->gtt_total_entries = sc->gtt_mappable_entries;
1090 agp_i965_get_gtt_total_entries(device_t dev)
1092 struct agp_i810_softc *sc;
1093 uint32_t pgetbl_ctl;
1096 sc = device_get_softc(dev);
1098 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1099 switch (pgetbl_ctl & AGP_I810_PGTBL_SIZE_MASK) {
1100 case AGP_I810_PGTBL_SIZE_128KB:
1101 sc->gtt_total_entries = 128 * 1024 / 4;
1103 case AGP_I810_PGTBL_SIZE_256KB:
1104 sc->gtt_total_entries = 256 * 1024 / 4;
1106 case AGP_I810_PGTBL_SIZE_512KB:
1107 sc->gtt_total_entries = 512 * 1024 / 4;
1109 /* GTT pagetable sizes bigger than 512KB are not possible on G33! */
1110 case AGP_I810_PGTBL_SIZE_1MB:
1111 sc->gtt_total_entries = 1024 * 1024 / 4;
1113 case AGP_I810_PGTBL_SIZE_2MB:
1114 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1116 case AGP_I810_PGTBL_SIZE_1_5MB:
1117 sc->gtt_total_entries = (1024 + 512) * 1024 / 4;
1120 device_printf(dev, "Unknown page table size\n");
1127 agp_gen5_adjust_pgtbl_size(device_t dev, uint32_t sz)
1129 struct agp_i810_softc *sc;
1130 uint32_t pgetbl_ctl, pgetbl_ctl2;
1132 sc = device_get_softc(dev);
1134 /* Disable per-process page table. */
1135 pgetbl_ctl2 = bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2);
1136 pgetbl_ctl2 &= ~AGP_I810_PGTBL_ENABLED;
1137 bus_write_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2, pgetbl_ctl2);
1139 /* Write the new ggtt size. */
1140 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1141 pgetbl_ctl &= ~AGP_I810_PGTBL_SIZE_MASK;
1143 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgetbl_ctl);
1147 agp_gen5_get_gtt_total_entries(device_t dev)
1149 struct agp_i810_softc *sc;
1152 sc = device_get_softc(dev);
1154 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1155 switch (gcc1 & AGP_G4x_GCC1_SIZE_MASK) {
1156 case AGP_G4x_GCC1_SIZE_1M:
1157 case AGP_G4x_GCC1_SIZE_VT_1M:
1158 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1MB);
1160 case AGP_G4x_GCC1_SIZE_VT_1_5M:
1161 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1_5MB);
1163 case AGP_G4x_GCC1_SIZE_2M:
1164 case AGP_G4x_GCC1_SIZE_VT_2M:
1165 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_2MB);
1168 device_printf(dev, "Unknown page table size\n");
1172 return (agp_i965_get_gtt_total_entries(dev));
1176 agp_i810_install_gatt(device_t dev)
1178 struct agp_i810_softc *sc;
1180 sc = device_get_softc(dev);
1182 /* Some i810s have on-chip memory called dcache. */
1183 if ((bus_read_1(sc->sc_res[0], AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
1185 sc->dcache_size = 4 * 1024 * 1024;
1187 sc->dcache_size = 0;
1189 /* According to the specs the gatt on the i810 must be 64k. */
1190 sc->gatt->ag_virtual = (void *)kmem_alloc_contig(kernel_arena,
1191 64 * 1024, M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE,
1192 0, VM_MEMATTR_WRITE_COMBINING);
1193 if (sc->gatt->ag_virtual == NULL) {
1195 device_printf(dev, "contiguous allocation failed\n");
1199 sc->gatt->ag_physical = vtophys((vm_offset_t)sc->gatt->ag_virtual);
1200 /* Install the GATT. */
1201 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1202 sc->gatt->ag_physical | 1);
1207 agp_i830_install_gatt_init(struct agp_i810_softc *sc)
1212 * The i830 automatically initializes the 128k gatt on boot.
1213 * GATT address is already in there, make sure it's enabled.
1215 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1217 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1219 sc->gatt->ag_physical = pgtblctl & ~1;
1223 agp_i830_install_gatt(device_t dev)
1225 struct agp_i810_softc *sc;
1227 sc = device_get_softc(dev);
1228 agp_i830_install_gatt_init(sc);
1233 agp_gen4_install_gatt(device_t dev, const vm_size_t gtt_offset)
1235 struct agp_i810_softc *sc;
1237 sc = device_get_softc(dev);
1238 pmap_change_attr((vm_offset_t)rman_get_virtual(sc->sc_res[0]) +
1239 gtt_offset, rman_get_size(sc->sc_res[0]) - gtt_offset,
1240 VM_MEMATTR_WRITE_COMBINING);
1241 agp_i830_install_gatt_init(sc);
1246 agp_i965_install_gatt(device_t dev)
1249 return (agp_gen4_install_gatt(dev, 512 * 1024));
1253 agp_g4x_install_gatt(device_t dev)
1256 return (agp_gen4_install_gatt(dev, 2 * 1024 * 1024));
1260 agp_i810_attach(device_t dev)
1262 struct agp_i810_softc *sc;
1265 sc = device_get_softc(dev);
1266 sc->bdev = agp_i810_find_bridge(dev);
1267 if (sc->bdev == NULL)
1270 sc->match = agp_i810_match(dev);
1272 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1273 AGP_APBASE : AGP_I915_GMADR);
1274 error = agp_generic_attach(dev);
1278 if (ptoa((vm_paddr_t)Maxmem) >
1279 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1280 device_printf(dev, "agp_i810 does not support physical "
1281 "memory above %ju.\n", (uintmax_t)(1ULL <<
1282 sc->match->driver->busdma_addr_mask_sz) - 1);
1286 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1287 agp_generic_detach(dev);
1291 sc->initial_aperture = AGP_GET_APERTURE(dev);
1292 sc->gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1293 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1295 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1296 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1297 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1298 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1299 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1300 bus_release_resources(dev, sc->match->driver->res_spec,
1302 free(sc->gatt, M_AGP);
1303 agp_generic_detach(dev);
1308 device_printf(dev, "aperture size is %dM",
1309 sc->initial_aperture / 1024 / 1024);
1311 printf(", detected %dk stolen memory\n", sc->stolen * 4);
1315 sc->match->driver->dump_regs(dev);
1316 device_printf(dev, "Mappable GTT entries: %d\n",
1317 sc->gtt_mappable_entries);
1318 device_printf(dev, "Total GTT entries: %d\n",
1319 sc->gtt_total_entries);
1325 agp_i810_deinstall_gatt(device_t dev)
1327 struct agp_i810_softc *sc;
1329 sc = device_get_softc(dev);
1330 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
1331 kmem_free(kernel_arena, (vm_offset_t)sc->gatt->ag_virtual, 64 * 1024);
1335 agp_i830_deinstall_gatt(device_t dev)
1337 struct agp_i810_softc *sc;
1338 unsigned int pgtblctl;
1340 sc = device_get_softc(dev);
1341 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1343 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1347 agp_i810_detach(device_t dev)
1349 struct agp_i810_softc *sc;
1351 sc = device_get_softc(dev);
1354 /* Clear the GATT base. */
1355 sc->match->driver->deinstall_gatt(dev);
1357 sc->match->driver->chipset_flush_teardown(dev);
1359 /* Put the aperture back the way it started. */
1360 AGP_SET_APERTURE(dev, sc->initial_aperture);
1362 free(sc->gatt, M_AGP);
1363 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1370 agp_i810_resume(device_t dev)
1372 struct agp_i810_softc *sc;
1373 sc = device_get_softc(dev);
1375 AGP_SET_APERTURE(dev, sc->initial_aperture);
1377 /* Install the GATT. */
1378 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1379 sc->gatt->ag_physical | 1);
1381 return (bus_generic_resume(dev));
1385 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1386 * while returning failure on later chipsets when an actual change is
1389 * This whole function is likely bogus, as the kernel would probably need to
1390 * reconfigure the placement of the AGP aperture if a larger size is requested,
1391 * which doesn't happen currently.
1394 agp_i810_set_aperture(device_t dev, u_int32_t aperture)
1396 struct agp_i810_softc *sc;
1399 sc = device_get_softc(dev);
1401 * Double check for sanity.
1403 if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
1404 device_printf(dev, "bad aperture size %d\n", aperture);
1408 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1409 miscc &= ~AGP_I810_MISCC_WINSIZE;
1410 if (aperture == 32 * 1024 * 1024)
1411 miscc |= AGP_I810_MISCC_WINSIZE_32;
1413 miscc |= AGP_I810_MISCC_WINSIZE_64;
1415 pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
1420 agp_i830_set_aperture(device_t dev, u_int32_t aperture)
1422 struct agp_i810_softc *sc;
1425 sc = device_get_softc(dev);
1427 if (aperture != 64 * 1024 * 1024 &&
1428 aperture != 128 * 1024 * 1024) {
1429 device_printf(dev, "bad aperture size %d\n", aperture);
1432 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1433 gcc1 &= ~AGP_I830_GCC1_GMASIZE;
1434 if (aperture == 64 * 1024 * 1024)
1435 gcc1 |= AGP_I830_GCC1_GMASIZE_64;
1437 gcc1 |= AGP_I830_GCC1_GMASIZE_128;
1439 pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
1444 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1447 return (agp_generic_set_aperture(dev, aperture));
1451 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1453 struct agp_i810_softc *sc;
1455 sc = device_get_softc(dev);
1456 return (sc->match->driver->set_aperture(dev, aperture));
1460 * Writes a GTT entry mapping the page at the given offset from the
1461 * beginning of the aperture to the given physical address. Setup the
1462 * caching mode according to flags.
1464 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1465 * from corresponding BAR start. For gen 4, offset is 512KB +
1466 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1468 * Also, the bits of the physical page address above 4GB needs to be
1469 * placed into bits 40-32 of PTE.
1472 agp_i810_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1477 pte = (u_int32_t)physical | I810_PTE_VALID;
1478 if (flags == AGP_DCACHE_MEMORY)
1479 pte |= I810_PTE_LOCAL;
1480 else if (flags == AGP_USER_CACHED_MEMORY)
1481 pte |= I830_PTE_SYSTEM_CACHED;
1482 agp_i810_write_gtt(dev, index, pte);
1486 agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte)
1488 struct agp_i810_softc *sc;
1490 sc = device_get_softc(dev);
1491 bus_write_4(sc->sc_res[0], AGP_I810_GTT + index * 4, pte);
1492 CTR2(KTR_AGP_I810, "810_pte %x %x", index, pte);
1496 agp_i830_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1501 pte = (u_int32_t)physical | I810_PTE_VALID;
1502 if (flags == AGP_USER_CACHED_MEMORY)
1503 pte |= I830_PTE_SYSTEM_CACHED;
1504 agp_i810_write_gtt(dev, index, pte);
1508 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1513 pte = (u_int32_t)physical | I810_PTE_VALID;
1514 if (flags == AGP_USER_CACHED_MEMORY)
1515 pte |= I830_PTE_SYSTEM_CACHED;
1516 pte |= (physical & 0x0000000f00000000ull) >> 28;
1517 agp_i915_write_gtt(dev, index, pte);
1521 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1523 struct agp_i810_softc *sc;
1525 sc = device_get_softc(dev);
1526 bus_write_4(sc->sc_res[1], index * 4, pte);
1527 CTR2(KTR_AGP_I810, "915_pte %x %x", index, pte);
1531 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1536 pte = (u_int32_t)physical | I810_PTE_VALID;
1537 if (flags == AGP_USER_CACHED_MEMORY)
1538 pte |= I830_PTE_SYSTEM_CACHED;
1539 pte |= (physical & 0x0000000f00000000ull) >> 28;
1540 agp_i965_write_gtt(dev, index, pte);
1544 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1546 struct agp_i810_softc *sc;
1548 sc = device_get_softc(dev);
1549 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1550 CTR2(KTR_AGP_I810, "965_pte %x %x", index, pte);
1554 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1559 pte = (u_int32_t)physical | I810_PTE_VALID;
1560 if (flags == AGP_USER_CACHED_MEMORY)
1561 pte |= I830_PTE_SYSTEM_CACHED;
1562 pte |= (physical & 0x0000000f00000000ull) >> 28;
1563 agp_g4x_write_gtt(dev, index, pte);
1567 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1569 struct agp_i810_softc *sc;
1571 sc = device_get_softc(dev);
1572 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1573 CTR2(KTR_AGP_I810, "g4x_pte %x %x", index, pte);
1577 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1579 struct agp_i810_softc *sc = device_get_softc(dev);
1582 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1583 device_printf(dev, "failed: offset is 0x%08jx, "
1584 "shift is %d, entries is %d\n", (intmax_t)offset,
1585 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1588 index = offset >> AGP_PAGE_SHIFT;
1589 if (sc->stolen != 0 && index < sc->stolen) {
1590 device_printf(dev, "trying to bind into stolen memory\n");
1593 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1598 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1600 struct agp_i810_softc *sc;
1603 sc = device_get_softc(dev);
1604 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1606 index = offset >> AGP_PAGE_SHIFT;
1607 if (sc->stolen != 0 && index < sc->stolen) {
1608 device_printf(dev, "trying to unbind from stolen memory\n");
1611 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1616 agp_i810_read_gtt_pte(device_t dev, u_int index)
1618 struct agp_i810_softc *sc;
1621 sc = device_get_softc(dev);
1622 pte = bus_read_4(sc->sc_res[0], AGP_I810_GTT + index * 4);
1627 agp_i915_read_gtt_pte(device_t dev, u_int index)
1629 struct agp_i810_softc *sc;
1632 sc = device_get_softc(dev);
1633 pte = bus_read_4(sc->sc_res[1], index * 4);
1638 agp_i965_read_gtt_pte(device_t dev, u_int index)
1640 struct agp_i810_softc *sc;
1643 sc = device_get_softc(dev);
1644 pte = bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1649 agp_g4x_read_gtt_pte(device_t dev, u_int index)
1651 struct agp_i810_softc *sc;
1654 sc = device_get_softc(dev);
1655 pte = bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1660 agp_i810_read_gtt_pte_paddr(device_t dev, u_int index)
1662 struct agp_i810_softc *sc;
1666 sc = device_get_softc(dev);
1667 pte = sc->match->driver->read_gtt_pte(dev, index);
1668 res = pte & ~PAGE_MASK;
1673 agp_i915_read_gtt_pte_paddr(device_t dev, u_int index)
1675 struct agp_i810_softc *sc;
1679 sc = device_get_softc(dev);
1680 pte = sc->match->driver->read_gtt_pte(dev, index);
1681 res = (pte & ~PAGE_MASK) | ((pte & 0xf0) << 28);
1686 * Writing via memory mapped registers already flushes all TLBs.
1689 agp_i810_flush_tlb(device_t dev)
1694 agp_i810_enable(device_t dev, u_int32_t mode)
1700 static struct agp_memory *
1701 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
1703 struct agp_i810_softc *sc;
1704 struct agp_memory *mem;
1707 sc = device_get_softc(dev);
1709 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
1710 sc->agp.as_allocated + size > sc->agp.as_maxmem)
1715 * Mapping local DRAM into GATT.
1717 if (sc->match->driver->chiptype != CHIP_I810)
1719 if (size != sc->dcache_size)
1721 } else if (type == 2) {
1723 * Type 2 is the contiguous physical memory type, that hands
1724 * back a physical address. This is used for cursors on i810.
1725 * Hand back as many single pages with physical as the user
1726 * wants, but only allow one larger allocation (ARGB cursor)
1729 if (size != AGP_PAGE_SIZE) {
1730 if (sc->argb_cursor != NULL)
1733 /* Allocate memory for ARGB cursor, if we can. */
1734 sc->argb_cursor = contigmalloc(size, M_AGP,
1735 0, 0, ~0, PAGE_SIZE, 0);
1736 if (sc->argb_cursor == NULL)
1741 mem = malloc(sizeof *mem, M_AGP, M_WAITOK);
1742 mem->am_id = sc->agp.as_nextid++;
1743 mem->am_size = size;
1744 mem->am_type = type;
1745 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
1746 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
1747 atop(round_page(size)));
1752 if (size == AGP_PAGE_SIZE) {
1754 * Allocate and wire down the page now so that we can
1755 * get its physical address.
1757 VM_OBJECT_WLOCK(mem->am_obj);
1758 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NOBUSY |
1759 VM_ALLOC_WIRED | VM_ALLOC_ZERO);
1760 VM_OBJECT_WUNLOCK(mem->am_obj);
1761 mem->am_physical = VM_PAGE_TO_PHYS(m);
1763 /* Our allocation is already nicely wired down for us.
1764 * Just grab the physical address.
1766 mem->am_physical = vtophys(sc->argb_cursor);
1769 mem->am_physical = 0;
1772 mem->am_is_bound = 0;
1773 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
1774 sc->agp.as_allocated += size;
1780 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
1782 struct agp_i810_softc *sc;
1785 if (mem->am_is_bound)
1788 sc = device_get_softc(dev);
1790 if (mem->am_type == 2) {
1791 if (mem->am_size == AGP_PAGE_SIZE) {
1793 * Unwire the page which we wired in alloc_memory.
1795 VM_OBJECT_WLOCK(mem->am_obj);
1796 m = vm_page_lookup(mem->am_obj, 0);
1798 vm_page_unwire(m, PQ_INACTIVE);
1800 VM_OBJECT_WUNLOCK(mem->am_obj);
1802 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
1803 sc->argb_cursor = NULL;
1807 sc->agp.as_allocated -= mem->am_size;
1808 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
1810 vm_object_deallocate(mem->am_obj);
1816 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
1818 struct agp_i810_softc *sc;
1821 /* Do some sanity checks first. */
1822 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
1823 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
1824 device_printf(dev, "binding memory at bad offset %#x\n",
1829 sc = device_get_softc(dev);
1830 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1831 mtx_lock(&sc->agp.as_lock);
1832 if (mem->am_is_bound) {
1833 mtx_unlock(&sc->agp.as_lock);
1836 /* The memory's already wired down, just stick it in the GTT. */
1837 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1838 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
1839 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
1841 mem->am_offset = offset;
1842 mem->am_is_bound = 1;
1843 mtx_unlock(&sc->agp.as_lock);
1847 if (mem->am_type != 1)
1848 return (agp_generic_bind_memory(dev, mem, offset));
1851 * Mapping local DRAM into GATT.
1853 if (sc->match->driver->chiptype != CHIP_I810)
1855 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
1856 bus_write_4(sc->sc_res[0],
1857 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
1863 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
1865 struct agp_i810_softc *sc;
1868 sc = device_get_softc(dev);
1870 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1871 mtx_lock(&sc->agp.as_lock);
1872 if (!mem->am_is_bound) {
1873 mtx_unlock(&sc->agp.as_lock);
1877 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1878 sc->match->driver->install_gtt_pte(dev,
1879 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
1881 mem->am_is_bound = 0;
1882 mtx_unlock(&sc->agp.as_lock);
1886 if (mem->am_type != 1)
1887 return (agp_generic_unbind_memory(dev, mem));
1889 if (sc->match->driver->chiptype != CHIP_I810)
1891 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1892 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
1898 static device_method_t agp_i810_methods[] = {
1899 /* Device interface */
1900 DEVMETHOD(device_identify, agp_i810_identify),
1901 DEVMETHOD(device_probe, agp_i810_probe),
1902 DEVMETHOD(device_attach, agp_i810_attach),
1903 DEVMETHOD(device_detach, agp_i810_detach),
1904 DEVMETHOD(device_suspend, bus_generic_suspend),
1905 DEVMETHOD(device_resume, agp_i810_resume),
1908 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
1909 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
1910 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
1911 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
1912 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
1913 DEVMETHOD(agp_enable, agp_i810_enable),
1914 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
1915 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
1916 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
1917 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
1918 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
1923 static driver_t agp_i810_driver = {
1926 sizeof(struct agp_i810_softc),
1929 static devclass_t agp_devclass;
1931 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, 0, 0);
1932 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
1933 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
1935 extern vm_page_t bogus_page;
1938 agp_intel_gtt_clear_range(device_t dev, u_int first_entry, u_int num_entries)
1940 struct agp_i810_softc *sc;
1943 sc = device_get_softc(dev);
1944 for (i = 0; i < num_entries; i++)
1945 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1946 VM_PAGE_TO_PHYS(bogus_page), 0);
1947 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
1951 agp_intel_gtt_insert_pages(device_t dev, u_int first_entry, u_int num_entries,
1952 vm_page_t *pages, u_int flags)
1954 struct agp_i810_softc *sc;
1957 sc = device_get_softc(dev);
1958 for (i = 0; i < num_entries; i++) {
1959 MPASS(pages[i]->valid == VM_PAGE_BITS_ALL);
1960 MPASS(pages[i]->wire_count > 0);
1961 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1962 VM_PAGE_TO_PHYS(pages[i]), flags);
1964 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
1968 agp_intel_gtt_get(device_t dev)
1970 struct agp_i810_softc *sc;
1971 struct intel_gtt res;
1973 sc = device_get_softc(dev);
1974 res.stolen_size = sc->stolen_size;
1975 res.gtt_total_entries = sc->gtt_total_entries;
1976 res.gtt_mappable_entries = sc->gtt_mappable_entries;
1977 res.do_idle_maps = 0;
1978 res.scratch_page_dma = VM_PAGE_TO_PHYS(bogus_page);
1979 if (sc->agp.as_aperture != NULL)
1980 res.gma_bus_addr = rman_get_start(sc->agp.as_aperture);
1982 res.gma_bus_addr = 0;
1987 agp_i810_chipset_flush_setup(device_t dev)
1994 agp_i810_chipset_flush_teardown(device_t dev)
1997 /* Nothing to do. */
2001 agp_i810_chipset_flush(device_t dev)
2004 /* Nothing to do. */
2008 agp_i830_chipset_flush(device_t dev)
2010 struct agp_i810_softc *sc;
2014 sc = device_get_softc(dev);
2015 pmap_invalidate_cache();
2016 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2017 bus_write_4(sc->sc_res[0], AGP_I830_HIC, hic | (1U << 31));
2018 for (i = 0; i < 20000 /* 1 sec */; i++) {
2019 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2020 if ((hic & (1U << 31)) == 0)
2027 agp_i915_chipset_flush_alloc_page(device_t dev, uint64_t start, uint64_t end)
2029 struct agp_i810_softc *sc;
2032 sc = device_get_softc(dev);
2033 vga = device_get_parent(dev);
2034 sc->sc_flush_page_rid = 100;
2035 sc->sc_flush_page_res = BUS_ALLOC_RESOURCE(device_get_parent(vga), dev,
2036 SYS_RES_MEMORY, &sc->sc_flush_page_rid, start, end, PAGE_SIZE,
2038 if (sc->sc_flush_page_res == NULL) {
2039 device_printf(dev, "Failed to allocate flush page at 0x%jx\n",
2043 sc->sc_flush_page_vaddr = rman_get_virtual(sc->sc_flush_page_res);
2045 device_printf(dev, "Allocated flush page phys 0x%jx virt %p\n",
2046 (uintmax_t)rman_get_start(sc->sc_flush_page_res),
2047 sc->sc_flush_page_vaddr);
2053 agp_i915_chipset_flush_free_page(device_t dev)
2055 struct agp_i810_softc *sc;
2058 sc = device_get_softc(dev);
2059 vga = device_get_parent(dev);
2060 if (sc->sc_flush_page_res == NULL)
2062 BUS_DEACTIVATE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2063 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2064 BUS_RELEASE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2065 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2069 agp_i915_chipset_flush_setup(device_t dev)
2071 struct agp_i810_softc *sc;
2075 sc = device_get_softc(dev);
2076 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2077 if ((temp & 1) != 0) {
2081 "Found already configured flush page at 0x%jx\n",
2083 sc->sc_bios_allocated_flush_page = 1;
2085 * In the case BIOS initialized the flush pointer (?)
2086 * register, expect that BIOS also set up the resource
2089 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2090 temp + PAGE_SIZE - 1);
2094 sc->sc_bios_allocated_flush_page = 0;
2095 error = agp_i915_chipset_flush_alloc_page(dev, 0, 0xffffffff);
2098 temp = rman_get_start(sc->sc_flush_page_res);
2099 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp | 1, 4);
2105 agp_i915_chipset_flush_teardown(device_t dev)
2107 struct agp_i810_softc *sc;
2110 sc = device_get_softc(dev);
2111 if (sc->sc_flush_page_res == NULL)
2113 if (!sc->sc_bios_allocated_flush_page) {
2114 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2116 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp, 4);
2118 agp_i915_chipset_flush_free_page(dev);
2122 agp_i965_chipset_flush_setup(device_t dev)
2124 struct agp_i810_softc *sc;
2126 uint32_t temp_hi, temp_lo;
2129 sc = device_get_softc(dev);
2131 temp_hi = pci_read_config(sc->bdev, AGP_I965_IFPADDR + 4, 4);
2132 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2134 if ((temp_lo & 1) != 0) {
2135 temp = ((uint64_t)temp_hi << 32) | (temp_lo & ~1);
2138 "Found already configured flush page at 0x%jx\n",
2140 sc->sc_bios_allocated_flush_page = 1;
2142 * In the case BIOS initialized the flush pointer (?)
2143 * register, expect that BIOS also set up the resource
2146 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2147 temp + PAGE_SIZE - 1);
2151 sc->sc_bios_allocated_flush_page = 0;
2152 error = agp_i915_chipset_flush_alloc_page(dev, 0, ~0);
2155 temp = rman_get_start(sc->sc_flush_page_res);
2156 pci_write_config(sc->bdev, AGP_I965_IFPADDR + 4,
2157 (temp >> 32) & UINT32_MAX, 4);
2158 pci_write_config(sc->bdev, AGP_I965_IFPADDR,
2159 (temp & UINT32_MAX) | 1, 4);
2165 agp_i965_chipset_flush_teardown(device_t dev)
2167 struct agp_i810_softc *sc;
2170 sc = device_get_softc(dev);
2171 if (sc->sc_flush_page_res == NULL)
2173 if (!sc->sc_bios_allocated_flush_page) {
2174 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2176 pci_write_config(sc->bdev, AGP_I965_IFPADDR, temp_lo, 4);
2178 agp_i915_chipset_flush_free_page(dev);
2182 agp_i915_chipset_flush(device_t dev)
2184 struct agp_i810_softc *sc;
2186 sc = device_get_softc(dev);
2187 *(uint32_t *)sc->sc_flush_page_vaddr = 1;
2191 agp_intel_gtt_chipset_flush(device_t dev)
2193 struct agp_i810_softc *sc;
2195 sc = device_get_softc(dev);
2196 sc->match->driver->chipset_flush(dev);
2201 agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list)
2206 agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
2207 struct sglist **sg_list)
2209 struct agp_i810_softc *sc;
2217 if (*sg_list != NULL)
2219 sc = device_get_softc(dev);
2220 sg = sglist_alloc(num_entries, M_WAITOK /* XXXKIB */);
2221 for (i = 0; i < num_entries; i++) {
2222 sg->sg_segs[i].ss_paddr = VM_PAGE_TO_PHYS(pages[i]);
2223 sg->sg_segs[i].ss_len = PAGE_SIZE;
2227 error = bus_dma_tag_create(bus_get_dma_tag(dev),
2228 1 /* alignment */, 0 /* boundary */,
2229 1ULL << sc->match->busdma_addr_mask_sz /* lowaddr */,
2230 BUS_SPACE_MAXADDR /* highaddr */,
2231 NULL /* filtfunc */, NULL /* filtfuncarg */,
2232 BUS_SPACE_MAXADDR /* maxsize */,
2233 BUS_SPACE_UNRESTRICTED /* nsegments */,
2234 BUS_SPACE_MAXADDR /* maxsegsz */,
2235 0 /* flags */, NULL /* lockfunc */, NULL /* lockfuncarg */,
2248 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2249 u_int first_entry, u_int flags)
2251 struct agp_i810_softc *sc;
2256 sc = device_get_softc(dev);
2257 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2258 spaddr = sg_list->sg_segs[i].ss_paddr;
2259 slen = sg_list->sg_segs[i].ss_len;
2260 for (; slen > 0; i++) {
2261 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2263 spaddr += AGP_PAGE_SIZE;
2264 slen -= AGP_PAGE_SIZE;
2267 sc->match->driver->read_gtt_pte(dev, first_entry + i - 1);
2271 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2274 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2278 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2282 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2290 intel_private.base = agp_intel_gtt_get(intel_agp);
2291 return (&intel_private.base);
2295 intel_gtt_chipset_flush(void)
2298 return (agp_intel_gtt_chipset_flush(intel_agp));
2302 intel_gtt_unmap_memory(struct sglist *sg_list)
2305 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2309 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2310 struct sglist **sg_list)
2313 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2318 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2322 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2326 intel_gtt_get_bridge_device(void)
2328 struct agp_i810_softc *sc;
2330 sc = device_get_softc(intel_agp);
2335 intel_gtt_read_pte_paddr(u_int entry)
2337 struct agp_i810_softc *sc;
2339 sc = device_get_softc(intel_agp);
2340 return (sc->match->driver->read_gtt_pte_paddr(intel_agp, entry));
2344 intel_gtt_read_pte(u_int entry)
2346 struct agp_i810_softc *sc;
2348 sc = device_get_softc(intel_agp);
2349 return (sc->match->driver->read_gtt_pte(intel_agp, entry));
2353 intel_gtt_write(u_int entry, uint32_t val)
2355 struct agp_i810_softc *sc;
2357 sc = device_get_softc(intel_agp);
2358 return (sc->match->driver->write_gtt(intel_agp, entry, val));