Linux 4.16.11
[linux/fpc-iii.git] / drivers / video / console / sticore.c
blobd1d3796773aa2d4c77716f3ba5e2fcebf0ae5653
1 /*
2 * linux/drivers/video/console/sticore.c -
3 * core code for console driver using HP's STI firmware
5 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 2001-2013 Helge Deller <deller@gmx.de>
7 * Copyright (C) 2001-2002 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
8 *
9 * TODO:
10 * - call STI in virtual mode rather than in real mode
11 * - screen blanking with state_mgmt() in text mode STI ?
12 * - try to make it work on m68k hp workstations ;)
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
20 #include <linux/init.h>
21 #include <linux/pci.h>
22 #include <linux/font.h>
24 #include <asm/hardware.h>
25 #include <asm/page.h>
26 #include <asm/parisc-device.h>
27 #include <asm/pdc.h>
28 #include <asm/cacheflush.h>
29 #include <asm/grfioctl.h>
31 #include "../fbdev/sticore.h"
33 #define STI_DRIVERVERSION "Version 0.9b"
35 static struct sti_struct *default_sti __read_mostly;
37 /* number of STI ROMS found and their ptrs to each struct */
38 static int num_sti_roms __read_mostly;
39 static struct sti_struct *sti_roms[MAX_STI_ROMS] __read_mostly;
42 /* The colour indices used by STI are
43 * 0 - Black
44 * 1 - White
45 * 2 - Red
46 * 3 - Yellow/Brown
47 * 4 - Green
48 * 5 - Cyan
49 * 6 - Blue
50 * 7 - Magenta
52 * So we have the same colours as VGA (basically one bit each for R, G, B),
53 * but have to translate them, anyway. */
55 static const u8 col_trans[8] = {
56 0, 6, 4, 5,
57 2, 7, 3, 1
60 #define c_fg(sti, c) col_trans[((c>> 8) & 7)]
61 #define c_bg(sti, c) col_trans[((c>>11) & 7)]
62 #define c_index(sti, c) ((c) & 0xff)
64 static const struct sti_init_flags default_init_flags = {
65 .wait = STI_WAIT,
66 .reset = 1,
67 .text = 1,
68 .nontext = 1,
69 .no_chg_bet = 1,
70 .no_chg_bei = 1,
71 .init_cmap_tx = 1,
74 static int sti_init_graph(struct sti_struct *sti)
76 struct sti_init_inptr *inptr = &sti->sti_data->init_inptr;
77 struct sti_init_inptr_ext *inptr_ext = &sti->sti_data->init_inptr_ext;
78 struct sti_init_outptr *outptr = &sti->sti_data->init_outptr;
79 unsigned long flags;
80 int ret, err;
82 spin_lock_irqsave(&sti->lock, flags);
84 memset(inptr, 0, sizeof(*inptr));
85 inptr->text_planes = 3; /* # of text planes (max 3 for STI) */
86 memset(inptr_ext, 0, sizeof(*inptr_ext));
87 inptr->ext_ptr = STI_PTR(inptr_ext);
88 outptr->errno = 0;
90 ret = sti_call(sti, sti->init_graph, &default_init_flags, inptr,
91 outptr, sti->glob_cfg);
93 if (ret >= 0)
94 sti->text_planes = outptr->text_planes;
95 err = outptr->errno;
97 spin_unlock_irqrestore(&sti->lock, flags);
99 if (ret < 0) {
100 pr_err("STI init_graph failed (ret %d, errno %d)\n", ret, err);
101 return -1;
104 return 0;
107 static const struct sti_conf_flags default_conf_flags = {
108 .wait = STI_WAIT,
111 static void sti_inq_conf(struct sti_struct *sti)
113 struct sti_conf_inptr *inptr = &sti->sti_data->inq_inptr;
114 struct sti_conf_outptr *outptr = &sti->sti_data->inq_outptr;
115 unsigned long flags;
116 s32 ret;
118 outptr->ext_ptr = STI_PTR(&sti->sti_data->inq_outptr_ext);
120 do {
121 spin_lock_irqsave(&sti->lock, flags);
122 memset(inptr, 0, sizeof(*inptr));
123 ret = sti_call(sti, sti->inq_conf, &default_conf_flags,
124 inptr, outptr, sti->glob_cfg);
125 spin_unlock_irqrestore(&sti->lock, flags);
126 } while (ret == 1);
129 static const struct sti_font_flags default_font_flags = {
130 .wait = STI_WAIT,
131 .non_text = 0,
134 void
135 sti_putc(struct sti_struct *sti, int c, int y, int x)
137 struct sti_font_inptr *inptr = &sti->sti_data->font_inptr;
138 struct sti_font_inptr inptr_default = {
139 .font_start_addr= STI_PTR(sti->font->raw),
140 .index = c_index(sti, c),
141 .fg_color = c_fg(sti, c),
142 .bg_color = c_bg(sti, c),
143 .dest_x = x * sti->font_width,
144 .dest_y = y * sti->font_height,
146 struct sti_font_outptr *outptr = &sti->sti_data->font_outptr;
147 s32 ret;
148 unsigned long flags;
150 do {
151 spin_lock_irqsave(&sti->lock, flags);
152 *inptr = inptr_default;
153 ret = sti_call(sti, sti->font_unpmv, &default_font_flags,
154 inptr, outptr, sti->glob_cfg);
155 spin_unlock_irqrestore(&sti->lock, flags);
156 } while (ret == 1);
159 static const struct sti_blkmv_flags clear_blkmv_flags = {
160 .wait = STI_WAIT,
161 .color = 1,
162 .clear = 1,
165 void
166 sti_set(struct sti_struct *sti, int src_y, int src_x,
167 int height, int width, u8 color)
169 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
170 struct sti_blkmv_inptr inptr_default = {
171 .fg_color = color,
172 .bg_color = color,
173 .src_x = src_x,
174 .src_y = src_y,
175 .dest_x = src_x,
176 .dest_y = src_y,
177 .width = width,
178 .height = height,
180 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
181 s32 ret;
182 unsigned long flags;
184 do {
185 spin_lock_irqsave(&sti->lock, flags);
186 *inptr = inptr_default;
187 ret = sti_call(sti, sti->block_move, &clear_blkmv_flags,
188 inptr, outptr, sti->glob_cfg);
189 spin_unlock_irqrestore(&sti->lock, flags);
190 } while (ret == 1);
193 void
194 sti_clear(struct sti_struct *sti, int src_y, int src_x,
195 int height, int width, int c)
197 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
198 struct sti_blkmv_inptr inptr_default = {
199 .fg_color = c_fg(sti, c),
200 .bg_color = c_bg(sti, c),
201 .src_x = src_x * sti->font_width,
202 .src_y = src_y * sti->font_height,
203 .dest_x = src_x * sti->font_width,
204 .dest_y = src_y * sti->font_height,
205 .width = width * sti->font_width,
206 .height = height* sti->font_height,
208 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
209 s32 ret;
210 unsigned long flags;
212 do {
213 spin_lock_irqsave(&sti->lock, flags);
214 *inptr = inptr_default;
215 ret = sti_call(sti, sti->block_move, &clear_blkmv_flags,
216 inptr, outptr, sti->glob_cfg);
217 spin_unlock_irqrestore(&sti->lock, flags);
218 } while (ret == 1);
221 static const struct sti_blkmv_flags default_blkmv_flags = {
222 .wait = STI_WAIT,
225 void
226 sti_bmove(struct sti_struct *sti, int src_y, int src_x,
227 int dst_y, int dst_x, int height, int width)
229 struct sti_blkmv_inptr *inptr = &sti->sti_data->blkmv_inptr;
230 struct sti_blkmv_inptr inptr_default = {
231 .src_x = src_x * sti->font_width,
232 .src_y = src_y * sti->font_height,
233 .dest_x = dst_x * sti->font_width,
234 .dest_y = dst_y * sti->font_height,
235 .width = width * sti->font_width,
236 .height = height* sti->font_height,
238 struct sti_blkmv_outptr *outptr = &sti->sti_data->blkmv_outptr;
239 s32 ret;
240 unsigned long flags;
242 do {
243 spin_lock_irqsave(&sti->lock, flags);
244 *inptr = inptr_default;
245 ret = sti_call(sti, sti->block_move, &default_blkmv_flags,
246 inptr, outptr, sti->glob_cfg);
247 spin_unlock_irqrestore(&sti->lock, flags);
248 } while (ret == 1);
252 static void sti_flush(unsigned long start, unsigned long end)
254 flush_icache_range(start, end);
257 static void sti_rom_copy(unsigned long base, unsigned long count, void *dest)
259 unsigned long dest_start = (unsigned long) dest;
261 /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */
262 while (count >= 4) {
263 count -= 4;
264 *(u32 *)dest = gsc_readl(base);
265 base += 4;
266 dest += 4;
268 while (count) {
269 count--;
270 *(u8 *)dest = gsc_readb(base);
271 base++;
272 dest++;
275 sti_flush(dest_start, (unsigned long)dest);
281 static char default_sti_path[21] __read_mostly;
283 #ifndef MODULE
284 static int __init sti_setup(char *str)
286 if (str)
287 strlcpy (default_sti_path, str, sizeof (default_sti_path));
289 return 1;
292 /* Assuming the machine has multiple STI consoles (=graphic cards) which
293 * all get detected by sticon, the user may define with the linux kernel
294 * parameter sti=<x> which of them will be the initial boot-console.
295 * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default
296 * STI screen.
298 __setup("sti=", sti_setup);
299 #endif
303 static char *font_name[MAX_STI_ROMS];
304 static int font_index[MAX_STI_ROMS],
305 font_height[MAX_STI_ROMS],
306 font_width[MAX_STI_ROMS];
307 #ifndef MODULE
308 static int sti_font_setup(char *str)
310 char *x;
311 int i = 0;
313 /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20
314 * or sti_font=7 style command lines. */
316 while (i<MAX_STI_ROMS && str && *str) {
317 if (*str>='0' && *str<='9') {
318 if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) {
319 font_height[i] = simple_strtoul(str, NULL, 0);
320 font_width[i] = simple_strtoul(x+1, NULL, 0);
321 } else {
322 font_index[i] = simple_strtoul(str, NULL, 0);
324 } else {
325 font_name[i] = str; /* fb font name */
328 if ((x = strchr(str, ',')))
329 *x++ = 0;
330 str = x;
332 i++;
335 return 1;
338 /* The optional linux kernel parameter "sti_font" defines which font
339 * should be used by the sticon driver to draw characters to the screen.
340 * Possible values are:
341 * - sti_font=<fb_fontname>:
342 * <fb_fontname> is the name of one of the linux-kernel built-in
343 * framebuffer font names (e.g. VGA8x16, SUN22x18).
344 * This is only available if the fonts have been statically compiled
345 * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options.
346 * - sti_font=<number>
347 * most STI ROMs have built-in HP specific fonts, which can be selected
348 * by giving the desired number to the sticon driver.
349 * NOTE: This number is machine and STI ROM dependend.
350 * - sti_font=<height>x<width> (e.g. sti_font=16x8)
351 * <height> and <width> gives hints to the height and width of the
352 * font which the user wants. The sticon driver will try to use
353 * a font with this height and width, but if no suitable font is
354 * found, sticon will use the default 8x8 font.
356 __setup("sti_font=", sti_font_setup);
357 #endif
361 static void sti_dump_globcfg(struct sti_glob_cfg *glob_cfg,
362 unsigned int sti_mem_request)
364 struct sti_glob_cfg_ext *cfg;
366 DPRINTK((KERN_INFO
367 "%d text planes\n"
368 "%4d x %4d screen resolution\n"
369 "%4d x %4d offscreen\n"
370 "%4d x %4d layout\n"
371 "regions at %08x %08x %08x %08x\n"
372 "regions at %08x %08x %08x %08x\n"
373 "reent_lvl %d\n"
374 "save_addr %08x\n",
375 glob_cfg->text_planes,
376 glob_cfg->onscreen_x, glob_cfg->onscreen_y,
377 glob_cfg->offscreen_x, glob_cfg->offscreen_y,
378 glob_cfg->total_x, glob_cfg->total_y,
379 glob_cfg->region_ptrs[0], glob_cfg->region_ptrs[1],
380 glob_cfg->region_ptrs[2], glob_cfg->region_ptrs[3],
381 glob_cfg->region_ptrs[4], glob_cfg->region_ptrs[5],
382 glob_cfg->region_ptrs[6], glob_cfg->region_ptrs[7],
383 glob_cfg->reent_lvl,
384 glob_cfg->save_addr));
386 /* dump extended cfg */
387 cfg = PTR_STI((unsigned long)glob_cfg->ext_ptr);
388 DPRINTK(( KERN_INFO
389 "monitor %d\n"
390 "in friendly mode: %d\n"
391 "power consumption %d watts\n"
392 "freq ref %d\n"
393 "sti_mem_addr %08x (size=%d bytes)\n",
394 cfg->curr_mon,
395 cfg->friendly_boot,
396 cfg->power,
397 cfg->freq_ref,
398 cfg->sti_mem_addr, sti_mem_request));
401 static void sti_dump_outptr(struct sti_struct *sti)
403 DPRINTK((KERN_INFO
404 "%d bits per pixel\n"
405 "%d used bits\n"
406 "%d planes\n"
407 "attributes %08x\n",
408 sti->sti_data->inq_outptr.bits_per_pixel,
409 sti->sti_data->inq_outptr.bits_used,
410 sti->sti_data->inq_outptr.planes,
411 sti->sti_data->inq_outptr.attributes));
414 static int sti_init_glob_cfg(struct sti_struct *sti, unsigned long rom_address,
415 unsigned long hpa)
417 struct sti_glob_cfg *glob_cfg;
418 struct sti_glob_cfg_ext *glob_cfg_ext;
419 void *save_addr;
420 void *sti_mem_addr;
421 int i, size;
423 if (sti->sti_mem_request < 256)
424 sti->sti_mem_request = 256; /* STI default */
426 size = sizeof(struct sti_all_data) + sti->sti_mem_request - 256;
428 sti->sti_data = kzalloc(size, STI_LOWMEM);
429 if (!sti->sti_data)
430 return -ENOMEM;
432 glob_cfg = &sti->sti_data->glob_cfg;
433 glob_cfg_ext = &sti->sti_data->glob_cfg_ext;
434 save_addr = &sti->sti_data->save_addr;
435 sti_mem_addr = &sti->sti_data->sti_mem_addr;
437 glob_cfg->ext_ptr = STI_PTR(glob_cfg_ext);
438 glob_cfg->save_addr = STI_PTR(save_addr);
439 for (i=0; i<8; i++) {
440 unsigned long newhpa, len;
442 if (sti->pd) {
443 unsigned char offs = sti->rm_entry[i];
445 if (offs == 0)
446 continue;
447 if (offs != PCI_ROM_ADDRESS &&
448 (offs < PCI_BASE_ADDRESS_0 ||
449 offs > PCI_BASE_ADDRESS_5)) {
450 printk (KERN_WARNING
451 "STI pci region mapping for region %d (%02x) can't be mapped\n",
452 i,sti->rm_entry[i]);
453 continue;
455 newhpa = pci_resource_start (sti->pd, (offs - PCI_BASE_ADDRESS_0) / 4);
456 } else
457 newhpa = (i == 0) ? rom_address : hpa;
459 sti->regions_phys[i] =
460 REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa);
462 len = sti->regions[i].region_desc.length * 4096;
463 if (len)
464 glob_cfg->region_ptrs[i] = sti->regions_phys[i];
466 DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
467 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
468 i, sti->regions_phys[i], glob_cfg->region_ptrs[i],
469 len/1024,
470 sti->regions[i].region_desc.btlb,
471 sti->regions[i].region_desc.sys_only,
472 sti->regions[i].region_desc.cache,
473 sti->regions[i].region_desc.last));
475 /* last entry reached ? */
476 if (sti->regions[i].region_desc.last)
477 break;
480 if (++i<8 && sti->regions[i].region)
481 printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n",
482 __FILE__, sti->regions[i].region);
484 glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr);
486 sti->glob_cfg = glob_cfg;
488 return 0;
491 #ifdef CONFIG_FONT_SUPPORT
492 static struct sti_cooked_font *
493 sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
495 const struct font_desc *fbfont = NULL;
496 unsigned int size, bpc;
497 void *dest;
498 struct sti_rom_font *nf;
499 struct sti_cooked_font *cooked_font;
501 if (fbfont_name && strlen(fbfont_name))
502 fbfont = find_font(fbfont_name);
503 if (!fbfont)
504 fbfont = get_default_font(1024,768, ~(u32)0, ~(u32)0);
505 if (!fbfont)
506 return NULL;
508 pr_info("STI selected %dx%d framebuffer font %s for sticon\n",
509 fbfont->width, fbfont->height, fbfont->name);
511 bpc = ((fbfont->width+7)/8) * fbfont->height;
512 size = bpc * 256;
513 size += sizeof(struct sti_rom_font);
515 nf = kzalloc(size, STI_LOWMEM);
516 if (!nf)
517 return NULL;
519 nf->first_char = 0;
520 nf->last_char = 255;
521 nf->width = fbfont->width;
522 nf->height = fbfont->height;
523 nf->font_type = STI_FONT_HPROMAN8;
524 nf->bytes_per_char = bpc;
525 nf->next_font = 0;
526 nf->underline_height = 1;
527 nf->underline_pos = fbfont->height - nf->underline_height;
529 dest = nf;
530 dest += sizeof(struct sti_rom_font);
531 memcpy(dest, fbfont->data, bpc*256);
533 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
534 if (!cooked_font) {
535 kfree(nf);
536 return NULL;
539 cooked_font->raw = nf;
540 cooked_font->next_font = NULL;
542 cooked_rom->font_start = cooked_font;
544 return cooked_font;
546 #else
547 static struct sti_cooked_font *
548 sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
550 return NULL;
552 #endif
554 static struct sti_cooked_font *sti_select_font(struct sti_cooked_rom *rom,
555 int (*search_font_fnc)(struct sti_cooked_rom *, int, int))
557 struct sti_cooked_font *font;
558 int i;
559 int index = num_sti_roms;
561 /* check for framebuffer-font first */
562 if ((font = sti_select_fbfont(rom, font_name[index])))
563 return font;
565 if (font_width[index] && font_height[index])
566 font_index[index] = search_font_fnc(rom,
567 font_height[index], font_width[index]);
569 for (font = rom->font_start, i = font_index[index];
570 font && (i > 0);
571 font = font->next_font, i--);
573 if (font)
574 return font;
575 else
576 return rom->font_start;
580 static void sti_dump_rom(struct sti_rom *rom)
582 printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n",
583 rom->graphics_id[0],
584 rom->graphics_id[1],
585 rom->revno[0] >> 4,
586 rom->revno[0] & 0x0f);
587 DPRINTK((" supports %d monitors\n", rom->num_mons));
588 DPRINTK((" font start %08x\n", rom->font_start));
589 DPRINTK((" region list %08x\n", rom->region_list));
590 DPRINTK((" init_graph %08x\n", rom->init_graph));
591 DPRINTK((" bus support %02x\n", rom->bus_support));
592 DPRINTK((" ext bus support %02x\n", rom->ext_bus_support));
593 DPRINTK((" alternate code type %d\n", rom->alt_code_type));
597 static int sti_cook_fonts(struct sti_cooked_rom *cooked_rom,
598 struct sti_rom *raw_rom)
600 struct sti_rom_font *raw_font, *font_start;
601 struct sti_cooked_font *cooked_font;
603 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
604 if (!cooked_font)
605 return 0;
607 cooked_rom->font_start = cooked_font;
609 raw_font = ((void *)raw_rom) + (raw_rom->font_start);
611 font_start = raw_font;
612 cooked_font->raw = raw_font;
614 while (raw_font->next_font) {
615 raw_font = ((void *)font_start) + (raw_font->next_font);
617 cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
618 if (!cooked_font->next_font)
619 return 1;
621 cooked_font = cooked_font->next_font;
623 cooked_font->raw = raw_font;
626 cooked_font->next_font = NULL;
627 return 1;
631 static int sti_search_font(struct sti_cooked_rom *rom, int height, int width)
633 struct sti_cooked_font *font;
634 int i = 0;
636 for (font = rom->font_start; font; font = font->next_font, i++) {
637 if ((font->raw->width == width) &&
638 (font->raw->height == height))
639 return i;
641 return 0;
644 #define BMODE_RELOCATE(offset) offset = (offset) / 4;
645 #define BMODE_LAST_ADDR_OFFS 0x50
647 static void *sti_bmode_font_raw(struct sti_cooked_font *f)
649 unsigned char *n, *p, *q;
650 int size = f->raw->bytes_per_char*256+sizeof(struct sti_rom_font);
652 n = kzalloc(4*size, STI_LOWMEM);
653 if (!n)
654 return NULL;
655 p = n + 3;
656 q = (unsigned char *)f->raw;
657 while (size--) {
658 *p = *q++;
659 p+=4;
661 return n + 3;
664 static void sti_bmode_rom_copy(unsigned long base, unsigned long count,
665 void *dest)
667 unsigned long dest_start = (unsigned long) dest;
669 while (count) {
670 count--;
671 *(u8 *)dest = gsc_readl(base);
672 base += 4;
673 dest++;
676 sti_flush(dest_start, (unsigned long)dest);
679 static struct sti_rom *sti_get_bmode_rom (unsigned long address)
681 struct sti_rom *raw;
682 u32 size;
683 struct sti_rom_font *raw_font, *font_start;
685 sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size);
687 size = (size+3) / 4;
688 raw = kmalloc(size, STI_LOWMEM);
689 if (raw) {
690 sti_bmode_rom_copy(address, size, raw);
691 memmove (&raw->res004, &raw->type[0], 0x3c);
692 raw->type[3] = raw->res004;
694 BMODE_RELOCATE (raw->region_list);
695 BMODE_RELOCATE (raw->font_start);
697 BMODE_RELOCATE (raw->init_graph);
698 BMODE_RELOCATE (raw->state_mgmt);
699 BMODE_RELOCATE (raw->font_unpmv);
700 BMODE_RELOCATE (raw->block_move);
701 BMODE_RELOCATE (raw->inq_conf);
703 raw_font = ((void *)raw) + raw->font_start;
704 font_start = raw_font;
706 while (raw_font->next_font) {
707 BMODE_RELOCATE (raw_font->next_font);
708 raw_font = ((void *)font_start) + raw_font->next_font;
711 return raw;
714 static struct sti_rom *sti_get_wmode_rom(unsigned long address)
716 struct sti_rom *raw;
717 unsigned long size;
719 /* read the ROM size directly from the struct in ROM */
720 size = gsc_readl(address + offsetof(struct sti_rom,last_addr));
722 raw = kmalloc(size, STI_LOWMEM);
723 if (raw)
724 sti_rom_copy(address, size, raw);
726 return raw;
729 static int sti_read_rom(int wordmode, struct sti_struct *sti,
730 unsigned long address)
732 struct sti_cooked_rom *cooked;
733 struct sti_rom *raw = NULL;
734 unsigned long revno;
736 cooked = kmalloc(sizeof *cooked, GFP_KERNEL);
737 if (!cooked)
738 goto out_err;
740 if (wordmode)
741 raw = sti_get_wmode_rom (address);
742 else
743 raw = sti_get_bmode_rom (address);
745 if (!raw)
746 goto out_err;
748 if (!sti_cook_fonts(cooked, raw)) {
749 printk(KERN_ERR "No font found for STI at %08lx\n", address);
750 goto out_err;
753 if (raw->region_list)
754 memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions));
756 address = (unsigned long) STI_PTR(raw);
758 pr_info("STI ROM supports 32 %sbit firmware functions.\n",
759 raw->alt_code_type == ALT_CODE_TYPE_PA_RISC_64
760 ? "and 64 " : "");
762 sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff);
763 sti->block_move = address + (raw->block_move & 0x03ffffff);
764 sti->init_graph = address + (raw->init_graph & 0x03ffffff);
765 sti->inq_conf = address + (raw->inq_conf & 0x03ffffff);
767 sti->rom = cooked;
768 sti->rom->raw = raw;
770 sti->font = sti_select_font(sti->rom, sti_search_font);
771 sti->font_width = sti->font->raw->width;
772 sti->font_height = sti->font->raw->height;
773 if (!wordmode)
774 sti->font->raw = sti_bmode_font_raw(sti->font);
776 sti->sti_mem_request = raw->sti_mem_req;
777 sti->graphics_id[0] = raw->graphics_id[0];
778 sti->graphics_id[1] = raw->graphics_id[1];
780 sti_dump_rom(raw);
782 /* check if the ROM routines in this card are compatible */
783 if (wordmode || sti->graphics_id[1] != 0x09A02587)
784 goto ok;
786 revno = (raw->revno[0] << 8) | raw->revno[1];
788 switch (sti->graphics_id[0]) {
789 case S9000_ID_HCRX:
790 /* HyperA or HyperB ? */
791 if (revno == 0x8408 || revno == 0x840b)
792 goto msg_not_supported;
793 break;
794 case CRT_ID_THUNDER:
795 if (revno == 0x8509)
796 goto msg_not_supported;
797 break;
798 case CRT_ID_THUNDER2:
799 if (revno == 0x850c)
800 goto msg_not_supported;
803 return 1;
805 msg_not_supported:
806 printk(KERN_ERR "Sorry, this GSC/STI card is not yet supported.\n");
807 printk(KERN_ERR "Please see http://parisc-linux.org/faq/"
808 "graphics-howto.html for more info.\n");
809 /* fall through */
810 out_err:
811 kfree(raw);
812 kfree(cooked);
813 return 0;
816 static struct sti_struct *sti_try_rom_generic(unsigned long address,
817 unsigned long hpa,
818 struct pci_dev *pd)
820 struct sti_struct *sti;
821 int ok;
822 u32 sig;
824 if (num_sti_roms >= MAX_STI_ROMS) {
825 printk(KERN_WARNING "maximum number of STI ROMS reached !\n");
826 return NULL;
829 sti = kzalloc(sizeof(*sti), GFP_KERNEL);
830 if (!sti) {
831 printk(KERN_ERR "Not enough memory !\n");
832 return NULL;
835 spin_lock_init(&sti->lock);
837 test_rom:
838 /* if we can't read the ROM, bail out early. Not being able
839 * to read the hpa is okay, for romless sti */
840 if (pdc_add_valid(address))
841 goto out_err;
843 sig = gsc_readl(address);
845 /* check for a PCI ROM structure */
846 if ((le32_to_cpu(sig)==0xaa55)) {
847 unsigned int i, rm_offset;
848 u32 *rm;
849 i = gsc_readl(address+0x04);
850 if (i != 1) {
851 /* The ROM could have multiple architecture
852 * dependent images (e.g. i386, parisc,...) */
853 printk(KERN_WARNING
854 "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
855 goto out_err;
858 sti->pd = pd;
860 i = gsc_readl(address+0x0c);
861 DPRINTK(("PCI ROM size (from header) = %d kB\n",
862 le16_to_cpu(i>>16)*512/1024));
863 rm_offset = le16_to_cpu(i & 0xffff);
864 if (rm_offset) {
865 /* read 16 bytes from the pci region mapper array */
866 rm = (u32*) &sti->rm_entry;
867 *rm++ = gsc_readl(address+rm_offset+0x00);
868 *rm++ = gsc_readl(address+rm_offset+0x04);
869 *rm++ = gsc_readl(address+rm_offset+0x08);
870 *rm++ = gsc_readl(address+rm_offset+0x0c);
871 DPRINTK(("PCI region Mapper offset = %08x: ",
872 rm_offset));
873 for (i=0; i<16; i++)
874 DPRINTK(("%02x ", sti->rm_entry[i]));
875 DPRINTK(("\n"));
878 address += le32_to_cpu(gsc_readl(address+8));
879 DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address));
880 goto test_rom;
883 ok = 0;
885 if ((sig & 0xff) == 0x01) {
886 DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
887 address, hpa));
888 ok = sti_read_rom(0, sti, address);
891 if ((sig & 0xffff) == 0x0303) {
892 DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
893 address, hpa));
894 ok = sti_read_rom(1, sti, address);
897 if (!ok)
898 goto out_err;
900 if (sti_init_glob_cfg(sti, address, hpa))
901 goto out_err; /* not enough memory */
903 /* disable STI PCI ROM. ROM and card RAM overlap and
904 * leaving it enabled would force HPMCs
906 if (sti->pd) {
907 unsigned long rom_base;
908 rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE);
909 pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE);
910 DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n"));
913 if (sti_init_graph(sti))
914 goto out_err;
916 sti_inq_conf(sti);
917 sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request);
918 sti_dump_outptr(sti);
920 pr_info(" graphics card name: %s\n",
921 sti->sti_data->inq_outptr.dev_name);
923 sti_roms[num_sti_roms] = sti;
924 num_sti_roms++;
926 return sti;
928 out_err:
929 kfree(sti);
930 return NULL;
933 static void sticore_check_for_default_sti(struct sti_struct *sti, char *path)
935 if (strcmp (path, default_sti_path) == 0)
936 default_sti = sti;
940 * on newer systems PDC gives the address of the ROM
941 * in the additional address field addr[1] while on
942 * older Systems the PDC stores it in page0->proc_sti
944 static int __init sticore_pa_init(struct parisc_device *dev)
946 char pa_path[21];
947 struct sti_struct *sti = NULL;
948 int hpa = dev->hpa.start;
950 if (dev->num_addrs && dev->addr[0])
951 sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
952 if (!sti)
953 sti = sti_try_rom_generic(hpa, hpa, NULL);
954 if (!sti)
955 sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
956 if (!sti)
957 return 1;
959 print_pa_hwpath(dev, pa_path);
960 sticore_check_for_default_sti(sti, pa_path);
961 return 0;
965 static int sticore_pci_init(struct pci_dev *pd, const struct pci_device_id *ent)
967 #ifdef CONFIG_PCI
968 unsigned long fb_base, rom_base;
969 unsigned int fb_len, rom_len;
970 int err;
971 struct sti_struct *sti;
973 err = pci_enable_device(pd);
974 if (err < 0) {
975 dev_err(&pd->dev, "Cannot enable PCI device\n");
976 return err;
979 fb_base = pci_resource_start(pd, 0);
980 fb_len = pci_resource_len(pd, 0);
981 rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE);
982 rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE);
983 if (rom_base) {
984 pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE);
985 DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base));
988 printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
989 rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
991 DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
992 rom_base, fb_base));
994 sti = sti_try_rom_generic(rom_base, fb_base, pd);
995 if (sti) {
996 char pa_path[30];
997 print_pci_hwpath(pd, pa_path);
998 sticore_check_for_default_sti(sti, pa_path);
1001 if (!sti) {
1002 printk(KERN_WARNING "Unable to handle STI device '%s'\n",
1003 pci_name(pd));
1004 return -ENODEV;
1006 #endif /* CONFIG_PCI */
1008 return 0;
1012 static void __exit sticore_pci_remove(struct pci_dev *pd)
1014 BUG();
1018 static struct pci_device_id sti_pci_tbl[] = {
1019 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) },
1020 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) },
1021 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) },
1022 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) },
1023 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) },
1024 { 0, } /* terminate list */
1026 MODULE_DEVICE_TABLE(pci, sti_pci_tbl);
1028 static struct pci_driver pci_sti_driver = {
1029 .name = "sti",
1030 .id_table = sti_pci_tbl,
1031 .probe = sticore_pci_init,
1032 .remove = __exit_p(sticore_pci_remove),
1035 static struct parisc_device_id sti_pa_tbl[] = {
1036 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 },
1037 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 },
1038 { 0, }
1040 MODULE_DEVICE_TABLE(parisc, sti_pa_tbl);
1042 static struct parisc_driver pa_sti_driver __refdata = {
1043 .name = "sti",
1044 .id_table = sti_pa_tbl,
1045 .probe = sticore_pa_init,
1050 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1053 static int sticore_initialized __read_mostly;
1055 static void sti_init_roms(void)
1057 if (sticore_initialized)
1058 return;
1060 sticore_initialized = 1;
1062 printk(KERN_INFO "STI GSC/PCI core graphics driver "
1063 STI_DRIVERVERSION "\n");
1065 /* Register drivers for native & PCI cards */
1066 register_parisc_driver(&pa_sti_driver);
1067 WARN_ON(pci_register_driver(&pci_sti_driver));
1069 /* if we didn't find the given default sti, take the first one */
1070 if (!default_sti)
1071 default_sti = sti_roms[0];
1076 * index = 0 gives default sti
1077 * index > 0 gives other stis in detection order
1079 struct sti_struct * sti_get_rom(unsigned int index)
1081 if (!sticore_initialized)
1082 sti_init_roms();
1084 if (index == 0)
1085 return default_sti;
1087 if (index > num_sti_roms)
1088 return NULL;
1090 return sti_roms[index-1];
1092 EXPORT_SYMBOL(sti_get_rom);
1095 int sti_call(const struct sti_struct *sti, unsigned long func,
1096 const void *flags, void *inptr, void *outptr,
1097 struct sti_glob_cfg *glob_cfg)
1099 unsigned long _flags = STI_PTR(flags);
1100 unsigned long _inptr = STI_PTR(inptr);
1101 unsigned long _outptr = STI_PTR(outptr);
1102 unsigned long _glob_cfg = STI_PTR(glob_cfg);
1103 int ret;
1105 #ifdef CONFIG_64BIT
1106 /* Check for overflow when using 32bit STI on 64bit kernel. */
1107 if (WARN_ONCE(_flags>>32 || _inptr>>32 || _outptr>>32 || _glob_cfg>>32,
1108 "Out of 32bit-range pointers!"))
1109 return -1;
1110 #endif
1112 ret = pdc_sti_call(func, _flags, _inptr, _outptr, _glob_cfg);
1114 return ret;
1117 MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1118 MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1119 MODULE_LICENSE("GPL v2");