video: Move HP PARISC STI core code to shared location
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 17 Apr 2023 12:56:43 +0000 (14:56 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Thu, 20 Apr 2023 08:04:51 +0000 (10:04 +0200)
STI core files have been located in console and fbdev code. Move
the source code and header to the directories for video helpers.
Also update the config and build rules such that the code depends
on the config symbol CONFIG_STI_CORE, which STI console and STI
framebuffer select automatically.

Cleans up the console makefile and prepares PARISC to implement
fb_is_primary_device() within the arch/ directory. No functional
changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Helge Deller <deller@gmx.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230417125651.25126-12-tzimmermann@suse.de
drivers/video/Kconfig
drivers/video/Makefile
drivers/video/console/Kconfig
drivers/video/console/Makefile
drivers/video/console/sticon.c
drivers/video/console/sticore.c [deleted file]
drivers/video/fbdev/Kconfig
drivers/video/fbdev/sticore.h [deleted file]
drivers/video/fbdev/stifb.c
drivers/video/sticore.c [new file with mode: 0644]
include/video/sticore.h [new file with mode: 0644]

index bf05363..8b2b9ac 100644 (file)
@@ -11,6 +11,13 @@ config APERTURE_HELPERS
          Support tracking and hand-over of aperture ownership. Required
          by graphics drivers for firmware-provided framebuffers.
 
+config STI_CORE
+       bool
+       depends on PARISC
+       help
+         STI refers to the HP "Standard Text Interface" which is a set of
+         BIOS routines contained in a ROM chip in HP PA-RISC based machines.
+
 config VIDEO_CMDLINE
        bool
 
index 831c9fa..6bbc039 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_APERTURE_HELPERS)    += aperture.o
+obj-$(CONFIG_STI_CORE)            += sticore.o
 obj-$(CONFIG_VGASTATE)            += vgastate.o
 obj-$(CONFIG_VIDEO_CMDLINE)       += cmdline.o
 obj-$(CONFIG_VIDEO_NOMODESET)     += nomodeset.o
index 22cea50..a2a88d4 100644 (file)
@@ -141,6 +141,7 @@ config STI_CONSOLE
        depends on PARISC && HAS_IOMEM
        select FONT_SUPPORT
        select CRC32
+       select STI_CORE
        default y
        help
          The STI console is the builtin display/keyboard on HP-PARISC
index db07b78..fd79016 100644 (file)
@@ -5,8 +5,6 @@
 
 obj-$(CONFIG_DUMMY_CONSOLE)       += dummycon.o
 obj-$(CONFIG_SGI_NEWPORT_CONSOLE) += newport_con.o
-obj-$(CONFIG_STI_CONSOLE)         += sticon.o sticore.o
+obj-$(CONFIG_STI_CONSOLE)         += sticon.o
 obj-$(CONFIG_VGA_CONSOLE)         += vgacon.o
 obj-$(CONFIG_MDA_CONSOLE)         += mdacon.o
-
-obj-$(CONFIG_FB_STI)              += sticore.o
index 89ad7ad..d11cfd2 100644 (file)
@@ -50,7 +50,7 @@
 
 #include <asm/io.h>
 
-#include "../fbdev/sticore.h"
+#include <video/sticore.h>
 
 /* switching to graphics mode */
 #define BLANK 0
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
deleted file mode 100644 (file)
index 6ea9596..0000000
+++ /dev/null
@@ -1,1172 +0,0 @@
-// 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");
-
index 96e9157..485e8c3 100644 (file)
@@ -551,10 +551,9 @@ config FB_STI
        select FB_CFB_FILLRECT
        select FB_CFB_COPYAREA
        select FB_CFB_IMAGEBLIT
+       select STI_CORE
        default y
        help
-         STI refers to the HP "Standard Text Interface" which is a set of
-         BIOS routines contained in a ROM chip in HP PA-RISC based machines.
          Enabling this option will implement the linux framebuffer device
          using calls to the STI BIOS routines for initialisation.
 
diff --git a/drivers/video/fbdev/sticore.h b/drivers/video/fbdev/sticore.h
deleted file mode 100644 (file)
index c087935..0000000
+++ /dev/null
@@ -1,404 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef STICORE_H
-#define STICORE_H
-
-/* generic STI structures & functions */
-
-#define MAX_STI_ROMS 4         /* max no. of ROMs which this driver handles */
-
-#define STI_REGION_MAX 8       /* hardcoded STI constants */
-#define STI_DEV_NAME_LENGTH 32
-#define STI_MONITOR_MAX 256
-
-#define STI_FONT_HPROMAN8 1
-#define STI_FONT_KANA8 2
-
-#define ALT_CODE_TYPE_UNKNOWN 0x00     /* alt code type values */
-#define ALT_CODE_TYPE_PA_RISC_64 0x01
-
-/* The latency of the STI functions cannot really be reduced by setting
- * this to 0;  STI doesn't seem to be designed to allow calling a different
- * function (or the same function with different arguments) after a
- * function exited with 1 as return value.
- *
- * As all of the functions below could be called from interrupt context,
- * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
- * block.  Really bad latency there.
- *
- * Probably the best solution to all this is have the generic code manage
- * the screen buffer and a kernel thread to call STI occasionally.
- *
- * Luckily, the frame buffer guys have the same problem so we can just wait
- * for them to fix it and steal their solution.   prumpf
- */
-
-#include <asm/io.h>
-
-#define STI_WAIT 1
-
-#define STI_PTR(p)     ( virt_to_phys(p) )
-#define PTR_STI(p)     ( phys_to_virt((unsigned long)p) )
-
-#define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
-#define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
-
-/* sti_font_xy() use the native font ROM ! */
-#define sti_font_x(sti) (PTR_STI(sti->font)->width)
-#define sti_font_y(sti) (PTR_STI(sti->font)->height)
-
-#ifdef CONFIG_64BIT
-#define STI_LOWMEM     (GFP_KERNEL | GFP_DMA)
-#else
-#define STI_LOWMEM     (GFP_KERNEL)
-#endif
-
-
-/* STI function configuration structs */
-
-typedef union region {
-       struct {
-               u32 offset      : 14;   /* offset in 4kbyte page */
-               u32 sys_only    : 1;    /* don't map to user space */
-               u32 cache       : 1;    /* map to data cache */
-               u32 btlb        : 1;    /* map to block tlb */
-               u32 last        : 1;    /* last region in list */
-               u32 length      : 14;   /* length in 4kbyte page */
-       } region_desc;
-
-       u32 region;                     /* complete region value */
-} region_t;
-
-#define REGION_OFFSET_TO_PHYS( rt, hpa ) \
-       (((rt).region_desc.offset << 12) + (hpa))
-
-struct sti_glob_cfg_ext {
-        u8 curr_mon;                   /* current monitor configured */
-        u8 friendly_boot;              /* in friendly boot mode */
-       s16 power;                      /* power calculation (in Watts) */
-       s32 freq_ref;                   /* frequency reference */
-       u32 sti_mem_addr;               /* pointer to global sti memory (size=sti_mem_request) */
-       u32 future_ptr;                 /* pointer to future data */
-};
-
-struct sti_glob_cfg {
-       s32 text_planes;                /* number of planes used for text */
-       s16 onscreen_x;                 /* screen width in pixels */
-       s16 onscreen_y;                 /* screen height in pixels */
-       s16 offscreen_x;                /* offset width in pixels */
-       s16 offscreen_y;                /* offset height in pixels */
-       s16 total_x;                    /* frame buffer width in pixels */
-       s16 total_y;                    /* frame buffer height in pixels */
-       u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
-       s32 reent_lvl;                  /* storage for reentry level value */
-       u32 save_addr;                  /* where to save or restore reentrant state */
-       u32 ext_ptr;                    /* pointer to extended glob_cfg data structure */
-};
-
-
-/* STI init function structs */
-
-struct sti_init_flags {
-       u32 wait : 1;           /* should routine idle wait or not */
-       u32 reset : 1;          /* hard reset the device? */
-       u32 text : 1;           /* turn on text display planes? */
-       u32 nontext : 1;        /* turn on non-text display planes? */
-       u32 clear : 1;          /* clear text display planes? */
-       u32 cmap_blk : 1;       /* non-text planes cmap black? */
-       u32 enable_be_timer : 1; /* enable bus error timer */
-       u32 enable_be_int : 1;  /* enable bus error timer interrupt */
-       u32 no_chg_tx : 1;      /* don't change text settings */
-       u32 no_chg_ntx : 1;     /* don't change non-text settings */
-       u32 no_chg_bet : 1;     /* don't change berr timer settings */
-       u32 no_chg_bei : 1;     /* don't change berr int settings */
-       u32 init_cmap_tx : 1;   /* initialize cmap for text planes */
-       u32 cmt_chg : 1;        /* change current monitor type */
-       u32 retain_ie : 1;      /* don't allow reset to clear int enables */
-       u32 caller_bootrom : 1; /* set only by bootrom for each call */
-       u32 caller_kernel : 1;  /* set only by kernel for each call */
-       u32 caller_other : 1;   /* set only by non-[BR/K] caller */
-       u32 pad : 14;           /* pad to word boundary */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_init_inptr_ext {
-       u8  config_mon_type;    /* configure to monitor type */
-       u8  pad[1];             /* pad to word boundary */
-       u16 inflight_data;      /* inflight data possible on PCI */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_init_inptr {
-       s32 text_planes;        /* number of planes to use for text */
-       u32 ext_ptr;            /* pointer to extended init_graph inptr data structure*/
-};
-
-
-struct sti_init_outptr {
-       s32 errno;              /* error number on failure */
-       s32 text_planes;        /* number of planes used for text */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-
-
-/* STI configuration function structs */
-
-struct sti_conf_flags {
-       u32 wait : 1;           /* should routine idle wait or not */
-       u32 pad : 31;           /* pad to word boundary */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_conf_inptr {
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_conf_outptr_ext {
-       u32 crt_config[3];      /* hardware specific X11/OGL information */
-       u32 crt_hdw[3];
-       u32 future_ptr;
-};
-
-struct sti_conf_outptr {
-       s32 errno;              /* error number on failure */
-       s16 onscreen_x;         /* screen width in pixels */
-       s16 onscreen_y;         /* screen height in pixels */
-       s16 offscreen_x;        /* offscreen width in pixels */
-       s16 offscreen_y;        /* offscreen height in pixels */
-       s16 total_x;            /* frame buffer width in pixels */
-       s16 total_y;            /* frame buffer height in pixels */
-       s32 bits_per_pixel;     /* bits/pixel device has configured */
-       s32 bits_used;          /* bits which can be accessed */
-       s32 planes;             /* number of fb planes in system */
-        u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
-       u32 attributes;         /* flags denoting attributes */
-       u32 ext_ptr;            /* pointer to future data */
-};
-
-struct sti_rom {
-        u8 type[4];
-        u8 res004;
-        u8 num_mons;
-        u8 revno[2];
-       u32 graphics_id[2];
-
-       u32 font_start;
-       u32 statesize;
-       u32 last_addr;
-       u32 region_list;
-
-       u16 reentsize;
-       u16 maxtime;
-       u32 mon_tbl_addr;
-       u32 user_data_addr;
-       u32 sti_mem_req;
-
-       u32 user_data_size;
-       u16 power;
-        u8 bus_support;
-        u8 ext_bus_support;
-        u8 alt_code_type;
-        u8 ext_dd_struct[3];
-       u32 cfb_addr;
-
-       u32 init_graph;
-       u32 state_mgmt;
-       u32 font_unpmv;
-       u32 block_move;
-       u32 self_test;
-       u32 excep_hdlr;
-       u32 inq_conf;
-       u32 set_cm_entry;
-       u32 dma_ctrl;
-        u8 res040[7 * 4];
-
-       u32 init_graph_addr;
-       u32 state_mgmt_addr;
-       u32 font_unp_addr;
-       u32 block_move_addr;
-       u32 self_test_addr;
-       u32 excep_hdlr_addr;
-       u32 inq_conf_addr;
-       u32 set_cm_entry_addr;
-       u32 image_unpack_addr;
-       u32 pa_risx_addrs[7];
-};
-
-struct sti_rom_font {
-       u16 first_char;
-       u16 last_char;
-        u8 width;
-        u8 height;
-        u8 font_type;          /* language type */
-        u8 bytes_per_char;
-       u32 next_font;
-        u8 underline_height;
-        u8 underline_pos;
-        u8 res008[2];
-};
-
-/* sticore internal font handling */
-
-struct sti_cooked_font {
-       struct sti_rom_font *raw;       /* native ptr for STI functions */
-       void *raw_ptr;                  /* kmalloc'ed font data */
-       struct sti_cooked_font *next_font;
-       int height, width;
-       int refcount;
-       u32 crc;
-};
-
-struct sti_cooked_rom {
-        struct sti_rom *raw;
-       struct sti_cooked_font *font_start;
-};
-
-/* STI font printing function structs */
-
-struct sti_font_inptr {
-       u32 font_start_addr;    /* address of font start */
-       s16 index;              /* index into font table of character */
-       u8 fg_color;            /* foreground color of character */
-       u8 bg_color;            /* background color of character */
-       s16 dest_x;             /* X location of character upper left */
-       s16 dest_y;             /* Y location of character upper left */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_font_flags {
-       u32 wait : 1;           /* should routine idle wait or not */
-       u32 non_text : 1;       /* font unpack/move in non_text planes =1, text =0 */
-       u32 pad : 30;           /* pad to word boundary */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_font_outptr {
-       s32 errno;              /* error number on failure */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-/* STI blockmove structs */
-
-struct sti_blkmv_flags {
-       u32 wait : 1;           /* should routine idle wait or not */
-       u32 color : 1;          /* change color during move? */
-       u32 clear : 1;          /* clear during move? */
-       u32 non_text : 1;       /* block move in non_text planes =1, text =0 */
-       u32 pad : 28;           /* pad to word boundary */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_blkmv_inptr {
-       u8 fg_color;            /* foreground color after move */
-       u8 bg_color;            /* background color after move */
-       s16 src_x;              /* source upper left pixel x location */
-       s16 src_y;              /* source upper left pixel y location */
-       s16 dest_x;             /* dest upper left pixel x location */
-       s16 dest_y;             /* dest upper left pixel y location */
-       s16 width;              /* block width in pixels */
-       s16 height;             /* block height in pixels */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-struct sti_blkmv_outptr {
-       s32 errno;              /* error number on failure */
-       u32 future_ptr;         /* pointer to future data */
-};
-
-
-/* sti_all_data is an internal struct which needs to be allocated in
- * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
-
-struct sti_all_data {
-       struct sti_glob_cfg glob_cfg;
-       struct sti_glob_cfg_ext glob_cfg_ext;
-
-       struct sti_conf_inptr           inq_inptr;
-       struct sti_conf_outptr          inq_outptr; /* configuration */
-       struct sti_conf_outptr_ext      inq_outptr_ext;
-
-       struct sti_init_inptr_ext       init_inptr_ext;
-       struct sti_init_inptr           init_inptr;
-       struct sti_init_outptr          init_outptr;
-
-       struct sti_blkmv_inptr          blkmv_inptr;
-       struct sti_blkmv_outptr         blkmv_outptr;
-
-       struct sti_font_inptr           font_inptr;
-       struct sti_font_outptr          font_outptr;
-
-       /* leave as last entries */
-       unsigned long save_addr[1024 / sizeof(unsigned long)];
-          /* min 256 bytes which is STI default, max sti->sti_mem_request */
-       unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
-       /* do not add something below here ! */
-};
-
-/* internal generic STI struct */
-
-struct sti_struct {
-       spinlock_t lock;
-
-       /* char **mon_strings; */
-       int sti_mem_request;
-       u32 graphics_id[2];
-
-       struct sti_cooked_rom *rom;
-
-       unsigned long font_unpmv;
-       unsigned long block_move;
-       unsigned long init_graph;
-       unsigned long inq_conf;
-
-       /* all following fields are initialized by the generic routines */
-       int text_planes;
-       region_t regions[STI_REGION_MAX];
-       unsigned long regions_phys[STI_REGION_MAX];
-
-       struct sti_glob_cfg *glob_cfg;  /* points into sti_all_data */
-
-       int wordmode;
-       struct sti_cooked_font *font;   /* ptr to selected font (cooked) */
-
-       struct pci_dev *pd;
-
-       /* PCI data structures (pg. 17ff from sti.pdf) */
-       u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
-
-       /* pointer to the fb_info where this STI device is used */
-       struct fb_info *info;
-
-       /* pointer to all internal data */
-       struct sti_all_data *sti_data;
-
-       /* pa_path of this device */
-       char pa_path[24];
-};
-
-
-/* sticore interface functions */
-
-struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
-void sti_font_convert_bytemode(struct sti_struct *sti, struct sti_cooked_font *f);
-
-
-/* sticore main function to call STI firmware */
-
-int sti_call(const struct sti_struct *sti, unsigned long func,
-               const void *flags, void *inptr, void *outptr,
-               struct sti_glob_cfg *glob_cfg);
-
-
-/* functions to call the STI ROM directly */
-
-void sti_putc(struct sti_struct *sti, int c, int y, int x,
-               struct sti_cooked_font *font);
-void sti_set(struct sti_struct *sti, int src_y, int src_x,
-               int height, int width, u8 color);
-void sti_clear(struct sti_struct *sti, int src_y, int src_x,
-               int height, int width, int c, struct sti_cooked_font *font);
-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);
-
-#endif /* STICORE_H */
index 99996bc..baca697 100644 (file)
@@ -69,7 +69,7 @@
 #include <asm/grfioctl.h>      /* for HP-UX compatibility */
 #include <linux/uaccess.h>
 
-#include "sticore.h"
+#include <video/sticore.h>
 
 /* REGION_BASE(fb_info, index) returns the virtual address for region <index> */
 #define REGION_BASE(fb_info, index) \
diff --git a/drivers/video/sticore.c b/drivers/video/sticore.c
new file mode 100644 (file)
index 0000000..f8aaede
--- /dev/null
@@ -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 <video/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/include/video/sticore.h b/include/video/sticore.h
new file mode 100644 (file)
index 0000000..c087935
--- /dev/null
@@ -0,0 +1,404 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef STICORE_H
+#define STICORE_H
+
+/* generic STI structures & functions */
+
+#define MAX_STI_ROMS 4         /* max no. of ROMs which this driver handles */
+
+#define STI_REGION_MAX 8       /* hardcoded STI constants */
+#define STI_DEV_NAME_LENGTH 32
+#define STI_MONITOR_MAX 256
+
+#define STI_FONT_HPROMAN8 1
+#define STI_FONT_KANA8 2
+
+#define ALT_CODE_TYPE_UNKNOWN 0x00     /* alt code type values */
+#define ALT_CODE_TYPE_PA_RISC_64 0x01
+
+/* The latency of the STI functions cannot really be reduced by setting
+ * this to 0;  STI doesn't seem to be designed to allow calling a different
+ * function (or the same function with different arguments) after a
+ * function exited with 1 as return value.
+ *
+ * As all of the functions below could be called from interrupt context,
+ * we have to spin_lock_irqsave around the do { ret = bla(); } while(ret==1)
+ * block.  Really bad latency there.
+ *
+ * Probably the best solution to all this is have the generic code manage
+ * the screen buffer and a kernel thread to call STI occasionally.
+ *
+ * Luckily, the frame buffer guys have the same problem so we can just wait
+ * for them to fix it and steal their solution.   prumpf
+ */
+
+#include <asm/io.h>
+
+#define STI_WAIT 1
+
+#define STI_PTR(p)     ( virt_to_phys(p) )
+#define PTR_STI(p)     ( phys_to_virt((unsigned long)p) )
+
+#define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
+#define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
+
+/* sti_font_xy() use the native font ROM ! */
+#define sti_font_x(sti) (PTR_STI(sti->font)->width)
+#define sti_font_y(sti) (PTR_STI(sti->font)->height)
+
+#ifdef CONFIG_64BIT
+#define STI_LOWMEM     (GFP_KERNEL | GFP_DMA)
+#else
+#define STI_LOWMEM     (GFP_KERNEL)
+#endif
+
+
+/* STI function configuration structs */
+
+typedef union region {
+       struct {
+               u32 offset      : 14;   /* offset in 4kbyte page */
+               u32 sys_only    : 1;    /* don't map to user space */
+               u32 cache       : 1;    /* map to data cache */
+               u32 btlb        : 1;    /* map to block tlb */
+               u32 last        : 1;    /* last region in list */
+               u32 length      : 14;   /* length in 4kbyte page */
+       } region_desc;
+
+       u32 region;                     /* complete region value */
+} region_t;
+
+#define REGION_OFFSET_TO_PHYS( rt, hpa ) \
+       (((rt).region_desc.offset << 12) + (hpa))
+
+struct sti_glob_cfg_ext {
+        u8 curr_mon;                   /* current monitor configured */
+        u8 friendly_boot;              /* in friendly boot mode */
+       s16 power;                      /* power calculation (in Watts) */
+       s32 freq_ref;                   /* frequency reference */
+       u32 sti_mem_addr;               /* pointer to global sti memory (size=sti_mem_request) */
+       u32 future_ptr;                 /* pointer to future data */
+};
+
+struct sti_glob_cfg {
+       s32 text_planes;                /* number of planes used for text */
+       s16 onscreen_x;                 /* screen width in pixels */
+       s16 onscreen_y;                 /* screen height in pixels */
+       s16 offscreen_x;                /* offset width in pixels */
+       s16 offscreen_y;                /* offset height in pixels */
+       s16 total_x;                    /* frame buffer width in pixels */
+       s16 total_y;                    /* frame buffer height in pixels */
+       u32 region_ptrs[STI_REGION_MAX]; /* region pointers */
+       s32 reent_lvl;                  /* storage for reentry level value */
+       u32 save_addr;                  /* where to save or restore reentrant state */
+       u32 ext_ptr;                    /* pointer to extended glob_cfg data structure */
+};
+
+
+/* STI init function structs */
+
+struct sti_init_flags {
+       u32 wait : 1;           /* should routine idle wait or not */
+       u32 reset : 1;          /* hard reset the device? */
+       u32 text : 1;           /* turn on text display planes? */
+       u32 nontext : 1;        /* turn on non-text display planes? */
+       u32 clear : 1;          /* clear text display planes? */
+       u32 cmap_blk : 1;       /* non-text planes cmap black? */
+       u32 enable_be_timer : 1; /* enable bus error timer */
+       u32 enable_be_int : 1;  /* enable bus error timer interrupt */
+       u32 no_chg_tx : 1;      /* don't change text settings */
+       u32 no_chg_ntx : 1;     /* don't change non-text settings */
+       u32 no_chg_bet : 1;     /* don't change berr timer settings */
+       u32 no_chg_bei : 1;     /* don't change berr int settings */
+       u32 init_cmap_tx : 1;   /* initialize cmap for text planes */
+       u32 cmt_chg : 1;        /* change current monitor type */
+       u32 retain_ie : 1;      /* don't allow reset to clear int enables */
+       u32 caller_bootrom : 1; /* set only by bootrom for each call */
+       u32 caller_kernel : 1;  /* set only by kernel for each call */
+       u32 caller_other : 1;   /* set only by non-[BR/K] caller */
+       u32 pad : 14;           /* pad to word boundary */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_init_inptr_ext {
+       u8  config_mon_type;    /* configure to monitor type */
+       u8  pad[1];             /* pad to word boundary */
+       u16 inflight_data;      /* inflight data possible on PCI */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_init_inptr {
+       s32 text_planes;        /* number of planes to use for text */
+       u32 ext_ptr;            /* pointer to extended init_graph inptr data structure*/
+};
+
+
+struct sti_init_outptr {
+       s32 errno;              /* error number on failure */
+       s32 text_planes;        /* number of planes used for text */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+
+
+/* STI configuration function structs */
+
+struct sti_conf_flags {
+       u32 wait : 1;           /* should routine idle wait or not */
+       u32 pad : 31;           /* pad to word boundary */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_conf_inptr {
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_conf_outptr_ext {
+       u32 crt_config[3];      /* hardware specific X11/OGL information */
+       u32 crt_hdw[3];
+       u32 future_ptr;
+};
+
+struct sti_conf_outptr {
+       s32 errno;              /* error number on failure */
+       s16 onscreen_x;         /* screen width in pixels */
+       s16 onscreen_y;         /* screen height in pixels */
+       s16 offscreen_x;        /* offscreen width in pixels */
+       s16 offscreen_y;        /* offscreen height in pixels */
+       s16 total_x;            /* frame buffer width in pixels */
+       s16 total_y;            /* frame buffer height in pixels */
+       s32 bits_per_pixel;     /* bits/pixel device has configured */
+       s32 bits_used;          /* bits which can be accessed */
+       s32 planes;             /* number of fb planes in system */
+        u8 dev_name[STI_DEV_NAME_LENGTH]; /* null terminated product name */
+       u32 attributes;         /* flags denoting attributes */
+       u32 ext_ptr;            /* pointer to future data */
+};
+
+struct sti_rom {
+        u8 type[4];
+        u8 res004;
+        u8 num_mons;
+        u8 revno[2];
+       u32 graphics_id[2];
+
+       u32 font_start;
+       u32 statesize;
+       u32 last_addr;
+       u32 region_list;
+
+       u16 reentsize;
+       u16 maxtime;
+       u32 mon_tbl_addr;
+       u32 user_data_addr;
+       u32 sti_mem_req;
+
+       u32 user_data_size;
+       u16 power;
+        u8 bus_support;
+        u8 ext_bus_support;
+        u8 alt_code_type;
+        u8 ext_dd_struct[3];
+       u32 cfb_addr;
+
+       u32 init_graph;
+       u32 state_mgmt;
+       u32 font_unpmv;
+       u32 block_move;
+       u32 self_test;
+       u32 excep_hdlr;
+       u32 inq_conf;
+       u32 set_cm_entry;
+       u32 dma_ctrl;
+        u8 res040[7 * 4];
+
+       u32 init_graph_addr;
+       u32 state_mgmt_addr;
+       u32 font_unp_addr;
+       u32 block_move_addr;
+       u32 self_test_addr;
+       u32 excep_hdlr_addr;
+       u32 inq_conf_addr;
+       u32 set_cm_entry_addr;
+       u32 image_unpack_addr;
+       u32 pa_risx_addrs[7];
+};
+
+struct sti_rom_font {
+       u16 first_char;
+       u16 last_char;
+        u8 width;
+        u8 height;
+        u8 font_type;          /* language type */
+        u8 bytes_per_char;
+       u32 next_font;
+        u8 underline_height;
+        u8 underline_pos;
+        u8 res008[2];
+};
+
+/* sticore internal font handling */
+
+struct sti_cooked_font {
+       struct sti_rom_font *raw;       /* native ptr for STI functions */
+       void *raw_ptr;                  /* kmalloc'ed font data */
+       struct sti_cooked_font *next_font;
+       int height, width;
+       int refcount;
+       u32 crc;
+};
+
+struct sti_cooked_rom {
+        struct sti_rom *raw;
+       struct sti_cooked_font *font_start;
+};
+
+/* STI font printing function structs */
+
+struct sti_font_inptr {
+       u32 font_start_addr;    /* address of font start */
+       s16 index;              /* index into font table of character */
+       u8 fg_color;            /* foreground color of character */
+       u8 bg_color;            /* background color of character */
+       s16 dest_x;             /* X location of character upper left */
+       s16 dest_y;             /* Y location of character upper left */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_font_flags {
+       u32 wait : 1;           /* should routine idle wait or not */
+       u32 non_text : 1;       /* font unpack/move in non_text planes =1, text =0 */
+       u32 pad : 30;           /* pad to word boundary */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_font_outptr {
+       s32 errno;              /* error number on failure */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+/* STI blockmove structs */
+
+struct sti_blkmv_flags {
+       u32 wait : 1;           /* should routine idle wait or not */
+       u32 color : 1;          /* change color during move? */
+       u32 clear : 1;          /* clear during move? */
+       u32 non_text : 1;       /* block move in non_text planes =1, text =0 */
+       u32 pad : 28;           /* pad to word boundary */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_blkmv_inptr {
+       u8 fg_color;            /* foreground color after move */
+       u8 bg_color;            /* background color after move */
+       s16 src_x;              /* source upper left pixel x location */
+       s16 src_y;              /* source upper left pixel y location */
+       s16 dest_x;             /* dest upper left pixel x location */
+       s16 dest_y;             /* dest upper left pixel y location */
+       s16 width;              /* block width in pixels */
+       s16 height;             /* block height in pixels */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+struct sti_blkmv_outptr {
+       s32 errno;              /* error number on failure */
+       u32 future_ptr;         /* pointer to future data */
+};
+
+
+/* sti_all_data is an internal struct which needs to be allocated in
+ * low memory (< 4GB) if STI is used with 32bit STI on a 64bit kernel */
+
+struct sti_all_data {
+       struct sti_glob_cfg glob_cfg;
+       struct sti_glob_cfg_ext glob_cfg_ext;
+
+       struct sti_conf_inptr           inq_inptr;
+       struct sti_conf_outptr          inq_outptr; /* configuration */
+       struct sti_conf_outptr_ext      inq_outptr_ext;
+
+       struct sti_init_inptr_ext       init_inptr_ext;
+       struct sti_init_inptr           init_inptr;
+       struct sti_init_outptr          init_outptr;
+
+       struct sti_blkmv_inptr          blkmv_inptr;
+       struct sti_blkmv_outptr         blkmv_outptr;
+
+       struct sti_font_inptr           font_inptr;
+       struct sti_font_outptr          font_outptr;
+
+       /* leave as last entries */
+       unsigned long save_addr[1024 / sizeof(unsigned long)];
+          /* min 256 bytes which is STI default, max sti->sti_mem_request */
+       unsigned long sti_mem_addr[256 / sizeof(unsigned long)];
+       /* do not add something below here ! */
+};
+
+/* internal generic STI struct */
+
+struct sti_struct {
+       spinlock_t lock;
+
+       /* char **mon_strings; */
+       int sti_mem_request;
+       u32 graphics_id[2];
+
+       struct sti_cooked_rom *rom;
+
+       unsigned long font_unpmv;
+       unsigned long block_move;
+       unsigned long init_graph;
+       unsigned long inq_conf;
+
+       /* all following fields are initialized by the generic routines */
+       int text_planes;
+       region_t regions[STI_REGION_MAX];
+       unsigned long regions_phys[STI_REGION_MAX];
+
+       struct sti_glob_cfg *glob_cfg;  /* points into sti_all_data */
+
+       int wordmode;
+       struct sti_cooked_font *font;   /* ptr to selected font (cooked) */
+
+       struct pci_dev *pd;
+
+       /* PCI data structures (pg. 17ff from sti.pdf) */
+       u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
+
+       /* pointer to the fb_info where this STI device is used */
+       struct fb_info *info;
+
+       /* pointer to all internal data */
+       struct sti_all_data *sti_data;
+
+       /* pa_path of this device */
+       char pa_path[24];
+};
+
+
+/* sticore interface functions */
+
+struct sti_struct *sti_get_rom(unsigned int index); /* 0: default sti */
+void sti_font_convert_bytemode(struct sti_struct *sti, struct sti_cooked_font *f);
+
+
+/* sticore main function to call STI firmware */
+
+int sti_call(const struct sti_struct *sti, unsigned long func,
+               const void *flags, void *inptr, void *outptr,
+               struct sti_glob_cfg *glob_cfg);
+
+
+/* functions to call the STI ROM directly */
+
+void sti_putc(struct sti_struct *sti, int c, int y, int x,
+               struct sti_cooked_font *font);
+void sti_set(struct sti_struct *sti, int src_y, int src_x,
+               int height, int width, u8 color);
+void sti_clear(struct sti_struct *sti, int src_y, int src_x,
+               int height, int width, int c, struct sti_cooked_font *font);
+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);
+
+#endif /* STICORE_H */