4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G
5 * integrated graphics chips.
7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
10 * This driver consists of two parts. The first part (intelfbdrv.c) provides
11 * the basic fbdev interfaces, is derived in part from the radeonfb and
12 * vesafb drivers, and is covered by the GPL. The second part (intelfbhw.c)
13 * provides the code to program the hardware. Most of it is derived from
14 * the i810/i830 XFree86 driver. The HW-specific code is covered here
15 * under a dual license (GPL and MIT/XFree86 license).
21 /* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */
25 * 01/2003 - Initial driver (0.1.0), no mode switching, no acceleration.
26 * This initial version is a basic core that works a lot like
27 * the vesafb driver. It must be built-in to the kernel,
28 * and the initial video mode must be set with vga=XXX at
29 * boot time. (David Dawes)
31 * 01/2003 - Version 0.2.0: Mode switching added, colormap support
32 * implemented, Y panning, and soft screen blanking implemented.
33 * No acceleration yet. (David Dawes)
35 * 01/2003 - Version 0.3.0: fbcon acceleration support added. Module
36 * option handling added. (David Dawes)
38 * 01/2003 - Version 0.4.0: fbcon HW cursor support added. (David Dawes)
40 * 01/2003 - Version 0.4.1: Add auto-generation of built-in modes.
43 * 02/2003 - Version 0.4.2: Add check for active non-CRT devices, and
44 * mode validation checks. (David Dawes)
46 * 02/2003 - Version 0.4.3: Check when the VC is in graphics mode so that
47 * acceleration is disabled while an XFree86 server is running.
50 * 02/2003 - Version 0.4.4: Monitor DPMS support. (David Dawes)
52 * 02/2003 - Version 0.4.5: Basic XFree86 + fbdev working. (David Dawes)
54 * 02/2003 - Version 0.5.0: Modify to work with the 2.5.32 kernel as well
55 * as 2.4.x kernels. (David Dawes)
57 * 02/2003 - Version 0.6.0: Split out HW-specifics into a separate file.
60 * 02/2003 - Version 0.7.0: Test on 852GM/855GM. Acceleration and HW
61 * cursor are disabled on this platform. (David Dawes)
63 * 02/2003 - Version 0.7.1: Test on 845G. Acceleration is disabled
64 * on this platform. (David Dawes)
66 * 02/2003 - Version 0.7.2: Test on 830M. Acceleration and HW
67 * cursor are disabled on this platform. (David Dawes)
69 * 02/2003 - Version 0.7.3: Fix 8-bit modes for mobile platforms
72 * 02/2003 - Version 0.7.4: Add checks for FB and FBCON_HAS_CFB* configured
73 * in the kernel, and add mode bpp verification and default
74 * bpp selection based on which FBCON_HAS_CFB* are configured.
77 * 02/2003 - Version 0.7.5: Add basic package/install scripts based on the
78 * DRI packaging scripts. (David Dawes)
80 * 04/2003 - Version 0.7.6: Fix typo that affects builds with SMP-enabled
81 * kernels. (David Dawes, reported by Anupam).
83 * 06/2003 - Version 0.7.7:
84 * Fix Makefile.kernel build problem (Tsutomu Yasuda).
85 * Fix mis-placed #endif (2.4.21 kernel).
87 * 09/2004 - Version 0.9.0 - by Sylvain Meyer
88 * Port to linux 2.6 kernel fbdev
89 * Fix HW accel and HW cursor on i845G
90 * Use of agpgart for fb memory reservation
93 * 10/2004 - Version 0.9.1
94 * Use module_param instead of old MODULE_PARM
97 * 11/2004 - Version 0.9.2
98 * Add vram option to reserve more memory than stolen by BIOS
99 * Fix intelfbhw_pan_display typo
100 * Add __initdata annotations
110 #include <linux/config.h>
111 #include <linux/module.h>
112 #include <linux/kernel.h>
113 #include <linux/errno.h>
114 #include <linux/string.h>
115 #include <linux/mm.h>
116 #include <linux/tty.h>
117 #include <linux/slab.h>
118 #include <linux/delay.h>
119 #include <linux/fb.h>
120 #include <linux/console.h>
121 #include <linux/selection.h>
122 #include <linux/ioport.h>
123 #include <linux/init.h>
124 #include <linux/pci.h>
125 #include <linux/vmalloc.h>
126 #include <linux/kd.h>
127 #include <linux/vt_kern.h>
128 #include <linux/pagemap.h>
129 #include <linux/version.h>
134 #include <asm/mtrr.h>
138 #include "intelfbdrv.h"
139 #include "intelfbhw.h"
142 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
143 * mobile chipsets from being registered.
145 #if DETECT_VGA_CLASS_ONLY
146 #define INTELFB_CLASS_MASK ~0 << 8
148 #define INTELFB_CLASS_MASK 0
151 static struct pci_device_id intelfb_pci_table[] __devinitdata = {
152 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_830M, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_830M },
153 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_845G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_845G },
154 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM },
155 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G },
160 static int num_registered = 0;
163 static struct fb_ops intel_fb_ops = {
164 .owner = THIS_MODULE,
165 .fb_check_var = intelfb_check_var,
166 .fb_set_par = intelfb_set_par,
167 .fb_setcolreg = intelfb_setcolreg,
168 .fb_blank = intelfb_blank,
169 .fb_pan_display = intelfb_pan_display,
170 .fb_fillrect = intelfb_fillrect,
171 .fb_copyarea = intelfb_copyarea,
172 .fb_imageblit = intelfb_imageblit,
173 .fb_cursor = intelfb_cursor,
174 .fb_sync = intelfb_sync,
175 .fb_ioctl = intelfb_ioctl
178 /* PCI driver module table */
179 static struct pci_driver intelfb_driver = {
180 .name = "Intel(R) " SUPPORTED_CHIPSETS " Framebuffer Driver",
181 .id_table = intelfb_pci_table,
182 .probe = intelfb_pci_register,
183 .remove = __devexit_p(intelfb_pci_unregister)
186 /* Module description/parameters */
187 MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
188 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
190 "Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS " chipsets");
191 MODULE_LICENSE("Dual BSD/GPL");
192 MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
194 static int accel __initdata = 1;
195 static int vram __initdata = 4;
196 static int hwcursor __initdata = 1;
197 static int mtrr __initdata = 1;
198 static int fixed __initdata = 0;
199 static int noinit __initdata = 0;
200 static int noregister __initdata = 0;
201 static int probeonly __initdata = 0;
202 static int idonly __initdata = 0;
203 static int bailearly __initdata = 0;
204 static char *mode __initdata = NULL;
206 module_param(accel, bool, S_IRUGO);
207 MODULE_PARM_DESC(accel, "Enable console acceleration");
208 module_param(vram, int, S_IRUGO);
209 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
210 module_param(hwcursor, bool, S_IRUGO);
211 MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
212 module_param(mtrr, bool, S_IRUGO);
213 MODULE_PARM_DESC(mtrr, "Enable MTRR support");
214 module_param(fixed, bool, S_IRUGO);
215 MODULE_PARM_DESC(fixed, "Disable mode switching");
216 module_param(noinit, bool, 0);
217 MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
218 module_param(noregister, bool, 0);
219 MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
220 module_param(probeonly, bool, 0);
221 MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
222 module_param(idonly, bool, 0);
223 MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
224 module_param(bailearly, bool, 0);
225 MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
226 module_param(mode, charp, S_IRUGO);
227 MODULE_PARM_DESC(mode,
228 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
229 /***************************************************************
230 * modules entry points *
231 ***************************************************************/
233 /* module load/unload entry points */
241 DBG_MSG("intelfb_init\n");
243 INF_MSG("Framebuffer driver for "
244 "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
245 INF_MSG("Version " INTELFB_VERSION "\n");
251 if (fb_get_options("intelfb", &option))
253 intelfb_setup(option);
256 return pci_module_init(&intelfb_driver);
262 DBG_MSG("intelfb_exit\n");
263 pci_unregister_driver(&intelfb_driver);
267 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
268 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name), NULL, 0)
269 #define OPT_STRVAL(opt, name) (opt + strlen(name))
271 static __inline__ char *
272 get_opt_string(const char *this_opt, const char *name)
278 p = OPT_STRVAL(this_opt, name);
280 while (p[i] && p[i] != ' ' && p[i] != ',')
282 ret = kmalloc(i + 1, GFP_KERNEL);
290 static __inline__ int
291 get_opt_int(const char *this_opt, const char *name, int *ret)
296 if (!OPT_EQUAL(this_opt, name))
299 *ret = OPT_INTVAL(this_opt, name);
303 static __inline__ int
304 get_opt_bool(const char *this_opt, const char *name, int *ret)
309 if (OPT_EQUAL(this_opt, name)) {
310 if (this_opt[strlen(name)] == '=')
311 *ret = simple_strtoul(this_opt + strlen(name) + 1,
316 if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name))
325 intelfb_setup(char *options)
329 DBG_MSG("intelfb_setup\n");
331 if (!options || !*options) {
332 DBG_MSG("no options\n");
335 DBG_MSG("options: %s\n", options);
338 * These are the built-in options analogous to the module parameters
343 * video=intelfb:[mode][,<param>=<val>] ...
347 * video=intelfb:1024x768-16@75,accel=0
350 while ((this_opt = strsep(&options, ","))) {
353 if (get_opt_bool(this_opt, "accel", &accel))
355 else if (get_opt_int(this_opt, "vram", &vram))
357 else if (get_opt_bool(this_opt, "hwcursor", &hwcursor))
359 else if (get_opt_bool(this_opt, "mtrr", &mtrr))
361 else if (get_opt_bool(this_opt, "fixed", &fixed))
363 else if (get_opt_bool(this_opt, "init", &noinit))
365 else if (OPT_EQUAL(this_opt, "mode="))
366 mode = get_opt_string(this_opt, "mode=");
376 module_init(intelfb_init);
379 module_exit(intelfb_exit);
382 /***************************************************************
383 * mtrr support functions *
384 ***************************************************************/
387 static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
389 dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical,
390 dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1);
391 if (dinfo->mtrr_reg < 0) {
392 ERR_MSG("unable to set MTRR\n");
397 static inline void unset_mtrr(struct intelfb_info *dinfo)
400 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
401 dinfo->aperture.size);
404 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
406 #define unset_mtrr(x) do { } while (0)
407 #endif /* CONFIG_MTRR */
409 /***************************************************************
410 * driver init / cleanup *
411 ***************************************************************/
414 cleanup(struct intelfb_info *dinfo)
416 DBG_MSG("cleanup\n");
421 fb_dealloc_cmap(&dinfo->info->cmap);
422 kfree(dinfo->info->pixmap.addr);
424 if (dinfo->registered)
425 unregister_framebuffer(dinfo->info);
429 if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) {
430 agp_unbind_memory(dinfo->gtt_fb_mem);
431 agp_free_memory(dinfo->gtt_fb_mem);
433 if (dinfo->gtt_cursor_mem) {
434 agp_unbind_memory(dinfo->gtt_cursor_mem);
435 agp_free_memory(dinfo->gtt_cursor_mem);
437 if (dinfo->gtt_ring_mem) {
438 agp_unbind_memory(dinfo->gtt_ring_mem);
439 agp_free_memory(dinfo->gtt_ring_mem);
442 if (dinfo->mmio_base)
443 iounmap((void __iomem *)dinfo->mmio_base);
444 if (dinfo->aperture.virtual)
445 iounmap((void __iomem *)dinfo->aperture.virtual);
447 if (dinfo->mmio_base_phys)
448 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
449 if (dinfo->aperture.physical)
450 release_mem_region(dinfo->aperture.physical,
451 dinfo->aperture.size);
452 framebuffer_release(dinfo->info);
455 #define bailout(dinfo) do { \
456 DBG_MSG("bailout\n"); \
458 INF_MSG("Not going to register framebuffer, exiting...\n"); \
464 intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
466 struct fb_info *info;
467 struct intelfb_info *dinfo;
469 int aperture_size, stolen_size;
470 struct agp_kern_info gtt_info;
474 DBG_MSG("intelfb_pci_register\n");
477 if (num_registered != 1) {
478 ERR_MSG("Attempted to register %d devices "
479 "(should be only 1).\n", num_registered);
483 info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
485 ERR_MSG("Could not allocate memory for intelfb_info.\n");
488 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
489 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
496 dinfo->fbops = &intel_fb_ops;
499 /* Reserve pixmap space. */
500 info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL);
501 if (info->pixmap.addr == NULL) {
502 ERR_MSG("Cannot reserve pixmap memory.\n");
505 memset(info->pixmap.addr, 0, 64 * 1024);
507 /* set early this option because it could be changed by tv encoder
509 dinfo->fixed_mode = fixed;
512 if ((err = pci_enable_device(pdev))) {
513 ERR_MSG("Cannot enable device.\n");
518 /* Set base addresses. */
519 dinfo->aperture.physical = pci_resource_start(pdev, 0);
520 dinfo->aperture.size = pci_resource_len(pdev, 0);
521 dinfo->mmio_base_phys = pci_resource_start(pdev, 1);
523 DBG_MSG("fb aperture: 0x%lx/0x%lx, MMIO region: 0x%lx/0x%lx\n",
524 pci_resource_start(pdev, 0), pci_resource_len(pdev, 0),
525 pci_resource_start(pdev, 1), pci_resource_len(pdev, 1));
527 /* Reserve the fb and MMIO regions */
528 if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size,
529 INTELFB_MODULE_NAME)) {
530 ERR_MSG("Cannot reserve FB region.\n");
534 if (!request_mem_region(dinfo->mmio_base_phys,
536 INTELFB_MODULE_NAME)) {
537 ERR_MSG("Cannot reserve MMIO region.\n");
542 /* Map the fb and MMIO regions */
543 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
544 (dinfo->aperture.physical, dinfo->aperture.size);
545 if (!dinfo->aperture.virtual) {
546 ERR_MSG("Cannot remap FB region.\n");
551 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
553 if (!dinfo->mmio_base) {
554 ERR_MSG("Cannot remap MMIO region.\n");
559 /* Get the chipset info. */
560 dinfo->pci_chipset = pdev->device;
562 if (intelfbhw_get_chipset(pdev, &dinfo->name, &dinfo->chipset,
568 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
573 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
574 "stolen memory %dkB\n",
575 pdev->bus->number, PCI_SLOT(pdev->devfn),
576 PCI_FUNC(pdev->devfn), dinfo->name,
577 BtoMB(aperture_size), BtoKB(stolen_size));
579 /* Set these from the options. */
580 dinfo->accel = accel;
581 dinfo->hwcursor = hwcursor;
583 if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
584 INF_MSG("Acceleration is not supported for the %s chipset.\n",
589 /* Framebuffer parameters - Use all the stolen memory if >= vram */
590 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
591 dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
592 dinfo->fbmem_gart = 0;
594 dinfo->fb.size = MB(vram);
595 dinfo->fbmem_gart = 1;
598 /* Allocate space for the ring buffer and HW cursor if enabled. */
600 dinfo->ring.size = RINGBUFFER_SIZE;
601 dinfo->ring_tail_mask = dinfo->ring.size - 1;
603 if (dinfo->hwcursor) {
604 dinfo->cursor.size = HW_CURSOR_SIZE;
607 /* Use agpgart to manage the GATT */
608 if (agp_backend_acquire()) {
609 ERR_MSG("cannot acquire agp\n");
614 /* get the current gatt info */
615 if (agp_copy_info(>t_info)) {
616 ERR_MSG("cannot get agp info\n");
617 agp_backend_release();
622 /* set the mem offsets - set them after the already used pages */
624 dinfo->ring.offset = (stolen_size >> 12)
625 + gtt_info.current_memory;
627 if (dinfo->hwcursor) {
628 dinfo->cursor.offset = (stolen_size >> 12) +
629 + gtt_info.current_memory + (dinfo->ring.size >> 12);
631 if (dinfo->fbmem_gart) {
632 dinfo->fb.offset = (stolen_size >> 12) +
633 + gtt_info.current_memory + (dinfo->ring.size >> 12)
634 + (dinfo->cursor.size >> 12);
637 /* Allocate memories (which aren't stolen) */
639 if (!(dinfo->gtt_ring_mem =
640 agp_allocate_memory(dinfo->ring.size >> 12,
641 AGP_NORMAL_MEMORY))) {
642 ERR_MSG("cannot allocate ring buffer memory\n");
643 agp_backend_release();
647 if (agp_bind_memory(dinfo->gtt_ring_mem,
648 dinfo->ring.offset)) {
649 ERR_MSG("cannot bind ring buffer memory\n");
650 agp_backend_release();
654 dinfo->ring.physical = dinfo->aperture.physical
655 + (dinfo->ring.offset << 12);
656 dinfo->ring.virtual = dinfo->aperture.virtual
657 + (dinfo->ring.offset << 12);
658 dinfo->ring_head = dinfo->ring.virtual;
660 if (dinfo->hwcursor) {
661 agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
663 if (!(dinfo->gtt_cursor_mem =
664 agp_allocate_memory(dinfo->cursor.size >> 12,
666 ERR_MSG("cannot allocate cursor memory\n");
667 agp_backend_release();
671 if (agp_bind_memory(dinfo->gtt_cursor_mem,
672 dinfo->cursor.offset)) {
673 ERR_MSG("cannot bind cursor memory\n");
674 agp_backend_release();
679 dinfo->cursor.physical
680 = dinfo->gtt_cursor_mem->physical;
682 dinfo->cursor.physical = dinfo->aperture.physical
683 + (dinfo->cursor.offset << 12);
684 dinfo->cursor.virtual = dinfo->aperture.virtual
685 + (dinfo->cursor.offset << 12);
687 if (dinfo->fbmem_gart) {
688 if (!(dinfo->gtt_fb_mem =
689 agp_allocate_memory(dinfo->fb.size >> 12,
690 AGP_NORMAL_MEMORY))) {
691 WRN_MSG("cannot allocate framebuffer memory - use "
693 dinfo->fbmem_gart = 0;
695 if (agp_bind_memory(dinfo->gtt_fb_mem,
697 WRN_MSG("cannot bind framebuffer memory - use "
699 dinfo->fbmem_gart = 0;
703 /* update framebuffer memory parameters */
704 if (!dinfo->fbmem_gart)
705 dinfo->fb.offset = 0; /* starts at offset 0 */
706 dinfo->fb.physical = dinfo->aperture.physical
707 + (dinfo->fb.offset << 12);
708 dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
709 dinfo->fb_start = dinfo->fb.offset << 12;
711 /* release agpgart */
712 agp_backend_release();
717 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%x)\n",
718 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
719 (u32 __iomem ) dinfo->fb.virtual);
720 DBG_MSG("MMIO: 0x%x/0x%x (0x%x)\n",
721 dinfo->mmio_base_phys, INTEL_REG_SIZE,
722 (u32 __iomem) dinfo->mmio_base);
723 DBG_MSG("ring buffer: 0x%x/0x%x (0x%x)\n",
724 dinfo->ring.physical, dinfo->ring.size,
725 (u32 __iomem ) dinfo->ring.virtual);
726 DBG_MSG("HW cursor: 0x%x/0x%x (0x%x) (offset 0x%x) (phys 0x%x)\n",
727 dinfo->cursor.physical, dinfo->cursor.size,
728 (u32 __iomem ) dinfo->cursor.virtual, dinfo->cursor.offset,
729 dinfo->cursor.physical);
731 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
732 "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
733 DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
739 * Check if the LVDS port or any DVO ports are enabled. If so,
740 * don't allow mode switching
742 dvo = intelfbhw_check_non_crt(dinfo);
744 dinfo->fixed_mode = 1;
745 WRN_MSG("Non-CRT device is enabled ( ");
749 s = intelfbhw_dvo_to_string(1 << i);
756 printk("). Disabling mode switching.\n");
762 if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
763 ERR_MSG("Video mode must be programmed at boot time.\n");
771 /* Initialise dinfo and related data. */
772 /* If an initial mode was programmed at boot time, get its details. */
773 if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB)
774 get_initial_mode(dinfo);
779 if (FIXED_MODE(dinfo)) {
780 /* remap fb address */
781 update_dinfo(dinfo, &dinfo->initial_var);
788 if (intelfb_set_fbinfo(dinfo)) {
796 for (i = 0; i < 16; i++) {
798 dinfo->palette[i].red = default_red[j];
799 dinfo->palette[i].green = default_grn[j];
800 dinfo->palette[i].blue = default_blu[j];
806 pci_set_drvdata(pdev, dinfo);
808 /* Save the initial register state. */
809 i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
810 bailearly > 6 ? bailearly - 6 : 0);
812 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
816 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
821 /* Cursor initialisation */
822 if (dinfo->hwcursor) {
823 intelfbhw_cursor_init(dinfo);
824 intelfbhw_cursor_reset(dinfo);
830 /* 2d acceleration init */
832 intelfbhw_2d_start(dinfo);
840 if (register_framebuffer(dinfo->info) < 0) {
841 ERR_MSG("Cannot register framebuffer.\n");
846 dinfo->registered = 1;
851 fb_dealloc_cmap(&info->cmap);
853 framebuffer_release(info);
857 static void __devexit
858 intelfb_pci_unregister(struct pci_dev *pdev)
860 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
862 DBG_MSG("intelfb_pci_unregister\n");
869 pci_set_drvdata(pdev, NULL);
872 /***************************************************************
874 ***************************************************************/
877 intelfb_var_to_depth(const struct fb_var_screeninfo *var)
879 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
880 var->bits_per_pixel, var->green.length);
882 switch (var->bits_per_pixel) {
884 return (var->green.length == 6) ? 16 : 15;
888 return var->bits_per_pixel;
893 static __inline__ int
894 var_to_refresh(const struct fb_var_screeninfo *var)
896 int xtot = var->xres + var->left_margin + var->right_margin +
898 int ytot = var->yres + var->upper_margin + var->lower_margin +
901 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
904 /***************************************************************
905 * Various intialisation functions *
906 ***************************************************************/
908 static void __devinit
909 get_initial_mode(struct intelfb_info *dinfo)
911 struct fb_var_screeninfo *var;
914 DBG_MSG("get_initial_mode\n");
916 dinfo->initial_vga = 1;
917 dinfo->initial_fb_base = screen_info.lfb_base;
918 dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
919 dinfo->initial_pitch = screen_info.lfb_linelength;
921 var = &dinfo->initial_var;
922 memset(var, 0, sizeof(*var));
923 var->xres = screen_info.lfb_width;
924 var->yres = screen_info.lfb_height;
925 var->bits_per_pixel = screen_info.lfb_depth;
926 switch (screen_info.lfb_depth) {
928 var->bits_per_pixel = 16;
931 var->bits_per_pixel = 32;
935 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
936 dinfo->initial_fb_base, dinfo->initial_video_ram,
937 BtoKB(dinfo->initial_video_ram));
939 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
940 var->xres, var->yres, var->bits_per_pixel,
941 dinfo->initial_pitch);
943 /* Dummy timing values (assume 60Hz) */
944 var->left_margin = (var->xres / 8) & 0xf8;
945 var->right_margin = 32;
946 var->upper_margin = 16;
947 var->lower_margin = 4;
948 var->hsync_len = (var->xres / 8) & 0xf8;
951 xtot = var->xres + var->left_margin +
952 var->right_margin + var->hsync_len;
953 ytot = var->yres + var->upper_margin +
954 var->lower_margin + var->vsync_len;
955 var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
960 if (var->bits_per_pixel > 8) {
961 var->red.offset = screen_info.red_pos;
962 var->red.length = screen_info.red_size;
963 var->green.offset = screen_info.green_pos;
964 var->green.length = screen_info.green_size;
965 var->blue.offset = screen_info.blue_pos;
966 var->blue.length = screen_info.blue_size;
967 var->transp.offset = screen_info.rsvd_pos;
968 var->transp.length = screen_info.rsvd_size;
971 var->green.length = 8;
972 var->blue.length = 8;
977 intelfb_init_var(struct intelfb_info *dinfo)
979 struct fb_var_screeninfo *var;
982 DBG_MSG("intelfb_init_var\n");
984 var = &dinfo->info->var;
985 if (FIXED_MODE(dinfo)) {
986 memcpy(var, &dinfo->initial_var,
987 sizeof(struct fb_var_screeninfo));
991 msrc = fb_find_mode(var, dinfo->info, mode,
997 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
1003 ERR_MSG("Cannot find a suitable video mode.\n");
1007 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
1008 var->bits_per_pixel, var_to_refresh(var));
1010 DBG_MSG("Initial video mode is from %d.\n", msrc);
1012 #if ALLOCATE_FOR_PANNING
1013 /* Allow use of half of the video ram for panning */
1014 var->xres_virtual = var->xres;
1016 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1017 if (var->yres_virtual < var->yres)
1018 var->yres_virtual = var->yres;
1020 var->yres_virtual = var->yres;
1024 var->accel_flags |= FB_ACCELF_TEXT;
1026 var->accel_flags &= ~FB_ACCELF_TEXT;
1031 static int __devinit
1032 intelfb_set_fbinfo(struct intelfb_info *dinfo)
1034 struct fb_info *info = dinfo->info;
1036 DBG_MSG("intelfb_set_fbinfo\n");
1038 info->flags = FBINFO_FLAG_DEFAULT;
1039 info->fbops = &intel_fb_ops;
1040 info->pseudo_palette = dinfo->pseudo_palette;
1042 info->pixmap.size = 64*1024;
1043 info->pixmap.buf_align = 8;
1044 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1046 if (intelfb_init_var(dinfo))
1049 info->pixmap.scan_align = 1;
1051 update_dinfo(dinfo, &info->var);
1056 /* Update dinfo to match the active video mode. */
1058 update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
1060 DBG_MSG("update_dinfo\n");
1062 dinfo->bpp = var->bits_per_pixel;
1063 dinfo->depth = intelfb_var_to_depth(var);
1064 dinfo->xres = var->xres;
1065 dinfo->yres = var->xres;
1066 dinfo->pixclock = var->pixclock;
1068 intelfb_get_fix(&dinfo->info->fix, dinfo->info);
1070 switch (dinfo->bpp) {
1072 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1073 dinfo->pitch = var->xres_virtual;
1076 dinfo->visual = FB_VISUAL_TRUECOLOR;
1077 dinfo->pitch = var->xres_virtual * 2;
1080 dinfo->visual = FB_VISUAL_TRUECOLOR;
1081 dinfo->pitch = var->xres_virtual * 4;
1085 /* Make sure the line length is a aligned correctly. */
1086 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
1088 if (FIXED_MODE(dinfo))
1089 dinfo->pitch = dinfo->initial_pitch;
1091 dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
1092 dinfo->info->fix.line_length = dinfo->pitch;
1093 dinfo->info->fix.visual = dinfo->visual;
1096 /* fbops functions */
1099 intelfb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
1101 struct intelfb_info *dinfo = GET_DINFO(info);
1103 DBG_MSG("intelfb_get_fix\n");
1105 memset(fix, 0, sizeof(*fix));
1106 strcpy(fix->id, dinfo->name);
1107 fix->smem_start = dinfo->fb.physical;
1108 fix->smem_len = dinfo->fb.size;
1109 fix->type = FB_TYPE_PACKED_PIXELS;
1111 fix->visual = dinfo->visual;
1115 fix->line_length = dinfo->pitch;
1116 fix->mmio_start = dinfo->mmio_base_phys;
1117 fix->mmio_len = INTEL_REG_SIZE;
1118 fix->accel = FB_ACCEL_I830;
1122 /***************************************************************
1124 ***************************************************************/
1127 intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1130 struct fb_var_screeninfo v;
1131 struct intelfb_info *dinfo;
1132 static int first = 1;
1134 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1136 dinfo = GET_DINFO(info);
1138 if (intelfbhw_validate_mode(dinfo, var) != 0)
1143 /* Check for a supported bpp. */
1144 if (v.bits_per_pixel <= 8) {
1145 v.bits_per_pixel = 8;
1146 } else if (v.bits_per_pixel <= 16) {
1147 if (v.bits_per_pixel == 16)
1149 v.bits_per_pixel = 16;
1150 } else if (v.bits_per_pixel <= 32) {
1151 v.bits_per_pixel = 32;
1155 change_var = ((info->var.xres != var->xres) ||
1156 (info->var.yres != var->yres) ||
1157 (info->var.xres_virtual != var->xres_virtual) ||
1158 (info->var.yres_virtual != var->yres_virtual) ||
1159 (info->var.bits_per_pixel != var->bits_per_pixel) ||
1160 memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
1161 memcmp(&info->var.green, &var->green,
1162 sizeof(var->green)) ||
1163 memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
1165 if (FIXED_MODE(dinfo) &&
1167 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1168 var->yres_virtual < dinfo->initial_var.yres ||
1169 var->xoffset || var->nonstd)) {
1171 ERR_MSG("Changing the video mode is not supported.\n");
1177 switch (intelfb_var_to_depth(&v)) {
1179 v.red.offset = v.green.offset = v.blue.offset = 0;
1180 v.red.length = v.green.length = v.blue.length = 8;
1181 v.transp.offset = v.transp.length = 0;
1187 v.red.length = v.green.length = v.blue.length = 5;
1188 v.transp.offset = v.transp.length = 0;
1197 v.transp.offset = v.transp.length = 0;
1203 v.red.length = v.green.length = v.blue.length = 8;
1204 v.transp.offset = v.transp.length = 0;
1210 v.red.length = v.green.length = v.blue.length = 8;
1211 v.transp.offset = 24;
1212 v.transp.length = 8;
1221 if (v.xoffset > v.xres_virtual - v.xres)
1222 v.xoffset = v.xres_virtual - v.xres;
1223 if (v.yoffset > v.yres_virtual - v.yres)
1224 v.yoffset = v.yres_virtual - v.yres;
1226 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1227 v.transp.msb_right = 0;
1235 intelfb_set_par(struct fb_info *info)
1237 struct intelfb_hwstate *hw;
1238 struct intelfb_info *dinfo = GET_DINFO(info);
1240 if (FIXED_MODE(dinfo)) {
1241 ERR_MSG("Changing the video mode is not supported.\n");
1245 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1249 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1250 info->var.yres, info->var.bits_per_pixel);
1252 intelfb_blank(FB_BLANK_POWERDOWN, info);
1255 intelfbhw_2d_stop(dinfo);
1257 memcpy(hw, &dinfo->save_state, sizeof(*hw));
1258 if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
1260 if (intelfbhw_program_mode(dinfo, hw, 0))
1264 intelfbhw_read_hw_state(dinfo, hw, 0);
1265 intelfbhw_print_hw_state(dinfo, hw);
1268 update_dinfo(dinfo, &info->var);
1271 intelfbhw_2d_start(dinfo);
1273 intelfb_pan_display(&info->var, info);
1275 intelfb_blank(FB_BLANK_UNBLANK, info);
1277 if (ACCEL(dinfo, info)) {
1278 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1279 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1280 FBINFO_HWACCEL_IMAGEBLIT;
1282 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1292 intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1293 unsigned blue, unsigned transp, struct fb_info *info)
1295 struct intelfb_info *dinfo = GET_DINFO(info);
1298 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1304 switch (dinfo->depth) {
1311 dinfo->palette[regno].red = red;
1312 dinfo->palette[regno].green = green;
1313 dinfo->palette[regno].blue = blue;
1315 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1320 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1321 ((green & 0xf800) >> 6) |
1322 ((blue & 0xf800) >> 11);
1325 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1326 ((green & 0xfc00) >> 5) |
1327 ((blue & 0xf800) >> 11);
1330 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1332 ((blue & 0xff00) >> 8);
1339 intelfb_blank(int blank, struct fb_info *info)
1341 intelfbhw_do_blank(blank, info);
1346 intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1348 intelfbhw_pan_display(var, info);
1352 /* When/if we have our own ioctls. */
1354 intelfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1355 unsigned long arg, struct fb_info *info)
1363 intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect)
1365 struct intelfb_info *dinfo = GET_DINFO(info);
1369 DBG_MSG("intelfb_fillrect\n");
1372 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1373 return cfb_fillrect(info, rect);
1375 if (rect->rop == ROP_COPY)
1376 rop = PAT_ROP_GXCOPY;
1378 rop = PAT_ROP_GXXOR;
1380 if (dinfo->depth != 8)
1381 color = dinfo->pseudo_palette[rect->color];
1383 color = rect->color;
1385 intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
1386 rect->width, rect->height, color,
1387 dinfo->pitch, info->var.bits_per_pixel,
1392 intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1394 struct intelfb_info *dinfo = GET_DINFO(info);
1397 DBG_MSG("intelfb_copyarea\n");
1400 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1401 return cfb_copyarea(info, region);
1403 intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
1404 region->dy, region->width, region->height,
1405 dinfo->pitch, info->var.bits_per_pixel);
1409 intelfb_imageblit(struct fb_info *info, const struct fb_image *image)
1411 struct intelfb_info *dinfo = GET_DINFO(info);
1412 u32 fgcolor, bgcolor;
1415 DBG_MSG("intelfb_imageblit\n");
1418 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1419 || image->depth != 1)
1420 return cfb_imageblit(info, image);
1422 if (dinfo->depth != 8) {
1423 fgcolor = dinfo->pseudo_palette[image->fg_color];
1424 bgcolor = dinfo->pseudo_palette[image->bg_color];
1426 fgcolor = image->fg_color;
1427 bgcolor = image->bg_color;
1430 if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
1431 image->height, image->data,
1432 image->dx, image->dy,
1433 dinfo->pitch, info->var.bits_per_pixel))
1434 return cfb_imageblit(info, image);
1438 intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1440 struct intelfb_info *dinfo = GET_DINFO(info);
1443 DBG_MSG("intelfb_cursor\n");
1446 if (!dinfo->hwcursor)
1447 return soft_cursor(info, cursor);
1449 intelfbhw_cursor_hide(dinfo);
1451 /* If XFree killed the cursor - restore it */
1452 if (INREG(CURSOR_A_BASEADDR) != dinfo->cursor.offset << 12) {
1455 DBG_MSG("the cursor was killed - restore it !!\n");
1456 DBG_MSG("size %d, %d pos %d, %d\n",
1457 cursor->image.width, cursor->image.height,
1458 cursor->image.dx, cursor->image.dy);
1460 intelfbhw_cursor_init(dinfo);
1461 intelfbhw_cursor_reset(dinfo);
1462 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1465 if (dinfo->depth != 8) {
1466 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1467 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1469 fg = cursor->image.fg_color;
1470 bg = cursor->image.bg_color;
1472 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1473 intelfbhw_cursor_load(dinfo, cursor->image.width,
1474 cursor->image.height,
1478 intelfbhw_cursor_show(dinfo);
1482 if (cursor->set & FB_CUR_SETPOS) {
1485 dx = cursor->image.dx - info->var.xoffset;
1486 dy = cursor->image.dy - info->var.yoffset;
1488 intelfbhw_cursor_setpos(dinfo, dx, dy);
1491 if (cursor->set & FB_CUR_SETSIZE) {
1492 if (cursor->image.width > 64 || cursor->image.height > 64)
1495 intelfbhw_cursor_reset(dinfo);
1498 if (cursor->set & FB_CUR_SETCMAP) {
1501 if (dinfo->depth != 8) {
1502 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1503 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1505 fg = cursor->image.fg_color;
1506 bg = cursor->image.bg_color;
1509 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1512 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1513 u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
1514 u32 size = s_pitch * cursor->image.height;
1515 u8 *dat = (u8 *) cursor->image.data;
1516 u8 *msk = (u8 *) cursor->mask;
1520 if (cursor->image.depth != 1)
1523 switch (cursor->rop) {
1525 for (i = 0; i < size; i++)
1526 src[i] = dat[i] ^ msk[i];
1530 for (i = 0; i < size; i++)
1531 src[i] = dat[i] & msk[i];
1535 /* save the bitmap to restore it when XFree will
1536 make the cursor dirty */
1537 memcpy(dinfo->cursor_src, src, size);
1539 intelfbhw_cursor_load(dinfo, cursor->image.width,
1540 cursor->image.height, src);
1544 intelfbhw_cursor_show(dinfo);
1550 intelfb_sync(struct fb_info *info)
1552 struct intelfb_info *dinfo = GET_DINFO(info);
1555 DBG_MSG("intelfb_sync\n");
1558 if (dinfo->ring_lockup)
1561 intelfbhw_do_sync(dinfo);