video-vga.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. * Copyright 2009 Intel Corporation; author H. Peter Anvin
  6. *
  7. * This file is part of the Linux kernel, and is made available under
  8. * the terms of the GNU General Public License version 2.
  9. *
  10. * ----------------------------------------------------------------------- */
  11. /*
  12. * Common all-VGA modes
  13. */
  14. #include "boot.h"
  15. #include "video.h"
  16. static struct mode_info vga_modes[] = {
  17. { VIDEO_80x25, 80, 25, 0 },
  18. { VIDEO_8POINT, 80, 50, 0 },
  19. { VIDEO_80x43, 80, 43, 0 },
  20. { VIDEO_80x28, 80, 28, 0 },
  21. { VIDEO_80x30, 80, 30, 0 },
  22. { VIDEO_80x34, 80, 34, 0 },
  23. { VIDEO_80x60, 80, 60, 0 },
  24. };
  25. static struct mode_info ega_modes[] = {
  26. { VIDEO_80x25, 80, 25, 0 },
  27. { VIDEO_8POINT, 80, 43, 0 },
  28. };
  29. static struct mode_info cga_modes[] = {
  30. { VIDEO_80x25, 80, 25, 0 },
  31. };
  32. static __videocard video_vga;
  33. /* Set basic 80x25 mode */
  34. static u8 vga_set_basic_mode(void)
  35. {
  36. struct biosregs ireg, oreg;
  37. u16 ax;
  38. u8 rows;
  39. u8 mode;
  40. initregs(&ireg);
  41. ax = 0x0f00;
  42. intcall(0x10, &ireg, &oreg);
  43. mode = oreg.al;
  44. set_fs(0);
  45. rows = rdfs8(0x484); /* rows minus one */
  46. if ((oreg.ax == 0x5003 || oreg.ax == 0x5007) &&
  47. (rows == 0 || rows == 24))
  48. return mode;
  49. if (mode != 3 && mode != 7)
  50. mode = 3;
  51. /* Set the mode */
  52. ireg.ax = mode; /* AH=0: set mode */
  53. intcall(0x10, &ireg, NULL);
  54. do_restore = 1;
  55. return mode;
  56. }
  57. static void vga_set_8font(void)
  58. {
  59. /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
  60. struct biosregs ireg;
  61. initregs(&ireg);
  62. /* Set 8x8 font */
  63. ireg.ax = 0x1112;
  64. /* ireg.bl = 0; */
  65. intcall(0x10, &ireg, NULL);
  66. /* Use alternate print screen */
  67. ireg.ax = 0x1200;
  68. ireg.bl = 0x20;
  69. intcall(0x10, &ireg, NULL);
  70. /* Turn off cursor emulation */
  71. ireg.ax = 0x1201;
  72. ireg.bl = 0x34;
  73. intcall(0x10, &ireg, NULL);
  74. /* Cursor is scan lines 6-7 */
  75. ireg.ax = 0x0100;
  76. ireg.cx = 0x0607;
  77. intcall(0x10, &ireg, NULL);
  78. }
  79. static void vga_set_14font(void)
  80. {
  81. /* Set 9x14 font - 80x28 on VGA */
  82. struct biosregs ireg;
  83. initregs(&ireg);
  84. /* Set 9x14 font */
  85. ireg.ax = 0x1111;
  86. /* ireg.bl = 0; */
  87. intcall(0x10, &ireg, NULL);
  88. /* Turn off cursor emulation */
  89. ireg.ax = 0x1201;
  90. ireg.bl = 0x34;
  91. intcall(0x10, &ireg, NULL);
  92. /* Cursor is scan lines 11-12 */
  93. ireg.ax = 0x0100;
  94. ireg.cx = 0x0b0c;
  95. intcall(0x10, &ireg, NULL);
  96. }
  97. static void vga_set_80x43(void)
  98. {
  99. /* Set 80x43 mode on VGA (not EGA) */
  100. struct biosregs ireg;
  101. initregs(&ireg);
  102. /* Set 350 scans */
  103. ireg.ax = 0x1201;
  104. ireg.bl = 0x30;
  105. intcall(0x10, &ireg, NULL);
  106. /* Reset video mode */
  107. ireg.ax = 0x0003;
  108. intcall(0x10, &ireg, NULL);
  109. vga_set_8font();
  110. }
  111. /* I/O address of the VGA CRTC */
  112. u16 vga_crtc(void)
  113. {
  114. return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
  115. }
  116. static void vga_set_480_scanlines(void)
  117. {
  118. u16 crtc; /* CRTC base address */
  119. u8 csel; /* CRTC miscellaneous output register */
  120. crtc = vga_crtc();
  121. out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
  122. out_idx(0x0b, crtc, 0x06); /* Vertical total */
  123. out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
  124. out_idx(0xea, crtc, 0x10); /* Vertical sync start */
  125. out_idx(0xdf, crtc, 0x12); /* Vertical display end */
  126. out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
  127. out_idx(0x04, crtc, 0x16); /* Vertical blank end */
  128. csel = inb(0x3cc);
  129. csel &= 0x0d;
  130. csel |= 0xe2;
  131. outb(csel, 0x3c2);
  132. }
  133. static void vga_set_vertical_end(int lines)
  134. {
  135. u16 crtc; /* CRTC base address */
  136. u8 ovfw; /* CRTC overflow register */
  137. int end = lines-1;
  138. crtc = vga_crtc();
  139. ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
  140. out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
  141. out_idx(end, crtc, 0x12); /* Vertical display end */
  142. }
  143. static void vga_set_80x30(void)
  144. {
  145. vga_set_480_scanlines();
  146. vga_set_vertical_end(30*16);
  147. }
  148. static void vga_set_80x34(void)
  149. {
  150. vga_set_480_scanlines();
  151. vga_set_14font();
  152. vga_set_vertical_end(34*14);
  153. }
  154. static void vga_set_80x60(void)
  155. {
  156. vga_set_480_scanlines();
  157. vga_set_8font();
  158. vga_set_vertical_end(60*8);
  159. }
  160. static int vga_set_mode(struct mode_info *mode)
  161. {
  162. /* Set the basic mode */
  163. vga_set_basic_mode();
  164. /* Override a possibly broken BIOS */
  165. force_x = mode->x;
  166. force_y = mode->y;
  167. switch (mode->mode) {
  168. case VIDEO_80x25:
  169. break;
  170. case VIDEO_8POINT:
  171. vga_set_8font();
  172. break;
  173. case VIDEO_80x43:
  174. vga_set_80x43();
  175. break;
  176. case VIDEO_80x28:
  177. vga_set_14font();
  178. break;
  179. case VIDEO_80x30:
  180. vga_set_80x30();
  181. break;
  182. case VIDEO_80x34:
  183. vga_set_80x34();
  184. break;
  185. case VIDEO_80x60:
  186. vga_set_80x60();
  187. break;
  188. }
  189. return 0;
  190. }
  191. /*
  192. * Note: this probe includes basic information required by all
  193. * systems. It should be executed first, by making sure
  194. * video-vga.c is listed first in the Makefile.
  195. */
  196. static int vga_probe(void)
  197. {
  198. static const char *card_name[] = {
  199. "CGA/MDA/HGC", "EGA", "VGA"
  200. };
  201. static struct mode_info *mode_lists[] = {
  202. cga_modes,
  203. ega_modes,
  204. vga_modes,
  205. };
  206. static int mode_count[] = {
  207. sizeof(cga_modes)/sizeof(struct mode_info),
  208. sizeof(ega_modes)/sizeof(struct mode_info),
  209. sizeof(vga_modes)/sizeof(struct mode_info),
  210. };
  211. struct biosregs ireg, oreg;
  212. initregs(&ireg);
  213. ireg.ax = 0x1200;
  214. ireg.bl = 0x10; /* Check EGA/VGA */
  215. intcall(0x10, &ireg, &oreg);
  216. #ifndef _WAKEUP
  217. boot_params.screen_info.orig_video_ega_bx = oreg.bx;
  218. #endif
  219. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  220. if (oreg.bl != 0x10) {
  221. /* EGA/VGA */
  222. ireg.ax = 0x1a00;
  223. intcall(0x10, &ireg, &oreg);
  224. if (oreg.al == 0x1a) {
  225. adapter = ADAPTER_VGA;
  226. #ifndef _WAKEUP
  227. boot_params.screen_info.orig_video_isVGA = 1;
  228. #endif
  229. } else {
  230. adapter = ADAPTER_EGA;
  231. }
  232. } else {
  233. adapter = ADAPTER_CGA;
  234. }
  235. video_vga.modes = mode_lists[adapter];
  236. video_vga.card_name = card_name[adapter];
  237. return mode_count[adapter];
  238. }
  239. static __videocard video_vga = {
  240. .card_name = "VGA",
  241. .probe = vga_probe,
  242. .set_mode = vga_set_mode,
  243. };