sticore.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  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 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 = kzalloc(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. printk(KERN_ERR "Not enough memory !\n");
  686. return NULL;
  687. }
  688. spin_lock_init(&sti->lock);
  689. test_rom:
  690. /* if we can't read the ROM, bail out early. Not being able
  691. * to read the hpa is okay, for romless sti */
  692. if (pdc_add_valid(address))
  693. goto out_err;
  694. sig = gsc_readl(address);
  695. /* check for a PCI ROM structure */
  696. if ((le32_to_cpu(sig)==0xaa55)) {
  697. unsigned int i, rm_offset;
  698. u32 *rm;
  699. i = gsc_readl(address+0x04);
  700. if (i != 1) {
  701. /* The ROM could have multiple architecture
  702. * dependent images (e.g. i386, parisc,...) */
  703. printk(KERN_WARNING
  704. "PCI ROM is not a STI ROM type image (0x%8x)\n", i);
  705. goto out_err;
  706. }
  707. sti->pd = pd;
  708. i = gsc_readl(address+0x0c);
  709. DPRINTK(("PCI ROM size (from header) = %d kB\n",
  710. le16_to_cpu(i>>16)*512/1024));
  711. rm_offset = le16_to_cpu(i & 0xffff);
  712. if (rm_offset) {
  713. /* read 16 bytes from the pci region mapper array */
  714. rm = (u32*) &sti->rm_entry;
  715. *rm++ = gsc_readl(address+rm_offset+0x00);
  716. *rm++ = gsc_readl(address+rm_offset+0x04);
  717. *rm++ = gsc_readl(address+rm_offset+0x08);
  718. *rm++ = gsc_readl(address+rm_offset+0x0c);
  719. DPRINTK(("PCI region Mapper offset = %08x: ",
  720. rm_offset));
  721. for (i=0; i<16; i++)
  722. DPRINTK(("%02x ", sti->rm_entry[i]));
  723. DPRINTK(("\n"));
  724. }
  725. address += le32_to_cpu(gsc_readl(address+8));
  726. DPRINTK(("sig %04x, PCI STI ROM at %08lx\n", sig, address));
  727. goto test_rom;
  728. }
  729. ok = 0;
  730. if ((sig & 0xff) == 0x01) {
  731. DPRINTK((" byte mode ROM at %08lx, hpa at %08lx\n",
  732. address, hpa));
  733. ok = sti_read_rom(0, sti, address);
  734. }
  735. if ((sig & 0xffff) == 0x0303) {
  736. DPRINTK((" word mode ROM at %08lx, hpa at %08lx\n",
  737. address, hpa));
  738. ok = sti_read_rom(1, sti, address);
  739. }
  740. if (!ok)
  741. goto out_err;
  742. if (sti_init_glob_cfg(sti, address, hpa))
  743. goto out_err; /* not enough memory */
  744. /* disable STI PCI ROM. ROM and card RAM overlap and
  745. * leaving it enabled would force HPMCs
  746. */
  747. if (sti->pd) {
  748. unsigned long rom_base;
  749. rom_base = pci_resource_start(sti->pd, PCI_ROM_RESOURCE);
  750. pci_write_config_dword(sti->pd, PCI_ROM_ADDRESS, rom_base & ~PCI_ROM_ADDRESS_ENABLE);
  751. DPRINTK((KERN_DEBUG "STI PCI ROM disabled\n"));
  752. }
  753. if (sti_init_graph(sti))
  754. goto out_err;
  755. sti_inq_conf(sti);
  756. sti_dump_globcfg(sti->glob_cfg, sti->sti_mem_request);
  757. sti_dump_outptr(sti);
  758. pr_info(" graphics card name: %s\n",
  759. sti->sti_data->inq_outptr.dev_name);
  760. sti_roms[num_sti_roms] = sti;
  761. num_sti_roms++;
  762. return sti;
  763. out_err:
  764. kfree(sti);
  765. return NULL;
  766. }
  767. static void sticore_check_for_default_sti(struct sti_struct *sti, char *path)
  768. {
  769. if (strcmp (path, default_sti_path) == 0)
  770. default_sti = sti;
  771. }
  772. /*
  773. * on newer systems PDC gives the address of the ROM
  774. * in the additional address field addr[1] while on
  775. * older Systems the PDC stores it in page0->proc_sti
  776. */
  777. static int sticore_pa_init(struct parisc_device *dev)
  778. {
  779. char pa_path[21];
  780. struct sti_struct *sti = NULL;
  781. int hpa = dev->hpa.start;
  782. if (dev->num_addrs && dev->addr[0])
  783. sti = sti_try_rom_generic(dev->addr[0], hpa, NULL);
  784. if (!sti)
  785. sti = sti_try_rom_generic(hpa, hpa, NULL);
  786. if (!sti)
  787. sti = sti_try_rom_generic(PAGE0->proc_sti, hpa, NULL);
  788. if (!sti)
  789. return 1;
  790. print_pa_hwpath(dev, pa_path);
  791. sticore_check_for_default_sti(sti, pa_path);
  792. return 0;
  793. }
  794. static int sticore_pci_init(struct pci_dev *pd, const struct pci_device_id *ent)
  795. {
  796. #ifdef CONFIG_PCI
  797. unsigned long fb_base, rom_base;
  798. unsigned int fb_len, rom_len;
  799. int err;
  800. struct sti_struct *sti;
  801. err = pci_enable_device(pd);
  802. if (err < 0) {
  803. dev_err(&pd->dev, "Cannot enable PCI device\n");
  804. return err;
  805. }
  806. fb_base = pci_resource_start(pd, 0);
  807. fb_len = pci_resource_len(pd, 0);
  808. rom_base = pci_resource_start(pd, PCI_ROM_RESOURCE);
  809. rom_len = pci_resource_len(pd, PCI_ROM_RESOURCE);
  810. if (rom_base) {
  811. pci_write_config_dword(pd, PCI_ROM_ADDRESS, rom_base | PCI_ROM_ADDRESS_ENABLE);
  812. DPRINTK((KERN_DEBUG "STI PCI ROM enabled at 0x%08lx\n", rom_base));
  813. }
  814. printk(KERN_INFO "STI PCI graphic ROM found at %08lx (%u kB), fb at %08lx (%u MB)\n",
  815. rom_base, rom_len/1024, fb_base, fb_len/1024/1024);
  816. DPRINTK((KERN_DEBUG "Trying PCI STI ROM at %08lx, PCI hpa at %08lx\n",
  817. rom_base, fb_base));
  818. sti = sti_try_rom_generic(rom_base, fb_base, pd);
  819. if (sti) {
  820. char pa_path[30];
  821. print_pci_hwpath(pd, pa_path);
  822. sticore_check_for_default_sti(sti, pa_path);
  823. }
  824. if (!sti) {
  825. printk(KERN_WARNING "Unable to handle STI device '%s'\n",
  826. pci_name(pd));
  827. return -ENODEV;
  828. }
  829. #endif /* CONFIG_PCI */
  830. return 0;
  831. }
  832. static void sticore_pci_remove(struct pci_dev *pd)
  833. {
  834. BUG();
  835. }
  836. static struct pci_device_id sti_pci_tbl[] = {
  837. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_EG) },
  838. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX6) },
  839. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX4) },
  840. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FX2) },
  841. { PCI_DEVICE(PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_VISUALIZE_FXE) },
  842. { 0, } /* terminate list */
  843. };
  844. MODULE_DEVICE_TABLE(pci, sti_pci_tbl);
  845. static struct pci_driver pci_sti_driver = {
  846. .name = "sti",
  847. .id_table = sti_pci_tbl,
  848. .probe = sticore_pci_init,
  849. .remove = sticore_pci_remove,
  850. };
  851. static struct parisc_device_id sti_pa_tbl[] = {
  852. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00077 },
  853. { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00085 },
  854. { 0, }
  855. };
  856. static struct parisc_driver pa_sti_driver = {
  857. .name = "sti",
  858. .id_table = sti_pa_tbl,
  859. .probe = sticore_pa_init,
  860. };
  861. /*
  862. * sti_init_roms() - detects all STI ROMs and stores them in sti_roms[]
  863. */
  864. static int sticore_initialized __read_mostly;
  865. static void sti_init_roms(void)
  866. {
  867. if (sticore_initialized)
  868. return;
  869. sticore_initialized = 1;
  870. printk(KERN_INFO "STI GSC/PCI core graphics driver "
  871. STI_DRIVERVERSION "\n");
  872. /* Register drivers for native & PCI cards */
  873. register_parisc_driver(&pa_sti_driver);
  874. WARN_ON(pci_register_driver(&pci_sti_driver));
  875. /* if we didn't find the given default sti, take the first one */
  876. if (!default_sti)
  877. default_sti = sti_roms[0];
  878. }
  879. /*
  880. * index = 0 gives default sti
  881. * index > 0 gives other stis in detection order
  882. */
  883. struct sti_struct * sti_get_rom(unsigned int index)
  884. {
  885. if (!sticore_initialized)
  886. sti_init_roms();
  887. if (index == 0)
  888. return default_sti;
  889. if (index > num_sti_roms)
  890. return NULL;
  891. return sti_roms[index-1];
  892. }
  893. EXPORT_SYMBOL(sti_get_rom);
  894. int sti_call(const struct sti_struct *sti, unsigned long func,
  895. const void *flags, void *inptr, void *outptr,
  896. struct sti_glob_cfg *glob_cfg)
  897. {
  898. unsigned long _flags = STI_PTR(flags);
  899. unsigned long _inptr = STI_PTR(inptr);
  900. unsigned long _outptr = STI_PTR(outptr);
  901. unsigned long _glob_cfg = STI_PTR(glob_cfg);
  902. int ret;
  903. #ifdef CONFIG_64BIT
  904. /* Check for overflow when using 32bit STI on 64bit kernel. */
  905. if (WARN_ONCE(_flags>>32 || _inptr>>32 || _outptr>>32 || _glob_cfg>>32,
  906. "Out of 32bit-range pointers!"))
  907. return -1;
  908. #endif
  909. ret = pdc_sti_call(func, _flags, _inptr, _outptr, _glob_cfg);
  910. return ret;
  911. }
  912. MODULE_AUTHOR("Philipp Rumpf, Helge Deller, Thomas Bogendoerfer");
  913. MODULE_DESCRIPTION("Core STI driver for HP's NGLE series graphics cards in HP PARISC machines");
  914. MODULE_LICENSE("GPL v2");