📄 sticore.c
字号:
/* * linux/drivers/video/sti/sticore.c - * core code for console driver using HP's STI firmware * * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> * Portions Copyright (C) 2001-2002 Helge Deller <deller@gmx.de> * Portions Copyright (C) 2001-2002 Thomas Bogendoerfer <tsbogend@alpha.franken.de> * * TODO: * - call STI in virtual mode rather than in real mode * - screen blanking with state_mgmt() in text mode STI ? * - try to make it work on m68k hp workstations ;) * - clean up the cache flushing functions * */#include <linux/config.h>#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/init.h>#include <linux/pci.h>#include <video/font.h>#include <asm/pgalloc.h>#include <asm/hardware.h>#include "sticore.h"#define STI_DRIVERVERSION "0.9"struct sti_struct *default_sti;static int num_sti_roms; /* # of STI ROMS found */static struct sti_struct *sti_roms[MAX_STI_ROMS]; /* ptr to each sti_struct *//* The colour indices used by STI are * 0 - Black * 1 - White * 2 - Red * 3 - Yellow/Brown * 4 - Green * 5 - Cyan * 6 - Blue * 7 - Magenta * * So we have the same colours as VGA (basically one bit each for R, G, B), * but have to translate them, anyway. */static const u8 col_trans[8] = { 0, 6, 4, 5, 2, 7, 3, 1};#define c_fg(sti, c) col_trans[((c>> 8) & 7)]#define c_bg(sti, c) col_trans[((c>>11) & 7)]#define c_index(sti, c) ((c) & 0xff)static const struct sti_init_flags default_init_flags = { wait: STI_WAIT, reset: 1, text: 1, nontext:1, no_chg_bet: 1, no_chg_bei: 1, init_cmap_tx: 1,};intsti_init_graph(struct sti_struct *sti) { struct sti_init_inptr_ext inptr_ext = { 0, }; struct sti_init_inptr inptr = { 3, /* # of text planes (3 is maximum for STI) */ STI_PTR(&inptr_ext) }; struct sti_init_outptr outptr = { 0, }; unsigned long flags; int ret; spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->init_graph, &default_init_flags, &inptr, &outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); if (ret < 0) { printk(KERN_ERR "STI init_graph failed (ret %d, errno %d)\n",ret,outptr.errno); return -1; } sti->text_planes = outptr.text_planes; return 0;}static const struct sti_conf_flags default_conf_flags = { wait: STI_WAIT, };voidsti_inq_conf(struct sti_struct *sti){ struct sti_conf_inptr inptr = { 0 }; unsigned long flags; s32 ret; sti->outptr.ext_ptr = STI_PTR(&sti->outptr_ext); do { spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->inq_conf, &default_conf_flags, &inptr, &sti->outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1);}static const struct sti_font_flags default_font_flags = { wait: STI_WAIT, non_text: 0,};voidsti_putc(struct sti_struct *sti, int c, int y, int x){ struct sti_font_inptr inptr = { STI_PTR(sti->font->raw), c_index(sti, c), c_fg(sti, c), c_bg(sti, c), x * sti->font_width, y * sti->font_height, 0 }; struct sti_font_outptr outptr = { 0, }; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->font_unpmv, &default_font_flags, &inptr, &outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1);}static const struct sti_blkmv_flags clear_blkmv_flags = { wait: STI_WAIT, color: 1, clear: 1, };voidsti_set(struct sti_struct *sti, int src_y, int src_x, int height, int width, u8 color){ struct sti_blkmv_inptr inptr = { color, color, src_x, src_y , src_x, src_y , width, height, 0 }; struct sti_blkmv_outptr outptr = { 0, }; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->block_move, &clear_blkmv_flags, &inptr, &outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1);}voidsti_clear(struct sti_struct *sti, int src_y, int src_x, int height, int width, int c){ struct sti_blkmv_inptr inptr = { c_fg(sti, c), c_bg(sti, c), src_x * sti->font_width, src_y * sti->font_height, src_x * sti->font_width, src_y * sti->font_height, width * sti->font_width, height* sti->font_height, 0 }; struct sti_blkmv_outptr outptr = { 0, }; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->block_move, &clear_blkmv_flags, &inptr, &outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1);}static const struct sti_blkmv_flags default_blkmv_flags = { wait: STI_WAIT, };voidsti_bmove(struct sti_struct *sti, int src_y, int src_x, int dst_y, int dst_x, int height, int width){ struct sti_blkmv_inptr inptr = { 0, 0, src_x * sti->font_width, src_y * sti->font_height, dst_x * sti->font_width, dst_y * sti->font_height, width * sti->font_width, height* sti->font_height, 0 }; struct sti_blkmv_outptr outptr = { 0, }; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); ret = STI_CALL(sti->block_move, &default_blkmv_flags, &inptr, &outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1);}void __initsti_rom_copy(unsigned long base, unsigned long count, void *dest){ unsigned long dest_len = count; unsigned long dest_start = (unsigned long) dest; /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */ while (count >= 4) { count -= 4; *(u32 *)dest = __raw_readl(base); base += 4; dest += 4; } while (count) { count--; *(u8 *)dest = __raw_readb(base); base++; dest++; } sti_flush(dest_start, dest_len); /* XXX */}static char default_sti_path[21];static int __init sti_setup(char *str){ if (str) strncpy (default_sti_path, str, sizeof (default_sti_path)); return 0;}/* Assuming the machine has multiple STI consoles (=graphic cards) which * all get detected by sticon, the user may define with the linux kernel * parameter sti=<x> which of them will be the initial boot-console. * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default * STI screen. */__setup("sti=", sti_setup);static char __initdata *font_name[MAX_STI_ROMS] = { "VGA8x16", };static int __initdata font_index[MAX_STI_ROMS], font_height[MAX_STI_ROMS], font_width[MAX_STI_ROMS];static int __init sti_font_setup(char *str){ char *x; int i = 0; /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20 * or sti_font=7 style command lines. */ while (i<MAX_STI_ROMS && str && *str) { if (*str>='0' && *str<='9') { if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) { font_height[i] = simple_strtoul(str, NULL, 0); font_width[i] = simple_strtoul(x+1, NULL, 0); } else { font_index[i] = simple_strtoul(str, NULL, 0); } } else { font_name[i] = str; /* fb font name */ } if ((x = strchr(str, ','))) *x++ = 0; str = x; i++; } return 0;}/* The optional linux kernel parameter "sti_font" defines which font * should be used by the sticon driver to draw characters to the screen. * Possible values are: * - sti_font=<fb_fontname>: * <fb_fontname> is the name of one of the linux-kernel built-in * framebuffer font names (e.g. VGA8x16, SUN22x18). * This is only available if the fonts have been statically compiled * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options. * - sti_font=<number> * most STI ROMs have built-in HP specific fonts, which can be selected * by giving the desired number to the sticon driver. * NOTE: This number is machine and STI ROM dependend. * - sti_font=<height>x<width> (e.g. sti_font=16x8) * <height> and <width> gives hints to the height and width of the * font which the user wants. The sticon driver will try to use * a font with this height and width, but if no suitable font is * found, sticon will use the default 8x8 font. */__setup("sti_font=", sti_font_setup); void __initsti_dump_globcfg(struct sti_glob_cfg *glob_cfg, unsigned int sti_mem_request){ struct sti_glob_cfg_ext *cfg; DPRINTK((KERN_INFO "%d text planes\n" "%4d x %4d screen resolution\n" "%4d x %4d offscreen\n" "%4d x %4d layout\n" "regions at %08x %08x %08x %08x\n" "regions at %08x %08x %08x %08x\n" "reent_lvl %d\n" "save_addr %08x\n", glob_cfg->text_planes, glob_cfg->onscreen_x, glob_cfg->onscreen_y, glob_cfg->offscreen_x, glob_cfg->offscreen_y, glob_cfg->total_x, glob_cfg->total_y, glob_cfg->region_ptrs[0], glob_cfg->region_ptrs[1], glob_cfg->region_ptrs[2], glob_cfg->region_ptrs[3], glob_cfg->region_ptrs[4], glob_cfg->region_ptrs[5], glob_cfg->region_ptrs[6], glob_cfg->region_ptrs[7], glob_cfg->reent_lvl, glob_cfg->save_addr)); /* dump extended cfg */ cfg = PTR_STI(glob_cfg->ext_ptr); DPRINTK(( KERN_INFO "monitor %d\n" "in friendly mode: %d\n" "power consumption %d watts\n" "freq ref %d\n" "sti_mem_addr %08x (size=%d bytes)\n", cfg->curr_mon, cfg->friendly_boot, cfg->power, cfg->freq_ref, cfg->sti_mem_addr, sti_mem_request));}void __initsti_dump_outptr(struct sti_struct *sti){ DPRINTK((KERN_INFO "%d bits per pixel\n" "%d used bits\n" "%d planes\n" "attributes %08x\n", sti->outptr.bits_per_pixel, sti->outptr.bits_used, sti->outptr.planes, sti->outptr.attributes));}int __initsti_init_glob_cfg(struct sti_struct *sti, unsigned long rom_address, unsigned long hpa){ struct sti_glob_cfg *glob_cfg; struct sti_glob_cfg_ext *glob_cfg_ext; void *save_addr; void *sti_mem_addr; const int save_addr_size = 1024; /* XXX */ int i; if (!sti->sti_mem_request) sti->sti_mem_request = 256; /* STI default */ glob_cfg = kmalloc(sizeof(*sti->glob_cfg), GFP_KERNEL); glob_cfg_ext = kmalloc(sizeof(*glob_cfg_ext), GFP_KERNEL); save_addr = kmalloc(save_addr_size, GFP_KERNEL); sti_mem_addr = kmalloc(sti->sti_mem_request, GFP_KERNEL); if (!(glob_cfg && glob_cfg_ext && save_addr && sti_mem_addr)) return -ENOMEM; memset(glob_cfg, 0, sizeof(*glob_cfg)); memset(glob_cfg_ext, 0, sizeof(*glob_cfg_ext)); memset(save_addr, 0, save_addr_size); memset(sti_mem_addr, 0, sti->sti_mem_request); glob_cfg->ext_ptr = STI_PTR(glob_cfg_ext); glob_cfg->save_addr = STI_PTR(save_addr); for (i=0; i<8; i++) { unsigned long newhpa, len; if (sti->pd) { unsigned char offs = sti->rm_entry[i]; if (offs == 0) continue; if (offs != PCI_ROM_ADDRESS && (offs < PCI_BASE_ADDRESS_0 || offs > PCI_BASE_ADDRESS_5)) { printk (KERN_WARNING "STI pci region maping for region %d (%02x) can't be mapped\n", i,sti->rm_entry[i]); continue; } newhpa = pci_resource_start (sti->pd, (offs - PCI_BASE_ADDRESS_0) / 4); } else newhpa = (i == 0) ? rom_address : hpa; sti->regions_phys[i] = REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa); /* remap virtually */ /* FIXME: add BTLB support if btlb==1 */ len = sti->regions[i].region_desc.length * 4096; if (len) glob_cfg->region_ptrs[i] = (unsigned long) ( sti->regions[i].region_desc.cache ? ioremap(sti->regions_phys[i], len) : ioremap_nocache(sti->regions_phys[i], len) ); DPRINTK(("region #%d: phys %08lx, virt %08x, len=%lukB, " "btlb=%d, sysonly=%d, cache=%d, last=%d\n", i, sti->regions_phys[i], glob_cfg->region_ptrs[i], len/1024, sti->regions[i].region_desc.btlb, sti->regions[i].region_desc.sys_only, sti->regions[i].region_desc.cache, sti->regions[i].region_desc.last)); /* last entry reached ? */ if (sti->regions[i].region_desc.last) break; } if (++i<8 && sti->regions[i].region) printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n", __FILE__, sti->regions[i].region); glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr); sti->glob_cfg = glob_cfg; return 0;}#ifdef CONFIG_FBstruct sti_cooked_font * __initsti_select_fbfont( struct sti_cooked_rom *cooked_rom, char *fbfont_name ){ struct fbcon_font_desc *fbfont; unsigned int size, bpc; void *dest; struct sti_rom_font *nf; struct sti_cooked_font *cooked_font; if (!fbfont_name || !strlen(fbfont_name)) return NULL; fbfont = fbcon_find_font(fbfont_name); if (!fbfont) fbfont = fbcon_get_default_font(1024,768); if (!fbfont) return NULL; DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n", fbfont->width, fbfont->height, fbfont->name)); bpc = ((fbfont->width+7)/8) * fbfont->height; size = bpc * 256; size += sizeof(struct sti_rom_font); nf = kmalloc(size, GFP_KERNEL); if (!nf) return NULL; memset(nf, 0, size); nf->first_char = 0; nf->last_char = 255; nf->width = fbfont->width; nf->height = fbfont->height; nf->font_type = STI_FONT_HPROMAN8; nf->bytes_per_char = bpc; nf->next_font = 0; nf->underline_height = 1; nf->underline_pos = fbfont->height - nf->underline_height; dest = nf; dest += sizeof(struct sti_rom_font); memcpy(dest, fbfont->data, bpc*256); cooked_font = kmalloc(sizeof(*cooked_font), GFP_KERNEL); if (!cooked_font) { kfree(nf); return NULL; } cooked_font->raw = nf; cooked_font->next_font = NULL; cooked_rom->font_start = cooked_font; return cooked_font;}#elsestruct sti_cooked_font * __initsti_select_fbfont(struct sti_cooked_rom *cooked_rom, char *fbfont_name){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -