vga.c revision 1.10 1 1.10 augustss /* $NetBSD: vga.c,v 1.10 1998/12/30 13:54:04 augustss Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 drochner * All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Author: Chris G. Demetriou
8 1.1 drochner *
9 1.1 drochner * Permission to use, copy, modify and distribute this software and
10 1.1 drochner * its documentation is hereby granted, provided that both the copyright
11 1.1 drochner * notice and this permission notice appear in all copies of the
12 1.1 drochner * software, derivative works or modified versions, and any portions
13 1.1 drochner * thereof, and that both notices appear in supporting documentation.
14 1.1 drochner *
15 1.1 drochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 drochner * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 drochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 drochner *
19 1.1 drochner * Carnegie Mellon requests users of this software to return to
20 1.1 drochner *
21 1.1 drochner * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 drochner * School of Computer Science
23 1.1 drochner * Carnegie Mellon University
24 1.1 drochner * Pittsburgh PA 15213-3890
25 1.1 drochner *
26 1.1 drochner * any improvements or extensions that they make and grant Carnegie the
27 1.1 drochner * rights to redistribute these changes.
28 1.1 drochner */
29 1.1 drochner
30 1.1 drochner #include <sys/param.h>
31 1.1 drochner #include <sys/systm.h>
32 1.1 drochner #include <sys/kernel.h>
33 1.1 drochner #include <sys/device.h>
34 1.1 drochner #include <sys/malloc.h>
35 1.1 drochner #include <sys/queue.h>
36 1.1 drochner #include <machine/bus.h>
37 1.1 drochner
38 1.1 drochner #include <dev/isa/isavar.h>
39 1.1 drochner #include <dev/isa/isareg.h>
40 1.1 drochner
41 1.4 drochner #include <dev/ic/mc6845reg.h>
42 1.4 drochner #include <dev/ic/pcdisplayvar.h>
43 1.4 drochner #include <dev/ic/vgareg.h>
44 1.4 drochner #include <dev/ic/vgavar.h>
45 1.4 drochner
46 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
47 1.1 drochner #include <dev/wscons/wsconsio.h>
48 1.1 drochner
49 1.3 drochner #include <dev/ic/pcdisplay.h>
50 1.1 drochner
51 1.1 drochner struct vgascreen {
52 1.4 drochner struct pcdisplayscreen pcs;
53 1.4 drochner
54 1.1 drochner LIST_ENTRY(vgascreen) next;
55 1.1 drochner
56 1.1 drochner struct vga_config *cfg;
57 1.1 drochner
58 1.1 drochner /* videostate */
59 1.1 drochner int fontset;
60 1.1 drochner /* font data */
61 1.1 drochner /* palette */
62 1.8 drochner
63 1.8 drochner int mindispoffset, maxdispoffset;
64 1.1 drochner };
65 1.1 drochner
66 1.1 drochner struct vga_config {
67 1.1 drochner struct vga_handle hdl;
68 1.1 drochner
69 1.1 drochner int nscreens;
70 1.1 drochner LIST_HEAD(, vgascreen) screens;
71 1.1 drochner struct vgascreen *active; /* current display */
72 1.5 drochner
73 1.5 drochner int vc_biosmapped;
74 1.5 drochner bus_space_tag_t vc_biostag;
75 1.5 drochner bus_space_handle_t vc_bioshdl;
76 1.1 drochner };
77 1.1 drochner
78 1.1 drochner static int vgaconsole, vga_console_type, vga_console_attached;
79 1.1 drochner static struct vgascreen vga_console_screen;
80 1.1 drochner static struct vga_config vga_console_vc;
81 1.1 drochner
82 1.4 drochner void vga_init_screen __P((struct vga_config *, struct vgascreen *,
83 1.4 drochner const struct wsscreen_descr *,
84 1.3 drochner int, long *));
85 1.1 drochner void vga_init __P((struct vga_config *, bus_space_tag_t,
86 1.1 drochner bus_space_tag_t));
87 1.1 drochner
88 1.3 drochner static int vga_alloc_attr __P((void *, int, int, int, long *));
89 1.8 drochner void vga_copyrows __P((void *, int, int, int));
90 1.1 drochner
91 1.1 drochner const struct wsdisplay_emulops vga_emulops = {
92 1.4 drochner pcdisplay_cursor,
93 1.7 drochner pcdisplay_mapchar,
94 1.6 drochner pcdisplay_putchar,
95 1.4 drochner pcdisplay_copycols,
96 1.4 drochner pcdisplay_erasecols,
97 1.8 drochner vga_copyrows,
98 1.4 drochner pcdisplay_eraserows,
99 1.3 drochner vga_alloc_attr
100 1.3 drochner };
101 1.3 drochner
102 1.3 drochner /*
103 1.3 drochner * translate WS(=ANSI) color codes to standard pc ones
104 1.3 drochner */
105 1.6 drochner static unsigned char fgansitopc[] = {
106 1.3 drochner #ifdef __alpha__
107 1.3 drochner /*
108 1.3 drochner * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
109 1.3 drochner * XXX We should probably not bother with this
110 1.3 drochner * XXX (reinitialize the palette registers).
111 1.3 drochner */
112 1.3 drochner FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
113 1.3 drochner FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
114 1.3 drochner #else
115 1.3 drochner FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
116 1.3 drochner FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
117 1.3 drochner #endif
118 1.3 drochner }, bgansitopc[] = {
119 1.3 drochner #ifdef __alpha__
120 1.3 drochner BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
121 1.3 drochner BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
122 1.3 drochner #else
123 1.3 drochner BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
124 1.3 drochner BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
125 1.3 drochner #endif
126 1.1 drochner };
127 1.1 drochner
128 1.1 drochner const struct wsscreen_descr vga_stdscreen = {
129 1.1 drochner "80x25", 80, 25,
130 1.1 drochner &vga_emulops,
131 1.3 drochner 8, 16,
132 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
133 1.3 drochner }, vga_stdscreen_mono = {
134 1.3 drochner "80x25", 80, 25,
135 1.3 drochner &vga_emulops,
136 1.3 drochner 8, 16,
137 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
138 1.1 drochner };
139 1.1 drochner
140 1.1 drochner const struct wsscreen_descr vga_50lscreen = {
141 1.1 drochner "80x50", 80, 50,
142 1.1 drochner &vga_emulops,
143 1.3 drochner 8, 8,
144 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
145 1.3 drochner }, vga_50lscreen_mono = {
146 1.3 drochner "80x50", 80, 50,
147 1.3 drochner &vga_emulops,
148 1.3 drochner 8, 8,
149 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
150 1.1 drochner };
151 1.1 drochner
152 1.2 drochner const struct wsscreen_descr *_vga_scrlist[] = {
153 1.1 drochner &vga_stdscreen,
154 1.1 drochner &vga_50lscreen,
155 1.1 drochner /* XXX other formats, graphics screen? */
156 1.3 drochner }, *_vga_scrlist_mono[] = {
157 1.3 drochner &vga_stdscreen_mono,
158 1.3 drochner &vga_50lscreen_mono,
159 1.3 drochner /* XXX other formats, graphics screen? */
160 1.1 drochner };
161 1.1 drochner
162 1.3 drochner const struct wsscreen_list vga_screenlist = {
163 1.3 drochner sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
164 1.3 drochner _vga_scrlist
165 1.3 drochner }, vga_screenlist_mono = {
166 1.3 drochner sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
167 1.3 drochner _vga_scrlist_mono
168 1.1 drochner };
169 1.1 drochner
170 1.1 drochner static int vga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
171 1.1 drochner static int vga_mmap __P((void *, off_t, int));
172 1.1 drochner static int vga_alloc_screen __P((void *, const struct wsscreen_descr *,
173 1.3 drochner void **, int *, int *, long *));
174 1.1 drochner static void vga_free_screen __P((void *, void *));
175 1.1 drochner static void vga_show_screen __P((void *, void *));
176 1.1 drochner static int vga_load_font __P((void *, void *, int, int, int, void *));
177 1.1 drochner
178 1.1 drochner const struct wsdisplay_accessops vga_accessops = {
179 1.1 drochner vga_ioctl,
180 1.1 drochner vga_mmap,
181 1.1 drochner vga_alloc_screen,
182 1.1 drochner vga_free_screen,
183 1.1 drochner vga_show_screen,
184 1.1 drochner vga_load_font
185 1.1 drochner };
186 1.1 drochner
187 1.1 drochner /*
188 1.1 drochner * The following functions implement back-end configuration grabbing
189 1.1 drochner * and attachment.
190 1.1 drochner */
191 1.1 drochner int
192 1.1 drochner vga_common_probe(iot, memt)
193 1.1 drochner bus_space_tag_t iot, memt;
194 1.1 drochner {
195 1.1 drochner bus_space_handle_t ioh_vga, ioh_6845, memh;
196 1.4 drochner u_int8_t regval;
197 1.1 drochner u_int16_t vgadata;
198 1.1 drochner int gotio_vga, gotio_6845, gotmem, mono, rv;
199 1.1 drochner int dispoffset;
200 1.1 drochner
201 1.1 drochner gotio_vga = gotio_6845 = gotmem = rv = 0;
202 1.1 drochner
203 1.1 drochner if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
204 1.1 drochner goto bad;
205 1.1 drochner gotio_vga = 1;
206 1.1 drochner
207 1.1 drochner /* read "misc output register" */
208 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, 0xc);
209 1.4 drochner mono = !(regval & 1);
210 1.1 drochner
211 1.1 drochner if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
212 1.1 drochner goto bad;
213 1.1 drochner gotio_6845 = 1;
214 1.1 drochner
215 1.1 drochner if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
216 1.1 drochner goto bad;
217 1.1 drochner gotmem = 1;
218 1.1 drochner
219 1.1 drochner dispoffset = (mono ? 0x10000 : 0x18000);
220 1.1 drochner
221 1.1 drochner vgadata = bus_space_read_2(memt, memh, dispoffset);
222 1.1 drochner bus_space_write_2(memt, memh, dispoffset, 0xa55a);
223 1.4 drochner if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
224 1.4 drochner goto bad;
225 1.1 drochner bus_space_write_2(memt, memh, dispoffset, vgadata);
226 1.1 drochner
227 1.4 drochner /*
228 1.4 drochner * check if this is really a VGA
229 1.4 drochner * (try to write "Color Select" register as XFree86 does)
230 1.4 drochner * XXX check before if at least EGA?
231 1.4 drochner */
232 1.4 drochner /* reset state */
233 1.4 drochner (void) bus_space_read_1(iot, ioh_6845, 10);
234 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
235 1.4 drochner 20 | 0x20); /* colselect | enable */
236 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
237 1.4 drochner /* toggle the implemented bits */
238 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
239 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
240 1.4 drochner 20 | 0x20);
241 1.4 drochner /* read back */
242 1.4 drochner if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
243 1.4 drochner goto bad;
244 1.4 drochner /* restore contents */
245 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
246 1.4 drochner
247 1.4 drochner rv = 1;
248 1.1 drochner bad:
249 1.1 drochner if (gotio_vga)
250 1.1 drochner bus_space_unmap(iot, ioh_vga, 0x10);
251 1.1 drochner if (gotio_6845)
252 1.1 drochner bus_space_unmap(iot, ioh_6845, 0x10);
253 1.1 drochner if (gotmem)
254 1.1 drochner bus_space_unmap(memt, memh, 0x20000);
255 1.1 drochner
256 1.1 drochner return (rv);
257 1.1 drochner }
258 1.1 drochner
259 1.1 drochner void
260 1.4 drochner vga_init_screen(vc, scr, type, existing, attrp)
261 1.4 drochner struct vga_config *vc;
262 1.1 drochner struct vgascreen *scr;
263 1.1 drochner const struct wsscreen_descr *type;
264 1.1 drochner int existing;
265 1.3 drochner long *attrp;
266 1.1 drochner {
267 1.8 drochner int cpos;
268 1.3 drochner int res;
269 1.1 drochner
270 1.4 drochner scr->cfg = vc;
271 1.4 drochner scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
272 1.4 drochner scr->pcs.type = type;
273 1.4 drochner scr->pcs.active = 0;
274 1.8 drochner scr->mindispoffset = 0;
275 1.8 drochner scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
276 1.1 drochner
277 1.1 drochner if (existing) {
278 1.1 drochner cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
279 1.1 drochner cpos |= vga_6845_read(&vc->hdl, cursorl);
280 1.1 drochner
281 1.1 drochner /* make sure we have a valid cursor position */
282 1.1 drochner if (cpos < 0 || cpos >= type->nrows * type->ncols)
283 1.1 drochner cpos = 0;
284 1.8 drochner
285 1.8 drochner scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
286 1.8 drochner scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
287 1.8 drochner
288 1.8 drochner /* make sure we have a valid memory offset */
289 1.8 drochner if (scr->pcs.dispoffset < scr->mindispoffset ||
290 1.8 drochner scr->pcs.dispoffset > scr->maxdispoffset)
291 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
292 1.8 drochner } else {
293 1.8 drochner cpos = 0;
294 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
295 1.1 drochner }
296 1.1 drochner
297 1.4 drochner scr->pcs.vc_crow = cpos / type->ncols;
298 1.4 drochner scr->pcs.vc_ccol = cpos % type->ncols;
299 1.4 drochner scr->pcs.cursoron = 1;
300 1.1 drochner
301 1.1 drochner #ifdef __alpha__
302 1.4 drochner if (!vc->hdl.vh_mono)
303 1.3 drochner /*
304 1.3 drochner * DEC firmware uses a blue background.
305 1.3 drochner */
306 1.3 drochner res = vga_alloc_attr(scr, WSCOL_WHITE, WSCOL_BLUE,
307 1.3 drochner WSATTR_WSCOLORS, attrp);
308 1.3 drochner else
309 1.3 drochner #endif
310 1.3 drochner res = vga_alloc_attr(scr, 0, 0, 0, attrp);
311 1.3 drochner #ifdef DIAGNOSTIC
312 1.3 drochner if (res)
313 1.3 drochner panic("vga_init_screen: attribute botch");
314 1.1 drochner #endif
315 1.1 drochner
316 1.4 drochner scr->pcs.mem = NULL;
317 1.1 drochner if (type == &vga_stdscreen) /* XXX do it better! */
318 1.1 drochner scr->fontset = 0;
319 1.1 drochner else
320 1.1 drochner scr->fontset = 1;
321 1.1 drochner
322 1.1 drochner vc->nscreens++;
323 1.1 drochner LIST_INSERT_HEAD(&vc->screens, scr, next);
324 1.1 drochner }
325 1.1 drochner
326 1.1 drochner void
327 1.1 drochner vga_init(vc, iot, memt)
328 1.1 drochner struct vga_config *vc;
329 1.1 drochner bus_space_tag_t iot, memt;
330 1.1 drochner {
331 1.1 drochner struct vga_handle *vh = &vc->hdl;
332 1.1 drochner u_int8_t mor;
333 1.1 drochner
334 1.1 drochner vh->vh_iot = iot;
335 1.1 drochner vh->vh_memt = memt;
336 1.1 drochner
337 1.1 drochner if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
338 1.1 drochner panic("vga_common_setup: couldn't map vga io");
339 1.1 drochner
340 1.1 drochner /* read "misc output register" */
341 1.1 drochner mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
342 1.4 drochner vh->vh_mono = !(mor & 1);
343 1.1 drochner
344 1.4 drochner if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
345 1.1 drochner &vh->vh_ioh_6845))
346 1.1 drochner panic("vga_common_setup: couldn't map 6845 io");
347 1.1 drochner
348 1.1 drochner if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
349 1.1 drochner panic("vga_common_setup: couldn't map memory");
350 1.1 drochner
351 1.1 drochner if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
352 1.4 drochner (vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
353 1.1 drochner &vh->vh_memh))
354 1.1 drochner panic("vga_common_setup: mem subrange failed");
355 1.5 drochner
356 1.5 drochner /* should only reserve the space (no need to map - save KVM) */
357 1.5 drochner vc->vc_biostag = memt;
358 1.5 drochner if (bus_space_map(vc->vc_biostag, 0xc0000, 0x8000, 0,
359 1.5 drochner &vc->vc_bioshdl))
360 1.5 drochner vc->vc_biosmapped = 0;
361 1.5 drochner else
362 1.5 drochner vc->vc_biosmapped = 1;
363 1.1 drochner
364 1.1 drochner vc->nscreens = 0;
365 1.1 drochner LIST_INIT(&vc->screens);
366 1.1 drochner vc->active = NULL;
367 1.1 drochner }
368 1.1 drochner
369 1.1 drochner void
370 1.1 drochner vga_common_attach(self, iot, memt, type)
371 1.1 drochner struct device *self;
372 1.1 drochner bus_space_tag_t iot, memt;
373 1.1 drochner int type;
374 1.1 drochner {
375 1.1 drochner int console;
376 1.1 drochner struct vga_config *vc;
377 1.1 drochner struct wsemuldisplaydev_attach_args aa;
378 1.1 drochner
379 1.1 drochner console = vga_is_console(iot, type);
380 1.1 drochner
381 1.1 drochner if (console) {
382 1.1 drochner vc = &vga_console_vc;
383 1.1 drochner vga_console_attached = 1;
384 1.1 drochner } else {
385 1.1 drochner vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
386 1.1 drochner vga_init(vc, iot, memt);
387 1.1 drochner }
388 1.1 drochner
389 1.1 drochner aa.console = console;
390 1.4 drochner aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
391 1.1 drochner aa.accessops = &vga_accessops;
392 1.1 drochner aa.accesscookie = vc;
393 1.1 drochner
394 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
395 1.1 drochner }
396 1.1 drochner
397 1.1 drochner int
398 1.1 drochner vga_cnattach(iot, memt, type, check)
399 1.1 drochner bus_space_tag_t iot, memt;
400 1.1 drochner int type, check;
401 1.1 drochner {
402 1.3 drochner long defattr;
403 1.3 drochner const struct wsscreen_descr *scr;
404 1.3 drochner
405 1.1 drochner if (check && !vga_common_probe(iot, memt))
406 1.1 drochner return (ENXIO);
407 1.1 drochner
408 1.1 drochner /* set up bus-independent VGA configuration */
409 1.1 drochner vga_init(&vga_console_vc, iot, memt);
410 1.4 drochner scr = vga_console_vc.hdl.vh_mono ? &vga_stdscreen_mono : &vga_stdscreen;
411 1.4 drochner vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
412 1.1 drochner
413 1.4 drochner vga_console_screen.pcs.active = 1;
414 1.1 drochner vga_console_vc.active = &vga_console_screen;
415 1.1 drochner
416 1.3 drochner wsdisplay_cnattach(scr, &vga_console_screen,
417 1.4 drochner vga_console_screen.pcs.vc_ccol,
418 1.4 drochner vga_console_screen.pcs.vc_crow,
419 1.3 drochner defattr);
420 1.1 drochner
421 1.1 drochner vgaconsole = 1;
422 1.1 drochner vga_console_type = type;
423 1.1 drochner return (0);
424 1.1 drochner }
425 1.1 drochner
426 1.1 drochner int
427 1.1 drochner vga_is_console(iot, type)
428 1.1 drochner bus_space_tag_t iot;
429 1.1 drochner int type;
430 1.1 drochner {
431 1.1 drochner if (vgaconsole &&
432 1.1 drochner !vga_console_attached &&
433 1.1 drochner iot == vga_console_vc.hdl.vh_iot &&
434 1.1 drochner (vga_console_type == -1 || (type == vga_console_type)))
435 1.1 drochner return (1);
436 1.1 drochner return (0);
437 1.1 drochner }
438 1.1 drochner
439 1.1 drochner int
440 1.1 drochner vga_ioctl(v, cmd, data, flag, p)
441 1.1 drochner void *v;
442 1.1 drochner u_long cmd;
443 1.1 drochner caddr_t data;
444 1.1 drochner int flag;
445 1.1 drochner struct proc *p;
446 1.1 drochner {
447 1.1 drochner #if 0
448 1.1 drochner struct vga_config *vc = v;
449 1.1 drochner #endif
450 1.1 drochner
451 1.1 drochner switch (cmd) {
452 1.1 drochner #if 0
453 1.1 drochner case WSDISPLAYIO_GTYPE:
454 1.1 drochner *(int *)data = vc->vc_type;
455 1.1 drochner /* XXX should get detailed hardware information here */
456 1.10 augustss return 0;
457 1.10 augustss #else
458 1.10 augustss case WSDISPLAYIO_GTYPE:
459 1.10 augustss *(int *)data = WSDISPLAY_TYPE_UNKNOWN;
460 1.1 drochner return 0;
461 1.1 drochner #endif
462 1.1 drochner case WSDISPLAYIO_GINFO:
463 1.1 drochner case WSDISPLAYIO_GETCMAP:
464 1.1 drochner case WSDISPLAYIO_PUTCMAP:
465 1.1 drochner case WSDISPLAYIO_GVIDEO:
466 1.1 drochner case WSDISPLAYIO_SVIDEO:
467 1.1 drochner case WSDISPLAYIO_GCURPOS:
468 1.1 drochner case WSDISPLAYIO_SCURPOS:
469 1.1 drochner case WSDISPLAYIO_GCURMAX:
470 1.1 drochner case WSDISPLAYIO_GCURSOR:
471 1.1 drochner case WSDISPLAYIO_SCURSOR:
472 1.1 drochner /* NONE of these operations are by the generic VGA driver. */
473 1.1 drochner return ENOTTY;
474 1.1 drochner }
475 1.1 drochner return -1;
476 1.1 drochner }
477 1.1 drochner
478 1.1 drochner static int
479 1.1 drochner vga_mmap(v, offset, prot)
480 1.1 drochner void *v;
481 1.1 drochner off_t offset;
482 1.1 drochner int prot;
483 1.1 drochner {
484 1.1 drochner
485 1.1 drochner /* XXX */
486 1.1 drochner return -1;
487 1.1 drochner }
488 1.1 drochner
489 1.1 drochner int
490 1.3 drochner vga_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
491 1.1 drochner void *v;
492 1.1 drochner const struct wsscreen_descr *type;
493 1.1 drochner void **cookiep;
494 1.1 drochner int *curxp, *curyp;
495 1.3 drochner long *defattrp;
496 1.1 drochner {
497 1.1 drochner struct vga_config *vc = v;
498 1.1 drochner struct vgascreen *scr;
499 1.1 drochner
500 1.1 drochner if (vc->nscreens == 1) {
501 1.1 drochner /*
502 1.1 drochner * When allocating the second screen, get backing store
503 1.1 drochner * for the first one too.
504 1.1 drochner * XXX We could be more clever and use video RAM.
505 1.1 drochner */
506 1.4 drochner vc->screens.lh_first->pcs.mem =
507 1.1 drochner malloc(type->ncols * type->nrows * 2, M_DEVBUF, M_WAITOK);
508 1.1 drochner }
509 1.1 drochner
510 1.1 drochner scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
511 1.4 drochner vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
512 1.1 drochner
513 1.4 drochner if (vc->nscreens == 1) {
514 1.4 drochner scr->pcs.active = 1;
515 1.1 drochner vc->active = scr;
516 1.4 drochner } else {
517 1.4 drochner scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
518 1.4 drochner M_DEVBUF, M_WAITOK);
519 1.4 drochner pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
520 1.1 drochner }
521 1.1 drochner
522 1.1 drochner *cookiep = scr;
523 1.4 drochner *curxp = scr->pcs.vc_ccol;
524 1.4 drochner *curyp = scr->pcs.vc_crow;
525 1.1 drochner
526 1.1 drochner return (0);
527 1.1 drochner }
528 1.1 drochner
529 1.1 drochner void
530 1.1 drochner vga_free_screen(v, cookie)
531 1.1 drochner void *v;
532 1.1 drochner void *cookie;
533 1.1 drochner {
534 1.1 drochner struct vgascreen *vs = cookie;
535 1.1 drochner
536 1.1 drochner LIST_REMOVE(vs, next);
537 1.1 drochner if (vs != &vga_console_screen)
538 1.1 drochner free(vs, M_DEVBUF);
539 1.1 drochner else
540 1.1 drochner panic("vga_free_screen: console");
541 1.1 drochner }
542 1.1 drochner
543 1.1 drochner void
544 1.1 drochner vga_show_screen(v, cookie)
545 1.1 drochner void *v;
546 1.1 drochner void *cookie;
547 1.1 drochner {
548 1.4 drochner struct vgascreen *scr = cookie, *oldscr;
549 1.1 drochner struct vga_config *vc = scr->cfg;
550 1.1 drochner struct vga_handle *vh = &vc->hdl;
551 1.4 drochner const struct wsscreen_descr *type = scr->pcs.type, *oldtype;
552 1.4 drochner int i;
553 1.1 drochner
554 1.4 drochner oldscr = vc->active;
555 1.4 drochner oldtype = oldscr->pcs.type;
556 1.4 drochner #ifdef DIAGNOSTIC
557 1.4 drochner if (!oldscr->pcs.active)
558 1.4 drochner panic("vga_show_screen: not active");
559 1.4 drochner #endif
560 1.4 drochner if (scr == oldscr) {
561 1.1 drochner return;
562 1.4 drochner }
563 1.4 drochner #ifdef DIAGNOSTIC
564 1.4 drochner if (scr->pcs.active)
565 1.4 drochner panic("vga_show_screen: active");
566 1.4 drochner #endif
567 1.4 drochner
568 1.4 drochner oldscr->pcs.active = 0;
569 1.1 drochner
570 1.4 drochner for (i = 0; i < oldtype->ncols * oldtype->nrows; i++)
571 1.4 drochner oldscr->pcs.mem[i] = bus_space_read_2(vh->vh_memt, vh->vh_memh,
572 1.8 drochner oldscr->pcs.dispoffset + i * 2);
573 1.1 drochner
574 1.4 drochner if (oldtype != type)
575 1.4 drochner vga_setscreentype(vh, type);
576 1.4 drochner if (oldscr->fontset != scr->fontset)
577 1.4 drochner vga_setfontset(vh, scr->fontset);
578 1.1 drochner /* swich colours */
579 1.1 drochner
580 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
581 1.8 drochner if (scr->pcs.dispoffset != oldscr->pcs.dispoffset) {
582 1.8 drochner vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
583 1.8 drochner vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
584 1.8 drochner }
585 1.8 drochner
586 1.1 drochner for (i = 0; i < type->ncols * type->nrows; i++)
587 1.4 drochner bus_space_write_2(vh->vh_memt, vh->vh_memh,
588 1.8 drochner scr->pcs.dispoffset + i * 2,
589 1.8 drochner scr->pcs.mem[i]);
590 1.1 drochner
591 1.4 drochner scr->pcs.active = 1;
592 1.4 drochner vc->active = scr;
593 1.1 drochner
594 1.4 drochner pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
595 1.4 drochner scr->pcs.vc_crow, scr->pcs.vc_ccol);
596 1.1 drochner }
597 1.1 drochner
598 1.1 drochner static int
599 1.1 drochner vga_load_font(v, cookie, first, num, stride, data)
600 1.1 drochner void *v;
601 1.1 drochner void *cookie;
602 1.1 drochner int first, num, stride;
603 1.1 drochner void *data;
604 1.1 drochner {
605 1.1 drochner struct vgascreen *scr = cookie;
606 1.1 drochner struct vga_config *vc = scr->cfg;
607 1.1 drochner
608 1.1 drochner if (stride != 1)
609 1.1 drochner return (EINVAL); /* XXX 1 byte per line */
610 1.1 drochner
611 1.1 drochner vga_loadchars(&vc->hdl, scr->fontset, first, num,
612 1.4 drochner scr->pcs.type->fontheight, data);
613 1.1 drochner return (0);
614 1.1 drochner }
615 1.1 drochner
616 1.3 drochner static int
617 1.3 drochner vga_alloc_attr(id, fg, bg, flags, attrp)
618 1.3 drochner void *id;
619 1.3 drochner int fg, bg;
620 1.3 drochner int flags;
621 1.3 drochner long *attrp;
622 1.3 drochner {
623 1.3 drochner struct vgascreen *scr = id;
624 1.3 drochner struct vga_config *vc = scr->cfg;
625 1.3 drochner
626 1.4 drochner if (vc->hdl.vh_mono) {
627 1.3 drochner if (flags & WSATTR_WSCOLORS)
628 1.3 drochner return (EINVAL);
629 1.3 drochner if (flags & WSATTR_REVERSE)
630 1.3 drochner *attrp = 0x70;
631 1.3 drochner else
632 1.3 drochner *attrp = 0x07;
633 1.3 drochner if (flags & WSATTR_UNDERLINE)
634 1.3 drochner *attrp |= FG_UNDERLINE;
635 1.3 drochner if (flags & WSATTR_HILIT)
636 1.3 drochner *attrp |= FG_INTENSE;
637 1.3 drochner } else {
638 1.3 drochner if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
639 1.3 drochner return (EINVAL);
640 1.3 drochner if (flags & WSATTR_WSCOLORS)
641 1.3 drochner *attrp = fgansitopc[fg] | bgansitopc[bg];
642 1.3 drochner else
643 1.3 drochner *attrp = 7;
644 1.3 drochner if (flags & WSATTR_HILIT)
645 1.3 drochner *attrp += 8;
646 1.3 drochner }
647 1.3 drochner if (flags & WSATTR_BLINK)
648 1.3 drochner *attrp |= FG_BLINK;
649 1.3 drochner return (0);
650 1.8 drochner }
651 1.8 drochner
652 1.8 drochner void
653 1.8 drochner vga_copyrows(id, srcrow, dstrow, nrows)
654 1.8 drochner void *id;
655 1.8 drochner int srcrow, dstrow, nrows;
656 1.8 drochner {
657 1.8 drochner struct vgascreen *scr = id;
658 1.8 drochner bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
659 1.8 drochner bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
660 1.8 drochner int ncols = scr->pcs.type->ncols;
661 1.8 drochner bus_size_t srcoff, dstoff;
662 1.8 drochner
663 1.8 drochner srcoff = srcrow * ncols + 0;
664 1.8 drochner dstoff = dstrow * ncols + 0;
665 1.8 drochner
666 1.8 drochner if (scr->pcs.active) {
667 1.8 drochner if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
668 1.8 drochner /* scroll up whole screen */
669 1.8 drochner if ((scr->pcs.dispoffset + srcrow * ncols * 2)
670 1.8 drochner <= scr->maxdispoffset) {
671 1.8 drochner scr->pcs.dispoffset += srcrow * ncols * 2;
672 1.8 drochner } else {
673 1.8 drochner bus_space_copy_region_2(memt, memh,
674 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
675 1.8 drochner memh, scr->mindispoffset,
676 1.8 drochner nrows * ncols);
677 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
678 1.8 drochner }
679 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrh,
680 1.8 drochner scr->pcs.dispoffset >> 9);
681 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrl,
682 1.8 drochner scr->pcs.dispoffset >> 1);
683 1.8 drochner } else {
684 1.8 drochner bus_space_copy_region_2(memt, memh,
685 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
686 1.8 drochner memh, scr->pcs.dispoffset + dstoff * 2,
687 1.8 drochner nrows * ncols);
688 1.8 drochner }
689 1.8 drochner } else
690 1.8 drochner bcopy(&scr->pcs.mem[srcoff], &scr->pcs.mem[dstoff],
691 1.8 drochner nrows * ncols * 2);
692 1.1 drochner }
693