blob: a09e236493576f7602366e66d57781616c5c3933 [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/
Phil Endecott3f7a26b2008-10-15 22:03:35 -07005 * 945G/945GM/945GME/965G/965GM integrated graphics chips.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Jan Engelhardt96de0e22007-10-19 23:21:04 +02007 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * 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
Maik Broemme0e170c72008-04-28 02:15:43 -0700102 *
103 * 04/2008 - Version 0.9.5
104 * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>)
Phil Endecott3f7a26b2008-10-15 22:03:35 -0700105 *
106 * 08/2008 - Version 0.9.6
107 * Add support for 945GME. (Phil Endecott <spam_from_intelfb@chezphil.org>)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 */
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#include <linux/module.h>
111#include <linux/kernel.h>
112#include <linux/errno.h>
113#include <linux/string.h>
114#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#include <linux/slab.h>
116#include <linux/delay.h>
117#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#include <linux/ioport.h>
119#include <linux/init.h>
120#include <linux/pci.h>
121#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#include <linux/pagemap.h>
Jon Smirla8f340e2006-07-10 04:44:12 -0700123#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125#include <asm/io.h>
126
127#ifdef CONFIG_MTRR
128#include <asm/mtrr.h>
129#endif
130
131#include "intelfb.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#include "intelfbhw.h"
Antonino A. Daplas56e004e2006-05-29 18:49:08 +1000133#include "../edid.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Adrian Bunk14c6f522005-05-01 08:59:23 -0700135static void __devinit get_initial_mode(struct intelfb_info *dinfo);
136static void update_dinfo(struct intelfb_info *dinfo,
137 struct fb_var_screeninfo *var);
Eric Hustvedt76497572006-06-20 14:36:41 -0400138static int intelfb_open(struct fb_info *info, int user);
139static int intelfb_release(struct fb_info *info, int user);
Adrian Bunk14c6f522005-05-01 08:59:23 -0700140static int intelfb_check_var(struct fb_var_screeninfo *var,
141 struct fb_info *info);
142static int intelfb_set_par(struct fb_info *info);
143static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
144 unsigned blue, unsigned transp,
145 struct fb_info *info);
146
147static int intelfb_blank(int blank, struct fb_info *info);
148static int intelfb_pan_display(struct fb_var_screeninfo *var,
149 struct fb_info *info);
150
151static void intelfb_fillrect(struct fb_info *info,
152 const struct fb_fillrect *rect);
153static void intelfb_copyarea(struct fb_info *info,
154 const struct fb_copyarea *region);
155static void intelfb_imageblit(struct fb_info *info,
156 const struct fb_image *image);
157static int intelfb_cursor(struct fb_info *info,
158 struct fb_cursor *cursor);
159
160static int intelfb_sync(struct fb_info *info);
161
Christoph Hellwig67a66802006-01-14 13:21:25 -0800162static int intelfb_ioctl(struct fb_info *info,
163 unsigned int cmd, unsigned long arg);
Adrian Bunk14c6f522005-05-01 08:59:23 -0700164
165static int __devinit intelfb_pci_register(struct pci_dev *pdev,
166 const struct pci_device_id *ent);
167static void __devexit intelfb_pci_unregister(struct pci_dev *pdev);
168static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo);
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/*
171 * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the
172 * mobile chipsets from being registered.
173 */
174#if DETECT_VGA_CLASS_ONLY
175#define INTELFB_CLASS_MASK ~0 << 8
176#else
177#define INTELFB_CLASS_MASK 0
178#endif
179
180static struct pci_device_id intelfb_pci_table[] __devinitdata = {
181 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_830M, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_830M },
182 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_845G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_845G },
183 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM },
184 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G },
185 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G },
Scott MacKenzie3a590262005-11-07 01:00:33 -0800186 { 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 +1100187 { 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 +1100188 { 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 },
Phil Endecott3f7a26b2008-10-15 22:03:35 -0700189 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GME, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GME },
Maik Broemme0e170c72008-04-28 02:15:43 -0700190 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965G },
191 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965GM },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 { 0, }
193};
194
195/* Global data */
196static int num_registered = 0;
197
198/* fb ops */
199static struct fb_ops intel_fb_ops = {
200 .owner = THIS_MODULE,
Eric Hustvedt76497572006-06-20 14:36:41 -0400201 .fb_open = intelfb_open,
202 .fb_release = intelfb_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .fb_check_var = intelfb_check_var,
204 .fb_set_par = intelfb_set_par,
205 .fb_setcolreg = intelfb_setcolreg,
206 .fb_blank = intelfb_blank,
207 .fb_pan_display = intelfb_pan_display,
208 .fb_fillrect = intelfb_fillrect,
209 .fb_copyarea = intelfb_copyarea,
210 .fb_imageblit = intelfb_imageblit,
211 .fb_cursor = intelfb_cursor,
212 .fb_sync = intelfb_sync,
213 .fb_ioctl = intelfb_ioctl
214};
215
216/* PCI driver module table */
217static struct pci_driver intelfb_driver = {
Andrew Morton5a3b5892005-06-21 17:16:57 -0700218 .name = "intelfb",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 .id_table = intelfb_pci_table,
220 .probe = intelfb_pci_register,
221 .remove = __devexit_p(intelfb_pci_unregister)
222};
223
224/* Module description/parameters */
225MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, "
226 "Sylvain Meyer <sylvain.meyer@worldonline.fr>");
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700227MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS
228 " chipsets");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229MODULE_LICENSE("Dual BSD/GPL");
230MODULE_DEVICE_TABLE(pci, intelfb_pci_table);
231
Patrick McManus346e3992005-05-28 15:51:46 -0700232static int accel = 1;
233static int vram = 4;
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800234static int hwcursor = 0;
Patrick McManus346e3992005-05-28 15:51:46 -0700235static int mtrr = 1;
236static int fixed = 0;
237static int noinit = 0;
238static int noregister = 0;
239static int probeonly = 0;
240static int idonly = 0;
241static int bailearly = 0;
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700242static int voffset = 48;
Patrick McManus346e3992005-05-28 15:51:46 -0700243static char *mode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245module_param(accel, bool, S_IRUGO);
James Simmons4c7ffe02005-09-09 13:04:31 -0700246MODULE_PARM_DESC(accel, "Enable hardware acceleration");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247module_param(vram, int, S_IRUGO);
248MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB");
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700249module_param(voffset, int, S_IRUGO);
250MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251module_param(hwcursor, bool, S_IRUGO);
252MODULE_PARM_DESC(hwcursor, "Enable HW cursor");
253module_param(mtrr, bool, S_IRUGO);
254MODULE_PARM_DESC(mtrr, "Enable MTRR support");
255module_param(fixed, bool, S_IRUGO);
256MODULE_PARM_DESC(fixed, "Disable mode switching");
257module_param(noinit, bool, 0);
258MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading");
259module_param(noregister, bool, 0);
260MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)");
261module_param(probeonly, bool, 0);
262MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)");
263module_param(idonly, bool, 0);
264MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)");
265module_param(bailearly, bool, 0);
266MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)");
267module_param(mode, charp, S_IRUGO);
268MODULE_PARM_DESC(mode,
269 "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\"");
270
271#ifndef MODULE
272#define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name)))
Eric Hustvedt65eb2f92006-05-29 18:38:55 +1000273#define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define OPT_STRVAL(opt, name) (opt + strlen(name))
275
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700276static __inline__ char * get_opt_string(const char *this_opt, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 const char *p;
279 int i;
280 char *ret;
281
282 p = OPT_STRVAL(this_opt, name);
283 i = 0;
284 while (p[i] && p[i] != ' ' && p[i] != ',')
285 i++;
286 ret = kmalloc(i + 1, GFP_KERNEL);
287 if (ret) {
288 strncpy(ret, p, i);
289 ret[i] = '\0';
290 }
291 return ret;
292}
293
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700294static __inline__ int get_opt_int(const char *this_opt, const char *name,
295 int *ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 if (!ret)
298 return 0;
299
300 if (!OPT_EQUAL(this_opt, name))
301 return 0;
302
303 *ret = OPT_INTVAL(this_opt, name);
304 return 1;
305}
306
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700307static __inline__ int get_opt_bool(const char *this_opt, const char *name,
308 int *ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 if (!ret)
311 return 0;
312
313 if (OPT_EQUAL(this_opt, name)) {
314 if (this_opt[strlen(name)] == '=')
315 *ret = simple_strtoul(this_opt + strlen(name) + 1,
316 NULL, 0);
317 else
318 *ret = 1;
319 } else {
320 if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name))
321 *ret = 0;
322 else
323 return 0;
324 }
325 return 1;
326}
327
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700328static int __init intelfb_setup(char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 char *this_opt;
331
332 DBG_MSG("intelfb_setup\n");
333
334 if (!options || !*options) {
335 DBG_MSG("no options\n");
336 return 0;
337 } else
338 DBG_MSG("options: %s\n", options);
339
340 /*
341 * These are the built-in options analogous to the module parameters
342 * defined above.
343 *
344 * The syntax is:
345 *
346 * video=intelfb:[mode][,<param>=<val>] ...
347 *
348 * e.g.,
349 *
350 * video=intelfb:1024x768-16@75,accel=0
351 */
352
353 while ((this_opt = strsep(&options, ","))) {
354 if (!*this_opt)
355 continue;
356 if (get_opt_bool(this_opt, "accel", &accel))
357 ;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700358 else if (get_opt_int(this_opt, "vram", &vram))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ;
360 else if (get_opt_bool(this_opt, "hwcursor", &hwcursor))
361 ;
362 else if (get_opt_bool(this_opt, "mtrr", &mtrr))
363 ;
364 else if (get_opt_bool(this_opt, "fixed", &fixed))
365 ;
366 else if (get_opt_bool(this_opt, "init", &noinit))
367 noinit = !noinit;
368 else if (OPT_EQUAL(this_opt, "mode="))
369 mode = get_opt_string(this_opt, "mode=");
370 else
371 mode = this_opt;
372 }
373
374 return 0;
375}
376
377#endif
378
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700379static int __init intelfb_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381#ifndef MODULE
382 char *option = NULL;
383#endif
384
385 DBG_MSG("intelfb_init\n");
386
387 INF_MSG("Framebuffer driver for "
388 "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n");
389 INF_MSG("Version " INTELFB_VERSION "\n");
390
391 if (idonly)
392 return -ENODEV;
393
394#ifndef MODULE
395 if (fb_get_options("intelfb", &option))
396 return -ENODEV;
397 intelfb_setup(option);
398#endif
399
400 return pci_register_driver(&intelfb_driver);
401}
402
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700403static void __exit intelfb_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405 DBG_MSG("intelfb_exit\n");
406 pci_unregister_driver(&intelfb_driver);
407}
408
409module_init(intelfb_init);
410module_exit(intelfb_exit);
411
412/***************************************************************
413 * mtrr support functions *
414 ***************************************************************/
415
416#ifdef CONFIG_MTRR
417static inline void __devinit set_mtrr(struct intelfb_info *dinfo)
418{
419 dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical,
420 dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1);
421 if (dinfo->mtrr_reg < 0) {
422 ERR_MSG("unable to set MTRR\n");
423 return;
424 }
425 dinfo->has_mtrr = 1;
426}
427static inline void unset_mtrr(struct intelfb_info *dinfo)
428{
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700429 if (dinfo->has_mtrr)
430 mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 dinfo->aperture.size);
432}
433#else
434#define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n")
435
436#define unset_mtrr(x) do { } while (0)
437#endif /* CONFIG_MTRR */
438
439/***************************************************************
440 * driver init / cleanup *
441 ***************************************************************/
442
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700443static void cleanup(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 DBG_MSG("cleanup\n");
446
447 if (!dinfo)
448 return;
449
Eric Hustvedt76497572006-06-20 14:36:41 -0400450 intelfbhw_disable_irq(dinfo);
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 fb_dealloc_cmap(&dinfo->info->cmap);
453 kfree(dinfo->info->pixmap.addr);
454
455 if (dinfo->registered)
456 unregister_framebuffer(dinfo->info);
457
458 unset_mtrr(dinfo);
459
460 if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) {
461 agp_unbind_memory(dinfo->gtt_fb_mem);
462 agp_free_memory(dinfo->gtt_fb_mem);
463 }
464 if (dinfo->gtt_cursor_mem) {
465 agp_unbind_memory(dinfo->gtt_cursor_mem);
466 agp_free_memory(dinfo->gtt_cursor_mem);
467 }
468 if (dinfo->gtt_ring_mem) {
469 agp_unbind_memory(dinfo->gtt_ring_mem);
470 agp_free_memory(dinfo->gtt_ring_mem);
471 }
472
Dennis Munsie76278992006-06-20 14:55:55 -0400473#ifdef CONFIG_FB_INTEL_I2C
474 /* un-register I2C bus */
475 intelfb_delete_i2c_busses(dinfo);
476#endif
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (dinfo->mmio_base)
479 iounmap((void __iomem *)dinfo->mmio_base);
480 if (dinfo->aperture.virtual)
481 iounmap((void __iomem *)dinfo->aperture.virtual);
482
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800483 if (dinfo->flag & INTELFB_MMIO_ACQUIRED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE);
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800485 if (dinfo->flag & INTELFB_FB_ACQUIRED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 release_mem_region(dinfo->aperture.physical,
487 dinfo->aperture.size);
488 framebuffer_release(dinfo->info);
489}
490
491#define bailout(dinfo) do { \
492 DBG_MSG("bailout\n"); \
493 cleanup(dinfo); \
494 INF_MSG("Not going to register framebuffer, exiting...\n"); \
495 return -ENODEV; \
496} while (0)
497
498
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700499static int __devinit intelfb_pci_register(struct pci_dev *pdev,
500 const struct pci_device_id *ent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 struct fb_info *info;
503 struct intelfb_info *dinfo;
James Simmons4c7ffe02005-09-09 13:04:31 -0700504 int i, err, dvo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 int aperture_size, stolen_size;
506 struct agp_kern_info gtt_info;
507 int agp_memtype;
508 const char *s;
509 struct agp_bridge_data *bridge;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700510 int aperture_bar = 0;
511 int mmio_bar = 1;
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700512 int offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 DBG_MSG("intelfb_pci_register\n");
515
516 num_registered++;
517 if (num_registered != 1) {
518 ERR_MSG("Attempted to register %d devices "
519 "(should be only 1).\n", num_registered);
520 return -ENODEV;
521 }
522
523 info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev);
524 if (!info) {
525 ERR_MSG("Could not allocate memory for intelfb_info.\n");
526 return -ENODEV;
527 }
528 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
529 ERR_MSG("Could not allocate cmap for intelfb_info.\n");
530 goto err_out_cmap;
531 return -ENODEV;
532 }
533
534 dinfo = info->par;
535 dinfo->info = info;
536 dinfo->fbops = &intel_fb_ops;
537 dinfo->pdev = pdev;
538
539 /* Reserve pixmap space. */
Jiri Slabyf5610b92007-02-12 00:55:12 -0800540 info->pixmap.addr = kzalloc(64 * 1024, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 if (info->pixmap.addr == NULL) {
542 ERR_MSG("Cannot reserve pixmap memory.\n");
543 goto err_out_pixmap;
544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /* set early this option because it could be changed by tv encoder
547 driver */
548 dinfo->fixed_mode = fixed;
549
550 /* Enable device. */
551 if ((err = pci_enable_device(pdev))) {
552 ERR_MSG("Cannot enable device.\n");
553 cleanup(dinfo);
554 return -ENODEV;
555 }
556
557 /* Set base addresses. */
Scott MacKenzie3a590262005-11-07 01:00:33 -0800558 if ((ent->device == PCI_DEVICE_ID_INTEL_915G) ||
Dave Airlie9639d5e2006-03-23 11:23:55 +1100559 (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
Dave Airlie9a906032006-03-23 21:53:05 +1100560 (ent->device == PCI_DEVICE_ID_INTEL_945G) ||
Maik Broemme0e170c72008-04-28 02:15:43 -0700561 (ent->device == PCI_DEVICE_ID_INTEL_945GM) ||
Phil Endecott3f7a26b2008-10-15 22:03:35 -0700562 (ent->device == PCI_DEVICE_ID_INTEL_945GME) ||
Maik Broemme0e170c72008-04-28 02:15:43 -0700563 (ent->device == PCI_DEVICE_ID_INTEL_965G) ||
564 (ent->device == PCI_DEVICE_ID_INTEL_965GM)) {
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 aperture_bar = 2;
567 mmio_bar = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569 dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar);
570 dinfo->aperture.size = pci_resource_len(pdev, aperture_bar);
571 dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar);
572 DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n",
573 (unsigned long long)pci_resource_start(pdev, aperture_bar),
574 (unsigned long long)pci_resource_len(pdev, aperture_bar),
575 (unsigned long long)pci_resource_start(pdev, mmio_bar),
576 (unsigned long long)pci_resource_len(pdev, mmio_bar));
577
578 /* Reserve the fb and MMIO regions */
579 if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size,
580 INTELFB_MODULE_NAME)) {
581 ERR_MSG("Cannot reserve FB region.\n");
582 cleanup(dinfo);
583 return -ENODEV;
584 }
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800585
586 dinfo->flag |= INTELFB_FB_ACQUIRED;
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (!request_mem_region(dinfo->mmio_base_phys,
589 INTEL_REG_SIZE,
590 INTELFB_MODULE_NAME)) {
591 ERR_MSG("Cannot reserve MMIO region.\n");
592 cleanup(dinfo);
593 return -ENODEV;
594 }
595
Antonino A. Daplas4b3760c2005-12-19 15:11:40 +0800596 dinfo->flag |= INTELFB_MMIO_ACQUIRED;
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 /* Get the chipset info. */
599 dinfo->pci_chipset = pdev->device;
600
Dave Airlied0249602006-03-20 20:26:45 +1100601 if (intelfbhw_get_chipset(pdev, dinfo)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 cleanup(dinfo);
603 return -ENODEV;
604 }
605
606 if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) {
607 cleanup(dinfo);
608 return -ENODEV;
609 }
610
611 INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, "
612 "stolen memory %dkB\n",
613 pdev->bus->number, PCI_SLOT(pdev->devfn),
614 PCI_FUNC(pdev->devfn), dinfo->name,
615 BtoMB(aperture_size), BtoKB(stolen_size));
616
617 /* Set these from the options. */
618 dinfo->accel = accel;
619 dinfo->hwcursor = hwcursor;
620
621 if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) {
622 INF_MSG("Acceleration is not supported for the %s chipset.\n",
623 dinfo->name);
624 dinfo->accel = 0;
625 }
626
627 /* Framebuffer parameters - Use all the stolen memory if >= vram */
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800628 if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size);
630 dinfo->fbmem_gart = 0;
631 } else {
632 dinfo->fb.size = MB(vram);
633 dinfo->fbmem_gart = 1;
634 }
635
636 /* Allocate space for the ring buffer and HW cursor if enabled. */
637 if (dinfo->accel) {
638 dinfo->ring.size = RINGBUFFER_SIZE;
639 dinfo->ring_tail_mask = dinfo->ring.size - 1;
640 }
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700641 if (dinfo->hwcursor)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 dinfo->cursor.size = HW_CURSOR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 /* Use agpgart to manage the GATT */
645 if (!(bridge = agp_backend_acquire(pdev))) {
646 ERR_MSG("cannot acquire agp\n");
647 cleanup(dinfo);
648 return -ENODEV;
649 }
650
651 /* get the current gatt info */
652 if (agp_copy_info(bridge, &gtt_info)) {
653 ERR_MSG("cannot get agp info\n");
654 agp_backend_release(bridge);
655 cleanup(dinfo);
656 return -ENODEV;
657 }
658
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800659 if (MB(voffset) < stolen_size)
660 offset = (stolen_size >> 12);
661 else
662 offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE;
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 /* set the mem offsets - set them after the already used pages */
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700665 if (dinfo->accel)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700666 dinfo->ring.offset = offset + gtt_info.current_memory;
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700667 if (dinfo->hwcursor)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700668 dinfo->cursor.offset = offset +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 + gtt_info.current_memory + (dinfo->ring.size >> 12);
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700670 if (dinfo->fbmem_gart)
Sylvain Meyer27aef2d2005-06-21 17:17:01 -0700671 dinfo->fb.offset = offset +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 + gtt_info.current_memory + (dinfo->ring.size >> 12)
673 + (dinfo->cursor.size >> 12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800675 /* Allocate memories (which aren't stolen) */
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800676 /* Map the fb and MMIO regions */
677 /* ioremap only up to the end of used aperture */
678 dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache
Antonino A. Daplas375726d2005-09-29 05:19:51 +0800679 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12)
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800680 + dinfo->fb.size);
681 if (!dinfo->aperture.virtual) {
682 ERR_MSG("Cannot remap FB region.\n");
683 cleanup(dinfo);
684 return -ENODEV;
685 }
686
687 dinfo->mmio_base =
688 (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys,
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700689 INTEL_REG_SIZE);
Sylvain Meyer6bd49342005-08-15 21:27:13 +0800690 if (!dinfo->mmio_base) {
691 ERR_MSG("Cannot remap MMIO region.\n");
692 cleanup(dinfo);
693 return -ENODEV;
694 }
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (dinfo->accel) {
697 if (!(dinfo->gtt_ring_mem =
698 agp_allocate_memory(bridge, dinfo->ring.size >> 12,
699 AGP_NORMAL_MEMORY))) {
700 ERR_MSG("cannot allocate ring buffer memory\n");
701 agp_backend_release(bridge);
702 cleanup(dinfo);
703 return -ENOMEM;
704 }
705 if (agp_bind_memory(dinfo->gtt_ring_mem,
706 dinfo->ring.offset)) {
707 ERR_MSG("cannot bind ring buffer memory\n");
708 agp_backend_release(bridge);
709 cleanup(dinfo);
710 return -EBUSY;
711 }
712 dinfo->ring.physical = dinfo->aperture.physical
713 + (dinfo->ring.offset << 12);
714 dinfo->ring.virtual = dinfo->aperture.virtual
715 + (dinfo->ring.offset << 12);
Al Viro0fe6e2d2006-06-23 06:05:39 +0100716 dinfo->ring_head = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718 if (dinfo->hwcursor) {
719 agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY
720 : AGP_NORMAL_MEMORY;
721 if (!(dinfo->gtt_cursor_mem =
722 agp_allocate_memory(bridge, dinfo->cursor.size >> 12,
723 agp_memtype))) {
724 ERR_MSG("cannot allocate cursor memory\n");
725 agp_backend_release(bridge);
726 cleanup(dinfo);
727 return -ENOMEM;
728 }
729 if (agp_bind_memory(dinfo->gtt_cursor_mem,
730 dinfo->cursor.offset)) {
731 ERR_MSG("cannot bind cursor memory\n");
732 agp_backend_release(bridge);
733 cleanup(dinfo);
734 return -EBUSY;
735 }
736 if (dinfo->mobile)
737 dinfo->cursor.physical
738 = dinfo->gtt_cursor_mem->physical;
739 else
740 dinfo->cursor.physical = dinfo->aperture.physical
741 + (dinfo->cursor.offset << 12);
742 dinfo->cursor.virtual = dinfo->aperture.virtual
743 + (dinfo->cursor.offset << 12);
744 }
745 if (dinfo->fbmem_gart) {
746 if (!(dinfo->gtt_fb_mem =
747 agp_allocate_memory(bridge, dinfo->fb.size >> 12,
748 AGP_NORMAL_MEMORY))) {
749 WRN_MSG("cannot allocate framebuffer memory - use "
750 "the stolen one\n");
751 dinfo->fbmem_gart = 0;
752 }
753 if (agp_bind_memory(dinfo->gtt_fb_mem,
754 dinfo->fb.offset)) {
755 WRN_MSG("cannot bind framebuffer memory - use "
756 "the stolen one\n");
757 dinfo->fbmem_gart = 0;
758 }
759 }
760
761 /* update framebuffer memory parameters */
762 if (!dinfo->fbmem_gart)
763 dinfo->fb.offset = 0; /* starts at offset 0 */
764 dinfo->fb.physical = dinfo->aperture.physical
765 + (dinfo->fb.offset << 12);
766 dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12);
767 dinfo->fb_start = dinfo->fb.offset << 12;
768
769 /* release agpgart */
770 agp_backend_release(bridge);
771
772 if (mtrr)
773 set_mtrr(dinfo);
774
Al Viro0fe6e2d2006-06-23 06:05:39 +0100775 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100777 dinfo->fb.virtual);
778 DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 dinfo->mmio_base_phys, INTEL_REG_SIZE,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100780 dinfo->mmio_base);
781 DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 dinfo->ring.physical, dinfo->ring.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100783 dinfo->ring.virtual);
784 DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 dinfo->cursor.physical, dinfo->cursor.size,
Al Viro0fe6e2d2006-06-23 06:05:39 +0100786 dinfo->cursor.virtual, dinfo->cursor.offset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 dinfo->cursor.physical);
788
789 DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, "
790 "noinit = %d\n", vram, accel, hwcursor, fixed, noinit);
791 DBG_MSG("options: mode = \"%s\"\n", mode ? mode : "");
792
793 if (probeonly)
794 bailout(dinfo);
795
796 /*
797 * Check if the LVDS port or any DVO ports are enabled. If so,
798 * don't allow mode switching
799 */
800 dvo = intelfbhw_check_non_crt(dinfo);
801 if (dvo) {
802 dinfo->fixed_mode = 1;
803 WRN_MSG("Non-CRT device is enabled ( ");
804 i = 0;
805 while (dvo) {
806 if (dvo & 1) {
807 s = intelfbhw_dvo_to_string(1 << i);
808 if (s)
809 printk("%s ", s);
810 }
811 dvo >>= 1;
812 ++i;
813 }
814 printk("). Disabling mode switching.\n");
815 }
816
817 if (bailearly == 1)
818 bailout(dinfo);
819
H. Peter Anvin3ea33512007-10-16 22:36:04 -0700820 if (FIXED_MODE(dinfo) &&
821 screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 ERR_MSG("Video mode must be programmed at boot time.\n");
823 cleanup(dinfo);
824 return -ENODEV;
825 }
826
827 if (bailearly == 2)
828 bailout(dinfo);
829
830 /* Initialise dinfo and related data. */
831 /* If an initial mode was programmed at boot time, get its details. */
H. Peter Anvin3ea33512007-10-16 22:36:04 -0700832 if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 get_initial_mode(dinfo);
834
835 if (bailearly == 3)
836 bailout(dinfo);
837
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700838 if (FIXED_MODE(dinfo)) /* remap fb address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 update_dinfo(dinfo, &dinfo->initial_var);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 if (bailearly == 4)
842 bailout(dinfo);
843
844
845 if (intelfb_set_fbinfo(dinfo)) {
846 cleanup(dinfo);
847 return -ENODEV;
848 }
849
850 if (bailearly == 5)
851 bailout(dinfo);
852
Dennis Munsie41c94802006-06-20 14:55:55 -0400853#ifdef CONFIG_FB_INTEL_I2C
854 /* register I2C bus */
855 intelfb_create_i2c_busses(dinfo);
856#endif
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (bailearly == 6)
859 bailout(dinfo);
860
861 pci_set_drvdata(pdev, dinfo);
862
863 /* Save the initial register state. */
864 i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state,
865 bailearly > 6 ? bailearly - 6 : 0);
866 if (i != 0) {
867 DBG_MSG("intelfbhw_read_hw_state returned %d\n", i);
868 bailout(dinfo);
869 }
870
871 intelfbhw_print_hw_state(dinfo, &dinfo->save_state);
872
873 if (bailearly == 18)
874 bailout(dinfo);
875
876 /* Cursor initialisation */
877 if (dinfo->hwcursor) {
878 intelfbhw_cursor_init(dinfo);
879 intelfbhw_cursor_reset(dinfo);
880 }
881
882 if (bailearly == 19)
883 bailout(dinfo);
884
885 /* 2d acceleration init */
886 if (dinfo->accel)
887 intelfbhw_2d_start(dinfo);
888
889 if (bailearly == 20)
890 bailout(dinfo);
891
892 if (noregister)
893 bailout(dinfo);
894
895 if (register_framebuffer(dinfo->info) < 0) {
896 ERR_MSG("Cannot register framebuffer.\n");
897 cleanup(dinfo);
898 return -ENODEV;
899 }
900
901 dinfo->registered = 1;
Eric Hustvedt76497572006-06-20 14:36:41 -0400902 dinfo->open = 0;
903
904 init_waitqueue_head(&dinfo->vsync.wait);
905 spin_lock_init(&dinfo->int_lock);
906 dinfo->irq_flags = 0;
Eric Hustvedtf80d0d22006-06-20 14:36:42 -0400907 dinfo->vsync.pan_display = 0;
908 dinfo->vsync.pan_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 return 0;
911
912err_out_pixmap:
913 fb_dealloc_cmap(&info->cmap);
914err_out_cmap:
915 framebuffer_release(info);
916 return -ENODEV;
917}
918
919static void __devexit
920intelfb_pci_unregister(struct pci_dev *pdev)
921{
922 struct intelfb_info *dinfo = pci_get_drvdata(pdev);
923
924 DBG_MSG("intelfb_pci_unregister\n");
925
926 if (!dinfo)
927 return;
928
929 cleanup(dinfo);
930
931 pci_set_drvdata(pdev, NULL);
932}
933
934/***************************************************************
935 * helper functions *
936 ***************************************************************/
937
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700938int __inline__ intelfb_var_to_depth(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
940 DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n",
941 var->bits_per_pixel, var->green.length);
942
943 switch (var->bits_per_pixel) {
944 case 16:
945 return (var->green.length == 6) ? 16 : 15;
946 case 32:
947 return 24;
948 default:
949 return var->bits_per_pixel;
950 }
951}
952
953
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700954static __inline__ int var_to_refresh(const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 int xtot = var->xres + var->left_margin + var->right_margin +
957 var->hsync_len;
958 int ytot = var->yres + var->upper_margin + var->lower_margin +
959 var->vsync_len;
960
961 return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot;
962}
963
964/***************************************************************
965 * Various intialisation functions *
966 ***************************************************************/
967
Krzysztof Halasa689c9562007-10-16 01:29:31 -0700968static void __devinit get_initial_mode(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
970 struct fb_var_screeninfo *var;
971 int xtot, ytot;
972
973 DBG_MSG("get_initial_mode\n");
974
975 dinfo->initial_vga = 1;
976 dinfo->initial_fb_base = screen_info.lfb_base;
977 dinfo->initial_video_ram = screen_info.lfb_size * KB(64);
978 dinfo->initial_pitch = screen_info.lfb_linelength;
979
980 var = &dinfo->initial_var;
981 memset(var, 0, sizeof(*var));
982 var->xres = screen_info.lfb_width;
983 var->yres = screen_info.lfb_height;
984 var->bits_per_pixel = screen_info.lfb_depth;
985 switch (screen_info.lfb_depth) {
986 case 15:
987 var->bits_per_pixel = 16;
988 break;
989 case 24:
990 var->bits_per_pixel = 32;
991 break;
992 }
993
994 DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n",
995 dinfo->initial_fb_base, dinfo->initial_video_ram,
996 BtoKB(dinfo->initial_video_ram));
997
998 DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n",
999 var->xres, var->yres, var->bits_per_pixel,
1000 dinfo->initial_pitch);
1001
1002 /* Dummy timing values (assume 60Hz) */
1003 var->left_margin = (var->xres / 8) & 0xf8;
1004 var->right_margin = 32;
1005 var->upper_margin = 16;
1006 var->lower_margin = 4;
1007 var->hsync_len = (var->xres / 8) & 0xf8;
1008 var->vsync_len = 4;
1009
1010 xtot = var->xres + var->left_margin +
1011 var->right_margin + var->hsync_len;
1012 ytot = var->yres + var->upper_margin +
1013 var->lower_margin + var->vsync_len;
1014 var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60;
1015
1016 var->height = -1;
1017 var->width = -1;
1018
1019 if (var->bits_per_pixel > 8) {
1020 var->red.offset = screen_info.red_pos;
1021 var->red.length = screen_info.red_size;
1022 var->green.offset = screen_info.green_pos;
1023 var->green.length = screen_info.green_size;
1024 var->blue.offset = screen_info.blue_pos;
1025 var->blue.length = screen_info.blue_size;
1026 var->transp.offset = screen_info.rsvd_pos;
1027 var->transp.length = screen_info.rsvd_size;
1028 } else {
1029 var->red.length = 8;
1030 var->green.length = 8;
1031 var->blue.length = 8;
1032 }
1033}
1034
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001035static int __devinit intelfb_init_var(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
1037 struct fb_var_screeninfo *var;
1038 int msrc = 0;
1039
1040 DBG_MSG("intelfb_init_var\n");
1041
1042 var = &dinfo->info->var;
1043 if (FIXED_MODE(dinfo)) {
1044 memcpy(var, &dinfo->initial_var,
1045 sizeof(struct fb_var_screeninfo));
1046 msrc = 5;
1047 } else {
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001048 const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev);
1049 u8 *edid_d = NULL;
1050
1051 if (edid_s) {
Alexey Dobriyanbfba7b32006-12-08 02:40:46 -08001052 edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL);
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001053
1054 if (edid_d) {
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001055 fb_edid_to_monspecs(edid_d,
1056 &dinfo->info->monspecs);
1057 kfree(edid_d);
1058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001060
1061 if (mode) {
1062 printk("intelfb: Looking for mode in private "
1063 "database\n");
1064 msrc = fb_find_mode(var, dinfo->info, mode,
1065 dinfo->info->monspecs.modedb,
1066 dinfo->info->monspecs.modedb_len,
1067 NULL, 0);
1068
1069 if (msrc && msrc > 1) {
1070 printk("intelfb: No mode in private database, "
1071 "intelfb: looking for mode in global "
1072 "database ");
1073 msrc = fb_find_mode(var, dinfo->info, mode,
Dennis Munsie7a532c62006-05-29 18:58:09 +10001074 NULL, 0, NULL, 0);
Antonino A. Daplas56e004e2006-05-29 18:49:08 +10001075
1076 if (msrc)
1077 msrc |= 8;
1078 }
1079
1080 }
1081
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001082 if (!msrc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE,
Dennis Munsie7a532c62006-05-29 18:58:09 +10001084 NULL, 0, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086
1087 if (!msrc) {
1088 ERR_MSG("Cannot find a suitable video mode.\n");
1089 return 1;
1090 }
1091
1092 INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres,
1093 var->bits_per_pixel, var_to_refresh(var));
1094
1095 DBG_MSG("Initial video mode is from %d.\n", msrc);
1096
1097#if ALLOCATE_FOR_PANNING
1098 /* Allow use of half of the video ram for panning */
1099 var->xres_virtual = var->xres;
1100 var->yres_virtual =
1101 dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres);
1102 if (var->yres_virtual < var->yres)
1103 var->yres_virtual = var->yres;
1104#else
1105 var->yres_virtual = var->yres;
1106#endif
1107
1108 if (dinfo->accel)
1109 var->accel_flags |= FB_ACCELF_TEXT;
1110 else
1111 var->accel_flags &= ~FB_ACCELF_TEXT;
1112
1113 return 0;
1114}
1115
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001116static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117{
1118 struct fb_info *info = dinfo->info;
1119
1120 DBG_MSG("intelfb_set_fbinfo\n");
1121
1122 info->flags = FBINFO_FLAG_DEFAULT;
1123 info->fbops = &intel_fb_ops;
1124 info->pseudo_palette = dinfo->pseudo_palette;
1125
1126 info->pixmap.size = 64*1024;
1127 info->pixmap.buf_align = 8;
James Simmons58a60642005-06-21 17:17:08 -07001128 info->pixmap.access_align = 32;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 info->pixmap.flags = FB_PIXMAP_SYSTEM;
1130
1131 if (intelfb_init_var(dinfo))
1132 return 1;
1133
1134 info->pixmap.scan_align = 1;
Antonino A. Daplas33c37c02005-12-19 15:11:49 +08001135 strcpy(info->fix.id, dinfo->name);
1136 info->fix.smem_start = dinfo->fb.physical;
1137 info->fix.smem_len = dinfo->fb.size;
1138 info->fix.type = FB_TYPE_PACKED_PIXELS;
1139 info->fix.type_aux = 0;
1140 info->fix.xpanstep = 8;
1141 info->fix.ypanstep = 1;
1142 info->fix.ywrapstep = 0;
1143 info->fix.mmio_start = dinfo->mmio_base_phys;
1144 info->fix.mmio_len = INTEL_REG_SIZE;
1145 info->fix.accel = FB_ACCEL_I830;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 update_dinfo(dinfo, &info->var);
1147
1148 return 0;
1149}
1150
1151/* Update dinfo to match the active video mode. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001152static void update_dinfo(struct intelfb_info *dinfo,
1153 struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
1155 DBG_MSG("update_dinfo\n");
1156
1157 dinfo->bpp = var->bits_per_pixel;
1158 dinfo->depth = intelfb_var_to_depth(var);
1159 dinfo->xres = var->xres;
1160 dinfo->yres = var->xres;
1161 dinfo->pixclock = var->pixclock;
1162
Antonino A. Daplas33c37c02005-12-19 15:11:49 +08001163 dinfo->info->fix.visual = dinfo->visual;
1164 dinfo->info->fix.line_length = dinfo->pitch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 switch (dinfo->bpp) {
1167 case 8:
1168 dinfo->visual = FB_VISUAL_PSEUDOCOLOR;
1169 dinfo->pitch = var->xres_virtual;
1170 break;
1171 case 16:
1172 dinfo->visual = FB_VISUAL_TRUECOLOR;
1173 dinfo->pitch = var->xres_virtual * 2;
1174 break;
1175 case 32:
1176 dinfo->visual = FB_VISUAL_TRUECOLOR;
1177 dinfo->pitch = var->xres_virtual * 4;
1178 break;
1179 }
1180
1181 /* Make sure the line length is a aligned correctly. */
Dennis Munsiedf7df8a2006-05-27 18:17:52 +10001182 if (IS_I9XX(dinfo))
1183 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX);
1184 else
1185 dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 if (FIXED_MODE(dinfo))
1188 dinfo->pitch = dinfo->initial_pitch;
1189
1190 dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual;
1191 dinfo->info->fix.line_length = dinfo->pitch;
1192 dinfo->info->fix.visual = dinfo->visual;
1193}
1194
1195/* fbops functions */
1196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197/***************************************************************
1198 * fbdev interface *
1199 ***************************************************************/
1200
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001201static int intelfb_open(struct fb_info *info, int user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001202{
1203 struct intelfb_info *dinfo = GET_DINFO(info);
1204
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001205 if (user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001206 dinfo->open++;
Eric Hustvedt76497572006-06-20 14:36:41 -04001207
1208 return 0;
1209}
1210
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001211static int intelfb_release(struct fb_info *info, int user)
Eric Hustvedt76497572006-06-20 14:36:41 -04001212{
1213 struct intelfb_info *dinfo = GET_DINFO(info);
1214
1215 if (user) {
1216 dinfo->open--;
1217 msleep(1);
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001218 if (!dinfo->open)
Eric Hustvedt76497572006-06-20 14:36:41 -04001219 intelfbhw_disable_irq(dinfo);
Eric Hustvedt76497572006-06-20 14:36:41 -04001220 }
1221
1222 return 0;
1223}
1224
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001225static int intelfb_check_var(struct fb_var_screeninfo *var,
1226 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
1228 int change_var = 0;
1229 struct fb_var_screeninfo v;
1230 struct intelfb_info *dinfo;
1231 static int first = 1;
Dave Airlie3587c502006-04-03 14:46:55 +10001232 int i;
1233 /* Good pitches to allow tiling. Don't care about pitches < 1024. */
1234 static const int pitches[] = {
1235 128 * 8,
1236 128 * 16,
1237 128 * 32,
1238 128 * 64,
1239 0
1240 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags);
1243
1244 dinfo = GET_DINFO(info);
1245
Dave Airlie3587c502006-04-03 14:46:55 +10001246 /* update the pitch */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 if (intelfbhw_validate_mode(dinfo, var) != 0)
1248 return -EINVAL;
1249
1250 v = *var;
1251
Dave Airlie3587c502006-04-03 14:46:55 +10001252 for (i = 0; pitches[i] != 0; i++) {
1253 if (pitches[i] >= v.xres_virtual) {
1254 v.xres_virtual = pitches[i];
1255 break;
1256 }
1257 }
1258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 /* Check for a supported bpp. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001260 if (v.bits_per_pixel <= 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 v.bits_per_pixel = 8;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001262 else if (v.bits_per_pixel <= 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 if (v.bits_per_pixel == 16)
1264 v.green.length = 6;
1265 v.bits_per_pixel = 16;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001266 } else if (v.bits_per_pixel <= 32)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 v.bits_per_pixel = 32;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001268 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return -EINVAL;
1270
1271 change_var = ((info->var.xres != var->xres) ||
1272 (info->var.yres != var->yres) ||
1273 (info->var.xres_virtual != var->xres_virtual) ||
1274 (info->var.yres_virtual != var->yres_virtual) ||
1275 (info->var.bits_per_pixel != var->bits_per_pixel) ||
1276 memcmp(&info->var.red, &var->red, sizeof(var->red)) ||
1277 memcmp(&info->var.green, &var->green,
1278 sizeof(var->green)) ||
1279 memcmp(&info->var.blue, &var->blue, sizeof(var->blue)));
1280
1281 if (FIXED_MODE(dinfo) &&
1282 (change_var ||
1283 var->yres_virtual > dinfo->initial_var.yres_virtual ||
1284 var->yres_virtual < dinfo->initial_var.yres ||
1285 var->xoffset || var->nonstd)) {
1286 if (first) {
1287 ERR_MSG("Changing the video mode is not supported.\n");
1288 first = 0;
1289 }
1290 return -EINVAL;
1291 }
1292
1293 switch (intelfb_var_to_depth(&v)) {
1294 case 8:
1295 v.red.offset = v.green.offset = v.blue.offset = 0;
1296 v.red.length = v.green.length = v.blue.length = 8;
1297 v.transp.offset = v.transp.length = 0;
1298 break;
1299 case 15:
1300 v.red.offset = 10;
1301 v.green.offset = 5;
1302 v.blue.offset = 0;
1303 v.red.length = v.green.length = v.blue.length = 5;
1304 v.transp.offset = v.transp.length = 0;
1305 break;
1306 case 16:
1307 v.red.offset = 11;
1308 v.green.offset = 5;
1309 v.blue.offset = 0;
1310 v.red.length = 5;
1311 v.green.length = 6;
1312 v.blue.length = 5;
1313 v.transp.offset = v.transp.length = 0;
1314 break;
1315 case 24:
1316 v.red.offset = 16;
1317 v.green.offset = 8;
1318 v.blue.offset = 0;
1319 v.red.length = v.green.length = v.blue.length = 8;
1320 v.transp.offset = v.transp.length = 0;
1321 break;
1322 case 32:
1323 v.red.offset = 16;
1324 v.green.offset = 8;
1325 v.blue.offset = 0;
1326 v.red.length = v.green.length = v.blue.length = 8;
1327 v.transp.offset = 24;
1328 v.transp.length = 8;
1329 break;
1330 }
1331
1332 if (v.xoffset < 0)
1333 v.xoffset = 0;
1334 if (v.yoffset < 0)
1335 v.yoffset = 0;
1336
1337 if (v.xoffset > v.xres_virtual - v.xres)
1338 v.xoffset = v.xres_virtual - v.xres;
1339 if (v.yoffset > v.yres_virtual - v.yres)
1340 v.yoffset = v.yres_virtual - v.yres;
1341
1342 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1343 v.transp.msb_right = 0;
1344
1345 *var = v;
1346
1347 return 0;
1348}
1349
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001350static int intelfb_set_par(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001352 struct intelfb_hwstate *hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 struct intelfb_info *dinfo = GET_DINFO(info);
1354
1355 if (FIXED_MODE(dinfo)) {
1356 ERR_MSG("Changing the video mode is not supported.\n");
1357 return -EINVAL;
1358 }
1359
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001360 hw = kmalloc(sizeof(*hw), GFP_ATOMIC);
1361 if (!hw)
1362 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364 DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres,
1365 info->var.yres, info->var.bits_per_pixel);
1366
1367 intelfb_blank(FB_BLANK_POWERDOWN, info);
1368
Sylvain Meyerdf529332005-06-21 17:17:02 -07001369 if (ACCEL(dinfo, info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 intelfbhw_2d_stop(dinfo);
1371
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001372 memcpy(hw, &dinfo->save_state, sizeof(*hw));
1373 if (intelfbhw_mode_to_hw(dinfo, hw, &info->var))
1374 goto invalid_mode;
1375 if (intelfbhw_program_mode(dinfo, hw, 0))
1376 goto invalid_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378#if REGDUMP > 0
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001379 intelfbhw_read_hw_state(dinfo, hw, 0);
1380 intelfbhw_print_hw_state(dinfo, hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381#endif
1382
1383 update_dinfo(dinfo, &info->var);
1384
Sylvain Meyerdf529332005-06-21 17:17:02 -07001385 if (ACCEL(dinfo, info))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 intelfbhw_2d_start(dinfo);
1387
1388 intelfb_pan_display(&info->var, info);
1389
1390 intelfb_blank(FB_BLANK_UNBLANK, info);
1391
1392 if (ACCEL(dinfo, info)) {
1393 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
1394 FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
1395 FBINFO_HWACCEL_IMAGEBLIT;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001396 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001398
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 kfree(hw);
1400 return 0;
1401invalid_mode:
1402 kfree(hw);
1403 return -EINVAL;
1404}
1405
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001406static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green,
1407 unsigned blue, unsigned transp,
1408 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409{
1410 struct intelfb_info *dinfo = GET_DINFO(info);
1411
1412#if VERBOSE > 0
1413 DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth);
1414#endif
1415
1416 if (regno > 255)
1417 return 1;
1418
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001419 if (dinfo->depth == 8) {
1420 red >>= 8;
1421 green >>= 8;
1422 blue >>= 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001424 intelfbhw_setcolreg(dinfo, regno, red, green, blue,
1425 transp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
Antonino A. Daplasd3015242006-03-11 03:27:26 -08001427
1428 if (regno < 16) {
1429 switch (dinfo->depth) {
1430 case 15:
1431 dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) |
1432 ((green & 0xf800) >> 6) |
1433 ((blue & 0xf800) >> 11);
1434 break;
1435 case 16:
1436 dinfo->pseudo_palette[regno] = (red & 0xf800) |
1437 ((green & 0xfc00) >> 5) |
1438 ((blue & 0xf800) >> 11);
1439 break;
1440 case 24:
1441 dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) |
1442 (green & 0xff00) |
1443 ((blue & 0xff00) >> 8);
1444 break;
1445 }
1446 }
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 return 0;
1449}
1450
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001451static int intelfb_blank(int blank, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
1453 intelfbhw_do_blank(blank, info);
1454 return 0;
1455}
1456
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001457static int intelfb_pan_display(struct fb_var_screeninfo *var,
1458 struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
1460 intelfbhw_pan_display(var, info);
1461 return 0;
1462}
1463
1464/* When/if we have our own ioctls. */
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001465static int intelfb_ioctl(struct fb_info *info, unsigned int cmd,
1466 unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
1468 int retval = 0;
Eric Hustvedt37bced32006-06-20 14:36:42 -04001469 struct intelfb_info *dinfo = GET_DINFO(info);
1470 u32 pipe = 0;
1471
1472 switch (cmd) {
1473 case FBIO_WAITFORVSYNC:
1474 if (get_user(pipe, (__u32 __user *)arg))
1475 return -EFAULT;
1476
1477 retval = intelfbhw_wait_for_vsync(dinfo, pipe);
1478 break;
1479 default:
1480 break;
1481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
1483 return retval;
1484}
1485
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001486static void intelfb_fillrect (struct fb_info *info,
1487 const struct fb_fillrect *rect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488{
1489 struct intelfb_info *dinfo = GET_DINFO(info);
1490 u32 rop, color;
1491
1492#if VERBOSE > 0
1493 DBG_MSG("intelfb_fillrect\n");
1494#endif
1495
1496 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1497 return cfb_fillrect(info, rect);
1498
1499 if (rect->rop == ROP_COPY)
1500 rop = PAT_ROP_GXCOPY;
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001501 else /* ROP_XOR */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 rop = PAT_ROP_GXXOR;
1503
1504 if (dinfo->depth != 8)
1505 color = dinfo->pseudo_palette[rect->color];
1506 else
1507 color = rect->color;
1508
1509 intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy,
1510 rect->width, rect->height, color,
1511 dinfo->pitch, info->var.bits_per_pixel,
1512 rop);
1513}
1514
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001515static void intelfb_copyarea(struct fb_info *info,
1516 const struct fb_copyarea *region)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517{
1518 struct intelfb_info *dinfo = GET_DINFO(info);
1519
1520#if VERBOSE > 0
1521 DBG_MSG("intelfb_copyarea\n");
1522#endif
1523
1524 if (!ACCEL(dinfo, info) || dinfo->depth == 4)
1525 return cfb_copyarea(info, region);
1526
1527 intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx,
1528 region->dy, region->width, region->height,
1529 dinfo->pitch, info->var.bits_per_pixel);
1530}
1531
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001532static void intelfb_imageblit(struct fb_info *info,
1533 const struct fb_image *image)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
1535 struct intelfb_info *dinfo = GET_DINFO(info);
1536 u32 fgcolor, bgcolor;
1537
1538#if VERBOSE > 0
1539 DBG_MSG("intelfb_imageblit\n");
1540#endif
1541
1542 if (!ACCEL(dinfo, info) || dinfo->depth == 4
1543 || image->depth != 1)
1544 return cfb_imageblit(info, image);
1545
1546 if (dinfo->depth != 8) {
1547 fgcolor = dinfo->pseudo_palette[image->fg_color];
1548 bgcolor = dinfo->pseudo_palette[image->bg_color];
1549 } else {
1550 fgcolor = image->fg_color;
1551 bgcolor = image->bg_color;
1552 }
1553
1554 if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width,
1555 image->height, image->data,
1556 image->dx, image->dy,
1557 dinfo->pitch, info->var.bits_per_pixel))
1558 return cfb_imageblit(info, image);
1559}
1560
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001561static int intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
1563 struct intelfb_info *dinfo = GET_DINFO(info);
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001564 u32 physical;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565#if VERBOSE > 0
1566 DBG_MSG("intelfb_cursor\n");
1567#endif
1568
1569 if (!dinfo->hwcursor)
Antonino A. Daplasc465e052005-11-07 01:00:35 -08001570 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 intelfbhw_cursor_hide(dinfo);
1573
1574 /* If XFree killed the cursor - restore it */
Dave Airlie3aff13c2006-03-31 17:08:52 +10001575 physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical :
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001576 (dinfo->cursor.offset << 12);
Dave Airlie8bb91f62006-03-23 13:06:32 +11001577
Dave Airlie8b91b0b2006-03-23 19:23:48 +11001578 if (INREG(CURSOR_A_BASEADDR) != physical) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 u32 fg, bg;
1580
1581 DBG_MSG("the cursor was killed - restore it !!\n");
1582 DBG_MSG("size %d, %d pos %d, %d\n",
1583 cursor->image.width, cursor->image.height,
1584 cursor->image.dx, cursor->image.dy);
1585
1586 intelfbhw_cursor_init(dinfo);
1587 intelfbhw_cursor_reset(dinfo);
1588 intelfbhw_cursor_setpos(dinfo, cursor->image.dx,
1589 cursor->image.dy);
1590
1591 if (dinfo->depth != 8) {
1592 fg =dinfo->pseudo_palette[cursor->image.fg_color];
1593 bg =dinfo->pseudo_palette[cursor->image.bg_color];
1594 } else {
1595 fg = cursor->image.fg_color;
1596 bg = cursor->image.bg_color;
1597 }
1598 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1599 intelfbhw_cursor_load(dinfo, cursor->image.width,
1600 cursor->image.height,
1601 dinfo->cursor_src);
1602
1603 if (cursor->enable)
1604 intelfbhw_cursor_show(dinfo);
1605 return 0;
1606 }
1607
1608 if (cursor->set & FB_CUR_SETPOS) {
1609 u32 dx, dy;
1610
1611 dx = cursor->image.dx - info->var.xoffset;
1612 dy = cursor->image.dy - info->var.yoffset;
1613
1614 intelfbhw_cursor_setpos(dinfo, dx, dy);
1615 }
1616
1617 if (cursor->set & FB_CUR_SETSIZE) {
1618 if (cursor->image.width > 64 || cursor->image.height > 64)
1619 return -ENXIO;
1620
1621 intelfbhw_cursor_reset(dinfo);
1622 }
1623
1624 if (cursor->set & FB_CUR_SETCMAP) {
1625 u32 fg, bg;
1626
1627 if (dinfo->depth != 8) {
1628 fg = dinfo->pseudo_palette[cursor->image.fg_color];
1629 bg = dinfo->pseudo_palette[cursor->image.bg_color];
1630 } else {
1631 fg = cursor->image.fg_color;
1632 bg = cursor->image.bg_color;
1633 }
1634
1635 intelfbhw_cursor_setcolor(dinfo, bg, fg);
1636 }
1637
1638 if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
1639 u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8);
1640 u32 size = s_pitch * cursor->image.height;
1641 u8 *dat = (u8 *) cursor->image.data;
1642 u8 *msk = (u8 *) cursor->mask;
1643 u8 src[64];
1644 u32 i;
1645
1646 if (cursor->image.depth != 1)
1647 return -ENXIO;
1648
1649 switch (cursor->rop) {
1650 case ROP_XOR:
1651 for (i = 0; i < size; i++)
1652 src[i] = dat[i] ^ msk[i];
1653 break;
1654 case ROP_COPY:
1655 default:
1656 for (i = 0; i < size; i++)
1657 src[i] = dat[i] & msk[i];
1658 break;
1659 }
1660
1661 /* save the bitmap to restore it when XFree will
1662 make the cursor dirty */
1663 memcpy(dinfo->cursor_src, src, size);
1664
1665 intelfbhw_cursor_load(dinfo, cursor->image.width,
1666 cursor->image.height, src);
1667 }
1668
1669 if (cursor->enable)
1670 intelfbhw_cursor_show(dinfo);
1671
1672 return 0;
1673}
1674
Krzysztof Halasa689c9562007-10-16 01:29:31 -07001675static int intelfb_sync(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
1677 struct intelfb_info *dinfo = GET_DINFO(info);
1678
1679#if VERBOSE > 0
1680 DBG_MSG("intelfb_sync\n");
1681#endif
1682
1683 if (dinfo->ring_lockup)
1684 return 0;
1685
1686 intelfbhw_do_sync(dinfo);
1687 return 0;
1688}
1689