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
31 * $FreeBSD: src/sys/dev/agp/agp_i810.c,v 1.56 2010/03/12 21:34:23 rnoland Exp $
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
43 #define KTR_AGP_I810 KTR_DEV
45 #define KTR_AGP_I810 0
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/malloc.h>
51 #include <sys/kernel.h>
56 #include <bus/pci/pcidevs.h>
57 #include <bus/pci/pcivar.h>
58 #include <bus/pci/pcireg.h>
61 #include <dev/agp/agp_i810.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_page.h>
66 #include <vm/vm_pageout.h>
69 #include <machine/md_var.h>
71 #define bus_read_1(r, o) \
72 bus_space_read_1((r)->r_bustag, (r)->r_bushandle, (o))
73 #define bus_read_4(r, o) \
74 bus_space_read_4((r)->r_bustag, (r)->r_bushandle, (o))
75 #define bus_write_4(r, o, v) \
76 bus_space_write_4((r)->r_bustag, (r)->r_bushandle, (o), (v))
78 MALLOC_DECLARE(M_AGP);
80 struct agp_i810_match;
82 static int agp_i810_check_active(device_t bridge_dev);
83 static int agp_i830_check_active(device_t bridge_dev);
84 static int agp_i915_check_active(device_t bridge_dev);
85 static int agp_sb_check_active(device_t bridge_dev);
87 static void agp_82852_set_desc(device_t dev,
88 const struct agp_i810_match *match);
89 static void agp_i810_set_desc(device_t dev, const struct agp_i810_match *match);
91 static void agp_i810_dump_regs(device_t dev);
92 static void agp_i830_dump_regs(device_t dev);
93 static void agp_i855_dump_regs(device_t dev);
94 static void agp_i915_dump_regs(device_t dev);
95 static void agp_i965_dump_regs(device_t dev);
96 static void agp_sb_dump_regs(device_t dev);
98 static int agp_i810_get_stolen_size(device_t dev);
99 static int agp_i830_get_stolen_size(device_t dev);
100 static int agp_i915_get_stolen_size(device_t dev);
101 static int agp_sb_get_stolen_size(device_t dev);
103 static int agp_i810_get_gtt_mappable_entries(device_t dev);
104 static int agp_i830_get_gtt_mappable_entries(device_t dev);
105 static int agp_i915_get_gtt_mappable_entries(device_t dev);
107 static int agp_i810_get_gtt_total_entries(device_t dev);
108 static int agp_i965_get_gtt_total_entries(device_t dev);
109 static int agp_gen5_get_gtt_total_entries(device_t dev);
110 static int agp_sb_get_gtt_total_entries(device_t dev);
112 static int agp_i810_install_gatt(device_t dev);
113 static int agp_i830_install_gatt(device_t dev);
115 static void agp_i810_deinstall_gatt(device_t dev);
116 static void agp_i830_deinstall_gatt(device_t dev);
118 static void agp_i810_install_gtt_pte(device_t dev, u_int index,
119 vm_offset_t physical, int flags);
120 static void agp_i830_install_gtt_pte(device_t dev, u_int index,
121 vm_offset_t physical, int flags);
122 static void agp_i915_install_gtt_pte(device_t dev, u_int index,
123 vm_offset_t physical, int flags);
124 static void agp_i965_install_gtt_pte(device_t dev, u_int index,
125 vm_offset_t physical, int flags);
126 static void agp_g4x_install_gtt_pte(device_t dev, u_int index,
127 vm_offset_t physical, int flags);
128 static void agp_sb_install_gtt_pte(device_t dev, u_int index,
129 vm_offset_t physical, int flags);
131 static void agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte);
132 static void agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte);
133 static void agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte);
134 static void agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte);
135 static void agp_sb_write_gtt(device_t dev, u_int index, uint32_t pte);
137 static u_int32_t agp_i810_read_gtt_pte(device_t dev, u_int index);
138 static u_int32_t agp_i915_read_gtt_pte(device_t dev, u_int index);
139 static u_int32_t agp_i965_read_gtt_pte(device_t dev, u_int index);
140 static u_int32_t agp_g4x_read_gtt_pte(device_t dev, u_int index);
142 static vm_paddr_t agp_i810_read_gtt_pte_paddr(device_t dev, u_int index);
143 static vm_paddr_t agp_i915_read_gtt_pte_paddr(device_t dev, u_int index);
144 static vm_paddr_t agp_sb_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 */
171 CHIP_SB, /* SandyBridge */
174 /* The i810 through i855 have the registers at BAR 1, and the GATT gets
175 * allocated by us. The i915 has registers in BAR 0 and the GATT is at the
176 * start of the stolen memory, and should only be accessed by the OS through
177 * BAR 3. The G965 has registers and GATT in the same BAR (0) -- first 512KB
178 * is registers, second 512KB is GATT.
180 static struct resource_spec agp_i810_res_spec[] = {
181 { SYS_RES_MEMORY, AGP_I810_MMADR, RF_ACTIVE | RF_SHAREABLE },
185 static struct resource_spec agp_i915_res_spec[] = {
186 { SYS_RES_MEMORY, AGP_I915_MMADR, RF_ACTIVE | RF_SHAREABLE },
187 { SYS_RES_MEMORY, AGP_I915_GTTADR, RF_ACTIVE | RF_SHAREABLE },
191 static struct resource_spec agp_i965_res_spec[] = {
192 { SYS_RES_MEMORY, AGP_I965_GTTMMADR, RF_ACTIVE | RF_SHAREABLE },
196 static struct resource_spec agp_g4x_res_spec[] = {
197 { SYS_RES_MEMORY, AGP_G4X_MMADR, RF_ACTIVE | RF_SHAREABLE },
198 { SYS_RES_MEMORY, AGP_G4X_GTTADR, RF_ACTIVE | RF_SHAREABLE },
202 struct agp_i810_softc {
203 struct agp_softc agp;
204 u_int32_t initial_aperture; /* aperture size at startup */
205 struct agp_gatt *gatt;
206 u_int32_t dcache_size; /* i810 only */
207 u_int32_t stolen; /* number of i830/845 gtt
208 entries for stolen memory */
209 u_int stolen_size; /* BIOS-reserved graphics memory */
210 u_int gtt_total_entries; /* Total number of gtt ptes */
211 u_int gtt_mappable_entries; /* Number of gtt ptes mappable by CPU */
212 device_t bdev; /* bridge device */
213 void *argb_cursor; /* contigmalloc area for ARGB cursor */
214 struct resource *sc_res[2];
215 const struct agp_i810_match *match;
216 int sc_flush_page_rid;
217 struct resource *sc_flush_page_res;
218 void *sc_flush_page_vaddr;
219 int sc_bios_allocated_flush_page;
222 static device_t intel_agp;
224 struct agp_i810_driver {
227 int busdma_addr_mask_sz;
228 struct resource_spec *res_spec;
229 int (*check_active)(device_t);
230 void (*set_desc)(device_t, const struct agp_i810_match *);
231 void (*dump_regs)(device_t);
232 int (*get_stolen_size)(device_t);
233 int (*get_gtt_total_entries)(device_t);
234 int (*get_gtt_mappable_entries)(device_t);
235 int (*install_gatt)(device_t);
236 void (*deinstall_gatt)(device_t);
237 void (*write_gtt)(device_t, u_int, uint32_t);
238 void (*install_gtt_pte)(device_t, u_int, vm_offset_t, int);
239 u_int32_t (*read_gtt_pte)(device_t, u_int);
240 vm_paddr_t (*read_gtt_pte_paddr)(device_t , u_int);
241 int (*set_aperture)(device_t, u_int32_t);
242 int (*chipset_flush_setup)(device_t);
243 void (*chipset_flush_teardown)(device_t);
244 void (*chipset_flush)(device_t);
247 static const struct agp_i810_driver agp_i810_i810_driver = {
248 .chiptype = CHIP_I810,
250 .busdma_addr_mask_sz = 32,
251 .res_spec = agp_i810_res_spec,
252 .check_active = agp_i810_check_active,
253 .set_desc = agp_i810_set_desc,
254 .dump_regs = agp_i810_dump_regs,
255 .get_stolen_size = agp_i810_get_stolen_size,
256 .get_gtt_mappable_entries = agp_i810_get_gtt_mappable_entries,
257 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
258 .install_gatt = agp_i810_install_gatt,
259 .deinstall_gatt = agp_i810_deinstall_gatt,
260 .write_gtt = agp_i810_write_gtt,
261 .install_gtt_pte = agp_i810_install_gtt_pte,
262 .read_gtt_pte = agp_i810_read_gtt_pte,
263 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
264 .set_aperture = agp_i810_set_aperture,
265 .chipset_flush_setup = agp_i810_chipset_flush_setup,
266 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
267 .chipset_flush = agp_i810_chipset_flush,
270 static const struct agp_i810_driver agp_i810_i815_driver = {
271 .chiptype = CHIP_I810,
273 .busdma_addr_mask_sz = 32,
274 .res_spec = agp_i810_res_spec,
275 .check_active = agp_i810_check_active,
276 .set_desc = agp_i810_set_desc,
277 .dump_regs = agp_i810_dump_regs,
278 .get_stolen_size = agp_i810_get_stolen_size,
279 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
280 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
281 .install_gatt = agp_i810_install_gatt,
282 .deinstall_gatt = agp_i810_deinstall_gatt,
283 .write_gtt = agp_i810_write_gtt,
284 .install_gtt_pte = agp_i810_install_gtt_pte,
285 .read_gtt_pte = agp_i810_read_gtt_pte,
286 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
287 .set_aperture = agp_i810_set_aperture,
288 .chipset_flush_setup = agp_i810_chipset_flush_setup,
289 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
290 .chipset_flush = agp_i830_chipset_flush,
293 static const struct agp_i810_driver agp_i810_i830_driver = {
294 .chiptype = CHIP_I830,
296 .busdma_addr_mask_sz = 32,
297 .res_spec = agp_i810_res_spec,
298 .check_active = agp_i830_check_active,
299 .set_desc = agp_i810_set_desc,
300 .dump_regs = agp_i830_dump_regs,
301 .get_stolen_size = agp_i830_get_stolen_size,
302 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
303 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
304 .install_gatt = agp_i830_install_gatt,
305 .deinstall_gatt = agp_i830_deinstall_gatt,
306 .write_gtt = agp_i810_write_gtt,
307 .install_gtt_pte = agp_i830_install_gtt_pte,
308 .read_gtt_pte = agp_i810_read_gtt_pte,
309 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
310 .set_aperture = agp_i830_set_aperture,
311 .chipset_flush_setup = agp_i810_chipset_flush_setup,
312 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
313 .chipset_flush = agp_i830_chipset_flush,
316 static const struct agp_i810_driver agp_i810_i855_driver = {
317 .chiptype = CHIP_I855,
319 .busdma_addr_mask_sz = 32,
320 .res_spec = agp_i810_res_spec,
321 .check_active = agp_i830_check_active,
322 .set_desc = agp_82852_set_desc,
323 .dump_regs = agp_i855_dump_regs,
324 .get_stolen_size = agp_i915_get_stolen_size,
325 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
326 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
327 .install_gatt = agp_i830_install_gatt,
328 .deinstall_gatt = agp_i830_deinstall_gatt,
329 .write_gtt = agp_i810_write_gtt,
330 .install_gtt_pte = agp_i830_install_gtt_pte,
331 .read_gtt_pte = agp_i810_read_gtt_pte,
332 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
333 .set_aperture = agp_i830_set_aperture,
334 .chipset_flush_setup = agp_i810_chipset_flush_setup,
335 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
336 .chipset_flush = agp_i830_chipset_flush,
339 static const struct agp_i810_driver agp_i810_i865_driver = {
340 .chiptype = CHIP_I855,
342 .busdma_addr_mask_sz = 32,
343 .res_spec = agp_i810_res_spec,
344 .check_active = agp_i830_check_active,
345 .set_desc = agp_i810_set_desc,
346 .dump_regs = agp_i855_dump_regs,
347 .get_stolen_size = agp_i915_get_stolen_size,
348 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
349 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
350 .install_gatt = agp_i830_install_gatt,
351 .deinstall_gatt = agp_i830_deinstall_gatt,
352 .write_gtt = agp_i810_write_gtt,
353 .install_gtt_pte = agp_i830_install_gtt_pte,
354 .read_gtt_pte = agp_i810_read_gtt_pte,
355 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
356 .set_aperture = agp_i915_set_aperture,
357 .chipset_flush_setup = agp_i810_chipset_flush_setup,
358 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
359 .chipset_flush = agp_i830_chipset_flush,
362 static const struct agp_i810_driver agp_i810_i915_driver = {
363 .chiptype = CHIP_I915,
365 .busdma_addr_mask_sz = 32,
366 .res_spec = agp_i915_res_spec,
367 .check_active = agp_i915_check_active,
368 .set_desc = agp_i810_set_desc,
369 .dump_regs = agp_i915_dump_regs,
370 .get_stolen_size = agp_i915_get_stolen_size,
371 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
372 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
373 .install_gatt = agp_i830_install_gatt,
374 .deinstall_gatt = agp_i830_deinstall_gatt,
375 .write_gtt = agp_i915_write_gtt,
376 .install_gtt_pte = agp_i915_install_gtt_pte,
377 .read_gtt_pte = agp_i915_read_gtt_pte,
378 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
379 .set_aperture = agp_i915_set_aperture,
380 .chipset_flush_setup = agp_i915_chipset_flush_setup,
381 .chipset_flush_teardown = agp_i915_chipset_flush_teardown,
382 .chipset_flush = agp_i915_chipset_flush,
385 static const struct agp_i810_driver agp_i810_g965_driver = {
386 .chiptype = CHIP_I965,
388 .busdma_addr_mask_sz = 36,
389 .res_spec = agp_i965_res_spec,
390 .check_active = agp_i915_check_active,
391 .set_desc = agp_i810_set_desc,
392 .dump_regs = agp_i965_dump_regs,
393 .get_stolen_size = agp_i915_get_stolen_size,
394 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
395 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
396 .install_gatt = agp_i830_install_gatt,
397 .deinstall_gatt = agp_i830_deinstall_gatt,
398 .write_gtt = agp_i965_write_gtt,
399 .install_gtt_pte = agp_i965_install_gtt_pte,
400 .read_gtt_pte = agp_i965_read_gtt_pte,
401 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
402 .set_aperture = agp_i915_set_aperture,
403 .chipset_flush_setup = agp_i965_chipset_flush_setup,
404 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
405 .chipset_flush = agp_i915_chipset_flush,
408 static const struct agp_i810_driver agp_i810_g33_driver = {
409 .chiptype = CHIP_G33,
411 .busdma_addr_mask_sz = 36,
412 .res_spec = agp_i915_res_spec,
413 .check_active = agp_i915_check_active,
414 .set_desc = agp_i810_set_desc,
415 .dump_regs = agp_i965_dump_regs,
416 .get_stolen_size = agp_i915_get_stolen_size,
417 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
418 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
419 .install_gatt = agp_i830_install_gatt,
420 .deinstall_gatt = agp_i830_deinstall_gatt,
421 .write_gtt = agp_i915_write_gtt,
422 .install_gtt_pte = agp_i915_install_gtt_pte,
423 .read_gtt_pte = agp_i915_read_gtt_pte,
424 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
425 .set_aperture = agp_i915_set_aperture,
426 .chipset_flush_setup = agp_i965_chipset_flush_setup,
427 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
428 .chipset_flush = agp_i915_chipset_flush,
431 static const struct agp_i810_driver agp_i810_igd_driver = {
432 .chiptype = CHIP_IGD,
434 .busdma_addr_mask_sz = 36,
435 .res_spec = agp_i915_res_spec,
436 .check_active = agp_i915_check_active,
437 .set_desc = agp_i810_set_desc,
438 .dump_regs = agp_i915_dump_regs,
439 .get_stolen_size = agp_i915_get_stolen_size,
440 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
441 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
442 .install_gatt = agp_i830_install_gatt,
443 .deinstall_gatt = agp_i830_deinstall_gatt,
444 .write_gtt = agp_i915_write_gtt,
445 .install_gtt_pte = agp_i915_install_gtt_pte,
446 .read_gtt_pte = agp_i915_read_gtt_pte,
447 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
448 .set_aperture = agp_i915_set_aperture,
449 .chipset_flush_setup = agp_i965_chipset_flush_setup,
450 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
451 .chipset_flush = agp_i915_chipset_flush,
454 static const struct agp_i810_driver agp_i810_g4x_driver = {
455 .chiptype = CHIP_G4X,
457 .busdma_addr_mask_sz = 36,
458 .res_spec = agp_i965_res_spec,
459 .check_active = agp_i915_check_active,
460 .set_desc = agp_i810_set_desc,
461 .dump_regs = agp_i965_dump_regs,
462 .get_stolen_size = agp_i915_get_stolen_size,
463 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
464 .get_gtt_total_entries = agp_gen5_get_gtt_total_entries,
465 .install_gatt = agp_i830_install_gatt,
466 .deinstall_gatt = agp_i830_deinstall_gatt,
467 .write_gtt = agp_g4x_write_gtt,
468 .install_gtt_pte = agp_g4x_install_gtt_pte,
469 .read_gtt_pte = agp_g4x_read_gtt_pte,
470 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
471 .set_aperture = agp_i915_set_aperture,
472 .chipset_flush_setup = agp_i965_chipset_flush_setup,
473 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
474 .chipset_flush = agp_i915_chipset_flush,
477 static const struct agp_i810_driver agp_i810_sb_driver = {
480 .busdma_addr_mask_sz = 40,
481 .res_spec = agp_g4x_res_spec,
482 .check_active = agp_sb_check_active,
483 .set_desc = agp_i810_set_desc,
484 .dump_regs = agp_sb_dump_regs,
485 .get_stolen_size = agp_sb_get_stolen_size,
486 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
487 .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
488 .install_gatt = agp_i830_install_gatt,
489 .deinstall_gatt = agp_i830_deinstall_gatt,
490 .write_gtt = agp_sb_write_gtt,
491 .install_gtt_pte = agp_sb_install_gtt_pte,
492 .read_gtt_pte = agp_g4x_read_gtt_pte,
493 .read_gtt_pte_paddr = agp_sb_read_gtt_pte_paddr,
494 .set_aperture = agp_i915_set_aperture,
495 .chipset_flush_setup = agp_i810_chipset_flush_setup,
496 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
497 .chipset_flush = agp_i810_chipset_flush,
500 /* For adding new devices, devid is the id of the graphics controller
501 * (pci:0:2:0, for example). The placeholder (usually at pci:0:2:1) for the
502 * second head should never be added. The bridge_offset is the offset to
503 * subtract from devid to get the id of the hostb that the device is on.
505 static const struct agp_i810_match {
508 const struct agp_i810_driver *driver;
509 } agp_i810_matches[] = {
512 .name = "Intel 82810 (i810 GMCH) SVGA controller",
513 .driver = &agp_i810_i810_driver
517 .name = "Intel 82810-DC100 (i810-DC100 GMCH) SVGA controller",
518 .driver = &agp_i810_i810_driver
522 .name = "Intel 82810E (i810E GMCH) SVGA controller",
523 .driver = &agp_i810_i810_driver
527 .name = "Intel 82815 (i815 GMCH) SVGA controller",
528 .driver = &agp_i810_i815_driver
532 .name = "Intel 82830M (830M GMCH) SVGA controller",
533 .driver = &agp_i810_i830_driver
537 .name = "Intel 82845M (845M GMCH) SVGA controller",
538 .driver = &agp_i810_i830_driver
542 .name = "Intel 82852/855GM SVGA controller",
543 .driver = &agp_i810_i855_driver
547 .name = "Intel 82865G (865G GMCH) SVGA controller",
548 .driver = &agp_i810_i865_driver
552 .name = "Intel 82915G (915G GMCH) SVGA controller",
553 .driver = &agp_i810_i915_driver
557 .name = "Intel E7221 SVGA controller",
558 .driver = &agp_i810_i915_driver
562 .name = "Intel 82915GM (915GM GMCH) SVGA controller",
563 .driver = &agp_i810_i915_driver
567 .name = "Intel 82945G (945G GMCH) SVGA controller",
568 .driver = &agp_i810_i915_driver
572 .name = "Intel 82945GM (945GM GMCH) SVGA controller",
573 .driver = &agp_i810_i915_driver
577 .name = "Intel 945GME SVGA controller",
578 .driver = &agp_i810_i915_driver
582 .name = "Intel 946GZ SVGA controller",
583 .driver = &agp_i810_g965_driver
587 .name = "Intel G965 SVGA controller",
588 .driver = &agp_i810_g965_driver
592 .name = "Intel Q965 SVGA controller",
593 .driver = &agp_i810_g965_driver
597 .name = "Intel G965 SVGA controller",
598 .driver = &agp_i810_g965_driver
602 .name = "Intel Q35 SVGA controller",
603 .driver = &agp_i810_g33_driver
607 .name = "Intel G33 SVGA controller",
608 .driver = &agp_i810_g33_driver
612 .name = "Intel Q33 SVGA controller",
613 .driver = &agp_i810_g33_driver
617 .name = "Intel Pineview SVGA controller",
618 .driver = &agp_i810_igd_driver
622 .name = "Intel Pineview (M) SVGA controller",
623 .driver = &agp_i810_igd_driver
627 .name = "Intel GM965 SVGA controller",
628 .driver = &agp_i810_g965_driver
632 .name = "Intel GME965 SVGA controller",
633 .driver = &agp_i810_g965_driver
637 .name = "Intel GM45 SVGA controller",
638 .driver = &agp_i810_g4x_driver
642 .name = "Intel Eaglelake SVGA controller",
643 .driver = &agp_i810_g4x_driver
647 .name = "Intel Q45 SVGA controller",
648 .driver = &agp_i810_g4x_driver
652 .name = "Intel G45 SVGA controller",
653 .driver = &agp_i810_g4x_driver
657 .name = "Intel G41 SVGA controller",
658 .driver = &agp_i810_g4x_driver
662 .name = "Intel Ironlake (D) SVGA controller",
663 .driver = &agp_i810_g4x_driver
667 .name = "Intel Ironlake (M) SVGA controller",
668 .driver = &agp_i810_g4x_driver
672 .name = "SandyBridge desktop GT1 IG",
673 .driver = &agp_i810_sb_driver
677 .name = "SandyBridge desktop GT2 IG",
678 .driver = &agp_i810_sb_driver
682 .name = "SandyBridge desktop GT2+ IG",
683 .driver = &agp_i810_sb_driver
687 .name = "SandyBridge mobile GT1 IG",
688 .driver = &agp_i810_sb_driver
692 .name = "SandyBridge mobile GT2 IG",
693 .driver = &agp_i810_sb_driver
697 .name = "SandyBridge mobile GT2+ IG",
698 .driver = &agp_i810_sb_driver
702 .name = "SandyBridge server IG",
703 .driver = &agp_i810_sb_driver
707 .name = "IvyBridge desktop GT1 IG",
708 .driver = &agp_i810_sb_driver
712 .name = "IvyBridge desktop GT2 IG",
713 .driver = &agp_i810_sb_driver
717 .name = "IvyBridge mobile GT1 IG",
718 .driver = &agp_i810_sb_driver
722 .name = "IvyBridge mobile GT2 IG",
723 .driver = &agp_i810_sb_driver
727 .name = "IvyBridge server GT1 IG",
728 .driver = &agp_i810_sb_driver
732 .name = "IvyBridge server GT2 IG",
733 .driver = &agp_i810_sb_driver
740 static const struct agp_i810_match*
741 agp_i810_match(device_t dev)
745 if (pci_get_vendor(dev) != PCI_VENDOR_INTEL)
748 devid = pci_get_subdevice(dev);
749 for (i = 0; agp_i810_matches[i].devid != 0; i++) {
750 if (agp_i810_matches[i].devid == devid)
753 if (agp_i810_matches[i].devid == 0)
756 return (&agp_i810_matches[i]);
760 * Find bridge device.
763 agp_i810_find_bridge(device_t dev)
766 return (pci_find_dbsf(0, 0, 0, 0));
770 agp_i810_identify(driver_t *driver, device_t parent)
773 if (device_find_child(parent, "agp", -1) == NULL &&
774 agp_i810_match(parent))
775 device_add_child(parent, "agp", -1);
779 agp_i810_check_active(device_t bridge_dev)
783 smram = pci_read_config(bridge_dev, AGP_I810_SMRAM, 1);
784 if ((smram & AGP_I810_SMRAM_GMS) == AGP_I810_SMRAM_GMS_DISABLED)
790 agp_i830_check_active(device_t bridge_dev)
794 gcc1 = pci_read_config(bridge_dev, AGP_I830_GCC1, 1);
795 if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED)
801 agp_i915_check_active(device_t bridge_dev)
805 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
806 if ((deven & AGP_I915_DEVEN_D2F0) == AGP_I915_DEVEN_D2F0_DISABLED)
812 agp_sb_check_active(device_t bridge_dev)
816 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
817 if ((deven & AGP_SB_DEVEN_D2EN) == AGP_SB_DEVEN_D2EN_DISABLED)
823 agp_82852_set_desc(device_t dev, const struct agp_i810_match *match)
826 switch (pci_read_config(dev, AGP_I85X_CAPID, 1)) {
829 "Intel 82855GME (855GME GMCH) SVGA controller");
833 "Intel 82855GM (855GM GMCH) SVGA controller");
837 "Intel 82852GME (852GME GMCH) SVGA controller");
841 "Intel 82852GM (852GM GMCH) SVGA controller");
845 "Intel 8285xM (85xGM GMCH) SVGA controller");
851 agp_i810_set_desc(device_t dev, const struct agp_i810_match *match)
854 device_set_desc(dev, match->name);
858 agp_i810_probe(device_t dev)
861 const struct agp_i810_match *match;
864 if (resource_disabled("agp", device_get_unit(dev)))
866 match = agp_i810_match(dev);
870 bdev = agp_i810_find_bridge(dev);
873 kprintf("I810: can't find bridge device\n");
878 * checking whether internal graphics device has been activated.
880 err = match->driver->check_active(bdev);
883 kprintf("i810: disabled, not probing\n");
887 match->driver->set_desc(dev, match);
888 return (BUS_PROBE_DEFAULT);
892 agp_i810_dump_regs(device_t dev)
894 struct agp_i810_softc *sc = device_get_softc(dev);
896 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
897 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
898 device_printf(dev, "AGP_I810_MISCC: 0x%04x\n",
899 pci_read_config(sc->bdev, AGP_I810_MISCC, 2));
903 agp_i830_dump_regs(device_t dev)
905 struct agp_i810_softc *sc = device_get_softc(dev);
907 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
908 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
909 device_printf(dev, "AGP_I830_GCC1: 0x%02x\n",
910 pci_read_config(sc->bdev, AGP_I830_GCC1, 1));
914 agp_i855_dump_regs(device_t dev)
916 struct agp_i810_softc *sc = device_get_softc(dev);
918 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
919 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
920 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
921 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
925 agp_i915_dump_regs(device_t dev)
927 struct agp_i810_softc *sc = device_get_softc(dev);
929 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
930 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
931 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
932 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
933 device_printf(dev, "AGP_I915_MSAC: 0x%02x\n",
934 pci_read_config(sc->bdev, AGP_I915_MSAC, 1));
938 agp_i965_dump_regs(device_t dev)
940 struct agp_i810_softc *sc = device_get_softc(dev);
942 device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
943 bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
944 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
945 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
946 device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
947 pci_read_config(sc->bdev, AGP_I965_MSAC, 1));
951 agp_sb_dump_regs(device_t dev)
953 struct agp_i810_softc *sc = device_get_softc(dev);
955 device_printf(dev, "AGP_SNB_GFX_MODE: %08x\n",
956 bus_read_4(sc->sc_res[0], AGP_SNB_GFX_MODE));
957 device_printf(dev, "AGP_SNB_GCC1: 0x%04x\n",
958 pci_read_config(sc->bdev, AGP_SNB_GCC1, 2));
962 agp_i810_get_stolen_size(device_t dev)
964 struct agp_i810_softc *sc;
966 sc = device_get_softc(dev);
973 agp_i830_get_stolen_size(device_t dev)
975 struct agp_i810_softc *sc;
978 sc = device_get_softc(dev);
980 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1);
981 switch (gcc1 & AGP_I830_GCC1_GMS) {
982 case AGP_I830_GCC1_GMS_STOLEN_512:
983 sc->stolen = (512 - 132) * 1024 / 4096;
984 sc->stolen_size = 512 * 1024;
986 case AGP_I830_GCC1_GMS_STOLEN_1024:
987 sc->stolen = (1024 - 132) * 1024 / 4096;
988 sc->stolen_size = 1024 * 1024;
990 case AGP_I830_GCC1_GMS_STOLEN_8192:
991 sc->stolen = (8192 - 132) * 1024 / 4096;
992 sc->stolen_size = 8192 * 1024;
997 "unknown memory configuration, disabling (GCC1 %x)\n",
1005 agp_i915_get_stolen_size(device_t dev)
1007 struct agp_i810_softc *sc;
1008 unsigned int gcc1, stolen, gtt_size;
1010 sc = device_get_softc(dev);
1013 * Stolen memory is set up at the beginning of the aperture by
1014 * the BIOS, consisting of the GATT followed by 4kb for the
1017 switch (sc->match->driver->chiptype) {
1025 switch (bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL) &
1026 AGP_I810_PGTBL_SIZE_MASK) {
1027 case AGP_I810_PGTBL_SIZE_128KB:
1030 case AGP_I810_PGTBL_SIZE_256KB:
1033 case AGP_I810_PGTBL_SIZE_512KB:
1036 case AGP_I965_PGTBL_SIZE_1MB:
1039 case AGP_I965_PGTBL_SIZE_2MB:
1042 case AGP_I965_PGTBL_SIZE_1_5MB:
1043 gtt_size = 1024 + 512;
1046 device_printf(dev, "Bad PGTBL size\n");
1051 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 2);
1052 switch (gcc1 & AGP_G33_MGGC_GGMS_MASK) {
1053 case AGP_G33_MGGC_GGMS_SIZE_1M:
1056 case AGP_G33_MGGC_GGMS_SIZE_2M:
1060 device_printf(dev, "Bad PGTBL size\n");
1069 device_printf(dev, "Bad chiptype\n");
1073 /* GCC1 is called MGGC on i915+ */
1074 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
1075 switch (gcc1 & AGP_I855_GCC1_GMS) {
1076 case AGP_I855_GCC1_GMS_STOLEN_1M:
1079 case AGP_I855_GCC1_GMS_STOLEN_4M:
1082 case AGP_I855_GCC1_GMS_STOLEN_8M:
1085 case AGP_I855_GCC1_GMS_STOLEN_16M:
1088 case AGP_I855_GCC1_GMS_STOLEN_32M:
1091 case AGP_I915_GCC1_GMS_STOLEN_48M:
1092 stolen = sc->match->driver->gen > 2 ? 48 * 1024 : 0;
1094 case AGP_I915_GCC1_GMS_STOLEN_64M:
1095 stolen = sc->match->driver->gen > 2 ? 64 * 1024 : 0;
1097 case AGP_G33_GCC1_GMS_STOLEN_128M:
1098 stolen = sc->match->driver->gen > 2 ? 128 * 1024 : 0;
1100 case AGP_G33_GCC1_GMS_STOLEN_256M:
1101 stolen = sc->match->driver->gen > 2 ? 256 * 1024 : 0;
1103 case AGP_G4X_GCC1_GMS_STOLEN_96M:
1104 if (sc->match->driver->chiptype == CHIP_I965 ||
1105 sc->match->driver->chiptype == CHIP_G4X)
1110 case AGP_G4X_GCC1_GMS_STOLEN_160M:
1111 if (sc->match->driver->chiptype == CHIP_I965 ||
1112 sc->match->driver->chiptype == CHIP_G4X)
1113 stolen = 160 * 1024;
1117 case AGP_G4X_GCC1_GMS_STOLEN_224M:
1118 if (sc->match->driver->chiptype == CHIP_I965 ||
1119 sc->match->driver->chiptype == CHIP_G4X)
1120 stolen = 224 * 1024;
1124 case AGP_G4X_GCC1_GMS_STOLEN_352M:
1125 if (sc->match->driver->chiptype == CHIP_I965 ||
1126 sc->match->driver->chiptype == CHIP_G4X)
1127 stolen = 352 * 1024;
1133 "unknown memory configuration, disabling (GCC1 %x)\n",
1139 sc->stolen_size = stolen * 1024;
1140 sc->stolen = (stolen - gtt_size) * 1024 / 4096;
1146 agp_sb_get_stolen_size(device_t dev)
1148 struct agp_i810_softc *sc;
1151 sc = device_get_softc(dev);
1152 gmch_ctl = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
1153 switch (gmch_ctl & AGP_SNB_GMCH_GMS_STOLEN_MASK) {
1154 case AGP_SNB_GMCH_GMS_STOLEN_32M:
1155 sc->stolen_size = 32 * 1024 * 1024;
1157 case AGP_SNB_GMCH_GMS_STOLEN_64M:
1158 sc->stolen_size = 64 * 1024 * 1024;
1160 case AGP_SNB_GMCH_GMS_STOLEN_96M:
1161 sc->stolen_size = 96 * 1024 * 1024;
1163 case AGP_SNB_GMCH_GMS_STOLEN_128M:
1164 sc->stolen_size = 128 * 1024 * 1024;
1166 case AGP_SNB_GMCH_GMS_STOLEN_160M:
1167 sc->stolen_size = 160 * 1024 * 1024;
1169 case AGP_SNB_GMCH_GMS_STOLEN_192M:
1170 sc->stolen_size = 192 * 1024 * 1024;
1172 case AGP_SNB_GMCH_GMS_STOLEN_224M:
1173 sc->stolen_size = 224 * 1024 * 1024;
1175 case AGP_SNB_GMCH_GMS_STOLEN_256M:
1176 sc->stolen_size = 256 * 1024 * 1024;
1178 case AGP_SNB_GMCH_GMS_STOLEN_288M:
1179 sc->stolen_size = 288 * 1024 * 1024;
1181 case AGP_SNB_GMCH_GMS_STOLEN_320M:
1182 sc->stolen_size = 320 * 1024 * 1024;
1184 case AGP_SNB_GMCH_GMS_STOLEN_352M:
1185 sc->stolen_size = 352 * 1024 * 1024;
1187 case AGP_SNB_GMCH_GMS_STOLEN_384M:
1188 sc->stolen_size = 384 * 1024 * 1024;
1190 case AGP_SNB_GMCH_GMS_STOLEN_416M:
1191 sc->stolen_size = 416 * 1024 * 1024;
1193 case AGP_SNB_GMCH_GMS_STOLEN_448M:
1194 sc->stolen_size = 448 * 1024 * 1024;
1196 case AGP_SNB_GMCH_GMS_STOLEN_480M:
1197 sc->stolen_size = 480 * 1024 * 1024;
1199 case AGP_SNB_GMCH_GMS_STOLEN_512M:
1200 sc->stolen_size = 512 * 1024 * 1024;
1203 sc->stolen = (sc->stolen_size - 4) / 4096;
1208 agp_i810_get_gtt_mappable_entries(device_t dev)
1210 struct agp_i810_softc *sc;
1214 sc = device_get_softc(dev);
1215 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1216 if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
1220 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1225 agp_i830_get_gtt_mappable_entries(device_t dev)
1227 struct agp_i810_softc *sc;
1231 sc = device_get_softc(dev);
1232 gmch_ctl = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1233 if ((gmch_ctl & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
1237 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1242 agp_i915_get_gtt_mappable_entries(device_t dev)
1244 struct agp_i810_softc *sc;
1247 sc = device_get_softc(dev);
1248 ap = AGP_GET_APERTURE(dev);
1249 sc->gtt_mappable_entries = ap >> AGP_PAGE_SHIFT;
1254 agp_i810_get_gtt_total_entries(device_t dev)
1256 struct agp_i810_softc *sc;
1258 sc = device_get_softc(dev);
1259 sc->gtt_total_entries = sc->gtt_mappable_entries;
1264 agp_i965_get_gtt_total_entries(device_t dev)
1266 struct agp_i810_softc *sc;
1267 uint32_t pgetbl_ctl;
1270 sc = device_get_softc(dev);
1272 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1273 switch (pgetbl_ctl & AGP_I810_PGTBL_SIZE_MASK) {
1274 case AGP_I810_PGTBL_SIZE_128KB:
1275 sc->gtt_total_entries = 128 * 1024 / 4;
1277 case AGP_I810_PGTBL_SIZE_256KB:
1278 sc->gtt_total_entries = 256 * 1024 / 4;
1280 case AGP_I810_PGTBL_SIZE_512KB:
1281 sc->gtt_total_entries = 512 * 1024 / 4;
1283 /* GTT pagetable sizes bigger than 512KB are not possible on G33! */
1284 case AGP_I810_PGTBL_SIZE_1MB:
1285 sc->gtt_total_entries = 1024 * 1024 / 4;
1287 case AGP_I810_PGTBL_SIZE_2MB:
1288 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1290 case AGP_I810_PGTBL_SIZE_1_5MB:
1291 sc->gtt_total_entries = (1024 + 512) * 1024 / 4;
1294 device_printf(dev, "Unknown page table size\n");
1301 agp_gen5_adjust_pgtbl_size(device_t dev, uint32_t sz)
1303 struct agp_i810_softc *sc;
1304 uint32_t pgetbl_ctl, pgetbl_ctl2;
1306 sc = device_get_softc(dev);
1308 /* Disable per-process page table. */
1309 pgetbl_ctl2 = bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2);
1310 pgetbl_ctl2 &= ~AGP_I810_PGTBL_ENABLED;
1311 bus_write_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2, pgetbl_ctl2);
1313 /* Write the new ggtt size. */
1314 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1315 pgetbl_ctl &= ~AGP_I810_PGTBL_SIZE_MASK;
1317 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgetbl_ctl);
1321 agp_gen5_get_gtt_total_entries(device_t dev)
1323 struct agp_i810_softc *sc;
1326 sc = device_get_softc(dev);
1328 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1329 switch (gcc1 & AGP_G4x_GCC1_SIZE_MASK) {
1330 case AGP_G4x_GCC1_SIZE_1M:
1331 case AGP_G4x_GCC1_SIZE_VT_1M:
1332 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1MB);
1334 case AGP_G4x_GCC1_SIZE_VT_1_5M:
1335 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1_5MB);
1337 case AGP_G4x_GCC1_SIZE_2M:
1338 case AGP_G4x_GCC1_SIZE_VT_2M:
1339 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_2MB);
1342 device_printf(dev, "Unknown page table size\n");
1346 return (agp_i965_get_gtt_total_entries(dev));
1350 agp_sb_get_gtt_total_entries(device_t dev)
1352 struct agp_i810_softc *sc;
1355 sc = device_get_softc(dev);
1357 gcc1 = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
1358 switch (gcc1 & AGP_SNB_GTT_SIZE_MASK) {
1360 case AGP_SNB_GTT_SIZE_0M:
1361 kprintf("Bad GTT size mask: 0x%04x\n", gcc1);
1363 case AGP_SNB_GTT_SIZE_1M:
1364 sc->gtt_total_entries = 1024 * 1024 / 4;
1366 case AGP_SNB_GTT_SIZE_2M:
1367 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1374 agp_i810_install_gatt(device_t dev)
1376 struct agp_i810_softc *sc;
1378 sc = device_get_softc(dev);
1380 /* Some i810s have on-chip memory called dcache. */
1381 if ((bus_read_1(sc->sc_res[0], AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
1383 sc->dcache_size = 4 * 1024 * 1024;
1385 sc->dcache_size = 0;
1387 /* According to the specs the gatt on the i810 must be 64k. */
1388 sc->gatt->ag_virtual = contigmalloc(64 * 1024, M_AGP, 0, 0, ~0,
1390 if (sc->gatt->ag_virtual == NULL) {
1392 device_printf(dev, "contiguous allocation failed\n");
1396 bzero(sc->gatt->ag_virtual, sc->gatt->ag_entries * sizeof(u_int32_t));
1397 sc->gatt->ag_physical = vtophys((vm_offset_t)sc->gatt->ag_virtual);
1399 /* Install the GATT. */
1400 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1401 sc->gatt->ag_physical | 1);
1406 agp_i830_install_gatt(device_t dev)
1408 struct agp_i810_softc *sc;
1411 sc = device_get_softc(dev);
1414 * The i830 automatically initializes the 128k gatt on boot.
1415 * GATT address is already in there, make sure it's enabled.
1417 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1419 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1421 sc->gatt->ag_physical = pgtblctl & ~1;
1426 agp_i810_attach(device_t dev)
1428 struct agp_i810_softc *sc;
1431 sc = device_get_softc(dev);
1432 sc->bdev = agp_i810_find_bridge(dev);
1433 if (sc->bdev == NULL)
1436 sc->match = agp_i810_match(dev);
1438 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1439 AGP_APBASE : AGP_I915_GMADR);
1440 error = agp_generic_attach(dev);
1444 if (ptoa((vm_paddr_t)Maxmem) >
1445 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1446 device_printf(dev, "agp_i810 does not support physical "
1447 "memory above %ju.\n", (uintmax_t)(1ULL <<
1448 sc->match->driver->busdma_addr_mask_sz) - 1);
1452 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1453 agp_generic_detach(dev);
1457 sc->initial_aperture = AGP_GET_APERTURE(dev);
1458 sc->gatt = kmalloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1459 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1461 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1462 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1463 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1464 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1465 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1466 bus_release_resources(dev, sc->match->driver->res_spec,
1468 kfree(sc->gatt, M_AGP);
1469 agp_generic_detach(dev);
1474 device_printf(dev, "aperture size is %dM",
1475 sc->initial_aperture / 1024 / 1024);
1477 kprintf(", detected %dk stolen memory\n", sc->stolen * 4);
1481 sc->match->driver->dump_regs(dev);
1482 device_printf(dev, "Mappable GTT entries: %d\n",
1483 sc->gtt_mappable_entries);
1484 device_printf(dev, "Total GTT entries: %d\n",
1485 sc->gtt_total_entries);
1491 agp_i810_deinstall_gatt(device_t dev)
1493 struct agp_i810_softc *sc;
1495 sc = device_get_softc(dev);
1496 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
1497 contigfree(sc->gatt->ag_virtual, 64 * 1024, M_AGP);
1501 agp_i830_deinstall_gatt(device_t dev)
1503 struct agp_i810_softc *sc;
1504 unsigned int pgtblctl;
1506 sc = device_get_softc(dev);
1507 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1509 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1513 agp_i810_detach(device_t dev)
1515 struct agp_i810_softc *sc;
1517 sc = device_get_softc(dev);
1520 /* Clear the GATT base. */
1521 sc->match->driver->deinstall_gatt(dev);
1523 sc->match->driver->chipset_flush_teardown(dev);
1525 /* Put the aperture back the way it started. */
1526 AGP_SET_APERTURE(dev, sc->initial_aperture);
1528 kfree(sc->gatt, M_AGP);
1529 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1536 agp_i810_resume(device_t dev)
1538 struct agp_i810_softc *sc;
1539 sc = device_get_softc(dev);
1541 AGP_SET_APERTURE(dev, sc->initial_aperture);
1543 /* Install the GATT. */
1544 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1545 sc->gatt->ag_physical | 1);
1547 return (bus_generic_resume(dev));
1551 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1552 * while returning failure on later chipsets when an actual change is
1555 * This whole function is likely bogus, as the kernel would probably need to
1556 * reconfigure the placement of the AGP aperture if a larger size is requested,
1557 * which doesn't happen currently.
1560 agp_i810_set_aperture(device_t dev, u_int32_t aperture)
1562 struct agp_i810_softc *sc;
1565 sc = device_get_softc(dev);
1567 * Double check for sanity.
1569 if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
1570 device_printf(dev, "bad aperture size %d\n", aperture);
1574 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1575 miscc &= ~AGP_I810_MISCC_WINSIZE;
1576 if (aperture == 32 * 1024 * 1024)
1577 miscc |= AGP_I810_MISCC_WINSIZE_32;
1579 miscc |= AGP_I810_MISCC_WINSIZE_64;
1581 pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
1586 agp_i830_set_aperture(device_t dev, u_int32_t aperture)
1588 struct agp_i810_softc *sc;
1591 sc = device_get_softc(dev);
1593 if (aperture != 64 * 1024 * 1024 &&
1594 aperture != 128 * 1024 * 1024) {
1595 device_printf(dev, "bad aperture size %d\n", aperture);
1598 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1599 gcc1 &= ~AGP_I830_GCC1_GMASIZE;
1600 if (aperture == 64 * 1024 * 1024)
1601 gcc1 |= AGP_I830_GCC1_GMASIZE_64;
1603 gcc1 |= AGP_I830_GCC1_GMASIZE_128;
1605 pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
1610 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1613 return (agp_generic_set_aperture(dev, aperture));
1617 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1619 struct agp_i810_softc *sc;
1621 sc = device_get_softc(dev);
1622 return (sc->match->driver->set_aperture(dev, aperture));
1626 * Writes a GTT entry mapping the page at the given offset from the
1627 * beginning of the aperture to the given physical address. Setup the
1628 * caching mode according to flags.
1630 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1631 * from corresponding BAR start. For gen 4, offset is 512KB +
1632 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1634 * Also, the bits of the physical page address above 4GB needs to be
1635 * placed into bits 40-32 of PTE.
1638 agp_i810_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1643 pte = (u_int32_t)physical | I810_PTE_VALID;
1644 if (flags == AGP_DCACHE_MEMORY)
1645 pte |= I810_PTE_LOCAL;
1646 else if (flags == AGP_USER_CACHED_MEMORY)
1647 pte |= I830_PTE_SYSTEM_CACHED;
1648 agp_i810_write_gtt(dev, index, pte);
1652 agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte)
1654 struct agp_i810_softc *sc;
1656 sc = device_get_softc(dev);
1657 bus_write_4(sc->sc_res[0], AGP_I810_GTT + index * 4, pte);
1661 agp_i830_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1666 pte = (u_int32_t)physical | I810_PTE_VALID;
1667 if (flags == AGP_USER_CACHED_MEMORY)
1668 pte |= I830_PTE_SYSTEM_CACHED;
1669 agp_i810_write_gtt(dev, index, pte);
1673 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1678 pte = (u_int32_t)physical | I810_PTE_VALID;
1679 if (flags == AGP_USER_CACHED_MEMORY)
1680 pte |= I830_PTE_SYSTEM_CACHED;
1681 pte |= (physical & 0x0000000f00000000ull) >> 28;
1682 agp_i915_write_gtt(dev, index, pte);
1686 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1688 struct agp_i810_softc *sc;
1690 sc = device_get_softc(dev);
1691 bus_write_4(sc->sc_res[1], index * 4, pte);
1695 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1700 pte = (u_int32_t)physical | I810_PTE_VALID;
1701 if (flags == AGP_USER_CACHED_MEMORY)
1702 pte |= I830_PTE_SYSTEM_CACHED;
1703 pte |= (physical & 0x0000000f00000000ull) >> 28;
1704 agp_i965_write_gtt(dev, index, pte);
1708 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1710 struct agp_i810_softc *sc;
1712 sc = device_get_softc(dev);
1713 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1717 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1722 pte = (u_int32_t)physical | I810_PTE_VALID;
1723 if (flags == AGP_USER_CACHED_MEMORY)
1724 pte |= I830_PTE_SYSTEM_CACHED;
1725 pte |= (physical & 0x0000000f00000000ull) >> 28;
1726 agp_g4x_write_gtt(dev, index, pte);
1730 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1732 struct agp_i810_softc *sc;
1734 sc = device_get_softc(dev);
1735 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1739 agp_sb_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1742 int type_mask, gfdt;
1745 pte = (u_int32_t)physical | I810_PTE_VALID;
1746 type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT;
1747 gfdt = (flags & AGP_USER_CACHED_MEMORY_GFDT) != 0 ? GEN6_PTE_GFDT : 0;
1749 if (type_mask == AGP_USER_MEMORY)
1750 pte |= GEN6_PTE_UNCACHED;
1751 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC)
1752 pte |= GEN6_PTE_LLC_MLC | gfdt;
1754 pte |= GEN6_PTE_LLC | gfdt;
1756 pte |= (physical & 0x000000ff00000000ull) >> 28;
1757 agp_sb_write_gtt(dev, index, pte);
1761 agp_sb_write_gtt(device_t dev, u_int index, uint32_t pte)
1763 struct agp_i810_softc *sc;
1765 sc = device_get_softc(dev);
1766 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1770 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1772 struct agp_i810_softc *sc = device_get_softc(dev);
1775 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1776 device_printf(dev, "failed: offset is 0x%08jx, "
1777 "shift is %d, entries is %d\n", (intmax_t)offset,
1778 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1781 index = offset >> AGP_PAGE_SHIFT;
1782 if (sc->stolen != 0 && index < sc->stolen) {
1783 device_printf(dev, "trying to bind into stolen memory\n");
1786 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1791 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1793 struct agp_i810_softc *sc;
1796 sc = device_get_softc(dev);
1797 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1799 index = offset >> AGP_PAGE_SHIFT;
1800 if (sc->stolen != 0 && index < sc->stolen) {
1801 device_printf(dev, "trying to unbind from stolen memory\n");
1804 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1809 agp_i810_read_gtt_pte(device_t dev, u_int index)
1811 struct agp_i810_softc *sc;
1814 sc = device_get_softc(dev);
1815 pte = bus_read_4(sc->sc_res[0], AGP_I810_GTT + index * 4);
1820 agp_i915_read_gtt_pte(device_t dev, u_int index)
1822 struct agp_i810_softc *sc;
1825 sc = device_get_softc(dev);
1826 pte = bus_read_4(sc->sc_res[1], index * 4);
1831 agp_i965_read_gtt_pte(device_t dev, u_int index)
1833 struct agp_i810_softc *sc;
1836 sc = device_get_softc(dev);
1837 pte = bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1842 agp_g4x_read_gtt_pte(device_t dev, u_int index)
1844 struct agp_i810_softc *sc;
1847 sc = device_get_softc(dev);
1848 pte = bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1853 agp_i810_read_gtt_pte_paddr(device_t dev, u_int index)
1855 struct agp_i810_softc *sc;
1859 sc = device_get_softc(dev);
1860 pte = sc->match->driver->read_gtt_pte(dev, index);
1861 res = pte & ~PAGE_MASK;
1866 agp_i915_read_gtt_pte_paddr(device_t dev, u_int index)
1868 struct agp_i810_softc *sc;
1872 sc = device_get_softc(dev);
1873 pte = sc->match->driver->read_gtt_pte(dev, index);
1874 res = (pte & ~PAGE_MASK) | ((pte & 0xf0) << 28);
1879 agp_sb_read_gtt_pte_paddr(device_t dev, u_int index)
1881 struct agp_i810_softc *sc;
1885 sc = device_get_softc(dev);
1886 pte = sc->match->driver->read_gtt_pte(dev, index);
1887 res = (pte & ~PAGE_MASK) | ((pte & 0xff0) << 28);
1892 * Writing via memory mapped registers already flushes all TLBs.
1895 agp_i810_flush_tlb(device_t dev)
1900 agp_i810_enable(device_t dev, u_int32_t mode)
1906 static struct agp_memory *
1907 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
1909 struct agp_i810_softc *sc;
1910 struct agp_memory *mem;
1913 sc = device_get_softc(dev);
1915 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
1916 sc->agp.as_allocated + size > sc->agp.as_maxmem)
1921 * Mapping local DRAM into GATT.
1923 if (sc->match->driver->chiptype != CHIP_I810)
1925 if (size != sc->dcache_size)
1927 } else if (type == 2) {
1929 * Type 2 is the contiguous physical memory type, that hands
1930 * back a physical address. This is used for cursors on i810.
1931 * Hand back as many single pages with physical as the user
1932 * wants, but only allow one larger allocation (ARGB cursor)
1935 if (size != AGP_PAGE_SIZE) {
1936 if (sc->argb_cursor != NULL)
1939 /* Allocate memory for ARGB cursor, if we can. */
1940 sc->argb_cursor = contigmalloc(size, M_AGP,
1941 0, 0, ~0, PAGE_SIZE, 0);
1942 if (sc->argb_cursor == NULL)
1947 mem = kmalloc(sizeof *mem, M_AGP, M_INTWAIT);
1948 mem->am_id = sc->agp.as_nextid++;
1949 mem->am_size = size;
1950 mem->am_type = type;
1951 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
1952 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
1953 atop(round_page(size)));
1958 if (size == AGP_PAGE_SIZE) {
1960 * Allocate and wire down the page now so that we can
1961 * get its physical address.
1963 VM_OBJECT_LOCK(mem->am_obj);
1964 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NORMAL |
1968 VM_OBJECT_UNLOCK(mem->am_obj);
1969 mem->am_physical = VM_PAGE_TO_PHYS(m);
1972 /* Our allocation is already nicely wired down for us.
1973 * Just grab the physical address.
1975 mem->am_physical = vtophys(sc->argb_cursor);
1978 mem->am_physical = 0;
1981 mem->am_is_bound = 0;
1982 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
1983 sc->agp.as_allocated += size;
1989 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
1991 struct agp_i810_softc *sc;
1993 if (mem->am_is_bound)
1996 sc = device_get_softc(dev);
1998 if (mem->am_type == 2) {
1999 if (mem->am_size == AGP_PAGE_SIZE) {
2001 * Unwire the page which we wired in alloc_memory.
2005 vm_object_hold(mem->am_obj);
2006 m = vm_page_lookup_busy_wait(mem->am_obj, 0,
2008 vm_object_drop(mem->am_obj);
2009 vm_page_unwire(m, 0);
2012 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
2013 sc->argb_cursor = NULL;
2017 sc->agp.as_allocated -= mem->am_size;
2018 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
2020 vm_object_deallocate(mem->am_obj);
2026 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
2028 struct agp_i810_softc *sc;
2031 /* Do some sanity checks first. */
2032 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
2033 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
2034 device_printf(dev, "binding memory at bad offset %#x\n",
2039 sc = device_get_softc(dev);
2040 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
2041 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
2042 if (mem->am_is_bound) {
2043 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2046 /* The memory's already wired down, just stick it in the GTT. */
2047 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2048 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
2049 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
2052 mem->am_offset = offset;
2053 mem->am_is_bound = 1;
2054 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2058 if (mem->am_type != 1)
2059 return (agp_generic_bind_memory(dev, mem, offset));
2062 * Mapping local DRAM into GATT.
2064 if (sc->match->driver->chiptype != CHIP_I810)
2066 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
2067 bus_write_4(sc->sc_res[0],
2068 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
2074 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
2076 struct agp_i810_softc *sc;
2079 sc = device_get_softc(dev);
2081 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
2082 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
2083 if (!mem->am_is_bound) {
2084 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2088 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2089 sc->match->driver->install_gtt_pte(dev,
2090 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
2093 mem->am_is_bound = 0;
2094 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2098 if (mem->am_type != 1)
2099 return (agp_generic_unbind_memory(dev, mem));
2101 if (sc->match->driver->chiptype != CHIP_I810)
2103 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2104 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
2110 static device_method_t agp_i810_methods[] = {
2111 /* Device interface */
2112 DEVMETHOD(device_identify, agp_i810_identify),
2113 DEVMETHOD(device_probe, agp_i810_probe),
2114 DEVMETHOD(device_attach, agp_i810_attach),
2115 DEVMETHOD(device_detach, agp_i810_detach),
2116 DEVMETHOD(device_suspend, bus_generic_suspend),
2117 DEVMETHOD(device_resume, agp_i810_resume),
2120 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
2121 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
2122 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
2123 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
2124 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
2125 DEVMETHOD(agp_enable, agp_i810_enable),
2126 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
2127 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
2128 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
2129 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
2130 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
2135 static driver_t agp_i810_driver = {
2138 sizeof(struct agp_i810_softc),
2141 static devclass_t agp_devclass;
2143 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, NULL, NULL);
2144 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
2145 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
2147 extern vm_page_t bogus_page;
2150 agp_intel_gtt_clear_range(device_t dev, u_int first_entry, u_int num_entries)
2152 struct agp_i810_softc *sc;
2155 sc = device_get_softc(dev);
2156 for (i = 0; i < num_entries; i++)
2157 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2158 VM_PAGE_TO_PHYS(bogus_page), 0);
2159 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
2163 agp_intel_gtt_insert_pages(device_t dev, u_int first_entry, u_int num_entries,
2164 vm_page_t *pages, u_int flags)
2166 struct agp_i810_softc *sc;
2169 sc = device_get_softc(dev);
2170 for (i = 0; i < num_entries; i++) {
2171 KKASSERT(pages[i]->valid == VM_PAGE_BITS_ALL);
2172 KKASSERT(pages[i]->wire_count > 0);
2173 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2174 VM_PAGE_TO_PHYS(pages[i]), flags);
2176 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
2180 agp_intel_gtt_get(device_t dev)
2182 struct agp_i810_softc *sc;
2183 struct intel_gtt res;
2185 sc = device_get_softc(dev);
2186 res.stolen_size = sc->stolen_size;
2187 res.gtt_total_entries = sc->gtt_total_entries;
2188 res.gtt_mappable_entries = sc->gtt_mappable_entries;
2189 res.do_idle_maps = 0;
2190 res.scratch_page_dma = VM_PAGE_TO_PHYS(bogus_page);
2195 agp_i810_chipset_flush_setup(device_t dev)
2202 agp_i810_chipset_flush_teardown(device_t dev)
2205 /* Nothing to do. */
2209 agp_i810_chipset_flush(device_t dev)
2212 /* Nothing to do. */
2216 agp_i830_chipset_flush(device_t dev)
2218 struct agp_i810_softc *sc;
2222 sc = device_get_softc(dev);
2223 cpu_wbinvd_on_all_cpus();
2224 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2225 bus_write_4(sc->sc_res[0], AGP_I830_HIC, hic | (1 << 31));
2226 for (i = 0; i < 20000 /* 1 sec */; i++) {
2227 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2228 if ((hic & (1 << 31)) != 0)
2235 agp_i915_chipset_flush_alloc_page(device_t dev, uint64_t start, uint64_t end)
2237 struct agp_i810_softc *sc;
2240 sc = device_get_softc(dev);
2241 vga = device_get_parent(dev);
2242 sc->sc_flush_page_rid = 100;
2243 sc->sc_flush_page_res = BUS_ALLOC_RESOURCE(device_get_parent(vga), dev,
2244 SYS_RES_MEMORY, &sc->sc_flush_page_rid, start, end, PAGE_SIZE,
2246 if (sc->sc_flush_page_res == NULL) {
2247 device_printf(dev, "Failed to allocate flush page at 0x%jx\n",
2251 sc->sc_flush_page_vaddr = rman_get_virtual(sc->sc_flush_page_res);
2253 device_printf(dev, "Allocated flush page phys 0x%jx virt %p\n",
2254 (uintmax_t)rman_get_start(sc->sc_flush_page_res),
2255 sc->sc_flush_page_vaddr);
2261 agp_i915_chipset_flush_free_page(device_t dev)
2263 struct agp_i810_softc *sc;
2266 sc = device_get_softc(dev);
2267 vga = device_get_parent(dev);
2268 if (sc->sc_flush_page_res == NULL)
2270 BUS_DEACTIVATE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2271 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2272 BUS_RELEASE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2273 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2277 agp_i915_chipset_flush_setup(device_t dev)
2279 struct agp_i810_softc *sc;
2283 sc = device_get_softc(dev);
2284 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2285 if ((temp & 1) != 0) {
2289 "Found already configured flush page at 0x%jx\n",
2291 sc->sc_bios_allocated_flush_page = 1;
2293 * In the case BIOS initialized the flush pointer (?)
2294 * register, expect that BIOS also set up the resource
2297 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2298 temp + PAGE_SIZE - 1);
2302 sc->sc_bios_allocated_flush_page = 0;
2303 error = agp_i915_chipset_flush_alloc_page(dev, 0, 0xffffffff);
2306 temp = rman_get_start(sc->sc_flush_page_res);
2307 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp | 1, 4);
2313 agp_i915_chipset_flush_teardown(device_t dev)
2315 struct agp_i810_softc *sc;
2318 sc = device_get_softc(dev);
2319 if (sc->sc_flush_page_res == NULL)
2321 if (!sc->sc_bios_allocated_flush_page) {
2322 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2324 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp, 4);
2326 agp_i915_chipset_flush_free_page(dev);
2330 agp_i965_chipset_flush_setup(device_t dev)
2332 struct agp_i810_softc *sc;
2334 uint32_t temp_hi, temp_lo;
2337 sc = device_get_softc(dev);
2339 temp_hi = pci_read_config(sc->bdev, AGP_I965_IFPADDR + 4, 4);
2340 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2342 if ((temp_lo & 1) != 0) {
2343 temp = ((uint64_t)temp_hi << 32) | (temp_lo & ~1);
2346 "Found already configured flush page at 0x%jx\n",
2348 sc->sc_bios_allocated_flush_page = 1;
2350 * In the case BIOS initialized the flush pointer (?)
2351 * register, expect that BIOS also set up the resource
2354 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2355 temp + PAGE_SIZE - 1);
2359 sc->sc_bios_allocated_flush_page = 0;
2360 error = agp_i915_chipset_flush_alloc_page(dev, 0, ~0);
2363 temp = rman_get_start(sc->sc_flush_page_res);
2364 pci_write_config(sc->bdev, AGP_I965_IFPADDR + 4,
2365 (temp >> 32) & UINT32_MAX, 4);
2366 pci_write_config(sc->bdev, AGP_I965_IFPADDR,
2367 (temp & UINT32_MAX) | 1, 4);
2373 agp_i965_chipset_flush_teardown(device_t dev)
2375 struct agp_i810_softc *sc;
2378 sc = device_get_softc(dev);
2379 if (sc->sc_flush_page_res == NULL)
2381 if (!sc->sc_bios_allocated_flush_page) {
2382 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2384 pci_write_config(sc->bdev, AGP_I965_IFPADDR, temp_lo, 4);
2386 agp_i915_chipset_flush_free_page(dev);
2390 agp_i915_chipset_flush(device_t dev)
2392 struct agp_i810_softc *sc;
2394 sc = device_get_softc(dev);
2395 *(uint32_t *)sc->sc_flush_page_vaddr = 1;
2399 agp_intel_gtt_chipset_flush(device_t dev)
2401 struct agp_i810_softc *sc;
2403 sc = device_get_softc(dev);
2404 sc->match->driver->chipset_flush(dev);
2409 agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list)
2414 agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
2415 struct sglist **sg_list)
2418 struct agp_i810_softc *sc;
2427 if (*sg_list != NULL)
2430 sc = device_get_softc(dev);
2432 sg = sglist_alloc(num_entries, M_WAITOK /* XXXKIB */);
2433 for (i = 0; i < num_entries; i++) {
2434 sg->sg_segs[i].ss_paddr = VM_PAGE_TO_PHYS(pages[i]);
2435 sg->sg_segs[i].ss_len = PAGE_SIZE;
2439 error = bus_dma_tag_create(bus_get_dma_tag(dev),
2440 1 /* alignment */, 0 /* boundary */,
2441 1ULL << sc->match->busdma_addr_mask_sz /* lowaddr */,
2442 BUS_SPACE_MAXADDR /* highaddr */,
2443 NULL /* filtfunc */, NULL /* filtfuncarg */,
2444 BUS_SPACE_MAXADDR /* maxsize */,
2445 BUS_SPACE_UNRESTRICTED /* nsegments */,
2446 BUS_SPACE_MAXADDR /* maxsegsz */,
2447 0 /* flags */, NULL /* lockfunc */, NULL /* lockfuncarg */,
2460 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2461 u_int first_entry, u_int flags)
2463 struct agp_i810_softc *sc;
2468 sc = device_get_softc(dev);
2469 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2470 spaddr = sg_list->sg_segs[i].ss_paddr;
2471 slen = sg_list->sg_segs[i].ss_len;
2472 for (; slen > 0; i++) {
2473 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2475 spaddr += AGP_PAGE_SIZE;
2476 slen -= AGP_PAGE_SIZE;
2479 sc->match->driver->read_gtt_pte(dev, first_entry + i - 1);
2483 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2486 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2490 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2494 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2502 return (agp_intel_gtt_get(intel_agp));
2506 intel_gtt_chipset_flush(void)
2509 return (agp_intel_gtt_chipset_flush(intel_agp));
2513 intel_gtt_unmap_memory(struct sglist *sg_list)
2516 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2520 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2521 struct sglist **sg_list)
2524 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2529 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2533 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2537 intel_gtt_get_bridge_device(void)
2539 struct agp_i810_softc *sc;
2541 sc = device_get_softc(intel_agp);
2546 intel_gtt_read_pte_paddr(u_int entry)
2548 struct agp_i810_softc *sc;
2550 sc = device_get_softc(intel_agp);
2551 return (sc->match->driver->read_gtt_pte_paddr(intel_agp, entry));
2555 intel_gtt_read_pte(u_int entry)
2557 struct agp_i810_softc *sc;
2559 sc = device_get_softc(intel_agp);
2560 return (sc->match->driver->read_gtt_pte(intel_agp, entry));
2564 intel_gtt_write(u_int entry, uint32_t val)
2566 struct agp_i810_softc *sc;
2568 sc = device_get_softc(intel_agp);
2569 sc->match->driver->write_gtt(intel_agp, entry, val);