Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

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