cregit-Linux how code gets into the kernel

Release 4.14 drivers/video/console/sticore.c

/*
 *  linux/drivers/video/console/sticore.c -
 *      core code for console driver using HP's STI firmware
 *
 *      Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
 *      Copyright (C) 2001-2013 Helge Deller <deller@gmx.de>
 *      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 ;)
 * 
 */

#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 <linux/font.h>

#include <asm/hardware.h>
#include <asm/page.h>
#include <asm/parisc-device.h>
#include <asm/pdc.h>
#include <asm/cacheflush.h>
#include <asm/grfioctl.h>

#include "../fbdev/sticore.h"


#define STI_DRIVERVERSION "Version 0.9b"


static struct sti_struct *default_sti __read_mostly;

/* number of STI ROMS found and their ptrs to each struct */

static int num_sti_roms __read_mostly;

static struct sti_struct *sti_roms[MAX_STI_ROMS] __read_mostly;


/* 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,
};


static int sti_init_graph(struct sti_struct *sti) { struct sti_init_inptr *inptr = &sti->sti_data->init_inptr; struct sti_init_inptr_ext *inptr_ext = &sti->sti_data->init_inptr_ext; struct sti_init_outptr *outptr = &sti->sti_data->init_outptr; unsigned long flags; int ret, err; spin_lock_irqsave(&sti->lock, flags); memset(inptr, 0, sizeof(*inptr)); inptr->text_planes = 3; /* # of text planes (max 3 for STI) */ memset(inptr_ext, 0, sizeof(*inptr_ext)); inptr->ext_ptr = STI_PTR(inptr_ext); outptr->errno = 0; ret = sti_call(sti, sti->init_graph, &default_init_flags, inptr, outptr, sti->glob_cfg); if (ret >= 0) sti->text_planes = outptr->text_planes; err = outptr->errno; spin_unlock_irqrestore(&sti->lock, flags); if (ret < 0) { pr_err("STI init_graph failed (ret %d, errno %d)\n", ret, err); return -1; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Helge Deller10052.63%125.00%
Linus Torvalds (pre-git)6534.21%125.00%
James Simmons2312.11%125.00%
Adrian Bunk21.05%125.00%
Total190100.00%4100.00%

static const struct sti_conf_flags default_conf_flags = { .wait = STI_WAIT, };
static void sti_inq_conf(struct sti_struct *sti) { struct sti_conf_inptr *inptr = &sti->sti_data->inq_inptr; struct sti_conf_outptr *outptr = &sti->sti_data->inq_outptr; unsigned long flags; s32 ret; outptr->ext_ptr = STI_PTR(&sti->sti_data->inq_outptr_ext); do { spin_lock_irqsave(&sti->lock, flags); memset(inptr, 0, sizeof(*inptr)); ret = sti_call(sti, sti->inq_conf, &default_conf_flags, inptr, outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)6957.02%120.00%
Helge Deller3932.23%120.00%
James Simmons119.09%240.00%
Adrian Bunk21.65%120.00%
Total121100.00%5100.00%

static const struct sti_font_flags default_font_flags = { .wait = STI_WAIT, .non_text = 0, };
void sti_putc(struct sti_struct *sti, int c, int y, int x) { struct sti_font_inptr *inptr = &sti->sti_data->font_inptr; struct sti_font_inptr inptr_default = { .font_start_addr= STI_PTR(sti->font->raw), .index = c_index(sti, c), .fg_color = c_fg(sti, c), .bg_color = c_bg(sti, c), .dest_x = x * sti->font_width, .dest_y = y * sti->font_height, }; struct sti_font_outptr *outptr = &sti->sti_data->font_outptr; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); *inptr = inptr_default; ret = sti_call(sti, sti->font_unpmv, &default_font_flags, inptr, outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11868.21%125.00%
James Simmons2816.18%250.00%
Helge Deller2715.61%125.00%
Total173100.00%4100.00%

static const struct sti_blkmv_flags clear_blkmv_flags = { .wait = STI_WAIT, .color = 1, .clear = 1, };
void sti_set(struct sti_struct *sti, int src_y, int src_x, int height, int width, u8 color) { struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr; struct sti_blkmv_inptr inptr_default = { .fg_color = color, .bg_color = color, .src_x = src_x, .src_y = src_y, .dest_x = src_x, .dest_y = src_y, .width = width, .height = height, }; struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); *inptr = inptr_default; ret = sti_call(sti, sti->block_move, &clear_blkmv_flags, inptr, outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10767.30%133.33%
Helge Deller2716.98%133.33%
James Simmons2515.72%133.33%
Total159100.00%3100.00%


void sti_clear(struct sti_struct *sti, int src_y, int src_x, int height, int width, int c) { struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr; struct sti_blkmv_inptr inptr_default = { .fg_color = c_fg(sti, c), .bg_color = c_bg(sti, c), .src_x = src_x * sti->font_width, .src_y = src_y * sti->font_height, .dest_x = src_x * sti->font_width, .dest_y = src_y * sti->font_height, .width = width * sti->font_width, .height = height* sti->font_height, }; struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); *inptr = inptr_default; ret = sti_call(sti, sti->block_move, &clear_blkmv_flags, inptr, outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11157.51%125.00%
James Simmons5528.50%250.00%
Helge Deller2713.99%125.00%
Total193100.00%4100.00%

static const struct sti_blkmv_flags default_blkmv_flags = { .wait = STI_WAIT, };
void sti_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 = &sti->sti_data->blkmv_inptr; struct sti_blkmv_inptr inptr_default = { .src_x = src_x * sti->font_width, .src_y = src_y * sti->font_height, .dest_x = dst_x * sti->font_width, .dest_y = dst_y * sti->font_height, .width = width * sti->font_width, .height = height* sti->font_height, }; struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr; s32 ret; unsigned long flags; do { spin_lock_irqsave(&sti->lock, flags); *inptr = inptr_default; ret = sti_call(sti, sti->block_move, &default_blkmv_flags, inptr, outptr, sti->glob_cfg); spin_unlock_irqrestore(&sti->lock, flags); } while (ret == 1); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11867.05%125.00%
James Simmons3117.61%250.00%
Helge Deller2715.34%125.00%
Total176100.00%4100.00%


static void sti_flush(unsigned long start, unsigned long end) { flush_icache_range(start, end); }

Contributors

PersonTokensPropCommitsCommitProp
James Simmons1780.95%150.00%
Kyle McMartin419.05%150.00%
Total21100.00%2100.00%


static void sti_rom_copy(unsigned long base, unsigned long count, void *dest) { 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 = gsc_readl(base); base += 4; dest += 4; } while (count) { count--; *(u8 *)dest = gsc_readb(base); base++; dest++; } sti_flush(dest_start, (unsigned long)dest); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)7878.79%120.00%
James Simmons1313.13%120.00%
Kyle McMartin55.05%120.00%
Matthew Wilcox22.02%120.00%
Adrian Bunk11.01%120.00%
Total99100.00%5100.00%

static char default_sti_path[21] __read_mostly; #ifndef MODULE
static int __init sti_setup(char *str) { if (str) strlcpy (default_sti_path, str, sizeof (default_sti_path)); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
James Simmons1756.67%120.00%
Linus Torvalds (pre-git)1033.33%120.00%
Hirofumi Ogawa13.33%120.00%
Helge Deller13.33%120.00%
Benjamin Collins13.33%120.00%
Total30100.00%5100.00%

/* 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); #endif static char *font_name[MAX_STI_ROMS]; static int font_index[MAX_STI_ROMS], font_height[MAX_STI_ROMS], font_width[MAX_STI_ROMS]; #ifndef MODULE
static int 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 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9559.38%133.33%
James Simmons6440.00%133.33%
Hirofumi Ogawa10.62%133.33%
Total160100.00%3100.00%

/* 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); #endif
static void sti_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((unsigned long)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)); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10358.86%125.00%
James Simmons6838.86%250.00%
Helge Deller42.29%125.00%
Total175100.00%4100.00%


static void sti_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->sti_data->inq_outptr.bits_per_pixel, sti->sti_data->inq_outptr.bits_used, sti->sti_data->inq_outptr.planes, sti->sti_data->inq_outptr.attributes)); }

Contributors

PersonTokensPropCommitsCommitProp
James Simmons4175.93%250.00%
Helge Deller1222.22%125.00%
Linus Torvalds (pre-git)11.85%125.00%
Total54100.00%4100.00%


static int sti_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; int i, size; if (sti->sti_mem_request < 256) sti->sti_mem_request = 256; /* STI default */ size = sizeof(struct sti_all_data) + sti->sti_mem_request - 256; sti->sti_data = kzalloc(size, STI_LOWMEM); if (