video-vesa.c 6.7 KB

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