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