sticore.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  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 1;
  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 1;
  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((unsigned long)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. len = sti->regions[i].region_desc.length * 4096;
  389. if (len)
  390. glob_cfg->region_ptrs[i] = sti->regions_phys[i];
  391. DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
  392. "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
  393. i, sti->regions_phys[i], glob_cfg->region_ptrs[i],
  394. len/1024,
  395. sti->regions[i].region_desc.btlb,
  396. sti->regions[i].region_desc.sys_only,
  397. sti->regions[i].region_desc.cache,
  398. sti->regions[i].region_desc.last));
  399. /* last entry reached ? */
  400. if (sti->regions[i].region_desc.last)
  401. break;
  402. }
  403. if (++i<8 && sti->regions[i].region)
  404. printk(KERN_WARNING "%s: *future ptr (0x%8x) not yet supported !\n",
  405. __FILE__, sti->regions[i].region);
  406. glob_cfg_ext->sti_mem_addr = STI_PTR(sti_mem_addr);
  407. sti->glob_cfg = glob_cfg;
  408. return 0;
  409. }
  410. #ifdef CONFIG_FB
  411. struct sti_cooked_font * __init
  412. sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
  413. {
  414. const struct font_desc *fbfont;
  415. unsigned int size, bpc;
  416. void *dest;
  417. struct sti_rom_font *nf;
  418. struct sti_cooked_font *cooked_font;
  419. if (!fbfont_name || !strlen(fbfont_name))
  420. return NULL;
  421. fbfont = find_font(fbfont_name);
  422. if (!fbfont)
  423. fbfont = get_default_font(1024,768);
  424. if (!fbfont)
  425. return NULL;
  426. DPRINTK((KERN_DEBUG "selected %dx%d fb-font %s\n",
  427. fbfont->width, fbfont->height, fbfont->name));
  428. bpc = ((fbfont->width+7)/8) * fbfont->height;
  429. size = bpc * 256;
  430. size += sizeof(struct sti_rom_font);
  431. nf = kzalloc(size, GFP_KERNEL);
  432. if (!nf)
  433. return NULL;
  434. nf->first_char = 0;
  435. nf->last_char = 255;
  436. nf->width = fbfont->width;
  437. nf->height = fbfont->height;
  438. nf->font_type = STI_FONT_HPROMAN8;
  439. nf->bytes_per_char = bpc;
  440. nf->next_font = 0;
  441. nf->underline_height = 1;
  442. nf->underline_pos = fbfont->height - nf->underline_height;
  443. dest = nf;
  444. dest += sizeof(struct sti_rom_font);
  445. memcpy(dest, fbfont->data, bpc*256);
  446. cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
  447. if (!cooked_font) {
  448. kfree(nf);
  449. return NULL;
  450. }
  451. cooked_font->raw = nf;
  452. cooked_font->next_font = NULL;
  453. cooked_rom->font_start = cooked_font;
  454. return cooked_font;
  455. }
  456. #else
  457. struct sti_cooked_font * __init
  458. sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
  459. {
  460. return NULL;
  461. }
  462. #endif
  463. struct sti_cooked_font * __init
  464. sti_select_font(struct sti_cooked_rom *rom,
  465. int (*search_font_fnc) (struct sti_cooked_rom *,int,int) )
  466. {
  467. struct sti_cooked_font *font;
  468. int i;
  469. int index = num_sti_roms;
  470. /* check for framebuffer-font first */
  471. if ((font = sti_select_fbfont(rom, font_name[index])))
  472. return font;
  473. if (font_width[index] && font_height[index])
  474. font_index[index] = search_font_fnc(rom,
  475. font_height[index], font_width[index]);
  476. for (font = rom->font_start, i = font_index[index];
  477. font && (i > 0);
  478. font = font->next_font, i--);
  479. if (font)
  480. return font;
  481. else
  482. return rom->font_start;
  483. }
  484. static void __init
  485. sti_dump_rom(struct sti_rom *rom)
  486. {
  487. printk(KERN_INFO " id %04x-%04x, conforms to spec rev. %d.%02x\n",
  488. rom->graphics_id[0],
  489. rom->graphics_id[1],
  490. rom->revno[0] >> 4,
  491. rom->revno[0] & 0x0f);
  492. DPRINTK((" supports %d monitors\n", rom->num_mons));
  493. DPRINTK((" font start %08x\n", rom->font_start));
  494. DPRINTK((" region list %08x\n", rom->region_list));
  495. DPRINTK((" init_graph %08x\n", rom->init_graph));
  496. DPRINTK((" bus support %02x\n", rom->bus_support));
  497. DPRINTK((" ext bus support %02x\n", rom->ext_bus_support));
  498. DPRINTK((" alternate code type %d\n", rom->alt_code_type));
  499. }
  500. static int __init
  501. sti_cook_fonts(struct sti_cooked_rom *cooked_rom,
  502. struct sti_rom *raw_rom)
  503. {
  504. struct sti_rom_font *raw_font, *font_start;
  505. struct sti_cooked_font *cooked_font;
  506. cooked_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
  507. if (!cooked_font)
  508. return 0;
  509. cooked_rom->font_start = cooked_font;
  510. raw_font = ((void *)raw_rom) + (raw_rom->font_start);
  511. font_start = raw_font;
  512. cooked_font->raw = raw_font;
  513. while (raw_font->next_font) {
  514. raw_font = ((void *)font_start) + (raw_font->next_font);
  515. cooked_font->next_font = kzalloc(sizeof(*cooked_font), GFP_KERNEL);
  516. if (!cooked_font->next_font)
  517. return 1;
  518. cooked_font = cooked_font->next_font;
  519. cooked_font->raw = raw_font;
  520. }
  521. cooked_font->next_font = NULL;
  522. return 1;
  523. }
  524. static int __init
  525. sti_search_font(struct sti_cooked_rom *rom, int height, int width)
  526. {
  527. struct sti_cooked_font *font;
  528. int i = 0;
  529. for (font = rom->font_start; font; font = font->next_font, i++) {
  530. if ((font->raw->width == width) &&
  531. (font->raw->height == height))
  532. return i;
  533. }
  534. return 0;
  535. }
  536. #define BMODE_RELOCATE(offset) offset = (offset) / 4;
  537. #define BMODE_LAST_ADDR_OFFS 0x50
  538. static void * __init
  539. sti_bmode_font_raw(struct sti_cooked_font *f)
  540. {
  541. unsigned char *n, *p, *q;
  542. int size = f->raw->bytes_per_char*256+sizeof(struct sti_rom_font);
  543. n = kzalloc (4*size, GFP_KERNEL);
  544. if (!n)
  545. return NULL;
  546. p = n + 3;
  547. q = (unsigned char *)f->raw;
  548. while (size--) {
  549. *p = *q++;
  550. p+=4;
  551. }
  552. return n + 3;
  553. }
  554. static void __init
  555. sti_bmode_rom_copy(unsigned long base, unsigned long count, void *dest)
  556. {
  557. unsigned long dest_len = count;
  558. unsigned long dest_start = (unsigned long) dest;
  559. while (count) {
  560. count--;
  561. *(u8 *)dest = gsc_readl(base);
  562. base += 4;
  563. dest++;
  564. }
  565. sti_flush(dest_start, dest_len);
  566. }
  567. static struct sti_rom * __init
  568. sti_get_bmode_rom (unsigned long address)
  569. {
  570. struct sti_rom *raw;
  571. u32 size;
  572. struct sti_rom_font *raw_font, *font_start;
  573. sti_bmode_rom_copy(address + BMODE_LAST_ADDR_OFFS, sizeof(size), &size);
  574. size = (size+3) / 4;
  575. raw = kmalloc(size, GFP_KERNEL);
  576. if (raw) {
  577. sti_bmode_rom_copy(address, size, raw);
  578. memmove (&raw->res004, &raw->type[0], 0x3c);
  579. raw->type[3] = raw->res004;
  580. BMODE_RELOCATE (raw->region_list);
  581. BMODE_RELOCATE (raw->font_start);
  582. BMODE_RELOCATE (raw->init_graph);
  583. BMODE_RELOCATE (raw->state_mgmt);
  584. BMODE_RELOCATE (raw->font_unpmv);
  585. BMODE_RELOCATE (raw->block_move);
  586. BMODE_RELOCATE (raw->inq_conf);
  587. raw_font = ((void *)raw) + raw->font_start;
  588. font_start = raw_font;
  589. while (raw_font->next_font) {
  590. BMODE_RELOCATE (raw_font->next_font);
  591. raw_font = ((void *)font_start) + raw_font->next_font;
  592. }
  593. }
  594. return raw;
  595. }
  596. struct sti_rom * __init
  597. sti_get_wmode_rom (unsigned long address)
  598. {
  599. struct sti_rom *raw;
  600. unsigned long size;
  601. /* read the ROM size directly from the struct in ROM */
  602. size = gsc_readl(address + offsetof(struct sti_rom,last_addr));
  603. raw = kmalloc(size, GFP_KERNEL);
  604. if (raw)
  605. sti_rom_copy(address, size, raw);
  606. return raw;
  607. }
  608. int __init
  609. sti_read_rom(int wordmode, struct sti_struct *sti, unsigned long address)
  610. {
  611. struct sti_cooked_rom *cooked;
  612. struct sti_rom *raw = NULL;
  613. cooked = kmalloc(sizeof *cooked, GFP_KERNEL);
  614. if (!cooked)
  615. goto out_err;
  616. if (wordmode)
  617. raw = sti_get_wmode_rom (address);
  618. else
  619. raw = sti_get_bmode_rom (address);
  620. if (!raw)
  621. goto out_err;
  622. if (!sti_cook_fonts(cooked, raw)) {
  623. printk(KERN_ERR "No font found for STI at %08lx\n", address);
  624. goto out_err;
  625. }
  626. if (raw->region_list)
  627. memcpy(sti->regions, ((void *)raw)+raw->region_list, sizeof(sti->regions));
  628. address = (unsigned long) STI_PTR(raw);
  629. sti->font_unpmv = address + (raw->font_unpmv & 0x03ffffff);
  630. sti->block_move = address + (raw->block_move & 0x03ffffff);
  631. sti->init_graph = address + (raw->init_graph & 0x03ffffff);
  632. sti->inq_conf = address + (raw->inq_conf & 0x03ffffff);
  633. sti->rom = cooked;
  634. sti->rom->raw = raw;
  635. sti->font = sti_select_font(sti->rom, sti_search_font);
  636. sti->font_width = sti->font->raw->width;
  637. sti->font_height = sti->font->raw->height;
  638. if (!wordmode)
  639. sti->font->raw = sti_bmode_font_raw(sti->font);
  640. sti->sti_mem_request = raw->sti_mem_req;
  641. sti->graphics_id[0] = raw->graphics_id[0];
  642. sti->graphics_id[1] = raw->graphics_id[1];
  643. sti_dump_rom(raw);
  644. return 1;
  645. out_err:
  646. kfree(raw);
  647. kfree(cooked);
  648. return 0;
  649. }
  650. static struct sti_struct * __init
  651. sti_try_rom_generic(unsigned long address, unsigned long hpa, struct pci_dev *pd)
  652. {
  653. struct sti_struct *sti;
  654. int ok;
  655. u32 sig;
  656. if (num_sti_roms >= MAX_STI_ROMS) {
  657. printk(KERN_WARNING "maximum number of STI ROMS reached !\n");
  658. return NULL;
  659. }
  660. sti = kzalloc(sizeof(*sti), GFP_KERNEL);
  661. if (!sti) {
  662. printk(KERN_ERR "Not enough memory !\n");
  663. return NULL;
  664. }
  665. spin_lock_init(&sti->lock);
  666. test_rom:
  667. /* if we can't read the ROM, bail out early. Not being able
  668. * to read the hpa is okay, for romless sti */
  669. if (pdc_add_valid(address))
  670. goto out_err;
  671. sig = gsc_readl(address);
  672. /* check for a PCI ROM structure */
  673. if ((le32_to_cpu(sig)==0xaa55)) {
  674. unsigned int i, rm_offset;
  675. u32 *rm;
  676. i = gsc_readl(address+0x04);
  677. if (i != 1) {
  678. /* The ROM could have multiple architecture
  679. * dependent images (e.g. i386, parisc,...) */
  680. printk(KERN_WARNING
  681. "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
  682. goto out_err;
  683. }
  684. sti->pd = pd;
  685. i = gsc_readl(address+0x0c);
  686. DPRINTK(("PCI ROM size (from header) = %d kB\n",
  687. le16_to_cpu(i>>16)*512/1024));
  688. rm_offset = le16_to_cpu(i & 0xffff);
  689. if (rm_offset) {
  690. /* read 16 bytes from the pci region mapper array */
  691. rm = (u32*) &sti->rm_entry;
  692. *rm++ = gsc_readl(address+rm_offset+0x00);
  693. *rm++ = gsc_readl(address+rm_offset+0x04);
  694. *rm++ = gsc_readl(address+rm_offset+0x08);
  695. *rm++ = gsc_readl(address+rm_offset+0x0c);
  696. DPRINTK(("PCI region Mapper offset = %08x: ",
  697. rm_offset));
  698. for (i=0; i<16; i++)
  699. DPRINTK(("%02x ", sti->rm_entry[i]));
  700. DPRINTK(("\n"));
  701. }
  702. address += le32_to_cpu(gsc_readl(address+8));
  703. DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address));
  704. goto test_rom;
  705. }
  706. ok = 0;
  707. if ((sig & 0xff) == 0x01) {
  708. DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
  709. address, hpa));
  710. ok = sti_read_rom(0, sti, address);
  711. }
  712. if ((sig & 0xffff) == 0x0303) {
  713. DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
  714. address, hpa));
  715. ok = sti_read_rom(1, sti, address);
  716. }
  717. if (!ok)
  718. goto out_err;
  719. if (sti_init_glob_cfg(sti, address, hpa))
  720. goto out_err; /* not enough memory */
  721. /* disable STI PCI ROM. ROM and card RAM overlap and
  722. * leaving it enabled would force HPMCs
  723. */
  724. if (sti->pd) {
  725. unsigned long rom_base;
  726. rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE);
  727. pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE);
  728. DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n"));
  729. }
  730. if (sti_init_graph(sti))
  731. goto out_err;
  732. sti_inq_conf(sti);
  733. sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request);
  734. sti_dump_outptr(sti);
  735. printk(KERN_INFO " graphics card name: %s\n", sti->outptr.dev_name );
  736. sti_roms[num_sti_roms] = sti;
  737. num_sti_roms++;
  738. return sti;
  739. out_err:
  740. kfree(sti);
  741. return NULL;
  742. }
  743. static void __init sticore_check_for_default_sti(struct sti_struct *sti, char *path)
  744. {
  745. if (strcmp (path, default_sti_path) == 0)
  746. default_sti = sti;
  747. }
  748. /*
  749. * on newer systems PDC gives the address of the ROM
  750. * in the additional address field addr[1] while on
  751. * older Systems the PDC stores it in page0->proc_sti
  752. */
  753. static int __init sticore_pa_init(struct parisc_device *dev)
  754. {
  755. char pa_path[21];
  756. struct sti_struct *sti = NULL;
  757. int hpa = dev->hpa.start;
  758. if (dev->num_addrs && dev->addr[0])
  759. sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
  760. if (!sti)
  761. sti = sti_try_rom_generic(hpa, hpa, NULL);
  762. if (!sti)
  763. sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
  764. if (!sti)
  765. return 1;
  766. print_pa_hwpath(dev, pa_path);
  767. sticore_check_for_default_sti(sti, pa_path);
  768. return 0;
  769. }
  770. static int __devinit sticore_pci_init(struct pci_dev *pd,
  771. const struct pci_device_id *ent)
  772. {
  773. #ifdef CONFIG_PCI
  774. unsigned long fb_base, rom_base;
  775. unsigned int fb_len, rom_len;
  776. struct sti_struct *sti;
  777. pci_enable_device(pd);
  778. fb_base = pci_resource_start(pd, 0);
  779. fb_len = pci_resource_len(pd, 0);
  780. rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE);
  781. rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE);
  782. if (rom_base) {
  783. pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE);
  784. DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base));
  785. }
  786. printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
  787. rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
  788. DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
  789. rom_base, fb_base));
  790. sti = sti_try_rom_generic(rom_base, fb_base, pd);
  791. if (sti) {
  792. char pa_path[30];
  793. print_pci_hwpath(pd, pa_path);
  794. sticore_check_for_default_sti(sti, pa_path);
  795. }
  796. if (!sti) {
  797. printk(KERN_WARNING "Unable to handle STI device '%s'\n",
  798. pci_name(pd));
  799. return -ENODEV;
  800. }
  801. #endif /* CONFIG_PCI */
  802. return 0;
  803. }
  804. static void __devexit sticore_pci_remove(struct pci_dev *pd)
  805. {
  806. BUG();
  807. }
  808. static struct pci_device_id sti_pci_tbl[] = {
  809. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) },
  810. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) },
  811. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) },
  812. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) },
  813. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) },
  814. { 0, } /* terminate list */
  815. };
  816. MODULE_DEVICE_TABLE(pci, sti_pci_tbl);
  817. static struct pci_driver pci_sti_driver = {
  818. .name = "sti",
  819. .id_table = sti_pci_tbl,
  820. .probe = sticore_pci_init,
  821. .remove = sticore_pci_remove,
  822. };
  823. static struct parisc_device_id sti_pa_tbl[] = {
  824. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 },
  825. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 },
  826. { 0, }
  827. };
  828. static struct parisc_driver pa_sti_driver = {
  829. .name = "sti",
  830. .id_table = sti_pa_tbl,
  831. .probe = sticore_pa_init,
  832. };
  833. /*
  834. * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
  835. */
  836. static int sticore_initialized __read_mostly;
  837. static void __init sti_init_roms(void)
  838. {
  839. if (sticore_initialized)
  840. return;
  841. sticore_initialized = 1;
  842. printk(KERN_INFO "STI GSC/PCI core graphics driver "
  843. STI_DRIVERVERSION "\n");
  844. /* Register drivers for native & PCI cards */
  845. register_parisc_driver(&pa_sti_driver);
  846. pci_register_driver(&pci_sti_driver);
  847. /* if we didn't find the given default sti, take the first one */
  848. if (!default_sti)
  849. default_sti = sti_roms[0];
  850. }
  851. /*
  852. * index = 0 gives default sti
  853. * index > 0 gives other stis in detection order
  854. */
  855. struct sti_struct * sti_get_rom(unsigned int index)
  856. {
  857. if (!sticore_initialized)
  858. sti_init_roms();
  859. if (index == 0)
  860. return default_sti;
  861. if (index > num_sti_roms)
  862. return NULL;
  863. return sti_roms[index-1];
  864. }
  865. EXPORT_SYMBOL(sti_get_rom);
  866. MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
  867. MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
  868. MODULE_LICENSE("GPL v2");