📄 fbdev.c
字号:
riva_set_fbinfo (rinfo); fb_memset (rinfo->fb_base, 0, rinfo->ram_amount); riva_load_video_mode (rinfo, &rinfo->disp.var); if (register_framebuffer ((struct fb_info *) rinfo) < 0) { printk (KERN_ERR PFX "error registering riva framebuffer\n"); goto err_out_iounmap_fb; } riva_boards = riva_board_list_add(riva_boards, rinfo); pci_set_drvdata (pd, rinfo); printk (KERN_INFO PFX "PCI Riva NV%d framebuffer ver %s (%s, %dMB @ 0x%lX)\n", rinfo->riva.Architecture, RIVAFB_VERSION, rinfo->drvr_name, rinfo->ram_amount / (1024 * 1024) + 1, rinfo->fb_base_phys); return 0;err_out_iounmap_fb: iounmap (rinfo->fb_base);err_out_iounmap_ctrl: iounmap (rinfo->ctrl_base);err_out_free_base1: release_mem_region (rinfo->fb_base_phys, rinfo->base1_region_size);err_out_free_base0: release_mem_region (rinfo->ctrl_base_phys, rinfo->base0_region_size);err_out_kfree: kfree (rinfo);err_out: return -ENODEV;}static void __devexit rivafb_remove_one (struct pci_dev *pd){ struct rivafb_info *board = pci_get_drvdata (pd); if (!board) return; riva_boards = riva_board_list_del(riva_boards, board); riva_load_state (board, &board->initial_state); unregister_framebuffer ((struct fb_info *) board); iounmap (board->ctrl_base); iounmap (board->fb_base); release_mem_region (board->ctrl_base_phys, board->base0_region_size); release_mem_region (board->fb_base_phys, board->base1_region_size); kfree (board); pci_set_drvdata (pd, NULL);}/*** riva_wclut - set CLUT entry ***/static void riva_wclut (unsigned char regnum, unsigned char red, unsigned char green, unsigned char blue){ unsigned int data = VGA_PEL_D; /* address write mode register is not translated.. */ vga_io_w (VGA_PEL_IW, regnum); vga_io_w (data, red); vga_io_w (data, green); vga_io_w (data, blue);}/* ------------ Hardware Independent Functions ------------ */#ifndef MODULEint __init rivafb_setup (char *options){ char *this_opt; if (!options || !*options) return 0; for (this_opt = strtok (options, ","); this_opt; this_opt = strtok (NULL, ",")) { if (!strncmp (this_opt, "font:", 5)) { char *p; int i; p = this_opt + 5; for (i = 0; i < sizeof (fontname) - 1; i++) if (!*p || *p == ' ' || *p == ',') break; memcpy (fontname, this_opt + 5, i); fontname[i] = 0; } else if (!strncmp (this_opt, "noaccel", 7)) { noaccel = 1; } else mode_option = this_opt; } return 0;}#endif /* !MODULE */ /* * Initialization *//* ------------------------------------------------------------------------- */ /* * Frame buffer operations */static int rivafb_get_fix (struct fb_fix_screeninfo *fix, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; struct display *p; DPRINTK ("ENTER\n"); assert (fix != NULL); assert (info != NULL); assert (rivainfo->drvr_name && rivainfo->drvr_name[0]); assert (rivainfo->fb_base_phys > 0); assert (rivainfo->ram_amount > 0); p = (con < 0) ? rivainfo->info.disp : &fb_display[con]; memset (fix, 0, sizeof (struct fb_fix_screeninfo)); sprintf (fix->id, "Riva %s", rivainfo->drvr_name); fix->smem_start = rivainfo->fb_base_phys; fix->smem_len = rivainfo->ram_amount; fix->type = p->type; fix->type_aux = p->type_aux; fix->visual = p->visual; fix->xpanstep = 1; fix->ypanstep = 1; fix->ywrapstep = 0; /* FIXME: no ywrap for now */ fix->line_length = p->line_length; /* FIXME: set up MMIO region, export via FB_ACCEL_xxx */ fix->mmio_start = 0; fix->mmio_len = 0; fix->accel = FB_ACCEL_NONE; DPRINTK ("EXIT, returning 0\n"); return 0;}static int rivafb_get_var (struct fb_var_screeninfo *var, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; DPRINTK ("ENTER\n"); assert (info != NULL); assert (var != NULL); *var = (con < 0) ? rivainfo->disp.var : fb_display[con].var; DPRINTK ("EXIT, returning 0\n"); return 0;}static int rivafb_set_var (struct fb_var_screeninfo *var, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; struct display *dsp; struct fb_var_screeninfo v; int nom, den; /* translating from pixels->bytes */ int i; unsigned chgvar = 0; static struct { int xres, yres; } modes[] = { { 1600, 1280}, { 1280, 1024}, { 1024, 768}, { 800, 600}, { 640, 480}, { -1, -1} }; DPRINTK ("ENTER\n"); assert (info != NULL); assert (var != NULL); DPRINTK ("Requested: %dx%dx%d\n", var->xres, var->yres, var->bits_per_pixel); DPRINTK (" virtual: %dx%d\n", var->xres_virtual, var->yres_virtual); DPRINTK (" offset: (%d,%d)\n", var->xoffset, var->yoffset); DPRINTK ("grayscale: %d\n", var->grayscale); dsp = (con < 0) ? rivainfo->info.disp : &fb_display[con]; assert (dsp != NULL); /* if var has changed, we should call changevar() later */ if (con >= 0) { chgvar = ((dsp->var.xres != var->xres) || (dsp->var.yres != var->yres) || (dsp->var.xres_virtual != var->xres_virtual) || (dsp->var.yres_virtual != var->yres_virtual) || (dsp->var.bits_per_pixel != var->bits_per_pixel) || memcmp (&dsp->var.red, &var->red, sizeof (var->red)) || memcmp (&dsp->var.green, &var->green, sizeof (var->green)) || memcmp (&dsp->var.blue, &var->blue, sizeof (var->blue))); } memcpy (&v, var, sizeof (v)); switch (v.bits_per_pixel) {#ifdef FBCON_HAS_MFB case 1: dsp->dispsw = &fbcon_mfb; dsp->line_length = v.xres_virtual / 8; dsp->visual = FB_VISUAL_MONO10; nom = 4; den = 8; break;#endif#ifdef FBCON_HAS_CFB8 case 2 ... 8: v.bits_per_pixel = 8; dsp->dispsw = &fbcon_cfb8; nom = 1; den = 1; dsp->line_length = v.xres_virtual; dsp->visual = FB_VISUAL_PSEUDOCOLOR; v.red.offset = 0; v.red.length = 6; v.green.offset = 0; v.green.length = 6; v.blue.offset = 0; v.blue.length = 6; break;#endif#ifdef FBCON_HAS_CFB16 case 9 ... 16: v.bits_per_pixel = 16; dsp->dispsw = &fbcon_cfb16; dsp->dispsw_data = &rivainfo->con_cmap.cfb16; nom = 2; den = 1; dsp->line_length = v.xres_virtual * 2; dsp->visual = FB_VISUAL_DIRECTCOLOR;#ifdef CONFIG_PREP v.red.offset = 2; v.green.offset = -3; v.blue.offset = 8;#else v.red.offset = 10; v.green.offset = 5; v.blue.offset = 0;#endif v.red.length = 5; v.green.length = 5; v.blue.length = 5; break;#endif#ifdef FBCON_HAS_CFB32 case 17 ... 32: v.bits_per_pixel = 32; dsp->dispsw = &fbcon_cfb32; dsp->dispsw_data = rivainfo->con_cmap.cfb32; nom = 4; den = 1; dsp->line_length = v.xres_virtual * 4; dsp->visual = FB_VISUAL_DIRECTCOLOR;#ifdef CONFIG_PREP v.red.offset = 8; v.green.offset = 16; v.blue.offset = 24;#else v.red.offset = 16; v.green.offset = 8; v.blue.offset = 0;#endif v.red.length = 8; v.green.length = 8; v.blue.length = 8; break;#endif default: printk (KERN_ERR PFX "mode %dx%dx%d rejected...color depth not supported.\n", var->xres, var->yres, var->bits_per_pixel); DPRINTK ("EXIT, returning -EINVAL\n"); return -EINVAL; } if (v.xres * nom / den * v.yres > rivainfo->ram_amount) { printk (KERN_ERR PFX "mode %dx%dx%d rejected...resolution too high to fit into video memory!\n", var->xres, var->yres, var->bits_per_pixel); DPRINTK ("EXIT - EINVAL error\n"); return -EINVAL; } /* use highest possible virtual resolution */ if (v.xres_virtual == -1 && v.yres_virtual == -1) { printk (KERN_WARNING PFX "using maximum available virtual resolution\n"); for (i = 0; modes[i].xres != -1; i++) { if (modes[i].xres * nom / den * modes[i].yres < rivainfo->ram_amount / 2) break; } if (modes[i].xres == -1) { printk (KERN_ERR PFX "could not find a virtual resolution that fits into video memory!!\n"); DPRINTK ("EXIT - EINVAL error\n"); return -EINVAL; } v.xres_virtual = modes[i].xres; v.yres_virtual = modes[i].yres; printk (KERN_INFO PFX "virtual resolution set to maximum of %dx%d\n", v.xres_virtual, v.yres_virtual); } else if (v.xres_virtual == -1) { /* FIXME: maximize X virtual resolution only */ } else if (v.yres_virtual == -1) { /* FIXME: maximize Y virtual resolution only */ } if (v.xoffset < 0) v.xoffset = 0; if (v.yoffset < 0) v.yoffset = 0; /* truncate xoffset and yoffset to maximum if too high */ if (v.xoffset > v.xres_virtual - v.xres) v.xoffset = v.xres_virtual - v.xres - 1; if (v.yoffset > v.yres_virtual - v.yres) v.yoffset = v.yres_virtual - v.yres - 1; v.red.msb_right = v.green.msb_right = v.blue.msb_right = v.transp.offset = v.transp.length = v.transp.msb_right = 0; switch (v.activate & FB_ACTIVATE_MASK) { case FB_ACTIVATE_TEST: DPRINTK ("EXIT - FB_ACTIVATE_TEST\n"); return 0; case FB_ACTIVATE_NXTOPEN: /* ?? */ case FB_ACTIVATE_NOW: break; /* continue */ default: DPRINTK ("EXIT - unknown activation type\n"); return -EINVAL; /* unknown */ } dsp->type = FB_TYPE_PACKED_PIXELS; /* FIXME: verify that the above code sets dsp->* fields correctly */ memcpy (&dsp->var, &v, sizeof (v)); riva_load_video_mode (rivainfo, &v); if (chgvar && info && info->changevar) info->changevar (con); DPRINTK ("EXIT, returning 0\n"); return 0;}static int rivafb_get_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; struct display *dsp; DPRINTK ("ENTER\n"); assert (rivainfo != NULL); assert (cmap != NULL); dsp = (con < 0) ? rivainfo->info.disp : &fb_display[con]; if (con == rivainfo->currcon) { /* current console? */ int rc = fb_get_cmap (cmap, kspc, riva_getcolreg, info); DPRINTK ("EXIT - returning %d\n", rc); return rc; } else if (dsp->cmap.len) /* non default colormap? */ fb_copy_cmap (&dsp->cmap, cmap, kspc ? 0 : 2); else fb_copy_cmap (fb_default_cmap (riva_get_cmap_len (&dsp->var)), cmap, kspc ? 0 : 2); DPRINTK ("EXIT, returning 0\n"); return 0;}static int rivafb_set_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; struct display *dsp; unsigned int cmap_len; DPRINTK ("ENTER\n"); assert (rivainfo != NULL); assert (cmap != NULL); dsp = (con < 0) ? rivainfo->info.disp : &fb_display[con]; cmap_len = riva_get_cmap_len (&dsp->var); if (dsp->cmap.len != cmap_len) { int err = fb_alloc_cmap (&dsp->cmap, cmap_len, 0); if (err) { DPRINTK ("EXIT - returning %d\n", err); return err; } } if (con == rivainfo->currcon) { /* current console? */ int rc = fb_set_cmap (cmap, kspc, riva_setcolreg, info); DPRINTK ("EXIT - returning %d\n", rc); return rc; } else fb_copy_cmap (cmap, &dsp->cmap, kspc ? 0 : 1); DPRINTK ("EXIT, returning 0\n"); return 0;}/** * rivafb_pan_display * @var: standard kernel fb changeable data * @con: * @info: pointer to rivafb_info object containing info for current riva board * * DESCRIPTION: * Pan (or wrap, depending on the `vmode' field) the display using the * `xoffset' and `yoffset' fields of the `var' structure. * If the values don't fit, return -EINVAL. * * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag */static int rivafb_pan_display (struct fb_var_screeninfo *var, int con, struct fb_info *info){ unsigned int base; struct display *dsp; struct rivafb_info *rivainfo = (struct rivafb_info *) info; DPRINTK ("ENTER\n"); assert (rivainfo != NULL); if (var->xoffset > (var->xres_virtual - var->xres)) return -EINVAL; if (var->yoffset > (var->yres_virtual - var->yres)) return -EINVAL; dsp = (con < 0) ? rivainfo->info.disp : &fb_display[con]; if (var->vmode & FB_VMODE_YWRAP) { if (var->yoffset < 0 || var->yoffset >= dsp->var.yres_virtual || var->xoffset) return -EINVAL; } else { if (var->xoffset + dsp->var.xres > dsp->var.xres_virtual || var->yoffset + dsp->var.yres > dsp->var.yres_virtual) return -EINVAL; } base = var->yoffset * dsp->line_length + var->xoffset; if (con == rivainfo->currcon) { rivainfo->riva.SetStartAddress (&rivainfo->riva, base); } dsp->var.xoffset = var->xoffset; dsp->var.yoffset = var->yoffset; if (var->vmode & FB_VMODE_YWRAP) dsp->var.vmode |= FB_VMODE_YWRAP; else dsp->var.vmode &= ~FB_VMODE_YWRAP; DPRINTK ("EXIT, returning 0\n"); return 0;}static int rivafb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg, int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; DPRINTK ("ENTER\n"); assert (rivainfo != NULL); /* no rivafb-specific ioctls */ DPRINTK ("EXIT, returning -EINVAL\n"); return -EINVAL;}static int rivafb_switch (int con, struct fb_info *info){ struct rivafb_info *rivainfo = (struct rivafb_info *) info; struct fb_cmap *cmap; struct display *dsp; DPRINTK ("ENTER\n"); assert (rivainfo != NULL); dsp = (con < 0) ? rivainfo->info.disp : &fb_display[con]; if (rivainfo->currcon >= 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -