video-vga.c 5.8 KB

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