16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/slab.h>
21 #include <linux/pci.h>
28 #include <asm/cacheflush.h>
31 #include "../sticore.h"
33 #define STI_DRIVERVERSION "Version 0.9a"
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)
74 static int sti_init_graph(
struct sti_struct *sti)
90 spin_unlock_irqrestore(&sti->
lock, flags);
105 static void sti_inq_conf(
struct sti_struct *sti)
117 spin_unlock_irqrestore(&sti->
lock, flags);
132 .fg_color =
c_fg(sti, c),
133 .bg_color =
c_bg(sti, c),
145 spin_unlock_irqrestore(&sti->
lock, flags);
177 spin_unlock_irqrestore(&sti->
lock, flags);
187 .bg_color =
c_bg(sti, c),
203 spin_unlock_irqrestore(&sti->
lock, flags);
231 spin_unlock_irqrestore(&sti->
lock, flags);
236 static void sti_flush(
unsigned long start,
unsigned long end)
241 static void __devinit sti_rom_copy(
unsigned long base,
unsigned long count,
244 unsigned long dest_start = (
unsigned long) dest;
249 *(
u32 *)dest = gsc_readl(base);
255 *(
u8 *)dest = gsc_readb(base);
260 sti_flush(dest_start, (
unsigned long)dest);
272 strlcpy (default_sti_path, str,
sizeof (default_sti_path));
293 static int __devinit sti_font_setup(
char *str)
302 if (*str>=
'0' && *str<=
'9') {
313 if ((x =
strchr(str,
',')))
341 __setup(
"sti_font=", sti_font_setup);
347 sti_dump_globcfg(
struct sti_glob_cfg *glob_cfg,
unsigned int sti_mem_request)
353 "%4d x %4d screen resolution\n"
354 "%4d x %4d offscreen\n"
356 "regions at %08x %08x %08x %08x\n"
357 "regions at %08x %08x %08x %08x\n"
375 "in friendly mode: %d\n"
376 "power consumption %d watts\n"
378 "sti_mem_addr %08x (size=%d bytes)\n",
390 "%d bits per pixel\n"
394 sti->
outptr.bits_per_pixel,
402 unsigned long rom_address,
unsigned long hpa)
408 const int save_addr_size = 1024;
415 glob_cfg_ext = kzalloc(
sizeof(*glob_cfg_ext),
GFP_KERNEL);
416 save_addr = kzalloc(save_addr_size,
GFP_KERNEL);
419 if (!(glob_cfg && glob_cfg_ext && save_addr && sti_mem_addr)) {
429 for (i=0; i<8; i++) {
430 unsigned long newhpa,
len;
441 "STI pci region mapping for region %d (%02x) can't be mapped\n",
447 newhpa = (i == 0) ? rom_address : hpa;
456 DPRINTK((
"region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
457 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
470 if (++i<8 && sti->regions[i].
region)
483 *sti_select_fbfont(
struct sti_cooked_rom *cooked_rom,
const char *fbfont_name)
486 unsigned int size, bpc;
491 if (!fbfont_name || !
strlen(fbfont_name))
524 cooked_font = kzalloc(
sizeof(*cooked_font),
GFP_KERNEL);
530 cooked_font->
raw = nf;
539 *sti_select_fbfont(
struct sti_cooked_rom *cooked_rom,
const char *fbfont_name)
551 int index = num_sti_roms;
554 if ((font = sti_select_fbfont(rom, font_name[index])))
557 if (font_width[index] && font_height[index])
558 font_index[
index] = search_font_fnc(rom,
559 font_height[index], font_width[index]);
561 for (font = rom->
font_start, i = font_index[index];
573 sti_dump_rom(
struct sti_rom *rom)
579 rom->
revno[0] & 0x0f);
597 cooked_font = kzalloc(
sizeof(*cooked_font),
GFP_KERNEL);
603 raw_font = ((
void *)raw_rom) + (raw_rom->
font_start);
605 font_start = raw_font;
606 cooked_font->
raw = raw_font;
609 raw_font = ((
void *)font_start) + (raw_font->
next_font);
617 cooked_font->
raw = raw_font;
632 if ((font->
raw->width == width) &&
633 (font->
raw->height == height))
639 #define BMODE_RELOCATE(offset) offset = (offset) / 4;
640 #define BMODE_LAST_ADDR_OFFS 0x50
645 unsigned char *
n, *
p, *
q;
652 q = (
unsigned char *)f->
raw;
661 sti_bmode_rom_copy(
unsigned long base,
unsigned long count,
void *dest)
663 unsigned long dest_start = (
unsigned long) dest;
667 *(
u8 *)dest = gsc_readl(base);
672 sti_flush(dest_start, (
unsigned long)dest);
676 sti_get_bmode_rom (
unsigned long address)
687 sti_bmode_rom_copy(address, size, raw);
701 font_start = raw_font;
705 raw_font = ((
void *)font_start) + raw_font->
next_font;
721 sti_rom_copy(address, size, raw);
727 unsigned long address)
738 raw = sti_get_wmode_rom (address);
740 raw = sti_get_bmode_rom (address);
745 if (!sti_cook_fonts(cooked, raw)) {
763 sti->
font = sti_select_font(sti->
rom, sti_search_font);
767 sti->
font->raw = sti_bmode_font_raw(sti->
font);
784 if (revno == 0x8408 || revno == 0x840b)
785 goto msg_not_supported;
789 goto msg_not_supported;
793 goto msg_not_supported;
799 printk(
KERN_ERR "Sorry, this GSC/STI card is not yet supported.\n");
801 "graphics-howto.html for more info.\n");
810 sti_try_rom_generic(
unsigned long address,
unsigned long hpa,
struct pci_dev *
pd)
835 sig = gsc_readl(address);
839 unsigned int i, rm_offset;
841 i = gsc_readl(address+0x04);
846 "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
852 i = gsc_readl(address+0x0c);
853 DPRINTK((
"PCI ROM size (from header) = %d kB\n",
859 *rm++ = gsc_readl(address+rm_offset+0x00);
860 *rm++ = gsc_readl(address+rm_offset+0x04);
861 *rm++ = gsc_readl(address+rm_offset+0x08);
862 *rm++ = gsc_readl(address+rm_offset+0x0c);
863 DPRINTK((
"PCI region Mapper offset = %08x: ",
871 DPRINTK((
"sig %04x, PCI STI ROM at %08lx\n", sig, address));
877 if ((sig & 0xff) == 0x01) {
878 DPRINTK((
" byte mode ROM at %08lx, hpa at %08lx\n",
880 ok = sti_read_rom(0, sti, address);
883 if ((sig & 0xffff) == 0x0303) {
884 DPRINTK((
" word mode ROM at %08lx, hpa at %08lx\n",
886 ok = sti_read_rom(1, sti, address);
892 if (sti_init_glob_cfg(sti, address, hpa))
899 unsigned long rom_base;
905 if (sti_init_graph(sti))
910 sti_dump_outptr(sti);
914 sti_roms[num_sti_roms] = sti;
926 if (
strcmp (path, default_sti_path) == 0)
939 int hpa = dev->
hpa.start;
942 sti = sti_try_rom_generic(dev->
addr[0], hpa,
NULL);
944 sti = sti_try_rom_generic(hpa, hpa,
NULL);
946 sti = sti_try_rom_generic(
PAGE0->proc_sti, hpa,
NULL);
951 sticore_check_for_default_sti(sti, pa_path);
960 unsigned long fb_base, rom_base;
961 unsigned int fb_len, rom_len;
967 dev_err(&pd->
dev,
"Cannot enable PCI device\n");
980 printk(
KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
981 rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
986 sti = sti_try_rom_generic(rom_base, fb_base, pd);
990 sticore_check_for_default_sti(sti, pa_path);
1022 .id_table = sti_pci_tbl,
1023 .probe = sticore_pci_init,
1024 .remove = sticore_pci_remove,
1035 .id_table = sti_pa_tbl,
1036 .probe = sticore_pa_init,
1046 static void __devinit sti_init_roms(
void)
1048 if (sticore_initialized)
1051 sticore_initialized = 1;
1058 WARN_ON(pci_register_driver(&pci_sti_driver));
1062 default_sti = sti_roms[0];
1072 if (!sticore_initialized)
1078 if (index > num_sti_roms)
1081 return sti_roms[index-1];
1085 MODULE_AUTHOR(
"Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1086 MODULE_DESCRIPTION(
"Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");