video-vesa.c 6.9 KB

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