📄 igafb.c
字号:
/* * linux/drivers/video/igafb.c -- Frame buffer device for IGA 1682 * * Copyright (C) 1998 Vladimir Roganov and Gleb Raiko * * This driver is partly based on the Frame buffer device for ATI Mach64 * and partially on VESA-related code. * * Copyright (C) 1997-1998 Geert Uytterhoeven * Copyright (C) 1998 Bernd Harries * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) * * 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. *//****************************************************************************** TODO: Despite of IGA Card has advanced graphic acceleration, initial version is almost dummy and does not support it. Support for video modes and acceleration must be added together with accelerated X-Windows driver implementation. Most important thing at this moment is that we have working JavaEngine1 console & X with new console interface.******************************************************************************/#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/tty.h>#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/delay.h>#include <linux/interrupt.h>#include <linux/fb.h>#include <linux/selection.h>#include <linux/console.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/nvram.h>#include <linux/kd.h>#include <linux/vt_kern.h>#include <asm/io.h>#ifdef __sparc__#include <asm/pbm.h>#include <asm/pcic.h>#endif#include <video/fbcon.h>#include <video/fbcon-cfb8.h>#include <video/fbcon-cfb16.h>#include <video/fbcon-cfb24.h>#include <video/fbcon-cfb32.h>#include "iga.h"static char igafb_name[16] = "IGA 1682";static char fontname[40] __initdata = { 0 };struct pci_mmap_map { unsigned long voff; unsigned long poff; unsigned long size; unsigned long prot_flag; unsigned long prot_mask;};struct fb_info_iga { struct fb_info fb_info; unsigned long frame_buffer_phys; char *frame_buffer; unsigned long io_base_phys; unsigned long io_base; u32 total_vram; struct pci_mmap_map *mmap_map; struct { u_short blue, green, red, pad; } palette[256]; int video_cmap_len; int currcon; struct display disp; struct display_switch dispsw; union {#ifdef FBCON_HAS_CFB16 u16 cfb16[16]; #endif#ifdef FBCON_HAS_CFB24 u32 cfb24[16];#endif#ifdef FBCON_HAS_CFB32 u32 cfb32[16];#endif } fbcon_cmap;#ifdef __sparc__ u8 open; u8 mmaped; int vtconsole; int consolecnt;#endif};struct fb_var_screeninfo default_var = { /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */ 640, 480, 640, 480, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, 0, 39722, 48, 16, 33, 10, 96, 2, 0, FB_VMODE_NONINTERLACED};#ifdef __sparc__struct fb_var_screeninfo default_var_1024x768 __initdata = { /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */ 1024, 768, 1024, 768, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, 0, 12699, 176, 16, 28, 1, 96, 3, FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED};struct fb_var_screeninfo default_var_1152x900 __initdata = { /* 1152x900, 76 Hz, Non-Interlaced (110.0 MHz dotclock) */ 1152, 900, 1152, 900, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, 0, 9091, 234, 24, 34, 3, 100, 3, FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED};struct fb_var_screeninfo default_var_1280x1024 __initdata = { /* 1280x1024, 75 Hz, Non-Interlaced (135.00 MHz dotclock) */ 1280, 1024, 1280, 1024, 0, 0, 8, 0, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, 0, -1, -1, 0, 7408, 248, 16, 38, 1, 144, 3, FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED};/* * Memory-mapped I/O functions for Sparc PCI * * On sparc we happen to access I/O with memory mapped functions too. */ #define pci_inb(info, reg) readb(info->io_base+(reg))#define pci_outb(info, val, reg) writeb(val, info->io_base+(reg))static inline unsigned int iga_inb(struct fb_info_iga *info, unsigned int reg, unsigned int idx ){ pci_outb(info, idx, reg); return pci_inb(info, reg + 1);}static inline void iga_outb(struct fb_info_iga *info, unsigned char val, unsigned int reg, unsigned int idx ){ pci_outb(info, idx, reg); pci_outb(info, val, reg+1);}#endif /* __sparc__ *//* * Very important functionality for the JavaEngine1 computer: * make screen border black (usign special IGA registers) */static void iga_blank_border(struct fb_info_iga *info){ int i;#if 0 /* * PROM does this for us, so keep this code as a reminder * about required read from 0x3DA and writing of 0x20 in the end. */ (void) pci_inb(info, 0x3DA); /* required for every access */ pci_outb(info, IGA_IDX_VGA_OVERSCAN, IGA_ATTR_CTL); (void) pci_inb(info, IGA_ATTR_CTL+1); pci_outb(info, 0x38, IGA_ATTR_CTL); pci_outb(info, 0x20, IGA_ATTR_CTL); /* re-enable visual */#endif /* * This does not work as it was designed because the overscan * color is looked up in the palette. Therefore, under X11 * overscan changes color. */ for (i=0; i < 3; i++) iga_outb(info, 0, IGA_EXT_CNTRL, IGA_IDX_OVERSCAN_COLOR + i);}/* * Frame buffer device API */static int igafb_update_var(int con, struct fb_info *info){ return 0;}static int igafb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info){ struct fb_info_iga *fb = (struct fb_info_iga*)info; memset(fix, 0, sizeof(struct fb_fix_screeninfo)); strcpy(fix->id, igafb_name); fix->smem_start = (unsigned long) fb->frame_buffer; fix->smem_len = fb->total_vram; fix->xpanstep = 0; fix->ypanstep = 0; fix->ywrapstep = 0; fix->type = FB_TYPE_PACKED_PIXELS; fix->type_aux = 0; fix->line_length = default_var.xres * (default_var.bits_per_pixel/8); fix->visual = default_var.bits_per_pixel <= 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; return 0;}static int igafb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info){ if(con == -1) memcpy(var, &default_var, sizeof(struct fb_var_screeninfo)); else *var = fb_display[con].var; return 0;}static int igafb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info){ memcpy(var, &default_var, sizeof(struct fb_var_screeninfo)); return 0;}#ifdef __sparc__static int igafb_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma){ struct fb_info_iga *fb = (struct fb_info_iga *)info; unsigned int size, page, map_size = 0; unsigned long map_offset = 0; int i; if (!fb->mmap_map) return -ENXIO; size = vma->vm_end - vma->vm_start; /* To stop the swapper from even considering these pages. */ vma->vm_flags |= (VM_SHM | VM_LOCKED); /* Each page, see which map applies */ for (page = 0; page < size; ) { map_size = 0; for (i = 0; fb->mmap_map[i].size; i++) { unsigned long start = fb->mmap_map[i].voff; unsigned long end = start + fb->mmap_map[i].size; unsigned long offset = (vma->vm_pgoff << PAGE_SHIFT) + page; if (start > offset) continue; if (offset >= end) continue; map_size = fb->mmap_map[i].size - (offset - start); map_offset = fb->mmap_map[i].poff + (offset - start); break; } if (!map_size) { page += PAGE_SIZE; continue; } if (page + map_size > size) map_size = size - page; pgprot_val(vma->vm_page_prot) &= ~(fb->mmap_map[i].prot_mask); pgprot_val(vma->vm_page_prot) |= fb->mmap_map[i].prot_flag; if (remap_page_range(vma->vm_start + page, map_offset, map_size, vma->vm_page_prot)) return -EAGAIN; page += map_size; } if (!map_size) return -EINVAL; if (!fb->mmaped) { int lastconsole = 0; if (info->display_fg) lastconsole = info->display_fg->vc_num; fb->mmaped = 1; if (fb->consolecnt && fb_display[lastconsole].fb_info ==info) { fb->vtconsole = lastconsole; vt_cons[lastconsole]->vc_mode = KD_GRAPHICS; } } return 0;}#endif /* __sparc__ */static int iga_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *fb_info){ /* * Read a single color register and split it into colors/transparent. * Return != 0 for invalid regno. */ struct fb_info_iga *info = (struct fb_info_iga*) fb_info; if (regno >= info->video_cmap_len) return 1; *red = info->palette[regno].red; *green = info->palette[regno].green; *blue = info->palette[regno].blue; *transp = 0; return 0;}static int iga_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *fb_info){ /* * Set a single color register. The values supplied are * already rounded down to the hardware's capabilities * (according to the entries in the `var' structure). Return * != 0 for invalid regno. */ struct fb_info_iga *info = (struct fb_info_iga*) fb_info; if (regno >= info->video_cmap_len) return 1; info->palette[regno].red = red; info->palette[regno].green = green; info->palette[regno].blue = blue; pci_outb(info, regno, DAC_W_INDEX); pci_outb(info, red, DAC_DATA); pci_outb(info, green, DAC_DATA); pci_outb(info, blue, DAC_DATA); if (regno < 16) { switch (default_var.bits_per_pixel) {#ifdef FBCON_HAS_CFB16 case 16: info->fbcon_cmap.cfb16[regno] = (regno << 10) | (regno << 5) | regno; break;#endif#ifdef FBCON_HAS_CFB24 case 24: info->fbcon_cmap.cfb24[regno] = (regno << 16) | (regno << 8) | regno; break;#endif#ifdef FBCON_HAS_CFB32 case 32: { int i; i = (regno << 8) | regno; info->fbcon_cmap.cfb32[regno] = (i << 16) | i; } break;#endif } } return 0;}static void do_install_cmap(int con, struct fb_info *fb_info){ struct fb_info_iga *info = (struct fb_info_iga*) fb_info; if (con != info->currcon) return; if (fb_display[con].cmap.len) fb_set_cmap(&fb_display[con].cmap, 1, iga_setcolreg, &info->fb_info); else fb_set_cmap(fb_default_cmap(info->video_cmap_len), 1, iga_setcolreg, &info->fb_info);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -