sticore.c 26 KB

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