sticore.c 26 KB

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