vgavar.h revision 1.11 1 /* $NetBSD: vgavar.h,v 1.11 2002/06/25 21:07:42 drochner 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 struct vga_handle {
33 struct pcdisplay_handle vh_ph;
34 bus_space_handle_t vh_ioh_vga, vh_allmemh;
35 int vh_mono;
36 };
37 #define vh_iot vh_ph.ph_iot
38 #define vh_memt vh_ph.ph_memt
39 #define vh_ioh_6845 vh_ph.ph_ioh_6845
40 #define vh_memh vh_ph.ph_memh
41
42 struct vga_funcs {
43 int (*vf_ioctl)(void *, u_long, caddr_t, int, struct proc *);
44 paddr_t (*vf_mmap)(void *, off_t, int);
45 };
46
47 struct vga_config {
48 struct vga_handle hdl;
49 struct vga_softc *softc;
50
51 int nscreens;
52 LIST_HEAD(, vgascreen) screens;
53 struct vgascreen *active; /* current display */
54 const struct wsscreen_descr *currenttype;
55 int currentfontset1, currentfontset2;
56
57 int vc_biosmapped;
58 bus_space_tag_t vc_biostag;
59 bus_space_handle_t vc_bioshdl;
60
61 int vc_nfontslots;
62 struct egavga_font *vc_fonts[8]; /* currently loaded */
63 TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
64
65 struct vgascreen *wantedscreen;
66 void (*switchcb)(void *, int, int);
67 void *switchcbarg;
68
69 int vc_type;
70 const struct vga_funcs *vc_funcs;
71
72 struct callout vc_switch_callout;
73 };
74
75 struct vga_softc {
76 struct device sc_dev;
77 struct vga_config *sc_vc;
78 };
79
80 static inline u_int8_t _vga_attr_read(struct vga_handle *, int);
81 static inline void _vga_attr_write(struct vga_handle *, int, u_int8_t);
82 static inline u_int8_t _vga_ts_read(struct vga_handle *, int);
83 static inline void _vga_ts_write(struct vga_handle *, int, u_int8_t);
84 static inline u_int8_t _vga_gdc_read(struct vga_handle *, int);
85 static inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t);
86 static inline u_int8_t _vga_crtc_read(struct vga_handle *, int);
87 static inline void _vga_crtc_write(struct vga_handle *, int, u_int8_t);
88
89 static inline u_int8_t
90 _vga_attr_read(struct vga_handle *vh, int reg)
91 {
92 u_int8_t res;
93
94 /* reset state */
95 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
96
97 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
98 res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
99
100 /* reset state XXX unneeded? */
101 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
102
103 /* enable */
104 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
105
106 return (res);
107 }
108
109 static inline void
110 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
111 {
112 /* reset state */
113 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
114
115 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
116 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
117
118 /* reset state XXX unneeded? */
119 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
120
121 /* enable */
122 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
123 }
124
125 static inline u_int8_t
126 _vga_ts_read(struct vga_handle *vh, int reg)
127 {
128 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
129 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
130 }
131
132 static inline void
133 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
134 {
135 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
136 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
137 }
138
139 static inline u_int8_t
140 _vga_gdc_read(struct vga_handle *vh, int reg)
141 {
142 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
143 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
144 }
145
146 static inline void
147 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
148 {
149 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
150 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
151 }
152
153 static inline u_int8_t
154 _vga_crtc_read(struct vga_handle *vh, int reg)
155 {
156 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
157 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA));
158 }
159
160 static inline void
161 _vga_crtc_write(struct vga_handle *vh, int reg, u_int8_t val)
162 {
163 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
164 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA, val);
165 }
166
167 #define vga_attr_read(vh, reg) \
168 _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
169 #define vga_attr_write(vh, reg, val) \
170 _vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
171 #define vga_ts_read(vh, reg) \
172 _vga_ts_read(vh, offsetof(struct reg_vgats, reg))
173 #define vga_ts_write(vh, reg, val) \
174 _vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
175 #define vga_gdc_read(vh, reg) \
176 _vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
177 #define vga_gdc_write(vh, reg, val) \
178 _vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
179
180 #define vga_6845_read(vh, reg) \
181 pcdisplay_6845_read(&(vh)->vh_ph, reg)
182 #define vga_6845_write(vh, reg, val) \
183 pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
184
185 int vga_common_probe(bus_space_tag_t, bus_space_tag_t);
186 void vga_common_attach(struct vga_softc *, bus_space_tag_t,
187 bus_space_tag_t, int, int,
188 const struct vga_funcs *);
189 #define VGA_QUIRK_ONEFONT 0x01
190 #define VGA_QUIRK_NOFASTSCROLL 0x02
191 int vga_is_console(bus_space_tag_t, int);
192
193 int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
194
195 struct wsscreen_descr;
196 void vga_loadchars(struct vga_handle *, int, int, int, int, char *);
197 void vga_setfontset(struct vga_handle *, int, int);
198 void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
199