sticore.c 26 KB

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