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>
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>
26 #include <asm/parisc-device.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
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] = {
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
= {
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
;
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
);
90 ret
= sti_call(sti
, sti
->init_graph
, &default_init_flags
, inptr
,
91 outptr
, sti
->glob_cfg
);
94 sti
->text_planes
= outptr
->text_planes
;
97 spin_unlock_irqrestore(&sti
->lock
, flags
);
100 pr_err("STI init_graph failed (ret %d, errno %d)\n", ret
, err
);
107 static const struct sti_conf_flags default_conf_flags
= {
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
;
118 outptr
->ext_ptr
= STI_PTR(&sti
->sti_data
->inq_outptr_ext
);
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
);
129 static const struct sti_font_flags default_font_flags
= {
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
;
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
);
159 static const struct sti_blkmv_flags clear_blkmv_flags
= {
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
= {
180 struct sti_blkmv_outptr
*outptr
= &sti
->sti_data
->blkmv_outptr
;
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
);
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
;
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
);
221 static const struct sti_blkmv_flags default_blkmv_flags
= {
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
;
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
);
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) ! */
264 *(u32
*)dest
= gsc_readl(base
);
270 *(u8
*)dest
= gsc_readb(base
);
275 sti_flush(dest_start
, (unsigned long)dest
);
281 static char default_sti_path
[21] __read_mostly
;
284 static int __init
sti_setup(char *str
)
287 strlcpy (default_sti_path
, str
, sizeof (default_sti_path
));
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
298 __setup("sti=", sti_setup
);
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
];
308 static int sti_font_setup(char *str
)
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);
322 font_index
[i
] = simple_strtoul(str
, NULL
, 0);
325 font_name
[i
] = str
; /* fb font name */
328 if ((x
= strchr(str
, ',')))
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
);
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
;
368 "%4d x %4d screen resolution\n"
369 "%4d x %4d offscreen\n"
371 "regions at %08x %08x %08x %08x\n"
372 "regions at %08x %08x %08x %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],
384 glob_cfg
->save_addr
));
386 /* dump extended cfg */
387 cfg
= PTR_STI((unsigned long)glob_cfg
->ext_ptr
);
390 "in friendly mode: %d\n"
391 "power consumption %d watts\n"
393 "sti_mem_addr %08x (size=%d bytes)\n",
398 cfg
->sti_mem_addr
, sti_mem_request
));
401 static void sti_dump_outptr(struct sti_struct
*sti
)
404 "%d bits per pixel\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
,
417 struct sti_glob_cfg
*glob_cfg
;
418 struct sti_glob_cfg_ext
*glob_cfg_ext
;
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
);
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
;
443 unsigned char offs
= sti
->rm_entry
[i
];
447 if (offs
!= PCI_ROM_ADDRESS
&&
448 (offs
< PCI_BASE_ADDRESS_0
||
449 offs
> PCI_BASE_ADDRESS_5
)) {
451 "STI pci region mapping for region %d (%02x) can't be mapped\n",
455 newhpa
= pci_resource_start (sti
->pd
, (offs
- PCI_BASE_ADDRESS_0
) / 4);
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;
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
],
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
)
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
;
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
;
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
);
504 fbfont
= get_default_font(1024,768, ~(u32
)0, ~(u32
)0);
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
;
513 size
+= sizeof(struct sti_rom_font
);
515 nf
= kzalloc(size
, STI_LOWMEM
);
521 nf
->width
= fbfont
->width
;
522 nf
->height
= fbfont
->height
;
523 nf
->font_type
= STI_FONT_HPROMAN8
;
524 nf
->bytes_per_char
= bpc
;
526 nf
->underline_height
= 1;
527 nf
->underline_pos
= fbfont
->height
- nf
->underline_height
;
530 dest
+= sizeof(struct sti_rom_font
);
531 memcpy(dest
, fbfont
->data
, bpc
*256);
533 cooked_font
= kzalloc(sizeof(*cooked_font
), GFP_KERNEL
);
539 cooked_font
->raw
= nf
;
540 cooked_font
->next_font
= NULL
;
542 cooked_rom
->font_start
= cooked_font
;
547 static struct sti_cooked_font
*
548 sti_select_fbfont(struct sti_cooked_rom
*cooked_rom
, const char *fbfont_name
)
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
;
559 int index
= num_sti_roms
;
561 /* check for framebuffer-font first */
562 if ((font
= sti_select_fbfont(rom
, font_name
[index
])))
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
];
571 font
= font
->next_font
, i
--);
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",
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
);
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
)
621 cooked_font
= cooked_font
->next_font
;
623 cooked_font
->raw
= raw_font
;
626 cooked_font
->next_font
= NULL
;
631 static int sti_search_font(struct sti_cooked_rom
*rom
, int height
, int width
)
633 struct sti_cooked_font
*font
;
636 for (font
= rom
->font_start
; font
; font
= font
->next_font
, i
++) {
637 if ((font
->raw
->width
== width
) &&
638 (font
->raw
->height
== height
))
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
= kcalloc(4, size
, STI_LOWMEM
);
656 q
= (unsigned char *)f
->raw
;
664 static void sti_bmode_rom_copy(unsigned long base
, unsigned long count
,
667 unsigned long dest_start
= (unsigned long) dest
;
671 *(u8
*)dest
= gsc_readl(base
);
676 sti_flush(dest_start
, (unsigned long)dest
);
679 static struct sti_rom
*sti_get_bmode_rom (unsigned long address
)
683 struct sti_rom_font
*raw_font
, *font_start
;
685 sti_bmode_rom_copy(address
+ BMODE_LAST_ADDR_OFFS
, sizeof(size
), &size
);
688 raw
= kmalloc(size
, STI_LOWMEM
);
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
;
714 static struct sti_rom
*sti_get_wmode_rom(unsigned long address
)
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
);
724 sti_rom_copy(address
, size
, 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
;
736 cooked
= kmalloc(sizeof *cooked
, GFP_KERNEL
);
741 raw
= sti_get_wmode_rom (address
);
743 raw
= sti_get_bmode_rom (address
);
748 if (!sti_cook_fonts(cooked
, raw
)) {
749 printk(KERN_ERR
"No font found for STI at %08lx\n", address
);
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
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);
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
;
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];
782 /* check if the ROM routines in this card are compatible */
783 if (wordmode
|| sti
->graphics_id
[1] != 0x09A02587)
786 revno
= (raw
->revno
[0] << 8) | raw
->revno
[1];
788 switch (sti
->graphics_id
[0]) {
790 /* HyperA or HyperB ? */
791 if (revno
== 0x8408 || revno
== 0x840b)
792 goto msg_not_supported
;
796 goto msg_not_supported
;
798 case CRT_ID_THUNDER2
:
800 goto 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");
816 static struct sti_struct
*sti_try_rom_generic(unsigned long address
,
820 struct sti_struct
*sti
;
824 if (num_sti_roms
>= MAX_STI_ROMS
) {
825 printk(KERN_WARNING
"maximum number of STI ROMS reached !\n");
829 sti
= kzalloc(sizeof(*sti
), GFP_KERNEL
);
833 spin_lock_init(&sti
->lock
);
836 /* if we can't read the ROM, bail out early. Not being able
837 * to read the hpa is okay, for romless sti */
838 if (pdc_add_valid(address
))
841 sig
= gsc_readl(address
);
843 /* check for a PCI ROM structure */
844 if ((le32_to_cpu(sig
)==0xaa55)) {
845 unsigned int i
, rm_offset
;
847 i
= gsc_readl(address
+0x04);
849 /* The ROM could have multiple architecture
850 * dependent images (e.g. i386, parisc,...) */
852 "PCI ROM is not a STI ROM type image (0x%8x)\n", i
);
858 i
= gsc_readl(address
+0x0c);
859 DPRINTK(("PCI ROM size (from header) = %d kB\n",
860 le16_to_cpu(i
>>16)*512/1024));
861 rm_offset
= le16_to_cpu(i
& 0xffff);
863 /* read 16 bytes from the pci region mapper array */
864 rm
= (u32
*) &sti
->rm_entry
;
865 *rm
++ = gsc_readl(address
+rm_offset
+0x00);
866 *rm
++ = gsc_readl(address
+rm_offset
+0x04);
867 *rm
++ = gsc_readl(address
+rm_offset
+0x08);
868 *rm
++ = gsc_readl(address
+rm_offset
+0x0c);
869 DPRINTK(("PCI region Mapper offset = %08x: ",
872 DPRINTK(("%02x ", sti
->rm_entry
[i
]));
876 address
+= le32_to_cpu(gsc_readl(address
+8));
877 DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig
, address
));
883 if ((sig
& 0xff) == 0x01) {
884 DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
886 ok
= sti_read_rom(0, sti
, address
);
889 if ((sig
& 0xffff) == 0x0303) {
890 DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
892 ok
= sti_read_rom(1, sti
, address
);
898 if (sti_init_glob_cfg(sti
, address
, hpa
))
899 goto out_err
; /* not enough memory */
901 /* disable STI PCI ROM. ROM and card RAM overlap and
902 * leaving it enabled would force HPMCs
905 unsigned long rom_base
;
906 rom_base
= pci_resource_start(sti
->pd
, PCI_ROM_RESOURCE
);
907 pci_write_config_dword(sti
->pd
, PCI_ROM_ADDRESS
, rom_base
& ~PCI_ROM_ADDRESS_ENABLE
);
908 DPRINTK((KERN_DEBUG
"STI PCI ROM disabled\n"));
911 if (sti_init_graph(sti
))
915 sti_dump_globcfg(sti
->glob_cfg
, sti
->sti_mem_request
);
916 sti_dump_outptr(sti
);
918 pr_info(" graphics card name: %s\n",
919 sti
->sti_data
->inq_outptr
.dev_name
);
921 sti_roms
[num_sti_roms
] = sti
;
931 static void sticore_check_for_default_sti(struct sti_struct
*sti
, char *path
)
933 if (strcmp (path
, default_sti_path
) == 0)
938 * on newer systems PDC gives the address of the ROM
939 * in the additional address field addr[1] while on
940 * older Systems the PDC stores it in page0->proc_sti
942 static int __init
sticore_pa_init(struct parisc_device
*dev
)
945 struct sti_struct
*sti
= NULL
;
946 int hpa
= dev
->hpa
.start
;
948 if (dev
->num_addrs
&& dev
->addr
[0])
949 sti
= sti_try_rom_generic(dev
->addr
[0], hpa
, NULL
);
951 sti
= sti_try_rom_generic(hpa
, hpa
, NULL
);
953 sti
= sti_try_rom_generic(PAGE0
->proc_sti
, hpa
, NULL
);
957 print_pa_hwpath(dev
, pa_path
);
958 sticore_check_for_default_sti(sti
, pa_path
);
963 static int sticore_pci_init(struct pci_dev
*pd
, const struct pci_device_id
*ent
)
966 unsigned long fb_base
, rom_base
;
967 unsigned int fb_len
, rom_len
;
969 struct sti_struct
*sti
;
971 err
= pci_enable_device(pd
);
973 dev_err(&pd
->dev
, "Cannot enable PCI device\n");
977 fb_base
= pci_resource_start(pd
, 0);
978 fb_len
= pci_resource_len(pd
, 0);
979 rom_base
= pci_resource_start(pd
, PCI_ROM_RESOURCE
);
980 rom_len
= pci_resource_len(pd
, PCI_ROM_RESOURCE
);
982 pci_write_config_dword(pd
, PCI_ROM_ADDRESS
, rom_base
| PCI_ROM_ADDRESS_ENABLE
);
983 DPRINTK((KERN_DEBUG
"STI PCI ROM enabled at 0x%08lx\n", rom_base
));
986 printk(KERN_INFO
"STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
987 rom_base
, rom_len
/1024, fb_base
, fb_len
/1024/1024);
989 DPRINTK((KERN_DEBUG
"Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
992 sti
= sti_try_rom_generic(rom_base
, fb_base
, pd
);
995 print_pci_hwpath(pd
, pa_path
);
996 sticore_check_for_default_sti(sti
, pa_path
);
1000 printk(KERN_WARNING
"Unable to handle STI device '%s'\n",
1004 #endif /* CONFIG_PCI */
1010 static void __exit
sticore_pci_remove(struct pci_dev
*pd
)
1016 static struct pci_device_id sti_pci_tbl
[] = {
1017 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_EG
) },
1018 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX6
) },
1019 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX4
) },
1020 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FX2
) },
1021 { PCI_DEVICE(PCI_VENDOR_ID_HP
, PCI_DEVICE_ID_HP_VISUALIZE_FXE
) },
1022 { 0, } /* terminate list */
1024 MODULE_DEVICE_TABLE(pci
, sti_pci_tbl
);
1026 static struct pci_driver pci_sti_driver
= {
1028 .id_table
= sti_pci_tbl
,
1029 .probe
= sticore_pci_init
,
1030 .remove
= __exit_p(sticore_pci_remove
),
1033 static struct parisc_device_id sti_pa_tbl
[] = {
1034 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00077 },
1035 { HPHW_FIO
, HVERSION_REV_ANY_ID
, HVERSION_ANY_ID
, 0x00085 },
1038 MODULE_DEVICE_TABLE(parisc
, sti_pa_tbl
);
1040 static struct parisc_driver pa_sti_driver __refdata
= {
1042 .id_table
= sti_pa_tbl
,
1043 .probe
= sticore_pa_init
,
1048 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1051 static int sticore_initialized __read_mostly
;
1053 static void sti_init_roms(void)
1055 if (sticore_initialized
)
1058 sticore_initialized
= 1;
1060 printk(KERN_INFO
"STI GSC/PCI core graphics driver "
1061 STI_DRIVERVERSION
"\n");
1063 /* Register drivers for native & PCI cards */
1064 register_parisc_driver(&pa_sti_driver
);
1065 WARN_ON(pci_register_driver(&pci_sti_driver
));
1067 /* if we didn't find the given default sti, take the first one */
1069 default_sti
= sti_roms
[0];
1074 * index = 0 gives default sti
1075 * index > 0 gives other stis in detection order
1077 struct sti_struct
* sti_get_rom(unsigned int index
)
1079 if (!sticore_initialized
)
1085 if (index
> num_sti_roms
)
1088 return sti_roms
[index
-1];
1090 EXPORT_SYMBOL(sti_get_rom
);
1093 int sti_call(const struct sti_struct
*sti
, unsigned long func
,
1094 const void *flags
, void *inptr
, void *outptr
,
1095 struct sti_glob_cfg
*glob_cfg
)
1097 unsigned long _flags
= STI_PTR(flags
);
1098 unsigned long _inptr
= STI_PTR(inptr
);
1099 unsigned long _outptr
= STI_PTR(outptr
);
1100 unsigned long _glob_cfg
= STI_PTR(glob_cfg
);
1104 /* Check for overflow when using 32bit STI on 64bit kernel. */
1105 if (WARN_ONCE(_flags
>>32 || _inptr
>>32 || _outptr
>>32 || _glob_cfg
>>32,
1106 "Out of 32bit-range pointers!"))
1110 ret
= pdc_sti_call(func
, _flags
, _inptr
, _outptr
, _glob_cfg
);
1115 MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1116 MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1117 MODULE_LICENSE("GPL v2");