4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/
5 * 945G/945GM integrated graphics chips.
7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
11 * This driver consists of two parts. The first part (intelfbdrv.c) provides
12 * the basic fbdev interfaces, is derived in part from the radeonfb and
13 * vesafb drivers, and is covered by the GPL. The second part (intelfbhw.c)
14 * provides the code to program the hardware. Most of it is derived from
15 * the i810/i830 XFree86 driver. The HW-specific code is covered here
16 * under a dual license (GPL and MIT/XFree86 license).
22 /* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */
26 * 01/2003 - Initial driver (0.1.0), no mode switching, no acceleration.
27 * This initial version is a basic core that works a lot like
28 * the vesafb driver. It must be built-in to the kernel,
29 * and the initial video mode must be set with vga=XXX at
30 * boot time. (David Dawes)
32 * 01/2003 - Version 0.2.0: Mode switching added, colormap support
33 * implemented, Y panning, and soft screen blanking implemented.
34 * No acceleration yet. (David Dawes)
36 * 01/2003 - Version 0.3.0: fbcon acceleration support added. Module
37 * option handling added. (David Dawes)
39 * 01/2003 - Version 0.4.0: fbcon HW cursor support added. (David Dawes)
41 * 01/2003 - Version 0.4.1: Add auto-generation of built-in modes.
44 * 02/2003 - Version 0.4.2: Add check for active non-CRT devices, and
45 * mode validation checks. (David Dawes)
47 * 02/2003 - Version 0.4.3: Check when the VC is in graphics mode so that
48 * acceleration is disabled while an XFree86 server is running.
51 * 02/2003 - Version 0.4.4: Monitor DPMS support. (David Dawes)
53 * 02/2003 - Version 0.4.5: Basic XFree86 + fbdev working. (David Dawes)
55 * 02/2003 - Version 0.5.0: Modify to work with the 2.5.32 kernel as well
56 * as 2.4.x kernels. (David Dawes)
58 * 02/2003 - Version 0.6.0: Split out HW-specifics into a separate file.
61 * 02/2003 - Version 0.7.0: Test on 852GM/855GM. Acceleration and HW
62 * cursor are disabled on this platform. (David Dawes)
64 * 02/2003 - Version 0.7.1: Test on 845G. Acceleration is disabled
65 * on this platform. (David Dawes)
67 * 02/2003 - Version 0.7.2: Test on 830M. Acceleration and HW
68 * cursor are disabled on this platform. (David Dawes)
70 * 02/2003 - Version 0.7.3: Fix 8-bit modes for mobile platforms
73 * 02/2003 - Version 0.7.4: Add checks for FB and FBCON_HAS_CFB* configured
74 * in the kernel, and add mode bpp verification and default
75 * bpp selection based on which FBCON_HAS_CFB* are configured.
78 * 02/2003 - Version 0.7.5: Add basic package/install scripts based on the
79 * DRI packaging scripts. (David Dawes)
81 * 04/2003 - Version 0.7.6: Fix typo that affects builds with SMP-enabled
82 * kernels. (David Dawes, reported by Anupam).
84 * 06/2003 - Version 0.7.7:
85 * Fix Makefile.kernel build problem (Tsutomu Yasuda).
86 * Fix mis-placed #endif (2.4.21 kernel).
88 * 09/2004 - Version 0.9.0 - by Sylvain Meyer
89 * Port to linux 2.6 kernel fbdev
90 * Fix HW accel and HW cursor on i845G
91 * Use of agpgart for fb memory reservation
94 * 10/2004 - Version 0.9.1
95 * Use module_param instead of old MODULE_PARM
98 * 11/2004 - Version 0.9.2
99 * Add vram option to reserve more memory than stolen by BIOS
100 * Fix intelfbhw_pan_display typo
101 * Add __initdata annotations
111 #include <linux/config.h>
112 #include <linux/module.h>
113 #include <linux/kernel.h>
114 #include <linux/errno.h>
115 #include <linux/string.h>
116 #include <linux/mm.h>
117 #include <linux/tty.h>
118 #include <linux/slab.h>
119 #include <linux/delay.h>
120 #include <linux/fb.h>
121 #include <linux/ioport.h>
122 #include <linux/init.h>
123 #include <linux/pci.h>
124 #include <linux/vmalloc.h>
125 #include <linux/pagemap.h>
130 #include <asm/mtrr.h>
134 #include "intelfbhw.h"
137 static void __devinit get_initial_mode(struct intelfb_info *dinfo);
138 static void update_dinfo(struct intelfb_info *dinfo,
139 struct fb_var_screeninfo *var);
140 static int intelfb_check_var(struct fb_var_screeninfo *var,
141 struct fb_info *info);
142 static int intelfb_set_par(struct fb_info *info);
143 static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
144 unsigned blue, unsigned transp,
145 struct fb_info *info);
147 static int intelfb_blank(int blank, struct fb_info *info);
148 static int intelfb_pan_display(struct fb_var_screeninfo *var,
149 struct fb_info *info);
151 static void intelfb_fillrect(struct fb_info *info,
152 const struct fb_fillrect *rect);
153 static void intelfb_copyarea(struct fb_info *info,
154 const struct fb_copyarea *region);
155 static void intelfb_imageblit(struct fb_info *info,
156 const struct fb_image *image);
157 static int intelfb_cursor(struct fb_info *info,
158 struct fb_cursor *cursor);
160 static int intelfb_sync(struct fb_info *info);
162 static int intelfb_ioctl(struct fb_info *info,
163 unsigned int cmd, unsigned long arg);
165 static int __devinit intelfb_pci_register(struct pci_dev *pdev,
166 const struct pci_device_id *ent);
167 static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
168 static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
171 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
172 * mobile chipsets from being registered.
174 #if DETECT_VGA_CLASS_ONLY
175 #define INTELFB_CLASS_MASK ~0 << 8
177 #define INTELFB_CLASS_MASK 0
180 static struct pci_device_id intelfb_pci_table[] __devinitdata = {
181 { 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 },
182 { 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 },
183 { 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 },
184 { 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 },
185 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G },
186 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM },
187 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945G },
188 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GM },
193 static int num_registered = 0;
196 static struct fb_ops intel_fb_ops = {
197 .owner = THIS_MODULE,
198 .fb_check_var = intelfb_check_var,
199 .fb_set_par = intelfb_set_par,
200 .fb_setcolreg = intelfb_setcolreg,
201 .fb_blank = intelfb_blank,
202 .fb_pan_display = intelfb_pan_display,
203 .fb_fillrect = intelfb_fillrect,
204 .fb_copyarea = intelfb_copyarea,
205 .fb_imageblit = intelfb_imageblit,
206 .fb_cursor = intelfb_cursor,
207 .fb_sync = intelfb_sync,
208 .fb_ioctl = intelfb_ioctl
211 /* PCI driver module table */
212 static struct pci_driver intelfb_driver = {
214 .id_table = intelfb_pci_table,
215 .probe = intelfb_pci_register,
216 .remove = __devexit_p(intelfb_pci_unregister)
219 /* Module description/parameters */
220 MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
221 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
223 "Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS " chipsets");
224 MODULE_LICENSE("Dual BSD/GPL");
225 MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
227 static int accel = 1;
229 static int hwcursor = 0;
231 static int fixed = 0;
232 static int noinit = 0;
233 static int noregister = 0;
234 static int probeonly = 0;
235 static int idonly = 0;
236 static int bailearly = 0;
237 static int voffset = 48;
238 static char *mode = NULL;
240 module_param(accel, bool, S_IRUGO);
241 MODULE_PARM_DESC(accel, "Enable hardware acceleration");
242 module_param(vram, int, S_IRUGO);
243 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
244 module_param(voffset, int, S_IRUGO);
245 MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
246 module_param(hwcursor, bool, S_IRUGO);
247 MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
248 module_param(mtrr, bool, S_IRUGO);
249 MODULE_PARM_DESC(mtrr, "Enable MTRR support");
250 module_param(fixed, bool, S_IRUGO);
251 MODULE_PARM_DESC(fixed, "Disable mode switching");
252 module_param(noinit, bool, 0);
253 MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
254 module_param(noregister, bool, 0);
255 MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
256 module_param(probeonly, bool, 0);
257 MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
258 module_param(idonly, bool, 0);
259 MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
260 module_param(bailearly, bool, 0);
261 MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
262 module_param(mode, charp, S_IRUGO);
263 MODULE_PARM_DESC(mode,
264 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
267 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
268 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, 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=");
383 DBG_MSG("intelfb_init\n");
385 INF_MSG("Framebuffer driver for "
386 "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
387 INF_MSG("Version " INTELFB_VERSION "\n");
393 if (fb_get_options("intelfb", &option))
395 intelfb_setup(option);
398 return pci_register_driver(&intelfb_driver);
404 DBG_MSG("intelfb_exit\n");
405 pci_unregister_driver(&intelfb_driver);
408 module_init(intelfb_init);
409 module_exit(intelfb_exit);
411 /***************************************************************
412 * mtrr support functions *
413 ***************************************************************/
416 static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
418 dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical,
419 dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1);
420 if (dinfo->mtrr_reg < 0) {
421 ERR_MSG("unable to set MTRR\n");
426 static inline void unset_mtrr(struct intelfb_info *dinfo)
429 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
430 dinfo->aperture.size);
433 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
435 #define unset_mtrr(x) do { } while (0)
436 #endif /* CONFIG_MTRR */
438 /***************************************************************
439 * driver init / cleanup *
440 ***************************************************************/
443 cleanup(struct intelfb_info *dinfo)
445 DBG_MSG("cleanup\n");
450 fb_dealloc_cmap(&dinfo->info->cmap);
451 kfree(dinfo->info->pixmap.addr);
453 if (dinfo->registered)
454 unregister_framebuffer(dinfo->info);
458 if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) {
459 agp_unbind_memory(dinfo->gtt_fb_mem);
460 agp_free_memory(dinfo->gtt_fb_mem);
462 if (dinfo->gtt_cursor_mem) {
463 agp_unbind_memory(dinfo->gtt_cursor_mem);
464 agp_free_memory(dinfo->gtt_cursor_mem);
466 if (dinfo->gtt_ring_mem) {
467 agp_unbind_memory(dinfo->gtt_ring_mem);
468 agp_free_memory(dinfo->gtt_ring_mem);
471 if (dinfo->mmio_base)
472 iounmap((void __iomem *)dinfo->mmio_base);
473 if (dinfo->aperture.virtual)
474 iounmap((void __iomem *)dinfo->aperture.virtual);
476 if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
477 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
478 if (dinfo->flag & INTELFB_FB_ACQUIRED)
479 release_mem_region(dinfo->aperture.physical,
480 dinfo->aperture.size);
481 framebuffer_release(dinfo->info);
484 #define bailout(dinfo) do { \
485 DBG_MSG("bailout\n"); \
487 INF_MSG("Not going to register framebuffer, exiting...\n"); \
493 intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
495 struct fb_info *info;
496 struct intelfb_info *dinfo;
498 int aperture_size, stolen_size;
499 struct agp_kern_info gtt_info;
502 struct agp_bridge_data *bridge;
503 int aperture_bar = 0;
507 DBG_MSG("intelfb_pci_register\n");
510 if (num_registered != 1) {
511 ERR_MSG("Attempted to register %d devices "
512 "(should be only 1).\n", num_registered);
516 info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
518 ERR_MSG("Could not allocate memory for intelfb_info.\n");
521 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
522 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
529 dinfo->fbops = &intel_fb_ops;
532 /* Reserve pixmap space. */
533 info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL);
534 if (info->pixmap.addr == NULL) {
535 ERR_MSG("Cannot reserve pixmap memory.\n");
538 memset(info->pixmap.addr, 0, 64 * 1024);
540 /* set early this option because it could be changed by tv encoder
542 dinfo->fixed_mode = fixed;
545 if ((err = pci_enable_device(pdev))) {
546 ERR_MSG("Cannot enable device.\n");
551 /* Set base addresses. */
552 if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
553 (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
554 (ent->device == PCI_DEVICE_ID_INTEL_945G) ||
555 (ent->device == PCI_DEVICE_ID_INTEL_945GM)) {
559 dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
560 dinfo->aperture.size = pci_resource_len(pdev, aperture_bar);
561 dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar);
562 DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
563 (unsigned long long)pci_resource_start(pdev, aperture_bar),
564 (unsigned long long)pci_resource_len(pdev, aperture_bar),
565 (unsigned long long)pci_resource_start(pdev, mmio_bar),
566 (unsigned long long)pci_resource_len(pdev, mmio_bar));
568 /* Reserve the fb and MMIO regions */
569 if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size,
570 INTELFB_MODULE_NAME)) {
571 ERR_MSG("Cannot reserve FB region.\n");
576 dinfo->flag |= INTELFB_FB_ACQUIRED;
578 if (!request_mem_region(dinfo->mmio_base_phys,
580 INTELFB_MODULE_NAME)) {
581 ERR_MSG("Cannot reserve MMIO region.\n");
586 dinfo->flag |= INTELFB_MMIO_ACQUIRED;
588 /* Get the chipset info. */
589 dinfo->pci_chipset = pdev->device;
591 if (intelfbhw_get_chipset(pdev, dinfo)) {
596 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
601 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
602 "stolen memory %dkB\n",
603 pdev->bus->number, PCI_SLOT(pdev->devfn),
604 PCI_FUNC(pdev->devfn), dinfo->name,
605 BtoMB(aperture_size), BtoKB(stolen_size));
607 /* Set these from the options. */
608 dinfo->accel = accel;
609 dinfo->hwcursor = hwcursor;
611 if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
612 INF_MSG("Acceleration is not supported for the %s chipset.\n",
617 /* Framebuffer parameters - Use all the stolen memory if >= vram */
618 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
619 dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
620 dinfo->fbmem_gart = 0;
622 dinfo->fb.size = MB(vram);
623 dinfo->fbmem_gart = 1;
626 /* Allocate space for the ring buffer and HW cursor if enabled. */
628 dinfo->ring.size = RINGBUFFER_SIZE;
629 dinfo->ring_tail_mask = dinfo->ring.size - 1;
631 if (dinfo->hwcursor) {
632 dinfo->cursor.size = HW_CURSOR_SIZE;
635 /* Use agpgart to manage the GATT */
636 if (!(bridge = agp_backend_acquire(pdev))) {
637 ERR_MSG("cannot acquire agp\n");
642 /* get the current gatt info */
643 if (agp_copy_info(bridge, >t_info)) {
644 ERR_MSG("cannot get agp info\n");
645 agp_backend_release(bridge);
650 if (MB(voffset) < stolen_size)
651 offset = (stolen_size >> 12);
653 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
655 /* set the mem offsets - set them after the already used pages */
657 dinfo->ring.offset = offset + gtt_info.current_memory;
659 if (dinfo->hwcursor) {
660 dinfo->cursor.offset = offset +
661 + gtt_info.current_memory + (dinfo->ring.size >> 12);
663 if (dinfo->fbmem_gart) {
664 dinfo->fb.offset = offset +
665 + gtt_info.current_memory + (dinfo->ring.size >> 12)
666 + (dinfo->cursor.size >> 12);
669 /* Allocate memories (which aren't stolen) */
670 /* Map the fb and MMIO regions */
671 /* ioremap only up to the end of used aperture */
672 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
673 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
675 if (!dinfo->aperture.virtual) {
676 ERR_MSG("Cannot remap FB region.\n");
682 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
684 if (!dinfo->mmio_base) {
685 ERR_MSG("Cannot remap MMIO region.\n");
691 if (!(dinfo->gtt_ring_mem =
692 agp_allocate_memory(bridge, dinfo->ring.size >> 12,
693 AGP_NORMAL_MEMORY))) {
694 ERR_MSG("cannot allocate ring buffer memory\n");
695 agp_backend_release(bridge);
699 if (agp_bind_memory(dinfo->gtt_ring_mem,
700 dinfo->ring.offset)) {
701 ERR_MSG("cannot bind ring buffer memory\n");
702 agp_backend_release(bridge);
706 dinfo->ring.physical = dinfo->aperture.physical
707 + (dinfo->ring.offset << 12);
708 dinfo->ring.virtual = dinfo->aperture.virtual
709 + (dinfo->ring.offset << 12);
710 dinfo->ring_head = dinfo->ring.virtual;
712 if (dinfo->hwcursor) {
713 agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
715 if (!(dinfo->gtt_cursor_mem =
716 agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
718 ERR_MSG("cannot allocate cursor memory\n");
719 agp_backend_release(bridge);
723 if (agp_bind_memory(dinfo->gtt_cursor_mem,
724 dinfo->cursor.offset)) {
725 ERR_MSG("cannot bind cursor memory\n");
726 agp_backend_release(bridge);
731 dinfo->cursor.physical
732 = dinfo->gtt_cursor_mem->physical;
734 dinfo->cursor.physical = dinfo->aperture.physical
735 + (dinfo->cursor.offset << 12);
736 dinfo->cursor.virtual = dinfo->aperture.virtual
737 + (dinfo->cursor.offset << 12);
739 if (dinfo->fbmem_gart) {
740 if (!(dinfo->gtt_fb_mem =
741 agp_allocate_memory(bridge, dinfo->fb.size >> 12,
742 AGP_NORMAL_MEMORY))) {
743 WRN_MSG("cannot allocate framebuffer memory - use "
745 dinfo->fbmem_gart = 0;
747 if (agp_bind_memory(dinfo->gtt_fb_mem,
749 WRN_MSG("cannot bind framebuffer memory - use "
751 dinfo->fbmem_gart = 0;
755 /* update framebuffer memory parameters */
756 if (!dinfo->fbmem_gart)
757 dinfo->fb.offset = 0; /* starts at offset 0 */
758 dinfo->fb.physical = dinfo->aperture.physical
759 + (dinfo->fb.offset << 12);
760 dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
761 dinfo->fb_start = dinfo->fb.offset << 12;
763 /* release agpgart */
764 agp_backend_release(bridge);
769 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%x)\n",
770 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
771 (u32 __iomem ) dinfo->fb.virtual);
772 DBG_MSG("MMIO: 0x%x/0x%x (0x%x)\n",
773 dinfo->mmio_base_phys, INTEL_REG_SIZE,
774 (u32 __iomem) dinfo->mmio_base);
775 DBG_MSG("ring buffer: 0x%x/0x%x (0x%x)\n",
776 dinfo->ring.physical, dinfo->ring.size,
777 (u32 __iomem ) dinfo->ring.virtual);
778 DBG_MSG("HW cursor: 0x%x/0x%x (0x%x) (offset 0x%x) (phys 0x%x)\n",
779 dinfo->cursor.physical, dinfo->cursor.size,
780 (u32 __iomem ) dinfo->cursor.virtual, dinfo->cursor.offset,
781 dinfo->cursor.physical);
783 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
784 "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
785 DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
791 * Check if the LVDS port or any DVO ports are enabled. If so,
792 * don't allow mode switching
794 dvo = intelfbhw_check_non_crt(dinfo);
796 dinfo->fixed_mode = 1;
797 WRN_MSG("Non-CRT device is enabled ( ");
801 s = intelfbhw_dvo_to_string(1 << i);
808 printk("). Disabling mode switching.\n");
814 if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
815 ERR_MSG("Video mode must be programmed at boot time.\n");
823 /* Initialise dinfo and related data. */
824 /* If an initial mode was programmed at boot time, get its details. */
825 if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB)
826 get_initial_mode(dinfo);
831 if (FIXED_MODE(dinfo)) {
832 /* remap fb address */
833 update_dinfo(dinfo, &dinfo->initial_var);
840 if (intelfb_set_fbinfo(dinfo)) {
851 pci_set_drvdata(pdev, dinfo);
853 /* Save the initial register state. */
854 i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
855 bailearly > 6 ? bailearly - 6 : 0);
857 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
861 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
866 /* Cursor initialisation */
867 if (dinfo->hwcursor) {
868 intelfbhw_cursor_init(dinfo);
869 intelfbhw_cursor_reset(dinfo);
875 /* 2d acceleration init */
877 intelfbhw_2d_start(dinfo);
885 if (register_framebuffer(dinfo->info) < 0) {
886 ERR_MSG("Cannot register framebuffer.\n");
891 dinfo->registered = 1;
896 fb_dealloc_cmap(&info->cmap);
898 framebuffer_release(info);
902 static void __devexit
903 intelfb_pci_unregister(struct pci_dev *pdev)
905 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
907 DBG_MSG("intelfb_pci_unregister\n");
914 pci_set_drvdata(pdev, NULL);
917 /***************************************************************
919 ***************************************************************/
922 intelfb_var_to_depth(const struct fb_var_screeninfo *var)
924 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
925 var->bits_per_pixel, var->green.length);
927 switch (var->bits_per_pixel) {
929 return (var->green.length == 6) ? 16 : 15;
933 return var->bits_per_pixel;
938 static __inline__ int
939 var_to_refresh(const struct fb_var_screeninfo *var)
941 int xtot = var->xres + var->left_margin + var->right_margin +
943 int ytot = var->yres + var->upper_margin + var->lower_margin +
946 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
949 /***************************************************************
950 * Various intialisation functions *
951 ***************************************************************/
953 static void __devinit
954 get_initial_mode(struct intelfb_info *dinfo)
956 struct fb_var_screeninfo *var;
959 DBG_MSG("get_initial_mode\n");
961 dinfo->initial_vga = 1;
962 dinfo->initial_fb_base = screen_info.lfb_base;
963 dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
964 dinfo->initial_pitch = screen_info.lfb_linelength;
966 var = &dinfo->initial_var;
967 memset(var, 0, sizeof(*var));
968 var->xres = screen_info.lfb_width;
969 var->yres = screen_info.lfb_height;
970 var->bits_per_pixel = screen_info.lfb_depth;
971 switch (screen_info.lfb_depth) {
973 var->bits_per_pixel = 16;
976 var->bits_per_pixel = 32;
980 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
981 dinfo->initial_fb_base, dinfo->initial_video_ram,
982 BtoKB(dinfo->initial_video_ram));
984 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
985 var->xres, var->yres, var->bits_per_pixel,
986 dinfo->initial_pitch);
988 /* Dummy timing values (assume 60Hz) */
989 var->left_margin = (var->xres / 8) & 0xf8;
990 var->right_margin = 32;
991 var->upper_margin = 16;
992 var->lower_margin = 4;
993 var->hsync_len = (var->xres / 8) & 0xf8;
996 xtot = var->xres + var->left_margin +
997 var->right_margin + var->hsync_len;
998 ytot = var->yres + var->upper_margin +
999 var->lower_margin + var->vsync_len;
1000 var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
1005 if (var->bits_per_pixel > 8) {
1006 var->red.offset = screen_info.red_pos;
1007 var->red.length = screen_info.red_size;
1008 var->green.offset = screen_info.green_pos;
1009 var->green.length = screen_info.green_size;
1010 var->blue.offset = screen_info.blue_pos;
1011 var->blue.length = screen_info.blue_size;
1012 var->transp.offset = screen_info.rsvd_pos;
1013 var->transp.length = screen_info.rsvd_size;
1015 var->red.length = 8;
1016 var->green.length = 8;
1017 var->blue.length = 8;
1021 static int __devinit
1022 intelfb_init_var(struct intelfb_info *dinfo)
1024 struct fb_var_screeninfo *var;
1027 DBG_MSG("intelfb_init_var\n");
1029 var = &dinfo->info->var;
1030 if (FIXED_MODE(dinfo)) {
1031 memcpy(var, &dinfo->initial_var,
1032 sizeof(struct fb_var_screeninfo));
1035 const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev);
1039 edid_d = kmalloc(EDID_LENGTH, GFP_KERNEL);
1042 memcpy(edid_d, edid_s, EDID_LENGTH);
1043 fb_edid_to_monspecs(edid_d,
1044 &dinfo->info->monspecs);
1050 printk("intelfb: Looking for mode in private "
1052 msrc = fb_find_mode(var, dinfo->info, mode,
1053 dinfo->info->monspecs.modedb,
1054 dinfo->info->monspecs.modedb_len,
1057 if (msrc && msrc > 1) {
1058 printk("intelfb: No mode in private database, "
1059 "intelfb: looking for mode in global "
1061 msrc = fb_find_mode(var, dinfo->info, mode,
1071 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
1077 ERR_MSG("Cannot find a suitable video mode.\n");
1081 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
1082 var->bits_per_pixel, var_to_refresh(var));
1084 DBG_MSG("Initial video mode is from %d.\n", msrc);
1086 #if ALLOCATE_FOR_PANNING
1087 /* Allow use of half of the video ram for panning */
1088 var->xres_virtual = var->xres;
1090 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1091 if (var->yres_virtual < var->yres)
1092 var->yres_virtual = var->yres;
1094 var->yres_virtual = var->yres;
1098 var->accel_flags |= FB_ACCELF_TEXT;
1100 var->accel_flags &= ~FB_ACCELF_TEXT;
1105 static int __devinit
1106 intelfb_set_fbinfo(struct intelfb_info *dinfo)
1108 struct fb_info *info = dinfo->info;
1110 DBG_MSG("intelfb_set_fbinfo\n");
1112 info->flags = FBINFO_FLAG_DEFAULT;
1113 info->fbops = &intel_fb_ops;
1114 info->pseudo_palette = dinfo->pseudo_palette;
1116 info->pixmap.size = 64*1024;
1117 info->pixmap.buf_align = 8;
1118 info->pixmap.access_align = 32;
1119 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1121 if (intelfb_init_var(dinfo))
1124 info->pixmap.scan_align = 1;
1125 strcpy(info->fix.id, dinfo->name);
1126 info->fix.smem_start = dinfo->fb.physical;
1127 info->fix.smem_len = dinfo->fb.size;
1128 info->fix.type = FB_TYPE_PACKED_PIXELS;
1129 info->fix.type_aux = 0;
1130 info->fix.xpanstep = 8;
1131 info->fix.ypanstep = 1;
1132 info->fix.ywrapstep = 0;
1133 info->fix.mmio_start = dinfo->mmio_base_phys;
1134 info->fix.mmio_len = INTEL_REG_SIZE;
1135 info->fix.accel = FB_ACCEL_I830;
1136 update_dinfo(dinfo, &info->var);
1141 /* Update dinfo to match the active video mode. */
1143 update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
1145 DBG_MSG("update_dinfo\n");
1147 dinfo->bpp = var->bits_per_pixel;
1148 dinfo->depth = intelfb_var_to_depth(var);
1149 dinfo->xres = var->xres;
1150 dinfo->yres = var->xres;
1151 dinfo->pixclock = var->pixclock;
1153 dinfo->info->fix.visual = dinfo->visual;
1154 dinfo->info->fix.line_length = dinfo->pitch;
1156 switch (dinfo->bpp) {
1158 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1159 dinfo->pitch = var->xres_virtual;
1162 dinfo->visual = FB_VISUAL_TRUECOLOR;
1163 dinfo->pitch = var->xres_virtual * 2;
1166 dinfo->visual = FB_VISUAL_TRUECOLOR;
1167 dinfo->pitch = var->xres_virtual * 4;
1171 /* Make sure the line length is a aligned correctly. */
1173 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX);
1175 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
1177 if (FIXED_MODE(dinfo))
1178 dinfo->pitch = dinfo->initial_pitch;
1180 dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
1181 dinfo->info->fix.line_length = dinfo->pitch;
1182 dinfo->info->fix.visual = dinfo->visual;
1185 /* fbops functions */
1187 /***************************************************************
1189 ***************************************************************/
1192 intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1195 struct fb_var_screeninfo v;
1196 struct intelfb_info *dinfo;
1197 static int first = 1;
1199 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1200 static const int pitches[] = {
1208 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1210 dinfo = GET_DINFO(info);
1212 /* update the pitch */
1213 if (intelfbhw_validate_mode(dinfo, var) != 0)
1218 for (i = 0; pitches[i] != 0; i++) {
1219 if (pitches[i] >= v.xres_virtual) {
1220 v.xres_virtual = pitches[i];
1225 /* Check for a supported bpp. */
1226 if (v.bits_per_pixel <= 8) {
1227 v.bits_per_pixel = 8;
1228 } else if (v.bits_per_pixel <= 16) {
1229 if (v.bits_per_pixel == 16)
1231 v.bits_per_pixel = 16;
1232 } else if (v.bits_per_pixel <= 32) {
1233 v.bits_per_pixel = 32;
1237 change_var = ((info->var.xres != var->xres) ||
1238 (info->var.yres != var->yres) ||
1239 (info->var.xres_virtual != var->xres_virtual) ||
1240 (info->var.yres_virtual != var->yres_virtual) ||
1241 (info->var.bits_per_pixel != var->bits_per_pixel) ||
1242 memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
1243 memcmp(&info->var.green, &var->green,
1244 sizeof(var->green)) ||
1245 memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
1247 if (FIXED_MODE(dinfo) &&
1249 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1250 var->yres_virtual < dinfo->initial_var.yres ||
1251 var->xoffset || var->nonstd)) {
1253 ERR_MSG("Changing the video mode is not supported.\n");
1259 switch (intelfb_var_to_depth(&v)) {
1261 v.red.offset = v.green.offset = v.blue.offset = 0;
1262 v.red.length = v.green.length = v.blue.length = 8;
1263 v.transp.offset = v.transp.length = 0;
1269 v.red.length = v.green.length = v.blue.length = 5;
1270 v.transp.offset = v.transp.length = 0;
1279 v.transp.offset = v.transp.length = 0;
1285 v.red.length = v.green.length = v.blue.length = 8;
1286 v.transp.offset = v.transp.length = 0;
1292 v.red.length = v.green.length = v.blue.length = 8;
1293 v.transp.offset = 24;
1294 v.transp.length = 8;
1303 if (v.xoffset > v.xres_virtual - v.xres)
1304 v.xoffset = v.xres_virtual - v.xres;
1305 if (v.yoffset > v.yres_virtual - v.yres)
1306 v.yoffset = v.yres_virtual - v.yres;
1308 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1309 v.transp.msb_right = 0;
1317 intelfb_set_par(struct fb_info *info)
1319 struct intelfb_hwstate *hw;
1320 struct intelfb_info *dinfo = GET_DINFO(info);
1322 if (FIXED_MODE(dinfo)) {
1323 ERR_MSG("Changing the video mode is not supported.\n");
1327 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1331 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1332 info->var.yres, info->var.bits_per_pixel);
1334 intelfb_blank(FB_BLANK_POWERDOWN, info);
1336 if (ACCEL(dinfo, info))
1337 intelfbhw_2d_stop(dinfo);
1339 memcpy(hw, &dinfo->save_state, sizeof(*hw));
1340 if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
1342 if (intelfbhw_program_mode(dinfo, hw, 0))
1346 intelfbhw_read_hw_state(dinfo, hw, 0);
1347 intelfbhw_print_hw_state(dinfo, hw);
1350 update_dinfo(dinfo, &info->var);
1352 if (ACCEL(dinfo, info))
1353 intelfbhw_2d_start(dinfo);
1355 intelfb_pan_display(&info->var, info);
1357 intelfb_blank(FB_BLANK_UNBLANK, info);
1359 if (ACCEL(dinfo, info)) {
1360 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1361 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1362 FBINFO_HWACCEL_IMAGEBLIT;
1364 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1374 intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1375 unsigned blue, unsigned transp, struct fb_info *info)
1377 struct intelfb_info *dinfo = GET_DINFO(info);
1380 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1386 if (dinfo->depth == 8) {
1391 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1396 switch (dinfo->depth) {
1398 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1399 ((green & 0xf800) >> 6) |
1400 ((blue & 0xf800) >> 11);
1403 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1404 ((green & 0xfc00) >> 5) |
1405 ((blue & 0xf800) >> 11);
1408 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1410 ((blue & 0xff00) >> 8);
1419 intelfb_blank(int blank, struct fb_info *info)
1421 intelfbhw_do_blank(blank, info);
1426 intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1428 intelfbhw_pan_display(var, info);
1432 /* When/if we have our own ioctls. */
1434 intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1442 intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect)
1444 struct intelfb_info *dinfo = GET_DINFO(info);
1448 DBG_MSG("intelfb_fillrect\n");
1451 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1452 return cfb_fillrect(info, rect);
1454 if (rect->rop == ROP_COPY)
1455 rop = PAT_ROP_GXCOPY;
1457 rop = PAT_ROP_GXXOR;
1459 if (dinfo->depth != 8)
1460 color = dinfo->pseudo_palette[rect->color];
1462 color = rect->color;
1464 intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
1465 rect->width, rect->height, color,
1466 dinfo->pitch, info->var.bits_per_pixel,
1471 intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1473 struct intelfb_info *dinfo = GET_DINFO(info);
1476 DBG_MSG("intelfb_copyarea\n");
1479 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1480 return cfb_copyarea(info, region);
1482 intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
1483 region->dy, region->width, region->height,
1484 dinfo->pitch, info->var.bits_per_pixel);
1488 intelfb_imageblit(struct fb_info *info, const struct fb_image *image)
1490 struct intelfb_info *dinfo = GET_DINFO(info);
1491 u32 fgcolor, bgcolor;
1494 DBG_MSG("intelfb_imageblit\n");
1497 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1498 || image->depth != 1)
1499 return cfb_imageblit(info, image);
1501 if (dinfo->depth != 8) {
1502 fgcolor = dinfo->pseudo_palette[image->fg_color];
1503 bgcolor = dinfo->pseudo_palette[image->bg_color];
1505 fgcolor = image->fg_color;
1506 bgcolor = image->bg_color;
1509 if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
1510 image->height, image->data,
1511 image->dx, image->dy,
1512 dinfo->pitch, info->var.bits_per_pixel))
1513 return cfb_imageblit(info, image);
1517 intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1519 struct intelfb_info *dinfo = GET_DINFO(info);
1522 DBG_MSG("intelfb_cursor\n");
1525 if (!dinfo->hwcursor)
1528 intelfbhw_cursor_hide(dinfo);
1530 /* If XFree killed the cursor - restore it */
1531 physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical :
1532 (dinfo->cursor.offset << 12);
1534 if (INREG(CURSOR_A_BASEADDR) != physical) {
1537 DBG_MSG("the cursor was killed - restore it !!\n");
1538 DBG_MSG("size %d, %d pos %d, %d\n",
1539 cursor->image.width, cursor->image.height,
1540 cursor->image.dx, cursor->image.dy);
1542 intelfbhw_cursor_init(dinfo);
1543 intelfbhw_cursor_reset(dinfo);
1544 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1547 if (dinfo->depth != 8) {
1548 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1549 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1551 fg = cursor->image.fg_color;
1552 bg = cursor->image.bg_color;
1554 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1555 intelfbhw_cursor_load(dinfo, cursor->image.width,
1556 cursor->image.height,
1560 intelfbhw_cursor_show(dinfo);
1564 if (cursor->set & FB_CUR_SETPOS) {
1567 dx = cursor->image.dx - info->var.xoffset;
1568 dy = cursor->image.dy - info->var.yoffset;
1570 intelfbhw_cursor_setpos(dinfo, dx, dy);
1573 if (cursor->set & FB_CUR_SETSIZE) {
1574 if (cursor->image.width > 64 || cursor->image.height > 64)
1577 intelfbhw_cursor_reset(dinfo);
1580 if (cursor->set & FB_CUR_SETCMAP) {
1583 if (dinfo->depth != 8) {
1584 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1585 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1587 fg = cursor->image.fg_color;
1588 bg = cursor->image.bg_color;
1591 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1594 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1595 u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
1596 u32 size = s_pitch * cursor->image.height;
1597 u8 *dat = (u8 *) cursor->image.data;
1598 u8 *msk = (u8 *) cursor->mask;
1602 if (cursor->image.depth != 1)
1605 switch (cursor->rop) {
1607 for (i = 0; i < size; i++)
1608 src[i] = dat[i] ^ msk[i];
1612 for (i = 0; i < size; i++)
1613 src[i] = dat[i] & msk[i];
1617 /* save the bitmap to restore it when XFree will
1618 make the cursor dirty */
1619 memcpy(dinfo->cursor_src, src, size);
1621 intelfbhw_cursor_load(dinfo, cursor->image.width,
1622 cursor->image.height, src);
1626 intelfbhw_cursor_show(dinfo);
1632 intelfb_sync(struct fb_info *info)
1634 struct intelfb_info *dinfo = GET_DINFO(info);
1637 DBG_MSG("intelfb_sync\n");
1640 if (dinfo->ring_lockup)
1643 intelfbhw_do_sync(dinfo);