video-vesa.c 7.2 KB

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