vgacon.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. /*
  2. * linux/drivers/video/vgacon.c -- Low level VGA based console driver
  3. *
  4. * Created 28 Sep 1997 by Geert Uytterhoeven
  5. *
  6. * Rewritten by Martin Mares <[email protected]>, July 1998
  7. *
  8. * This file is based on the old console.c, vga.c and vesa_blank.c drivers.
  9. *
  10. * Copyright (C) 1991, 1992 Linus Torvalds
  11. * 1995 Jay Estabrook
  12. *
  13. * User definable mapping table and font loading by Eugene G. Crosser,
  14. * <[email protected]>
  15. *
  16. * Improved loadable font/UTF-8 support by H. Peter Anvin
  17. * Feb-Sep 1995 <[email protected]>
  18. *
  19. * Colour palette handling, by Simon Tatham
  20. * 17-Jun-95 <[email protected]>
  21. *
  22. * if 512 char mode is already enabled don't re-enable it,
  23. * because it causes screen to flicker, by Mitja Horvat
  24. * 5-May-96 <[email protected]>
  25. *
  26. * Use 2 outw instead of 4 outb_p to reduce erroneous text
  27. * flashing on RHS of screen during heavy console scrolling .
  28. * Oct 1996, Paul Gortmaker.
  29. *
  30. *
  31. * This file is subject to the terms and conditions of the GNU General Public
  32. * License. See the file COPYING in the main directory of this archive for
  33. * more details.
  34. */
  35. #include <linux/module.h>
  36. #include <linux/types.h>
  37. #include <linux/fs.h>
  38. #include <linux/kernel.h>
  39. #include <linux/console.h>
  40. #include <linux/string.h>
  41. #include <linux/kd.h>
  42. #include <linux/slab.h>
  43. #include <linux/vt_kern.h>
  44. #include <linux/sched.h>
  45. #include <linux/selection.h>
  46. #include <linux/spinlock.h>
  47. #include <linux/ioport.h>
  48. #include <linux/init.h>
  49. #include <linux/screen_info.h>
  50. #include <video/vga.h>
  51. #include <asm/io.h>
  52. static DEFINE_RAW_SPINLOCK(vga_lock);
  53. static int cursor_size_lastfrom;
  54. static int cursor_size_lastto;
  55. static u32 vgacon_xres;
  56. static u32 vgacon_yres;
  57. static struct vgastate vgastate;
  58. #define BLANK 0x0020
  59. #define VGA_FONTWIDTH 8 /* VGA does not support fontwidths != 8 */
  60. /*
  61. * Interface used by the world
  62. */
  63. static const char *vgacon_startup(void);
  64. static void vgacon_init(struct vc_data *c, int init);
  65. static void vgacon_deinit(struct vc_data *c);
  66. static void vgacon_cursor(struct vc_data *c, int mode);
  67. static int vgacon_switch(struct vc_data *c);
  68. static int vgacon_blank(struct vc_data *c, int blank, int mode_switch);
  69. static void vgacon_scrolldelta(struct vc_data *c, int lines);
  70. static int vgacon_set_origin(struct vc_data *c);
  71. static void vgacon_save_screen(struct vc_data *c);
  72. static void vgacon_invert_region(struct vc_data *c, u16 * p, int count);
  73. static struct uni_pagedict *vgacon_uni_pagedir;
  74. static int vgacon_refcount;
  75. /* Description of the hardware situation */
  76. static unsigned long vga_vram_base __read_mostly; /* Base of video memory */
  77. static unsigned long vga_vram_end __read_mostly; /* End of video memory */
  78. static unsigned int vga_vram_size __read_mostly; /* Size of video memory */
  79. static u16 vga_video_port_reg __read_mostly; /* Video register select port */
  80. static u16 vga_video_port_val __read_mostly; /* Video register value port */
  81. static unsigned int vga_video_num_columns; /* Number of text columns */
  82. static unsigned int vga_video_num_lines; /* Number of text lines */
  83. static bool vga_can_do_color; /* Do we support colors? */
  84. static unsigned int vga_default_font_height __read_mostly; /* Height of default screen font */
  85. static unsigned char vga_video_type __read_mostly; /* Card type */
  86. static int vga_vesa_blanked;
  87. static bool vga_palette_blanked;
  88. static bool vga_is_gfx;
  89. static bool vga_512_chars;
  90. static int vga_video_font_height;
  91. static int vga_scan_lines __read_mostly;
  92. static unsigned int vga_rolled_over; /* last vc_origin offset before wrap */
  93. static bool vga_hardscroll_enabled;
  94. static bool vga_hardscroll_user_enable = true;
  95. static int __init no_scroll(char *str)
  96. {
  97. /*
  98. * Disabling scrollback is required for the Braillex ib80-piezo
  99. * Braille reader made by F.H. Papenmeier (Germany).
  100. * Use the "no-scroll" bootflag.
  101. */
  102. vga_hardscroll_user_enable = vga_hardscroll_enabled = false;
  103. return 1;
  104. }
  105. __setup("no-scroll", no_scroll);
  106. /*
  107. * By replacing the four outb_p with two back to back outw, we can reduce
  108. * the window of opportunity to see text mislocated to the RHS of the
  109. * console during heavy scrolling activity. However there is the remote
  110. * possibility that some pre-dinosaur hardware won't like the back to back
  111. * I/O. Since the Xservers get away with it, we should be able to as well.
  112. */
  113. static inline void write_vga(unsigned char reg, unsigned int val)
  114. {
  115. unsigned int v1, v2;
  116. unsigned long flags;
  117. /*
  118. * ddprintk might set the console position from interrupt
  119. * handlers, thus the write has to be IRQ-atomic.
  120. */
  121. raw_spin_lock_irqsave(&vga_lock, flags);
  122. v1 = reg + (val & 0xff00);
  123. v2 = reg + 1 + ((val << 8) & 0xff00);
  124. outw(v1, vga_video_port_reg);
  125. outw(v2, vga_video_port_reg);
  126. raw_spin_unlock_irqrestore(&vga_lock, flags);
  127. }
  128. static inline void vga_set_mem_top(struct vc_data *c)
  129. {
  130. write_vga(12, (c->vc_visible_origin - vga_vram_base) / 2);
  131. }
  132. static void vgacon_restore_screen(struct vc_data *c)
  133. {
  134. if (c->vc_origin != c->vc_visible_origin)
  135. vgacon_scrolldelta(c, 0);
  136. }
  137. static void vgacon_scrolldelta(struct vc_data *c, int lines)
  138. {
  139. vc_scrolldelta_helper(c, lines, vga_rolled_over, (void *)vga_vram_base,
  140. vga_vram_size);
  141. vga_set_mem_top(c);
  142. }
  143. static const char *vgacon_startup(void)
  144. {
  145. const char *display_desc = NULL;
  146. u16 saved1, saved2;
  147. volatile u16 *p;
  148. if (screen_info.orig_video_isVGA == VIDEO_TYPE_VLFB ||
  149. screen_info.orig_video_isVGA == VIDEO_TYPE_EFI) {
  150. no_vga:
  151. #ifdef CONFIG_DUMMY_CONSOLE
  152. conswitchp = &dummy_con;
  153. return conswitchp->con_startup();
  154. #else
  155. return NULL;
  156. #endif
  157. }
  158. /* boot_params.screen_info reasonably initialized? */
  159. if ((screen_info.orig_video_lines == 0) ||
  160. (screen_info.orig_video_cols == 0))
  161. goto no_vga;
  162. /* VGA16 modes are not handled by VGACON */
  163. if ((screen_info.orig_video_mode == 0x0D) || /* 320x200/4 */
  164. (screen_info.orig_video_mode == 0x0E) || /* 640x200/4 */
  165. (screen_info.orig_video_mode == 0x10) || /* 640x350/4 */
  166. (screen_info.orig_video_mode == 0x12) || /* 640x480/4 */
  167. (screen_info.orig_video_mode == 0x6A)) /* 800x600/4 (VESA) */
  168. goto no_vga;
  169. vga_video_num_lines = screen_info.orig_video_lines;
  170. vga_video_num_columns = screen_info.orig_video_cols;
  171. vgastate.vgabase = NULL;
  172. if (screen_info.orig_video_mode == 7) {
  173. /* Monochrome display */
  174. vga_vram_base = 0xb0000;
  175. vga_video_port_reg = VGA_CRT_IM;
  176. vga_video_port_val = VGA_CRT_DM;
  177. if ((screen_info.orig_video_ega_bx & 0xff) != 0x10) {
  178. static struct resource ega_console_resource =
  179. { .name = "ega",
  180. .flags = IORESOURCE_IO,
  181. .start = 0x3B0,
  182. .end = 0x3BF };
  183. vga_video_type = VIDEO_TYPE_EGAM;
  184. vga_vram_size = 0x8000;
  185. display_desc = "EGA+";
  186. request_resource(&ioport_resource,
  187. &ega_console_resource);
  188. } else {
  189. static struct resource mda1_console_resource =
  190. { .name = "mda",
  191. .flags = IORESOURCE_IO,
  192. .start = 0x3B0,
  193. .end = 0x3BB };
  194. static struct resource mda2_console_resource =
  195. { .name = "mda",
  196. .flags = IORESOURCE_IO,
  197. .start = 0x3BF,
  198. .end = 0x3BF };
  199. vga_video_type = VIDEO_TYPE_MDA;
  200. vga_vram_size = 0x2000;
  201. display_desc = "*MDA";
  202. request_resource(&ioport_resource,
  203. &mda1_console_resource);
  204. request_resource(&ioport_resource,
  205. &mda2_console_resource);
  206. vga_video_font_height = 14;
  207. }
  208. } else {
  209. /* If not, it is color. */
  210. vga_can_do_color = true;
  211. vga_vram_base = 0xb8000;
  212. vga_video_port_reg = VGA_CRT_IC;
  213. vga_video_port_val = VGA_CRT_DC;
  214. if ((screen_info.orig_video_ega_bx & 0xff) != 0x10) {
  215. int i;
  216. vga_vram_size = 0x8000;
  217. if (!screen_info.orig_video_isVGA) {
  218. static struct resource ega_console_resource =
  219. { .name = "ega",
  220. .flags = IORESOURCE_IO,
  221. .start = 0x3C0,
  222. .end = 0x3DF };
  223. vga_video_type = VIDEO_TYPE_EGAC;
  224. display_desc = "EGA";
  225. request_resource(&ioport_resource,
  226. &ega_console_resource);
  227. } else {
  228. static struct resource vga_console_resource =
  229. { .name = "vga+",
  230. .flags = IORESOURCE_IO,
  231. .start = 0x3C0,
  232. .end = 0x3DF };
  233. vga_video_type = VIDEO_TYPE_VGAC;
  234. display_desc = "VGA+";
  235. request_resource(&ioport_resource,
  236. &vga_console_resource);
  237. /*
  238. * Normalise the palette registers, to point
  239. * the 16 screen colours to the first 16
  240. * DAC entries.
  241. */
  242. for (i = 0; i < 16; i++) {
  243. inb_p(VGA_IS1_RC);
  244. outb_p(i, VGA_ATT_W);
  245. outb_p(i, VGA_ATT_W);
  246. }
  247. outb_p(0x20, VGA_ATT_W);
  248. /*
  249. * Now set the DAC registers back to their
  250. * default values
  251. */
  252. for (i = 0; i < 16; i++) {
  253. outb_p(color_table[i], VGA_PEL_IW);
  254. outb_p(default_red[i], VGA_PEL_D);
  255. outb_p(default_grn[i], VGA_PEL_D);
  256. outb_p(default_blu[i], VGA_PEL_D);
  257. }
  258. }
  259. } else {
  260. static struct resource cga_console_resource =
  261. { .name = "cga",
  262. .flags = IORESOURCE_IO,
  263. .start = 0x3D4,
  264. .end = 0x3D5 };
  265. vga_video_type = VIDEO_TYPE_CGA;
  266. vga_vram_size = 0x2000;
  267. display_desc = "*CGA";
  268. request_resource(&ioport_resource,
  269. &cga_console_resource);
  270. vga_video_font_height = 8;
  271. }
  272. }
  273. vga_vram_base = VGA_MAP_MEM(vga_vram_base, vga_vram_size);
  274. vga_vram_end = vga_vram_base + vga_vram_size;
  275. /*
  276. * Find out if there is a graphics card present.
  277. * Are there smarter methods around?
  278. */
  279. p = (volatile u16 *) vga_vram_base;
  280. saved1 = scr_readw(p);
  281. saved2 = scr_readw(p + 1);
  282. scr_writew(0xAA55, p);
  283. scr_writew(0x55AA, p + 1);
  284. if (scr_readw(p) != 0xAA55 || scr_readw(p + 1) != 0x55AA) {
  285. scr_writew(saved1, p);
  286. scr_writew(saved2, p + 1);
  287. goto no_vga;
  288. }
  289. scr_writew(0x55AA, p);
  290. scr_writew(0xAA55, p + 1);
  291. if (scr_readw(p) != 0x55AA || scr_readw(p + 1) != 0xAA55) {
  292. scr_writew(saved1, p);
  293. scr_writew(saved2, p + 1);
  294. goto no_vga;
  295. }
  296. scr_writew(saved1, p);
  297. scr_writew(saved2, p + 1);
  298. if (vga_video_type == VIDEO_TYPE_EGAC
  299. || vga_video_type == VIDEO_TYPE_VGAC
  300. || vga_video_type == VIDEO_TYPE_EGAM) {
  301. vga_hardscroll_enabled = vga_hardscroll_user_enable;
  302. vga_default_font_height = screen_info.orig_video_points;
  303. vga_video_font_height = screen_info.orig_video_points;
  304. /* This may be suboptimal but is a safe bet - go with it */
  305. vga_scan_lines =
  306. vga_video_font_height * vga_video_num_lines;
  307. }
  308. vgacon_xres = screen_info.orig_video_cols * VGA_FONTWIDTH;
  309. vgacon_yres = vga_scan_lines;
  310. return display_desc;
  311. }
  312. static void vgacon_init(struct vc_data *c, int init)
  313. {
  314. struct uni_pagedict *p;
  315. /*
  316. * We cannot be loaded as a module, therefore init will be 1
  317. * if we are the default console, however if we are a fallback
  318. * console, for example if fbcon has failed registration, then
  319. * init will be 0, so we need to make sure our boot parameters
  320. * have been copied to the console structure for vgacon_resize
  321. * ultimately called by vc_resize. Any subsequent calls to
  322. * vgacon_init init will have init set to 0 too.
  323. */
  324. c->vc_can_do_color = vga_can_do_color;
  325. c->vc_scan_lines = vga_scan_lines;
  326. c->vc_font.height = c->vc_cell_height = vga_video_font_height;
  327. /* set dimensions manually if init != 0 since vc_resize() will fail */
  328. if (init) {
  329. c->vc_cols = vga_video_num_columns;
  330. c->vc_rows = vga_video_num_lines;
  331. } else
  332. vc_resize(c, vga_video_num_columns, vga_video_num_lines);
  333. c->vc_complement_mask = 0x7700;
  334. if (vga_512_chars)
  335. c->vc_hi_font_mask = 0x0800;
  336. p = *c->uni_pagedict_loc;
  337. if (c->uni_pagedict_loc != &vgacon_uni_pagedir) {
  338. con_free_unimap(c);
  339. c->uni_pagedict_loc = &vgacon_uni_pagedir;
  340. vgacon_refcount++;
  341. }
  342. if (!vgacon_uni_pagedir && p)
  343. con_set_default_unimap(c);
  344. /* Only set the default if the user didn't deliberately override it */
  345. if (global_cursor_default == -1)
  346. global_cursor_default =
  347. !(screen_info.flags & VIDEO_FLAGS_NOCURSOR);
  348. }
  349. static void vgacon_deinit(struct vc_data *c)
  350. {
  351. /* When closing the active console, reset video origin */
  352. if (con_is_visible(c)) {
  353. c->vc_visible_origin = vga_vram_base;
  354. vga_set_mem_top(c);
  355. }
  356. if (!--vgacon_refcount)
  357. con_free_unimap(c);
  358. c->uni_pagedict_loc = &c->uni_pagedict;
  359. con_set_default_unimap(c);
  360. }
  361. static u8 vgacon_build_attr(struct vc_data *c, u8 color,
  362. enum vc_intensity intensity,
  363. bool blink, bool underline, bool reverse,
  364. bool italic)
  365. {
  366. u8 attr = color;
  367. if (vga_can_do_color) {
  368. if (italic)
  369. attr = (attr & 0xF0) | c->vc_itcolor;
  370. else if (underline)
  371. attr = (attr & 0xf0) | c->vc_ulcolor;
  372. else if (intensity == VCI_HALF_BRIGHT)
  373. attr = (attr & 0xf0) | c->vc_halfcolor;
  374. }
  375. if (reverse)
  376. attr =
  377. ((attr) & 0x88) | ((((attr) >> 4) | ((attr) << 4)) &
  378. 0x77);
  379. if (blink)
  380. attr ^= 0x80;
  381. if (intensity == VCI_BOLD)
  382. attr ^= 0x08;
  383. if (!vga_can_do_color) {
  384. if (italic)
  385. attr = (attr & 0xF8) | 0x02;
  386. else if (underline)
  387. attr = (attr & 0xf8) | 0x01;
  388. else if (intensity == VCI_HALF_BRIGHT)
  389. attr = (attr & 0xf0) | 0x08;
  390. }
  391. return attr;
  392. }
  393. static void vgacon_invert_region(struct vc_data *c, u16 * p, int count)
  394. {
  395. const bool col = vga_can_do_color;
  396. while (count--) {
  397. u16 a = scr_readw(p);
  398. if (col)
  399. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
  400. (((a) & 0x0700) << 4);
  401. else
  402. a ^= ((a & 0x0700) == 0x0100) ? 0x7000 : 0x7700;
  403. scr_writew(a, p++);
  404. }
  405. }
  406. static void vgacon_set_cursor_size(int xpos, int from, int to)
  407. {
  408. unsigned long flags;
  409. int curs, cure;
  410. if ((from == cursor_size_lastfrom) && (to == cursor_size_lastto))
  411. return;
  412. cursor_size_lastfrom = from;
  413. cursor_size_lastto = to;
  414. raw_spin_lock_irqsave(&vga_lock, flags);
  415. if (vga_video_type >= VIDEO_TYPE_VGAC) {
  416. outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg);
  417. curs = inb_p(vga_video_port_val);
  418. outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg);
  419. cure = inb_p(vga_video_port_val);
  420. } else {
  421. curs = 0;
  422. cure = 0;
  423. }
  424. curs = (curs & 0xc0) | from;
  425. cure = (cure & 0xe0) | to;
  426. outb_p(VGA_CRTC_CURSOR_START, vga_video_port_reg);
  427. outb_p(curs, vga_video_port_val);
  428. outb_p(VGA_CRTC_CURSOR_END, vga_video_port_reg);
  429. outb_p(cure, vga_video_port_val);
  430. raw_spin_unlock_irqrestore(&vga_lock, flags);
  431. }
  432. static void vgacon_cursor(struct vc_data *c, int mode)
  433. {
  434. if (c->vc_mode != KD_TEXT)
  435. return;
  436. vgacon_restore_screen(c);
  437. switch (mode) {
  438. case CM_ERASE:
  439. write_vga(14, (c->vc_pos - vga_vram_base) / 2);
  440. if (vga_video_type >= VIDEO_TYPE_VGAC)
  441. vgacon_set_cursor_size(c->state.x, 31, 30);
  442. else
  443. vgacon_set_cursor_size(c->state.x, 31, 31);
  444. break;
  445. case CM_MOVE:
  446. case CM_DRAW:
  447. write_vga(14, (c->vc_pos - vga_vram_base) / 2);
  448. switch (CUR_SIZE(c->vc_cursor_type)) {
  449. case CUR_UNDERLINE:
  450. vgacon_set_cursor_size(c->state.x,
  451. c->vc_cell_height -
  452. (c->vc_cell_height <
  453. 10 ? 2 : 3),
  454. c->vc_cell_height -
  455. (c->vc_cell_height <
  456. 10 ? 1 : 2));
  457. break;
  458. case CUR_TWO_THIRDS:
  459. vgacon_set_cursor_size(c->state.x,
  460. c->vc_cell_height / 3,
  461. c->vc_cell_height -
  462. (c->vc_cell_height <
  463. 10 ? 1 : 2));
  464. break;
  465. case CUR_LOWER_THIRD:
  466. vgacon_set_cursor_size(c->state.x,
  467. (c->vc_cell_height * 2) / 3,
  468. c->vc_cell_height -
  469. (c->vc_cell_height <
  470. 10 ? 1 : 2));
  471. break;
  472. case CUR_LOWER_HALF:
  473. vgacon_set_cursor_size(c->state.x,
  474. c->vc_cell_height / 2,
  475. c->vc_cell_height -
  476. (c->vc_cell_height <
  477. 10 ? 1 : 2));
  478. break;
  479. case CUR_NONE:
  480. if (vga_video_type >= VIDEO_TYPE_VGAC)
  481. vgacon_set_cursor_size(c->state.x, 31, 30);
  482. else
  483. vgacon_set_cursor_size(c->state.x, 31, 31);
  484. break;
  485. default:
  486. vgacon_set_cursor_size(c->state.x, 1,
  487. c->vc_cell_height);
  488. break;
  489. }
  490. break;
  491. }
  492. }
  493. static int vgacon_doresize(struct vc_data *c,
  494. unsigned int width, unsigned int height)
  495. {
  496. unsigned long flags;
  497. unsigned int scanlines = height * c->vc_cell_height;
  498. u8 scanlines_lo = 0, r7 = 0, vsync_end = 0, mode, max_scan;
  499. raw_spin_lock_irqsave(&vga_lock, flags);
  500. vgacon_xres = width * VGA_FONTWIDTH;
  501. vgacon_yres = height * c->vc_cell_height;
  502. if (vga_video_type >= VIDEO_TYPE_VGAC) {
  503. outb_p(VGA_CRTC_MAX_SCAN, vga_video_port_reg);
  504. max_scan = inb_p(vga_video_port_val);
  505. if (max_scan & 0x80)
  506. scanlines <<= 1;
  507. outb_p(VGA_CRTC_MODE, vga_video_port_reg);
  508. mode = inb_p(vga_video_port_val);
  509. if (mode & 0x04)
  510. scanlines >>= 1;
  511. scanlines -= 1;
  512. scanlines_lo = scanlines & 0xff;
  513. outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg);
  514. r7 = inb_p(vga_video_port_val) & ~0x42;
  515. if (scanlines & 0x100)
  516. r7 |= 0x02;
  517. if (scanlines & 0x200)
  518. r7 |= 0x40;
  519. /* deprotect registers */
  520. outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
  521. vsync_end = inb_p(vga_video_port_val);
  522. outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
  523. outb_p(vsync_end & ~0x80, vga_video_port_val);
  524. }
  525. outb_p(VGA_CRTC_H_DISP, vga_video_port_reg);
  526. outb_p(width - 1, vga_video_port_val);
  527. outb_p(VGA_CRTC_OFFSET, vga_video_port_reg);
  528. outb_p(width >> 1, vga_video_port_val);
  529. if (vga_video_type >= VIDEO_TYPE_VGAC) {
  530. outb_p(VGA_CRTC_V_DISP_END, vga_video_port_reg);
  531. outb_p(scanlines_lo, vga_video_port_val);
  532. outb_p(VGA_CRTC_OVERFLOW, vga_video_port_reg);
  533. outb_p(r7,vga_video_port_val);
  534. /* reprotect registers */
  535. outb_p(VGA_CRTC_V_SYNC_END, vga_video_port_reg);
  536. outb_p(vsync_end, vga_video_port_val);
  537. }
  538. raw_spin_unlock_irqrestore(&vga_lock, flags);
  539. return 0;
  540. }
  541. static int vgacon_switch(struct vc_data *c)
  542. {
  543. int x = c->vc_cols * VGA_FONTWIDTH;
  544. int y = c->vc_rows * c->vc_cell_height;
  545. int rows = screen_info.orig_video_lines * vga_default_font_height/
  546. c->vc_cell_height;
  547. /*
  548. * We need to save screen size here as it's the only way
  549. * we can spot the screen has been resized and we need to
  550. * set size of freshly allocated screens ourselves.
  551. */
  552. vga_video_num_columns = c->vc_cols;
  553. vga_video_num_lines = c->vc_rows;
  554. /* We can only copy out the size of the video buffer here,
  555. * otherwise we get into VGA BIOS */
  556. if (!vga_is_gfx) {
  557. scr_memcpyw((u16 *) c->vc_origin, (u16 *) c->vc_screenbuf,
  558. c->vc_screenbuf_size > vga_vram_size ?
  559. vga_vram_size : c->vc_screenbuf_size);
  560. if ((vgacon_xres != x || vgacon_yres != y) &&
  561. (!(vga_video_num_columns % 2) &&
  562. vga_video_num_columns <= screen_info.orig_video_cols &&
  563. vga_video_num_lines <= rows))
  564. vgacon_doresize(c, c->vc_cols, c->vc_rows);
  565. }
  566. return 0; /* Redrawing not needed */
  567. }
  568. static void vga_set_palette(struct vc_data *vc, const unsigned char *table)
  569. {
  570. int i, j;
  571. vga_w(vgastate.vgabase, VGA_PEL_MSK, 0xff);
  572. for (i = j = 0; i < 16; i++) {
  573. vga_w(vgastate.vgabase, VGA_PEL_IW, table[i]);
  574. vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2);
  575. vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2);
  576. vga_w(vgastate.vgabase, VGA_PEL_D, vc->vc_palette[j++] >> 2);
  577. }
  578. }
  579. static void vgacon_set_palette(struct vc_data *vc, const unsigned char *table)
  580. {
  581. if (vga_video_type != VIDEO_TYPE_VGAC || vga_palette_blanked
  582. || !con_is_visible(vc))
  583. return;
  584. vga_set_palette(vc, table);
  585. }
  586. /* structure holding original VGA register settings */
  587. static struct {
  588. unsigned char SeqCtrlIndex; /* Sequencer Index reg. */
  589. unsigned char CrtCtrlIndex; /* CRT-Contr. Index reg. */
  590. unsigned char CrtMiscIO; /* Miscellaneous register */
  591. unsigned char HorizontalTotal; /* CRT-Controller:00h */
  592. unsigned char HorizDisplayEnd; /* CRT-Controller:01h */
  593. unsigned char StartHorizRetrace; /* CRT-Controller:04h */
  594. unsigned char EndHorizRetrace; /* CRT-Controller:05h */
  595. unsigned char Overflow; /* CRT-Controller:07h */
  596. unsigned char StartVertRetrace; /* CRT-Controller:10h */
  597. unsigned char EndVertRetrace; /* CRT-Controller:11h */
  598. unsigned char ModeControl; /* CRT-Controller:17h */
  599. unsigned char ClockingMode; /* Seq-Controller:01h */
  600. } vga_state;
  601. static void vga_vesa_blank(struct vgastate *state, int mode)
  602. {
  603. /* save original values of VGA controller registers */
  604. if (!vga_vesa_blanked) {
  605. raw_spin_lock_irq(&vga_lock);
  606. vga_state.SeqCtrlIndex = vga_r(state->vgabase, VGA_SEQ_I);
  607. vga_state.CrtCtrlIndex = inb_p(vga_video_port_reg);
  608. vga_state.CrtMiscIO = vga_r(state->vgabase, VGA_MIS_R);
  609. raw_spin_unlock_irq(&vga_lock);
  610. outb_p(0x00, vga_video_port_reg); /* HorizontalTotal */
  611. vga_state.HorizontalTotal = inb_p(vga_video_port_val);
  612. outb_p(0x01, vga_video_port_reg); /* HorizDisplayEnd */
  613. vga_state.HorizDisplayEnd = inb_p(vga_video_port_val);
  614. outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */
  615. vga_state.StartHorizRetrace = inb_p(vga_video_port_val);
  616. outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */
  617. vga_state.EndHorizRetrace = inb_p(vga_video_port_val);
  618. outb_p(0x07, vga_video_port_reg); /* Overflow */
  619. vga_state.Overflow = inb_p(vga_video_port_val);
  620. outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */
  621. vga_state.StartVertRetrace = inb_p(vga_video_port_val);
  622. outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */
  623. vga_state.EndVertRetrace = inb_p(vga_video_port_val);
  624. outb_p(0x17, vga_video_port_reg); /* ModeControl */
  625. vga_state.ModeControl = inb_p(vga_video_port_val);
  626. vga_state.ClockingMode = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE);
  627. }
  628. /* assure that video is enabled */
  629. /* "0x20" is VIDEO_ENABLE_bit in register 01 of sequencer */
  630. raw_spin_lock_irq(&vga_lock);
  631. vga_wseq(state->vgabase, VGA_SEQ_CLOCK_MODE, vga_state.ClockingMode | 0x20);
  632. /* test for vertical retrace in process.... */
  633. if ((vga_state.CrtMiscIO & 0x80) == 0x80)
  634. vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO & 0xEF);
  635. /*
  636. * Set <End of vertical retrace> to minimum (0) and
  637. * <Start of vertical Retrace> to maximum (incl. overflow)
  638. * Result: turn off vertical sync (VSync) pulse.
  639. */
  640. if (mode & VESA_VSYNC_SUSPEND) {
  641. outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */
  642. outb_p(0xff, vga_video_port_val); /* maximum value */
  643. outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */
  644. outb_p(0x40, vga_video_port_val); /* minimum (bits 0..3) */
  645. outb_p(0x07, vga_video_port_reg); /* Overflow */
  646. outb_p(vga_state.Overflow | 0x84, vga_video_port_val); /* bits 9,10 of vert. retrace */
  647. }
  648. if (mode & VESA_HSYNC_SUSPEND) {
  649. /*
  650. * Set <End of horizontal retrace> to minimum (0) and
  651. * <Start of horizontal Retrace> to maximum
  652. * Result: turn off horizontal sync (HSync) pulse.
  653. */
  654. outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */
  655. outb_p(0xff, vga_video_port_val); /* maximum */
  656. outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */
  657. outb_p(0x00, vga_video_port_val); /* minimum (0) */
  658. }
  659. /* restore both index registers */
  660. vga_w(state->vgabase, VGA_SEQ_I, vga_state.SeqCtrlIndex);
  661. outb_p(vga_state.CrtCtrlIndex, vga_video_port_reg);
  662. raw_spin_unlock_irq(&vga_lock);
  663. }
  664. static void vga_vesa_unblank(struct vgastate *state)
  665. {
  666. /* restore original values of VGA controller registers */
  667. raw_spin_lock_irq(&vga_lock);
  668. vga_w(state->vgabase, VGA_MIS_W, vga_state.CrtMiscIO);
  669. outb_p(0x00, vga_video_port_reg); /* HorizontalTotal */
  670. outb_p(vga_state.HorizontalTotal, vga_video_port_val);
  671. outb_p(0x01, vga_video_port_reg); /* HorizDisplayEnd */
  672. outb_p(vga_state.HorizDisplayEnd, vga_video_port_val);
  673. outb_p(0x04, vga_video_port_reg); /* StartHorizRetrace */
  674. outb_p(vga_state.StartHorizRetrace, vga_video_port_val);
  675. outb_p(0x05, vga_video_port_reg); /* EndHorizRetrace */
  676. outb_p(vga_state.EndHorizRetrace, vga_video_port_val);
  677. outb_p(0x07, vga_video_port_reg); /* Overflow */
  678. outb_p(vga_state.Overflow, vga_video_port_val);
  679. outb_p(0x10, vga_video_port_reg); /* StartVertRetrace */
  680. outb_p(vga_state.StartVertRetrace, vga_video_port_val);
  681. outb_p(0x11, vga_video_port_reg); /* EndVertRetrace */
  682. outb_p(vga_state.EndVertRetrace, vga_video_port_val);
  683. outb_p(0x17, vga_video_port_reg); /* ModeControl */
  684. outb_p(vga_state.ModeControl, vga_video_port_val);
  685. /* ClockingMode */
  686. vga_wseq(state->vgabase, VGA_SEQ_CLOCK_MODE, vga_state.ClockingMode);
  687. /* restore index/control registers */
  688. vga_w(state->vgabase, VGA_SEQ_I, vga_state.SeqCtrlIndex);
  689. outb_p(vga_state.CrtCtrlIndex, vga_video_port_reg);
  690. raw_spin_unlock_irq(&vga_lock);
  691. }
  692. static void vga_pal_blank(struct vgastate *state)
  693. {
  694. int i;
  695. vga_w(state->vgabase, VGA_PEL_MSK, 0xff);
  696. for (i = 0; i < 16; i++) {
  697. vga_w(state->vgabase, VGA_PEL_IW, i);
  698. vga_w(state->vgabase, VGA_PEL_D, 0);
  699. vga_w(state->vgabase, VGA_PEL_D, 0);
  700. vga_w(state->vgabase, VGA_PEL_D, 0);
  701. }
  702. }
  703. static int vgacon_blank(struct vc_data *c, int blank, int mode_switch)
  704. {
  705. switch (blank) {
  706. case 0: /* Unblank */
  707. if (vga_vesa_blanked) {
  708. vga_vesa_unblank(&vgastate);
  709. vga_vesa_blanked = 0;
  710. }
  711. if (vga_palette_blanked) {
  712. vga_set_palette(c, color_table);
  713. vga_palette_blanked = false;
  714. return 0;
  715. }
  716. vga_is_gfx = false;
  717. /* Tell console.c that it has to restore the screen itself */
  718. return 1;
  719. case 1: /* Normal blanking */
  720. case -1: /* Obsolete */
  721. if (!mode_switch && vga_video_type == VIDEO_TYPE_VGAC) {
  722. vga_pal_blank(&vgastate);
  723. vga_palette_blanked = true;
  724. return 0;
  725. }
  726. vgacon_set_origin(c);
  727. scr_memsetw((void *) vga_vram_base, BLANK,
  728. c->vc_screenbuf_size);
  729. if (mode_switch)
  730. vga_is_gfx = true;
  731. return 1;
  732. default: /* VESA blanking */
  733. if (vga_video_type == VIDEO_TYPE_VGAC) {
  734. vga_vesa_blank(&vgastate, blank - 1);
  735. vga_vesa_blanked = blank;
  736. }
  737. return 0;
  738. }
  739. }
  740. /*
  741. * PIO_FONT support.
  742. *
  743. * The font loading code goes back to the codepage package by
  744. * Joel Hoffman ([email protected]). (He reports that the original
  745. * reference is: "From: p. 307 of _Programmer's Guide to PC & PS/2
  746. * Video Systems_ by Richard Wilton. 1987. Microsoft Press".)
  747. *
  748. * Change for certain monochrome monitors by Yury Shevchuck
  749. * ([email protected]).
  750. */
  751. #define colourmap 0xa0000
  752. /* Pauline Middelink <[email protected]> reports that we
  753. should use 0xA0000 for the bwmap as well.. */
  754. #define blackwmap 0xa0000
  755. #define cmapsz 8192
  756. static int vgacon_do_font_op(struct vgastate *state, char *arg, int set,
  757. bool ch512)
  758. {
  759. unsigned short video_port_status = vga_video_port_reg + 6;
  760. int font_select = 0x00, beg, i;
  761. char *charmap;
  762. bool clear_attribs = false;
  763. if (vga_video_type != VIDEO_TYPE_EGAM) {
  764. charmap = (char *) VGA_MAP_MEM(colourmap, 0);
  765. beg = 0x0e;
  766. } else {
  767. charmap = (char *) VGA_MAP_MEM(blackwmap, 0);
  768. beg = 0x0a;
  769. }
  770. /*
  771. * All fonts are loaded in slot 0 (0:1 for 512 ch)
  772. */
  773. if (!arg)
  774. return -EINVAL; /* Return to default font not supported */
  775. font_select = ch512 ? 0x04 : 0x00;
  776. raw_spin_lock_irq(&vga_lock);
  777. /* First, the Sequencer */
  778. vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
  779. /* CPU writes only to map 2 */
  780. vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, 0x04);
  781. /* Sequential addressing */
  782. vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, 0x07);
  783. /* Clear synchronous reset */
  784. vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x03);
  785. /* Now, the graphics controller, select map 2 */
  786. vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, 0x02);
  787. /* disable odd-even addressing */
  788. vga_wgfx(state->vgabase, VGA_GFX_MODE, 0x00);
  789. /* map start at A000:0000 */
  790. vga_wgfx(state->vgabase, VGA_GFX_MISC, 0x00);
  791. raw_spin_unlock_irq(&vga_lock);
  792. if (arg) {
  793. if (set)
  794. for (i = 0; i < cmapsz; i++) {
  795. vga_writeb(arg[i], charmap + i);
  796. cond_resched();
  797. }
  798. else
  799. for (i = 0; i < cmapsz; i++) {
  800. arg[i] = vga_readb(charmap + i);
  801. cond_resched();
  802. }
  803. /*
  804. * In 512-character mode, the character map is not contiguous if
  805. * we want to remain EGA compatible -- which we do
  806. */
  807. if (ch512) {
  808. charmap += 2 * cmapsz;
  809. arg += cmapsz;
  810. if (set)
  811. for (i = 0; i < cmapsz; i++) {
  812. vga_writeb(arg[i], charmap + i);
  813. cond_resched();
  814. }
  815. else
  816. for (i = 0; i < cmapsz; i++) {
  817. arg[i] = vga_readb(charmap + i);
  818. cond_resched();
  819. }
  820. }
  821. }
  822. raw_spin_lock_irq(&vga_lock);
  823. /* First, the sequencer, Synchronous reset */
  824. vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x01);
  825. /* CPU writes to maps 0 and 1 */
  826. vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, 0x03);
  827. /* odd-even addressing */
  828. vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, 0x03);
  829. /* Character Map Select */
  830. if (set)
  831. vga_wseq(state->vgabase, VGA_SEQ_CHARACTER_MAP, font_select);
  832. /* clear synchronous reset */
  833. vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x03);
  834. /* Now, the graphics controller, select map 0 for CPU */
  835. vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, 0x00);
  836. /* enable even-odd addressing */
  837. vga_wgfx(state->vgabase, VGA_GFX_MODE, 0x10);
  838. /* map starts at b800:0 or b000:0 */
  839. vga_wgfx(state->vgabase, VGA_GFX_MISC, beg);
  840. /* if 512 char mode is already enabled don't re-enable it. */
  841. if ((set) && (ch512 != vga_512_chars)) {
  842. vga_512_chars = ch512;
  843. /* 256-char: enable intensity bit
  844. 512-char: disable intensity bit */
  845. inb_p(video_port_status); /* clear address flip-flop */
  846. /* color plane enable register */
  847. vga_wattr(state->vgabase, VGA_ATC_PLANE_ENABLE, ch512 ? 0x07 : 0x0f);
  848. /* Wilton (1987) mentions the following; I don't know what
  849. it means, but it works, and it appears necessary */
  850. inb_p(video_port_status);
  851. vga_wattr(state->vgabase, VGA_AR_ENABLE_DISPLAY, 0);
  852. clear_attribs = true;
  853. }
  854. raw_spin_unlock_irq(&vga_lock);
  855. if (clear_attribs) {
  856. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  857. struct vc_data *c = vc_cons[i].d;
  858. if (c && c->vc_sw == &vga_con) {
  859. /* force hi font mask to 0, so we always clear
  860. the bit on either transition */
  861. c->vc_hi_font_mask = 0x00;
  862. clear_buffer_attributes(c);
  863. c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
  864. }
  865. }
  866. }
  867. return 0;
  868. }
  869. /*
  870. * Adjust the screen to fit a font of a certain height
  871. */
  872. static int vgacon_adjust_height(struct vc_data *vc, unsigned fontheight)
  873. {
  874. unsigned char ovr, vde, fsr;
  875. int rows, maxscan, i;
  876. rows = vc->vc_scan_lines / fontheight; /* Number of video rows we end up with */
  877. maxscan = rows * fontheight - 1; /* Scan lines to actually display-1 */
  878. /* Reprogram the CRTC for the new font size
  879. Note: the attempt to read the overflow register will fail
  880. on an EGA, but using 0xff for the previous value appears to
  881. be OK for EGA text modes in the range 257-512 scan lines, so I
  882. guess we don't need to worry about it.
  883. The same applies for the spill bits in the font size and cursor
  884. registers; they are write-only on EGA, but it appears that they
  885. are all don't care bits on EGA, so I guess it doesn't matter. */
  886. raw_spin_lock_irq(&vga_lock);
  887. outb_p(0x07, vga_video_port_reg); /* CRTC overflow register */
  888. ovr = inb_p(vga_video_port_val);
  889. outb_p(0x09, vga_video_port_reg); /* Font size register */
  890. fsr = inb_p(vga_video_port_val);
  891. raw_spin_unlock_irq(&vga_lock);
  892. vde = maxscan & 0xff; /* Vertical display end reg */
  893. ovr = (ovr & 0xbd) + /* Overflow register */
  894. ((maxscan & 0x100) >> 7) + ((maxscan & 0x200) >> 3);
  895. fsr = (fsr & 0xe0) + (fontheight - 1); /* Font size register */
  896. raw_spin_lock_irq(&vga_lock);
  897. outb_p(0x07, vga_video_port_reg); /* CRTC overflow register */
  898. outb_p(ovr, vga_video_port_val);
  899. outb_p(0x09, vga_video_port_reg); /* Font size */
  900. outb_p(fsr, vga_video_port_val);
  901. outb_p(0x12, vga_video_port_reg); /* Vertical display limit */
  902. outb_p(vde, vga_video_port_val);
  903. raw_spin_unlock_irq(&vga_lock);
  904. vga_video_font_height = fontheight;
  905. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  906. struct vc_data *c = vc_cons[i].d;
  907. if (c && c->vc_sw == &vga_con) {
  908. if (con_is_visible(c)) {
  909. /* void size to cause regs to be rewritten */
  910. cursor_size_lastfrom = 0;
  911. cursor_size_lastto = 0;
  912. c->vc_sw->con_cursor(c, CM_DRAW);
  913. }
  914. c->vc_font.height = c->vc_cell_height = fontheight;
  915. vc_resize(c, 0, rows); /* Adjust console size */
  916. }
  917. }
  918. return 0;
  919. }
  920. static int vgacon_font_set(struct vc_data *c, struct console_font *font,
  921. unsigned int flags)
  922. {
  923. unsigned charcount = font->charcount;
  924. int rc;
  925. if (vga_video_type < VIDEO_TYPE_EGAM)
  926. return -EINVAL;
  927. if (font->width != VGA_FONTWIDTH ||
  928. (charcount != 256 && charcount != 512))
  929. return -EINVAL;
  930. rc = vgacon_do_font_op(&vgastate, font->data, 1, charcount == 512);
  931. if (rc)
  932. return rc;
  933. if (!(flags & KD_FONT_FLAG_DONT_RECALC))
  934. rc = vgacon_adjust_height(c, font->height);
  935. return rc;
  936. }
  937. static int vgacon_font_get(struct vc_data *c, struct console_font *font)
  938. {
  939. if (vga_video_type < VIDEO_TYPE_EGAM)
  940. return -EINVAL;
  941. font->width = VGA_FONTWIDTH;
  942. font->height = c->vc_font.height;
  943. font->charcount = vga_512_chars ? 512 : 256;
  944. if (!font->data)
  945. return 0;
  946. return vgacon_do_font_op(&vgastate, font->data, 0, vga_512_chars);
  947. }
  948. static int vgacon_resize(struct vc_data *c, unsigned int width,
  949. unsigned int height, unsigned int user)
  950. {
  951. if ((width << 1) * height > vga_vram_size)
  952. return -EINVAL;
  953. if (user) {
  954. /*
  955. * Ho ho! Someone (svgatextmode, eh?) may have reprogrammed
  956. * the video mode! Set the new defaults then and go away.
  957. */
  958. screen_info.orig_video_cols = width;
  959. screen_info.orig_video_lines = height;
  960. vga_default_font_height = c->vc_cell_height;
  961. return 0;
  962. }
  963. if (width % 2 || width > screen_info.orig_video_cols ||
  964. height > (screen_info.orig_video_lines * vga_default_font_height)/
  965. c->vc_cell_height)
  966. return -EINVAL;
  967. if (con_is_visible(c) && !vga_is_gfx) /* who knows */
  968. vgacon_doresize(c, width, height);
  969. return 0;
  970. }
  971. static int vgacon_set_origin(struct vc_data *c)
  972. {
  973. if (vga_is_gfx || /* We don't play origin tricks in graphic modes */
  974. (console_blanked && !vga_palette_blanked)) /* Nor we write to blanked screens */
  975. return 0;
  976. c->vc_origin = c->vc_visible_origin = vga_vram_base;
  977. vga_set_mem_top(c);
  978. vga_rolled_over = 0;
  979. return 1;
  980. }
  981. static void vgacon_save_screen(struct vc_data *c)
  982. {
  983. static int vga_bootup_console = 0;
  984. if (!vga_bootup_console) {
  985. /* This is a gross hack, but here is the only place we can
  986. * set bootup console parameters without messing up generic
  987. * console initialization routines.
  988. */
  989. vga_bootup_console = 1;
  990. c->state.x = screen_info.orig_x;
  991. c->state.y = screen_info.orig_y;
  992. }
  993. /* We can't copy in more than the size of the video buffer,
  994. * or we'll be copying in VGA BIOS */
  995. if (!vga_is_gfx)
  996. scr_memcpyw((u16 *) c->vc_screenbuf, (u16 *) c->vc_origin,
  997. c->vc_screenbuf_size > vga_vram_size ? vga_vram_size : c->vc_screenbuf_size);
  998. }
  999. static bool vgacon_scroll(struct vc_data *c, unsigned int t, unsigned int b,
  1000. enum con_scroll dir, unsigned int lines)
  1001. {
  1002. unsigned long oldo;
  1003. unsigned int delta;
  1004. if (t || b != c->vc_rows || vga_is_gfx || c->vc_mode != KD_TEXT)
  1005. return false;
  1006. if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2)
  1007. return false;
  1008. vgacon_restore_screen(c);
  1009. oldo = c->vc_origin;
  1010. delta = lines * c->vc_size_row;
  1011. if (dir == SM_UP) {
  1012. if (c->vc_scr_end + delta >= vga_vram_end) {
  1013. scr_memcpyw((u16 *) vga_vram_base,
  1014. (u16 *) (oldo + delta),
  1015. c->vc_screenbuf_size - delta);
  1016. c->vc_origin = vga_vram_base;
  1017. vga_rolled_over = oldo - vga_vram_base;
  1018. } else
  1019. c->vc_origin += delta;
  1020. scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size -
  1021. delta), c->vc_video_erase_char,
  1022. delta);
  1023. } else {
  1024. if (oldo - delta < vga_vram_base) {
  1025. scr_memmovew((u16 *) (vga_vram_end -
  1026. c->vc_screenbuf_size +
  1027. delta), (u16 *) oldo,
  1028. c->vc_screenbuf_size - delta);
  1029. c->vc_origin = vga_vram_end - c->vc_screenbuf_size;
  1030. vga_rolled_over = 0;
  1031. } else
  1032. c->vc_origin -= delta;
  1033. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  1034. scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char,
  1035. delta);
  1036. }
  1037. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  1038. c->vc_visible_origin = c->vc_origin;
  1039. vga_set_mem_top(c);
  1040. c->vc_pos = (c->vc_pos - oldo) + c->vc_origin;
  1041. return true;
  1042. }
  1043. /*
  1044. * The console `switch' structure for the VGA based console
  1045. */
  1046. static void vgacon_clear(struct vc_data *vc, int sy, int sx, int height,
  1047. int width) { }
  1048. static void vgacon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
  1049. static void vgacon_putcs(struct vc_data *vc, const unsigned short *s,
  1050. int count, int ypos, int xpos) { }
  1051. const struct consw vga_con = {
  1052. .owner = THIS_MODULE,
  1053. .con_startup = vgacon_startup,
  1054. .con_init = vgacon_init,
  1055. .con_deinit = vgacon_deinit,
  1056. .con_clear = vgacon_clear,
  1057. .con_putc = vgacon_putc,
  1058. .con_putcs = vgacon_putcs,
  1059. .con_cursor = vgacon_cursor,
  1060. .con_scroll = vgacon_scroll,
  1061. .con_switch = vgacon_switch,
  1062. .con_blank = vgacon_blank,
  1063. .con_font_set = vgacon_font_set,
  1064. .con_font_get = vgacon_font_get,
  1065. .con_resize = vgacon_resize,
  1066. .con_set_palette = vgacon_set_palette,
  1067. .con_scrolldelta = vgacon_scrolldelta,
  1068. .con_set_origin = vgacon_set_origin,
  1069. .con_save_screen = vgacon_save_screen,
  1070. .con_build_attr = vgacon_build_attr,
  1071. .con_invert_region = vgacon_invert_region,
  1072. };
  1073. EXPORT_SYMBOL(vga_con);
  1074. MODULE_LICENSE("GPL");