]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/boot/video-bios.c
x86: move suspend wakeup code to C
[mirror_ubuntu-artful-kernel.git] / arch / x86 / boot / video-bios.c
CommitLineData
5e8ddcbe
PA
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-bios.c
13 *
14 * Standard video BIOS modes
15 *
16 * We have two options for this; silent and scanned.
17 */
18
19#include "boot.h"
20#include "video.h"
21
22__videocard video_bios;
23
24/* Set a conventional BIOS mode */
25static int set_bios_mode(u8 mode);
26
27static int bios_set_mode(struct mode_info *mi)
28{
29 return set_bios_mode(mi->mode - VIDEO_FIRST_BIOS);
30}
31
32static int set_bios_mode(u8 mode)
33{
34 u16 ax;
35 u8 new_mode;
36
37 ax = mode; /* AH=0x00 Set Video Mode */
38 asm volatile(INT10
39 : "+a" (ax)
40 : : "ebx", "ecx", "edx", "esi", "edi");
41
42 ax = 0x0f00; /* Get Current Video Mode */
43 asm volatile(INT10
44 : "+a" (ax)
45 : : "ebx", "ecx", "edx", "esi", "edi");
46
8218d029 47 do_restore = 1; /* Assume video contents were lost */
5e8ddcbe
PA
48 new_mode = ax & 0x7f; /* Not all BIOSes are clean with the top bit */
49
50 if (new_mode == mode)
51 return 0; /* Mode change OK */
52
e44b7b75 53#ifndef _WAKEUP
5e8ddcbe
PA
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");
62 }
e44b7b75 63#endif
5e8ddcbe
PA
64 return -1;
65}
66
67static int bios_probe(void)
68{
69 u8 mode;
e44b7b75
PM
70#ifdef _WAKEUP
71 u8 saved_mode = 0x03;
72#else
5e8ddcbe 73 u8 saved_mode = boot_params.screen_info.orig_video_mode;
e44b7b75 74#endif
5e8ddcbe
PA
75 u16 crtc;
76 struct mode_info *mi;
77 int nmodes = 0;
78
79 if (adapter != ADAPTER_EGA && adapter != ADAPTER_VGA)
80 return 0;
81
82 set_fs(0);
83 crtc = vga_crtc();
84
85 video_bios.modes = GET_HEAP(struct mode_info, 0);
86
87 for (mode = 0x14; mode <= 0x7f; mode++) {
e6e1ace9 88 if (!heap_free(sizeof(struct mode_info)))
5e8ddcbe
PA
89 break;
90
91 if (mode_defined(VIDEO_FIRST_BIOS+mode))
92 continue;
93
94 if (set_bios_mode(mode))
95 continue;
96
97 /* Try to verify that it's a text mode. */
98
99 /* Attribute Controller: make graphics controller disabled */
100 if (in_idx(0x3c0, 0x10) & 0x01)
101 continue;
102
103 /* Graphics Controller: verify Alpha addressing enabled */
104 if (in_idx(0x3ce, 0x06) & 0x01)
105 continue;
106
107 /* CRTC cursor location low should be zero(?) */
108 if (in_idx(crtc, 0x0f))
109 continue;
110
111 mi = GET_HEAP(struct mode_info, 1);
112 mi->mode = VIDEO_FIRST_BIOS+mode;
1cac5004 113 mi->depth = 0; /* text */
5e8ddcbe
PA
114 mi->x = rdfs16(0x44a);
115 mi->y = rdfs8(0x484)+1;
116 nmodes++;
117 }
118
119 set_bios_mode(saved_mode);
120
121 return nmodes;
122}
123
124__videocard video_bios =
125{
1cac5004 126 .card_name = "BIOS",
5e8ddcbe
PA
127 .probe = bios_probe,
128 .set_mode = bios_set_mode,
129 .unsafe = 1,
130 .xmode_first = VIDEO_FIRST_BIOS,
131 .xmode_n = 0x80,
132};