1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/console/sticore.c -
4 * core code for console driver using HP's STI firmware
6 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
7 * Copyright (C) 2001-2023 Helge Deller <deller@gmx.de>
8 * Copyright (C) 2001-2002 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
11 * - call STI in virtual mode rather than in real mode
12 * - screen blanking with state_mgmt() in text mode STI ?
13 * - try to make it work on m68k hp workstations ;)
17 #define pr_fmt(fmt) "%s: " fmt, KBUILD_MODNAME
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/init.h>
24 #include <linux/pci.h>
25 #include <linux/font.h>
27 #include <asm/hardware.h>
29 #include <asm/parisc-device.h>
31 #include <asm/cacheflush.h>
32 #include <asm/grfioctl.h>
34 #include <video/sticore.h>
36 #define STI_DRIVERVERSION "Version 0.9c"
38 static struct sti_struct
*default_sti __read_mostly
;
40 /* number of STI ROMS found and their ptrs to each struct */
41 static int num_sti_roms __read_mostly
;
42 static struct sti_struct
*sti_roms
[MAX_STI_ROMS
] __read_mostly
;
44 static void *store_sti_val(struct sti_struct
*sti
, void *ptr
, unsigned long val
)
48 if (IS_ENABLED(CONFIG_64BIT
) && sti
->do_call64
) {
49 /* used for 64-bit STI ROM */
50 unsigned long *ptr64
= ptr
;
52 ptr64
= PTR_ALIGN(ptr64
, sizeof(void *));
57 /* used for 32-bit STI ROM */
62 #define store_sti_ptr(sti, dest, ptr) \
63 store_sti_val(sti, dest, STI_PTR(ptr))
65 /* The colour indices used by STI are
75 * So we have the same colours as VGA (basically one bit each for R, G, B),
76 * but have to translate them, anyway. */
78 static const u8 col_trans
[8] = {
83 #define c_fg(sti, c) col_trans[((c>> 8) & 7)]
84 #define c_bg(sti, c) col_trans[((c>>11) & 7)]
85 #define c_index(sti, c) ((c) & 0xff)
87 static const struct sti_init_flags default_init_flags
= {
97 static int sti_init_graph(struct sti_struct
*sti
)
99 struct sti_init_inptr
*inptr
= &sti
->sti_data
->init_inptr
;
100 struct sti_init_inptr_ext
*inptr_ext
= &sti
->sti_data
->init_inptr_ext
;
101 struct sti_init_outptr
*outptr
= &sti
->sti_data
->init_outptr
;
105 spin_lock_irqsave(&sti
->lock
, flags
);
107 memset(inptr
, 0, sizeof(*inptr
));
108 inptr
->text_planes
= 3; /* # of text planes (max 3 for STI) */
109 memset(inptr_ext
, 0, sizeof(*inptr_ext
));
110 store_sti_ptr(sti
, &inptr
->ext_ptr
, inptr_ext
);
113 ret
= sti_call(sti
, sti
->init_graph
, &default_init_flags
, inptr
,
114 outptr
, sti
->glob_cfg
);
117 sti
->text_planes
= outptr
->text_planes
;
120 spin_unlock_irqrestore(&sti
->lock
, flags
);
123 pr_err("STI init_graph failed (ret %d, errno %d)\n", ret
, err
);
130 static const struct sti_conf_flags default_conf_flags
= {
134 static void sti_inq_conf(struct sti_struct
*sti
)
136 struct sti_conf_inptr
*inptr
= &sti
->sti_data
->inq_inptr
;
137 struct sti_conf_outptr
*outptr
= &sti
->sti_data
->inq_outptr
;
141 store_sti_ptr(sti
, &outptr
->ext_ptr
, &sti
->sti_data
->inq_outptr_ext
);
144 spin_lock_irqsave(&sti
->lock
, flags
);
145 memset(inptr
, 0, sizeof(*inptr
));
146 ret
= sti_call(sti
, sti
->inq_conf
, &default_conf_flags
,
147 inptr
, outptr
, sti
->glob_cfg
);
148 spin_unlock_irqrestore(&sti
->lock
, flags
);
152 static const struct sti_font_flags default_font_flags
= {
158 sti_putc(struct sti_struct
*sti
, int c
, int y
, int x
,
159 struct sti_cooked_font
*font
)
161 struct sti_font_inptr
*inptr
;
162 struct sti_font_inptr inptr_default
= {
163 .font_start_addr
= (void *)STI_PTR(font
->raw
),
164 .index
= c_index(sti
, c
),
165 .fg_color
= c_fg(sti
, c
),
166 .bg_color
= c_bg(sti
, c
),
167 .dest_x
= x
* font
->width
,
168 .dest_y
= y
* font
->height
,
170 struct sti_font_outptr
*outptr
= &sti
->sti_data
->font_outptr
;
175 spin_lock_irqsave(&sti
->lock
, flags
);
176 inptr
= &inptr_default
;
177 if (IS_ENABLED(CONFIG_64BIT
) && !sti
->do_call64
) {
178 /* copy below 4G if calling 32-bit on LP64 kernel */
179 inptr
= &sti
->sti_data
->font_inptr
;
180 *inptr
= inptr_default
;
181 /* skip first 4 bytes for 32-bit STI call */
182 inptr
= (void *)(((unsigned long)inptr
) + sizeof(u32
));
184 ret
= sti_call(sti
, sti
->font_unpmv
, &default_font_flags
,
185 inptr
, outptr
, sti
->glob_cfg
);
186 spin_unlock_irqrestore(&sti
->lock
, flags
);
190 static const struct sti_blkmv_flags clear_blkmv_flags
= {
197 sti_set(struct sti_struct
*sti
, int src_y
, int src_x
,
198 int height
, int width
, u8 color
)
200 struct sti_blkmv_inptr
*inptr
;
201 struct sti_blkmv_inptr inptr_default
= {
211 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
216 spin_lock_irqsave(&sti
->lock
, flags
);
217 inptr
= &inptr_default
;
218 if (IS_ENABLED(CONFIG_64BIT
) && !sti
->do_call64
) {
219 /* copy below 4G if calling 32-bit on LP64 kernel */
220 inptr
= &sti
->sti_data
->blkmv_inptr
;
221 *inptr
= inptr_default
;
223 ret
= sti_call(sti
, sti
->block_move
, &clear_blkmv_flags
,
224 inptr
, outptr
, sti
->glob_cfg
);
225 spin_unlock_irqrestore(&sti
->lock
, flags
);
230 sti_clear(struct sti_struct
*sti
, int src_y
, int src_x
,
231 int height
, int width
, int c
, struct sti_cooked_font
*font
)
233 struct sti_blkmv_inptr
*inptr
;
234 struct sti_blkmv_inptr inptr_default
= {
235 .fg_color
= c_fg(sti
, c
),
236 .bg_color
= c_bg(sti
, c
),
237 .src_x
= src_x
* font
->width
,
238 .src_y
= src_y
* font
->height
,
239 .dest_x
= src_x
* font
->width
,
240 .dest_y
= src_y
* font
->height
,
241 .width
= width
* font
->width
,
242 .height
= height
* font
->height
,
244 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
249 spin_lock_irqsave(&sti
->lock
, flags
);
250 inptr
= &inptr_default
;
251 if (IS_ENABLED(CONFIG_64BIT
) && !sti
->do_call64
) {
252 /* copy below 4G if calling 32-bit on LP64 kernel */
253 inptr
= &sti
->sti_data
->blkmv_inptr
;
254 *inptr
= inptr_default
;
256 ret
= sti_call(sti
, sti
->block_move
, &clear_blkmv_flags
,
257 inptr
, outptr
, sti
->glob_cfg
);
258 spin_unlock_irqrestore(&sti
->lock
, flags
);
262 static const struct sti_blkmv_flags default_blkmv_flags
= {
267 sti_bmove(struct sti_struct
*sti
, int src_y
, int src_x
,
268 int dst_y
, int dst_x
, int height
, int width
,
269 struct sti_cooked_font
*font
)
271 struct sti_blkmv_inptr
*inptr
;
272 struct sti_blkmv_inptr inptr_default
= {
273 .src_x
= src_x
* font
->width
,
274 .src_y
= src_y
* font
->height
,
275 .dest_x
= dst_x
* font
->width
,
276 .dest_y
= dst_y
* font
->height
,
277 .width
= width
* font
->width
,
278 .height
= height
* font
->height
,
280 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
285 spin_lock_irqsave(&sti
->lock
, flags
);
286 inptr
= &inptr_default
;
287 if (IS_ENABLED(CONFIG_64BIT
) && !sti
->do_call64
) {
288 /* copy below 4G if calling 32-bit on LP64 kernel */
289 inptr
= &sti
->sti_data
->blkmv_inptr
;
290 *inptr
= inptr_default
;
292 ret
= sti_call(sti
, sti
->block_move
, &default_blkmv_flags
,
293 inptr
, outptr
, sti
->glob_cfg
);
294 spin_unlock_irqrestore(&sti
->lock
, flags
);
299 static void sti_flush(unsigned long start
, unsigned long end
)
301 flush_icache_range(start
, end
);
304 static void sti_rom_copy(unsigned long base
, unsigned long count
, void *dest
)
306 unsigned long dest_start
= (unsigned long) dest
;
308 /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */
311 *(u32
*)dest
= gsc_readl(base
);
317 *(u8
*)dest
= gsc_readb(base
);
322 sti_flush(dest_start
, (unsigned long)dest
);
328 static char default_sti_path
[21] __read_mostly
;
331 static int __init
sti_setup(char *str
)
334 strscpy(default_sti_path
, str
, sizeof(default_sti_path
));
339 /* Assuming the machine has multiple STI consoles (=graphic cards) which
340 * all get detected by sticon, the user may define with the linux kernel
341 * parameter sti=<x> which of them will be the initial boot-console.
342 * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default
345 __setup("sti=", sti_setup
);
350 static char *font_name
;
351 static int font_index
,
355 static int sti_font_setup(char *str
)
358 * The default font can be selected in various ways.
359 * a) sti_font=VGA8x16, sti_font=10x20, sti_font=10*20 selects
360 * an built-in Linux framebuffer font.
361 * b) sti_font=<index>, where index is (1..x) with 1 selecting
362 * the first HP STI ROM built-in font..
365 if (*str
>= '0' && *str
<= '9') {
368 if ((x
= strchr(str
, 'x')) || (x
= strchr(str
, '*'))) {
369 font_height
= simple_strtoul(str
, NULL
, 0);
370 font_width
= simple_strtoul(x
+1, NULL
, 0);
372 font_index
= simple_strtoul(str
, NULL
, 0);
375 font_name
= str
; /* fb font name */
381 /* The optional linux kernel parameter "sti_font" defines which font
382 * should be used by the sticon driver to draw characters to the screen.
383 * Possible values are:
384 * - sti_font=<fb_fontname>:
385 * <fb_fontname> is the name of one of the linux-kernel built-in
386 * framebuffer font names (e.g. VGA8x16, SUN22x18).
387 * This is only available if the fonts have been statically compiled
388 * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options.
389 * - sti_font=<number> (<number> = 1,2,3,...)
390 * most STI ROMs have built-in HP specific fonts, which can be selected
391 * by giving the desired number to the sticon driver.
392 * NOTE: This number is machine and STI ROM dependend.
393 * - sti_font=<height>x<width> (e.g. sti_font=16x8)
394 * <height> and <width> gives hints to the height and width of the
395 * font which the user wants. The sticon driver will try to use
396 * a font with this height and width, but if no suitable font is
397 * found, sticon will use the default 8x8 font.
399 __setup("sti_font=", sti_font_setup
);
404 static void sti_dump_globcfg(struct sti_struct
*sti
)
406 struct sti_glob_cfg
*glob_cfg
= sti
->glob_cfg
;
407 struct sti_glob_cfg_ext
*cfg
= &sti
->sti_data
->glob_cfg_ext
;
409 pr_debug("%d text planes\n"
410 "%4d x %4d screen resolution\n"
411 "%4d x %4d offscreen\n"
412 "%4d x %4d layout\n",
413 glob_cfg
->text_planes
,
414 glob_cfg
->onscreen_x
, glob_cfg
->onscreen_y
,
415 glob_cfg
->offscreen_x
, glob_cfg
->offscreen_y
,
416 glob_cfg
->total_x
, glob_cfg
->total_y
);
418 /* dump extended cfg */
419 pr_debug("monitor %d\n"
420 "in friendly mode: %d\n"
421 "power consumption %d watts\n"
423 "sti_mem_addr %px (size=%d bytes)\n",
428 cfg
->sti_mem_addr
, sti
->sti_mem_request
);
431 static void sti_dump_outptr(struct sti_struct
*sti
)
433 pr_debug("%d bits per pixel\n"
437 sti
->sti_data
->inq_outptr
.bits_per_pixel
,
438 sti
->sti_data
->inq_outptr
.bits_used
,
439 sti
->sti_data
->inq_outptr
.planes
,
440 sti
->sti_data
->inq_outptr
.attributes
);
443 static int sti_init_glob_cfg(struct sti_struct
*sti
, unsigned long rom_address
,
446 struct sti_glob_cfg
*glob_cfg
;
447 struct sti_glob_cfg_ext
*glob_cfg_ext
;
448 void *save_addr
, *ptr
;
452 if (sti
->sti_mem_request
< 256)
453 sti
->sti_mem_request
= 256; /* STI default */
455 size
= sizeof(struct sti_all_data
) + sti
->sti_mem_request
- 256;
457 sti
->sti_data
= kzalloc(size
, STI_LOWMEM
);
461 glob_cfg
= &sti
->sti_data
->glob_cfg
;
462 glob_cfg_ext
= &sti
->sti_data
->glob_cfg_ext
;
463 save_addr
= &sti
->sti_data
->save_addr
;
464 sti_mem_addr
= &sti
->sti_data
->sti_mem_addr
;
466 for (i
= 0; i
< STI_REGION_MAX
; i
++) {
467 unsigned long newhpa
, len
;
470 unsigned char offs
= sti
->rm_entry
[i
];
474 if (offs
!= PCI_ROM_ADDRESS
&&
475 (offs
< PCI_BASE_ADDRESS_0
||
476 offs
> PCI_BASE_ADDRESS_5
)) {
477 pr_warn("STI pci region mapping for region %d (%02x) can't be mapped\n",
481 newhpa
= pci_resource_start (sti
->pd
, (offs
- PCI_BASE_ADDRESS_0
) / 4);
483 newhpa
= (i
== 0) ? rom_address
: hpa
;
485 sti
->regions_phys
[i
] =
486 REGION_OFFSET_TO_PHYS(sti
->regions
[i
], newhpa
);
488 len
= sti
->regions
[i
].region_desc
.length
* 4096;
490 pr_debug("region #%d: phys %08lx, len=%lukB, "
491 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
492 i
, sti
->regions_phys
[i
], len
/ 1024,
493 sti
->regions
[i
].region_desc
.btlb
,
494 sti
->regions
[i
].region_desc
.sys_only
,
495 sti
->regions
[i
].region_desc
.cache
,
496 sti
->regions
[i
].region_desc
.last
);
498 /* last entry reached ? */
499 if (sti
->regions
[i
].region_desc
.last
)
503 ptr
= &glob_cfg
->region_ptrs
;
504 for (i
= 0; i
< STI_REGION_MAX
; i
++)
505 ptr
= store_sti_val(sti
, ptr
, sti
->regions_phys
[i
]);
507 *(s32
*)ptr
= 0; /* set reent_lvl */
509 ptr
= store_sti_ptr(sti
, ptr
, save_addr
);
510 ptr
= store_sti_ptr(sti
, ptr
, glob_cfg_ext
);
512 store_sti_ptr(sti
, &glob_cfg_ext
->sti_mem_addr
, sti_mem_addr
);
514 sti
->glob_cfg
= glob_cfg
;
519 #ifdef CONFIG_FONT_SUPPORT
520 static struct sti_cooked_font
*
521 sti_select_fbfont(struct sti_cooked_rom
*cooked_rom
, const char *fbfont_name
)
523 const struct font_desc
*fbfont
= NULL
;
524 unsigned int size
, bpc
;
526 struct sti_rom_font
*nf
;
527 struct sti_cooked_font
*cooked_font
;
529 if (fbfont_name
&& strlen(fbfont_name
))
530 fbfont
= find_font(fbfont_name
);
532 fbfont
= get_default_font(1024, 768, NULL
, NULL
);
536 pr_info(" using %ux%u framebuffer font %s\n",
537 fbfont
->width
, fbfont
->height
, fbfont
->name
);
539 bpc
= ((fbfont
->width
+7)/8) * fbfont
->height
;
540 size
= bpc
* fbfont
->charcount
;
541 size
+= sizeof(struct sti_rom_font
);
543 nf
= kzalloc(size
, STI_LOWMEM
);
548 nf
->last_char
= fbfont
->charcount
- 1;
549 nf
->width
= fbfont
->width
;
550 nf
->height
= fbfont
->height
;
551 nf
->font_type
= STI_FONT_HPROMAN8
;
552 nf
->bytes_per_char
= bpc
;
554 nf
->underline_height
= 1;
555 nf
->underline_pos
= fbfont
->height
- nf
->underline_height
;
558 dest
+= sizeof(struct sti_rom_font
);
559 memcpy(dest
, fbfont
->data
, bpc
* fbfont
->charcount
);
561 cooked_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
567 cooked_font
->raw
= nf
;
568 cooked_font
->raw_ptr
= nf
;
569 cooked_font
->next_font
= NULL
;
571 cooked_rom
->font_start
= cooked_font
;
576 static struct sti_cooked_font
*
577 sti_select_fbfont(struct sti_cooked_rom
*cooked_rom
, const char *fbfont_name
)
583 static void sti_dump_font(struct sti_cooked_font
*font
)
586 unsigned char *p
= (unsigned char *)font
->raw
;
589 p
+= sizeof(struct sti_rom_font
);
590 pr_debug(" w %d h %d bpc %d\n", font
->width
, font
->height
,
591 font
->raw
->bytes_per_char
);
593 for (n
= 0; n
< 256 * font
->raw
->bytes_per_char
; n
+= 16, p
+= 16) {
594 pr_debug(" 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x,"
595 " 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x,"
596 " 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n",
597 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7], p
[8],
598 p
[9], p
[10], p
[11], p
[12], p
[13], p
[14], p
[15]);
603 static int sti_search_font(struct sti_cooked_rom
*rom
, int height
, int width
)
605 struct sti_cooked_font
*font
;
608 for (font
= rom
->font_start
; font
; font
= font
->next_font
, i
++) {
609 if ((font
->raw
->width
== width
) &&
610 (font
->raw
->height
== height
))
616 static struct sti_cooked_font
*sti_select_font(struct sti_cooked_rom
*rom
)
618 struct sti_cooked_font
*font
;
621 /* check for framebuffer-font first */
623 font
= sti_select_fbfont(rom
, font_name
);
628 if (font_width
&& font_height
)
629 font_index
= sti_search_font(rom
,
630 font_height
, font_width
);
632 for (font
= rom
->font_start
, i
= font_index
- 1;
634 font
= font
->next_font
, i
--);
639 return rom
->font_start
;
643 static void sti_dump_rom(struct sti_struct
*sti
)
645 struct sti_rom
*rom
= sti
->rom
->raw
;
646 struct sti_cooked_font
*font_start
;
649 pr_info(" id %04x-%04x, conforms to spec rev. %d.%02x\n",
653 rom
->revno
[0] & 0x0f);
654 pr_debug(" supports %d monitors\n", rom
->num_mons
);
655 pr_debug(" font start %08x\n", rom
->font_start
);
656 pr_debug(" region list %08x\n", rom
->region_list
);
657 pr_debug(" init_graph %08x\n", rom
->init_graph
);
658 pr_debug(" bus support %02x\n", rom
->bus_support
);
659 pr_debug(" ext bus support %02x\n", rom
->ext_bus_support
);
660 pr_debug(" alternate code type %d\n", rom
->alt_code_type
);
662 font_start
= sti
->rom
->font_start
;
665 struct sti_rom_font
*f
= font_start
->raw
;
667 pr_info(" built-in font #%d: size %dx%d, chars %d-%d, bpc %d\n", ++nr
,
669 f
->first_char
, f
->last_char
, f
->bytes_per_char
);
670 font_start
= font_start
->next_font
;
675 static int sti_cook_fonts(struct sti_cooked_rom
*cooked_rom
,
676 struct sti_rom
*raw_rom
)
678 struct sti_rom_font
*raw_font
, *font_start
;
679 struct sti_cooked_font
*cooked_font
;
681 cooked_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
685 cooked_rom
->font_start
= cooked_font
;
687 raw_font
= ((void *)raw_rom
) + (raw_rom
->font_start
);
689 font_start
= raw_font
;
690 cooked_font
->raw
= raw_font
;
692 while (raw_font
->next_font
) {
693 raw_font
= ((void *)font_start
) + (raw_font
->next_font
);
695 cooked_font
->next_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
696 if (!cooked_font
->next_font
)
699 cooked_font
= cooked_font
->next_font
;
701 cooked_font
->raw
= raw_font
;
704 cooked_font
->next_font
= NULL
;
708 #define BMODE_RELOCATE(offset) offset = (offset) / 4;
709 #define BMODE_LAST_ADDR_OFFS 0x50
711 void sti_font_convert_bytemode(struct sti_struct
*sti
, struct sti_cooked_font
*f
)
713 unsigned char *n
, *p
, *q
;
714 int size
= f
->raw
->bytes_per_char
* (f
->raw
->last_char
+ 1) + sizeof(struct sti_rom_font
);
715 struct sti_rom_font
*old_font
;
720 old_font
= f
->raw_ptr
;
721 n
= kcalloc(4, size
, STI_LOWMEM
);
726 q
= (unsigned char *) f
->raw
;
731 /* store new ptr to byte-mode font and delete old font */
732 f
->raw
= (struct sti_rom_font
*) (n
+ 3);
735 EXPORT_SYMBOL(sti_font_convert_bytemode
);
737 static void sti_bmode_rom_copy(unsigned long base
, unsigned long count
,
740 unsigned long dest_start
= (unsigned long) dest
;
744 *(u8
*)dest
= gsc_readl(base
);
749 sti_flush(dest_start
, (unsigned long)dest
);
752 static struct sti_rom
*sti_get_bmode_rom (unsigned long address
)
756 struct sti_rom_font
*raw_font
, *font_start
;
758 sti_bmode_rom_copy(address
+ BMODE_LAST_ADDR_OFFS
, sizeof(size
), &size
);
761 raw
= kmalloc(size
, STI_LOWMEM
);
763 sti_bmode_rom_copy(address
, size
, raw
);
764 memmove (&raw
->res004
, &raw
->type
[0], 0x3c);
765 raw
->type
[3] = raw
->res004
;
767 BMODE_RELOCATE (raw
->region_list
);
768 BMODE_RELOCATE (raw
->font_start
);
770 BMODE_RELOCATE (raw
->init_graph
);
771 BMODE_RELOCATE (raw
->state_mgmt
);
772 BMODE_RELOCATE (raw
->font_unpmv
);
773 BMODE_RELOCATE (raw
->block_move
);
774 BMODE_RELOCATE (raw
->inq_conf
);
776 raw_font
= ((void *)raw
) + raw
->font_start
;
777 font_start
= raw_font
;
779 while (raw_font
->next_font
) {
780 BMODE_RELOCATE (raw_font
->next_font
);
781 raw_font
= ((void *)font_start
) + raw_font
->next_font
;
787 static struct sti_rom
*sti_get_wmode_rom(unsigned long address
)
792 /* read the ROM size directly from the struct in ROM */
793 size
= gsc_readl(address
+ offsetof(struct sti_rom
,last_addr
));
795 raw
= kmalloc(size
, STI_LOWMEM
);
797 sti_rom_copy(address
, size
, raw
);
802 static int sti_read_rom(int wordmode
, struct sti_struct
*sti
,
803 unsigned long address
)
805 struct sti_cooked_rom
*cooked
;
806 struct sti_rom
*raw
= NULL
;
809 cooked
= kmalloc(sizeof *cooked
, GFP_KERNEL
);
814 raw
= sti_get_wmode_rom (address
);
816 raw
= sti_get_bmode_rom (address
);
821 if (!sti_cook_fonts(cooked
, raw
)) {
822 pr_warn("No font found for STI at %08lx\n", address
);
826 if (raw
->region_list
)
827 memcpy(sti
->regions
, ((void *)raw
)+raw
->region_list
, sizeof(sti
->regions
));
829 address
= (unsigned long) STI_PTR(raw
);
831 pr_info("STI %s ROM supports 32 %sbit firmware functions.\n",
832 wordmode
? "word mode" : "byte mode",
833 raw
->alt_code_type
== ALT_CODE_TYPE_PA_RISC_64
836 if (IS_ENABLED(CONFIG_64BIT
) &&
837 raw
->alt_code_type
== ALT_CODE_TYPE_PA_RISC_64
) {
839 sti
->font_unpmv
= address
+ (raw
->font_unp_addr
& 0x03ffffff);
840 sti
->block_move
= address
+ (raw
->block_move_addr
& 0x03ffffff);
841 sti
->init_graph
= address
+ (raw
->init_graph_addr
& 0x03ffffff);
842 sti
->inq_conf
= address
+ (raw
->inq_conf_addr
& 0x03ffffff);
844 sti
->font_unpmv
= address
+ (raw
->font_unpmv
& 0x03ffffff);
845 sti
->block_move
= address
+ (raw
->block_move
& 0x03ffffff);
846 sti
->init_graph
= address
+ (raw
->init_graph
& 0x03ffffff);
847 sti
->inq_conf
= address
+ (raw
->inq_conf
& 0x03ffffff);
854 sti
->wordmode
= wordmode
;
855 sti
->font
= sti_select_font(sti
->rom
);
856 sti
->font
->width
= sti
->font
->raw
->width
;
857 sti
->font
->height
= sti
->font
->raw
->height
;
858 sti_font_convert_bytemode(sti
, sti
->font
);
859 sti_dump_font(sti
->font
);
861 pr_info(" using %d-bit STI ROM functions\n",
862 (IS_ENABLED(CONFIG_64BIT
) && sti
->do_call64
) ? 64 : 32);
864 sti
->sti_mem_request
= raw
->sti_mem_req
;
865 pr_debug(" mem_request = %d, reentsize %d\n",
866 sti
->sti_mem_request
, raw
->reentsize
);
868 sti
->graphics_id
[0] = raw
->graphics_id
[0];
869 sti
->graphics_id
[1] = raw
->graphics_id
[1];
871 /* check if the ROM routines in this card are compatible */
872 if (wordmode
|| sti
->graphics_id
[1] != 0x09A02587)
875 revno
= (raw
->revno
[0] << 8) | raw
->revno
[1];
877 switch (sti
->graphics_id
[0]) {
879 /* HyperA or HyperB ? */
880 if (revno
== 0x8408 || revno
== 0x840b)
881 goto msg_not_supported
;
885 goto msg_not_supported
;
887 case CRT_ID_THUNDER2
:
889 goto msg_not_supported
;
895 pr_warn("Sorry, this GSC/STI card is not yet supported.\n");
896 pr_warn("Please see https://parisc.wiki.kernel.org/"
897 "index.php/Graphics_howto for more info.\n");
905 static struct sti_struct
*sti_try_rom_generic(unsigned long address
,
909 struct sti_struct
*sti
;
913 if (num_sti_roms
>= MAX_STI_ROMS
) {
914 pr_warn("maximum number of STI ROMS reached !\n");
918 sti
= kzalloc(sizeof(*sti
), GFP_KERNEL
);
922 spin_lock_init(&sti
->lock
);
925 /* pdc_add_valid() works only on 32-bit kernels */
926 if ((!IS_ENABLED(CONFIG_64BIT
) ||
927 (boot_cpu_data
.pdc
.capabilities
& PDC_MODEL_OS32
)) &&
928 pdc_add_valid(address
)) {
932 sig
= gsc_readl(address
);
934 /* check for a PCI ROM structure */
935 if ((le32_to_cpu(sig
)==0xaa55)) {
936 unsigned int i
, rm_offset
;
938 i
= gsc_readl(address
+0x04);
940 /* The ROM could have multiple architecture
941 * dependent images (e.g. i386, parisc,...) */
942 pr_warn("PCI ROM is not a STI ROM type image (0x%8x)\n", i
);
948 i
= gsc_readl(address
+0x0c);
949 pr_debug("PCI ROM size (from header) = %d kB\n",
950 le16_to_cpu(i
>>16)*512/1024);
951 rm_offset
= le16_to_cpu(i
& 0xffff);
953 /* read 16 bytes from the pci region mapper array */
954 rm
= (u32
*) &sti
->rm_entry
;
955 *rm
++ = gsc_readl(address
+rm_offset
+0x00);
956 *rm
++ = gsc_readl(address
+rm_offset
+0x04);
957 *rm
++ = gsc_readl(address
+rm_offset
+0x08);
958 *rm
++ = gsc_readl(address
+rm_offset
+0x0c);
961 address
+= le32_to_cpu(gsc_readl(address
+8));
962 pr_debug("sig %04x, PCI STI ROM at %08lx\n", sig
, address
);
968 if ((sig
& 0xff) == 0x01) {
969 pr_debug(" byte mode ROM at %08lx, hpa at %08lx\n",
971 ok
= sti_read_rom(0, sti
, address
);
974 if ((sig
& 0xffff) == 0x0303) {
975 pr_debug(" word mode ROM at %08lx, hpa at %08lx\n",
977 ok
= sti_read_rom(1, sti
, address
);
983 if (sti_init_glob_cfg(sti
, address
, hpa
))
984 goto out_err
; /* not enough memory */
986 /* disable STI PCI ROM. ROM and card RAM overlap and
987 * leaving it enabled would force HPMCs
990 unsigned long rom_base
;
991 rom_base
= pci_resource_start(sti
->pd
, PCI_ROM_RESOURCE
);
992 pci_write_config_dword(sti
->pd
, PCI_ROM_ADDRESS
, rom_base
& ~PCI_ROM_ADDRESS_ENABLE
);
993 pr_debug("STI PCI ROM disabled\n");
996 if (sti_init_graph(sti
))
1000 sti_dump_globcfg(sti
);
1001 sti_dump_outptr(sti
);
1003 pr_info(" graphics card name: %s\n",
1004 sti
->sti_data
->inq_outptr
.dev_name
);
1006 sti_roms
[num_sti_roms
] = sti
;
1016 static void sticore_check_for_default_sti(struct sti_struct
*sti
, char *path
)
1018 pr_info(" located at [%s]\n", sti
->pa_path
);
1019 if (strcmp (path
, default_sti_path
) == 0)
1024 * on newer systems PDC gives the address of the ROM
1025 * in the additional address field addr[1] while on
1026 * older Systems the PDC stores it in page0->proc_sti
1028 static int __init
sticore_pa_init(struct parisc_device
*dev
)
1030 struct sti_struct
*sti
= NULL
;
1031 int hpa
= dev
->hpa
.start
;
1033 if (dev
->num_addrs
&& dev
->addr
[0])
1034 sti
= sti_try_rom_generic(dev
->addr
[0], hpa
, NULL
);
1036 sti
= sti_try_rom_generic(hpa
, hpa
, NULL
);
1038 sti
= sti_try_rom_generic(PAGE0
->proc_sti
, hpa
, NULL
);
1042 print_pa_hwpath(dev
, sti
->pa_path
);
1043 sticore_check_for_default_sti(sti
, sti
->pa_path
);
1045 sti
->dev
= &dev
->dev
;
1051 static int sticore_pci_init(struct pci_dev
*pd
, const struct pci_device_id
*ent
)
1054 unsigned long fb_base
, rom_base
;
1055 unsigned int fb_len
, rom_len
;
1057 struct sti_struct
*sti
;
1059 err
= pci_enable_device(pd
);
1061 dev_err(&pd
->dev
, "Cannot enable PCI device\n");
1065 fb_base
= pci_resource_start(pd
, 0);
1066 fb_len
= pci_resource_len(pd
, 0);
1067 rom_base
= pci_resource_start(pd
, PCI_ROM_RESOURCE
);
1068 rom_len
= pci_resource_len(pd
, PCI_ROM_RESOURCE
);
1070 pci_write_config_dword(pd
, PCI_ROM_ADDRESS
, rom_base
| PCI_ROM_ADDRESS_ENABLE
);
1071 pr_debug("STI PCI ROM enabled at 0x%08lx\n", rom_base
);
1074 pr_info("STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
1075 rom_base
, rom_len
/1024, fb_base
, fb_len
/1024/1024);
1077 pr_debug("Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
1080 sti
= sti_try_rom_generic(rom_base
, fb_base
, pd
);
1082 print_pci_hwpath(pd
, sti
->pa_path
);
1083 sticore_check_for_default_sti(sti
, sti
->pa_path
);
1087 pr_warn("Unable to handle STI device '%s'\n", pci_name(pd
));
1091 sti
->dev
= &pd
->dev
;
1092 #endif /* CONFIG_PCI */
1098 static void __exit
sticore_pci_remove(struct pci_dev
*pd
)
1104 static struct pci_device_id sti_pci_tbl
[] = {
1105 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_EG
) },
1106 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX6
) },
1107 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX4
) },
1108 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX2
) },
1109 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FXE
) },
1110 { 0, } /* terminate list */
1112 MODULE_DEVICE_TABLE(pci
, sti_pci_tbl
);
1114 static struct pci_driver pci_sti_driver
= {
1116 .id_table
= sti_pci_tbl
,
1117 .probe
= sticore_pci_init
,
1118 .remove
= __exit_p(sticore_pci_remove
),
1121 static struct parisc_device_id sti_pa_tbl
[] = {
1122 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00077 },
1123 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00085 },
1126 MODULE_DEVICE_TABLE(parisc
, sti_pa_tbl
);
1128 static struct parisc_driver pa_sti_driver __refdata
= {
1130 .id_table
= sti_pa_tbl
,
1131 .probe
= sticore_pa_init
,
1136 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1139 static int sticore_initialized __read_mostly
;
1141 static void sti_init_roms(void)
1143 if (sticore_initialized
)
1146 sticore_initialized
= 1;
1148 pr_info("STI GSC/PCI core graphics driver "
1149 STI_DRIVERVERSION
"\n");
1151 /* Register drivers for native & PCI cards */
1152 register_parisc_driver(&pa_sti_driver
);
1153 WARN_ON(pci_register_driver(&pci_sti_driver
));
1155 /* if we didn't find the given default sti, take the first one */
1157 default_sti
= sti_roms
[0];
1162 * index = 0 gives default sti
1163 * index > 0 gives other stis in detection order
1165 struct sti_struct
* sti_get_rom(unsigned int index
)
1167 if (!sticore_initialized
)
1173 if (index
> num_sti_roms
)
1176 return sti_roms
[index
-1];
1178 EXPORT_SYMBOL(sti_get_rom
);
1181 int sti_call(const struct sti_struct
*sti
, unsigned long func
,
1182 const void *flags
, void *inptr
, void *outptr
,
1183 struct sti_glob_cfg
*glob_cfg
)
1185 unsigned long _flags
= STI_PTR(flags
);
1186 unsigned long _inptr
= STI_PTR(inptr
);
1187 unsigned long _outptr
= STI_PTR(outptr
);
1188 unsigned long _glob_cfg
= STI_PTR(glob_cfg
);
1191 /* Check for overflow when using 32bit STI on 64bit kernel. */
1192 if (WARN_ONCE(IS_ENABLED(CONFIG_64BIT
) && !sti
->do_call64
&&
1193 (upper_32_bits(_flags
) || upper_32_bits(_inptr
) ||
1194 upper_32_bits(_outptr
) || upper_32_bits(_glob_cfg
)),
1195 "Out of 32bit-range pointers!"))
1198 ret
= pdc_sti_call(func
, _flags
, _inptr
, _outptr
, _glob_cfg
,
1204 MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1205 MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1206 MODULE_LICENSE("GPL v2");