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>
57 #include <bus/pci/pcivar.h>
58 #include <bus/pci/pcireg.h>
61 #include <dev/agp/intel-gtt.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);
248 struct intel_gtt base;
251 static const struct agp_i810_driver agp_i810_i810_driver = {
252 .chiptype = CHIP_I810,
254 .busdma_addr_mask_sz = 32,
255 .res_spec = agp_i810_res_spec,
256 .check_active = agp_i810_check_active,
257 .set_desc = agp_i810_set_desc,
258 .dump_regs = agp_i810_dump_regs,
259 .get_stolen_size = agp_i810_get_stolen_size,
260 .get_gtt_mappable_entries = agp_i810_get_gtt_mappable_entries,
261 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
262 .install_gatt = agp_i810_install_gatt,
263 .deinstall_gatt = agp_i810_deinstall_gatt,
264 .write_gtt = agp_i810_write_gtt,
265 .install_gtt_pte = agp_i810_install_gtt_pte,
266 .read_gtt_pte = agp_i810_read_gtt_pte,
267 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
268 .set_aperture = agp_i810_set_aperture,
269 .chipset_flush_setup = agp_i810_chipset_flush_setup,
270 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
271 .chipset_flush = agp_i810_chipset_flush,
274 static const struct agp_i810_driver agp_i810_i815_driver = {
275 .chiptype = CHIP_I810,
277 .busdma_addr_mask_sz = 32,
278 .res_spec = agp_i810_res_spec,
279 .check_active = agp_i810_check_active,
280 .set_desc = agp_i810_set_desc,
281 .dump_regs = agp_i810_dump_regs,
282 .get_stolen_size = agp_i810_get_stolen_size,
283 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
284 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
285 .install_gatt = agp_i810_install_gatt,
286 .deinstall_gatt = agp_i810_deinstall_gatt,
287 .write_gtt = agp_i810_write_gtt,
288 .install_gtt_pte = agp_i810_install_gtt_pte,
289 .read_gtt_pte = agp_i810_read_gtt_pte,
290 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
291 .set_aperture = agp_i810_set_aperture,
292 .chipset_flush_setup = agp_i810_chipset_flush_setup,
293 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
294 .chipset_flush = agp_i830_chipset_flush,
297 static const struct agp_i810_driver agp_i810_i830_driver = {
298 .chiptype = CHIP_I830,
300 .busdma_addr_mask_sz = 32,
301 .res_spec = agp_i810_res_spec,
302 .check_active = agp_i830_check_active,
303 .set_desc = agp_i810_set_desc,
304 .dump_regs = agp_i830_dump_regs,
305 .get_stolen_size = agp_i830_get_stolen_size,
306 .get_gtt_mappable_entries = agp_i830_get_gtt_mappable_entries,
307 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
308 .install_gatt = agp_i830_install_gatt,
309 .deinstall_gatt = agp_i830_deinstall_gatt,
310 .write_gtt = agp_i810_write_gtt,
311 .install_gtt_pte = agp_i830_install_gtt_pte,
312 .read_gtt_pte = agp_i810_read_gtt_pte,
313 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
314 .set_aperture = agp_i830_set_aperture,
315 .chipset_flush_setup = agp_i810_chipset_flush_setup,
316 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
317 .chipset_flush = agp_i830_chipset_flush,
320 static const struct agp_i810_driver agp_i810_i855_driver = {
321 .chiptype = CHIP_I855,
323 .busdma_addr_mask_sz = 32,
324 .res_spec = agp_i810_res_spec,
325 .check_active = agp_i830_check_active,
326 .set_desc = agp_82852_set_desc,
327 .dump_regs = agp_i855_dump_regs,
328 .get_stolen_size = agp_i915_get_stolen_size,
329 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
330 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
331 .install_gatt = agp_i830_install_gatt,
332 .deinstall_gatt = agp_i830_deinstall_gatt,
333 .write_gtt = agp_i810_write_gtt,
334 .install_gtt_pte = agp_i830_install_gtt_pte,
335 .read_gtt_pte = agp_i810_read_gtt_pte,
336 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
337 .set_aperture = agp_i830_set_aperture,
338 .chipset_flush_setup = agp_i810_chipset_flush_setup,
339 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
340 .chipset_flush = agp_i830_chipset_flush,
343 static const struct agp_i810_driver agp_i810_i865_driver = {
344 .chiptype = CHIP_I855,
346 .busdma_addr_mask_sz = 32,
347 .res_spec = agp_i810_res_spec,
348 .check_active = agp_i830_check_active,
349 .set_desc = agp_i810_set_desc,
350 .dump_regs = agp_i855_dump_regs,
351 .get_stolen_size = agp_i915_get_stolen_size,
352 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
353 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
354 .install_gatt = agp_i830_install_gatt,
355 .deinstall_gatt = agp_i830_deinstall_gatt,
356 .write_gtt = agp_i810_write_gtt,
357 .install_gtt_pte = agp_i830_install_gtt_pte,
358 .read_gtt_pte = agp_i810_read_gtt_pte,
359 .read_gtt_pte_paddr = agp_i810_read_gtt_pte_paddr,
360 .set_aperture = agp_i915_set_aperture,
361 .chipset_flush_setup = agp_i810_chipset_flush_setup,
362 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
363 .chipset_flush = agp_i830_chipset_flush,
366 static const struct agp_i810_driver agp_i810_i915_driver = {
367 .chiptype = CHIP_I915,
369 .busdma_addr_mask_sz = 32,
370 .res_spec = agp_i915_res_spec,
371 .check_active = agp_i915_check_active,
372 .set_desc = agp_i810_set_desc,
373 .dump_regs = agp_i915_dump_regs,
374 .get_stolen_size = agp_i915_get_stolen_size,
375 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
376 .get_gtt_total_entries = agp_i810_get_gtt_total_entries,
377 .install_gatt = agp_i830_install_gatt,
378 .deinstall_gatt = agp_i830_deinstall_gatt,
379 .write_gtt = agp_i915_write_gtt,
380 .install_gtt_pte = agp_i915_install_gtt_pte,
381 .read_gtt_pte = agp_i915_read_gtt_pte,
382 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
383 .set_aperture = agp_i915_set_aperture,
384 .chipset_flush_setup = agp_i915_chipset_flush_setup,
385 .chipset_flush_teardown = agp_i915_chipset_flush_teardown,
386 .chipset_flush = agp_i915_chipset_flush,
389 static const struct agp_i810_driver agp_i810_g965_driver = {
390 .chiptype = CHIP_I965,
392 .busdma_addr_mask_sz = 36,
393 .res_spec = agp_i965_res_spec,
394 .check_active = agp_i915_check_active,
395 .set_desc = agp_i810_set_desc,
396 .dump_regs = agp_i965_dump_regs,
397 .get_stolen_size = agp_i915_get_stolen_size,
398 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
399 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
400 .install_gatt = agp_i830_install_gatt,
401 .deinstall_gatt = agp_i830_deinstall_gatt,
402 .write_gtt = agp_i965_write_gtt,
403 .install_gtt_pte = agp_i965_install_gtt_pte,
404 .read_gtt_pte = agp_i965_read_gtt_pte,
405 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
406 .set_aperture = agp_i915_set_aperture,
407 .chipset_flush_setup = agp_i965_chipset_flush_setup,
408 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
409 .chipset_flush = agp_i915_chipset_flush,
412 static const struct agp_i810_driver agp_i810_g33_driver = {
413 .chiptype = CHIP_G33,
415 .busdma_addr_mask_sz = 36,
416 .res_spec = agp_i915_res_spec,
417 .check_active = agp_i915_check_active,
418 .set_desc = agp_i810_set_desc,
419 .dump_regs = agp_i965_dump_regs,
420 .get_stolen_size = agp_i915_get_stolen_size,
421 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
422 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
423 .install_gatt = agp_i830_install_gatt,
424 .deinstall_gatt = agp_i830_deinstall_gatt,
425 .write_gtt = agp_i915_write_gtt,
426 .install_gtt_pte = agp_i915_install_gtt_pte,
427 .read_gtt_pte = agp_i915_read_gtt_pte,
428 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
429 .set_aperture = agp_i915_set_aperture,
430 .chipset_flush_setup = agp_i965_chipset_flush_setup,
431 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
432 .chipset_flush = agp_i915_chipset_flush,
435 static const struct agp_i810_driver agp_i810_igd_driver = {
436 .chiptype = CHIP_IGD,
438 .busdma_addr_mask_sz = 36,
439 .res_spec = agp_i915_res_spec,
440 .check_active = agp_i915_check_active,
441 .set_desc = agp_i810_set_desc,
442 .dump_regs = agp_i915_dump_regs,
443 .get_stolen_size = agp_i915_get_stolen_size,
444 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
445 .get_gtt_total_entries = agp_i965_get_gtt_total_entries,
446 .install_gatt = agp_i830_install_gatt,
447 .deinstall_gatt = agp_i830_deinstall_gatt,
448 .write_gtt = agp_i915_write_gtt,
449 .install_gtt_pte = agp_i915_install_gtt_pte,
450 .read_gtt_pte = agp_i915_read_gtt_pte,
451 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
452 .set_aperture = agp_i915_set_aperture,
453 .chipset_flush_setup = agp_i965_chipset_flush_setup,
454 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
455 .chipset_flush = agp_i915_chipset_flush,
458 static const struct agp_i810_driver agp_i810_g4x_driver = {
459 .chiptype = CHIP_G4X,
461 .busdma_addr_mask_sz = 36,
462 .res_spec = agp_i965_res_spec,
463 .check_active = agp_i915_check_active,
464 .set_desc = agp_i810_set_desc,
465 .dump_regs = agp_i965_dump_regs,
466 .get_stolen_size = agp_i915_get_stolen_size,
467 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
468 .get_gtt_total_entries = agp_gen5_get_gtt_total_entries,
469 .install_gatt = agp_i830_install_gatt,
470 .deinstall_gatt = agp_i830_deinstall_gatt,
471 .write_gtt = agp_g4x_write_gtt,
472 .install_gtt_pte = agp_g4x_install_gtt_pte,
473 .read_gtt_pte = agp_g4x_read_gtt_pte,
474 .read_gtt_pte_paddr = agp_i915_read_gtt_pte_paddr,
475 .set_aperture = agp_i915_set_aperture,
476 .chipset_flush_setup = agp_i965_chipset_flush_setup,
477 .chipset_flush_teardown = agp_i965_chipset_flush_teardown,
478 .chipset_flush = agp_i915_chipset_flush,
481 static const struct agp_i810_driver agp_i810_sb_driver = {
484 .busdma_addr_mask_sz = 40,
485 .res_spec = agp_g4x_res_spec,
486 .check_active = agp_sb_check_active,
487 .set_desc = agp_i810_set_desc,
488 .dump_regs = agp_sb_dump_regs,
489 .get_stolen_size = agp_sb_get_stolen_size,
490 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
491 .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
492 .install_gatt = agp_i830_install_gatt,
493 .deinstall_gatt = agp_i830_deinstall_gatt,
494 .write_gtt = agp_sb_write_gtt,
495 .install_gtt_pte = agp_sb_install_gtt_pte,
496 .read_gtt_pte = agp_g4x_read_gtt_pte,
497 .read_gtt_pte_paddr = agp_sb_read_gtt_pte_paddr,
498 .set_aperture = agp_i915_set_aperture,
499 .chipset_flush_setup = agp_i810_chipset_flush_setup,
500 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
501 .chipset_flush = agp_i810_chipset_flush,
504 static const struct agp_i810_driver valleyview_gtt_driver = {
507 .busdma_addr_mask_sz = 40,
508 .res_spec = agp_g4x_res_spec,
509 .check_active = agp_sb_check_active,
510 .set_desc = agp_i810_set_desc,
511 .dump_regs = agp_sb_dump_regs,
512 .get_stolen_size = agp_sb_get_stolen_size,
513 .get_gtt_mappable_entries = agp_i915_get_gtt_mappable_entries,
514 .get_gtt_total_entries = agp_sb_get_gtt_total_entries,
515 .install_gatt = agp_i830_install_gatt,
516 .deinstall_gatt = agp_i830_deinstall_gatt,
517 .write_gtt = agp_sb_write_gtt,
518 .install_gtt_pte = agp_sb_install_gtt_pte,
519 .read_gtt_pte = agp_g4x_read_gtt_pte,
520 .read_gtt_pte_paddr = agp_sb_read_gtt_pte_paddr,
521 .set_aperture = agp_i915_set_aperture,
522 .chipset_flush_setup = agp_i810_chipset_flush_setup,
523 .chipset_flush_teardown = agp_i810_chipset_flush_teardown,
524 .chipset_flush = agp_i810_chipset_flush,
527 /* For adding new devices, devid is the id of the graphics controller
528 * (pci:0:2:0, for example). The placeholder (usually at pci:0:2:1) for the
529 * second head should never be added. The bridge_offset is the offset to
530 * subtract from devid to get the id of the hostb that the device is on.
532 static const struct agp_i810_match {
535 const struct agp_i810_driver *driver;
536 } agp_i810_matches[] = {
539 .name = "Intel 82810 (i810 GMCH) SVGA controller",
540 .driver = &agp_i810_i810_driver
544 .name = "Intel 82810-DC100 (i810-DC100 GMCH) SVGA controller",
545 .driver = &agp_i810_i810_driver
549 .name = "Intel 82810E (i810E GMCH) SVGA controller",
550 .driver = &agp_i810_i810_driver
554 .name = "Intel 82815 (i815 GMCH) SVGA controller",
555 .driver = &agp_i810_i815_driver
559 .name = "Intel 82830M (830M GMCH) SVGA controller",
560 .driver = &agp_i810_i830_driver
564 .name = "Intel 82845M (845M GMCH) SVGA controller",
565 .driver = &agp_i810_i830_driver
569 .name = "Intel 82852/855GM SVGA controller",
570 .driver = &agp_i810_i855_driver
574 .name = "Intel 82865G (865G GMCH) SVGA controller",
575 .driver = &agp_i810_i865_driver
579 .name = "Intel 82915G (915G GMCH) SVGA controller",
580 .driver = &agp_i810_i915_driver
584 .name = "Intel E7221 SVGA controller",
585 .driver = &agp_i810_i915_driver
589 .name = "Intel 82915GM (915GM GMCH) SVGA controller",
590 .driver = &agp_i810_i915_driver
594 .name = "Intel 82945G (945G GMCH) SVGA controller",
595 .driver = &agp_i810_i915_driver
599 .name = "Intel 82945GM (945GM GMCH) SVGA controller",
600 .driver = &agp_i810_i915_driver
604 .name = "Intel 945GME SVGA controller",
605 .driver = &agp_i810_i915_driver
609 .name = "Intel 946GZ SVGA controller",
610 .driver = &agp_i810_g965_driver
614 .name = "Intel G965 SVGA controller",
615 .driver = &agp_i810_g965_driver
619 .name = "Intel Q965 SVGA controller",
620 .driver = &agp_i810_g965_driver
624 .name = "Intel G965 SVGA controller",
625 .driver = &agp_i810_g965_driver
629 .name = "Intel Q35 SVGA controller",
630 .driver = &agp_i810_g33_driver
634 .name = "Intel G33 SVGA controller",
635 .driver = &agp_i810_g33_driver
639 .name = "Intel Q33 SVGA controller",
640 .driver = &agp_i810_g33_driver
644 .name = "Intel Pineview SVGA controller",
645 .driver = &agp_i810_igd_driver
649 .name = "Intel Pineview (M) SVGA controller",
650 .driver = &agp_i810_igd_driver
654 .name = "Intel GM965 SVGA controller",
655 .driver = &agp_i810_g965_driver
659 .name = "Intel GME965 SVGA controller",
660 .driver = &agp_i810_g965_driver
664 .name = "Intel GM45 SVGA controller",
665 .driver = &agp_i810_g4x_driver
669 .name = "Intel Eaglelake SVGA controller",
670 .driver = &agp_i810_g4x_driver
674 .name = "Intel Q45 SVGA controller",
675 .driver = &agp_i810_g4x_driver
679 .name = "Intel G45 SVGA controller",
680 .driver = &agp_i810_g4x_driver
684 .name = "Intel G41 SVGA controller",
685 .driver = &agp_i810_g4x_driver
689 .name = "Intel Ironlake (D) SVGA controller",
690 .driver = &agp_i810_g4x_driver
694 .name = "Intel Ironlake (M) SVGA controller",
695 .driver = &agp_i810_g4x_driver
699 .name = "SandyBridge desktop GT1 IG",
700 .driver = &agp_i810_sb_driver
704 .name = "SandyBridge desktop GT2 IG",
705 .driver = &agp_i810_sb_driver
709 .name = "SandyBridge desktop GT2+ IG",
710 .driver = &agp_i810_sb_driver
714 .name = "SandyBridge mobile GT1 IG",
715 .driver = &agp_i810_sb_driver
719 .name = "SandyBridge mobile GT2 IG",
720 .driver = &agp_i810_sb_driver
724 .name = "SandyBridge mobile GT2+ IG",
725 .driver = &agp_i810_sb_driver
729 .name = "SandyBridge server IG",
730 .driver = &agp_i810_sb_driver
734 .name = "IvyBridge desktop GT1 IG",
735 .driver = &agp_i810_sb_driver
739 .name = "IvyBridge desktop GT2 IG",
740 .driver = &agp_i810_sb_driver
744 .name = "IvyBridge mobile GT1 IG",
745 .driver = &agp_i810_sb_driver
749 .name = "IvyBridge mobile GT2 IG",
750 .driver = &agp_i810_sb_driver
754 .name = "IvyBridge server GT1 IG",
755 .driver = &agp_i810_sb_driver
759 .name = "IvyBridge server GT2 IG",
760 .driver = &agp_i810_sb_driver
764 .name = "ValleyView",
765 .driver = &valleyview_gtt_driver
769 .name = "Haswell desktop GT1 IG",
770 .driver = &agp_i810_sb_driver
774 .name = "Haswell desktop GT2 IG",
775 .driver = &agp_i810_sb_driver
777 { 0x0422, "Haswell", &agp_i810_sb_driver },
780 .name = "Haswell mobile GT1 IG",
781 .driver = &agp_i810_sb_driver
785 .name = "Haswell mobile GT2 IG",
786 .driver = &agp_i810_sb_driver
788 { 0x0426, "Haswell", &agp_i810_sb_driver },
791 .name = "Haswell server GT1 IG",
792 .driver = &agp_i810_sb_driver
796 .name = "Haswell server GT2 IG",
797 .driver = &agp_i810_sb_driver
799 { 0x042a, "Haswell", &agp_i810_sb_driver },
800 { 0x0c02, "Haswell", &agp_i810_sb_driver },
801 { 0x0c12, "Haswell", &agp_i810_sb_driver },
802 { 0x0c22, "Haswell", &agp_i810_sb_driver },
803 { 0x0c06, "Haswell", &agp_i810_sb_driver },
806 .name = "Haswell SDV",
807 .driver = &agp_i810_sb_driver
809 { 0x0c26, "Haswell", &agp_i810_sb_driver },
810 { 0x0c0a, "Haswell", &agp_i810_sb_driver },
811 { 0x0c1a, "Haswell", &agp_i810_sb_driver },
812 { 0x0c2a, "Haswell", &agp_i810_sb_driver },
813 { 0x0a02, "Haswell", &agp_i810_sb_driver },
814 { 0x0a12, "Haswell", &agp_i810_sb_driver },
815 { 0x0a22, "Haswell", &agp_i810_sb_driver },
816 { 0x0a06, "Haswell", &agp_i810_sb_driver },
817 { 0x0a16, "Haswell", &agp_i810_sb_driver },
818 { 0x0a26, "Haswell", &agp_i810_sb_driver },
819 { 0x0a0a, "Haswell", &agp_i810_sb_driver },
820 { 0x0a1a, "Haswell", &agp_i810_sb_driver },
821 { 0x0a2a, "Haswell", &agp_i810_sb_driver },
822 { 0x0d12, "Haswell", &agp_i810_sb_driver },
823 { 0x0d22, "Haswell", &agp_i810_sb_driver },
824 { 0x0d32, "Haswell", &agp_i810_sb_driver },
825 { 0x0d16, "Haswell", &agp_i810_sb_driver },
826 { 0x0d26, "Haswell", &agp_i810_sb_driver },
827 { 0x0d36, "Haswell", &agp_i810_sb_driver },
828 { 0x0d1a, "Haswell", &agp_i810_sb_driver },
829 { 0x0d2a, "Haswell", &agp_i810_sb_driver },
830 { 0x0d3a, "Haswell", &agp_i810_sb_driver },
836 static const struct agp_i810_match*
837 agp_i810_match(device_t dev)
841 if (pci_get_vendor(dev) != PCI_VENDOR_INTEL)
844 devid = pci_get_device(dev);
845 for (i = 0; agp_i810_matches[i].devid != 0; i++) {
846 if (agp_i810_matches[i].devid == devid)
849 if (agp_i810_matches[i].devid == 0)
852 return (&agp_i810_matches[i]);
856 * Find bridge device.
859 agp_i810_find_bridge(device_t dev)
862 return (pci_find_dbsf(0, 0, 0, 0));
866 agp_i810_identify(driver_t *driver, device_t parent)
869 if (device_find_child(parent, "agp", -1) == NULL &&
870 agp_i810_match(parent))
871 device_add_child(parent, "agp", -1);
875 agp_i810_check_active(device_t bridge_dev)
879 smram = pci_read_config(bridge_dev, AGP_I810_SMRAM, 1);
880 if ((smram & AGP_I810_SMRAM_GMS) == AGP_I810_SMRAM_GMS_DISABLED)
886 agp_i830_check_active(device_t bridge_dev)
890 gcc1 = pci_read_config(bridge_dev, AGP_I830_GCC1, 1);
891 if ((gcc1 & AGP_I830_GCC1_DEV2) == AGP_I830_GCC1_DEV2_DISABLED)
897 agp_i915_check_active(device_t bridge_dev)
901 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
902 if ((deven & AGP_I915_DEVEN_D2F0) == AGP_I915_DEVEN_D2F0_DISABLED)
908 agp_sb_check_active(device_t bridge_dev)
912 deven = pci_read_config(bridge_dev, AGP_I915_DEVEN, 4);
913 if ((deven & AGP_SB_DEVEN_D2EN) == AGP_SB_DEVEN_D2EN_DISABLED)
919 agp_82852_set_desc(device_t dev, const struct agp_i810_match *match)
922 switch (pci_read_config(dev, AGP_I85X_CAPID, 1)) {
925 "Intel 82855GME (855GME GMCH) SVGA controller");
929 "Intel 82855GM (855GM GMCH) SVGA controller");
933 "Intel 82852GME (852GME GMCH) SVGA controller");
937 "Intel 82852GM (852GM GMCH) SVGA controller");
941 "Intel 8285xM (85xGM GMCH) SVGA controller");
947 agp_i810_set_desc(device_t dev, const struct agp_i810_match *match)
950 device_set_desc(dev, match->name);
954 agp_i810_probe(device_t dev)
957 const struct agp_i810_match *match;
960 if (resource_disabled("agp", device_get_unit(dev)))
962 match = agp_i810_match(dev);
966 bdev = agp_i810_find_bridge(dev);
969 kprintf("I810: can't find bridge device\n");
974 * checking whether internal graphics device has been activated.
976 err = match->driver->check_active(bdev);
979 kprintf("i810: disabled, not probing\n");
983 match->driver->set_desc(dev, match);
984 return (BUS_PROBE_DEFAULT);
988 agp_i810_dump_regs(device_t dev)
990 struct agp_i810_softc *sc = device_get_softc(dev);
992 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
993 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
994 device_printf(dev, "AGP_I810_MISCC: 0x%04x\n",
995 pci_read_config(sc->bdev, AGP_I810_MISCC, 2));
999 agp_i830_dump_regs(device_t dev)
1001 struct agp_i810_softc *sc = device_get_softc(dev);
1003 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
1004 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
1005 device_printf(dev, "AGP_I830_GCC1: 0x%02x\n",
1006 pci_read_config(sc->bdev, AGP_I830_GCC1, 1));
1010 agp_i855_dump_regs(device_t dev)
1012 struct agp_i810_softc *sc = device_get_softc(dev);
1014 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
1015 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
1016 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
1017 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
1021 agp_i915_dump_regs(device_t dev)
1023 struct agp_i810_softc *sc = device_get_softc(dev);
1025 device_printf(dev, "AGP_I810_PGTBL_CTL: %08x\n",
1026 bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL));
1027 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
1028 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
1029 device_printf(dev, "AGP_I915_MSAC: 0x%02x\n",
1030 pci_read_config(sc->bdev, AGP_I915_MSAC, 1));
1034 agp_i965_dump_regs(device_t dev)
1036 struct agp_i810_softc *sc = device_get_softc(dev);
1038 device_printf(dev, "AGP_I965_PGTBL_CTL2: %08x\n",
1039 bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2));
1040 device_printf(dev, "AGP_I855_GCC1: 0x%02x\n",
1041 pci_read_config(sc->bdev, AGP_I855_GCC1, 1));
1042 device_printf(dev, "AGP_I965_MSAC: 0x%02x\n",
1043 pci_read_config(sc->bdev, AGP_I965_MSAC, 1));
1047 agp_sb_dump_regs(device_t dev)
1049 struct agp_i810_softc *sc = device_get_softc(dev);
1051 device_printf(dev, "AGP_SNB_GFX_MODE: %08x\n",
1052 bus_read_4(sc->sc_res[0], AGP_SNB_GFX_MODE));
1053 device_printf(dev, "AGP_SNB_GCC1: 0x%04x\n",
1054 pci_read_config(sc->bdev, AGP_SNB_GCC1, 2));
1058 agp_i810_get_stolen_size(device_t dev)
1060 struct agp_i810_softc *sc;
1062 sc = device_get_softc(dev);
1064 sc->stolen_size = 0;
1069 agp_i830_get_stolen_size(device_t dev)
1071 struct agp_i810_softc *sc;
1074 sc = device_get_softc(dev);
1076 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 1);
1077 switch (gcc1 & AGP_I830_GCC1_GMS) {
1078 case AGP_I830_GCC1_GMS_STOLEN_512:
1079 sc->stolen = (512 - 132) * 1024 / 4096;
1080 sc->stolen_size = 512 * 1024;
1082 case AGP_I830_GCC1_GMS_STOLEN_1024:
1083 sc->stolen = (1024 - 132) * 1024 / 4096;
1084 sc->stolen_size = 1024 * 1024;
1086 case AGP_I830_GCC1_GMS_STOLEN_8192:
1087 sc->stolen = (8192 - 132) * 1024 / 4096;
1088 sc->stolen_size = 8192 * 1024;
1093 "unknown memory configuration, disabling (GCC1 %x)\n",
1101 agp_i915_get_stolen_size(device_t dev)
1103 struct agp_i810_softc *sc;
1104 unsigned int gcc1, stolen, gtt_size;
1106 sc = device_get_softc(dev);
1109 * Stolen memory is set up at the beginning of the aperture by
1110 * the BIOS, consisting of the GATT followed by 4kb for the
1113 switch (sc->match->driver->chiptype) {
1121 switch (bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL) &
1122 AGP_I810_PGTBL_SIZE_MASK) {
1123 case AGP_I810_PGTBL_SIZE_128KB:
1126 case AGP_I810_PGTBL_SIZE_256KB:
1129 case AGP_I810_PGTBL_SIZE_512KB:
1132 case AGP_I965_PGTBL_SIZE_1MB:
1135 case AGP_I965_PGTBL_SIZE_2MB:
1138 case AGP_I965_PGTBL_SIZE_1_5MB:
1139 gtt_size = 1024 + 512;
1142 device_printf(dev, "Bad PGTBL size\n");
1147 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 2);
1148 switch (gcc1 & AGP_G33_MGGC_GGMS_MASK) {
1149 case AGP_G33_MGGC_GGMS_SIZE_1M:
1152 case AGP_G33_MGGC_GGMS_SIZE_2M:
1156 device_printf(dev, "Bad PGTBL size\n");
1165 device_printf(dev, "Bad chiptype\n");
1169 /* GCC1 is called MGGC on i915+ */
1170 gcc1 = pci_read_config(sc->bdev, AGP_I855_GCC1, 1);
1171 switch (gcc1 & AGP_I855_GCC1_GMS) {
1172 case AGP_I855_GCC1_GMS_STOLEN_1M:
1175 case AGP_I855_GCC1_GMS_STOLEN_4M:
1178 case AGP_I855_GCC1_GMS_STOLEN_8M:
1181 case AGP_I855_GCC1_GMS_STOLEN_16M:
1184 case AGP_I855_GCC1_GMS_STOLEN_32M:
1187 case AGP_I915_GCC1_GMS_STOLEN_48M:
1188 stolen = sc->match->driver->gen > 2 ? 48 * 1024 : 0;
1190 case AGP_I915_GCC1_GMS_STOLEN_64M:
1191 stolen = sc->match->driver->gen > 2 ? 64 * 1024 : 0;
1193 case AGP_G33_GCC1_GMS_STOLEN_128M:
1194 stolen = sc->match->driver->gen > 2 ? 128 * 1024 : 0;
1196 case AGP_G33_GCC1_GMS_STOLEN_256M:
1197 stolen = sc->match->driver->gen > 2 ? 256 * 1024 : 0;
1199 case AGP_G4X_GCC1_GMS_STOLEN_96M:
1200 if (sc->match->driver->chiptype == CHIP_I965 ||
1201 sc->match->driver->chiptype == CHIP_G4X)
1206 case AGP_G4X_GCC1_GMS_STOLEN_160M:
1207 if (sc->match->driver->chiptype == CHIP_I965 ||
1208 sc->match->driver->chiptype == CHIP_G4X)
1209 stolen = 160 * 1024;
1213 case AGP_G4X_GCC1_GMS_STOLEN_224M:
1214 if (sc->match->driver->chiptype == CHIP_I965 ||
1215 sc->match->driver->chiptype == CHIP_G4X)
1216 stolen = 224 * 1024;
1220 case AGP_G4X_GCC1_GMS_STOLEN_352M:
1221 if (sc->match->driver->chiptype == CHIP_I965 ||
1222 sc->match->driver->chiptype == CHIP_G4X)
1223 stolen = 352 * 1024;
1229 "unknown memory configuration, disabling (GCC1 %x)\n",
1235 sc->stolen_size = stolen * 1024;
1236 sc->stolen = (stolen - gtt_size) * 1024 / 4096;
1242 agp_sb_get_stolen_size(device_t dev)
1244 struct agp_i810_softc *sc;
1247 sc = device_get_softc(dev);
1248 gmch_ctl = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
1249 switch (gmch_ctl & AGP_SNB_GMCH_GMS_STOLEN_MASK) {
1250 case AGP_SNB_GMCH_GMS_STOLEN_32M:
1251 sc->stolen_size = 32 * 1024 * 1024;
1253 case AGP_SNB_GMCH_GMS_STOLEN_64M:
1254 sc->stolen_size = 64 * 1024 * 1024;
1256 case AGP_SNB_GMCH_GMS_STOLEN_96M:
1257 sc->stolen_size = 96 * 1024 * 1024;
1259 case AGP_SNB_GMCH_GMS_STOLEN_128M:
1260 sc->stolen_size = 128 * 1024 * 1024;
1262 case AGP_SNB_GMCH_GMS_STOLEN_160M:
1263 sc->stolen_size = 160 * 1024 * 1024;
1265 case AGP_SNB_GMCH_GMS_STOLEN_192M:
1266 sc->stolen_size = 192 * 1024 * 1024;
1268 case AGP_SNB_GMCH_GMS_STOLEN_224M:
1269 sc->stolen_size = 224 * 1024 * 1024;
1271 case AGP_SNB_GMCH_GMS_STOLEN_256M:
1272 sc->stolen_size = 256 * 1024 * 1024;
1274 case AGP_SNB_GMCH_GMS_STOLEN_288M:
1275 sc->stolen_size = 288 * 1024 * 1024;
1277 case AGP_SNB_GMCH_GMS_STOLEN_320M:
1278 sc->stolen_size = 320 * 1024 * 1024;
1280 case AGP_SNB_GMCH_GMS_STOLEN_352M:
1281 sc->stolen_size = 352 * 1024 * 1024;
1283 case AGP_SNB_GMCH_GMS_STOLEN_384M:
1284 sc->stolen_size = 384 * 1024 * 1024;
1286 case AGP_SNB_GMCH_GMS_STOLEN_416M:
1287 sc->stolen_size = 416 * 1024 * 1024;
1289 case AGP_SNB_GMCH_GMS_STOLEN_448M:
1290 sc->stolen_size = 448 * 1024 * 1024;
1292 case AGP_SNB_GMCH_GMS_STOLEN_480M:
1293 sc->stolen_size = 480 * 1024 * 1024;
1295 case AGP_SNB_GMCH_GMS_STOLEN_512M:
1296 sc->stolen_size = 512 * 1024 * 1024;
1299 sc->stolen = (sc->stolen_size - 4) / 4096;
1304 agp_i810_get_gtt_mappable_entries(device_t dev)
1306 struct agp_i810_softc *sc;
1310 sc = device_get_softc(dev);
1311 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1312 if ((miscc & AGP_I810_MISCC_WINSIZE) == AGP_I810_MISCC_WINSIZE_32)
1316 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1321 agp_i830_get_gtt_mappable_entries(device_t dev)
1323 struct agp_i810_softc *sc;
1327 sc = device_get_softc(dev);
1328 gmch_ctl = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1329 if ((gmch_ctl & AGP_I830_GCC1_GMASIZE) == AGP_I830_GCC1_GMASIZE_64)
1333 sc->gtt_mappable_entries = (ap * 1024 * 1024) >> AGP_PAGE_SHIFT;
1338 agp_i915_get_gtt_mappable_entries(device_t dev)
1340 struct agp_i810_softc *sc;
1343 sc = device_get_softc(dev);
1344 ap = AGP_GET_APERTURE(dev);
1345 sc->gtt_mappable_entries = ap >> AGP_PAGE_SHIFT;
1350 agp_i810_get_gtt_total_entries(device_t dev)
1352 struct agp_i810_softc *sc;
1354 sc = device_get_softc(dev);
1355 sc->gtt_total_entries = sc->gtt_mappable_entries;
1360 agp_i965_get_gtt_total_entries(device_t dev)
1362 struct agp_i810_softc *sc;
1363 uint32_t pgetbl_ctl;
1366 sc = device_get_softc(dev);
1368 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1369 switch (pgetbl_ctl & AGP_I810_PGTBL_SIZE_MASK) {
1370 case AGP_I810_PGTBL_SIZE_128KB:
1371 sc->gtt_total_entries = 128 * 1024 / 4;
1373 case AGP_I810_PGTBL_SIZE_256KB:
1374 sc->gtt_total_entries = 256 * 1024 / 4;
1376 case AGP_I810_PGTBL_SIZE_512KB:
1377 sc->gtt_total_entries = 512 * 1024 / 4;
1379 /* GTT pagetable sizes bigger than 512KB are not possible on G33! */
1380 case AGP_I810_PGTBL_SIZE_1MB:
1381 sc->gtt_total_entries = 1024 * 1024 / 4;
1383 case AGP_I810_PGTBL_SIZE_2MB:
1384 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1386 case AGP_I810_PGTBL_SIZE_1_5MB:
1387 sc->gtt_total_entries = (1024 + 512) * 1024 / 4;
1390 device_printf(dev, "Unknown page table size\n");
1397 agp_gen5_adjust_pgtbl_size(device_t dev, uint32_t sz)
1399 struct agp_i810_softc *sc;
1400 uint32_t pgetbl_ctl, pgetbl_ctl2;
1402 sc = device_get_softc(dev);
1404 /* Disable per-process page table. */
1405 pgetbl_ctl2 = bus_read_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2);
1406 pgetbl_ctl2 &= ~AGP_I810_PGTBL_ENABLED;
1407 bus_write_4(sc->sc_res[0], AGP_I965_PGTBL_CTL2, pgetbl_ctl2);
1409 /* Write the new ggtt size. */
1410 pgetbl_ctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1411 pgetbl_ctl &= ~AGP_I810_PGTBL_SIZE_MASK;
1413 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgetbl_ctl);
1417 agp_gen5_get_gtt_total_entries(device_t dev)
1419 struct agp_i810_softc *sc;
1422 sc = device_get_softc(dev);
1424 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1425 switch (gcc1 & AGP_G4x_GCC1_SIZE_MASK) {
1426 case AGP_G4x_GCC1_SIZE_1M:
1427 case AGP_G4x_GCC1_SIZE_VT_1M:
1428 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1MB);
1430 case AGP_G4x_GCC1_SIZE_VT_1_5M:
1431 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_1_5MB);
1433 case AGP_G4x_GCC1_SIZE_2M:
1434 case AGP_G4x_GCC1_SIZE_VT_2M:
1435 agp_gen5_adjust_pgtbl_size(dev, AGP_I810_PGTBL_SIZE_2MB);
1438 device_printf(dev, "Unknown page table size\n");
1442 return (agp_i965_get_gtt_total_entries(dev));
1446 agp_sb_get_gtt_total_entries(device_t dev)
1448 struct agp_i810_softc *sc;
1451 sc = device_get_softc(dev);
1453 gcc1 = pci_read_config(sc->bdev, AGP_SNB_GCC1, 2);
1454 switch (gcc1 & AGP_SNB_GTT_SIZE_MASK) {
1456 case AGP_SNB_GTT_SIZE_0M:
1457 kprintf("Bad GTT size mask: 0x%04x\n", gcc1);
1459 case AGP_SNB_GTT_SIZE_1M:
1460 sc->gtt_total_entries = 1024 * 1024 / 4;
1462 case AGP_SNB_GTT_SIZE_2M:
1463 sc->gtt_total_entries = 2 * 1024 * 1024 / 4;
1470 agp_i810_install_gatt(device_t dev)
1472 struct agp_i810_softc *sc;
1474 sc = device_get_softc(dev);
1476 /* Some i810s have on-chip memory called dcache. */
1477 if ((bus_read_1(sc->sc_res[0], AGP_I810_DRT) & AGP_I810_DRT_POPULATED)
1479 sc->dcache_size = 4 * 1024 * 1024;
1481 sc->dcache_size = 0;
1483 /* According to the specs the gatt on the i810 must be 64k. */
1484 sc->gatt->ag_virtual = contigmalloc(64 * 1024, M_AGP, 0, 0, ~0,
1486 if (sc->gatt->ag_virtual == NULL) {
1488 device_printf(dev, "contiguous allocation failed\n");
1492 bzero(sc->gatt->ag_virtual, sc->gatt->ag_entries * sizeof(u_int32_t));
1493 sc->gatt->ag_physical = vtophys((vm_offset_t)sc->gatt->ag_virtual);
1495 /* Install the GATT. */
1496 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1497 sc->gatt->ag_physical | 1);
1502 agp_i830_install_gatt(device_t dev)
1504 struct agp_i810_softc *sc;
1507 sc = device_get_softc(dev);
1510 * The i830 automatically initializes the 128k gatt on boot.
1511 * GATT address is already in there, make sure it's enabled.
1513 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1515 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1517 sc->gatt->ag_physical = pgtblctl & ~1;
1522 agp_i810_attach(device_t dev)
1524 struct agp_i810_softc *sc;
1527 sc = device_get_softc(dev);
1528 sc->bdev = agp_i810_find_bridge(dev);
1529 if (sc->bdev == NULL)
1532 sc->match = agp_i810_match(dev);
1534 agp_set_aperture_resource(dev, sc->match->driver->gen <= 2 ?
1535 AGP_APBASE : AGP_I915_GMADR);
1536 error = agp_generic_attach(dev);
1540 if (ptoa((vm_paddr_t)Maxmem) >
1541 (1ULL << sc->match->driver->busdma_addr_mask_sz) - 1) {
1542 device_printf(dev, "agp_i810 does not support physical "
1543 "memory above %ju.\n", (uintmax_t)(1ULL <<
1544 sc->match->driver->busdma_addr_mask_sz) - 1);
1548 if (bus_alloc_resources(dev, sc->match->driver->res_spec, sc->sc_res)) {
1549 agp_generic_detach(dev);
1553 sc->initial_aperture = AGP_GET_APERTURE(dev);
1554 sc->gatt = kmalloc(sizeof(struct agp_gatt), M_AGP, M_WAITOK);
1555 sc->gatt->ag_entries = AGP_GET_APERTURE(dev) >> AGP_PAGE_SHIFT;
1557 if ((error = sc->match->driver->get_stolen_size(dev)) != 0 ||
1558 (error = sc->match->driver->install_gatt(dev)) != 0 ||
1559 (error = sc->match->driver->get_gtt_mappable_entries(dev)) != 0 ||
1560 (error = sc->match->driver->get_gtt_total_entries(dev)) != 0 ||
1561 (error = sc->match->driver->chipset_flush_setup(dev)) != 0) {
1562 bus_release_resources(dev, sc->match->driver->res_spec,
1564 kfree(sc->gatt, M_AGP);
1565 agp_generic_detach(dev);
1570 device_printf(dev, "aperture size is %dM",
1571 sc->initial_aperture / 1024 / 1024);
1573 kprintf(", detected %dk stolen memory\n", sc->stolen * 4);
1577 sc->match->driver->dump_regs(dev);
1578 device_printf(dev, "Mappable GTT entries: %d\n",
1579 sc->gtt_mappable_entries);
1580 device_printf(dev, "Total GTT entries: %d\n",
1581 sc->gtt_total_entries);
1587 agp_i810_deinstall_gatt(device_t dev)
1589 struct agp_i810_softc *sc;
1591 sc = device_get_softc(dev);
1592 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, 0);
1593 contigfree(sc->gatt->ag_virtual, 64 * 1024, M_AGP);
1597 agp_i830_deinstall_gatt(device_t dev)
1599 struct agp_i810_softc *sc;
1600 unsigned int pgtblctl;
1602 sc = device_get_softc(dev);
1603 pgtblctl = bus_read_4(sc->sc_res[0], AGP_I810_PGTBL_CTL);
1605 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL, pgtblctl);
1609 agp_i810_detach(device_t dev)
1611 struct agp_i810_softc *sc;
1613 sc = device_get_softc(dev);
1616 /* Clear the GATT base. */
1617 sc->match->driver->deinstall_gatt(dev);
1619 sc->match->driver->chipset_flush_teardown(dev);
1621 /* Put the aperture back the way it started. */
1622 AGP_SET_APERTURE(dev, sc->initial_aperture);
1624 kfree(sc->gatt, M_AGP);
1625 bus_release_resources(dev, sc->match->driver->res_spec, sc->sc_res);
1632 agp_i810_resume(device_t dev)
1634 struct agp_i810_softc *sc;
1635 sc = device_get_softc(dev);
1637 AGP_SET_APERTURE(dev, sc->initial_aperture);
1639 /* Install the GATT. */
1640 bus_write_4(sc->sc_res[0], AGP_I810_PGTBL_CTL,
1641 sc->gatt->ag_physical | 1);
1643 return (bus_generic_resume(dev));
1647 * Sets the PCI resource size of the aperture on i830-class and below chipsets,
1648 * while returning failure on later chipsets when an actual change is
1651 * This whole function is likely bogus, as the kernel would probably need to
1652 * reconfigure the placement of the AGP aperture if a larger size is requested,
1653 * which doesn't happen currently.
1656 agp_i810_set_aperture(device_t dev, u_int32_t aperture)
1658 struct agp_i810_softc *sc;
1661 sc = device_get_softc(dev);
1663 * Double check for sanity.
1665 if (aperture != 32 * 1024 * 1024 && aperture != 64 * 1024 * 1024) {
1666 device_printf(dev, "bad aperture size %d\n", aperture);
1670 miscc = pci_read_config(sc->bdev, AGP_I810_MISCC, 2);
1671 miscc &= ~AGP_I810_MISCC_WINSIZE;
1672 if (aperture == 32 * 1024 * 1024)
1673 miscc |= AGP_I810_MISCC_WINSIZE_32;
1675 miscc |= AGP_I810_MISCC_WINSIZE_64;
1677 pci_write_config(sc->bdev, AGP_I810_MISCC, miscc, 2);
1682 agp_i830_set_aperture(device_t dev, u_int32_t aperture)
1684 struct agp_i810_softc *sc;
1687 sc = device_get_softc(dev);
1689 if (aperture != 64 * 1024 * 1024 &&
1690 aperture != 128 * 1024 * 1024) {
1691 device_printf(dev, "bad aperture size %d\n", aperture);
1694 gcc1 = pci_read_config(sc->bdev, AGP_I830_GCC1, 2);
1695 gcc1 &= ~AGP_I830_GCC1_GMASIZE;
1696 if (aperture == 64 * 1024 * 1024)
1697 gcc1 |= AGP_I830_GCC1_GMASIZE_64;
1699 gcc1 |= AGP_I830_GCC1_GMASIZE_128;
1701 pci_write_config(sc->bdev, AGP_I830_GCC1, gcc1, 2);
1706 agp_i915_set_aperture(device_t dev, u_int32_t aperture)
1709 return (agp_generic_set_aperture(dev, aperture));
1713 agp_i810_method_set_aperture(device_t dev, u_int32_t aperture)
1715 struct agp_i810_softc *sc;
1717 sc = device_get_softc(dev);
1718 return (sc->match->driver->set_aperture(dev, aperture));
1722 * Writes a GTT entry mapping the page at the given offset from the
1723 * beginning of the aperture to the given physical address. Setup the
1724 * caching mode according to flags.
1726 * For gen 1, 2 and 3, GTT start is located at AGP_I810_GTT offset
1727 * from corresponding BAR start. For gen 4, offset is 512KB +
1728 * AGP_I810_GTT, for gen 5 and 6 it is 2MB + AGP_I810_GTT.
1730 * Also, the bits of the physical page address above 4GB needs to be
1731 * placed into bits 40-32 of PTE.
1734 agp_i810_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1739 pte = (u_int32_t)physical | I810_PTE_VALID;
1740 if (flags == AGP_DCACHE_MEMORY)
1741 pte |= I810_PTE_LOCAL;
1742 else if (flags == AGP_USER_CACHED_MEMORY)
1743 pte |= I830_PTE_SYSTEM_CACHED;
1744 agp_i810_write_gtt(dev, index, pte);
1748 agp_i810_write_gtt(device_t dev, u_int index, uint32_t pte)
1750 struct agp_i810_softc *sc;
1752 sc = device_get_softc(dev);
1753 bus_write_4(sc->sc_res[0], AGP_I810_GTT + index * 4, pte);
1757 agp_i830_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1762 pte = (u_int32_t)physical | I810_PTE_VALID;
1763 if (flags == AGP_USER_CACHED_MEMORY)
1764 pte |= I830_PTE_SYSTEM_CACHED;
1765 agp_i810_write_gtt(dev, index, pte);
1769 agp_i915_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1774 pte = (u_int32_t)physical | I810_PTE_VALID;
1775 if (flags == AGP_USER_CACHED_MEMORY)
1776 pte |= I830_PTE_SYSTEM_CACHED;
1777 pte |= (physical & 0x0000000f00000000ull) >> 28;
1778 agp_i915_write_gtt(dev, index, pte);
1782 agp_i915_write_gtt(device_t dev, u_int index, uint32_t pte)
1784 struct agp_i810_softc *sc;
1786 sc = device_get_softc(dev);
1787 bus_write_4(sc->sc_res[1], index * 4, pte);
1791 agp_i965_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1796 pte = (u_int32_t)physical | I810_PTE_VALID;
1797 if (flags == AGP_USER_CACHED_MEMORY)
1798 pte |= I830_PTE_SYSTEM_CACHED;
1799 pte |= (physical & 0x0000000f00000000ull) >> 28;
1800 agp_i965_write_gtt(dev, index, pte);
1804 agp_i965_write_gtt(device_t dev, u_int index, uint32_t pte)
1806 struct agp_i810_softc *sc;
1808 sc = device_get_softc(dev);
1809 bus_write_4(sc->sc_res[0], index * 4 + (512 * 1024), pte);
1813 agp_g4x_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1818 pte = (u_int32_t)physical | I810_PTE_VALID;
1819 if (flags == AGP_USER_CACHED_MEMORY)
1820 pte |= I830_PTE_SYSTEM_CACHED;
1821 pte |= (physical & 0x0000000f00000000ull) >> 28;
1822 agp_g4x_write_gtt(dev, index, pte);
1826 agp_g4x_write_gtt(device_t dev, u_int index, uint32_t pte)
1828 struct agp_i810_softc *sc;
1830 sc = device_get_softc(dev);
1831 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1835 agp_sb_install_gtt_pte(device_t dev, u_int index, vm_offset_t physical,
1838 int type_mask, gfdt;
1841 pte = (u_int32_t)physical | I810_PTE_VALID;
1842 type_mask = flags & ~AGP_USER_CACHED_MEMORY_GFDT;
1843 gfdt = (flags & AGP_USER_CACHED_MEMORY_GFDT) != 0 ? GEN6_PTE_GFDT : 0;
1845 if (type_mask == AGP_USER_MEMORY)
1846 pte |= GEN6_PTE_UNCACHED;
1847 else if (type_mask == AGP_USER_CACHED_MEMORY_LLC_MLC)
1848 pte |= GEN6_PTE_LLC_MLC | gfdt;
1850 pte |= GEN6_PTE_LLC | gfdt;
1852 pte |= (physical & 0x000000ff00000000ull) >> 28;
1853 agp_sb_write_gtt(dev, index, pte);
1857 agp_sb_write_gtt(device_t dev, u_int index, uint32_t pte)
1859 struct agp_i810_softc *sc;
1861 sc = device_get_softc(dev);
1862 bus_write_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024), pte);
1866 agp_i810_bind_page(device_t dev, vm_offset_t offset, vm_offset_t physical)
1868 struct agp_i810_softc *sc = device_get_softc(dev);
1871 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT)) {
1872 device_printf(dev, "failed: offset is 0x%08jx, "
1873 "shift is %d, entries is %d\n", (intmax_t)offset,
1874 AGP_PAGE_SHIFT, sc->gatt->ag_entries);
1877 index = offset >> AGP_PAGE_SHIFT;
1878 if (sc->stolen != 0 && index < sc->stolen) {
1879 device_printf(dev, "trying to bind into stolen memory\n");
1882 sc->match->driver->install_gtt_pte(dev, index, physical, 0);
1887 agp_i810_unbind_page(device_t dev, vm_offset_t offset)
1889 struct agp_i810_softc *sc;
1892 sc = device_get_softc(dev);
1893 if (offset >= (sc->gatt->ag_entries << AGP_PAGE_SHIFT))
1895 index = offset >> AGP_PAGE_SHIFT;
1896 if (sc->stolen != 0 && index < sc->stolen) {
1897 device_printf(dev, "trying to unbind from stolen memory\n");
1900 sc->match->driver->install_gtt_pte(dev, index, 0, 0);
1905 agp_i810_read_gtt_pte(device_t dev, u_int index)
1907 struct agp_i810_softc *sc;
1910 sc = device_get_softc(dev);
1911 pte = bus_read_4(sc->sc_res[0], AGP_I810_GTT + index * 4);
1916 agp_i915_read_gtt_pte(device_t dev, u_int index)
1918 struct agp_i810_softc *sc;
1921 sc = device_get_softc(dev);
1922 pte = bus_read_4(sc->sc_res[1], index * 4);
1927 agp_i965_read_gtt_pte(device_t dev, u_int index)
1929 struct agp_i810_softc *sc;
1932 sc = device_get_softc(dev);
1933 pte = bus_read_4(sc->sc_res[0], index * 4 + (512 * 1024));
1938 agp_g4x_read_gtt_pte(device_t dev, u_int index)
1940 struct agp_i810_softc *sc;
1943 sc = device_get_softc(dev);
1944 pte = bus_read_4(sc->sc_res[0], index * 4 + (2 * 1024 * 1024));
1949 agp_i810_read_gtt_pte_paddr(device_t dev, u_int index)
1951 struct agp_i810_softc *sc;
1955 sc = device_get_softc(dev);
1956 pte = sc->match->driver->read_gtt_pte(dev, index);
1957 res = pte & ~PAGE_MASK;
1962 agp_i915_read_gtt_pte_paddr(device_t dev, u_int index)
1964 struct agp_i810_softc *sc;
1968 sc = device_get_softc(dev);
1969 pte = sc->match->driver->read_gtt_pte(dev, index);
1970 res = (pte & ~PAGE_MASK) | ((pte & 0xf0) << 28);
1975 agp_sb_read_gtt_pte_paddr(device_t dev, u_int index)
1977 struct agp_i810_softc *sc;
1981 sc = device_get_softc(dev);
1982 pte = sc->match->driver->read_gtt_pte(dev, index);
1983 res = (pte & ~PAGE_MASK) | ((pte & 0xff0) << 28);
1988 * Writing via memory mapped registers already flushes all TLBs.
1991 agp_i810_flush_tlb(device_t dev)
1996 agp_i810_enable(device_t dev, u_int32_t mode)
2002 static struct agp_memory *
2003 agp_i810_alloc_memory(device_t dev, int type, vm_size_t size)
2005 struct agp_i810_softc *sc;
2006 struct agp_memory *mem;
2009 sc = device_get_softc(dev);
2011 if ((size & (AGP_PAGE_SIZE - 1)) != 0 ||
2012 sc->agp.as_allocated + size > sc->agp.as_maxmem)
2017 * Mapping local DRAM into GATT.
2019 if (sc->match->driver->chiptype != CHIP_I810)
2021 if (size != sc->dcache_size)
2023 } else if (type == 2) {
2025 * Type 2 is the contiguous physical memory type, that hands
2026 * back a physical address. This is used for cursors on i810.
2027 * Hand back as many single pages with physical as the user
2028 * wants, but only allow one larger allocation (ARGB cursor)
2031 if (size != AGP_PAGE_SIZE) {
2032 if (sc->argb_cursor != NULL)
2035 /* Allocate memory for ARGB cursor, if we can. */
2036 sc->argb_cursor = contigmalloc(size, M_AGP,
2037 0, 0, ~0, PAGE_SIZE, 0);
2038 if (sc->argb_cursor == NULL)
2043 mem = kmalloc(sizeof *mem, M_AGP, M_INTWAIT);
2044 mem->am_id = sc->agp.as_nextid++;
2045 mem->am_size = size;
2046 mem->am_type = type;
2047 if (type != 1 && (type != 2 || size == AGP_PAGE_SIZE))
2048 mem->am_obj = vm_object_allocate(OBJT_DEFAULT,
2049 atop(round_page(size)));
2054 if (size == AGP_PAGE_SIZE) {
2056 * Allocate and wire down the page now so that we can
2057 * get its physical address.
2059 VM_OBJECT_LOCK(mem->am_obj);
2060 m = vm_page_grab(mem->am_obj, 0, VM_ALLOC_NORMAL |
2064 VM_OBJECT_UNLOCK(mem->am_obj);
2065 mem->am_physical = VM_PAGE_TO_PHYS(m);
2068 /* Our allocation is already nicely wired down for us.
2069 * Just grab the physical address.
2071 mem->am_physical = vtophys(sc->argb_cursor);
2074 mem->am_physical = 0;
2077 mem->am_is_bound = 0;
2078 TAILQ_INSERT_TAIL(&sc->agp.as_memory, mem, am_link);
2079 sc->agp.as_allocated += size;
2085 agp_i810_free_memory(device_t dev, struct agp_memory *mem)
2087 struct agp_i810_softc *sc;
2089 if (mem->am_is_bound)
2092 sc = device_get_softc(dev);
2094 if (mem->am_type == 2) {
2095 if (mem->am_size == AGP_PAGE_SIZE) {
2097 * Unwire the page which we wired in alloc_memory.
2101 vm_object_hold(mem->am_obj);
2102 m = vm_page_lookup_busy_wait(mem->am_obj, 0,
2104 vm_object_drop(mem->am_obj);
2105 vm_page_unwire(m, 0);
2108 contigfree(sc->argb_cursor, mem->am_size, M_AGP);
2109 sc->argb_cursor = NULL;
2113 sc->agp.as_allocated -= mem->am_size;
2114 TAILQ_REMOVE(&sc->agp.as_memory, mem, am_link);
2116 vm_object_deallocate(mem->am_obj);
2122 agp_i810_bind_memory(device_t dev, struct agp_memory *mem, vm_offset_t offset)
2124 struct agp_i810_softc *sc;
2127 /* Do some sanity checks first. */
2128 if ((offset & (AGP_PAGE_SIZE - 1)) != 0 ||
2129 offset + mem->am_size > AGP_GET_APERTURE(dev)) {
2130 device_printf(dev, "binding memory at bad offset %#x\n",
2135 sc = device_get_softc(dev);
2136 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
2137 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
2138 if (mem->am_is_bound) {
2139 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2142 /* The memory's already wired down, just stick it in the GTT. */
2143 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2144 sc->match->driver->install_gtt_pte(dev, (offset + i) >>
2145 AGP_PAGE_SHIFT, mem->am_physical + i, 0);
2148 mem->am_offset = offset;
2149 mem->am_is_bound = 1;
2150 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2154 if (mem->am_type != 1)
2155 return (agp_generic_bind_memory(dev, mem, offset));
2158 * Mapping local DRAM into GATT.
2160 if (sc->match->driver->chiptype != CHIP_I810)
2162 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE)
2163 bus_write_4(sc->sc_res[0],
2164 AGP_I810_GTT + (i >> AGP_PAGE_SHIFT) * 4, i | 3);
2170 agp_i810_unbind_memory(device_t dev, struct agp_memory *mem)
2172 struct agp_i810_softc *sc;
2175 sc = device_get_softc(dev);
2177 if (mem->am_type == 2 && mem->am_size != AGP_PAGE_SIZE) {
2178 lockmgr(&sc->agp.as_lock, LK_EXCLUSIVE);
2179 if (!mem->am_is_bound) {
2180 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2184 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2185 sc->match->driver->install_gtt_pte(dev,
2186 (mem->am_offset + i) >> AGP_PAGE_SHIFT, 0, 0);
2189 mem->am_is_bound = 0;
2190 lockmgr(&sc->agp.as_lock, LK_RELEASE);
2194 if (mem->am_type != 1)
2195 return (agp_generic_unbind_memory(dev, mem));
2197 if (sc->match->driver->chiptype != CHIP_I810)
2199 for (i = 0; i < mem->am_size; i += AGP_PAGE_SIZE) {
2200 sc->match->driver->install_gtt_pte(dev, i >> AGP_PAGE_SHIFT,
2206 static device_method_t agp_i810_methods[] = {
2207 /* Device interface */
2208 DEVMETHOD(device_identify, agp_i810_identify),
2209 DEVMETHOD(device_probe, agp_i810_probe),
2210 DEVMETHOD(device_attach, agp_i810_attach),
2211 DEVMETHOD(device_detach, agp_i810_detach),
2212 DEVMETHOD(device_suspend, bus_generic_suspend),
2213 DEVMETHOD(device_resume, agp_i810_resume),
2216 DEVMETHOD(agp_get_aperture, agp_generic_get_aperture),
2217 DEVMETHOD(agp_set_aperture, agp_i810_method_set_aperture),
2218 DEVMETHOD(agp_bind_page, agp_i810_bind_page),
2219 DEVMETHOD(agp_unbind_page, agp_i810_unbind_page),
2220 DEVMETHOD(agp_flush_tlb, agp_i810_flush_tlb),
2221 DEVMETHOD(agp_enable, agp_i810_enable),
2222 DEVMETHOD(agp_alloc_memory, agp_i810_alloc_memory),
2223 DEVMETHOD(agp_free_memory, agp_i810_free_memory),
2224 DEVMETHOD(agp_bind_memory, agp_i810_bind_memory),
2225 DEVMETHOD(agp_unbind_memory, agp_i810_unbind_memory),
2226 DEVMETHOD(agp_chipset_flush, agp_intel_gtt_chipset_flush),
2231 static driver_t agp_i810_driver = {
2234 sizeof(struct agp_i810_softc),
2237 static devclass_t agp_devclass;
2239 DRIVER_MODULE(agp_i810, vgapci, agp_i810_driver, agp_devclass, NULL, NULL);
2240 MODULE_DEPEND(agp_i810, agp, 1, 1, 1);
2241 MODULE_DEPEND(agp_i810, pci, 1, 1, 1);
2243 extern vm_page_t bogus_page;
2246 agp_intel_gtt_clear_range(device_t dev, u_int first_entry, u_int num_entries)
2248 struct agp_i810_softc *sc;
2251 sc = device_get_softc(dev);
2252 for (i = 0; i < num_entries; i++)
2253 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2254 VM_PAGE_TO_PHYS(bogus_page), 0);
2255 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
2259 agp_intel_gtt_insert_pages(device_t dev, u_int first_entry, u_int num_entries,
2260 vm_page_t *pages, u_int flags)
2262 struct agp_i810_softc *sc;
2265 sc = device_get_softc(dev);
2266 for (i = 0; i < num_entries; i++) {
2267 KKASSERT(pages[i]->valid == VM_PAGE_BITS_ALL);
2268 KKASSERT(pages[i]->wire_count > 0);
2269 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2270 VM_PAGE_TO_PHYS(pages[i]), flags);
2272 sc->match->driver->read_gtt_pte(dev, first_entry + num_entries - 1);
2276 agp_intel_gtt_get(device_t dev)
2278 struct agp_i810_softc *sc;
2279 struct intel_gtt res;
2281 sc = device_get_softc(dev);
2282 res.stolen_size = sc->stolen_size;
2283 res.gtt_total_entries = sc->gtt_total_entries;
2284 res.gtt_mappable_entries = sc->gtt_mappable_entries;
2285 res.do_idle_maps = 0;
2286 res.scratch_page_dma = VM_PAGE_TO_PHYS(bogus_page);
2291 agp_i810_chipset_flush_setup(device_t dev)
2298 agp_i810_chipset_flush_teardown(device_t dev)
2301 /* Nothing to do. */
2305 agp_i810_chipset_flush(device_t dev)
2308 /* Nothing to do. */
2312 agp_i830_chipset_flush(device_t dev)
2314 struct agp_i810_softc *sc;
2318 sc = device_get_softc(dev);
2319 cpu_wbinvd_on_all_cpus();
2320 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2321 bus_write_4(sc->sc_res[0], AGP_I830_HIC, hic | (1 << 31));
2322 for (i = 0; i < 20000 /* 1 sec */; i++) {
2323 hic = bus_read_4(sc->sc_res[0], AGP_I830_HIC);
2324 if ((hic & (1 << 31)) != 0)
2331 agp_i915_chipset_flush_alloc_page(device_t dev, uint64_t start, uint64_t end)
2333 struct agp_i810_softc *sc;
2336 sc = device_get_softc(dev);
2337 vga = device_get_parent(dev);
2338 sc->sc_flush_page_rid = 100;
2339 sc->sc_flush_page_res = BUS_ALLOC_RESOURCE(device_get_parent(vga), dev,
2340 SYS_RES_MEMORY, &sc->sc_flush_page_rid, start, end, PAGE_SIZE,
2342 if (sc->sc_flush_page_res == NULL) {
2343 device_printf(dev, "Failed to allocate flush page at 0x%jx\n",
2347 sc->sc_flush_page_vaddr = rman_get_virtual(sc->sc_flush_page_res);
2349 device_printf(dev, "Allocated flush page phys 0x%jx virt %p\n",
2350 (uintmax_t)rman_get_start(sc->sc_flush_page_res),
2351 sc->sc_flush_page_vaddr);
2357 agp_i915_chipset_flush_free_page(device_t dev)
2359 struct agp_i810_softc *sc;
2362 sc = device_get_softc(dev);
2363 vga = device_get_parent(dev);
2364 if (sc->sc_flush_page_res == NULL)
2366 BUS_DEACTIVATE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2367 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2368 BUS_RELEASE_RESOURCE(device_get_parent(vga), dev, SYS_RES_MEMORY,
2369 sc->sc_flush_page_rid, sc->sc_flush_page_res);
2373 agp_i915_chipset_flush_setup(device_t dev)
2375 struct agp_i810_softc *sc;
2379 sc = device_get_softc(dev);
2380 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2381 if ((temp & 1) != 0) {
2385 "Found already configured flush page at 0x%jx\n",
2387 sc->sc_bios_allocated_flush_page = 1;
2389 * In the case BIOS initialized the flush pointer (?)
2390 * register, expect that BIOS also set up the resource
2393 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2394 temp + PAGE_SIZE - 1);
2398 sc->sc_bios_allocated_flush_page = 0;
2399 error = agp_i915_chipset_flush_alloc_page(dev, 0, 0xffffffff);
2402 temp = rman_get_start(sc->sc_flush_page_res);
2403 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp | 1, 4);
2409 agp_i915_chipset_flush_teardown(device_t dev)
2411 struct agp_i810_softc *sc;
2414 sc = device_get_softc(dev);
2415 if (sc->sc_flush_page_res == NULL)
2417 if (!sc->sc_bios_allocated_flush_page) {
2418 temp = pci_read_config(sc->bdev, AGP_I915_IFPADDR, 4);
2420 pci_write_config(sc->bdev, AGP_I915_IFPADDR, temp, 4);
2422 agp_i915_chipset_flush_free_page(dev);
2426 agp_i965_chipset_flush_setup(device_t dev)
2428 struct agp_i810_softc *sc;
2430 uint32_t temp_hi, temp_lo;
2433 sc = device_get_softc(dev);
2435 temp_hi = pci_read_config(sc->bdev, AGP_I965_IFPADDR + 4, 4);
2436 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2438 if ((temp_lo & 1) != 0) {
2439 temp = ((uint64_t)temp_hi << 32) | (temp_lo & ~1);
2442 "Found already configured flush page at 0x%jx\n",
2444 sc->sc_bios_allocated_flush_page = 1;
2446 * In the case BIOS initialized the flush pointer (?)
2447 * register, expect that BIOS also set up the resource
2450 error = agp_i915_chipset_flush_alloc_page(dev, temp,
2451 temp + PAGE_SIZE - 1);
2455 sc->sc_bios_allocated_flush_page = 0;
2456 error = agp_i915_chipset_flush_alloc_page(dev, 0, ~0);
2459 temp = rman_get_start(sc->sc_flush_page_res);
2460 pci_write_config(sc->bdev, AGP_I965_IFPADDR + 4,
2461 (temp >> 32) & UINT32_MAX, 4);
2462 pci_write_config(sc->bdev, AGP_I965_IFPADDR,
2463 (temp & UINT32_MAX) | 1, 4);
2469 agp_i965_chipset_flush_teardown(device_t dev)
2471 struct agp_i810_softc *sc;
2474 sc = device_get_softc(dev);
2475 if (sc->sc_flush_page_res == NULL)
2477 if (!sc->sc_bios_allocated_flush_page) {
2478 temp_lo = pci_read_config(sc->bdev, AGP_I965_IFPADDR, 4);
2480 pci_write_config(sc->bdev, AGP_I965_IFPADDR, temp_lo, 4);
2482 agp_i915_chipset_flush_free_page(dev);
2486 agp_i915_chipset_flush(device_t dev)
2488 struct agp_i810_softc *sc;
2490 sc = device_get_softc(dev);
2491 *(uint32_t *)sc->sc_flush_page_vaddr = 1;
2495 agp_intel_gtt_chipset_flush(device_t dev)
2497 struct agp_i810_softc *sc;
2499 sc = device_get_softc(dev);
2500 sc->match->driver->chipset_flush(dev);
2505 agp_intel_gtt_unmap_memory(device_t dev, struct sglist *sg_list)
2510 agp_intel_gtt_map_memory(device_t dev, vm_page_t *pages, u_int num_entries,
2511 struct sglist **sg_list)
2514 struct agp_i810_softc *sc;
2523 if (*sg_list != NULL)
2526 sc = device_get_softc(dev);
2528 sg = sglist_alloc(num_entries, M_WAITOK /* XXXKIB */);
2529 for (i = 0; i < num_entries; i++) {
2530 sg->sg_segs[i].ss_paddr = VM_PAGE_TO_PHYS(pages[i]);
2531 sg->sg_segs[i].ss_len = PAGE_SIZE;
2535 error = bus_dma_tag_create(bus_get_dma_tag(dev),
2536 1 /* alignment */, 0 /* boundary */,
2537 1ULL << sc->match->busdma_addr_mask_sz /* lowaddr */,
2538 BUS_SPACE_MAXADDR /* highaddr */,
2539 NULL /* filtfunc */, NULL /* filtfuncarg */,
2540 BUS_SPACE_MAXADDR /* maxsize */,
2541 BUS_SPACE_UNRESTRICTED /* nsegments */,
2542 BUS_SPACE_MAXADDR /* maxsegsz */,
2543 0 /* flags */, NULL /* lockfunc */, NULL /* lockfuncarg */,
2556 agp_intel_gtt_insert_sg_entries(device_t dev, struct sglist *sg_list,
2557 u_int first_entry, u_int flags)
2559 struct agp_i810_softc *sc;
2564 sc = device_get_softc(dev);
2565 for (i = j = 0; j < sg_list->sg_nseg; j++) {
2566 spaddr = sg_list->sg_segs[i].ss_paddr;
2567 slen = sg_list->sg_segs[i].ss_len;
2568 for (; slen > 0; i++) {
2569 sc->match->driver->install_gtt_pte(dev, first_entry + i,
2571 spaddr += AGP_PAGE_SIZE;
2572 slen -= AGP_PAGE_SIZE;
2575 sc->match->driver->read_gtt_pte(dev, first_entry + i - 1);
2579 intel_gtt_clear_range(u_int first_entry, u_int num_entries)
2582 agp_intel_gtt_clear_range(intel_agp, first_entry, num_entries);
2586 intel_gtt_insert_pages(u_int first_entry, u_int num_entries, vm_page_t *pages,
2590 agp_intel_gtt_insert_pages(intel_agp, first_entry, num_entries,
2594 const struct intel_gtt *intel_gtt_get(void)
2596 intel_private.base = agp_intel_gtt_get(intel_agp);
2597 return &intel_private.base;
2601 intel_gtt_chipset_flush(void)
2604 return (agp_intel_gtt_chipset_flush(intel_agp));
2608 intel_gtt_unmap_memory(struct sglist *sg_list)
2611 agp_intel_gtt_unmap_memory(intel_agp, sg_list);
2615 intel_gtt_map_memory(vm_page_t *pages, u_int num_entries,
2616 struct sglist **sg_list)
2619 return (agp_intel_gtt_map_memory(intel_agp, pages, num_entries,
2624 intel_gtt_insert_sg_entries(struct sglist *sg_list, u_int first_entry,
2628 agp_intel_gtt_insert_sg_entries(intel_agp, sg_list, first_entry, flags);
2632 intel_gtt_read_pte_paddr(u_int entry)
2634 struct agp_i810_softc *sc;
2636 sc = device_get_softc(intel_agp);
2637 return (sc->match->driver->read_gtt_pte_paddr(intel_agp, entry));
2641 intel_gtt_read_pte(u_int entry)
2643 struct agp_i810_softc *sc;
2645 sc = device_get_softc(intel_agp);
2646 return (sc->match->driver->read_gtt_pte(intel_agp, entry));
2650 intel_gtt_write(u_int entry, uint32_t val)
2652 struct agp_i810_softc *sc;
2654 sc = device_get_softc(intel_agp);
2655 sc->match->driver->write_gtt(intel_agp, entry, val);