sticore.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:25k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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