diff options
Diffstat (limited to '')
-rw-r--r-- | drivers/video/console/Kconfig | 151 | ||||
-rw-r--r-- | drivers/video/console/Makefile | 12 | ||||
-rw-r--r-- | drivers/video/console/dummycon.c | 146 | ||||
-rw-r--r-- | drivers/video/console/mdacon.c | 578 | ||||
-rw-r--r-- | drivers/video/console/newport_con.c | 745 | ||||
-rw-r--r-- | drivers/video/console/sticon.c | 408 | ||||
-rw-r--r-- | drivers/video/console/sticore.c | 1172 | ||||
-rw-r--r-- | drivers/video/console/vgacon.c | 1207 |
8 files changed, 4419 insertions, 0 deletions
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig new file mode 100644 index 000000000..22cea5082 --- /dev/null +++ b/drivers/video/console/Kconfig @@ -0,0 +1,151 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Video configuration +# + +menu "Console display driver support" + +config VGA_CONSOLE + bool "VGA text console" if EXPERT || !X86 + depends on !4xx && !PPC_8xx && !SPARC && !M68K && !PARISC && !SUPERH && \ + (!ARM || ARCH_FOOTBRIDGE || ARCH_INTEGRATOR || ARCH_NETWINDER) && \ + !ARM64 && !ARC && !MICROBLAZE && !OPENRISC && !S390 && !UML + select APERTURE_HELPERS if (DRM || FB || VFIO_PCI_CORE) + default y + help + Saying Y here will allow you to use Linux in text mode through a + display that complies with the generic VGA standard. Virtually + everyone wants that. + + The program SVGATextMode can be used to utilize SVGA video cards to + their full potential in text mode. Download it from + <ftp://ibiblio.org/pub/Linux/utils/console/>. + + Say Y. + +config MDA_CONSOLE + depends on !M68K && !PARISC && ISA + tristate "MDA text console (dual-headed)" + help + Say Y here if you have an old MDA or monochrome Hercules graphics + adapter in your system acting as a second head ( = video card). You + will then be able to use two monitors with your Linux system. Do not + say Y here if your MDA card is the primary card in your system; the + normal VGA driver will handle it. + + To compile this driver as a module, choose M here: the + module will be called mdacon. + + If unsure, say N. + +config SGI_NEWPORT_CONSOLE + tristate "SGI Newport Console support" + depends on SGI_IP22 && HAS_IOMEM + select FONT_SUPPORT + help + Say Y here if you want the console on the Newport aka XL graphics + card of your Indy. Most people say Y here. + +config DUMMY_CONSOLE + bool + default y + +config DUMMY_CONSOLE_COLUMNS + int "Initial number of console screen columns" + depends on DUMMY_CONSOLE && !ARM + default 160 if PARISC + default 80 + help + On PA-RISC, the default value is 160, which should fit a 1280x1024 + monitor. + Select 80 if you use a 640x480 resolution by default. + +config DUMMY_CONSOLE_ROWS + int "Initial number of console screen rows" + depends on DUMMY_CONSOLE && !ARM + default 64 if PARISC + default 25 + help + On PA-RISC, the default value is 64, which should fit a 1280x1024 + monitor. + Select 25 if you use a 640x480 resolution by default. + +config FRAMEBUFFER_CONSOLE + bool "Framebuffer Console support" + depends on FB && !UML + select VT_HW_CONSOLE_BINDING + select CRC32 + select FONT_SUPPORT + help + Low-level framebuffer-based console driver. + +config FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION + bool "Enable legacy fbcon hardware acceleration code" + depends on FRAMEBUFFER_CONSOLE + default y if PARISC + default n + help + This option enables the fbcon (framebuffer text-based) hardware + acceleration for graphics drivers which were written for the fbdev + graphics interface. + + On modern machines, on mainstream machines (like x86-64) or when + using a modern Linux distribution those fbdev drivers usually aren't used. + So enabling this option wouldn't have any effect, which is why you want + to disable this option on such newer machines. + + If you compile this kernel for older machines which still require the + fbdev drivers, you may want to say Y. + + If unsure, select n. + +config FRAMEBUFFER_CONSOLE_DETECT_PRIMARY + bool "Map the console to the primary display device" + depends on FRAMEBUFFER_CONSOLE + default n + help + If this option is selected, the framebuffer console will + automatically select the primary display device (if the architecture + supports this feature). Otherwise, the framebuffer console will + always select the first framebuffer driver that is loaded. The latter + is the default behavior. + + You can always override the automatic selection of the primary device + by using the fbcon=map: boot option. + + If unsure, select n. + +config FRAMEBUFFER_CONSOLE_ROTATION + bool "Framebuffer Console Rotation" + depends on FRAMEBUFFER_CONSOLE + help + Enable display rotation for the framebuffer console. This is done + in software and may be significantly slower than a normally oriented + display. Note that the rotation is done at the console level only + such that other users of the framebuffer will remain normally + oriented. + +config FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER + bool "Framebuffer Console Deferred Takeover" + depends on FB=y && FRAMEBUFFER_CONSOLE && DUMMY_CONSOLE + help + If enabled this defers the framebuffer console taking over the + console from the dummy console until the first text is displayed on + the console. This is useful in combination with the "quiet" kernel + commandline option to keep the framebuffer contents initially put up + by the firmware in place, rather then replacing the contents with a + black screen as soon as fbcon loads. + +config STI_CONSOLE + bool "STI text console" + depends on PARISC && HAS_IOMEM + select FONT_SUPPORT + select CRC32 + default y + help + The STI console is the builtin display/keyboard on HP-PARISC + machines. Say Y here to build support for it into your kernel. + The alternative is to use your primary serial port as a console. + +endmenu + diff --git a/drivers/video/console/Makefile b/drivers/video/console/Makefile new file mode 100644 index 000000000..db07b784b --- /dev/null +++ b/drivers/video/console/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for the Linux graphics to console drivers. +# 5 Aug 1999, James Simmons, <mailto:jsimmons@users.sf.net> +# Rewritten to use lists instead of if-statements. + +obj-$(CONFIG_DUMMY_CONSOLE) += dummycon.o +obj-$(CONFIG_SGI_NEWPORT_CONSOLE) += newport_con.o +obj-$(CONFIG_STI_CONSOLE) += sticon.o sticore.o +obj-$(CONFIG_VGA_CONSOLE) += vgacon.o +obj-$(CONFIG_MDA_CONSOLE) += mdacon.o + +obj-$(CONFIG_FB_STI) += sticore.o diff --git a/drivers/video/console/dummycon.c b/drivers/video/console/dummycon.c new file mode 100644 index 000000000..f1711b2f9 --- /dev/null +++ b/drivers/video/console/dummycon.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * linux/drivers/video/dummycon.c -- A dummy console driver + * + * To be used if there's no other console driver (e.g. for plain VGA text) + * available, usually until fbcon takes console over. + */ + +#include <linux/types.h> +#include <linux/kdev_t.h> +#include <linux/console.h> +#include <linux/vt_kern.h> +#include <linux/screen_info.h> +#include <linux/init.h> +#include <linux/module.h> + +/* + * Dummy console driver + */ + +#if defined(__arm__) +#define DUMMY_COLUMNS screen_info.orig_video_cols +#define DUMMY_ROWS screen_info.orig_video_lines +#else +/* set by Kconfig. Use 80x25 for 640x480 and 160x64 for 1280x1024 */ +#define DUMMY_COLUMNS CONFIG_DUMMY_CONSOLE_COLUMNS +#define DUMMY_ROWS CONFIG_DUMMY_CONSOLE_ROWS +#endif + +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER +/* These are both protected by the console_lock */ +static RAW_NOTIFIER_HEAD(dummycon_output_nh); +static bool dummycon_putc_called; + +void dummycon_register_output_notifier(struct notifier_block *nb) +{ + WARN_CONSOLE_UNLOCKED(); + + raw_notifier_chain_register(&dummycon_output_nh, nb); + + if (dummycon_putc_called) + nb->notifier_call(nb, 0, NULL); +} + +void dummycon_unregister_output_notifier(struct notifier_block *nb) +{ + WARN_CONSOLE_UNLOCKED(); + + raw_notifier_chain_unregister(&dummycon_output_nh, nb); +} + +static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) +{ + WARN_CONSOLE_UNLOCKED(); + + dummycon_putc_called = true; + raw_notifier_call_chain(&dummycon_output_nh, 0, NULL); +} + +static void dummycon_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos) +{ + int i; + + if (!dummycon_putc_called) { + /* Ignore erases */ + for (i = 0 ; i < count; i++) { + if (s[i] != vc->vc_video_erase_char) + break; + } + if (i == count) + return; + + dummycon_putc_called = true; + } + + raw_notifier_call_chain(&dummycon_output_nh, 0, NULL); +} + +static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch) +{ + /* Redraw, so that we get putc(s) for output done while blanked */ + return 1; +} +#else +static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) { } +static void dummycon_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos) { } +static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch) +{ + return 0; +} +#endif + +static const char *dummycon_startup(void) +{ + return "dummy device"; +} + +static void dummycon_init(struct vc_data *vc, int init) +{ + vc->vc_can_do_color = 1; + if (init) { + vc->vc_cols = DUMMY_COLUMNS; + vc->vc_rows = DUMMY_ROWS; + } else + vc_resize(vc, DUMMY_COLUMNS, DUMMY_ROWS); +} + +static void dummycon_deinit(struct vc_data *vc) { } +static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height, + int width) { } +static void dummycon_cursor(struct vc_data *vc, int mode) { } + +static bool dummycon_scroll(struct vc_data *vc, unsigned int top, + unsigned int bottom, enum con_scroll dir, + unsigned int lines) +{ + return false; +} + +static int dummycon_switch(struct vc_data *vc) +{ + return 0; +} + +/* + * The console `switch' structure for the dummy console + * + * Most of the operations are dummies. + */ + +const struct consw dummy_con = { + .owner = THIS_MODULE, + .con_startup = dummycon_startup, + .con_init = dummycon_init, + .con_deinit = dummycon_deinit, + .con_clear = dummycon_clear, + .con_putc = dummycon_putc, + .con_putcs = dummycon_putcs, + .con_cursor = dummycon_cursor, + .con_scroll = dummycon_scroll, + .con_switch = dummycon_switch, + .con_blank = dummycon_blank, +}; +EXPORT_SYMBOL_GPL(dummy_con); diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c new file mode 100644 index 000000000..ef29b3219 --- /dev/null +++ b/drivers/video/console/mdacon.c @@ -0,0 +1,578 @@ +/* + * linux/drivers/video/mdacon.c -- Low level MDA based console driver + * + * (c) 1998 Andrew Apted <ajapted@netspace.net.au> + * + * including portions (c) 1995-1998 Patrick Caulfield. + * + * slight improvements (c) 2000 Edward Betts <edward@debian.org> + * + * This file is based on the VGA console driver (vgacon.c): + * + * Created 28 Sep 1997 by Geert Uytterhoeven + * + * Rewritten by Martin Mares <mj@ucw.cz>, July 1998 + * + * and on the old console.c, vga.c and vesa_blank.c drivers: + * + * Copyright (C) 1991, 1992 Linus Torvalds + * 1995 Jay Estabrook + * + * 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. + * + * Changelog: + * Paul G. (03/2001) Fix mdacon= boot prompt to use __setup(). + */ + +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/console.h> +#include <linux/string.h> +#include <linux/kd.h> +#include <linux/vt_kern.h> +#include <linux/vt_buffer.h> +#include <linux/selection.h> +#include <linux/spinlock.h> +#include <linux/ioport.h> +#include <linux/delay.h> +#include <linux/init.h> + +#include <asm/io.h> +#include <asm/vga.h> + +static DEFINE_SPINLOCK(mda_lock); + +/* description of the hardware layout */ + +static u16 *mda_vram_base; /* Base of video memory */ +static unsigned long mda_vram_len; /* Size of video memory */ +static unsigned int mda_num_columns; /* Number of text columns */ +static unsigned int mda_num_lines; /* Number of text lines */ + +static unsigned int mda_index_port; /* Register select port */ +static unsigned int mda_value_port; /* Register value port */ +static unsigned int mda_mode_port; /* Mode control port */ +static unsigned int mda_status_port; /* Status and Config port */ +static unsigned int mda_gfx_port; /* Graphics control port */ + +/* current hardware state */ + +static int mda_cursor_loc=-1; +static int mda_cursor_size_from=-1; +static int mda_cursor_size_to=-1; + +static enum { TYPE_MDA, TYPE_HERC, TYPE_HERCPLUS, TYPE_HERCCOLOR } mda_type; +static char *mda_type_name; + +/* console information */ + +static int mda_first_vc = 13; +static int mda_last_vc = 16; + +static struct vc_data *mda_display_fg = NULL; + +module_param(mda_first_vc, int, 0); +MODULE_PARM_DESC(mda_first_vc, "First virtual console. Default: 13"); +module_param(mda_last_vc, int, 0); +MODULE_PARM_DESC(mda_last_vc, "Last virtual console. Default: 16"); + +/* MDA register values + */ + +#define MDA_CURSOR_BLINKING 0x00 +#define MDA_CURSOR_OFF 0x20 +#define MDA_CURSOR_SLOWBLINK 0x60 + +#define MDA_MODE_GRAPHICS 0x02 +#define MDA_MODE_VIDEO_EN 0x08 +#define MDA_MODE_BLINK_EN 0x20 +#define MDA_MODE_GFX_PAGE1 0x80 + +#define MDA_STATUS_HSYNC 0x01 +#define MDA_STATUS_VSYNC 0x80 +#define MDA_STATUS_VIDEO 0x08 + +#define MDA_CONFIG_COL132 0x08 +#define MDA_GFX_MODE_EN 0x01 +#define MDA_GFX_PAGE_EN 0x02 + + +/* + * MDA could easily be classified as "pre-dinosaur hardware". + */ + +static void write_mda_b(unsigned int val, unsigned char reg) +{ + unsigned long flags; + + spin_lock_irqsave(&mda_lock, flags); + + outb_p(reg, mda_index_port); + outb_p(val, mda_value_port); + + spin_unlock_irqrestore(&mda_lock, flags); +} + +static void write_mda_w(unsigned int val, unsigned char reg) +{ + unsigned long flags; + + spin_lock_irqsave(&mda_lock, flags); + + outb_p(reg, mda_index_port); outb_p(val >> 8, mda_value_port); + outb_p(reg+1, mda_index_port); outb_p(val & 0xff, mda_value_port); + + spin_unlock_irqrestore(&mda_lock, flags); +} + +#ifdef TEST_MDA_B +static int test_mda_b(unsigned char val, unsigned char reg) +{ + unsigned long flags; + + spin_lock_irqsave(&mda_lock, flags); + + outb_p(reg, mda_index_port); + outb (val, mda_value_port); + + udelay(20); val = (inb_p(mda_value_port) == val); + + spin_unlock_irqrestore(&mda_lock, flags); + return val; +} +#endif + +static inline void mda_set_cursor(unsigned int location) +{ + if (mda_cursor_loc == location) + return; + + write_mda_w(location >> 1, 0x0e); + + mda_cursor_loc = location; +} + +static inline void mda_set_cursor_size(int from, int to) +{ + if (mda_cursor_size_from==from && mda_cursor_size_to==to) + return; + + if (from > to) { + write_mda_b(MDA_CURSOR_OFF, 0x0a); /* disable cursor */ + } else { + write_mda_b(from, 0x0a); /* cursor start */ + write_mda_b(to, 0x0b); /* cursor end */ + } + + mda_cursor_size_from = from; + mda_cursor_size_to = to; +} + + +#ifndef MODULE +static int __init mdacon_setup(char *str) +{ + /* command line format: mdacon=<first>,<last> */ + + int ints[3]; + + str = get_options(str, ARRAY_SIZE(ints), ints); + + if (ints[0] < 2) + return 0; + + if (ints[1] < 1 || ints[1] > MAX_NR_CONSOLES || + ints[2] < 1 || ints[2] > MAX_NR_CONSOLES) + return 0; + + mda_first_vc = ints[1]; + mda_last_vc = ints[2]; + return 1; +} + +__setup("mdacon=", mdacon_setup); +#endif + +static int mda_detect(void) +{ + int count=0; + u16 *p, p_save; + u16 *q, q_save; + + /* do a memory check */ + + p = mda_vram_base; + q = mda_vram_base + 0x01000 / 2; + + p_save = scr_readw(p); + q_save = scr_readw(q); + + scr_writew(0xAA55, p); + if (scr_readw(p) == 0xAA55) + count++; + + scr_writew(0x55AA, p); + if (scr_readw(p) == 0x55AA) + count++; + + scr_writew(p_save, p); + + if (count != 2) { + return 0; + } + + /* check if we have 4K or 8K */ + + scr_writew(0xA55A, q); + scr_writew(0x0000, p); + if (scr_readw(q) == 0xA55A) + count++; + + scr_writew(0x5AA5, q); + scr_writew(0x0000, p); + if (scr_readw(q) == 0x5AA5) + count++; + + scr_writew(p_save, p); + scr_writew(q_save, q); + + if (count == 4) { + mda_vram_len = 0x02000; + } + + /* Ok, there is definitely a card registering at the correct + * memory location, so now we do an I/O port test. + */ + +#ifdef TEST_MDA_B + /* Edward: These two mess `tests' mess up my cursor on bootup */ + + /* cursor low register */ + if (!test_mda_b(0x66, 0x0f)) + return 0; + + /* cursor low register */ + if (!test_mda_b(0x99, 0x0f)) + return 0; +#endif + + /* See if the card is a Hercules, by checking whether the vsync + * bit of the status register is changing. This test lasts for + * approximately 1/10th of a second. + */ + + p_save = q_save = inb_p(mda_status_port) & MDA_STATUS_VSYNC; + + for (count = 0; count < 50000 && p_save == q_save; count++) { + q_save = inb(mda_status_port) & MDA_STATUS_VSYNC; + udelay(2); + } + + if (p_save != q_save) { + switch (inb_p(mda_status_port) & 0x70) { + case 0x10: + mda_type = TYPE_HERCPLUS; + mda_type_name = "HerculesPlus"; + break; + case 0x50: + mda_type = TYPE_HERCCOLOR; + mda_type_name = "HerculesColor"; + break; + default: + mda_type = TYPE_HERC; + mda_type_name = "Hercules"; + break; + } + } + + return 1; +} + +static void mda_initialize(void) +{ + write_mda_b(97, 0x00); /* horizontal total */ + write_mda_b(80, 0x01); /* horizontal displayed */ + write_mda_b(82, 0x02); /* horizontal sync pos */ + write_mda_b(15, 0x03); /* horizontal sync width */ + + write_mda_b(25, 0x04); /* vertical total */ + write_mda_b(6, 0x05); /* vertical total adjust */ + write_mda_b(25, 0x06); /* vertical displayed */ + write_mda_b(25, 0x07); /* vertical sync pos */ + + write_mda_b(2, 0x08); /* interlace mode */ + write_mda_b(13, 0x09); /* maximum scanline */ + write_mda_b(12, 0x0a); /* cursor start */ + write_mda_b(13, 0x0b); /* cursor end */ + + write_mda_w(0x0000, 0x0c); /* start address */ + write_mda_w(0x0000, 0x0e); /* cursor location */ + + outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN, mda_mode_port); + outb_p(0x00, mda_status_port); + outb_p(0x00, mda_gfx_port); +} + +static const char *mdacon_startup(void) +{ + mda_num_columns = 80; + mda_num_lines = 25; + + mda_vram_len = 0x01000; + mda_vram_base = (u16 *)VGA_MAP_MEM(0xb0000, mda_vram_len); + + mda_index_port = 0x3b4; + mda_value_port = 0x3b5; + mda_mode_port = 0x3b8; + mda_status_port = 0x3ba; + mda_gfx_port = 0x3bf; + + mda_type = TYPE_MDA; + mda_type_name = "MDA"; + + if (! mda_detect()) { + printk("mdacon: MDA card not detected.\n"); + return NULL; + } + + if (mda_type != TYPE_MDA) { + mda_initialize(); + } + + /* cursor looks ugly during boot-up, so turn it off */ + mda_set_cursor(mda_vram_len - 1); + + printk("mdacon: %s with %ldK of memory detected.\n", + mda_type_name, mda_vram_len/1024); + + return "MDA-2"; +} + +static void mdacon_init(struct vc_data *c, int init) +{ + c->vc_complement_mask = 0x0800; /* reverse video */ + c->vc_display_fg = &mda_display_fg; + + if (init) { + c->vc_cols = mda_num_columns; + c->vc_rows = mda_num_lines; + } else + vc_resize(c, mda_num_columns, mda_num_lines); + + /* make the first MDA console visible */ + + if (mda_display_fg == NULL) + mda_display_fg = c; +} + +static void mdacon_deinit(struct vc_data *c) +{ + /* con_set_default_unimap(c->vc_num); */ + + if (mda_display_fg == c) + mda_display_fg = NULL; +} + +static inline u16 mda_convert_attr(u16 ch) +{ + u16 attr = 0x0700; + + /* Underline and reverse-video are mutually exclusive on MDA. + * Since reverse-video is used for cursors and selected areas, + * it takes precedence. + */ + + if (ch & 0x0800) attr = 0x7000; /* reverse */ + else if (ch & 0x0400) attr = 0x0100; /* underline */ + + return ((ch & 0x0200) << 2) | /* intensity */ + (ch & 0x8000) | /* blink */ + (ch & 0x00ff) | attr; +} + +static u8 mdacon_build_attr(struct vc_data *c, u8 color, + enum vc_intensity intensity, + bool blink, bool underline, bool reverse, + bool italic) +{ + /* The attribute is just a bit vector: + * + * Bit 0..1 : intensity (0..2) + * Bit 2 : underline + * Bit 3 : reverse + * Bit 7 : blink + */ + + return (intensity & VCI_MASK) | + (underline << 2) | + (reverse << 3) | + (italic << 4) | + (blink << 7); +} + +static void mdacon_invert_region(struct vc_data *c, u16 *p, int count) +{ + for (; count > 0; count--) { + scr_writew(scr_readw(p) ^ 0x0800, p); + p++; + } +} + +static inline u16 *mda_addr(unsigned int x, unsigned int y) +{ + return mda_vram_base + y * mda_num_columns + x; +} + +static void mdacon_putc(struct vc_data *c, int ch, int y, int x) +{ + scr_writew(mda_convert_attr(ch), mda_addr(x, y)); +} + +static void mdacon_putcs(struct vc_data *c, const unsigned short *s, + int count, int y, int x) +{ + u16 *dest = mda_addr(x, y); + + for (; count > 0; count--) { + scr_writew(mda_convert_attr(scr_readw(s++)), dest++); + } +} + +static void mdacon_clear(struct vc_data *c, int y, int x, + int height, int width) +{ + u16 *dest = mda_addr(x, y); + u16 eattr = mda_convert_attr(c->vc_video_erase_char); + + if (width <= 0 || height <= 0) + return; + + if (x==0 && width==mda_num_columns) { + scr_memsetw(dest, eattr, height*width*2); + } else { + for (; height > 0; height--, dest+=mda_num_columns) + scr_memsetw(dest, eattr, width*2); + } +} + +static int mdacon_switch(struct vc_data *c) +{ + return 1; /* redrawing needed */ +} + +static int mdacon_blank(struct vc_data *c, int blank, int mode_switch) +{ + if (mda_type == TYPE_MDA) { + if (blank) + scr_memsetw(mda_vram_base, + mda_convert_attr(c->vc_video_erase_char), + c->vc_screenbuf_size); + /* Tell console.c that it has to restore the screen itself */ + return 1; + } else { + if (blank) + outb_p(0x00, mda_mode_port); /* disable video */ + else + outb_p(MDA_MODE_VIDEO_EN | MDA_MODE_BLINK_EN, + mda_mode_port); + return 0; + } +} + +static void mdacon_cursor(struct vc_data *c, int mode) +{ + if (mode == CM_ERASE) { + mda_set_cursor(mda_vram_len - 1); + return; + } + + mda_set_cursor(c->state.y * mda_num_columns * 2 + c->state.x * 2); + + switch (CUR_SIZE(c->vc_cursor_type)) { + + case CUR_LOWER_THIRD: mda_set_cursor_size(10, 13); break; + case CUR_LOWER_HALF: mda_set_cursor_size(7, 13); break; + case CUR_TWO_THIRDS: mda_set_cursor_size(4, 13); break; + case CUR_BLOCK: mda_set_cursor_size(1, 13); break; + case CUR_NONE: mda_set_cursor_size(14, 13); break; + default: mda_set_cursor_size(12, 13); break; + } +} + +static bool mdacon_scroll(struct vc_data *c, unsigned int t, unsigned int b, + enum con_scroll dir, unsigned int lines) +{ + u16 eattr = mda_convert_attr(c->vc_video_erase_char); + + if (!lines) + return false; + + if (lines > c->vc_rows) /* maximum realistic size */ + lines = c->vc_rows; + + switch (dir) { + + case SM_UP: + scr_memmovew(mda_addr(0, t), mda_addr(0, t + lines), + (b-t-lines)*mda_num_columns*2); + scr_memsetw(mda_addr(0, b - lines), eattr, + lines*mda_num_columns*2); + break; + + case SM_DOWN: + scr_memmovew(mda_addr(0, t + lines), mda_addr(0, t), + (b-t-lines)*mda_num_columns*2); + scr_memsetw(mda_addr(0, t), eattr, lines*mda_num_columns*2); + break; + } + + return false; +} + + +/* + * The console `switch' structure for the MDA based console + */ + +static const struct consw mda_con = { + .owner = THIS_MODULE, + .con_startup = mdacon_startup, + .con_init = mdacon_init, + .con_deinit = mdacon_deinit, + .con_clear = mdacon_clear, + .con_putc = mdacon_putc, + .con_putcs = mdacon_putcs, + .con_cursor = mdacon_cursor, + .con_scroll = mdacon_scroll, + .con_switch = mdacon_switch, + .con_blank = mdacon_blank, + .con_build_attr = mdacon_build_attr, + .con_invert_region = mdacon_invert_region, +}; + +int __init mda_console_init(void) +{ + int err; + + if (mda_first_vc > mda_last_vc) + return 1; + console_lock(); + err = do_take_over_console(&mda_con, mda_first_vc-1, mda_last_vc-1, 0); + console_unlock(); + return err; +} + +static void __exit mda_console_exit(void) +{ + give_up_console(&mda_con); +} + +module_init(mda_console_init); +module_exit(mda_console_exit); + +MODULE_LICENSE("GPL"); + diff --git a/drivers/video/console/newport_con.c b/drivers/video/console/newport_con.c new file mode 100644 index 000000000..d9c682ae0 --- /dev/null +++ b/drivers/video/console/newport_con.c @@ -0,0 +1,745 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * newport_con.c: Abscon for newport hardware + * + * (C) 1998 Thomas Bogendoerfer (tsbogend@alpha.franken.de) + * (C) 1999 Ulf Carlsson (ulfc@thepuffingruop.com) + * + * This driver is based on sgicons.c and cons_newport. + * + * Copyright (C) 1996 David S. Miller (davem@davemloft.net) + * Copyright (C) 1997 Miguel de Icaza (miguel@nuclecu.unam.mx) + */ +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/kd.h> +#include <linux/selection.h> +#include <linux/console.h> +#include <linux/vt_kern.h> +#include <linux/mm.h> +#include <linux/module.h> +#include <linux/slab.h> + +#include <asm/io.h> +#include <linux/uaccess.h> +#include <asm/page.h> +#include <asm/gio_device.h> + +#include <video/newport.h> + +#include <linux/linux_logo.h> +#include <linux/font.h> + +#define NEWPORT_LEN 0x10000 + +#define FONT_DATA ((unsigned char *)font_vga_8x16.data) + +static unsigned char *font_data[MAX_NR_CONSOLES]; + +static struct newport_regs *npregs; +static unsigned long newport_addr; + +static int logo_active; +static int topscan; +static int xcurs_correction = 29; +static int newport_xsize; +static int newport_ysize; +static int newport_has_init; + +static int newport_set_def_font(int unit, struct console_font *op); + +#define BMASK(c) (c << 24) + +#define RENDER(regs, cp) do { \ +(regs)->go.zpattern = BMASK((cp)[0x0]); (regs)->go.zpattern = BMASK((cp)[0x1]); \ +(regs)->go.zpattern = BMASK((cp)[0x2]); (regs)->go.zpattern = BMASK((cp)[0x3]); \ +(regs)->go.zpattern = BMASK((cp)[0x4]); (regs)->go.zpattern = BMASK((cp)[0x5]); \ +(regs)->go.zpattern = BMASK((cp)[0x6]); (regs)->go.zpattern = BMASK((cp)[0x7]); \ +(regs)->go.zpattern = BMASK((cp)[0x8]); (regs)->go.zpattern = BMASK((cp)[0x9]); \ +(regs)->go.zpattern = BMASK((cp)[0xa]); (regs)->go.zpattern = BMASK((cp)[0xb]); \ +(regs)->go.zpattern = BMASK((cp)[0xc]); (regs)->go.zpattern = BMASK((cp)[0xd]); \ +(regs)->go.zpattern = BMASK((cp)[0xe]); (regs)->go.zpattern = BMASK((cp)[0xf]); \ +} while(0) + +#define TESTVAL 0xdeadbeef +#define XSTI_TO_FXSTART(val) (((val) & 0xffff) << 11) + +static inline void newport_render_background(int xstart, int ystart, + int xend, int yend, int ci) +{ + newport_wait(npregs); + npregs->set.wrmask = 0xffffffff; + npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | + NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX + | NPORT_DMODE0_STOPY); + npregs->set.colori = ci; + npregs->set.xystarti = + (xstart << 16) | ((ystart + topscan) & 0x3ff); + npregs->go.xyendi = + ((xend + 7) << 16) | ((yend + topscan + 15) & 0x3ff); +} + +static inline void newport_init_cmap(void) +{ + unsigned short i; + + for (i = 0; i < 16; i++) { + newport_bfwait(npregs); + newport_cmap_setaddr(npregs, color_table[i]); + newport_cmap_setrgb(npregs, + default_red[i], + default_grn[i], default_blu[i]); + } +} + +static const struct linux_logo *newport_show_logo(void) +{ +#ifdef CONFIG_LOGO_SGI_CLUT224 + const struct linux_logo *logo = fb_find_logo(8); + const unsigned char *clut; + const unsigned char *data; + unsigned long i; + + if (!logo) + return NULL; + clut = logo->clut; + data = logo->data; + + for (i = 0; i < logo->clutsize; i++) { + newport_bfwait(npregs); + newport_cmap_setaddr(npregs, i + 0x20); + newport_cmap_setrgb(npregs, clut[0], clut[1], clut[2]); + clut += 3; + } + + newport_wait(npregs); + npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | + NPORT_DMODE0_CHOST); + + npregs->set.xystarti = ((newport_xsize - logo->width) << 16) | (0); + npregs->set.xyendi = ((newport_xsize - 1) << 16); + newport_wait(npregs); + + for (i = 0; i < logo->width*logo->height; i++) + npregs->go.hostrw0 = *data++ << 24; + + return logo; +#else + return NULL; +#endif /* CONFIG_LOGO_SGI_CLUT224 */ +} + +static inline void newport_clear_screen(int xstart, int ystart, int xend, + int yend, int ci) +{ + if (logo_active) + return; + + newport_wait(npregs); + npregs->set.wrmask = 0xffffffff; + npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | + NPORT_DMODE0_DOSETUP | NPORT_DMODE0_STOPX + | NPORT_DMODE0_STOPY); + npregs->set.colori = ci; + npregs->set.xystarti = (xstart << 16) | ystart; + npregs->go.xyendi = (xend << 16) | yend; +} + +static inline void newport_clear_lines(int ystart, int yend, int ci) +{ + ystart = ((ystart << 4) + topscan) & 0x3ff; + yend = ((yend << 4) + topscan + 15) & 0x3ff; + newport_clear_screen(0, ystart, 1280 + 63, yend, ci); +} + +static void newport_reset(void) +{ + unsigned short treg; + int i; + + newport_wait(npregs); + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); + newport_vc2_set(npregs, VC2_IREG_CONTROL, + (treg | VC2_CTRL_EVIDEO)); + + treg = newport_vc2_get(npregs, VC2_IREG_CENTRY); + newport_vc2_set(npregs, VC2_IREG_RADDR, treg); + npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | + NPORT_DMODE_W2 | VC2_PROTOCOL); + for (i = 0; i < 128; i++) { + newport_bfwait(npregs); + if (i == 92 || i == 94) + npregs->set.dcbdata0.byshort.s1 = 0xff00; + else + npregs->set.dcbdata0.byshort.s1 = 0x0000; + } + + newport_init_cmap(); + + /* turn off popup plane */ + npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | + XM9_CRS_CONFIG | NPORT_DMODE_W1); + npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; + npregs->set.dcbmode = (DCB_XMAP1 | R_DCB_XMAP9_PROTOCOL | + XM9_CRS_CONFIG | NPORT_DMODE_W1); + npregs->set.dcbdata0.bybytes.b3 &= ~XM9_PUPMODE; + + topscan = 0; + npregs->cset.topscan = 0x3ff; + npregs->cset.xywin = (4096 << 16) | 4096; + + /* Clear the screen. */ + newport_clear_screen(0, 0, 1280 + 63, 1024, 0); +} + +/* + * calculate the actual screen size by reading + * the video timing out of the VC2 + */ +static void newport_get_screensize(void) +{ + int i, cols; + unsigned short ventry, treg; + unsigned short linetable[128]; /* should be enough */ + + ventry = newport_vc2_get(npregs, VC2_IREG_VENTRY); + newport_vc2_set(npregs, VC2_IREG_RADDR, ventry); + npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | + NPORT_DMODE_W2 | VC2_PROTOCOL); + for (i = 0; i < 128; i++) { + newport_bfwait(npregs); + linetable[i] = npregs->set.dcbdata0.byshort.s1; + } + + newport_xsize = newport_ysize = 0; + for (i = 0; i < ARRAY_SIZE(linetable) - 1 && linetable[i + 1]; i += 2) { + cols = 0; + newport_vc2_set(npregs, VC2_IREG_RADDR, linetable[i]); + npregs->set.dcbmode = (NPORT_DMODE_AVC2 | VC2_REGADDR_RAM | + NPORT_DMODE_W2 | VC2_PROTOCOL); + do { + newport_bfwait(npregs); + treg = npregs->set.dcbdata0.byshort.s1; + if ((treg & 1) == 0) + cols += (treg >> 7) & 0xfe; + if ((treg & 0x80) == 0) { + newport_bfwait(npregs); + treg = npregs->set.dcbdata0.byshort.s1; + } + } while ((treg & 0x8000) == 0); + if (cols) { + if (cols > newport_xsize) + newport_xsize = cols; + newport_ysize += linetable[i + 1]; + } + } + printk("NG1: Screensize %dx%d\n", newport_xsize, newport_ysize); +} + +static void newport_get_revisions(void) +{ + unsigned int tmp; + unsigned int board_rev; + unsigned int rex3_rev; + unsigned int vc2_rev; + unsigned int cmap_rev; + unsigned int xmap9_rev; + unsigned int bt445_rev; + unsigned int bitplanes; + + rex3_rev = npregs->cset.status & NPORT_STAT_VERS; + + npregs->set.dcbmode = (DCB_CMAP0 | NCMAP_PROTOCOL | + NCMAP_REGADDR_RREG | NPORT_DMODE_W1); + tmp = npregs->set.dcbdata0.bybytes.b3; + cmap_rev = tmp & 7; + board_rev = (tmp >> 4) & 7; + bitplanes = ((board_rev > 1) && (tmp & 0x80)) ? 8 : 24; + + npregs->set.dcbmode = (DCB_CMAP1 | NCMAP_PROTOCOL | + NCMAP_REGADDR_RREG | NPORT_DMODE_W1); + tmp = npregs->set.dcbdata0.bybytes.b3; + if ((tmp & 7) < cmap_rev) + cmap_rev = (tmp & 7); + + vc2_rev = (newport_vc2_get(npregs, VC2_IREG_CONFIG) >> 5) & 7; + + npregs->set.dcbmode = (DCB_XMAP0 | R_DCB_XMAP9_PROTOCOL | + XM9_CRS_REVISION | NPORT_DMODE_W1); + xmap9_rev = npregs->set.dcbdata0.bybytes.b3 & 7; + + npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | + BT445_CSR_ADDR_REG | NPORT_DMODE_W1); + npregs->set.dcbdata0.bybytes.b3 = BT445_REVISION_REG; + npregs->set.dcbmode = (DCB_BT445 | BT445_PROTOCOL | + BT445_CSR_REVISION | NPORT_DMODE_W1); + bt445_rev = (npregs->set.dcbdata0.bybytes.b3 >> 4) - 0x0a; + +#define L(a) (char)('A'+(a)) + printk + ("NG1: Revision %d, %d bitplanes, REX3 revision %c, VC2 revision %c, xmap9 revision %c, cmap revision %c, bt445 revision %c\n", + board_rev, bitplanes, L(rex3_rev), L(vc2_rev), L(xmap9_rev), + L(cmap_rev ? (cmap_rev + 1) : 0), L(bt445_rev)); +#undef L + + if (board_rev == 3) /* I don't know all affected revisions */ + xcurs_correction = 21; +} + +static void newport_exit(void) +{ + int i; + + /* free memory used by user font */ + for (i = 0; i < MAX_NR_CONSOLES; i++) + newport_set_def_font(i, NULL); +} + +/* Can't be __init, do_take_over_console may call it later */ +static const char *newport_startup(void) +{ + int i; + + npregs->cset.config = NPORT_CFG_GD0; + + if (newport_wait(npregs)) + goto out_unmap; + + npregs->set.xstarti = TESTVAL; + if (npregs->set._xstart.word != XSTI_TO_FXSTART(TESTVAL)) + goto out_unmap; + + for (i = 0; i < MAX_NR_CONSOLES; i++) + font_data[i] = FONT_DATA; + + newport_reset(); + newport_get_revisions(); + newport_get_screensize(); + newport_has_init = 1; + + return "SGI Newport"; + +out_unmap: + return NULL; +} + +static void newport_init(struct vc_data *vc, int init) +{ + int cols, rows; + + cols = newport_xsize / 8; + rows = newport_ysize / 16; + vc->vc_can_do_color = 1; + if (init) { + vc->vc_cols = cols; + vc->vc_rows = rows; + } else + vc_resize(vc, cols, rows); +} + +static void newport_deinit(struct vc_data *c) +{ + if (!con_is_bound(&newport_con) && newport_has_init) { + newport_exit(); + newport_has_init = 0; + } +} + +static void newport_clear(struct vc_data *vc, int sy, int sx, int height, + int width) +{ + int xend = ((sx + width) << 3) - 1; + int ystart = ((sy << 4) + topscan) & 0x3ff; + int yend = (((sy + height) << 4) + topscan - 1) & 0x3ff; + + if (logo_active) + return; + + if (ystart < yend) { + newport_clear_screen(sx << 3, ystart, xend, yend, + (vc->state.color & 0xf0) >> 4); + } else { + newport_clear_screen(sx << 3, ystart, xend, 1023, + (vc->state.color & 0xf0) >> 4); + newport_clear_screen(sx << 3, 0, xend, yend, + (vc->state.color & 0xf0) >> 4); + } +} + +static void newport_putc(struct vc_data *vc, int charattr, int ypos, + int xpos) +{ + unsigned char *p; + + p = &font_data[vc->vc_num][(charattr & 0xff) << 4]; + charattr = (charattr >> 8) & 0xff; + xpos <<= 3; + ypos <<= 4; + + newport_render_background(xpos, ypos, xpos, ypos, + (charattr & 0xf0) >> 4); + + /* Set the color and drawing mode. */ + newport_wait(npregs); + npregs->set.colori = charattr & 0xf; + npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | + NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | + NPORT_DMODE0_L32); + + /* Set coordinates for bitmap operation. */ + npregs->set.xystarti = (xpos << 16) | ((ypos + topscan) & 0x3ff); + npregs->set.xyendi = ((xpos + 7) << 16); + newport_wait(npregs); + + /* Go, baby, go... */ + RENDER(npregs, p); +} + +static void newport_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos) +{ + int i; + int charattr; + unsigned char *p; + + charattr = (scr_readw(s) >> 8) & 0xff; + + xpos <<= 3; + ypos <<= 4; + + if (!logo_active) + /* Clear the area behing the string */ + newport_render_background(xpos, ypos, + xpos + ((count - 1) << 3), ypos, + (charattr & 0xf0) >> 4); + + newport_wait(npregs); + + /* Set the color and drawing mode. */ + npregs->set.colori = charattr & 0xf; + npregs->set.drawmode0 = (NPORT_DMODE0_DRAW | NPORT_DMODE0_BLOCK | + NPORT_DMODE0_STOPX | NPORT_DMODE0_ZPENAB | + NPORT_DMODE0_L32); + + for (i = 0; i < count; i++, xpos += 8) { + p = &font_data[vc->vc_num][(scr_readw(s++) & 0xff) << 4]; + + newport_wait(npregs); + + /* Set coordinates for bitmap operation. */ + npregs->set.xystarti = + (xpos << 16) | ((ypos + topscan) & 0x3ff); + npregs->set.xyendi = ((xpos + 7) << 16); + + /* Go, baby, go... */ + RENDER(npregs, p); + } +} + +static void newport_cursor(struct vc_data *vc, int mode) +{ + unsigned short treg; + int xcurs, ycurs; + + switch (mode) { + case CM_ERASE: + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); + newport_vc2_set(npregs, VC2_IREG_CONTROL, + (treg & ~(VC2_CTRL_ECDISP))); + break; + + case CM_MOVE: + case CM_DRAW: + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); + newport_vc2_set(npregs, VC2_IREG_CONTROL, + (treg | VC2_CTRL_ECDISP)); + xcurs = (vc->vc_pos - vc->vc_visible_origin) / 2; + ycurs = ((xcurs / vc->vc_cols) << 4) + 31; + xcurs = ((xcurs % vc->vc_cols) << 3) + xcurs_correction; + newport_vc2_set(npregs, VC2_IREG_CURSX, xcurs); + newport_vc2_set(npregs, VC2_IREG_CURSY, ycurs); + } +} + +static int newport_switch(struct vc_data *vc) +{ + static int logo_drawn = 0; + + topscan = 0; + npregs->cset.topscan = 0x3ff; + + if (!logo_drawn) { + if (newport_show_logo()) { + logo_drawn = 1; + logo_active = 1; + } + } + + return 1; +} + +static int newport_blank(struct vc_data *c, int blank, int mode_switch) +{ + unsigned short treg; + + if (blank == 0) { + /* unblank console */ + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); + newport_vc2_set(npregs, VC2_IREG_CONTROL, + (treg | VC2_CTRL_EDISP)); + } else { + /* blank console */ + treg = newport_vc2_get(npregs, VC2_IREG_CONTROL); + newport_vc2_set(npregs, VC2_IREG_CONTROL, + (treg & ~(VC2_CTRL_EDISP))); + } + return 1; +} + +static int newport_set_font(int unit, struct console_font *op) +{ + int w = op->width; + int h = op->height; + int size = h * op->charcount; + int i; + unsigned char *new_data, *data = op->data, *p; + + /* ladis: when I grow up, there will be a day... and more sizes will + * be supported ;-) */ + if ((w != 8) || (h != 16) + || (op->charcount != 256 && op->charcount != 512)) + return -EINVAL; + + if (!(new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, + GFP_USER))) return -ENOMEM; + + new_data += FONT_EXTRA_WORDS * sizeof(int); + FNTSIZE(new_data) = size; + FNTCHARCNT(new_data) = op->charcount; + REFCOUNT(new_data) = 0; /* usage counter */ + FNTSUM(new_data) = 0; + + p = new_data; + for (i = 0; i < op->charcount; i++) { + memcpy(p, data, h); + data += 32; + p += h; + } + + /* check if font is already used by other console */ + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (font_data[i] != FONT_DATA + && FNTSIZE(font_data[i]) == size + && !memcmp(font_data[i], new_data, size)) { + kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); + /* current font is the same as the new one */ + if (i == unit) + return 0; + new_data = font_data[i]; + break; + } + } + /* old font is user font */ + if (font_data[unit] != FONT_DATA) { + if (--REFCOUNT(font_data[unit]) == 0) + kfree(font_data[unit] - + FONT_EXTRA_WORDS * sizeof(int)); + } + REFCOUNT(new_data)++; + font_data[unit] = new_data; + + return 0; +} + +static int newport_set_def_font(int unit, struct console_font *op) +{ + if (font_data[unit] != FONT_DATA) { + if (--REFCOUNT(font_data[unit]) == 0) + kfree(font_data[unit] - + FONT_EXTRA_WORDS * sizeof(int)); + font_data[unit] = FONT_DATA; + } + + return 0; +} + +static int newport_font_default(struct vc_data *vc, struct console_font *op, char *name) +{ + return newport_set_def_font(vc->vc_num, op); +} + +static int newport_font_set(struct vc_data *vc, struct console_font *font, unsigned flags) +{ + return newport_set_font(vc->vc_num, font); +} + +static bool newport_scroll(struct vc_data *vc, unsigned int t, unsigned int b, + enum con_scroll dir, unsigned int lines) +{ + int count, x, y; + unsigned short *s, *d; + unsigned short chattr; + + logo_active = 0; /* it's time to disable the logo now.. */ + + if (t == 0 && b == vc->vc_rows) { + if (dir == SM_UP) { + topscan = (topscan + (lines << 4)) & 0x3ff; + newport_clear_lines(vc->vc_rows - lines, + vc->vc_rows - 1, + (vc->state.color & 0xf0) >> 4); + } else { + topscan = (topscan + (-lines << 4)) & 0x3ff; + newport_clear_lines(0, lines - 1, + (vc->state.color & 0xf0) >> 4); + } + npregs->cset.topscan = (topscan - 1) & 0x3ff; + return false; + } + + count = (b - t - lines) * vc->vc_cols; + if (dir == SM_UP) { + x = 0; + y = t; + s = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * (t + lines)); + d = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * t); + while (count--) { + chattr = scr_readw(s++); + if (chattr != scr_readw(d)) { + newport_putc(vc, chattr, y, x); + scr_writew(chattr, d); + } + d++; + if (++x == vc->vc_cols) { + x = 0; + y++; + } + } + d = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * (b - lines)); + x = 0; + y = b - lines; + for (count = 0; count < (lines * vc->vc_cols); count++) { + if (scr_readw(d) != vc->vc_video_erase_char) { + newport_putc(vc, vc->vc_video_erase_char, + y, x); + scr_writew(vc->vc_video_erase_char, d); + } + d++; + if (++x == vc->vc_cols) { + x = 0; + y++; + } + } + } else { + x = vc->vc_cols - 1; + y = b - 1; + s = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * (b - lines) - 2); + d = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * b - 2); + while (count--) { + chattr = scr_readw(s--); + if (chattr != scr_readw(d)) { + newport_putc(vc, chattr, y, x); + scr_writew(chattr, d); + } + d--; + if (x-- == 0) { + x = vc->vc_cols - 1; + y--; + } + } + d = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * t); + x = 0; + y = t; + for (count = 0; count < (lines * vc->vc_cols); count++) { + if (scr_readw(d) != vc->vc_video_erase_char) { + newport_putc(vc, vc->vc_video_erase_char, + y, x); + scr_writew(vc->vc_video_erase_char, d); + } + d++; + if (++x == vc->vc_cols) { + x = 0; + y++; + } + } + } + return true; +} + +static void newport_save_screen(struct vc_data *vc) { } + +const struct consw newport_con = { + .owner = THIS_MODULE, + .con_startup = newport_startup, + .con_init = newport_init, + .con_deinit = newport_deinit, + .con_clear = newport_clear, + .con_putc = newport_putc, + .con_putcs = newport_putcs, + .con_cursor = newport_cursor, + .con_scroll = newport_scroll, + .con_switch = newport_switch, + .con_blank = newport_blank, + .con_font_set = newport_font_set, + .con_font_default = newport_font_default, + .con_save_screen = newport_save_screen +}; + +static int newport_probe(struct gio_device *dev, + const struct gio_device_id *id) +{ + int err; + + if (!dev->resource.start) + return -EINVAL; + + if (npregs) + return -EBUSY; /* we only support one Newport as console */ + + newport_addr = dev->resource.start + 0xF0000; + if (!request_mem_region(newport_addr, NEWPORT_LEN, "Newport")) + return -ENODEV; + + npregs = (struct newport_regs *)/* ioremap cannot fail */ + ioremap(newport_addr, sizeof(struct newport_regs)); + console_lock(); + err = do_take_over_console(&newport_con, 0, MAX_NR_CONSOLES - 1, 1); + console_unlock(); + + if (err) { + iounmap((void *)npregs); + release_mem_region(newport_addr, NEWPORT_LEN); + } + return err; +} + +static void newport_remove(struct gio_device *dev) +{ + give_up_console(&newport_con); + iounmap((void *)npregs); + release_mem_region(newport_addr, NEWPORT_LEN); +} + +static struct gio_device_id newport_ids[] = { + { .id = 0x7e }, + { .id = 0xff } +}; + +MODULE_ALIAS("gio:7e"); + +static struct gio_driver newport_driver = { + .name = "newport", + .id_table = newport_ids, + .probe = newport_probe, + .remove = newport_remove, +}; +module_driver(newport_driver, gio_register_driver, gio_unregister_driver); + +MODULE_LICENSE("GPL"); diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c new file mode 100644 index 000000000..f304163e8 --- /dev/null +++ b/drivers/video/console/sticon.c @@ -0,0 +1,408 @@ +/* + * linux/drivers/video/console/sticon.c - console driver using HP's STI firmware + * + * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org> + * Copyright (C) 2002-2020 Helge Deller <deller@gmx.de> + * + * Based on linux/drivers/video/vgacon.c and linux/drivers/video/fbcon.c, + * which were + * + * Created 28 Sep 1997 by Geert Uytterhoeven + * Rewritten by Martin Mares <mj@ucw.cz>, July 1998 + * Copyright (C) 1991, 1992 Linus Torvalds + * 1995 Jay Estabrook + * Copyright (C) 1995 Geert Uytterhoeven + * Copyright (C) 1993 Bjoern Brauel + * Roman Hodek + * Copyright (C) 1993 Hamish Macdonald + * Greg Harp + * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk] + * + * with work by William Rucklidge (wjr@cs.cornell.edu) + * Geert Uytterhoeven + * Jes Sorensen (jds@kom.auc.dk) + * Martin Apel + * with work by Guenther Kelleter + * Martin Schaller + * Andreas Schwab + * Emmanuel Marty (core@ggi-project.org) + * Jakub Jelinek (jj@ultra.linux.cz) + * Martin Mares <mj@ucw.cz> + * + * 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. + * + */ + +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/console.h> +#include <linux/errno.h> +#include <linux/vt_kern.h> +#include <linux/kd.h> +#include <linux/selection.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/font.h> +#include <linux/crc32.h> +#include <linux/fb.h> + +#include <asm/io.h> + +#include "../fbdev/sticore.h" + +/* switching to graphics mode */ +#define BLANK 0 +static int vga_is_gfx; + +#define STI_DEF_FONT sticon_sti->font + +/* borrowed from fbcon.c */ +#define FNTREFCOUNT(fd) (fd->refcount) +#define FNTCRC(fd) (fd->crc) +static struct sti_cooked_font *font_data[MAX_NR_CONSOLES]; + +/* this is the sti_struct used for this console */ +static struct sti_struct *sticon_sti; + +static const char *sticon_startup(void) +{ + return "STI console"; +} + +static void sticon_putc(struct vc_data *conp, int c, int ypos, int xpos) +{ + if (vga_is_gfx || console_blanked) + return; + + if (conp->vc_mode != KD_TEXT) + return; + + sti_putc(sticon_sti, c, ypos, xpos, font_data[conp->vc_num]); +} + +static void sticon_putcs(struct vc_data *conp, const unsigned short *s, + int count, int ypos, int xpos) +{ + if (vga_is_gfx || console_blanked) + return; + + if (conp->vc_mode != KD_TEXT) + return; + + while (count--) { + sti_putc(sticon_sti, scr_readw(s++), ypos, xpos++, + font_data[conp->vc_num]); + } +} + +static void sticon_cursor(struct vc_data *conp, int mode) +{ + unsigned short car1; + + /* no cursor update if screen is blanked */ + if (vga_is_gfx || console_blanked) + return; + + car1 = conp->vc_screenbuf[conp->state.x + conp->state.y * conp->vc_cols]; + switch (mode) { + case CM_ERASE: + sti_putc(sticon_sti, car1, conp->state.y, conp->state.x, + font_data[conp->vc_num]); + break; + case CM_MOVE: + case CM_DRAW: + switch (CUR_SIZE(conp->vc_cursor_type)) { + case CUR_UNDERLINE: + case CUR_LOWER_THIRD: + case CUR_LOWER_HALF: + case CUR_TWO_THIRDS: + case CUR_BLOCK: + sti_putc(sticon_sti, (car1 & 255) + (0 << 8) + (7 << 11), + conp->state.y, conp->state.x, font_data[conp->vc_num]); + break; + } + break; + } +} + +static bool sticon_scroll(struct vc_data *conp, unsigned int t, + unsigned int b, enum con_scroll dir, unsigned int count) +{ + struct sti_struct *sti = sticon_sti; + + if (vga_is_gfx) + return false; + + sticon_cursor(conp, CM_ERASE); + + switch (dir) { + case SM_UP: + sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols, + font_data[conp->vc_num]); + sti_clear(sti, b - count, 0, count, conp->vc_cols, + conp->vc_video_erase_char, font_data[conp->vc_num]); + break; + + case SM_DOWN: + sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols, + font_data[conp->vc_num]); + sti_clear(sti, t, 0, count, conp->vc_cols, + conp->vc_video_erase_char, font_data[conp->vc_num]); + break; + } + + return false; +} + +static int sticon_set_def_font(int unit, struct console_font *op) +{ + if (font_data[unit] != STI_DEF_FONT) { + if (--FNTREFCOUNT(font_data[unit]) == 0) { + kfree(font_data[unit]->raw_ptr); + kfree(font_data[unit]); + } + font_data[unit] = STI_DEF_FONT; + } + + return 0; +} + +static int sticon_set_font(struct vc_data *vc, struct console_font *op) +{ + struct sti_struct *sti = sticon_sti; + int vc_cols, vc_rows, vc_old_cols, vc_old_rows; + int unit = vc->vc_num; + int w = op->width; + int h = op->height; + int size, i, bpc, pitch; + struct sti_rom_font *new_font; + struct sti_cooked_font *cooked_font; + unsigned char *data = op->data, *p; + + if ((w < 6) || (h < 6) || (w > 32) || (h > 32) + || (op->charcount != 256 && op->charcount != 512)) + return -EINVAL; + pitch = ALIGN(w, 8) / 8; + bpc = pitch * h; + size = bpc * op->charcount; + + new_font = kmalloc(sizeof(*new_font) + size, STI_LOWMEM); + if (!new_font) + return -ENOMEM; + + new_font->first_char = 0; + new_font->last_char = op->charcount - 1; + new_font->width = w; + new_font->height = h; + new_font->font_type = STI_FONT_HPROMAN8; + new_font->bytes_per_char = bpc; + new_font->underline_height = 0; + new_font->underline_pos = 0; + + cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); + if (!cooked_font) { + kfree(new_font); + return -ENOMEM; + } + cooked_font->raw = new_font; + cooked_font->raw_ptr = new_font; + cooked_font->width = w; + cooked_font->height = h; + FNTREFCOUNT(cooked_font) = 0; /* usage counter */ + + p = (unsigned char *) new_font; + p += sizeof(*new_font); + for (i = 0; i < op->charcount; i++) { + memcpy(p, data, bpc); + data += pitch*32; + p += bpc; + } + FNTCRC(cooked_font) = crc32(0, new_font, size + sizeof(*new_font)); + sti_font_convert_bytemode(sti, cooked_font); + new_font = cooked_font->raw_ptr; + + /* check if font is already used by other console */ + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (font_data[i] != STI_DEF_FONT + && (FNTCRC(font_data[i]) == FNTCRC(cooked_font))) { + kfree(new_font); + kfree(cooked_font); + /* current font is the same as the new one */ + if (i == unit) + return 0; + cooked_font = font_data[i]; + new_font = cooked_font->raw_ptr; + break; + } + } + + /* clear screen with old font: we now may have less rows */ + vc_old_rows = vc->vc_rows; + vc_old_cols = vc->vc_cols; + sti_clear(sticon_sti, 0, 0, vc_old_rows, vc_old_cols, + vc->vc_video_erase_char, font_data[vc->vc_num]); + + /* delete old font in case it is a user font */ + sticon_set_def_font(unit, NULL); + + FNTREFCOUNT(cooked_font)++; + font_data[unit] = cooked_font; + + vc_cols = sti_onscreen_x(sti) / cooked_font->width; + vc_rows = sti_onscreen_y(sti) / cooked_font->height; + vc_resize(vc, vc_cols, vc_rows); + + /* need to repaint screen if cols & rows are same as old font */ + if (vc_cols == vc_old_cols && vc_rows == vc_old_rows) + update_screen(vc); + + return 0; +} + +static int sticon_font_default(struct vc_data *vc, struct console_font *op, char *name) +{ + return sticon_set_def_font(vc->vc_num, op); +} + +static int sticon_font_set(struct vc_data *vc, struct console_font *font, + unsigned int flags) +{ + return sticon_set_font(vc, font); +} + +static void sticon_init(struct vc_data *c, int init) +{ + struct sti_struct *sti = sticon_sti; + int vc_cols, vc_rows; + + sti_set(sti, 0, 0, sti_onscreen_y(sti), sti_onscreen_x(sti), 0); + vc_cols = sti_onscreen_x(sti) / sti->font->width; + vc_rows = sti_onscreen_y(sti) / sti->font->height; + c->vc_can_do_color = 1; + + if (init) { + c->vc_cols = vc_cols; + c->vc_rows = vc_rows; + } else { + vc_resize(c, vc_cols, vc_rows); + } +} + +static void sticon_deinit(struct vc_data *c) +{ + int i; + + /* free memory used by user font */ + for (i = 0; i < MAX_NR_CONSOLES; i++) + sticon_set_def_font(i, NULL); +} + +static void sticon_clear(struct vc_data *conp, int sy, int sx, int height, + int width) +{ + if (!height || !width) + return; + + sti_clear(sticon_sti, sy, sx, height, width, + conp->vc_video_erase_char, font_data[conp->vc_num]); +} + +static int sticon_switch(struct vc_data *conp) +{ + return 1; /* needs refreshing */ +} + +static int sticon_blank(struct vc_data *c, int blank, int mode_switch) +{ + if (blank == 0) { + if (mode_switch) + vga_is_gfx = 0; + return 1; + } + sti_clear(sticon_sti, 0, 0, c->vc_rows, c->vc_cols, BLANK, + font_data[c->vc_num]); + if (mode_switch) + vga_is_gfx = 1; + return 1; +} + +static u8 sticon_build_attr(struct vc_data *conp, u8 color, + enum vc_intensity intens, + bool blink, bool underline, bool reverse, + bool italic) +{ + u8 fg = color & 7; + u8 bg = (color & 0x70) >> 4; + + if (reverse) + return (fg << 3) | bg; + else + return (bg << 3) | fg; +} + +static void sticon_invert_region(struct vc_data *conp, u16 *p, int count) +{ + int col = 1; /* vga_can_do_color; */ + + while (count--) { + u16 a = scr_readw(p); + + if (col) + a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4); + else + a = ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700; + + scr_writew(a, p++); + } +} + +static const struct consw sti_con = { + .owner = THIS_MODULE, + .con_startup = sticon_startup, + .con_init = sticon_init, + .con_deinit = sticon_deinit, + .con_clear = sticon_clear, + .con_putc = sticon_putc, + .con_putcs = sticon_putcs, + .con_cursor = sticon_cursor, + .con_scroll = sticon_scroll, + .con_switch = sticon_switch, + .con_blank = sticon_blank, + .con_font_set = sticon_font_set, + .con_font_default = sticon_font_default, + .con_build_attr = sticon_build_attr, + .con_invert_region = sticon_invert_region, +}; + + + +static int __init sticonsole_init(void) +{ + int err, i; + + /* already initialized ? */ + if (sticon_sti) + return 0; + + sticon_sti = sti_get_rom(0); + if (!sticon_sti) + return -ENODEV; + + for (i = 0; i < MAX_NR_CONSOLES; i++) + font_data[i] = STI_DEF_FONT; + + pr_info("sticon: Initializing STI text console on %s at [%s]\n", + sticon_sti->sti_data->inq_outptr.dev_name, + sticon_sti->pa_path); + console_lock(); + err = do_take_over_console(&sti_con, 0, MAX_NR_CONSOLES - 1, + PAGE0->mem_cons.cl_class != CL_DUPLEX); + console_unlock(); + + return err; +} + +module_init(sticonsole_init); +MODULE_LICENSE("GPL"); diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c new file mode 100644 index 000000000..db568f67e --- /dev/null +++ b/drivers/video/console/sticore.c @@ -0,0 +1,1172 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * 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-2020 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 ;) + * + */ + +#define pr_fmt(fmt) "%s: " fmt, KBUILD_MODNAME + +#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 <asm/fb.h> + +#include "../fbdev/sticore.h" + +#define STI_DRIVERVERSION "Version 0.9c" + +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; +} + +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); +} + +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_cooked_font *font) +{ + struct sti_font_inptr *inptr = &sti->sti_data->font_inptr; + struct sti_font_inptr inptr_default = { + .font_start_addr = STI_PTR(font->raw), + .index = c_index(sti, c), + .fg_color = c_fg(sti, c), + .bg_color = c_bg(sti, c), + .dest_x = x * font->width, + .dest_y = y * 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); +} + +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); +} + +void +sti_clear(struct sti_struct *sti, int src_y, int src_x, + int height, int width, int c, struct sti_cooked_font *font) +{ + 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 * font->width, + .src_y = src_y * font->height, + .dest_x = src_x * font->width, + .dest_y = src_y * font->height, + .width = width * font->width, + .height = height * 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); +} + +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_cooked_font *font) +{ + struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr; + struct sti_blkmv_inptr inptr_default = { + .src_x = src_x * font->width, + .src_y = src_y * font->height, + .dest_x = dst_x * font->width, + .dest_y = dst_y * font->height, + .width = width * font->width, + .height = height * 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); +} + + +static void sti_flush(unsigned long start, unsigned long end) +{ + flush_icache_range(start, end); +} + +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); +} + + + + +static char default_sti_path[21] __read_mostly; + +#ifndef MODULE +static int __init sti_setup(char *str) +{ + if (str) + strscpy(default_sti_path, str, sizeof(default_sti_path)); + + return 1; +} + +/* 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; +static int font_index, + font_height, + font_width; +#ifndef MODULE +static int sti_font_setup(char *str) +{ + /* + * The default font can be selected in various ways. + * a) sti_font=VGA8x16, sti_font=10x20, sti_font=10*20 selects + * an built-in Linux framebuffer font. + * b) sti_font=<index>, where index is (1..x) with 1 selecting + * the first HP STI ROM built-in font.. + */ + + if (*str >= '0' && *str <= '9') { + char *x; + + if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) { + font_height = simple_strtoul(str, NULL, 0); + font_width = simple_strtoul(x+1, NULL, 0); + } else { + font_index = simple_strtoul(str, NULL, 0); + } + } else { + font_name = str; /* fb font name */ + } + + return 1; +} + +/* 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> (<number> = 1,2,3,...) + * 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; + + pr_debug("%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); + pr_debug("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); +} + +static void sti_dump_outptr(struct sti_struct *sti) +{ + pr_debug("%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); +} + +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 (!sti->sti_data) + return -ENOMEM; + + glob_cfg = &sti->sti_data->glob_cfg; + glob_cfg_ext = &sti->sti_data->glob_cfg_ext; + save_addr = &sti->sti_data->save_addr; + sti_mem_addr = &sti->sti_data->sti_mem_addr; + + 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)) { + pr_warn("STI pci region mapping 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); + + len = sti->regions[i].region_desc.length * 4096; + if (len) + glob_cfg->region_ptrs[i] = sti->regions_phys[i]; + + pr_debug("region #%d: phys %08lx, region_ptr %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) + pr_warn("future ptr (0x%8x) not yet supported !\n", + sti->regions[i].region); + + glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr); + + sti->glob_cfg = glob_cfg; + + return 0; +} + +#ifdef CONFIG_FONT_SUPPORT +static struct sti_cooked_font * +sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) +{ + const struct font_desc *fbfont = NULL; + unsigned int size, bpc; + void *dest; + struct sti_rom_font *nf; + struct sti_cooked_font *cooked_font; + + if (fbfont_name && strlen(fbfont_name)) + fbfont = find_font(fbfont_name); + if (!fbfont) + fbfont = get_default_font(1024,768, ~(u32)0, ~(u32)0); + if (!fbfont) + return NULL; + + pr_info(" using %ux%u framebuffer font %s\n", + fbfont->width, fbfont->height, fbfont->name); + + bpc = ((fbfont->width+7)/8) * fbfont->height; + size = bpc * fbfont->charcount; + size += sizeof(struct sti_rom_font); + + nf = kzalloc(size, STI_LOWMEM); + if (!nf) + return NULL; + + nf->first_char = 0; + nf->last_char = fbfont->charcount - 1; + 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 * fbfont->charcount); + + cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); + if (!cooked_font) { + kfree(nf); + return NULL; + } + + cooked_font->raw = nf; + cooked_font->raw_ptr = nf; + cooked_font->next_font = NULL; + + cooked_rom->font_start = cooked_font; + + return cooked_font; +} +#else +static struct sti_cooked_font * +sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name) +{ + return NULL; +} +#endif + +static void sti_dump_font(struct sti_cooked_font *font) +{ +#ifdef STI_DUMP_FONT + unsigned char *p = (unsigned char *)font->raw; + int n; + + p += sizeof(struct sti_rom_font); + pr_debug(" w %d h %d bpc %d\n", font->width, font->height, + font->raw->bytes_per_char); + + for (n = 0; n < 256 * font->raw->bytes_per_char; n += 16, p += 16) { + pr_debug(" 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x," + " 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x," + " 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], + p[9], p[10], p[11], p[12], p[13], p[14], p[15]); + } +#endif +} + +static int sti_search_font(struct sti_cooked_rom *rom, int height, int width) +{ + struct sti_cooked_font *font; + int i = 0; + + for (font = rom->font_start; font; font = font->next_font, i++) { + if ((font->raw->width == width) && + (font->raw->height == height)) + return i; + } + return 0; +} + +static struct sti_cooked_font *sti_select_font(struct sti_cooked_rom *rom) +{ + struct sti_cooked_font *font; + int i; + + /* check for framebuffer-font first */ + if (!font_index) { + font = sti_select_fbfont(rom, font_name); + if (font) + return font; + } + + if (font_width && font_height) + font_index = sti_search_font(rom, + font_height, font_width); + + for (font = rom->font_start, i = font_index - 1; + font && (i > 0); + font = font->next_font, i--); + + if (font) + return font; + else + return rom->font_start; +} + + +static void sti_dump_rom(struct sti_struct *sti) +{ + struct sti_rom *rom = sti->rom->raw; + struct sti_cooked_font *font_start; + int nr; + + pr_info(" id %04x-%04x, conforms to spec rev. %d.%02x\n", + rom->graphics_id[0], + rom->graphics_id[1], + rom->revno[0] >> 4, + rom->revno[0] & 0x0f); + pr_debug(" supports %d monitors\n", rom->num_mons); + pr_debug(" font start %08x\n", rom->font_start); + pr_debug(" region list %08x\n", rom->region_list); + pr_debug(" init_graph %08x\n", rom->init_graph); + pr_debug(" bus support %02x\n", rom->bus_support); + pr_debug(" ext bus support %02x\n", rom->ext_bus_support); + pr_debug(" alternate code type %d\n", rom->alt_code_type); + + font_start = sti->rom->font_start; + nr = 0; + while (font_start) { + struct sti_rom_font *f = font_start->raw; + + pr_info(" built-in font #%d: size %dx%d, chars %d-%d, bpc %d\n", ++nr, + f->width, f->height, + f->first_char, f->last_char, f->bytes_per_char); + font_start = font_start->next_font; + } +} + + +static int sti_cook_fonts(struct sti_cooked_rom *cooked_rom, + struct sti_rom *raw_rom) +{ + struct sti_rom_font *raw_font, *font_start; + struct sti_cooked_font *cooked_font; + + cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); + if (!cooked_font) + return 0; + + cooked_rom->font_start = cooked_font; + + raw_font = ((void *)raw_rom) + (raw_rom->font_start); + + font_start = raw_font; + cooked_font->raw = raw_font; + + while (raw_font->next_font) { + raw_font = ((void *)font_start) + (raw_font->next_font); + + cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL); + if (!cooked_font->next_font) + return 1; + + cooked_font = cooked_font->next_font; + + cooked_font->raw = raw_font; + } + + cooked_font->next_font = NULL; + return 1; +} + +#define BMODE_RELOCATE(offset) offset = (offset) / 4; +#define BMODE_LAST_ADDR_OFFS 0x50 + +void sti_font_convert_bytemode(struct sti_struct *sti, struct sti_cooked_font *f) +{ + unsigned char *n, *p, *q; + int size = f->raw->bytes_per_char * (f->raw->last_char + 1) + sizeof(struct sti_rom_font); + struct sti_rom_font *old_font; + + if (sti->wordmode) + return; + + old_font = f->raw_ptr; + n = kcalloc(4, size, STI_LOWMEM); + f->raw_ptr = n; + if (!n) + return; + p = n + 3; + q = (unsigned char *) f->raw; + while (size--) { + *p = *q++; + p += 4; + } + /* store new ptr to byte-mode font and delete old font */ + f->raw = (struct sti_rom_font *) (n + 3); + kfree(old_font); +} +EXPORT_SYMBOL(sti_font_convert_bytemode); + +static void sti_bmode_rom_copy(unsigned long base, unsigned long count, + void *dest) +{ + unsigned long dest_start = (unsigned long) dest; + + while (count) { + count--; + *(u8 *)dest = gsc_readl(base); + base += 4; + dest++; + } + + sti_flush(dest_start, (unsigned long)dest); +} + +static struct sti_rom *sti_get_bmode_rom (unsigned long address) +{ + struct sti_rom *raw; + u32 size; + struct sti_rom_font *raw_font, *font_start; + + sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size); + + size = (size+3) / 4; + raw = kmalloc(size, STI_LOWMEM); + if (raw) { + sti_bmode_rom_copy(address, size, raw); + memmove (&raw->res004, &raw->type[0], 0x3c); + raw->type[3] = raw->res004; + + BMODE_RELOCATE (raw->region_list); + BMODE_RELOCATE (raw->font_start); + + BMODE_RELOCATE (raw->init_graph); + BMODE_RELOCATE (raw->state_mgmt); + BMODE_RELOCATE (raw->font_unpmv); + BMODE_RELOCATE (raw->block_move); + BMODE_RELOCATE (raw->inq_conf); + + raw_font = ((void *)raw) + raw->font_start; + font_start = raw_font; + + while (raw_font->next_font) { + BMODE_RELOCATE (raw_font->next_font); + raw_font = ((void *)font_start) + raw_font->next_font; + } + } + return raw; +} + +static struct sti_rom *sti_get_wmode_rom(unsigned long address) +{ + struct sti_rom *raw; + unsigned long size; + + /* read the ROM size directly from the struct in ROM */ + size = gsc_readl(address + offsetof(struct sti_rom,last_addr)); + + raw = kmalloc(size, STI_LOWMEM); + if (raw) + sti_rom_copy(address, size, raw); + + return raw; +} + +static int sti_read_rom(int wordmode, struct sti_struct *sti, + unsigned long address) +{ + struct sti_cooked_rom *cooked; + struct sti_rom *raw = NULL; + unsigned long revno; + + cooked = kmalloc(sizeof *cooked, GFP_KERNEL); + if (!cooked) + goto out_err; + + if (wordmode) + raw = sti_get_wmode_rom (address); + else + raw = sti_get_bmode_rom (address); + + if (!raw) + goto out_err; + + if (!sti_cook_fonts(cooked, raw)) { + pr_warn("No font found for STI at %08lx\n", address); + goto out_err; + } + + if (raw->region_list) + memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions)); + + address = (unsigned long) STI_PTR(raw); + + pr_info("STI %s ROM supports 32 %sbit firmware functions.\n", + wordmode ? "word mode" : "byte mode", + raw->alt_code_type == ALT_CODE_TYPE_PA_RISC_64 + ? "and 64 " : ""); + + sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff); + sti->block_move = address + (raw->block_move & 0x03ffffff); + sti->init_graph = address + (raw->init_graph & 0x03ffffff); + sti->inq_conf = address + (raw->inq_conf & 0x03ffffff); + + sti->rom = cooked; + sti->rom->raw = raw; + sti_dump_rom(sti); + + sti->wordmode = wordmode; + sti->font = sti_select_font(sti->rom); + sti->font->width = sti->font->raw->width; + sti->font->height = sti->font->raw->height; + sti_font_convert_bytemode(sti, sti->font); + sti_dump_font(sti->font); + + sti->sti_mem_request = raw->sti_mem_req; + sti->graphics_id[0] = raw->graphics_id[0]; + sti->graphics_id[1] = raw->graphics_id[1]; + + /* check if the ROM routines in this card are compatible */ + if (wordmode || sti->graphics_id[1] != 0x09A02587) + goto ok; + + revno = (raw->revno[0] << 8) | raw->revno[1]; + + switch (sti->graphics_id[0]) { + case S9000_ID_HCRX: + /* HyperA or HyperB ? */ + if (revno == 0x8408 || revno == 0x840b) + goto msg_not_supported; + break; + case CRT_ID_THUNDER: + if (revno == 0x8509) + goto msg_not_supported; + break; + case CRT_ID_THUNDER2: + if (revno == 0x850c) + goto msg_not_supported; + } +ok: + return 1; + +msg_not_supported: + pr_warn("Sorry, this GSC/STI card is not yet supported.\n"); + pr_warn("Please see https://parisc.wiki.kernel.org/" + "index.php/Graphics_howto for more info.\n"); + /* fall through */ +out_err: + kfree(raw); + kfree(cooked); + return 0; +} + +static struct sti_struct *sti_try_rom_generic(unsigned long address, + unsigned long hpa, + struct pci_dev *pd) +{ + struct sti_struct *sti; + int ok; + u32 sig; + + if (num_sti_roms >= MAX_STI_ROMS) { + pr_warn("maximum number of STI ROMS reached !\n"); + return NULL; + } + + sti = kzalloc(sizeof(*sti), GFP_KERNEL); + if (!sti) + return NULL; + + spin_lock_init(&sti->lock); + +test_rom: + /* if we can't read the ROM, bail out early. Not being able + * to read the hpa is okay, for romless sti */ + if (pdc_add_valid(address)) + goto out_err; + + sig = gsc_readl(address); + + /* check for a PCI ROM structure */ + if ((le32_to_cpu(sig)==0xaa55)) { + unsigned int i, rm_offset; + u32 *rm; + i = gsc_readl(address+0x04); + if (i != 1) { + /* The ROM could have multiple architecture + * dependent images (e.g. i386, parisc,...) */ + pr_warn("PCI ROM is not a STI ROM type image (0x%8x)\n", i); + goto out_err; + } + + sti->pd = pd; + + i = gsc_readl(address+0x0c); + pr_debug("PCI ROM size (from header) = %d kB\n", + le16_to_cpu(i>>16)*512/1024); + rm_offset = le16_to_cpu(i & 0xffff); + if (rm_offset) { + /* read 16 bytes from the pci region mapper array */ + rm = (u32*) &sti->rm_entry; + *rm++ = gsc_readl(address+rm_offset+0x00); + *rm++ = gsc_readl(address+rm_offset+0x04); + *rm++ = gsc_readl(address+rm_offset+0x08); + *rm++ = gsc_readl(address+rm_offset+0x0c); + } + + address += le32_to_cpu(gsc_readl(address+8)); + pr_debug("sig %04x, PCI STI ROM at %08lx\n", sig, address); + goto test_rom; + } + + ok = 0; + + if ((sig & 0xff) == 0x01) { + pr_debug(" byte mode ROM at %08lx, hpa at %08lx\n", + address, hpa); + ok = sti_read_rom(0, sti, address); + } + + if ((sig & 0xffff) == 0x0303) { + pr_debug(" word mode ROM at %08lx, hpa at %08lx\n", + address, hpa); + ok = sti_read_rom(1, sti, address); + } + + if (!ok) + goto out_err; + + if (sti_init_glob_cfg(sti, address, hpa)) + goto out_err; /* not enough memory */ + + /* disable STI PCI ROM. ROM and card RAM overlap and + * leaving it enabled would force HPMCs + */ + if (sti->pd) { + unsigned long rom_base; + rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE); + pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE); + pr_debug("STI PCI ROM disabled\n"); + } + + if (sti_init_graph(sti)) + goto out_err; + + sti_inq_conf(sti); + sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request); + sti_dump_outptr(sti); + + pr_info(" graphics card name: %s\n", + sti->sti_data->inq_outptr.dev_name); + + sti_roms[num_sti_roms] = sti; + num_sti_roms++; + + return sti; + +out_err: + kfree(sti); + return NULL; +} + +static void sticore_check_for_default_sti(struct sti_struct *sti, char *path) +{ + pr_info(" located at [%s]\n", sti->pa_path); + if (strcmp (path, default_sti_path) == 0) + default_sti = sti; +} + +/* + * on newer systems PDC gives the address of the ROM + * in the additional address field addr[1] while on + * older Systems the PDC stores it in page0->proc_sti + */ +static int __init sticore_pa_init(struct parisc_device *dev) +{ + struct sti_struct *sti = NULL; + int hpa = dev->hpa.start; + + if (dev->num_addrs && dev->addr[0]) + sti = sti_try_rom_generic(dev->addr[0], hpa, NULL); + if (!sti) + sti = sti_try_rom_generic(hpa, hpa, NULL); + if (!sti) + sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL); + if (!sti) + return 1; + + print_pa_hwpath(dev, sti->pa_path); + sticore_check_for_default_sti(sti, sti->pa_path); + return 0; +} + + +static int sticore_pci_init(struct pci_dev *pd, const struct pci_device_id *ent) +{ +#ifdef CONFIG_PCI + unsigned long fb_base, rom_base; + unsigned int fb_len, rom_len; + int err; + struct sti_struct *sti; + + err = pci_enable_device(pd); + if (err < 0) { + dev_err(&pd->dev, "Cannot enable PCI device\n"); + return err; + } + + fb_base = pci_resource_start(pd, 0); + fb_len = pci_resource_len(pd, 0); + rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE); + rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE); + if (rom_base) { + pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE); + pr_debug("STI PCI ROM enabled at 0x%08lx\n", rom_base); + } + + pr_info("STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n", + rom_base, rom_len/1024, fb_base, fb_len/1024/1024); + + pr_debug("Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n", + rom_base, fb_base); + + sti = sti_try_rom_generic(rom_base, fb_base, pd); + if (sti) { + print_pci_hwpath(pd, sti->pa_path); + sticore_check_for_default_sti(sti, sti->pa_path); + } + + if (!sti) { + pr_warn("Unable to handle STI device '%s'\n", pci_name(pd)); + return -ENODEV; + } +#endif /* CONFIG_PCI */ + + return 0; +} + + +static void __exit sticore_pci_remove(struct pci_dev *pd) +{ + BUG(); +} + + +static struct pci_device_id sti_pci_tbl[] = { + { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) }, + { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) }, + { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) }, + { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) }, + { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) }, + { 0, } /* terminate list */ +}; +MODULE_DEVICE_TABLE(pci, sti_pci_tbl); + +static struct pci_driver pci_sti_driver = { + .name = "sti", + .id_table = sti_pci_tbl, + .probe = sticore_pci_init, + .remove = __exit_p(sticore_pci_remove), +}; + +static struct parisc_device_id sti_pa_tbl[] = { + { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 }, + { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 }, + { 0, } +}; +MODULE_DEVICE_TABLE(parisc, sti_pa_tbl); + +static struct parisc_driver pa_sti_driver __refdata = { + .name = "sti", + .id_table = sti_pa_tbl, + .probe = sticore_pa_init, +}; + + +/* + * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[] + */ + +static int sticore_initialized __read_mostly; + +static void sti_init_roms(void) +{ + if (sticore_initialized) + return; + + sticore_initialized = 1; + + pr_info("STI GSC/PCI core graphics driver " + STI_DRIVERVERSION "\n"); + + /* Register drivers for native & PCI cards */ + register_parisc_driver(&pa_sti_driver); + WARN_ON(pci_register_driver(&pci_sti_driver)); + + /* if we didn't find the given default sti, take the first one */ + if (!default_sti) + default_sti = sti_roms[0]; + +} + +/* + * index = 0 gives default sti + * index > 0 gives other stis in detection order + */ +struct sti_struct * sti_get_rom(unsigned int index) +{ + if (!sticore_initialized) + sti_init_roms(); + + if (index == 0) + return default_sti; + + if (index > num_sti_roms) + return NULL; + + return sti_roms[index-1]; +} +EXPORT_SYMBOL(sti_get_rom); + + +int sti_call(const struct sti_struct *sti, unsigned long func, + const void *flags, void *inptr, void *outptr, + struct sti_glob_cfg *glob_cfg) +{ + unsigned long _flags = STI_PTR(flags); + unsigned long _inptr = STI_PTR(inptr); + unsigned long _outptr = STI_PTR(outptr); + unsigned long _glob_cfg = STI_PTR(glob_cfg); + int ret; + +#ifdef CONFIG_64BIT + /* Check for overflow when using 32bit STI on 64bit kernel. */ + if (WARN_ONCE(_flags>>32 || _inptr>>32 || _outptr>>32 || _glob_cfg>>32, + "Out of 32bit-range pointers!")) + return -1; +#endif + + ret = pdc_sti_call(func, _flags, _inptr, _outptr, _glob_cfg); + + return ret; +} + +#if defined(CONFIG_FB_STI) +/* check if given fb_info is the primary device */ +int fb_is_primary_device(struct fb_info *info) +{ + struct sti_struct *sti; + + sti = sti_get_rom(0); + + /* if no built-in graphics card found, allow any fb driver as default */ + if (!sti) + return true; + + /* return true if it's the default built-in framebuffer driver */ + return (sti->info == info); +} +EXPORT_SYMBOL(fb_is_primary_device); +#endif + +MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer"); +MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines"); +MODULE_LICENSE("GPL v2"); + diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c new file mode 100644 index 000000000..fcdf017e2 --- /dev/null +++ b/drivers/video/console/vgacon.c @@ -0,0 +1,1207 @@ +/* + * linux/drivers/video/vgacon.c -- Low level VGA based console driver + * + * Created 28 Sep 1997 by Geert Uytterhoeven + * + * Rewritten by Martin Mares <mj@ucw.cz>, July 1998 + * + * This file is based on the old console.c, vga.c and vesa_blank.c drivers. + * + * Copyright (C) 1991, 1992 Linus Torvalds + * 1995 Jay Estabrook + * + * User definable mapping table and font loading by Eugene G. Crosser, + * <crosser@average.org> + * + * Improved loadable font/UTF-8 support by H. Peter Anvin + * Feb-Sep 1995 <peter.anvin@linux.org> + * + * Colour palette handling, by Simon Tatham + * 17-Jun-95 <sgt20@cam.ac.uk> + * + * if 512 char mode is already enabled don't re-enable it, + * because it causes screen to flicker, by Mitja Horvat + * 5-May-96 <mitja.horvat@guest.arnes.si> + * + * Use 2 outw instead of 4 outb_p to reduce erroneous text + * flashing on RHS of screen during heavy console scrolling . + * Oct 1996, Paul Gortmaker. + * + * + * 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. + */ + +#include <linux/module.h> +#include <linux/types.h> +#include <linux/fs.h> +#include <linux/kernel.h> +#include <linux/console.h> +#include <linux/string.h> +#include <linux/kd.h> +#include <linux/slab.h> +#include <linux/vt_kern.h> +#include <linux/sched.h> +#include <linux/selection.h> +#include <linux/spinlock.h> +#include <linux/ioport.h> +#include <linux/init.h> +#include <linux/screen_info.h> +#include <video/vga.h> +#include <asm/io.h> + +static DEFINE_RAW_SPINLOCK(vga_lock); +static int cursor_size_lastfrom; +static int cursor_size_lastto; +static u32 vgacon_xres; +static u32 vgacon_yres; +static struct vgastate vgastate; + +#define BLANK 0x0020 + +#define VGA_FONTWIDTH 8 /* VGA does not support fontwidths != 8 */ +/* + * Interface used by the world + */ + +static const char *vgacon_startup(void); +static void vgacon_init(struct vc_data *c, int init); +static void vgacon_deinit(struct vc_data *c); +static void vgacon_cursor(struct vc_data *c, int mode); +static int vgacon_switch(struct vc_data *c); +static int vgacon_blank(struct vc_data *c, int blank, int mode_switch); +static void vgacon_scrolldelta(struct vc_data *c, int lines); +static int vgacon_set_origin(struct vc_data *c); +static void vgacon_save_screen(struct vc_data *c); +static void vgacon_invert_region(struct vc_data *c, u16 * p, int count); +static struct uni_pagedict *vgacon_uni_pagedir; +static int vgacon_refcount; + +/* Description of the hardware situation */ +static unsigned long vga_vram_base __read_mostly; /* Base of video memory */ +static unsigned long vga_vram_end __read_mostly; /* End of video memory */ +static unsigned int vga_vram_size __read_mostly; /* Size of video memory */ +static u16 vga_video_port_reg __read_mostly; /* Video register select port */ +static u16 vga_video_port_val __read_mostly; /* Video register value port */ +static unsigned int vga_video_num_columns; /* Number of text columns */ +static unsigned int vga_video_num_lines; /* Number of text lines */ +static bool vga_can_do_color; /* Do we support colors? */ +static unsigned int vga_default_font_height __read_mostly; /* Height of default screen font */ +static unsigned char vga_video_type __read_mostly; /* Card type */ +static int vga_vesa_blanked; +static bool vga_palette_blanked; +static bool vga_is_gfx; +static bool vga_512_chars; +static int vga_video_font_height; +static int vga_scan_lines __read_mostly; +static unsigned int vga_rolled_over; /* last vc_origin offset before wrap */ + +static bool vga_hardscroll_enabled; +static bool vga_hardscroll_user_enable = true; + +static int __init no_scroll(char *str) +{ + /* + * Disabling scrollback is required for the Braillex ib80-piezo + * Braille reader made by F.H. Papenmeier (Germany). + * Use the "no-scroll" bootflag. + */ + vga_hardscroll_user_enable = vga_hardscroll_enabled = false; + return 1; +} + +__setup("no-scroll", no_scroll); + +/* + * By replacing the four outb_p with two back to back outw, we can reduce + * the window of opportunity to see text mislocated to the RHS of the + * console during heavy scrolling activity. However there is the remote + * possibility that some pre-dinosaur hardware won't like the back to back + * I/O. Since the Xservers get away with it, we should be able to as well. + */ +static inline void write_vga(unsigned char reg, unsigned int val) +{ + unsigned int v1, v2; + unsigned long flags; + + /* + * ddprintk might set the console position from interrupt + * handlers, thus the write has to be IRQ-atomic. + */ + raw_spin_lock_irqsave(&vga_lock, flags); + v1 = reg + (val & 0xff00); + v2 = reg + 1 + ((val << 8) & 0xff00); + outw(v1, vga_video_port_reg); + outw(v2, vga_video_port_reg); + raw_spin_unlock_irqrestore(&vga_lock, flags); +} + +static inline void vga_set_mem_top(struct vc_data *c) +{ + write_vga(12, (c->vc_visible_origin - vga_vram_base) / 2); +} + +static void vgacon_restore_screen(struct vc_data *c) +{ + if (c->vc_origin != c->vc_visible_origin) + vgacon_scrolldelta(c, 0); +} + +static void vgacon_scrolldelta(struct vc_data *c, int lines) +{ + vc_scrolldelta_helper(c, lines, vga_rolled_over, (void *)vga_vram_base, + vga_vram_size); + vga_set_mem_top(c); +} + +static const char *vgacon_startup(void) +{ + const char *display_desc = NULL; + u16 saved1, saved2; + volatile u16 *p; + + if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB || + screen_info.orig_video_isVGA == VIDEO_TYPE_EFI) { + no_vga: +#ifdef CONFIG_DUMMY_CONSOLE + conswitchp = &dummy_con; + return conswitchp->con_startup(); +#else + return NULL; +#endif + } + + /* boot_params.screen_info reasonably initialized? */ + if ((screen_info.orig_video_lines == 0) || + (screen_info.orig_video_cols == 0)) + goto no_vga; + + /* VGA16 modes are not handled by VGACON */ + if ((screen_info.orig_video_mode == 0x0D) || /* 320x200/4 */ + (screen_info.orig_video_mode == 0x0E) || /* 640x200/4 */ + (screen_info.orig_video_mode == 0x10) || /* 640x350/4 */ + (screen_info.orig_video_mode == 0x12) || /* 640x480/4 */ + (screen_info.orig_video_mode == 0x6A)) /* 800x600/4 (VESA) */ + goto no_vga; + + vga_video_num_lines = screen_info.orig_video_lines; + vga_video_num_columns = screen_info.orig_video_cols; + vgastate.vgabase = NULL; + + if (screen_info.orig_video_mode == 7) { + /* Monochrome display */ + vga_vram_base = 0xb0000; + vga_video_port_reg = VGA_CRT_IM; + vga_video_port_val = VGA_CRT_DM; + if ((screen_info.orig_video_ega_bx & 0xff) != 0x10) { + static struct resource ega_console_resource = + { .name = "ega", + .flags = IORESOURCE_IO, + .start = 0x3B0, + .end = 0x3BF }; + vga_video_type = VIDEO_TYPE_EGAM; + vga_vram_size = 0x8000; + display_desc = "EGA+"; + request_resource(&ioport_resource, + &ega_console_resource); + } else { + static struct resource mda1_console_resource = + { .name = "mda", + .flags = IORESOURCE_IO, + .start = 0x3B0, + .end = 0x3BB }; + static struct resource mda2_console_resource = + { .name = "mda", + .flags = IORESOURCE_IO, + .start = 0x3BF, + .end = 0x3BF }; + vga_video_type = VIDEO_TYPE_MDA; + vga_vram_size = 0x2000; + display_desc = "*MDA"; + request_resource(&ioport_resource, + &mda1_console_resource); + request_resource(&ioport_resource, + &mda2_console_resource); + vga_video_font_height = 14; + } + } else { + /* If not, it is color. */ + vga_can_do_color = true; + vga_vram_base = 0xb8000; + vga_video_port_reg = VGA_CRT_IC; + vga_video_port_val = VGA_CRT_DC; + if ((screen_info.orig_video_ega_bx & 0xff) != 0x10) { + int i; + + vga_vram_size = 0x8000; + + if (!screen_info.orig_video_isVGA) { + static struct resource ega_console_resource = + { .name = "ega", + .flags = IORESOURCE_IO, + .start = 0x3C0, + .end = 0x3DF }; + vga_video_type = VIDEO_TYPE_EGAC; + display_desc = "EGA"; + request_resource(&ioport_resource, + &ega_console_resource); + } else { + static struct resource vga_console_resource = + { .name = "vga+", + .flags = IORESOURCE_IO, + .start = 0x3C0, + .end = 0x3DF }; + vga_video_type = VIDEO_TYPE_VGAC; + display_desc = "VGA+"; + request_resource(&ioport_resource, + &vga_console_resource); + + /* + * Normalise the palette registers, to point + * the 16 screen colours to the first 16 + * DAC entries. + */ + + for (i = 0; i < 16; i++) { + inb_p(VGA_IS1_RC); + outb_p(i, VGA_ATT_W); + outb_p(i, VGA_ATT_W); + } + outb_p(0x20, VGA_ATT_W); + + /* + * Now set the DAC registers back to their + * default values + */ + for (i = 0; i < 16; i++) { + outb_p(color_table[i], VGA_PEL_IW); + outb_p(default_red[i], VGA_PEL_D); + outb_p(default_grn[i], VGA_PEL_D); + outb_p(default_blu[i], VGA_PEL_D); + } + } + } else { + static struct resource cga_console_resource = + { .name = "cga", + .flags = IORESOURCE_IO, + .start = 0x3D4, + .end = 0x3D5 }; + vga_video_type = VIDEO_TYPE_CGA; + vga_vram_size = 0x2000; + display_desc = "*CGA"; + request_resource(&ioport_resource, + &cga_console_resource); + vga_video_font_height = 8; + } + } + + vga_vram_base = VGA_MAP_MEM(vga_vram_base, vga_vram_size); + vga_vram_end = vga_vram_base + vga_vram_size; + + /* + * Find out if there is a graphics card present. + * Are there smarter methods around? + */ + p = (volatile u16 *) vga_vram_base; + saved1 = scr_readw(p); + saved2 = scr_readw(p + 1); + scr_writew(0xAA55, p); + scr_writew(0x55AA, p + 1); + if (scr_readw(p) != 0xAA55 || scr_readw(p + 1) != 0x55AA) { + scr_writew(saved1, p); + scr_writew(saved2, p + 1); + goto no_vga; + } + scr_writew(0x55AA, p); + scr_writew(0xAA55, p + 1); + if (scr_readw(p) != 0x55AA || scr_readw(p + 1) != 0xAA55) { + scr_writew(saved1, p); + scr_writew(saved2, p + 1); + goto no_vga; + } + scr_writew(saved1, p); + scr_writew(saved2, p + 1); + + if (vga_video_type == VIDEO_TYPE_EGAC + || vga_video_type == VIDEO_TYPE_VGAC + || vga_video_type == VIDEO_TYPE_EGAM) { + vga_hardscroll_enabled = vga_hardscroll_user_enable; + vga_default_font_height = screen_info.orig_video_points; + vga_video_font_height = screen_info.orig_video_points; + /* This may be suboptimal but is a safe bet - go with it */ + vga_scan_lines = + vga_video_font_height * vga_video_num_lines; + } + + vgacon_xres = screen_info.orig_video_cols * VGA_FONTWIDTH; + vgacon_yres = vga_scan_lines; + + return display_desc; +} + +static void vgacon_init(struct vc_data *c, int init) +{ + struct uni_pagedict *p; + + /* + * We cannot be loaded as a module, therefore init will be 1 + * if we are the default console, however if we are a fallback + * console, for example if fbcon has failed registration, then + * init will be 0, so we need to make sure our boot parameters + * have been copied to the console structure for vgacon_resize + * ultimately called by vc_resize. Any subsequent calls to + * vgacon_init init will have init set to 0 too. + */ + c->vc_can_do_color = vga_can_do_color; + c->vc_scan_lines = vga_scan_lines; + c->vc_font.height = c->vc_cell_height = vga_video_font_height; + + /* set dimensions manually if init != 0 since vc_resize() will fail */ + if (init) { + c->vc_cols = vga_video_num_columns; + c->vc_rows = vga_video_num_lines; + } else + vc_resize(c, vga_video_num_columns, vga_video_num_lines); + + c->vc_complement_mask = 0x7700; + if (vga_512_chars) + c->vc_hi_font_mask = 0x0800; + p = *c->uni_pagedict_loc; + if (c->uni_pagedict_loc != &vgacon_uni_pagedir) { + con_free_unimap(c); + c->uni_pagedict_loc = &vgacon_uni_pagedir; + vgacon_refcount++; + } + if (!vgacon_uni_pagedir && p) + con_set_default_unimap(c); + + /* Only set the default if the user didn't deliberately override it */ + if (global_cursor_default == -1) + global_cursor_default = + !(screen_info.flags & VIDEO_FLAGS_NOCURSOR); +} + +static void vgacon_deinit(struct vc_data *c) +{ + /* When closing the active console, reset video origin */ + if (con_is_visible(c)) { + c->vc_visible_origin = vga_vram_base; + vga_set_mem_top(c); + } + + if (!--vgacon_refcount) + con_free_unimap(c); + c->uni_pagedict_loc = &c->uni_pagedict; + con_set_default_unimap(c); +} + +static u8 vgacon_build_attr(struct vc_data *c, u8 color, + enum vc_intensity intensity, + bool blink, bool underline, bool reverse, + bool italic) +{ + u8 attr = color; + + if (vga_can_do_color) { + if (italic) + attr = (attr & 0xF0) | c->vc_itcolor; + else if (underline) + attr = (attr & 0xf0) | c->vc_ulcolor; + else if (intensity == VCI_HALF_BRIGHT) + attr = (attr & 0xf0) | c->vc_halfcolor; + } + if (reverse) + attr = + ((attr) & 0x88) | ((((attr) >> 4) | ((attr) << 4)) & + 0x77); + if (blink) + attr ^= 0x80; + if (intensity == VCI_BOLD) + attr ^= 0x08; + if (!vga_can_do_color) { + if (italic) + attr = (attr & 0xF8) | 0x02; + else if (underline) + attr = (attr & 0xf8) | 0x01; + else if (intensity == VCI_HALF_BRIGHT) + attr = (attr & 0xf0) | 0x08; + } + return attr; +} + +static void vgacon_invert_region(struct vc_data *c, u16 * p, int count) +{ + const bool col = vga_can_do_color; + + while (count--) { + u16 a = scr_readw(p); + if (col) + a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | + (((a) & 0x0700) << 4); + else + a ^= ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700; + scr_writew(a, p++); + } +} + +static void vgacon_set_cursor_size(int xpos, int from, int to) +{ + unsigned long flags; + int curs, cure; + + if ((from == cursor_size_lastfrom) && (to == cursor_size_lastto)) + return; + cursor_size_lastfrom = from; + cursor_size_lastto = to; + + raw_spin_lock_irqsave(&vga_lock, flags); + if (vga_video_type >= VIDEO_TYPE_VGAC) { + outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg); + curs = inb_p(vga_video_port_val); + outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg); + cure = inb_p(vga_video_port_val); + } else { + curs = 0; + cure = 0; + } + + curs = (curs & 0xc0) | from; + cure = (cure & 0xe0) | to; + + outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg); + outb_p(curs, vga_video_port_val); + outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg); + outb_p(cure, vga_video_port_val); + raw_spin_unlock_irqrestore(&vga_lock, flags); +} + +static void vgacon_cursor(struct vc_data *c, int mode) +{ + if (c->vc_mode != KD_TEXT) + return; + + vgacon_restore_screen(c); + + switch (mode) { + case CM_ERASE: + write_vga(14, (c->vc_pos - vga_vram_base) / 2); + if (vga_video_type >= VIDEO_TYPE_VGAC) + vgacon_set_cursor_size(c->state.x, 31, 30); + else + vgacon_set_cursor_size(c->state.x, 31, 31); + break; + + case CM_MOVE: + case CM_DRAW: + write_vga(14, (c->vc_pos - vga_vram_base) / 2); + switch (CUR_SIZE(c->vc_cursor_type)) { + case CUR_UNDERLINE: + vgacon_set_cursor_size(c->state.x, + c->vc_cell_height - + (c->vc_cell_height < + 10 ? 2 : 3), + c->vc_cell_height - + (c->vc_cell_height < + 10 ? 1 : 2)); + break; + case CUR_TWO_THIRDS: + vgacon_set_cursor_size(c->state.x, + c->vc_cell_height / 3, + c->vc_cell_height - + (c->vc_cell_height < + 10 ? 1 : 2)); + break; + case CUR_LOWER_THIRD: + vgacon_set_cursor_size(c->state.x, + (c->vc_cell_height * 2) / 3, + c->vc_cell_height - + (c->vc_cell_height < + 10 ? 1 : 2)); + break; + case CUR_LOWER_HALF: + vgacon_set_cursor_size(c->state.x, + c->vc_cell_height / 2, + c->vc_cell_height - + (c->vc_cell_height < + 10 ? 1 : 2)); + break; + case CUR_NONE: + if (vga_video_type >= VIDEO_TYPE_VGAC) + vgacon_set_cursor_size(c->state.x, 31, 30); + else + vgacon_set_cursor_size(c->state.x, 31, 31); + break; + default: + vgacon_set_cursor_size(c->state.x, 1, + c->vc_cell_height); + break; + } + break; + } +} + +static int vgacon_doresize(struct vc_data *c, + unsigned int width, unsigned int height) +{ + unsigned long flags; + unsigned int scanlines = height * c->vc_cell_height; + u8 scanlines_lo = 0, r7 = 0, vsync_end = 0, mode, max_scan; + + raw_spin_lock_irqsave(&vga_lock, flags); + + vgacon_xres = width * VGA_FONTWIDTH; + vgacon_yres = height * c->vc_cell_height; + if (vga_video_type >= VIDEO_TYPE_VGAC) { + outb_p(VGA_CRTC_MAX_SCAN, vga_video_port_reg); + max_scan = inb_p(vga_video_port_val); + + if (max_scan & 0x80) + scanlines <<= 1; + + outb_p(VGA_CRTC_MODE, vga_video_port_reg); + mode = inb_p(vga_video_port_val); + + if (mode & 0x04) + scanlines >>= 1; + + scanlines -= 1; + scanlines_lo = scanlines & 0xff; + + outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg); + r7 = inb_p(vga_video_port_val) & ~0x42; + + if (scanlines & 0x100) + r7 |= 0x02; + if (scanlines & 0x200) + r7 |= 0x40; + + /* deprotect registers */ + outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg); + vsync_end = inb_p(vga_video_port_val); + outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg); + outb_p(vsync_end & ~0x80, vga_video_port_val); + } + + outb_p(VGA_CRTC_H_DISP, vga_video_port_reg); + outb_p(width - 1, vga_video_port_val); + outb_p(VGA_CRTC_OFFSET, vga_video_port_reg); + outb_p(width >> 1, vga_video_port_val); + + if (vga_video_type >= VIDEO_TYPE_VGAC) { + outb_p(VGA_CRTC_V_DISP_END, vga_video_port_reg); + outb_p(scanlines_lo, vga_video_port_val); + outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg); + outb_p(r7,vga_video_port_val); + + /* reprotect registers */ + outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg); + outb_p(vsync_end, vga_video_port_val); + } + + raw_spin_unlock_irqrestore(&vga_lock, flags); + return 0; +} + +static int vgacon_switch(struct vc_data *c) +{ + int x = c->vc_cols * VGA_FONTWIDTH; + int y = c->vc_rows * c->vc_cell_height; + int rows = screen_info.orig_video_lines * vga_default_font_height/ + c->vc_cell_height; + /* + * We need to save screen size here as it's the only way + * we can spot the screen has been resized and we need to + * set size of freshly allocated screens ourselves. + */ + vga_video_num_columns = c->vc_cols; + vga_video_num_lines = c->vc_rows; + + /* We can only copy out the size of the video buffer here, + * otherwise we get into VGA BIOS */ + + if (!vga_is_gfx) { + scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf, + c->vc_screenbuf_size > vga_vram_size ? + vga_vram_size : c->vc_screenbuf_size); + + if ((vgacon_xres != x || vgacon_yres != y) && + (!(vga_video_num_columns % 2) && + vga_video_num_columns <= screen_info.orig_video_cols && + vga_video_num_lines <= rows)) + vgacon_doresize(c, c->vc_cols, c->vc_rows); + } + + return 0; /* Redrawing not needed */ +} + +static void vga_set_palette(struct vc_data *vc, const unsigned char *table) +{ + int i, j; + + vga_w(vgastate.vgabase, VGA_PEL_MSK, 0xff); + for (i = j = 0; i < 16; i++) { + vga_w(vgastate.vgabase, VGA_PEL_IW, table[i]); + vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2); + vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2); + vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2); + } +} + +static void vgacon_set_palette(struct vc_data *vc, const unsigned char *table) +{ + if (vga_video_type != VIDEO_TYPE_VGAC || vga_palette_blanked + || !con_is_visible(vc)) + return; + vga_set_palette(vc, table); +} + +/* structure holding original VGA register settings */ +static struct { + unsigned char SeqCtrlIndex; /* Sequencer Index reg. */ + unsigned char CrtCtrlIndex; /* CRT-Contr. Index reg. */ + unsigned char CrtMiscIO; /* Miscellaneous register */ + unsigned char HorizontalTotal; /* CRT-Controller:00h */ + unsigned char HorizDisplayEnd; /* CRT-Controller:01h */ + unsigned char StartHorizRetrace; /* CRT-Controller:04h */ + unsigned char EndHorizRetrace; /* CRT-Controller:05h */ + unsigned char Overflow; /* CRT-Controller:07h */ + unsigned char StartVertRetrace; /* CRT-Controller:10h */ + unsigned char EndVertRetrace; /* CRT-Controller:11h */ + unsigned char ModeControl; /* CRT-Controller:17h */ + unsigned char ClockingMode; /* Seq-Controller:01h */ +} vga_state; + +static void vga_vesa_blank(struct vgastate *state, int mode) +{ + /* save original values of VGA controller registers */ + if (!vga_vesa_blanked) { + raw_spin_lock_irq(&vga_lock); + vga_state.SeqCtrlIndex = vga_r(state->vgabase, VGA_SEQ_I); + vga_state.CrtCtrlIndex = inb_p(vga_video_port_reg); + vga_state.CrtMiscIO = vga_r(state->vgabase, VGA_MIS_R); + raw_spin_unlock_irq(&vga_lock); + + outb_p(0x00, vga_video_port_reg); /* HorizontalTotal */ + vga_state.HorizontalTotal = inb_p(vga_video_port_val); + outb_p(0x01, vga_video_port_reg); /* HorizDisplayEnd */ + vga_state.HorizDisplayEnd = inb_p(vga_video_port_val); + outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */ + vga_state.StartHorizRetrace = inb_p(vga_video_port_val); + outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */ + vga_state.EndHorizRetrace = inb_p(vga_video_port_val); + outb_p(0x07, vga_video_port_reg); /* Overflow */ + vga_state.Overflow = inb_p(vga_video_port_val); + outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */ + vga_state.StartVertRetrace = inb_p(vga_video_port_val); + outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */ + vga_state.EndVertRetrace = inb_p(vga_video_port_val); + outb_p(0x17, vga_video_port_reg); /* ModeControl */ + vga_state.ModeControl = inb_p(vga_video_port_val); + vga_state.ClockingMode = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE); + } + + /* assure that video is enabled */ + /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */ + raw_spin_lock_irq(&vga_lock); + vga_wseq(state->vgabase, VGA_SEQ_CLOCK_MODE, vga_state.ClockingMode | 0x20); + + /* test for vertical retrace in process.... */ + if ((vga_state.CrtMiscIO & 0x80) == 0x80) + vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO & 0xEF); + + /* + * Set <End of vertical retrace> to minimum (0) and + * <Start of vertical Retrace> to maximum (incl. overflow) + * Result: turn off vertical sync (VSync) pulse. + */ + if (mode & VESA_VSYNC_SUSPEND) { + outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */ + outb_p(0xff, vga_video_port_val); /* maximum value */ + outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */ + outb_p(0x40, vga_video_port_val); /* minimum (bits 0..3) */ + outb_p(0x07, vga_video_port_reg); /* Overflow */ + outb_p(vga_state.Overflow | 0x84, vga_video_port_val); /* bits 9,10 of vert. retrace */ + } + + if (mode & VESA_HSYNC_SUSPEND) { + /* + * Set <End of horizontal retrace> to minimum (0) and + * <Start of horizontal Retrace> to maximum + * Result: turn off horizontal sync (HSync) pulse. + */ + outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */ + outb_p(0xff, vga_video_port_val); /* maximum */ + outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */ + outb_p(0x00, vga_video_port_val); /* minimum (0) */ + } + + /* restore both index registers */ + vga_w(state->vgabase, VGA_SEQ_I, vga_state.SeqCtrlIndex); + outb_p(vga_state.CrtCtrlIndex, vga_video_port_reg); + raw_spin_unlock_irq(&vga_lock); +} + +static void vga_vesa_unblank(struct vgastate *state) +{ + /* restore original values of VGA controller registers */ + raw_spin_lock_irq(&vga_lock); + vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO); + + outb_p(0x00, vga_video_port_reg); /* HorizontalTotal */ + outb_p(vga_state.HorizontalTotal, vga_video_port_val); + outb_p(0x01, vga_video_port_reg); /* HorizDisplayEnd */ + outb_p(vga_state.HorizDisplayEnd, vga_video_port_val); + outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */ + outb_p(vga_state.StartHorizRetrace, vga_video_port_val); + outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */ + outb_p(vga_state.EndHorizRetrace, vga_video_port_val); + outb_p(0x07, vga_video_port_reg); /* Overflow */ + outb_p(vga_state.Overflow, vga_video_port_val); + outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */ + outb_p(vga_state.StartVertRetrace, vga_video_port_val); + outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */ + outb_p(vga_state.EndVertRetrace, vga_video_port_val); + outb_p(0x17, vga_video_port_reg); /* ModeControl */ + outb_p(vga_state.ModeControl, vga_video_port_val); + /* ClockingMode */ + vga_wseq(state->vgabase, VGA_SEQ_CLOCK_MODE, vga_state.ClockingMode); + + /* restore index/control registers */ + vga_w(state->vgabase, VGA_SEQ_I, vga_state.SeqCtrlIndex); + outb_p(vga_state.CrtCtrlIndex, vga_video_port_reg); + raw_spin_unlock_irq(&vga_lock); +} + +static void vga_pal_blank(struct vgastate *state) +{ + int i; + + vga_w(state->vgabase, VGA_PEL_MSK, 0xff); + for (i = 0; i < 16; i++) { + vga_w(state->vgabase, VGA_PEL_IW, i); + vga_w(state->vgabase, VGA_PEL_D, 0); + vga_w(state->vgabase, VGA_PEL_D, 0); + vga_w(state->vgabase, VGA_PEL_D, 0); + } +} + +static int vgacon_blank(struct vc_data *c, int blank, int mode_switch) +{ + switch (blank) { + case 0: /* Unblank */ + if (vga_vesa_blanked) { + vga_vesa_unblank(&vgastate); + vga_vesa_blanked = 0; + } + if (vga_palette_blanked) { + vga_set_palette(c, color_table); + vga_palette_blanked = false; + return 0; + } + vga_is_gfx = false; + /* Tell console.c that it has to restore the screen itself */ + return 1; + case 1: /* Normal blanking */ + case -1: /* Obsolete */ + if (!mode_switch && vga_video_type == VIDEO_TYPE_VGAC) { + vga_pal_blank(&vgastate); + vga_palette_blanked = true; + return 0; + } + vgacon_set_origin(c); + scr_memsetw((void *) vga_vram_base, BLANK, + c->vc_screenbuf_size); + if (mode_switch) + vga_is_gfx = true; + return 1; + default: /* VESA blanking */ + if (vga_video_type == VIDEO_TYPE_VGAC) { + vga_vesa_blank(&vgastate, blank - 1); + vga_vesa_blanked = blank; + } + return 0; + } +} + +/* + * PIO_FONT support. + * + * The font loading code goes back to the codepage package by + * Joel Hoffman (joel@wam.umd.edu). (He reports that the original + * reference is: "From: p. 307 of _Programmer's Guide to PC & PS/2 + * Video Systems_ by Richard Wilton. 1987. Microsoft Press".) + * + * Change for certain monochrome monitors by Yury Shevchuck + * (sizif@botik.yaroslavl.su). + */ + +#define colourmap 0xa0000 +/* Pauline Middelink <middelin@polyware.iaf.nl> reports that we + should use 0xA0000 for the bwmap as well.. */ +#define blackwmap 0xa0000 +#define cmapsz 8192 + +static int vgacon_do_font_op(struct vgastate *state, char *arg, int set, + bool ch512) +{ + unsigned short video_port_status = vga_video_port_reg + 6; + int font_select = 0x00, beg, i; + char *charmap; + bool clear_attribs = false; + if (vga_video_type != VIDEO_TYPE_EGAM) { + charmap = (char *) VGA_MAP_MEM(colourmap, 0); + beg = 0x0e; + } else { + charmap = (char *) VGA_MAP_MEM(blackwmap, 0); + beg = 0x0a; + } + + /* + * All fonts are loaded in slot 0 (0:1 for 512 ch) + */ + + if (!arg) + return -EINVAL; /* Return to default font not supported */ + + font_select = ch512 ? 0x04 : 0x00; + + raw_spin_lock_irq(&vga_lock); + /* First, the Sequencer */ + vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); + /* CPU writes only to map 2 */ + vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, 0x04); + /* Sequential addressing */ + vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, 0x07); + /* Clear synchronous reset */ + vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x03); + + /* Now, the graphics controller, select map 2 */ + vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, 0x02); + /* disable odd-even addressing */ + vga_wgfx(state->vgabase, VGA_GFX_MODE, 0x00); + /* map start at A000:0000 */ + vga_wgfx(state->vgabase, VGA_GFX_MISC, 0x00); + raw_spin_unlock_irq(&vga_lock); + + if (arg) { + if (set) + for (i = 0; i < cmapsz; i++) { + vga_writeb(arg[i], charmap + i); + cond_resched(); + } + else + for (i = 0; i < cmapsz; i++) { + arg[i] = vga_readb(charmap + i); + cond_resched(); + } + + /* + * In 512-character mode, the character map is not contiguous if + * we want to remain EGA compatible -- which we do + */ + + if (ch512) { + charmap += 2 * cmapsz; + arg += cmapsz; + if (set) + for (i = 0; i < cmapsz; i++) { + vga_writeb(arg[i], charmap + i); + cond_resched(); + } + else + for (i = 0; i < cmapsz; i++) { + arg[i] = vga_readb(charmap + i); + cond_resched(); + } + } + } + + raw_spin_lock_irq(&vga_lock); + /* First, the sequencer, Synchronous reset */ + vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x01); + /* CPU writes to maps 0 and 1 */ + vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, 0x03); + /* odd-even addressing */ + vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, 0x03); + /* Character Map Select */ + if (set) + vga_wseq(state->vgabase, VGA_SEQ_CHARACTER_MAP, font_select); + /* clear synchronous reset */ + vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x03); + + /* Now, the graphics controller, select map 0 for CPU */ + vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, 0x00); + /* enable even-odd addressing */ + vga_wgfx(state->vgabase, VGA_GFX_MODE, 0x10); + /* map starts at b800:0 or b000:0 */ + vga_wgfx(state->vgabase, VGA_GFX_MISC, beg); + + /* if 512 char mode is already enabled don't re-enable it. */ + if ((set) && (ch512 != vga_512_chars)) { + vga_512_chars = ch512; + /* 256-char: enable intensity bit + 512-char: disable intensity bit */ + inb_p(video_port_status); /* clear address flip-flop */ + /* color plane enable register */ + vga_wattr(state->vgabase, VGA_ATC_PLANE_ENABLE, ch512 ? 0x07 : 0x0f); + /* Wilton (1987) mentions the following; I don't know what + it means, but it works, and it appears necessary */ + inb_p(video_port_status); + vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0); + clear_attribs = true; + } + raw_spin_unlock_irq(&vga_lock); + + if (clear_attribs) { + for (i = 0; i < MAX_NR_CONSOLES; i++) { + struct vc_data *c = vc_cons[i].d; + if (c && c->vc_sw == &vga_con) { + /* force hi font mask to 0, so we always clear + the bit on either transition */ + c->vc_hi_font_mask = 0x00; + clear_buffer_attributes(c); + c->vc_hi_font_mask = ch512 ? 0x0800 : 0; + } + } + } + return 0; +} + +/* + * Adjust the screen to fit a font of a certain height + */ +static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight) +{ + unsigned char ovr, vde, fsr; + int rows, maxscan, i; + + rows = vc->vc_scan_lines / fontheight; /* Number of video rows we end up with */ + maxscan = rows * fontheight - 1; /* Scan lines to actually display-1 */ + + /* Reprogram the CRTC for the new font size + Note: the attempt to read the overflow register will fail + on an EGA, but using 0xff for the previous value appears to + be OK for EGA text modes in the range 257-512 scan lines, so I + guess we don't need to worry about it. + + The same applies for the spill bits in the font size and cursor + registers; they are write-only on EGA, but it appears that they + are all don't care bits on EGA, so I guess it doesn't matter. */ + + raw_spin_lock_irq(&vga_lock); + outb_p(0x07, vga_video_port_reg); /* CRTC overflow register */ + ovr = inb_p(vga_video_port_val); + outb_p(0x09, vga_video_port_reg); /* Font size register */ + fsr = inb_p(vga_video_port_val); + raw_spin_unlock_irq(&vga_lock); + + vde = maxscan & 0xff; /* Vertical display end reg */ + ovr = (ovr & 0xbd) + /* Overflow register */ + ((maxscan & 0x100) >> 7) + ((maxscan & 0x200) >> 3); + fsr = (fsr & 0xe0) + (fontheight - 1); /* Font size register */ + + raw_spin_lock_irq(&vga_lock); + outb_p(0x07, vga_video_port_reg); /* CRTC overflow register */ + outb_p(ovr, vga_video_port_val); + outb_p(0x09, vga_video_port_reg); /* Font size */ + outb_p(fsr, vga_video_port_val); + outb_p(0x12, vga_video_port_reg); /* Vertical display limit */ + outb_p(vde, vga_video_port_val); + raw_spin_unlock_irq(&vga_lock); + vga_video_font_height = fontheight; + + for (i = 0; i < MAX_NR_CONSOLES; i++) { + struct vc_data *c = vc_cons[i].d; + + if (c && c->vc_sw == &vga_con) { + if (con_is_visible(c)) { + /* void size to cause regs to be rewritten */ + cursor_size_lastfrom = 0; + cursor_size_lastto = 0; + c->vc_sw->con_cursor(c, CM_DRAW); + } + c->vc_font.height = c->vc_cell_height = fontheight; + vc_resize(c, 0, rows); /* Adjust console size */ + } + } + return 0; +} + +static int vgacon_font_set(struct vc_data *c, struct console_font *font, + unsigned int flags) +{ + unsigned charcount = font->charcount; + int rc; + + if (vga_video_type < VIDEO_TYPE_EGAM) + return -EINVAL; + + if (font->width != VGA_FONTWIDTH || + (charcount != 256 && charcount != 512)) + return -EINVAL; + + rc = vgacon_do_font_op(&vgastate, font->data, 1, charcount == 512); + if (rc) + return rc; + + if (!(flags & KD_FONT_FLAG_DONT_RECALC)) + rc = vgacon_adjust_height(c, font->height); + return rc; +} + +static int vgacon_font_get(struct vc_data *c, struct console_font *font) +{ + if (vga_video_type < VIDEO_TYPE_EGAM) + return -EINVAL; + + font->width = VGA_FONTWIDTH; + font->height = c->vc_font.height; + font->charcount = vga_512_chars ? 512 : 256; + if (!font->data) + return 0; + return vgacon_do_font_op(&vgastate, font->data, 0, vga_512_chars); +} + +static int vgacon_resize(struct vc_data *c, unsigned int width, + unsigned int height, unsigned int user) +{ + if ((width << 1) * height > vga_vram_size) + return -EINVAL; + + if (user) { + /* + * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed + * the video mode! Set the new defaults then and go away. + */ + screen_info.orig_video_cols = width; + screen_info.orig_video_lines = height; + vga_default_font_height = c->vc_cell_height; + return 0; + } + if (width % 2 || width > screen_info.orig_video_cols || + height > (screen_info.orig_video_lines * vga_default_font_height)/ + c->vc_cell_height) + return -EINVAL; + + if (con_is_visible(c) && !vga_is_gfx) /* who knows */ + vgacon_doresize(c, width, height); + return 0; +} + +static int vgacon_set_origin(struct vc_data *c) +{ + if (vga_is_gfx || /* We don't play origin tricks in graphic modes */ + (console_blanked && !vga_palette_blanked)) /* Nor we write to blanked screens */ + return 0; + c->vc_origin = c->vc_visible_origin = vga_vram_base; + vga_set_mem_top(c); + vga_rolled_over = 0; + return 1; +} + +static void vgacon_save_screen(struct vc_data *c) +{ + static int vga_bootup_console = 0; + + if (!vga_bootup_console) { + /* This is a gross hack, but here is the only place we can + * set bootup console parameters without messing up generic + * console initialization routines. + */ + vga_bootup_console = 1; + c->state.x = screen_info.orig_x; + c->state.y = screen_info.orig_y; + } + + /* We can't copy in more than the size of the video buffer, + * or we'll be copying in VGA BIOS */ + + if (!vga_is_gfx) + scr_memcpyw((u16 *) c->vc_screenbuf, (u16 *) c->vc_origin, + c->vc_screenbuf_size > vga_vram_size ? vga_vram_size : c->vc_screenbuf_size); +} + +static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b, + enum con_scroll dir, unsigned int lines) +{ + unsigned long oldo; + unsigned int delta; + + if (t || b != c->vc_rows || vga_is_gfx || c->vc_mode != KD_TEXT) + return false; + + if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2) + return false; + + vgacon_restore_screen(c); + oldo = c->vc_origin; + delta = lines * c->vc_size_row; + if (dir == SM_UP) { + if (c->vc_scr_end + delta >= vga_vram_end) { + scr_memcpyw((u16 *) vga_vram_base, + (u16 *) (oldo + delta), + c->vc_screenbuf_size - delta); + c->vc_origin = vga_vram_base; + vga_rolled_over = oldo - vga_vram_base; + } else + c->vc_origin += delta; + scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size - + delta), c->vc_video_erase_char, + delta); + } else { + if (oldo - delta < vga_vram_base) { + scr_memmovew((u16 *) (vga_vram_end - + c->vc_screenbuf_size + + delta), (u16 *) oldo, + c->vc_screenbuf_size - delta); + c->vc_origin = vga_vram_end - c->vc_screenbuf_size; + vga_rolled_over = 0; + } else + c->vc_origin -= delta; + c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; + scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char, + delta); + } + c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; + c->vc_visible_origin = c->vc_origin; + vga_set_mem_top(c); + c->vc_pos = (c->vc_pos - oldo) + c->vc_origin; + return true; +} + +/* + * The console `switch' structure for the VGA based console + */ + +static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height, + int width) { } +static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { } +static void vgacon_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos) { } + +const struct consw vga_con = { + .owner = THIS_MODULE, + .con_startup = vgacon_startup, + .con_init = vgacon_init, + .con_deinit = vgacon_deinit, + .con_clear = vgacon_clear, + .con_putc = vgacon_putc, + .con_putcs = vgacon_putcs, + .con_cursor = vgacon_cursor, + .con_scroll = vgacon_scroll, + .con_switch = vgacon_switch, + .con_blank = vgacon_blank, + .con_font_set = vgacon_font_set, + .con_font_get = vgacon_font_get, + .con_resize = vgacon_resize, + .con_set_palette = vgacon_set_palette, + .con_scrolldelta = vgacon_scrolldelta, + .con_set_origin = vgacon_set_origin, + .con_save_screen = vgacon_save_screen, + .con_build_attr = vgacon_build_attr, + .con_invert_region = vgacon_invert_region, +}; +EXPORT_SYMBOL(vga_con); + +MODULE_LICENSE("GPL"); |