sticore.c 25 KB

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