video-vesa.c 7.2 KB

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