Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * intelfb |
| 3 | * |
Dave Airlie | 9639d5e | 2006-03-23 11:23:55 +1100 | [diff] [blame] | 4 | * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/ |
Phil Endecott | 3f7a26b | 2008-10-15 22:03:35 -0700 | [diff] [blame] | 5 | * 945G/945GM/945GME/965G/965GM integrated graphics chips. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 7 | * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * 2004 Sylvain Meyer |
Dave Airlie | 8bb91f6 | 2006-03-23 13:06:32 +1100 | [diff] [blame] | 9 | * 2006 David Airlie |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 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 Broemme | 0e170c7 | 2008-04-28 02:15:43 -0700 | [diff] [blame] | 102 | * |
| 103 | * 04/2008 - Version 0.9.5 |
| 104 | * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>) |
Phil Endecott | 3f7a26b | 2008-10-15 22:03:35 -0700 | [diff] [blame] | 105 | * |
| 106 | * 08/2008 - Version 0.9.6 |
| 107 | * Add support for 945GME. (Phil Endecott <spam_from_intelfb@chezphil.org>) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | */ |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | #include <linux/module.h> |
| 111 | #include <linux/kernel.h> |
| 112 | #include <linux/errno.h> |
| 113 | #include <linux/string.h> |
| 114 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #include <linux/slab.h> |
| 116 | #include <linux/delay.h> |
| 117 | #include <linux/fb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #include <linux/ioport.h> |
| 119 | #include <linux/init.h> |
| 120 | #include <linux/pci.h> |
| 121 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #include <linux/pagemap.h> |
Jon Smirl | a8f340e | 2006-07-10 04:44:12 -0700 | [diff] [blame] | 123 | #include <linux/screen_info.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | #include <asm/io.h> |
| 126 | |
| 127 | #ifdef CONFIG_MTRR |
| 128 | #include <asm/mtrr.h> |
| 129 | #endif |
| 130 | |
| 131 | #include "intelfb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | #include "intelfbhw.h" |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 133 | #include "../edid.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Adrian Bunk | 14c6f52 | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 135 | static void __devinit get_initial_mode(struct intelfb_info *dinfo); |
| 136 | static void update_dinfo(struct intelfb_info *dinfo, |
| 137 | struct fb_var_screeninfo *var); |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 138 | static int intelfb_open(struct fb_info *info, int user); |
| 139 | static int intelfb_release(struct fb_info *info, int user); |
Adrian Bunk | 14c6f52 | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 140 | static int intelfb_check_var(struct fb_var_screeninfo *var, |
| 141 | struct fb_info *info); |
| 142 | static int intelfb_set_par(struct fb_info *info); |
| 143 | static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 144 | unsigned blue, unsigned transp, |
| 145 | struct fb_info *info); |
| 146 | |
| 147 | static int intelfb_blank(int blank, struct fb_info *info); |
| 148 | static int intelfb_pan_display(struct fb_var_screeninfo *var, |
| 149 | struct fb_info *info); |
| 150 | |
| 151 | static void intelfb_fillrect(struct fb_info *info, |
| 152 | const struct fb_fillrect *rect); |
| 153 | static void intelfb_copyarea(struct fb_info *info, |
| 154 | const struct fb_copyarea *region); |
| 155 | static void intelfb_imageblit(struct fb_info *info, |
| 156 | const struct fb_image *image); |
| 157 | static int intelfb_cursor(struct fb_info *info, |
| 158 | struct fb_cursor *cursor); |
| 159 | |
| 160 | static int intelfb_sync(struct fb_info *info); |
| 161 | |
Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 162 | static int intelfb_ioctl(struct fb_info *info, |
| 163 | unsigned int cmd, unsigned long arg); |
Adrian Bunk | 14c6f52 | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 164 | |
| 165 | static int __devinit intelfb_pci_register(struct pci_dev *pdev, |
| 166 | const struct pci_device_id *ent); |
| 167 | static void __devexit intelfb_pci_unregister(struct pci_dev *pdev); |
| 168 | static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo); |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* |
| 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 | |
| 180 | static struct pci_device_id intelfb_pci_table[] __devinitdata = { |
| 181 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_830M, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_830M }, |
| 182 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_845G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_845G }, |
| 183 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_85XGM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_85XGM }, |
| 184 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_865G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_865G }, |
Stefan Husemann | 347486b | 2009-04-13 14:40:10 -0700 | [diff] [blame] | 185 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_854, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_854 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915G }, |
Scott MacKenzie | 3a59026 | 2005-11-07 01:00:33 -0800 | [diff] [blame] | 187 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM }, |
Dave Airlie | 9639d5e | 2006-03-23 11:23:55 +1100 | [diff] [blame] | 188 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945G }, |
Dave Airlie | 9a90603 | 2006-03-23 21:53:05 +1100 | [diff] [blame] | 189 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GM }, |
Phil Endecott | 3f7a26b | 2008-10-15 22:03:35 -0700 | [diff] [blame] | 190 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GME, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GME }, |
Maik Broemme | 0e170c7 | 2008-04-28 02:15:43 -0700 | [diff] [blame] | 191 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965G }, |
| 192 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965GM }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 202 | .fb_open = intelfb_open, |
| 203 | .fb_release = intelfb_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | .fb_check_var = intelfb_check_var, |
| 205 | .fb_set_par = intelfb_set_par, |
| 206 | .fb_setcolreg = intelfb_setcolreg, |
| 207 | .fb_blank = intelfb_blank, |
| 208 | .fb_pan_display = intelfb_pan_display, |
| 209 | .fb_fillrect = intelfb_fillrect, |
| 210 | .fb_copyarea = intelfb_copyarea, |
| 211 | .fb_imageblit = intelfb_imageblit, |
| 212 | .fb_cursor = intelfb_cursor, |
| 213 | .fb_sync = intelfb_sync, |
| 214 | .fb_ioctl = intelfb_ioctl |
| 215 | }; |
| 216 | |
| 217 | /* PCI driver module table */ |
| 218 | static struct pci_driver intelfb_driver = { |
Andrew Morton | 5a3b589 | 2005-06-21 17:16:57 -0700 | [diff] [blame] | 219 | .name = "intelfb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | .id_table = intelfb_pci_table, |
| 221 | .probe = intelfb_pci_register, |
| 222 | .remove = __devexit_p(intelfb_pci_unregister) |
| 223 | }; |
| 224 | |
| 225 | /* Module description/parameters */ |
| 226 | MODULE_AUTHOR("David Dawes <dawes@tungstengraphics.com>, " |
| 227 | "Sylvain Meyer <sylvain.meyer@worldonline.fr>"); |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 228 | MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS |
| 229 | " chipsets"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | MODULE_LICENSE("Dual BSD/GPL"); |
| 231 | MODULE_DEVICE_TABLE(pci, intelfb_pci_table); |
| 232 | |
Patrick McManus | 346e399b | 2005-05-28 15:51:46 -0700 | [diff] [blame] | 233 | static int accel = 1; |
| 234 | static int vram = 4; |
Antonino A. Daplas | 375726d | 2005-09-29 05:19:51 +0800 | [diff] [blame] | 235 | static int hwcursor = 0; |
Patrick McManus | 346e399b | 2005-05-28 15:51:46 -0700 | [diff] [blame] | 236 | static int mtrr = 1; |
| 237 | static int fixed = 0; |
| 238 | static int noinit = 0; |
| 239 | static int noregister = 0; |
| 240 | static int probeonly = 0; |
| 241 | static int idonly = 0; |
| 242 | static int bailearly = 0; |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 243 | static int voffset = 48; |
Patrick McManus | 346e399b | 2005-05-28 15:51:46 -0700 | [diff] [blame] | 244 | static char *mode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | module_param(accel, bool, S_IRUGO); |
James Simmons | 4c7ffe0 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 247 | MODULE_PARM_DESC(accel, "Enable hardware acceleration"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | module_param(vram, int, S_IRUGO); |
| 249 | MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"); |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 250 | module_param(voffset, int, S_IRUGO); |
| 251 | MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | module_param(hwcursor, bool, S_IRUGO); |
| 253 | MODULE_PARM_DESC(hwcursor, "Enable HW cursor"); |
| 254 | module_param(mtrr, bool, S_IRUGO); |
| 255 | MODULE_PARM_DESC(mtrr, "Enable MTRR support"); |
| 256 | module_param(fixed, bool, S_IRUGO); |
| 257 | MODULE_PARM_DESC(fixed, "Disable mode switching"); |
| 258 | module_param(noinit, bool, 0); |
| 259 | MODULE_PARM_DESC(noinit, "Don't initialise graphics mode when loading"); |
| 260 | module_param(noregister, bool, 0); |
| 261 | MODULE_PARM_DESC(noregister, "Don't register, just probe and exit (debug)"); |
| 262 | module_param(probeonly, bool, 0); |
| 263 | MODULE_PARM_DESC(probeonly, "Do a minimal probe (debug)"); |
| 264 | module_param(idonly, bool, 0); |
| 265 | MODULE_PARM_DESC(idonly, "Just identify without doing anything else (debug)"); |
| 266 | module_param(bailearly, bool, 0); |
| 267 | MODULE_PARM_DESC(bailearly, "Bail out early, depending on value (debug)"); |
| 268 | module_param(mode, charp, S_IRUGO); |
| 269 | MODULE_PARM_DESC(mode, |
| 270 | "Initial video mode \"<xres>x<yres>[-<depth>][@<refresh>]\""); |
| 271 | |
| 272 | #ifndef MODULE |
| 273 | #define OPT_EQUAL(opt, name) (!strncmp(opt, name, strlen(name))) |
Eric Hustvedt | 65eb2f9 | 2006-05-29 18:38:55 +1000 | [diff] [blame] | 274 | #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | #define OPT_STRVAL(opt, name) (opt + strlen(name)) |
| 276 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 277 | static __inline__ char * get_opt_string(const char *this_opt, const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
| 279 | const char *p; |
| 280 | int i; |
| 281 | char *ret; |
| 282 | |
| 283 | p = OPT_STRVAL(this_opt, name); |
| 284 | i = 0; |
| 285 | while (p[i] && p[i] != ' ' && p[i] != ',') |
| 286 | i++; |
| 287 | ret = kmalloc(i + 1, GFP_KERNEL); |
| 288 | if (ret) { |
| 289 | strncpy(ret, p, i); |
| 290 | ret[i] = '\0'; |
| 291 | } |
| 292 | return ret; |
| 293 | } |
| 294 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 295 | static __inline__ int get_opt_int(const char *this_opt, const char *name, |
| 296 | int *ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
| 298 | if (!ret) |
| 299 | return 0; |
| 300 | |
| 301 | if (!OPT_EQUAL(this_opt, name)) |
| 302 | return 0; |
| 303 | |
| 304 | *ret = OPT_INTVAL(this_opt, name); |
| 305 | return 1; |
| 306 | } |
| 307 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 308 | static __inline__ int get_opt_bool(const char *this_opt, const char *name, |
| 309 | int *ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | if (!ret) |
| 312 | return 0; |
| 313 | |
| 314 | if (OPT_EQUAL(this_opt, name)) { |
| 315 | if (this_opt[strlen(name)] == '=') |
| 316 | *ret = simple_strtoul(this_opt + strlen(name) + 1, |
| 317 | NULL, 0); |
| 318 | else |
| 319 | *ret = 1; |
| 320 | } else { |
| 321 | if (OPT_EQUAL(this_opt, "no") && OPT_EQUAL(this_opt + 2, name)) |
| 322 | *ret = 0; |
| 323 | else |
| 324 | return 0; |
| 325 | } |
| 326 | return 1; |
| 327 | } |
| 328 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 329 | static int __init intelfb_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | ; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 359 | else if (get_opt_int(this_opt, "vram", &vram)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 380 | static int __init intelfb_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
| 382 | #ifndef MODULE |
| 383 | char *option = NULL; |
| 384 | #endif |
| 385 | |
| 386 | DBG_MSG("intelfb_init\n"); |
| 387 | |
| 388 | INF_MSG("Framebuffer driver for " |
| 389 | "Intel(R) " SUPPORTED_CHIPSETS " chipsets\n"); |
| 390 | INF_MSG("Version " INTELFB_VERSION "\n"); |
| 391 | |
| 392 | if (idonly) |
| 393 | return -ENODEV; |
| 394 | |
| 395 | #ifndef MODULE |
| 396 | if (fb_get_options("intelfb", &option)) |
| 397 | return -ENODEV; |
| 398 | intelfb_setup(option); |
| 399 | #endif |
| 400 | |
| 401 | return pci_register_driver(&intelfb_driver); |
| 402 | } |
| 403 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 404 | static void __exit intelfb_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
| 406 | DBG_MSG("intelfb_exit\n"); |
| 407 | pci_unregister_driver(&intelfb_driver); |
| 408 | } |
| 409 | |
| 410 | module_init(intelfb_init); |
| 411 | module_exit(intelfb_exit); |
| 412 | |
| 413 | /*************************************************************** |
| 414 | * mtrr support functions * |
| 415 | ***************************************************************/ |
| 416 | |
| 417 | #ifdef CONFIG_MTRR |
| 418 | static inline void __devinit set_mtrr(struct intelfb_info *dinfo) |
| 419 | { |
| 420 | dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical, |
| 421 | dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1); |
| 422 | if (dinfo->mtrr_reg < 0) { |
| 423 | ERR_MSG("unable to set MTRR\n"); |
| 424 | return; |
| 425 | } |
| 426 | dinfo->has_mtrr = 1; |
| 427 | } |
| 428 | static inline void unset_mtrr(struct intelfb_info *dinfo) |
| 429 | { |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 430 | if (dinfo->has_mtrr) |
| 431 | mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | dinfo->aperture.size); |
| 433 | } |
| 434 | #else |
| 435 | #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n") |
| 436 | |
| 437 | #define unset_mtrr(x) do { } while (0) |
| 438 | #endif /* CONFIG_MTRR */ |
| 439 | |
| 440 | /*************************************************************** |
| 441 | * driver init / cleanup * |
| 442 | ***************************************************************/ |
| 443 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 444 | static void cleanup(struct intelfb_info *dinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
| 446 | DBG_MSG("cleanup\n"); |
| 447 | |
| 448 | if (!dinfo) |
| 449 | return; |
| 450 | |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 451 | intelfbhw_disable_irq(dinfo); |
| 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | fb_dealloc_cmap(&dinfo->info->cmap); |
| 454 | kfree(dinfo->info->pixmap.addr); |
| 455 | |
| 456 | if (dinfo->registered) |
| 457 | unregister_framebuffer(dinfo->info); |
| 458 | |
| 459 | unset_mtrr(dinfo); |
| 460 | |
| 461 | if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) { |
| 462 | agp_unbind_memory(dinfo->gtt_fb_mem); |
| 463 | agp_free_memory(dinfo->gtt_fb_mem); |
| 464 | } |
| 465 | if (dinfo->gtt_cursor_mem) { |
| 466 | agp_unbind_memory(dinfo->gtt_cursor_mem); |
| 467 | agp_free_memory(dinfo->gtt_cursor_mem); |
| 468 | } |
| 469 | if (dinfo->gtt_ring_mem) { |
| 470 | agp_unbind_memory(dinfo->gtt_ring_mem); |
| 471 | agp_free_memory(dinfo->gtt_ring_mem); |
| 472 | } |
| 473 | |
Dennis Munsie | 7627899 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 474 | #ifdef CONFIG_FB_INTEL_I2C |
| 475 | /* un-register I2C bus */ |
| 476 | intelfb_delete_i2c_busses(dinfo); |
| 477 | #endif |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (dinfo->mmio_base) |
| 480 | iounmap((void __iomem *)dinfo->mmio_base); |
| 481 | if (dinfo->aperture.virtual) |
| 482 | iounmap((void __iomem *)dinfo->aperture.virtual); |
| 483 | |
Antonino A. Daplas | 4b3760c | 2005-12-19 15:11:40 +0800 | [diff] [blame] | 484 | if (dinfo->flag & INTELFB_MMIO_ACQUIRED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE); |
Antonino A. Daplas | 4b3760c | 2005-12-19 15:11:40 +0800 | [diff] [blame] | 486 | if (dinfo->flag & INTELFB_FB_ACQUIRED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | release_mem_region(dinfo->aperture.physical, |
| 488 | dinfo->aperture.size); |
| 489 | framebuffer_release(dinfo->info); |
| 490 | } |
| 491 | |
| 492 | #define bailout(dinfo) do { \ |
| 493 | DBG_MSG("bailout\n"); \ |
| 494 | cleanup(dinfo); \ |
| 495 | INF_MSG("Not going to register framebuffer, exiting...\n"); \ |
| 496 | return -ENODEV; \ |
| 497 | } while (0) |
| 498 | |
| 499 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 500 | static int __devinit intelfb_pci_register(struct pci_dev *pdev, |
| 501 | const struct pci_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | struct fb_info *info; |
| 504 | struct intelfb_info *dinfo; |
James Simmons | 4c7ffe0 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 505 | int i, err, dvo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | int aperture_size, stolen_size; |
| 507 | struct agp_kern_info gtt_info; |
| 508 | int agp_memtype; |
| 509 | const char *s; |
| 510 | struct agp_bridge_data *bridge; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 511 | int aperture_bar = 0; |
| 512 | int mmio_bar = 1; |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 513 | int offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | DBG_MSG("intelfb_pci_register\n"); |
| 516 | |
| 517 | num_registered++; |
| 518 | if (num_registered != 1) { |
| 519 | ERR_MSG("Attempted to register %d devices " |
| 520 | "(should be only 1).\n", num_registered); |
| 521 | return -ENODEV; |
| 522 | } |
| 523 | |
| 524 | info = framebuffer_alloc(sizeof(struct intelfb_info), &pdev->dev); |
| 525 | if (!info) { |
| 526 | ERR_MSG("Could not allocate memory for intelfb_info.\n"); |
| 527 | return -ENODEV; |
| 528 | } |
| 529 | if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) { |
| 530 | ERR_MSG("Could not allocate cmap for intelfb_info.\n"); |
| 531 | goto err_out_cmap; |
| 532 | return -ENODEV; |
| 533 | } |
| 534 | |
| 535 | dinfo = info->par; |
| 536 | dinfo->info = info; |
| 537 | dinfo->fbops = &intel_fb_ops; |
| 538 | dinfo->pdev = pdev; |
| 539 | |
| 540 | /* Reserve pixmap space. */ |
Jiri Slaby | f5610b9 | 2007-02-12 00:55:12 -0800 | [diff] [blame] | 541 | info->pixmap.addr = kzalloc(64 * 1024, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (info->pixmap.addr == NULL) { |
| 543 | ERR_MSG("Cannot reserve pixmap memory.\n"); |
| 544 | goto err_out_pixmap; |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* set early this option because it could be changed by tv encoder |
| 548 | driver */ |
| 549 | dinfo->fixed_mode = fixed; |
| 550 | |
| 551 | /* Enable device. */ |
| 552 | if ((err = pci_enable_device(pdev))) { |
| 553 | ERR_MSG("Cannot enable device.\n"); |
| 554 | cleanup(dinfo); |
| 555 | return -ENODEV; |
| 556 | } |
| 557 | |
| 558 | /* Set base addresses. */ |
Scott MacKenzie | 3a59026 | 2005-11-07 01:00:33 -0800 | [diff] [blame] | 559 | if ((ent->device == PCI_DEVICE_ID_INTEL_915G) || |
Dave Airlie | 9639d5e | 2006-03-23 11:23:55 +1100 | [diff] [blame] | 560 | (ent->device == PCI_DEVICE_ID_INTEL_915GM) || |
Dave Airlie | 9a90603 | 2006-03-23 21:53:05 +1100 | [diff] [blame] | 561 | (ent->device == PCI_DEVICE_ID_INTEL_945G) || |
Maik Broemme | 0e170c7 | 2008-04-28 02:15:43 -0700 | [diff] [blame] | 562 | (ent->device == PCI_DEVICE_ID_INTEL_945GM) || |
Phil Endecott | 3f7a26b | 2008-10-15 22:03:35 -0700 | [diff] [blame] | 563 | (ent->device == PCI_DEVICE_ID_INTEL_945GME) || |
Maik Broemme | 0e170c7 | 2008-04-28 02:15:43 -0700 | [diff] [blame] | 564 | (ent->device == PCI_DEVICE_ID_INTEL_965G) || |
| 565 | (ent->device == PCI_DEVICE_ID_INTEL_965GM)) { |
| 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | aperture_bar = 2; |
| 568 | mmio_bar = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar); |
| 571 | dinfo->aperture.size = pci_resource_len(pdev, aperture_bar); |
| 572 | dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar); |
| 573 | DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n", |
| 574 | (unsigned long long)pci_resource_start(pdev, aperture_bar), |
| 575 | (unsigned long long)pci_resource_len(pdev, aperture_bar), |
| 576 | (unsigned long long)pci_resource_start(pdev, mmio_bar), |
| 577 | (unsigned long long)pci_resource_len(pdev, mmio_bar)); |
| 578 | |
| 579 | /* Reserve the fb and MMIO regions */ |
| 580 | if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size, |
| 581 | INTELFB_MODULE_NAME)) { |
| 582 | ERR_MSG("Cannot reserve FB region.\n"); |
| 583 | cleanup(dinfo); |
| 584 | return -ENODEV; |
| 585 | } |
Antonino A. Daplas | 4b3760c | 2005-12-19 15:11:40 +0800 | [diff] [blame] | 586 | |
| 587 | dinfo->flag |= INTELFB_FB_ACQUIRED; |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (!request_mem_region(dinfo->mmio_base_phys, |
| 590 | INTEL_REG_SIZE, |
| 591 | INTELFB_MODULE_NAME)) { |
| 592 | ERR_MSG("Cannot reserve MMIO region.\n"); |
| 593 | cleanup(dinfo); |
| 594 | return -ENODEV; |
| 595 | } |
| 596 | |
Antonino A. Daplas | 4b3760c | 2005-12-19 15:11:40 +0800 | [diff] [blame] | 597 | dinfo->flag |= INTELFB_MMIO_ACQUIRED; |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* Get the chipset info. */ |
| 600 | dinfo->pci_chipset = pdev->device; |
| 601 | |
Dave Airlie | d024960 | 2006-03-20 20:26:45 +1100 | [diff] [blame] | 602 | if (intelfbhw_get_chipset(pdev, dinfo)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | cleanup(dinfo); |
| 604 | return -ENODEV; |
| 605 | } |
| 606 | |
| 607 | if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) { |
| 608 | cleanup(dinfo); |
| 609 | return -ENODEV; |
| 610 | } |
| 611 | |
| 612 | INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, " |
| 613 | "stolen memory %dkB\n", |
| 614 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
| 615 | PCI_FUNC(pdev->devfn), dinfo->name, |
| 616 | BtoMB(aperture_size), BtoKB(stolen_size)); |
| 617 | |
| 618 | /* Set these from the options. */ |
| 619 | dinfo->accel = accel; |
| 620 | dinfo->hwcursor = hwcursor; |
| 621 | |
| 622 | if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) { |
| 623 | INF_MSG("Acceleration is not supported for the %s chipset.\n", |
| 624 | dinfo->name); |
| 625 | dinfo->accel = 0; |
| 626 | } |
| 627 | |
| 628 | /* Framebuffer parameters - Use all the stolen memory if >= vram */ |
Antonino A. Daplas | 375726d | 2005-09-29 05:19:51 +0800 | [diff] [blame] | 629 | if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size); |
| 631 | dinfo->fbmem_gart = 0; |
| 632 | } else { |
| 633 | dinfo->fb.size = MB(vram); |
| 634 | dinfo->fbmem_gart = 1; |
| 635 | } |
| 636 | |
| 637 | /* Allocate space for the ring buffer and HW cursor if enabled. */ |
| 638 | if (dinfo->accel) { |
| 639 | dinfo->ring.size = RINGBUFFER_SIZE; |
| 640 | dinfo->ring_tail_mask = dinfo->ring.size - 1; |
| 641 | } |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 642 | if (dinfo->hwcursor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | dinfo->cursor.size = HW_CURSOR_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | /* Use agpgart to manage the GATT */ |
| 646 | if (!(bridge = agp_backend_acquire(pdev))) { |
| 647 | ERR_MSG("cannot acquire agp\n"); |
| 648 | cleanup(dinfo); |
| 649 | return -ENODEV; |
| 650 | } |
| 651 | |
| 652 | /* get the current gatt info */ |
| 653 | if (agp_copy_info(bridge, >t_info)) { |
| 654 | ERR_MSG("cannot get agp info\n"); |
| 655 | agp_backend_release(bridge); |
| 656 | cleanup(dinfo); |
| 657 | return -ENODEV; |
| 658 | } |
| 659 | |
Antonino A. Daplas | 375726d | 2005-09-29 05:19:51 +0800 | [diff] [blame] | 660 | if (MB(voffset) < stolen_size) |
| 661 | offset = (stolen_size >> 12); |
| 662 | else |
| 663 | offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE; |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | /* set the mem offsets - set them after the already used pages */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 666 | if (dinfo->accel) |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 667 | dinfo->ring.offset = offset + gtt_info.current_memory; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 668 | if (dinfo->hwcursor) |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 669 | dinfo->cursor.offset = offset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | + gtt_info.current_memory + (dinfo->ring.size >> 12); |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 671 | if (dinfo->fbmem_gart) |
Sylvain Meyer | 27aef2d | 2005-06-21 17:17:01 -0700 | [diff] [blame] | 672 | dinfo->fb.offset = offset + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | + gtt_info.current_memory + (dinfo->ring.size >> 12) |
| 674 | + (dinfo->cursor.size >> 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Antonino A. Daplas | 375726d | 2005-09-29 05:19:51 +0800 | [diff] [blame] | 676 | /* Allocate memories (which aren't stolen) */ |
Sylvain Meyer | 6bd4934 | 2005-08-15 21:27:13 +0800 | [diff] [blame] | 677 | /* Map the fb and MMIO regions */ |
| 678 | /* ioremap only up to the end of used aperture */ |
| 679 | dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache |
Antonino A. Daplas | 375726d | 2005-09-29 05:19:51 +0800 | [diff] [blame] | 680 | (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12) |
Sylvain Meyer | 6bd4934 | 2005-08-15 21:27:13 +0800 | [diff] [blame] | 681 | + dinfo->fb.size); |
| 682 | if (!dinfo->aperture.virtual) { |
| 683 | ERR_MSG("Cannot remap FB region.\n"); |
| 684 | cleanup(dinfo); |
| 685 | return -ENODEV; |
| 686 | } |
| 687 | |
| 688 | dinfo->mmio_base = |
| 689 | (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys, |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 690 | INTEL_REG_SIZE); |
Sylvain Meyer | 6bd4934 | 2005-08-15 21:27:13 +0800 | [diff] [blame] | 691 | if (!dinfo->mmio_base) { |
| 692 | ERR_MSG("Cannot remap MMIO region.\n"); |
| 693 | cleanup(dinfo); |
| 694 | return -ENODEV; |
| 695 | } |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (dinfo->accel) { |
| 698 | if (!(dinfo->gtt_ring_mem = |
| 699 | agp_allocate_memory(bridge, dinfo->ring.size >> 12, |
| 700 | AGP_NORMAL_MEMORY))) { |
| 701 | ERR_MSG("cannot allocate ring buffer memory\n"); |
| 702 | agp_backend_release(bridge); |
| 703 | cleanup(dinfo); |
| 704 | return -ENOMEM; |
| 705 | } |
| 706 | if (agp_bind_memory(dinfo->gtt_ring_mem, |
| 707 | dinfo->ring.offset)) { |
| 708 | ERR_MSG("cannot bind ring buffer memory\n"); |
| 709 | agp_backend_release(bridge); |
| 710 | cleanup(dinfo); |
| 711 | return -EBUSY; |
| 712 | } |
| 713 | dinfo->ring.physical = dinfo->aperture.physical |
| 714 | + (dinfo->ring.offset << 12); |
| 715 | dinfo->ring.virtual = dinfo->aperture.virtual |
| 716 | + (dinfo->ring.offset << 12); |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 717 | dinfo->ring_head = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | if (dinfo->hwcursor) { |
| 720 | agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY |
| 721 | : AGP_NORMAL_MEMORY; |
| 722 | if (!(dinfo->gtt_cursor_mem = |
| 723 | agp_allocate_memory(bridge, dinfo->cursor.size >> 12, |
| 724 | agp_memtype))) { |
| 725 | ERR_MSG("cannot allocate cursor memory\n"); |
| 726 | agp_backend_release(bridge); |
| 727 | cleanup(dinfo); |
| 728 | return -ENOMEM; |
| 729 | } |
| 730 | if (agp_bind_memory(dinfo->gtt_cursor_mem, |
| 731 | dinfo->cursor.offset)) { |
| 732 | ERR_MSG("cannot bind cursor memory\n"); |
| 733 | agp_backend_release(bridge); |
| 734 | cleanup(dinfo); |
| 735 | return -EBUSY; |
| 736 | } |
| 737 | if (dinfo->mobile) |
| 738 | dinfo->cursor.physical |
| 739 | = dinfo->gtt_cursor_mem->physical; |
| 740 | else |
| 741 | dinfo->cursor.physical = dinfo->aperture.physical |
| 742 | + (dinfo->cursor.offset << 12); |
| 743 | dinfo->cursor.virtual = dinfo->aperture.virtual |
| 744 | + (dinfo->cursor.offset << 12); |
| 745 | } |
| 746 | if (dinfo->fbmem_gart) { |
| 747 | if (!(dinfo->gtt_fb_mem = |
| 748 | agp_allocate_memory(bridge, dinfo->fb.size >> 12, |
| 749 | AGP_NORMAL_MEMORY))) { |
| 750 | WRN_MSG("cannot allocate framebuffer memory - use " |
| 751 | "the stolen one\n"); |
| 752 | dinfo->fbmem_gart = 0; |
| 753 | } |
| 754 | if (agp_bind_memory(dinfo->gtt_fb_mem, |
| 755 | dinfo->fb.offset)) { |
| 756 | WRN_MSG("cannot bind framebuffer memory - use " |
| 757 | "the stolen one\n"); |
| 758 | dinfo->fbmem_gart = 0; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /* update framebuffer memory parameters */ |
| 763 | if (!dinfo->fbmem_gart) |
| 764 | dinfo->fb.offset = 0; /* starts at offset 0 */ |
| 765 | dinfo->fb.physical = dinfo->aperture.physical |
| 766 | + (dinfo->fb.offset << 12); |
| 767 | dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12); |
| 768 | dinfo->fb_start = dinfo->fb.offset << 12; |
| 769 | |
| 770 | /* release agpgart */ |
| 771 | agp_backend_release(bridge); |
| 772 | |
| 773 | if (mtrr) |
| 774 | set_mtrr(dinfo); |
| 775 | |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 776 | DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size, |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 778 | dinfo->fb.virtual); |
| 779 | DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | dinfo->mmio_base_phys, INTEL_REG_SIZE, |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 781 | dinfo->mmio_base); |
| 782 | DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | dinfo->ring.physical, dinfo->ring.size, |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 784 | dinfo->ring.virtual); |
| 785 | DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | dinfo->cursor.physical, dinfo->cursor.size, |
Al Viro | 0fe6e2d | 2006-06-23 06:05:39 +0100 | [diff] [blame] | 787 | dinfo->cursor.virtual, dinfo->cursor.offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | dinfo->cursor.physical); |
| 789 | |
| 790 | DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, " |
| 791 | "noinit = %d\n", vram, accel, hwcursor, fixed, noinit); |
| 792 | DBG_MSG("options: mode = \"%s\"\n", mode ? mode : ""); |
| 793 | |
| 794 | if (probeonly) |
| 795 | bailout(dinfo); |
| 796 | |
| 797 | /* |
| 798 | * Check if the LVDS port or any DVO ports are enabled. If so, |
| 799 | * don't allow mode switching |
| 800 | */ |
| 801 | dvo = intelfbhw_check_non_crt(dinfo); |
| 802 | if (dvo) { |
| 803 | dinfo->fixed_mode = 1; |
| 804 | WRN_MSG("Non-CRT device is enabled ( "); |
| 805 | i = 0; |
| 806 | while (dvo) { |
| 807 | if (dvo & 1) { |
| 808 | s = intelfbhw_dvo_to_string(1 << i); |
| 809 | if (s) |
| 810 | printk("%s ", s); |
| 811 | } |
| 812 | dvo >>= 1; |
| 813 | ++i; |
| 814 | } |
| 815 | printk("). Disabling mode switching.\n"); |
| 816 | } |
| 817 | |
| 818 | if (bailearly == 1) |
| 819 | bailout(dinfo); |
| 820 | |
H. Peter Anvin | 3ea3351 | 2007-10-16 22:36:04 -0700 | [diff] [blame] | 821 | if (FIXED_MODE(dinfo) && |
| 822 | screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | ERR_MSG("Video mode must be programmed at boot time.\n"); |
| 824 | cleanup(dinfo); |
| 825 | return -ENODEV; |
| 826 | } |
| 827 | |
| 828 | if (bailearly == 2) |
| 829 | bailout(dinfo); |
| 830 | |
| 831 | /* Initialise dinfo and related data. */ |
| 832 | /* If an initial mode was programmed at boot time, get its details. */ |
H. Peter Anvin | 3ea3351 | 2007-10-16 22:36:04 -0700 | [diff] [blame] | 833 | if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | get_initial_mode(dinfo); |
| 835 | |
| 836 | if (bailearly == 3) |
| 837 | bailout(dinfo); |
| 838 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 839 | if (FIXED_MODE(dinfo)) /* remap fb address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | update_dinfo(dinfo, &dinfo->initial_var); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
| 842 | if (bailearly == 4) |
| 843 | bailout(dinfo); |
| 844 | |
| 845 | |
| 846 | if (intelfb_set_fbinfo(dinfo)) { |
| 847 | cleanup(dinfo); |
| 848 | return -ENODEV; |
| 849 | } |
| 850 | |
| 851 | if (bailearly == 5) |
| 852 | bailout(dinfo); |
| 853 | |
Dennis Munsie | 41c9480 | 2006-06-20 14:55:55 -0400 | [diff] [blame] | 854 | #ifdef CONFIG_FB_INTEL_I2C |
| 855 | /* register I2C bus */ |
| 856 | intelfb_create_i2c_busses(dinfo); |
| 857 | #endif |
| 858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | if (bailearly == 6) |
| 860 | bailout(dinfo); |
| 861 | |
| 862 | pci_set_drvdata(pdev, dinfo); |
| 863 | |
| 864 | /* Save the initial register state. */ |
| 865 | i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state, |
| 866 | bailearly > 6 ? bailearly - 6 : 0); |
| 867 | if (i != 0) { |
| 868 | DBG_MSG("intelfbhw_read_hw_state returned %d\n", i); |
| 869 | bailout(dinfo); |
| 870 | } |
| 871 | |
| 872 | intelfbhw_print_hw_state(dinfo, &dinfo->save_state); |
| 873 | |
| 874 | if (bailearly == 18) |
| 875 | bailout(dinfo); |
| 876 | |
| 877 | /* Cursor initialisation */ |
| 878 | if (dinfo->hwcursor) { |
| 879 | intelfbhw_cursor_init(dinfo); |
| 880 | intelfbhw_cursor_reset(dinfo); |
| 881 | } |
| 882 | |
| 883 | if (bailearly == 19) |
| 884 | bailout(dinfo); |
| 885 | |
| 886 | /* 2d acceleration init */ |
| 887 | if (dinfo->accel) |
| 888 | intelfbhw_2d_start(dinfo); |
| 889 | |
| 890 | if (bailearly == 20) |
| 891 | bailout(dinfo); |
| 892 | |
| 893 | if (noregister) |
| 894 | bailout(dinfo); |
| 895 | |
| 896 | if (register_framebuffer(dinfo->info) < 0) { |
| 897 | ERR_MSG("Cannot register framebuffer.\n"); |
| 898 | cleanup(dinfo); |
| 899 | return -ENODEV; |
| 900 | } |
| 901 | |
| 902 | dinfo->registered = 1; |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 903 | dinfo->open = 0; |
| 904 | |
| 905 | init_waitqueue_head(&dinfo->vsync.wait); |
| 906 | spin_lock_init(&dinfo->int_lock); |
| 907 | dinfo->irq_flags = 0; |
Eric Hustvedt | f80d0d2 | 2006-06-20 14:36:42 -0400 | [diff] [blame] | 908 | dinfo->vsync.pan_display = 0; |
| 909 | dinfo->vsync.pan_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | return 0; |
| 912 | |
| 913 | err_out_pixmap: |
| 914 | fb_dealloc_cmap(&info->cmap); |
| 915 | err_out_cmap: |
| 916 | framebuffer_release(info); |
| 917 | return -ENODEV; |
| 918 | } |
| 919 | |
| 920 | static void __devexit |
| 921 | intelfb_pci_unregister(struct pci_dev *pdev) |
| 922 | { |
| 923 | struct intelfb_info *dinfo = pci_get_drvdata(pdev); |
| 924 | |
| 925 | DBG_MSG("intelfb_pci_unregister\n"); |
| 926 | |
| 927 | if (!dinfo) |
| 928 | return; |
| 929 | |
| 930 | cleanup(dinfo); |
| 931 | |
| 932 | pci_set_drvdata(pdev, NULL); |
| 933 | } |
| 934 | |
| 935 | /*************************************************************** |
| 936 | * helper functions * |
| 937 | ***************************************************************/ |
| 938 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 939 | int __inline__ intelfb_var_to_depth(const struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
| 941 | DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n", |
| 942 | var->bits_per_pixel, var->green.length); |
| 943 | |
| 944 | switch (var->bits_per_pixel) { |
| 945 | case 16: |
| 946 | return (var->green.length == 6) ? 16 : 15; |
| 947 | case 32: |
| 948 | return 24; |
| 949 | default: |
| 950 | return var->bits_per_pixel; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 955 | static __inline__ int var_to_refresh(const struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | { |
| 957 | int xtot = var->xres + var->left_margin + var->right_margin + |
| 958 | var->hsync_len; |
| 959 | int ytot = var->yres + var->upper_margin + var->lower_margin + |
| 960 | var->vsync_len; |
| 961 | |
| 962 | return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot; |
| 963 | } |
| 964 | |
| 965 | /*************************************************************** |
| 966 | * Various intialisation functions * |
| 967 | ***************************************************************/ |
| 968 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 969 | static void __devinit get_initial_mode(struct intelfb_info *dinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | { |
| 971 | struct fb_var_screeninfo *var; |
| 972 | int xtot, ytot; |
| 973 | |
| 974 | DBG_MSG("get_initial_mode\n"); |
| 975 | |
| 976 | dinfo->initial_vga = 1; |
| 977 | dinfo->initial_fb_base = screen_info.lfb_base; |
| 978 | dinfo->initial_video_ram = screen_info.lfb_size * KB(64); |
| 979 | dinfo->initial_pitch = screen_info.lfb_linelength; |
| 980 | |
| 981 | var = &dinfo->initial_var; |
| 982 | memset(var, 0, sizeof(*var)); |
| 983 | var->xres = screen_info.lfb_width; |
| 984 | var->yres = screen_info.lfb_height; |
| 985 | var->bits_per_pixel = screen_info.lfb_depth; |
| 986 | switch (screen_info.lfb_depth) { |
| 987 | case 15: |
| 988 | var->bits_per_pixel = 16; |
| 989 | break; |
| 990 | case 24: |
| 991 | var->bits_per_pixel = 32; |
| 992 | break; |
| 993 | } |
| 994 | |
| 995 | DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n", |
| 996 | dinfo->initial_fb_base, dinfo->initial_video_ram, |
| 997 | BtoKB(dinfo->initial_video_ram)); |
| 998 | |
| 999 | DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n", |
| 1000 | var->xres, var->yres, var->bits_per_pixel, |
| 1001 | dinfo->initial_pitch); |
| 1002 | |
| 1003 | /* Dummy timing values (assume 60Hz) */ |
| 1004 | var->left_margin = (var->xres / 8) & 0xf8; |
| 1005 | var->right_margin = 32; |
| 1006 | var->upper_margin = 16; |
| 1007 | var->lower_margin = 4; |
| 1008 | var->hsync_len = (var->xres / 8) & 0xf8; |
| 1009 | var->vsync_len = 4; |
| 1010 | |
| 1011 | xtot = var->xres + var->left_margin + |
| 1012 | var->right_margin + var->hsync_len; |
| 1013 | ytot = var->yres + var->upper_margin + |
| 1014 | var->lower_margin + var->vsync_len; |
| 1015 | var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60; |
| 1016 | |
| 1017 | var->height = -1; |
| 1018 | var->width = -1; |
| 1019 | |
| 1020 | if (var->bits_per_pixel > 8) { |
| 1021 | var->red.offset = screen_info.red_pos; |
| 1022 | var->red.length = screen_info.red_size; |
| 1023 | var->green.offset = screen_info.green_pos; |
| 1024 | var->green.length = screen_info.green_size; |
| 1025 | var->blue.offset = screen_info.blue_pos; |
| 1026 | var->blue.length = screen_info.blue_size; |
| 1027 | var->transp.offset = screen_info.rsvd_pos; |
| 1028 | var->transp.length = screen_info.rsvd_size; |
| 1029 | } else { |
| 1030 | var->red.length = 8; |
| 1031 | var->green.length = 8; |
| 1032 | var->blue.length = 8; |
| 1033 | } |
| 1034 | } |
| 1035 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1036 | static int __devinit intelfb_init_var(struct intelfb_info *dinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
| 1038 | struct fb_var_screeninfo *var; |
| 1039 | int msrc = 0; |
| 1040 | |
| 1041 | DBG_MSG("intelfb_init_var\n"); |
| 1042 | |
| 1043 | var = &dinfo->info->var; |
| 1044 | if (FIXED_MODE(dinfo)) { |
| 1045 | memcpy(var, &dinfo->initial_var, |
| 1046 | sizeof(struct fb_var_screeninfo)); |
| 1047 | msrc = 5; |
| 1048 | } else { |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 1049 | const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev); |
| 1050 | u8 *edid_d = NULL; |
| 1051 | |
| 1052 | if (edid_s) { |
Alexey Dobriyan | bfba7b3 | 2006-12-08 02:40:46 -0800 | [diff] [blame] | 1053 | edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL); |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 1054 | |
| 1055 | if (edid_d) { |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 1056 | fb_edid_to_monspecs(edid_d, |
| 1057 | &dinfo->info->monspecs); |
| 1058 | kfree(edid_d); |
| 1059 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 1061 | |
| 1062 | if (mode) { |
| 1063 | printk("intelfb: Looking for mode in private " |
| 1064 | "database\n"); |
| 1065 | msrc = fb_find_mode(var, dinfo->info, mode, |
| 1066 | dinfo->info->monspecs.modedb, |
| 1067 | dinfo->info->monspecs.modedb_len, |
| 1068 | NULL, 0); |
| 1069 | |
| 1070 | if (msrc && msrc > 1) { |
| 1071 | printk("intelfb: No mode in private database, " |
| 1072 | "intelfb: looking for mode in global " |
| 1073 | "database "); |
| 1074 | msrc = fb_find_mode(var, dinfo->info, mode, |
Dennis Munsie | 7a532c6 | 2006-05-29 18:58:09 +1000 | [diff] [blame] | 1075 | NULL, 0, NULL, 0); |
Antonino A. Daplas | 56e004e | 2006-05-29 18:49:08 +1000 | [diff] [blame] | 1076 | |
| 1077 | if (msrc) |
| 1078 | msrc |= 8; |
| 1079 | } |
| 1080 | |
| 1081 | } |
| 1082 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1083 | if (!msrc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE, |
Dennis Munsie | 7a532c6 | 2006-05-29 18:58:09 +1000 | [diff] [blame] | 1085 | NULL, 0, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | if (!msrc) { |
| 1089 | ERR_MSG("Cannot find a suitable video mode.\n"); |
| 1090 | return 1; |
| 1091 | } |
| 1092 | |
| 1093 | INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres, |
| 1094 | var->bits_per_pixel, var_to_refresh(var)); |
| 1095 | |
| 1096 | DBG_MSG("Initial video mode is from %d.\n", msrc); |
| 1097 | |
| 1098 | #if ALLOCATE_FOR_PANNING |
| 1099 | /* Allow use of half of the video ram for panning */ |
| 1100 | var->xres_virtual = var->xres; |
| 1101 | var->yres_virtual = |
| 1102 | dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres); |
| 1103 | if (var->yres_virtual < var->yres) |
| 1104 | var->yres_virtual = var->yres; |
| 1105 | #else |
| 1106 | var->yres_virtual = var->yres; |
| 1107 | #endif |
| 1108 | |
| 1109 | if (dinfo->accel) |
| 1110 | var->accel_flags |= FB_ACCELF_TEXT; |
| 1111 | else |
| 1112 | var->accel_flags &= ~FB_ACCELF_TEXT; |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1117 | static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | { |
| 1119 | struct fb_info *info = dinfo->info; |
| 1120 | |
| 1121 | DBG_MSG("intelfb_set_fbinfo\n"); |
| 1122 | |
| 1123 | info->flags = FBINFO_FLAG_DEFAULT; |
| 1124 | info->fbops = &intel_fb_ops; |
| 1125 | info->pseudo_palette = dinfo->pseudo_palette; |
| 1126 | |
| 1127 | info->pixmap.size = 64*1024; |
| 1128 | info->pixmap.buf_align = 8; |
James Simmons | 58a6064 | 2005-06-21 17:17:08 -0700 | [diff] [blame] | 1129 | info->pixmap.access_align = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
| 1131 | |
| 1132 | if (intelfb_init_var(dinfo)) |
| 1133 | return 1; |
| 1134 | |
| 1135 | info->pixmap.scan_align = 1; |
Antonino A. Daplas | 33c37c0 | 2005-12-19 15:11:49 +0800 | [diff] [blame] | 1136 | strcpy(info->fix.id, dinfo->name); |
| 1137 | info->fix.smem_start = dinfo->fb.physical; |
| 1138 | info->fix.smem_len = dinfo->fb.size; |
| 1139 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1140 | info->fix.type_aux = 0; |
| 1141 | info->fix.xpanstep = 8; |
| 1142 | info->fix.ypanstep = 1; |
| 1143 | info->fix.ywrapstep = 0; |
| 1144 | info->fix.mmio_start = dinfo->mmio_base_phys; |
| 1145 | info->fix.mmio_len = INTEL_REG_SIZE; |
| 1146 | info->fix.accel = FB_ACCEL_I830; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | update_dinfo(dinfo, &info->var); |
| 1148 | |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
| 1152 | /* Update dinfo to match the active video mode. */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1153 | static void update_dinfo(struct intelfb_info *dinfo, |
| 1154 | struct fb_var_screeninfo *var) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | { |
| 1156 | DBG_MSG("update_dinfo\n"); |
| 1157 | |
| 1158 | dinfo->bpp = var->bits_per_pixel; |
| 1159 | dinfo->depth = intelfb_var_to_depth(var); |
| 1160 | dinfo->xres = var->xres; |
| 1161 | dinfo->yres = var->xres; |
| 1162 | dinfo->pixclock = var->pixclock; |
| 1163 | |
Antonino A. Daplas | 33c37c0 | 2005-12-19 15:11:49 +0800 | [diff] [blame] | 1164 | dinfo->info->fix.visual = dinfo->visual; |
| 1165 | dinfo->info->fix.line_length = dinfo->pitch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
| 1167 | switch (dinfo->bpp) { |
| 1168 | case 8: |
| 1169 | dinfo->visual = FB_VISUAL_PSEUDOCOLOR; |
| 1170 | dinfo->pitch = var->xres_virtual; |
| 1171 | break; |
| 1172 | case 16: |
| 1173 | dinfo->visual = FB_VISUAL_TRUECOLOR; |
| 1174 | dinfo->pitch = var->xres_virtual * 2; |
| 1175 | break; |
| 1176 | case 32: |
| 1177 | dinfo->visual = FB_VISUAL_TRUECOLOR; |
| 1178 | dinfo->pitch = var->xres_virtual * 4; |
| 1179 | break; |
| 1180 | } |
| 1181 | |
| 1182 | /* Make sure the line length is a aligned correctly. */ |
Dennis Munsie | df7df8a | 2006-05-27 18:17:52 +1000 | [diff] [blame] | 1183 | if (IS_I9XX(dinfo)) |
| 1184 | dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX); |
| 1185 | else |
| 1186 | dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
| 1188 | if (FIXED_MODE(dinfo)) |
| 1189 | dinfo->pitch = dinfo->initial_pitch; |
| 1190 | |
| 1191 | dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual; |
| 1192 | dinfo->info->fix.line_length = dinfo->pitch; |
| 1193 | dinfo->info->fix.visual = dinfo->visual; |
| 1194 | } |
| 1195 | |
| 1196 | /* fbops functions */ |
| 1197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | /*************************************************************** |
| 1199 | * fbdev interface * |
| 1200 | ***************************************************************/ |
| 1201 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1202 | static int intelfb_open(struct fb_info *info, int user) |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1203 | { |
| 1204 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1205 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1206 | if (user) |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1207 | dinfo->open++; |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1208 | |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1212 | static int intelfb_release(struct fb_info *info, int user) |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1213 | { |
| 1214 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1215 | |
| 1216 | if (user) { |
| 1217 | dinfo->open--; |
| 1218 | msleep(1); |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1219 | if (!dinfo->open) |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1220 | intelfbhw_disable_irq(dinfo); |
Eric Hustvedt | 7649757 | 2006-06-20 14:36:41 -0400 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1226 | static int intelfb_check_var(struct fb_var_screeninfo *var, |
| 1227 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
| 1229 | int change_var = 0; |
| 1230 | struct fb_var_screeninfo v; |
| 1231 | struct intelfb_info *dinfo; |
| 1232 | static int first = 1; |
Dave Airlie | 3587c50 | 2006-04-03 14:46:55 +1000 | [diff] [blame] | 1233 | int i; |
| 1234 | /* Good pitches to allow tiling. Don't care about pitches < 1024. */ |
| 1235 | static const int pitches[] = { |
| 1236 | 128 * 8, |
| 1237 | 128 * 16, |
| 1238 | 128 * 32, |
| 1239 | 128 * 64, |
| 1240 | 0 |
| 1241 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags); |
| 1244 | |
| 1245 | dinfo = GET_DINFO(info); |
| 1246 | |
Dave Airlie | 3587c50 | 2006-04-03 14:46:55 +1000 | [diff] [blame] | 1247 | /* update the pitch */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | if (intelfbhw_validate_mode(dinfo, var) != 0) |
| 1249 | return -EINVAL; |
| 1250 | |
| 1251 | v = *var; |
| 1252 | |
Dave Airlie | 3587c50 | 2006-04-03 14:46:55 +1000 | [diff] [blame] | 1253 | for (i = 0; pitches[i] != 0; i++) { |
| 1254 | if (pitches[i] >= v.xres_virtual) { |
| 1255 | v.xres_virtual = pitches[i]; |
| 1256 | break; |
| 1257 | } |
| 1258 | } |
| 1259 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | /* Check for a supported bpp. */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1261 | if (v.bits_per_pixel <= 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | v.bits_per_pixel = 8; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1263 | else if (v.bits_per_pixel <= 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | if (v.bits_per_pixel == 16) |
| 1265 | v.green.length = 6; |
| 1266 | v.bits_per_pixel = 16; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1267 | } else if (v.bits_per_pixel <= 32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | v.bits_per_pixel = 32; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1269 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | return -EINVAL; |
| 1271 | |
| 1272 | change_var = ((info->var.xres != var->xres) || |
| 1273 | (info->var.yres != var->yres) || |
| 1274 | (info->var.xres_virtual != var->xres_virtual) || |
| 1275 | (info->var.yres_virtual != var->yres_virtual) || |
| 1276 | (info->var.bits_per_pixel != var->bits_per_pixel) || |
| 1277 | memcmp(&info->var.red, &var->red, sizeof(var->red)) || |
| 1278 | memcmp(&info->var.green, &var->green, |
| 1279 | sizeof(var->green)) || |
| 1280 | memcmp(&info->var.blue, &var->blue, sizeof(var->blue))); |
| 1281 | |
| 1282 | if (FIXED_MODE(dinfo) && |
| 1283 | (change_var || |
| 1284 | var->yres_virtual > dinfo->initial_var.yres_virtual || |
| 1285 | var->yres_virtual < dinfo->initial_var.yres || |
| 1286 | var->xoffset || var->nonstd)) { |
| 1287 | if (first) { |
| 1288 | ERR_MSG("Changing the video mode is not supported.\n"); |
| 1289 | first = 0; |
| 1290 | } |
| 1291 | return -EINVAL; |
| 1292 | } |
| 1293 | |
| 1294 | switch (intelfb_var_to_depth(&v)) { |
| 1295 | case 8: |
| 1296 | v.red.offset = v.green.offset = v.blue.offset = 0; |
| 1297 | v.red.length = v.green.length = v.blue.length = 8; |
| 1298 | v.transp.offset = v.transp.length = 0; |
| 1299 | break; |
| 1300 | case 15: |
| 1301 | v.red.offset = 10; |
| 1302 | v.green.offset = 5; |
| 1303 | v.blue.offset = 0; |
| 1304 | v.red.length = v.green.length = v.blue.length = 5; |
| 1305 | v.transp.offset = v.transp.length = 0; |
| 1306 | break; |
| 1307 | case 16: |
| 1308 | v.red.offset = 11; |
| 1309 | v.green.offset = 5; |
| 1310 | v.blue.offset = 0; |
| 1311 | v.red.length = 5; |
| 1312 | v.green.length = 6; |
| 1313 | v.blue.length = 5; |
| 1314 | v.transp.offset = v.transp.length = 0; |
| 1315 | break; |
| 1316 | case 24: |
| 1317 | v.red.offset = 16; |
| 1318 | v.green.offset = 8; |
| 1319 | v.blue.offset = 0; |
| 1320 | v.red.length = v.green.length = v.blue.length = 8; |
| 1321 | v.transp.offset = v.transp.length = 0; |
| 1322 | break; |
| 1323 | case 32: |
| 1324 | v.red.offset = 16; |
| 1325 | v.green.offset = 8; |
| 1326 | v.blue.offset = 0; |
| 1327 | v.red.length = v.green.length = v.blue.length = 8; |
| 1328 | v.transp.offset = 24; |
| 1329 | v.transp.length = 8; |
| 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | if (v.xoffset < 0) |
| 1334 | v.xoffset = 0; |
| 1335 | if (v.yoffset < 0) |
| 1336 | v.yoffset = 0; |
| 1337 | |
| 1338 | if (v.xoffset > v.xres_virtual - v.xres) |
| 1339 | v.xoffset = v.xres_virtual - v.xres; |
| 1340 | if (v.yoffset > v.yres_virtual - v.yres) |
| 1341 | v.yoffset = v.yres_virtual - v.yres; |
| 1342 | |
| 1343 | v.red.msb_right = v.green.msb_right = v.blue.msb_right = |
| 1344 | v.transp.msb_right = 0; |
| 1345 | |
| 1346 | *var = v; |
| 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1351 | static int intelfb_set_par(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | { |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1353 | struct intelfb_hwstate *hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1355 | |
| 1356 | if (FIXED_MODE(dinfo)) { |
| 1357 | ERR_MSG("Changing the video mode is not supported.\n"); |
| 1358 | return -EINVAL; |
| 1359 | } |
| 1360 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1361 | hw = kmalloc(sizeof(*hw), GFP_ATOMIC); |
| 1362 | if (!hw) |
| 1363 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
| 1365 | DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres, |
| 1366 | info->var.yres, info->var.bits_per_pixel); |
| 1367 | |
Paul Menzel | b586640 | 2009-06-16 15:34:37 -0700 | [diff] [blame] | 1368 | /* |
| 1369 | * Disable VCO prior to timing register change. |
| 1370 | */ |
| 1371 | OUTREG(DPLL_A, INREG(DPLL_A) & ~DPLL_VCO_ENABLE); |
| 1372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | intelfb_blank(FB_BLANK_POWERDOWN, info); |
| 1374 | |
Sylvain Meyer | df52933 | 2005-06-21 17:17:02 -0700 | [diff] [blame] | 1375 | if (ACCEL(dinfo, info)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | intelfbhw_2d_stop(dinfo); |
| 1377 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1378 | memcpy(hw, &dinfo->save_state, sizeof(*hw)); |
| 1379 | if (intelfbhw_mode_to_hw(dinfo, hw, &info->var)) |
| 1380 | goto invalid_mode; |
| 1381 | if (intelfbhw_program_mode(dinfo, hw, 0)) |
| 1382 | goto invalid_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | #if REGDUMP > 0 |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1385 | intelfbhw_read_hw_state(dinfo, hw, 0); |
| 1386 | intelfbhw_print_hw_state(dinfo, hw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | #endif |
| 1388 | |
| 1389 | update_dinfo(dinfo, &info->var); |
| 1390 | |
Sylvain Meyer | df52933 | 2005-06-21 17:17:02 -0700 | [diff] [blame] | 1391 | if (ACCEL(dinfo, info)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | intelfbhw_2d_start(dinfo); |
| 1393 | |
| 1394 | intelfb_pan_display(&info->var, info); |
| 1395 | |
| 1396 | intelfb_blank(FB_BLANK_UNBLANK, info); |
| 1397 | |
| 1398 | if (ACCEL(dinfo, info)) { |
| 1399 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | |
| 1400 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | |
| 1401 | FBINFO_HWACCEL_IMAGEBLIT; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1402 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | kfree(hw); |
| 1406 | return 0; |
| 1407 | invalid_mode: |
| 1408 | kfree(hw); |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1412 | static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 1413 | unsigned blue, unsigned transp, |
| 1414 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | { |
| 1416 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1417 | |
| 1418 | #if VERBOSE > 0 |
| 1419 | DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth); |
| 1420 | #endif |
| 1421 | |
| 1422 | if (regno > 255) |
| 1423 | return 1; |
| 1424 | |
Antonino A. Daplas | d301524 | 2006-03-11 03:27:26 -0800 | [diff] [blame] | 1425 | if (dinfo->depth == 8) { |
| 1426 | red >>= 8; |
| 1427 | green >>= 8; |
| 1428 | blue >>= 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
Antonino A. Daplas | d301524 | 2006-03-11 03:27:26 -0800 | [diff] [blame] | 1430 | intelfbhw_setcolreg(dinfo, regno, red, green, blue, |
| 1431 | transp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
Antonino A. Daplas | d301524 | 2006-03-11 03:27:26 -0800 | [diff] [blame] | 1433 | |
| 1434 | if (regno < 16) { |
| 1435 | switch (dinfo->depth) { |
| 1436 | case 15: |
| 1437 | dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) | |
| 1438 | ((green & 0xf800) >> 6) | |
| 1439 | ((blue & 0xf800) >> 11); |
| 1440 | break; |
| 1441 | case 16: |
| 1442 | dinfo->pseudo_palette[regno] = (red & 0xf800) | |
| 1443 | ((green & 0xfc00) >> 5) | |
| 1444 | ((blue & 0xf800) >> 11); |
| 1445 | break; |
| 1446 | case 24: |
| 1447 | dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) | |
| 1448 | (green & 0xff00) | |
| 1449 | ((blue & 0xff00) >> 8); |
| 1450 | break; |
| 1451 | } |
| 1452 | } |
| 1453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | return 0; |
| 1455 | } |
| 1456 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1457 | static int intelfb_blank(int blank, struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
| 1459 | intelfbhw_do_blank(blank, info); |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1463 | static int intelfb_pan_display(struct fb_var_screeninfo *var, |
| 1464 | struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | { |
| 1466 | intelfbhw_pan_display(var, info); |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | /* When/if we have our own ioctls. */ |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1471 | static int intelfb_ioctl(struct fb_info *info, unsigned int cmd, |
| 1472 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | { |
| 1474 | int retval = 0; |
Eric Hustvedt | 37bced3 | 2006-06-20 14:36:42 -0400 | [diff] [blame] | 1475 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1476 | u32 pipe = 0; |
| 1477 | |
| 1478 | switch (cmd) { |
| 1479 | case FBIO_WAITFORVSYNC: |
| 1480 | if (get_user(pipe, (__u32 __user *)arg)) |
| 1481 | return -EFAULT; |
| 1482 | |
| 1483 | retval = intelfbhw_wait_for_vsync(dinfo, pipe); |
| 1484 | break; |
| 1485 | default: |
| 1486 | break; |
| 1487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
| 1489 | return retval; |
| 1490 | } |
| 1491 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1492 | static void intelfb_fillrect (struct fb_info *info, |
| 1493 | const struct fb_fillrect *rect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | { |
| 1495 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1496 | u32 rop, color; |
| 1497 | |
| 1498 | #if VERBOSE > 0 |
| 1499 | DBG_MSG("intelfb_fillrect\n"); |
| 1500 | #endif |
| 1501 | |
Hannes Eder | fd00205 | 2009-01-06 14:42:35 -0800 | [diff] [blame] | 1502 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) { |
| 1503 | cfb_fillrect(info, rect); |
| 1504 | return; |
| 1505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | |
| 1507 | if (rect->rop == ROP_COPY) |
| 1508 | rop = PAT_ROP_GXCOPY; |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1509 | else /* ROP_XOR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | rop = PAT_ROP_GXXOR; |
| 1511 | |
| 1512 | if (dinfo->depth != 8) |
| 1513 | color = dinfo->pseudo_palette[rect->color]; |
| 1514 | else |
| 1515 | color = rect->color; |
| 1516 | |
| 1517 | intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy, |
| 1518 | rect->width, rect->height, color, |
| 1519 | dinfo->pitch, info->var.bits_per_pixel, |
| 1520 | rop); |
| 1521 | } |
| 1522 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1523 | static void intelfb_copyarea(struct fb_info *info, |
| 1524 | const struct fb_copyarea *region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | { |
| 1526 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1527 | |
| 1528 | #if VERBOSE > 0 |
| 1529 | DBG_MSG("intelfb_copyarea\n"); |
| 1530 | #endif |
| 1531 | |
Hannes Eder | fd00205 | 2009-01-06 14:42:35 -0800 | [diff] [blame] | 1532 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) { |
| 1533 | cfb_copyarea(info, region); |
| 1534 | return; |
| 1535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
| 1537 | intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx, |
| 1538 | region->dy, region->width, region->height, |
| 1539 | dinfo->pitch, info->var.bits_per_pixel); |
| 1540 | } |
| 1541 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1542 | static void intelfb_imageblit(struct fb_info *info, |
| 1543 | const struct fb_image *image) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | { |
| 1545 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1546 | u32 fgcolor, bgcolor; |
| 1547 | |
| 1548 | #if VERBOSE > 0 |
| 1549 | DBG_MSG("intelfb_imageblit\n"); |
| 1550 | #endif |
| 1551 | |
| 1552 | if (!ACCEL(dinfo, info) || dinfo->depth == 4 |
Hannes Eder | fd00205 | 2009-01-06 14:42:35 -0800 | [diff] [blame] | 1553 | || image->depth != 1) { |
| 1554 | cfb_imageblit(info, image); |
| 1555 | return; |
| 1556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
| 1558 | if (dinfo->depth != 8) { |
| 1559 | fgcolor = dinfo->pseudo_palette[image->fg_color]; |
| 1560 | bgcolor = dinfo->pseudo_palette[image->bg_color]; |
| 1561 | } else { |
| 1562 | fgcolor = image->fg_color; |
| 1563 | bgcolor = image->bg_color; |
| 1564 | } |
| 1565 | |
| 1566 | if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width, |
| 1567 | image->height, image->data, |
| 1568 | image->dx, image->dy, |
Hannes Eder | fd00205 | 2009-01-06 14:42:35 -0800 | [diff] [blame] | 1569 | dinfo->pitch, info->var.bits_per_pixel)) { |
| 1570 | cfb_imageblit(info, image); |
| 1571 | return; |
| 1572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1575 | static int intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | { |
| 1577 | struct intelfb_info *dinfo = GET_DINFO(info); |
Dave Airlie | 8b91b0b | 2006-03-23 19:23:48 +1100 | [diff] [blame] | 1578 | u32 physical; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | #if VERBOSE > 0 |
| 1580 | DBG_MSG("intelfb_cursor\n"); |
| 1581 | #endif |
| 1582 | |
| 1583 | if (!dinfo->hwcursor) |
Antonino A. Daplas | c465e05 | 2005-11-07 01:00:35 -0800 | [diff] [blame] | 1584 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
| 1586 | intelfbhw_cursor_hide(dinfo); |
| 1587 | |
| 1588 | /* If XFree killed the cursor - restore it */ |
Dave Airlie | 3aff13c | 2006-03-31 17:08:52 +1000 | [diff] [blame] | 1589 | physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical : |
Dave Airlie | 8b91b0b | 2006-03-23 19:23:48 +1100 | [diff] [blame] | 1590 | (dinfo->cursor.offset << 12); |
Dave Airlie | 8bb91f6 | 2006-03-23 13:06:32 +1100 | [diff] [blame] | 1591 | |
Dave Airlie | 8b91b0b | 2006-03-23 19:23:48 +1100 | [diff] [blame] | 1592 | if (INREG(CURSOR_A_BASEADDR) != physical) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | u32 fg, bg; |
| 1594 | |
| 1595 | DBG_MSG("the cursor was killed - restore it !!\n"); |
| 1596 | DBG_MSG("size %d, %d pos %d, %d\n", |
| 1597 | cursor->image.width, cursor->image.height, |
| 1598 | cursor->image.dx, cursor->image.dy); |
| 1599 | |
| 1600 | intelfbhw_cursor_init(dinfo); |
| 1601 | intelfbhw_cursor_reset(dinfo); |
| 1602 | intelfbhw_cursor_setpos(dinfo, cursor->image.dx, |
| 1603 | cursor->image.dy); |
| 1604 | |
| 1605 | if (dinfo->depth != 8) { |
| 1606 | fg =dinfo->pseudo_palette[cursor->image.fg_color]; |
| 1607 | bg =dinfo->pseudo_palette[cursor->image.bg_color]; |
| 1608 | } else { |
| 1609 | fg = cursor->image.fg_color; |
| 1610 | bg = cursor->image.bg_color; |
| 1611 | } |
| 1612 | intelfbhw_cursor_setcolor(dinfo, bg, fg); |
| 1613 | intelfbhw_cursor_load(dinfo, cursor->image.width, |
| 1614 | cursor->image.height, |
| 1615 | dinfo->cursor_src); |
| 1616 | |
| 1617 | if (cursor->enable) |
| 1618 | intelfbhw_cursor_show(dinfo); |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | if (cursor->set & FB_CUR_SETPOS) { |
| 1623 | u32 dx, dy; |
| 1624 | |
| 1625 | dx = cursor->image.dx - info->var.xoffset; |
| 1626 | dy = cursor->image.dy - info->var.yoffset; |
| 1627 | |
| 1628 | intelfbhw_cursor_setpos(dinfo, dx, dy); |
| 1629 | } |
| 1630 | |
| 1631 | if (cursor->set & FB_CUR_SETSIZE) { |
| 1632 | if (cursor->image.width > 64 || cursor->image.height > 64) |
| 1633 | return -ENXIO; |
| 1634 | |
| 1635 | intelfbhw_cursor_reset(dinfo); |
| 1636 | } |
| 1637 | |
| 1638 | if (cursor->set & FB_CUR_SETCMAP) { |
| 1639 | u32 fg, bg; |
| 1640 | |
| 1641 | if (dinfo->depth != 8) { |
| 1642 | fg = dinfo->pseudo_palette[cursor->image.fg_color]; |
| 1643 | bg = dinfo->pseudo_palette[cursor->image.bg_color]; |
| 1644 | } else { |
| 1645 | fg = cursor->image.fg_color; |
| 1646 | bg = cursor->image.bg_color; |
| 1647 | } |
| 1648 | |
| 1649 | intelfbhw_cursor_setcolor(dinfo, bg, fg); |
| 1650 | } |
| 1651 | |
| 1652 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { |
| 1653 | u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8); |
| 1654 | u32 size = s_pitch * cursor->image.height; |
| 1655 | u8 *dat = (u8 *) cursor->image.data; |
| 1656 | u8 *msk = (u8 *) cursor->mask; |
| 1657 | u8 src[64]; |
| 1658 | u32 i; |
| 1659 | |
| 1660 | if (cursor->image.depth != 1) |
| 1661 | return -ENXIO; |
| 1662 | |
| 1663 | switch (cursor->rop) { |
| 1664 | case ROP_XOR: |
| 1665 | for (i = 0; i < size; i++) |
| 1666 | src[i] = dat[i] ^ msk[i]; |
| 1667 | break; |
| 1668 | case ROP_COPY: |
| 1669 | default: |
| 1670 | for (i = 0; i < size; i++) |
| 1671 | src[i] = dat[i] & msk[i]; |
| 1672 | break; |
| 1673 | } |
| 1674 | |
| 1675 | /* save the bitmap to restore it when XFree will |
| 1676 | make the cursor dirty */ |
| 1677 | memcpy(dinfo->cursor_src, src, size); |
| 1678 | |
| 1679 | intelfbhw_cursor_load(dinfo, cursor->image.width, |
| 1680 | cursor->image.height, src); |
| 1681 | } |
| 1682 | |
| 1683 | if (cursor->enable) |
| 1684 | intelfbhw_cursor_show(dinfo); |
| 1685 | |
| 1686 | return 0; |
| 1687 | } |
| 1688 | |
Krzysztof Halasa | 689c956 | 2007-10-16 01:29:31 -0700 | [diff] [blame] | 1689 | static int intelfb_sync(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | { |
| 1691 | struct intelfb_info *dinfo = GET_DINFO(info); |
| 1692 | |
| 1693 | #if VERBOSE > 0 |
| 1694 | DBG_MSG("intelfb_sync\n"); |
| 1695 | #endif |
| 1696 | |
| 1697 | if (dinfo->ring_lockup) |
| 1698 | return 0; |
| 1699 | |
| 1700 | intelfbhw_do_sync(dinfo); |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |