vgavar.h revision 1.10.8.1 1 /* $NetBSD: vgavar.h,v 1.10.8.1 2002/07/15 10:35:21 gehenna Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/callout.h>
31
32 #include "opt_vga.h"
33
34 struct vga_handle {
35 struct pcdisplay_handle vh_ph;
36 bus_space_handle_t vh_ioh_vga, vh_allmemh;
37 int vh_mono;
38 };
39 #define vh_iot vh_ph.ph_iot
40 #define vh_memt vh_ph.ph_memt
41 #define vh_ioh_6845 vh_ph.ph_ioh_6845
42 #define vh_memh vh_ph.ph_memh
43
44 struct vga_funcs {
45 int (*vf_ioctl)(void *, u_long, caddr_t, int, struct proc *);
46 paddr_t (*vf_mmap)(void *, off_t, int);
47 };
48
49 struct vga_config {
50 struct vga_handle hdl;
51 struct vga_softc *softc;
52
53 int nscreens;
54 LIST_HEAD(, vgascreen) screens;
55 struct vgascreen *active; /* current display */
56 const struct wsscreen_descr *currenttype;
57 int currentfontset1, currentfontset2;
58
59 int vc_biosmapped;
60 bus_space_tag_t vc_biostag;
61 bus_space_handle_t vc_bioshdl;
62
63 int vc_nfontslots;
64 struct egavga_font *vc_fonts[8]; /* currently loaded */
65 TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
66
67 struct vgascreen *wantedscreen;
68 void (*switchcb)(void *, int, int);
69 void *switchcbarg;
70
71 int vc_type;
72 const struct vga_funcs *vc_funcs;
73
74 struct callout vc_switch_callout;
75 int vc_quirks;
76 };
77
78 struct vga_softc {
79 struct device sc_dev;
80 struct vga_config *sc_vc;
81 };
82
83 static inline u_int8_t _vga_attr_read(struct vga_handle *, int);
84 static inline void _vga_attr_write(struct vga_handle *, int, u_int8_t);
85 static inline u_int8_t _vga_ts_read(struct vga_handle *, int);
86 static inline void _vga_ts_write(struct vga_handle *, int, u_int8_t);
87 static inline u_int8_t _vga_gdc_read(struct vga_handle *, int);
88 static inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t);
89 static inline u_int8_t _vga_crtc_read(struct vga_handle *, int);
90 static inline void _vga_crtc_write(struct vga_handle *, int, u_int8_t);
91
92 static inline u_int8_t
93 _vga_attr_read(struct vga_handle *vh, int reg)
94 {
95 u_int8_t res;
96
97 /* reset state */
98 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
99
100 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
101 res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
102
103 /* reset state XXX unneeded? */
104 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
105
106 /* enable */
107 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
108
109 return (res);
110 }
111
112 static inline void
113 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
114 {
115 /* reset state */
116 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
117
118 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
119 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
120
121 /* reset state XXX unneeded? */
122 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
123
124 /* enable */
125 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
126 }
127
128 static inline u_int8_t
129 _vga_ts_read(struct vga_handle *vh, int reg)
130 {
131 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
132 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
133 }
134
135 static inline void
136 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
137 {
138 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
139 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
140 }
141
142 static inline u_int8_t
143 _vga_gdc_read(struct vga_handle *vh, int reg)
144 {
145 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
146 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
147 }
148
149 static inline void
150 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
151 {
152 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
153 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
154 }
155
156 static inline u_int8_t
157 _vga_crtc_read(struct vga_handle *vh, int reg)
158 {
159 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
160 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA));
161 }
162
163 static inline void
164 _vga_crtc_write(struct vga_handle *vh, int reg, u_int8_t val)
165 {
166 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
167 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA, val);
168 }
169
170 #define vga_attr_read(vh, reg) \
171 _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
172 #define vga_attr_write(vh, reg, val) \
173 _vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
174 #define vga_ts_read(vh, reg) \
175 _vga_ts_read(vh, offsetof(struct reg_vgats, reg))
176 #define vga_ts_write(vh, reg, val) \
177 _vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
178 #define vga_gdc_read(vh, reg) \
179 _vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
180 #define vga_gdc_write(vh, reg, val) \
181 _vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
182
183 #define vga_6845_read(vh, reg) \
184 pcdisplay_6845_read(&(vh)->vh_ph, reg)
185 #define vga_6845_write(vh, reg, val) \
186 pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
187
188 int vga_common_probe(bus_space_tag_t, bus_space_tag_t);
189 void vga_common_attach(struct vga_softc *, bus_space_tag_t,
190 bus_space_tag_t, int, int, const struct vga_funcs *);
191 #define VGA_QUIRK_ONEFONT 0x01
192 #define VGA_QUIRK_NOFASTSCROLL 0x02
193 int vga_is_console(bus_space_tag_t, int);
194
195 int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
196
197 struct wsscreen_descr;
198 void vga_loadchars(struct vga_handle *, int, int, int, int, char *);
199 void vga_readoutchars(struct vga_handle *, int, int, int, int, char *);
200 #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
201 void vga_copyfont01(struct vga_handle *);
202 #endif
203 void vga_setfontset(struct vga_handle *, int, int);
204 void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
205