sticore.c 26 KB

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