4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/
5 * 945G/945GM/945GME/965G/965GM 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
103 * 04/2008 - Version 0.9.5
104 * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>)
106 * 08/2008 - Version 0.9.6
107 * Add support for 945GME. (Phil Endecott <spam_from_intelfb@chezphil.org>)
110 #include <linux/module.h>
111 #include <linux/kernel.h>
112 #include <linux/errno.h>
113 #include <linux/string.h>
114 #include <linux/mm.h>
115 #include <linux/slab.h>
116 #include <linux/delay.h>
117 #include <linux/fb.h>
118 #include <linux/ioport.h>
119 #include <linux/init.h>
120 #include <linux/pci.h>
121 #include <linux/vmalloc.h>
122 #include <linux/pagemap.h>
123 #include <linux/screen_info.h>
128 #include <asm/mtrr.h>
132 #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_open(struct fb_info
*info
, int user
);
139 static int intelfb_release(struct fb_info
*info
, int user
);
140 static int intelfb_check_var(struct fb_var_screeninfo
*var
,
141 struct fb_info
*info
);
142 static int intelfb_set_par(struct fb_info
*info
);
143 static int intelfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
144 unsigned blue
, unsigned transp
,
145 struct fb_info
*info
);
147 static int intelfb_blank(int blank
, struct fb_info
*info
);
148 static int intelfb_pan_display(struct fb_var_screeninfo
*var
,
149 struct fb_info
*info
);
151 static void intelfb_fillrect(struct fb_info
*info
,
152 const struct fb_fillrect
*rect
);
153 static void intelfb_copyarea(struct fb_info
*info
,
154 const struct fb_copyarea
*region
);
155 static void intelfb_imageblit(struct fb_info
*info
,
156 const struct fb_image
*image
);
157 static int intelfb_cursor(struct fb_info
*info
,
158 struct fb_cursor
*cursor
);
160 static int intelfb_sync(struct fb_info
*info
);
162 static int intelfb_ioctl(struct fb_info
*info
,
163 unsigned int cmd
, unsigned long arg
);
165 static int __devinit
intelfb_pci_register(struct pci_dev
*pdev
,
166 const struct pci_device_id
*ent
);
167 static void __devexit
intelfb_pci_unregister(struct pci_dev
*pdev
);
168 static int __devinit
intelfb_set_fbinfo(struct intelfb_info
*dinfo
);
171 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
172 * mobile chipsets from being registered.
174 #if DETECT_VGA_CLASS_ONLY
175 #define INTELFB_CLASS_MASK ~0 << 8
177 #define INTELFB_CLASS_MASK 0
180 static struct pci_device_id intelfb_pci_table
[] __devinitdata
= {
181 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_830M
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_830M
},
182 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_845G
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_845G
},
183 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_85XGM
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_85XGM
},
184 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_865G
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_865G
},
185 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_854
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_854
},
186 { 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
},
187 { 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
},
188 { 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
},
189 { 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
},
190 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_945GME
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_945GME
},
191 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_965G
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_965G
},
192 { PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_965GM
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_CLASS_DISPLAY_VGA
<< 8, INTELFB_CLASS_MASK
, INTEL_965GM
},
197 static int num_registered
= 0;
200 static struct fb_ops intel_fb_ops
= {
201 .owner
= THIS_MODULE
,
202 .fb_open
= intelfb_open
,
203 .fb_release
= intelfb_release
,
204 .fb_check_var
= intelfb_check_var
,
205 .fb_set_par
= intelfb_set_par
,
206 .fb_setcolreg
= intelfb_setcolreg
,
207 .fb_blank
= intelfb_blank
,
208 .fb_pan_display
= intelfb_pan_display
,
209 .fb_fillrect
= intelfb_fillrect
,
210 .fb_copyarea
= intelfb_copyarea
,
211 .fb_imageblit
= intelfb_imageblit
,
212 .fb_cursor
= intelfb_cursor
,
213 .fb_sync
= intelfb_sync
,
214 .fb_ioctl
= intelfb_ioctl
217 /* PCI driver module table */
218 static struct pci_driver intelfb_driver
= {
220 .id_table
= intelfb_pci_table
,
221 .probe
= intelfb_pci_register
,
222 .remove
= __devexit_p(intelfb_pci_unregister
)
225 /* Module description/parameters */
226 MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
227 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
228 MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS
230 MODULE_LICENSE("Dual BSD/GPL");
231 MODULE_DEVICE_TABLE(pci
, intelfb_pci_table
);
233 static int accel
= 1;
235 static int hwcursor
= 0;
237 static int fixed
= 0;
238 static int noinit
= 0;
239 static int noregister
= 0;
240 static int probeonly
= 0;
241 static int idonly
= 0;
242 static int bailearly
= 0;
243 static int voffset
= 48;
244 static char *mode
= NULL
;
246 module_param(accel
, bool, S_IRUGO
);
247 MODULE_PARM_DESC(accel
, "Enable hardware acceleration");
248 module_param(vram
, int, S_IRUGO
);
249 MODULE_PARM_DESC(vram
, "System RAM to allocate to framebuffer in MiB");
250 module_param(voffset
, int, S_IRUGO
);
251 MODULE_PARM_DESC(voffset
, "Offset of framebuffer in MiB");
252 module_param(hwcursor
, bool, S_IRUGO
);
253 MODULE_PARM_DESC(hwcursor
, "Enable HW cursor");
254 module_param(mtrr
, bool, S_IRUGO
);
255 MODULE_PARM_DESC(mtrr
, "Enable MTRR support");
256 module_param(fixed
, bool, S_IRUGO
);
257 MODULE_PARM_DESC(fixed
, "Disable mode switching");
258 module_param(noinit
, bool, 0);
259 MODULE_PARM_DESC(noinit
, "Don't initialise graphics mode when loading");
260 module_param(noregister
, bool, 0);
261 MODULE_PARM_DESC(noregister
, "Don't register, just probe and exit (debug)");
262 module_param(probeonly
, bool, 0);
263 MODULE_PARM_DESC(probeonly
, "Do a minimal probe (debug)");
264 module_param(idonly
, bool, 0);
265 MODULE_PARM_DESC(idonly
, "Just identify without doing anything else (debug)");
266 module_param(bailearly
, bool, 0);
267 MODULE_PARM_DESC(bailearly
, "Bail out early, depending on value (debug)");
268 module_param(mode
, charp
, S_IRUGO
);
269 MODULE_PARM_DESC(mode
,
270 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
273 #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
274 #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
275 #define OPT_STRVAL(opt, name) (opt + strlen(name))
277 static __inline__
char * get_opt_string(const char *this_opt
, const char *name
)
283 p
= OPT_STRVAL(this_opt
, name
);
285 while (p
[i
] && p
[i
] != ' ' && p
[i
] != ',')
287 ret
= kmalloc(i
+ 1, GFP_KERNEL
);
295 static __inline__
int get_opt_int(const char *this_opt
, const char *name
,
301 if (!OPT_EQUAL(this_opt
, name
))
304 *ret
= OPT_INTVAL(this_opt
, name
);
308 static __inline__
int get_opt_bool(const char *this_opt
, const char *name
,
314 if (OPT_EQUAL(this_opt
, name
)) {
315 if (this_opt
[strlen(name
)] == '=')
316 *ret
= simple_strtoul(this_opt
+ strlen(name
) + 1,
321 if (OPT_EQUAL(this_opt
, "no") && OPT_EQUAL(this_opt
+ 2, name
))
329 static int __init
intelfb_setup(char *options
)
333 DBG_MSG("intelfb_setup\n");
335 if (!options
|| !*options
) {
336 DBG_MSG("no options\n");
339 DBG_MSG("options: %s\n", options
);
342 * These are the built-in options analogous to the module parameters
347 * video=intelfb:[mode][,<param>=<val>] ...
351 * video=intelfb:1024x768-16@75,accel=0
354 while ((this_opt
= strsep(&options
, ","))) {
357 if (get_opt_bool(this_opt
, "accel", &accel
))
359 else if (get_opt_int(this_opt
, "vram", &vram
))
361 else if (get_opt_bool(this_opt
, "hwcursor", &hwcursor
))
363 else if (get_opt_bool(this_opt
, "mtrr", &mtrr
))
365 else if (get_opt_bool(this_opt
, "fixed", &fixed
))
367 else if (get_opt_bool(this_opt
, "init", &noinit
))
369 else if (OPT_EQUAL(this_opt
, "mode="))
370 mode
= get_opt_string(this_opt
, "mode=");
380 static int __init
intelfb_init(void)
386 DBG_MSG("intelfb_init\n");
388 INF_MSG("Framebuffer driver for "
389 "Intel(R) " SUPPORTED_CHIPSETS
" chipsets\n");
390 INF_MSG("Version " INTELFB_VERSION
"\n");
396 if (fb_get_options("intelfb", &option
))
398 intelfb_setup(option
);
401 return pci_register_driver(&intelfb_driver
);
404 static void __exit
intelfb_exit(void)
406 DBG_MSG("intelfb_exit\n");
407 pci_unregister_driver(&intelfb_driver
);
410 module_init(intelfb_init
);
411 module_exit(intelfb_exit
);
413 /***************************************************************
414 * mtrr support functions *
415 ***************************************************************/
418 static inline void __devinit
set_mtrr(struct intelfb_info
*dinfo
)
420 dinfo
->mtrr_reg
= mtrr_add(dinfo
->aperture
.physical
,
421 dinfo
->aperture
.size
, MTRR_TYPE_WRCOMB
, 1);
422 if (dinfo
->mtrr_reg
< 0) {
423 ERR_MSG("unable to set MTRR\n");
428 static inline void unset_mtrr(struct intelfb_info
*dinfo
)
431 mtrr_del(dinfo
->mtrr_reg
, dinfo
->aperture
.physical
,
432 dinfo
->aperture
.size
);
435 #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
437 #define unset_mtrr(x) do { } while (0)
438 #endif /* CONFIG_MTRR */
440 /***************************************************************
441 * driver init / cleanup *
442 ***************************************************************/
444 static void cleanup(struct intelfb_info
*dinfo
)
446 DBG_MSG("cleanup\n");
451 intelfbhw_disable_irq(dinfo
);
453 fb_dealloc_cmap(&dinfo
->info
->cmap
);
454 kfree(dinfo
->info
->pixmap
.addr
);
456 if (dinfo
->registered
)
457 unregister_framebuffer(dinfo
->info
);
461 if (dinfo
->fbmem_gart
&& dinfo
->gtt_fb_mem
) {
462 agp_unbind_memory(dinfo
->gtt_fb_mem
);
463 agp_free_memory(dinfo
->gtt_fb_mem
);
465 if (dinfo
->gtt_cursor_mem
) {
466 agp_unbind_memory(dinfo
->gtt_cursor_mem
);
467 agp_free_memory(dinfo
->gtt_cursor_mem
);
469 if (dinfo
->gtt_ring_mem
) {
470 agp_unbind_memory(dinfo
->gtt_ring_mem
);
471 agp_free_memory(dinfo
->gtt_ring_mem
);
474 #ifdef CONFIG_FB_INTEL_I2C
475 /* un-register I2C bus */
476 intelfb_delete_i2c_busses(dinfo
);
479 if (dinfo
->mmio_base
)
480 iounmap((void __iomem
*)dinfo
->mmio_base
);
481 if (dinfo
->aperture
.virtual)
482 iounmap((void __iomem
*)dinfo
->aperture
.virtual);
484 if (dinfo
->flag
& INTELFB_MMIO_ACQUIRED
)
485 release_mem_region(dinfo
->mmio_base_phys
, INTEL_REG_SIZE
);
486 if (dinfo
->flag
& INTELFB_FB_ACQUIRED
)
487 release_mem_region(dinfo
->aperture
.physical
,
488 dinfo
->aperture
.size
);
489 framebuffer_release(dinfo
->info
);
492 #define bailout(dinfo) do { \
493 DBG_MSG("bailout\n"); \
495 INF_MSG("Not going to register framebuffer, exiting...\n"); \
500 static int __devinit
intelfb_pci_register(struct pci_dev
*pdev
,
501 const struct pci_device_id
*ent
)
503 struct fb_info
*info
;
504 struct intelfb_info
*dinfo
;
506 int aperture_size
, stolen_size
;
507 struct agp_kern_info gtt_info
;
510 struct agp_bridge_data
*bridge
;
511 int aperture_bar
= 0;
515 DBG_MSG("intelfb_pci_register\n");
518 if (num_registered
!= 1) {
519 ERR_MSG("Attempted to register %d devices "
520 "(should be only 1).\n", num_registered
);
524 info
= framebuffer_alloc(sizeof(struct intelfb_info
), &pdev
->dev
);
526 ERR_MSG("Could not allocate memory for intelfb_info.\n");
529 if (fb_alloc_cmap(&info
->cmap
, 256, 1) < 0) {
530 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
537 dinfo
->fbops
= &intel_fb_ops
;
540 /* Reserve pixmap space. */
541 info
->pixmap
.addr
= kzalloc(64 * 1024, GFP_KERNEL
);
542 if (info
->pixmap
.addr
== NULL
) {
543 ERR_MSG("Cannot reserve pixmap memory.\n");
547 /* set early this option because it could be changed by tv encoder
549 dinfo
->fixed_mode
= fixed
;
552 if ((err
= pci_enable_device(pdev
))) {
553 ERR_MSG("Cannot enable device.\n");
558 /* Set base addresses. */
559 if ((ent
->device
== PCI_DEVICE_ID_INTEL_915G
) ||
560 (ent
->device
== PCI_DEVICE_ID_INTEL_915GM
) ||
561 (ent
->device
== PCI_DEVICE_ID_INTEL_945G
) ||
562 (ent
->device
== PCI_DEVICE_ID_INTEL_945GM
) ||
563 (ent
->device
== PCI_DEVICE_ID_INTEL_945GME
) ||
564 (ent
->device
== PCI_DEVICE_ID_INTEL_965G
) ||
565 (ent
->device
== PCI_DEVICE_ID_INTEL_965GM
)) {
570 dinfo
->aperture
.physical
= pci_resource_start(pdev
, aperture_bar
);
571 dinfo
->aperture
.size
= pci_resource_len(pdev
, aperture_bar
);
572 dinfo
->mmio_base_phys
= pci_resource_start(pdev
, mmio_bar
);
573 DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
574 (unsigned long long)pci_resource_start(pdev
, aperture_bar
),
575 (unsigned long long)pci_resource_len(pdev
, aperture_bar
),
576 (unsigned long long)pci_resource_start(pdev
, mmio_bar
),
577 (unsigned long long)pci_resource_len(pdev
, mmio_bar
));
579 /* Reserve the fb and MMIO regions */
580 if (!request_mem_region(dinfo
->aperture
.physical
, dinfo
->aperture
.size
,
581 INTELFB_MODULE_NAME
)) {
582 ERR_MSG("Cannot reserve FB region.\n");
587 dinfo
->flag
|= INTELFB_FB_ACQUIRED
;
589 if (!request_mem_region(dinfo
->mmio_base_phys
,
591 INTELFB_MODULE_NAME
)) {
592 ERR_MSG("Cannot reserve MMIO region.\n");
597 dinfo
->flag
|= INTELFB_MMIO_ACQUIRED
;
599 /* Get the chipset info. */
600 dinfo
->pci_chipset
= pdev
->device
;
602 if (intelfbhw_get_chipset(pdev
, dinfo
)) {
607 if (intelfbhw_get_memory(pdev
, &aperture_size
,&stolen_size
)) {
612 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
613 "stolen memory %dkB\n",
614 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
),
615 PCI_FUNC(pdev
->devfn
), dinfo
->name
,
616 BtoMB(aperture_size
), BtoKB(stolen_size
));
618 /* Set these from the options. */
619 dinfo
->accel
= accel
;
620 dinfo
->hwcursor
= hwcursor
;
622 if (NOACCEL_CHIPSET(dinfo
) && dinfo
->accel
== 1) {
623 INF_MSG("Acceleration is not supported for the %s chipset.\n",
628 /* Framebuffer parameters - Use all the stolen memory if >= vram */
629 if (ROUND_UP_TO_PAGE(stolen_size
) >= MB(vram
)) {
630 dinfo
->fb
.size
= ROUND_UP_TO_PAGE(stolen_size
);
631 dinfo
->fbmem_gart
= 0;
633 dinfo
->fb
.size
= MB(vram
);
634 dinfo
->fbmem_gart
= 1;
637 /* Allocate space for the ring buffer and HW cursor if enabled. */
639 dinfo
->ring
.size
= RINGBUFFER_SIZE
;
640 dinfo
->ring_tail_mask
= dinfo
->ring
.size
- 1;
643 dinfo
->cursor
.size
= HW_CURSOR_SIZE
;
645 /* Use agpgart to manage the GATT */
646 if (!(bridge
= agp_backend_acquire(pdev
))) {
647 ERR_MSG("cannot acquire agp\n");
652 /* get the current gatt info */
653 if (agp_copy_info(bridge
, >t_info
)) {
654 ERR_MSG("cannot get agp info\n");
655 agp_backend_release(bridge
);
660 if (MB(voffset
) < stolen_size
)
661 offset
= (stolen_size
>> 12);
663 offset
= ROUND_UP_TO_PAGE(MB(voffset
))/GTT_PAGE_SIZE
;
665 /* set the mem offsets - set them after the already used pages */
667 dinfo
->ring
.offset
= offset
+ gtt_info
.current_memory
;
669 dinfo
->cursor
.offset
= offset
+
670 + gtt_info
.current_memory
+ (dinfo
->ring
.size
>> 12);
671 if (dinfo
->fbmem_gart
)
672 dinfo
->fb
.offset
= offset
+
673 + gtt_info
.current_memory
+ (dinfo
->ring
.size
>> 12)
674 + (dinfo
->cursor
.size
>> 12);
676 /* Allocate memories (which aren't stolen) */
677 /* Map the fb and MMIO regions */
678 /* ioremap only up to the end of used aperture */
679 dinfo
->aperture
.virtual = (u8 __iomem
*)ioremap_nocache
680 (dinfo
->aperture
.physical
, ((offset
+ dinfo
->fb
.offset
) << 12)
682 if (!dinfo
->aperture
.virtual) {
683 ERR_MSG("Cannot remap FB region.\n");
689 (u8 __iomem
*)ioremap_nocache(dinfo
->mmio_base_phys
,
691 if (!dinfo
->mmio_base
) {
692 ERR_MSG("Cannot remap MMIO region.\n");
698 if (!(dinfo
->gtt_ring_mem
=
699 agp_allocate_memory(bridge
, dinfo
->ring
.size
>> 12,
700 AGP_NORMAL_MEMORY
))) {
701 ERR_MSG("cannot allocate ring buffer memory\n");
702 agp_backend_release(bridge
);
706 if (agp_bind_memory(dinfo
->gtt_ring_mem
,
707 dinfo
->ring
.offset
)) {
708 ERR_MSG("cannot bind ring buffer memory\n");
709 agp_backend_release(bridge
);
713 dinfo
->ring
.physical
= dinfo
->aperture
.physical
714 + (dinfo
->ring
.offset
<< 12);
715 dinfo
->ring
.virtual = dinfo
->aperture
.virtual
716 + (dinfo
->ring
.offset
<< 12);
717 dinfo
->ring_head
= 0;
719 if (dinfo
->hwcursor
) {
720 agp_memtype
= dinfo
->mobile
? AGP_PHYSICAL_MEMORY
722 if (!(dinfo
->gtt_cursor_mem
=
723 agp_allocate_memory(bridge
, dinfo
->cursor
.size
>> 12,
725 ERR_MSG("cannot allocate cursor memory\n");
726 agp_backend_release(bridge
);
730 if (agp_bind_memory(dinfo
->gtt_cursor_mem
,
731 dinfo
->cursor
.offset
)) {
732 ERR_MSG("cannot bind cursor memory\n");
733 agp_backend_release(bridge
);
738 dinfo
->cursor
.physical
739 = dinfo
->gtt_cursor_mem
->physical
;
741 dinfo
->cursor
.physical
= dinfo
->aperture
.physical
742 + (dinfo
->cursor
.offset
<< 12);
743 dinfo
->cursor
.virtual = dinfo
->aperture
.virtual
744 + (dinfo
->cursor
.offset
<< 12);
746 if (dinfo
->fbmem_gart
) {
747 if (!(dinfo
->gtt_fb_mem
=
748 agp_allocate_memory(bridge
, dinfo
->fb
.size
>> 12,
749 AGP_NORMAL_MEMORY
))) {
750 WRN_MSG("cannot allocate framebuffer memory - use "
752 dinfo
->fbmem_gart
= 0;
754 if (agp_bind_memory(dinfo
->gtt_fb_mem
,
756 WRN_MSG("cannot bind framebuffer memory - use "
758 dinfo
->fbmem_gart
= 0;
762 /* update framebuffer memory parameters */
763 if (!dinfo
->fbmem_gart
)
764 dinfo
->fb
.offset
= 0; /* starts at offset 0 */
765 dinfo
->fb
.physical
= dinfo
->aperture
.physical
766 + (dinfo
->fb
.offset
<< 12);
767 dinfo
->fb
.virtual = dinfo
->aperture
.virtual + (dinfo
->fb
.offset
<< 12);
768 dinfo
->fb_start
= dinfo
->fb
.offset
<< 12;
770 /* release agpgart */
771 agp_backend_release(bridge
);
776 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
777 dinfo
->fb
.physical
, dinfo
->fb
.offset
, dinfo
->fb
.size
,
779 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
780 dinfo
->mmio_base_phys
, INTEL_REG_SIZE
,
782 DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n",
783 dinfo
->ring
.physical
, dinfo
->ring
.size
,
784 dinfo
->ring
.virtual);
785 DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
786 dinfo
->cursor
.physical
, dinfo
->cursor
.size
,
787 dinfo
->cursor
.virtual, dinfo
->cursor
.offset
,
788 dinfo
->cursor
.physical
);
790 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
791 "noinit = %d\n", vram
, accel
, hwcursor
, fixed
, noinit
);
792 DBG_MSG("options: mode = \"%s\"\n", mode
? mode
: "");
798 * Check if the LVDS port or any DVO ports are enabled. If so,
799 * don't allow mode switching
801 dvo
= intelfbhw_check_non_crt(dinfo
);
803 dinfo
->fixed_mode
= 1;
804 WRN_MSG("Non-CRT device is enabled ( ");
808 s
= intelfbhw_dvo_to_string(1 << i
);
815 printk("). Disabling mode switching.\n");
821 if (FIXED_MODE(dinfo
) &&
822 screen_info
.orig_video_isVGA
!= VIDEO_TYPE_VLFB
) {
823 ERR_MSG("Video mode must be programmed at boot time.\n");
831 /* Initialise dinfo and related data. */
832 /* If an initial mode was programmed at boot time, get its details. */
833 if (screen_info
.orig_video_isVGA
== VIDEO_TYPE_VLFB
)
834 get_initial_mode(dinfo
);
839 if (FIXED_MODE(dinfo
)) /* remap fb address */
840 update_dinfo(dinfo
, &dinfo
->initial_var
);
846 if (intelfb_set_fbinfo(dinfo
)) {
854 #ifdef CONFIG_FB_INTEL_I2C
855 /* register I2C bus */
856 intelfb_create_i2c_busses(dinfo
);
862 pci_set_drvdata(pdev
, dinfo
);
864 /* Save the initial register state. */
865 i
= intelfbhw_read_hw_state(dinfo
, &dinfo
->save_state
,
866 bailearly
> 6 ? bailearly
- 6 : 0);
868 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i
);
872 intelfbhw_print_hw_state(dinfo
, &dinfo
->save_state
);
877 /* read active pipe */
878 dinfo
->pipe
= intelfbhw_active_pipe(&dinfo
->save_state
);
880 /* Cursor initialisation */
881 if (dinfo
->hwcursor
) {
882 intelfbhw_cursor_init(dinfo
);
883 intelfbhw_cursor_reset(dinfo
);
889 /* 2d acceleration init */
891 intelfbhw_2d_start(dinfo
);
899 if (register_framebuffer(dinfo
->info
) < 0) {
900 ERR_MSG("Cannot register framebuffer.\n");
905 dinfo
->registered
= 1;
908 init_waitqueue_head(&dinfo
->vsync
.wait
);
909 spin_lock_init(&dinfo
->int_lock
);
910 dinfo
->irq_flags
= 0;
911 dinfo
->vsync
.pan_display
= 0;
912 dinfo
->vsync
.pan_offset
= 0;
917 fb_dealloc_cmap(&info
->cmap
);
919 framebuffer_release(info
);
923 static void __devexit
924 intelfb_pci_unregister(struct pci_dev
*pdev
)
926 struct intelfb_info
*dinfo
= pci_get_drvdata(pdev
);
928 DBG_MSG("intelfb_pci_unregister\n");
935 pci_set_drvdata(pdev
, NULL
);
938 /***************************************************************
940 ***************************************************************/
942 int __inline__
intelfb_var_to_depth(const struct fb_var_screeninfo
*var
)
944 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
945 var
->bits_per_pixel
, var
->green
.length
);
947 switch (var
->bits_per_pixel
) {
949 return (var
->green
.length
== 6) ? 16 : 15;
953 return var
->bits_per_pixel
;
958 static __inline__
int var_to_refresh(const struct fb_var_screeninfo
*var
)
960 int xtot
= var
->xres
+ var
->left_margin
+ var
->right_margin
+
962 int ytot
= var
->yres
+ var
->upper_margin
+ var
->lower_margin
+
965 return (1000000000 / var
->pixclock
* 1000 + 500) / xtot
/ ytot
;
968 /***************************************************************
969 * Various intialisation functions *
970 ***************************************************************/
972 static void __devinit
get_initial_mode(struct intelfb_info
*dinfo
)
974 struct fb_var_screeninfo
*var
;
977 DBG_MSG("get_initial_mode\n");
979 dinfo
->initial_vga
= 1;
980 dinfo
->initial_fb_base
= screen_info
.lfb_base
;
981 dinfo
->initial_video_ram
= screen_info
.lfb_size
* KB(64);
982 dinfo
->initial_pitch
= screen_info
.lfb_linelength
;
984 var
= &dinfo
->initial_var
;
985 memset(var
, 0, sizeof(*var
));
986 var
->xres
= screen_info
.lfb_width
;
987 var
->yres
= screen_info
.lfb_height
;
988 var
->bits_per_pixel
= screen_info
.lfb_depth
;
989 switch (screen_info
.lfb_depth
) {
991 var
->bits_per_pixel
= 16;
994 var
->bits_per_pixel
= 32;
998 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
999 dinfo
->initial_fb_base
, dinfo
->initial_video_ram
,
1000 BtoKB(dinfo
->initial_video_ram
));
1002 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
1003 var
->xres
, var
->yres
, var
->bits_per_pixel
,
1004 dinfo
->initial_pitch
);
1006 /* Dummy timing values (assume 60Hz) */
1007 var
->left_margin
= (var
->xres
/ 8) & 0xf8;
1008 var
->right_margin
= 32;
1009 var
->upper_margin
= 16;
1010 var
->lower_margin
= 4;
1011 var
->hsync_len
= (var
->xres
/ 8) & 0xf8;
1014 xtot
= var
->xres
+ var
->left_margin
+
1015 var
->right_margin
+ var
->hsync_len
;
1016 ytot
= var
->yres
+ var
->upper_margin
+
1017 var
->lower_margin
+ var
->vsync_len
;
1018 var
->pixclock
= 10000000 / xtot
* 1000 / ytot
* 100 / 60;
1023 if (var
->bits_per_pixel
> 8) {
1024 var
->red
.offset
= screen_info
.red_pos
;
1025 var
->red
.length
= screen_info
.red_size
;
1026 var
->green
.offset
= screen_info
.green_pos
;
1027 var
->green
.length
= screen_info
.green_size
;
1028 var
->blue
.offset
= screen_info
.blue_pos
;
1029 var
->blue
.length
= screen_info
.blue_size
;
1030 var
->transp
.offset
= screen_info
.rsvd_pos
;
1031 var
->transp
.length
= screen_info
.rsvd_size
;
1033 var
->red
.length
= 8;
1034 var
->green
.length
= 8;
1035 var
->blue
.length
= 8;
1039 static int __devinit
intelfb_init_var(struct intelfb_info
*dinfo
)
1041 struct fb_var_screeninfo
*var
;
1044 DBG_MSG("intelfb_init_var\n");
1046 var
= &dinfo
->info
->var
;
1047 if (FIXED_MODE(dinfo
)) {
1048 memcpy(var
, &dinfo
->initial_var
,
1049 sizeof(struct fb_var_screeninfo
));
1052 const u8
*edid_s
= fb_firmware_edid(&dinfo
->pdev
->dev
);
1056 edid_d
= kmemdup(edid_s
, EDID_LENGTH
, GFP_KERNEL
);
1059 fb_edid_to_monspecs(edid_d
,
1060 &dinfo
->info
->monspecs
);
1066 printk("intelfb: Looking for mode in private "
1068 msrc
= fb_find_mode(var
, dinfo
->info
, mode
,
1069 dinfo
->info
->monspecs
.modedb
,
1070 dinfo
->info
->monspecs
.modedb_len
,
1073 if (msrc
&& msrc
> 1) {
1074 printk("intelfb: No mode in private database, "
1075 "intelfb: looking for mode in global "
1077 msrc
= fb_find_mode(var
, dinfo
->info
, mode
,
1087 msrc
= fb_find_mode(var
, dinfo
->info
, PREFERRED_MODE
,
1092 ERR_MSG("Cannot find a suitable video mode.\n");
1096 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var
->xres
, var
->yres
,
1097 var
->bits_per_pixel
, var_to_refresh(var
));
1099 DBG_MSG("Initial video mode is from %d.\n", msrc
);
1101 #if ALLOCATE_FOR_PANNING
1102 /* Allow use of half of the video ram for panning */
1103 var
->xres_virtual
= var
->xres
;
1105 dinfo
->fb
.size
/ 2 / (var
->bits_per_pixel
* var
->xres
);
1106 if (var
->yres_virtual
< var
->yres
)
1107 var
->yres_virtual
= var
->yres
;
1109 var
->yres_virtual
= var
->yres
;
1113 var
->accel_flags
|= FB_ACCELF_TEXT
;
1115 var
->accel_flags
&= ~FB_ACCELF_TEXT
;
1120 static int __devinit
intelfb_set_fbinfo(struct intelfb_info
*dinfo
)
1122 struct fb_info
*info
= dinfo
->info
;
1124 DBG_MSG("intelfb_set_fbinfo\n");
1126 info
->flags
= FBINFO_FLAG_DEFAULT
;
1127 info
->fbops
= &intel_fb_ops
;
1128 info
->pseudo_palette
= dinfo
->pseudo_palette
;
1130 info
->pixmap
.size
= 64*1024;
1131 info
->pixmap
.buf_align
= 8;
1132 info
->pixmap
.access_align
= 32;
1133 info
->pixmap
.flags
= FB_PIXMAP_SYSTEM
;
1135 if (intelfb_init_var(dinfo
))
1138 info
->pixmap
.scan_align
= 1;
1139 strcpy(info
->fix
.id
, dinfo
->name
);
1140 info
->fix
.smem_start
= dinfo
->fb
.physical
;
1141 info
->fix
.smem_len
= dinfo
->fb
.size
;
1142 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1143 info
->fix
.type_aux
= 0;
1144 info
->fix
.xpanstep
= 8;
1145 info
->fix
.ypanstep
= 1;
1146 info
->fix
.ywrapstep
= 0;
1147 info
->fix
.mmio_start
= dinfo
->mmio_base_phys
;
1148 info
->fix
.mmio_len
= INTEL_REG_SIZE
;
1149 info
->fix
.accel
= FB_ACCEL_I830
;
1150 update_dinfo(dinfo
, &info
->var
);
1155 /* Update dinfo to match the active video mode. */
1156 static void update_dinfo(struct intelfb_info
*dinfo
,
1157 struct fb_var_screeninfo
*var
)
1159 DBG_MSG("update_dinfo\n");
1161 dinfo
->bpp
= var
->bits_per_pixel
;
1162 dinfo
->depth
= intelfb_var_to_depth(var
);
1163 dinfo
->xres
= var
->xres
;
1164 dinfo
->yres
= var
->xres
;
1165 dinfo
->pixclock
= var
->pixclock
;
1167 dinfo
->info
->fix
.visual
= dinfo
->visual
;
1168 dinfo
->info
->fix
.line_length
= dinfo
->pitch
;
1170 switch (dinfo
->bpp
) {
1172 dinfo
->visual
= FB_VISUAL_PSEUDOCOLOR
;
1173 dinfo
->pitch
= var
->xres_virtual
;
1176 dinfo
->visual
= FB_VISUAL_TRUECOLOR
;
1177 dinfo
->pitch
= var
->xres_virtual
* 2;
1180 dinfo
->visual
= FB_VISUAL_TRUECOLOR
;
1181 dinfo
->pitch
= var
->xres_virtual
* 4;
1185 /* Make sure the line length is a aligned correctly. */
1187 dinfo
->pitch
= ROUND_UP_TO(dinfo
->pitch
, STRIDE_ALIGNMENT_I9XX
);
1189 dinfo
->pitch
= ROUND_UP_TO(dinfo
->pitch
, STRIDE_ALIGNMENT
);
1191 if (FIXED_MODE(dinfo
))
1192 dinfo
->pitch
= dinfo
->initial_pitch
;
1194 dinfo
->info
->screen_base
= (char __iomem
*)dinfo
->fb
.virtual;
1195 dinfo
->info
->fix
.line_length
= dinfo
->pitch
;
1196 dinfo
->info
->fix
.visual
= dinfo
->visual
;
1199 /* fbops functions */
1201 /***************************************************************
1203 ***************************************************************/
1205 static int intelfb_open(struct fb_info
*info
, int user
)
1207 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1215 static int intelfb_release(struct fb_info
*info
, int user
)
1217 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1223 intelfbhw_disable_irq(dinfo
);
1229 static int intelfb_check_var(struct fb_var_screeninfo
*var
,
1230 struct fb_info
*info
)
1233 struct fb_var_screeninfo v
;
1234 struct intelfb_info
*dinfo
;
1235 static int first
= 1;
1237 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1238 static const int pitches
[] = {
1246 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var
->accel_flags
);
1248 dinfo
= GET_DINFO(info
);
1250 /* update the pitch */
1251 if (intelfbhw_validate_mode(dinfo
, var
) != 0)
1256 for (i
= 0; pitches
[i
] != 0; i
++) {
1257 if (pitches
[i
] >= v
.xres_virtual
) {
1258 v
.xres_virtual
= pitches
[i
];
1263 /* Check for a supported bpp. */
1264 if (v
.bits_per_pixel
<= 8)
1265 v
.bits_per_pixel
= 8;
1266 else if (v
.bits_per_pixel
<= 16) {
1267 if (v
.bits_per_pixel
== 16)
1269 v
.bits_per_pixel
= 16;
1270 } else if (v
.bits_per_pixel
<= 32)
1271 v
.bits_per_pixel
= 32;
1275 change_var
= ((info
->var
.xres
!= var
->xres
) ||
1276 (info
->var
.yres
!= var
->yres
) ||
1277 (info
->var
.xres_virtual
!= var
->xres_virtual
) ||
1278 (info
->var
.yres_virtual
!= var
->yres_virtual
) ||
1279 (info
->var
.bits_per_pixel
!= var
->bits_per_pixel
) ||
1280 memcmp(&info
->var
.red
, &var
->red
, sizeof(var
->red
)) ||
1281 memcmp(&info
->var
.green
, &var
->green
,
1282 sizeof(var
->green
)) ||
1283 memcmp(&info
->var
.blue
, &var
->blue
, sizeof(var
->blue
)));
1285 if (FIXED_MODE(dinfo
) &&
1287 var
->yres_virtual
> dinfo
->initial_var
.yres_virtual
||
1288 var
->yres_virtual
< dinfo
->initial_var
.yres
||
1289 var
->xoffset
|| var
->nonstd
)) {
1291 ERR_MSG("Changing the video mode is not supported.\n");
1297 switch (intelfb_var_to_depth(&v
)) {
1299 v
.red
.offset
= v
.green
.offset
= v
.blue
.offset
= 0;
1300 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1301 v
.transp
.offset
= v
.transp
.length
= 0;
1307 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 5;
1308 v
.transp
.offset
= v
.transp
.length
= 0;
1317 v
.transp
.offset
= v
.transp
.length
= 0;
1323 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1324 v
.transp
.offset
= v
.transp
.length
= 0;
1330 v
.red
.length
= v
.green
.length
= v
.blue
.length
= 8;
1331 v
.transp
.offset
= 24;
1332 v
.transp
.length
= 8;
1341 if (v
.xoffset
> v
.xres_virtual
- v
.xres
)
1342 v
.xoffset
= v
.xres_virtual
- v
.xres
;
1343 if (v
.yoffset
> v
.yres_virtual
- v
.yres
)
1344 v
.yoffset
= v
.yres_virtual
- v
.yres
;
1346 v
.red
.msb_right
= v
.green
.msb_right
= v
.blue
.msb_right
=
1347 v
.transp
.msb_right
= 0;
1354 static int intelfb_set_par(struct fb_info
*info
)
1356 struct intelfb_hwstate
*hw
;
1357 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1359 if (FIXED_MODE(dinfo
)) {
1360 ERR_MSG("Changing the video mode is not supported.\n");
1364 hw
= kmalloc(sizeof(*hw
), GFP_ATOMIC
);
1368 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info
->var
.xres
,
1369 info
->var
.yres
, info
->var
.bits_per_pixel
);
1372 * Disable VCO prior to timing register change.
1374 OUTREG(DPLL_A
, INREG(DPLL_A
) & ~DPLL_VCO_ENABLE
);
1376 intelfb_blank(FB_BLANK_POWERDOWN
, info
);
1378 if (ACCEL(dinfo
, info
))
1379 intelfbhw_2d_stop(dinfo
);
1381 memcpy(hw
, &dinfo
->save_state
, sizeof(*hw
));
1382 if (intelfbhw_mode_to_hw(dinfo
, hw
, &info
->var
))
1384 if (intelfbhw_program_mode(dinfo
, hw
, 0))
1388 intelfbhw_read_hw_state(dinfo
, hw
, 0);
1389 intelfbhw_print_hw_state(dinfo
, hw
);
1392 update_dinfo(dinfo
, &info
->var
);
1394 if (ACCEL(dinfo
, info
))
1395 intelfbhw_2d_start(dinfo
);
1397 intelfb_pan_display(&info
->var
, info
);
1399 intelfb_blank(FB_BLANK_UNBLANK
, info
);
1401 if (ACCEL(dinfo
, info
)) {
1402 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
|
1403 FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
|
1404 FBINFO_HWACCEL_IMAGEBLIT
;
1406 info
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1415 static int intelfb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
1416 unsigned blue
, unsigned transp
,
1417 struct fb_info
*info
)
1419 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1422 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno
, dinfo
->depth
);
1428 if (dinfo
->depth
== 8) {
1433 intelfbhw_setcolreg(dinfo
, regno
, red
, green
, blue
,
1438 switch (dinfo
->depth
) {
1440 dinfo
->pseudo_palette
[regno
] = ((red
& 0xf800) >> 1) |
1441 ((green
& 0xf800) >> 6) |
1442 ((blue
& 0xf800) >> 11);
1445 dinfo
->pseudo_palette
[regno
] = (red
& 0xf800) |
1446 ((green
& 0xfc00) >> 5) |
1447 ((blue
& 0xf800) >> 11);
1450 dinfo
->pseudo_palette
[regno
] = ((red
& 0xff00) << 8) |
1452 ((blue
& 0xff00) >> 8);
1460 static int intelfb_blank(int blank
, struct fb_info
*info
)
1462 intelfbhw_do_blank(blank
, info
);
1466 static int intelfb_pan_display(struct fb_var_screeninfo
*var
,
1467 struct fb_info
*info
)
1469 intelfbhw_pan_display(var
, info
);
1473 /* When/if we have our own ioctls. */
1474 static int intelfb_ioctl(struct fb_info
*info
, unsigned int cmd
,
1478 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1482 case FBIO_WAITFORVSYNC
:
1483 if (get_user(pipe
, (__u32 __user
*)arg
))
1486 retval
= intelfbhw_wait_for_vsync(dinfo
, pipe
);
1495 static void intelfb_fillrect (struct fb_info
*info
,
1496 const struct fb_fillrect
*rect
)
1498 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1502 DBG_MSG("intelfb_fillrect\n");
1505 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4) {
1506 cfb_fillrect(info
, rect
);
1510 if (rect
->rop
== ROP_COPY
)
1511 rop
= PAT_ROP_GXCOPY
;
1513 rop
= PAT_ROP_GXXOR
;
1515 if (dinfo
->depth
!= 8)
1516 color
= dinfo
->pseudo_palette
[rect
->color
];
1518 color
= rect
->color
;
1520 intelfbhw_do_fillrect(dinfo
, rect
->dx
, rect
->dy
,
1521 rect
->width
, rect
->height
, color
,
1522 dinfo
->pitch
, info
->var
.bits_per_pixel
,
1526 static void intelfb_copyarea(struct fb_info
*info
,
1527 const struct fb_copyarea
*region
)
1529 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1532 DBG_MSG("intelfb_copyarea\n");
1535 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4) {
1536 cfb_copyarea(info
, region
);
1540 intelfbhw_do_bitblt(dinfo
, region
->sx
, region
->sy
, region
->dx
,
1541 region
->dy
, region
->width
, region
->height
,
1542 dinfo
->pitch
, info
->var
.bits_per_pixel
);
1545 static void intelfb_imageblit(struct fb_info
*info
,
1546 const struct fb_image
*image
)
1548 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1549 u32 fgcolor
, bgcolor
;
1552 DBG_MSG("intelfb_imageblit\n");
1555 if (!ACCEL(dinfo
, info
) || dinfo
->depth
== 4
1556 || image
->depth
!= 1) {
1557 cfb_imageblit(info
, image
);
1561 if (dinfo
->depth
!= 8) {
1562 fgcolor
= dinfo
->pseudo_palette
[image
->fg_color
];
1563 bgcolor
= dinfo
->pseudo_palette
[image
->bg_color
];
1565 fgcolor
= image
->fg_color
;
1566 bgcolor
= image
->bg_color
;
1569 if (!intelfbhw_do_drawglyph(dinfo
, fgcolor
, bgcolor
, image
->width
,
1570 image
->height
, image
->data
,
1571 image
->dx
, image
->dy
,
1572 dinfo
->pitch
, info
->var
.bits_per_pixel
)) {
1573 cfb_imageblit(info
, image
);
1578 static int intelfb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1580 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1583 DBG_MSG("intelfb_cursor\n");
1586 if (!dinfo
->hwcursor
)
1589 intelfbhw_cursor_hide(dinfo
);
1591 /* If XFree killed the cursor - restore it */
1592 physical
= (dinfo
->mobile
|| IS_I9XX(dinfo
)) ? dinfo
->cursor
.physical
:
1593 (dinfo
->cursor
.offset
<< 12);
1595 if (INREG(CURSOR_A_BASEADDR
) != physical
) {
1598 DBG_MSG("the cursor was killed - restore it !!\n");
1599 DBG_MSG("size %d, %d pos %d, %d\n",
1600 cursor
->image
.width
, cursor
->image
.height
,
1601 cursor
->image
.dx
, cursor
->image
.dy
);
1603 intelfbhw_cursor_init(dinfo
);
1604 intelfbhw_cursor_reset(dinfo
);
1605 intelfbhw_cursor_setpos(dinfo
, cursor
->image
.dx
,
1608 if (dinfo
->depth
!= 8) {
1609 fg
=dinfo
->pseudo_palette
[cursor
->image
.fg_color
];
1610 bg
=dinfo
->pseudo_palette
[cursor
->image
.bg_color
];
1612 fg
= cursor
->image
.fg_color
;
1613 bg
= cursor
->image
.bg_color
;
1615 intelfbhw_cursor_setcolor(dinfo
, bg
, fg
);
1616 intelfbhw_cursor_load(dinfo
, cursor
->image
.width
,
1617 cursor
->image
.height
,
1621 intelfbhw_cursor_show(dinfo
);
1625 if (cursor
->set
& FB_CUR_SETPOS
) {
1628 dx
= cursor
->image
.dx
- info
->var
.xoffset
;
1629 dy
= cursor
->image
.dy
- info
->var
.yoffset
;
1631 intelfbhw_cursor_setpos(dinfo
, dx
, dy
);
1634 if (cursor
->set
& FB_CUR_SETSIZE
) {
1635 if (cursor
->image
.width
> 64 || cursor
->image
.height
> 64)
1638 intelfbhw_cursor_reset(dinfo
);
1641 if (cursor
->set
& FB_CUR_SETCMAP
) {
1644 if (dinfo
->depth
!= 8) {
1645 fg
= dinfo
->pseudo_palette
[cursor
->image
.fg_color
];
1646 bg
= dinfo
->pseudo_palette
[cursor
->image
.bg_color
];
1648 fg
= cursor
->image
.fg_color
;
1649 bg
= cursor
->image
.bg_color
;
1652 intelfbhw_cursor_setcolor(dinfo
, bg
, fg
);
1655 if (cursor
->set
& (FB_CUR_SETSHAPE
| FB_CUR_SETIMAGE
)) {
1656 u32 s_pitch
= (ROUND_UP_TO(cursor
->image
.width
, 8) / 8);
1657 u32 size
= s_pitch
* cursor
->image
.height
;
1658 u8
*dat
= (u8
*) cursor
->image
.data
;
1659 u8
*msk
= (u8
*) cursor
->mask
;
1663 if (cursor
->image
.depth
!= 1)
1666 switch (cursor
->rop
) {
1668 for (i
= 0; i
< size
; i
++)
1669 src
[i
] = dat
[i
] ^ msk
[i
];
1673 for (i
= 0; i
< size
; i
++)
1674 src
[i
] = dat
[i
] & msk
[i
];
1678 /* save the bitmap to restore it when XFree will
1679 make the cursor dirty */
1680 memcpy(dinfo
->cursor_src
, src
, size
);
1682 intelfbhw_cursor_load(dinfo
, cursor
->image
.width
,
1683 cursor
->image
.height
, src
);
1687 intelfbhw_cursor_show(dinfo
);
1692 static int intelfb_sync(struct fb_info
*info
)
1694 struct intelfb_info
*dinfo
= GET_DINFO(info
);
1697 DBG_MSG("intelfb_sync\n");
1700 if (dinfo
->ring_lockup
)
1703 intelfbhw_do_sync(dinfo
);