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-2013 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 #include <linux/module.h>
18 #include <linux/types.h>
19 #include <linux/kernel.h>
20 #include <linux/slab.h>
21 #include <linux/init.h>
22 #include <linux/pci.h>
23 #include <linux/font.h>
25 #include <asm/hardware.h>
27 #include <asm/parisc-device.h>
29 #include <asm/cacheflush.h>
30 #include <asm/grfioctl.h>
32 #include "../fbdev/sticore.h"
34 #define STI_DRIVERVERSION "Version 0.9b"
36 static struct sti_struct
*default_sti __read_mostly
;
38 /* number of STI ROMS found and their ptrs to each struct */
39 static int num_sti_roms __read_mostly
;
40 static struct sti_struct
*sti_roms
[MAX_STI_ROMS
] __read_mostly
;
43 /* The colour indices used by STI are
53 * So we have the same colours as VGA (basically one bit each for R, G, B),
54 * but have to translate them, anyway. */
56 static const u8 col_trans
[8] = {
61 #define c_fg(sti, c) col_trans[((c>> 8) & 7)]
62 #define c_bg(sti, c) col_trans[((c>>11) & 7)]
63 #define c_index(sti, c) ((c) & 0xff)
65 static const struct sti_init_flags default_init_flags
= {
75 static int sti_init_graph(struct sti_struct
*sti
)
77 struct sti_init_inptr
*inptr
= &sti
->sti_data
->init_inptr
;
78 struct sti_init_inptr_ext
*inptr_ext
= &sti
->sti_data
->init_inptr_ext
;
79 struct sti_init_outptr
*outptr
= &sti
->sti_data
->init_outptr
;
83 spin_lock_irqsave(&sti
->lock
, flags
);
85 memset(inptr
, 0, sizeof(*inptr
));
86 inptr
->text_planes
= 3; /* # of text planes (max 3 for STI) */
87 memset(inptr_ext
, 0, sizeof(*inptr_ext
));
88 inptr
->ext_ptr
= STI_PTR(inptr_ext
);
91 ret
= sti_call(sti
, sti
->init_graph
, &default_init_flags
, inptr
,
92 outptr
, sti
->glob_cfg
);
95 sti
->text_planes
= outptr
->text_planes
;
98 spin_unlock_irqrestore(&sti
->lock
, flags
);
101 pr_err("STI init_graph failed (ret %d, errno %d)\n", ret
, err
);
108 static const struct sti_conf_flags default_conf_flags
= {
112 static void sti_inq_conf(struct sti_struct
*sti
)
114 struct sti_conf_inptr
*inptr
= &sti
->sti_data
->inq_inptr
;
115 struct sti_conf_outptr
*outptr
= &sti
->sti_data
->inq_outptr
;
119 outptr
->ext_ptr
= STI_PTR(&sti
->sti_data
->inq_outptr_ext
);
122 spin_lock_irqsave(&sti
->lock
, flags
);
123 memset(inptr
, 0, sizeof(*inptr
));
124 ret
= sti_call(sti
, sti
->inq_conf
, &default_conf_flags
,
125 inptr
, outptr
, sti
->glob_cfg
);
126 spin_unlock_irqrestore(&sti
->lock
, flags
);
130 static const struct sti_font_flags default_font_flags
= {
136 sti_putc(struct sti_struct
*sti
, int c
, int y
, int x
)
138 struct sti_font_inptr
*inptr
= &sti
->sti_data
->font_inptr
;
139 struct sti_font_inptr inptr_default
= {
140 .font_start_addr
= STI_PTR(sti
->font
->raw
),
141 .index
= c_index(sti
, c
),
142 .fg_color
= c_fg(sti
, c
),
143 .bg_color
= c_bg(sti
, c
),
144 .dest_x
= x
* sti
->font_width
,
145 .dest_y
= y
* sti
->font_height
,
147 struct sti_font_outptr
*outptr
= &sti
->sti_data
->font_outptr
;
152 spin_lock_irqsave(&sti
->lock
, flags
);
153 *inptr
= inptr_default
;
154 ret
= sti_call(sti
, sti
->font_unpmv
, &default_font_flags
,
155 inptr
, outptr
, sti
->glob_cfg
);
156 spin_unlock_irqrestore(&sti
->lock
, flags
);
160 static const struct sti_blkmv_flags clear_blkmv_flags
= {
167 sti_set(struct sti_struct
*sti
, int src_y
, int src_x
,
168 int height
, int width
, u8 color
)
170 struct sti_blkmv_inptr
*inptr
= &sti
->sti_data
->blkmv_inptr
;
171 struct sti_blkmv_inptr inptr_default
= {
181 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
186 spin_lock_irqsave(&sti
->lock
, flags
);
187 *inptr
= inptr_default
;
188 ret
= sti_call(sti
, sti
->block_move
, &clear_blkmv_flags
,
189 inptr
, outptr
, sti
->glob_cfg
);
190 spin_unlock_irqrestore(&sti
->lock
, flags
);
195 sti_clear(struct sti_struct
*sti
, int src_y
, int src_x
,
196 int height
, int width
, int c
)
198 struct sti_blkmv_inptr
*inptr
= &sti
->sti_data
->blkmv_inptr
;
199 struct sti_blkmv_inptr inptr_default
= {
200 .fg_color
= c_fg(sti
, c
),
201 .bg_color
= c_bg(sti
, c
),
202 .src_x
= src_x
* sti
->font_width
,
203 .src_y
= src_y
* sti
->font_height
,
204 .dest_x
= src_x
* sti
->font_width
,
205 .dest_y
= src_y
* sti
->font_height
,
206 .width
= width
* sti
->font_width
,
207 .height
= height
* sti
->font_height
,
209 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
214 spin_lock_irqsave(&sti
->lock
, flags
);
215 *inptr
= inptr_default
;
216 ret
= sti_call(sti
, sti
->block_move
, &clear_blkmv_flags
,
217 inptr
, outptr
, sti
->glob_cfg
);
218 spin_unlock_irqrestore(&sti
->lock
, flags
);
222 static const struct sti_blkmv_flags default_blkmv_flags
= {
227 sti_bmove(struct sti_struct
*sti
, int src_y
, int src_x
,
228 int dst_y
, int dst_x
, int height
, int width
)
230 struct sti_blkmv_inptr
*inptr
= &sti
->sti_data
->blkmv_inptr
;
231 struct sti_blkmv_inptr inptr_default
= {
232 .src_x
= src_x
* sti
->font_width
,
233 .src_y
= src_y
* sti
->font_height
,
234 .dest_x
= dst_x
* sti
->font_width
,
235 .dest_y
= dst_y
* sti
->font_height
,
236 .width
= width
* sti
->font_width
,
237 .height
= height
* sti
->font_height
,
239 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
244 spin_lock_irqsave(&sti
->lock
, flags
);
245 *inptr
= inptr_default
;
246 ret
= sti_call(sti
, sti
->block_move
, &default_blkmv_flags
,
247 inptr
, outptr
, sti
->glob_cfg
);
248 spin_unlock_irqrestore(&sti
->lock
, flags
);
253 static void sti_flush(unsigned long start
, unsigned long end
)
255 flush_icache_range(start
, end
);
258 static void sti_rom_copy(unsigned long base
, unsigned long count
, void *dest
)
260 unsigned long dest_start
= (unsigned long) dest
;
262 /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */
265 *(u32
*)dest
= gsc_readl(base
);
271 *(u8
*)dest
= gsc_readb(base
);
276 sti_flush(dest_start
, (unsigned long)dest
);
282 static char default_sti_path
[21] __read_mostly
;
285 static int __init
sti_setup(char *str
)
288 strlcpy (default_sti_path
, str
, sizeof (default_sti_path
));
293 /* Assuming the machine has multiple STI consoles (=graphic cards) which
294 * all get detected by sticon, the user may define with the linux kernel
295 * parameter sti=<x> which of them will be the initial boot-console.
296 * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default
299 __setup("sti=", sti_setup
);
304 static char *font_name
[MAX_STI_ROMS
];
305 static int font_index
[MAX_STI_ROMS
],
306 font_height
[MAX_STI_ROMS
],
307 font_width
[MAX_STI_ROMS
];
309 static int sti_font_setup(char *str
)
314 /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20
315 * or sti_font=7 style command lines. */
317 while (i
<MAX_STI_ROMS
&& str
&& *str
) {
318 if (*str
>='0' && *str
<='9') {
319 if ((x
= strchr(str
, 'x')) || (x
= strchr(str
, '*'))) {
320 font_height
[i
] = simple_strtoul(str
, NULL
, 0);
321 font_width
[i
] = simple_strtoul(x
+1, NULL
, 0);
323 font_index
[i
] = simple_strtoul(str
, NULL
, 0);
326 font_name
[i
] = str
; /* fb font name */
329 if ((x
= strchr(str
, ',')))
339 /* The optional linux kernel parameter "sti_font" defines which font
340 * should be used by the sticon driver to draw characters to the screen.
341 * Possible values are:
342 * - sti_font=<fb_fontname>:
343 * <fb_fontname> is the name of one of the linux-kernel built-in
344 * framebuffer font names (e.g. VGA8x16, SUN22x18).
345 * This is only available if the fonts have been statically compiled
346 * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options.
347 * - sti_font=<number>
348 * most STI ROMs have built-in HP specific fonts, which can be selected
349 * by giving the desired number to the sticon driver.
350 * NOTE: This number is machine and STI ROM dependend.
351 * - sti_font=<height>x<width> (e.g. sti_font=16x8)
352 * <height> and <width> gives hints to the height and width of the
353 * font which the user wants. The sticon driver will try to use
354 * a font with this height and width, but if no suitable font is
355 * found, sticon will use the default 8x8 font.
357 __setup("sti_font=", sti_font_setup
);
362 static void sti_dump_globcfg(struct sti_glob_cfg
*glob_cfg
,
363 unsigned int sti_mem_request
)
365 struct sti_glob_cfg_ext
*cfg
;
369 "%4d x %4d screen resolution\n"
370 "%4d x %4d offscreen\n"
372 "regions at %08x %08x %08x %08x\n"
373 "regions at %08x %08x %08x %08x\n"
376 glob_cfg
->text_planes
,
377 glob_cfg
->onscreen_x
, glob_cfg
->onscreen_y
,
378 glob_cfg
->offscreen_x
, glob_cfg
->offscreen_y
,
379 glob_cfg
->total_x
, glob_cfg
->total_y
,
380 glob_cfg
->region_ptrs
[0], glob_cfg
->region_ptrs
[1],
381 glob_cfg
->region_ptrs
[2], glob_cfg
->region_ptrs
[3],
382 glob_cfg
->region_ptrs
[4], glob_cfg
->region_ptrs
[5],
383 glob_cfg
->region_ptrs
[6], glob_cfg
->region_ptrs
[7],
385 glob_cfg
->save_addr
));
387 /* dump extended cfg */
388 cfg
= PTR_STI((unsigned long)glob_cfg
->ext_ptr
);
391 "in friendly mode: %d\n"
392 "power consumption %d watts\n"
394 "sti_mem_addr %08x (size=%d bytes)\n",
399 cfg
->sti_mem_addr
, sti_mem_request
));
402 static void sti_dump_outptr(struct sti_struct
*sti
)
405 "%d bits per pixel\n"
409 sti
->sti_data
->inq_outptr
.bits_per_pixel
,
410 sti
->sti_data
->inq_outptr
.bits_used
,
411 sti
->sti_data
->inq_outptr
.planes
,
412 sti
->sti_data
->inq_outptr
.attributes
));
415 static int sti_init_glob_cfg(struct sti_struct
*sti
, unsigned long rom_address
,
418 struct sti_glob_cfg
*glob_cfg
;
419 struct sti_glob_cfg_ext
*glob_cfg_ext
;
424 if (sti
->sti_mem_request
< 256)
425 sti
->sti_mem_request
= 256; /* STI default */
427 size
= sizeof(struct sti_all_data
) + sti
->sti_mem_request
- 256;
429 sti
->sti_data
= kzalloc(size
, STI_LOWMEM
);
433 glob_cfg
= &sti
->sti_data
->glob_cfg
;
434 glob_cfg_ext
= &sti
->sti_data
->glob_cfg_ext
;
435 save_addr
= &sti
->sti_data
->save_addr
;
436 sti_mem_addr
= &sti
->sti_data
->sti_mem_addr
;
438 glob_cfg
->ext_ptr
= STI_PTR(glob_cfg_ext
);
439 glob_cfg
->save_addr
= STI_PTR(save_addr
);
440 for (i
=0; i
<8; i
++) {
441 unsigned long newhpa
, len
;
444 unsigned char offs
= sti
->rm_entry
[i
];
448 if (offs
!= PCI_ROM_ADDRESS
&&
449 (offs
< PCI_BASE_ADDRESS_0
||
450 offs
> PCI_BASE_ADDRESS_5
)) {
452 "STI pci region mapping for region %d (%02x) can't be mapped\n",
456 newhpa
= pci_resource_start (sti
->pd
, (offs
- PCI_BASE_ADDRESS_0
) / 4);
458 newhpa
= (i
== 0) ? rom_address
: hpa
;
460 sti
->regions_phys
[i
] =
461 REGION_OFFSET_TO_PHYS(sti
->regions
[i
], newhpa
);
463 len
= sti
->regions
[i
].region_desc
.length
* 4096;
465 glob_cfg
->region_ptrs
[i
] = sti
->regions_phys
[i
];
467 DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
468 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
469 i
, sti
->regions_phys
[i
], glob_cfg
->region_ptrs
[i
],
471 sti
->regions
[i
].region_desc
.btlb
,
472 sti
->regions
[i
].region_desc
.sys_only
,
473 sti
->regions
[i
].region_desc
.cache
,
474 sti
->regions
[i
].region_desc
.last
));
476 /* last entry reached ? */
477 if (sti
->regions
[i
].region_desc
.last
)
481 if (++i
<8 && sti
->regions
[i
].region
)
482 printk(KERN_WARNING
"%s: *future ptr (0x%8x) not yet supported !\n",
483 __FILE__
, sti
->regions
[i
].region
);
485 glob_cfg_ext
->sti_mem_addr
= STI_PTR(sti_mem_addr
);
487 sti
->glob_cfg
= glob_cfg
;
492 #ifdef CONFIG_FONT_SUPPORT
493 static struct sti_cooked_font
*
494 sti_select_fbfont(struct sti_cooked_rom
*cooked_rom
, const char *fbfont_name
)
496 const struct font_desc
*fbfont
= NULL
;
497 unsigned int size
, bpc
;
499 struct sti_rom_font
*nf
;
500 struct sti_cooked_font
*cooked_font
;
502 if (fbfont_name
&& strlen(fbfont_name
))
503 fbfont
= find_font(fbfont_name
);
505 fbfont
= get_default_font(1024,768, ~(u32
)0, ~(u32
)0);
509 pr_info("STI selected %dx%d framebuffer font %s for sticon\n",
510 fbfont
->width
, fbfont
->height
, fbfont
->name
);
512 bpc
= ((fbfont
->width
+7)/8) * fbfont
->height
;
514 size
+= sizeof(struct sti_rom_font
);
516 nf
= kzalloc(size
, STI_LOWMEM
);
522 nf
->width
= fbfont
->width
;
523 nf
->height
= fbfont
->height
;
524 nf
->font_type
= STI_FONT_HPROMAN8
;
525 nf
->bytes_per_char
= bpc
;
527 nf
->underline_height
= 1;
528 nf
->underline_pos
= fbfont
->height
- nf
->underline_height
;
531 dest
+= sizeof(struct sti_rom_font
);
532 memcpy(dest
, fbfont
->data
, bpc
*256);
534 cooked_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
540 cooked_font
->raw
= nf
;
541 cooked_font
->next_font
= NULL
;
543 cooked_rom
->font_start
= cooked_font
;
548 static struct sti_cooked_font
*
549 sti_select_fbfont(struct sti_cooked_rom
*cooked_rom
, const char *fbfont_name
)
555 static struct sti_cooked_font
*sti_select_font(struct sti_cooked_rom
*rom
,
556 int (*search_font_fnc
)(struct sti_cooked_rom
*, int, int))
558 struct sti_cooked_font
*font
;
560 int index
= num_sti_roms
;
562 /* check for framebuffer-font first */
563 if ((font
= sti_select_fbfont(rom
, font_name
[index
])))
566 if (font_width
[index
] && font_height
[index
])
567 font_index
[index
] = search_font_fnc(rom
,
568 font_height
[index
], font_width
[index
]);
570 for (font
= rom
->font_start
, i
= font_index
[index
];
572 font
= font
->next_font
, i
--);
577 return rom
->font_start
;
581 static void sti_dump_rom(struct sti_rom
*rom
)
583 printk(KERN_INFO
" id %04x-%04x, conforms to spec rev. %d.%02x\n",
587 rom
->revno
[0] & 0x0f);
588 DPRINTK((" supports %d monitors\n", rom
->num_mons
));
589 DPRINTK((" font start %08x\n", rom
->font_start
));
590 DPRINTK((" region list %08x\n", rom
->region_list
));
591 DPRINTK((" init_graph %08x\n", rom
->init_graph
));
592 DPRINTK((" bus support %02x\n", rom
->bus_support
));
593 DPRINTK((" ext bus support %02x\n", rom
->ext_bus_support
));
594 DPRINTK((" alternate code type %d\n", rom
->alt_code_type
));
598 static int sti_cook_fonts(struct sti_cooked_rom
*cooked_rom
,
599 struct sti_rom
*raw_rom
)
601 struct sti_rom_font
*raw_font
, *font_start
;
602 struct sti_cooked_font
*cooked_font
;
604 cooked_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
608 cooked_rom
->font_start
= cooked_font
;
610 raw_font
= ((void *)raw_rom
) + (raw_rom
->font_start
);
612 font_start
= raw_font
;
613 cooked_font
->raw
= raw_font
;
615 while (raw_font
->next_font
) {
616 raw_font
= ((void *)font_start
) + (raw_font
->next_font
);
618 cooked_font
->next_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
619 if (!cooked_font
->next_font
)
622 cooked_font
= cooked_font
->next_font
;
624 cooked_font
->raw
= raw_font
;
627 cooked_font
->next_font
= NULL
;
632 static int sti_search_font(struct sti_cooked_rom
*rom
, int height
, int width
)
634 struct sti_cooked_font
*font
;
637 for (font
= rom
->font_start
; font
; font
= font
->next_font
, i
++) {
638 if ((font
->raw
->width
== width
) &&
639 (font
->raw
->height
== height
))
645 #define BMODE_RELOCATE(offset) offset = (offset) / 4;
646 #define BMODE_LAST_ADDR_OFFS 0x50
648 static void *sti_bmode_font_raw(struct sti_cooked_font
*f
)
650 unsigned char *n
, *p
, *q
;
651 int size
= f
->raw
->bytes_per_char
*256+sizeof(struct sti_rom_font
);
653 n
= kcalloc(4, size
, STI_LOWMEM
);
657 q
= (unsigned char *)f
->raw
;
665 static void sti_bmode_rom_copy(unsigned long base
, unsigned long count
,
668 unsigned long dest_start
= (unsigned long) dest
;
672 *(u8
*)dest
= gsc_readl(base
);
677 sti_flush(dest_start
, (unsigned long)dest
);
680 static struct sti_rom
*sti_get_bmode_rom (unsigned long address
)
684 struct sti_rom_font
*raw_font
, *font_start
;
686 sti_bmode_rom_copy(address
+ BMODE_LAST_ADDR_OFFS
, sizeof(size
), &size
);
689 raw
= kmalloc(size
, STI_LOWMEM
);
691 sti_bmode_rom_copy(address
, size
, raw
);
692 memmove (&raw
->res004
, &raw
->type
[0], 0x3c);
693 raw
->type
[3] = raw
->res004
;
695 BMODE_RELOCATE (raw
->region_list
);
696 BMODE_RELOCATE (raw
->font_start
);
698 BMODE_RELOCATE (raw
->init_graph
);
699 BMODE_RELOCATE (raw
->state_mgmt
);
700 BMODE_RELOCATE (raw
->font_unpmv
);
701 BMODE_RELOCATE (raw
->block_move
);
702 BMODE_RELOCATE (raw
->inq_conf
);
704 raw_font
= ((void *)raw
) + raw
->font_start
;
705 font_start
= raw_font
;
707 while (raw_font
->next_font
) {
708 BMODE_RELOCATE (raw_font
->next_font
);
709 raw_font
= ((void *)font_start
) + raw_font
->next_font
;
715 static struct sti_rom
*sti_get_wmode_rom(unsigned long address
)
720 /* read the ROM size directly from the struct in ROM */
721 size
= gsc_readl(address
+ offsetof(struct sti_rom
,last_addr
));
723 raw
= kmalloc(size
, STI_LOWMEM
);
725 sti_rom_copy(address
, size
, raw
);
730 static int sti_read_rom(int wordmode
, struct sti_struct
*sti
,
731 unsigned long address
)
733 struct sti_cooked_rom
*cooked
;
734 struct sti_rom
*raw
= NULL
;
737 cooked
= kmalloc(sizeof *cooked
, GFP_KERNEL
);
742 raw
= sti_get_wmode_rom (address
);
744 raw
= sti_get_bmode_rom (address
);
749 if (!sti_cook_fonts(cooked
, raw
)) {
750 printk(KERN_ERR
"No font found for STI at %08lx\n", address
);
754 if (raw
->region_list
)
755 memcpy(sti
->regions
, ((void *)raw
)+raw
->region_list
, sizeof(sti
->regions
));
757 address
= (unsigned long) STI_PTR(raw
);
759 pr_info("STI ROM supports 32 %sbit firmware functions.\n",
760 raw
->alt_code_type
== ALT_CODE_TYPE_PA_RISC_64
763 sti
->font_unpmv
= address
+ (raw
->font_unpmv
& 0x03ffffff);
764 sti
->block_move
= address
+ (raw
->block_move
& 0x03ffffff);
765 sti
->init_graph
= address
+ (raw
->init_graph
& 0x03ffffff);
766 sti
->inq_conf
= address
+ (raw
->inq_conf
& 0x03ffffff);
771 sti
->font
= sti_select_font(sti
->rom
, sti_search_font
);
772 sti
->font_width
= sti
->font
->raw
->width
;
773 sti
->font_height
= sti
->font
->raw
->height
;
775 sti
->font
->raw
= sti_bmode_font_raw(sti
->font
);
777 sti
->sti_mem_request
= raw
->sti_mem_req
;
778 sti
->graphics_id
[0] = raw
->graphics_id
[0];
779 sti
->graphics_id
[1] = raw
->graphics_id
[1];
783 /* check if the ROM routines in this card are compatible */
784 if (wordmode
|| sti
->graphics_id
[1] != 0x09A02587)
787 revno
= (raw
->revno
[0] << 8) | raw
->revno
[1];
789 switch (sti
->graphics_id
[0]) {
791 /* HyperA or HyperB ? */
792 if (revno
== 0x8408 || revno
== 0x840b)
793 goto msg_not_supported
;
797 goto msg_not_supported
;
799 case CRT_ID_THUNDER2
:
801 goto msg_not_supported
;
807 printk(KERN_ERR
"Sorry, this GSC/STI card is not yet supported.\n");
808 printk(KERN_ERR
"Please see http://parisc-linux.org/faq/"
809 "graphics-howto.html for more info.\n");
817 static struct sti_struct
*sti_try_rom_generic(unsigned long address
,
821 struct sti_struct
*sti
;
825 if (num_sti_roms
>= MAX_STI_ROMS
) {
826 printk(KERN_WARNING
"maximum number of STI ROMS reached !\n");
830 sti
= kzalloc(sizeof(*sti
), GFP_KERNEL
);
834 spin_lock_init(&sti
->lock
);
837 /* if we can't read the ROM, bail out early. Not being able
838 * to read the hpa is okay, for romless sti */
839 if (pdc_add_valid(address
))
842 sig
= gsc_readl(address
);
844 /* check for a PCI ROM structure */
845 if ((le32_to_cpu(sig
)==0xaa55)) {
846 unsigned int i
, rm_offset
;
848 i
= gsc_readl(address
+0x04);
850 /* The ROM could have multiple architecture
851 * dependent images (e.g. i386, parisc,...) */
853 "PCI ROM is not a STI ROM type image (0x%8x)\n", i
);
859 i
= gsc_readl(address
+0x0c);
860 DPRINTK(("PCI ROM size (from header) = %d kB\n",
861 le16_to_cpu(i
>>16)*512/1024));
862 rm_offset
= le16_to_cpu(i
& 0xffff);
864 /* read 16 bytes from the pci region mapper array */
865 rm
= (u32
*) &sti
->rm_entry
;
866 *rm
++ = gsc_readl(address
+rm_offset
+0x00);
867 *rm
++ = gsc_readl(address
+rm_offset
+0x04);
868 *rm
++ = gsc_readl(address
+rm_offset
+0x08);
869 *rm
++ = gsc_readl(address
+rm_offset
+0x0c);
870 DPRINTK(("PCI region Mapper offset = %08x: ",
873 DPRINTK(("%02x ", sti
->rm_entry
[i
]));
877 address
+= le32_to_cpu(gsc_readl(address
+8));
878 DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig
, address
));
884 if ((sig
& 0xff) == 0x01) {
885 DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
887 ok
= sti_read_rom(0, sti
, address
);
890 if ((sig
& 0xffff) == 0x0303) {
891 DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
893 ok
= sti_read_rom(1, sti
, address
);
899 if (sti_init_glob_cfg(sti
, address
, hpa
))
900 goto out_err
; /* not enough memory */
902 /* disable STI PCI ROM. ROM and card RAM overlap and
903 * leaving it enabled would force HPMCs
906 unsigned long rom_base
;
907 rom_base
= pci_resource_start(sti
->pd
, PCI_ROM_RESOURCE
);
908 pci_write_config_dword(sti
->pd
, PCI_ROM_ADDRESS
, rom_base
& ~PCI_ROM_ADDRESS_ENABLE
);
909 DPRINTK((KERN_DEBUG
"STI PCI ROM disabled\n"));
912 if (sti_init_graph(sti
))
916 sti_dump_globcfg(sti
->glob_cfg
, sti
->sti_mem_request
);
917 sti_dump_outptr(sti
);
919 pr_info(" graphics card name: %s\n",
920 sti
->sti_data
->inq_outptr
.dev_name
);
922 sti_roms
[num_sti_roms
] = sti
;
932 static void sticore_check_for_default_sti(struct sti_struct
*sti
, char *path
)
934 if (strcmp (path
, default_sti_path
) == 0)
939 * on newer systems PDC gives the address of the ROM
940 * in the additional address field addr[1] while on
941 * older Systems the PDC stores it in page0->proc_sti
943 static int __init
sticore_pa_init(struct parisc_device
*dev
)
946 struct sti_struct
*sti
= NULL
;
947 int hpa
= dev
->hpa
.start
;
949 if (dev
->num_addrs
&& dev
->addr
[0])
950 sti
= sti_try_rom_generic(dev
->addr
[0], hpa
, NULL
);
952 sti
= sti_try_rom_generic(hpa
, hpa
, NULL
);
954 sti
= sti_try_rom_generic(PAGE0
->proc_sti
, hpa
, NULL
);
958 print_pa_hwpath(dev
, pa_path
);
959 sticore_check_for_default_sti(sti
, pa_path
);
964 static int sticore_pci_init(struct pci_dev
*pd
, const struct pci_device_id
*ent
)
967 unsigned long fb_base
, rom_base
;
968 unsigned int fb_len
, rom_len
;
970 struct sti_struct
*sti
;
972 err
= pci_enable_device(pd
);
974 dev_err(&pd
->dev
, "Cannot enable PCI device\n");
978 fb_base
= pci_resource_start(pd
, 0);
979 fb_len
= pci_resource_len(pd
, 0);
980 rom_base
= pci_resource_start(pd
, PCI_ROM_RESOURCE
);
981 rom_len
= pci_resource_len(pd
, PCI_ROM_RESOURCE
);
983 pci_write_config_dword(pd
, PCI_ROM_ADDRESS
, rom_base
| PCI_ROM_ADDRESS_ENABLE
);
984 DPRINTK((KERN_DEBUG
"STI PCI ROM enabled at 0x%08lx\n", rom_base
));
987 printk(KERN_INFO
"STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
988 rom_base
, rom_len
/1024, fb_base
, fb_len
/1024/1024);
990 DPRINTK((KERN_DEBUG
"Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
993 sti
= sti_try_rom_generic(rom_base
, fb_base
, pd
);
996 print_pci_hwpath(pd
, pa_path
);
997 sticore_check_for_default_sti(sti
, pa_path
);
1001 printk(KERN_WARNING
"Unable to handle STI device '%s'\n",
1005 #endif /* CONFIG_PCI */
1011 static void __exit
sticore_pci_remove(struct pci_dev
*pd
)
1017 static struct pci_device_id sti_pci_tbl
[] = {
1018 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_EG
) },
1019 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX6
) },
1020 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX4
) },
1021 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX2
) },
1022 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FXE
) },
1023 { 0, } /* terminate list */
1025 MODULE_DEVICE_TABLE(pci
, sti_pci_tbl
);
1027 static struct pci_driver pci_sti_driver
= {
1029 .id_table
= sti_pci_tbl
,
1030 .probe
= sticore_pci_init
,
1031 .remove
= __exit_p(sticore_pci_remove
),
1034 static struct parisc_device_id sti_pa_tbl
[] = {
1035 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00077 },
1036 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00085 },
1039 MODULE_DEVICE_TABLE(parisc
, sti_pa_tbl
);
1041 static struct parisc_driver pa_sti_driver __refdata
= {
1043 .id_table
= sti_pa_tbl
,
1044 .probe
= sticore_pa_init
,
1049 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1052 static int sticore_initialized __read_mostly
;
1054 static void sti_init_roms(void)
1056 if (sticore_initialized
)
1059 sticore_initialized
= 1;
1061 printk(KERN_INFO
"STI GSC/PCI core graphics driver "
1062 STI_DRIVERVERSION
"\n");
1064 /* Register drivers for native & PCI cards */
1065 register_parisc_driver(&pa_sti_driver
);
1066 WARN_ON(pci_register_driver(&pci_sti_driver
));
1068 /* if we didn't find the given default sti, take the first one */
1070 default_sti
= sti_roms
[0];
1075 * index = 0 gives default sti
1076 * index > 0 gives other stis in detection order
1078 struct sti_struct
* sti_get_rom(unsigned int index
)
1080 if (!sticore_initialized
)
1086 if (index
> num_sti_roms
)
1089 return sti_roms
[index
-1];
1091 EXPORT_SYMBOL(sti_get_rom
);
1094 int sti_call(const struct sti_struct
*sti
, unsigned long func
,
1095 const void *flags
, void *inptr
, void *outptr
,
1096 struct sti_glob_cfg
*glob_cfg
)
1098 unsigned long _flags
= STI_PTR(flags
);
1099 unsigned long _inptr
= STI_PTR(inptr
);
1100 unsigned long _outptr
= STI_PTR(outptr
);
1101 unsigned long _glob_cfg
= STI_PTR(glob_cfg
);
1105 /* Check for overflow when using 32bit STI on 64bit kernel. */
1106 if (WARN_ONCE(_flags
>>32 || _inptr
>>32 || _outptr
>>32 || _glob_cfg
>>32,
1107 "Out of 32bit-range pointers!"))
1111 ret
= pdc_sti_call(func
, _flags
, _inptr
, _outptr
, _glob_cfg
);
1116 MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1117 MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1118 MODULE_LICENSE("GPL v2");