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(kernel_arena,
1193 64 * 1024, M_NOWAIT | M_ZERO, 0, ~0, PAGE_SIZE,
1194 0, VM_MEMATTR_WRITE_COMBINING);
1195 if (sc->gatt->ag_virtual == NULL) {
1197 device_printf(dev, "contiguous allocation failed\n");
1201 sc->gatt->ag_physical = vtophys((vm_offset_t)sc->gatt->ag_virtual);
1202 /* Install the GATT. */
1203 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1204 sc->gatt->ag_physical | 1);
1209 agp_i830_install_gatt_init(struct agp_i810_softc *sc)
1214 * The i830 automatically initializes the 128k gatt on boot.
1215 * GATT address is already in there, make sure it's enabled.
1217 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1219 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1221 sc->gatt->ag_physical = pgtblctl & ~1;
1225 agp_i830_install_gatt(device_t dev)
1227 struct agp_i810_softc *sc;
1229 sc = device_get_softc(dev);
1230 agp_i830_install_gatt_init(sc);
1235 agp_gen4_install_gatt(device_t dev, const vm_size_t gtt_offset)
1237 struct agp_i810_softc *sc;
1239 sc = device_get_softc(dev);
1240 pmap_change_attr((vm_offset_t)rman_get_virtual(sc->sc_res[0]) +
1241 gtt_offset, rman_get_size(sc->sc_res[0]) - gtt_offset,
1242 VM_MEMATTR_WRITE_COMBINING);
1243 agp_i830_install_gatt_init(sc);
1248 agp_i965_install_gatt(device_t dev)
1251 return (agp_gen4_install_gatt(dev, 512 * 1024));
1255 agp_g4x_install_gatt(device_t dev)
1258 return (agp_gen4_install_gatt(dev, 2 * 1024 * 1024));
1262 agp_i810_attach(device_t dev)
1264 struct agp_i810_softc *sc;
1267 sc = device_get_softc(dev);
1268 sc->bdev = agp_i810_find_bridge(dev);
1269 if (sc->bdev == NULL)
1272 sc->match = agp_i810_match(dev);
1274 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1275 AGP_APBASE : AGP_I915_GMADR);
1276 error = agp_generic_attach(dev);
1280 if (ptoa((vm_paddr_t)Maxmem) >
1281 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1282 device_printf(dev, "agp_i810 does not support physical "
1283 "memory above %ju.\n", (uintmax_t)(1ULL <<
1284 sc->match->driver->busdma_addr_mask_sz) - 1);
1288 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1289 agp_generic_detach(dev);
1293 sc->initial_aperture = AGP_GET_APERTURE(dev);
1294 sc->gatt = malloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1295 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1297 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1298 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1299 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1300 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1301 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1302 bus_release_resources(dev, sc->match->driver->res_spec,
1304 free(sc->gatt, M_AGP);
1305 agp_generic_detach(dev);
1310 device_printf(dev, "aperture size is %dM",
1311 sc->initial_aperture / 1024 / 1024);
1313 printf(", detected %dk stolen memory\n", sc->stolen * 4);
1317 sc->match->driver->dump_regs(dev);
1318 device_printf(dev, "Mappable GTT entries: %d\n",
1319 sc->gtt_mappable_entries);
1320 device_printf(dev, "Total GTT entries: %d\n",
1321 sc->gtt_total_entries);
1327 agp_i810_deinstall_gatt(device_t dev)
1329 struct agp_i810_softc *sc;
1331 sc = device_get_softc(dev);
1332 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
1333 kmem_free(kernel_arena, (vm_offset_t)sc->gatt->ag_virtual, 64 * 1024);
1337 agp_i830_deinstall_gatt(device_t dev)
1339 struct agp_i810_softc *sc;
1340 unsigned int pgtblctl;
1342 sc = device_get_softc(dev);
1343 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1345 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1349 agp_i810_detach(device_t dev)
1351 struct agp_i810_softc *sc;
1353 sc = device_get_softc(dev);
1356 /* Clear the GATT base. */
1357 sc->match->driver->deinstall_gatt(dev);
1359 sc->match->driver->chipset_flush_teardown(dev);
1361 /* Put the aperture back the way it started. */
1362 AGP_SET_APERTURE(dev, sc->initial_aperture);
1364 free(sc->gatt, M_AGP);
1365 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1372 agp_i810_resume(device_t dev)
1374 struct agp_i810_softc *sc;
1375 sc = device_get_softc(dev);
1377 AGP_SET_APERTURE(dev, sc->initial_aperture);
1379 /* Install the GATT. */
1380 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1381 sc->gatt->ag_physical | 1);
1383 return (bus_generic_resume(dev));
1387 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1388 * while returning failure on later chipsets when an actual change is
1391 * This whole function is likely bogus, as the kernel would probably need to
1392 * reconfigure the placement of the AGP aperture if a larger size is requested,
1393 * which doesn't happen currently.
1396 agp_i810_set_aperture(device_t dev, u_int32_t aperture)
1398 struct agp_i810_softc *sc;
1401 sc = device_get_softc(dev);
1403 * Double check for sanity.
1405 if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
1406 device_printf(dev, "bad aperture size %d\n", aperture);
1410 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1411 miscc &= ~AGP_I810_MISCC_WINSIZE;
1412 if (aperture == 32 * 1024 * 1024)
1413 miscc |= AGP_I810_MISCC_WINSIZE_32;
1415 miscc |= AGP_I810_MISCC_WINSIZE_64;
1417 pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
1422 agp_i830_set_aperture(device_t dev, u_int32_t aperture)
1424 struct agp_i810_softc *sc;
1427 sc = device_get_softc(dev);
1429 if (aperture != 64 * 1024 * 1024 &&
1430 aperture != 128 * 1024 * 1024) {
1431 device_printf(dev, "bad aperture size %d\n", aperture);
1434 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1435 gcc1 &= ~AGP_I830_GCC1_GMASIZE;
1436 if (aperture == 64 * 1024 * 1024)
1437 gcc1 |= AGP_I830_GCC1_GMASIZE_64;
1439 gcc1 |= AGP_I830_GCC1_GMASIZE_128;
1441 pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
1446 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1449 return (agp_generic_set_aperture(dev, aperture));
1453 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1455 struct agp_i810_softc *sc;
1457 sc = device_get_softc(dev);
1458 return (sc->match->driver->set_aperture(dev, aperture));
1462 * Writes a GTT entry mapping the page at the given offset from the
1463 * beginning of the aperture to the given physical address. Setup the
1464 * caching mode according to flags.
1466 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1467 * from corresponding BAR start. For gen 4, offset is 512KB +
1468 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1470 * Also, the bits of the physical page address above 4GB needs to be
1471 * placed into bits 40-32 of PTE.
1474 agp_i810_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1479 pte = (u_int32_t)physical | I810_PTE_VALID;
1480 if (flags == AGP_DCACHE_MEMORY)
1481 pte |= I810_PTE_LOCAL;
1482 else if (flags == AGP_USER_CACHED_MEMORY)
1483 pte |= I830_PTE_SYSTEM_CACHED;
1484 agp_i810_write_gtt(dev, index, pte);
1488 agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte)
1490 struct agp_i810_softc *sc;
1492 sc = device_get_softc(dev);
1493 bus_write_4(sc->sc_res[0], AGP_I810_GTT + index * 4, pte);
1494 CTR2(KTR_AGP_I810, "810_pte %x %x", index, pte);
1498 agp_i830_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1503 pte = (u_int32_t)physical | I810_PTE_VALID;
1504 if (flags == AGP_USER_CACHED_MEMORY)
1505 pte |= I830_PTE_SYSTEM_CACHED;
1506 agp_i810_write_gtt(dev, index, pte);
1510 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1515 pte = (u_int32_t)physical | I810_PTE_VALID;
1516 if (flags == AGP_USER_CACHED_MEMORY)
1517 pte |= I830_PTE_SYSTEM_CACHED;
1518 pte |= (physical & 0x0000000f00000000ull) >> 28;
1519 agp_i915_write_gtt(dev, index, pte);
1523 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1525 struct agp_i810_softc *sc;
1527 sc = device_get_softc(dev);
1528 bus_write_4(sc->sc_res[1], index * 4, pte);
1529 CTR2(KTR_AGP_I810, "915_pte %x %x", index, pte);
1533 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1538 pte = (u_int32_t)physical | I810_PTE_VALID;
1539 if (flags == AGP_USER_CACHED_MEMORY)
1540 pte |= I830_PTE_SYSTEM_CACHED;
1541 pte |= (physical & 0x0000000f00000000ull) >> 28;
1542 agp_i965_write_gtt(dev, index, pte);
1546 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1548 struct agp_i810_softc *sc;
1550 sc = device_get_softc(dev);
1551 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1552 CTR2(KTR_AGP_I810, "965_pte %x %x", index, pte);
1556 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1561 pte = (u_int32_t)physical | I810_PTE_VALID;
1562 if (flags == AGP_USER_CACHED_MEMORY)
1563 pte |= I830_PTE_SYSTEM_CACHED;
1564 pte |= (physical & 0x0000000f00000000ull) >> 28;
1565 agp_g4x_write_gtt(dev, index, pte);
1569 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1571 struct agp_i810_softc *sc;
1573 sc = device_get_softc(dev);
1574 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1575 CTR2(KTR_AGP_I810, "g4x_pte %x %x", index, pte);
1579 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1581 struct agp_i810_softc *sc = device_get_softc(dev);
1584 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1585 device_printf(dev, "failed: offset is 0x%08jx, "
1586 "shift is %d, entries is %d\n", (intmax_t)offset,
1587 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1590 index = offset >> AGP_PAGE_SHIFT;
1591 if (sc->stolen != 0 && index < sc->stolen) {
1592 device_printf(dev, "trying to bind into stolen memory\n");
1595 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1600 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1602 struct agp_i810_softc *sc;
1605 sc = device_get_softc(dev);
1606 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1608 index = offset >> AGP_PAGE_SHIFT;
1609 if (sc->stolen != 0 && index < sc->stolen) {
1610 device_printf(dev, "trying to unbind from stolen memory\n");
1613 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1618 agp_i810_read_gtt_pte(device_t dev, u_int index)
1620 struct agp_i810_softc *sc;
1623 sc = device_get_softc(dev);
1624 pte = bus_read_4(sc->sc_res[0], AGP_I810_GTT + index * 4);
1629 agp_i915_read_gtt_pte(device_t dev, u_int index)
1631 struct agp_i810_softc *sc;
1634 sc = device_get_softc(dev);
1635 pte = bus_read_4(sc->sc_res[1], index * 4);
1640 agp_i965_read_gtt_pte(device_t dev, u_int index)
1642 struct agp_i810_softc *sc;
1645 sc = device_get_softc(dev);
1646 pte = bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1651 agp_g4x_read_gtt_pte(device_t dev, u_int index)
1653 struct agp_i810_softc *sc;
1656 sc = device_get_softc(dev);
1657 pte = bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1662 agp_i810_read_gtt_pte_paddr(device_t dev, u_int index)
1664 struct agp_i810_softc *sc;
1668 sc = device_get_softc(dev);
1669 pte = sc->match->driver->read_gtt_pte(dev, index);
1670 res = pte & ~PAGE_MASK;
1675 agp_i915_read_gtt_pte_paddr(device_t dev, u_int index)
1677 struct agp_i810_softc *sc;
1681 sc = device_get_softc(dev);
1682 pte = sc->match->driver->read_gtt_pte(dev, index);
1683 res = (pte & ~PAGE_MASK) | ((pte & 0xf0) << 28);
1688 * Writing via memory mapped registers already flushes all TLBs.
1691 agp_i810_flush_tlb(device_t dev)
1696 agp_i810_enable(device_t dev, u_int32_t mode)
1702 static struct agp_memory *
1703 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
1705 struct agp_i810_softc *sc;
1706 struct agp_memory *mem;
1709 sc = device_get_softc(dev);
1711 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
1712 sc->agp.as_allocated + size > sc->agp.as_maxmem)
1717 * Mapping local DRAM into GATT.
1719 if (sc->match->driver->chiptype != CHIP_I810)
1721 if (size != sc->dcache_size)
1723 } else if (type == 2) {
1725 * Type 2 is the contiguous physical memory type, that hands
1726 * back a physical address. This is used for cursors on i810.
1727 * Hand back as many single pages with physical as the user
1728 * wants, but only allow one larger allocation (ARGB cursor)
1731 if (size != AGP_PAGE_SIZE) {
1732 if (sc->argb_cursor != NULL)
1735 /* Allocate memory for ARGB cursor, if we can. */
1736 sc->argb_cursor = contigmalloc(size, M_AGP,
1737 0, 0, ~0, PAGE_SIZE, 0);
1738 if (sc->argb_cursor == NULL)
1743 mem = malloc(sizeof *mem, M_AGP, M_WAITOK);
1744 mem->am_id = sc->agp.as_nextid++;
1745 mem->am_size = size;
1746 mem->am_type = type;
1747 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
1748 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
1749 atop(round_page(size)));
1754 if (size == AGP_PAGE_SIZE) {
1756 * Allocate and wire down the page now so that we can
1757 * get its physical address.
1759 VM_OBJECT_WLOCK(mem->am_obj);
1760 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NOBUSY |
1761 VM_ALLOC_WIRED | VM_ALLOC_ZERO);
1762 VM_OBJECT_WUNLOCK(mem->am_obj);
1763 mem->am_physical = VM_PAGE_TO_PHYS(m);
1765 /* Our allocation is already nicely wired down for us.
1766 * Just grab the physical address.
1768 mem->am_physical = vtophys(sc->argb_cursor);
1771 mem->am_physical = 0;
1774 mem->am_is_bound = 0;
1775 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
1776 sc->agp.as_allocated += size;
1782 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
1784 struct agp_i810_softc *sc;
1787 if (mem->am_is_bound)
1790 sc = device_get_softc(dev);
1792 if (mem->am_type == 2) {
1793 if (mem->am_size == AGP_PAGE_SIZE) {
1795 * Unwire the page which we wired in alloc_memory.
1797 VM_OBJECT_WLOCK(mem->am_obj);
1798 m = vm_page_lookup(mem->am_obj, 0);
1800 vm_page_unwire(m, PQ_INACTIVE);
1802 VM_OBJECT_WUNLOCK(mem->am_obj);
1804 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
1805 sc->argb_cursor = NULL;
1809 sc->agp.as_allocated -= mem->am_size;
1810 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
1812 vm_object_deallocate(mem->am_obj);
1818 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
1820 struct agp_i810_softc *sc;
1823 /* Do some sanity checks first. */
1824 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
1825 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
1826 device_printf(dev, "binding memory at bad offset %#x\n",
1831 sc = device_get_softc(dev);
1832 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1833 mtx_lock(&sc->agp.as_lock);
1834 if (mem->am_is_bound) {
1835 mtx_unlock(&sc->agp.as_lock);
1838 /* The memory's already wired down, just stick it in the GTT. */
1839 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1840 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
1841 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
1843 mem->am_offset = offset;
1844 mem->am_is_bound = 1;
1845 mtx_unlock(&sc->agp.as_lock);
1849 if (mem->am_type != 1)
1850 return (agp_generic_bind_memory(dev, mem, offset));
1853 * Mapping local DRAM into GATT.
1855 if (sc->match->driver->chiptype != CHIP_I810)
1857 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
1858 bus_write_4(sc->sc_res[0],
1859 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
1865 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
1867 struct agp_i810_softc *sc;
1870 sc = device_get_softc(dev);
1872 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1873 mtx_lock(&sc->agp.as_lock);
1874 if (!mem->am_is_bound) {
1875 mtx_unlock(&sc->agp.as_lock);
1879 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1880 sc->match->driver->install_gtt_pte(dev,
1881 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
1883 mem->am_is_bound = 0;
1884 mtx_unlock(&sc->agp.as_lock);
1888 if (mem->am_type != 1)
1889 return (agp_generic_unbind_memory(dev, mem));
1891 if (sc->match->driver->chiptype != CHIP_I810)
1893 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1894 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
1900 static device_method_t agp_i810_methods[] = {
1901 /* Device interface */
1902 DEVMETHOD(device_identify, agp_i810_identify),
1903 DEVMETHOD(device_probe, agp_i810_probe),
1904 DEVMETHOD(device_attach, agp_i810_attach),
1905 DEVMETHOD(device_detach, agp_i810_detach),
1906 DEVMETHOD(device_suspend, bus_generic_suspend),
1907 DEVMETHOD(device_resume, agp_i810_resume),
1910 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
1911 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
1912 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
1913 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
1914 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
1915 DEVMETHOD(agp_enable, agp_i810_enable),
1916 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
1917 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
1918 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
1919 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
1920 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
1925 static driver_t agp_i810_driver = {
1928 sizeof(struct agp_i810_softc),
1931 static devclass_t agp_devclass;
1933 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, 0, 0);
1934 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
1935 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
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_install_pte(device_t dev, u_int index, vm_paddr_t addr,
2251 struct agp_i810_softc *sc;
2253 sc = device_get_softc(dev);
2254 sc->match->driver->install_gtt_pte(dev, index, addr, flags);
2258 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2259 u_int first_entry, u_int flags)
2261 struct agp_i810_softc *sc;
2266 sc = device_get_softc(dev);
2267 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2268 spaddr = sg_list->sg_segs[i].ss_paddr;
2269 slen = sg_list->sg_segs[i].ss_len;
2270 for (; slen > 0; i++) {
2271 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2273 spaddr += AGP_PAGE_SIZE;
2274 slen -= AGP_PAGE_SIZE;
2277 sc->match->driver->read_gtt_pte(dev, first_entry + i - 1);
2281 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2284 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2288 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2292 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2300 intel_private.base = agp_intel_gtt_get(intel_agp);
2301 return (&intel_private.base);
2305 intel_gtt_chipset_flush(void)
2308 return (agp_intel_gtt_chipset_flush(intel_agp));
2312 intel_gtt_unmap_memory(struct sglist *sg_list)
2315 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2319 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2320 struct sglist **sg_list)
2323 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2328 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2332 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2336 intel_gtt_install_pte(u_int index, vm_paddr_t addr, u_int flags)
2339 agp_intel_gtt_install_pte(intel_agp, index, addr, flags);
2343 intel_gtt_get_bridge_device(void)
2345 struct agp_i810_softc *sc;
2347 sc = device_get_softc(intel_agp);
2352 intel_gtt_read_pte_paddr(u_int entry)
2354 struct agp_i810_softc *sc;
2356 sc = device_get_softc(intel_agp);
2357 return (sc->match->driver->read_gtt_pte_paddr(intel_agp, entry));
2361 intel_gtt_read_pte(u_int entry)
2363 struct agp_i810_softc *sc;
2365 sc = device_get_softc(intel_agp);
2366 return (sc->match->driver->read_gtt_pte(intel_agp, entry));
2370 intel_gtt_write(u_int entry, uint32_t val)
2372 struct agp_i810_softc *sc;
2374 sc = device_get_softc(intel_agp);
2375 return (sc->match->driver->write_gtt(intel_agp, entry, val));