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