video-vesa.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. * arch/i386/boot/video-vesa.c
  12. *
  13. * VESA text modes
  14. */
  15. #include "boot.h"
  16. #include "video.h"
  17. #include "vesa.h"
  18. /* VESA information */
  19. static struct vesa_general_info vginfo;
  20. static struct vesa_mode_info vminfo;
  21. __videocard video_vesa;
  22. static void vesa_store_mode_params_graphics(void);
  23. static int vesa_probe(void)
  24. {
  25. #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
  26. u16 ax, cx, di;
  27. u16 mode;
  28. addr_t mode_ptr;
  29. struct mode_info *mi;
  30. int nmodes = 0;
  31. video_vesa.modes = GET_HEAP(struct mode_info, 0);
  32. ax = 0x4f00;
  33. di = (size_t)&vginfo;
  34. asm(INT10
  35. : "+a" (ax), "+D" (di), "=m" (vginfo)
  36. : : "ebx", "ecx", "edx", "esi");
  37. if (ax != 0x004f ||
  38. vginfo.signature != VESA_MAGIC ||
  39. vginfo.version < 0x0102)
  40. return 0; /* Not present */
  41. #endif /* CONFIG_VIDEO_VESA || CONFIG_FIRMWARE_EDID */
  42. #ifdef CONFIG_VIDEO_VESA
  43. set_fs(vginfo.video_mode_ptr.seg);
  44. mode_ptr = vginfo.video_mode_ptr.off;
  45. while ((mode = rdfs16(mode_ptr)) != 0xffff) {
  46. mode_ptr += 2;
  47. if (!heap_free(sizeof(struct mode_info)))
  48. break; /* Heap full, can't save mode info */
  49. if (mode & ~0x1ff)
  50. continue;
  51. memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
  52. ax = 0x4f01;
  53. cx = mode;
  54. di = (size_t)&vminfo;
  55. asm(INT10
  56. : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
  57. : : "ebx", "edx", "esi");
  58. if (ax != 0x004f)
  59. continue;
  60. if ((vminfo.mode_attr & 0x15) == 0x05) {
  61. /* Text Mode, TTY BIOS supported,
  62. supported by hardware */
  63. mi = GET_HEAP(struct mode_info, 1);
  64. mi->mode = mode + VIDEO_FIRST_VESA;
  65. mi->depth = 0; /* text */
  66. mi->x = vminfo.h_res;
  67. mi->y = vminfo.v_res;
  68. nmodes++;
  69. } else if ((vminfo.mode_attr & 0x99) == 0x99 &&
  70. (vminfo.memory_layout == 4 ||
  71. vminfo.memory_layout == 6) &&
  72. vminfo.memory_planes == 1) {
  73. #ifdef CONFIG_FB
  74. /* Graphics mode, color, linear frame buffer
  75. supported. Only register the mode if
  76. if framebuffer is configured, however,
  77. otherwise the user will be left without a screen.
  78. We don't require CONFIG_FB_VESA, however, since
  79. some of the other framebuffer drivers can use
  80. this mode-setting, too. */
  81. mi = GET_HEAP(struct mode_info, 1);
  82. mi->mode = mode + VIDEO_FIRST_VESA;
  83. mi->depth = vminfo.bpp;
  84. mi->x = vminfo.h_res;
  85. mi->y = vminfo.v_res;
  86. nmodes++;
  87. #endif
  88. }
  89. }
  90. return nmodes;
  91. #else
  92. return 0;
  93. #endif /* CONFIG_VIDEO_VESA */
  94. }
  95. static int vesa_set_mode(struct mode_info *mode)
  96. {
  97. u16 ax, bx, cx, di;
  98. int is_graphic;
  99. u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
  100. memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
  101. ax = 0x4f01;
  102. cx = vesa_mode;
  103. di = (size_t)&vminfo;
  104. asm(INT10
  105. : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
  106. : : "ebx", "edx", "esi");
  107. if (ax != 0x004f)
  108. return -1;
  109. if ((vminfo.mode_attr & 0x15) == 0x05) {
  110. /* It's a supported text mode */
  111. is_graphic = 0;
  112. } else if ((vminfo.mode_attr & 0x99) == 0x99) {
  113. /* It's a graphics mode with linear frame buffer */
  114. is_graphic = 1;
  115. vesa_mode |= 0x4000; /* Request linear frame buffer */
  116. } else {
  117. return -1; /* Invalid mode */
  118. }
  119. ax = 0x4f02;
  120. bx = vesa_mode;
  121. di = 0;
  122. asm volatile(INT10
  123. : "+a" (ax), "+b" (bx), "+D" (di)
  124. : : "ecx", "edx", "esi");
  125. if (ax != 0x004f)
  126. return -1;
  127. graphic_mode = is_graphic;
  128. if (!is_graphic) {
  129. /* Text mode */
  130. force_x = mode->x;
  131. force_y = mode->y;
  132. do_restore = 1;
  133. } else {
  134. /* Graphics mode */
  135. vesa_store_mode_params_graphics();
  136. }
  137. return 0;
  138. }
  139. /* Switch DAC to 8-bit mode */
  140. static void vesa_dac_set_8bits(void)
  141. {
  142. u8 dac_size = 6;
  143. /* If possible, switch the DAC to 8-bit mode */
  144. if (vginfo.capabilities & 1) {
  145. u16 ax, bx;
  146. ax = 0x4f08;
  147. bx = 0x0800;
  148. asm volatile(INT10
  149. : "+a" (ax), "+b" (bx)
  150. : : "ecx", "edx", "esi", "edi");
  151. if (ax == 0x004f)
  152. dac_size = bx >> 8;
  153. }
  154. /* Set the color sizes to the DAC size, and offsets to 0 */
  155. boot_params.screen_info.red_size = dac_size;
  156. boot_params.screen_info.green_size = dac_size;
  157. boot_params.screen_info.blue_size = dac_size;
  158. boot_params.screen_info.rsvd_size = dac_size;
  159. boot_params.screen_info.red_pos = 0;
  160. boot_params.screen_info.green_pos = 0;
  161. boot_params.screen_info.blue_pos = 0;
  162. boot_params.screen_info.rsvd_pos = 0;
  163. }
  164. /* Save the VESA protected mode info */
  165. static void vesa_store_pm_info(void)
  166. {
  167. u16 ax, bx, di, es;
  168. ax = 0x4f0a;
  169. bx = di = 0;
  170. asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
  171. : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
  172. : : "ecx", "esi");
  173. if (ax != 0x004f)
  174. return;
  175. boot_params.screen_info.vesapm_seg = es;
  176. boot_params.screen_info.vesapm_off = di;
  177. }
  178. /*
  179. * Save video mode parameters for graphics mode
  180. */
  181. static void vesa_store_mode_params_graphics(void)
  182. {
  183. /* Tell the kernel we're in VESA graphics mode */
  184. boot_params.screen_info.orig_video_isVGA = 0x23;
  185. /* Mode parameters */
  186. boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
  187. boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
  188. boot_params.screen_info.lfb_width = vminfo.h_res;
  189. boot_params.screen_info.lfb_height = vminfo.v_res;
  190. boot_params.screen_info.lfb_depth = vminfo.bpp;
  191. boot_params.screen_info.pages = vminfo.image_planes;
  192. boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
  193. memcpy(&boot_params.screen_info.red_size,
  194. &vminfo.rmask, 8);
  195. /* General parameters */
  196. boot_params.screen_info.lfb_size = vginfo.total_memory;
  197. if (vminfo.bpp <= 8)
  198. vesa_dac_set_8bits();
  199. vesa_store_pm_info();
  200. }
  201. /*
  202. * Save EDID information for the kernel; this is invoked, separately,
  203. * after mode-setting.
  204. */
  205. void vesa_store_edid(void)
  206. {
  207. #ifdef CONFIG_FIRMWARE_EDID
  208. u16 ax, bx, cx, dx, di;
  209. /* Apparently used as a nonsense token... */
  210. memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
  211. if (vginfo.version < 0x0200)
  212. return; /* EDID requires VBE 2.0+ */
  213. ax = 0x4f15; /* VBE DDC */
  214. bx = 0x0000; /* Report DDC capabilities */
  215. cx = 0; /* Controller 0 */
  216. di = 0; /* ES:DI must be 0 by spec */
  217. /* Note: The VBE DDC spec is different from the main VESA spec;
  218. we genuinely have to assume all registers are destroyed here. */
  219. asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
  220. : "+a" (ax), "+b" (bx)
  221. : "c" (cx), "D" (di)
  222. : "esi");
  223. if (ax != 0x004f)
  224. return; /* No EDID */
  225. /* BH = time in seconds to transfer EDD information */
  226. /* BL = DDC level supported */
  227. ax = 0x4f15; /* VBE DDC */
  228. bx = 0x0001; /* Read EDID */
  229. cx = 0; /* Controller 0 */
  230. dx = 0; /* EDID block number */
  231. di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
  232. asm(INT10
  233. : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
  234. : "c" (cx), "D" (di)
  235. : "esi");
  236. #endif /* CONFIG_FIRMWARE_EDID */
  237. }
  238. __videocard video_vesa =
  239. {
  240. .card_name = "VESA",
  241. .probe = vesa_probe,
  242. .set_mode = vesa_set_mode,
  243. .xmode_first = VIDEO_FIRST_VESA,
  244. .xmode_n = 0x200,
  245. };