Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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