vgavar.h revision 1.31 1 /* $NetBSD: vgavar.h,v 1.31 2014/08/21 13:52:22 macallan 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, void *, int, struct lwp *);
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
58 #if 0
59 int vc_biosmapped;
60 bus_space_tag_t vc_biostag;
61 bus_space_handle_t vc_bioshdl;
62 #endif
63 struct vgascreen *wantedscreen;
64 void (*switchcb)(void *, int, int);
65 void *switchcbarg;
66
67 struct callout vc_switch_callout;
68 int vc_quirks;
69 int vc_type;
70 const struct vga_funcs *vc_funcs;
71
72 u_int8_t palette[256 * 3];
73 #ifndef VGA_RASTERCONSOLE
74 int currentfontset1, currentfontset2;
75 int vc_nfontslots;
76 struct egavga_font *vc_fonts[8]; /* currently loaded */
77 TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
78 #else
79 int nfonts;
80 LIST_HEAD(, vga_raster_font) vc_fontlist;
81 #endif /* !VGA_RASTERCONSOLE */
82 };
83
84 struct vga_softc {
85 device_t sc_dev;
86 struct vga_config *sc_vc;
87 };
88
89 static __inline u_int8_t _vga_attr_read(struct vga_handle *, int);
90 static __inline void _vga_attr_write(struct vga_handle *, int, u_int8_t);
91 static __inline u_int8_t _vga_ts_read(struct vga_handle *, int);
92 static __inline void _vga_ts_write(struct vga_handle *, int, u_int8_t);
93 static __inline u_int8_t _vga_gdc_read(struct vga_handle *, int);
94 static __inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t);
95
96 #define vga_raw_read(vh, reg) \
97 bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, reg)
98 #define vga_raw_write(vh, reg, value) \
99 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, reg, value)
100
101 #define vga_enable(vh) \
102 vga_raw_write(vh, 0, 0x20)
103
104 #define vga_reset_state(vh) \
105 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10)
106
107 static __inline u_int8_t
108 _vga_attr_read(struct vga_handle *vh, int reg)
109 {
110 u_int8_t res;
111
112 /* reset state */
113 vga_reset_state(vh);
114
115 vga_raw_write(vh, VGA_ATC_INDEX, reg);
116 res = vga_raw_read(vh, VGA_ATC_DATAR);
117
118 /* XXX unneeded? */
119 vga_reset_state(vh);
120
121 vga_enable(vh);
122
123 return res;
124 }
125
126 static __inline void
127 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
128 {
129
130 vga_reset_state(vh);
131
132 vga_raw_write(vh, VGA_ATC_INDEX, reg);
133 vga_raw_write(vh, VGA_ATC_DATAW, val);
134
135 /* XXX unneeded? */
136 vga_reset_state(vh);
137
138 vga_enable(vh);
139 }
140
141 static __inline u_int8_t
142 _vga_ts_read(struct vga_handle *vh, int reg)
143 {
144
145 vga_raw_write(vh, VGA_TS_INDEX, reg);
146 return vga_raw_read(vh, VGA_TS_DATA);
147 }
148
149 static __inline void
150 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
151 {
152
153 vga_raw_write(vh, VGA_TS_INDEX, reg);
154 vga_raw_write(vh, VGA_TS_DATA, val);
155 }
156
157 static __inline u_int8_t
158 _vga_gdc_read(struct vga_handle *vh, int reg)
159 {
160
161 vga_raw_write(vh, VGA_GDC_INDEX, reg);
162 return vga_raw_read(vh, VGA_GDC_DATA);
163 }
164
165 static __inline void
166 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
167 {
168
169 vga_raw_write(vh, VGA_GDC_INDEX, reg);
170 vga_raw_write(vh, VGA_GDC_DATA, val);
171 }
172
173 #define vga_attr_read(vh, reg) \
174 _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
175 #define vga_attr_write(vh, reg, val) \
176 _vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
177 #define vga_ts_read(vh, reg) \
178 _vga_ts_read(vh, offsetof(struct reg_vgats, reg))
179 #define vga_ts_write(vh, reg, val) \
180 _vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
181 #define vga_gdc_read(vh, reg) \
182 _vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
183 #define vga_gdc_write(vh, reg, val) \
184 _vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
185
186 #define vga_6845_read(vh, reg) \
187 pcdisplay_6845_read(&(vh)->vh_ph, reg)
188 #define vga_6845_write(vh, reg, val) \
189 pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
190 #define _vga_6845_read(vh, reg) \
191 _pcdisplay_6845_read(&(vh)->vh_ph, reg)
192 #define _vga_6845_write(vh, reg, val) \
193 _pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
194
195 int vga_common_probe(bus_space_tag_t, bus_space_tag_t);
196 void vga_common_attach(struct vga_softc *, bus_space_tag_t,
197 bus_space_tag_t, int, int, const struct vga_funcs *);
198 #define VGA_QUIRK_ONEFONT 0x01
199 #define VGA_QUIRK_NOFASTSCROLL 0x02
200 int vga_is_console(bus_space_tag_t, int);
201
202 int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
203 int vga_cndetach(void);
204
205 void vga_resume(struct vga_softc *);
206
207 #ifndef VGA_RASTERCONSOLE
208 struct wsscreen_descr;
209 void vga_loadchars(struct vga_handle *, int, int, int, int, const char *);
210 void vga_readoutchars(struct vga_handle *, int, int, int, int, char *);
211 #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
212 void vga_copyfont01(struct vga_handle *);
213 #endif
214 void vga_setfontset(struct vga_handle *, int, int);
215 void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
216 #else /* !VGA_RASTERCONSOLE */
217 void vga_load_builtinfont(struct vga_handle *, u_int8_t *, int, int);
218 #endif /* !VGA_RASTERCONSOLE */
219 void vga_reset(struct vga_handle *, void (*)(struct vga_handle *));
220 void vga_initregs(struct vga_handle *);
221
222 extern int vga_no_builtinfont;
223