2 * Copyright (c) 2000 Doug Rabson
3 * Copyright (c) 2000 Ruslan Ermilov
4 * Copyright (c) 2011 The FreeBSD Foundation
7 * Portions of this software were developed by Konstantin Belousov
8 * under sponsorship from the FreeBSD Foundation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Fixes for 830/845G support: David Dawes <dawes@xfree86.org>
34 * 852GM/855GM/865G support added by David Dawes <dawes@xfree86.org>
36 * This is generic Intel GTT handling code, morphed from the AGP
41 #define KTR_AGP_I810 KTR_DEV
43 #define KTR_AGP_I810 0
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
55 #include <bus/pci/pcivar.h>
56 #include <bus/pci/pcireg.h>
59 #include <drm/intel-gtt.h>
62 #include <vm/vm_object.h>
63 #include <vm/vm_page.h>
64 #include <vm/vm_param.h>
65 #include <vm/vm_pageout.h>
68 #include <vm/vm_page2.h>
70 #include <machine/md_var.h>
72 #define bus_read_1(r, o) \
73 bus_space_read_1((r)->r_bustag, (r)->r_bushandle, (o))
74 #define bus_read_4(r, o) \
75 bus_space_read_4((r)->r_bustag, (r)->r_bushandle, (o))
76 #define bus_write_4(r, o, v) \
77 bus_space_write_4((r)->r_bustag, (r)->r_bushandle, (o), (v))
79 MALLOC_DECLARE(M_AGP);
81 struct agp_i810_match;
83 static int agp_i915_check_active(device_t bridge_dev);
84 static int agp_sb_check_active(device_t bridge_dev);
86 static void agp_i810_set_desc(device_t dev, const struct agp_i810_match *match);
88 static void agp_i915_dump_regs(device_t dev);
89 static void agp_i965_dump_regs(device_t dev);
90 static void agp_sb_dump_regs(device_t dev);
92 static int agp_i915_get_stolen_size(device_t dev);
93 static int agp_sb_get_stolen_size(device_t dev);
94 static int agp_gen8_get_stolen_size(device_t dev);
96 static int agp_i915_get_gtt_mappable_entries(device_t dev);
98 static int agp_i810_get_gtt_total_entries(device_t dev);
99 static int agp_i965_get_gtt_total_entries(device_t dev);
100 static int agp_gen5_get_gtt_total_entries(device_t dev);
101 static int agp_sb_get_gtt_total_entries(device_t dev);
102 static int agp_gen8_get_gtt_total_entries(device_t dev);
104 static int agp_i830_install_gatt(device_t dev);
105 static int agp_sb_install_gatt(device_t dev);
106 static int agp_vlv_install_gatt(device_t dev);
108 static void agp_i830_deinstall_gatt(device_t dev);
109 static void agp_sb_deinstall_gatt(device_t dev);
111 static void agp_i915_install_gtt_pte(device_t dev, u_int index,
112 vm_offset_t physical, int flags);
113 static void agp_i965_install_gtt_pte(device_t dev, u_int index,
114 vm_offset_t physical, int flags);
115 static void agp_g4x_install_gtt_pte(device_t dev, u_int index,
116 vm_offset_t physical, int flags);
117 static void agp_sb_install_gtt_pte(device_t dev, u_int index,
118 vm_offset_t physical, int flags);
119 static void agp_vlv_install_gtt_pte(device_t dev, u_int index,
120 vm_offset_t physical, int flags);
121 static void agp_gen8_install_gtt_pte(device_t dev, u_int index,
122 vm_offset_t physical, int flags);
124 static void agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte);
125 static void agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte);
126 static void agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte);
127 static void agp_sb_write_gtt(device_t dev, u_int index, uint32_t pte);
129 static void agp_i915_sync_gtt_pte(device_t dev, u_int index);
130 static void agp_i965_sync_gtt_pte(device_t dev, u_int index);
131 static void agp_g4x_sync_gtt_pte(device_t dev, u_int index);
133 static int agp_i915_set_aperture(device_t dev, u_int32_t aperture);
135 static int agp_i810_chipset_flush_setup(device_t dev);
136 static int agp_i915_chipset_flush_setup(device_t dev);
137 static int agp_i965_chipset_flush_setup(device_t dev);
139 static void agp_i810_chipset_flush_teardown(device_t dev);
140 static void agp_i915_chipset_flush_teardown(device_t dev);
141 static void agp_i965_chipset_flush_teardown(device_t dev);
143 static void agp_i810_chipset_flush(device_t dev);
144 static void agp_i915_chipset_flush(device_t dev);
147 CHIP_I810, /* i810/i815 */
148 CHIP_I830, /* 830M/845G */
149 CHIP_I855, /* 852GM/855GM/865G */
150 CHIP_I915, /* 915G/915GM */
151 CHIP_I965, /* G965 */
152 CHIP_G33, /* G33/Q33/Q35 */
153 CHIP_IGD, /* Pineview */
154 CHIP_G4X, /* G45/Q45 */
155 CHIP_SB, /* SandyBridge */
158 /* The i810 through i855 have the registers at BAR 1, and the GATT gets
159 * allocated by us. The i915 has registers in BAR 0 and the GATT is at the
160 * start of the stolen memory, and should only be accessed by the OS through
161 * BAR 3. The G965 has registers and GATT in the same BAR (0) -- first 512KB
162 * is registers, second 512KB is GATT.
164 static struct resource_spec agp_i915_res_spec[] = {
165 { SYS_RES_MEMORY, AGP_I915_MMADR, RF_ACTIVE | RF_SHAREABLE },
166 { SYS_RES_MEMORY, AGP_I915_GTTADR, RF_ACTIVE | RF_SHAREABLE },
170 static struct resource_spec agp_i965_res_spec[] = {
171 { SYS_RES_MEMORY, AGP_I965_GTTMMADR, RF_ACTIVE | RF_SHAREABLE },
175 static struct resource_spec agp_g4x_res_spec[] = {
176 { SYS_RES_MEMORY, AGP_G4X_MMADR, RF_ACTIVE | RF_SHAREABLE },
177 { SYS_RES_MEMORY, AGP_G4X_GTTADR, RF_ACTIVE | RF_SHAREABLE },
181 struct agp_i810_softc {
182 struct agp_softc agp;
183 u_int32_t initial_aperture; /* aperture size at startup */
184 struct agp_gatt *gatt;
185 u_int32_t dcache_size; /* i810 only */
186 u_int32_t stolen; /* number of i830/845 gtt
187 entries for stolen memory */
188 u_int stolen_size; /* BIOS-reserved graphics memory */
189 u_int gtt_total_entries; /* Total number of gtt ptes */
190 u_int gtt_mappable_entries; /* Number of gtt ptes mappable by CPU */
191 device_t bdev; /* bridge device */
192 void *argb_cursor; /* contigmalloc area for ARGB cursor */
193 struct resource *sc_res[3];
194 const struct agp_i810_match *match;
195 int sc_flush_page_rid;
196 struct resource *sc_flush_page_res;
197 void *sc_flush_page_vaddr;
198 int sc_bios_allocated_flush_page;
201 static device_t intel_agp;
203 struct agp_i810_driver {
206 int busdma_addr_mask_sz;
207 struct resource_spec *res_spec;
208 int (*check_active)(device_t);
209 void (*set_desc)(device_t, const struct agp_i810_match *);
210 void (*dump_regs)(device_t);
211 int (*get_stolen_size)(device_t);
212 int (*get_gtt_total_entries)(device_t);
213 int (*get_gtt_mappable_entries)(device_t);
214 int (*install_gatt)(device_t);
215 void (*deinstall_gatt)(device_t);
216 void (*write_gtt)(device_t, u_int, uint32_t);
217 void (*install_gtt_pte)(device_t, u_int, vm_offset_t, int);
218 void (*sync_gtt_pte)(device_t, u_int);
219 int (*set_aperture)(device_t, u_int32_t);
220 int (*chipset_flush_setup)(device_t);
221 void (*chipset_flush_teardown)(device_t);
222 void (*chipset_flush)(device_t);
226 struct intel_gtt base;
229 static const struct agp_i810_driver agp_i810_i915_driver = {
230 .chiptype = CHIP_I915,
232 .busdma_addr_mask_sz = 32,
233 .res_spec = agp_i915_res_spec,
234 .check_active = agp_i915_check_active,
235 .set_desc = agp_i810_set_desc,
236 .dump_regs = agp_i915_dump_regs,
237 .get_stolen_size = agp_i915_get_stolen_size,
238 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
239 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
240 .install_gatt = agp_i830_install_gatt,
241 .deinstall_gatt = agp_i830_deinstall_gatt,
242 .write_gtt = agp_i915_write_gtt,
243 .install_gtt_pte = agp_i915_install_gtt_pte,
244 .sync_gtt_pte = agp_i915_sync_gtt_pte,
245 .set_aperture = agp_i915_set_aperture,
246 .chipset_flush_setup = agp_i915_chipset_flush_setup,
247 .chipset_flush_teardown = agp_i915_chipset_flush_teardown,
248 .chipset_flush = agp_i915_chipset_flush,
251 static const struct agp_i810_driver agp_i810_g965_driver = {
252 .chiptype = CHIP_I965,
254 .busdma_addr_mask_sz = 36,
255 .res_spec = agp_i965_res_spec,
256 .check_active = agp_i915_check_active,
257 .set_desc = agp_i810_set_desc,
258 .dump_regs = agp_i965_dump_regs,
259 .get_stolen_size = agp_i915_get_stolen_size,
260 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
261 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
262 .install_gatt = agp_i830_install_gatt,
263 .deinstall_gatt = agp_i830_deinstall_gatt,
264 .write_gtt = agp_i965_write_gtt,
265 .install_gtt_pte = agp_i965_install_gtt_pte,
266 .sync_gtt_pte = agp_i965_sync_gtt_pte,
267 .set_aperture = agp_i915_set_aperture,
268 .chipset_flush_setup = agp_i965_chipset_flush_setup,
269 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
270 .chipset_flush = agp_i915_chipset_flush,
273 static const struct agp_i810_driver agp_i810_g33_driver = {
274 .chiptype = CHIP_G33,
276 .busdma_addr_mask_sz = 36,
277 .res_spec = agp_i915_res_spec,
278 .check_active = agp_i915_check_active,
279 .set_desc = agp_i810_set_desc,
280 .dump_regs = agp_i965_dump_regs,
281 .get_stolen_size = agp_i915_get_stolen_size,
282 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
283 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
284 .install_gatt = agp_i830_install_gatt,
285 .deinstall_gatt = agp_i830_deinstall_gatt,
286 .write_gtt = agp_i915_write_gtt,
287 .install_gtt_pte = agp_i965_install_gtt_pte,
288 .sync_gtt_pte = agp_i915_sync_gtt_pte,
289 .set_aperture = agp_i915_set_aperture,
290 .chipset_flush_setup = agp_i965_chipset_flush_setup,
291 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
292 .chipset_flush = agp_i915_chipset_flush,
295 static const struct agp_i810_driver pineview_gtt_driver = {
296 .chiptype = CHIP_IGD,
298 .busdma_addr_mask_sz = 36,
299 .res_spec = agp_i915_res_spec,
300 .check_active = agp_i915_check_active,
301 .set_desc = agp_i810_set_desc,
302 .dump_regs = agp_i915_dump_regs,
303 .get_stolen_size = agp_i915_get_stolen_size,
304 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
305 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
306 .install_gatt = agp_i830_install_gatt,
307 .deinstall_gatt = agp_i830_deinstall_gatt,
308 .write_gtt = agp_i915_write_gtt,
309 .install_gtt_pte = agp_i965_install_gtt_pte,
310 .sync_gtt_pte = agp_i915_sync_gtt_pte,
311 .set_aperture = agp_i915_set_aperture,
312 .chipset_flush_setup = agp_i965_chipset_flush_setup,
313 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
314 .chipset_flush = agp_i915_chipset_flush,
317 static const struct agp_i810_driver agp_i810_g4x_driver = {
318 .chiptype = CHIP_G4X,
320 .busdma_addr_mask_sz = 36,
321 .res_spec = agp_i965_res_spec,
322 .check_active = agp_i915_check_active,
323 .set_desc = agp_i810_set_desc,
324 .dump_regs = agp_i965_dump_regs,
325 .get_stolen_size = agp_i915_get_stolen_size,
326 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
327 .get_gtt_total_entries = agp_gen5_get_gtt_total_entries,
328 .install_gatt = agp_i830_install_gatt,
329 .deinstall_gatt = agp_i830_deinstall_gatt,
330 .write_gtt = agp_g4x_write_gtt,
331 .install_gtt_pte = agp_g4x_install_gtt_pte,
332 .sync_gtt_pte = agp_g4x_sync_gtt_pte,
333 .set_aperture = agp_i915_set_aperture,
334 .chipset_flush_setup = agp_i965_chipset_flush_setup,
335 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
336 .chipset_flush = agp_i915_chipset_flush,
339 static const struct agp_i810_driver agp_i810_sb_driver = {
342 .busdma_addr_mask_sz = 40,
343 .res_spec = agp_g4x_res_spec,
344 .check_active = agp_sb_check_active,
345 .set_desc = agp_i810_set_desc,
346 .dump_regs = agp_sb_dump_regs,
347 .get_stolen_size = agp_sb_get_stolen_size,
348 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
349 .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
350 .install_gatt = agp_sb_install_gatt,
351 .deinstall_gatt = agp_sb_deinstall_gatt,
352 .write_gtt = agp_sb_write_gtt,
353 .install_gtt_pte = agp_sb_install_gtt_pte,
354 .sync_gtt_pte = agp_g4x_sync_gtt_pte,
355 .set_aperture = agp_i915_set_aperture,
356 .chipset_flush_setup = agp_i810_chipset_flush_setup,
357 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
358 .chipset_flush = agp_i810_chipset_flush,
361 static const struct agp_i810_driver valleyview_gtt_driver = {
364 .busdma_addr_mask_sz = 40,
365 .res_spec = agp_g4x_res_spec,
366 .check_active = NULL,
367 .set_desc = agp_i810_set_desc,
368 .dump_regs = agp_sb_dump_regs,
369 .get_stolen_size = agp_sb_get_stolen_size,
370 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
371 .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
372 .install_gatt = agp_vlv_install_gatt,
373 .deinstall_gatt = agp_sb_deinstall_gatt,
374 .write_gtt = agp_sb_write_gtt,
375 .install_gtt_pte = agp_vlv_install_gtt_pte,
376 .sync_gtt_pte = agp_g4x_sync_gtt_pte,
377 .set_aperture = agp_i915_set_aperture,
378 .chipset_flush_setup = agp_i810_chipset_flush_setup,
379 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
380 .chipset_flush = agp_i810_chipset_flush,
383 static const struct agp_i810_driver broadwell_gtt_driver = {
386 .busdma_addr_mask_sz = 40,
387 .res_spec = agp_g4x_res_spec,
388 .check_active = agp_sb_check_active,
389 .set_desc = agp_i810_set_desc,
390 .dump_regs = agp_sb_dump_regs,
391 .get_stolen_size = agp_gen8_get_stolen_size,
392 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
393 .get_gtt_total_entries = agp_gen8_get_gtt_total_entries,
394 .install_gatt = agp_i830_install_gatt,
395 .deinstall_gatt = agp_i830_deinstall_gatt,
397 .install_gtt_pte = agp_gen8_install_gtt_pte,
398 .sync_gtt_pte = agp_g4x_sync_gtt_pte,
399 .set_aperture = agp_i915_set_aperture,
400 .chipset_flush_setup = agp_i810_chipset_flush_setup,
401 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
402 .chipset_flush = agp_i810_chipset_flush,
405 /* For adding new devices, devid is the id of the graphics controller
406 * (pci:0:2:0, for example). The placeholder (usually at pci:0:2:1) for the
407 * second head should never be added. The bridge_offset is the offset to
408 * subtract from devid to get the id of the hostb that the device is on.
410 static const struct agp_i810_match {
413 const struct agp_i810_driver *driver;
414 } agp_i810_matches[] = {
417 .name = "Intel 82915G (915G GMCH) SVGA controller",
418 .driver = &agp_i810_i915_driver
422 .name = "Intel E7221 SVGA controller",
423 .driver = &agp_i810_i915_driver
427 .name = "Intel 82915GM (915GM GMCH) SVGA controller",
428 .driver = &agp_i810_i915_driver
432 .name = "Intel 82945G (945G GMCH) SVGA controller",
433 .driver = &agp_i810_i915_driver
437 .name = "Intel 82945GM (945GM GMCH) SVGA controller",
438 .driver = &agp_i810_i915_driver
442 .name = "Intel 945GME SVGA controller",
443 .driver = &agp_i810_i915_driver
447 .name = "Intel 946GZ SVGA controller",
448 .driver = &agp_i810_g965_driver
452 .name = "Intel G965 SVGA controller",
453 .driver = &agp_i810_g965_driver
457 .name = "Intel Q965 SVGA controller",
458 .driver = &agp_i810_g965_driver
462 .name = "Intel G965 SVGA controller",
463 .driver = &agp_i810_g965_driver
467 .name = "Intel Q35 SVGA controller",
468 .driver = &agp_i810_g33_driver
472 .name = "Intel G33 SVGA controller",
473 .driver = &agp_i810_g33_driver
477 .name = "Intel Q33 SVGA controller",
478 .driver = &agp_i810_g33_driver
482 .name = "Intel Pineview SVGA controller",
483 .driver = &pineview_gtt_driver
487 .name = "Intel Pineview (M) SVGA controller",
488 .driver = &pineview_gtt_driver
492 .name = "Intel GM965 SVGA controller",
493 .driver = &agp_i810_g965_driver
497 .name = "Intel GME965 SVGA controller",
498 .driver = &agp_i810_g965_driver
502 .name = "Intel GM45 SVGA controller",
503 .driver = &agp_i810_g4x_driver
507 .name = "Intel Eaglelake SVGA controller",
508 .driver = &agp_i810_g4x_driver
512 .name = "Intel Q45 SVGA controller",
513 .driver = &agp_i810_g4x_driver
517 .name = "Intel G45 SVGA controller",
518 .driver = &agp_i810_g4x_driver
522 .name = "Intel G41 SVGA controller",
523 .driver = &agp_i810_g4x_driver
527 .name = "Intel Ironlake (D) SVGA controller",
528 .driver = &agp_i810_g4x_driver
532 .name = "Intel Ironlake (M) SVGA controller",
533 .driver = &agp_i810_g4x_driver
537 .name = "SandyBridge desktop GT1 IG",
538 .driver = &agp_i810_sb_driver
542 .name = "SandyBridge desktop GT2 IG",
543 .driver = &agp_i810_sb_driver
547 .name = "SandyBridge desktop GT2+ IG",
548 .driver = &agp_i810_sb_driver
552 .name = "SandyBridge mobile GT1 IG",
553 .driver = &agp_i810_sb_driver
557 .name = "SandyBridge mobile GT2 IG",
558 .driver = &agp_i810_sb_driver
562 .name = "SandyBridge mobile GT2+ IG",
563 .driver = &agp_i810_sb_driver
567 .name = "SandyBridge server IG",
568 .driver = &agp_i810_sb_driver
572 .name = "IvyBridge desktop GT1 IG",
573 .driver = &agp_i810_sb_driver
577 .name = "IvyBridge desktop GT2 IG",
578 .driver = &agp_i810_sb_driver
582 .name = "IvyBridge mobile GT1 IG",
583 .driver = &agp_i810_sb_driver
587 .name = "IvyBridge mobile GT2 IG",
588 .driver = &agp_i810_sb_driver
592 .name = "IvyBridge server GT1 IG",
593 .driver = &agp_i810_sb_driver
597 .name = "IvyBridge server GT2 IG",
598 .driver = &agp_i810_sb_driver
601 { 0x0f30, "ValleyView/Baytrail", &valleyview_gtt_driver },
602 { 0x0f31, "ValleyView/Baytrail", &valleyview_gtt_driver },
603 { 0x0f32, "ValleyView/Baytrail", &valleyview_gtt_driver },
604 { 0x0f33, "ValleyView/Baytrail", &valleyview_gtt_driver },
605 { 0x0155, "ValleyView/Baytrail", &valleyview_gtt_driver },
606 { 0x0157, "ValleyView/Baytrail", &valleyview_gtt_driver },
610 .name = "Haswell desktop GT1 IG",
611 .driver = &agp_i810_sb_driver
615 .name = "Haswell desktop GT2 IG",
616 .driver = &agp_i810_sb_driver
618 { 0x041e, "Haswell", &agp_i810_sb_driver },
619 { 0x0422, "Haswell", &agp_i810_sb_driver },
622 .name = "Haswell mobile GT1 IG",
623 .driver = &agp_i810_sb_driver
627 .name = "Haswell mobile GT2 IG",
628 .driver = &agp_i810_sb_driver
630 { 0x0426, "Haswell", &agp_i810_sb_driver },
633 .name = "Haswell server GT1 IG",
634 .driver = &agp_i810_sb_driver
638 .name = "Haswell server GT2 IG",
639 .driver = &agp_i810_sb_driver
641 { 0x042a, "Haswell", &agp_i810_sb_driver },
642 { 0x0c02, "Haswell", &agp_i810_sb_driver },
643 { 0x0c12, "Haswell", &agp_i810_sb_driver },
644 { 0x0c22, "Haswell", &agp_i810_sb_driver },
645 { 0x0c06, "Haswell", &agp_i810_sb_driver },
648 .name = "Haswell SDV",
649 .driver = &agp_i810_sb_driver
651 { 0x0c26, "Haswell", &agp_i810_sb_driver },
652 { 0x0c0a, "Haswell", &agp_i810_sb_driver },
653 { 0x0c1a, "Haswell", &agp_i810_sb_driver },
654 { 0x0c2a, "Haswell", &agp_i810_sb_driver },
655 { 0x0a02, "Haswell", &agp_i810_sb_driver },
656 { 0x0a12, "Haswell", &agp_i810_sb_driver },
657 { 0x0a22, "Haswell", &agp_i810_sb_driver },
658 { 0x0a06, "Haswell", &agp_i810_sb_driver },
659 { 0x0a16, "Haswell", &agp_i810_sb_driver },
660 { 0x0a26, "Haswell", &agp_i810_sb_driver },
661 { 0x0a0a, "Haswell", &agp_i810_sb_driver },
662 { 0x0a1a, "Haswell", &agp_i810_sb_driver },
663 { 0x0a2a, "Haswell", &agp_i810_sb_driver },
664 { 0x0d12, "Haswell", &agp_i810_sb_driver },
665 { 0x0d22, "Haswell", &agp_i810_sb_driver },
666 { 0x0d32, "Haswell", &agp_i810_sb_driver },
667 { 0x0d16, "Haswell", &agp_i810_sb_driver },
668 { 0x0d26, "Haswell", &agp_i810_sb_driver },
669 { 0x0d36, "Haswell", &agp_i810_sb_driver },
670 { 0x0d1a, "Haswell", &agp_i810_sb_driver },
671 { 0x0d2a, "Haswell", &agp_i810_sb_driver },
672 { 0x0d3a, "Haswell", &agp_i810_sb_driver },
674 { 0x1602, "Broadwell", &broadwell_gtt_driver }, /* m */
675 { 0x1606, "Broadwell", &broadwell_gtt_driver },
676 { 0x160B, "Broadwell", &broadwell_gtt_driver },
677 { 0x160E, "Broadwell", &broadwell_gtt_driver },
678 { 0x1616, "Broadwell", &broadwell_gtt_driver },
679 { 0x161E, "Broadwell", &broadwell_gtt_driver },
681 { 0x160A, "Broadwell", &broadwell_gtt_driver }, /* d */
682 { 0x160D, "Broadwell", &broadwell_gtt_driver },
688 static const struct agp_i810_match*
689 agp_i810_match(device_t dev)
693 if (pci_get_vendor(dev) != PCI_VENDOR_INTEL)
696 devid = pci_get_device(dev);
697 for (i = 0; agp_i810_matches[i].devid != 0; i++) {
698 if (agp_i810_matches[i].devid == devid)
701 if (agp_i810_matches[i].devid == 0)
704 return (&agp_i810_matches[i]);
708 * Find bridge device.
711 agp_i810_find_bridge(device_t dev)
714 return (pci_find_dbsf(0, 0, 0, 0));
718 agp_i810_identify(driver_t *driver, device_t parent)
721 if (device_find_child(parent, "agp", -1) == NULL &&
722 agp_i810_match(parent))
723 device_add_child(parent, "agp", -1);
727 agp_i915_check_active(device_t bridge_dev)
731 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
732 if ((deven & AGP_I915_DEVEN_D2F0) == AGP_I915_DEVEN_D2F0_DISABLED)
738 agp_sb_check_active(device_t bridge_dev)
742 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
743 if ((deven & AGP_SB_DEVEN_D2EN) == AGP_SB_DEVEN_D2EN_DISABLED)
749 agp_i810_set_desc(device_t dev, const struct agp_i810_match *match)
752 device_set_desc(dev, match->name);
756 agp_i810_probe(device_t dev)
759 const struct agp_i810_match *match;
762 if (resource_disabled("agp", device_get_unit(dev)))
764 match = agp_i810_match(dev);
768 bdev = agp_i810_find_bridge(dev);
771 kprintf("I810: can't find bridge device\n");
776 * checking whether internal graphics device has been activated.
778 if (match->driver->check_active != NULL) {
779 err = match->driver->check_active(bdev);
782 kprintf("i810: disabled, not probing\n");
787 match->driver->set_desc(dev, match);
788 return (BUS_PROBE_DEFAULT);
792 agp_i915_dump_regs(device_t dev)
794 struct agp_i810_softc *sc = device_get_softc(dev);
796 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
797 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
798 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
799 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
800 device_printf(dev, "AGP_I915_MSAC: 0x%02x\n",
801 pci_read_config(sc->bdev, AGP_I915_MSAC, 1));
805 agp_i965_dump_regs(device_t dev)
807 struct agp_i810_softc *sc = device_get_softc(dev);
809 device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
810 bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
811 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
812 pci_read_config(dev, AGP_I855_GCC1, 1));
813 device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
814 pci_read_config(dev, AGP_I965_MSAC, 1));
818 agp_sb_dump_regs(device_t dev)
820 struct agp_i810_softc *sc = device_get_softc(dev);
822 device_printf(dev, "AGP_SNB_GFX_MODE: %08x\n",
823 bus_read_4(sc->sc_res[0], AGP_SNB_GFX_MODE));
824 device_printf(dev, "AGP_SNB_GCC1: 0x%04x\n",
825 pci_read_config(dev, AGP_SNB_GCC1, 2));
829 agp_i915_get_stolen_size(device_t dev)
831 struct agp_i810_softc *sc;
832 unsigned int gcc1, stolen, gtt_size;
834 sc = device_get_softc(dev);
837 * Stolen memory is set up at the beginning of the aperture by
838 * the BIOS, consisting of the GATT followed by 4kb for the
841 switch (sc->match->driver->chiptype) {
849 switch (bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL) &
850 AGP_I810_PGTBL_SIZE_MASK) {
851 case AGP_I810_PGTBL_SIZE_128KB:
854 case AGP_I810_PGTBL_SIZE_256KB:
857 case AGP_I810_PGTBL_SIZE_512KB:
860 case AGP_I965_PGTBL_SIZE_1MB:
863 case AGP_I965_PGTBL_SIZE_2MB:
866 case AGP_I965_PGTBL_SIZE_1_5MB:
867 gtt_size = 1024 + 512;
870 device_printf(dev, "Bad PGTBL size\n");
875 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 2);
876 switch (gcc1 & AGP_G33_MGGC_GGMS_MASK) {
877 case AGP_G33_MGGC_GGMS_SIZE_1M:
880 case AGP_G33_MGGC_GGMS_SIZE_2M:
884 device_printf(dev, "Bad PGTBL size\n");
893 device_printf(dev, "Bad chiptype\n");
897 /* GCC1 is called MGGC on i915+ */
898 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
899 switch (gcc1 & AGP_I855_GCC1_GMS) {
900 case AGP_I855_GCC1_GMS_STOLEN_1M:
903 case AGP_I855_GCC1_GMS_STOLEN_4M:
906 case AGP_I855_GCC1_GMS_STOLEN_8M:
909 case AGP_I855_GCC1_GMS_STOLEN_16M:
912 case AGP_I855_GCC1_GMS_STOLEN_32M:
915 case AGP_I915_GCC1_GMS_STOLEN_48M:
916 stolen = sc->match->driver->gen > 2 ? 48 * 1024 : 0;
918 case AGP_I915_GCC1_GMS_STOLEN_64M:
919 stolen = sc->match->driver->gen > 2 ? 64 * 1024 : 0;
921 case AGP_G33_GCC1_GMS_STOLEN_128M:
922 stolen = sc->match->driver->gen > 2 ? 128 * 1024 : 0;
924 case AGP_G33_GCC1_GMS_STOLEN_256M:
925 stolen = sc->match->driver->gen > 2 ? 256 * 1024 : 0;
927 case AGP_G4X_GCC1_GMS_STOLEN_96M:
928 if (sc->match->driver->chiptype == CHIP_I965 ||
929 sc->match->driver->chiptype == CHIP_G4X)
934 case AGP_G4X_GCC1_GMS_STOLEN_160M:
935 if (sc->match->driver->chiptype == CHIP_I965 ||
936 sc->match->driver->chiptype == CHIP_G4X)
941 case AGP_G4X_GCC1_GMS_STOLEN_224M:
942 if (sc->match->driver->chiptype == CHIP_I965 ||
943 sc->match->driver->chiptype == CHIP_G4X)
948 case AGP_G4X_GCC1_GMS_STOLEN_352M:
949 if (sc->match->driver->chiptype == CHIP_I965 ||
950 sc->match->driver->chiptype == CHIP_G4X)
957 "unknown memory configuration, disabling (GCC1 %x)\n",
963 sc->stolen_size = stolen * 1024;
964 sc->stolen = (stolen - gtt_size) * 1024 / 4096;
970 agp_sb_get_stolen_size(device_t dev)
972 struct agp_i810_softc *sc;
975 sc = device_get_softc(dev);
976 gmch_ctl = pci_read_config(dev, AGP_SNB_GCC1, 2);
978 switch (gmch_ctl & AGP_SNB_GMCH_GMS_STOLEN_MASK) {
979 case AGP_SNB_GMCH_GMS_STOLEN_32M:
980 sc->stolen_size = 32 * 1024 * 1024;
982 case AGP_SNB_GMCH_GMS_STOLEN_64M:
983 sc->stolen_size = 64 * 1024 * 1024;
985 case AGP_SNB_GMCH_GMS_STOLEN_96M:
986 sc->stolen_size = 96 * 1024 * 1024;
988 case AGP_SNB_GMCH_GMS_STOLEN_128M:
989 sc->stolen_size = 128 * 1024 * 1024;
991 case AGP_SNB_GMCH_GMS_STOLEN_160M:
992 sc->stolen_size = 160 * 1024 * 1024;
994 case AGP_SNB_GMCH_GMS_STOLEN_192M:
995 sc->stolen_size = 192 * 1024 * 1024;
997 case AGP_SNB_GMCH_GMS_STOLEN_224M:
998 sc->stolen_size = 224 * 1024 * 1024;
1000 case AGP_SNB_GMCH_GMS_STOLEN_256M:
1001 sc->stolen_size = 256 * 1024 * 1024;
1003 case AGP_SNB_GMCH_GMS_STOLEN_288M:
1004 sc->stolen_size = 288 * 1024 * 1024;
1006 case AGP_SNB_GMCH_GMS_STOLEN_320M:
1007 sc->stolen_size = 320 * 1024 * 1024;
1009 case AGP_SNB_GMCH_GMS_STOLEN_352M:
1010 sc->stolen_size = 352 * 1024 * 1024;
1012 case AGP_SNB_GMCH_GMS_STOLEN_384M:
1013 sc->stolen_size = 384 * 1024 * 1024;
1015 case AGP_SNB_GMCH_GMS_STOLEN_416M:
1016 sc->stolen_size = 416 * 1024 * 1024;
1018 case AGP_SNB_GMCH_GMS_STOLEN_448M:
1019 sc->stolen_size = 448 * 1024 * 1024;
1021 case AGP_SNB_GMCH_GMS_STOLEN_480M:
1022 sc->stolen_size = 480 * 1024 * 1024;
1024 case AGP_SNB_GMCH_GMS_STOLEN_512M:
1025 sc->stolen_size = 512 * 1024 * 1024;
1028 sc->stolen = (sc->stolen_size - 4) / 4096;
1033 agp_gen8_get_stolen_size(device_t dev)
1035 struct agp_i810_softc *sc;
1039 sc = device_get_softc(dev);
1040 gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
1041 v = (gcc1 >> 8) & 0xFF;
1042 sc->stolen_size = v * (32L * 1024 * 1024); /* 32MB increments */
1048 agp_i915_get_gtt_mappable_entries(device_t dev)
1050 struct agp_i810_softc *sc;
1053 sc = device_get_softc(dev);
1054 ap = AGP_GET_APERTURE(dev);
1055 sc->gtt_mappable_entries = ap >> AGP_PAGE_SHIFT;
1060 agp_i810_get_gtt_total_entries(device_t dev)
1062 struct agp_i810_softc *sc;
1064 sc = device_get_softc(dev);
1065 sc->gtt_total_entries = sc->gtt_mappable_entries;
1070 agp_i965_get_gtt_total_entries(device_t dev)
1072 struct agp_i810_softc *sc;
1073 uint32_t pgetbl_ctl;
1076 sc = device_get_softc(dev);
1078 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1079 switch (pgetbl_ctl & AGP_I810_PGTBL_SIZE_MASK) {
1080 case AGP_I810_PGTBL_SIZE_128KB:
1081 sc->gtt_total_entries = 128 * 1024 / 4;
1083 case AGP_I810_PGTBL_SIZE_256KB:
1084 sc->gtt_total_entries = 256 * 1024 / 4;
1086 case AGP_I810_PGTBL_SIZE_512KB:
1087 sc->gtt_total_entries = 512 * 1024 / 4;
1089 /* GTT pagetable sizes bigger than 512KB are not possible on G33! */
1090 case AGP_I810_PGTBL_SIZE_1MB:
1091 sc->gtt_total_entries = 1024 * 1024 / 4;
1093 case AGP_I810_PGTBL_SIZE_2MB:
1094 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1096 case AGP_I810_PGTBL_SIZE_1_5MB:
1097 sc->gtt_total_entries = (1024 + 512) * 1024 / 4;
1100 device_printf(dev, "Unknown page table size\n");
1107 agp_gen5_adjust_pgtbl_size(device_t dev, uint32_t sz)
1109 struct agp_i810_softc *sc;
1110 uint32_t pgetbl_ctl, pgetbl_ctl2;
1112 sc = device_get_softc(dev);
1114 /* Disable per-process page table. */
1115 pgetbl_ctl2 = bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2);
1116 pgetbl_ctl2 &= ~AGP_I810_PGTBL_ENABLED;
1117 bus_write_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2, pgetbl_ctl2);
1119 /* Write the new ggtt size. */
1120 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1121 pgetbl_ctl &= ~AGP_I810_PGTBL_SIZE_MASK;
1123 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgetbl_ctl);
1127 agp_gen5_get_gtt_total_entries(device_t dev)
1129 struct agp_i810_softc *sc;
1132 sc = device_get_softc(dev);
1134 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1135 switch (gcc1 & AGP_G4x_GCC1_SIZE_MASK) {
1136 case AGP_G4x_GCC1_SIZE_1M:
1137 case AGP_G4x_GCC1_SIZE_VT_1M:
1138 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1MB);
1140 case AGP_G4x_GCC1_SIZE_VT_1_5M:
1141 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1_5MB);
1143 case AGP_G4x_GCC1_SIZE_2M:
1144 case AGP_G4x_GCC1_SIZE_VT_2M:
1145 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_2MB);
1148 device_printf(dev, "Unknown page table size\n");
1152 return (agp_i965_get_gtt_total_entries(dev));
1156 agp_sb_get_gtt_total_entries(device_t dev)
1158 struct agp_i810_softc *sc;
1161 sc = device_get_softc(dev);
1163 gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
1164 switch (gcc1 & AGP_SNB_GTT_SIZE_MASK) {
1166 case AGP_SNB_GTT_SIZE_0M:
1167 kprintf("Bad GTT size mask: 0x%04x\n", gcc1);
1169 case AGP_SNB_GTT_SIZE_1M:
1170 sc->gtt_total_entries = 1024 * 1024 / 4;
1172 case AGP_SNB_GTT_SIZE_2M:
1173 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1180 agp_gen8_get_gtt_total_entries(device_t dev)
1182 struct agp_i810_softc *sc;
1186 sc = device_get_softc(dev);
1188 gcc1 = pci_read_config(dev, AGP_SNB_GCC1, 2);
1189 v = (gcc1 >> 6) & 3;
1192 sc->gtt_total_entries = (v << 20) / 8;
1195 * XXX limit to 2GB due to misc integer overflows calculated on
1198 while ((long)sc->gtt_total_entries * PAGE_SIZE >= 4LL*1024*1024*1024)
1199 sc->gtt_total_entries >>= 1;
1201 kprintf("GTT SIZE %ld representing %ldM vmap\n",
1202 (long)sc->gtt_total_entries * 8,
1203 (long)sc->gtt_total_entries * PAGE_SIZE);
1209 agp_i830_install_gatt(device_t dev)
1211 struct agp_i810_softc *sc;
1214 sc = device_get_softc(dev);
1217 * The i830 automatically initializes the 128k gatt on boot.
1218 * GATT address is already in there, make sure it's enabled.
1220 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1222 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1224 sc->gatt->ag_physical = pgtblctl & ~1;
1229 agp_sb_install_gatt(device_t dev)
1231 struct agp_i810_softc *sc;
1234 sc = device_get_softc(dev);
1237 * The i830 automatically initializes the 128k gatt on boot.
1238 * GATT address is already in there, make sure it's enabled.
1240 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1242 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1244 sc->gatt->ag_physical = pgtblctl & ~1;
1249 agp_vlv_install_gatt(device_t dev)
1251 void *pg = contigmalloc(4096, M_AGP, M_WAITOK | M_ZERO,
1252 0x10000, 0xFFFFFFFFU,
1253 PAGE_SIZE, PAGE_SIZE);
1254 struct agp_i810_softc *sc;
1259 * Make the entire aperture valid by pointing to a page of junk
1262 * NOTE: valleyview has not PGTBL_CTL
1264 sc = device_get_softc(dev);
1265 pte = vtophys(pg) | 0x03;
1266 for (i = 0; i < 2 * 1024 * 1024; i += 4)
1267 bus_write_4(sc->sc_res[0], i + (2 * 1024 * 1024), pte);
1273 agp_i810_attach(device_t dev)
1275 struct agp_i810_softc *sc;
1278 sc = device_get_softc(dev);
1279 sc->bdev = agp_i810_find_bridge(dev);
1280 if (sc->bdev == NULL)
1283 sc->match = agp_i810_match(dev);
1285 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1286 AGP_APBASE : AGP_I915_GMADR);
1287 error = agp_generic_attach(dev);
1291 if (ptoa((vm_paddr_t)Maxmem) >
1292 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1293 device_printf(dev, "agp_i810 does not support physical "
1294 "memory above %ju.\n", (uintmax_t)(1ULL <<
1295 sc->match->driver->busdma_addr_mask_sz) - 1);
1299 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1300 agp_generic_detach(dev);
1304 sc->initial_aperture = AGP_GET_APERTURE(dev);
1305 sc->gatt = kmalloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1306 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1308 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1309 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1310 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1311 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1312 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1313 bus_release_resources(dev, sc->match->driver->res_spec,
1315 kfree(sc->gatt, M_AGP);
1316 agp_generic_detach(dev);
1321 device_printf(dev, "aperture size is %dM",
1322 sc->initial_aperture / 1024 / 1024);
1324 kprintf(", detected %dk stolen memory\n", sc->stolen * 4);
1328 sc->match->driver->dump_regs(dev);
1329 device_printf(dev, "Mappable GTT entries: %d\n",
1330 sc->gtt_mappable_entries);
1331 device_printf(dev, "Total GTT entries: %d\n",
1332 sc->gtt_total_entries);
1338 agp_i830_deinstall_gatt(device_t dev)
1340 struct agp_i810_softc *sc;
1341 unsigned int pgtblctl;
1343 sc = device_get_softc(dev);
1344 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1346 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1350 agp_sb_deinstall_gatt(device_t dev)
1352 struct agp_i810_softc *sc;
1353 unsigned int pgtblctl;
1355 sc = device_get_softc(dev);
1356 if (sc->sc_res[0]) {
1357 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1359 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1364 agp_i810_detach(device_t dev)
1366 struct agp_i810_softc *sc;
1368 sc = device_get_softc(dev);
1371 /* Clear the GATT base. */
1372 sc->match->driver->deinstall_gatt(dev);
1374 sc->match->driver->chipset_flush_teardown(dev);
1376 /* Put the aperture back the way it started. */
1377 AGP_SET_APERTURE(dev, sc->initial_aperture);
1379 kfree(sc->gatt, M_AGP);
1380 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1387 agp_i810_resume(device_t dev)
1389 struct agp_i810_softc *sc;
1390 sc = device_get_softc(dev);
1392 AGP_SET_APERTURE(dev, sc->initial_aperture);
1394 /* Install the GATT. */
1395 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1396 sc->gatt->ag_physical | 1);
1398 return (bus_generic_resume(dev));
1402 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1403 * while returning failure on later chipsets when an actual change is
1406 * This whole function is likely bogus, as the kernel would probably need to
1407 * reconfigure the placement of the AGP aperture if a larger size is requested,
1408 * which doesn't happen currently.
1412 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1415 return (agp_generic_set_aperture(dev, aperture));
1419 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1421 struct agp_i810_softc *sc;
1423 sc = device_get_softc(dev);
1424 return (sc->match->driver->set_aperture(dev, aperture));
1428 * Writes a GTT entry mapping the page at the given offset from the
1429 * beginning of the aperture to the given physical address. Setup the
1430 * caching mode according to flags.
1432 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1433 * from corresponding BAR start. For gen 4, offset is 512KB +
1434 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1436 * Also, the bits of the physical page address above 4GB needs to be
1437 * placed into bits 40-32 of PTE.
1440 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1445 pte = (u_int32_t)physical | I810_PTE_VALID;
1446 if (flags == AGP_USER_CACHED_MEMORY)
1447 pte |= I830_PTE_SYSTEM_CACHED;
1449 agp_i915_write_gtt(dev, index, pte);
1453 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1455 struct agp_i810_softc *sc;
1457 sc = device_get_softc(dev);
1458 bus_write_4(sc->sc_res[0], index * 4, pte);
1462 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1467 pte = (u_int32_t)physical | I810_PTE_VALID;
1468 if (flags == AGP_USER_CACHED_MEMORY)
1469 pte |= I830_PTE_SYSTEM_CACHED;
1471 pte |= (physical >> 28) & 0xf0;
1472 agp_i965_write_gtt(dev, index, pte);
1476 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1478 struct agp_i810_softc *sc;
1480 sc = device_get_softc(dev);
1481 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1485 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1490 pte = (u_int32_t)physical | I810_PTE_VALID;
1491 if (flags == AGP_USER_CACHED_MEMORY)
1492 pte |= I830_PTE_SYSTEM_CACHED;
1494 pte |= (physical >> 28) & 0xf0;
1495 agp_g4x_write_gtt(dev, index, pte);
1499 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1501 struct agp_i810_softc *sc;
1503 sc = device_get_softc(dev);
1504 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1508 agp_sb_install_gtt_pte(device_t dev, u_int index,
1509 vm_offset_t physical, int flags)
1511 int type_mask, gfdt;
1514 pte = (u_int32_t)physical | I810_PTE_VALID;
1515 type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT;
1516 gfdt = (flags & AGP_USER_CACHED_MEMORY_GFDT) != 0 ? GEN6_PTE_GFDT : 0;
1518 if (type_mask == AGP_USER_MEMORY)
1519 pte |= GEN6_PTE_UNCACHED;
1520 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC)
1521 pte |= GEN6_PTE_LLC_MLC | gfdt;
1523 pte |= GEN6_PTE_LLC | gfdt;
1525 pte |= (physical & 0x000000ff00000000ull) >> 28;
1526 agp_sb_write_gtt(dev, index, pte);
1529 #define GEN6_PTE_VALID (1 << 0)
1530 #define BYT_PTE_WRITEABLE (1 << 1)
1531 #define BYT_PTE_SNOOPED_BY_CPU_CACHES (1 << 2)
1532 #define GEN6_PTE_ADDR_ENCODE(addr) GEN6_GTT_ADDR_ENCODE(addr)
1533 #define GEN6_GTT_ADDR_ENCODE(addr) ((addr) | (((addr) >> 28) & 0xff0))
1536 agp_vlv_install_gtt_pte(device_t dev, u_int index,
1537 vm_offset_t physical, int flags)
1542 pte = GEN6_PTE_ADDR_ENCODE(physical) | GEN6_PTE_VALID;
1543 pte |= BYT_PTE_WRITEABLE;
1545 type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT;
1546 if (type_mask != AGP_USER_MEMORY) {
1547 pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES;
1548 if (flags & AGP_USER_CACHED_MEMORY_GFDT)
1549 pte |= GEN6_PTE_GFDT;
1551 agp_sb_write_gtt(dev, index, pte);
1555 agp_gen8_install_gtt_pte(device_t dev, u_int index,
1556 vm_offset_t physical, int flags)
1558 struct agp_i810_softc *sc;
1562 pte = (u_int64_t)physical | GEN8_PTE_PRESENT | GEN8_PTE_RW;
1563 type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT;
1565 if (type_mask == AGP_USER_MEMORY)
1566 pte |= GEN8_PTE_PWT; /* XXX */
1567 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC)
1568 pte |= GEN8_PTE_PWT; /* XXX */
1570 pte |= GEN8_PTE_PWT; /* XXX */
1572 sc = device_get_softc(dev);
1573 bus_write_4(sc->sc_res[0], index * 8 + (2 * 1024 * 1024),
1575 bus_write_4(sc->sc_res[0], index * 8 + (2 * 1024 * 1024) + 4,
1576 (uint32_t)(pte >> 32));
1580 agp_sb_write_gtt(device_t dev, u_int index, uint32_t pte)
1582 struct agp_i810_softc *sc;
1584 sc = device_get_softc(dev);
1585 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1589 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1591 struct agp_i810_softc *sc = device_get_softc(dev);
1594 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1595 device_printf(dev, "failed: offset is 0x%08jx, "
1596 "shift is %d, entries is %d\n", (intmax_t)offset,
1597 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1600 index = offset >> AGP_PAGE_SHIFT;
1601 if (sc->stolen != 0 && index < sc->stolen) {
1602 device_printf(dev, "trying to bind into stolen memory\n");
1605 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1610 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1612 struct agp_i810_softc *sc;
1615 sc = device_get_softc(dev);
1616 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1618 index = offset >> AGP_PAGE_SHIFT;
1619 if (sc->stolen != 0 && index < sc->stolen) {
1620 device_printf(dev, "trying to unbind from stolen memory\n");
1623 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1628 agp_i915_sync_gtt_pte(device_t dev, u_int index)
1630 struct agp_i810_softc *sc;
1632 sc = device_get_softc(dev);
1633 bus_read_4(sc->sc_res[1], index * 4);
1637 agp_i965_sync_gtt_pte(device_t dev, u_int index)
1639 struct agp_i810_softc *sc;
1641 sc = device_get_softc(dev);
1642 bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1646 agp_g4x_sync_gtt_pte(device_t dev, u_int index)
1648 struct agp_i810_softc *sc;
1650 sc = device_get_softc(dev);
1651 bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1655 * Writing via memory mapped registers already flushes all TLBs.
1658 agp_i810_flush_tlb(device_t dev)
1663 agp_i810_enable(device_t dev, u_int32_t mode)
1669 static struct agp_memory *
1670 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
1672 struct agp_i810_softc *sc;
1673 struct agp_memory *mem;
1676 sc = device_get_softc(dev);
1678 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
1679 sc->agp.as_allocated + size > sc->agp.as_maxmem)
1684 * Mapping local DRAM into GATT.
1686 if (sc->match->driver->chiptype != CHIP_I810)
1688 if (size != sc->dcache_size)
1690 } else if (type == 2) {
1692 * Type 2 is the contiguous physical memory type, that hands
1693 * back a physical address. This is used for cursors on i810.
1694 * Hand back as many single pages with physical as the user
1695 * wants, but only allow one larger allocation (ARGB cursor)
1698 if (size != AGP_PAGE_SIZE) {
1699 if (sc->argb_cursor != NULL)
1702 /* Allocate memory for ARGB cursor, if we can. */
1703 sc->argb_cursor = contigmalloc(size, M_AGP,
1704 0, 0, ~0, PAGE_SIZE, 0);
1705 if (sc->argb_cursor == NULL)
1710 mem = kmalloc(sizeof *mem, M_AGP, M_INTWAIT);
1711 mem->am_id = sc->agp.as_nextid++;
1712 mem->am_size = size;
1713 mem->am_type = type;
1714 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
1715 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
1716 atop(round_page(size)));
1721 if (size == AGP_PAGE_SIZE) {
1723 * Allocate and wire down the page now so that we can
1724 * get its physical address.
1726 VM_OBJECT_LOCK(mem->am_obj);
1727 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NORMAL |
1731 VM_OBJECT_UNLOCK(mem->am_obj);
1732 mem->am_physical = VM_PAGE_TO_PHYS(m);
1735 /* Our allocation is already nicely wired down for us.
1736 * Just grab the physical address.
1738 mem->am_physical = vtophys(sc->argb_cursor);
1741 mem->am_physical = 0;
1744 mem->am_is_bound = 0;
1745 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
1746 sc->agp.as_allocated += size;
1752 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
1754 struct agp_i810_softc *sc;
1756 if (mem->am_is_bound)
1759 sc = device_get_softc(dev);
1761 if (mem->am_type == 2) {
1762 if (mem->am_size == AGP_PAGE_SIZE) {
1764 * Unwire the page which we wired in alloc_memory.
1768 vm_object_hold(mem->am_obj);
1769 m = vm_page_lookup_busy_wait(mem->am_obj, 0,
1771 vm_object_drop(mem->am_obj);
1772 vm_page_unwire(m, 0);
1775 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
1776 sc->argb_cursor = NULL;
1780 sc->agp.as_allocated -= mem->am_size;
1781 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
1783 vm_object_deallocate(mem->am_obj);
1789 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
1791 struct agp_i810_softc *sc;
1794 /* Do some sanity checks first. */
1795 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
1796 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
1797 device_printf(dev, "binding memory at bad offset %#x\n",
1802 sc = device_get_softc(dev);
1803 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1804 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
1805 if (mem->am_is_bound) {
1806 lockmgr(&sc->agp.as_lock, LK_RELEASE);
1809 /* The memory's already wired down, just stick it in the GTT. */
1810 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1811 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
1812 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
1815 mem->am_offset = offset;
1816 mem->am_is_bound = 1;
1817 lockmgr(&sc->agp.as_lock, LK_RELEASE);
1821 if (mem->am_type != 1)
1822 return (agp_generic_bind_memory(dev, mem, offset));
1825 * Mapping local DRAM into GATT.
1827 if (sc->match->driver->chiptype != CHIP_I810)
1829 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
1830 bus_write_4(sc->sc_res[0],
1831 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
1837 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
1839 struct agp_i810_softc *sc;
1842 sc = device_get_softc(dev);
1844 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
1845 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
1846 if (!mem->am_is_bound) {
1847 lockmgr(&sc->agp.as_lock, LK_RELEASE);
1851 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1852 sc->match->driver->install_gtt_pte(dev,
1853 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
1856 mem->am_is_bound = 0;
1857 lockmgr(&sc->agp.as_lock, LK_RELEASE);
1861 if (mem->am_type != 1)
1862 return (agp_generic_unbind_memory(dev, mem));
1864 if (sc->match->driver->chiptype != CHIP_I810)
1866 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
1867 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
1873 static device_method_t agp_i810_methods[] = {
1874 /* Device interface */
1875 DEVMETHOD(device_identify, agp_i810_identify),
1876 DEVMETHOD(device_probe, agp_i810_probe),
1877 DEVMETHOD(device_attach, agp_i810_attach),
1878 DEVMETHOD(device_detach, agp_i810_detach),
1879 DEVMETHOD(device_suspend, bus_generic_suspend),
1880 DEVMETHOD(device_resume, agp_i810_resume),
1883 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
1884 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
1885 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
1886 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
1887 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
1888 DEVMETHOD(agp_enable, agp_i810_enable),
1889 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
1890 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
1891 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
1892 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
1893 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
1898 static driver_t agp_i810_driver = {
1901 sizeof(struct agp_i810_softc),
1904 static devclass_t agp_devclass;
1906 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, NULL, NULL);
1907 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
1908 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
1910 extern vm_page_t bogus_page;
1913 agp_intel_gtt_clear_range(device_t dev, u_int first_entry, u_int num_entries)
1915 struct agp_i810_softc *sc;
1918 sc = device_get_softc(dev);
1919 for (i = 0; i < num_entries; i++)
1920 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1921 VM_PAGE_TO_PHYS(bogus_page), 0);
1922 sc->match->driver->sync_gtt_pte(dev, first_entry + num_entries - 1);
1926 agp_intel_gtt_insert_pages(device_t dev, u_int first_entry, u_int num_entries,
1927 vm_page_t *pages, u_int flags)
1929 struct agp_i810_softc *sc;
1932 sc = device_get_softc(dev);
1933 for (i = 0; i < num_entries; i++) {
1934 KKASSERT(pages[i]->valid == VM_PAGE_BITS_ALL);
1935 KKASSERT(pages[i]->wire_count > 0);
1936 sc->match->driver->install_gtt_pte(dev, first_entry + i,
1937 VM_PAGE_TO_PHYS(pages[i]), flags);
1939 sc->match->driver->sync_gtt_pte(dev, first_entry + num_entries - 1);
1943 agp_intel_gtt_get(device_t dev)
1945 struct agp_i810_softc *sc;
1946 struct intel_gtt res;
1948 sc = device_get_softc(dev);
1949 res.stolen_size = sc->stolen_size;
1950 res.gtt_total_entries = sc->gtt_total_entries;
1951 res.gtt_mappable_entries = sc->gtt_mappable_entries;
1952 res.do_idle_maps = 0;
1953 res.scratch_page_dma = VM_PAGE_TO_PHYS(bogus_page);
1958 agp_i810_chipset_flush_setup(device_t dev)
1965 agp_i810_chipset_flush_teardown(device_t dev)
1968 /* Nothing to do. */
1972 agp_i810_chipset_flush(device_t dev)
1975 /* Nothing to do. */
1979 agp_i915_chipset_flush_alloc_page(device_t dev, uint64_t start, uint64_t end)
1981 struct agp_i810_softc *sc;
1984 sc = device_get_softc(dev);
1985 vga = device_get_parent(dev);
1986 sc->sc_flush_page_rid = 100;
1987 sc->sc_flush_page_res = BUS_ALLOC_RESOURCE(device_get_parent(vga), dev,
1988 SYS_RES_MEMORY, &sc->sc_flush_page_rid, start, end, PAGE_SIZE,
1990 if (sc->sc_flush_page_res == NULL) {
1991 device_printf(dev, "Failed to allocate flush page at 0x%jx\n",
1995 sc->sc_flush_page_vaddr = rman_get_virtual(sc->sc_flush_page_res);
1997 device_printf(dev, "Allocated flush page phys 0x%jx virt %p\n",
1998 (uintmax_t)rman_get_start(sc->sc_flush_page_res),
1999 sc->sc_flush_page_vaddr);
2005 agp_i915_chipset_flush_free_page(device_t dev)
2007 struct agp_i810_softc *sc;
2010 sc = device_get_softc(dev);
2011 vga = device_get_parent(dev);
2012 if (sc->sc_flush_page_res == NULL)
2014 BUS_DEACTIVATE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2015 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2016 BUS_RELEASE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2017 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2021 agp_i915_chipset_flush_setup(device_t dev)
2023 struct agp_i810_softc *sc;
2027 sc = device_get_softc(dev);
2028 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2029 if ((temp & 1) != 0) {
2033 "Found already configured flush page at 0x%jx\n",
2035 sc->sc_bios_allocated_flush_page = 1;
2037 * In the case BIOS initialized the flush pointer (?)
2038 * register, expect that BIOS also set up the resource
2041 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2042 temp + PAGE_SIZE - 1);
2046 sc->sc_bios_allocated_flush_page = 0;
2047 error = agp_i915_chipset_flush_alloc_page(dev, 0, 0xffffffff);
2050 temp = rman_get_start(sc->sc_flush_page_res);
2051 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp | 1, 4);
2057 agp_i915_chipset_flush_teardown(device_t dev)
2059 struct agp_i810_softc *sc;
2062 sc = device_get_softc(dev);
2063 if (sc->sc_flush_page_res == NULL)
2065 if (!sc->sc_bios_allocated_flush_page) {
2066 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2068 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp, 4);
2070 agp_i915_chipset_flush_free_page(dev);
2074 agp_i965_chipset_flush_setup(device_t dev)
2076 struct agp_i810_softc *sc;
2078 uint32_t temp_hi, temp_lo;
2081 sc = device_get_softc(dev);
2083 temp_hi = pci_read_config(sc->bdev, AGP_I965_IFPADDR + 4, 4);
2084 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2086 if ((temp_lo & 1) != 0) {
2087 temp = ((uint64_t)temp_hi << 32) | (temp_lo & ~1);
2090 "Found already configured flush page at 0x%jx\n",
2092 sc->sc_bios_allocated_flush_page = 1;
2094 * In the case BIOS initialized the flush pointer (?)
2095 * register, expect that BIOS also set up the resource
2098 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2099 temp + PAGE_SIZE - 1);
2103 sc->sc_bios_allocated_flush_page = 0;
2104 error = agp_i915_chipset_flush_alloc_page(dev, 0, ~0);
2107 temp = rman_get_start(sc->sc_flush_page_res);
2108 pci_write_config(sc->bdev, AGP_I965_IFPADDR + 4,
2109 (temp >> 32) & UINT32_MAX, 4);
2110 pci_write_config(sc->bdev, AGP_I965_IFPADDR,
2111 (temp & UINT32_MAX) | 1, 4);
2117 agp_i965_chipset_flush_teardown(device_t dev)
2119 struct agp_i810_softc *sc;
2122 sc = device_get_softc(dev);
2123 if (sc->sc_flush_page_res == NULL)
2125 if (!sc->sc_bios_allocated_flush_page) {
2126 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2128 pci_write_config(sc->bdev, AGP_I965_IFPADDR, temp_lo, 4);
2130 agp_i915_chipset_flush_free_page(dev);
2134 agp_i915_chipset_flush(device_t dev)
2136 struct agp_i810_softc *sc;
2138 sc = device_get_softc(dev);
2139 *(uint32_t *)sc->sc_flush_page_vaddr = 1;
2143 agp_intel_gtt_chipset_flush(device_t dev)
2145 struct agp_i810_softc *sc;
2147 sc = device_get_softc(dev);
2148 sc->match->driver->chipset_flush(dev);
2153 agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list)
2158 agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
2159 struct sglist **sg_list)
2162 struct agp_i810_softc *sc;
2171 if (*sg_list != NULL)
2174 sc = device_get_softc(dev);
2176 sg = sglist_alloc(num_entries, M_WAITOK /* XXXKIB */);
2177 for (i = 0; i < num_entries; i++) {
2178 sg->sg_segs[i].ss_paddr = VM_PAGE_TO_PHYS(pages[i]);
2179 sg->sg_segs[i].ss_len = PAGE_SIZE;
2183 error = bus_dma_tag_create(bus_get_dma_tag(dev),
2184 1 /* alignment */, 0 /* boundary */,
2185 1ULL << sc->match->busdma_addr_mask_sz /* lowaddr */,
2186 BUS_SPACE_MAXADDR /* highaddr */,
2187 NULL /* filtfunc */, NULL /* filtfuncarg */,
2188 BUS_SPACE_MAXADDR /* maxsize */,
2189 BUS_SPACE_UNRESTRICTED /* nsegments */,
2190 BUS_SPACE_MAXADDR /* maxsegsz */,
2191 0 /* flags */, NULL /* lockfunc */, NULL /* lockfuncarg */,
2204 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2205 u_int first_entry, u_int flags)
2207 struct agp_i810_softc *sc;
2212 sc = device_get_softc(dev);
2213 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2214 spaddr = sg_list->sg_segs[i].ss_paddr;
2215 slen = sg_list->sg_segs[i].ss_len;
2216 for (; slen > 0; i++) {
2217 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2219 spaddr += AGP_PAGE_SIZE;
2220 slen -= AGP_PAGE_SIZE;
2223 sc->match->driver->sync_gtt_pte(dev, first_entry + i - 1);
2227 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2230 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2234 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2238 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2242 void intel_gtt_get(size_t *gtt_total, size_t *stolen_size,
2243 phys_addr_t *mappable_base, unsigned long *mappable_end)
2245 struct agp_info ainfo;
2247 intel_private.base = agp_intel_gtt_get(intel_agp);
2249 *gtt_total = intel_private.base.gtt_total_entries << PAGE_SHIFT;
2250 *stolen_size = intel_private.base.stolen_size;
2251 agp_get_info(intel_agp, &ainfo);
2252 *mappable_base = ainfo.ai_aperture_base;
2253 *mappable_end = intel_private.base.gtt_mappable_entries << PAGE_SHIFT;
2257 intel_gtt_chipset_flush(void)
2260 return (agp_intel_gtt_chipset_flush(intel_agp));
2264 intel_gtt_unmap_memory(struct sglist *sg_list)
2267 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2271 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2272 struct sglist **sg_list)
2275 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2280 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2284 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2291 intel_gtt_sync_pte(u_int entry)
2293 struct agp_i810_softc *sc;
2295 sc = device_get_softc(intel_agp);
2296 sc->match->driver->sync_gtt_pte(intel_agp, entry);
2303 intel_gtt_write(u_int entry, uint32_t val)
2305 struct agp_i810_softc *sc;
2307 sc = device_get_softc(intel_agp);
2308 sc->match->driver->write_gtt(intel_agp, entry, val);