📄 tdfxfb.c
字号:
/* * * tdfxfb.c * * Author: Hannu Mallat <hmallat@cc.hut.fi> * * Copyright © 1999 Hannu Mallat * All rights reserved * * Created : Thu Sep 23 18:17:43 1999, hmallat * Last modified: Tue Nov 2 21:19:47 1999, hmallat * * Lots of the information here comes from the Daryll Strauss' Banshee * patches to the XF86 server, and the rest comes from the 3dfx * Banshee specification. I'm very much indebted to Daryll for his * work on the X server. * * Voodoo3 support was contributed Harold Oga. Lots of additions * (proper acceleration, 24 bpp, hardware cursor) and bug fixes by Attila * Kesmarki. Thanks guys! * * Voodoo1 and Voodoo2 support aren't relevant to this driver as they * behave very differently from the Voodoo3/4/5. For anyone wanting to * use frame buffer on the Voodoo1/2, see the sstfb driver (which is * located at http://www.sourceforge.net/projects/sstfb). * * While I _am_ grateful to 3Dfx for releasing the specs for Banshee, * I do wish the next version is a bit more complete. Without the XF86 * patches I couldn't have gotten even this far... for instance, the * extensions to the VGA register set go completely unmentioned in the * spec! Also, lots of references are made to the 'SST core', but no * spec is publicly available, AFAIK. * * The structure of this driver comes pretty much from the Permedia * driver by Ilario Nardinocchi, which in turn is based on skeletonfb. * * TODO: * - multihead support (basically need to support an array of fb_infos) * - support other architectures (PPC, Alpha); does the fact that the VGA * core can be accessed only thru I/O (not memory mapped) complicate * things? * * Version history: * * 0.1.4 (released 2002-05-28) ported over to new fbdev api by James Simmons * * 0.1.3 (released 1999-11-02) added Attila's panning support, code * reorg, hwcursor address page size alignment * (for mmaping both frame buffer and regs), * and my changes to get rid of hardcoded * VGA i/o register locations (uses PCI * configuration info now) * 0.1.2 (released 1999-10-19) added Attila Kesmarki's bug fixes and * improvements * 0.1.1 (released 1999-10-07) added Voodoo3 support by Harold Oga. * 0.1.0 (released 1999-10-06) initial version * */#include <linux/module.h>#include <linux/kernel.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/slab.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/pci.h>#include <asm/io.h>#include <video/tdfx.h>#define DPRINTK(a, b...) pr_debug("fb: %s: " a, __func__ , ## b)#ifdef CONFIG_MTRR#include <asm/mtrr.h>#else/* duplicate asm/mtrr.h defines to work on archs without mtrr */#define MTRR_TYPE_WRCOMB 1static inline int mtrr_add(unsigned long base, unsigned long size, unsigned int type, char increment){ return -ENODEV;}static inline int mtrr_del(int reg, unsigned long base, unsigned long size){ return -ENODEV;}#endif#define BANSHEE_MAX_PIXCLOCK 270000#define VOODOO3_MAX_PIXCLOCK 300000#define VOODOO5_MAX_PIXCLOCK 350000static struct fb_fix_screeninfo tdfx_fix __devinitdata = { .type = FB_TYPE_PACKED_PIXELS, .visual = FB_VISUAL_PSEUDOCOLOR, .ypanstep = 1, .ywrapstep = 1, .accel = FB_ACCEL_3DFX_BANSHEE};static struct fb_var_screeninfo tdfx_var __devinitdata = { /* "640x480, 8 bpp @ 60 Hz */ .xres = 640, .yres = 480, .xres_virtual = 640, .yres_virtual = 1024, .bits_per_pixel = 8, .red = {0, 8, 0}, .blue = {0, 8, 0}, .green = {0, 8, 0}, .activate = FB_ACTIVATE_NOW, .height = -1, .width = -1, .accel_flags = FB_ACCELF_TEXT, .pixclock = 39722, .left_margin = 40, .right_margin = 24, .upper_margin = 32, .lower_margin = 11, .hsync_len = 96, .vsync_len = 2, .vmode = FB_VMODE_NONINTERLACED};/* * PCI driver prototypes */static int __devinit tdfxfb_probe(struct pci_dev *pdev, const struct pci_device_id *id);static void __devexit tdfxfb_remove(struct pci_dev *pdev);static struct pci_device_id tdfxfb_id_table[] = { { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO5, PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 0xff0000, 0 }, { 0, }};static struct pci_driver tdfxfb_driver = { .name = "tdfxfb", .id_table = tdfxfb_id_table, .probe = tdfxfb_probe, .remove = __devexit_p(tdfxfb_remove),};MODULE_DEVICE_TABLE(pci, tdfxfb_id_table);/* * Driver data */static int nopan;static int nowrap = 1; /* not implemented (yet) */static int hwcursor = 1;static char *mode_option __devinitdata;/* mtrr option */static int nomtrr __devinitdata;/* ------------------------------------------------------------------------- * Hardware-specific funcions * ------------------------------------------------------------------------- */static inline u8 vga_inb(struct tdfx_par *par, u32 reg){ return inb(par->iobase + reg - 0x300);}static inline void vga_outb(struct tdfx_par *par, u32 reg, u8 val){ outb(val, par->iobase + reg - 0x300);}static inline void gra_outb(struct tdfx_par *par, u32 idx, u8 val){ vga_outb(par, GRA_I, idx); wmb(); vga_outb(par, GRA_D, val); wmb();}static inline void seq_outb(struct tdfx_par *par, u32 idx, u8 val){ vga_outb(par, SEQ_I, idx); wmb(); vga_outb(par, SEQ_D, val); wmb();}static inline u8 seq_inb(struct tdfx_par *par, u32 idx){ vga_outb(par, SEQ_I, idx); mb(); return vga_inb(par, SEQ_D);}static inline void crt_outb(struct tdfx_par *par, u32 idx, u8 val){ vga_outb(par, CRT_I, idx); wmb(); vga_outb(par, CRT_D, val); wmb();}static inline u8 crt_inb(struct tdfx_par *par, u32 idx){ vga_outb(par, CRT_I, idx); mb(); return vga_inb(par, CRT_D);}static inline void att_outb(struct tdfx_par *par, u32 idx, u8 val){ unsigned char tmp; tmp = vga_inb(par, IS1_R); vga_outb(par, ATT_IW, idx); vga_outb(par, ATT_IW, val);}static inline void vga_disable_video(struct tdfx_par *par){ unsigned char s; s = seq_inb(par, 0x01) | 0x20; seq_outb(par, 0x00, 0x01); seq_outb(par, 0x01, s); seq_outb(par, 0x00, 0x03);}static inline void vga_enable_video(struct tdfx_par *par){ unsigned char s; s = seq_inb(par, 0x01) & 0xdf; seq_outb(par, 0x00, 0x01); seq_outb(par, 0x01, s); seq_outb(par, 0x00, 0x03);}static inline void vga_enable_palette(struct tdfx_par *par){ vga_inb(par, IS1_R); mb(); vga_outb(par, ATT_IW, 0x20);}static inline u32 tdfx_inl(struct tdfx_par *par, unsigned int reg){ return readl(par->regbase_virt + reg);}static inline void tdfx_outl(struct tdfx_par *par, unsigned int reg, u32 val){ writel(val, par->regbase_virt + reg);}static inline void banshee_make_room(struct tdfx_par *par, int size){ /* Note: The Voodoo3's onboard FIFO has 32 slots. This loop * won't quit if you ask for more. */ while ((tdfx_inl(par, STATUS) & 0x1f) < size - 1) cpu_relax();}static int banshee_wait_idle(struct fb_info *info){ struct tdfx_par *par = info->par; int i = 0; banshee_make_room(par, 1); tdfx_outl(par, COMMAND_3D, COMMAND_3D_NOP); do { if ((tdfx_inl(par, STATUS) & STATUS_BUSY) == 0) i++; } while (i < 3); return 0;}/* * Set the color of a palette entry in 8bpp mode */static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c){ banshee_make_room(par, 2); tdfx_outl(par, DACADDR, regno); /* read after write makes it working */ tdfx_inl(par, DACADDR); tdfx_outl(par, DACDATA, c);}static u32 do_calc_pll(int freq, int *freq_out){ int m, n, k, best_m, best_n, best_k, best_error; int fref = 14318; best_error = freq; best_n = best_m = best_k = 0; for (k = 3; k >= 0; k--) { for (m = 63; m >= 0; m--) { /* * Estimate value of n that produces target frequency * with current m and k */ int n_estimated = ((freq * (m + 2) << k) / fref) - 2; /* Search neighborhood of estimated n */ for (n = max(0, n_estimated); n <= min(255, n_estimated + 1); n++) { /* * Calculate PLL freqency with current m, k and * estimated n */ int f = (fref * (n + 2) / (m + 2)) >> k; int error = abs(f - freq); /* * If this is the closest we've come to the * target frequency then remember n, m and k */ if (error < best_error) { best_error = error; best_n = n; best_m = m; best_k = k; } } } } n = best_n; m = best_m; k = best_k; *freq_out = (fref * (n + 2) / (m + 2)) >> k; return (n << 8) | (m << 2) | k;}static void do_write_regs(struct fb_info *info, struct banshee_reg *reg){ struct tdfx_par *par = info->par; int i; banshee_wait_idle(info); tdfx_outl(par, MISCINIT1, tdfx_inl(par, MISCINIT1) | 0x01); crt_outb(par, 0x11, crt_inb(par, 0x11) & 0x7f); /* CRT unprotect */ banshee_make_room(par, 3); tdfx_outl(par, VGAINIT1, reg->vgainit1 & 0x001FFFFF); tdfx_outl(par, VIDPROCCFG, reg->vidcfg & ~0x00000001);#if 0 tdfx_outl(par, PLLCTRL1, reg->mempll); tdfx_outl(par, PLLCTRL2, reg->gfxpll);#endif tdfx_outl(par, PLLCTRL0, reg->vidpll); vga_outb(par, MISC_W, reg->misc[0x00] | 0x01); for (i = 0; i < 5; i++) seq_outb(par, i, reg->seq[i]); for (i = 0; i < 25; i++) crt_outb(par, i, reg->crt[i]); for (i = 0; i < 9; i++) gra_outb(par, i, reg->gra[i]); for (i = 0; i < 21; i++) att_outb(par, i, reg->att[i]); crt_outb(par, 0x1a, reg->ext[0]); crt_outb(par, 0x1b, reg->ext[1]); vga_enable_palette(par); vga_enable_video(par); banshee_make_room(par, 9); tdfx_outl(par, VGAINIT0, reg->vgainit0); tdfx_outl(par, DACMODE, reg->dacmode); tdfx_outl(par, VIDDESKSTRIDE, reg->stride); tdfx_outl(par, HWCURPATADDR, reg->curspataddr); tdfx_outl(par, VIDSCREENSIZE, reg->screensize); tdfx_outl(par, VIDDESKSTART, reg->startaddr); tdfx_outl(par, VIDPROCCFG, reg->vidcfg); tdfx_outl(par, VGAINIT1, reg->vgainit1); tdfx_outl(par, MISCINIT0, reg->miscinit0); banshee_make_room(par, 8); tdfx_outl(par, SRCBASE, reg->startaddr); tdfx_outl(par, DSTBASE, reg->startaddr); tdfx_outl(par, COMMANDEXTRA_2D, 0); tdfx_outl(par, CLIP0MIN, 0); tdfx_outl(par, CLIP0MAX, 0x0fff0fff); tdfx_outl(par, CLIP1MIN, 0); tdfx_outl(par, CLIP1MAX, 0x0fff0fff); tdfx_outl(par, SRCXY, 0); banshee_wait_idle(info);}static unsigned long do_lfb_size(struct tdfx_par *par, unsigned short dev_id){ u32 draminit0 = tdfx_inl(par, DRAMINIT0); u32 draminit1 = tdfx_inl(par, DRAMINIT1); u32 miscinit1; int num_chips = (draminit0 & DRAMINIT0_SGRAM_NUM) ? 8 : 4; int chip_size; /* in MB */ int has_sgram = draminit1 & DRAMINIT1_MEM_SDRAM; if (dev_id < PCI_DEVICE_ID_3DFX_VOODOO5) { /* Banshee/Voodoo3 */ chip_size = 2; if (has_sgram && !(draminit0 & DRAMINIT0_SGRAM_TYPE)) chip_size = 1; } else { /* Voodoo4/5 */ has_sgram = 0; chip_size = draminit0 & DRAMINIT0_SGRAM_TYPE_MASK; chip_size = 1 << (chip_size >> DRAMINIT0_SGRAM_TYPE_SHIFT); } /* disable block writes for SDRAM */ miscinit1 = tdfx_inl(par, MISCINIT1); miscinit1 |= has_sgram ? 0 : MISCINIT1_2DBLOCK_DIS; miscinit1 |= MISCINIT1_CLUT_INV; banshee_make_room(par, 1); tdfx_outl(par, MISCINIT1, miscinit1); return num_chips * chip_size * 1024l * 1024;}/* ------------------------------------------------------------------------- */static int tdfxfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){ struct tdfx_par *par = info->par; u32 lpitch; if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && var->bits_per_pixel != 24 && var->bits_per_pixel != 32) { DPRINTK("depth not supported: %u\n", var->bits_per_pixel); return -EINVAL; } if (var->xres != var->xres_virtual) var->xres_virtual = var->xres; if (var->yres > var->yres_virtual) var->yres_virtual = var->yres; if (var->xoffset) { DPRINTK("xoffset not supported\n"); return -EINVAL; } var->yoffset = 0; /* * Banshee doesn't support interlace, but Voodoo4/5 and probably * Voodoo3 do. * no direct information about device id now? * use max_pixclock for this... */ if (((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) &&
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -