1 /*
2 * linux/drivers/video/fbmem.c
3 *
4 * Copyright (C) 1994 Martin Schaller
5 *
6 * 2001 - Documented with DocBook
7 * - Brad Douglas <brad@neruo.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive
11 * for more details.
12 */
13
14 #include <linux/config.h>
15 #include <linux/module.h>
16
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/sched.h>
20 #include <linux/smp_lock.h>
21 #include <linux/kernel.h>
22 #include <linux/major.h>
23 #include <linux/slab.h>
24 #include <linux/mman.h>
25 #include <linux/tty.h>
26 #include <linux/console.h>
27 #include <linux/init.h>
28 #include <linux/proc_fs.h>
29 #ifdef CONFIG_KMOD
30 #include <linux/kmod.h>
31 #endif
32 #include <linux/devfs_fs_kernel.h>
33
34 #if defined(__mc68000__) || defined(CONFIG_APUS)
35 #include <asm/setup.h>
36 #endif
37
38 #include <asm/io.h>
39 #include <asm/uaccess.h>
40 #include <asm/page.h>
41 #include <asm/pgtable.h>
42
43 #include <linux/fb.h>
44 #include <video/fbcon.h>
45
46 /*
47 * Frame buffer device initialization and setup routines
48 */
49
50 extern int acornfb_init(void);
51 extern int acornfb_setup(char*);
52 extern int amifb_init(void);
53 extern int amifb_setup(char*);
54 extern int atafb_init(void);
55 extern int atafb_setup(char*);
56 extern int macfb_init(void);
57 extern int macfb_setup(char*);
58 extern int cyberfb_init(void);
59 extern int cyberfb_setup(char*);
60 extern int pm2fb_init(void);
61 extern int pm2fb_setup(char*);
62 extern int pm3fb_init(void);
63 extern int pm3fb_setup(char*);
64 extern int cyber2000fb_init(void);
65 extern int retz3fb_init(void);
66 extern int retz3fb_setup(char*);
67 extern int clgenfb_init(void);
68 extern int clgenfb_setup(char*);
69 extern int hitfb_init(void);
70 extern int vfb_init(void);
71 extern int vfb_setup(char*);
72 extern int offb_init(void);
73 extern int atyfb_init(void);
74 extern int atyfb_setup(char*);
75 extern int aty128fb_init(void);
76 extern int aty128fb_setup(char*);
77 extern int neofb_init(void);
78 extern int neofb_setup(char*);
79 extern int igafb_init(void);
80 extern int igafb_setup(char*);
81 extern int imsttfb_init(void);
82 extern int imsttfb_setup(char*);
83 extern int dnfb_init(void);
84 extern int tgafb_init(void);
85 extern int tgafb_setup(char*);
86 extern int virgefb_init(void);
87 extern int virgefb_setup(char*);
88 extern int resolver_video_setup(char*);
89 extern int s3triofb_init(void);
90 extern int vesafb_init(void);
91 extern int vesafb_setup(char*);
92 extern int vga16fb_init(void);
93 extern int vga16fb_setup(char*);
94 extern int hgafb_init(void);
95 extern int hgafb_setup(char*);
96 extern int matroxfb_init(void);
97 extern int matroxfb_setup(char*);
98 extern int hpfb_init(void);
99 extern int sbusfb_init(void);
100 extern int sbusfb_setup(char*);
101 extern int control_init(void);
102 extern int control_setup(char*);
103 extern int platinum_init(void);
104 extern int platinum_setup(char*);
105 extern int valkyriefb_init(void);
106 extern int valkyriefb_setup(char*);
107 extern int chips_init(void);
108 extern int g364fb_init(void);
109 extern int sa1100fb_init(void);
110 extern int fm2fb_init(void);
111 extern int fm2fb_setup(char*);
112 extern int q40fb_init(void);
113 extern int sun3fb_init(void);
114 extern int sun3fb_setup(char *);
115 extern int sgivwfb_init(void);
116 extern int sgivwfb_setup(char*);
117 extern int rivafb_init(void);
118 extern int rivafb_setup(char*);
119 extern int tdfxfb_init(void);
120 extern int tdfxfb_setup(char*);
121 extern int tridentfb_init(void);
122 extern int tridentfb_setup(char*);
123 extern int sisfb_init(void);
124 extern int sisfb_setup(char*);
125 extern int stifb_init(void);
126 extern int stifb_setup(char*);
127 extern int pmagaafb_init(void);
128 extern int pmagbafb_init(void);
129 extern int pmagbbfb_init(void);
130 extern int maxinefb_init(void);
131 extern int tx3912fb_init(void);
132 extern int radeonfb_init(void);
133 extern int radeonfb_setup(char*);
134 extern int intelfb_init(void);
135 extern int intelfb_setup(char*);
136 extern int e1355fb_init(void);
137 extern int e1355fb_setup(char*);
138 extern int e1356fb_init(void);
139 extern int e1356fb_setup(char*);
140 extern int au1100fb_init(void);
141 extern int au1100fb_setup(char*);
142 extern int pvr2fb_init(void);
143 extern int pvr2fb_setup(char*);
144 extern int sstfb_init(void);
145 extern int sstfb_setup(char*);
146 extern int it8181fb_init(void);
147 extern int it8181fb_setup(char*);
148
149 static struct {
150 const char *name;
151 int (*init)(void);
152 int (*setup)(char*);
153 } fb_drivers[] __initdata = {
154
155 #ifdef CONFIG_FB_SBUS
156 /*
157 * Sbusfb must be initialized _before_ other frame buffer devices that
158 * use PCI probing
159 */
160 { "sbus", sbusfb_init, sbusfb_setup },
161 #endif
162
163 /*
164 * Chipset specific drivers that use resource management
165 */
166
167 #ifdef CONFIG_FB_RETINAZ3
168 { "retz3", retz3fb_init, retz3fb_setup },
169 #endif
170 #ifdef CONFIG_FB_AMIGA
171 { "amifb", amifb_init, amifb_setup },
172 #endif
173 #ifdef CONFIG_FB_CYBER
174 { "cyber", cyberfb_init, cyberfb_setup },
175 #endif
176 #ifdef CONFIG_FB_CYBER2000
177 { "cyber2000", cyber2000fb_init, NULL },
178 #endif
179 #ifdef CONFIG_FB_PM2
180 { "pm2fb", pm2fb_init, pm2fb_setup },
181 #endif
182 #ifdef CONFIG_FB_PM3
183 { "pm3fb", pm3fb_init, pm3fb_setup },
184 #endif
185 #ifdef CONFIG_FB_CLGEN
186 { "clgen", clgenfb_init, clgenfb_setup },
187 #endif
188 #ifdef CONFIG_FB_ATY
189 { "atyfb", atyfb_init, atyfb_setup },
190 #endif
191 #ifdef CONFIG_FB_MATROX
192 { "matrox", matroxfb_init, matroxfb_setup },
193 #endif
194 #ifdef CONFIG_FB_ATY128
195 { "aty128fb", aty128fb_init, aty128fb_setup },
196 #endif
197 #ifdef CONFIG_FB_NEOMAGIC
198 { "neo", neofb_init, neofb_setup },
199 #endif
200 #ifdef CONFIG_FB_VIRGE
201 { "virge", virgefb_init, virgefb_setup },
202 #endif
203 #ifdef CONFIG_FB_RIVA
204 { "riva", rivafb_init, rivafb_setup },
205 #endif
206 #ifdef CONFIG_FB_RADEON
207 { "radeon", radeonfb_init, radeonfb_setup },
208 #endif
209 #ifdef CONFIG_FB_INTEL
210 { "intelfb", intelfb_init, intelfb_setup },
211 #endif
212 #ifdef CONFIG_FB_CONTROL
213 { "controlfb", control_init, control_setup },
214 #endif
215 #ifdef CONFIG_FB_PLATINUM
216 { "platinumfb", platinum_init, platinum_setup },
217 #endif
218 #ifdef CONFIG_FB_VALKYRIE
219 { "valkyriefb", valkyriefb_init, valkyriefb_setup },
220 #endif
221 #ifdef CONFIG_FB_CT65550
222 { "chipsfb", chips_init, NULL },
223 #endif
224 #ifdef CONFIG_FB_IMSTT
225 { "imsttfb", imsttfb_init, imsttfb_setup },
226 #endif
227 #ifdef CONFIG_FB_S3TRIO
228 { "s3trio", s3triofb_init, NULL },
229 #endif
230 #ifdef CONFIG_FB_FM2
231 { "fm2fb", fm2fb_init, fm2fb_setup },
232 #endif
233 #ifdef CONFIG_FB_SIS
234 { "sisfb", sisfb_init, sisfb_setup },
235 #endif
236 #ifdef CONFIG_FB_TRIDENT
237 { "trident", tridentfb_init, tridentfb_setup },
238 #endif
239 #ifdef CONFIG_FB_VOODOO1
240 { "sst", sstfb_init, sstfb_setup },
241 #endif
242
243 /*
244 * Generic drivers that are used as fallbacks
245 *
246 * These depend on resource management and must be initialized
247 * _after_ all other frame buffer devices that use resource
248 * management!
249 */
250
251 #ifdef CONFIG_FB_OF
252 { "offb", offb_init, NULL },
253 #endif
254 #ifdef CONFIG_FB_VESA
255 { "vesa", vesafb_init, vesafb_setup },
256 #endif
257
258 /*
259 * Chipset specific drivers that don't use resource management (yet)
260 */
261
262 #ifdef CONFIG_FB_3DFX
263 { "tdfx", tdfxfb_init, tdfxfb_setup },
264 #endif
265 #ifdef CONFIG_FB_SGIVW
266 { "sgivw", sgivwfb_init, sgivwfb_setup },
267 #endif
268 #ifdef CONFIG_FB_ACORN
269 { "acorn", acornfb_init, acornfb_setup },
270 #endif
271 #ifdef CONFIG_FB_ATARI
272 { "atafb", atafb_init, atafb_setup },
273 #endif
274 #ifdef CONFIG_FB_MAC
275 { "macfb", macfb_init, macfb_setup },
276 #endif
277 #ifdef CONFIG_FB_HGA
278 { "hga", hgafb_init, hgafb_setup },
279 #endif
280 #ifdef CONFIG_FB_IGA
281 { "igafb", igafb_init, igafb_setup },
282 #endif
283 #ifdef CONFIG_APOLLO
284 { "apollo", dnfb_init, NULL },
285 #endif
286 #ifdef CONFIG_FB_Q40
287 { "q40fb", q40fb_init, NULL },
288 #endif
289 #ifdef CONFIG_FB_TGA
290 { "tga", tgafb_init, tgafb_setup },
291 #endif
292 #ifdef CONFIG_FB_HP300
293 { "hpfb", hpfb_init, NULL },
294 #endif
295 #ifdef CONFIG_FB_G364
296 { "g364", g364fb_init, NULL },
297 #endif
298 #ifdef CONFIG_FB_SA1100
299 { "sa1100", sa1100fb_init, NULL },
300 #endif
301 #ifdef CONFIG_FB_SUN3
302 { "sun3", sun3fb_init, sun3fb_setup },
303 #endif
304 #ifdef CONFIG_FB_HIT
305 { "hitfb", hitfb_init, NULL },
306 #endif
307 #ifdef CONFIG_FB_TX3912
308 { "tx3912", tx3912fb_init, NULL },
309 #endif
310 #ifdef CONFIG_FB_E1355
311 { "e1355fb", e1355fb_init, e1355fb_setup },
312 #endif
313 #ifdef CONFIG_FB_E1356
314 { "e1356fb", e1356fb_init, e1356fb_setup },
315 #endif
316 #ifdef CONFIG_FB_PVR2
317 { "pvr2", pvr2fb_init, pvr2fb_setup },
318 #endif
319 #ifdef CONFIG_FB_PMAG_AA
320 { "pmagaafb", pmagaafb_init, NULL },
321 #endif
322 #ifdef CONFIG_FB_PMAG_BA
323 { "pmagbafb", pmagbafb_init, NULL },
324 #endif
325 #ifdef CONFIG_FB_PMAGB_B
326 { "pmagbbfb", pmagbbfb_init, NULL },
327 #endif
328 #ifdef CONFIG_FB_MAXINE
329 { "maxinefb", maxinefb_init, NULL },
330 #endif
331 #ifdef CONFIG_FB_AU1100
332 { "au1100fb", au1100fb_init, au1100fb_setup },
333 #endif
334 #ifdef CONFIG_FB_IT8181
335 { "it8181fb", it8181fb_init, it8181fb_setup },
336 #endif
337
338
339 /*
340 * Generic drivers that don't use resource management (yet)
341 */
342
343 #ifdef CONFIG_FB_VGA16
344 { "vga16", vga16fb_init, vga16fb_setup },
345 #endif
346 #ifdef CONFIG_FB_STI
347 { "stifb", stifb_init, stifb_setup },
348 #endif
349
350 #ifdef CONFIG_GSP_RESOLVER
351 /* Not a real frame buffer device... */
352 { "resolver", NULL, resolver_video_setup },
353 #endif
354
355 #ifdef CONFIG_FB_VIRTUAL
356 /*
357 * Vfb must be last to avoid that it becomes your primary display if
358 * other display devices are present
359 */
360 { "vfb", vfb_init, vfb_setup },
361 #endif
362 };
363
364 #define NUM_FB_DRIVERS (sizeof(fb_drivers)/sizeof(*fb_drivers))
365
366 extern const char *global_mode_option;
367
368 static initcall_t pref_init_funcs[FB_MAX];
369 static int num_pref_init_funcs __initdata = 0;
370
371
372 struct fb_info *registered_fb[FB_MAX];
373 int num_registered_fb;
374 extern int fbcon_softback_size;
375
376 static int first_fb_vc;
377 static int last_fb_vc = MAX_NR_CONSOLES-1;
378 static int fbcon_is_default = 1;
379
380 #ifdef CONFIG_FB_OF
381 static int ofonly __initdata = 0;
382 #endif
383
fbmem_read_proc(char * buf,char ** start,off_t offset,int len,int * eof,void * private)384 static int fbmem_read_proc(char *buf, char **start, off_t offset,
385 int len, int *eof, void *private)
386 {
387 struct fb_info **fi;
388 int clen;
389
390 clen = 0;
391 for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && clen < 4000; fi++)
392 if (*fi)
393 clen += sprintf(buf + clen, "%d %s\n",
394 GET_FB_IDX((*fi)->node),
395 (*fi)->modename);
396 *start = buf + offset;
397 if (clen > offset)
398 clen -= offset;
399 else
400 clen = 0;
401 return clen < len ? clen : len;
402 }
403
404 static ssize_t
fb_read(struct file * file,char * buf,size_t count,loff_t * ppos)405 fb_read(struct file *file, char *buf, size_t count, loff_t *ppos)
406 {
407 loff_t p = *ppos;
408 struct inode *inode = file->f_dentry->d_inode;
409 int fbidx = GET_FB_IDX(inode->i_rdev);
410 struct fb_info *info = registered_fb[fbidx];
411 struct fb_ops *fb = info->fbops;
412 struct fb_fix_screeninfo fix;
413 unsigned int size;
414
415 if (! fb || ! info->disp)
416 return -ENODEV;
417
418 if (p < 0)
419 return -EINVAL;
420
421 fb->fb_get_fix(&fix,PROC_CONSOLE(info), info);
422 size = info->mapped_vram ? info->mapped_vram : fix.smem_len;
423
424 if (p >= size)
425 return 0;
426 if (count > size - p)
427 count = size - p;
428 if (count) {
429 char *base_addr;
430
431 base_addr = info->disp->screen_base;
432 count -= copy_to_user(buf, base_addr+p, count);
433 if (!count)
434 return -EFAULT;
435 *ppos = p + count;
436 }
437 return count;
438 }
439
440 static ssize_t
fb_write(struct file * file,const char * buf,size_t count,loff_t * ppos)441 fb_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
442 {
443 loff_t p = *ppos;
444 struct inode *inode = file->f_dentry->d_inode;
445 int fbidx = GET_FB_IDX(inode->i_rdev);
446 struct fb_info *info = registered_fb[fbidx];
447 struct fb_ops *fb = info->fbops;
448 struct fb_fix_screeninfo fix;
449 int err;
450 unsigned int size;
451
452 if (! fb || ! info->disp)
453 return -ENODEV;
454
455 if (p < 0)
456 return -EINVAL;
457
458 fb->fb_get_fix(&fix, PROC_CONSOLE(info), info);
459 size = info->mapped_vram ? info->mapped_vram : fix.smem_len;
460
461 if (p > size)
462 return -ENOSPC;
463 err = 0;
464 if (count > size - p) {
465 count = size - p;
466 err = -ENOSPC;
467 }
468 if (count) {
469 char *base_addr;
470
471 base_addr = info->disp->screen_base;
472 count -= copy_from_user(base_addr+p, buf, count);
473 *ppos = p + count;
474 err = -EFAULT;
475 }
476 if (count)
477 return count;
478 return err;
479 }
480
481 #ifdef CONFIG_KMOD
try_to_load(int fb)482 static void try_to_load(int fb)
483 {
484 char modname[16];
485
486 sprintf(modname, "fb%d", fb);
487 request_module(modname);
488 }
489 #endif /* CONFIG_KMOD */
490
491 static int
fb_ioctl(struct inode * inode,struct file * file,unsigned int cmd,unsigned long arg)492 fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
493 unsigned long arg)
494 {
495 int fbidx = GET_FB_IDX(inode->i_rdev);
496 struct fb_info *info = registered_fb[fbidx];
497 struct fb_ops *fb = info->fbops;
498 struct fb_cmap cmap;
499 struct fb_var_screeninfo var;
500 struct fb_fix_screeninfo fix;
501 struct fb_con2fbmap con2fb;
502 int i;
503
504 if (! fb)
505 return -ENODEV;
506 switch (cmd) {
507 case FBIOGET_VSCREENINFO:
508 if ((i = fb->fb_get_var(&var, PROC_CONSOLE(info), info)))
509 return i;
510 return copy_to_user((void *) arg, &var,
511 sizeof(var)) ? -EFAULT : 0;
512 case FBIOPUT_VSCREENINFO:
513 if (copy_from_user(&var, (void *) arg, sizeof(var)))
514 return -EFAULT;
515 i = var.activate & FB_ACTIVATE_ALL
516 ? set_all_vcs(fbidx, fb, &var, info)
517 : fb->fb_set_var(&var, PROC_CONSOLE(info), info);
518 if (i)
519 return i;
520 if (copy_to_user((void *) arg, &var, sizeof(var)))
521 return -EFAULT;
522 return 0;
523 case FBIOGET_FSCREENINFO:
524 if ((i = fb->fb_get_fix(&fix, PROC_CONSOLE(info), info)))
525 return i;
526 return copy_to_user((void *) arg, &fix, sizeof(fix)) ?
527 -EFAULT : 0;
528 case FBIOPUTCMAP:
529 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
530 return -EFAULT;
531 return (fb->fb_set_cmap(&cmap, 0, PROC_CONSOLE(info), info));
532 case FBIOGETCMAP:
533 if (copy_from_user(&cmap, (void *) arg, sizeof(cmap)))
534 return -EFAULT;
535 return (fb->fb_get_cmap(&cmap, 0, PROC_CONSOLE(info), info));
536 case FBIOPAN_DISPLAY:
537 if (copy_from_user(&var, (void *) arg, sizeof(var)))
538 return -EFAULT;
539 if (fb->fb_pan_display == NULL)
540 return (var.xoffset || var.yoffset) ? -EINVAL : 0;
541 if ((i=fb->fb_pan_display(&var, PROC_CONSOLE(info), info)))
542 return i;
543 if (copy_to_user((void *) arg, &var, sizeof(var)))
544 return -EFAULT;
545 return i;
546 case FBIOGET_CON2FBMAP:
547 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
548 return -EFAULT;
549 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
550 return -EINVAL;
551 con2fb.framebuffer = con2fb_map[con2fb.console-1];
552 return copy_to_user((void *)arg, &con2fb,
553 sizeof(con2fb)) ? -EFAULT : 0;
554 case FBIOPUT_CON2FBMAP:
555 if (copy_from_user(&con2fb, (void *)arg, sizeof(con2fb)))
556 return - EFAULT;
557 if (con2fb.console < 0 || con2fb.console > MAX_NR_CONSOLES)
558 return -EINVAL;
559 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
560 return -EINVAL;
561 #ifdef CONFIG_KMOD
562 if (!registered_fb[con2fb.framebuffer])
563 try_to_load(con2fb.framebuffer);
564 #endif /* CONFIG_KMOD */
565 if (!registered_fb[con2fb.framebuffer])
566 return -EINVAL;
567 if (con2fb.console != 0)
568 set_con2fb_map(con2fb.console-1, con2fb.framebuffer);
569 else
570 /* set them all */
571 for (i = 0; i < MAX_NR_CONSOLES; i++)
572 set_con2fb_map(i, con2fb.framebuffer);
573 return 0;
574 case FBIOBLANK:
575 if (info->blank == 0)
576 return -EINVAL;
577 (*info->blank)(arg, info);
578 return 0;
579 default:
580 if (fb->fb_ioctl == NULL)
581 return -EINVAL;
582 return fb->fb_ioctl(inode, file, cmd, arg, PROC_CONSOLE(info),
583 info);
584 }
585 }
586
587 static int
fb_mmap(struct file * file,struct vm_area_struct * vma)588 fb_mmap(struct file *file, struct vm_area_struct * vma)
589 {
590 int fbidx = GET_FB_IDX(file->f_dentry->d_inode->i_rdev);
591 struct fb_info *info = registered_fb[fbidx];
592 struct fb_ops *fb = info->fbops;
593 unsigned long off;
594 #if !defined(__sparc__) || defined(__sparc_v9__)
595 struct fb_fix_screeninfo fix;
596 struct fb_var_screeninfo var;
597 unsigned long start;
598 u32 len;
599 #endif
600
601 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
602 return -EINVAL;
603 off = vma->vm_pgoff << PAGE_SHIFT;
604 if (!fb)
605 return -ENODEV;
606 if (fb->fb_mmap) {
607 int res;
608 lock_kernel();
609 res = fb->fb_mmap(info, file, vma);
610 unlock_kernel();
611 /* This is an IO map - tell maydump to skip this VMA */
612 vma->vm_flags |= VM_IO;
613 return res;
614 }
615
616 #if defined(__sparc__) && !defined(__sparc_v9__)
617 /* Should never get here, all fb drivers should have their own
618 mmap routines */
619 return -EINVAL;
620 #else
621 /* !sparc32... */
622
623 lock_kernel();
624 fb->fb_get_fix(&fix, PROC_CONSOLE(info), info);
625
626 /* frame buffer memory */
627 start = fix.smem_start;
628 len = PAGE_ALIGN((start & ~PAGE_MASK) + fix.smem_len);
629 if (off >= len) {
630 /* memory mapped io */
631 off -= len;
632 fb->fb_get_var(&var, PROC_CONSOLE(info), info);
633 if (var.accel_flags) {
634 unlock_kernel();
635 return -EINVAL;
636 }
637 start = fix.mmio_start;
638 len = PAGE_ALIGN((start & ~PAGE_MASK)+fix.mmio_len);
639 }
640 unlock_kernel();
641 start &= PAGE_MASK;
642 if ((vma->vm_end - vma->vm_start + off) > len)
643 return -EINVAL;
644 off += start;
645 vma->vm_pgoff = off >> PAGE_SHIFT;
646 /* This is an IO map - tell maydump to skip this VMA */
647 vma->vm_flags |= VM_IO;
648 #if defined(__sparc_v9__)
649 vma->vm_flags |= (VM_SHM | VM_LOCKED);
650 if (io_remap_page_range(vma->vm_start, off,
651 vma->vm_end - vma->vm_start, vma->vm_page_prot, 0))
652 return -EAGAIN;
653 #else
654 #if defined(__mc68000__)
655 #if defined(CONFIG_SUN3)
656 pgprot_val(vma->vm_page_prot) |= SUN3_PAGE_NOCACHE;
657 #else
658 if (CPU_IS_020_OR_030)
659 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE030;
660 if (CPU_IS_040_OR_060) {
661 pgprot_val(vma->vm_page_prot) &= _CACHEMASK040;
662 /* Use no-cache mode, serialized */
663 pgprot_val(vma->vm_page_prot) |= _PAGE_NOCACHE_S;
664 }
665 #endif
666 #elif defined(__powerpc__)
667 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE|_PAGE_GUARDED;
668 #elif defined(__alpha__)
669 /* Caching is off in the I/O space quadrant by design. */
670 #elif defined(__i386__) || defined(__x86_64__)
671 if (boot_cpu_data.x86 > 3)
672 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
673 #elif defined(__arm__) || defined(__mips__)
674 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
675 #elif defined(__sh__)
676 pgprot_val(vma->vm_page_prot) &= ~_PAGE_CACHABLE;
677 #elif defined(__hppa__)
678 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
679 #elif defined(__ia64__)
680 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
681 #elif defined(__hppa__)
682 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
683 #else
684 #warning What do we have to do here??
685 #endif
686 if (io_remap_page_range(vma->vm_start, off,
687 vma->vm_end - vma->vm_start, vma->vm_page_prot))
688 return -EAGAIN;
689 #endif /* !__sparc_v9__ */
690 return 0;
691 #endif /* !sparc32 */
692 }
693
694 #if 1 /* to go away in 2.5.0 */
GET_FB_IDX(kdev_t rdev)695 int GET_FB_IDX(kdev_t rdev)
696 {
697 int fbidx = MINOR(rdev);
698 if (fbidx >= 32) {
699 int newfbidx = fbidx >> 5;
700 static int warned;
701 if (!(warned & (1<<newfbidx))) {
702 warned |= 1<<newfbidx;
703 printk("Warning: Remapping obsolete /dev/fb* minor %d to %d\n",
704 fbidx, newfbidx);
705 }
706 fbidx = newfbidx;
707 }
708 return fbidx;
709 }
710 #endif
711
712 static int
fb_open(struct inode * inode,struct file * file)713 fb_open(struct inode *inode, struct file *file)
714 {
715 int fbidx = GET_FB_IDX(inode->i_rdev);
716 struct fb_info *info;
717 int res = 0;
718
719 #ifdef CONFIG_KMOD
720 if (!(info = registered_fb[fbidx]))
721 try_to_load(fbidx);
722 #endif /* CONFIG_KMOD */
723 if (!(info = registered_fb[fbidx]))
724 return -ENODEV;
725 if (info->fbops->owner)
726 __MOD_INC_USE_COUNT(info->fbops->owner);
727 if (info->fbops->fb_open) {
728 res = info->fbops->fb_open(info,1);
729 if (res && info->fbops->owner)
730 __MOD_DEC_USE_COUNT(info->fbops->owner);
731 }
732 return res;
733 }
734
735 static int
fb_release(struct inode * inode,struct file * file)736 fb_release(struct inode *inode, struct file *file)
737 {
738 int fbidx = GET_FB_IDX(inode->i_rdev);
739 struct fb_info *info;
740
741 lock_kernel();
742 info = registered_fb[fbidx];
743 if (info->fbops->fb_release)
744 info->fbops->fb_release(info,1);
745 if (info->fbops->owner)
746 __MOD_DEC_USE_COUNT(info->fbops->owner);
747 unlock_kernel();
748 return 0;
749 }
750
751 static struct file_operations fb_fops = {
752 owner: THIS_MODULE,
753 read: fb_read,
754 write: fb_write,
755 ioctl: fb_ioctl,
756 mmap: fb_mmap,
757 open: fb_open,
758 release: fb_release,
759 #ifdef HAVE_ARCH_FB_UNMAPPED_AREA
760 get_unmapped_area: get_fb_unmapped_area,
761 #endif
762 };
763
764 static devfs_handle_t devfs_handle;
765
766
767 /**
768 * register_framebuffer - registers a frame buffer device
769 * @fb_info: frame buffer info structure
770 *
771 * Registers a frame buffer device @fb_info.
772 *
773 * Returns negative errno on error, or zero for success.
774 *
775 */
776
777 int
register_framebuffer(struct fb_info * fb_info)778 register_framebuffer(struct fb_info *fb_info)
779 {
780 int i, j;
781 char name_buf[8];
782 static int fb_ever_opened[FB_MAX];
783 static int first = 1;
784
785 if (num_registered_fb == FB_MAX)
786 return -ENXIO;
787 num_registered_fb++;
788 for (i = 0 ; i < FB_MAX; i++)
789 if (!registered_fb[i])
790 break;
791 fb_info->node = MKDEV(FB_MAJOR, i);
792 registered_fb[i] = fb_info;
793 if (!fb_ever_opened[i]) {
794 struct module *owner = fb_info->fbops->owner;
795 /*
796 * We assume initial frame buffer devices can be opened this
797 * many times
798 */
799 for (j = 0; j < MAX_NR_CONSOLES; j++)
800 if (con2fb_map[j] == i) {
801 if (owner)
802 __MOD_INC_USE_COUNT(owner);
803 if (!fb_info->fbops->fb_open)
804 continue;
805 if (!fb_info->fbops->fb_open(fb_info,0))
806 continue;
807 if (owner)
808 __MOD_DEC_USE_COUNT(owner);
809 }
810 fb_ever_opened[i] = 1;
811 }
812
813 if (first) {
814 first = 0;
815 take_over_console(&fb_con, first_fb_vc, last_fb_vc, fbcon_is_default);
816 }
817 sprintf (name_buf, "%d", i);
818 fb_info->devfs_handle =
819 devfs_register (devfs_handle, name_buf, DEVFS_FL_DEFAULT,
820 FB_MAJOR, i, S_IFCHR | S_IRUGO | S_IWUGO,
821 &fb_fops, NULL);
822
823 return 0;
824 }
825
826
827 /**
828 * unregister_framebuffer - releases a frame buffer device
829 * @fb_info: frame buffer info structure
830 *
831 * Unregisters a frame buffer device @fb_info.
832 *
833 * Returns negative errno on error, or zero for success.
834 *
835 */
836
837 int
unregister_framebuffer(struct fb_info * fb_info)838 unregister_framebuffer(struct fb_info *fb_info)
839 {
840 int i, j;
841
842 i = GET_FB_IDX(fb_info->node);
843 for (j = 0; j < MAX_NR_CONSOLES; j++)
844 if (con2fb_map[j] == i)
845 return -EBUSY;
846 if (!registered_fb[i])
847 return -EINVAL;
848 devfs_unregister (fb_info->devfs_handle);
849 fb_info->devfs_handle = NULL;
850 devfs_unregister (fb_info->devfs_lhandle);
851 fb_info->devfs_lhandle = NULL;
852 registered_fb[i]=NULL;
853 num_registered_fb--;
854 return 0;
855 }
856
857
858 /**
859 * fbmem_init - init frame buffer subsystem
860 *
861 * Initialize the frame buffer subsystem.
862 *
863 * NOTE: This function is _only_ to be called by drivers/char/mem.c.
864 *
865 */
866
867 void __init
fbmem_init(void)868 fbmem_init(void)
869 {
870 int i;
871
872 create_proc_read_entry("fb", 0, 0, fbmem_read_proc, NULL);
873
874 devfs_handle = devfs_mk_dir (NULL, "fb", NULL);
875 if (devfs_register_chrdev(FB_MAJOR,"fb",&fb_fops))
876 printk("unable to get major %d for fb devs\n", FB_MAJOR);
877
878 #ifdef CONFIG_FB_OF
879 if (ofonly) {
880 offb_init();
881 return;
882 }
883 #endif
884
885 /*
886 * Probe for all builtin frame buffer devices
887 */
888 for (i = 0; i < num_pref_init_funcs; i++)
889 pref_init_funcs[i]();
890
891 for (i = 0; i < NUM_FB_DRIVERS; i++)
892 if (fb_drivers[i].init)
893 fb_drivers[i].init();
894 }
895
896
897 /**
898 * video_setup - process command line options
899 * @options: string of options
900 *
901 * Process command line options for frame buffer subsystem.
902 *
903 * NOTE: This function is a __setup and __init function.
904 *
905 * Returns zero.
906 *
907 */
908
video_setup(char * options)909 int __init video_setup(char *options)
910 {
911 int i, j;
912
913 if (!options || !*options)
914 return 0;
915
916 if (!strncmp(options, "scrollback:", 11)) {
917 options += 11;
918 if (*options) {
919 fbcon_softback_size = simple_strtoul(options, &options, 0);
920 if (*options == 'k' || *options == 'K') {
921 fbcon_softback_size *= 1024;
922 options++;
923 }
924 if (*options != ',')
925 return 0;
926 options++;
927 } else
928 return 0;
929 }
930
931 if (!strncmp(options, "map:", 4)) {
932 options += 4;
933 if (*options)
934 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
935 if (!options[j])
936 j = 0;
937 con2fb_map[i] = (options[j++]-'0') % FB_MAX;
938 }
939 return 0;
940 }
941
942 if (!strncmp(options, "vc:", 3)) {
943 options += 3;
944 if (*options)
945 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
946 if (first_fb_vc < 0)
947 first_fb_vc = 0;
948 if (*options++ == '-')
949 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
950 fbcon_is_default = 0;
951 }
952
953 #ifdef CONFIG_FB_OF
954 if (!strcmp(options, "ofonly")) {
955 ofonly = 1;
956 return 0;
957 }
958 #endif
959
960 if (num_pref_init_funcs == FB_MAX)
961 return 0;
962
963 for (i = 0; i < NUM_FB_DRIVERS; i++) {
964 j = strlen(fb_drivers[i].name);
965 if (!strncmp(options, fb_drivers[i].name, j) &&
966 options[j] == ':') {
967 if (!strcmp(options+j+1, "off"))
968 fb_drivers[i].init = NULL;
969 else {
970 if (fb_drivers[i].init) {
971 pref_init_funcs[num_pref_init_funcs++] =
972 fb_drivers[i].init;
973 fb_drivers[i].init = NULL;
974 }
975 if (fb_drivers[i].setup)
976 fb_drivers[i].setup(options+j+1);
977 }
978 return 0;
979 }
980 }
981
982 /*
983 * If we get here no fb was specified.
984 * We consider the argument to be a global video mode option.
985 */
986 global_mode_option = options;
987 return 0;
988 }
989
990 __setup("video=", video_setup);
991
992 /*
993 * Visible symbols for modules
994 */
995
996 EXPORT_SYMBOL(register_framebuffer);
997 EXPORT_SYMBOL(unregister_framebuffer);
998 EXPORT_SYMBOL(registered_fb);
999 EXPORT_SYMBOL(num_registered_fb);
1000 #if 1 /* to go away in 2.5.0 */
1001 EXPORT_SYMBOL(GET_FB_IDX);
1002 #endif
1003
1004 MODULE_LICENSE("GPL");
1005