blob: 39e247e96172a53c24aefbfe1c6a6beae89d01bc [file] [log] [blame]
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07001/* -*- 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
Randy Dunlap8218d022007-07-26 10:10:35 -070047 do_restore = 1; /* Assume video contents were lost */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070048 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
Pavel Macheke44b7b72008-04-10 23:28:10 +020053#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070054 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 }
Pavel Macheke44b7b72008-04-10 23:28:10 +020063#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070064 return -1;
65}
66
67static int bios_probe(void)
68{
69 u8 mode;
Pavel Macheke44b7b72008-04-10 23:28:10 +020070#ifdef _WAKEUP
71 u8 saved_mode = 0x03;
72#else
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070073 u8 saved_mode = boot_params.screen_info.orig_video_mode;
Pavel Macheke44b7b72008-04-10 23:28:10 +020074#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070075 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++) {
H. Peter Anvine6e1ace2007-10-25 16:09:38 -070088 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070089 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;
H. Peter Anvin1cac5002008-01-30 13:33:02 +0100113 mi->depth = 0; /* text */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700114 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{
H. Peter Anvin1cac5002008-01-30 13:33:02 +0100126 .card_name = "BIOS",
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700127 .probe = bios_probe,
128 .set_mode = bios_set_mode,
129 .unsafe = 1,
130 .xmode_first = VIDEO_FIRST_BIOS,
131 .xmode_n = 0x80,
132};