video-vesa.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. * Copyright 2009 Intel Corporation; author H. Peter Anvin
  6. *
  7. * This file is part of the Linux kernel, and is made available under
  8. * the terms of the GNU General Public License version 2.
  9. *
  10. * ----------------------------------------------------------------------- */
  11. /*
  12. * VESA text modes
  13. */
  14. #include "boot.h"
  15. #include "video.h"
  16. #include "vesa.h"
  17. /* VESA information */
  18. static struct vesa_general_info vginfo;
  19. static struct vesa_mode_info vminfo;
  20. static __videocard video_vesa;
  21. #ifndef _WAKEUP
  22. static void vesa_store_mode_params_graphics(void);
  23. #else /* _WAKEUP */
  24. static inline void vesa_store_mode_params_graphics(void) {}
  25. #endif /* _WAKEUP */
  26. static int vesa_probe(void)
  27. {
  28. #if defined(CONFIG_VIDEO_VESA) || defined(CONFIG_FIRMWARE_EDID)
  29. struct biosregs ireg, oreg;
  30. u16 mode;
  31. addr_t mode_ptr;
  32. struct mode_info *mi;
  33. int nmodes = 0;
  34. video_vesa.modes = GET_HEAP(struct mode_info, 0);
  35. initregs(&ireg);
  36. ireg.ax = 0x4f00;
  37. ireg.di = (size_t)&vginfo;
  38. intcall(0x10, &ireg, &oreg);
  39. if (ireg.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. ireg.ax = 0x4f01;
  55. ireg.cx = mode;
  56. ireg.di = (size_t)&vminfo;
  57. intcall(0x10, &ireg, &oreg);
  58. if (ireg.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_BOOT_VESA_SUPPORT
  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. mi = GET_HEAP(struct mode_info, 1);
  79. mi->mode = mode + VIDEO_FIRST_VESA;
  80. mi->depth = vminfo.bpp;
  81. mi->x = vminfo.h_res;
  82. mi->y = vminfo.v_res;
  83. nmodes++;
  84. #endif
  85. }
  86. }
  87. return nmodes;
  88. #else
  89. return 0;
  90. #endif /* CONFIG_VIDEO_VESA */
  91. }
  92. static int vesa_set_mode(struct mode_info *mode)
  93. {
  94. struct biosregs ireg, oreg;
  95. int is_graphic;
  96. u16 vesa_mode = mode->mode - VIDEO_FIRST_VESA;
  97. memset(&vminfo, 0, sizeof vminfo); /* Just in case... */
  98. initregs(&ireg);
  99. ireg.ax = 0x4f01;
  100. ireg.cx = vesa_mode;
  101. ireg.di = (size_t)&vminfo;
  102. intcall(0x10, &ireg, &oreg);
  103. if (oreg.ax != 0x004f)
  104. return -1;
  105. if ((vminfo.mode_attr & 0x15) == 0x05) {
  106. /* It's a supported text mode */
  107. is_graphic = 0;
  108. #ifdef CONFIG_FB_BOOT_VESA_SUPPORT
  109. } else if ((vminfo.mode_attr & 0x99) == 0x99) {
  110. /* It's a graphics mode with linear frame buffer */
  111. is_graphic = 1;
  112. vesa_mode |= 0x4000; /* Request linear frame buffer */
  113. #endif
  114. } else {
  115. return -1; /* Invalid mode */
  116. }
  117. initregs(&ireg);
  118. ireg.ax = 0x4f02;
  119. ireg.bx = vesa_mode;
  120. intcall(0x10, &ireg, &oreg);
  121. if (oreg.ax != 0x004f)
  122. return -1;
  123. graphic_mode = is_graphic;
  124. if (!is_graphic) {
  125. /* Text mode */
  126. force_x = mode->x;
  127. force_y = mode->y;
  128. do_restore = 1;
  129. } else {
  130. /* Graphics mode */
  131. vesa_store_mode_params_graphics();
  132. }
  133. return 0;
  134. }
  135. #ifndef _WAKEUP
  136. /* Switch DAC to 8-bit mode */
  137. static void vesa_dac_set_8bits(void)
  138. {
  139. struct biosregs ireg, oreg;
  140. u8 dac_size = 6;
  141. /* If possible, switch the DAC to 8-bit mode */
  142. if (vginfo.capabilities & 1) {
  143. initregs(&ireg);
  144. ireg.ax = 0x4f08;
  145. ireg.bh = 0x08;
  146. intcall(0x10, &ireg, &oreg);
  147. if (oreg.ax == 0x004f)
  148. dac_size = oreg.bh;
  149. }
  150. /* Set the color sizes to the DAC size, and offsets to 0 */
  151. boot_params.screen_info.red_size = dac_size;
  152. boot_params.screen_info.green_size = dac_size;
  153. boot_params.screen_info.blue_size = dac_size;
  154. boot_params.screen_info.rsvd_size = dac_size;
  155. boot_params.screen_info.red_pos = 0;
  156. boot_params.screen_info.green_pos = 0;
  157. boot_params.screen_info.blue_pos = 0;
  158. boot_params.screen_info.rsvd_pos = 0;
  159. }
  160. /* Save the VESA protected mode info */
  161. static void vesa_store_pm_info(void)
  162. {
  163. struct biosregs ireg, oreg;
  164. initregs(&ireg);
  165. ireg.ax = 0x4f0a;
  166. intcall(0x10, &ireg, &oreg);
  167. if (oreg.ax != 0x004f)
  168. return;
  169. boot_params.screen_info.vesapm_seg = oreg.es;
  170. boot_params.screen_info.vesapm_off = oreg.di;
  171. }
  172. /*
  173. * Save video mode parameters for graphics mode
  174. */
  175. static void vesa_store_mode_params_graphics(void)
  176. {
  177. /* Tell the kernel we're in VESA graphics mode */
  178. boot_params.screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
  179. /* Mode parameters */
  180. boot_params.screen_info.vesa_attributes = vminfo.mode_attr;
  181. boot_params.screen_info.lfb_linelength = vminfo.logical_scan;
  182. boot_params.screen_info.lfb_width = vminfo.h_res;
  183. boot_params.screen_info.lfb_height = vminfo.v_res;
  184. boot_params.screen_info.lfb_depth = vminfo.bpp;
  185. boot_params.screen_info.pages = vminfo.image_planes;
  186. boot_params.screen_info.lfb_base = vminfo.lfb_ptr;
  187. memcpy(&boot_params.screen_info.red_size,
  188. &vminfo.rmask, 8);
  189. /* General parameters */
  190. boot_params.screen_info.lfb_size = vginfo.total_memory;
  191. if (vminfo.bpp <= 8)
  192. vesa_dac_set_8bits();
  193. vesa_store_pm_info();
  194. }
  195. /*
  196. * Save EDID information for the kernel; this is invoked, separately,
  197. * after mode-setting.
  198. */
  199. void vesa_store_edid(void)
  200. {
  201. #ifdef CONFIG_FIRMWARE_EDID
  202. struct biosregs ireg, oreg;
  203. /* Apparently used as a nonsense token... */
  204. memset(&boot_params.edid_info, 0x13, sizeof boot_params.edid_info);
  205. if (vginfo.version < 0x0200)
  206. return; /* EDID requires VBE 2.0+ */
  207. initregs(&ireg);
  208. ireg.ax = 0x4f15; /* VBE DDC */
  209. /* ireg.bx = 0x0000; */ /* Report DDC capabilities */
  210. /* ireg.cx = 0; */ /* Controller 0 */
  211. ireg.es = 0; /* ES:DI must be 0 by spec */
  212. intcall(0x10, &ireg, &oreg);
  213. if (oreg.ax != 0x004f)
  214. return; /* No EDID */
  215. /* BH = time in seconds to transfer EDD information */
  216. /* BL = DDC level supported */
  217. ireg.ax = 0x4f15; /* VBE DDC */
  218. ireg.bx = 0x0001; /* Read EDID */
  219. /* ireg.cx = 0; */ /* Controller 0 */
  220. /* ireg.dx = 0; */ /* EDID block number */
  221. ireg.es = ds();
  222. ireg.di =(size_t)&boot_params.edid_info; /* (ES:)Pointer to block */
  223. intcall(0x10, &ireg, &oreg);
  224. #endif /* CONFIG_FIRMWARE_EDID */
  225. }
  226. #endif /* not _WAKEUP */
  227. static __videocard video_vesa =
  228. {
  229. .card_name = "VESA",
  230. .probe = vesa_probe,
  231. .set_mode = vesa_set_mode,
  232. .xmode_first = VIDEO_FIRST_VESA,
  233. .xmode_n = 0x200,
  234. };