sticore.c 28 KB

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