1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
8 * ----------------------------------------------------------------------- */
11 * Standard video BIOS modes
13 * We have two options for this; silent and scanned.
19 static __videocard video_bios
;
21 /* Set a conventional BIOS mode */
22 static int set_bios_mode(u8 mode
);
24 static int bios_set_mode(struct mode_info
*mi
)
26 return set_bios_mode(mi
->mode
- VIDEO_FIRST_BIOS
);
29 static int set_bios_mode(u8 mode
)
31 struct biosregs ireg
, oreg
;
35 ireg
.al
= mode
; /* AH=0x00 Set Video Mode */
36 intcall(0x10, &ireg
, NULL
);
38 ireg
.ah
= 0x0f; /* Get Current Video Mode */
39 intcall(0x10, &ireg
, &oreg
);
41 do_restore
= 1; /* Assume video contents were lost */
43 /* Not all BIOSes are clean with the top bit */
44 new_mode
= oreg
.al
& 0x7f;
47 return 0; /* Mode change OK */
50 if (new_mode
!= boot_params
.screen_info
.orig_video_mode
) {
51 /* Mode setting failed, but we didn't end up where we
52 started. That's bad. Try to revert to the original
54 ireg
.ax
= boot_params
.screen_info
.orig_video_mode
;
55 intcall(0x10, &ireg
, NULL
);
61 static int bios_probe(void)
67 u8 saved_mode
= boot_params
.screen_info
.orig_video_mode
;
73 if (adapter
!= ADAPTER_EGA
&& adapter
!= ADAPTER_VGA
)
79 video_bios
.modes
= GET_HEAP(struct mode_info
, 0);
81 for (mode
= 0x14; mode
<= 0x7f; mode
++) {
82 if (!heap_free(sizeof(struct mode_info
)))
85 if (mode_defined(VIDEO_FIRST_BIOS
+mode
))
88 if (set_bios_mode(mode
))
91 /* Try to verify that it's a text mode. */
93 /* Attribute Controller: make graphics controller disabled */
94 if (in_idx(0x3c0, 0x10) & 0x01)
97 /* Graphics Controller: verify Alpha addressing enabled */
98 if (in_idx(0x3ce, 0x06) & 0x01)
101 /* CRTC cursor location low should be zero(?) */
102 if (in_idx(crtc
, 0x0f))
105 mi
= GET_HEAP(struct mode_info
, 1);
106 mi
->mode
= VIDEO_FIRST_BIOS
+mode
;
107 mi
->depth
= 0; /* text */
108 mi
->x
= rdfs16(0x44a);
109 mi
->y
= rdfs8(0x484)+1;
113 set_bios_mode(saved_mode
);
118 static __videocard video_bios
=
122 .set_mode
= bios_set_mode
,
124 .xmode_first
= VIDEO_FIRST_BIOS
,