video-vga.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. __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 end)
  104. {
  105. u16 crtc;
  106. u8 csel;
  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(end, 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, 0x3cc);
  119. }
  120. static void vga_set_80x30(void)
  121. {
  122. vga_set_480_scanlines(0xdf);
  123. }
  124. static void vga_set_80x34(void)
  125. {
  126. vga_set_14font();
  127. vga_set_480_scanlines(0xdb);
  128. }
  129. static void vga_set_80x60(void)
  130. {
  131. vga_set_8font();
  132. vga_set_480_scanlines(0xdf);
  133. }
  134. static int vga_set_mode(struct mode_info *mode)
  135. {
  136. /* Set the basic mode */
  137. vga_set_basic_mode();
  138. /* Override a possibly broken BIOS */
  139. force_x = mode->x;
  140. force_y = mode->y;
  141. switch (mode->mode) {
  142. case VIDEO_80x25:
  143. break;
  144. case VIDEO_8POINT:
  145. vga_set_8font();
  146. break;
  147. case VIDEO_80x43:
  148. vga_set_80x43();
  149. break;
  150. case VIDEO_80x28:
  151. vga_set_14font();
  152. break;
  153. case VIDEO_80x30:
  154. vga_set_80x30();
  155. break;
  156. case VIDEO_80x34:
  157. vga_set_80x34();
  158. break;
  159. case VIDEO_80x60:
  160. vga_set_80x60();
  161. break;
  162. }
  163. return 0;
  164. }
  165. /*
  166. * Note: this probe includes basic information required by all
  167. * systems. It should be executed first, by making sure
  168. * video-vga.c is listed first in the Makefile.
  169. */
  170. static int vga_probe(void)
  171. {
  172. u16 ega_bx;
  173. static const char *card_name[] = {
  174. "CGA/MDA/HGC", "EGA", "VGA"
  175. };
  176. static struct mode_info *mode_lists[] = {
  177. cga_modes,
  178. ega_modes,
  179. vga_modes,
  180. };
  181. static int mode_count[] = {
  182. sizeof(cga_modes)/sizeof(struct mode_info),
  183. sizeof(ega_modes)/sizeof(struct mode_info),
  184. sizeof(vga_modes)/sizeof(struct mode_info),
  185. };
  186. u8 vga_flag;
  187. asm(INT10
  188. : "=b" (ega_bx)
  189. : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
  190. : "ecx", "edx", "esi", "edi");
  191. #ifndef _WAKEUP
  192. boot_params.screen_info.orig_video_ega_bx = ega_bx;
  193. #endif
  194. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  195. if ((u8)ega_bx != 0x10) {
  196. /* EGA/VGA */
  197. asm(INT10
  198. : "=a" (vga_flag)
  199. : "a" (0x1a00)
  200. : "ebx", "ecx", "edx", "esi", "edi");
  201. if (vga_flag == 0x1a) {
  202. adapter = ADAPTER_VGA;
  203. #ifndef _WAKEUP
  204. boot_params.screen_info.orig_video_isVGA = 1;
  205. #endif
  206. } else {
  207. adapter = ADAPTER_EGA;
  208. }
  209. } else {
  210. adapter = ADAPTER_CGA;
  211. }
  212. video_vga.modes = mode_lists[adapter];
  213. video_vga.card_name = card_name[adapter];
  214. return mode_count[adapter];
  215. }
  216. __videocard video_vga = {
  217. .card_name = "VGA",
  218. .probe = vga_probe,
  219. .set_mode = vga_set_mode,
  220. };