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
104 #include <linux/module.h>
105 #include <linux/kernel.h>
106 #include <linux/errno.h>
107 #include <linux/string.h>
108 #include <linux/mm.h>
109 #include <linux/slab.h>
110 #include <linux/delay.h>
111 #include <linux/fb.h>
112 #include <linux/ioport.h>
113 #include <linux/init.h>
114 #include <linux/pci.h>
115 #include <linux/vmalloc.h>
116 #include <linux/pagemap.h>
117 #include <linux/screen_info.h>
122 #include <asm/mtrr.h>
126 #include "intelfbhw.h"
129 static void __devinit
get_initial_mode(struct intelfb_info
*dinfo
);
130 static void update_dinfo(struct intelfb_info
*dinfo
,
131 struct fb_var_screeninfo
*var
);
132 static int intelfb_open(struct fb_info
*info
, int user
);
133 static int intelfb_release(struct fb_info
*info
, int user
);
134 static int intelfb_check_var(struct fb_var_screeninfo
*var
,
135 struct fb_info
*info
);
136 static int intelfb_set_par(struct fb_info
*info
);
137 static int intelfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
138 unsigned blue
, unsigned transp
,
139 struct fb_info
*info
);
141 static int intelfb_blank(int blank
, struct fb_info
*info
);
142 static int intelfb_pan_display(struct fb_var_screeninfo
*var
,
143 struct fb_info
*info
);
145 static void intelfb_fillrect(struct fb_info
*info
,
146 const struct fb_fillrect
*rect
);
147 static void intelfb_copyarea(struct fb_info
*info
,
148 const struct fb_copyarea
*region
);
149 static void intelfb_imageblit(struct fb_info
*info
,
150 const struct fb_image
*image
);
151 static int intelfb_cursor(struct fb_info
*info
,
152 struct fb_cursor
*cursor
);
154 static int intelfb_sync(struct fb_info
*info
);
156 static int intelfb_ioctl(struct fb_info
*info
,
157 unsigned int cmd
, unsigned long arg
);
159 static int __devinit
intelfb_pci_register(struct pci_dev
*pdev
,
160 const struct pci_device_id
*ent
);
161 static void __devexit
intelfb_pci_unregister(struct pci_dev
*pdev
);
162 static int __devinit
intelfb_set_fbinfo(struct intelfb_info
*dinfo
);
165 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
166 * mobile chipsets from being registered.
168 #if DETECT_VGA_CLASS_ONLY
169 #define INTELFB_CLASS_MASK ~0 << 8
171 #define INTELFB_CLASS_MASK 0
174 static struct pci_device_id intelfb_pci_table
[] __devinitdata
= {
175 { 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
},
176 { 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
},
177 { 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
},
178 { 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
},
179 { 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
},
180 { 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
},
181 { 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
},
182 { 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
},
187 static int num_registered
= 0;
190 static struct fb_ops intel_fb_ops
= {
191 .owner
= THIS_MODULE
,
192 .fb_open
= intelfb_open
,
193 .fb_release
= intelfb_release
,
194 .fb_check_var
= intelfb_check_var
,
195 .fb_set_par
= intelfb_set_par
,
196 .fb_setcolreg
= intelfb_setcolreg
,
197 .fb_blank
= intelfb_blank
,
198 .fb_pan_display
= intelfb_pan_display
,
199 .fb_fillrect
= intelfb_fillrect
,
200 .fb_copyarea
= intelfb_copyarea
,
201 .fb_imageblit
= intelfb_imageblit
,
202 .fb_cursor
= intelfb_cursor
,
203 .fb_sync
= intelfb_sync
,
204 .fb_ioctl
= intelfb_ioctl
207 /* PCI driver module table */
208 static struct pci_driver intelfb_driver
= {
210 .id_table
= intelfb_pci_table
,
211 .probe
= intelfb_pci_register
,
212 .remove
= __devexit_p(intelfb_pci_unregister
)
215 /* Module description/parameters */
216 MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
217 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
218 MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS
220 MODULE_LICENSE("Dual BSD/GPL");
221 MODULE_DEVICE_TABLE(pci
, intelfb_pci_table
);
223 static int accel
= 1;
225 static int hwcursor
= 0;
227 static int fixed
= 0;
228 static int noinit
= 0;
229 static int noregister
= 0;
230 static int probeonly
= 0;
231 static int idonly
= 0;
232 static int bailearly
= 0;
233 static int voffset
= 48;
234 static char *mode
= NULL
;
236 module_param(accel
, bool, S_IRUGO
);
237 MODULE_PARM_DESC(accel
, "Enable hardware acceleration");
238 module_param(vram
, int, S_IRUGO
);
239 MODULE_PARM_DESC(vram
, "System RAM to allocate to framebuffer in MiB");
240 module_param(voffset
, int, S_IRUGO
);
241 MODULE_PARM_DESC(voffset
, "Offset of framebuffer in MiB");
242 module_param(hwcursor
, bool, S_IRUGO
);
243 MODULE_PARM_DESC(hwcursor
, "Enable HW cursor");
244 module_param(mtrr
, bool, S_IRUGO
);
245 MODULE_PARM_DESC(mtrr
, "Enable MTRR support");
246 module_param(fixed
, bool, S_IRUGO
);
247 MODULE_PARM_DESC(fixed
, "Disable mode switching");
248 module_param(noinit
, bool, 0);
249 MODULE_PARM_DESC(noinit
, "Don't initialise graphics mode when loading");
250 module_param(noregister
, bool, 0);
251 MODULE_PARM_DESC(noregister
, "Don't register, just probe and exit (debug)");
252 module_param(probeonly
, bool, 0);
253 MODULE_PARM_DESC(probeonly
, "Do a minimal probe (debug)");
254 module_param(idonly
, bool, 0);
255 MODULE_PARM_DESC(idonly
, "Just identify without doing anything else (debug)");
256 module_param(bailearly
, bool, 0);
257 MODULE_PARM_DESC(bailearly
, "Bail out early, depending on value (debug)");
258 module_param(mode
, charp
, S_IRUGO
);
259 MODULE_PARM_DESC(mode
,
260 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
263 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
264 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
265 #define OPT_STRVAL(opt, name) (opt + strlen(name))
267 static __inline__
char * get_opt_string(const char *this_opt
, const char *name
)
273 p
= OPT_STRVAL(this_opt
, name
);
275 while (p
[i
] && p
[i
] != ' ' && p
[i
] != ',')
277 ret
= kmalloc(i
+ 1, GFP_KERNEL
);
285 static __inline__
int get_opt_int(const char *this_opt
, const char *name
,
291 if (!OPT_EQUAL(this_opt
, name
))
294 *ret
= OPT_INTVAL(this_opt
, name
);
298 static __inline__
int get_opt_bool(const char *this_opt
, const char *name
,
304 if (OPT_EQUAL(this_opt
, name
)) {
305 if (this_opt
[strlen(name
)] == '=')
306 *ret
= simple_strtoul(this_opt
+ strlen(name
) + 1,
311 if (OPT_EQUAL(this_opt
, "no") && OPT_EQUAL(this_opt
+ 2, name
))
319 static int __init
intelfb_setup(char *options
)
323 DBG_MSG("intelfb_setup\n");
325 if (!options
|| !*options
) {
326 DBG_MSG("no options\n");
329 DBG_MSG("options: %s\n", options
);
332 * These are the built-in options analogous to the module parameters
337 * video=intelfb:[mode][,<param>=<val>] ...
341 * video=intelfb:1024x768-16@75,accel=0
344 while ((this_opt
= strsep(&options
, ","))) {
347 if (get_opt_bool(this_opt
, "accel", &accel
))
349 else if (get_opt_int(this_opt
, "vram", &vram
))
351 else if (get_opt_bool(this_opt
, "hwcursor", &hwcursor
))
353 else if (get_opt_bool(this_opt
, "mtrr", &mtrr
))
355 else if (get_opt_bool(this_opt
, "fixed", &fixed
))
357 else if (get_opt_bool(this_opt
, "init", &noinit
))
359 else if (OPT_EQUAL(this_opt
, "mode="))
360 mode
= get_opt_string(this_opt
, "mode=");
370 static int __init
intelfb_init(void)
376 DBG_MSG("intelfb_init\n");
378 INF_MSG("Framebuffer driver for "
379 "Intel(R) " SUPPORTED_CHIPSETS
" chipsets\n");
380 INF_MSG("Version " INTELFB_VERSION
"\n");
386 if (fb_get_options("intelfb", &option
))
388 intelfb_setup(option
);
391 return pci_register_driver(&intelfb_driver
);
394 static void __exit
intelfb_exit(void)
396 DBG_MSG("intelfb_exit\n");
397 pci_unregister_driver(&intelfb_driver
);
400 module_init(intelfb_init
);
401 module_exit(intelfb_exit
);
403 /***************************************************************
404 * mtrr support functions *
405 ***************************************************************/
408 static inline void __devinit
set_mtrr(struct intelfb_info
*dinfo
)
410 dinfo
->mtrr_reg
= mtrr_add(dinfo
->aperture
.physical
,
411 dinfo
->aperture
.size
, MTRR_TYPE_WRCOMB
, 1);
412 if (dinfo
->mtrr_reg
< 0) {
413 ERR_MSG("unable to set MTRR\n");
418 static inline void unset_mtrr(struct intelfb_info
*dinfo
)
421 mtrr_del(dinfo
->mtrr_reg
, dinfo
->aperture
.physical
,
422 dinfo
->aperture
.size
);
425 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
427 #define unset_mtrr(x) do { } while (0)
428 #endif /* CONFIG_MTRR */
430 /***************************************************************
431 * driver init / cleanup *
432 ***************************************************************/
434 static void cleanup(struct intelfb_info
*dinfo
)
436 DBG_MSG("cleanup\n");
441 intelfbhw_disable_irq(dinfo
);
443 fb_dealloc_cmap(&dinfo
->info
->cmap
);
444 kfree(dinfo
->info
->pixmap
.addr
);
446 if (dinfo
->registered
)
447 unregister_framebuffer(dinfo
->info
);
451 if (dinfo
->fbmem_gart
&& dinfo
->gtt_fb_mem
) {
452 agp_unbind_memory(dinfo
->gtt_fb_mem
);
453 agp_free_memory(dinfo
->gtt_fb_mem
);
455 if (dinfo
->gtt_cursor_mem
) {
456 agp_unbind_memory(dinfo
->gtt_cursor_mem
);
457 agp_free_memory(dinfo
->gtt_cursor_mem
);
459 if (dinfo
->gtt_ring_mem
) {
460 agp_unbind_memory(dinfo
->gtt_ring_mem
);
461 agp_free_memory(dinfo
->gtt_ring_mem
);
464 #ifdef CONFIG_FB_INTEL_I2C
465 /* un-register I2C bus */
466 intelfb_delete_i2c_busses(dinfo
);
469 if (dinfo
->mmio_base
)
470 iounmap((void __iomem
*)dinfo
->mmio_base
);
471 if (dinfo
->aperture
.virtual)
472 iounmap((void __iomem
*)dinfo
->aperture
.virtual);
474 if (dinfo
->flag
& INTELFB_MMIO_ACQUIRED
)
475 release_mem_region(dinfo
->mmio_base_phys
, INTEL_REG_SIZE
);
476 if (dinfo
->flag
& INTELFB_FB_ACQUIRED
)
477 release_mem_region(dinfo
->aperture
.physical
,
478 dinfo
->aperture
.size
);
479 framebuffer_release(dinfo
->info
);
482 #define bailout(dinfo) do { \
483 DBG_MSG("bailout\n"); \
485 INF_MSG("Not going to register framebuffer, exiting...\n"); \
490 static int __devinit
intelfb_pci_register(struct pci_dev
*pdev
,
491 const struct pci_device_id
*ent
)
493 struct fb_info
*info
;
494 struct intelfb_info
*dinfo
;
496 int aperture_size
, stolen_size
;
497 struct agp_kern_info gtt_info
;
500 struct agp_bridge_data
*bridge
;
501 int aperture_bar
= 0;
505 DBG_MSG("intelfb_pci_register\n");
508 if (num_registered
!= 1) {
509 ERR_MSG("Attempted to register %d devices "
510 "(should be only 1).\n", num_registered
);
514 info
= framebuffer_alloc(sizeof(struct intelfb_info
), &pdev
->dev
);
516 ERR_MSG("Could not allocate memory for intelfb_info.\n");
519 if (fb_alloc_cmap(&info
->cmap
, 256, 1) < 0) {
520 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
527 dinfo
->fbops
= &intel_fb_ops
;
530 /* Reserve pixmap space. */
531 info
->pixmap
.addr
= kzalloc(64 * 1024, GFP_KERNEL
);
532 if (info
->pixmap
.addr
== NULL
) {
533 ERR_MSG("Cannot reserve pixmap memory.\n");
537 /* set early this option because it could be changed by tv encoder
539 dinfo
->fixed_mode
= fixed
;
542 if ((err
= pci_enable_device(pdev
))) {
543 ERR_MSG("Cannot enable device.\n");
548 /* Set base addresses. */
549 if ((ent
->device
== PCI_DEVICE_ID_INTEL_915G
) ||
550 (ent
->device
== PCI_DEVICE_ID_INTEL_915GM
) ||
551 (ent
->device
== PCI_DEVICE_ID_INTEL_945G
) ||
552 (ent
->device
== PCI_DEVICE_ID_INTEL_945GM
)) {
556 dinfo
->aperture
.physical
= pci_resource_start(pdev
, aperture_bar
);
557 dinfo
->aperture
.size
= pci_resource_len(pdev
, aperture_bar
);
558 dinfo
->mmio_base_phys
= pci_resource_start(pdev
, mmio_bar
);
559 DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
560 (unsigned long long)pci_resource_start(pdev
, aperture_bar
),
561 (unsigned long long)pci_resource_len(pdev
, aperture_bar
),
562 (unsigned long long)pci_resource_start(pdev
, mmio_bar
),
563 (unsigned long long)pci_resource_len(pdev
, mmio_bar
));
565 /* Reserve the fb and MMIO regions */
566 if (!request_mem_region(dinfo
->aperture
.physical
, dinfo
->aperture
.size
,
567 INTELFB_MODULE_NAME
)) {
568 ERR_MSG("Cannot reserve FB region.\n");
573 dinfo
->flag
|= INTELFB_FB_ACQUIRED
;
575 if (!request_mem_region(dinfo
->mmio_base_phys
,
577 INTELFB_MODULE_NAME
)) {
578 ERR_MSG("Cannot reserve MMIO region.\n");
583 dinfo
->flag
|= INTELFB_MMIO_ACQUIRED
;
585 /* Get the chipset info. */
586 dinfo
->pci_chipset
= pdev
->device
;
588 if (intelfbhw_get_chipset(pdev
, dinfo
)) {
593 if (intelfbhw_get_memory(pdev
, &aperture_size
,&stolen_size
)) {
598 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
599 "stolen memory %dkB\n",
600 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
601 PCI_FUNC(pdev
->devfn
), dinfo
->name
,
602 BtoMB(aperture_size
), BtoKB(stolen_size
));
604 /* Set these from the options. */
605 dinfo
->accel
= accel
;
606 dinfo
->hwcursor
= hwcursor
;
608 if (NOACCEL_CHIPSET(dinfo
) && dinfo
->accel
== 1) {
609 INF_MSG("Acceleration is not supported for the %s chipset.\n",
614 /* Framebuffer parameters - Use all the stolen memory if >= vram */
615 if (ROUND_UP_TO_PAGE(stolen_size
) >= MB(vram
)) {
616 dinfo
->fb
.size
= ROUND_UP_TO_PAGE(stolen_size
);
617 dinfo
->fbmem_gart
= 0;
619 dinfo
->fb
.size
= MB(vram
);
620 dinfo
->fbmem_gart
= 1;
623 /* Allocate space for the ring buffer and HW cursor if enabled. */
625 dinfo
->ring
.size
= RINGBUFFER_SIZE
;
626 dinfo
->ring_tail_mask
= dinfo
->ring
.size
- 1;
629 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 dinfo
->cursor
.offset
= offset
+
656 + gtt_info
.current_memory
+ (dinfo
->ring
.size
>> 12);
657 if (dinfo
->fbmem_gart
)
658 dinfo
->fb
.offset
= offset
+
659 + gtt_info
.current_memory
+ (dinfo
->ring
.size
>> 12)
660 + (dinfo
->cursor
.size
>> 12);
662 /* Allocate memories (which aren't stolen) */
663 /* Map the fb and MMIO regions */
664 /* ioremap only up to the end of used aperture */
665 dinfo
->aperture
.virtual = (u8 __iomem
*)ioremap_nocache
666 (dinfo
->aperture
.physical
, ((offset
+ dinfo
->fb
.offset
) << 12)
668 if (!dinfo
->aperture
.virtual) {
669 ERR_MSG("Cannot remap FB region.\n");
675 (u8 __iomem
*)ioremap_nocache(dinfo
->mmio_base_phys
,
677 if (!dinfo
->mmio_base
) {
678 ERR_MSG("Cannot remap MMIO region.\n");
684 if (!(dinfo
->gtt_ring_mem
=
685 agp_allocate_memory(bridge
, dinfo
->ring
.size
>> 12,
686 AGP_NORMAL_MEMORY
))) {
687 ERR_MSG("cannot allocate ring buffer memory\n");
688 agp_backend_release(bridge
);
692 if (agp_bind_memory(dinfo
->gtt_ring_mem
,
693 dinfo
->ring
.offset
)) {
694 ERR_MSG("cannot bind ring buffer memory\n");
695 agp_backend_release(bridge
);
699 dinfo
->ring
.physical
= dinfo
->aperture
.physical
700 + (dinfo
->ring
.offset
<< 12);
701 dinfo
->ring
.virtual = dinfo
->aperture
.virtual
702 + (dinfo
->ring
.offset
<< 12);
703 dinfo
->ring_head
= 0;
705 if (dinfo
->hwcursor
) {
706 agp_memtype
= dinfo
->mobile
? AGP_PHYSICAL_MEMORY
708 if (!(dinfo
->gtt_cursor_mem
=
709 agp_allocate_memory(bridge
, dinfo
->cursor
.size
>> 12,
711 ERR_MSG("cannot allocate cursor memory\n");
712 agp_backend_release(bridge
);
716 if (agp_bind_memory(dinfo
->gtt_cursor_mem
,
717 dinfo
->cursor
.offset
)) {
718 ERR_MSG("cannot bind cursor memory\n");
719 agp_backend_release(bridge
);
724 dinfo
->cursor
.physical
725 = dinfo
->gtt_cursor_mem
->physical
;
727 dinfo
->cursor
.physical
= dinfo
->aperture
.physical
728 + (dinfo
->cursor
.offset
<< 12);
729 dinfo
->cursor
.virtual = dinfo
->aperture
.virtual
730 + (dinfo
->cursor
.offset
<< 12);
732 if (dinfo
->fbmem_gart
) {
733 if (!(dinfo
->gtt_fb_mem
=
734 agp_allocate_memory(bridge
, dinfo
->fb
.size
>> 12,
735 AGP_NORMAL_MEMORY
))) {
736 WRN_MSG("cannot allocate framebuffer memory - use "
738 dinfo
->fbmem_gart
= 0;
740 if (agp_bind_memory(dinfo
->gtt_fb_mem
,
742 WRN_MSG("cannot bind framebuffer memory - use "
744 dinfo
->fbmem_gart
= 0;
748 /* update framebuffer memory parameters */
749 if (!dinfo
->fbmem_gart
)
750 dinfo
->fb
.offset
= 0; /* starts at offset 0 */
751 dinfo
->fb
.physical
= dinfo
->aperture
.physical
752 + (dinfo
->fb
.offset
<< 12);
753 dinfo
->fb
.virtual = dinfo
->aperture
.virtual + (dinfo
->fb
.offset
<< 12);
754 dinfo
->fb_start
= dinfo
->fb
.offset
<< 12;
756 /* release agpgart */
757 agp_backend_release(bridge
);
762 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
763 dinfo
->fb
.physical
, dinfo
->fb
.offset
, dinfo
->fb
.size
,
765 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
766 dinfo
->mmio_base_phys
, INTEL_REG_SIZE
,
768 DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n",
769 dinfo
->ring
.physical
, dinfo
->ring
.size
,
770 dinfo
->ring
.virtual);
771 DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
772 dinfo
->cursor
.physical
, dinfo
->cursor
.size
,
773 dinfo
->cursor
.virtual, dinfo
->cursor
.offset
,
774 dinfo
->cursor
.physical
);
776 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
777 "noinit = %d\n", vram
, accel
, hwcursor
, fixed
, noinit
);
778 DBG_MSG("options: mode = \"%s\"\n", mode
? mode
: "");
784 * Check if the LVDS port or any DVO ports are enabled. If so,
785 * don't allow mode switching
787 dvo
= intelfbhw_check_non_crt(dinfo
);
789 dinfo
->fixed_mode
= 1;
790 WRN_MSG("Non-CRT device is enabled ( ");
794 s
= intelfbhw_dvo_to_string(1 << i
);
801 printk("). Disabling mode switching.\n");
807 if (FIXED_MODE(dinfo
) && ORIG_VIDEO_ISVGA
!= VIDEO_TYPE_VLFB
) {
808 ERR_MSG("Video mode must be programmed at boot time.\n");
816 /* Initialise dinfo and related data. */
817 /* If an initial mode was programmed at boot time, get its details. */
818 if (ORIG_VIDEO_ISVGA
== VIDEO_TYPE_VLFB
)
819 get_initial_mode(dinfo
);
824 if (FIXED_MODE(dinfo
)) /* remap fb address */
825 update_dinfo(dinfo
, &dinfo
->initial_var
);
831 if (intelfb_set_fbinfo(dinfo
)) {
839 #ifdef CONFIG_FB_INTEL_I2C
840 /* register I2C bus */
841 intelfb_create_i2c_busses(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;
890 init_waitqueue_head(&dinfo
->vsync
.wait
);
891 spin_lock_init(&dinfo
->int_lock
);
892 dinfo
->irq_flags
= 0;
893 dinfo
->vsync
.pan_display
= 0;
894 dinfo
->vsync
.pan_offset
= 0;
899 fb_dealloc_cmap(&info
->cmap
);
901 framebuffer_release(info
);
905 static void __devexit
906 intelfb_pci_unregister(struct pci_dev
*pdev
)
908 struct intelfb_info
*dinfo
= pci_get_drvdata(pdev
);
910 DBG_MSG("intelfb_pci_unregister\n");
917 pci_set_drvdata(pdev
, NULL
);
920 /***************************************************************
922 ***************************************************************/
924 int __inline__
intelfb_var_to_depth(const struct fb_var_screeninfo
*var
)
926 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
927 var
->bits_per_pixel
, var
->green
.length
);
929 switch (var
->bits_per_pixel
) {
931 return (var
->green
.length
== 6) ? 16 : 15;
935 return var
->bits_per_pixel
;
940 static __inline__
int var_to_refresh(const struct fb_var_screeninfo
*var
)
942 int xtot
= var
->xres
+ var
->left_margin
+ var
->right_margin
+
944 int ytot
= var
->yres
+ var
->upper_margin
+ var
->lower_margin
+
947 return (1000000000 / var
->pixclock
* 1000 + 500) / xtot
/ ytot
;
950 /***************************************************************
951 * Various intialisation functions *
952 ***************************************************************/
954 static void __devinit
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
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
= kmemdup(edid_s
, EDID_LENGTH
, GFP_KERNEL
);
1041 fb_edid_to_monspecs(edid_d
,
1042 &dinfo
->info
->monspecs
);
1048 printk("intelfb: Looking for mode in private "
1050 msrc
= fb_find_mode(var
, dinfo
->info
, mode
,
1051 dinfo
->info
->monspecs
.modedb
,
1052 dinfo
->info
->monspecs
.modedb_len
,
1055 if (msrc
&& msrc
> 1) {
1056 printk("intelfb: No mode in private database, "
1057 "intelfb: looking for mode in global "
1059 msrc
= fb_find_mode(var
, dinfo
->info
, mode
,
1069 msrc
= fb_find_mode(var
, dinfo
->info
, PREFERRED_MODE
,
1074 ERR_MSG("Cannot find a suitable video mode.\n");
1078 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var
->xres
, var
->yres
,
1079 var
->bits_per_pixel
, var_to_refresh(var
));
1081 DBG_MSG("Initial video mode is from %d.\n", msrc
);
1083 #if ALLOCATE_FOR_PANNING
1084 /* Allow use of half of the video ram for panning */
1085 var
->xres_virtual
= var
->xres
;
1087 dinfo
->fb
.size
/ 2 / (var
->bits_per_pixel
* var
->xres
);
1088 if (var
->yres_virtual
< var
->yres
)
1089 var
->yres_virtual
= var
->yres
;
1091 var
->yres_virtual
= var
->yres
;
1095 var
->accel_flags
|= FB_ACCELF_TEXT
;
1097 var
->accel_flags
&= ~FB_ACCELF_TEXT
;
1102 static int __devinit
intelfb_set_fbinfo(struct intelfb_info
*dinfo
)
1104 struct fb_info
*info
= dinfo
->info
;
1106 DBG_MSG("intelfb_set_fbinfo\n");
1108 info
->flags
= FBINFO_FLAG_DEFAULT
;
1109 info
->fbops
= &intel_fb_ops
;
1110 info
->pseudo_palette
= dinfo
->pseudo_palette
;
1112 info
->pixmap
.size
= 64*1024;
1113 info
->pixmap
.buf_align
= 8;
1114 info
->pixmap
.access_align
= 32;
1115 info
->pixmap
.flags
= FB_PIXMAP_SYSTEM
;
1117 if (intelfb_init_var(dinfo
))
1120 info
->pixmap
.scan_align
= 1;
1121 strcpy(info
->fix
.id
, dinfo
->name
);
1122 info
->fix
.smem_start
= dinfo
->fb
.physical
;
1123 info
->fix
.smem_len
= dinfo
->fb
.size
;
1124 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1125 info
->fix
.type_aux
= 0;
1126 info
->fix
.xpanstep
= 8;
1127 info
->fix
.ypanstep
= 1;
1128 info
->fix
.ywrapstep
= 0;
1129 info
->fix
.mmio_start
= dinfo
->mmio_base_phys
;
1130 info
->fix
.mmio_len
= INTEL_REG_SIZE
;
1131 info
->fix
.accel
= FB_ACCEL_I830
;
1132 update_dinfo(dinfo
, &info
->var
);
1137 /* Update dinfo to match the active video mode. */
1138 static void update_dinfo(struct intelfb_info
*dinfo
,
1139 struct fb_var_screeninfo
*var
)
1141 DBG_MSG("update_dinfo\n");
1143 dinfo
->bpp
= var
->bits_per_pixel
;
1144 dinfo
->depth
= intelfb_var_to_depth(var
);
1145 dinfo
->xres
= var
->xres
;
1146 dinfo
->yres
= var
->xres
;
1147 dinfo
->pixclock
= var
->pixclock
;
1149 dinfo
->info
->fix
.visual
= dinfo
->visual
;
1150 dinfo
->info
->fix
.line_length
= dinfo
->pitch
;
1152 switch (dinfo
->bpp
) {
1154 dinfo
->visual
= FB_VISUAL_PSEUDOCOLOR
;
1155 dinfo
->pitch
= var
->xres_virtual
;
1158 dinfo
->visual
= FB_VISUAL_TRUECOLOR
;
1159 dinfo
->pitch
= var
->xres_virtual
* 2;
1162 dinfo
->visual
= FB_VISUAL_TRUECOLOR
;
1163 dinfo
->pitch
= var
->xres_virtual
* 4;
1167 /* Make sure the line length is a aligned correctly. */
1169 dinfo
->pitch
= ROUND_UP_TO(dinfo
->pitch
, STRIDE_ALIGNMENT_I9XX
);
1171 dinfo
->pitch
= ROUND_UP_TO(dinfo
->pitch
, STRIDE_ALIGNMENT
);
1173 if (FIXED_MODE(dinfo
))
1174 dinfo
->pitch
= dinfo
->initial_pitch
;
1176 dinfo
->info
->screen_base
= (char __iomem
*)dinfo
->fb
.virtual;
1177 dinfo
->info
->fix
.line_length
= dinfo
->pitch
;
1178 dinfo
->info
->fix
.visual
= dinfo
->visual
;
1181 /* fbops functions */
1183 /***************************************************************
1185 ***************************************************************/
1187 static int intelfb_open(struct fb_info
*info
, int user
)
1189 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1197 static int intelfb_release(struct fb_info
*info
, int user
)
1199 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1205 intelfbhw_disable_irq(dinfo
);
1211 static int intelfb_check_var(struct fb_var_screeninfo
*var
,
1212 struct fb_info
*info
)
1215 struct fb_var_screeninfo v
;
1216 struct intelfb_info
*dinfo
;
1217 static int first
= 1;
1219 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1220 static const int pitches
[] = {
1228 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var
->accel_flags
);
1230 dinfo
= GET_DINFO(info
);
1232 /* update the pitch */
1233 if (intelfbhw_validate_mode(dinfo
, var
) != 0)
1238 for (i
= 0; pitches
[i
] != 0; i
++) {
1239 if (pitches
[i
] >= v
.xres_virtual
) {
1240 v
.xres_virtual
= pitches
[i
];
1245 /* Check for a supported bpp. */
1246 if (v
.bits_per_pixel
<= 8)
1247 v
.bits_per_pixel
= 8;
1248 else if (v
.bits_per_pixel
<= 16) {
1249 if (v
.bits_per_pixel
== 16)
1251 v
.bits_per_pixel
= 16;
1252 } else if (v
.bits_per_pixel
<= 32)
1253 v
.bits_per_pixel
= 32;
1257 change_var
= ((info
->var
.xres
!= var
->xres
) ||
1258 (info
->var
.yres
!= var
->yres
) ||
1259 (info
->var
.xres_virtual
!= var
->xres_virtual
) ||
1260 (info
->var
.yres_virtual
!= var
->yres_virtual
) ||
1261 (info
->var
.bits_per_pixel
!= var
->bits_per_pixel
) ||
1262 memcmp(&info
->var
.red
, &var
->red
, sizeof(var
->red
)) ||
1263 memcmp(&info
->var
.green
, &var
->green
,
1264 sizeof(var
->green
)) ||
1265 memcmp(&info
->var
.blue
, &var
->blue
, sizeof(var
->blue
)));
1267 if (FIXED_MODE(dinfo
) &&
1269 var
->yres_virtual
> dinfo
->initial_var
.yres_virtual
||
1270 var
->yres_virtual
< dinfo
->initial_var
.yres
||
1271 var
->xoffset
|| var
->nonstd
)) {
1273 ERR_MSG("Changing the video mode is not supported.\n");
1279 switch (intelfb_var_to_depth(&v
)) {
1281 v
.red
.offset
= v
.green
.offset
= v
.blue
.offset
= 0;
1282 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1283 v
.transp
.offset
= v
.transp
.length
= 0;
1289 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 5;
1290 v
.transp
.offset
= v
.transp
.length
= 0;
1299 v
.transp
.offset
= v
.transp
.length
= 0;
1305 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1306 v
.transp
.offset
= v
.transp
.length
= 0;
1312 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1313 v
.transp
.offset
= 24;
1314 v
.transp
.length
= 8;
1323 if (v
.xoffset
> v
.xres_virtual
- v
.xres
)
1324 v
.xoffset
= v
.xres_virtual
- v
.xres
;
1325 if (v
.yoffset
> v
.yres_virtual
- v
.yres
)
1326 v
.yoffset
= v
.yres_virtual
- v
.yres
;
1328 v
.red
.msb_right
= v
.green
.msb_right
= v
.blue
.msb_right
=
1329 v
.transp
.msb_right
= 0;
1336 static int intelfb_set_par(struct fb_info
*info
)
1338 struct intelfb_hwstate
*hw
;
1339 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1341 if (FIXED_MODE(dinfo
)) {
1342 ERR_MSG("Changing the video mode is not supported.\n");
1346 hw
= kmalloc(sizeof(*hw
), GFP_ATOMIC
);
1350 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info
->var
.xres
,
1351 info
->var
.yres
, info
->var
.bits_per_pixel
);
1353 intelfb_blank(FB_BLANK_POWERDOWN
, info
);
1355 if (ACCEL(dinfo
, info
))
1356 intelfbhw_2d_stop(dinfo
);
1358 memcpy(hw
, &dinfo
->save_state
, sizeof(*hw
));
1359 if (intelfbhw_mode_to_hw(dinfo
, hw
, &info
->var
))
1361 if (intelfbhw_program_mode(dinfo
, hw
, 0))
1365 intelfbhw_read_hw_state(dinfo
, hw
, 0);
1366 intelfbhw_print_hw_state(dinfo
, hw
);
1369 update_dinfo(dinfo
, &info
->var
);
1371 if (ACCEL(dinfo
, info
))
1372 intelfbhw_2d_start(dinfo
);
1374 intelfb_pan_display(&info
->var
, info
);
1376 intelfb_blank(FB_BLANK_UNBLANK
, info
);
1378 if (ACCEL(dinfo
, info
)) {
1379 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
|
1380 FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
|
1381 FBINFO_HWACCEL_IMAGEBLIT
;
1383 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1392 static int intelfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1393 unsigned blue
, unsigned transp
,
1394 struct fb_info
*info
)
1396 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1399 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno
, dinfo
->depth
);
1405 if (dinfo
->depth
== 8) {
1410 intelfbhw_setcolreg(dinfo
, regno
, red
, green
, blue
,
1415 switch (dinfo
->depth
) {
1417 dinfo
->pseudo_palette
[regno
] = ((red
& 0xf800) >> 1) |
1418 ((green
& 0xf800) >> 6) |
1419 ((blue
& 0xf800) >> 11);
1422 dinfo
->pseudo_palette
[regno
] = (red
& 0xf800) |
1423 ((green
& 0xfc00) >> 5) |
1424 ((blue
& 0xf800) >> 11);
1427 dinfo
->pseudo_palette
[regno
] = ((red
& 0xff00) << 8) |
1429 ((blue
& 0xff00) >> 8);
1437 static int intelfb_blank(int blank
, struct fb_info
*info
)
1439 intelfbhw_do_blank(blank
, info
);
1443 static int intelfb_pan_display(struct fb_var_screeninfo
*var
,
1444 struct fb_info
*info
)
1446 intelfbhw_pan_display(var
, info
);
1450 /* When/if we have our own ioctls. */
1451 static int intelfb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1455 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1459 case FBIO_WAITFORVSYNC
:
1460 if (get_user(pipe
, (__u32 __user
*)arg
))
1463 retval
= intelfbhw_wait_for_vsync(dinfo
, pipe
);
1472 static void intelfb_fillrect (struct fb_info
*info
,
1473 const struct fb_fillrect
*rect
)
1475 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1479 DBG_MSG("intelfb_fillrect\n");
1482 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4)
1483 return cfb_fillrect(info
, rect
);
1485 if (rect
->rop
== ROP_COPY
)
1486 rop
= PAT_ROP_GXCOPY
;
1488 rop
= PAT_ROP_GXXOR
;
1490 if (dinfo
->depth
!= 8)
1491 color
= dinfo
->pseudo_palette
[rect
->color
];
1493 color
= rect
->color
;
1495 intelfbhw_do_fillrect(dinfo
, rect
->dx
, rect
->dy
,
1496 rect
->width
, rect
->height
, color
,
1497 dinfo
->pitch
, info
->var
.bits_per_pixel
,
1501 static void intelfb_copyarea(struct fb_info
*info
,
1502 const struct fb_copyarea
*region
)
1504 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1507 DBG_MSG("intelfb_copyarea\n");
1510 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4)
1511 return cfb_copyarea(info
, region
);
1513 intelfbhw_do_bitblt(dinfo
, region
->sx
, region
->sy
, region
->dx
,
1514 region
->dy
, region
->width
, region
->height
,
1515 dinfo
->pitch
, info
->var
.bits_per_pixel
);
1518 static void intelfb_imageblit(struct fb_info
*info
,
1519 const struct fb_image
*image
)
1521 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1522 u32 fgcolor
, bgcolor
;
1525 DBG_MSG("intelfb_imageblit\n");
1528 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4
1529 || image
->depth
!= 1)
1530 return cfb_imageblit(info
, image
);
1532 if (dinfo
->depth
!= 8) {
1533 fgcolor
= dinfo
->pseudo_palette
[image
->fg_color
];
1534 bgcolor
= dinfo
->pseudo_palette
[image
->bg_color
];
1536 fgcolor
= image
->fg_color
;
1537 bgcolor
= image
->bg_color
;
1540 if (!intelfbhw_do_drawglyph(dinfo
, fgcolor
, bgcolor
, image
->width
,
1541 image
->height
, image
->data
,
1542 image
->dx
, image
->dy
,
1543 dinfo
->pitch
, info
->var
.bits_per_pixel
))
1544 return cfb_imageblit(info
, image
);
1547 static int intelfb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1549 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1552 DBG_MSG("intelfb_cursor\n");
1555 if (!dinfo
->hwcursor
)
1558 intelfbhw_cursor_hide(dinfo
);
1560 /* If XFree killed the cursor - restore it */
1561 physical
= (dinfo
->mobile
|| IS_I9XX(dinfo
)) ? dinfo
->cursor
.physical
:
1562 (dinfo
->cursor
.offset
<< 12);
1564 if (INREG(CURSOR_A_BASEADDR
) != physical
) {
1567 DBG_MSG("the cursor was killed - restore it !!\n");
1568 DBG_MSG("size %d, %d pos %d, %d\n",
1569 cursor
->image
.width
, cursor
->image
.height
,
1570 cursor
->image
.dx
, cursor
->image
.dy
);
1572 intelfbhw_cursor_init(dinfo
);
1573 intelfbhw_cursor_reset(dinfo
);
1574 intelfbhw_cursor_setpos(dinfo
, cursor
->image
.dx
,
1577 if (dinfo
->depth
!= 8) {
1578 fg
=dinfo
->pseudo_palette
[cursor
->image
.fg_color
];
1579 bg
=dinfo
->pseudo_palette
[cursor
->image
.bg_color
];
1581 fg
= cursor
->image
.fg_color
;
1582 bg
= cursor
->image
.bg_color
;
1584 intelfbhw_cursor_setcolor(dinfo
, bg
, fg
);
1585 intelfbhw_cursor_load(dinfo
, cursor
->image
.width
,
1586 cursor
->image
.height
,
1590 intelfbhw_cursor_show(dinfo
);
1594 if (cursor
->set
& FB_CUR_SETPOS
) {
1597 dx
= cursor
->image
.dx
- info
->var
.xoffset
;
1598 dy
= cursor
->image
.dy
- info
->var
.yoffset
;
1600 intelfbhw_cursor_setpos(dinfo
, dx
, dy
);
1603 if (cursor
->set
& FB_CUR_SETSIZE
) {
1604 if (cursor
->image
.width
> 64 || cursor
->image
.height
> 64)
1607 intelfbhw_cursor_reset(dinfo
);
1610 if (cursor
->set
& FB_CUR_SETCMAP
) {
1613 if (dinfo
->depth
!= 8) {
1614 fg
= dinfo
->pseudo_palette
[cursor
->image
.fg_color
];
1615 bg
= dinfo
->pseudo_palette
[cursor
->image
.bg_color
];
1617 fg
= cursor
->image
.fg_color
;
1618 bg
= cursor
->image
.bg_color
;
1621 intelfbhw_cursor_setcolor(dinfo
, bg
, fg
);
1624 if (cursor
->set
& (FB_CUR_SETSHAPE
| FB_CUR_SETIMAGE
)) {
1625 u32 s_pitch
= (ROUND_UP_TO(cursor
->image
.width
, 8) / 8);
1626 u32 size
= s_pitch
* cursor
->image
.height
;
1627 u8
*dat
= (u8
*) cursor
->image
.data
;
1628 u8
*msk
= (u8
*) cursor
->mask
;
1632 if (cursor
->image
.depth
!= 1)
1635 switch (cursor
->rop
) {
1637 for (i
= 0; i
< size
; i
++)
1638 src
[i
] = dat
[i
] ^ msk
[i
];
1642 for (i
= 0; i
< size
; i
++)
1643 src
[i
] = dat
[i
] & msk
[i
];
1647 /* save the bitmap to restore it when XFree will
1648 make the cursor dirty */
1649 memcpy(dinfo
->cursor_src
, src
, size
);
1651 intelfbhw_cursor_load(dinfo
, cursor
->image
.width
,
1652 cursor
->image
.height
, src
);
1656 intelfbhw_cursor_show(dinfo
);
1661 static int intelfb_sync(struct fb_info
*info
)
1663 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1666 DBG_MSG("intelfb_sync\n");
1669 if (dinfo
->ring_lockup
)
1672 intelfbhw_do_sync(dinfo
);