sticore.c 26 KB

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