📄 fbmem.c
字号:
/* * linux/drivers/video/fbmem.c * * Copyright (C) 1994 Martin Schaller * * 2001 - Documented with DocBook * - Brad Douglas <brad@neruo.com> * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details. */#include <linux/config.h>#include <linux/module.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/smp_lock.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/slab.h>#include <linux/mman.h>#include <linux/tty.h>#include <linux/console.h>#include <linux/init.h>#include <linux/proc_fs.h>#ifdef CONFIG_KMOD#include <linux/kmod.h>#endif#include <linux/devfs_fs_kernel.h>#if defined(__mc68000__) || defined(CONFIG_APUS)#include <asm/setup.h>#endif#include <asm/io.h>#include <asm/uaccess.h>#include <asm/page.h>#include <asm/pgtable.h>#include <linux/fb.h>#include <video/fbcon.h> /* * Frame buffer device initialization and setup routines */extern int acornfb_init(void);extern int acornfb_setup(char*);extern int amifb_init(void);extern int amifb_setup(char*);extern int atafb_init(void);extern int atafb_setup(char*);extern int macfb_init(void);extern int macfb_setup(char*);extern int cyberfb_init(void);extern int cyberfb_setup(char*);extern int pm2fb_init(void);extern int pm2fb_setup(char*);extern int pm3fb_init(void);extern int pm3fb_setup(char*);extern int cyber2000fb_init(void);extern int retz3fb_init(void);extern int retz3fb_setup(char*);extern int clgenfb_init(void);extern int clgenfb_setup(char*);extern int hitfb_init(void);extern int vfb_init(void);extern int vfb_setup(char*);extern int offb_init(void);extern int atyfb_init(void);extern int atyfb_setup(char*);extern int aty128fb_init(void);extern int aty128fb_setup(char*);extern int neofb_init(void);extern int neofb_setup(char*);extern int igafb_init(void);extern int igafb_setup(char*);extern int imsttfb_init(void);extern int imsttfb_setup(char*);extern int dnfb_init(void);extern int tgafb_init(void);extern int tgafb_setup(char*);extern int virgefb_init(void);extern int virgefb_setup(char*);extern int resolver_video_setup(char*);extern int s3triofb_init(void);extern int vesafb_init(void);extern int vesafb_setup(char*);extern int vga16fb_init(void);extern int vga16fb_setup(char*);extern int hgafb_init(void);extern int hgafb_setup(char*);extern int matroxfb_init(void);extern int matroxfb_setup(char*);extern int hpfb_init(void);extern int sbusfb_init(void);extern int sbusfb_setup(char*);extern int control_init(void);extern int control_setup(char*);extern int platinum_init(void);extern int platinum_setup(char*);extern int valkyriefb_init(void);extern int valkyriefb_setup(char*);extern int chips_init(void);extern int g364fb_init(void);extern int sa1100fb_init(void);extern int fm2fb_init(void);extern int fm2fb_setup(char*);extern int q40fb_init(void);extern int sun3fb_init(void);extern int sun3fb_setup(char *);extern int sgivwfb_init(void);extern int sgivwfb_setup(char*);extern int rivafb_init(void);extern int rivafb_setup(char*);extern int tdfxfb_init(void);extern int tdfxfb_setup(char*);extern int tridentfb_init(void);extern int tridentfb_setup(char*);extern int sisfb_init(void);extern int sisfb_setup(char*);extern int stifb_init(void);extern int stifb_setup(char*);extern int pmagbafb_init(void);extern int pmagbbfb_init(void);extern void maxinefb_init(void);extern int tx3912fb_init(void);extern int radeonfb_init(void);extern int radeonfb_setup(char*);extern int e1355fb_init(void);extern int e1355fb_setup(char*);extern int au1100fb_init(void);extern int au1100fb_setup(char*);extern int pvr2fb_init(void);extern int pvr2fb_setup(char*);extern int sstfb_init(void);extern int sstfb_setup(char*);/*
* 配置各种显示设备的数据结构
*/
static struct { const char *name; //设备名称 int (*init)(void); //指向设备初始化函数 int (*setup)(char*);//指向设备安装函数} fb_drivers[] __initdata = {#ifdef CONFIG_FB_SBUS /* * Sbusfb must be initialized _before_ other frame buffer devices that * use PCI probing */ { "sbus", sbusfb_init, sbusfb_setup },#endif /* * Chipset specific drivers that use resource management */#ifdef CONFIG_FB_RETINAZ3 { "retz3", retz3fb_init, retz3fb_setup },#endif#ifdef CONFIG_FB_AMIGA { "amifb", amifb_init, amifb_setup },#endif#ifdef CONFIG_FB_CYBER { "cyber", cyberfb_init, cyberfb_setup },#endif#ifdef CONFIG_FB_CYBER2000 { "cyber2000", cyber2000fb_init, NULL },#endif#ifdef CONFIG_FB_PM2 { "pm2fb", pm2fb_init, pm2fb_setup },#endif#ifdef CONFIG_FB_PM3 { "pm3fb", pm3fb_init, pm3fb_setup },#endif#ifdef CONFIG_FB_CLGEN { "clgen", clgenfb_init, clgenfb_setup },#endif#ifdef CONFIG_FB_ATY { "atyfb", atyfb_init, atyfb_setup },#endif#ifdef CONFIG_FB_MATROX { "matrox", matroxfb_init, matroxfb_setup },#endif#ifdef CONFIG_FB_ATY128 { "aty128fb", aty128fb_init, aty128fb_setup },#endif#ifdef CONFIG_FB_NEOMAGIC { "neo", neofb_init, neofb_setup },#endif#ifdef CONFIG_FB_VIRGE { "virge", virgefb_init, virgefb_setup },#endif#ifdef CONFIG_FB_RIVA { "riva", rivafb_init, rivafb_setup },#endif#ifdef CONFIG_FB_RADEON { "radeon", radeonfb_init, radeonfb_setup },#endif#ifdef CONFIG_FB_CONTROL { "controlfb", control_init, control_setup },#endif#ifdef CONFIG_FB_PLATINUM { "platinumfb", platinum_init, platinum_setup },#endif#ifdef CONFIG_FB_VALKYRIE { "valkyriefb", valkyriefb_init, valkyriefb_setup },#endif#ifdef CONFIG_FB_CT65550 { "chipsfb", chips_init, NULL },#endif#ifdef CONFIG_FB_IMSTT { "imsttfb", imsttfb_init, imsttfb_setup },#endif#ifdef CONFIG_FB_S3TRIO { "s3trio", s3triofb_init, NULL },#endif #ifdef CONFIG_FB_FM2 { "fm2fb", fm2fb_init, fm2fb_setup },#endif #ifdef CONFIG_FB_SIS { "sisfb", sisfb_init, sisfb_setup },#endif#ifdef CONFIG_FB_TRIDENT { "trident", tridentfb_init, tridentfb_setup },#endif#ifdef CONFIG_FB_VOODOO1 { "sst", sstfb_init, sstfb_setup },#endif /* * Generic drivers that are used as fallbacks * * These depend on resource management and must be initialized * _after_ all other frame buffer devices that use resource * management! */#ifdef CONFIG_FB_OF { "offb", offb_init, NULL },#endif#ifdef CONFIG_FB_VESA { "vesa", vesafb_init, vesafb_setup },#endif /* * Chipset specific drivers that don't use resource management (yet) */#ifdef CONFIG_FB_3DFX { "tdfx", tdfxfb_init, tdfxfb_setup },#endif#ifdef CONFIG_FB_SGIVW { "sgivw", sgivwfb_init, sgivwfb_setup },#endif#ifdef CONFIG_FB_ACORN { "acorn", acornfb_init, acornfb_setup },#endif#ifdef CONFIG_FB_ATARI { "atafb", atafb_init, atafb_setup },#endif#ifdef CONFIG_FB_MAC { "macfb", macfb_init, macfb_setup },#endif#ifdef CONFIG_FB_HGA { "hga", hgafb_init, hgafb_setup },#endif #ifdef CONFIG_FB_IGA { "igafb", igafb_init, igafb_setup },#endif#ifdef CONFIG_APOLLO { "apollo", dnfb_init, NULL },#endif#ifdef CONFIG_FB_Q40 { "q40fb", q40fb_init, NULL },#endif#ifdef CONFIG_FB_TGA { "tga", tgafb_init, tgafb_setup },#endif#ifdef CONFIG_FB_HP300 { "hpfb", hpfb_init, NULL },#endif #ifdef CONFIG_FB_G364 { "g364", g364fb_init, NULL },#endif#ifdef CONFIG_FB_SA1100 { "sa1100", sa1100fb_init, NULL },#endif#ifdef CONFIG_FB_SUN3 { "sun3", sun3fb_init, sun3fb_setup },#endif#ifdef CONFIG_FB_HIT { "hitfb", hitfb_init, NULL },#endif#ifdef CONFIG_FB_TX3912 { "tx3912", tx3912fb_init, NULL },#endif#ifdef CONFIG_FB_E1355 { "e1355fb", e1355fb_init, e1355fb_setup },#endif#ifdef CONFIG_FB_PVR2 { "pvr2", pvr2fb_init, pvr2fb_setup },#endif#ifdef CONFIG_FB_PMAG_BA { "pmagbafb", pmagbafb_init, NULL },#endif#ifdef CONFIG_FB_PMAGB_B { "pmagbbfb", pmagbbfb_init, NULL },#endif#ifdef CONFIG_FB_MAXINE { "maxinefb", maxinefb_init, NULL },#endif#ifdef CONFIG_FB_AU1100 { "au1100fb", au1100fb_init, au1100fb_setup },#endif /* * Generic drivers that don't use resource management (yet) */#ifdef CONFIG_FB_VGA16 { "vga16", vga16fb_init, vga16fb_setup },#endif #ifdef CONFIG_FB_STI { "stifb", stifb_init, stifb_setup },#endif#ifdef CONFIG_GSP_RESOLVER /* Not a real frame buffer device... */ { "resolver", NULL, resolver_video_setup },#endif#ifdef CONFIG_FB_VIRTUAL /* * Vfb must be last to avoid that it becomes your primary display if * other display devices are present */ { "vfb", vfb_init, vfb_setup },#endif};
/*
* 定义表示设备数目的常量
*/#define NUM_FB_DRIVERS (sizeof(fb_drivers)/sizeof(*fb_drivers))extern const char *global_mode_option;static initcall_t pref_init_funcs[FB_MAX];static int num_pref_init_funcs __initdata = 0;//registered_fb:指向已登记入内核的设备的fb_info结构的数组
struct fb_info *registered_fb[FB_MAX];int num_registered_fb;extern int fbcon_softback_size; static int first_fb_vc;static int last_fb_vc = MAX_NR_CONSOLES-1;static int fbcon_is_default = 1;#ifdef CONFIG_FB_OFstatic int ofonly __initdata = 0;#endif
/*
*
*/static int fbmem_read_proc(char *buf, char **start, off_t offset, int len, int *eof, void *private){ struct fb_info **fi; int clen; clen = 0;
/*
* 将已登记的各个显示设备的设备号及名称写到buf+clen的位置,
* 其中clen记录了已登记的设备信息的字节数
*/ for (fi = registered_fb; fi < ®istered_fb[FB_MAX] && len < 4000; fi++) if (*fi) clen += sprintf(buf + clen, "%d %s\n", GET_FB_IDX((*fi)->node), (*fi)->modename);
*start = buf + offset; //FB中用于显示信息的内存的起始地址
if (clen > offset) clen -= offset; else clen = 0; return clen < len ? clen : len;}
/*
* 将file指向的FB中、ppos位置开始的的count个字节读入buf中
*/static ssize_tfb_read(struct file *file, char *buf, size_t count, loff_t *ppos){ unsigned long p = *ppos;
// 获取设备节点 struct inode *inode = file->f_dentry->d_inode;
/* 以下语句用于指向可对FB进行底层操作的函数 */ int fbidx = GET_FB_IDX(inode->i_rdev); struct fb_info *info = registered_fb[fbidx]; struct fb_ops *fb = info->fbops;
struct fb_fix_screeninfo fix;
// 若未找到可对FB进行底层操作的函数或设备不可显示,则出错返回 if (! fb || ! info->disp) return -ENODEV;
// 用fix指向FB的不可修改信息 fb->fb_get_fix(&fix,PROC_CONSOLE(info), info);
// 起始位置p不合法,返回
if (p >= fix.smem_len) return 0;
// 需要传输的字节数connt大于FB的容量,调整count值至FB的最大容量
if (count >= fix.smem_len) count = fix.smem_len;
// 从起始位置开始后的count字节超出FB的范围,调整count值 if (count + p > fix.smem_len) count = fix.smem_len - p;
// count值合法,进行字节传输 if (count) { char *base_addr; base_addr = info->disp->screen_base;
count -= copy_to_user(buf, base_addr+p, count);
if (!count) return -EFAULT; *ppos += count; // 修改起始位置 } return count;}
/*
* 将buf中count个字节写入到file指向的FB的ppos位置处
*/static ssize_tfb_write(struct file *file, const char *buf, size_t count, loff_t *ppos){ unsigned long p = *ppos; struct inode *inode = file->f_dentry->d_inode; int fbidx = GET_FB_IDX(inode->i_rdev); struct fb_info *info = registered_fb[fbidx]; struct fb_ops *fb = info->fbops;
struct fb_fix_screeninfo fix; int err; if (! fb || ! info->disp) return -ENODEV; fb->fb_get_fix(&fix, PROC_CONSOLE(info), info);
if (p > fix.smem_len) return -ENOSPC; if (count >= fix.smem_len) count = fix.smem_len; err = 0; if (count + p > fix.smem_len) { count = fix.smem_len - p; err = -ENOSPC; }
if (count) { char *base_addr; base_addr = info->disp->screen_base; count -= copy_from_user(base_addr+p, buf, count); *ppos += count; err = -EFAULT; } if (count) return count; return err;}
/*
* 加载设备fbn,其中n从0到31
*/#ifdef CONFIG_KMODstatic void try_to_load(int fb){ char modname[16]; sprintf(modname, "fb%d", fb); request_module(modname);}#endif /* CONFIG_KMOD */
/*
*
*/static int fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int fbidx = GET_FB_IDX(inode->i_rdev); struct fb_info *info = registered_fb[fbidx]; struct fb_ops *fb = info->fbops;
struct fb_cmap cmap; struct fb_var_screeninfo var;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -