blob: 0428f211f1928b940cb4667220c8d845744c0239 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * intelfb
3 *
Dave Airlie9639d5e2006-03-23 11:23:55 +11004 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/
Dave Airlie9a906032006-03-23 21:53:05 +11005 * 945G/945GM integrated graphics chips.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
8 * 2004 Sylvain Meyer
Dave Airlie8bb91f62006-03-23 13:06:32 +11009 * 2006 David Airlie
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
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).
17 *
18 * Author: David Dawes
19 *
20 */
21
22/* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */
23
24/*
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)
31 *
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)
35 *
36 * 01/2003 - Version 0.3.0: fbcon acceleration support added. Module
37 * option handling added. (David Dawes)
38 *
39 * 01/2003 - Version 0.4.0: fbcon HW cursor support added. (David Dawes)
40 *
41 * 01/2003 - Version 0.4.1: Add auto-generation of built-in modes.
42 * (David Dawes)
43 *
44 * 02/2003 - Version 0.4.2: Add check for active non-CRT devices, and
45 * mode validation checks. (David Dawes)
46 *
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)
50 *
51 * 02/2003 - Version 0.4.4: Monitor DPMS support. (David Dawes)
52 *
53 * 02/2003 - Version 0.4.5: Basic XFree86 + fbdev working. (David Dawes)
54 *
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)
57 *
58 * 02/2003 - Version 0.6.0: Split out HW-specifics into a separate file.
59 * (David Dawes)
60 *
61 * 02/2003 - Version 0.7.0: Test on 852GM/855GM. Acceleration and HW
62 * cursor are disabled on this platform. (David Dawes)
63 *
64 * 02/2003 - Version 0.7.1: Test on 845G. Acceleration is disabled
65 * on this platform. (David Dawes)
66 *
67 * 02/2003 - Version 0.7.2: Test on 830M. Acceleration and HW
68 * cursor are disabled on this platform. (David Dawes)
69 *
70 * 02/2003 - Version 0.7.3: Fix 8-bit modes for mobile platforms
71 * (David Dawes)
72 *
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)
77 *
78 * 02/2003 - Version 0.7.5: Add basic package/install scripts based on the
79 * DRI packaging scripts. (David Dawes)
80 *
81 * 04/2003 - Version 0.7.6: Fix typo that affects builds with SMP-enabled
82 * kernels. (David Dawes, reported by Anupam).
83 *
84 * 06/2003 - Version 0.7.7:
85 * Fix Makefile.kernel build problem (Tsutomu Yasuda).
86 * Fix mis-placed #endif (2.4.21 kernel).
87 *
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
93 *
94 * 10/2004 - Version 0.9.1
95 * Use module_param instead of old MODULE_PARM
96 * Some cleanup
97 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 */
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#include <linux/module.h>
105#include <linux/kernel.h>
106#include <linux/errno.h>
107#include <linux/string.h>
108#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#include <linux/slab.h>
110#include <linux/delay.h>
111#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#include <linux/ioport.h>
113#include <linux/init.h>
114#include <linux/pci.h>
115#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#include <linux/pagemap.h>
Jon Smirla8f340e2006-07-10 04:44:12 -0700117#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119#include <asm/io.h>
120
121#ifdef CONFIG_MTRR
122#include <asm/mtrr.h>
123#endif
124
125#include "intelfb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#include "intelfbhw.h"
Antonino A. Daplas56e004e2006-05-29 18:49:08 +1000127#include "../edid.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Adrian Bunk14c6f522005-05-01 08:59:23 -0700129static void __devinit get_initial_mode(struct intelfb_info *dinfo);
130static void update_dinfo(struct intelfb_info *dinfo,
131 struct fb_var_screeninfo *var);
Eric Hustvedt76497572006-06-20 14:36:41 -0400132static int intelfb_open(struct fb_info *info, int user);
133static int intelfb_release(struct fb_info *info, int user);
Adrian Bunk14c6f522005-05-01 08:59:23 -0700134static int intelfb_check_var(struct fb_var_screeninfo *var,
135 struct fb_info *info);
136static int intelfb_set_par(struct fb_info *info);
137static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
138 unsigned blue, unsigned transp,
139 struct fb_info *info);
140
141static int intelfb_blank(int blank, struct fb_info *info);
142static int intelfb_pan_display(struct fb_var_screeninfo *var,
143 struct fb_info *info);
144
145static void intelfb_fillrect(struct fb_info *info,
146 const struct fb_fillrect *rect);
147static void intelfb_copyarea(struct fb_info *info,
148 const struct fb_copyarea *region);
149static void intelfb_imageblit(struct fb_info *info,
150 const struct fb_image *image);
151static int intelfb_cursor(struct fb_info *info,
152 struct fb_cursor *cursor);
153
154static int intelfb_sync(struct fb_info *info);
155
Christoph Hellwig67a66802006-01-14 13:21:25 -0800156static int intelfb_ioctl(struct fb_info *info,
157 unsigned int cmd, unsigned long arg);
Adrian Bunk14c6f522005-05-01 08:59:23 -0700158
159static int __devinit intelfb_pci_register(struct pci_dev *pdev,
160 const struct pci_device_id *ent);
161static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
162static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*
165 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
166 * mobile chipsets from being registered.
167 */
168#if DETECT_VGA_CLASS_ONLY
169#define INTELFB_CLASS_MASK ~0 << 8
170#else
171#define INTELFB_CLASS_MASK 0
172#endif
173
174static 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 },
Scott MacKenzie3a590262005-11-07 01:00:33 -0800180 { 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 },
Dave Airlie9639d5e2006-03-23 11:23:55 +1100181 { 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 },
Dave Airlie9a906032006-03-23 21:53:05 +1100182 { 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 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 { 0, }
184};
185
186/* Global data */
187static int num_registered = 0;
188
189/* fb ops */
190static struct fb_ops intel_fb_ops = {
191 .owner = THIS_MODULE,
Eric Hustvedt76497572006-06-20 14:36:41 -0400192 .fb_open = intelfb_open,
193 .fb_release = intelfb_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 .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
205};
206
207/* PCI driver module table */
208static struct pci_driver intelfb_driver = {
Andrew Morton5a3b5892005-06-21 17:16:57 -0700209 .name = "intelfb",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .id_table = intelfb_pci_table,
211 .probe = intelfb_pci_register,
212 .remove = __devexit_p(intelfb_pci_unregister)
213};
214
215/* Module description/parameters */
216MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
217 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700218MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS
219 " chipsets");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220MODULE_LICENSE("Dual BSD/GPL");
221MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
222
Patrick McManus346e3992005-05-28 15:51:46 -0700223static int accel = 1;
224static int vram = 4;
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800225static int hwcursor = 0;
Patrick McManus346e3992005-05-28 15:51:46 -0700226static int mtrr = 1;
227static int fixed = 0;
228static int noinit = 0;
229static int noregister = 0;
230static int probeonly = 0;
231static int idonly = 0;
232static int bailearly = 0;
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700233static int voffset = 48;
Patrick McManus346e3992005-05-28 15:51:46 -0700234static char *mode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236module_param(accel, bool, S_IRUGO);
James Simmons4c7ffe02005-09-09 13:04:31 -0700237MODULE_PARM_DESC(accel, "Enable hardware acceleration");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238module_param(vram, int, S_IRUGO);
239MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700240module_param(voffset, int, S_IRUGO);
241MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242module_param(hwcursor, bool, S_IRUGO);
243MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
244module_param(mtrr, bool, S_IRUGO);
245MODULE_PARM_DESC(mtrr, "Enable MTRR support");
246module_param(fixed, bool, S_IRUGO);
247MODULE_PARM_DESC(fixed, "Disable mode switching");
248module_param(noinit, bool, 0);
249MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
250module_param(noregister, bool, 0);
251MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
252module_param(probeonly, bool, 0);
253MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
254module_param(idonly, bool, 0);
255MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
256module_param(bailearly, bool, 0);
257MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
258module_param(mode, charp, S_IRUGO);
259MODULE_PARM_DESC(mode,
260 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
261
262#ifndef MODULE
263#define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
Eric Hustvedt65eb2f92006-05-29 18:38:55 +1000264#define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#define OPT_STRVAL(opt, name) (opt + strlen(name))
266
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700267static __inline__ char * get_opt_string(const char *this_opt, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 const char *p;
270 int i;
271 char *ret;
272
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';
281 }
282 return ret;
283}
284
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700285static __inline__ int get_opt_int(const char *this_opt, const char *name,
286 int *ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 if (!ret)
289 return 0;
290
291 if (!OPT_EQUAL(this_opt, name))
292 return 0;
293
294 *ret = OPT_INTVAL(this_opt, name);
295 return 1;
296}
297
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700298static __inline__ int get_opt_bool(const char *this_opt, const char *name,
299 int *ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 if (!ret)
302 return 0;
303
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;
315 }
316 return 1;
317}
318
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700319static int __init intelfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 char *this_opt;
322
323 DBG_MSG("intelfb_setup\n");
324
325 if (!options || !*options) {
326 DBG_MSG("no options\n");
327 return 0;
328 } else
329 DBG_MSG("options: %s\n", options);
330
331 /*
332 * These are the built-in options analogous to the module parameters
333 * defined above.
334 *
335 * The syntax is:
336 *
337 * video=intelfb:[mode][,<param>=<val>] ...
338 *
339 * e.g.,
340 *
341 * video=intelfb:1024x768-16@75,accel=0
342 */
343
344 while ((this_opt = strsep(&options, ","))) {
345 if (!*this_opt)
346 continue;
347 if (get_opt_bool(this_opt, "accel", &accel))
348 ;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700349 else if (get_opt_int(this_opt, "vram", &vram))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 ;
351 else if (get_opt_bool(this_opt, "hwcursor", &hwcursor))
352 ;
353 else if (get_opt_bool(this_opt, "mtrr", &mtrr))
354 ;
355 else if (get_opt_bool(this_opt, "fixed", &fixed))
356 ;
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;
363 }
364
365 return 0;
366}
367
368#endif
369
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700370static int __init intelfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372#ifndef MODULE
373 char *option = NULL;
374#endif
375
376 DBG_MSG("intelfb_init\n");
377
378 INF_MSG("Framebuffer driver for "
379 "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
380 INF_MSG("Version " INTELFB_VERSION "\n");
381
382 if (idonly)
383 return -ENODEV;
384
385#ifndef MODULE
386 if (fb_get_options("intelfb", &option))
387 return -ENODEV;
388 intelfb_setup(option);
389#endif
390
391 return pci_register_driver(&intelfb_driver);
392}
393
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700394static void __exit intelfb_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 DBG_MSG("intelfb_exit\n");
397 pci_unregister_driver(&intelfb_driver);
398}
399
400module_init(intelfb_init);
401module_exit(intelfb_exit);
402
403/***************************************************************
404 * mtrr support functions *
405 ***************************************************************/
406
407#ifdef CONFIG_MTRR
408static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
409{
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;
415 }
416 dinfo->has_mtrr = 1;
417}
418static inline void unset_mtrr(struct intelfb_info *dinfo)
419{
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700420 if (dinfo->has_mtrr)
421 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 dinfo->aperture.size);
423}
424#else
425#define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
426
427#define unset_mtrr(x) do { } while (0)
428#endif /* CONFIG_MTRR */
429
430/***************************************************************
431 * driver init / cleanup *
432 ***************************************************************/
433
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700434static void cleanup(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
436 DBG_MSG("cleanup\n");
437
438 if (!dinfo)
439 return;
440
Eric Hustvedt76497572006-06-20 14:36:41 -0400441 intelfbhw_disable_irq(dinfo);
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 fb_dealloc_cmap(&dinfo->info->cmap);
444 kfree(dinfo->info->pixmap.addr);
445
446 if (dinfo->registered)
447 unregister_framebuffer(dinfo->info);
448
449 unset_mtrr(dinfo);
450
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);
454 }
455 if (dinfo->gtt_cursor_mem) {
456 agp_unbind_memory(dinfo->gtt_cursor_mem);
457 agp_free_memory(dinfo->gtt_cursor_mem);
458 }
459 if (dinfo->gtt_ring_mem) {
460 agp_unbind_memory(dinfo->gtt_ring_mem);
461 agp_free_memory(dinfo->gtt_ring_mem);
462 }
463
Dennis Munsie76278992006-06-20 14:55:55 -0400464#ifdef CONFIG_FB_INTEL_I2C
465 /* un-register I2C bus */
466 intelfb_delete_i2c_busses(dinfo);
467#endif
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (dinfo->mmio_base)
470 iounmap((void __iomem *)dinfo->mmio_base);
471 if (dinfo->aperture.virtual)
472 iounmap((void __iomem *)dinfo->aperture.virtual);
473
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800474 if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800476 if (dinfo->flag & INTELFB_FB_ACQUIRED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 release_mem_region(dinfo->aperture.physical,
478 dinfo->aperture.size);
479 framebuffer_release(dinfo->info);
480}
481
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)
488
489
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700490static int __devinit intelfb_pci_register(struct pci_dev *pdev,
491 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492{
493 struct fb_info *info;
494 struct intelfb_info *dinfo;
James Simmons4c7ffe02005-09-09 13:04:31 -0700495 int i, err, dvo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 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;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700501 int aperture_bar = 0;
502 int mmio_bar = 1;
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700503 int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 DBG_MSG("intelfb_pci_register\n");
506
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;
512 }
513
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;
518 }
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;
523 }
524
525 dinfo = info->par;
526 dinfo->info = info;
527 dinfo->fbops = &intel_fb_ops;
528 dinfo->pdev = pdev;
529
530 /* Reserve pixmap space. */
Jiri Slabyf5610b92007-02-12 00:55:12 -0800531 info->pixmap.addr = kzalloc(64 * 1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 if (info->pixmap.addr == NULL) {
533 ERR_MSG("Cannot reserve pixmap memory.\n");
534 goto err_out_pixmap;
535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 /* set early this option because it could be changed by tv encoder
538 driver */
539 dinfo->fixed_mode = fixed;
540
541 /* Enable device. */
542 if ((err = pci_enable_device(pdev))) {
543 ERR_MSG("Cannot enable device.\n");
544 cleanup(dinfo);
545 return -ENODEV;
546 }
547
548 /* Set base addresses. */
Scott MacKenzie3a590262005-11-07 01:00:33 -0800549 if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
Dave Airlie9639d5e2006-03-23 11:23:55 +1100550 (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
Dave Airlie9a906032006-03-23 21:53:05 +1100551 (ent->device == PCI_DEVICE_ID_INTEL_945G) ||
552 (ent->device == PCI_DEVICE_ID_INTEL_945GM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 aperture_bar = 2;
554 mmio_bar = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
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));
564
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;
571 }
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800572
573 dinfo->flag |= INTELFB_FB_ACQUIRED;
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 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;
581 }
582
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800583 dinfo->flag |= INTELFB_MMIO_ACQUIRED;
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* Get the chipset info. */
586 dinfo->pci_chipset = pdev->device;
587
Dave Airlied0249602006-03-20 20:26:45 +1100588 if (intelfbhw_get_chipset(pdev, dinfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 cleanup(dinfo);
590 return -ENODEV;
591 }
592
593 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
594 cleanup(dinfo);
595 return -ENODEV;
596 }
597
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));
603
604 /* Set these from the options. */
605 dinfo->accel = accel;
606 dinfo->hwcursor = hwcursor;
607
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;
612 }
613
614 /* Framebuffer parameters - Use all the stolen memory if >= vram */
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800615 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 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;
621 }
622
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;
627 }
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700628 if (dinfo->hwcursor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 dinfo->cursor.size = HW_CURSOR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
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;
636 }
637
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;
644 }
645
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800646 if (MB(voffset) < stolen_size)
647 offset = (stolen_size >> 12);
648 else
649 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* set the mem offsets - set them after the already used pages */
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700652 if (dinfo->accel)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700653 dinfo->ring.offset = offset + gtt_info.current_memory;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700654 if (dinfo->hwcursor)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700655 dinfo->cursor.offset = offset +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 + gtt_info.current_memory + (dinfo->ring.size >> 12);
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700657 if (dinfo->fbmem_gart)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700658 dinfo->fb.offset = offset +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 + gtt_info.current_memory + (dinfo->ring.size >> 12)
660 + (dinfo->cursor.size >> 12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800662 /* Allocate memories (which aren't stolen) */
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800663 /* Map the fb and MMIO regions */
664 /* ioremap only up to the end of used aperture */
665 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800666 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800667 + dinfo->fb.size);
668 if (!dinfo->aperture.virtual) {
669 ERR_MSG("Cannot remap FB region.\n");
670 cleanup(dinfo);
671 return -ENODEV;
672 }
673
674 dinfo->mmio_base =
675 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700676 INTEL_REG_SIZE);
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800677 if (!dinfo->mmio_base) {
678 ERR_MSG("Cannot remap MMIO region.\n");
679 cleanup(dinfo);
680 return -ENODEV;
681 }
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 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;
691 }
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;
698 }
699 dinfo->ring.physical = dinfo->aperture.physical
700 + (dinfo->ring.offset << 12);
701 dinfo->ring.virtual = dinfo->aperture.virtual
702 + (dinfo->ring.offset << 12);
Al Viro0fe6e2d2006-06-23 06:05:39 +0100703 dinfo->ring_head = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
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;
715 }
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;
722 }
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);
731 }
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;
739 }
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;
745 }
746 }
747
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;
755
756 /* release agpgart */
757 agp_backend_release(bridge);
758
759 if (mtrr)
760 set_mtrr(dinfo);
761
Al Viro0fe6e2d2006-06-23 06:05:39 +0100762 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100764 dinfo->fb.virtual);
765 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 dinfo->mmio_base_phys, INTEL_REG_SIZE,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100767 dinfo->mmio_base);
768 DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 dinfo->ring.physical, dinfo->ring.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100770 dinfo->ring.virtual);
771 DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 dinfo->cursor.physical, dinfo->cursor.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100773 dinfo->cursor.virtual, dinfo->cursor.offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 dinfo->cursor.physical);
775
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 : "");
779
780 if (probeonly)
781 bailout(dinfo);
782
783 /*
784 * Check if the LVDS port or any DVO ports are enabled. If so,
785 * don't allow mode switching
786 */
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);
797 }
798 dvo >>= 1;
799 ++i;
800 }
801 printk("). Disabling mode switching.\n");
802 }
803
804 if (bailearly == 1)
805 bailout(dinfo);
806
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;
811 }
812
813 if (bailearly == 2)
814 bailout(dinfo);
815
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);
820
821 if (bailearly == 3)
822 bailout(dinfo);
823
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700824 if (FIXED_MODE(dinfo)) /* remap fb address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 update_dinfo(dinfo, &dinfo->initial_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 if (bailearly == 4)
828 bailout(dinfo);
829
830
831 if (intelfb_set_fbinfo(dinfo)) {
832 cleanup(dinfo);
833 return -ENODEV;
834 }
835
836 if (bailearly == 5)
837 bailout(dinfo);
838
Dennis Munsie41c94802006-06-20 14:55:55 -0400839#ifdef CONFIG_FB_INTEL_I2C
840 /* register I2C bus */
841 intelfb_create_i2c_busses(dinfo);
842#endif
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 if (bailearly == 6)
845 bailout(dinfo);
846
847 pci_set_drvdata(pdev, dinfo);
848
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);
855 }
856
857 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
858
859 if (bailearly == 18)
860 bailout(dinfo);
861
862 /* Cursor initialisation */
863 if (dinfo->hwcursor) {
864 intelfbhw_cursor_init(dinfo);
865 intelfbhw_cursor_reset(dinfo);
866 }
867
868 if (bailearly == 19)
869 bailout(dinfo);
870
871 /* 2d acceleration init */
872 if (dinfo->accel)
873 intelfbhw_2d_start(dinfo);
874
875 if (bailearly == 20)
876 bailout(dinfo);
877
878 if (noregister)
879 bailout(dinfo);
880
881 if (register_framebuffer(dinfo->info) < 0) {
882 ERR_MSG("Cannot register framebuffer.\n");
883 cleanup(dinfo);
884 return -ENODEV;
885 }
886
887 dinfo->registered = 1;
Eric Hustvedt76497572006-06-20 14:36:41 -0400888 dinfo->open = 0;
889
890 init_waitqueue_head(&dinfo->vsync.wait);
891 spin_lock_init(&dinfo->int_lock);
892 dinfo->irq_flags = 0;
Eric Hustvedtf80d0d22006-06-20 14:36:42 -0400893 dinfo->vsync.pan_display = 0;
894 dinfo->vsync.pan_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 return 0;
897
898err_out_pixmap:
899 fb_dealloc_cmap(&info->cmap);
900err_out_cmap:
901 framebuffer_release(info);
902 return -ENODEV;
903}
904
905static void __devexit
906intelfb_pci_unregister(struct pci_dev *pdev)
907{
908 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
909
910 DBG_MSG("intelfb_pci_unregister\n");
911
912 if (!dinfo)
913 return;
914
915 cleanup(dinfo);
916
917 pci_set_drvdata(pdev, NULL);
918}
919
920/***************************************************************
921 * helper functions *
922 ***************************************************************/
923
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700924int __inline__ intelfb_var_to_depth(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
927 var->bits_per_pixel, var->green.length);
928
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;
936 }
937}
938
939
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700940static __inline__ int var_to_refresh(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
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;
946
947 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
948}
949
950/***************************************************************
951 * Various intialisation functions *
952 ***************************************************************/
953
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700954static void __devinit get_initial_mode(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 struct fb_var_screeninfo *var;
957 int xtot, ytot;
958
959 DBG_MSG("get_initial_mode\n");
960
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;
965
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;
978 }
979
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));
983
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);
987
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;
995
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;
1001
1002 var->height = -1;
1003 var->width = -1;
1004
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;
1018 }
1019}
1020
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001021static int __devinit intelfb_init_var(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022{
1023 struct fb_var_screeninfo *var;
1024 int msrc = 0;
1025
1026 DBG_MSG("intelfb_init_var\n");
1027
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 {
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001034 const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev);
1035 u8 *edid_d = NULL;
1036
1037 if (edid_s) {
Alexey Dobriyanbfba7b32006-12-08 02:40:46 -08001038 edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL);
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001039
1040 if (edid_d) {
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001041 fb_edid_to_monspecs(edid_d,
1042 &dinfo->info->monspecs);
1043 kfree(edid_d);
1044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001046
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);
1054
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,
Dennis Munsie7a532c62006-05-29 18:58:09 +10001060 NULL, 0, NULL, 0);
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001061
1062 if (msrc)
1063 msrc |= 8;
1064 }
1065
1066 }
1067
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001068 if (!msrc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
Dennis Munsie7a532c62006-05-29 18:58:09 +10001070 NULL, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
1072
1073 if (!msrc) {
1074 ERR_MSG("Cannot find a suitable video mode.\n");
1075 return 1;
1076 }
1077
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));
1080
1081 DBG_MSG("Initial video mode is from %d.\n", msrc);
1082
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
1093
1094 if (dinfo->accel)
1095 var->accel_flags |= FB_ACCELF_TEXT;
1096 else
1097 var->accel_flags &= ~FB_ACCELF_TEXT;
1098
1099 return 0;
1100}
1101
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001102static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
1104 struct fb_info *info = dinfo->info;
1105
1106 DBG_MSG("intelfb_set_fbinfo\n");
1107
1108 info->flags = FBINFO_FLAG_DEFAULT;
1109 info->fbops = &intel_fb_ops;
1110 info->pseudo_palette = dinfo->pseudo_palette;
1111
1112 info->pixmap.size = 64*1024;
1113 info->pixmap.buf_align = 8;
James Simmons58a60642005-06-21 17:17:08 -07001114 info->pixmap.access_align = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1116
1117 if (intelfb_init_var(dinfo))
1118 return 1;
1119
1120 info->pixmap.scan_align = 1;
Antonino A. Daplas33c37c02005-12-19 15:11:49 +08001121 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 update_dinfo(dinfo, &info->var);
1133
1134 return 0;
1135}
1136
1137/* Update dinfo to match the active video mode. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001138static void update_dinfo(struct intelfb_info *dinfo,
1139 struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
1141 DBG_MSG("update_dinfo\n");
1142
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;
1148
Antonino A. Daplas33c37c02005-12-19 15:11:49 +08001149 dinfo->info->fix.visual = dinfo->visual;
1150 dinfo->info->fix.line_length = dinfo->pitch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
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;
1165 }
1166
1167 /* Make sure the line length is a aligned correctly. */
Dennis Munsiedf7df8a2006-05-27 18:17:52 +10001168 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
1173 if (FIXED_MODE(dinfo))
1174 dinfo->pitch = dinfo->initial_pitch;
1175
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;
1179}
1180
1181/* fbops functions */
1182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183/***************************************************************
1184 * fbdev interface *
1185 ***************************************************************/
1186
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001187static int intelfb_open(struct fb_info *info, int user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001188{
1189 struct intelfb_info *dinfo = GET_DINFO(info);
1190
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001191 if (user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001192 dinfo->open++;
Eric Hustvedt76497572006-06-20 14:36:41 -04001193
1194 return 0;
1195}
1196
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001197static int intelfb_release(struct fb_info *info, int user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001198{
1199 struct intelfb_info *dinfo = GET_DINFO(info);
1200
1201 if (user) {
1202 dinfo->open--;
1203 msleep(1);
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001204 if (!dinfo->open)
Eric Hustvedt76497572006-06-20 14:36:41 -04001205 intelfbhw_disable_irq(dinfo);
Eric Hustvedt76497572006-06-20 14:36:41 -04001206 }
1207
1208 return 0;
1209}
1210
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001211static int intelfb_check_var(struct fb_var_screeninfo *var,
1212 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214 int change_var = 0;
1215 struct fb_var_screeninfo v;
1216 struct intelfb_info *dinfo;
1217 static int first = 1;
Dave Airlie3587c502006-04-03 14:46:55 +10001218 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,
1225 0
1226 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1229
1230 dinfo = GET_DINFO(info);
1231
Dave Airlie3587c502006-04-03 14:46:55 +10001232 /* update the pitch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 if (intelfbhw_validate_mode(dinfo, var) != 0)
1234 return -EINVAL;
1235
1236 v = *var;
1237
Dave Airlie3587c502006-04-03 14:46:55 +10001238 for (i = 0; pitches[i] != 0; i++) {
1239 if (pitches[i] >= v.xres_virtual) {
1240 v.xres_virtual = pitches[i];
1241 break;
1242 }
1243 }
1244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 /* Check for a supported bpp. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001246 if (v.bits_per_pixel <= 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 v.bits_per_pixel = 8;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001248 else if (v.bits_per_pixel <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 if (v.bits_per_pixel == 16)
1250 v.green.length = 6;
1251 v.bits_per_pixel = 16;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001252 } else if (v.bits_per_pixel <= 32)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 v.bits_per_pixel = 32;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001254 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 return -EINVAL;
1256
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)));
1266
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;
1275 }
1276 return -EINVAL;
1277 }
1278
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;
1316 }
1317
1318 if (v.xoffset < 0)
1319 v.xoffset = 0;
1320 if (v.yoffset < 0)
1321 v.yoffset = 0;
1322
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;
1327
1328 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1329 v.transp.msb_right = 0;
1330
1331 *var = v;
1332
1333 return 0;
1334}
1335
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001336static int intelfb_set_par(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001338 struct intelfb_hwstate *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 struct intelfb_info *dinfo = GET_DINFO(info);
1340
1341 if (FIXED_MODE(dinfo)) {
1342 ERR_MSG("Changing the video mode is not supported.\n");
1343 return -EINVAL;
1344 }
1345
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001346 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1347 if (!hw)
1348 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1351 info->var.yres, info->var.bits_per_pixel);
1352
1353 intelfb_blank(FB_BLANK_POWERDOWN, info);
1354
Sylvain Meyerdf529332005-06-21 17:17:02 -07001355 if (ACCEL(dinfo, info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 intelfbhw_2d_stop(dinfo);
1357
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001358 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364#if REGDUMP > 0
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001365 intelfbhw_read_hw_state(dinfo, hw, 0);
1366 intelfbhw_print_hw_state(dinfo, hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367#endif
1368
1369 update_dinfo(dinfo, &info->var);
1370
Sylvain Meyerdf529332005-06-21 17:17:02 -07001371 if (ACCEL(dinfo, info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 intelfbhw_2d_start(dinfo);
1373
1374 intelfb_pan_display(&info->var, info);
1375
1376 intelfb_blank(FB_BLANK_UNBLANK, info);
1377
1378 if (ACCEL(dinfo, info)) {
1379 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1380 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1381 FBINFO_HWACCEL_IMAGEBLIT;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001382 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 kfree(hw);
1386 return 0;
1387invalid_mode:
1388 kfree(hw);
1389 return -EINVAL;
1390}
1391
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001392static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1393 unsigned blue, unsigned transp,
1394 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
1396 struct intelfb_info *dinfo = GET_DINFO(info);
1397
1398#if VERBOSE > 0
1399 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1400#endif
1401
1402 if (regno > 255)
1403 return 1;
1404
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001405 if (dinfo->depth == 8) {
1406 red >>= 8;
1407 green >>= 8;
1408 blue >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001410 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1411 transp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001413
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;
1431 }
1432 }
1433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 return 0;
1435}
1436
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001437static int intelfb_blank(int blank, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
1439 intelfbhw_do_blank(blank, info);
1440 return 0;
1441}
1442
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001443static int intelfb_pan_display(struct fb_var_screeninfo *var,
1444 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
1446 intelfbhw_pan_display(var, info);
1447 return 0;
1448}
1449
1450/* When/if we have our own ioctls. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001451static int intelfb_ioctl(struct fb_info *info, unsigned int cmd,
1452 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
1454 int retval = 0;
Eric Hustvedt37bced32006-06-20 14:36:42 -04001455 struct intelfb_info *dinfo = GET_DINFO(info);
1456 u32 pipe = 0;
1457
1458 switch (cmd) {
1459 case FBIO_WAITFORVSYNC:
1460 if (get_user(pipe, (__u32 __user *)arg))
1461 return -EFAULT;
1462
1463 retval = intelfbhw_wait_for_vsync(dinfo, pipe);
1464 break;
1465 default:
1466 break;
1467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 return retval;
1470}
1471
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001472static void intelfb_fillrect (struct fb_info *info,
1473 const struct fb_fillrect *rect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 struct intelfb_info *dinfo = GET_DINFO(info);
1476 u32 rop, color;
1477
1478#if VERBOSE > 0
1479 DBG_MSG("intelfb_fillrect\n");
1480#endif
1481
1482 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1483 return cfb_fillrect(info, rect);
1484
1485 if (rect->rop == ROP_COPY)
1486 rop = PAT_ROP_GXCOPY;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001487 else /* ROP_XOR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 rop = PAT_ROP_GXXOR;
1489
1490 if (dinfo->depth != 8)
1491 color = dinfo->pseudo_palette[rect->color];
1492 else
1493 color = rect->color;
1494
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);
1499}
1500
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001501static void intelfb_copyarea(struct fb_info *info,
1502 const struct fb_copyarea *region)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 struct intelfb_info *dinfo = GET_DINFO(info);
1505
1506#if VERBOSE > 0
1507 DBG_MSG("intelfb_copyarea\n");
1508#endif
1509
1510 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1511 return cfb_copyarea(info, region);
1512
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);
1516}
1517
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001518static void intelfb_imageblit(struct fb_info *info,
1519 const struct fb_image *image)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
1521 struct intelfb_info *dinfo = GET_DINFO(info);
1522 u32 fgcolor, bgcolor;
1523
1524#if VERBOSE > 0
1525 DBG_MSG("intelfb_imageblit\n");
1526#endif
1527
1528 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1529 || image->depth != 1)
1530 return cfb_imageblit(info, image);
1531
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;
1538 }
1539
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);
1545}
1546
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001547static int intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
1549 struct intelfb_info *dinfo = GET_DINFO(info);
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001550 u32 physical;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551#if VERBOSE > 0
1552 DBG_MSG("intelfb_cursor\n");
1553#endif
1554
1555 if (!dinfo->hwcursor)
Antonino A. Daplasc465e052005-11-07 01:00:35 -08001556 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 intelfbhw_cursor_hide(dinfo);
1559
1560 /* If XFree killed the cursor - restore it */
Dave Airlie3aff13c2006-03-31 17:08:52 +10001561 physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical :
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001562 (dinfo->cursor.offset << 12);
Dave Airlie8bb91f62006-03-23 13:06:32 +11001563
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001564 if (INREG(CURSOR_A_BASEADDR) != physical) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 u32 fg, bg;
1566
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);
1571
1572 intelfbhw_cursor_init(dinfo);
1573 intelfbhw_cursor_reset(dinfo);
1574 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1575 cursor->image.dy);
1576
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;
1583 }
1584 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1585 intelfbhw_cursor_load(dinfo, cursor->image.width,
1586 cursor->image.height,
1587 dinfo->cursor_src);
1588
1589 if (cursor->enable)
1590 intelfbhw_cursor_show(dinfo);
1591 return 0;
1592 }
1593
1594 if (cursor->set & FB_CUR_SETPOS) {
1595 u32 dx, dy;
1596
1597 dx = cursor->image.dx - info->var.xoffset;
1598 dy = cursor->image.dy - info->var.yoffset;
1599
1600 intelfbhw_cursor_setpos(dinfo, dx, dy);
1601 }
1602
1603 if (cursor->set & FB_CUR_SETSIZE) {
1604 if (cursor->image.width > 64 || cursor->image.height > 64)
1605 return -ENXIO;
1606
1607 intelfbhw_cursor_reset(dinfo);
1608 }
1609
1610 if (cursor->set & FB_CUR_SETCMAP) {
1611 u32 fg, bg;
1612
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;
1619 }
1620
1621 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1622 }
1623
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;
1631
1632 if (cursor->image.depth != 1)
1633 return -ENXIO;
1634
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;
1645 }
1646
1647 /* save the bitmap to restore it when XFree will
1648 make the cursor dirty */
1649 memcpy(dinfo->cursor_src, src, size);
1650
1651 intelfbhw_cursor_load(dinfo, cursor->image.width,
1652 cursor->image.height, src);
1653 }
1654
1655 if (cursor->enable)
1656 intelfbhw_cursor_show(dinfo);
1657
1658 return 0;
1659}
1660
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001661static int intelfb_sync(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662{
1663 struct intelfb_info *dinfo = GET_DINFO(info);
1664
1665#if VERBOSE > 0
1666 DBG_MSG("intelfb_sync\n");
1667#endif
1668
1669 if (dinfo->ring_lockup)
1670 return 0;
1671
1672 intelfbhw_do_sync(dinfo);
1673 return 0;
1674}
1675