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/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/slab.h>
117 #include <linux/delay.h>
118 #include <linux/fb.h>
119 #include <linux/ioport.h>
120 #include <linux/init.h>
121 #include <linux/pci.h>
122 #include <linux/vmalloc.h>
123 #include <linux/pagemap.h>
124 #include <linux/screen_info.h>
129 #include <asm/mtrr.h>
133 #include "intelfbhw.h"
136 static void __devinit get_initial_mode(struct intelfb_info *dinfo);
137 static void update_dinfo(struct intelfb_info *dinfo,
138 struct fb_var_screeninfo *var);
139 static int intelfb_check_var(struct fb_var_screeninfo *var,
140 struct fb_info *info);
141 static int intelfb_set_par(struct fb_info *info);
142 static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
143 unsigned blue, unsigned transp,
144 struct fb_info *info);
146 static int intelfb_blank(int blank, struct fb_info *info);
147 static int intelfb_pan_display(struct fb_var_screeninfo *var,
148 struct fb_info *info);
150 static void intelfb_fillrect(struct fb_info *info,
151 const struct fb_fillrect *rect);
152 static void intelfb_copyarea(struct fb_info *info,
153 const struct fb_copyarea *region);
154 static void intelfb_imageblit(struct fb_info *info,
155 const struct fb_image *image);
156 static int intelfb_cursor(struct fb_info *info,
157 struct fb_cursor *cursor);
159 static int intelfb_sync(struct fb_info *info);
161 static int intelfb_ioctl(struct fb_info *info,
162 unsigned int cmd, unsigned long arg);
164 static int __devinit intelfb_pci_register(struct pci_dev *pdev,
165 const struct pci_device_id *ent);
166 static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
167 static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
170 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
171 * mobile chipsets from being registered.
173 #if DETECT_VGA_CLASS_ONLY
174 #define INTELFB_CLASS_MASK ~0 << 8
176 #define INTELFB_CLASS_MASK 0
179 static struct pci_device_id intelfb_pci_table[] __devinitdata = {
180 { 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 },
181 { 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 },
182 { 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 },
183 { 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 },
184 { 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 },
185 { 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 },
186 { 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 },
187 { 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 },
192 static int num_registered = 0;
195 static struct fb_ops intel_fb_ops = {
196 .owner = THIS_MODULE,
197 .fb_check_var = intelfb_check_var,
198 .fb_set_par = intelfb_set_par,
199 .fb_setcolreg = intelfb_setcolreg,
200 .fb_blank = intelfb_blank,
201 .fb_pan_display = intelfb_pan_display,
202 .fb_fillrect = intelfb_fillrect,
203 .fb_copyarea = intelfb_copyarea,
204 .fb_imageblit = intelfb_imageblit,
205 .fb_cursor = intelfb_cursor,
206 .fb_sync = intelfb_sync,
207 .fb_ioctl = intelfb_ioctl
210 /* PCI driver module table */
211 static struct pci_driver intelfb_driver = {
213 .id_table = intelfb_pci_table,
214 .probe = intelfb_pci_register,
215 .remove = __devexit_p(intelfb_pci_unregister)
218 /* Module description/parameters */
219 MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
220 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
222 "Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS " chipsets");
223 MODULE_LICENSE("Dual BSD/GPL");
224 MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
226 static int accel = 1;
228 static int hwcursor = 0;
230 static int fixed = 0;
231 static int noinit = 0;
232 static int noregister = 0;
233 static int probeonly = 0;
234 static int idonly = 0;
235 static int bailearly = 0;
236 static int voffset = 48;
237 static char *mode = NULL;
239 module_param(accel, bool, S_IRUGO);
240 MODULE_PARM_DESC(accel, "Enable hardware acceleration");
241 module_param(vram, int, S_IRUGO);
242 MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
243 module_param(voffset, int, S_IRUGO);
244 MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
245 module_param(hwcursor, bool, S_IRUGO);
246 MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
247 module_param(mtrr, bool, S_IRUGO);
248 MODULE_PARM_DESC(mtrr, "Enable MTRR support");
249 module_param(fixed, bool, S_IRUGO);
250 MODULE_PARM_DESC(fixed, "Disable mode switching");
251 module_param(noinit, bool, 0);
252 MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
253 module_param(noregister, bool, 0);
254 MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
255 module_param(probeonly, bool, 0);
256 MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
257 module_param(idonly, bool, 0);
258 MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
259 module_param(bailearly, bool, 0);
260 MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
261 module_param(mode, charp, S_IRUGO);
262 MODULE_PARM_DESC(mode,
263 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
266 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
267 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
268 #define OPT_STRVAL(opt, name) (opt + strlen(name))
270 static __inline__ char *
271 get_opt_string(const char *this_opt, const char *name)
277 p = OPT_STRVAL(this_opt, name);
279 while (p[i] && p[i] != ' ' && p[i] != ',')
281 ret = kmalloc(i + 1, GFP_KERNEL);
289 static __inline__ int
290 get_opt_int(const char *this_opt, const char *name, int *ret)
295 if (!OPT_EQUAL(this_opt, name))
298 *ret = OPT_INTVAL(this_opt, name);
302 static __inline__ int
303 get_opt_bool(const char *this_opt, const char *name, int *ret)
308 if (OPT_EQUAL(this_opt, name)) {
309 if (this_opt[strlen(name)] == '=')
310 *ret = simple_strtoul(this_opt + strlen(name) + 1,
315 if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name))
324 intelfb_setup(char *options)
328 DBG_MSG("intelfb_setup\n");
330 if (!options || !*options) {
331 DBG_MSG("no options\n");
334 DBG_MSG("options: %s\n", options);
337 * These are the built-in options analogous to the module parameters
342 * video=intelfb:[mode][,<param>=<val>] ...
346 * video=intelfb:1024x768-16@75,accel=0
349 while ((this_opt = strsep(&options, ","))) {
352 if (get_opt_bool(this_opt, "accel", &accel))
354 else if (get_opt_int(this_opt, "vram", &vram))
356 else if (get_opt_bool(this_opt, "hwcursor", &hwcursor))
358 else if (get_opt_bool(this_opt, "mtrr", &mtrr))
360 else if (get_opt_bool(this_opt, "fixed", &fixed))
362 else if (get_opt_bool(this_opt, "init", &noinit))
364 else if (OPT_EQUAL(this_opt, "mode="))
365 mode = get_opt_string(this_opt, "mode=");
382 DBG_MSG("intelfb_init\n");
384 INF_MSG("Framebuffer driver for "
385 "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
386 INF_MSG("Version " INTELFB_VERSION "\n");
392 if (fb_get_options("intelfb", &option))
394 intelfb_setup(option);
397 return pci_register_driver(&intelfb_driver);
403 DBG_MSG("intelfb_exit\n");
404 pci_unregister_driver(&intelfb_driver);
407 module_init(intelfb_init);
408 module_exit(intelfb_exit);
410 /***************************************************************
411 * mtrr support functions *
412 ***************************************************************/
415 static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
417 dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical,
418 dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1);
419 if (dinfo->mtrr_reg < 0) {
420 ERR_MSG("unable to set MTRR\n");
425 static inline void unset_mtrr(struct intelfb_info *dinfo)
428 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
429 dinfo->aperture.size);
432 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
434 #define unset_mtrr(x) do { } while (0)
435 #endif /* CONFIG_MTRR */
437 /***************************************************************
438 * driver init / cleanup *
439 ***************************************************************/
442 cleanup(struct intelfb_info *dinfo)
444 DBG_MSG("cleanup\n");
449 fb_dealloc_cmap(&dinfo->info->cmap);
450 kfree(dinfo->info->pixmap.addr);
452 if (dinfo->registered)
453 unregister_framebuffer(dinfo->info);
457 if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) {
458 agp_unbind_memory(dinfo->gtt_fb_mem);
459 agp_free_memory(dinfo->gtt_fb_mem);
461 if (dinfo->gtt_cursor_mem) {
462 agp_unbind_memory(dinfo->gtt_cursor_mem);
463 agp_free_memory(dinfo->gtt_cursor_mem);
465 if (dinfo->gtt_ring_mem) {
466 agp_unbind_memory(dinfo->gtt_ring_mem);
467 agp_free_memory(dinfo->gtt_ring_mem);
470 if (dinfo->mmio_base)
471 iounmap((void __iomem *)dinfo->mmio_base);
472 if (dinfo->aperture.virtual)
473 iounmap((void __iomem *)dinfo->aperture.virtual);
475 if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
476 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
477 if (dinfo->flag & INTELFB_FB_ACQUIRED)
478 release_mem_region(dinfo->aperture.physical,
479 dinfo->aperture.size);
480 framebuffer_release(dinfo->info);
483 #define bailout(dinfo) do { \
484 DBG_MSG("bailout\n"); \
486 INF_MSG("Not going to register framebuffer, exiting...\n"); \
492 intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
494 struct fb_info *info;
495 struct intelfb_info *dinfo;
497 int aperture_size, stolen_size;
498 struct agp_kern_info gtt_info;
501 struct agp_bridge_data *bridge;
502 int aperture_bar = 0;
506 DBG_MSG("intelfb_pci_register\n");
509 if (num_registered != 1) {
510 ERR_MSG("Attempted to register %d devices "
511 "(should be only 1).\n", num_registered);
515 info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
517 ERR_MSG("Could not allocate memory for intelfb_info.\n");
520 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
521 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
528 dinfo->fbops = &intel_fb_ops;
531 /* Reserve pixmap space. */
532 info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL);
533 if (info->pixmap.addr == NULL) {
534 ERR_MSG("Cannot reserve pixmap memory.\n");
537 memset(info->pixmap.addr, 0, 64 * 1024);
539 /* set early this option because it could be changed by tv encoder
541 dinfo->fixed_mode = fixed;
544 if ((err = pci_enable_device(pdev))) {
545 ERR_MSG("Cannot enable device.\n");
550 /* Set base addresses. */
551 if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
552 (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
553 (ent->device == PCI_DEVICE_ID_INTEL_945G) ||
554 (ent->device == PCI_DEVICE_ID_INTEL_945GM)) {
558 dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
559 dinfo->aperture.size = pci_resource_len(pdev, aperture_bar);
560 dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar);
561 DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
562 (unsigned long long)pci_resource_start(pdev, aperture_bar),
563 (unsigned long long)pci_resource_len(pdev, aperture_bar),
564 (unsigned long long)pci_resource_start(pdev, mmio_bar),
565 (unsigned long long)pci_resource_len(pdev, mmio_bar));
567 /* Reserve the fb and MMIO regions */
568 if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size,
569 INTELFB_MODULE_NAME)) {
570 ERR_MSG("Cannot reserve FB region.\n");
575 dinfo->flag |= INTELFB_FB_ACQUIRED;
577 if (!request_mem_region(dinfo->mmio_base_phys,
579 INTELFB_MODULE_NAME)) {
580 ERR_MSG("Cannot reserve MMIO region.\n");
585 dinfo->flag |= INTELFB_MMIO_ACQUIRED;
587 /* Get the chipset info. */
588 dinfo->pci_chipset = pdev->device;
590 if (intelfbhw_get_chipset(pdev, dinfo)) {
595 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
600 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
601 "stolen memory %dkB\n",
602 pdev->bus->number, PCI_SLOT(pdev->devfn),
603 PCI_FUNC(pdev->devfn), dinfo->name,
604 BtoMB(aperture_size), BtoKB(stolen_size));
606 /* Set these from the options. */
607 dinfo->accel = accel;
608 dinfo->hwcursor = hwcursor;
610 if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
611 INF_MSG("Acceleration is not supported for the %s chipset.\n",
616 /* Framebuffer parameters - Use all the stolen memory if >= vram */
617 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
618 dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
619 dinfo->fbmem_gart = 0;
621 dinfo->fb.size = MB(vram);
622 dinfo->fbmem_gart = 1;
625 /* Allocate space for the ring buffer and HW cursor if enabled. */
627 dinfo->ring.size = RINGBUFFER_SIZE;
628 dinfo->ring_tail_mask = dinfo->ring.size - 1;
630 if (dinfo->hwcursor) {
631 dinfo->cursor.size = HW_CURSOR_SIZE;
634 /* Use agpgart to manage the GATT */
635 if (!(bridge = agp_backend_acquire(pdev))) {
636 ERR_MSG("cannot acquire agp\n");
641 /* get the current gatt info */
642 if (agp_copy_info(bridge, >t_info)) {
643 ERR_MSG("cannot get agp info\n");
644 agp_backend_release(bridge);
649 if (MB(voffset) < stolen_size)
650 offset = (stolen_size >> 12);
652 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
654 /* set the mem offsets - set them after the already used pages */
656 dinfo->ring.offset = offset + gtt_info.current_memory;
658 if (dinfo->hwcursor) {
659 dinfo->cursor.offset = offset +
660 + gtt_info.current_memory + (dinfo->ring.size >> 12);
662 if (dinfo->fbmem_gart) {
663 dinfo->fb.offset = offset +
664 + gtt_info.current_memory + (dinfo->ring.size >> 12)
665 + (dinfo->cursor.size >> 12);
668 /* Allocate memories (which aren't stolen) */
669 /* Map the fb and MMIO regions */
670 /* ioremap only up to the end of used aperture */
671 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
672 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
674 if (!dinfo->aperture.virtual) {
675 ERR_MSG("Cannot remap FB region.\n");
681 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
683 if (!dinfo->mmio_base) {
684 ERR_MSG("Cannot remap MMIO region.\n");
690 if (!(dinfo->gtt_ring_mem =
691 agp_allocate_memory(bridge, dinfo->ring.size >> 12,
692 AGP_NORMAL_MEMORY))) {
693 ERR_MSG("cannot allocate ring buffer memory\n");
694 agp_backend_release(bridge);
698 if (agp_bind_memory(dinfo->gtt_ring_mem,
699 dinfo->ring.offset)) {
700 ERR_MSG("cannot bind ring buffer memory\n");
701 agp_backend_release(bridge);
705 dinfo->ring.physical = dinfo->aperture.physical
706 + (dinfo->ring.offset << 12);
707 dinfo->ring.virtual = dinfo->aperture.virtual
708 + (dinfo->ring.offset << 12);
709 dinfo->ring_head = 0;
711 if (dinfo->hwcursor) {
712 agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
714 if (!(dinfo->gtt_cursor_mem =
715 agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
717 ERR_MSG("cannot allocate cursor memory\n");
718 agp_backend_release(bridge);
722 if (agp_bind_memory(dinfo->gtt_cursor_mem,
723 dinfo->cursor.offset)) {
724 ERR_MSG("cannot bind cursor memory\n");
725 agp_backend_release(bridge);
730 dinfo->cursor.physical
731 = dinfo->gtt_cursor_mem->physical;
733 dinfo->cursor.physical = dinfo->aperture.physical
734 + (dinfo->cursor.offset << 12);
735 dinfo->cursor.virtual = dinfo->aperture.virtual
736 + (dinfo->cursor.offset << 12);
738 if (dinfo->fbmem_gart) {
739 if (!(dinfo->gtt_fb_mem =
740 agp_allocate_memory(bridge, dinfo->fb.size >> 12,
741 AGP_NORMAL_MEMORY))) {
742 WRN_MSG("cannot allocate framebuffer memory - use "
744 dinfo->fbmem_gart = 0;
746 if (agp_bind_memory(dinfo->gtt_fb_mem,
748 WRN_MSG("cannot bind framebuffer memory - use "
750 dinfo->fbmem_gart = 0;
754 /* update framebuffer memory parameters */
755 if (!dinfo->fbmem_gart)
756 dinfo->fb.offset = 0; /* starts at offset 0 */
757 dinfo->fb.physical = dinfo->aperture.physical
758 + (dinfo->fb.offset << 12);
759 dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
760 dinfo->fb_start = dinfo->fb.offset << 12;
762 /* release agpgart */
763 agp_backend_release(bridge);
768 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
769 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
771 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
772 dinfo->mmio_base_phys, INTEL_REG_SIZE,
774 DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n",
775 dinfo->ring.physical, dinfo->ring.size,
776 dinfo->ring.virtual);
777 DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
778 dinfo->cursor.physical, dinfo->cursor.size,
779 dinfo->cursor.virtual, dinfo->cursor.offset,
780 dinfo->cursor.physical);
782 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
783 "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
784 DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
790 * Check if the LVDS port or any DVO ports are enabled. If so,
791 * don't allow mode switching
793 dvo = intelfbhw_check_non_crt(dinfo);
795 dinfo->fixed_mode = 1;
796 WRN_MSG("Non-CRT device is enabled ( ");
800 s = intelfbhw_dvo_to_string(1 << i);
807 printk("). Disabling mode switching.\n");
813 if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
814 ERR_MSG("Video mode must be programmed at boot time.\n");
822 /* Initialise dinfo and related data. */
823 /* If an initial mode was programmed at boot time, get its details. */
824 if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB)
825 get_initial_mode(dinfo);
830 if (FIXED_MODE(dinfo)) {
831 /* remap fb address */
832 update_dinfo(dinfo, &dinfo->initial_var);
839 if (intelfb_set_fbinfo(dinfo)) {
850 pci_set_drvdata(pdev, dinfo);
852 /* Save the initial register state. */
853 i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
854 bailearly > 6 ? bailearly - 6 : 0);
856 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
860 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
865 /* Cursor initialisation */
866 if (dinfo->hwcursor) {
867 intelfbhw_cursor_init(dinfo);
868 intelfbhw_cursor_reset(dinfo);
874 /* 2d acceleration init */
876 intelfbhw_2d_start(dinfo);
884 if (register_framebuffer(dinfo->info) < 0) {
885 ERR_MSG("Cannot register framebuffer.\n");
890 dinfo->registered = 1;
895 fb_dealloc_cmap(&info->cmap);
897 framebuffer_release(info);
901 static void __devexit
902 intelfb_pci_unregister(struct pci_dev *pdev)
904 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
906 DBG_MSG("intelfb_pci_unregister\n");
913 pci_set_drvdata(pdev, NULL);
916 /***************************************************************
918 ***************************************************************/
921 intelfb_var_to_depth(const struct fb_var_screeninfo *var)
923 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
924 var->bits_per_pixel, var->green.length);
926 switch (var->bits_per_pixel) {
928 return (var->green.length == 6) ? 16 : 15;
932 return var->bits_per_pixel;
937 static __inline__ int
938 var_to_refresh(const struct fb_var_screeninfo *var)
940 int xtot = var->xres + var->left_margin + var->right_margin +
942 int ytot = var->yres + var->upper_margin + var->lower_margin +
945 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
948 /***************************************************************
949 * Various intialisation functions *
950 ***************************************************************/
952 static void __devinit
953 get_initial_mode(struct intelfb_info *dinfo)
955 struct fb_var_screeninfo *var;
958 DBG_MSG("get_initial_mode\n");
960 dinfo->initial_vga = 1;
961 dinfo->initial_fb_base = screen_info.lfb_base;
962 dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
963 dinfo->initial_pitch = screen_info.lfb_linelength;
965 var = &dinfo->initial_var;
966 memset(var, 0, sizeof(*var));
967 var->xres = screen_info.lfb_width;
968 var->yres = screen_info.lfb_height;
969 var->bits_per_pixel = screen_info.lfb_depth;
970 switch (screen_info.lfb_depth) {
972 var->bits_per_pixel = 16;
975 var->bits_per_pixel = 32;
979 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
980 dinfo->initial_fb_base, dinfo->initial_video_ram,
981 BtoKB(dinfo->initial_video_ram));
983 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
984 var->xres, var->yres, var->bits_per_pixel,
985 dinfo->initial_pitch);
987 /* Dummy timing values (assume 60Hz) */
988 var->left_margin = (var->xres / 8) & 0xf8;
989 var->right_margin = 32;
990 var->upper_margin = 16;
991 var->lower_margin = 4;
992 var->hsync_len = (var->xres / 8) & 0xf8;
995 xtot = var->xres + var->left_margin +
996 var->right_margin + var->hsync_len;
997 ytot = var->yres + var->upper_margin +
998 var->lower_margin + var->vsync_len;
999 var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
1004 if (var->bits_per_pixel > 8) {
1005 var->red.offset = screen_info.red_pos;
1006 var->red.length = screen_info.red_size;
1007 var->green.offset = screen_info.green_pos;
1008 var->green.length = screen_info.green_size;
1009 var->blue.offset = screen_info.blue_pos;
1010 var->blue.length = screen_info.blue_size;
1011 var->transp.offset = screen_info.rsvd_pos;
1012 var->transp.length = screen_info.rsvd_size;
1014 var->red.length = 8;
1015 var->green.length = 8;
1016 var->blue.length = 8;
1020 static int __devinit
1021 intelfb_init_var(struct intelfb_info *dinfo)
1023 struct fb_var_screeninfo *var;
1026 DBG_MSG("intelfb_init_var\n");
1028 var = &dinfo->info->var;
1029 if (FIXED_MODE(dinfo)) {
1030 memcpy(var, &dinfo->initial_var,
1031 sizeof(struct fb_var_screeninfo));
1034 const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev);
1038 edid_d = kmalloc(EDID_LENGTH, GFP_KERNEL);
1041 memcpy(edid_d, edid_s, EDID_LENGTH);
1042 fb_edid_to_monspecs(edid_d,
1043 &dinfo->info->monspecs);
1049 printk("intelfb: Looking for mode in private "
1051 msrc = fb_find_mode(var, dinfo->info, mode,
1052 dinfo->info->monspecs.modedb,
1053 dinfo->info->monspecs.modedb_len,
1056 if (msrc && msrc > 1) {
1057 printk("intelfb: No mode in private database, "
1058 "intelfb: looking for mode in global "
1060 msrc = fb_find_mode(var, dinfo->info, mode,
1070 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
1076 ERR_MSG("Cannot find a suitable video mode.\n");
1080 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
1081 var->bits_per_pixel, var_to_refresh(var));
1083 DBG_MSG("Initial video mode is from %d.\n", msrc);
1085 #if ALLOCATE_FOR_PANNING
1086 /* Allow use of half of the video ram for panning */
1087 var->xres_virtual = var->xres;
1089 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1090 if (var->yres_virtual < var->yres)
1091 var->yres_virtual = var->yres;
1093 var->yres_virtual = var->yres;
1097 var->accel_flags |= FB_ACCELF_TEXT;
1099 var->accel_flags &= ~FB_ACCELF_TEXT;
1104 static int __devinit
1105 intelfb_set_fbinfo(struct intelfb_info *dinfo)
1107 struct fb_info *info = dinfo->info;
1109 DBG_MSG("intelfb_set_fbinfo\n");
1111 info->flags = FBINFO_FLAG_DEFAULT;
1112 info->fbops = &intel_fb_ops;
1113 info->pseudo_palette = dinfo->pseudo_palette;
1115 info->pixmap.size = 64*1024;
1116 info->pixmap.buf_align = 8;
1117 info->pixmap.access_align = 32;
1118 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1120 if (intelfb_init_var(dinfo))
1123 info->pixmap.scan_align = 1;
1124 strcpy(info->fix.id, dinfo->name);
1125 info->fix.smem_start = dinfo->fb.physical;
1126 info->fix.smem_len = dinfo->fb.size;
1127 info->fix.type = FB_TYPE_PACKED_PIXELS;
1128 info->fix.type_aux = 0;
1129 info->fix.xpanstep = 8;
1130 info->fix.ypanstep = 1;
1131 info->fix.ywrapstep = 0;
1132 info->fix.mmio_start = dinfo->mmio_base_phys;
1133 info->fix.mmio_len = INTEL_REG_SIZE;
1134 info->fix.accel = FB_ACCEL_I830;
1135 update_dinfo(dinfo, &info->var);
1140 /* Update dinfo to match the active video mode. */
1142 update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
1144 DBG_MSG("update_dinfo\n");
1146 dinfo->bpp = var->bits_per_pixel;
1147 dinfo->depth = intelfb_var_to_depth(var);
1148 dinfo->xres = var->xres;
1149 dinfo->yres = var->xres;
1150 dinfo->pixclock = var->pixclock;
1152 dinfo->info->fix.visual = dinfo->visual;
1153 dinfo->info->fix.line_length = dinfo->pitch;
1155 switch (dinfo->bpp) {
1157 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1158 dinfo->pitch = var->xres_virtual;
1161 dinfo->visual = FB_VISUAL_TRUECOLOR;
1162 dinfo->pitch = var->xres_virtual * 2;
1165 dinfo->visual = FB_VISUAL_TRUECOLOR;
1166 dinfo->pitch = var->xres_virtual * 4;
1170 /* Make sure the line length is a aligned correctly. */
1172 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX);
1174 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
1176 if (FIXED_MODE(dinfo))
1177 dinfo->pitch = dinfo->initial_pitch;
1179 dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
1180 dinfo->info->fix.line_length = dinfo->pitch;
1181 dinfo->info->fix.visual = dinfo->visual;
1184 /* fbops functions */
1186 /***************************************************************
1188 ***************************************************************/
1191 intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1194 struct fb_var_screeninfo v;
1195 struct intelfb_info *dinfo;
1196 static int first = 1;
1198 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1199 static const int pitches[] = {
1207 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1209 dinfo = GET_DINFO(info);
1211 /* update the pitch */
1212 if (intelfbhw_validate_mode(dinfo, var) != 0)
1217 for (i = 0; pitches[i] != 0; i++) {
1218 if (pitches[i] >= v.xres_virtual) {
1219 v.xres_virtual = pitches[i];
1224 /* Check for a supported bpp. */
1225 if (v.bits_per_pixel <= 8) {
1226 v.bits_per_pixel = 8;
1227 } else if (v.bits_per_pixel <= 16) {
1228 if (v.bits_per_pixel == 16)
1230 v.bits_per_pixel = 16;
1231 } else if (v.bits_per_pixel <= 32) {
1232 v.bits_per_pixel = 32;
1236 change_var = ((info->var.xres != var->xres) ||
1237 (info->var.yres != var->yres) ||
1238 (info->var.xres_virtual != var->xres_virtual) ||
1239 (info->var.yres_virtual != var->yres_virtual) ||
1240 (info->var.bits_per_pixel != var->bits_per_pixel) ||
1241 memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
1242 memcmp(&info->var.green, &var->green,
1243 sizeof(var->green)) ||
1244 memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
1246 if (FIXED_MODE(dinfo) &&
1248 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1249 var->yres_virtual < dinfo->initial_var.yres ||
1250 var->xoffset || var->nonstd)) {
1252 ERR_MSG("Changing the video mode is not supported.\n");
1258 switch (intelfb_var_to_depth(&v)) {
1260 v.red.offset = v.green.offset = v.blue.offset = 0;
1261 v.red.length = v.green.length = v.blue.length = 8;
1262 v.transp.offset = v.transp.length = 0;
1268 v.red.length = v.green.length = v.blue.length = 5;
1269 v.transp.offset = v.transp.length = 0;
1278 v.transp.offset = v.transp.length = 0;
1284 v.red.length = v.green.length = v.blue.length = 8;
1285 v.transp.offset = v.transp.length = 0;
1291 v.red.length = v.green.length = v.blue.length = 8;
1292 v.transp.offset = 24;
1293 v.transp.length = 8;
1302 if (v.xoffset > v.xres_virtual - v.xres)
1303 v.xoffset = v.xres_virtual - v.xres;
1304 if (v.yoffset > v.yres_virtual - v.yres)
1305 v.yoffset = v.yres_virtual - v.yres;
1307 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1308 v.transp.msb_right = 0;
1316 intelfb_set_par(struct fb_info *info)
1318 struct intelfb_hwstate *hw;
1319 struct intelfb_info *dinfo = GET_DINFO(info);
1321 if (FIXED_MODE(dinfo)) {
1322 ERR_MSG("Changing the video mode is not supported.\n");
1326 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1330 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1331 info->var.yres, info->var.bits_per_pixel);
1333 intelfb_blank(FB_BLANK_POWERDOWN, info);
1335 if (ACCEL(dinfo, info))
1336 intelfbhw_2d_stop(dinfo);
1338 memcpy(hw, &dinfo->save_state, sizeof(*hw));
1339 if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
1341 if (intelfbhw_program_mode(dinfo, hw, 0))
1345 intelfbhw_read_hw_state(dinfo, hw, 0);
1346 intelfbhw_print_hw_state(dinfo, hw);
1349 update_dinfo(dinfo, &info->var);
1351 if (ACCEL(dinfo, info))
1352 intelfbhw_2d_start(dinfo);
1354 intelfb_pan_display(&info->var, info);
1356 intelfb_blank(FB_BLANK_UNBLANK, info);
1358 if (ACCEL(dinfo, info)) {
1359 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1360 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1361 FBINFO_HWACCEL_IMAGEBLIT;
1363 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1373 intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1374 unsigned blue, unsigned transp, struct fb_info *info)
1376 struct intelfb_info *dinfo = GET_DINFO(info);
1379 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1385 if (dinfo->depth == 8) {
1390 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1395 switch (dinfo->depth) {
1397 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1398 ((green & 0xf800) >> 6) |
1399 ((blue & 0xf800) >> 11);
1402 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1403 ((green & 0xfc00) >> 5) |
1404 ((blue & 0xf800) >> 11);
1407 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1409 ((blue & 0xff00) >> 8);
1418 intelfb_blank(int blank, struct fb_info *info)
1420 intelfbhw_do_blank(blank, info);
1425 intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1427 intelfbhw_pan_display(var, info);
1431 /* When/if we have our own ioctls. */
1433 intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
1441 intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect)
1443 struct intelfb_info *dinfo = GET_DINFO(info);
1447 DBG_MSG("intelfb_fillrect\n");
1450 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1451 return cfb_fillrect(info, rect);
1453 if (rect->rop == ROP_COPY)
1454 rop = PAT_ROP_GXCOPY;
1456 rop = PAT_ROP_GXXOR;
1458 if (dinfo->depth != 8)
1459 color = dinfo->pseudo_palette[rect->color];
1461 color = rect->color;
1463 intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
1464 rect->width, rect->height, color,
1465 dinfo->pitch, info->var.bits_per_pixel,
1470 intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1472 struct intelfb_info *dinfo = GET_DINFO(info);
1475 DBG_MSG("intelfb_copyarea\n");
1478 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1479 return cfb_copyarea(info, region);
1481 intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
1482 region->dy, region->width, region->height,
1483 dinfo->pitch, info->var.bits_per_pixel);
1487 intelfb_imageblit(struct fb_info *info, const struct fb_image *image)
1489 struct intelfb_info *dinfo = GET_DINFO(info);
1490 u32 fgcolor, bgcolor;
1493 DBG_MSG("intelfb_imageblit\n");
1496 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1497 || image->depth != 1)
1498 return cfb_imageblit(info, image);
1500 if (dinfo->depth != 8) {
1501 fgcolor = dinfo->pseudo_palette[image->fg_color];
1502 bgcolor = dinfo->pseudo_palette[image->bg_color];
1504 fgcolor = image->fg_color;
1505 bgcolor = image->bg_color;
1508 if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
1509 image->height, image->data,
1510 image->dx, image->dy,
1511 dinfo->pitch, info->var.bits_per_pixel))
1512 return cfb_imageblit(info, image);
1516 intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1518 struct intelfb_info *dinfo = GET_DINFO(info);
1521 DBG_MSG("intelfb_cursor\n");
1524 if (!dinfo->hwcursor)
1527 intelfbhw_cursor_hide(dinfo);
1529 /* If XFree killed the cursor - restore it */
1530 physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical :
1531 (dinfo->cursor.offset << 12);
1533 if (INREG(CURSOR_A_BASEADDR) != physical) {
1536 DBG_MSG("the cursor was killed - restore it !!\n");
1537 DBG_MSG("size %d, %d pos %d, %d\n",
1538 cursor->image.width, cursor->image.height,
1539 cursor->image.dx, cursor->image.dy);
1541 intelfbhw_cursor_init(dinfo);
1542 intelfbhw_cursor_reset(dinfo);
1543 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1546 if (dinfo->depth != 8) {
1547 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1548 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1550 fg = cursor->image.fg_color;
1551 bg = cursor->image.bg_color;
1553 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1554 intelfbhw_cursor_load(dinfo, cursor->image.width,
1555 cursor->image.height,
1559 intelfbhw_cursor_show(dinfo);
1563 if (cursor->set & FB_CUR_SETPOS) {
1566 dx = cursor->image.dx - info->var.xoffset;
1567 dy = cursor->image.dy - info->var.yoffset;
1569 intelfbhw_cursor_setpos(dinfo, dx, dy);
1572 if (cursor->set & FB_CUR_SETSIZE) {
1573 if (cursor->image.width > 64 || cursor->image.height > 64)
1576 intelfbhw_cursor_reset(dinfo);
1579 if (cursor->set & FB_CUR_SETCMAP) {
1582 if (dinfo->depth != 8) {
1583 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1584 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1586 fg = cursor->image.fg_color;
1587 bg = cursor->image.bg_color;
1590 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1593 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1594 u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
1595 u32 size = s_pitch * cursor->image.height;
1596 u8 *dat = (u8 *) cursor->image.data;
1597 u8 *msk = (u8 *) cursor->mask;
1601 if (cursor->image.depth != 1)
1604 switch (cursor->rop) {
1606 for (i = 0; i < size; i++)
1607 src[i] = dat[i] ^ msk[i];
1611 for (i = 0; i < size; i++)
1612 src[i] = dat[i] & msk[i];
1616 /* save the bitmap to restore it when XFree will
1617 make the cursor dirty */
1618 memcpy(dinfo->cursor_src, src, size);
1620 intelfbhw_cursor_load(dinfo, cursor->image.width,
1621 cursor->image.height, src);
1625 intelfbhw_cursor_show(dinfo);
1631 intelfb_sync(struct fb_info *info)
1633 struct intelfb_info *dinfo = GET_DINFO(info);
1636 DBG_MSG("intelfb_sync\n");
1639 if (dinfo->ring_lockup)
1642 intelfbhw_do_sync(dinfo);