video-vga.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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(int lines)
  104. {
  105. u16 crtc; /* CRTC base address */
  106. u8 csel; /* CRTC miscellaneous output register */
  107. u8 ovfw; /* CRTC overflow register */
  108. int end = lines-1;
  109. crtc = vga_crtc();
  110. ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
  111. out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
  112. out_idx(0x0b, crtc, 0x06); /* Vertical total */
  113. out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
  114. out_idx(0xea, crtc, 0x10); /* Vertical sync start */
  115. out_idx(end, crtc, 0x12); /* Vertical display end */
  116. out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
  117. out_idx(0x04, crtc, 0x16); /* Vertical blank end */
  118. csel = inb(0x3cc);
  119. csel &= 0x0d;
  120. csel |= 0xe2;
  121. outb(csel, 0x3c2);
  122. }
  123. static void vga_set_80x30(void)
  124. {
  125. vga_set_480_scanlines(30*16);
  126. }
  127. static void vga_set_80x34(void)
  128. {
  129. vga_set_14font();
  130. vga_set_480_scanlines(34*14);
  131. }
  132. static void vga_set_80x60(void)
  133. {
  134. vga_set_8font();
  135. vga_set_480_scanlines(60*8);
  136. }
  137. static int vga_set_mode(struct mode_info *mode)
  138. {
  139. /* Set the basic mode */
  140. vga_set_basic_mode();
  141. /* Override a possibly broken BIOS */
  142. force_x = mode->x;
  143. force_y = mode->y;
  144. switch (mode->mode) {
  145. case VIDEO_80x25:
  146. break;
  147. case VIDEO_8POINT:
  148. vga_set_8font();
  149. break;
  150. case VIDEO_80x43:
  151. vga_set_80x43();
  152. break;
  153. case VIDEO_80x28:
  154. vga_set_14font();
  155. break;
  156. case VIDEO_80x30:
  157. vga_set_80x30();
  158. break;
  159. case VIDEO_80x34:
  160. vga_set_80x34();
  161. break;
  162. case VIDEO_80x60:
  163. vga_set_80x60();
  164. break;
  165. }
  166. return 0;
  167. }
  168. /*
  169. * Note: this probe includes basic information required by all
  170. * systems. It should be executed first, by making sure
  171. * video-vga.c is listed first in the Makefile.
  172. */
  173. static int vga_probe(void)
  174. {
  175. u16 ega_bx;
  176. static const char *card_name[] = {
  177. "CGA/MDA/HGC", "EGA", "VGA"
  178. };
  179. static struct mode_info *mode_lists[] = {
  180. cga_modes,
  181. ega_modes,
  182. vga_modes,
  183. };
  184. static int mode_count[] = {
  185. sizeof(cga_modes)/sizeof(struct mode_info),
  186. sizeof(ega_modes)/sizeof(struct mode_info),
  187. sizeof(vga_modes)/sizeof(struct mode_info),
  188. };
  189. u8 vga_flag;
  190. asm(INT10
  191. : "=b" (ega_bx)
  192. : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
  193. : "ecx", "edx", "esi", "edi");
  194. #ifndef _WAKEUP
  195. boot_params.screen_info.orig_video_ega_bx = ega_bx;
  196. #endif
  197. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  198. if ((u8)ega_bx != 0x10) {
  199. /* EGA/VGA */
  200. asm(INT10
  201. : "=a" (vga_flag)
  202. : "a" (0x1a00)
  203. : "ebx", "ecx", "edx", "esi", "edi");
  204. if (vga_flag == 0x1a) {
  205. adapter = ADAPTER_VGA;
  206. #ifndef _WAKEUP
  207. boot_params.screen_info.orig_video_isVGA = 1;
  208. #endif
  209. } else {
  210. adapter = ADAPTER_EGA;
  211. }
  212. } else {
  213. adapter = ADAPTER_CGA;
  214. }
  215. video_vga.modes = mode_lists[adapter];
  216. video_vga.card_name = card_name[adapter];
  217. return mode_count[adapter];
  218. }
  219. static __videocard video_vga = {
  220. .card_name = "VGA",
  221. .probe = vga_probe,
  222. .set_mode = vga_set_mode,
  223. };