[PARISC] Fix stifb with IOREMAP and a 64-bit kernel
[deliverable/linux.git] / drivers / video / console / sticore.c
CommitLineData
1da177e4
LT
1/*
2 * linux/drivers/video/console/sticore.c -
3 * core code for console driver using HP's STI firmware
4 *
5 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 2001-2003 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 ;)
13 *
14 */
15
16#include <linux/config.h>
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>
24
25#include <asm/hardware.h>
26#include <asm/parisc-device.h>
27#include <asm/cacheflush.h>
28
29#include "../sticore.h"
30
31#define STI_DRIVERVERSION "Version 0.9a"
32
cb6fc18e 33struct sti_struct *default_sti __read_mostly;
1da177e4 34
cb6fc18e
HD
35/* number of STI ROMS found and their ptrs to each struct */
36static int num_sti_roms __read_mostly;
37static struct sti_struct *sti_roms[MAX_STI_ROMS] __read_mostly;
1da177e4
LT
38
39
40/* The colour indices used by STI are
41 * 0 - Black
42 * 1 - White
43 * 2 - Red
44 * 3 - Yellow/Brown
45 * 4 - Green
46 * 5 - Cyan
47 * 6 - Blue
48 * 7 - Magenta
49 *
50 * So we have the same colours as VGA (basically one bit each for R, G, B),
51 * but have to translate them, anyway. */
52
53static const u8 col_trans[8] = {
54 0, 6, 4, 5,
55 2, 7, 3, 1
56};
57
58#define c_fg(sti, c) col_trans[((c>> 8) & 7)]
59#define c_bg(sti, c) col_trans[((c>>11) & 7)]
60#define c_index(sti, c) ((c) & 0xff)
61
62static const struct sti_init_flags default_init_flags = {
63 .wait = STI_WAIT,
64 .reset = 1,
65 .text = 1,
66 .nontext = 1,
67 .no_chg_bet = 1,
68 .no_chg_bei = 1,
69 .init_cmap_tx = 1,
70};
71
72int
73sti_init_graph(struct sti_struct *sti)
74{
75 struct sti_init_inptr_ext inptr_ext = { 0, };
76 struct sti_init_inptr inptr = {
77 .text_planes = 3, /* # of text planes (max 3 for STI) */
78 .ext_ptr = STI_PTR(&inptr_ext)
79 };
80 struct sti_init_outptr outptr = { 0, };
81 unsigned long flags;
82 int ret;
83
84 spin_lock_irqsave(&sti->lock, flags);
85
86 ret = STI_CALL(sti->init_graph, &default_init_flags, &inptr,
87 &outptr, sti->glob_cfg);
88
89 spin_unlock_irqrestore(&sti->lock, flags);
90
91 if (ret < 0) {
92 printk(KERN_ERR "STI init_graph failed (ret %d, errno %d)\n",ret,outptr.errno);
93 return -1;
94 }
95
96 sti->text_planes = outptr.text_planes;
97 return 0;
98}
99
100static const struct sti_conf_flags default_conf_flags = {
101 .wait = STI_WAIT,
102};
103
104void
105sti_inq_conf(struct sti_struct *sti)
106{
107 struct sti_conf_inptr inptr = { 0, };
108 unsigned long flags;
109 s32 ret;
110
111 sti->outptr.ext_ptr = STI_PTR(&sti->outptr_ext);
112
113 do {
114 spin_lock_irqsave(&sti->lock, flags);
115 ret = STI_CALL(sti->inq_conf, &default_conf_flags,
116 &inptr, &sti->outptr, sti->glob_cfg);
117 spin_unlock_irqrestore(&sti->lock, flags);
118 } while (ret == 1);
119}
120
121static const struct sti_font_flags default_font_flags = {
122 .wait = STI_WAIT,
123 .non_text = 0,
124};
125
126void
127sti_putc(struct sti_struct *sti, int c, int y, int x)
128{
129 struct sti_font_inptr inptr = {
130 .font_start_addr= STI_PTR(sti->font->raw),
131 .index = c_index(sti, c),
132 .fg_color = c_fg(sti, c),
133 .bg_color = c_bg(sti, c),
134 .dest_x = x * sti->font_width,
135 .dest_y = y * sti->font_height,
136 };
137 struct sti_font_outptr outptr = { 0, };
138 s32 ret;
139 unsigned long flags;
140
141 do {
142 spin_lock_irqsave(&sti->lock, flags);
143 ret = STI_CALL(sti->font_unpmv, &default_font_flags,
144 &inptr, &outptr, sti->glob_cfg);
145 spin_unlock_irqrestore(&sti->lock, flags);
146 } while (ret == 1);
147}
148
149static const struct sti_blkmv_flags clear_blkmv_flags = {
150 .wait = STI_WAIT,
151 .color = 1,
152 .clear = 1,
153};
154
155void
156sti_set(struct sti_struct *sti, int src_y, int src_x,
157 int height, int width, u8 color)
158{
159 struct sti_blkmv_inptr inptr = {
160 .fg_color = color,
161 .bg_color = color,
162 .src_x = src_x,
163 .src_y = src_y,
164 .dest_x = src_x,
165 .dest_y = src_y,
166 .width = width,
167 .height = height,
168 };
169 struct sti_blkmv_outptr outptr = { 0, };
170 s32 ret;
171 unsigned long flags;
172
173 do {
174 spin_lock_irqsave(&sti->lock, flags);
175 ret = STI_CALL(sti->block_move, &clear_blkmv_flags,
176 &inptr, &outptr, sti->glob_cfg);
177 spin_unlock_irqrestore(&sti->lock, flags);
178 } while (ret == 1);
179}
180
181void
182sti_clear(struct sti_struct *sti, int src_y, int src_x,
183 int height, int width, int c)
184{
185 struct sti_blkmv_inptr inptr = {
186 .fg_color = c_fg(sti, c),
187 .bg_color = c_bg(sti, c),
188 .src_x = src_x * sti->font_width,
189 .src_y = src_y * sti->font_height,
190 .dest_x = src_x * sti->font_width,
191 .dest_y = src_y * sti->font_height,
192 .width = width * sti->font_width,
193 .height = height* sti->font_height,
194 };
195 struct sti_blkmv_outptr outptr = { 0, };
196 s32 ret;
197 unsigned long flags;
198
199 do {
200 spin_lock_irqsave(&sti->lock, flags);
201 ret = STI_CALL(sti->block_move, &clear_blkmv_flags,
202 &inptr, &outptr, sti->glob_cfg);
203 spin_unlock_irqrestore(&sti->lock, flags);
204 } while (ret == 1);
205}
206
207static const struct sti_blkmv_flags default_blkmv_flags = {
208 .wait = STI_WAIT,
209};
210
211void
212sti_bmove(struct sti_struct *sti, int src_y, int src_x,
213 int dst_y, int dst_x, int height, int width)
214{
215 struct sti_blkmv_inptr inptr = {
216 .src_x = src_x * sti->font_width,
217 .src_y = src_y * sti->font_height,
218 .dest_x = dst_x * sti->font_width,
219 .dest_y = dst_y * sti->font_height,
220 .width = width * sti->font_width,
221 .height = height* sti->font_height,
222 };
223 struct sti_blkmv_outptr outptr = { 0, };
224 s32 ret;
225 unsigned long flags;
226
227 do {
228 spin_lock_irqsave(&sti->lock, flags);
229 ret = STI_CALL(sti->block_move, &default_blkmv_flags,
230 &inptr, &outptr, sti->glob_cfg);
231 spin_unlock_irqrestore(&sti->lock, flags);
232 } while (ret == 1);
233}
234
235
236/* FIXME: Do we have another solution for this ? */
237static void sti_flush(unsigned long from, unsigned long len)
238{
239 flush_data_cache();
240 flush_kernel_dcache_range(from, len);
241 flush_icache_range(from, from+len);
242}
243
244void __init
245sti_rom_copy(unsigned long base, unsigned long count, void *dest)
246{
247 unsigned long dest_len = count;
248 unsigned long dest_start = (unsigned long) dest;
249
250 /* this still needs to be revisited (see arch/parisc/mm/init.c:246) ! */
251 while (count >= 4) {
252 count -= 4;
253 *(u32 *)dest = gsc_readl(base);
254 base += 4;
255 dest += 4;
256 }
257 while (count) {
258 count--;
259 *(u8 *)dest = gsc_readb(base);
260 base++;
261 dest++;
262 }
263
264 sti_flush(dest_start, dest_len);
265}
266
267
268
269
cb6fc18e 270static char default_sti_path[21] __read_mostly;
1da177e4
LT
271
272#ifndef MODULE
273static int __init sti_setup(char *str)
274{
275 if (str)
276 strlcpy (default_sti_path, str, sizeof (default_sti_path));
277
278 return 0;
279}
280
281/* Assuming the machine has multiple STI consoles (=graphic cards) which
282 * all get detected by sticon, the user may define with the linux kernel
283 * parameter sti=<x> which of them will be the initial boot-console.
284 * <x> is a number between 0 and MAX_STI_ROMS, with 0 as the default
285 * STI screen.
286 */
287__setup("sti=", sti_setup);
288#endif
289
290
291
292static char __initdata *font_name[MAX_STI_ROMS] = { "VGA8x16", };
293static int __initdata font_index[MAX_STI_ROMS],
294 font_height[MAX_STI_ROMS],
295 font_width[MAX_STI_ROMS];
296#ifndef MODULE
297static int __init sti_font_setup(char *str)
298{
299 char *x;
300 int i = 0;
301
302 /* we accept sti_font=VGA8x16, sti_font=10x20, sti_font=10*20
303 * or sti_font=7 style command lines. */
304
305 while (i<MAX_STI_ROMS && str && *str) {
306 if (*str>='0' && *str<='9') {
307 if ((x = strchr(str, 'x')) || (x = strchr(str, '*'))) {
308 font_height[i] = simple_strtoul(str, NULL, 0);
309 font_width[i] = simple_strtoul(x+1, NULL, 0);
310 } else {
311 font_index[i] = simple_strtoul(str, NULL, 0);
312 }
313 } else {
314 font_name[i] = str; /* fb font name */
315 }
316
317 if ((x = strchr(str, ',')))
318 *x++ = 0;
319 str = x;
320
321 i++;
322 }
323
324 return 0;
325}
326
327/* The optional linux kernel parameter "sti_font" defines which font
328 * should be used by the sticon driver to draw characters to the screen.
329 * Possible values are:
330 * - sti_font=<fb_fontname>:
331 * <fb_fontname> is the name of one of the linux-kernel built-in
332 * framebuffer font names (e.g. VGA8x16, SUN22x18).
333 * This is only available if the fonts have been statically compiled
334 * in with e.g. the CONFIG_FONT_8x16 or CONFIG_FONT_SUN12x22 options.
335 * - sti_font=<number>
336 * most STI ROMs have built-in HP specific fonts, which can be selected
337 * by giving the desired number to the sticon driver.
338 * NOTE: This number is machine and STI ROM dependend.
339 * - sti_font=<height>x<width> (e.g. sti_font=16x8)
340 * <height> and <width> gives hints to the height and width of the
341 * font which the user wants. The sticon driver will try to use
342 * a font with this height and width, but if no suitable font is
343 * found, sticon will use the default 8x8 font.
344 */
345__setup("sti_font=", sti_font_setup);
346#endif
347
348
349
350static void __init
351sti_dump_globcfg(struct sti_glob_cfg *glob_cfg, unsigned int sti_mem_request)
352{
353 struct sti_glob_cfg_ext *cfg;
354
355 DPRINTK((KERN_INFO
356 "%d text planes\n"
357 "%4d x %4d screen resolution\n"
358 "%4d x %4d offscreen\n"
359 "%4d x %4d layout\n"
360 "regions at %08x %08x %08x %08x\n"
361 "regions at %08x %08x %08x %08x\n"
362 "reent_lvl %d\n"
363 "save_addr %08x\n",
364 glob_cfg->text_planes,
365 glob_cfg->onscreen_x, glob_cfg->onscreen_y,
366 glob_cfg->offscreen_x, glob_cfg->offscreen_y,
367 glob_cfg->total_x, glob_cfg->total_y,
368 glob_cfg->region_ptrs[0], glob_cfg->region_ptrs[1],
369 glob_cfg->region_ptrs[2], glob_cfg->region_ptrs[3],
370 glob_cfg->region_ptrs[4], glob_cfg->region_ptrs[5],
371 glob_cfg->region_ptrs[6], glob_cfg->region_ptrs[7],
372 glob_cfg->reent_lvl,
373 glob_cfg->save_addr));
374
375 /* dump extended cfg */
857600c7 376 cfg = PTR_STI((unsigned long)glob_cfg->ext_ptr);
1da177e4
LT
377 DPRINTK(( KERN_INFO
378 "monitor %d\n"
379 "in friendly mode: %d\n"
380 "power consumption %d watts\n"
381 "freq ref %d\n"
382 "sti_mem_addr %08x (size=%d bytes)\n",
383 cfg->curr_mon,
384 cfg->friendly_boot,
385 cfg->power,
386 cfg->freq_ref,
387 cfg->sti_mem_addr, sti_mem_request));
388}
389
390static void __init
391sti_dump_outptr(struct sti_struct *sti)
392{
393 DPRINTK((KERN_INFO
394 "%d bits per pixel\n"
395 "%d used bits\n"
396 "%d planes\n"
397 "attributes %08x\n",
398 sti->outptr.bits_per_pixel,
399 sti->outptr.bits_used,
400 sti->outptr.planes,
401 sti->outptr.attributes));
402}
403
404static int __init
405sti_init_glob_cfg(struct sti_struct *sti,
406 unsigned long rom_address, unsigned long hpa)
407{
408 struct sti_glob_cfg *glob_cfg;
409 struct sti_glob_cfg_ext *glob_cfg_ext;
410 void *save_addr;
411 void *sti_mem_addr;
412 const int save_addr_size = 1024; /* XXX */
413 int i;
414
415 if (!sti->sti_mem_request)
416 sti->sti_mem_request = 256; /* STI default */
417
cb6fc18e
HD
418 glob_cfg = kzalloc(sizeof(*sti->glob_cfg), GFP_KERNEL);
419 glob_cfg_ext = kzalloc(sizeof(*glob_cfg_ext), GFP_KERNEL);
420 save_addr = kzalloc(save_addr_size, GFP_KERNEL);
421 sti_mem_addr = kzalloc(sti->sti_mem_request, GFP_KERNEL);
1da177e4
LT
422
423 if (!(glob_cfg && glob_cfg_ext && save_addr && sti_mem_addr)) {
424 kfree(glob_cfg);
425 kfree(glob_cfg_ext);
426 kfree(save_addr);
427 kfree(sti_mem_addr);
428 return -ENOMEM;
429 }
430
1da177e4
LT
431 glob_cfg->ext_ptr = STI_PTR(glob_cfg_ext);
432 glob_cfg->save_addr = STI_PTR(save_addr);
433 for (i=0; i<8; i++) {
434 unsigned long newhpa, len;
435
436 if (sti->pd) {
437 unsigned char offs = sti->rm_entry[i];
438
439 if (offs == 0)
440 continue;
441 if (offs != PCI_ROM_ADDRESS &&
442 (offs < PCI_BASE_ADDRESS_0 ||
443 offs > PCI_BASE_ADDRESS_5)) {
444 printk (KERN_WARNING
445 "STI pci region maping for region %d (%02x) can't be mapped\n",
446 i,sti->rm_entry[i]);
447 continue;
448 }
449 newhpa = pci_resource_start (sti->pd, (offs - PCI_BASE_ADDRESS_0) / 4);
450 } else
451 newhpa = (i == 0) ? rom_address : hpa;
452
453 sti->regions_phys[i] =
454 REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa);
455
1da177e4 456 len = sti->regions[i].region_desc.length * 4096;
1da177e4
LT
457 if (len)
458 glob_cfg->region_ptrs[i] = sti->regions_phys[i];
1da177e4 459
857600c7 460 DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
1da177e4
LT
461 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
462 i, sti->regions_phys[i], glob_cfg->region_ptrs[i],
463 len/1024,
464 sti->regions[i].region_desc.btlb,
465 sti->regions[i].region_desc.sys_only,
466 sti->regions[i].region_desc.cache,
467 sti->regions[i].region_desc.last));
468
469 /* last entry reached ? */
470 if (sti->regions[i].region_desc.last)
471 break;
472 }
473
474 if (++i<8 && sti->regions[i].region)
475 printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n",
476 __FILE__, sti->regions[i].region);
477
478 glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr);
479
480 sti->glob_cfg = glob_cfg;
481
482 return 0;
483}
484
485#ifdef CONFIG_FB
486struct sti_cooked_font * __init
cb6fc18e 487sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
1da177e4 488{
cb6fc18e 489 const struct font_desc *fbfont;
1da177e4
LT
490 unsigned int size, bpc;
491 void *dest;
492 struct sti_rom_font *nf;
493 struct sti_cooked_font *cooked_font;
494
495 if (!fbfont_name || !strlen(fbfont_name))
951a0150 496 return NULL;
1da177e4
LT
497 fbfont = find_font(fbfont_name);
498 if (!fbfont)
951a0150 499 fbfont = get_default_font(1024,768);
1da177e4 500 if (!fbfont)
951a0150 501 return NULL;
1da177e4
LT
502
503 DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n",
504 fbfont->width, fbfont->height, fbfont->name));
505
506 bpc = ((fbfont->width+7)/8) * fbfont->height;
507 size = bpc * 256;
508 size += sizeof(struct sti_rom_font);
509
cb6fc18e 510 nf = kzalloc(size, GFP_KERNEL);
1da177e4 511 if (!nf)
951a0150 512 return NULL;
1da177e4
LT
513
514 nf->first_char = 0;
515 nf->last_char = 255;
516 nf->width = fbfont->width;
517 nf->height = fbfont->height;
518 nf->font_type = STI_FONT_HPROMAN8;
519 nf->bytes_per_char = bpc;
520 nf->next_font = 0;
521 nf->underline_height = 1;
522 nf->underline_pos = fbfont->height - nf->underline_height;
523
524 dest = nf;
525 dest += sizeof(struct sti_rom_font);
526 memcpy(dest, fbfont->data, bpc*256);
527
cb6fc18e 528 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
1da177e4 529 if (!cooked_font) {
951a0150
MW
530 kfree(nf);
531 return NULL;
1da177e4
LT
532 }
533
534 cooked_font->raw = nf;
535 cooked_font->next_font = NULL;
536
537 cooked_rom->font_start = cooked_font;
538
539 return cooked_font;
540}
541#else
542struct sti_cooked_font * __init
cb6fc18e 543sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
1da177e4
LT
544{
545 return NULL;
546}
547#endif
548
549struct sti_cooked_font * __init
550sti_select_font(struct sti_cooked_rom *rom,
551 int (*search_font_fnc) (struct sti_cooked_rom *,int,int) )
552{
553 struct sti_cooked_font *font;
554 int i;
555 int index = num_sti_roms;
556
557 /* check for framebuffer-font first */
558 if ((font = sti_select_fbfont(rom, font_name[index])))
559 return font;
560
561 if (font_width[index] && font_height[index])
562 font_index[index] = search_font_fnc(rom,
563 font_height[index], font_width[index]);
564
565 for (font = rom->font_start, i = font_index[index];
566 font && (i > 0);
567 font = font->next_font, i--);
568
569 if (font)
570 return font;
571 else
572 return rom->font_start;
573}
574
575
576static void __init
577sti_dump_rom(struct sti_rom *rom)
578{
951a0150 579 printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n",
1da177e4
LT
580 rom->graphics_id[0],
581 rom->graphics_id[1],
582 rom->revno[0] >> 4,
583 rom->revno[0] & 0x0f);
584 DPRINTK((" supports %d monitors\n", rom->num_mons));
585 DPRINTK((" font start %08x\n", rom->font_start));
586 DPRINTK((" region list %08x\n", rom->region_list));
587 DPRINTK((" init_graph %08x\n", rom->init_graph));
588 DPRINTK((" bus support %02x\n", rom->bus_support));
589 DPRINTK((" ext bus support %02x\n", rom->ext_bus_support));
590 DPRINTK((" alternate code type %d\n", rom->alt_code_type));
591}
592
593
594static int __init
595sti_cook_fonts(struct sti_cooked_rom *cooked_rom,
596 struct sti_rom *raw_rom)
597{
598 struct sti_rom_font *raw_font, *font_start;
599 struct sti_cooked_font *cooked_font;
600
cb6fc18e 601 cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
1da177e4
LT
602 if (!cooked_font)
603 return 0;
604
605 cooked_rom->font_start = cooked_font;
606
607 raw_font = ((void *)raw_rom) + (raw_rom->font_start);
608
609 font_start = raw_font;
610 cooked_font->raw = raw_font;
611
612 while (raw_font->next_font) {
613 raw_font = ((void *)font_start) + (raw_font->next_font);
614
cb6fc18e 615 cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
1da177e4
LT
616 if (!cooked_font->next_font)
617 return 1;
618
619 cooked_font = cooked_font->next_font;
620
621 cooked_font->raw = raw_font;
622 }
623
624 cooked_font->next_font = NULL;
625 return 1;
626}
627
628
629static int __init
630sti_search_font(struct sti_cooked_rom *rom, int height, int width)
631{
632 struct sti_cooked_font *font;
633 int i = 0;
634
951a0150
MW
635 for (font = rom->font_start; font; font = font->next_font, i++) {
636 if ((font->raw->width == width) &&
637 (font->raw->height == height))
1da177e4
LT
638 return i;
639 }
640 return 0;
641}
642
951a0150
MW
643#define BMODE_RELOCATE(offset) offset = (offset) / 4;
644#define BMODE_LAST_ADDR_OFFS 0x50
1da177e4
LT
645
646static void * __init
647sti_bmode_font_raw(struct sti_cooked_font *f)
648{
649 unsigned char *n, *p, *q;
650 int size = f->raw->bytes_per_char*256+sizeof(struct sti_rom_font);
651
cb6fc18e 652 n = kzalloc (4*size, GFP_KERNEL);
1da177e4
LT
653 if (!n)
654 return NULL;
1da177e4
LT
655 p = n + 3;
656 q = (unsigned char *)f->raw;
657 while (size--) {
658 *p = *q++;
659 p+=4;
660 }
661 return n + 3;
662}
663
664static void __init
665sti_bmode_rom_copy(unsigned long base, unsigned long count, void *dest)
666{
667 unsigned long dest_len = count;
668 unsigned long dest_start = (unsigned long) dest;
669
670 while (count) {
671 count--;
672 *(u8 *)dest = gsc_readl(base);
673 base += 4;
674 dest++;
675 }
676 sti_flush(dest_start, dest_len);
677}
678
679static struct sti_rom * __init
680sti_get_bmode_rom (unsigned long address)
681{
682 struct sti_rom *raw;
683 u32 size;
951a0150
MW
684 struct sti_rom_font *raw_font, *font_start;
685
1da177e4 686 sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size);
951a0150
MW
687
688 size = (size+3) / 4;
1da177e4
LT
689 raw = kmalloc(size, GFP_KERNEL);
690 if (raw) {
951a0150
MW
691 sti_bmode_rom_copy(address, size, raw);
692 memmove (&raw->res004, &raw->type[0], 0x3c);
693 raw->type[3] = raw->res004;
1da177e4 694
951a0150
MW
695 BMODE_RELOCATE (raw->region_list);
696 BMODE_RELOCATE (raw->font_start);
1da177e4 697
951a0150
MW
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);
1da177e4 703
951a0150
MW
704 raw_font = ((void *)raw) + raw->font_start;
705 font_start = raw_font;
1da177e4 706
951a0150
MW
707 while (raw_font->next_font) {
708 BMODE_RELOCATE (raw_font->next_font);
709 raw_font = ((void *)font_start) + raw_font->next_font;
710 }
1da177e4 711 }
951a0150 712 return raw;
1da177e4
LT
713}
714
715struct sti_rom * __init
716sti_get_wmode_rom (unsigned long address)
717{
718 struct sti_rom *raw;
719 unsigned long size;
951a0150 720
1da177e4
LT
721 /* read the ROM size directly from the struct in ROM */
722 size = gsc_readl(address + offsetof(struct sti_rom,last_addr));
723
724 raw = kmalloc(size, GFP_KERNEL);
951a0150
MW
725 if (raw)
726 sti_rom_copy(address, size, raw);
1da177e4 727
951a0150 728 return raw;
1da177e4
LT
729}
730
731int __init
732sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address)
733{
734 struct sti_cooked_rom *cooked;
735 struct sti_rom *raw = NULL;
736
737 cooked = kmalloc(sizeof *cooked, GFP_KERNEL);
738 if (!cooked)
739 goto out_err;
740
951a0150
MW
741 if (wordmode)
742 raw = sti_get_wmode_rom (address);
743 else
744 raw = sti_get_bmode_rom (address);
745
746 if (!raw)
747 goto out_err;
1da177e4 748
1da177e4
LT
749 if (!sti_cook_fonts(cooked, raw)) {
750 printk(KERN_ERR "No font found for STI at %08lx\n", address);
751 goto out_err;
752 }
753
754 if (raw->region_list)
755 memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions));
756
757 address = (unsigned long) STI_PTR(raw);
758
759 sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff);
760 sti->block_move = address + (raw->block_move & 0x03ffffff);
761 sti->init_graph = address + (raw->init_graph & 0x03ffffff);
762 sti->inq_conf = address + (raw->inq_conf & 0x03ffffff);
763
764 sti->rom = cooked;
765 sti->rom->raw = raw;
766
767 sti->font = sti_select_font(sti->rom, sti_search_font);
768 sti->font_width = sti->font->raw->width;
769 sti->font_height = sti->font->raw->height;
770 if (!wordmode)
951a0150 771 sti->font->raw = sti_bmode_font_raw(sti->font);
1da177e4
LT
772
773 sti->sti_mem_request = raw->sti_mem_req;
774 sti->graphics_id[0] = raw->graphics_id[0];
775 sti->graphics_id[1] = raw->graphics_id[1];
776
777 sti_dump_rom(raw);
778
779 return 1;
780
781out_err:
782 kfree(raw);
783 kfree(cooked);
784 return 0;
785}
786
787static struct sti_struct * __init
788sti_try_rom_generic(unsigned long address, unsigned long hpa, struct pci_dev *pd)
789{
790 struct sti_struct *sti;
791 int ok;
792 u32 sig;
793
794 if (num_sti_roms >= MAX_STI_ROMS) {
951a0150
MW
795 printk(KERN_WARNING "maximum number of STI ROMS reached !\n");
796 return NULL;
1da177e4
LT
797 }
798
cb6fc18e 799 sti = kzalloc(sizeof(*sti), GFP_KERNEL);
1da177e4 800 if (!sti) {
951a0150
MW
801 printk(KERN_ERR "Not enough memory !\n");
802 return NULL;
1da177e4 803 }
951a0150 804
1da177e4
LT
805 spin_lock_init(&sti->lock);
806
807test_rom:
808 /* if we can't read the ROM, bail out early. Not being able
809 * to read the hpa is okay, for romless sti */
810 if (pdc_add_valid(address))
811 goto out_err;
812
813 sig = gsc_readl(address);
814
815 /* check for a PCI ROM structure */
816 if ((le32_to_cpu(sig)==0xaa55)) {
817 unsigned int i, rm_offset;
818 u32 *rm;
819 i = gsc_readl(address+0x04);
820 if (i != 1) {
821 /* The ROM could have multiple architecture
822 * dependent images (e.g. i386, parisc,...) */
823 printk(KERN_WARNING
824 "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
825 goto out_err;
826 }
827
828 sti->pd = pd;
829
830 i = gsc_readl(address+0x0c);
831 DPRINTK(("PCI ROM size (from header) = %d kB\n",
832 le16_to_cpu(i>>16)*512/1024));
833 rm_offset = le16_to_cpu(i & 0xffff);
834 if (rm_offset) {
835 /* read 16 bytes from the pci region mapper array */
836 rm = (u32*) &sti->rm_entry;
837 *rm++ = gsc_readl(address+rm_offset+0x00);
838 *rm++ = gsc_readl(address+rm_offset+0x04);
839 *rm++ = gsc_readl(address+rm_offset+0x08);
840 *rm++ = gsc_readl(address+rm_offset+0x0c);
841 DPRINTK(("PCI region Mapper offset = %08x: ",
842 rm_offset));
843 for (i=0; i<16; i++)
844 DPRINTK(("%02x ", sti->rm_entry[i]));
845 DPRINTK(("\n"));
846 }
847
848 address += le32_to_cpu(gsc_readl(address+8));
849 DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address));
850 goto test_rom;
851 }
852
853 ok = 0;
854
855 if ((sig & 0xff) == 0x01) {
856 DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
857 address, hpa));
858 ok = sti_read_rom(0, sti, address);
859 }
860
861 if ((sig & 0xffff) == 0x0303) {
862 DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
863 address, hpa));
864 ok = sti_read_rom(1, sti, address);
865 }
866
867 if (!ok)
868 goto out_err;
869
870 if (sti_init_glob_cfg(sti, address, hpa))
871 goto out_err; /* not enough memory */
872
873 /* disable STI PCI ROM. ROM and card RAM overlap and
874 * leaving it enabled would force HPMCs
875 */
876 if (sti->pd) {
877 unsigned long rom_base;
878 rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE);
879 pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE);
880 DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n"));
881 }
882
883 if (sti_init_graph(sti))
884 goto out_err;
885
886 sti_inq_conf(sti);
887 sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request);
888 sti_dump_outptr(sti);
889
890 printk(KERN_INFO " graphics card name: %s\n", sti->outptr.dev_name );
891
892 sti_roms[num_sti_roms] = sti;
893 num_sti_roms++;
894
895 return sti;
896
897out_err:
898 kfree(sti);
899 return NULL;
900}
901
902static void __init sticore_check_for_default_sti(struct sti_struct *sti, char *path)
903{
904 if (strcmp (path, default_sti_path) == 0)
905 default_sti = sti;
906}
907
908/*
909 * on newer systems PDC gives the address of the ROM
910 * in the additional address field addr[1] while on
911 * older Systems the PDC stores it in page0->proc_sti
912 */
913static int __init sticore_pa_init(struct parisc_device *dev)
914{
1da177e4
LT
915 char pa_path[21];
916 struct sti_struct *sti = NULL;
951a0150
MW
917 int hpa = dev->hpa.start;
918
919 if (dev->num_addrs && dev->addr[0])
920 sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
921 if (!sti)
922 sti = sti_try_rom_generic(hpa, hpa, NULL);
923 if (!sti)
924 sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
1da177e4
LT
925 if (!sti)
926 return 1;
951a0150 927
1da177e4 928 print_pa_hwpath(dev, pa_path);
951a0150 929 sticore_check_for_default_sti(sti, pa_path);
1da177e4
LT
930 return 0;
931}
932
933
934static int __devinit sticore_pci_init(struct pci_dev *pd,
935 const struct pci_device_id *ent)
936{
937#ifdef CONFIG_PCI
938 unsigned long fb_base, rom_base;
939 unsigned int fb_len, rom_len;
940 struct sti_struct *sti;
941
942 pci_enable_device(pd);
943
944 fb_base = pci_resource_start(pd, 0);
945 fb_len = pci_resource_len(pd, 0);
946 rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE);
947 rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE);
948 if (rom_base) {
949 pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE);
950 DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base));
951 }
952
953 printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
954 rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
955
956 DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
957 rom_base, fb_base));
958
959 sti = sti_try_rom_generic(rom_base, fb_base, pd);
960 if (sti) {
961 char pa_path[30];
962 print_pci_hwpath(pd, pa_path);
963 sticore_check_for_default_sti(sti, pa_path);
964 }
965
966 if (!sti) {
967 printk(KERN_WARNING "Unable to handle STI device '%s'\n",
968 pci_name(pd));
969 return -ENODEV;
970 }
971#endif /* CONFIG_PCI */
972
973 return 0;
974}
975
976
977static void __devexit sticore_pci_remove(struct pci_dev *pd)
978{
979 BUG();
980}
981
982
983static struct pci_device_id sti_pci_tbl[] = {
984 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) },
985 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) },
986 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) },
987 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) },
988 { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) },
989 { 0, } /* terminate list */
990};
991MODULE_DEVICE_TABLE(pci, sti_pci_tbl);
992
993static struct pci_driver pci_sti_driver = {
994 .name = "sti",
995 .id_table = sti_pci_tbl,
996 .probe = sticore_pci_init,
997 .remove = sticore_pci_remove,
998};
999
1000static struct parisc_device_id sti_pa_tbl[] = {
1001 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 },
1002 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 },
1003 { 0, }
1004};
1005
1006static struct parisc_driver pa_sti_driver = {
1007 .name = "sti",
1008 .id_table = sti_pa_tbl,
1009 .probe = sticore_pa_init,
1010};
1011
1012
1013/*
1014 * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
1015 */
1016
cb6fc18e 1017static int sticore_initialized __read_mostly;
1da177e4
LT
1018
1019static void __init sti_init_roms(void)
1020{
1021 if (sticore_initialized)
1022 return;
1023
1024 sticore_initialized = 1;
1025
1026 printk(KERN_INFO "STI GSC/PCI core graphics driver "
1027 STI_DRIVERVERSION "\n");
1028
1029 /* Register drivers for native & PCI cards */
1030 register_parisc_driver(&pa_sti_driver);
1031 pci_register_driver(&pci_sti_driver);
1032
1033 /* if we didn't find the given default sti, take the first one */
1034 if (!default_sti)
1035 default_sti = sti_roms[0];
1036
1037}
1038
1039/*
1040 * index = 0 gives default sti
1041 * index > 0 gives other stis in detection order
1042 */
1043struct sti_struct * sti_get_rom(unsigned int index)
1044{
1045 if (!sticore_initialized)
1046 sti_init_roms();
1047
1048 if (index == 0)
1049 return default_sti;
1050
1051 if (index > num_sti_roms)
1052 return NULL;
1053
1054 return sti_roms[index-1];
1055}
1056EXPORT_SYMBOL(sti_get_rom);
1057
1058MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
1059MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
1060MODULE_LICENSE("GPL v2");
1061
This page took 0.160979 seconds and 5 git commands to generate.