vgavar.h revision 1.10 1 /* $NetBSD: vgavar.h,v 1.10 2001/12/29 17:40:35 junyoung 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 struct egavga_font *vc_fonts[8]; /* currently loaded */
62 TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
63
64 struct vgascreen *wantedscreen;
65 void (*switchcb)(void *, int, int);
66 void *switchcbarg;
67
68 int vc_type;
69 const struct vga_funcs *vc_funcs;
70
71 struct callout vc_switch_callout;
72 };
73
74 struct vga_softc {
75 struct device sc_dev;
76 struct vga_config *sc_vc;
77 };
78
79 static inline u_int8_t _vga_attr_read(struct vga_handle *, int);
80 static inline void _vga_attr_write(struct vga_handle *, int, u_int8_t);
81 static inline u_int8_t _vga_ts_read(struct vga_handle *, int);
82 static inline void _vga_ts_write(struct vga_handle *, int, u_int8_t);
83 static inline u_int8_t _vga_gdc_read(struct vga_handle *, int);
84 static inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t);
85 static inline u_int8_t _vga_crtc_read(struct vga_handle *, int);
86 static inline void _vga_crtc_write(struct vga_handle *, int, u_int8_t);
87
88 static inline u_int8_t
89 _vga_attr_read(struct vga_handle *vh, int reg)
90 {
91 u_int8_t res;
92
93 /* reset state */
94 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
95
96 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
97 res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
98
99 /* reset state XXX unneeded? */
100 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
101
102 /* enable */
103 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
104
105 return (res);
106 }
107
108 static inline void
109 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
110 {
111 /* reset state */
112 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
113
114 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
115 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
116
117 /* reset state XXX unneeded? */
118 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
119
120 /* enable */
121 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
122 }
123
124 static inline u_int8_t
125 _vga_ts_read(struct vga_handle *vh, int reg)
126 {
127 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
128 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
129 }
130
131 static inline void
132 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
133 {
134 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
135 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
136 }
137
138 static inline u_int8_t
139 _vga_gdc_read(struct vga_handle *vh, int reg)
140 {
141 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
142 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
143 }
144
145 static inline void
146 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
147 {
148 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
149 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
150 }
151
152 static inline u_int8_t
153 _vga_crtc_read(struct vga_handle *vh, int reg)
154 {
155 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
156 return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA));
157 }
158
159 static inline void
160 _vga_crtc_write(struct vga_handle *vh, int reg, u_int8_t val)
161 {
162 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
163 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA, val);
164 }
165
166 #define vga_attr_read(vh, reg) \
167 _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
168 #define vga_attr_write(vh, reg, val) \
169 _vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
170 #define vga_ts_read(vh, reg) \
171 _vga_ts_read(vh, offsetof(struct reg_vgats, reg))
172 #define vga_ts_write(vh, reg, val) \
173 _vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
174 #define vga_gdc_read(vh, reg) \
175 _vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
176 #define vga_gdc_write(vh, reg, val) \
177 _vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
178
179 #define vga_6845_read(vh, reg) \
180 pcdisplay_6845_read(&(vh)->vh_ph, reg)
181 #define vga_6845_write(vh, reg, val) \
182 pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
183
184 int vga_common_probe(bus_space_tag_t, bus_space_tag_t);
185 void vga_common_attach(struct vga_softc *, bus_space_tag_t,
186 bus_space_tag_t, int, const struct vga_funcs *);
187 int vga_is_console(bus_space_tag_t, int);
188
189 int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
190
191 struct wsscreen_descr;
192 void vga_loadchars(struct vga_handle *, int, int, int, int, char *);
193 void vga_setfontset(struct vga_handle *, int, int);
194 void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
195