video-vesa.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. static __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_BOOT_VESA_SUPPORT
  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. mi = GET_HEAP(struct mode_info, 1);
  81. mi->mode = mode + VIDEO_FIRST_VESA;
  82. mi->depth = vminfo.bpp;
  83. mi->x = vminfo.h_res;
  84. mi->y = vminfo.v_res;
  85. nmodes++;
  86. #endif
  87. }
  88. }
  89. return nmodes;
  90. #else
  91. return 0;
  92. #endif /* CONFIG_VIDEO_VESA */
  93. }
  94. static int vesa_set_mode(struct mode_info *mode)
  95. {
  96. u16 ax, bx, cx, di;
  97. int is_graphic;
  98. u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
  99. memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
  100. ax = 0x4f01;
  101. cx = vesa_mode;
  102. di = (size_t)&vminfo;
  103. asm(INT10
  104. : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
  105. : : "ebx", "edx", "esi");
  106. if (ax != 0x004f)
  107. return -1;
  108. if ((vminfo.mode_attr & 0x15) == 0x05) {
  109. /* It's a supported text mode */
  110. is_graphic = 0;
  111. #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
  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. #endif
  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. #ifndef _WAKEUP
  141. /* Switch DAC to 8-bit mode */
  142. static void vesa_dac_set_8bits(void)
  143. {
  144. u8 dac_size = 6;
  145. /* If possible, switch the DAC to 8-bit mode */
  146. if (vginfo.capabilities & 1) {
  147. u16 ax, bx;
  148. ax = 0x4f08;
  149. bx = 0x0800;
  150. asm volatile(INT10
  151. : "+a" (ax), "+b" (bx)
  152. : : "ecx", "edx", "esi", "edi");
  153. if (ax == 0x004f)
  154. dac_size = bx >> 8;
  155. }
  156. /* Set the color sizes to the DAC size, and offsets to 0 */
  157. boot_params.screen_info.red_size = dac_size;
  158. boot_params.screen_info.green_size = dac_size;
  159. boot_params.screen_info.blue_size = dac_size;
  160. boot_params.screen_info.rsvd_size = dac_size;
  161. boot_params.screen_info.red_pos = 0;
  162. boot_params.screen_info.green_pos = 0;
  163. boot_params.screen_info.blue_pos = 0;
  164. boot_params.screen_info.rsvd_pos = 0;
  165. }
  166. /* Save the VESA protected mode info */
  167. static void vesa_store_pm_info(void)
  168. {
  169. u16 ax, bx, di, es;
  170. ax = 0x4f0a;
  171. bx = di = 0;
  172. asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
  173. : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
  174. : : "ecx", "esi");
  175. if (ax != 0x004f)
  176. return;
  177. boot_params.screen_info.vesapm_seg = es;
  178. boot_params.screen_info.vesapm_off = di;
  179. }
  180. /*
  181. * Save video mode parameters for graphics mode
  182. */
  183. static void vesa_store_mode_params_graphics(void)
  184. {
  185. /* Tell the kernel we're in VESA graphics mode */
  186. boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
  187. /* Mode parameters */
  188. boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
  189. boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
  190. boot_params.screen_info.lfb_width = vminfo.h_res;
  191. boot_params.screen_info.lfb_height = vminfo.v_res;
  192. boot_params.screen_info.lfb_depth = vminfo.bpp;
  193. boot_params.screen_info.pages = vminfo.image_planes;
  194. boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
  195. memcpy(&boot_params.screen_info.red_size,
  196. &vminfo.rmask, 8);
  197. /* General parameters */
  198. boot_params.screen_info.lfb_size = vginfo.total_memory;
  199. if (vminfo.bpp <= 8)
  200. vesa_dac_set_8bits();
  201. vesa_store_pm_info();
  202. }
  203. /*
  204. * Save EDID information for the kernel; this is invoked, separately,
  205. * after mode-setting.
  206. */
  207. void vesa_store_edid(void)
  208. {
  209. #ifdef CONFIG_FIRMWARE_EDID
  210. u16 ax, bx, cx, dx, di;
  211. /* Apparently used as a nonsense token... */
  212. memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
  213. if (vginfo.version < 0x0200)
  214. return; /* EDID requires VBE 2.0+ */
  215. ax = 0x4f15; /* VBE DDC */
  216. bx = 0x0000; /* Report DDC capabilities */
  217. cx = 0; /* Controller 0 */
  218. di = 0; /* ES:DI must be 0 by spec */
  219. /* Note: The VBE DDC spec is different from the main VESA spec;
  220. we genuinely have to assume all registers are destroyed here. */
  221. asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
  222. : "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
  223. : : "esi", "edx");
  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. #endif /* not _WAKEUP */
  240. static __videocard video_vesa =
  241. {
  242. .card_name = "VESA",
  243. .probe = vesa_probe,
  244. .set_mode = vesa_set_mode,
  245. .xmode_first = VIDEO_FIRST_VESA,
  246. .xmode_n = 0x200,
  247. };