4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM
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/ioport.h>
121 #include <linux/init.h>
122 #include <linux/pci.h>
123 #include <linux/vmalloc.h>
124 #include <linux/pagemap.h>
129 #include <asm/mtrr.h>
133 #include "intelfbhw.h"
135 static void __devinit get_initial_mode(struct intelfb_info *dinfo);
136 static void update_dinfo(struct intelfb_info *dinfo,
137 struct fb_var_screeninfo *var);
138 static int intelfb_get_fix(struct fb_fix_screeninfo *fix,
139 struct fb_info *info);
141 static int intelfb_check_var(struct fb_var_screeninfo *var,
142 struct fb_info *info);
143 static int intelfb_set_par(struct fb_info *info);
144 static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
145 unsigned blue, unsigned transp,
146 struct fb_info *info);
148 static int intelfb_blank(int blank, struct fb_info *info);
149 static int intelfb_pan_display(struct fb_var_screeninfo *var,
150 struct fb_info *info);
152 static void intelfb_fillrect(struct fb_info *info,
153 const struct fb_fillrect *rect);
154 static void intelfb_copyarea(struct fb_info *info,
155 const struct fb_copyarea *region);
156 static void intelfb_imageblit(struct fb_info *info,
157 const struct fb_image *image);
158 static int intelfb_cursor(struct fb_info *info,
159 struct fb_cursor *cursor);
161 static int intelfb_sync(struct fb_info *info);
163 static int intelfb_ioctl(struct inode *inode, struct file *file,
164 unsigned int cmd, unsigned long arg,
165 struct fb_info *info);
167 static int __devinit intelfb_pci_register(struct pci_dev *pdev,
168 const struct pci_device_id *ent);
169 static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
170 static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
173 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
174 * mobile chipsets from being registered.
176 #if DETECT_VGA_CLASS_ONLY
177 #define INTELFB_CLASS_MASK ~0 << 8
179 #define INTELFB_CLASS_MASK 0
182 static struct pci_device_id intelfb_pci_table[] __devinitdata = {
183 { 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 },
184 { 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 },
185 { 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 },
186 { 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 },
187 { 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 },
188 { 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 },
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), 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->mmio_base_phys)
477 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
478 if (dinfo->aperture.physical)
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)) {
556 /* Disable HW cursor on 915G/M (not implemented yet) */
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");
575 if (!request_mem_region(dinfo->mmio_base_phys,
577 INTELFB_MODULE_NAME)) {
578 ERR_MSG("Cannot reserve MMIO region.\n");
583 /* Get the chipset info. */
584 dinfo->pci_chipset = pdev->device;
586 if (intelfbhw_get_chipset(pdev, &dinfo->name, &dinfo->chipset,
592 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
597 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
598 "stolen memory %dkB\n",
599 pdev->bus->number, PCI_SLOT(pdev->devfn),
600 PCI_FUNC(pdev->devfn), dinfo->name,
601 BtoMB(aperture_size), BtoKB(stolen_size));
603 /* Set these from the options. */
604 dinfo->accel = accel;
605 dinfo->hwcursor = hwcursor;
607 if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
608 INF_MSG("Acceleration is not supported for the %s chipset.\n",
613 /* Framebuffer parameters - Use all the stolen memory if >= vram */
614 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
615 dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
616 dinfo->fbmem_gart = 0;
618 dinfo->fb.size = MB(vram);
619 dinfo->fbmem_gart = 1;
622 /* Allocate space for the ring buffer and HW cursor if enabled. */
624 dinfo->ring.size = RINGBUFFER_SIZE;
625 dinfo->ring_tail_mask = dinfo->ring.size - 1;
627 if (dinfo->hwcursor) {
628 dinfo->cursor.size = HW_CURSOR_SIZE;
631 /* Use agpgart to manage the GATT */
632 if (!(bridge = agp_backend_acquire(pdev))) {
633 ERR_MSG("cannot acquire agp\n");
638 /* get the current gatt info */
639 if (agp_copy_info(bridge, >t_info)) {
640 ERR_MSG("cannot get agp info\n");
641 agp_backend_release(bridge);
646 if (MB(voffset) < stolen_size)
647 offset = (stolen_size >> 12);
649 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
651 /* set the mem offsets - set them after the already used pages */
653 dinfo->ring.offset = offset + gtt_info.current_memory;
655 if (dinfo->hwcursor) {
656 dinfo->cursor.offset = offset +
657 + gtt_info.current_memory + (dinfo->ring.size >> 12);
659 if (dinfo->fbmem_gart) {
660 dinfo->fb.offset = offset +
661 + gtt_info.current_memory + (dinfo->ring.size >> 12)
662 + (dinfo->cursor.size >> 12);
665 /* Allocate memories (which aren't stolen) */
666 /* Map the fb and MMIO regions */
667 /* ioremap only up to the end of used aperture */
668 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
669 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
671 if (!dinfo->aperture.virtual) {
672 ERR_MSG("Cannot remap FB region.\n");
678 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
680 if (!dinfo->mmio_base) {
681 ERR_MSG("Cannot remap MMIO region.\n");
687 if (!(dinfo->gtt_ring_mem =
688 agp_allocate_memory(bridge, dinfo->ring.size >> 12,
689 AGP_NORMAL_MEMORY))) {
690 ERR_MSG("cannot allocate ring buffer memory\n");
691 agp_backend_release(bridge);
695 if (agp_bind_memory(dinfo->gtt_ring_mem,
696 dinfo->ring.offset)) {
697 ERR_MSG("cannot bind ring buffer memory\n");
698 agp_backend_release(bridge);
702 dinfo->ring.physical = dinfo->aperture.physical
703 + (dinfo->ring.offset << 12);
704 dinfo->ring.virtual = dinfo->aperture.virtual
705 + (dinfo->ring.offset << 12);
706 dinfo->ring_head = dinfo->ring.virtual;
708 if (dinfo->hwcursor) {
709 agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
711 if (!(dinfo->gtt_cursor_mem =
712 agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
714 ERR_MSG("cannot allocate cursor memory\n");
715 agp_backend_release(bridge);
719 if (agp_bind_memory(dinfo->gtt_cursor_mem,
720 dinfo->cursor.offset)) {
721 ERR_MSG("cannot bind cursor memory\n");
722 agp_backend_release(bridge);
727 dinfo->cursor.physical
728 = dinfo->gtt_cursor_mem->physical;
730 dinfo->cursor.physical = dinfo->aperture.physical
731 + (dinfo->cursor.offset << 12);
732 dinfo->cursor.virtual = dinfo->aperture.virtual
733 + (dinfo->cursor.offset << 12);
735 if (dinfo->fbmem_gart) {
736 if (!(dinfo->gtt_fb_mem =
737 agp_allocate_memory(bridge, dinfo->fb.size >> 12,
738 AGP_NORMAL_MEMORY))) {
739 WRN_MSG("cannot allocate framebuffer memory - use "
741 dinfo->fbmem_gart = 0;
743 if (agp_bind_memory(dinfo->gtt_fb_mem,
745 WRN_MSG("cannot bind framebuffer memory - use "
747 dinfo->fbmem_gart = 0;
751 /* update framebuffer memory parameters */
752 if (!dinfo->fbmem_gart)
753 dinfo->fb.offset = 0; /* starts at offset 0 */
754 dinfo->fb.physical = dinfo->aperture.physical
755 + (dinfo->fb.offset << 12);
756 dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
757 dinfo->fb_start = dinfo->fb.offset << 12;
759 /* release agpgart */
760 agp_backend_release(bridge);
765 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%x)\n",
766 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
767 (u32 __iomem ) dinfo->fb.virtual);
768 DBG_MSG("MMIO: 0x%x/0x%x (0x%x)\n",
769 dinfo->mmio_base_phys, INTEL_REG_SIZE,
770 (u32 __iomem) dinfo->mmio_base);
771 DBG_MSG("ring buffer: 0x%x/0x%x (0x%x)\n",
772 dinfo->ring.physical, dinfo->ring.size,
773 (u32 __iomem ) dinfo->ring.virtual);
774 DBG_MSG("HW cursor: 0x%x/0x%x (0x%x) (offset 0x%x) (phys 0x%x)\n",
775 dinfo->cursor.physical, dinfo->cursor.size,
776 (u32 __iomem ) dinfo->cursor.virtual, dinfo->cursor.offset,
777 dinfo->cursor.physical);
779 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
780 "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
781 DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
787 * Check if the LVDS port or any DVO ports are enabled. If so,
788 * don't allow mode switching
790 dvo = intelfbhw_check_non_crt(dinfo);
792 dinfo->fixed_mode = 1;
793 WRN_MSG("Non-CRT device is enabled ( ");
797 s = intelfbhw_dvo_to_string(1 << i);
804 printk("). Disabling mode switching.\n");
810 if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
811 ERR_MSG("Video mode must be programmed at boot time.\n");
819 /* Initialise dinfo and related data. */
820 /* If an initial mode was programmed at boot time, get its details. */
821 if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB)
822 get_initial_mode(dinfo);
827 if (FIXED_MODE(dinfo)) {
828 /* remap fb address */
829 update_dinfo(dinfo, &dinfo->initial_var);
836 if (intelfb_set_fbinfo(dinfo)) {
847 pci_set_drvdata(pdev, dinfo);
849 /* Save the initial register state. */
850 i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
851 bailearly > 6 ? bailearly - 6 : 0);
853 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
857 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
862 /* Cursor initialisation */
863 if (dinfo->hwcursor) {
864 intelfbhw_cursor_init(dinfo);
865 intelfbhw_cursor_reset(dinfo);
871 /* 2d acceleration init */
873 intelfbhw_2d_start(dinfo);
881 if (register_framebuffer(dinfo->info) < 0) {
882 ERR_MSG("Cannot register framebuffer.\n");
887 dinfo->registered = 1;
892 fb_dealloc_cmap(&info->cmap);
894 framebuffer_release(info);
898 static void __devexit
899 intelfb_pci_unregister(struct pci_dev *pdev)
901 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
903 DBG_MSG("intelfb_pci_unregister\n");
910 pci_set_drvdata(pdev, NULL);
913 /***************************************************************
915 ***************************************************************/
918 intelfb_var_to_depth(const struct fb_var_screeninfo *var)
920 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
921 var->bits_per_pixel, var->green.length);
923 switch (var->bits_per_pixel) {
925 return (var->green.length == 6) ? 16 : 15;
929 return var->bits_per_pixel;
934 static __inline__ int
935 var_to_refresh(const struct fb_var_screeninfo *var)
937 int xtot = var->xres + var->left_margin + var->right_margin +
939 int ytot = var->yres + var->upper_margin + var->lower_margin +
942 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
945 /***************************************************************
946 * Various intialisation functions *
947 ***************************************************************/
949 static void __devinit
950 get_initial_mode(struct intelfb_info *dinfo)
952 struct fb_var_screeninfo *var;
955 DBG_MSG("get_initial_mode\n");
957 dinfo->initial_vga = 1;
958 dinfo->initial_fb_base = screen_info.lfb_base;
959 dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
960 dinfo->initial_pitch = screen_info.lfb_linelength;
962 var = &dinfo->initial_var;
963 memset(var, 0, sizeof(*var));
964 var->xres = screen_info.lfb_width;
965 var->yres = screen_info.lfb_height;
966 var->bits_per_pixel = screen_info.lfb_depth;
967 switch (screen_info.lfb_depth) {
969 var->bits_per_pixel = 16;
972 var->bits_per_pixel = 32;
976 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
977 dinfo->initial_fb_base, dinfo->initial_video_ram,
978 BtoKB(dinfo->initial_video_ram));
980 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
981 var->xres, var->yres, var->bits_per_pixel,
982 dinfo->initial_pitch);
984 /* Dummy timing values (assume 60Hz) */
985 var->left_margin = (var->xres / 8) & 0xf8;
986 var->right_margin = 32;
987 var->upper_margin = 16;
988 var->lower_margin = 4;
989 var->hsync_len = (var->xres / 8) & 0xf8;
992 xtot = var->xres + var->left_margin +
993 var->right_margin + var->hsync_len;
994 ytot = var->yres + var->upper_margin +
995 var->lower_margin + var->vsync_len;
996 var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
1001 if (var->bits_per_pixel > 8) {
1002 var->red.offset = screen_info.red_pos;
1003 var->red.length = screen_info.red_size;
1004 var->green.offset = screen_info.green_pos;
1005 var->green.length = screen_info.green_size;
1006 var->blue.offset = screen_info.blue_pos;
1007 var->blue.length = screen_info.blue_size;
1008 var->transp.offset = screen_info.rsvd_pos;
1009 var->transp.length = screen_info.rsvd_size;
1011 var->red.length = 8;
1012 var->green.length = 8;
1013 var->blue.length = 8;
1017 static int __devinit
1018 intelfb_init_var(struct intelfb_info *dinfo)
1020 struct fb_var_screeninfo *var;
1023 DBG_MSG("intelfb_init_var\n");
1025 var = &dinfo->info->var;
1026 if (FIXED_MODE(dinfo)) {
1027 memcpy(var, &dinfo->initial_var,
1028 sizeof(struct fb_var_screeninfo));
1032 msrc = fb_find_mode(var, dinfo->info, mode,
1033 vesa_modes, VESA_MODEDB_SIZE,
1039 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
1040 vesa_modes, VESA_MODEDB_SIZE,
1046 ERR_MSG("Cannot find a suitable video mode.\n");
1050 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
1051 var->bits_per_pixel, var_to_refresh(var));
1053 DBG_MSG("Initial video mode is from %d.\n", msrc);
1055 #if ALLOCATE_FOR_PANNING
1056 /* Allow use of half of the video ram for panning */
1057 var->xres_virtual = var->xres;
1059 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1060 if (var->yres_virtual < var->yres)
1061 var->yres_virtual = var->yres;
1063 var->yres_virtual = var->yres;
1067 var->accel_flags |= FB_ACCELF_TEXT;
1069 var->accel_flags &= ~FB_ACCELF_TEXT;
1074 static int __devinit
1075 intelfb_set_fbinfo(struct intelfb_info *dinfo)
1077 struct fb_info *info = dinfo->info;
1079 DBG_MSG("intelfb_set_fbinfo\n");
1081 info->flags = FBINFO_FLAG_DEFAULT;
1082 info->fbops = &intel_fb_ops;
1083 info->pseudo_palette = dinfo->pseudo_palette;
1085 info->pixmap.size = 64*1024;
1086 info->pixmap.buf_align = 8;
1087 info->pixmap.access_align = 32;
1088 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1090 if (intelfb_init_var(dinfo))
1093 info->pixmap.scan_align = 1;
1095 update_dinfo(dinfo, &info->var);
1100 /* Update dinfo to match the active video mode. */
1102 update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var)
1104 DBG_MSG("update_dinfo\n");
1106 dinfo->bpp = var->bits_per_pixel;
1107 dinfo->depth = intelfb_var_to_depth(var);
1108 dinfo->xres = var->xres;
1109 dinfo->yres = var->xres;
1110 dinfo->pixclock = var->pixclock;
1112 intelfb_get_fix(&dinfo->info->fix, dinfo->info);
1114 switch (dinfo->bpp) {
1116 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1117 dinfo->pitch = var->xres_virtual;
1120 dinfo->visual = FB_VISUAL_TRUECOLOR;
1121 dinfo->pitch = var->xres_virtual * 2;
1124 dinfo->visual = FB_VISUAL_TRUECOLOR;
1125 dinfo->pitch = var->xres_virtual * 4;
1129 /* Make sure the line length is a aligned correctly. */
1130 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
1132 if (FIXED_MODE(dinfo))
1133 dinfo->pitch = dinfo->initial_pitch;
1135 dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
1136 dinfo->info->fix.line_length = dinfo->pitch;
1137 dinfo->info->fix.visual = dinfo->visual;
1140 /* fbops functions */
1143 intelfb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
1145 struct intelfb_info *dinfo = GET_DINFO(info);
1147 DBG_MSG("intelfb_get_fix\n");
1149 memset(fix, 0, sizeof(*fix));
1150 strcpy(fix->id, dinfo->name);
1151 fix->smem_start = dinfo->fb.physical;
1152 fix->smem_len = dinfo->fb.size;
1153 fix->type = FB_TYPE_PACKED_PIXELS;
1155 fix->visual = dinfo->visual;
1159 fix->line_length = dinfo->pitch;
1160 fix->mmio_start = dinfo->mmio_base_phys;
1161 fix->mmio_len = INTEL_REG_SIZE;
1162 fix->accel = FB_ACCEL_I830;
1166 /***************************************************************
1168 ***************************************************************/
1171 intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1174 struct fb_var_screeninfo v;
1175 struct intelfb_info *dinfo;
1176 static int first = 1;
1178 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1180 dinfo = GET_DINFO(info);
1182 if (intelfbhw_validate_mode(dinfo, var) != 0)
1187 /* Check for a supported bpp. */
1188 if (v.bits_per_pixel <= 8) {
1189 v.bits_per_pixel = 8;
1190 } else if (v.bits_per_pixel <= 16) {
1191 if (v.bits_per_pixel == 16)
1193 v.bits_per_pixel = 16;
1194 } else if (v.bits_per_pixel <= 32) {
1195 v.bits_per_pixel = 32;
1199 change_var = ((info->var.xres != var->xres) ||
1200 (info->var.yres != var->yres) ||
1201 (info->var.xres_virtual != var->xres_virtual) ||
1202 (info->var.yres_virtual != var->yres_virtual) ||
1203 (info->var.bits_per_pixel != var->bits_per_pixel) ||
1204 memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
1205 memcmp(&info->var.green, &var->green,
1206 sizeof(var->green)) ||
1207 memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
1209 if (FIXED_MODE(dinfo) &&
1211 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1212 var->yres_virtual < dinfo->initial_var.yres ||
1213 var->xoffset || var->nonstd)) {
1215 ERR_MSG("Changing the video mode is not supported.\n");
1221 switch (intelfb_var_to_depth(&v)) {
1223 v.red.offset = v.green.offset = v.blue.offset = 0;
1224 v.red.length = v.green.length = v.blue.length = 8;
1225 v.transp.offset = v.transp.length = 0;
1231 v.red.length = v.green.length = v.blue.length = 5;
1232 v.transp.offset = v.transp.length = 0;
1241 v.transp.offset = v.transp.length = 0;
1247 v.red.length = v.green.length = v.blue.length = 8;
1248 v.transp.offset = v.transp.length = 0;
1254 v.red.length = v.green.length = v.blue.length = 8;
1255 v.transp.offset = 24;
1256 v.transp.length = 8;
1265 if (v.xoffset > v.xres_virtual - v.xres)
1266 v.xoffset = v.xres_virtual - v.xres;
1267 if (v.yoffset > v.yres_virtual - v.yres)
1268 v.yoffset = v.yres_virtual - v.yres;
1270 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1271 v.transp.msb_right = 0;
1279 intelfb_set_par(struct fb_info *info)
1281 struct intelfb_hwstate *hw;
1282 struct intelfb_info *dinfo = GET_DINFO(info);
1284 if (FIXED_MODE(dinfo)) {
1285 ERR_MSG("Changing the video mode is not supported.\n");
1289 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1293 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1294 info->var.yres, info->var.bits_per_pixel);
1296 intelfb_blank(FB_BLANK_POWERDOWN, info);
1298 if (ACCEL(dinfo, info))
1299 intelfbhw_2d_stop(dinfo);
1301 memcpy(hw, &dinfo->save_state, sizeof(*hw));
1302 if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
1304 if (intelfbhw_program_mode(dinfo, hw, 0))
1308 intelfbhw_read_hw_state(dinfo, hw, 0);
1309 intelfbhw_print_hw_state(dinfo, hw);
1312 update_dinfo(dinfo, &info->var);
1314 if (ACCEL(dinfo, info))
1315 intelfbhw_2d_start(dinfo);
1317 intelfb_pan_display(&info->var, info);
1319 intelfb_blank(FB_BLANK_UNBLANK, info);
1321 if (ACCEL(dinfo, info)) {
1322 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1323 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1324 FBINFO_HWACCEL_IMAGEBLIT;
1326 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1336 intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1337 unsigned blue, unsigned transp, struct fb_info *info)
1339 struct intelfb_info *dinfo = GET_DINFO(info);
1342 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1348 switch (dinfo->depth) {
1355 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1360 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1361 ((green & 0xf800) >> 6) |
1362 ((blue & 0xf800) >> 11);
1365 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1366 ((green & 0xfc00) >> 5) |
1367 ((blue & 0xf800) >> 11);
1370 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1372 ((blue & 0xff00) >> 8);
1379 intelfb_blank(int blank, struct fb_info *info)
1381 intelfbhw_do_blank(blank, info);
1386 intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1388 intelfbhw_pan_display(var, info);
1392 /* When/if we have our own ioctls. */
1394 intelfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1395 unsigned long arg, struct fb_info *info)
1403 intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect)
1405 struct intelfb_info *dinfo = GET_DINFO(info);
1409 DBG_MSG("intelfb_fillrect\n");
1412 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1413 return cfb_fillrect(info, rect);
1415 if (rect->rop == ROP_COPY)
1416 rop = PAT_ROP_GXCOPY;
1418 rop = PAT_ROP_GXXOR;
1420 if (dinfo->depth != 8)
1421 color = dinfo->pseudo_palette[rect->color];
1423 color = rect->color;
1425 intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
1426 rect->width, rect->height, color,
1427 dinfo->pitch, info->var.bits_per_pixel,
1432 intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
1434 struct intelfb_info *dinfo = GET_DINFO(info);
1437 DBG_MSG("intelfb_copyarea\n");
1440 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1441 return cfb_copyarea(info, region);
1443 intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
1444 region->dy, region->width, region->height,
1445 dinfo->pitch, info->var.bits_per_pixel);
1449 intelfb_imageblit(struct fb_info *info, const struct fb_image *image)
1451 struct intelfb_info *dinfo = GET_DINFO(info);
1452 u32 fgcolor, bgcolor;
1455 DBG_MSG("intelfb_imageblit\n");
1458 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1459 || image->depth != 1)
1460 return cfb_imageblit(info, image);
1462 if (dinfo->depth != 8) {
1463 fgcolor = dinfo->pseudo_palette[image->fg_color];
1464 bgcolor = dinfo->pseudo_palette[image->bg_color];
1466 fgcolor = image->fg_color;
1467 bgcolor = image->bg_color;
1470 if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
1471 image->height, image->data,
1472 image->dx, image->dy,
1473 dinfo->pitch, info->var.bits_per_pixel))
1474 return cfb_imageblit(info, image);
1478 intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1480 struct intelfb_info *dinfo = GET_DINFO(info);
1483 DBG_MSG("intelfb_cursor\n");
1486 if (!dinfo->hwcursor)
1489 intelfbhw_cursor_hide(dinfo);
1491 /* If XFree killed the cursor - restore it */
1492 if (INREG(CURSOR_A_BASEADDR) != dinfo->cursor.offset << 12) {
1495 DBG_MSG("the cursor was killed - restore it !!\n");
1496 DBG_MSG("size %d, %d pos %d, %d\n",
1497 cursor->image.width, cursor->image.height,
1498 cursor->image.dx, cursor->image.dy);
1500 intelfbhw_cursor_init(dinfo);
1501 intelfbhw_cursor_reset(dinfo);
1502 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1505 if (dinfo->depth != 8) {
1506 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1507 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1509 fg = cursor->image.fg_color;
1510 bg = cursor->image.bg_color;
1512 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1513 intelfbhw_cursor_load(dinfo, cursor->image.width,
1514 cursor->image.height,
1518 intelfbhw_cursor_show(dinfo);
1522 if (cursor->set & FB_CUR_SETPOS) {
1525 dx = cursor->image.dx - info->var.xoffset;
1526 dy = cursor->image.dy - info->var.yoffset;
1528 intelfbhw_cursor_setpos(dinfo, dx, dy);
1531 if (cursor->set & FB_CUR_SETSIZE) {
1532 if (cursor->image.width > 64 || cursor->image.height > 64)
1535 intelfbhw_cursor_reset(dinfo);
1538 if (cursor->set & FB_CUR_SETCMAP) {
1541 if (dinfo->depth != 8) {
1542 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1543 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1545 fg = cursor->image.fg_color;
1546 bg = cursor->image.bg_color;
1549 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1552 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1553 u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
1554 u32 size = s_pitch * cursor->image.height;
1555 u8 *dat = (u8 *) cursor->image.data;
1556 u8 *msk = (u8 *) cursor->mask;
1560 if (cursor->image.depth != 1)
1563 switch (cursor->rop) {
1565 for (i = 0; i < size; i++)
1566 src[i] = dat[i] ^ msk[i];
1570 for (i = 0; i < size; i++)
1571 src[i] = dat[i] & msk[i];
1575 /* save the bitmap to restore it when XFree will
1576 make the cursor dirty */
1577 memcpy(dinfo->cursor_src, src, size);
1579 intelfbhw_cursor_load(dinfo, cursor->image.width,
1580 cursor->image.height, src);
1584 intelfbhw_cursor_show(dinfo);
1590 intelfb_sync(struct fb_info *info)
1592 struct intelfb_info *dinfo = GET_DINFO(info);
1595 DBG_MSG("intelfb_sync\n");
1598 if (dinfo->ring_lockup)
1601 intelfbhw_do_sync(dinfo);