1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /* -*- linux-c -*- ------------------------------------------------------- *
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 1991, 1992 Linus Torvalds
5*4882a593Smuzhiyun * Copyright 2007 rPath, Inc. - All Rights Reserved
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * ----------------------------------------------------------------------- */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun * Header file for the real-mode video probing code
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #ifndef BOOT_VIDEO_H
14*4882a593Smuzhiyun #define BOOT_VIDEO_H
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <linux/types.h>
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun /*
19*4882a593Smuzhiyun * This code uses an extended set of video mode numbers. These include:
20*4882a593Smuzhiyun * Aliases for standard modes
21*4882a593Smuzhiyun * NORMAL_VGA (-1)
22*4882a593Smuzhiyun * EXTENDED_VGA (-2)
23*4882a593Smuzhiyun * ASK_VGA (-3)
24*4882a593Smuzhiyun * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
25*4882a593Smuzhiyun * of compatibility when extending the table. These are between 0x00 and 0xff.
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun #define VIDEO_FIRST_MENU 0x0000
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* Standard BIOS video modes (BIOS number + 0x0100) */
30*4882a593Smuzhiyun #define VIDEO_FIRST_BIOS 0x0100
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* VESA BIOS video modes (VESA number + 0x0200) */
33*4882a593Smuzhiyun #define VIDEO_FIRST_VESA 0x0200
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* Video7 special modes (BIOS number + 0x0900) */
36*4882a593Smuzhiyun #define VIDEO_FIRST_V7 0x0900
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /* Special video modes */
39*4882a593Smuzhiyun #define VIDEO_FIRST_SPECIAL 0x0f00
40*4882a593Smuzhiyun #define VIDEO_80x25 0x0f00
41*4882a593Smuzhiyun #define VIDEO_8POINT 0x0f01
42*4882a593Smuzhiyun #define VIDEO_80x43 0x0f02
43*4882a593Smuzhiyun #define VIDEO_80x28 0x0f03
44*4882a593Smuzhiyun #define VIDEO_CURRENT_MODE 0x0f04
45*4882a593Smuzhiyun #define VIDEO_80x30 0x0f05
46*4882a593Smuzhiyun #define VIDEO_80x34 0x0f06
47*4882a593Smuzhiyun #define VIDEO_80x60 0x0f07
48*4882a593Smuzhiyun #define VIDEO_GFX_HACK 0x0f08
49*4882a593Smuzhiyun #define VIDEO_LAST_SPECIAL 0x0f09
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* Video modes given by resolution */
52*4882a593Smuzhiyun #define VIDEO_FIRST_RESOLUTION 0x1000
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun /* The "recalculate timings" flag */
55*4882a593Smuzhiyun #define VIDEO_RECALC 0x8000
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun void store_screen(void);
58*4882a593Smuzhiyun #define DO_STORE() store_screen()
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /*
61*4882a593Smuzhiyun * Mode table structures
62*4882a593Smuzhiyun */
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun struct mode_info {
65*4882a593Smuzhiyun u16 mode; /* Mode number (vga= style) */
66*4882a593Smuzhiyun u16 x, y; /* Width, height */
67*4882a593Smuzhiyun u16 depth; /* Bits per pixel, 0 for text mode */
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun struct card_info {
71*4882a593Smuzhiyun const char *card_name;
72*4882a593Smuzhiyun int (*set_mode)(struct mode_info *mode);
73*4882a593Smuzhiyun int (*probe)(void);
74*4882a593Smuzhiyun struct mode_info *modes;
75*4882a593Smuzhiyun int nmodes; /* Number of probed modes so far */
76*4882a593Smuzhiyun int unsafe; /* Probing is unsafe, only do after "scan" */
77*4882a593Smuzhiyun u16 xmode_first; /* Unprobed modes to try to call anyway */
78*4882a593Smuzhiyun u16 xmode_n; /* Size of unprobed mode range */
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun #define __videocard struct card_info __section(".videocards") __attribute__((used))
82*4882a593Smuzhiyun extern struct card_info video_cards[], video_cards_end[];
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun int mode_defined(u16 mode); /* video.c */
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun /* Basic video information */
87*4882a593Smuzhiyun #define ADAPTER_CGA 0 /* CGA/MDA/HGC */
88*4882a593Smuzhiyun #define ADAPTER_EGA 1
89*4882a593Smuzhiyun #define ADAPTER_VGA 2
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun extern int adapter;
92*4882a593Smuzhiyun extern int force_x, force_y; /* Don't query the BIOS for cols/rows */
93*4882a593Smuzhiyun extern int do_restore; /* Restore screen contents */
94*4882a593Smuzhiyun extern int graphic_mode; /* Graphics mode with linear frame buffer */
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* Accessing VGA indexed registers */
in_idx(u16 port,u8 index)97*4882a593Smuzhiyun static inline u8 in_idx(u16 port, u8 index)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun outb(index, port);
100*4882a593Smuzhiyun return inb(port+1);
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
out_idx(u8 v,u16 port,u8 index)103*4882a593Smuzhiyun static inline void out_idx(u8 v, u16 port, u8 index)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun outw(index+(v << 8), port);
106*4882a593Smuzhiyun }
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun /* Writes a value to an indexed port and then reads the port again */
tst_idx(u8 v,u16 port,u8 index)109*4882a593Smuzhiyun static inline u8 tst_idx(u8 v, u16 port, u8 index)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun out_idx(port, index, v);
112*4882a593Smuzhiyun return in_idx(port, index);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* Get the I/O port of the VGA CRTC */
116*4882a593Smuzhiyun u16 vga_crtc(void); /* video-vga.c */
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun #endif /* BOOT_VIDEO_H */
119