pcmcia: CompactFlash driver for PA Semi Electra boards
[pv_ops_mirror.git] / drivers / video / intelfb / intelfbdrv.c
blob0428f211f1928b940cb4667220c8d845744c0239
1 /*
2 * intelfb
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>
8 * 2004 Sylvain Meyer
9 * 2006 David Airlie
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).
18 * Author: David Dawes
22 /* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */
25 * Changes:
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.
42 * (David Dawes)
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.
49 * (David Dawes)
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.
59 * (David Dawes)
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
71 * (David Dawes)
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.
76 * (David Dawes)
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
92 * Add mtrr support
94 * 10/2004 - Version 0.9.1
95 * Use module_param instead of old MODULE_PARM
96 * Some cleanup
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>
119 #include <asm/io.h>
121 #ifdef CONFIG_MTRR
122 #include <asm/mtrr.h>
123 #endif
125 #include "intelfb.h"
126 #include "intelfbhw.h"
127 #include "../edid.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
170 #else
171 #define INTELFB_CLASS_MASK 0
172 #endif
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 },
183 { 0, }
186 /* Global data */
187 static int num_registered = 0;
189 /* fb ops */
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 = {
209 .name = "intelfb",
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
219 " chipsets");
220 MODULE_LICENSE("Dual BSD/GPL");
221 MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
223 static int accel = 1;
224 static int vram = 4;
225 static int hwcursor = 0;
226 static int mtrr = 1;
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>]\"");
262 #ifndef MODULE
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)
269 const char *p;
270 int i;
271 char *ret;
273 p = OPT_STRVAL(this_opt, name);
274 i = 0;
275 while (p[i] && p[i] != ' ' && p[i] != ',')
276 i++;
277 ret = kmalloc(i + 1, GFP_KERNEL);
278 if (ret) {
279 strncpy(ret, p, i);
280 ret[i] = '\0';
282 return ret;
285 static __inline__ int get_opt_int(const char *this_opt, const char *name,
286 int *ret)
288 if (!ret)
289 return 0;
291 if (!OPT_EQUAL(this_opt, name))
292 return 0;
294 *ret = OPT_INTVAL(this_opt, name);
295 return 1;
298 static __inline__ int get_opt_bool(const char *this_opt, const char *name,
299 int *ret)
301 if (!ret)
302 return 0;
304 if (OPT_EQUAL(this_opt, name)) {
305 if (this_opt[strlen(name)] == '=')
306 *ret = simple_strtoul(this_opt + strlen(name) + 1,
307 NULL, 0);
308 else
309 *ret = 1;
310 } else {
311 if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name))
312 *ret = 0;
313 else
314 return 0;
316 return 1;
319 static int __init intelfb_setup(char *options)
321 char *this_opt;
323 DBG_MSG("intelfb_setup\n");
325 if (!options || !*options) {
326 DBG_MSG("no options\n");
327 return 0;
328 } else
329 DBG_MSG("options: %s\n", options);
332 * These are the built-in options analogous to the module parameters
333 * defined above.
335 * The syntax is:
337 * video=intelfb:[mode][,<param>=<val>] ...
339 * e.g.,
341 * video=intelfb:1024x768-16@75,accel=0
344 while ((this_opt = strsep(&options, ","))) {
345 if (!*this_opt)
346 continue;
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))
358 noinit = !noinit;
359 else if (OPT_EQUAL(this_opt, "mode="))
360 mode = get_opt_string(this_opt, "mode=");
361 else
362 mode = this_opt;
365 return 0;
368 #endif
370 static int __init intelfb_init(void)
372 #ifndef MODULE
373 char *option = NULL;
374 #endif
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");
382 if (idonly)
383 return -ENODEV;
385 #ifndef MODULE
386 if (fb_get_options("intelfb", &option))
387 return -ENODEV;
388 intelfb_setup(option);
389 #endif
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 ***************************************************************/
407 #ifdef CONFIG_MTRR
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");
414 return;
416 dinfo->has_mtrr = 1;
418 static inline void unset_mtrr(struct intelfb_info *dinfo)
420 if (dinfo->has_mtrr)
421 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
422 dinfo->aperture.size);
424 #else
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");
438 if (!dinfo)
439 return;
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);
449 unset_mtrr(dinfo);
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);
467 #endif
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"); \
484 cleanup(dinfo); \
485 INF_MSG("Not going to register framebuffer, exiting...\n"); \
486 return -ENODEV; \
487 } while (0)
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;
495 int i, err, dvo;
496 int aperture_size, stolen_size;
497 struct agp_kern_info gtt_info;
498 int agp_memtype;
499 const char *s;
500 struct agp_bridge_data *bridge;
501 int aperture_bar = 0;
502 int mmio_bar = 1;
503 int offset;
505 DBG_MSG("intelfb_pci_register\n");
507 num_registered++;
508 if (num_registered != 1) {
509 ERR_MSG("Attempted to register %d devices "
510 "(should be only 1).\n", num_registered);
511 return -ENODEV;
514 info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
515 if (!info) {
516 ERR_MSG("Could not allocate memory for intelfb_info.\n");
517 return -ENODEV;
519 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
520 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
521 goto err_out_cmap;
522 return -ENODEV;
525 dinfo = info->par;
526 dinfo->info = info;
527 dinfo->fbops = &intel_fb_ops;
528 dinfo->pdev = pdev;
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");
534 goto err_out_pixmap;
537 /* set early this option because it could be changed by tv encoder
538 driver */
539 dinfo->fixed_mode = fixed;
541 /* Enable device. */
542 if ((err = pci_enable_device(pdev))) {
543 ERR_MSG("Cannot enable device.\n");
544 cleanup(dinfo);
545 return -ENODEV;
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)) {
553 aperture_bar = 2;
554 mmio_bar = 0;
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");
569 cleanup(dinfo);
570 return -ENODEV;
573 dinfo->flag |= INTELFB_FB_ACQUIRED;
575 if (!request_mem_region(dinfo->mmio_base_phys,
576 INTEL_REG_SIZE,
577 INTELFB_MODULE_NAME)) {
578 ERR_MSG("Cannot reserve MMIO region.\n");
579 cleanup(dinfo);
580 return -ENODEV;
583 dinfo->flag |= INTELFB_MMIO_ACQUIRED;
585 /* Get the chipset info. */
586 dinfo->pci_chipset = pdev->device;
588 if (intelfbhw_get_chipset(pdev, dinfo)) {
589 cleanup(dinfo);
590 return -ENODEV;
593 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
594 cleanup(dinfo);
595 return -ENODEV;
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",
610 dinfo->name);
611 dinfo->accel = 0;
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;
618 } else {
619 dinfo->fb.size = MB(vram);
620 dinfo->fbmem_gart = 1;
623 /* Allocate space for the ring buffer and HW cursor if enabled. */
624 if (dinfo->accel) {
625 dinfo->ring.size = RINGBUFFER_SIZE;
626 dinfo->ring_tail_mask = dinfo->ring.size - 1;
628 if (dinfo->hwcursor)
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");
634 cleanup(dinfo);
635 return -ENODEV;
638 /* get the current gatt info */
639 if (agp_copy_info(bridge, &gtt_info)) {
640 ERR_MSG("cannot get agp info\n");
641 agp_backend_release(bridge);
642 cleanup(dinfo);
643 return -ENODEV;
646 if (MB(voffset) < stolen_size)
647 offset = (stolen_size >> 12);
648 else
649 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
651 /* set the mem offsets - set them after the already used pages */
652 if (dinfo->accel)
653 dinfo->ring.offset = offset + gtt_info.current_memory;
654 if (dinfo->hwcursor)
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)
667 + dinfo->fb.size);
668 if (!dinfo->aperture.virtual) {
669 ERR_MSG("Cannot remap FB region.\n");
670 cleanup(dinfo);
671 return -ENODEV;
674 dinfo->mmio_base =
675 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
676 INTEL_REG_SIZE);
677 if (!dinfo->mmio_base) {
678 ERR_MSG("Cannot remap MMIO region.\n");
679 cleanup(dinfo);
680 return -ENODEV;
683 if (dinfo->accel) {
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);
689 cleanup(dinfo);
690 return -ENOMEM;
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);
696 cleanup(dinfo);
697 return -EBUSY;
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
707 : AGP_NORMAL_MEMORY;
708 if (!(dinfo->gtt_cursor_mem =
709 agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
710 agp_memtype))) {
711 ERR_MSG("cannot allocate cursor memory\n");
712 agp_backend_release(bridge);
713 cleanup(dinfo);
714 return -ENOMEM;
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);
720 cleanup(dinfo);
721 return -EBUSY;
723 if (dinfo->mobile)
724 dinfo->cursor.physical
725 = dinfo->gtt_cursor_mem->physical;
726 else
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 "
737 "the stolen one\n");
738 dinfo->fbmem_gart = 0;
740 if (agp_bind_memory(dinfo->gtt_fb_mem,
741 dinfo->fb.offset)) {
742 WRN_MSG("cannot bind framebuffer memory - use "
743 "the stolen one\n");
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);
759 if (mtrr)
760 set_mtrr(dinfo);
762 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
763 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
764 dinfo->fb.virtual);
765 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
766 dinfo->mmio_base_phys, INTEL_REG_SIZE,
767 dinfo->mmio_base);
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 : "");
780 if (probeonly)
781 bailout(dinfo);
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);
788 if (dvo) {
789 dinfo->fixed_mode = 1;
790 WRN_MSG("Non-CRT device is enabled ( ");
791 i = 0;
792 while (dvo) {
793 if (dvo & 1) {
794 s = intelfbhw_dvo_to_string(1 << i);
795 if (s)
796 printk("%s ", s);
798 dvo >>= 1;
799 ++i;
801 printk("). Disabling mode switching.\n");
804 if (bailearly == 1)
805 bailout(dinfo);
807 if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) {
808 ERR_MSG("Video mode must be programmed at boot time.\n");
809 cleanup(dinfo);
810 return -ENODEV;
813 if (bailearly == 2)
814 bailout(dinfo);
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);
821 if (bailearly == 3)
822 bailout(dinfo);
824 if (FIXED_MODE(dinfo)) /* remap fb address */
825 update_dinfo(dinfo, &dinfo->initial_var);
827 if (bailearly == 4)
828 bailout(dinfo);
831 if (intelfb_set_fbinfo(dinfo)) {
832 cleanup(dinfo);
833 return -ENODEV;
836 if (bailearly == 5)
837 bailout(dinfo);
839 #ifdef CONFIG_FB_INTEL_I2C
840 /* register I2C bus */
841 intelfb_create_i2c_busses(dinfo);
842 #endif
844 if (bailearly == 6)
845 bailout(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);
852 if (i != 0) {
853 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
854 bailout(dinfo);
857 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
859 if (bailearly == 18)
860 bailout(dinfo);
862 /* Cursor initialisation */
863 if (dinfo->hwcursor) {
864 intelfbhw_cursor_init(dinfo);
865 intelfbhw_cursor_reset(dinfo);
868 if (bailearly == 19)
869 bailout(dinfo);
871 /* 2d acceleration init */
872 if (dinfo->accel)
873 intelfbhw_2d_start(dinfo);
875 if (bailearly == 20)
876 bailout(dinfo);
878 if (noregister)
879 bailout(dinfo);
881 if (register_framebuffer(dinfo->info) < 0) {
882 ERR_MSG("Cannot register framebuffer.\n");
883 cleanup(dinfo);
884 return -ENODEV;
887 dinfo->registered = 1;
888 dinfo->open = 0;
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;
896 return 0;
898 err_out_pixmap:
899 fb_dealloc_cmap(&info->cmap);
900 err_out_cmap:
901 framebuffer_release(info);
902 return -ENODEV;
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");
912 if (!dinfo)
913 return;
915 cleanup(dinfo);
917 pci_set_drvdata(pdev, NULL);
920 /***************************************************************
921 * helper functions *
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) {
930 case 16:
931 return (var->green.length == 6) ? 16 : 15;
932 case 32:
933 return 24;
934 default:
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 +
943 var->hsync_len;
944 int ytot = var->yres + var->upper_margin + var->lower_margin +
945 var->vsync_len;
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;
957 int xtot, ytot;
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) {
972 case 15:
973 var->bits_per_pixel = 16;
974 break;
975 case 24:
976 var->bits_per_pixel = 32;
977 break;
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;
994 var->vsync_len = 4;
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;
1002 var->height = -1;
1003 var->width = -1;
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;
1014 } else {
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;
1024 int msrc = 0;
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));
1032 msrc = 5;
1033 } else {
1034 const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev);
1035 u8 *edid_d = NULL;
1037 if (edid_s) {
1038 edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL);
1040 if (edid_d) {
1041 fb_edid_to_monspecs(edid_d,
1042 &dinfo->info->monspecs);
1043 kfree(edid_d);
1047 if (mode) {
1048 printk("intelfb: Looking for mode in private "
1049 "database\n");
1050 msrc = fb_find_mode(var, dinfo->info, mode,
1051 dinfo->info->monspecs.modedb,
1052 dinfo->info->monspecs.modedb_len,
1053 NULL, 0);
1055 if (msrc && msrc > 1) {
1056 printk("intelfb: No mode in private database, "
1057 "intelfb: looking for mode in global "
1058 "database ");
1059 msrc = fb_find_mode(var, dinfo->info, mode,
1060 NULL, 0, NULL, 0);
1062 if (msrc)
1063 msrc |= 8;
1068 if (!msrc)
1069 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
1070 NULL, 0, NULL, 0);
1073 if (!msrc) {
1074 ERR_MSG("Cannot find a suitable video mode.\n");
1075 return 1;
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;
1086 var->yres_virtual =
1087 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1088 if (var->yres_virtual < var->yres)
1089 var->yres_virtual = var->yres;
1090 #else
1091 var->yres_virtual = var->yres;
1092 #endif
1094 if (dinfo->accel)
1095 var->accel_flags |= FB_ACCELF_TEXT;
1096 else
1097 var->accel_flags &= ~FB_ACCELF_TEXT;
1099 return 0;
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))
1118 return 1;
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);
1134 return 0;
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) {
1153 case 8:
1154 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1155 dinfo->pitch = var->xres_virtual;
1156 break;
1157 case 16:
1158 dinfo->visual = FB_VISUAL_TRUECOLOR;
1159 dinfo->pitch = var->xres_virtual * 2;
1160 break;
1161 case 32:
1162 dinfo->visual = FB_VISUAL_TRUECOLOR;
1163 dinfo->pitch = var->xres_virtual * 4;
1164 break;
1167 /* Make sure the line length is a aligned correctly. */
1168 if (IS_I9XX(dinfo))
1169 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX);
1170 else
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 /***************************************************************
1184 * fbdev interface *
1185 ***************************************************************/
1187 static int intelfb_open(struct fb_info *info, int user)
1189 struct intelfb_info *dinfo = GET_DINFO(info);
1191 if (user)
1192 dinfo->open++;
1194 return 0;
1197 static int intelfb_release(struct fb_info *info, int user)
1199 struct intelfb_info *dinfo = GET_DINFO(info);
1201 if (user) {
1202 dinfo->open--;
1203 msleep(1);
1204 if (!dinfo->open)
1205 intelfbhw_disable_irq(dinfo);
1208 return 0;
1211 static int intelfb_check_var(struct fb_var_screeninfo *var,
1212 struct fb_info *info)
1214 int change_var = 0;
1215 struct fb_var_screeninfo v;
1216 struct intelfb_info *dinfo;
1217 static int first = 1;
1218 int i;
1219 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1220 static const int pitches[] = {
1221 128 * 8,
1222 128 * 16,
1223 128 * 32,
1224 128 * 64,
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)
1234 return -EINVAL;
1236 v = *var;
1238 for (i = 0; pitches[i] != 0; i++) {
1239 if (pitches[i] >= v.xres_virtual) {
1240 v.xres_virtual = pitches[i];
1241 break;
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)
1250 v.green.length = 6;
1251 v.bits_per_pixel = 16;
1252 } else if (v.bits_per_pixel <= 32)
1253 v.bits_per_pixel = 32;
1254 else
1255 return -EINVAL;
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) &&
1268 (change_var ||
1269 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1270 var->yres_virtual < dinfo->initial_var.yres ||
1271 var->xoffset || var->nonstd)) {
1272 if (first) {
1273 ERR_MSG("Changing the video mode is not supported.\n");
1274 first = 0;
1276 return -EINVAL;
1279 switch (intelfb_var_to_depth(&v)) {
1280 case 8:
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;
1284 break;
1285 case 15:
1286 v.red.offset = 10;
1287 v.green.offset = 5;
1288 v.blue.offset = 0;
1289 v.red.length = v.green.length = v.blue.length = 5;
1290 v.transp.offset = v.transp.length = 0;
1291 break;
1292 case 16:
1293 v.red.offset = 11;
1294 v.green.offset = 5;
1295 v.blue.offset = 0;
1296 v.red.length = 5;
1297 v.green.length = 6;
1298 v.blue.length = 5;
1299 v.transp.offset = v.transp.length = 0;
1300 break;
1301 case 24:
1302 v.red.offset = 16;
1303 v.green.offset = 8;
1304 v.blue.offset = 0;
1305 v.red.length = v.green.length = v.blue.length = 8;
1306 v.transp.offset = v.transp.length = 0;
1307 break;
1308 case 32:
1309 v.red.offset = 16;
1310 v.green.offset = 8;
1311 v.blue.offset = 0;
1312 v.red.length = v.green.length = v.blue.length = 8;
1313 v.transp.offset = 24;
1314 v.transp.length = 8;
1315 break;
1318 if (v.xoffset < 0)
1319 v.xoffset = 0;
1320 if (v.yoffset < 0)
1321 v.yoffset = 0;
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;
1331 *var = v;
1333 return 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");
1343 return -EINVAL;
1346 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1347 if (!hw)
1348 return -ENOMEM;
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))
1360 goto invalid_mode;
1361 if (intelfbhw_program_mode(dinfo, hw, 0))
1362 goto invalid_mode;
1364 #if REGDUMP > 0
1365 intelfbhw_read_hw_state(dinfo, hw, 0);
1366 intelfbhw_print_hw_state(dinfo, hw);
1367 #endif
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;
1382 } else
1383 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1385 kfree(hw);
1386 return 0;
1387 invalid_mode:
1388 kfree(hw);
1389 return -EINVAL;
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);
1398 #if VERBOSE > 0
1399 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1400 #endif
1402 if (regno > 255)
1403 return 1;
1405 if (dinfo->depth == 8) {
1406 red >>= 8;
1407 green >>= 8;
1408 blue >>= 8;
1410 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1411 transp);
1414 if (regno < 16) {
1415 switch (dinfo->depth) {
1416 case 15:
1417 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1418 ((green & 0xf800) >> 6) |
1419 ((blue & 0xf800) >> 11);
1420 break;
1421 case 16:
1422 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1423 ((green & 0xfc00) >> 5) |
1424 ((blue & 0xf800) >> 11);
1425 break;
1426 case 24:
1427 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1428 (green & 0xff00) |
1429 ((blue & 0xff00) >> 8);
1430 break;
1434 return 0;
1437 static int intelfb_blank(int blank, struct fb_info *info)
1439 intelfbhw_do_blank(blank, info);
1440 return 0;
1443 static int intelfb_pan_display(struct fb_var_screeninfo *var,
1444 struct fb_info *info)
1446 intelfbhw_pan_display(var, info);
1447 return 0;
1450 /* When/if we have our own ioctls. */
1451 static int intelfb_ioctl(struct fb_info *info, unsigned int cmd,
1452 unsigned long arg)
1454 int retval = 0;
1455 struct intelfb_info *dinfo = GET_DINFO(info);
1456 u32 pipe = 0;
1458 switch (cmd) {
1459 case FBIO_WAITFORVSYNC:
1460 if (get_user(pipe, (__u32 __user *)arg))
1461 return -EFAULT;
1463 retval = intelfbhw_wait_for_vsync(dinfo, pipe);
1464 break;
1465 default:
1466 break;
1469 return retval;
1472 static void intelfb_fillrect (struct fb_info *info,
1473 const struct fb_fillrect *rect)
1475 struct intelfb_info *dinfo = GET_DINFO(info);
1476 u32 rop, color;
1478 #if VERBOSE > 0
1479 DBG_MSG("intelfb_fillrect\n");
1480 #endif
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;
1487 else /* ROP_XOR */
1488 rop = PAT_ROP_GXXOR;
1490 if (dinfo->depth != 8)
1491 color = dinfo->pseudo_palette[rect->color];
1492 else
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,
1498 rop);
1501 static void intelfb_copyarea(struct fb_info *info,
1502 const struct fb_copyarea *region)
1504 struct intelfb_info *dinfo = GET_DINFO(info);
1506 #if VERBOSE > 0
1507 DBG_MSG("intelfb_copyarea\n");
1508 #endif
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;
1524 #if VERBOSE > 0
1525 DBG_MSG("intelfb_imageblit\n");
1526 #endif
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];
1535 } else {
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);
1550 u32 physical;
1551 #if VERBOSE > 0
1552 DBG_MSG("intelfb_cursor\n");
1553 #endif
1555 if (!dinfo->hwcursor)
1556 return -ENODEV;
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) {
1565 u32 fg, bg;
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,
1575 cursor->image.dy);
1577 if (dinfo->depth != 8) {
1578 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1579 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1580 } else {
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,
1587 dinfo->cursor_src);
1589 if (cursor->enable)
1590 intelfbhw_cursor_show(dinfo);
1591 return 0;
1594 if (cursor->set & FB_CUR_SETPOS) {
1595 u32 dx, dy;
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)
1605 return -ENXIO;
1607 intelfbhw_cursor_reset(dinfo);
1610 if (cursor->set & FB_CUR_SETCMAP) {
1611 u32 fg, bg;
1613 if (dinfo->depth != 8) {
1614 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1615 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1616 } else {
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;
1629 u8 src[64];
1630 u32 i;
1632 if (cursor->image.depth != 1)
1633 return -ENXIO;
1635 switch (cursor->rop) {
1636 case ROP_XOR:
1637 for (i = 0; i < size; i++)
1638 src[i] = dat[i] ^ msk[i];
1639 break;
1640 case ROP_COPY:
1641 default:
1642 for (i = 0; i < size; i++)
1643 src[i] = dat[i] & msk[i];
1644 break;
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);
1655 if (cursor->enable)
1656 intelfbhw_cursor_show(dinfo);
1658 return 0;
1661 static int intelfb_sync(struct fb_info *info)
1663 struct intelfb_info *dinfo = GET_DINFO(info);
1665 #if VERBOSE > 0
1666 DBG_MSG("intelfb_sync\n");
1667 #endif
1669 if (dinfo->ring_lockup)
1670 return 0;
1672 intelfbhw_do_sync(dinfo);
1673 return 0;