1 /* $NetBSD: vgavar.h,v 1.33 2015/01/14 17:45:27 chs 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@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 #ifdef _KERNEL_OPT
33 #include "opt_vga.h"
34 #endif
35 
36 struct vga_handle {
37           struct pcdisplay_handle vh_ph;
38           bus_space_handle_t vh_ioh_vga, vh_allmemh;
39           int vh_mono;
40 };
41 #define vh_iot                vh_ph.ph_iot
42 #define vh_memt     vh_ph.ph_memt
43 #define vh_ioh_6845           vh_ph.ph_ioh_6845
44 #define vh_memh     vh_ph.ph_memh
45 
46 struct vga_funcs {
47           int (*vf_ioctl)(void *, u_long, void *, int, struct lwp *);
48           paddr_t (*vf_mmap)(void *, off_t, int);
49 };
50 
51 struct vga_config {
52           struct vga_handle hdl;
53           struct vga_softc *softc;
54 
55           int nscreens;
56           LIST_HEAD(, vgascreen) screens;
57           struct vgascreen *active; /* current display */
58           const struct wsscreen_descr *currenttype;
59 
60           struct vgascreen *wantedscreen;
61           void (*switchcb)(void *, int, int);
62           void *switchcbarg;
63 
64           struct callout vc_switch_callout;
65           int vc_quirks;
66           int vc_type;
67           const struct vga_funcs *vc_funcs;
68 
69           u_int8_t palette[256 * 3];
70 #ifndef VGA_RASTERCONSOLE
71           int currentfontset1, currentfontset2;
72           int vc_nfontslots;
73           struct egavga_font *vc_fonts[8]; /* currently loaded */
74           TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
75 #else
76           int nfonts;
77           LIST_HEAD(, vga_raster_font) vc_fontlist;
78 #endif /* !VGA_RASTERCONSOLE */
79 };
80 
81 struct vga_softc {
82           device_t sc_dev;
83           struct vga_config *sc_vc;
84 };
85 
86 static __inline u_int8_t      _vga_attr_read(struct vga_handle *, int);
87 static __inline void          _vga_attr_write(struct vga_handle *, int, u_int8_t);
88 static __inline u_int8_t      _vga_ts_read(struct vga_handle *, int);
89 static __inline void          _vga_ts_write(struct vga_handle *, int, u_int8_t);
90 static __inline u_int8_t      _vga_gdc_read(struct vga_handle *, int);
91 static __inline void          _vga_gdc_write(struct vga_handle *, int, u_int8_t);
92 
93 #define   vga_raw_read(vh, reg) \
94     bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, reg)
95 #define   vga_raw_write(vh, reg, value) \
96     bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, reg, value)
97 
98 #define   vga_enable(vh) \
99     vga_raw_write(vh, 0, 0x20)
100 
101 #define vga_reset_state(vh) \
102     (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10)
103 
104 static __inline u_int8_t
_vga_attr_read(struct vga_handle * vh,int reg)105 _vga_attr_read(struct vga_handle *vh, int reg)
106 {
107           u_int8_t res;
108 
109           /* reset state */
110           vga_reset_state(vh);
111 
112           vga_raw_write(vh, VGA_ATC_INDEX, reg);
113           res = vga_raw_read(vh, VGA_ATC_DATAR);
114 
115           /* XXX unneeded? */
116           vga_reset_state(vh);
117 
118           vga_enable(vh);
119 
120           return res;
121 }
122 
123 static __inline void
_vga_attr_write(struct vga_handle * vh,int reg,u_int8_t val)124 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
125 {
126 
127           vga_reset_state(vh);
128 
129           vga_raw_write(vh, VGA_ATC_INDEX, reg);
130           vga_raw_write(vh, VGA_ATC_DATAW, val);
131 
132           /* XXX unneeded? */
133           vga_reset_state(vh);
134 
135           vga_enable(vh);
136 }
137 
138 static __inline u_int8_t
_vga_ts_read(struct vga_handle * vh,int reg)139 _vga_ts_read(struct vga_handle *vh, int reg)
140 {
141 
142           vga_raw_write(vh, VGA_TS_INDEX, reg);
143           return vga_raw_read(vh, VGA_TS_DATA);
144 }
145 
146 static __inline void
_vga_ts_write(struct vga_handle * vh,int reg,u_int8_t val)147 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
148 {
149 
150           vga_raw_write(vh, VGA_TS_INDEX, reg);
151           vga_raw_write(vh, VGA_TS_DATA, val);
152 }
153 
154 static __inline u_int8_t
_vga_gdc_read(struct vga_handle * vh,int reg)155 _vga_gdc_read(struct vga_handle *vh, int reg)
156 {
157 
158           vga_raw_write(vh, VGA_GDC_INDEX, reg);
159           return vga_raw_read(vh, VGA_GDC_DATA);
160 }
161 
162 static __inline void
_vga_gdc_write(struct vga_handle * vh,int reg,u_int8_t val)163 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
164 {
165 
166           vga_raw_write(vh, VGA_GDC_INDEX, reg);
167           vga_raw_write(vh, VGA_GDC_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 #define _vga_6845_read(vh, reg) \
188           _pcdisplay_6845_read(&(vh)->vh_ph, reg)
189 #define _vga_6845_write(vh, reg, val) \
190           _pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
191 
192 int       vga_common_probe(bus_space_tag_t, bus_space_tag_t);
193 void      vga_common_attach(struct vga_softc *, bus_space_tag_t,
194                                 bus_space_tag_t, int, int, const struct vga_funcs *);
195 #define VGA_QUIRK_ONEFONT     0x01
196 #define VGA_QUIRK_NOFASTSCROLL          0x02
197 int       vga_is_console(bus_space_tag_t, int);
198 
199 int       vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
200 int       vga_cndetach(void);
201 
202 void      vga_resume(struct vga_softc *);
203 
204 #ifndef VGA_RASTERCONSOLE
205 struct wsscreen_descr;
206 void      vga_loadchars(struct vga_handle *, int, int, int, int, const char *);
207 void      vga_readoutchars(struct vga_handle *, int, int, int, int, char *);
208 #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
209 void      vga_copyfont01(struct vga_handle *);
210 #endif
211 void      vga_setfontset(struct vga_handle *, int, int);
212 void      vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
213 #else /* !VGA_RASTERCONSOLE */
214 void      vga_load_builtinfont(struct vga_handle *, u_int8_t *, int, int);
215 #endif /* !VGA_RASTERCONSOLE */
216 void      vga_reset(struct vga_handle *, void (*)(struct vga_handle *));
217 void      vga_initregs(struct vga_handle *);
218 
219 extern int vga_no_builtinfont;
220