Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * intelfb |
| 3 | * |
| 4 | * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G |
| 5 | * integrated graphics chips. |
| 6 | * |
| 7 | * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org> |
| 8 | * 2004 Sylvain Meyer |
| 9 | * |
| 10 | * This driver consists of two parts. The first part (intelfbdrv.c) provides |
| 11 | * the basic fbdev interfaces, is derived in part from the radeonfb and |
| 12 | * vesafb drivers, and is covered by the GPL. The second part (intelfbhw.c) |
| 13 | * provides the code to program the hardware. Most of it is derived from |
| 14 | * the i810/i830 XFree86 driver. The HW-specific code is covered here |
| 15 | * under a dual license (GPL and MIT/XFree86 license). |
| 16 | * |
| 17 | * Author: David Dawes |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | /* $DHD: intelfb/intelfbdrv.c,v 1.20 2003/06/27 15:17:40 dawes Exp $ */ |
| 22 | |
| 23 | /* |
| 24 | * Changes: |
| 25 | * 01/2003 - Initial driver (0.1.0), no mode switching, no acceleration. |
| 26 | * This initial version is a basic core that works a lot like |
| 27 | * the vesafb driver. It must be built-in to the kernel, |
| 28 | * and the initial video mode must be set with vga=XXX at |
| 29 | * boot time. (David Dawes) |
| 30 | * |
| 31 | * 01/2003 - Version 0.2.0: Mode switching added, colormap support |
| 32 | * implemented, Y panning, and soft screen blanking implemented. |
| 33 | * No acceleration yet. (David Dawes) |
| 34 | * |
| 35 | * 01/2003 - Version 0.3.0: fbcon acceleration support added. Module |
| 36 | * option handling added. (David Dawes) |
| 37 | * |
| 38 | * 01/2003 - Version 0.4.0: fbcon HW cursor support added. (David Dawes) |
| 39 | * |
| 40 | * 01/2003 - Version 0.4.1: Add auto-generation of built-in modes. |
| 41 | * (David Dawes) |
| 42 | * |
| 43 | * 02/2003 - Version 0.4.2: Add check for active non-CRT devices, and |
| 44 | * mode validation checks. (David Dawes) |
| 45 | * |
| 46 | * 02/2003 - Version 0.4.3: Check when the VC is in graphics mode so that |
| 47 | * acceleration is disabled while an XFree86 server is running. |
| 48 | * (David Dawes) |
| 49 | * |
| 50 | * 02/2003 - Version 0.4.4: Monitor DPMS support. (David Dawes) |
| 51 | * |
| 52 | * 02/2003 - Version 0.4.5: Basic XFree86 + fbdev working. (David Dawes) |
| 53 | * |
| 54 | * 02/2003 - Version 0.5.0: Modify to work with the 2.5.32 kernel as well |
| 55 | * as 2.4.x kernels. (David Dawes) |
| 56 | * |
| 57 | * 02/2003 - Version 0.6.0: Split out HW-specifics into a separate file. |
| 58 | * (David Dawes) |
| 59 | * |
| 60 | * 02/2003 - Version 0.7.0: Test on 852GM/855GM. Acceleration and HW |
| 61 | * cursor are disabled on this platform. (David Dawes) |
| 62 | * |
| 63 | * 02/2003 - Version 0.7.1: Test on 845G. Acceleration is disabled |
| 64 | * on this platform. (David Dawes) |
| 65 | * |
| 66 | * 02/2003 - Version 0.7.2: Test on 830M. Acceleration and HW |
| 67 | * cursor are disabled on this platform. (David Dawes) |
| 68 | * |
| 69 | * 02/2003 - Version 0.7.3: Fix 8-bit modes for mobile platforms |
| 70 | * (David Dawes) |
| 71 | * |
| 72 | * 02/2003 - Version 0.7.4: Add checks for FB and FBCON_HAS_CFB* configured |
| 73 | * in the kernel, and add mode bpp verification and default |
| 74 | * bpp selection based on which FBCON_HAS_CFB* are configured. |
| 75 | * (David Dawes) |
| 76 | * |
| 77 | * 02/2003 - Version 0.7.5: Add basic package/install scripts based on the |
| 78 | * DRI packaging scripts. (David Dawes) |
| 79 | * |
| 80 | * 04/2003 - Version 0.7.6: Fix typo that affects builds with SMP-enabled |
| 81 | * kernels. (David Dawes, reported by Anupam). |
| 82 | * |
| 83 | * 06/2003 - Version 0.7.7: |
| 84 | * Fix Makefile.kernel build problem (Tsutomu Yasuda). |
| 85 | * Fix mis-placed #endif (2.4.21 kernel). |
| 86 | * |
| 87 | * 09/2004 - Version 0.9.0 - by Sylvain Meyer |
| 88 | * Port to linux 2.6 kernel fbdev |
| 89 | * Fix HW accel and HW cursor on i845G |
| 90 | * Use of agpgart for fb memory reservation |
| 91 | * Add mtrr support |
| 92 | * |
| 93 | * 10/2004 - Version 0.9.1 |
| 94 | * Use module_param instead of old MODULE_PARM |
| 95 | * Some cleanup |
| 96 | * |
| 97 | * 11/2004 - Version 0.9.2 |
| 98 | * Add vram option to reserve more memory than stolen by BIOS |
| 99 | * Fix intelfbhw_pan_display typo |
| 100 | * Add __initdata annotations |
| 101 | * |
| 102 | * TODO: |
| 103 | * |
| 104 | * |
| 105 | * Wish List: |
| 106 | * |
| 107 | * |
| 108 | */ |
| 109 | |
| 110 | #include <linux/config.h> |
| 111 | #include <linux/module.h> |
| 112 | #include <linux/kernel.h> |
| 113 | #include <linux/errno.h> |
| 114 | #include <linux/string.h> |
| 115 | #include <linux/mm.h> |
| 116 | #include <linux/tty.h> |
| 117 | #include <linux/slab.h> |
| 118 | #include <linux/delay.h> |
| 119 | #include <linux/fb.h> |
| 120 | #include <linux/console.h> |
| 121 | #include <linux/selection.h> |
| 122 | #include <linux/ioport.h> |
| 123 | #include <linux/init.h> |
| 124 | #include <linux/pci.h> |
| 125 | #include <linux/vmalloc.h> |
| 126 | #include <linux/kd.h> |
| 127 | #include <linux/vt_kern.h> |
| 128 | #include <linux/pagemap.h> |
| 129 | #include <linux/version.h> |
| 130 | |
| 131 | #include <asm/io.h> |
| 132 | |
| 133 | #ifdef CONFIG_MTRR |
| 134 | #include <asm/mtrr.h> |
| 135 | #endif |
| 136 | |
| 137 | #include "intelfb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | #include "intelfbhw.h" |
| 139 | |
Adrian Bunk | 14c6f52 | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 140 | static void __devinit get_initial_mode(struct intelfb_info *dinfo); |
| 141 | static void update_dinfo(struct intelfb_info *dinfo, |
| 142 | struct fb_var_screeninfo *var); |
| 143 | static int intelfb_get_fix(struct fb_fix_screeninfo *fix, |
| 144 | struct fb_info *info); |
| 145 | |
| 146 | static int intelfb_check_var(struct fb_var_screeninfo *var, |
| 147 | struct fb_info *info); |
| 148 | static int intelfb_set_par(struct fb_info *info); |
| 149 | static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 150 | unsigned blue, unsigned transp, |
| 151 | struct fb_info *info); |
| 152 | |
| 153 | static int intelfb_blank(int blank, struct fb_info *info); |
| 154 | static int intelfb_pan_display(struct fb_var_screeninfo *var, |
| 155 | struct fb_info *info); |
| 156 | |
| 157 | static void intelfb_fillrect(struct fb_info *info, |
| 158 | const struct fb_fillrect *rect); |
| 159 | static void intelfb_copyarea(struct fb_info *info, |
| 160 | const struct fb_copyarea *region); |
| 161 | static void intelfb_imageblit(struct fb_info *info, |
| 162 | const struct fb_image *image); |
| 163 | static int intelfb_cursor(struct fb_info *info, |
| 164 | struct fb_cursor *cursor); |
| 165 | |
| 166 | static int intelfb_sync(struct fb_info *info); |
| 167 | |
| 168 | static int intelfb_ioctl(struct inode *inode, struct file *file, |
| 169 | unsigned int cmd, unsigned long arg, |
| 170 | struct fb_info *info); |
| 171 | |
| 172 | static int __devinit intelfb_pci_register(struct pci_dev *pdev, |
| 173 | const struct pci_device_id *ent); |
| 174 | static void __devexit intelfb_pci_unregister(struct pci_dev *pdev); |
| 175 | static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo); |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | /* |
| 178 | * Limiting the class to PCI_CLASS_DISPLAY_VGA prevents function 1 of the |
| 179 | * mobile chipsets from being registered. |
| 180 | */ |
| 181 | #if DETECT_VGA_CLASS_ONLY |
| 182 | #define INTELFB_CLASS_MASK ~0 << 8 |
| 183 | #else |
| 184 | #define INTELFB_CLASS_MASK 0 |
| 185 | #endif |
| 186 | |
| 187 | static struct pci_device_id intelfb_pci_table[] __devinitdata = { |
| 188 | { 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 }, |
| 189 | { 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 }, |
| 190 | { 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 }, |
| 191 | { 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 }, |
| 192 | { 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 }, |
| 193 | { 0, } |
| 194 | }; |
| 195 | |
| 196 | /* Global data */ |
| 197 | static int num_registered = 0; |
| 198 | |
| 199 | /* fb ops */ |
| 200 | static struct fb_ops intel_fb_ops = { |
| 201 | .owner = THIS_MODULE, |
| 202 | .fb_check_var = intelfb_check_var, |
| 203 | .fb_set_par = intelfb_set_par, |
| 204 | .fb_setcolreg = intelfb_setcolreg, |
| 205 | .fb_blank = intelfb_blank, |
| 206 | .fb_pan_display = intelfb_pan_display, |
| 207 | .fb_fillrect = intelfb_fillrect, |
| 208 | .fb_copyarea = intelfb_copyarea, |
| 209 | .fb_imageblit = intelfb_imageblit, |
| 210 | .fb_cursor = intelfb_cursor, |
| 211 | .fb_sync = intelfb_sync, |
| 212 | .fb_ioctl = intelfb_ioctl |
| 213 | }; |
| 214 | |
| 215 | /* PCI driver module table */ |
| 216 | static struct pci_driver intelfb_driver = { |
Andrew Morton | 5a3b589 | 2005-06-21 17:16:57 -0700 | [diff] [blame] | 217 | .name = "intelfb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | .id_table = intelfb_pci_table, |
| 219 | .probe = intelfb_pci_register, |
| 220 | .remove = __devexit_p(intelfb_pci_unregister) |
| 221 | }; |
| 222 | |
| 223 | /* Module description/parameters */ |
| 224 | MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, " |
| 225 | "Sylvain Meyer <sylvain.meyer@worldonline.fr>"); |
| 226 | MODULE_DESCRIPTION( |
| 227 | "Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS " chipsets"); |
| 228 | MODULE_LICENSE("Dual BSD/GPL"); |
| 229 | MODULE_DEVICE_TABLE(pci, intelfb_pci_table); |
| 230 | |
Patrick McManus | 346e399 | 2005-05-28 15:51:46 -0700 | [diff] [blame] | 231 | static int accel = 1; |
| 232 | static int vram = 4; |
| 233 | static int hwcursor = 1; |
| 234 | static int mtrr = 1; |
| 235 | static int fixed = 0; |
| 236 | static int noinit = 0; |
| 237 | static int noregister = 0; |
| 238 | static int probeonly = 0; |
| 239 | static int idonly = 0; |
| 240 | static int bailearly = 0; |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 241 | static int voffset = 48; |
Patrick McManus | 346e399 | 2005-05-28 15:51:46 -0700 | [diff] [blame] | 242 | static char *mode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | module_param(accel, bool, S_IRUGO); |
| 245 | MODULE_PARM_DESC(accel, "Enable console acceleration"); |
| 246 | module_param(vram, int, S_IRUGO); |
| 247 | MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"); |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 248 | module_param(voffset, int, S_IRUGO); |
| 249 | MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | module_param(hwcursor, bool, S_IRUGO); |
| 251 | MODULE_PARM_DESC(hwcursor, "Enable HW cursor"); |
| 252 | module_param(mtrr, bool, S_IRUGO); |
| 253 | MODULE_PARM_DESC(mtrr, "Enable MTRR support"); |
| 254 | module_param(fixed, bool, S_IRUGO); |
| 255 | MODULE_PARM_DESC(fixed, "Disable mode switching"); |
| 256 | module_param(noinit, bool, 0); |
| 257 | MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading"); |
| 258 | module_param(noregister, bool, 0); |
| 259 | MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)"); |
| 260 | module_param(probeonly, bool, 0); |
| 261 | MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)"); |
| 262 | module_param(idonly, bool, 0); |
| 263 | MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)"); |
| 264 | module_param(bailearly, bool, 0); |
| 265 | MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)"); |
| 266 | module_param(mode, charp, S_IRUGO); |
| 267 | MODULE_PARM_DESC(mode, |
| 268 | "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\""); |
| 269 | |
| 270 | #ifndef MODULE |
| 271 | #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name))) |
| 272 | #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name), NULL, 0) |
| 273 | #define OPT_STRVAL(opt, name) (opt + strlen(name)) |
| 274 | |
| 275 | static __inline__ char * |
| 276 | get_opt_string(const char *this_opt, const char *name) |
| 277 | { |
| 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 | |
| 294 | static __inline__ int |
| 295 | get_opt_int(const char *this_opt, const char *name, int *ret) |
| 296 | { |
| 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 | |
| 307 | static __inline__ int |
| 308 | get_opt_bool(const char *this_opt, const char *name, int *ret) |
| 309 | { |
| 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 | |
| 328 | static int __init |
| 329 | intelfb_setup(char *options) |
| 330 | { |
| 331 | char *this_opt; |
| 332 | |
| 333 | DBG_MSG("intelfb_setup\n"); |
| 334 | |
| 335 | if (!options || !*options) { |
| 336 | DBG_MSG("no options\n"); |
| 337 | return 0; |
| 338 | } else |
| 339 | DBG_MSG("options: %s\n", options); |
| 340 | |
| 341 | /* |
| 342 | * These are the built-in options analogous to the module parameters |
| 343 | * defined above. |
| 344 | * |
| 345 | * The syntax is: |
| 346 | * |
| 347 | * video=intelfb:[mode][,<param>=<val>] ... |
| 348 | * |
| 349 | * e.g., |
| 350 | * |
| 351 | * video=intelfb:1024x768-16@75,accel=0 |
| 352 | */ |
| 353 | |
| 354 | while ((this_opt = strsep(&options, ","))) { |
| 355 | if (!*this_opt) |
| 356 | continue; |
| 357 | if (get_opt_bool(this_opt, "accel", &accel)) |
| 358 | ; |
| 359 | else if (get_opt_int(this_opt, "vram", &vram)) |
| 360 | ; |
| 361 | else if (get_opt_bool(this_opt, "hwcursor", &hwcursor)) |
| 362 | ; |
| 363 | else if (get_opt_bool(this_opt, "mtrr", &mtrr)) |
| 364 | ; |
| 365 | else if (get_opt_bool(this_opt, "fixed", &fixed)) |
| 366 | ; |
| 367 | else if (get_opt_bool(this_opt, "init", &noinit)) |
| 368 | noinit = !noinit; |
| 369 | else if (OPT_EQUAL(this_opt, "mode=")) |
| 370 | mode = get_opt_string(this_opt, "mode="); |
| 371 | else |
| 372 | mode = this_opt; |
| 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | #endif |
| 379 | |
| 380 | static int __init |
| 381 | intelfb_init(void) |
| 382 | { |
| 383 | #ifndef MODULE |
| 384 | char *option = NULL; |
| 385 | #endif |
| 386 | |
| 387 | DBG_MSG("intelfb_init\n"); |
| 388 | |
| 389 | INF_MSG("Framebuffer driver for " |
| 390 | "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n"); |
| 391 | INF_MSG("Version " INTELFB_VERSION "\n"); |
| 392 | |
| 393 | if (idonly) |
| 394 | return -ENODEV; |
| 395 | |
| 396 | #ifndef MODULE |
| 397 | if (fb_get_options("intelfb", &option)) |
| 398 | return -ENODEV; |
| 399 | intelfb_setup(option); |
| 400 | #endif |
| 401 | |
| 402 | return pci_register_driver(&intelfb_driver); |
| 403 | } |
| 404 | |
| 405 | static void __exit |
| 406 | intelfb_exit(void) |
| 407 | { |
| 408 | DBG_MSG("intelfb_exit\n"); |
| 409 | pci_unregister_driver(&intelfb_driver); |
| 410 | } |
| 411 | |
| 412 | module_init(intelfb_init); |
| 413 | module_exit(intelfb_exit); |
| 414 | |
| 415 | /*************************************************************** |
| 416 | * mtrr support functions * |
| 417 | ***************************************************************/ |
| 418 | |
| 419 | #ifdef CONFIG_MTRR |
| 420 | static inline void __devinit set_mtrr(struct intelfb_info *dinfo) |
| 421 | { |
| 422 | dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical, |
| 423 | dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1); |
| 424 | if (dinfo->mtrr_reg < 0) { |
| 425 | ERR_MSG("unable to set MTRR\n"); |
| 426 | return; |
| 427 | } |
| 428 | dinfo->has_mtrr = 1; |
| 429 | } |
| 430 | static inline void unset_mtrr(struct intelfb_info *dinfo) |
| 431 | { |
| 432 | if (dinfo->has_mtrr) |
| 433 | mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical, |
| 434 | dinfo->aperture.size); |
| 435 | } |
| 436 | #else |
| 437 | #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n") |
| 438 | |
| 439 | #define unset_mtrr(x) do { } while (0) |
| 440 | #endif /* CONFIG_MTRR */ |
| 441 | |
| 442 | /*************************************************************** |
| 443 | * driver init / cleanup * |
| 444 | ***************************************************************/ |
| 445 | |
| 446 | static void |
| 447 | cleanup(struct intelfb_info *dinfo) |
| 448 | { |
| 449 | DBG_MSG("cleanup\n"); |
| 450 | |
| 451 | if (!dinfo) |
| 452 | return; |
| 453 | |
| 454 | fb_dealloc_cmap(&dinfo->info->cmap); |
| 455 | kfree(dinfo->info->pixmap.addr); |
| 456 | |
| 457 | if (dinfo->registered) |
| 458 | unregister_framebuffer(dinfo->info); |
| 459 | |
| 460 | unset_mtrr(dinfo); |
| 461 | |
| 462 | if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) { |
| 463 | agp_unbind_memory(dinfo->gtt_fb_mem); |
| 464 | agp_free_memory(dinfo->gtt_fb_mem); |
| 465 | } |
| 466 | if (dinfo->gtt_cursor_mem) { |
| 467 | agp_unbind_memory(dinfo->gtt_cursor_mem); |
| 468 | agp_free_memory(dinfo->gtt_cursor_mem); |
| 469 | } |
| 470 | if (dinfo->gtt_ring_mem) { |
| 471 | agp_unbind_memory(dinfo->gtt_ring_mem); |
| 472 | agp_free_memory(dinfo->gtt_ring_mem); |
| 473 | } |
| 474 | |
| 475 | if (dinfo->mmio_base) |
| 476 | iounmap((void __iomem *)dinfo->mmio_base); |
| 477 | if (dinfo->aperture.virtual) |
| 478 | iounmap((void __iomem *)dinfo->aperture.virtual); |
| 479 | |
| 480 | if (dinfo->mmio_base_phys) |
| 481 | release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE); |
| 482 | if (dinfo->aperture.physical) |
| 483 | release_mem_region(dinfo->aperture.physical, |
| 484 | dinfo->aperture.size); |
| 485 | framebuffer_release(dinfo->info); |
| 486 | } |
| 487 | |
| 488 | #define bailout(dinfo) do { \ |
| 489 | DBG_MSG("bailout\n"); \ |
| 490 | cleanup(dinfo); \ |
| 491 | INF_MSG("Not going to register framebuffer, exiting...\n"); \ |
| 492 | return -ENODEV; \ |
| 493 | } while (0) |
| 494 | |
| 495 | |
| 496 | static int __devinit |
| 497 | intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 498 | { |
| 499 | struct fb_info *info; |
| 500 | struct intelfb_info *dinfo; |
| 501 | int i, j, err, dvo; |
| 502 | int aperture_size, stolen_size; |
| 503 | struct agp_kern_info gtt_info; |
| 504 | int agp_memtype; |
| 505 | const char *s; |
| 506 | struct agp_bridge_data *bridge; |
| 507 | int aperture_bar = 0; |
| 508 | int mmio_bar = 1; |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 509 | int offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | DBG_MSG("intelfb_pci_register\n"); |
| 512 | |
| 513 | num_registered++; |
| 514 | if (num_registered != 1) { |
| 515 | ERR_MSG("Attempted to register %d devices " |
| 516 | "(should be only 1).\n", num_registered); |
| 517 | return -ENODEV; |
| 518 | } |
| 519 | |
| 520 | info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev); |
| 521 | if (!info) { |
| 522 | ERR_MSG("Could not allocate memory for intelfb_info.\n"); |
| 523 | return -ENODEV; |
| 524 | } |
| 525 | if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) { |
| 526 | ERR_MSG("Could not allocate cmap for intelfb_info.\n"); |
| 527 | goto err_out_cmap; |
| 528 | return -ENODEV; |
| 529 | } |
| 530 | |
| 531 | dinfo = info->par; |
| 532 | dinfo->info = info; |
| 533 | dinfo->fbops = &intel_fb_ops; |
| 534 | dinfo->pdev = pdev; |
| 535 | |
| 536 | /* Reserve pixmap space. */ |
| 537 | info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL); |
| 538 | if (info->pixmap.addr == NULL) { |
| 539 | ERR_MSG("Cannot reserve pixmap memory.\n"); |
| 540 | goto err_out_pixmap; |
| 541 | } |
| 542 | memset(info->pixmap.addr, 0, 64 * 1024); |
| 543 | |
| 544 | /* set early this option because it could be changed by tv encoder |
| 545 | driver */ |
| 546 | dinfo->fixed_mode = fixed; |
| 547 | |
| 548 | /* Enable device. */ |
| 549 | if ((err = pci_enable_device(pdev))) { |
| 550 | ERR_MSG("Cannot enable device.\n"); |
| 551 | cleanup(dinfo); |
| 552 | return -ENODEV; |
| 553 | } |
| 554 | |
| 555 | /* Set base addresses. */ |
| 556 | if (ent->device == PCI_DEVICE_ID_INTEL_915G) { |
| 557 | aperture_bar = 2; |
| 558 | mmio_bar = 0; |
| 559 | /* Disable HW cursor on 915G (not implemented yet) */ |
| 560 | hwcursor = 0; |
| 561 | } |
| 562 | dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar); |
| 563 | dinfo->aperture.size = pci_resource_len(pdev, aperture_bar); |
| 564 | dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar); |
| 565 | DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n", |
| 566 | (unsigned long long)pci_resource_start(pdev, aperture_bar), |
| 567 | (unsigned long long)pci_resource_len(pdev, aperture_bar), |
| 568 | (unsigned long long)pci_resource_start(pdev, mmio_bar), |
| 569 | (unsigned long long)pci_resource_len(pdev, mmio_bar)); |
| 570 | |
| 571 | /* Reserve the fb and MMIO regions */ |
| 572 | if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size, |
| 573 | INTELFB_MODULE_NAME)) { |
| 574 | ERR_MSG("Cannot reserve FB region.\n"); |
| 575 | cleanup(dinfo); |
| 576 | return -ENODEV; |
| 577 | } |
| 578 | if (!request_mem_region(dinfo->mmio_base_phys, |
| 579 | INTEL_REG_SIZE, |
| 580 | INTELFB_MODULE_NAME)) { |
| 581 | ERR_MSG("Cannot reserve MMIO region.\n"); |
| 582 | cleanup(dinfo); |
| 583 | return -ENODEV; |
| 584 | } |
| 585 | |
| 586 | /* Map the fb and MMIO regions */ |
| 587 | dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache |
| 588 | (dinfo->aperture.physical, dinfo->aperture.size); |
| 589 | if (!dinfo->aperture.virtual) { |
| 590 | ERR_MSG("Cannot remap FB region.\n"); |
| 591 | cleanup(dinfo); |
| 592 | return -ENODEV; |
| 593 | } |
| 594 | dinfo->mmio_base = |
| 595 | (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys, |
| 596 | INTEL_REG_SIZE); |
| 597 | if (!dinfo->mmio_base) { |
| 598 | ERR_MSG("Cannot remap MMIO region.\n"); |
| 599 | cleanup(dinfo); |
| 600 | return -ENODEV; |
| 601 | } |
| 602 | |
| 603 | /* Get the chipset info. */ |
| 604 | dinfo->pci_chipset = pdev->device; |
| 605 | |
| 606 | if (intelfbhw_get_chipset(pdev, &dinfo->name, &dinfo->chipset, |
| 607 | &dinfo->mobile)) { |
| 608 | cleanup(dinfo); |
| 609 | return -ENODEV; |
| 610 | } |
| 611 | |
| 612 | if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) { |
| 613 | cleanup(dinfo); |
| 614 | return -ENODEV; |
| 615 | } |
| 616 | |
| 617 | INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, " |
| 618 | "stolen memory %dkB\n", |
| 619 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 620 | PCI_FUNC(pdev->devfn), dinfo->name, |
| 621 | BtoMB(aperture_size), BtoKB(stolen_size)); |
| 622 | |
| 623 | /* Set these from the options. */ |
| 624 | dinfo->accel = accel; |
| 625 | dinfo->hwcursor = hwcursor; |
| 626 | |
| 627 | if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) { |
| 628 | INF_MSG("Acceleration is not supported for the %s chipset.\n", |
| 629 | dinfo->name); |
| 630 | dinfo->accel = 0; |
| 631 | } |
| 632 | |
| 633 | /* Framebuffer parameters - Use all the stolen memory if >= vram */ |
| 634 | if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) { |
| 635 | dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size); |
| 636 | dinfo->fbmem_gart = 0; |
| 637 | } else { |
| 638 | dinfo->fb.size = MB(vram); |
| 639 | dinfo->fbmem_gart = 1; |
| 640 | } |
| 641 | |
| 642 | /* Allocate space for the ring buffer and HW cursor if enabled. */ |
| 643 | if (dinfo->accel) { |
| 644 | dinfo->ring.size = RINGBUFFER_SIZE; |
| 645 | dinfo->ring_tail_mask = dinfo->ring.size - 1; |
| 646 | } |
| 647 | if (dinfo->hwcursor) { |
| 648 | dinfo->cursor.size = HW_CURSOR_SIZE; |
| 649 | } |
| 650 | |
| 651 | /* Use agpgart to manage the GATT */ |
| 652 | if (!(bridge = agp_backend_acquire(pdev))) { |
| 653 | ERR_MSG("cannot acquire agp\n"); |
| 654 | cleanup(dinfo); |
| 655 | return -ENODEV; |
| 656 | } |
| 657 | |
| 658 | /* get the current gatt info */ |
| 659 | if (agp_copy_info(bridge, >t_info)) { |
| 660 | ERR_MSG("cannot get agp info\n"); |
| 661 | agp_backend_release(bridge); |
| 662 | cleanup(dinfo); |
| 663 | return -ENODEV; |
| 664 | } |
| 665 | |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 666 | if (MB(voffset) < stolen_size) |
| 667 | offset = (stolen_size >> 12); |
| 668 | else |
| 669 | offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE; |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* set the mem offsets - set them after the already used pages */ |
| 672 | if (dinfo->accel) { |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 673 | dinfo->ring.offset = offset + gtt_info.current_memory; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | if (dinfo->hwcursor) { |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 676 | dinfo->cursor.offset = offset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | + gtt_info.current_memory + (dinfo->ring.size >> 12); |
| 678 | } |
| 679 | if (dinfo->fbmem_gart) { |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame^] | 680 | dinfo->fb.offset = offset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | + gtt_info.current_memory + (dinfo->ring.size >> 12) |
| 682 | + (dinfo->cursor.size >> 12); |
| 683 | } |
| 684 | |
| 685 | /* Allocate memories (which aren't stolen) */ |
| 686 | if (dinfo->accel) { |
| 687 | if (!(dinfo->gtt_ring_mem = |
| 688 | agp_allocate_memory(bridge, dinfo->ring.size >> 12, |
| 689 | AGP_NORMAL_MEMORY))) { |
| 690 | ERR_MSG("cannot allocate ring buffer memory\n"); |
| 691 | agp_backend_release(bridge); |
| 692 | cleanup(dinfo); |
| 693 | return -ENOMEM; |
| 694 | } |
| 695 | if (agp_bind_memory(dinfo->gtt_ring_mem, |
| 696 | dinfo->ring.offset)) { |
| 697 | ERR_MSG("cannot bind ring buffer memory\n"); |
| 698 | agp_backend_release(bridge); |
| 699 | cleanup(dinfo); |
| 700 | return -EBUSY; |
| 701 | } |
| 702 | dinfo->ring.physical = dinfo->aperture.physical |
| 703 | + (dinfo->ring.offset << 12); |
| 704 | dinfo->ring.virtual = dinfo->aperture.virtual |
| 705 | + (dinfo->ring.offset << 12); |
| 706 | dinfo->ring_head = dinfo->ring.virtual; |
| 707 | } |
| 708 | if (dinfo->hwcursor) { |
| 709 | agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY |
| 710 | : AGP_NORMAL_MEMORY; |
| 711 | if (!(dinfo->gtt_cursor_mem = |
| 712 | agp_allocate_memory(bridge, dinfo->cursor.size >> 12, |
| 713 | agp_memtype))) { |
| 714 | ERR_MSG("cannot allocate cursor memory\n"); |
| 715 | agp_backend_release(bridge); |
| 716 | cleanup(dinfo); |
| 717 | return -ENOMEM; |
| 718 | } |
| 719 | if (agp_bind_memory(dinfo->gtt_cursor_mem, |
| 720 | dinfo->cursor.offset)) { |
| 721 | ERR_MSG("cannot bind cursor memory\n"); |
| 722 | agp_backend_release(bridge); |
| 723 | cleanup(dinfo); |
| 724 | return -EBUSY; |
| 725 | } |
| 726 | if (dinfo->mobile) |
| 727 | dinfo->cursor.physical |
| 728 | = dinfo->gtt_cursor_mem->physical; |
| 729 | else |
| 730 | dinfo->cursor.physical = dinfo->aperture.physical |
| 731 | + (dinfo->cursor.offset << 12); |
| 732 | dinfo->cursor.virtual = dinfo->aperture.virtual |
| 733 | + (dinfo->cursor.offset << 12); |
| 734 | } |
| 735 | if (dinfo->fbmem_gart) { |
| 736 | if (!(dinfo->gtt_fb_mem = |
| 737 | agp_allocate_memory(bridge, dinfo->fb.size >> 12, |
| 738 | AGP_NORMAL_MEMORY))) { |
| 739 | WRN_MSG("cannot allocate framebuffer memory - use " |
| 740 | "the stolen one\n"); |
| 741 | dinfo->fbmem_gart = 0; |
| 742 | } |
| 743 | if (agp_bind_memory(dinfo->gtt_fb_mem, |
| 744 | dinfo->fb.offset)) { |
| 745 | WRN_MSG("cannot bind framebuffer memory - use " |
| 746 | "the stolen one\n"); |
| 747 | dinfo->fbmem_gart = 0; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | /* update framebuffer memory parameters */ |
| 752 | if (!dinfo->fbmem_gart) |
| 753 | dinfo->fb.offset = 0; /* starts at offset 0 */ |
| 754 | dinfo->fb.physical = dinfo->aperture.physical |
| 755 | + (dinfo->fb.offset << 12); |
| 756 | dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12); |
| 757 | dinfo->fb_start = dinfo->fb.offset << 12; |
| 758 | |
| 759 | /* release agpgart */ |
| 760 | agp_backend_release(bridge); |
| 761 | |
| 762 | if (mtrr) |
| 763 | set_mtrr(dinfo); |
| 764 | |
| 765 | DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%x)\n", |
| 766 | dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size, |
| 767 | (u32 __iomem ) dinfo->fb.virtual); |
| 768 | DBG_MSG("MMIO: 0x%x/0x%x (0x%x)\n", |
| 769 | dinfo->mmio_base_phys, INTEL_REG_SIZE, |
| 770 | (u32 __iomem) dinfo->mmio_base); |
| 771 | DBG_MSG("ring buffer: 0x%x/0x%x (0x%x)\n", |
| 772 | dinfo->ring.physical, dinfo->ring.size, |
| 773 | (u32 __iomem ) dinfo->ring.virtual); |
| 774 | DBG_MSG("HW cursor: 0x%x/0x%x (0x%x) (offset 0x%x) (phys 0x%x)\n", |
| 775 | dinfo->cursor.physical, dinfo->cursor.size, |
| 776 | (u32 __iomem ) dinfo->cursor.virtual, dinfo->cursor.offset, |
| 777 | dinfo->cursor.physical); |
| 778 | |
| 779 | DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, " |
| 780 | "noinit = %d\n", vram, accel, hwcursor, fixed, noinit); |
| 781 | DBG_MSG("options: mode = \"%s\"\n", mode ? mode : ""); |
| 782 | |
| 783 | if (probeonly) |
| 784 | bailout(dinfo); |
| 785 | |
| 786 | /* |
| 787 | * Check if the LVDS port or any DVO ports are enabled. If so, |
| 788 | * don't allow mode switching |
| 789 | */ |
| 790 | dvo = intelfbhw_check_non_crt(dinfo); |
| 791 | if (dvo) { |
| 792 | dinfo->fixed_mode = 1; |
| 793 | WRN_MSG("Non-CRT device is enabled ( "); |
| 794 | i = 0; |
| 795 | while (dvo) { |
| 796 | if (dvo & 1) { |
| 797 | s = intelfbhw_dvo_to_string(1 << i); |
| 798 | if (s) |
| 799 | printk("%s ", s); |
| 800 | } |
| 801 | dvo >>= 1; |
| 802 | ++i; |
| 803 | } |
| 804 | printk("). Disabling mode switching.\n"); |
| 805 | } |
| 806 | |
| 807 | if (bailearly == 1) |
| 808 | bailout(dinfo); |
| 809 | |
| 810 | if (FIXED_MODE(dinfo) && ORIG_VIDEO_ISVGA != VIDEO_TYPE_VLFB) { |
| 811 | ERR_MSG("Video mode must be programmed at boot time.\n"); |
| 812 | cleanup(dinfo); |
| 813 | return -ENODEV; |
| 814 | } |
| 815 | |
| 816 | if (bailearly == 2) |
| 817 | bailout(dinfo); |
| 818 | |
| 819 | /* Initialise dinfo and related data. */ |
| 820 | /* If an initial mode was programmed at boot time, get its details. */ |
| 821 | if (ORIG_VIDEO_ISVGA == VIDEO_TYPE_VLFB) |
| 822 | get_initial_mode(dinfo); |
| 823 | |
| 824 | if (bailearly == 3) |
| 825 | bailout(dinfo); |
| 826 | |
| 827 | if (FIXED_MODE(dinfo)) { |
| 828 | /* remap fb address */ |
| 829 | update_dinfo(dinfo, &dinfo->initial_var); |
| 830 | } |
| 831 | |
| 832 | if (bailearly == 4) |
| 833 | bailout(dinfo); |
| 834 | |
| 835 | |
| 836 | if (intelfb_set_fbinfo(dinfo)) { |
| 837 | cleanup(dinfo); |
| 838 | return -ENODEV; |
| 839 | } |
| 840 | |
| 841 | if (bailearly == 5) |
| 842 | bailout(dinfo); |
| 843 | |
| 844 | for (i = 0; i < 16; i++) { |
| 845 | j = color_table[i]; |
| 846 | dinfo->palette[i].red = default_red[j]; |
| 847 | dinfo->palette[i].green = default_grn[j]; |
| 848 | dinfo->palette[i].blue = default_blu[j]; |
| 849 | } |
| 850 | |
| 851 | if (bailearly == 6) |
| 852 | bailout(dinfo); |
| 853 | |
| 854 | pci_set_drvdata(pdev, dinfo); |
| 855 | |
| 856 | /* Save the initial register state. */ |
| 857 | i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state, |
| 858 | bailearly > 6 ? bailearly - 6 : 0); |
| 859 | if (i != 0) { |
| 860 | DBG_MSG("intelfbhw_read_hw_state returned %d\n", i); |
| 861 | bailout(dinfo); |
| 862 | } |
| 863 | |
| 864 | intelfbhw_print_hw_state(dinfo, &dinfo->save_state); |
| 865 | |
| 866 | if (bailearly == 18) |
| 867 | bailout(dinfo); |
| 868 | |
| 869 | /* Cursor initialisation */ |
| 870 | if (dinfo->hwcursor) { |
| 871 | intelfbhw_cursor_init(dinfo); |
| 872 | intelfbhw_cursor_reset(dinfo); |
| 873 | } |
| 874 | |
| 875 | if (bailearly == 19) |
| 876 | bailout(dinfo); |
| 877 | |
| 878 | /* 2d acceleration init */ |
| 879 | if (dinfo->accel) |
| 880 | intelfbhw_2d_start(dinfo); |
| 881 | |
| 882 | if (bailearly == 20) |
| 883 | bailout(dinfo); |
| 884 | |
| 885 | if (noregister) |
| 886 | bailout(dinfo); |
| 887 | |
| 888 | if (register_framebuffer(dinfo->info) < 0) { |
| 889 | ERR_MSG("Cannot register framebuffer.\n"); |
| 890 | cleanup(dinfo); |
| 891 | return -ENODEV; |
| 892 | } |
| 893 | |
| 894 | dinfo->registered = 1; |
| 895 | |
| 896 | return 0; |
| 897 | |
| 898 | err_out_pixmap: |
| 899 | fb_dealloc_cmap(&info->cmap); |
| 900 | err_out_cmap: |
| 901 | framebuffer_release(info); |
| 902 | return -ENODEV; |
| 903 | } |
| 904 | |
| 905 | static void __devexit |
| 906 | intelfb_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 | |
| 924 | int __inline__ |
| 925 | intelfb_var_to_depth(const struct fb_var_screeninfo *var) |
| 926 | { |
| 927 | DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n", |
| 928 | var->bits_per_pixel, var->green.length); |
| 929 | |
| 930 | switch (var->bits_per_pixel) { |
| 931 | case 16: |
| 932 | return (var->green.length == 6) ? 16 : 15; |
| 933 | case 32: |
| 934 | return 24; |
| 935 | default: |
| 936 | return var->bits_per_pixel; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | |
| 941 | static __inline__ int |
| 942 | var_to_refresh(const struct fb_var_screeninfo *var) |
| 943 | { |
| 944 | int xtot = var->xres + var->left_margin + var->right_margin + |
| 945 | var->hsync_len; |
| 946 | int ytot = var->yres + var->upper_margin + var->lower_margin + |
| 947 | var->vsync_len; |
| 948 | |
| 949 | return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot; |
| 950 | } |
| 951 | |
| 952 | /*************************************************************** |
| 953 | * Various intialisation functions * |
| 954 | ***************************************************************/ |
| 955 | |
| 956 | static void __devinit |
| 957 | get_initial_mode(struct intelfb_info *dinfo) |
| 958 | { |
| 959 | struct fb_var_screeninfo *var; |
| 960 | int xtot, ytot; |
| 961 | |
| 962 | DBG_MSG("get_initial_mode\n"); |
| 963 | |
| 964 | dinfo->initial_vga = 1; |
| 965 | dinfo->initial_fb_base = screen_info.lfb_base; |
| 966 | dinfo->initial_video_ram = screen_info.lfb_size * KB(64); |
| 967 | dinfo->initial_pitch = screen_info.lfb_linelength; |
| 968 | |
| 969 | var = &dinfo->initial_var; |
| 970 | memset(var, 0, sizeof(*var)); |
| 971 | var->xres = screen_info.lfb_width; |
| 972 | var->yres = screen_info.lfb_height; |
| 973 | var->bits_per_pixel = screen_info.lfb_depth; |
| 974 | switch (screen_info.lfb_depth) { |
| 975 | case 15: |
| 976 | var->bits_per_pixel = 16; |
| 977 | break; |
| 978 | case 24: |
| 979 | var->bits_per_pixel = 32; |
| 980 | break; |
| 981 | } |
| 982 | |
| 983 | DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n", |
| 984 | dinfo->initial_fb_base, dinfo->initial_video_ram, |
| 985 | BtoKB(dinfo->initial_video_ram)); |
| 986 | |
| 987 | DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n", |
| 988 | var->xres, var->yres, var->bits_per_pixel, |
| 989 | dinfo->initial_pitch); |
| 990 | |
| 991 | /* Dummy timing values (assume 60Hz) */ |
| 992 | var->left_margin = (var->xres / 8) & 0xf8; |
| 993 | var->right_margin = 32; |
| 994 | var->upper_margin = 16; |
| 995 | var->lower_margin = 4; |
| 996 | var->hsync_len = (var->xres / 8) & 0xf8; |
| 997 | var->vsync_len = 4; |
| 998 | |
| 999 | xtot = var->xres + var->left_margin + |
| 1000 | var->right_margin + var->hsync_len; |
| 1001 | ytot = var->yres + var->upper_margin + |
| 1002 | var->lower_margin + var->vsync_len; |
| 1003 | var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60; |
| 1004 | |
| 1005 | var->height = -1; |
| 1006 | var->width = -1; |
| 1007 | |
| 1008 | if (var->bits_per_pixel > 8) { |
| 1009 | var->red.offset = screen_info.red_pos; |
| 1010 | var->red.length = screen_info.red_size; |
| 1011 | var->green.offset = screen_info.green_pos; |
| 1012 | var->green.length = screen_info.green_size; |
| 1013 | var->blue.offset = screen_info.blue_pos; |
| 1014 | var->blue.length = screen_info.blue_size; |
| 1015 | var->transp.offset = screen_info.rsvd_pos; |
| 1016 | var->transp.length = screen_info.rsvd_size; |
| 1017 | } else { |
| 1018 | var->red.length = 8; |
| 1019 | var->green.length = 8; |
| 1020 | var->blue.length = 8; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | static int __devinit |
| 1025 | intelfb_init_var(struct intelfb_info *dinfo) |
| 1026 | { |
| 1027 | struct fb_var_screeninfo *var; |
| 1028 | int msrc = 0; |
| 1029 | |
| 1030 | DBG_MSG("intelfb_init_var\n"); |
| 1031 | |
| 1032 | var = &dinfo->info->var; |
| 1033 | if (FIXED_MODE(dinfo)) { |
| 1034 | memcpy(var, &dinfo->initial_var, |
| 1035 | sizeof(struct fb_var_screeninfo)); |
| 1036 | msrc = 5; |
| 1037 | } else { |
| 1038 | if (mode) { |
| 1039 | msrc = fb_find_mode(var, dinfo->info, mode, |
| 1040 | vesa_modes, VESA_MODEDB_SIZE, |
| 1041 | NULL, 0); |
| 1042 | if (msrc) |
| 1043 | msrc |= 8; |
| 1044 | } |
| 1045 | if (!msrc) { |
| 1046 | msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE, |
| 1047 | vesa_modes, VESA_MODEDB_SIZE, |
| 1048 | NULL, 0); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | if (!msrc) { |
| 1053 | ERR_MSG("Cannot find a suitable video mode.\n"); |
| 1054 | return 1; |
| 1055 | } |
| 1056 | |
| 1057 | INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres, |
| 1058 | var->bits_per_pixel, var_to_refresh(var)); |
| 1059 | |
| 1060 | DBG_MSG("Initial video mode is from %d.\n", msrc); |
| 1061 | |
| 1062 | #if ALLOCATE_FOR_PANNING |
| 1063 | /* Allow use of half of the video ram for panning */ |
| 1064 | var->xres_virtual = var->xres; |
| 1065 | var->yres_virtual = |
| 1066 | dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres); |
| 1067 | if (var->yres_virtual < var->yres) |
| 1068 | var->yres_virtual = var->yres; |
| 1069 | #else |
| 1070 | var->yres_virtual = var->yres; |
| 1071 | #endif |
| 1072 | |
| 1073 | if (dinfo->accel) |
| 1074 | var->accel_flags |= FB_ACCELF_TEXT; |
| 1075 | else |
| 1076 | var->accel_flags &= ~FB_ACCELF_TEXT; |
| 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | static int __devinit |
| 1082 | intelfb_set_fbinfo(struct intelfb_info *dinfo) |
| 1083 | { |
| 1084 | struct fb_info *info = dinfo->info; |
| 1085 | |
| 1086 | DBG_MSG("intelfb_set_fbinfo\n"); |
| 1087 | |
| 1088 | info->flags = FBINFO_FLAG_DEFAULT; |
| 1089 | info->fbops = &intel_fb_ops; |
| 1090 | info->pseudo_palette = dinfo->pseudo_palette; |
| 1091 | |
| 1092 | info->pixmap.size = 64*1024; |
| 1093 | info->pixmap.buf_align = 8; |
| 1094 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
| 1095 | |
| 1096 | if (intelfb_init_var(dinfo)) |
| 1097 | return 1; |
| 1098 | |
| 1099 | info->pixmap.scan_align = 1; |
| 1100 | |
| 1101 | update_dinfo(dinfo, &info->var); |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | /* Update dinfo to match the active video mode. */ |
| 1107 | static void |
| 1108 | update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var) |
| 1109 | { |
| 1110 | DBG_MSG("update_dinfo\n"); |
| 1111 | |
| 1112 | dinfo->bpp = var->bits_per_pixel; |
| 1113 | dinfo->depth = intelfb_var_to_depth(var); |
| 1114 | dinfo->xres = var->xres; |
| 1115 | dinfo->yres = var->xres; |
| 1116 | dinfo->pixclock = var->pixclock; |
| 1117 | |
| 1118 | intelfb_get_fix(&dinfo->info->fix, dinfo->info); |
| 1119 | |
| 1120 | switch (dinfo->bpp) { |
| 1121 | case 8: |
| 1122 | dinfo->visual = FB_VISUAL_PSEUDOCOLOR; |
| 1123 | dinfo->pitch = var->xres_virtual; |
| 1124 | break; |
| 1125 | case 16: |
| 1126 | dinfo->visual = FB_VISUAL_TRUECOLOR; |
| 1127 | dinfo->pitch = var->xres_virtual * 2; |
| 1128 | break; |
| 1129 | case 32: |
| 1130 | dinfo->visual = FB_VISUAL_TRUECOLOR; |
| 1131 | dinfo->pitch = var->xres_virtual * 4; |
| 1132 | break; |
| 1133 | } |
| 1134 | |
| 1135 | /* Make sure the line length is a aligned correctly. */ |
| 1136 | dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT); |
| 1137 | |
| 1138 | if (FIXED_MODE(dinfo)) |
| 1139 | dinfo->pitch = dinfo->initial_pitch; |
| 1140 | |
| 1141 | dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual; |
| 1142 | dinfo->info->fix.line_length = dinfo->pitch; |
| 1143 | dinfo->info->fix.visual = dinfo->visual; |
| 1144 | } |
| 1145 | |
| 1146 | /* fbops functions */ |
| 1147 | |
| 1148 | static int |
| 1149 | intelfb_get_fix(struct fb_fix_screeninfo *fix, struct fb_info *info) |
| 1150 | { |
| 1151 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1152 | |
| 1153 | DBG_MSG("intelfb_get_fix\n"); |
| 1154 | |
| 1155 | memset(fix, 0, sizeof(*fix)); |
| 1156 | strcpy(fix->id, dinfo->name); |
| 1157 | fix->smem_start = dinfo->fb.physical; |
| 1158 | fix->smem_len = dinfo->fb.size; |
| 1159 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 1160 | fix->type_aux = 0; |
| 1161 | fix->visual = dinfo->visual; |
| 1162 | fix->xpanstep = 8; |
| 1163 | fix->ypanstep = 1; |
| 1164 | fix->ywrapstep = 0; |
| 1165 | fix->line_length = dinfo->pitch; |
| 1166 | fix->mmio_start = dinfo->mmio_base_phys; |
| 1167 | fix->mmio_len = INTEL_REG_SIZE; |
| 1168 | fix->accel = FB_ACCEL_I830; |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | /*************************************************************** |
| 1173 | * fbdev interface * |
| 1174 | ***************************************************************/ |
| 1175 | |
| 1176 | static int |
| 1177 | intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| 1178 | { |
| 1179 | int change_var = 0; |
| 1180 | struct fb_var_screeninfo v; |
| 1181 | struct intelfb_info *dinfo; |
| 1182 | static int first = 1; |
| 1183 | |
| 1184 | DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags); |
| 1185 | |
| 1186 | dinfo = GET_DINFO(info); |
| 1187 | |
| 1188 | if (intelfbhw_validate_mode(dinfo, var) != 0) |
| 1189 | return -EINVAL; |
| 1190 | |
| 1191 | v = *var; |
| 1192 | |
| 1193 | /* Check for a supported bpp. */ |
| 1194 | if (v.bits_per_pixel <= 8) { |
| 1195 | v.bits_per_pixel = 8; |
| 1196 | } else if (v.bits_per_pixel <= 16) { |
| 1197 | if (v.bits_per_pixel == 16) |
| 1198 | v.green.length = 6; |
| 1199 | v.bits_per_pixel = 16; |
| 1200 | } else if (v.bits_per_pixel <= 32) { |
| 1201 | v.bits_per_pixel = 32; |
| 1202 | } else |
| 1203 | return -EINVAL; |
| 1204 | |
| 1205 | change_var = ((info->var.xres != var->xres) || |
| 1206 | (info->var.yres != var->yres) || |
| 1207 | (info->var.xres_virtual != var->xres_virtual) || |
| 1208 | (info->var.yres_virtual != var->yres_virtual) || |
| 1209 | (info->var.bits_per_pixel != var->bits_per_pixel) || |
| 1210 | memcmp(&info->var.red, &var->red, sizeof(var->red)) || |
| 1211 | memcmp(&info->var.green, &var->green, |
| 1212 | sizeof(var->green)) || |
| 1213 | memcmp(&info->var.blue, &var->blue, sizeof(var->blue))); |
| 1214 | |
| 1215 | if (FIXED_MODE(dinfo) && |
| 1216 | (change_var || |
| 1217 | var->yres_virtual > dinfo->initial_var.yres_virtual || |
| 1218 | var->yres_virtual < dinfo->initial_var.yres || |
| 1219 | var->xoffset || var->nonstd)) { |
| 1220 | if (first) { |
| 1221 | ERR_MSG("Changing the video mode is not supported.\n"); |
| 1222 | first = 0; |
| 1223 | } |
| 1224 | return -EINVAL; |
| 1225 | } |
| 1226 | |
| 1227 | switch (intelfb_var_to_depth(&v)) { |
| 1228 | case 8: |
| 1229 | v.red.offset = v.green.offset = v.blue.offset = 0; |
| 1230 | v.red.length = v.green.length = v.blue.length = 8; |
| 1231 | v.transp.offset = v.transp.length = 0; |
| 1232 | break; |
| 1233 | case 15: |
| 1234 | v.red.offset = 10; |
| 1235 | v.green.offset = 5; |
| 1236 | v.blue.offset = 0; |
| 1237 | v.red.length = v.green.length = v.blue.length = 5; |
| 1238 | v.transp.offset = v.transp.length = 0; |
| 1239 | break; |
| 1240 | case 16: |
| 1241 | v.red.offset = 11; |
| 1242 | v.green.offset = 5; |
| 1243 | v.blue.offset = 0; |
| 1244 | v.red.length = 5; |
| 1245 | v.green.length = 6; |
| 1246 | v.blue.length = 5; |
| 1247 | v.transp.offset = v.transp.length = 0; |
| 1248 | break; |
| 1249 | case 24: |
| 1250 | v.red.offset = 16; |
| 1251 | v.green.offset = 8; |
| 1252 | v.blue.offset = 0; |
| 1253 | v.red.length = v.green.length = v.blue.length = 8; |
| 1254 | v.transp.offset = v.transp.length = 0; |
| 1255 | break; |
| 1256 | case 32: |
| 1257 | v.red.offset = 16; |
| 1258 | v.green.offset = 8; |
| 1259 | v.blue.offset = 0; |
| 1260 | v.red.length = v.green.length = v.blue.length = 8; |
| 1261 | v.transp.offset = 24; |
| 1262 | v.transp.length = 8; |
| 1263 | break; |
| 1264 | } |
| 1265 | |
| 1266 | if (v.xoffset < 0) |
| 1267 | v.xoffset = 0; |
| 1268 | if (v.yoffset < 0) |
| 1269 | v.yoffset = 0; |
| 1270 | |
| 1271 | if (v.xoffset > v.xres_virtual - v.xres) |
| 1272 | v.xoffset = v.xres_virtual - v.xres; |
| 1273 | if (v.yoffset > v.yres_virtual - v.yres) |
| 1274 | v.yoffset = v.yres_virtual - v.yres; |
| 1275 | |
| 1276 | v.red.msb_right = v.green.msb_right = v.blue.msb_right = |
| 1277 | v.transp.msb_right = 0; |
| 1278 | |
| 1279 | *var = v; |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | static int |
| 1285 | intelfb_set_par(struct fb_info *info) |
| 1286 | { |
| 1287 | struct intelfb_hwstate *hw; |
| 1288 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1289 | |
| 1290 | if (FIXED_MODE(dinfo)) { |
| 1291 | ERR_MSG("Changing the video mode is not supported.\n"); |
| 1292 | return -EINVAL; |
| 1293 | } |
| 1294 | |
| 1295 | hw = kmalloc(sizeof(*hw), GFP_ATOMIC); |
| 1296 | if (!hw) |
| 1297 | return -ENOMEM; |
| 1298 | |
| 1299 | DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres, |
| 1300 | info->var.yres, info->var.bits_per_pixel); |
| 1301 | |
| 1302 | intelfb_blank(FB_BLANK_POWERDOWN, info); |
| 1303 | |
| 1304 | if (dinfo->accel) |
| 1305 | intelfbhw_2d_stop(dinfo); |
| 1306 | |
| 1307 | memcpy(hw, &dinfo->save_state, sizeof(*hw)); |
| 1308 | if (intelfbhw_mode_to_hw(dinfo, hw, &info->var)) |
| 1309 | goto invalid_mode; |
| 1310 | if (intelfbhw_program_mode(dinfo, hw, 0)) |
| 1311 | goto invalid_mode; |
| 1312 | |
| 1313 | #if REGDUMP > 0 |
| 1314 | intelfbhw_read_hw_state(dinfo, hw, 0); |
| 1315 | intelfbhw_print_hw_state(dinfo, hw); |
| 1316 | #endif |
| 1317 | |
| 1318 | update_dinfo(dinfo, &info->var); |
| 1319 | |
| 1320 | if (dinfo->accel) |
| 1321 | intelfbhw_2d_start(dinfo); |
| 1322 | |
| 1323 | intelfb_pan_display(&info->var, info); |
| 1324 | |
| 1325 | intelfb_blank(FB_BLANK_UNBLANK, info); |
| 1326 | |
| 1327 | if (ACCEL(dinfo, info)) { |
| 1328 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | |
| 1329 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | |
| 1330 | FBINFO_HWACCEL_IMAGEBLIT; |
| 1331 | } else { |
| 1332 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 1333 | } |
| 1334 | kfree(hw); |
| 1335 | return 0; |
| 1336 | invalid_mode: |
| 1337 | kfree(hw); |
| 1338 | return -EINVAL; |
| 1339 | } |
| 1340 | |
| 1341 | static int |
| 1342 | intelfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 1343 | unsigned blue, unsigned transp, struct fb_info *info) |
| 1344 | { |
| 1345 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1346 | |
| 1347 | #if VERBOSE > 0 |
| 1348 | DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth); |
| 1349 | #endif |
| 1350 | |
| 1351 | if (regno > 255) |
| 1352 | return 1; |
| 1353 | |
| 1354 | switch (dinfo->depth) { |
| 1355 | case 8: |
| 1356 | { |
| 1357 | red >>= 8; |
| 1358 | green >>= 8; |
| 1359 | blue >>= 8; |
| 1360 | |
| 1361 | dinfo->palette[regno].red = red; |
| 1362 | dinfo->palette[regno].green = green; |
| 1363 | dinfo->palette[regno].blue = blue; |
| 1364 | |
| 1365 | intelfbhw_setcolreg(dinfo, regno, red, green, blue, |
| 1366 | transp); |
| 1367 | } |
| 1368 | break; |
| 1369 | case 15: |
| 1370 | dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) | |
| 1371 | ((green & 0xf800) >> 6) | |
| 1372 | ((blue & 0xf800) >> 11); |
| 1373 | break; |
| 1374 | case 16: |
| 1375 | dinfo->pseudo_palette[regno] = (red & 0xf800) | |
| 1376 | ((green & 0xfc00) >> 5) | |
| 1377 | ((blue & 0xf800) >> 11); |
| 1378 | break; |
| 1379 | case 24: |
| 1380 | dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) | |
| 1381 | (green & 0xff00) | |
| 1382 | ((blue & 0xff00) >> 8); |
| 1383 | break; |
| 1384 | } |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
| 1388 | static int |
| 1389 | intelfb_blank(int blank, struct fb_info *info) |
| 1390 | { |
| 1391 | intelfbhw_do_blank(blank, info); |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
| 1395 | static int |
| 1396 | intelfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| 1397 | { |
| 1398 | intelfbhw_pan_display(var, info); |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
| 1402 | /* When/if we have our own ioctls. */ |
| 1403 | static int |
| 1404 | intelfb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, |
| 1405 | unsigned long arg, struct fb_info *info) |
| 1406 | { |
| 1407 | int retval = 0; |
| 1408 | |
| 1409 | return retval; |
| 1410 | } |
| 1411 | |
| 1412 | static void |
| 1413 | intelfb_fillrect (struct fb_info *info, const struct fb_fillrect *rect) |
| 1414 | { |
| 1415 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1416 | u32 rop, color; |
| 1417 | |
| 1418 | #if VERBOSE > 0 |
| 1419 | DBG_MSG("intelfb_fillrect\n"); |
| 1420 | #endif |
| 1421 | |
| 1422 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) |
| 1423 | return cfb_fillrect(info, rect); |
| 1424 | |
| 1425 | if (rect->rop == ROP_COPY) |
| 1426 | rop = PAT_ROP_GXCOPY; |
| 1427 | else // ROP_XOR |
| 1428 | rop = PAT_ROP_GXXOR; |
| 1429 | |
| 1430 | if (dinfo->depth != 8) |
| 1431 | color = dinfo->pseudo_palette[rect->color]; |
| 1432 | else |
| 1433 | color = rect->color; |
| 1434 | |
| 1435 | intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy, |
| 1436 | rect->width, rect->height, color, |
| 1437 | dinfo->pitch, info->var.bits_per_pixel, |
| 1438 | rop); |
| 1439 | } |
| 1440 | |
| 1441 | static void |
| 1442 | intelfb_copyarea(struct fb_info *info, const struct fb_copyarea *region) |
| 1443 | { |
| 1444 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1445 | |
| 1446 | #if VERBOSE > 0 |
| 1447 | DBG_MSG("intelfb_copyarea\n"); |
| 1448 | #endif |
| 1449 | |
| 1450 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) |
| 1451 | return cfb_copyarea(info, region); |
| 1452 | |
| 1453 | intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx, |
| 1454 | region->dy, region->width, region->height, |
| 1455 | dinfo->pitch, info->var.bits_per_pixel); |
| 1456 | } |
| 1457 | |
| 1458 | static void |
| 1459 | intelfb_imageblit(struct fb_info *info, const struct fb_image *image) |
| 1460 | { |
| 1461 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1462 | u32 fgcolor, bgcolor; |
| 1463 | |
| 1464 | #if VERBOSE > 0 |
| 1465 | DBG_MSG("intelfb_imageblit\n"); |
| 1466 | #endif |
| 1467 | |
| 1468 | if (!ACCEL(dinfo, info) || dinfo->depth == 4 |
| 1469 | || image->depth != 1) |
| 1470 | return cfb_imageblit(info, image); |
| 1471 | |
| 1472 | if (dinfo->depth != 8) { |
| 1473 | fgcolor = dinfo->pseudo_palette[image->fg_color]; |
| 1474 | bgcolor = dinfo->pseudo_palette[image->bg_color]; |
| 1475 | } else { |
| 1476 | fgcolor = image->fg_color; |
| 1477 | bgcolor = image->bg_color; |
| 1478 | } |
| 1479 | |
| 1480 | if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width, |
| 1481 | image->height, image->data, |
| 1482 | image->dx, image->dy, |
| 1483 | dinfo->pitch, info->var.bits_per_pixel)) |
| 1484 | return cfb_imageblit(info, image); |
| 1485 | } |
| 1486 | |
| 1487 | static int |
| 1488 | intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 1489 | { |
| 1490 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1491 | |
| 1492 | #if VERBOSE > 0 |
| 1493 | DBG_MSG("intelfb_cursor\n"); |
| 1494 | #endif |
| 1495 | |
| 1496 | if (!dinfo->hwcursor) |
| 1497 | return soft_cursor(info, cursor); |
| 1498 | |
| 1499 | intelfbhw_cursor_hide(dinfo); |
| 1500 | |
| 1501 | /* If XFree killed the cursor - restore it */ |
| 1502 | if (INREG(CURSOR_A_BASEADDR) != dinfo->cursor.offset << 12) { |
| 1503 | u32 fg, bg; |
| 1504 | |
| 1505 | DBG_MSG("the cursor was killed - restore it !!\n"); |
| 1506 | DBG_MSG("size %d, %d pos %d, %d\n", |
| 1507 | cursor->image.width, cursor->image.height, |
| 1508 | cursor->image.dx, cursor->image.dy); |
| 1509 | |
| 1510 | intelfbhw_cursor_init(dinfo); |
| 1511 | intelfbhw_cursor_reset(dinfo); |
| 1512 | intelfbhw_cursor_setpos(dinfo, cursor->image.dx, |
| 1513 | cursor->image.dy); |
| 1514 | |
| 1515 | if (dinfo->depth != 8) { |
| 1516 | fg =dinfo->pseudo_palette[cursor->image.fg_color]; |
| 1517 | bg =dinfo->pseudo_palette[cursor->image.bg_color]; |
| 1518 | } else { |
| 1519 | fg = cursor->image.fg_color; |
| 1520 | bg = cursor->image.bg_color; |
| 1521 | } |
| 1522 | intelfbhw_cursor_setcolor(dinfo, bg, fg); |
| 1523 | intelfbhw_cursor_load(dinfo, cursor->image.width, |
| 1524 | cursor->image.height, |
| 1525 | dinfo->cursor_src); |
| 1526 | |
| 1527 | if (cursor->enable) |
| 1528 | intelfbhw_cursor_show(dinfo); |
| 1529 | return 0; |
| 1530 | } |
| 1531 | |
| 1532 | if (cursor->set & FB_CUR_SETPOS) { |
| 1533 | u32 dx, dy; |
| 1534 | |
| 1535 | dx = cursor->image.dx - info->var.xoffset; |
| 1536 | dy = cursor->image.dy - info->var.yoffset; |
| 1537 | |
| 1538 | intelfbhw_cursor_setpos(dinfo, dx, dy); |
| 1539 | } |
| 1540 | |
| 1541 | if (cursor->set & FB_CUR_SETSIZE) { |
| 1542 | if (cursor->image.width > 64 || cursor->image.height > 64) |
| 1543 | return -ENXIO; |
| 1544 | |
| 1545 | intelfbhw_cursor_reset(dinfo); |
| 1546 | } |
| 1547 | |
| 1548 | if (cursor->set & FB_CUR_SETCMAP) { |
| 1549 | u32 fg, bg; |
| 1550 | |
| 1551 | if (dinfo->depth != 8) { |
| 1552 | fg = dinfo->pseudo_palette[cursor->image.fg_color]; |
| 1553 | bg = dinfo->pseudo_palette[cursor->image.bg_color]; |
| 1554 | } else { |
| 1555 | fg = cursor->image.fg_color; |
| 1556 | bg = cursor->image.bg_color; |
| 1557 | } |
| 1558 | |
| 1559 | intelfbhw_cursor_setcolor(dinfo, bg, fg); |
| 1560 | } |
| 1561 | |
| 1562 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { |
| 1563 | u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8); |
| 1564 | u32 size = s_pitch * cursor->image.height; |
| 1565 | u8 *dat = (u8 *) cursor->image.data; |
| 1566 | u8 *msk = (u8 *) cursor->mask; |
| 1567 | u8 src[64]; |
| 1568 | u32 i; |
| 1569 | |
| 1570 | if (cursor->image.depth != 1) |
| 1571 | return -ENXIO; |
| 1572 | |
| 1573 | switch (cursor->rop) { |
| 1574 | case ROP_XOR: |
| 1575 | for (i = 0; i < size; i++) |
| 1576 | src[i] = dat[i] ^ msk[i]; |
| 1577 | break; |
| 1578 | case ROP_COPY: |
| 1579 | default: |
| 1580 | for (i = 0; i < size; i++) |
| 1581 | src[i] = dat[i] & msk[i]; |
| 1582 | break; |
| 1583 | } |
| 1584 | |
| 1585 | /* save the bitmap to restore it when XFree will |
| 1586 | make the cursor dirty */ |
| 1587 | memcpy(dinfo->cursor_src, src, size); |
| 1588 | |
| 1589 | intelfbhw_cursor_load(dinfo, cursor->image.width, |
| 1590 | cursor->image.height, src); |
| 1591 | } |
| 1592 | |
| 1593 | if (cursor->enable) |
| 1594 | intelfbhw_cursor_show(dinfo); |
| 1595 | |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | static int |
| 1600 | intelfb_sync(struct fb_info *info) |
| 1601 | { |
| 1602 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1603 | |
| 1604 | #if VERBOSE > 0 |
| 1605 | DBG_MSG("intelfb_sync\n"); |
| 1606 | #endif |
| 1607 | |
| 1608 | if (dinfo->ring_lockup) |
| 1609 | return 0; |
| 1610 | |
| 1611 | intelfbhw_do_sync(dinfo); |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |