2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2000 Doug Rabson
5 * Copyright (c) 2000 Ruslan Ermilov
6 * Copyright (c) 2011 The FreeBSD Foundation
9 * Portions of this software were developed by Konstantin Belousov
10 * under sponsorship from the FreeBSD Foundation.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Fixes for 830/845G support: David Dawes <dawes@xfree86.org>
36 * 852GM/855GM/865G support added by David Dawes <dawes@xfree86.org>
38 * This is generic Intel GTT handling code, morphed from the AGP
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
46 #define KTR_AGP_I810 KTR_DEV
48 #define KTR_AGP_I810 0
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/malloc.h>
54 #include <sys/kernel.h>
56 #include <sys/module.h>
59 #include <sys/mutex.h>
61 #include <sys/rwlock.h>
63 #include <dev/agp/agppriv.h>
64 #include <dev/agp/agpreg.h>
65 #include <dev/agp/agp_i810.h>
66 #include <dev/pci/pcivar.h>
67 #include <dev/pci/pcireg.h>
68 #include <dev/pci/pci_private.h>
71 #include <vm/vm_extern.h>
72 #include <vm/vm_kern.h>
73 #include <vm/vm_param.h>
74 #include <vm/vm_object.h>
75 #include <vm/vm_page.h>
76 #include <vm/vm_pageout.h>
79 #include <machine/bus.h>
80 #include <machine/resource.h>
81 #include <machine/md_var.h>
84 MALLOC_DECLARE(M_AGP);
86 struct agp_i810_match;
88 static int agp_i810_check_active(device_t bridge_dev);
89 static int agp_i830_check_active(device_t bridge_dev);
90 static int agp_i915_check_active(device_t bridge_dev);
92 static void agp_82852_set_desc(device_t dev,
93 const struct agp_i810_match *match);
94 static void agp_i810_set_desc(device_t dev, const struct agp_i810_match *match);
96 static void agp_i810_dump_regs(device_t dev);
97 static void agp_i830_dump_regs(device_t dev);
98 static void agp_i855_dump_regs(device_t dev);
99 static void agp_i915_dump_regs(device_t dev);
100 static void agp_i965_dump_regs(device_t dev);
102 static int agp_i810_get_stolen_size(device_t dev);
103 static int agp_i830_get_stolen_size(device_t dev);
104 static int agp_i915_get_stolen_size(device_t dev);
106 static int agp_i810_get_gtt_mappable_entries(device_t dev);
107 static int agp_i830_get_gtt_mappable_entries(device_t dev);
108 static int agp_i915_get_gtt_mappable_entries(device_t dev);
110 static int agp_i810_get_gtt_total_entries(device_t dev);
111 static int agp_i965_get_gtt_total_entries(device_t dev);
112 static int agp_gen5_get_gtt_total_entries(device_t dev);
114 static int agp_i810_install_gatt(device_t dev);
115 static int agp_i830_install_gatt(device_t dev);
116 static int agp_i965_install_gatt(device_t dev);
117 static int agp_g4x_install_gatt(device_t dev);
119 static void agp_i810_deinstall_gatt(device_t dev);
120 static void agp_i830_deinstall_gatt(device_t dev);
122 static void agp_i810_install_gtt_pte(device_t dev, u_int index,
123 vm_offset_t physical, int flags);
124 static void agp_i830_install_gtt_pte(device_t dev, u_int index,
125 vm_offset_t physical, int flags);
126 static void agp_i915_install_gtt_pte(device_t dev, u_int index,
127 vm_offset_t physical, int flags);
128 static void agp_i965_install_gtt_pte(device_t dev, u_int index,
129 vm_offset_t physical, int flags);
130 static void agp_g4x_install_gtt_pte(device_t dev, u_int index,
131 vm_offset_t physical, int flags);
133 static void agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte);
134 static void agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte);
135 static void agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte);
136 static void agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte);
138 static u_int32_t agp_i810_read_gtt_pte(device_t dev, u_int index);
139 static u_int32_t agp_i915_read_gtt_pte(device_t dev, u_int index);
140 static u_int32_t agp_i965_read_gtt_pte(device_t dev, u_int index);
141 static u_int32_t agp_g4x_read_gtt_pte(device_t dev, u_int index);
143 static vm_paddr_t agp_i810_read_gtt_pte_paddr(device_t dev, u_int index);
144 static vm_paddr_t agp_i915_read_gtt_pte_paddr(device_t dev, u_int index);
146 static int agp_i810_set_aperture(device_t dev, u_int32_t aperture);
147 static int agp_i830_set_aperture(device_t dev, u_int32_t aperture);
148 static int agp_i915_set_aperture(device_t dev, u_int32_t aperture);
150 static int agp_i810_chipset_flush_setup(device_t dev);
151 static int agp_i915_chipset_flush_setup(device_t dev);
152 static int agp_i965_chipset_flush_setup(device_t dev);
154 static void agp_i810_chipset_flush_teardown(device_t dev);
155 static void agp_i915_chipset_flush_teardown(device_t dev);
156 static void agp_i965_chipset_flush_teardown(device_t dev);
158 static void agp_i810_chipset_flush(device_t dev);
159 static void agp_i830_chipset_flush(device_t dev);
160 static void agp_i915_chipset_flush(device_t dev);
163 CHIP_I810, /* i810/i815 */
164 CHIP_I830, /* 830M/845G */
165 CHIP_I855, /* 852GM/855GM/865G */
166 CHIP_I915, /* 915G/915GM */
167 CHIP_I965, /* G965 */
168 CHIP_G33, /* G33/Q33/Q35 */
169 CHIP_IGD, /* Pineview */
170 CHIP_G4X, /* G45/Q45 */
173 /* The i810 through i855 have the registers at BAR 1, and the GATT gets
174 * allocated by us. The i915 has registers in BAR 0 and the GATT is at the
175 * start of the stolen memory, and should only be accessed by the OS through
176 * BAR 3. The G965 has registers and GATT in the same BAR (0) -- first 512KB
177 * is registers, second 512KB is GATT.
179 static struct resource_spec agp_i810_res_spec[] = {
180 { SYS_RES_MEMORY, AGP_I810_MMADR, RF_ACTIVE | RF_SHAREABLE },
184 static struct resource_spec agp_i915_res_spec[] = {
185 { SYS_RES_MEMORY, AGP_I915_MMADR, RF_ACTIVE | RF_SHAREABLE },
186 { SYS_RES_MEMORY, AGP_I915_GTTADR, RF_ACTIVE | RF_SHAREABLE },
190 static struct resource_spec agp_i965_res_spec[] = {
191 { SYS_RES_MEMORY, AGP_I965_GTTMMADR, RF_ACTIVE | RF_SHAREABLE },
192 { SYS_RES_MEMORY, AGP_I965_APBASE, RF_ACTIVE | RF_SHAREABLE },
196 struct agp_i810_softc {
197 struct agp_softc agp;
198 u_int32_t initial_aperture; /* aperture size at startup */
199 struct agp_gatt *gatt;
200 u_int32_t dcache_size; /* i810 only */
201 u_int32_t stolen; /* number of i830/845 gtt
202 entries for stolen memory */
203 u_int stolen_size; /* BIOS-reserved graphics memory */
204 u_int gtt_total_entries; /* Total number of gtt ptes */
205 u_int gtt_mappable_entries; /* Number of gtt ptes mappable by CPU */
206 device_t bdev; /* bridge device */
207 void *argb_cursor; /* contigmalloc area for ARGB cursor */
208 struct resource *sc_res[2];
209 const struct agp_i810_match *match;
210 int sc_flush_page_rid;
211 struct resource *sc_flush_page_res;
212 void *sc_flush_page_vaddr;
213 int sc_bios_allocated_flush_page;
216 static device_t intel_agp;
218 struct agp_i810_driver {
221 int busdma_addr_mask_sz;
222 struct resource_spec *res_spec;
223 int (*check_active)(device_t);
224 void (*set_desc)(device_t, const struct agp_i810_match *);
225 void (*dump_regs)(device_t);
226 int (*get_stolen_size)(device_t);
227 int (*get_gtt_total_entries)(device_t);
228 int (*get_gtt_mappable_entries)(device_t);
229 int (*install_gatt)(device_t);
230 void (*deinstall_gatt)(device_t);
231 void (*write_gtt)(device_t, u_int, uint32_t);
232 void (*install_gtt_pte)(device_t, u_int, vm_offset_t, int);
233 u_int32_t (*read_gtt_pte)(device_t, u_int);
234 vm_paddr_t (*read_gtt_pte_paddr)(device_t , u_int);
235 int (*set_aperture)(device_t, u_int32_t);
236 int (*chipset_flush_setup)(device_t);
237 void (*chipset_flush_teardown)(device_t);
238 void (*chipset_flush)(device_t);
242 struct intel_gtt base;
245 static const struct agp_i810_driver agp_i810_i810_driver = {
246 .chiptype = CHIP_I810,
248 .busdma_addr_mask_sz = 32,
249 .res_spec = agp_i810_res_spec,
250 .check_active = agp_i810_check_active,
251 .set_desc = agp_i810_set_desc,
252 .dump_regs = agp_i810_dump_regs,
253 .get_stolen_size = agp_i810_get_stolen_size,
254 .get_gtt_mappable_entries = agp_i810_get_gtt_mappable_entries,
255 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
256 .install_gatt = agp_i810_install_gatt,
257 .deinstall_gatt = agp_i810_deinstall_gatt,
258 .write_gtt = agp_i810_write_gtt,
259 .install_gtt_pte = agp_i810_install_gtt_pte,
260 .read_gtt_pte = agp_i810_read_gtt_pte,
261 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
262 .set_aperture = agp_i810_set_aperture,
263 .chipset_flush_setup = agp_i810_chipset_flush_setup,
264 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
265 .chipset_flush = agp_i810_chipset_flush,
268 static const struct agp_i810_driver agp_i810_i815_driver = {
269 .chiptype = CHIP_I810,
271 .busdma_addr_mask_sz = 32,
272 .res_spec = agp_i810_res_spec,
273 .check_active = agp_i810_check_active,
274 .set_desc = agp_i810_set_desc,
275 .dump_regs = agp_i810_dump_regs,
276 .get_stolen_size = agp_i810_get_stolen_size,
277 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
278 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
279 .install_gatt = agp_i810_install_gatt,
280 .deinstall_gatt = agp_i810_deinstall_gatt,
281 .write_gtt = agp_i810_write_gtt,
282 .install_gtt_pte = agp_i810_install_gtt_pte,
283 .read_gtt_pte = agp_i810_read_gtt_pte,
284 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
285 .set_aperture = agp_i810_set_aperture,
286 .chipset_flush_setup = agp_i810_chipset_flush_setup,
287 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
288 .chipset_flush = agp_i830_chipset_flush,
291 static const struct agp_i810_driver agp_i810_i830_driver = {
292 .chiptype = CHIP_I830,
294 .busdma_addr_mask_sz = 32,
295 .res_spec = agp_i810_res_spec,
296 .check_active = agp_i830_check_active,
297 .set_desc = agp_i810_set_desc,
298 .dump_regs = agp_i830_dump_regs,
299 .get_stolen_size = agp_i830_get_stolen_size,
300 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
301 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
302 .install_gatt = agp_i830_install_gatt,
303 .deinstall_gatt = agp_i830_deinstall_gatt,
304 .write_gtt = agp_i810_write_gtt,
305 .install_gtt_pte = agp_i830_install_gtt_pte,
306 .read_gtt_pte = agp_i810_read_gtt_pte,
307 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
308 .set_aperture = agp_i830_set_aperture,
309 .chipset_flush_setup = agp_i810_chipset_flush_setup,
310 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
311 .chipset_flush = agp_i830_chipset_flush,
314 static const struct agp_i810_driver agp_i810_i855_driver = {
315 .chiptype = CHIP_I855,
317 .busdma_addr_mask_sz = 32,
318 .res_spec = agp_i810_res_spec,
319 .check_active = agp_i830_check_active,
320 .set_desc = agp_82852_set_desc,
321 .dump_regs = agp_i855_dump_regs,
322 .get_stolen_size = agp_i915_get_stolen_size,
323 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
324 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
325 .install_gatt = agp_i830_install_gatt,
326 .deinstall_gatt = agp_i830_deinstall_gatt,
327 .write_gtt = agp_i810_write_gtt,
328 .install_gtt_pte = agp_i830_install_gtt_pte,
329 .read_gtt_pte = agp_i810_read_gtt_pte,
330 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
331 .set_aperture = agp_i830_set_aperture,
332 .chipset_flush_setup = agp_i810_chipset_flush_setup,
333 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
334 .chipset_flush = agp_i830_chipset_flush,
337 static const struct agp_i810_driver agp_i810_i865_driver = {
338 .chiptype = CHIP_I855,
340 .busdma_addr_mask_sz = 32,
341 .res_spec = agp_i810_res_spec,
342 .check_active = agp_i830_check_active,
343 .set_desc = agp_i810_set_desc,
344 .dump_regs = agp_i855_dump_regs,
345 .get_stolen_size = agp_i915_get_stolen_size,
346 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
347 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
348 .install_gatt = agp_i830_install_gatt,
349 .deinstall_gatt = agp_i830_deinstall_gatt,
350 .write_gtt = agp_i810_write_gtt,
351 .install_gtt_pte = agp_i830_install_gtt_pte,
352 .read_gtt_pte = agp_i810_read_gtt_pte,
353 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
354 .set_aperture = agp_i915_set_aperture,
355 .chipset_flush_setup = agp_i810_chipset_flush_setup,
356 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
357 .chipset_flush = agp_i830_chipset_flush,
360 static const struct agp_i810_driver agp_i810_i915_driver = {
361 .chiptype = CHIP_I915,
363 .busdma_addr_mask_sz = 32,
364 .res_spec = agp_i915_res_spec,
365 .check_active = agp_i915_check_active,
366 .set_desc = agp_i810_set_desc,
367 .dump_regs = agp_i915_dump_regs,
368 .get_stolen_size = agp_i915_get_stolen_size,
369 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
370 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
371 .install_gatt = agp_i830_install_gatt,
372 .deinstall_gatt = agp_i830_deinstall_gatt,
373 .write_gtt = agp_i915_write_gtt,
374 .install_gtt_pte = agp_i915_install_gtt_pte,
375 .read_gtt_pte = agp_i915_read_gtt_pte,
376 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
377 .set_aperture = agp_i915_set_aperture,
378 .chipset_flush_setup = agp_i915_chipset_flush_setup,
379 .chipset_flush_teardown = agp_i915_chipset_flush_teardown,
380 .chipset_flush = agp_i915_chipset_flush,
383 static const struct agp_i810_driver agp_i810_g33_driver = {
384 .chiptype = CHIP_G33,
386 .busdma_addr_mask_sz = 36,
387 .res_spec = agp_i915_res_spec,
388 .check_active = agp_i915_check_active,
389 .set_desc = agp_i810_set_desc,
390 .dump_regs = agp_i965_dump_regs,
391 .get_stolen_size = agp_i915_get_stolen_size,
392 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
393 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
394 .install_gatt = agp_i830_install_gatt,
395 .deinstall_gatt = agp_i830_deinstall_gatt,
396 .write_gtt = agp_i915_write_gtt,
397 .install_gtt_pte = agp_i915_install_gtt_pte,
398 .read_gtt_pte = agp_i915_read_gtt_pte,
399 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
400 .set_aperture = agp_i915_set_aperture,
401 .chipset_flush_setup = agp_i965_chipset_flush_setup,
402 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
403 .chipset_flush = agp_i915_chipset_flush,
406 static const struct agp_i810_driver agp_i810_igd_driver = {
407 .chiptype = CHIP_IGD,
409 .busdma_addr_mask_sz = 36,
410 .res_spec = agp_i915_res_spec,
411 .check_active = agp_i915_check_active,
412 .set_desc = agp_i810_set_desc,
413 .dump_regs = agp_i915_dump_regs,
414 .get_stolen_size = agp_i915_get_stolen_size,
415 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
416 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
417 .install_gatt = agp_i830_install_gatt,
418 .deinstall_gatt = agp_i830_deinstall_gatt,
419 .write_gtt = agp_i915_write_gtt,
420 .install_gtt_pte = agp_i915_install_gtt_pte,
421 .read_gtt_pte = agp_i915_read_gtt_pte,
422 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
423 .set_aperture = agp_i915_set_aperture,
424 .chipset_flush_setup = agp_i965_chipset_flush_setup,
425 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
426 .chipset_flush = agp_i915_chipset_flush,
429 static const struct agp_i810_driver agp_i810_g965_driver = {
430 .chiptype = CHIP_I965,
432 .busdma_addr_mask_sz = 36,
433 .res_spec = agp_i965_res_spec,
434 .check_active = agp_i915_check_active,
435 .set_desc = agp_i810_set_desc,
436 .dump_regs = agp_i965_dump_regs,
437 .get_stolen_size = agp_i915_get_stolen_size,
438 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
439 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
440 .install_gatt = agp_i965_install_gatt,
441 .deinstall_gatt = agp_i830_deinstall_gatt,
442 .write_gtt = agp_i965_write_gtt,
443 .install_gtt_pte = agp_i965_install_gtt_pte,
444 .read_gtt_pte = agp_i965_read_gtt_pte,
445 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
446 .set_aperture = agp_i915_set_aperture,
447 .chipset_flush_setup = agp_i965_chipset_flush_setup,
448 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
449 .chipset_flush = agp_i915_chipset_flush,
452 static const struct agp_i810_driver agp_i810_g4x_driver = {
453 .chiptype = CHIP_G4X,
455 .busdma_addr_mask_sz = 36,
456 .res_spec = agp_i965_res_spec,
457 .check_active = agp_i915_check_active,
458 .set_desc = agp_i810_set_desc,
459 .dump_regs = agp_i965_dump_regs,
460 .get_stolen_size = agp_i915_get_stolen_size,
461 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
462 .get_gtt_total_entries = agp_gen5_get_gtt_total_entries,
463 .install_gatt = agp_g4x_install_gatt,
464 .deinstall_gatt = agp_i830_deinstall_gatt,
465 .write_gtt = agp_g4x_write_gtt,
466 .install_gtt_pte = agp_g4x_install_gtt_pte,
467 .read_gtt_pte = agp_g4x_read_gtt_pte,
468 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
469 .set_aperture = agp_i915_set_aperture,
470 .chipset_flush_setup = agp_i965_chipset_flush_setup,
471 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
472 .chipset_flush = agp_i915_chipset_flush,
475 /* For adding new devices, devid is the id of the graphics controller
476 * (pci:0:2:0, for example). The placeholder (usually at pci:0:2:1) for the
477 * second head should never be added. The bridge_offset is the offset to
478 * subtract from devid to get the id of the hostb that the device is on.
480 static const struct agp_i810_match {
483 const struct agp_i810_driver *driver;
484 } agp_i810_matches[] = {
487 .name = "Intel 82810 (i810 GMCH) SVGA controller",
488 .driver = &agp_i810_i810_driver
492 .name = "Intel 82810-DC100 (i810-DC100 GMCH) SVGA controller",
493 .driver = &agp_i810_i810_driver
497 .name = "Intel 82810E (i810E GMCH) SVGA controller",
498 .driver = &agp_i810_i810_driver
502 .name = "Intel 82815 (i815 GMCH) SVGA controller",
503 .driver = &agp_i810_i815_driver
507 .name = "Intel 82830M (830M GMCH) SVGA controller",
508 .driver = &agp_i810_i830_driver
512 .name = "Intel 82845M (845M GMCH) SVGA controller",
513 .driver = &agp_i810_i830_driver
517 .name = "Intel 82852/855GM SVGA controller",
518 .driver = &agp_i810_i855_driver
522 .name = "Intel 82865G (865G GMCH) SVGA controller",
523 .driver = &agp_i810_i865_driver
527 .name = "Intel 82915G (915G GMCH) SVGA controller",
528 .driver = &agp_i810_i915_driver
532 .name = "Intel E7221 SVGA controller",
533 .driver = &agp_i810_i915_driver
537 .name = "Intel 82915GM (915GM GMCH) SVGA controller",
538 .driver = &agp_i810_i915_driver
542 .name = "Intel 82945G (945G GMCH) SVGA controller",
543 .driver = &agp_i810_i915_driver
547 .name = "Intel 82945GM (945GM GMCH) SVGA controller",
548 .driver = &agp_i810_i915_driver
552 .name = "Intel 945GME SVGA controller",
553 .driver = &agp_i810_i915_driver
557 .name = "Intel 946GZ SVGA controller",
558 .driver = &agp_i810_g965_driver
562 .name = "Intel G965 SVGA controller",
563 .driver = &agp_i810_g965_driver
567 .name = "Intel Q965 SVGA controller",
568 .driver = &agp_i810_g965_driver
572 .name = "Intel G965 SVGA controller",
573 .driver = &agp_i810_g965_driver
577 .name = "Intel Q35 SVGA controller",
578 .driver = &agp_i810_g33_driver
582 .name = "Intel G33 SVGA controller",
583 .driver = &agp_i810_g33_driver
587 .name = "Intel Q33 SVGA controller",
588 .driver = &agp_i810_g33_driver
592 .name = "Intel Pineview SVGA controller",
593 .driver = &agp_i810_igd_driver
597 .name = "Intel Pineview (M) SVGA controller",
598 .driver = &agp_i810_igd_driver
602 .name = "Intel GM965 SVGA controller",
603 .driver = &agp_i810_g965_driver
607 .name = "Intel GME965 SVGA controller",
608 .driver = &agp_i810_g965_driver
612 .name = "Intel GM45 SVGA controller",
613 .driver = &agp_i810_g4x_driver
617 .name = "Intel Eaglelake SVGA controller",
618 .driver = &agp_i810_g4x_driver
622 .name = "Intel Q45 SVGA controller",
623 .driver = &agp_i810_g4x_driver
627 .name = "Intel G45 SVGA controller",
628 .driver = &agp_i810_g4x_driver
632 .name = "Intel G41 SVGA controller",
633 .driver = &agp_i810_g4x_driver
637 .name = "Intel Ironlake (D) SVGA controller",
638 .driver = &agp_i810_g4x_driver
642 .name = "Intel Ironlake (M) SVGA controller",
643 .driver = &agp_i810_g4x_driver
650 static const struct agp_i810_match*
651 agp_i810_match(device_t dev)
655 if (pci_get_class(dev) != PCIC_DISPLAY
656 || (pci_get_subclass(dev) != PCIS_DISPLAY_VGA &&
657 pci_get_subclass(dev) != PCIS_DISPLAY_OTHER))
660 devid = pci_get_devid(dev);
661 for (i = 0; agp_i810_matches[i].devid != 0; i++) {
662 if (agp_i810_matches[i].devid == devid)
665 if (agp_i810_matches[i].devid == 0)
668 return (&agp_i810_matches[i]);
672 * Find bridge device.
675 agp_i810_find_bridge(device_t dev)
678 return (pci_find_dbsf(0, 0, 0, 0));
682 agp_i810_identify(driver_t *driver, device_t parent)
685 if (device_find_child(parent, "agp", -1) == NULL &&
686 agp_i810_match(parent))
687 device_add_child(parent, "agp", -1);
691 agp_i810_check_active(device_t bridge_dev)
695 smram = pci_read_config(bridge_dev, AGP_I810_SMRAM, 1);
696 if ((smram & AGP_I810_SMRAM_GMS) == AGP_I810_SMRAM_GMS_DISABLED)
702 agp_i830_check_active(device_t bridge_dev)
706 gcc1 = pci_read_config(bridge_dev, AGP_I830_GCC1, 1);
707 if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED)
713 agp_i915_check_active(device_t bridge_dev)
717 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
718 if ((deven & AGP_I915_DEVEN_D2F0) == AGP_I915_DEVEN_D2F0_DISABLED)
724 agp_82852_set_desc(device_t dev, const struct agp_i810_match *match)
727 switch (pci_read_config(dev, AGP_I85X_CAPID, 1)) {
730 "Intel 82855GME (855GME GMCH) SVGA controller");
734 "Intel 82855GM (855GM GMCH) SVGA controller");
738 "Intel 82852GME (852GME GMCH) SVGA controller");
742 "Intel 82852GM (852GM GMCH) SVGA controller");
746 "Intel 8285xM (85xGM GMCH) SVGA controller");
752 agp_i810_set_desc(device_t dev, const struct agp_i810_match *match)
755 device_set_desc(dev, match->name);
759 agp_i810_probe(device_t dev)
762 const struct agp_i810_match *match;
765 if (resource_disabled("agp", device_get_unit(dev)))
767 match = agp_i810_match(dev);
771 bdev = agp_i810_find_bridge(dev);
774 printf("I810: can't find bridge device\n");
779 * checking whether internal graphics device has been activated.
781 err = match->driver->check_active(bdev);
784 printf("i810: disabled, not probing\n");
788 match->driver->set_desc(dev, match);
789 return (BUS_PROBE_DEFAULT);
793 agp_i810_dump_regs(device_t dev)
795 struct agp_i810_softc *sc = device_get_softc(dev);
797 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
798 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
799 device_printf(dev, "AGP_I810_MISCC: 0x%04x\n",
800 pci_read_config(sc->bdev, AGP_I810_MISCC, 2));
804 agp_i830_dump_regs(device_t dev)
806 struct agp_i810_softc *sc = device_get_softc(dev);
808 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
809 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
810 device_printf(dev, "AGP_I830_GCC1: 0x%02x\n",
811 pci_read_config(sc->bdev, AGP_I830_GCC1, 1));
815 agp_i855_dump_regs(device_t dev)
817 struct agp_i810_softc *sc = device_get_softc(dev);
819 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
820 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
821 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
822 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
826 agp_i915_dump_regs(device_t dev)
828 struct agp_i810_softc *sc = device_get_softc(dev);
830 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
831 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
832 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
833 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
834 device_printf(dev, "AGP_I915_MSAC: 0x%02x\n",
835 pci_read_config(sc->bdev, AGP_I915_MSAC, 1));
839 agp_i965_dump_regs(device_t dev)
841 struct agp_i810_softc *sc = device_get_softc(dev);
843 device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
844 bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
845 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
846 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
847 device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
848 pci_read_config(sc->bdev, AGP_I965_MSAC, 1));
852 agp_i810_get_stolen_size(device_t dev)
854 struct agp_i810_softc *sc;
856 sc = device_get_softc(dev);
863 agp_i830_get_stolen_size(device_t dev)
865 struct agp_i810_softc *sc;
868 sc = device_get_softc(dev);
870 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1);
871 switch (gcc1 & AGP_I830_GCC1_GMS) {
872 case AGP_I830_GCC1_GMS_STOLEN_512:
873 sc->stolen = (512 - 132) * 1024 / 4096;
874 sc->stolen_size = 512 * 1024;
876 case AGP_I830_GCC1_GMS_STOLEN_1024:
877 sc->stolen = (1024 - 132) * 1024 / 4096;
878 sc->stolen_size = 1024 * 1024;
880 case AGP_I830_GCC1_GMS_STOLEN_8192:
881 sc->stolen = (8192 - 132) * 1024 / 4096;
882 sc->stolen_size = 8192 * 1024;
887 "unknown memory configuration, disabling (GCC1 %x)\n",
895 agp_i915_get_stolen_size(device_t dev)
897 struct agp_i810_softc *sc;
898 unsigned int gcc1, stolen, gtt_size;
900 sc = device_get_softc(dev);
903 * Stolen memory is set up at the beginning of the aperture by
904 * the BIOS, consisting of the GATT followed by 4kb for the
907 switch (sc->match->driver->chiptype) {
915 switch (bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL) &
916 AGP_I810_PGTBL_SIZE_MASK) {
917 case AGP_I810_PGTBL_SIZE_128KB:
920 case AGP_I810_PGTBL_SIZE_256KB:
923 case AGP_I810_PGTBL_SIZE_512KB:
926 case AGP_I965_PGTBL_SIZE_1MB:
929 case AGP_I965_PGTBL_SIZE_2MB:
932 case AGP_I965_PGTBL_SIZE_1_5MB:
933 gtt_size = 1024 + 512;
936 device_printf(dev, "Bad PGTBL size\n");
941 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 2);
942 switch (gcc1 & AGP_G33_MGGC_GGMS_MASK) {
943 case AGP_G33_MGGC_GGMS_SIZE_1M:
946 case AGP_G33_MGGC_GGMS_SIZE_2M:
950 device_printf(dev, "Bad PGTBL size\n");
959 device_printf(dev, "Bad chiptype\n");
963 /* GCC1 is called MGGC on i915+ */
964 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
965 switch (gcc1 & AGP_I855_GCC1_GMS) {
966 case AGP_I855_GCC1_GMS_STOLEN_1M:
969 case AGP_I855_GCC1_GMS_STOLEN_4M:
972 case AGP_I855_GCC1_GMS_STOLEN_8M:
975 case AGP_I855_GCC1_GMS_STOLEN_16M:
978 case AGP_I855_GCC1_GMS_STOLEN_32M:
981 case AGP_I915_GCC1_GMS_STOLEN_48M:
982 stolen = sc->match->driver->gen > 2 ? 48 * 1024 : 0;
984 case AGP_I915_GCC1_GMS_STOLEN_64M:
985 stolen = sc->match->driver->gen > 2 ? 64 * 1024 : 0;
987 case AGP_G33_GCC1_GMS_STOLEN_128M:
988 stolen = sc->match->driver->gen > 2 ? 128 * 1024 : 0;
990 case AGP_G33_GCC1_GMS_STOLEN_256M:
991 stolen = sc->match->driver->gen > 2 ? 256 * 1024 : 0;
993 case AGP_G4X_GCC1_GMS_STOLEN_96M:
994 if (sc->match->driver->chiptype == CHIP_I965 ||
995 sc->match->driver->chiptype == CHIP_G4X)
1000 case AGP_G4X_GCC1_GMS_STOLEN_160M:
1001 if (sc->match->driver->chiptype == CHIP_I965 ||
1002 sc->match->driver->chiptype == CHIP_G4X)
1003 stolen = 160 * 1024;
1007 case AGP_G4X_GCC1_GMS_STOLEN_224M:
1008 if (sc->match->driver->chiptype == CHIP_I965 ||
1009 sc->match->driver->chiptype == CHIP_G4X)
1010 stolen = 224 * 1024;
1014 case AGP_G4X_GCC1_GMS_STOLEN_352M:
1015 if (sc->match->driver->chiptype == CHIP_I965 ||
1016 sc->match->driver->chiptype == CHIP_G4X)
1017 stolen = 352 * 1024;
1023 "unknown memory configuration, disabling (GCC1 %x)\n",
1029 sc->stolen_size = stolen * 1024;
1030 sc->stolen = (stolen - gtt_size) * 1024 / 4096;
1036 agp_i810_get_gtt_mappable_entries(device_t dev)
1038 struct agp_i810_softc *sc;
1042 sc = device_get_softc(dev);
1043 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1044 if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
1048 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1053 agp_i830_get_gtt_mappable_entries(device_t dev)
1055 struct agp_i810_softc *sc;
1059 sc = device_get_softc(dev);
1060 gmch_ctl = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1061 if ((gmch_ctl & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
1065 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1070 agp_i915_get_gtt_mappable_entries(device_t dev)
1072 struct agp_i810_softc *sc;
1075 sc = device_get_softc(dev);
1076 ap = AGP_GET_APERTURE(dev);
1077 sc->gtt_mappable_entries = ap >> AGP_PAGE_SHIFT;
1082 agp_i810_get_gtt_total_entries(device_t dev)
1084 struct agp_i810_softc *sc;
1086 sc = device_get_softc(dev);
1087 sc->gtt_total_entries = sc->gtt_mappable_entries;
1092 agp_i965_get_gtt_total_entries(device_t dev)
1094 struct agp_i810_softc *sc;
1095 uint32_t pgetbl_ctl;
1098 sc = device_get_softc(dev);
1100 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1101 switch (pgetbl_ctl & AGP_I810_PGTBL_SIZE_MASK) {
1102 case AGP_I810_PGTBL_SIZE_128KB:
1103 sc->gtt_total_entries = 128 * 1024 / 4;
1105 case AGP_I810_PGTBL_SIZE_256KB:
1106 sc->gtt_total_entries = 256 * 1024 / 4;
1108 case AGP_I810_PGTBL_SIZE_512KB:
1109 sc->gtt_total_entries = 512 * 1024 / 4;
1111 /* GTT pagetable sizes bigger than 512KB are not possible on G33! */
1112 case AGP_I810_PGTBL_SIZE_1MB:
1113 sc->gtt_total_entries = 1024 * 1024 / 4;
1115 case AGP_I810_PGTBL_SIZE_2MB:
1116 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1118 case AGP_I810_PGTBL_SIZE_1_5MB:
1119 sc->gtt_total_entries = (1024 + 512) * 1024 / 4;
1122 device_printf(dev, "Unknown page table size\n");
1129 agp_gen5_adjust_pgtbl_size(device_t dev, uint32_t sz)
1131 struct agp_i810_softc *sc;
1132 uint32_t pgetbl_ctl, pgetbl_ctl2;
1134 sc = device_get_softc(dev);
1136 /* Disable per-process page table. */
1137 pgetbl_ctl2 = bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2);
1138 pgetbl_ctl2 &= ~AGP_I810_PGTBL_ENABLED;
1139 bus_write_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2, pgetbl_ctl2);
1141 /* Write the new ggtt size. */
1142 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1143 pgetbl_ctl &= ~AGP_I810_PGTBL_SIZE_MASK;
1145 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgetbl_ctl);
1149 agp_gen5_get_gtt_total_entries(device_t dev)
1151 struct agp_i810_softc *sc;
1154 sc = device_get_softc(dev);
1156 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1157 switch (gcc1 & AGP_G4x_GCC1_SIZE_MASK) {
1158 case AGP_G4x_GCC1_SIZE_1M:
1159 case AGP_G4x_GCC1_SIZE_VT_1M:
1160 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1MB);
1162 case AGP_G4x_GCC1_SIZE_VT_1_5M:
1163 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1_5MB);
1165 case AGP_G4x_GCC1_SIZE_2M:
1166 case AGP_G4x_GCC1_SIZE_VT_2M:
1167 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_2MB);
1170 device_printf(dev, "Unknown page table size\n");
1174 return (agp_i965_get_gtt_total_entries(dev));
1178 agp_i810_install_gatt(device_t dev)
1180 struct agp_i810_softc *sc;
1182 sc = device_get_softc(dev);
1184 /* Some i810s have on-chip memory called dcache. */
1185 if ((bus_read_1(sc->sc_res[0], AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
1187 sc->dcache_size = 4 * 1024 * 1024;
1189 sc->dcache_size = 0;
1191 /* According to the specs the gatt on the i810 must be 64k. */
1192 sc->gatt->ag_virtual = (void *)kmem_alloc_contig(64 * 1024, M_NOWAIT |
1193 M_ZERO, 0, ~0, PAGE_SIZE, 0, VM_MEMATTR_WRITE_COMBINING);
1194 if (sc->gatt->ag_virtual == NULL) {
1196 device_printf(dev, "contiguous allocation failed\n");
1200 sc->gatt->ag_physical = vtophys((vm_offset_t)sc->gatt->ag_virtual);
1201 /* Install the GATT. */
1202 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1203 sc->gatt->ag_physical | 1);
1208 agp_i830_install_gatt_init(struct agp_i810_softc *sc)
1213 * The i830 automatically initializes the 128k gatt on boot.
1214 * GATT address is already in there, make sure it's enabled.
1216 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1218 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1220 sc->gatt->ag_physical = pgtblctl & ~1;
1224 agp_i830_install_gatt(device_t dev)
1226 struct agp_i810_softc *sc;
1228 sc = device_get_softc(dev);
1229 agp_i830_install_gatt_init(sc);
1234 agp_gen4_install_gatt(device_t dev, const vm_size_t gtt_offset)
1236 struct agp_i810_softc *sc;
1238 sc = device_get_softc(dev);
1239 pmap_change_attr((vm_offset_t)rman_get_virtual(sc->sc_res[0]) +
1240 gtt_offset, rman_get_size(sc->sc_res[0]) - gtt_offset,
1241 VM_MEMATTR_WRITE_COMBINING);
1242 agp_i830_install_gatt_init(sc);
1247 agp_i965_install_gatt(device_t dev)
1250 return (agp_gen4_install_gatt(dev, 512 * 1024));
1254 agp_g4x_install_gatt(device_t dev)
1257 return (agp_gen4_install_gatt(dev, 2 * 1024 * 1024));
1261 agp_i810_attach(device_t dev)
1263 struct agp_i810_softc *sc;
1266 sc = device_get_softc(dev);
1267 sc->bdev = agp_i810_find_bridge(dev);
1268 if (sc->bdev == NULL)
1271 sc->match = agp_i810_match(dev);
1273 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1274 AGP_APBASE : AGP_I915_GMADR);
1275 error = agp_generic_attach(dev);
1279 if (ptoa((vm_paddr_t)Maxmem) >
1280 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1281 device_printf(dev, "agp_i810 does not support physical "
1282 "memory above %ju.\n", (uintmax_t)(1ULL <<
1283 sc->match->driver->busdma_addr_mask_sz) - 1);
1287 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1288 agp_generic_detach(dev);
1292 sc->initial_aperture = AGP_GET_APERTURE(dev);
1293 sc->gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1294 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1296 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1297 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1298 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1299 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1300 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1301 bus_release_resources(dev, sc->match->driver->res_spec,
1303 free(sc->gatt, M_AGP);
1304 agp_generic_detach(dev);
1309 device_printf(dev, "aperture size is %dM",
1310 sc->initial_aperture / 1024 / 1024);
1312 printf(", detected %dk stolen memory\n", sc->stolen * 4);
1316 sc->match->driver->dump_regs(dev);
1317 device_printf(dev, "Mappable GTT entries: %d\n",
1318 sc->gtt_mappable_entries);
1319 device_printf(dev, "Total GTT entries: %d\n",
1320 sc->gtt_total_entries);
1326 agp_i810_deinstall_gatt(device_t dev)
1328 struct agp_i810_softc *sc;
1330 sc = device_get_softc(dev);
1331 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
1332 kmem_free((vm_offset_t)sc->gatt->ag_virtual, 64 * 1024);
1336 agp_i830_deinstall_gatt(device_t dev)
1338 struct agp_i810_softc *sc;
1339 unsigned int pgtblctl;
1341 sc = device_get_softc(dev);
1342 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1344 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1348 agp_i810_detach(device_t dev)
1350 struct agp_i810_softc *sc;
1352 sc = device_get_softc(dev);
1355 /* Clear the GATT base. */
1356 sc->match->driver->deinstall_gatt(dev);
1358 sc->match->driver->chipset_flush_teardown(dev);
1360 /* Put the aperture back the way it started. */
1361 AGP_SET_APERTURE(dev, sc->initial_aperture);
1363 free(sc->gatt, M_AGP);
1364 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1371 agp_i810_resume(device_t dev)
1373 struct agp_i810_softc *sc;
1374 sc = device_get_softc(dev);
1376 AGP_SET_APERTURE(dev, sc->initial_aperture);
1378 /* Install the GATT. */
1379 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1380 sc->gatt->ag_physical | 1);
1382 return (bus_generic_resume(dev));
1386 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1387 * while returning failure on later chipsets when an actual change is
1390 * This whole function is likely bogus, as the kernel would probably need to
1391 * reconfigure the placement of the AGP aperture if a larger size is requested,
1392 * which doesn't happen currently.
1395 agp_i810_set_aperture(device_t dev, u_int32_t aperture)
1397 struct agp_i810_softc *sc;
1400 sc = device_get_softc(dev);
1402 * Double check for sanity.
1404 if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
1405 device_printf(dev, "bad aperture size %d\n", aperture);
1409 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1410 miscc &= ~AGP_I810_MISCC_WINSIZE;
1411 if (aperture == 32 * 1024 * 1024)
1412 miscc |= AGP_I810_MISCC_WINSIZE_32;
1414 miscc |= AGP_I810_MISCC_WINSIZE_64;
1416 pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
1421 agp_i830_set_aperture(device_t dev, u_int32_t aperture)
1423 struct agp_i810_softc *sc;
1426 sc = device_get_softc(dev);
1428 if (aperture != 64 * 1024 * 1024 &&
1429 aperture != 128 * 1024 * 1024) {
1430 device_printf(dev, "bad aperture size %d\n", aperture);
1433 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1434 gcc1 &= ~AGP_I830_GCC1_GMASIZE;
1435 if (aperture == 64 * 1024 * 1024)
1436 gcc1 |= AGP_I830_GCC1_GMASIZE_64;
1438 gcc1 |= AGP_I830_GCC1_GMASIZE_128;
1440 pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
1445 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1448 return (agp_generic_set_aperture(dev, aperture));
1452 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1454 struct agp_i810_softc *sc;
1456 sc = device_get_softc(dev);
1457 return (sc->match->driver->set_aperture(dev, aperture));
1461 * Writes a GTT entry mapping the page at the given offset from the
1462 * beginning of the aperture to the given physical address. Setup the
1463 * caching mode according to flags.
1465 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1466 * from corresponding BAR start. For gen 4, offset is 512KB +
1467 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1469 * Also, the bits of the physical page address above 4GB needs to be
1470 * placed into bits 40-32 of PTE.
1473 agp_i810_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1478 pte = (u_int32_t)physical | I810_PTE_VALID;
1479 if (flags == AGP_DCACHE_MEMORY)
1480 pte |= I810_PTE_LOCAL;
1481 else if (flags == AGP_USER_CACHED_MEMORY)
1482 pte |= I830_PTE_SYSTEM_CACHED;
1483 agp_i810_write_gtt(dev, index, pte);
1487 agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte)
1489 struct agp_i810_softc *sc;
1491 sc = device_get_softc(dev);
1492 bus_write_4(sc->sc_res[0], AGP_I810_GTT + index * 4, pte);
1493 CTR2(KTR_AGP_I810, "810_pte %x %x", index, pte);
1497 agp_i830_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1502 pte = (u_int32_t)physical | I810_PTE_VALID;
1503 if (flags == AGP_USER_CACHED_MEMORY)
1504 pte |= I830_PTE_SYSTEM_CACHED;
1505 agp_i810_write_gtt(dev, index, pte);
1509 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1514 pte = (u_int32_t)physical | I810_PTE_VALID;
1515 if (flags == AGP_USER_CACHED_MEMORY)
1516 pte |= I830_PTE_SYSTEM_CACHED;
1517 pte |= (physical & 0x0000000f00000000ull) >> 28;
1518 agp_i915_write_gtt(dev, index, pte);
1522 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1524 struct agp_i810_softc *sc;
1526 sc = device_get_softc(dev);
1527 bus_write_4(sc->sc_res[1], index * 4, pte);
1528 CTR2(KTR_AGP_I810, "915_pte %x %x", index, pte);
1532 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1537 pte = (u_int32_t)physical | I810_PTE_VALID;
1538 if (flags == AGP_USER_CACHED_MEMORY)
1539 pte |= I830_PTE_SYSTEM_CACHED;
1540 pte |= (physical & 0x0000000f00000000ull) >> 28;
1541 agp_i965_write_gtt(dev, index, pte);
1545 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1547 struct agp_i810_softc *sc;
1549 sc = device_get_softc(dev);
1550 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1551 CTR2(KTR_AGP_I810, "965_pte %x %x", index, pte);
1555 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1560 pte = (u_int32_t)physical | I810_PTE_VALID;
1561 if (flags == AGP_USER_CACHED_MEMORY)
1562 pte |= I830_PTE_SYSTEM_CACHED;
1563 pte |= (physical & 0x0000000f00000000ull) >> 28;
1564 agp_g4x_write_gtt(dev, index, pte);
1568 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1570 struct agp_i810_softc *sc;
1572 sc = device_get_softc(dev);
1573 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1574 CTR2(KTR_AGP_I810, "g4x_pte %x %x", index, pte);
1578 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1580 struct agp_i810_softc *sc = device_get_softc(dev);
1583 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1584 device_printf(dev, "failed: offset is 0x%08jx, "
1585 "shift is %d, entries is %d\n", (intmax_t)offset,
1586 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1589 index = offset >> AGP_PAGE_SHIFT;
1590 if (sc->stolen != 0 && index < sc->stolen) {
1591 device_printf(dev, "trying to bind into stolen memory\n");
1594 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1599 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1601 struct agp_i810_softc *sc;
1604 sc = device_get_softc(dev);
1605 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1607 index = offset >> AGP_PAGE_SHIFT;
1608 if (sc->stolen != 0 && index < sc->stolen) {
1609 device_printf(dev, "trying to unbind from stolen memory\n");
1612 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1617 agp_i810_read_gtt_pte(device_t dev, u_int index)
1619 struct agp_i810_softc *sc;
1622 sc = device_get_softc(dev);
1623 pte = bus_read_4(sc->sc_res[0], AGP_I810_GTT + index * 4);
1628 agp_i915_read_gtt_pte(device_t dev, u_int index)
1630 struct agp_i810_softc *sc;
1633 sc = device_get_softc(dev);
1634 pte = bus_read_4(sc->sc_res[1], index * 4);
1639 agp_i965_read_gtt_pte(device_t dev, u_int index)
1641 struct agp_i810_softc *sc;
1644 sc = device_get_softc(dev);
1645 pte = bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1650 agp_g4x_read_gtt_pte(device_t dev, u_int index)
1652 struct agp_i810_softc *sc;
1655 sc = device_get_softc(dev);
1656 pte = bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1661 agp_i810_read_gtt_pte_paddr(device_t dev, u_int index)
1663 struct agp_i810_softc *sc;
1667 sc = device_get_softc(dev);
1668 pte = sc->match->driver->read_gtt_pte(dev, index);
1669 res = pte & ~PAGE_MASK;
1674 agp_i915_read_gtt_pte_paddr(device_t dev, u_int index)
1676 struct agp_i810_softc *sc;
1680 sc = device_get_softc(dev);
1681 pte = sc->match->driver->read_gtt_pte(dev, index);
1682 res = (pte & ~PAGE_MASK) | ((pte & 0xf0) << 28);
1687 * Writing via memory mapped registers already flushes all TLBs.
1690 agp_i810_flush_tlb(device_t dev)
1695 agp_i810_enable(device_t dev, u_int32_t mode)
1701 static struct agp_memory *
1702 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
1704 struct agp_i810_softc *sc;
1705 struct agp_memory *mem;
1708 sc = device_get_softc(dev);
1710 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
1711 sc->agp.as_allocated + size > sc->agp.as_maxmem)
1716 * Mapping local DRAM into GATT.
1718 if (sc->match->driver->chiptype != CHIP_I810)
1720 if (size != sc->dcache_size)
1722 } else if (type == 2) {
1724 * Type 2 is the contiguous physical memory type, that hands
1725 * back a physical address. This is used for cursors on i810.
1726 * Hand back as many single pages with physical as the user
1727 * wants, but only allow one larger allocation (ARGB cursor)
1730 if (size != AGP_PAGE_SIZE) {
1731 if (sc->argb_cursor != NULL)
1734 /* Allocate memory for ARGB cursor, if we can. */
1735 sc->argb_cursor = contigmalloc(size, M_AGP,
1736 0, 0, ~0, PAGE_SIZE, 0);
1737 if (sc->argb_cursor == NULL)
1742 mem = malloc(sizeof *mem, M_AGP, M_WAITOK);
1743 mem->am_id = sc->agp.as_nextid++;
1744 mem->am_size = size;
1745 mem->am_type = type;
1746 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
1747 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
1748 atop(round_page(size)));
1753 if (size == AGP_PAGE_SIZE) {
1755 * Allocate and wire down the page now so that we can
1756 * get its physical address.
1758 VM_OBJECT_WLOCK(mem->am_obj);
1759 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NOBUSY |
1760 VM_ALLOC_WIRED | VM_ALLOC_ZERO);
1761 VM_OBJECT_WUNLOCK(mem->am_obj);
1762 mem->am_physical = VM_PAGE_TO_PHYS(m);
1764 /* Our allocation is already nicely wired down for us.
1765 * Just grab the physical address.
1767 mem->am_physical = vtophys(sc->argb_cursor);
1770 mem->am_physical = 0;
1773 mem->am_is_bound = 0;
1774 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
1775 sc->agp.as_allocated += size;
1781 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
1783 struct agp_i810_softc *sc;
1786 if (mem->am_is_bound)
1789 sc = device_get_softc(dev);
1791 if (mem->am_type == 2) {
1792 if (mem->am_size == AGP_PAGE_SIZE) {
1794 * Unwire the page which we wired in alloc_memory.
1796 VM_OBJECT_WLOCK(mem->am_obj);
1797 m = vm_page_lookup(mem->am_obj, 0);
1798 vm_page_unwire(m, PQ_INACTIVE);
1799 VM_OBJECT_WUNLOCK(mem->am_obj);
1801 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
1802 sc->argb_cursor = NULL;
1806 sc->agp.as_allocated -= mem->am_size;
1807 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
1809 vm_object_deallocate(mem->am_obj);
1815 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
1817 struct agp_i810_softc *sc;
1820 /* Do some sanity checks first. */
1821 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
1822 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
1823 device_printf(dev, "binding memory at bad offset %#x\n",
1828 sc = device_get_softc(dev);
1829 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1830 mtx_lock(&sc->agp.as_lock);
1831 if (mem->am_is_bound) {
1832 mtx_unlock(&sc->agp.as_lock);
1835 /* The memory's already wired down, just stick it in the GTT. */
1836 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1837 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
1838 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
1840 mem->am_offset = offset;
1841 mem->am_is_bound = 1;
1842 mtx_unlock(&sc->agp.as_lock);
1846 if (mem->am_type != 1)
1847 return (agp_generic_bind_memory(dev, mem, offset));
1850 * Mapping local DRAM into GATT.
1852 if (sc->match->driver->chiptype != CHIP_I810)
1854 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
1855 bus_write_4(sc->sc_res[0],
1856 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
1862 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
1864 struct agp_i810_softc *sc;
1867 sc = device_get_softc(dev);
1869 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1870 mtx_lock(&sc->agp.as_lock);
1871 if (!mem->am_is_bound) {
1872 mtx_unlock(&sc->agp.as_lock);
1876 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1877 sc->match->driver->install_gtt_pte(dev,
1878 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
1880 mem->am_is_bound = 0;
1881 mtx_unlock(&sc->agp.as_lock);
1885 if (mem->am_type != 1)
1886 return (agp_generic_unbind_memory(dev, mem));
1888 if (sc->match->driver->chiptype != CHIP_I810)
1890 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1891 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
1897 static device_method_t agp_i810_methods[] = {
1898 /* Device interface */
1899 DEVMETHOD(device_identify, agp_i810_identify),
1900 DEVMETHOD(device_probe, agp_i810_probe),
1901 DEVMETHOD(device_attach, agp_i810_attach),
1902 DEVMETHOD(device_detach, agp_i810_detach),
1903 DEVMETHOD(device_suspend, bus_generic_suspend),
1904 DEVMETHOD(device_resume, agp_i810_resume),
1907 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
1908 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
1909 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
1910 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
1911 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
1912 DEVMETHOD(agp_enable, agp_i810_enable),
1913 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
1914 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
1915 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
1916 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
1917 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
1922 static driver_t agp_i810_driver = {
1925 sizeof(struct agp_i810_softc),
1928 static devclass_t agp_devclass;
1930 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, 0, 0);
1931 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
1932 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
1935 agp_intel_gtt_clear_range(device_t dev, u_int first_entry, u_int num_entries)
1937 struct agp_i810_softc *sc;
1940 sc = device_get_softc(dev);
1941 for (i = 0; i < num_entries; i++)
1942 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1943 VM_PAGE_TO_PHYS(bogus_page), 0);
1944 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
1948 agp_intel_gtt_insert_pages(device_t dev, u_int first_entry, u_int num_entries,
1949 vm_page_t *pages, u_int flags)
1951 struct agp_i810_softc *sc;
1954 sc = device_get_softc(dev);
1955 for (i = 0; i < num_entries; i++) {
1956 MPASS(pages[i]->valid == VM_PAGE_BITS_ALL);
1957 MPASS(pages[i]->ref_count > 0);
1958 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1959 VM_PAGE_TO_PHYS(pages[i]), flags);
1961 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
1965 agp_intel_gtt_get(device_t dev)
1967 struct agp_i810_softc *sc;
1968 struct intel_gtt res;
1970 sc = device_get_softc(dev);
1971 res.stolen_size = sc->stolen_size;
1972 res.gtt_total_entries = sc->gtt_total_entries;
1973 res.gtt_mappable_entries = sc->gtt_mappable_entries;
1974 res.do_idle_maps = 0;
1975 res.scratch_page_dma = VM_PAGE_TO_PHYS(bogus_page);
1976 if (sc->agp.as_aperture != NULL)
1977 res.gma_bus_addr = rman_get_start(sc->agp.as_aperture);
1979 res.gma_bus_addr = 0;
1984 agp_i810_chipset_flush_setup(device_t dev)
1991 agp_i810_chipset_flush_teardown(device_t dev)
1994 /* Nothing to do. */
1998 agp_i810_chipset_flush(device_t dev)
2001 /* Nothing to do. */
2005 agp_i830_chipset_flush(device_t dev)
2007 struct agp_i810_softc *sc;
2011 sc = device_get_softc(dev);
2012 pmap_invalidate_cache();
2013 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2014 bus_write_4(sc->sc_res[0], AGP_I830_HIC, hic | (1U << 31));
2015 for (i = 0; i < 20000 /* 1 sec */; i++) {
2016 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2017 if ((hic & (1U << 31)) == 0)
2024 agp_i915_chipset_flush_alloc_page(device_t dev, uint64_t start, uint64_t end)
2026 struct agp_i810_softc *sc;
2029 sc = device_get_softc(dev);
2030 vga = device_get_parent(dev);
2031 sc->sc_flush_page_rid = 100;
2032 sc->sc_flush_page_res = BUS_ALLOC_RESOURCE(device_get_parent(vga), dev,
2033 SYS_RES_MEMORY, &sc->sc_flush_page_rid, start, end, PAGE_SIZE,
2035 if (sc->sc_flush_page_res == NULL) {
2036 device_printf(dev, "Failed to allocate flush page at 0x%jx\n",
2040 sc->sc_flush_page_vaddr = rman_get_virtual(sc->sc_flush_page_res);
2042 device_printf(dev, "Allocated flush page phys 0x%jx virt %p\n",
2043 (uintmax_t)rman_get_start(sc->sc_flush_page_res),
2044 sc->sc_flush_page_vaddr);
2050 agp_i915_chipset_flush_free_page(device_t dev)
2052 struct agp_i810_softc *sc;
2055 sc = device_get_softc(dev);
2056 vga = device_get_parent(dev);
2057 if (sc->sc_flush_page_res == NULL)
2059 BUS_DEACTIVATE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2060 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2061 BUS_RELEASE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2062 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2066 agp_i915_chipset_flush_setup(device_t dev)
2068 struct agp_i810_softc *sc;
2072 sc = device_get_softc(dev);
2073 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2074 if ((temp & 1) != 0) {
2078 "Found already configured flush page at 0x%jx\n",
2080 sc->sc_bios_allocated_flush_page = 1;
2082 * In the case BIOS initialized the flush pointer (?)
2083 * register, expect that BIOS also set up the resource
2086 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2087 temp + PAGE_SIZE - 1);
2091 sc->sc_bios_allocated_flush_page = 0;
2092 error = agp_i915_chipset_flush_alloc_page(dev, 0, 0xffffffff);
2095 temp = rman_get_start(sc->sc_flush_page_res);
2096 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp | 1, 4);
2102 agp_i915_chipset_flush_teardown(device_t dev)
2104 struct agp_i810_softc *sc;
2107 sc = device_get_softc(dev);
2108 if (sc->sc_flush_page_res == NULL)
2110 if (!sc->sc_bios_allocated_flush_page) {
2111 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2113 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp, 4);
2115 agp_i915_chipset_flush_free_page(dev);
2119 agp_i965_chipset_flush_setup(device_t dev)
2121 struct agp_i810_softc *sc;
2123 uint32_t temp_hi, temp_lo;
2126 sc = device_get_softc(dev);
2128 temp_hi = pci_read_config(sc->bdev, AGP_I965_IFPADDR + 4, 4);
2129 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2131 if ((temp_lo & 1) != 0) {
2132 temp = ((uint64_t)temp_hi << 32) | (temp_lo & ~1);
2135 "Found already configured flush page at 0x%jx\n",
2137 sc->sc_bios_allocated_flush_page = 1;
2139 * In the case BIOS initialized the flush pointer (?)
2140 * register, expect that BIOS also set up the resource
2143 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2144 temp + PAGE_SIZE - 1);
2148 sc->sc_bios_allocated_flush_page = 0;
2149 error = agp_i915_chipset_flush_alloc_page(dev, 0, ~0);
2152 temp = rman_get_start(sc->sc_flush_page_res);
2153 pci_write_config(sc->bdev, AGP_I965_IFPADDR + 4,
2154 (temp >> 32) & UINT32_MAX, 4);
2155 pci_write_config(sc->bdev, AGP_I965_IFPADDR,
2156 (temp & UINT32_MAX) | 1, 4);
2162 agp_i965_chipset_flush_teardown(device_t dev)
2164 struct agp_i810_softc *sc;
2167 sc = device_get_softc(dev);
2168 if (sc->sc_flush_page_res == NULL)
2170 if (!sc->sc_bios_allocated_flush_page) {
2171 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2173 pci_write_config(sc->bdev, AGP_I965_IFPADDR, temp_lo, 4);
2175 agp_i915_chipset_flush_free_page(dev);
2179 agp_i915_chipset_flush(device_t dev)
2181 struct agp_i810_softc *sc;
2183 sc = device_get_softc(dev);
2184 *(uint32_t *)sc->sc_flush_page_vaddr = 1;
2188 agp_intel_gtt_chipset_flush(device_t dev)
2190 struct agp_i810_softc *sc;
2192 sc = device_get_softc(dev);
2193 sc->match->driver->chipset_flush(dev);
2198 agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list)
2203 agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
2204 struct sglist **sg_list)
2206 struct agp_i810_softc *sc;
2214 if (*sg_list != NULL)
2216 sc = device_get_softc(dev);
2217 sg = sglist_alloc(num_entries, M_WAITOK /* XXXKIB */);
2218 for (i = 0; i < num_entries; i++) {
2219 sg->sg_segs[i].ss_paddr = VM_PAGE_TO_PHYS(pages[i]);
2220 sg->sg_segs[i].ss_len = PAGE_SIZE;
2224 error = bus_dma_tag_create(bus_get_dma_tag(dev),
2225 1 /* alignment */, 0 /* boundary */,
2226 1ULL << sc->match->busdma_addr_mask_sz /* lowaddr */,
2227 BUS_SPACE_MAXADDR /* highaddr */,
2228 NULL /* filtfunc */, NULL /* filtfuncarg */,
2229 BUS_SPACE_MAXADDR /* maxsize */,
2230 BUS_SPACE_UNRESTRICTED /* nsegments */,
2231 BUS_SPACE_MAXADDR /* maxsegsz */,
2232 0 /* flags */, NULL /* lockfunc */, NULL /* lockfuncarg */,
2245 agp_intel_gtt_install_pte(device_t dev, u_int index, vm_paddr_t addr,
2248 struct agp_i810_softc *sc;
2250 sc = device_get_softc(dev);
2251 sc->match->driver->install_gtt_pte(dev, index, addr, flags);
2255 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2256 u_int first_entry, u_int flags)
2258 struct agp_i810_softc *sc;
2263 sc = device_get_softc(dev);
2264 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2265 spaddr = sg_list->sg_segs[i].ss_paddr;
2266 slen = sg_list->sg_segs[i].ss_len;
2267 for (; slen > 0; i++) {
2268 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2270 spaddr += AGP_PAGE_SIZE;
2271 slen -= AGP_PAGE_SIZE;
2274 sc->match->driver->read_gtt_pte(dev, first_entry + i - 1);
2278 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2281 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2285 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2289 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2297 intel_private.base = agp_intel_gtt_get(intel_agp);
2298 return (&intel_private.base);
2302 intel_gtt_chipset_flush(void)
2305 return (agp_intel_gtt_chipset_flush(intel_agp));
2309 intel_gtt_unmap_memory(struct sglist *sg_list)
2312 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2316 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2317 struct sglist **sg_list)
2320 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2325 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2329 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2333 intel_gtt_install_pte(u_int index, vm_paddr_t addr, u_int flags)
2336 agp_intel_gtt_install_pte(intel_agp, index, addr, flags);
2340 intel_gtt_get_bridge_device(void)
2342 struct agp_i810_softc *sc;
2344 sc = device_get_softc(intel_agp);
2349 intel_gtt_read_pte_paddr(u_int entry)
2351 struct agp_i810_softc *sc;
2353 sc = device_get_softc(intel_agp);
2354 return (sc->match->driver->read_gtt_pte_paddr(intel_agp, entry));
2358 intel_gtt_read_pte(u_int entry)
2360 struct agp_i810_softc *sc;
2362 sc = device_get_softc(intel_agp);
2363 return (sc->match->driver->read_gtt_pte(intel_agp, entry));
2367 intel_gtt_write(u_int entry, uint32_t val)
2369 struct agp_i810_softc *sc;
2371 sc = device_get_softc(intel_agp);
2372 return (sc->match->driver->write_gtt(intel_agp, entry, val));