x86: move suspend wakeup code to C
[linux-2.6/mini2440.git] / arch / x86 / boot / video-bios.c
blob39e247e96172a53c24aefbfe1c6a6beae89d01bc
1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
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.
9 * ----------------------------------------------------------------------- */
12 * arch/i386/boot/video-bios.c
14 * Standard video BIOS modes
16 * We have two options for this; silent and scanned.
19 #include "boot.h"
20 #include "video.h"
22 __videocard video_bios;
24 /* Set a conventional BIOS mode */
25 static int set_bios_mode(u8 mode);
27 static int bios_set_mode(struct mode_info *mi)
29 return set_bios_mode(mi->mode - VIDEO_FIRST_BIOS);
32 static int set_bios_mode(u8 mode)
34 u16 ax;
35 u8 new_mode;
37 ax = mode; /* AH=0x00 Set Video Mode */
38 asm volatile(INT10
39 : "+a" (ax)
40 : : "ebx", "ecx", "edx", "esi", "edi");
42 ax = 0x0f00; /* Get Current Video Mode */
43 asm volatile(INT10
44 : "+a" (ax)
45 : : "ebx", "ecx", "edx", "esi", "edi");
47 do_restore = 1; /* Assume video contents were lost */
48 new_mode = ax & 0x7f; /* Not all BIOSes are clean with the top bit */
50 if (new_mode == mode)
51 return 0; /* Mode change OK */
53 #ifndef _WAKEUP
54 if (new_mode != boot_params.screen_info.orig_video_mode) {
55 /* Mode setting failed, but we didn't end up where we
56 started. That's bad. Try to revert to the original
57 video mode. */
58 ax = boot_params.screen_info.orig_video_mode;
59 asm volatile(INT10
60 : "+a" (ax)
61 : : "ebx", "ecx", "edx", "esi", "edi");
63 #endif
64 return -1;
67 static int bios_probe(void)
69 u8 mode;
70 #ifdef _WAKEUP
71 u8 saved_mode = 0x03;
72 #else
73 u8 saved_mode = boot_params.screen_info.orig_video_mode;
74 #endif
75 u16 crtc;
76 struct mode_info *mi;
77 int nmodes = 0;
79 if (adapter != ADAPTER_EGA && adapter != ADAPTER_VGA)
80 return 0;
82 set_fs(0);
83 crtc = vga_crtc();
85 video_bios.modes = GET_HEAP(struct mode_info, 0);
87 for (mode = 0x14; mode <= 0x7f; mode++) {
88 if (!heap_free(sizeof(struct mode_info)))
89 break;
91 if (mode_defined(VIDEO_FIRST_BIOS+mode))
92 continue;
94 if (set_bios_mode(mode))
95 continue;
97 /* Try to verify that it's a text mode. */
99 /* Attribute Controller: make graphics controller disabled */
100 if (in_idx(0x3c0, 0x10) & 0x01)
101 continue;
103 /* Graphics Controller: verify Alpha addressing enabled */
104 if (in_idx(0x3ce, 0x06) & 0x01)
105 continue;
107 /* CRTC cursor location low should be zero(?) */
108 if (in_idx(crtc, 0x0f))
109 continue;
111 mi = GET_HEAP(struct mode_info, 1);
112 mi->mode = VIDEO_FIRST_BIOS+mode;
113 mi->depth = 0; /* text */
114 mi->x = rdfs16(0x44a);
115 mi->y = rdfs8(0x484)+1;
116 nmodes++;
119 set_bios_mode(saved_mode);
121 return nmodes;
124 __videocard video_bios =
126 .card_name = "BIOS",
127 .probe = bios_probe,
128 .set_mode = bios_set_mode,
129 .unsafe = 1,
130 .xmode_first = VIDEO_FIRST_BIOS,
131 .xmode_n = 0x80,