blob: 49e0c18833e0d23361f218e3c67a51e171f600ed [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
H. Peter Anvincf06de72009-04-01 18:20:11 -07005 * Copyright 2009 Intel Corporation; author H. Peter Anvin
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07006 *
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/*
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070013 * Standard video BIOS modes
14 *
15 * We have two options for this; silent and scanned.
16 */
17
18#include "boot.h"
19#include "video.h"
20
roel kluin8bcad302008-10-21 19:49:09 -040021static __videocard video_bios;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070022
23/* Set a conventional BIOS mode */
24static int set_bios_mode(u8 mode);
25
26static int bios_set_mode(struct mode_info *mi)
27{
28 return set_bios_mode(mi->mode - VIDEO_FIRST_BIOS);
29}
30
31static int set_bios_mode(u8 mode)
32{
H. Peter Anvincf06de72009-04-01 18:20:11 -070033 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070034 u8 new_mode;
35
H. Peter Anvincf06de72009-04-01 18:20:11 -070036 initregs(&ireg);
37 ireg.al = mode; /* AH=0x00 Set Video Mode */
38 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070039
H. Peter Anvincf06de72009-04-01 18:20:11 -070040 ireg.ah = 0x0f; /* Get Current Video Mode */
41 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070042
Randy Dunlap8218d022007-07-26 10:10:35 -070043 do_restore = 1; /* Assume video contents were lost */
H. Peter Anvincf06de72009-04-01 18:20:11 -070044
45 /* Not all BIOSes are clean with the top bit */
Akinobu Mitafebe04d2009-07-01 11:13:07 +090046 new_mode = oreg.al & 0x7f;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070047
48 if (new_mode == mode)
49 return 0; /* Mode change OK */
50
Pavel Macheke44b7b72008-04-10 23:28:10 +020051#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070052 if (new_mode != boot_params.screen_info.orig_video_mode) {
53 /* Mode setting failed, but we didn't end up where we
54 started. That's bad. Try to revert to the original
55 video mode. */
H. Peter Anvincf06de72009-04-01 18:20:11 -070056 ireg.ax = boot_params.screen_info.orig_video_mode;
57 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070058 }
Pavel Macheke44b7b72008-04-10 23:28:10 +020059#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070060 return -1;
61}
62
63static int bios_probe(void)
64{
65 u8 mode;
Pavel Macheke44b7b72008-04-10 23:28:10 +020066#ifdef _WAKEUP
67 u8 saved_mode = 0x03;
68#else
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070069 u8 saved_mode = boot_params.screen_info.orig_video_mode;
Pavel Macheke44b7b72008-04-10 23:28:10 +020070#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070071 u16 crtc;
72 struct mode_info *mi;
73 int nmodes = 0;
74
75 if (adapter != ADAPTER_EGA && adapter != ADAPTER_VGA)
76 return 0;
77
78 set_fs(0);
79 crtc = vga_crtc();
80
81 video_bios.modes = GET_HEAP(struct mode_info, 0);
82
83 for (mode = 0x14; mode <= 0x7f; mode++) {
H. Peter Anvine6e1ace2007-10-25 16:09:38 -070084 if (!heap_free(sizeof(struct mode_info)))
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070085 break;
86
87 if (mode_defined(VIDEO_FIRST_BIOS+mode))
88 continue;
89
90 if (set_bios_mode(mode))
91 continue;
92
93 /* Try to verify that it's a text mode. */
94
95 /* Attribute Controller: make graphics controller disabled */
96 if (in_idx(0x3c0, 0x10) & 0x01)
97 continue;
98
99 /* Graphics Controller: verify Alpha addressing enabled */
100 if (in_idx(0x3ce, 0x06) & 0x01)
101 continue;
102
103 /* CRTC cursor location low should be zero(?) */
104 if (in_idx(crtc, 0x0f))
105 continue;
106
107 mi = GET_HEAP(struct mode_info, 1);
108 mi->mode = VIDEO_FIRST_BIOS+mode;
H. Peter Anvin1cac5002008-01-30 13:33:02 +0100109 mi->depth = 0; /* text */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700110 mi->x = rdfs16(0x44a);
111 mi->y = rdfs8(0x484)+1;
112 nmodes++;
113 }
114
115 set_bios_mode(saved_mode);
116
117 return nmodes;
118}
119
roel kluin8bcad302008-10-21 19:49:09 -0400120static __videocard video_bios =
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700121{
H. Peter Anvin1cac5002008-01-30 13:33:02 +0100122 .card_name = "BIOS",
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700123 .probe = bios_probe,
124 .set_mode = bios_set_mode,
125 .unsafe = 1,
126 .xmode_first = VIDEO_FIRST_BIOS,
127 .xmode_n = 0x80,
128};