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