Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * intelfb | |
3 | * | |
9639d5ec | 4 | * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/ |
3f7a26b4 | 5 | * 945G/945GM/945GME/965G/965GM integrated graphics chips. |
1da177e4 | 6 | * |
96de0e25 | 7 | * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org> |
1da177e4 | 8 | * 2004 Sylvain Meyer |
8bb91f6a | 9 | * 2006 David Airlie |
1da177e4 LT |
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 | |
0e170c72 MB |
102 | * |
103 | * 04/2008 - Version 0.9.5 | |
104 | * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>) | |
3f7a26b4 PE |
105 | * |
106 | * 08/2008 - Version 0.9.6 | |
107 | * Add support for 945GME. (Phil Endecott <spam_from_intelfb@chezphil.org>) | |
1da177e4 LT |
108 | */ |
109 | ||
1da177e4 LT |
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> | |
1da177e4 LT |
115 | #include <linux/slab.h> |
116 | #include <linux/delay.h> | |
117 | #include <linux/fb.h> | |
1da177e4 LT |
118 | #include <linux/ioport.h> |
119 | #include <linux/init.h> | |
120 | #include <linux/pci.h> | |
121 | #include <linux/vmalloc.h> | |
1da177e4 | 122 | #include <linux/pagemap.h> |
a8f340e3 | 123 | #include <linux/screen_info.h> |
1da177e4 LT |
124 | |
125 | #include <asm/io.h> | |
126 | ||
127 | #ifdef CONFIG_MTRR | |
128 | #include <asm/mtrr.h> | |
129 | #endif | |
130 | ||
131 | #include "intelfb.h" | |
1da177e4 | 132 | #include "intelfbhw.h" |
56e004e5 | 133 | #include "../edid.h" |
1da177e4 | 134 | |
14c6f52f AB |
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); | |
7649757b EH |
138 | static int intelfb_open(struct fb_info *info, int user); |
139 | static int intelfb_release(struct fb_info *info, int user); | |
14c6f52f AB |
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 | ||
67a6680d CH |
162 | static int intelfb_ioctl(struct fb_info *info, |
163 | unsigned int cmd, unsigned long arg); | |
14c6f52f AB |
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 | ||
1da177e4 LT |
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 }, | |
347486bb | 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 }, |
1da177e4 | 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 }, |
3a59026b | 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 }, |
9639d5ec | 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 }, |
9a90603f | 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 }, |
3f7a26b4 | 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 }, |
0e170c72 MB |
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 }, | |
1da177e4 LT |
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, | |
7649757b EH |
202 | .fb_open = intelfb_open, |
203 | .fb_release = intelfb_release, | |
1da177e4 LT |
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 = { | |
5a3b5899 | 219 | .name = "intelfb", |
1da177e4 LT |
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>"); | |
689c9568 KH |
228 | MODULE_DESCRIPTION("Framebuffer driver for Intel(R) " SUPPORTED_CHIPSETS |
229 | " chipsets"); | |
1da177e4 LT |
230 | MODULE_LICENSE("Dual BSD/GPL"); |
231 | MODULE_DEVICE_TABLE(pci, intelfb_pci_table); | |
232 | ||
90ab5ee9 | 233 | static bool accel = 1; |
346e399b | 234 | static int vram = 4; |
90ab5ee9 RR |
235 | static bool hwcursor = 0; |
236 | static bool mtrr = 1; | |
237 | static bool fixed = 0; | |
238 | static bool noinit = 0; | |
239 | static bool noregister = 0; | |
240 | static bool probeonly = 0; | |
241 | static bool idonly = 0; | |
346e399b | 242 | static int bailearly = 0; |
27aef2d4 | 243 | static int voffset = 48; |
346e399b | 244 | static char *mode = NULL; |
1da177e4 LT |
245 | |
246 | module_param(accel, bool, S_IRUGO); | |
4c7ffe0b | 247 | MODULE_PARM_DESC(accel, "Enable hardware acceleration"); |
1da177e4 LT |
248 | module_param(vram, int, S_IRUGO); |
249 | MODULE_PARM_DESC(vram, "System RAM to allocate to framebuffer in MiB"); | |
27aef2d4 SM |
250 | module_param(voffset, int, S_IRUGO); |
251 | MODULE_PARM_DESC(voffset, "Offset of framebuffer in MiB"); | |
1da177e4 LT |
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)"); | |
a6e02554 | 266 | module_param(bailearly, int, 0); |
1da177e4 LT |
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))) | |
65eb2f97 | 274 | #define OPT_INTVAL(opt, name) simple_strtoul(opt + strlen(name) + 1, NULL, 0) |
1da177e4 LT |
275 | #define OPT_STRVAL(opt, name) (opt + strlen(name)) |
276 | ||
689c9568 | 277 | static __inline__ char * get_opt_string(const char *this_opt, const char *name) |
1da177e4 LT |
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 | ||
689c9568 KH |
295 | static __inline__ int get_opt_int(const char *this_opt, const char *name, |
296 | int *ret) | |
1da177e4 LT |
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 | ||
689c9568 KH |
308 | static __inline__ int get_opt_bool(const char *this_opt, const char *name, |
309 | int *ret) | |
1da177e4 LT |
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 | ||
689c9568 | 329 | static int __init intelfb_setup(char *options) |
1da177e4 LT |
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 | ; | |
689c9568 | 359 | else if (get_opt_int(this_opt, "vram", &vram)) |
1da177e4 LT |
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 | ||
689c9568 | 380 | static int __init intelfb_init(void) |
1da177e4 LT |
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 | ||
689c9568 | 404 | static void __exit intelfb_exit(void) |
1da177e4 LT |
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 | { | |
689c9568 KH |
430 | if (dinfo->has_mtrr) |
431 | mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical, | |
1da177e4 LT |
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 | ||
689c9568 | 444 | static void cleanup(struct intelfb_info *dinfo) |
1da177e4 LT |
445 | { |
446 | DBG_MSG("cleanup\n"); | |
447 | ||
448 | if (!dinfo) | |
449 | return; | |
450 | ||
7649757b EH |
451 | intelfbhw_disable_irq(dinfo); |
452 | ||
1da177e4 LT |
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 | ||
7627899b DM |
474 | #ifdef CONFIG_FB_INTEL_I2C |
475 | /* un-register I2C bus */ | |
476 | intelfb_delete_i2c_busses(dinfo); | |
477 | #endif | |
478 | ||
1da177e4 LT |
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 | ||
4b3760ce | 484 | if (dinfo->flag & INTELFB_MMIO_ACQUIRED) |
1da177e4 | 485 | release_mem_region(dinfo->mmio_base_phys, INTEL_REG_SIZE); |
4b3760ce | 486 | if (dinfo->flag & INTELFB_FB_ACQUIRED) |
1da177e4 LT |
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 | ||
689c9568 KH |
500 | static int __devinit intelfb_pci_register(struct pci_dev *pdev, |
501 | const struct pci_device_id *ent) | |
1da177e4 LT |
502 | { |
503 | struct fb_info *info; | |
504 | struct intelfb_info *dinfo; | |
4c7ffe0b | 505 | int i, err, dvo; |
1da177e4 LT |
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; | |
689c9568 KH |
511 | int aperture_bar = 0; |
512 | int mmio_bar = 1; | |
27aef2d4 | 513 | int offset; |
1da177e4 LT |
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; | |
1da177e4 LT |
532 | } |
533 | ||
534 | dinfo = info->par; | |
535 | dinfo->info = info; | |
536 | dinfo->fbops = &intel_fb_ops; | |
537 | dinfo->pdev = pdev; | |
538 | ||
539 | /* Reserve pixmap space. */ | |
f5610b9c | 540 | info->pixmap.addr = kzalloc(64 * 1024, GFP_KERNEL); |
1da177e4 LT |
541 | if (info->pixmap.addr == NULL) { |
542 | ERR_MSG("Cannot reserve pixmap memory.\n"); | |
543 | goto err_out_pixmap; | |
544 | } | |
1da177e4 LT |
545 | |
546 | /* set early this option because it could be changed by tv encoder | |
547 | driver */ | |
548 | dinfo->fixed_mode = fixed; | |
549 | ||
550 | /* Enable device. */ | |
551 | if ((err = pci_enable_device(pdev))) { | |
552 | ERR_MSG("Cannot enable device.\n"); | |
553 | cleanup(dinfo); | |
554 | return -ENODEV; | |
555 | } | |
556 | ||
557 | /* Set base addresses. */ | |
3a59026b | 558 | if ((ent->device == PCI_DEVICE_ID_INTEL_915G) || |
9639d5ec | 559 | (ent->device == PCI_DEVICE_ID_INTEL_915GM) || |
9a90603f | 560 | (ent->device == PCI_DEVICE_ID_INTEL_945G) || |
0e170c72 | 561 | (ent->device == PCI_DEVICE_ID_INTEL_945GM) || |
3f7a26b4 | 562 | (ent->device == PCI_DEVICE_ID_INTEL_945GME) || |
0e170c72 MB |
563 | (ent->device == PCI_DEVICE_ID_INTEL_965G) || |
564 | (ent->device == PCI_DEVICE_ID_INTEL_965GM)) { | |
565 | ||
1da177e4 LT |
566 | aperture_bar = 2; |
567 | mmio_bar = 0; | |
1da177e4 LT |
568 | } |
569 | dinfo->aperture.physical = pci_resource_start(pdev, aperture_bar); | |
570 | dinfo->aperture.size = pci_resource_len(pdev, aperture_bar); | |
571 | dinfo->mmio_base_phys = pci_resource_start(pdev, mmio_bar); | |
572 | DBG_MSG("fb aperture: 0x%llx/0x%llx, MMIO region: 0x%llx/0x%llx\n", | |
573 | (unsigned long long)pci_resource_start(pdev, aperture_bar), | |
574 | (unsigned long long)pci_resource_len(pdev, aperture_bar), | |
575 | (unsigned long long)pci_resource_start(pdev, mmio_bar), | |
576 | (unsigned long long)pci_resource_len(pdev, mmio_bar)); | |
577 | ||
578 | /* Reserve the fb and MMIO regions */ | |
579 | if (!request_mem_region(dinfo->aperture.physical, dinfo->aperture.size, | |
580 | INTELFB_MODULE_NAME)) { | |
581 | ERR_MSG("Cannot reserve FB region.\n"); | |
582 | cleanup(dinfo); | |
583 | return -ENODEV; | |
584 | } | |
4b3760ce AD |
585 | |
586 | dinfo->flag |= INTELFB_FB_ACQUIRED; | |
587 | ||
1da177e4 LT |
588 | if (!request_mem_region(dinfo->mmio_base_phys, |
589 | INTEL_REG_SIZE, | |
590 | INTELFB_MODULE_NAME)) { | |
591 | ERR_MSG("Cannot reserve MMIO region.\n"); | |
592 | cleanup(dinfo); | |
593 | return -ENODEV; | |
594 | } | |
595 | ||
4b3760ce AD |
596 | dinfo->flag |= INTELFB_MMIO_ACQUIRED; |
597 | ||
1da177e4 LT |
598 | /* Get the chipset info. */ |
599 | dinfo->pci_chipset = pdev->device; | |
600 | ||
d024960c | 601 | if (intelfbhw_get_chipset(pdev, dinfo)) { |
1da177e4 LT |
602 | cleanup(dinfo); |
603 | return -ENODEV; | |
604 | } | |
605 | ||
606 | if (intelfbhw_get_memory(pdev, &aperture_size,&stolen_size)) { | |
607 | cleanup(dinfo); | |
608 | return -ENODEV; | |
609 | } | |
610 | ||
611 | INF_MSG("%02x:%02x.%d: %s, aperture size %dMB, " | |
612 | "stolen memory %dkB\n", | |
613 | pdev->bus->number, PCI_SLOT(pdev->devfn), | |
614 | PCI_FUNC(pdev->devfn), dinfo->name, | |
615 | BtoMB(aperture_size), BtoKB(stolen_size)); | |
616 | ||
617 | /* Set these from the options. */ | |
618 | dinfo->accel = accel; | |
619 | dinfo->hwcursor = hwcursor; | |
620 | ||
621 | if (NOACCEL_CHIPSET(dinfo) && dinfo->accel == 1) { | |
622 | INF_MSG("Acceleration is not supported for the %s chipset.\n", | |
623 | dinfo->name); | |
624 | dinfo->accel = 0; | |
625 | } | |
626 | ||
627 | /* Framebuffer parameters - Use all the stolen memory if >= vram */ | |
375726d7 | 628 | if (ROUND_UP_TO_PAGE(stolen_size) >= MB(vram)) { |
1da177e4 LT |
629 | dinfo->fb.size = ROUND_UP_TO_PAGE(stolen_size); |
630 | dinfo->fbmem_gart = 0; | |
631 | } else { | |
632 | dinfo->fb.size = MB(vram); | |
633 | dinfo->fbmem_gart = 1; | |
634 | } | |
635 | ||
636 | /* Allocate space for the ring buffer and HW cursor if enabled. */ | |
637 | if (dinfo->accel) { | |
638 | dinfo->ring.size = RINGBUFFER_SIZE; | |
639 | dinfo->ring_tail_mask = dinfo->ring.size - 1; | |
640 | } | |
689c9568 | 641 | if (dinfo->hwcursor) |
1da177e4 | 642 | dinfo->cursor.size = HW_CURSOR_SIZE; |
1da177e4 LT |
643 | |
644 | /* Use agpgart to manage the GATT */ | |
645 | if (!(bridge = agp_backend_acquire(pdev))) { | |
646 | ERR_MSG("cannot acquire agp\n"); | |
647 | cleanup(dinfo); | |
648 | return -ENODEV; | |
649 | } | |
650 | ||
651 | /* get the current gatt info */ | |
652 | if (agp_copy_info(bridge, >t_info)) { | |
653 | ERR_MSG("cannot get agp info\n"); | |
654 | agp_backend_release(bridge); | |
655 | cleanup(dinfo); | |
656 | return -ENODEV; | |
657 | } | |
658 | ||
375726d7 AD |
659 | if (MB(voffset) < stolen_size) |
660 | offset = (stolen_size >> 12); | |
661 | else | |
662 | offset = ROUND_UP_TO_PAGE(MB(voffset))/GTT_PAGE_SIZE; | |
663 | ||
1da177e4 | 664 | /* set the mem offsets - set them after the already used pages */ |
689c9568 | 665 | if (dinfo->accel) |
27aef2d4 | 666 | dinfo->ring.offset = offset + gtt_info.current_memory; |
689c9568 | 667 | if (dinfo->hwcursor) |
27aef2d4 | 668 | dinfo->cursor.offset = offset + |
1da177e4 | 669 | + gtt_info.current_memory + (dinfo->ring.size >> 12); |
689c9568 | 670 | if (dinfo->fbmem_gart) |
27aef2d4 | 671 | dinfo->fb.offset = offset + |
1da177e4 LT |
672 | + gtt_info.current_memory + (dinfo->ring.size >> 12) |
673 | + (dinfo->cursor.size >> 12); | |
1da177e4 | 674 | |
375726d7 | 675 | /* Allocate memories (which aren't stolen) */ |
6bd49341 SM |
676 | /* Map the fb and MMIO regions */ |
677 | /* ioremap only up to the end of used aperture */ | |
678 | dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache | |
375726d7 | 679 | (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12) |
6bd49341 SM |
680 | + dinfo->fb.size); |
681 | if (!dinfo->aperture.virtual) { | |
682 | ERR_MSG("Cannot remap FB region.\n"); | |
701d707c | 683 | agp_backend_release(bridge); |
6bd49341 SM |
684 | cleanup(dinfo); |
685 | return -ENODEV; | |
686 | } | |
687 | ||
688 | dinfo->mmio_base = | |
689 | (u8 __iomem *)ioremap_nocache(dinfo->mmio_base_phys, | |
689c9568 | 690 | INTEL_REG_SIZE); |
6bd49341 SM |
691 | if (!dinfo->mmio_base) { |
692 | ERR_MSG("Cannot remap MMIO region.\n"); | |
701d707c | 693 | agp_backend_release(bridge); |
6bd49341 SM |
694 | cleanup(dinfo); |
695 | return -ENODEV; | |
696 | } | |
697 | ||
1da177e4 LT |
698 | if (dinfo->accel) { |
699 | if (!(dinfo->gtt_ring_mem = | |
700 | agp_allocate_memory(bridge, dinfo->ring.size >> 12, | |
701 | AGP_NORMAL_MEMORY))) { | |
702 | ERR_MSG("cannot allocate ring buffer memory\n"); | |
703 | agp_backend_release(bridge); | |
704 | cleanup(dinfo); | |
705 | return -ENOMEM; | |
706 | } | |
707 | if (agp_bind_memory(dinfo->gtt_ring_mem, | |
708 | dinfo->ring.offset)) { | |
709 | ERR_MSG("cannot bind ring buffer memory\n"); | |
710 | agp_backend_release(bridge); | |
711 | cleanup(dinfo); | |
712 | return -EBUSY; | |
713 | } | |
714 | dinfo->ring.physical = dinfo->aperture.physical | |
715 | + (dinfo->ring.offset << 12); | |
716 | dinfo->ring.virtual = dinfo->aperture.virtual | |
717 | + (dinfo->ring.offset << 12); | |
0fe6e2d2 | 718 | dinfo->ring_head = 0; |
1da177e4 LT |
719 | } |
720 | if (dinfo->hwcursor) { | |
721 | agp_memtype = dinfo->mobile ? AGP_PHYSICAL_MEMORY | |
722 | : AGP_NORMAL_MEMORY; | |
723 | if (!(dinfo->gtt_cursor_mem = | |
724 | agp_allocate_memory(bridge, dinfo->cursor.size >> 12, | |
725 | agp_memtype))) { | |
726 | ERR_MSG("cannot allocate cursor memory\n"); | |
727 | agp_backend_release(bridge); | |
728 | cleanup(dinfo); | |
729 | return -ENOMEM; | |
730 | } | |
731 | if (agp_bind_memory(dinfo->gtt_cursor_mem, | |
732 | dinfo->cursor.offset)) { | |
733 | ERR_MSG("cannot bind cursor memory\n"); | |
734 | agp_backend_release(bridge); | |
735 | cleanup(dinfo); | |
736 | return -EBUSY; | |
737 | } | |
738 | if (dinfo->mobile) | |
739 | dinfo->cursor.physical | |
740 | = dinfo->gtt_cursor_mem->physical; | |
741 | else | |
742 | dinfo->cursor.physical = dinfo->aperture.physical | |
743 | + (dinfo->cursor.offset << 12); | |
744 | dinfo->cursor.virtual = dinfo->aperture.virtual | |
745 | + (dinfo->cursor.offset << 12); | |
746 | } | |
747 | if (dinfo->fbmem_gart) { | |
748 | if (!(dinfo->gtt_fb_mem = | |
749 | agp_allocate_memory(bridge, dinfo->fb.size >> 12, | |
750 | AGP_NORMAL_MEMORY))) { | |
751 | WRN_MSG("cannot allocate framebuffer memory - use " | |
752 | "the stolen one\n"); | |
753 | dinfo->fbmem_gart = 0; | |
754 | } | |
755 | if (agp_bind_memory(dinfo->gtt_fb_mem, | |
756 | dinfo->fb.offset)) { | |
757 | WRN_MSG("cannot bind framebuffer memory - use " | |
758 | "the stolen one\n"); | |
759 | dinfo->fbmem_gart = 0; | |
760 | } | |
761 | } | |
762 | ||
763 | /* update framebuffer memory parameters */ | |
764 | if (!dinfo->fbmem_gart) | |
765 | dinfo->fb.offset = 0; /* starts at offset 0 */ | |
766 | dinfo->fb.physical = dinfo->aperture.physical | |
767 | + (dinfo->fb.offset << 12); | |
768 | dinfo->fb.virtual = dinfo->aperture.virtual + (dinfo->fb.offset << 12); | |
769 | dinfo->fb_start = dinfo->fb.offset << 12; | |
770 | ||
771 | /* release agpgart */ | |
772 | agp_backend_release(bridge); | |
773 | ||
774 | if (mtrr) | |
775 | set_mtrr(dinfo); | |
776 | ||
0fe6e2d2 | 777 | DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n", |
1da177e4 | 778 | dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size, |
0fe6e2d2 AV |
779 | dinfo->fb.virtual); |
780 | DBG_MSG("MMIO: 0x%x/0x%x (0x%p)\n", | |
1da177e4 | 781 | dinfo->mmio_base_phys, INTEL_REG_SIZE, |
0fe6e2d2 AV |
782 | dinfo->mmio_base); |
783 | DBG_MSG("ring buffer: 0x%x/0x%x (0x%p)\n", | |
1da177e4 | 784 | dinfo->ring.physical, dinfo->ring.size, |
0fe6e2d2 AV |
785 | dinfo->ring.virtual); |
786 | DBG_MSG("HW cursor: 0x%x/0x%x (0x%p) (offset 0x%x) (phys 0x%x)\n", | |
1da177e4 | 787 | dinfo->cursor.physical, dinfo->cursor.size, |
0fe6e2d2 | 788 | dinfo->cursor.virtual, dinfo->cursor.offset, |
1da177e4 LT |
789 | dinfo->cursor.physical); |
790 | ||
791 | DBG_MSG("options: vram = %d, accel = %d, hwcursor = %d, fixed = %d, " | |
792 | "noinit = %d\n", vram, accel, hwcursor, fixed, noinit); | |
793 | DBG_MSG("options: mode = \"%s\"\n", mode ? mode : ""); | |
794 | ||
795 | if (probeonly) | |
796 | bailout(dinfo); | |
797 | ||
798 | /* | |
799 | * Check if the LVDS port or any DVO ports are enabled. If so, | |
800 | * don't allow mode switching | |
801 | */ | |
802 | dvo = intelfbhw_check_non_crt(dinfo); | |
803 | if (dvo) { | |
804 | dinfo->fixed_mode = 1; | |
805 | WRN_MSG("Non-CRT device is enabled ( "); | |
806 | i = 0; | |
807 | while (dvo) { | |
808 | if (dvo & 1) { | |
809 | s = intelfbhw_dvo_to_string(1 << i); | |
810 | if (s) | |
811 | printk("%s ", s); | |
812 | } | |
813 | dvo >>= 1; | |
814 | ++i; | |
815 | } | |
816 | printk("). Disabling mode switching.\n"); | |
817 | } | |
818 | ||
819 | if (bailearly == 1) | |
820 | bailout(dinfo); | |
821 | ||
3ea33510 PA |
822 | if (FIXED_MODE(dinfo) && |
823 | screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) { | |
1da177e4 LT |
824 | ERR_MSG("Video mode must be programmed at boot time.\n"); |
825 | cleanup(dinfo); | |
826 | return -ENODEV; | |
827 | } | |
828 | ||
829 | if (bailearly == 2) | |
830 | bailout(dinfo); | |
831 | ||
832 | /* Initialise dinfo and related data. */ | |
833 | /* If an initial mode was programmed at boot time, get its details. */ | |
3ea33510 | 834 | if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB) |
1da177e4 LT |
835 | get_initial_mode(dinfo); |
836 | ||
837 | if (bailearly == 3) | |
838 | bailout(dinfo); | |
839 | ||
689c9568 | 840 | if (FIXED_MODE(dinfo)) /* remap fb address */ |
1da177e4 | 841 | update_dinfo(dinfo, &dinfo->initial_var); |
1da177e4 LT |
842 | |
843 | if (bailearly == 4) | |
844 | bailout(dinfo); | |
845 | ||
846 | ||
847 | if (intelfb_set_fbinfo(dinfo)) { | |
848 | cleanup(dinfo); | |
849 | return -ENODEV; | |
850 | } | |
851 | ||
852 | if (bailearly == 5) | |
853 | bailout(dinfo); | |
854 | ||
41c9480a DM |
855 | #ifdef CONFIG_FB_INTEL_I2C |
856 | /* register I2C bus */ | |
857 | intelfb_create_i2c_busses(dinfo); | |
858 | #endif | |
859 | ||
1da177e4 LT |
860 | if (bailearly == 6) |
861 | bailout(dinfo); | |
862 | ||
863 | pci_set_drvdata(pdev, dinfo); | |
864 | ||
865 | /* Save the initial register state. */ | |
866 | i = intelfbhw_read_hw_state(dinfo, &dinfo->save_state, | |
867 | bailearly > 6 ? bailearly - 6 : 0); | |
868 | if (i != 0) { | |
869 | DBG_MSG("intelfbhw_read_hw_state returned %d\n", i); | |
870 | bailout(dinfo); | |
871 | } | |
872 | ||
873 | intelfbhw_print_hw_state(dinfo, &dinfo->save_state); | |
874 | ||
875 | if (bailearly == 18) | |
876 | bailout(dinfo); | |
877 | ||
cfbd646f KH |
878 | /* read active pipe */ |
879 | dinfo->pipe = intelfbhw_active_pipe(&dinfo->save_state); | |
880 | ||
1da177e4 LT |
881 | /* Cursor initialisation */ |
882 | if (dinfo->hwcursor) { | |
883 | intelfbhw_cursor_init(dinfo); | |
884 | intelfbhw_cursor_reset(dinfo); | |
885 | } | |
886 | ||
887 | if (bailearly == 19) | |
888 | bailout(dinfo); | |
889 | ||
890 | /* 2d acceleration init */ | |
891 | if (dinfo->accel) | |
892 | intelfbhw_2d_start(dinfo); | |
893 | ||
894 | if (bailearly == 20) | |
895 | bailout(dinfo); | |
896 | ||
897 | if (noregister) | |
898 | bailout(dinfo); | |
899 | ||
900 | if (register_framebuffer(dinfo->info) < 0) { | |
901 | ERR_MSG("Cannot register framebuffer.\n"); | |
902 | cleanup(dinfo); | |
903 | return -ENODEV; | |
904 | } | |
905 | ||
906 | dinfo->registered = 1; | |
7649757b EH |
907 | dinfo->open = 0; |
908 | ||
909 | init_waitqueue_head(&dinfo->vsync.wait); | |
910 | spin_lock_init(&dinfo->int_lock); | |
911 | dinfo->irq_flags = 0; | |
f80d0d23 EH |
912 | dinfo->vsync.pan_display = 0; |
913 | dinfo->vsync.pan_offset = 0; | |
1da177e4 LT |
914 | |
915 | return 0; | |
916 | ||
917 | err_out_pixmap: | |
918 | fb_dealloc_cmap(&info->cmap); | |
919 | err_out_cmap: | |
920 | framebuffer_release(info); | |
921 | return -ENODEV; | |
922 | } | |
923 | ||
924 | static void __devexit | |
925 | intelfb_pci_unregister(struct pci_dev *pdev) | |
926 | { | |
927 | struct intelfb_info *dinfo = pci_get_drvdata(pdev); | |
928 | ||
929 | DBG_MSG("intelfb_pci_unregister\n"); | |
930 | ||
931 | if (!dinfo) | |
932 | return; | |
933 | ||
934 | cleanup(dinfo); | |
935 | ||
936 | pci_set_drvdata(pdev, NULL); | |
937 | } | |
938 | ||
939 | /*************************************************************** | |
940 | * helper functions * | |
941 | ***************************************************************/ | |
942 | ||
689c9568 | 943 | int __inline__ intelfb_var_to_depth(const struct fb_var_screeninfo *var) |
1da177e4 LT |
944 | { |
945 | DBG_MSG("intelfb_var_to_depth: bpp: %d, green.length is %d\n", | |
946 | var->bits_per_pixel, var->green.length); | |
947 | ||
948 | switch (var->bits_per_pixel) { | |
949 | case 16: | |
950 | return (var->green.length == 6) ? 16 : 15; | |
951 | case 32: | |
952 | return 24; | |
953 | default: | |
954 | return var->bits_per_pixel; | |
955 | } | |
956 | } | |
957 | ||
958 | ||
689c9568 | 959 | static __inline__ int var_to_refresh(const struct fb_var_screeninfo *var) |
1da177e4 LT |
960 | { |
961 | int xtot = var->xres + var->left_margin + var->right_margin + | |
962 | var->hsync_len; | |
963 | int ytot = var->yres + var->upper_margin + var->lower_margin + | |
964 | var->vsync_len; | |
965 | ||
966 | return (1000000000 / var->pixclock * 1000 + 500) / xtot / ytot; | |
967 | } | |
968 | ||
969 | /*************************************************************** | |
970 | * Various intialisation functions * | |
971 | ***************************************************************/ | |
972 | ||
689c9568 | 973 | static void __devinit get_initial_mode(struct intelfb_info *dinfo) |
1da177e4 LT |
974 | { |
975 | struct fb_var_screeninfo *var; | |
976 | int xtot, ytot; | |
977 | ||
978 | DBG_MSG("get_initial_mode\n"); | |
979 | ||
980 | dinfo->initial_vga = 1; | |
981 | dinfo->initial_fb_base = screen_info.lfb_base; | |
982 | dinfo->initial_video_ram = screen_info.lfb_size * KB(64); | |
983 | dinfo->initial_pitch = screen_info.lfb_linelength; | |
984 | ||
985 | var = &dinfo->initial_var; | |
986 | memset(var, 0, sizeof(*var)); | |
987 | var->xres = screen_info.lfb_width; | |
988 | var->yres = screen_info.lfb_height; | |
989 | var->bits_per_pixel = screen_info.lfb_depth; | |
990 | switch (screen_info.lfb_depth) { | |
991 | case 15: | |
992 | var->bits_per_pixel = 16; | |
993 | break; | |
994 | case 24: | |
995 | var->bits_per_pixel = 32; | |
996 | break; | |
997 | } | |
998 | ||
999 | DBG_MSG("Initial info: FB is 0x%x/0x%x (%d kByte)\n", | |
1000 | dinfo->initial_fb_base, dinfo->initial_video_ram, | |
1001 | BtoKB(dinfo->initial_video_ram)); | |
1002 | ||
1003 | DBG_MSG("Initial info: mode is %dx%d-%d (%d)\n", | |
1004 | var->xres, var->yres, var->bits_per_pixel, | |
1005 | dinfo->initial_pitch); | |
1006 | ||
1007 | /* Dummy timing values (assume 60Hz) */ | |
1008 | var->left_margin = (var->xres / 8) & 0xf8; | |
1009 | var->right_margin = 32; | |
1010 | var->upper_margin = 16; | |
1011 | var->lower_margin = 4; | |
1012 | var->hsync_len = (var->xres / 8) & 0xf8; | |
1013 | var->vsync_len = 4; | |
1014 | ||
1015 | xtot = var->xres + var->left_margin + | |
1016 | var->right_margin + var->hsync_len; | |
1017 | ytot = var->yres + var->upper_margin + | |
1018 | var->lower_margin + var->vsync_len; | |
1019 | var->pixclock = 10000000 / xtot * 1000 / ytot * 100 / 60; | |
1020 | ||
1021 | var->height = -1; | |
1022 | var->width = -1; | |
1023 | ||
1024 | if (var->bits_per_pixel > 8) { | |
1025 | var->red.offset = screen_info.red_pos; | |
1026 | var->red.length = screen_info.red_size; | |
1027 | var->green.offset = screen_info.green_pos; | |
1028 | var->green.length = screen_info.green_size; | |
1029 | var->blue.offset = screen_info.blue_pos; | |
1030 | var->blue.length = screen_info.blue_size; | |
1031 | var->transp.offset = screen_info.rsvd_pos; | |
1032 | var->transp.length = screen_info.rsvd_size; | |
1033 | } else { | |
1034 | var->red.length = 8; | |
1035 | var->green.length = 8; | |
1036 | var->blue.length = 8; | |
1037 | } | |
1038 | } | |
1039 | ||
689c9568 | 1040 | static int __devinit intelfb_init_var(struct intelfb_info *dinfo) |
1da177e4 LT |
1041 | { |
1042 | struct fb_var_screeninfo *var; | |
1043 | int msrc = 0; | |
1044 | ||
1045 | DBG_MSG("intelfb_init_var\n"); | |
1046 | ||
1047 | var = &dinfo->info->var; | |
1048 | if (FIXED_MODE(dinfo)) { | |
1049 | memcpy(var, &dinfo->initial_var, | |
1050 | sizeof(struct fb_var_screeninfo)); | |
1051 | msrc = 5; | |
1052 | } else { | |
56e004e5 AD |
1053 | const u8 *edid_s = fb_firmware_edid(&dinfo->pdev->dev); |
1054 | u8 *edid_d = NULL; | |
1055 | ||
1056 | if (edid_s) { | |
bfba7b37 | 1057 | edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL); |
56e004e5 AD |
1058 | |
1059 | if (edid_d) { | |
56e004e5 AD |
1060 | fb_edid_to_monspecs(edid_d, |
1061 | &dinfo->info->monspecs); | |
1062 | kfree(edid_d); | |
1063 | } | |
1064 | } | |
1065 | ||
1da177e4 | 1066 | if (mode) { |
56e004e5 AD |
1067 | printk("intelfb: Looking for mode in private " |
1068 | "database\n"); | |
1da177e4 | 1069 | msrc = fb_find_mode(var, dinfo->info, mode, |
56e004e5 AD |
1070 | dinfo->info->monspecs.modedb, |
1071 | dinfo->info->monspecs.modedb_len, | |
080a4168 | 1072 | NULL, 0); |
56e004e5 AD |
1073 | |
1074 | if (msrc && msrc > 1) { | |
1075 | printk("intelfb: No mode in private database, " | |
1076 | "intelfb: looking for mode in global " | |
1077 | "database "); | |
1078 | msrc = fb_find_mode(var, dinfo->info, mode, | |
7a532c69 | 1079 | NULL, 0, NULL, 0); |
56e004e5 AD |
1080 | |
1081 | if (msrc) | |
1082 | msrc |= 8; | |
1083 | } | |
1084 | ||
1da177e4 | 1085 | } |
56e004e5 | 1086 | |
689c9568 | 1087 | if (!msrc) |
1da177e4 | 1088 | msrc = fb_find_mode(var, dinfo->info, PREFERRED_MODE, |
7a532c69 | 1089 | NULL, 0, NULL, 0); |
1da177e4 LT |
1090 | } |
1091 | ||
1092 | if (!msrc) { | |
1093 | ERR_MSG("Cannot find a suitable video mode.\n"); | |
1094 | return 1; | |
1095 | } | |
1096 | ||
1097 | INF_MSG("Initial video mode is %dx%d-%d@%d.\n", var->xres, var->yres, | |
1098 | var->bits_per_pixel, var_to_refresh(var)); | |
1099 | ||
1100 | DBG_MSG("Initial video mode is from %d.\n", msrc); | |
1101 | ||
1102 | #if ALLOCATE_FOR_PANNING | |
1103 | /* Allow use of half of the video ram for panning */ | |
1104 | var->xres_virtual = var->xres; | |
1105 | var->yres_virtual = | |
1106 | dinfo->fb.size / 2 / (var->bits_per_pixel * var->xres); | |
1107 | if (var->yres_virtual < var->yres) | |
1108 | var->yres_virtual = var->yres; | |
1109 | #else | |
1110 | var->yres_virtual = var->yres; | |
1111 | #endif | |
1112 | ||
1113 | if (dinfo->accel) | |
1114 | var->accel_flags |= FB_ACCELF_TEXT; | |
1115 | else | |
1116 | var->accel_flags &= ~FB_ACCELF_TEXT; | |
1117 | ||
1118 | return 0; | |
1119 | } | |
1120 | ||
689c9568 | 1121 | static int __devinit intelfb_set_fbinfo(struct intelfb_info *dinfo) |
1da177e4 LT |
1122 | { |
1123 | struct fb_info *info = dinfo->info; | |
1124 | ||
1125 | DBG_MSG("intelfb_set_fbinfo\n"); | |
1126 | ||
1127 | info->flags = FBINFO_FLAG_DEFAULT; | |
1128 | info->fbops = &intel_fb_ops; | |
1129 | info->pseudo_palette = dinfo->pseudo_palette; | |
1130 | ||
1131 | info->pixmap.size = 64*1024; | |
1132 | info->pixmap.buf_align = 8; | |
58a60643 | 1133 | info->pixmap.access_align = 32; |
1da177e4 LT |
1134 | info->pixmap.flags = FB_PIXMAP_SYSTEM; |
1135 | ||
1136 | if (intelfb_init_var(dinfo)) | |
1137 | return 1; | |
1138 | ||
1139 | info->pixmap.scan_align = 1; | |
33c37c06 AD |
1140 | strcpy(info->fix.id, dinfo->name); |
1141 | info->fix.smem_start = dinfo->fb.physical; | |
1142 | info->fix.smem_len = dinfo->fb.size; | |
1143 | info->fix.type = FB_TYPE_PACKED_PIXELS; | |
1144 | info->fix.type_aux = 0; | |
1145 | info->fix.xpanstep = 8; | |
1146 | info->fix.ypanstep = 1; | |
1147 | info->fix.ywrapstep = 0; | |
1148 | info->fix.mmio_start = dinfo->mmio_base_phys; | |
1149 | info->fix.mmio_len = INTEL_REG_SIZE; | |
1150 | info->fix.accel = FB_ACCEL_I830; | |
1da177e4 LT |
1151 | update_dinfo(dinfo, &info->var); |
1152 | ||
1153 | return 0; | |
1154 | } | |
1155 | ||
1156 | /* Update dinfo to match the active video mode. */ | |
689c9568 KH |
1157 | static void update_dinfo(struct intelfb_info *dinfo, |
1158 | struct fb_var_screeninfo *var) | |
1da177e4 LT |
1159 | { |
1160 | DBG_MSG("update_dinfo\n"); | |
1161 | ||
1162 | dinfo->bpp = var->bits_per_pixel; | |
1163 | dinfo->depth = intelfb_var_to_depth(var); | |
1164 | dinfo->xres = var->xres; | |
1165 | dinfo->yres = var->xres; | |
1166 | dinfo->pixclock = var->pixclock; | |
1167 | ||
33c37c06 AD |
1168 | dinfo->info->fix.visual = dinfo->visual; |
1169 | dinfo->info->fix.line_length = dinfo->pitch; | |
1da177e4 LT |
1170 | |
1171 | switch (dinfo->bpp) { | |
1172 | case 8: | |
1173 | dinfo->visual = FB_VISUAL_PSEUDOCOLOR; | |
1174 | dinfo->pitch = var->xres_virtual; | |
1175 | break; | |
1176 | case 16: | |
1177 | dinfo->visual = FB_VISUAL_TRUECOLOR; | |
1178 | dinfo->pitch = var->xres_virtual * 2; | |
1179 | break; | |
1180 | case 32: | |
1181 | dinfo->visual = FB_VISUAL_TRUECOLOR; | |
1182 | dinfo->pitch = var->xres_virtual * 4; | |
1183 | break; | |
1184 | } | |
1185 | ||
1186 | /* Make sure the line length is a aligned correctly. */ | |
df7df8ab DM |
1187 | if (IS_I9XX(dinfo)) |
1188 | dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT_I9XX); | |
1189 | else | |
1190 | dinfo->pitch = ROUND_UP_TO(dinfo->pitch, STRIDE_ALIGNMENT); | |
1da177e4 LT |
1191 | |
1192 | if (FIXED_MODE(dinfo)) | |
1193 | dinfo->pitch = dinfo->initial_pitch; | |
1194 | ||
1195 | dinfo->info->screen_base = (char __iomem *)dinfo->fb.virtual; | |
1196 | dinfo->info->fix.line_length = dinfo->pitch; | |
1197 | dinfo->info->fix.visual = dinfo->visual; | |
1198 | } | |
1199 | ||
1200 | /* fbops functions */ | |
1201 | ||
1da177e4 LT |
1202 | /*************************************************************** |
1203 | * fbdev interface * | |
1204 | ***************************************************************/ | |
1205 | ||
689c9568 | 1206 | static int intelfb_open(struct fb_info *info, int user) |
7649757b EH |
1207 | { |
1208 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1209 | ||
689c9568 | 1210 | if (user) |
7649757b | 1211 | dinfo->open++; |
7649757b EH |
1212 | |
1213 | return 0; | |
1214 | } | |
1215 | ||
689c9568 | 1216 | static int intelfb_release(struct fb_info *info, int user) |
7649757b EH |
1217 | { |
1218 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1219 | ||
1220 | if (user) { | |
1221 | dinfo->open--; | |
1222 | msleep(1); | |
689c9568 | 1223 | if (!dinfo->open) |
7649757b | 1224 | intelfbhw_disable_irq(dinfo); |
7649757b EH |
1225 | } |
1226 | ||
1227 | return 0; | |
1228 | } | |
1229 | ||
689c9568 KH |
1230 | static int intelfb_check_var(struct fb_var_screeninfo *var, |
1231 | struct fb_info *info) | |
1da177e4 LT |
1232 | { |
1233 | int change_var = 0; | |
1234 | struct fb_var_screeninfo v; | |
1235 | struct intelfb_info *dinfo; | |
1236 | static int first = 1; | |
3587c509 DA |
1237 | int i; |
1238 | /* Good pitches to allow tiling. Don't care about pitches < 1024. */ | |
1239 | static const int pitches[] = { | |
1240 | 128 * 8, | |
1241 | 128 * 16, | |
1242 | 128 * 32, | |
1243 | 128 * 64, | |
1244 | 0 | |
1245 | }; | |
1da177e4 LT |
1246 | |
1247 | DBG_MSG("intelfb_check_var: accel_flags is %d\n", var->accel_flags); | |
1248 | ||
1249 | dinfo = GET_DINFO(info); | |
1250 | ||
3587c509 | 1251 | /* update the pitch */ |
1da177e4 LT |
1252 | if (intelfbhw_validate_mode(dinfo, var) != 0) |
1253 | return -EINVAL; | |
1254 | ||
1255 | v = *var; | |
1256 | ||
3587c509 DA |
1257 | for (i = 0; pitches[i] != 0; i++) { |
1258 | if (pitches[i] >= v.xres_virtual) { | |
1259 | v.xres_virtual = pitches[i]; | |
1260 | break; | |
1261 | } | |
1262 | } | |
1263 | ||
1da177e4 | 1264 | /* Check for a supported bpp. */ |
689c9568 | 1265 | if (v.bits_per_pixel <= 8) |
1da177e4 | 1266 | v.bits_per_pixel = 8; |
689c9568 | 1267 | else if (v.bits_per_pixel <= 16) { |
1da177e4 LT |
1268 | if (v.bits_per_pixel == 16) |
1269 | v.green.length = 6; | |
1270 | v.bits_per_pixel = 16; | |
689c9568 | 1271 | } else if (v.bits_per_pixel <= 32) |
1da177e4 | 1272 | v.bits_per_pixel = 32; |
689c9568 | 1273 | else |
1da177e4 LT |
1274 | return -EINVAL; |
1275 | ||
1276 | change_var = ((info->var.xres != var->xres) || | |
1277 | (info->var.yres != var->yres) || | |
1278 | (info->var.xres_virtual != var->xres_virtual) || | |
1279 | (info->var.yres_virtual != var->yres_virtual) || | |
1280 | (info->var.bits_per_pixel != var->bits_per_pixel) || | |
1281 | memcmp(&info->var.red, &var->red, sizeof(var->red)) || | |
1282 | memcmp(&info->var.green, &var->green, | |
1283 | sizeof(var->green)) || | |
1284 | memcmp(&info->var.blue, &var->blue, sizeof(var->blue))); | |
1285 | ||
1286 | if (FIXED_MODE(dinfo) && | |
1287 | (change_var || | |
1288 | var->yres_virtual > dinfo->initial_var.yres_virtual || | |
1289 | var->yres_virtual < dinfo->initial_var.yres || | |
1290 | var->xoffset || var->nonstd)) { | |
1291 | if (first) { | |
1292 | ERR_MSG("Changing the video mode is not supported.\n"); | |
1293 | first = 0; | |
1294 | } | |
1295 | return -EINVAL; | |
1296 | } | |
1297 | ||
1298 | switch (intelfb_var_to_depth(&v)) { | |
1299 | case 8: | |
1300 | v.red.offset = v.green.offset = v.blue.offset = 0; | |
1301 | v.red.length = v.green.length = v.blue.length = 8; | |
1302 | v.transp.offset = v.transp.length = 0; | |
1303 | break; | |
1304 | case 15: | |
1305 | v.red.offset = 10; | |
1306 | v.green.offset = 5; | |
1307 | v.blue.offset = 0; | |
1308 | v.red.length = v.green.length = v.blue.length = 5; | |
1309 | v.transp.offset = v.transp.length = 0; | |
1310 | break; | |
1311 | case 16: | |
1312 | v.red.offset = 11; | |
1313 | v.green.offset = 5; | |
1314 | v.blue.offset = 0; | |
1315 | v.red.length = 5; | |
1316 | v.green.length = 6; | |
1317 | v.blue.length = 5; | |
1318 | v.transp.offset = v.transp.length = 0; | |
1319 | break; | |
1320 | case 24: | |
1321 | v.red.offset = 16; | |
1322 | v.green.offset = 8; | |
1323 | v.blue.offset = 0; | |
1324 | v.red.length = v.green.length = v.blue.length = 8; | |
1325 | v.transp.offset = v.transp.length = 0; | |
1326 | break; | |
1327 | case 32: | |
1328 | v.red.offset = 16; | |
1329 | v.green.offset = 8; | |
1330 | v.blue.offset = 0; | |
1331 | v.red.length = v.green.length = v.blue.length = 8; | |
1332 | v.transp.offset = 24; | |
1333 | v.transp.length = 8; | |
1334 | break; | |
1335 | } | |
1336 | ||
1337 | if (v.xoffset < 0) | |
1338 | v.xoffset = 0; | |
1339 | if (v.yoffset < 0) | |
1340 | v.yoffset = 0; | |
1341 | ||
1342 | if (v.xoffset > v.xres_virtual - v.xres) | |
1343 | v.xoffset = v.xres_virtual - v.xres; | |
1344 | if (v.yoffset > v.yres_virtual - v.yres) | |
1345 | v.yoffset = v.yres_virtual - v.yres; | |
1346 | ||
1347 | v.red.msb_right = v.green.msb_right = v.blue.msb_right = | |
1348 | v.transp.msb_right = 0; | |
1349 | ||
1350 | *var = v; | |
1351 | ||
1352 | return 0; | |
1353 | } | |
1354 | ||
689c9568 | 1355 | static int intelfb_set_par(struct fb_info *info) |
1da177e4 | 1356 | { |
689c9568 | 1357 | struct intelfb_hwstate *hw; |
1da177e4 LT |
1358 | struct intelfb_info *dinfo = GET_DINFO(info); |
1359 | ||
1360 | if (FIXED_MODE(dinfo)) { | |
1361 | ERR_MSG("Changing the video mode is not supported.\n"); | |
1362 | return -EINVAL; | |
1363 | } | |
1364 | ||
689c9568 KH |
1365 | hw = kmalloc(sizeof(*hw), GFP_ATOMIC); |
1366 | if (!hw) | |
1367 | return -ENOMEM; | |
1da177e4 LT |
1368 | |
1369 | DBG_MSG("intelfb_set_par (%dx%d-%d)\n", info->var.xres, | |
1370 | info->var.yres, info->var.bits_per_pixel); | |
1371 | ||
b5866401 PM |
1372 | /* |
1373 | * Disable VCO prior to timing register change. | |
1374 | */ | |
1375 | OUTREG(DPLL_A, INREG(DPLL_A) & ~DPLL_VCO_ENABLE); | |
1376 | ||
1da177e4 LT |
1377 | intelfb_blank(FB_BLANK_POWERDOWN, info); |
1378 | ||
df529338 | 1379 | if (ACCEL(dinfo, info)) |
1da177e4 LT |
1380 | intelfbhw_2d_stop(dinfo); |
1381 | ||
689c9568 KH |
1382 | memcpy(hw, &dinfo->save_state, sizeof(*hw)); |
1383 | if (intelfbhw_mode_to_hw(dinfo, hw, &info->var)) | |
1384 | goto invalid_mode; | |
1385 | if (intelfbhw_program_mode(dinfo, hw, 0)) | |
1386 | goto invalid_mode; | |
1da177e4 LT |
1387 | |
1388 | #if REGDUMP > 0 | |
689c9568 KH |
1389 | intelfbhw_read_hw_state(dinfo, hw, 0); |
1390 | intelfbhw_print_hw_state(dinfo, hw); | |
1da177e4 LT |
1391 | #endif |
1392 | ||
1393 | update_dinfo(dinfo, &info->var); | |
1394 | ||
df529338 | 1395 | if (ACCEL(dinfo, info)) |
1da177e4 LT |
1396 | intelfbhw_2d_start(dinfo); |
1397 | ||
1398 | intelfb_pan_display(&info->var, info); | |
1399 | ||
1400 | intelfb_blank(FB_BLANK_UNBLANK, info); | |
1401 | ||
1402 | if (ACCEL(dinfo, info)) { | |
1403 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | | |
1404 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | | |
1405 | FBINFO_HWACCEL_IMAGEBLIT; | |
689c9568 | 1406 | } else |
1da177e4 | 1407 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
689c9568 | 1408 | |
1da177e4 LT |
1409 | kfree(hw); |
1410 | return 0; | |
1411 | invalid_mode: | |
1412 | kfree(hw); | |
1413 | return -EINVAL; | |
1414 | } | |
1415 | ||
689c9568 KH |
1416 | static int intelfb_setcolreg(unsigned regno, unsigned red, unsigned green, |
1417 | unsigned blue, unsigned transp, | |
1418 | struct fb_info *info) | |
1da177e4 LT |
1419 | { |
1420 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1421 | ||
1422 | #if VERBOSE > 0 | |
1423 | DBG_MSG("intelfb_setcolreg: regno %d, depth %d\n", regno, dinfo->depth); | |
1424 | #endif | |
1425 | ||
1426 | if (regno > 255) | |
1427 | return 1; | |
1428 | ||
d3015247 AD |
1429 | if (dinfo->depth == 8) { |
1430 | red >>= 8; | |
1431 | green >>= 8; | |
1432 | blue >>= 8; | |
1433 | ||
1434 | intelfbhw_setcolreg(dinfo, regno, red, green, blue, | |
1435 | transp); | |
1436 | } | |
1da177e4 | 1437 | |
d3015247 AD |
1438 | if (regno < 16) { |
1439 | switch (dinfo->depth) { | |
1440 | case 15: | |
1441 | dinfo->pseudo_palette[regno] = ((red & 0xf800) >> 1) | | |
1442 | ((green & 0xf800) >> 6) | | |
1443 | ((blue & 0xf800) >> 11); | |
1444 | break; | |
1445 | case 16: | |
1446 | dinfo->pseudo_palette[regno] = (red & 0xf800) | | |
1447 | ((green & 0xfc00) >> 5) | | |
1448 | ((blue & 0xf800) >> 11); | |
1449 | break; | |
1450 | case 24: | |
1451 | dinfo->pseudo_palette[regno] = ((red & 0xff00) << 8) | | |
1452 | (green & 0xff00) | | |
1453 | ((blue & 0xff00) >> 8); | |
1454 | break; | |
1da177e4 | 1455 | } |
1da177e4 | 1456 | } |
d3015247 | 1457 | |
1da177e4 LT |
1458 | return 0; |
1459 | } | |
1460 | ||
689c9568 | 1461 | static int intelfb_blank(int blank, struct fb_info *info) |
1da177e4 LT |
1462 | { |
1463 | intelfbhw_do_blank(blank, info); | |
1464 | return 0; | |
1465 | } | |
1466 | ||
689c9568 KH |
1467 | static int intelfb_pan_display(struct fb_var_screeninfo *var, |
1468 | struct fb_info *info) | |
1da177e4 LT |
1469 | { |
1470 | intelfbhw_pan_display(var, info); | |
1471 | return 0; | |
1472 | } | |
1473 | ||
1474 | /* When/if we have our own ioctls. */ | |
689c9568 KH |
1475 | static int intelfb_ioctl(struct fb_info *info, unsigned int cmd, |
1476 | unsigned long arg) | |
1da177e4 LT |
1477 | { |
1478 | int retval = 0; | |
37bced38 EH |
1479 | struct intelfb_info *dinfo = GET_DINFO(info); |
1480 | u32 pipe = 0; | |
1481 | ||
1482 | switch (cmd) { | |
1483 | case FBIO_WAITFORVSYNC: | |
1484 | if (get_user(pipe, (__u32 __user *)arg)) | |
1485 | return -EFAULT; | |
1486 | ||
1487 | retval = intelfbhw_wait_for_vsync(dinfo, pipe); | |
1488 | break; | |
1489 | default: | |
1490 | break; | |
1491 | } | |
1da177e4 LT |
1492 | |
1493 | return retval; | |
1494 | } | |
1495 | ||
689c9568 KH |
1496 | static void intelfb_fillrect (struct fb_info *info, |
1497 | const struct fb_fillrect *rect) | |
1da177e4 LT |
1498 | { |
1499 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1500 | u32 rop, color; | |
1501 | ||
1502 | #if VERBOSE > 0 | |
1503 | DBG_MSG("intelfb_fillrect\n"); | |
1504 | #endif | |
1505 | ||
fd002050 HE |
1506 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) { |
1507 | cfb_fillrect(info, rect); | |
1508 | return; | |
1509 | } | |
1da177e4 LT |
1510 | |
1511 | if (rect->rop == ROP_COPY) | |
1512 | rop = PAT_ROP_GXCOPY; | |
689c9568 | 1513 | else /* ROP_XOR */ |
1da177e4 LT |
1514 | rop = PAT_ROP_GXXOR; |
1515 | ||
1516 | if (dinfo->depth != 8) | |
1517 | color = dinfo->pseudo_palette[rect->color]; | |
1518 | else | |
1519 | color = rect->color; | |
1520 | ||
1521 | intelfbhw_do_fillrect(dinfo, rect->dx, rect->dy, | |
1522 | rect->width, rect->height, color, | |
1523 | dinfo->pitch, info->var.bits_per_pixel, | |
1524 | rop); | |
1525 | } | |
1526 | ||
689c9568 KH |
1527 | static void intelfb_copyarea(struct fb_info *info, |
1528 | const struct fb_copyarea *region) | |
1da177e4 LT |
1529 | { |
1530 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1531 | ||
1532 | #if VERBOSE > 0 | |
1533 | DBG_MSG("intelfb_copyarea\n"); | |
1534 | #endif | |
1535 | ||
fd002050 HE |
1536 | if (!ACCEL(dinfo, info) || dinfo->depth == 4) { |
1537 | cfb_copyarea(info, region); | |
1538 | return; | |
1539 | } | |
1da177e4 LT |
1540 | |
1541 | intelfbhw_do_bitblt(dinfo, region->sx, region->sy, region->dx, | |
1542 | region->dy, region->width, region->height, | |
1543 | dinfo->pitch, info->var.bits_per_pixel); | |
1544 | } | |
1545 | ||
689c9568 KH |
1546 | static void intelfb_imageblit(struct fb_info *info, |
1547 | const struct fb_image *image) | |
1da177e4 LT |
1548 | { |
1549 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1550 | u32 fgcolor, bgcolor; | |
1551 | ||
1552 | #if VERBOSE > 0 | |
1553 | DBG_MSG("intelfb_imageblit\n"); | |
1554 | #endif | |
1555 | ||
1556 | if (!ACCEL(dinfo, info) || dinfo->depth == 4 | |
fd002050 HE |
1557 | || image->depth != 1) { |
1558 | cfb_imageblit(info, image); | |
1559 | return; | |
1560 | } | |
1da177e4 LT |
1561 | |
1562 | if (dinfo->depth != 8) { | |
1563 | fgcolor = dinfo->pseudo_palette[image->fg_color]; | |
1564 | bgcolor = dinfo->pseudo_palette[image->bg_color]; | |
1565 | } else { | |
1566 | fgcolor = image->fg_color; | |
1567 | bgcolor = image->bg_color; | |
1568 | } | |
1569 | ||
1570 | if (!intelfbhw_do_drawglyph(dinfo, fgcolor, bgcolor, image->width, | |
1571 | image->height, image->data, | |
1572 | image->dx, image->dy, | |
fd002050 HE |
1573 | dinfo->pitch, info->var.bits_per_pixel)) { |
1574 | cfb_imageblit(info, image); | |
1575 | return; | |
1576 | } | |
1da177e4 LT |
1577 | } |
1578 | ||
689c9568 | 1579 | static int intelfb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
1da177e4 LT |
1580 | { |
1581 | struct intelfb_info *dinfo = GET_DINFO(info); | |
8b91b0b4 | 1582 | u32 physical; |
1da177e4 LT |
1583 | #if VERBOSE > 0 |
1584 | DBG_MSG("intelfb_cursor\n"); | |
1585 | #endif | |
1586 | ||
1587 | if (!dinfo->hwcursor) | |
c465e05a | 1588 | return -ENODEV; |
1da177e4 LT |
1589 | |
1590 | intelfbhw_cursor_hide(dinfo); | |
1591 | ||
1592 | /* If XFree killed the cursor - restore it */ | |
3aff13cf | 1593 | physical = (dinfo->mobile || IS_I9XX(dinfo)) ? dinfo->cursor.physical : |
8b91b0b4 | 1594 | (dinfo->cursor.offset << 12); |
8bb91f6a | 1595 | |
8b91b0b4 | 1596 | if (INREG(CURSOR_A_BASEADDR) != physical) { |
1da177e4 LT |
1597 | u32 fg, bg; |
1598 | ||
1599 | DBG_MSG("the cursor was killed - restore it !!\n"); | |
1600 | DBG_MSG("size %d, %d pos %d, %d\n", | |
1601 | cursor->image.width, cursor->image.height, | |
1602 | cursor->image.dx, cursor->image.dy); | |
1603 | ||
1604 | intelfbhw_cursor_init(dinfo); | |
1605 | intelfbhw_cursor_reset(dinfo); | |
1606 | intelfbhw_cursor_setpos(dinfo, cursor->image.dx, | |
1607 | cursor->image.dy); | |
1608 | ||
1609 | if (dinfo->depth != 8) { | |
1610 | fg =dinfo->pseudo_palette[cursor->image.fg_color]; | |
1611 | bg =dinfo->pseudo_palette[cursor->image.bg_color]; | |
1612 | } else { | |
1613 | fg = cursor->image.fg_color; | |
1614 | bg = cursor->image.bg_color; | |
1615 | } | |
1616 | intelfbhw_cursor_setcolor(dinfo, bg, fg); | |
1617 | intelfbhw_cursor_load(dinfo, cursor->image.width, | |
1618 | cursor->image.height, | |
1619 | dinfo->cursor_src); | |
1620 | ||
1621 | if (cursor->enable) | |
1622 | intelfbhw_cursor_show(dinfo); | |
1623 | return 0; | |
1624 | } | |
1625 | ||
1626 | if (cursor->set & FB_CUR_SETPOS) { | |
1627 | u32 dx, dy; | |
1628 | ||
1629 | dx = cursor->image.dx - info->var.xoffset; | |
1630 | dy = cursor->image.dy - info->var.yoffset; | |
1631 | ||
1632 | intelfbhw_cursor_setpos(dinfo, dx, dy); | |
1633 | } | |
1634 | ||
1635 | if (cursor->set & FB_CUR_SETSIZE) { | |
1636 | if (cursor->image.width > 64 || cursor->image.height > 64) | |
1637 | return -ENXIO; | |
1638 | ||
1639 | intelfbhw_cursor_reset(dinfo); | |
1640 | } | |
1641 | ||
1642 | if (cursor->set & FB_CUR_SETCMAP) { | |
1643 | u32 fg, bg; | |
1644 | ||
1645 | if (dinfo->depth != 8) { | |
1646 | fg = dinfo->pseudo_palette[cursor->image.fg_color]; | |
1647 | bg = dinfo->pseudo_palette[cursor->image.bg_color]; | |
1648 | } else { | |
1649 | fg = cursor->image.fg_color; | |
1650 | bg = cursor->image.bg_color; | |
1651 | } | |
1652 | ||
1653 | intelfbhw_cursor_setcolor(dinfo, bg, fg); | |
1654 | } | |
1655 | ||
1656 | if (cursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) { | |
1657 | u32 s_pitch = (ROUND_UP_TO(cursor->image.width, 8) / 8); | |
1658 | u32 size = s_pitch * cursor->image.height; | |
1659 | u8 *dat = (u8 *) cursor->image.data; | |
1660 | u8 *msk = (u8 *) cursor->mask; | |
1661 | u8 src[64]; | |
1662 | u32 i; | |
1663 | ||
1664 | if (cursor->image.depth != 1) | |
1665 | return -ENXIO; | |
1666 | ||
1667 | switch (cursor->rop) { | |
1668 | case ROP_XOR: | |
1669 | for (i = 0; i < size; i++) | |
1670 | src[i] = dat[i] ^ msk[i]; | |
1671 | break; | |
1672 | case ROP_COPY: | |
1673 | default: | |
1674 | for (i = 0; i < size; i++) | |
1675 | src[i] = dat[i] & msk[i]; | |
1676 | break; | |
1677 | } | |
1678 | ||
1679 | /* save the bitmap to restore it when XFree will | |
1680 | make the cursor dirty */ | |
1681 | memcpy(dinfo->cursor_src, src, size); | |
1682 | ||
1683 | intelfbhw_cursor_load(dinfo, cursor->image.width, | |
1684 | cursor->image.height, src); | |
1685 | } | |
1686 | ||
1687 | if (cursor->enable) | |
1688 | intelfbhw_cursor_show(dinfo); | |
1689 | ||
1690 | return 0; | |
1691 | } | |
1692 | ||
689c9568 | 1693 | static int intelfb_sync(struct fb_info *info) |
1da177e4 LT |
1694 | { |
1695 | struct intelfb_info *dinfo = GET_DINFO(info); | |
1696 | ||
1697 | #if VERBOSE > 0 | |
1698 | DBG_MSG("intelfb_sync\n"); | |
1699 | #endif | |
1700 | ||
1701 | if (dinfo->ring_lockup) | |
1702 | return 0; | |
1703 | ||
1704 | intelfbhw_do_sync(dinfo); | |
1705 | return 0; | |
1706 | } | |
1707 |