vga.c revision 1.34 1 1.34 drochner /* $NetBSD: vga.c,v 1.34 2000/09/15 14:13:01 drochner 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.26 thorpej #include <sys/callout.h>
33 1.1 drochner #include <sys/kernel.h>
34 1.1 drochner #include <sys/device.h>
35 1.1 drochner #include <sys/malloc.h>
36 1.1 drochner #include <sys/queue.h>
37 1.1 drochner #include <machine/bus.h>
38 1.1 drochner
39 1.4 drochner #include <dev/ic/mc6845reg.h>
40 1.4 drochner #include <dev/ic/pcdisplayvar.h>
41 1.4 drochner #include <dev/ic/vgareg.h>
42 1.4 drochner #include <dev/ic/vgavar.h>
43 1.4 drochner
44 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
45 1.1 drochner #include <dev/wscons/wsconsio.h>
46 1.14 drochner #include <dev/wscons/unicode.h>
47 1.1 drochner
48 1.3 drochner #include <dev/ic/pcdisplay.h>
49 1.1 drochner
50 1.16 drochner #include "opt_wsdisplay_compat.h" /* for WSCONS_SUPPORT_PCVTFONTS */
51 1.16 drochner
52 1.12 drochner static struct vgafont {
53 1.12 drochner char name[16];
54 1.12 drochner int height;
55 1.12 drochner int encoding;
56 1.12 drochner #ifdef notyet
57 1.12 drochner int firstchar, numchars;
58 1.12 drochner #endif
59 1.12 drochner int slot;
60 1.12 drochner } vga_builtinfont = {
61 1.12 drochner "builtin",
62 1.12 drochner 16,
63 1.12 drochner WSDISPLAY_FONTENC_IBM,
64 1.12 drochner #ifdef notyet
65 1.12 drochner 0, 256,
66 1.12 drochner #endif
67 1.12 drochner 0
68 1.12 drochner };
69 1.12 drochner
70 1.1 drochner struct vgascreen {
71 1.4 drochner struct pcdisplayscreen pcs;
72 1.4 drochner
73 1.1 drochner LIST_ENTRY(vgascreen) next;
74 1.1 drochner
75 1.1 drochner struct vga_config *cfg;
76 1.1 drochner
77 1.1 drochner /* videostate */
78 1.12 drochner struct vgafont *fontset1, *fontset2;
79 1.1 drochner /* font data */
80 1.1 drochner /* palette */
81 1.8 drochner
82 1.8 drochner int mindispoffset, maxdispoffset;
83 1.1 drochner };
84 1.1 drochner
85 1.1 drochner struct vga_config {
86 1.1 drochner struct vga_handle hdl;
87 1.1 drochner
88 1.1 drochner int nscreens;
89 1.1 drochner LIST_HEAD(, vgascreen) screens;
90 1.1 drochner struct vgascreen *active; /* current display */
91 1.11 drochner const struct wsscreen_descr *currenttype;
92 1.12 drochner int currentfontset1, currentfontset2;
93 1.5 drochner
94 1.5 drochner int vc_biosmapped;
95 1.5 drochner bus_space_tag_t vc_biostag;
96 1.5 drochner bus_space_handle_t vc_bioshdl;
97 1.12 drochner
98 1.12 drochner struct vgafont *vc_fonts[8];
99 1.22 drochner
100 1.22 drochner struct vgascreen *wantedscreen;
101 1.22 drochner void (*switchcb) __P((void *, int, int));
102 1.22 drochner void *switchcbarg;
103 1.26 thorpej
104 1.29 simonb paddr_t (*vc_mmap) __P((void *, off_t, int));
105 1.28 soda
106 1.26 thorpej struct callout vc_switch_callout;
107 1.1 drochner };
108 1.1 drochner
109 1.1 drochner static int vgaconsole, vga_console_type, vga_console_attached;
110 1.1 drochner static struct vgascreen vga_console_screen;
111 1.1 drochner static struct vga_config vga_console_vc;
112 1.1 drochner
113 1.12 drochner int vga_selectfont __P((struct vga_config *, struct vgascreen *,
114 1.12 drochner char *, char *));
115 1.4 drochner void vga_init_screen __P((struct vga_config *, struct vgascreen *,
116 1.4 drochner const struct wsscreen_descr *,
117 1.3 drochner int, long *));
118 1.1 drochner void vga_init __P((struct vga_config *, bus_space_tag_t,
119 1.1 drochner bus_space_tag_t));
120 1.12 drochner static void vga_setfont __P((struct vga_config *, struct vgascreen *));
121 1.1 drochner
122 1.13 drochner static int vga_mapchar __P((void *, int, unsigned int *));
123 1.3 drochner static int vga_alloc_attr __P((void *, int, int, int, long *));
124 1.8 drochner void vga_copyrows __P((void *, int, int, int));
125 1.1 drochner
126 1.1 drochner const struct wsdisplay_emulops vga_emulops = {
127 1.4 drochner pcdisplay_cursor,
128 1.12 drochner vga_mapchar,
129 1.6 drochner pcdisplay_putchar,
130 1.4 drochner pcdisplay_copycols,
131 1.4 drochner pcdisplay_erasecols,
132 1.8 drochner vga_copyrows,
133 1.4 drochner pcdisplay_eraserows,
134 1.3 drochner vga_alloc_attr
135 1.3 drochner };
136 1.3 drochner
137 1.3 drochner /*
138 1.3 drochner * translate WS(=ANSI) color codes to standard pc ones
139 1.3 drochner */
140 1.6 drochner static unsigned char fgansitopc[] = {
141 1.3 drochner #ifdef __alpha__
142 1.3 drochner /*
143 1.3 drochner * XXX DEC HAS SWITCHED THE CODES FOR BLUE AND RED!!!
144 1.3 drochner * XXX We should probably not bother with this
145 1.3 drochner * XXX (reinitialize the palette registers).
146 1.3 drochner */
147 1.3 drochner FG_BLACK, FG_BLUE, FG_GREEN, FG_CYAN, FG_RED,
148 1.3 drochner FG_MAGENTA, FG_BROWN, FG_LIGHTGREY
149 1.3 drochner #else
150 1.3 drochner FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
151 1.3 drochner FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
152 1.3 drochner #endif
153 1.3 drochner }, bgansitopc[] = {
154 1.3 drochner #ifdef __alpha__
155 1.3 drochner BG_BLACK, BG_BLUE, BG_GREEN, BG_CYAN, BG_RED,
156 1.3 drochner BG_MAGENTA, BG_BROWN, BG_LIGHTGREY
157 1.3 drochner #else
158 1.3 drochner BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
159 1.3 drochner BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
160 1.3 drochner #endif
161 1.1 drochner };
162 1.1 drochner
163 1.33 lukem const struct wsscreen_descr vga_25lscreen = {
164 1.1 drochner "80x25", 80, 25,
165 1.1 drochner &vga_emulops,
166 1.3 drochner 8, 16,
167 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
168 1.33 lukem }, vga_25lscreen_mono = {
169 1.3 drochner "80x25", 80, 25,
170 1.3 drochner &vga_emulops,
171 1.3 drochner 8, 16,
172 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
173 1.33 lukem }, vga_25lscreen_bf = {
174 1.12 drochner "80x25bf", 80, 25,
175 1.12 drochner &vga_emulops,
176 1.12 drochner 8, 16,
177 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
178 1.17 drochner }, vga_40lscreen = {
179 1.17 drochner "80x40", 80, 40,
180 1.17 drochner &vga_emulops,
181 1.17 drochner 8, 10,
182 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
183 1.17 drochner }, vga_40lscreen_mono = {
184 1.17 drochner "80x40", 80, 40,
185 1.17 drochner &vga_emulops,
186 1.17 drochner 8, 10,
187 1.17 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
188 1.17 drochner }, vga_40lscreen_bf = {
189 1.17 drochner "80x40bf", 80, 40,
190 1.17 drochner &vga_emulops,
191 1.17 drochner 8, 10,
192 1.17 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
193 1.12 drochner }, vga_50lscreen = {
194 1.1 drochner "80x50", 80, 50,
195 1.1 drochner &vga_emulops,
196 1.3 drochner 8, 8,
197 1.3 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
198 1.3 drochner }, vga_50lscreen_mono = {
199 1.3 drochner "80x50", 80, 50,
200 1.3 drochner &vga_emulops,
201 1.3 drochner 8, 8,
202 1.3 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
203 1.12 drochner }, vga_50lscreen_bf = {
204 1.12 drochner "80x50bf", 80, 50,
205 1.12 drochner &vga_emulops,
206 1.12 drochner 8, 8,
207 1.12 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
208 1.30 drochner }, vga_24lscreen = {
209 1.30 drochner "80x24", 80, 24,
210 1.30 drochner &vga_emulops,
211 1.30 drochner 8, 16,
212 1.30 drochner WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
213 1.30 drochner }, vga_24lscreen_mono = {
214 1.30 drochner "80x24", 80, 24,
215 1.30 drochner &vga_emulops,
216 1.30 drochner 8, 16,
217 1.30 drochner WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
218 1.30 drochner }, vga_24lscreen_bf = {
219 1.30 drochner "80x24bf", 80, 24,
220 1.30 drochner &vga_emulops,
221 1.30 drochner 8, 16,
222 1.30 drochner WSSCREEN_WSCOLORS | WSSCREEN_BLINK
223 1.1 drochner };
224 1.1 drochner
225 1.12 drochner #define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
226 1.12 drochner
227 1.2 drochner const struct wsscreen_descr *_vga_scrlist[] = {
228 1.33 lukem &vga_25lscreen,
229 1.33 lukem &vga_25lscreen_bf,
230 1.17 drochner &vga_40lscreen,
231 1.17 drochner &vga_40lscreen_bf,
232 1.1 drochner &vga_50lscreen,
233 1.12 drochner &vga_50lscreen_bf,
234 1.30 drochner &vga_24lscreen,
235 1.30 drochner &vga_24lscreen_bf,
236 1.1 drochner /* XXX other formats, graphics screen? */
237 1.3 drochner }, *_vga_scrlist_mono[] = {
238 1.33 lukem &vga_25lscreen_mono,
239 1.17 drochner &vga_40lscreen_mono,
240 1.3 drochner &vga_50lscreen_mono,
241 1.30 drochner &vga_24lscreen_mono,
242 1.3 drochner /* XXX other formats, graphics screen? */
243 1.1 drochner };
244 1.1 drochner
245 1.3 drochner const struct wsscreen_list vga_screenlist = {
246 1.3 drochner sizeof(_vga_scrlist) / sizeof(struct wsscreen_descr *),
247 1.3 drochner _vga_scrlist
248 1.3 drochner }, vga_screenlist_mono = {
249 1.3 drochner sizeof(_vga_scrlist_mono) / sizeof(struct wsscreen_descr *),
250 1.3 drochner _vga_scrlist_mono
251 1.1 drochner };
252 1.1 drochner
253 1.1 drochner static int vga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
254 1.29 simonb static paddr_t vga_mmap __P((void *, off_t, int));
255 1.1 drochner static int vga_alloc_screen __P((void *, const struct wsscreen_descr *,
256 1.3 drochner void **, int *, int *, long *));
257 1.1 drochner static void vga_free_screen __P((void *, void *));
258 1.22 drochner static int vga_show_screen __P((void *, void *, int,
259 1.22 drochner void (*) (void *, int, int), void *));
260 1.12 drochner static int vga_load_font __P((void *, void *, struct wsdisplay_font *));
261 1.1 drochner
262 1.22 drochner void vga_doswitch __P((struct vga_config *));
263 1.22 drochner
264 1.1 drochner const struct wsdisplay_accessops vga_accessops = {
265 1.1 drochner vga_ioctl,
266 1.1 drochner vga_mmap,
267 1.1 drochner vga_alloc_screen,
268 1.1 drochner vga_free_screen,
269 1.1 drochner vga_show_screen,
270 1.1 drochner vga_load_font
271 1.1 drochner };
272 1.1 drochner
273 1.1 drochner /*
274 1.1 drochner * The following functions implement back-end configuration grabbing
275 1.1 drochner * and attachment.
276 1.1 drochner */
277 1.1 drochner int
278 1.1 drochner vga_common_probe(iot, memt)
279 1.1 drochner bus_space_tag_t iot, memt;
280 1.1 drochner {
281 1.1 drochner bus_space_handle_t ioh_vga, ioh_6845, memh;
282 1.4 drochner u_int8_t regval;
283 1.1 drochner u_int16_t vgadata;
284 1.1 drochner int gotio_vga, gotio_6845, gotmem, mono, rv;
285 1.1 drochner int dispoffset;
286 1.1 drochner
287 1.1 drochner gotio_vga = gotio_6845 = gotmem = rv = 0;
288 1.1 drochner
289 1.1 drochner if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
290 1.1 drochner goto bad;
291 1.1 drochner gotio_vga = 1;
292 1.1 drochner
293 1.1 drochner /* read "misc output register" */
294 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, 0xc);
295 1.4 drochner mono = !(regval & 1);
296 1.1 drochner
297 1.1 drochner if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
298 1.1 drochner goto bad;
299 1.1 drochner gotio_6845 = 1;
300 1.1 drochner
301 1.1 drochner if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
302 1.1 drochner goto bad;
303 1.1 drochner gotmem = 1;
304 1.1 drochner
305 1.1 drochner dispoffset = (mono ? 0x10000 : 0x18000);
306 1.1 drochner
307 1.1 drochner vgadata = bus_space_read_2(memt, memh, dispoffset);
308 1.1 drochner bus_space_write_2(memt, memh, dispoffset, 0xa55a);
309 1.4 drochner if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
310 1.4 drochner goto bad;
311 1.1 drochner bus_space_write_2(memt, memh, dispoffset, vgadata);
312 1.1 drochner
313 1.4 drochner /*
314 1.4 drochner * check if this is really a VGA
315 1.4 drochner * (try to write "Color Select" register as XFree86 does)
316 1.4 drochner * XXX check before if at least EGA?
317 1.4 drochner */
318 1.4 drochner /* reset state */
319 1.4 drochner (void) bus_space_read_1(iot, ioh_6845, 10);
320 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
321 1.4 drochner 20 | 0x20); /* colselect | enable */
322 1.4 drochner regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
323 1.4 drochner /* toggle the implemented bits */
324 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
325 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
326 1.4 drochner 20 | 0x20);
327 1.4 drochner /* read back */
328 1.4 drochner if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
329 1.4 drochner goto bad;
330 1.4 drochner /* restore contents */
331 1.4 drochner bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
332 1.4 drochner
333 1.4 drochner rv = 1;
334 1.1 drochner bad:
335 1.1 drochner if (gotio_vga)
336 1.1 drochner bus_space_unmap(iot, ioh_vga, 0x10);
337 1.1 drochner if (gotio_6845)
338 1.1 drochner bus_space_unmap(iot, ioh_6845, 0x10);
339 1.1 drochner if (gotmem)
340 1.1 drochner bus_space_unmap(memt, memh, 0x20000);
341 1.1 drochner
342 1.1 drochner return (rv);
343 1.1 drochner }
344 1.1 drochner
345 1.12 drochner /*
346 1.15 drochner * We want at least ASCII 32..127 be present in the
347 1.15 drochner * first font slot.
348 1.12 drochner */
349 1.12 drochner #define vga_valid_primary_font(f) \
350 1.12 drochner (f->encoding == WSDISPLAY_FONTENC_IBM || \
351 1.34 drochner f->encoding == WSDISPLAY_FONTENC_ISO || \
352 1.34 drochner f->encoding == WSDISPLAY_FONTENC_ISO7)
353 1.12 drochner
354 1.12 drochner int
355 1.12 drochner vga_selectfont(vc, scr, name1, name2)
356 1.12 drochner struct vga_config *vc;
357 1.12 drochner struct vgascreen *scr;
358 1.15 drochner char *name1, *name2; /* NULL: take first found */
359 1.12 drochner {
360 1.12 drochner const struct wsscreen_descr *type = scr->pcs.type;
361 1.12 drochner struct vgafont *f1, *f2;
362 1.12 drochner int i;
363 1.12 drochner
364 1.12 drochner f1 = f2 = 0;
365 1.12 drochner
366 1.12 drochner for (i = 0; i < 8; i++) {
367 1.12 drochner struct vgafont *f = vc->vc_fonts[i];
368 1.12 drochner if (!f || f->height != type->fontheight)
369 1.12 drochner continue;
370 1.12 drochner if (!f1 &&
371 1.12 drochner vga_valid_primary_font(f) &&
372 1.12 drochner (!name1 || !strcmp(name1, f->name))) {
373 1.12 drochner f1 = f;
374 1.12 drochner continue;
375 1.12 drochner }
376 1.12 drochner if (!f2 &&
377 1.12 drochner VGA_SCREEN_CANTWOFONTS(type) &&
378 1.12 drochner (!name2 || !strcmp(name2, f->name))) {
379 1.12 drochner f2 = f;
380 1.12 drochner continue;
381 1.12 drochner }
382 1.12 drochner }
383 1.12 drochner
384 1.15 drochner /*
385 1.15 drochner * The request fails if no primary font was found,
386 1.15 drochner * or if a second font was requested but not found.
387 1.15 drochner */
388 1.12 drochner if (f1 && (!name2 || f2)) {
389 1.12 drochner #ifdef VGAFONTDEBUG
390 1.12 drochner if (scr != &vga_console_screen || vga_console_attached) {
391 1.12 drochner printf("vga (%s): font1=%s (slot %d)", type->name,
392 1.12 drochner f1->name, f1->slot);
393 1.12 drochner if (f2)
394 1.12 drochner printf(", font2=%s (slot %d)",
395 1.12 drochner f2->name, f2->slot);
396 1.12 drochner printf("\n");
397 1.12 drochner }
398 1.12 drochner #endif
399 1.12 drochner scr->fontset1 = f1;
400 1.12 drochner scr->fontset2 = f2;
401 1.12 drochner return (0);
402 1.12 drochner }
403 1.12 drochner return (ENXIO);
404 1.12 drochner }
405 1.12 drochner
406 1.1 drochner void
407 1.4 drochner vga_init_screen(vc, scr, type, existing, attrp)
408 1.4 drochner struct vga_config *vc;
409 1.1 drochner struct vgascreen *scr;
410 1.1 drochner const struct wsscreen_descr *type;
411 1.1 drochner int existing;
412 1.3 drochner long *attrp;
413 1.1 drochner {
414 1.8 drochner int cpos;
415 1.3 drochner int res;
416 1.1 drochner
417 1.4 drochner scr->cfg = vc;
418 1.4 drochner scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
419 1.4 drochner scr->pcs.type = type;
420 1.4 drochner scr->pcs.active = 0;
421 1.8 drochner scr->mindispoffset = 0;
422 1.8 drochner scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
423 1.1 drochner
424 1.1 drochner if (existing) {
425 1.1 drochner cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
426 1.1 drochner cpos |= vga_6845_read(&vc->hdl, cursorl);
427 1.1 drochner
428 1.1 drochner /* make sure we have a valid cursor position */
429 1.1 drochner if (cpos < 0 || cpos >= type->nrows * type->ncols)
430 1.1 drochner cpos = 0;
431 1.8 drochner
432 1.8 drochner scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
433 1.8 drochner scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
434 1.8 drochner
435 1.8 drochner /* make sure we have a valid memory offset */
436 1.8 drochner if (scr->pcs.dispoffset < scr->mindispoffset ||
437 1.8 drochner scr->pcs.dispoffset > scr->maxdispoffset)
438 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
439 1.8 drochner } else {
440 1.8 drochner cpos = 0;
441 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
442 1.1 drochner }
443 1.1 drochner
444 1.4 drochner scr->pcs.vc_crow = cpos / type->ncols;
445 1.4 drochner scr->pcs.vc_ccol = cpos % type->ncols;
446 1.25 ad pcdisplay_cursor_init(&scr->pcs, existing);
447 1.1 drochner
448 1.1 drochner #ifdef __alpha__
449 1.4 drochner if (!vc->hdl.vh_mono)
450 1.3 drochner /*
451 1.3 drochner * DEC firmware uses a blue background.
452 1.3 drochner */
453 1.3 drochner res = vga_alloc_attr(scr, WSCOL_WHITE, WSCOL_BLUE,
454 1.3 drochner WSATTR_WSCOLORS, attrp);
455 1.3 drochner else
456 1.3 drochner #endif
457 1.3 drochner res = vga_alloc_attr(scr, 0, 0, 0, attrp);
458 1.3 drochner #ifdef DIAGNOSTIC
459 1.3 drochner if (res)
460 1.3 drochner panic("vga_init_screen: attribute botch");
461 1.1 drochner #endif
462 1.1 drochner
463 1.4 drochner scr->pcs.mem = NULL;
464 1.15 drochner
465 1.15 drochner scr->fontset1 = scr->fontset2 = 0;
466 1.12 drochner if (vga_selectfont(vc, scr, 0, 0)) {
467 1.12 drochner if (scr == &vga_console_screen)
468 1.12 drochner panic("vga_init_screen: no font");
469 1.12 drochner else
470 1.12 drochner printf("vga_init_screen: no font\n");
471 1.12 drochner }
472 1.15 drochner
473 1.1 drochner vc->nscreens++;
474 1.1 drochner LIST_INSERT_HEAD(&vc->screens, scr, next);
475 1.1 drochner }
476 1.1 drochner
477 1.1 drochner void
478 1.1 drochner vga_init(vc, iot, memt)
479 1.1 drochner struct vga_config *vc;
480 1.1 drochner bus_space_tag_t iot, memt;
481 1.1 drochner {
482 1.1 drochner struct vga_handle *vh = &vc->hdl;
483 1.1 drochner u_int8_t mor;
484 1.12 drochner int i;
485 1.1 drochner
486 1.1 drochner vh->vh_iot = iot;
487 1.1 drochner vh->vh_memt = memt;
488 1.1 drochner
489 1.1 drochner if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
490 1.1 drochner panic("vga_common_setup: couldn't map vga io");
491 1.1 drochner
492 1.1 drochner /* read "misc output register" */
493 1.1 drochner mor = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, 0xc);
494 1.4 drochner vh->vh_mono = !(mor & 1);
495 1.1 drochner
496 1.4 drochner if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
497 1.1 drochner &vh->vh_ioh_6845))
498 1.1 drochner panic("vga_common_setup: couldn't map 6845 io");
499 1.1 drochner
500 1.1 drochner if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
501 1.1 drochner panic("vga_common_setup: couldn't map memory");
502 1.1 drochner
503 1.1 drochner if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
504 1.4 drochner (vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
505 1.1 drochner &vh->vh_memh))
506 1.1 drochner panic("vga_common_setup: mem subrange failed");
507 1.5 drochner
508 1.5 drochner /* should only reserve the space (no need to map - save KVM) */
509 1.5 drochner vc->vc_biostag = memt;
510 1.5 drochner if (bus_space_map(vc->vc_biostag, 0xc0000, 0x8000, 0,
511 1.5 drochner &vc->vc_bioshdl))
512 1.5 drochner vc->vc_biosmapped = 0;
513 1.5 drochner else
514 1.5 drochner vc->vc_biosmapped = 1;
515 1.1 drochner
516 1.1 drochner vc->nscreens = 0;
517 1.1 drochner LIST_INIT(&vc->screens);
518 1.1 drochner vc->active = NULL;
519 1.34 drochner vc->currenttype = vh->vh_mono ? &vga_25lscreen_mono : &vga_25lscreen;
520 1.26 thorpej callout_init(&vc->vc_switch_callout);
521 1.12 drochner
522 1.12 drochner vc->vc_fonts[0] = &vga_builtinfont;
523 1.23 drochner for (i = 1; i < 8; i++)
524 1.12 drochner vc->vc_fonts[i] = 0;
525 1.12 drochner
526 1.12 drochner vc->currentfontset1 = vc->currentfontset2 = 0;
527 1.1 drochner }
528 1.1 drochner
529 1.1 drochner void
530 1.32 thorpej vga_common_attach(self, iot, memt, type, map)
531 1.28 soda struct device *self;
532 1.28 soda bus_space_tag_t iot, memt;
533 1.28 soda int type;
534 1.31 jeffs paddr_t (*map) __P((void *, off_t, int));
535 1.28 soda {
536 1.1 drochner int console;
537 1.1 drochner struct vga_config *vc;
538 1.1 drochner struct wsemuldisplaydev_attach_args aa;
539 1.1 drochner
540 1.1 drochner console = vga_is_console(iot, type);
541 1.1 drochner
542 1.1 drochner if (console) {
543 1.1 drochner vc = &vga_console_vc;
544 1.1 drochner vga_console_attached = 1;
545 1.1 drochner } else {
546 1.1 drochner vc = malloc(sizeof(struct vga_config), M_DEVBUF, M_WAITOK);
547 1.1 drochner vga_init(vc, iot, memt);
548 1.1 drochner }
549 1.1 drochner
550 1.28 soda vc->vc_mmap = map;
551 1.28 soda
552 1.1 drochner aa.console = console;
553 1.4 drochner aa.scrdata = (vc->hdl.vh_mono ? &vga_screenlist_mono : &vga_screenlist);
554 1.1 drochner aa.accessops = &vga_accessops;
555 1.1 drochner aa.accesscookie = vc;
556 1.1 drochner
557 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
558 1.1 drochner }
559 1.1 drochner
560 1.1 drochner int
561 1.1 drochner vga_cnattach(iot, memt, type, check)
562 1.1 drochner bus_space_tag_t iot, memt;
563 1.1 drochner int type, check;
564 1.1 drochner {
565 1.3 drochner long defattr;
566 1.3 drochner const struct wsscreen_descr *scr;
567 1.3 drochner
568 1.1 drochner if (check && !vga_common_probe(iot, memt))
569 1.1 drochner return (ENXIO);
570 1.1 drochner
571 1.1 drochner /* set up bus-independent VGA configuration */
572 1.1 drochner vga_init(&vga_console_vc, iot, memt);
573 1.34 drochner #ifdef VGA_CONSOLE_SCREENTYPE
574 1.34 drochner scr = wsdisplay_screentype_pick(vga_console_vc.hdl.vh_mono ?
575 1.34 drochner &vga_screenlist_mono : &vga_screenlist, VGA_CONSOLE_SCREENTYPE);
576 1.34 drochner if (!scr)
577 1.34 drochner panic("vga_cnattach: invalid screen type");
578 1.34 drochner if (scr->fontheight != 16)
579 1.34 drochner panic("vga_cnattach: console screen type w/o font");
580 1.34 drochner if (scr != vga_console_vc.currenttype) {
581 1.34 drochner vga_setscreentype(&vga_console_vc.hdl, scr);
582 1.34 drochner vga_console_vc.currenttype = scr;
583 1.34 drochner }
584 1.34 drochner #else
585 1.11 drochner scr = vga_console_vc.currenttype;
586 1.34 drochner #endif
587 1.4 drochner vga_init_screen(&vga_console_vc, &vga_console_screen, scr, 1, &defattr);
588 1.1 drochner
589 1.4 drochner vga_console_screen.pcs.active = 1;
590 1.1 drochner vga_console_vc.active = &vga_console_screen;
591 1.1 drochner
592 1.3 drochner wsdisplay_cnattach(scr, &vga_console_screen,
593 1.4 drochner vga_console_screen.pcs.vc_ccol,
594 1.4 drochner vga_console_screen.pcs.vc_crow,
595 1.3 drochner defattr);
596 1.1 drochner
597 1.1 drochner vgaconsole = 1;
598 1.1 drochner vga_console_type = type;
599 1.1 drochner return (0);
600 1.1 drochner }
601 1.1 drochner
602 1.1 drochner int
603 1.1 drochner vga_is_console(iot, type)
604 1.1 drochner bus_space_tag_t iot;
605 1.1 drochner int type;
606 1.1 drochner {
607 1.1 drochner if (vgaconsole &&
608 1.1 drochner !vga_console_attached &&
609 1.1 drochner iot == vga_console_vc.hdl.vh_iot &&
610 1.1 drochner (vga_console_type == -1 || (type == vga_console_type)))
611 1.1 drochner return (1);
612 1.1 drochner return (0);
613 1.1 drochner }
614 1.1 drochner
615 1.1 drochner int
616 1.1 drochner vga_ioctl(v, cmd, data, flag, p)
617 1.1 drochner void *v;
618 1.1 drochner u_long cmd;
619 1.1 drochner caddr_t data;
620 1.1 drochner int flag;
621 1.1 drochner struct proc *p;
622 1.1 drochner {
623 1.1 drochner #if 0
624 1.1 drochner struct vga_config *vc = v;
625 1.1 drochner #endif
626 1.1 drochner
627 1.1 drochner switch (cmd) {
628 1.1 drochner #if 0
629 1.1 drochner case WSDISPLAYIO_GTYPE:
630 1.1 drochner *(int *)data = vc->vc_type;
631 1.1 drochner /* XXX should get detailed hardware information here */
632 1.10 augustss return 0;
633 1.10 augustss #else
634 1.10 augustss case WSDISPLAYIO_GTYPE:
635 1.10 augustss *(int *)data = WSDISPLAY_TYPE_UNKNOWN;
636 1.1 drochner return 0;
637 1.1 drochner #endif
638 1.12 drochner
639 1.1 drochner case WSDISPLAYIO_GINFO:
640 1.1 drochner case WSDISPLAYIO_GETCMAP:
641 1.1 drochner case WSDISPLAYIO_PUTCMAP:
642 1.1 drochner case WSDISPLAYIO_GVIDEO:
643 1.1 drochner case WSDISPLAYIO_SVIDEO:
644 1.1 drochner case WSDISPLAYIO_GCURPOS:
645 1.1 drochner case WSDISPLAYIO_SCURPOS:
646 1.1 drochner case WSDISPLAYIO_GCURMAX:
647 1.1 drochner case WSDISPLAYIO_GCURSOR:
648 1.1 drochner case WSDISPLAYIO_SCURSOR:
649 1.1 drochner /* NONE of these operations are by the generic VGA driver. */
650 1.1 drochner return ENOTTY;
651 1.1 drochner }
652 1.12 drochner
653 1.1 drochner return -1;
654 1.1 drochner }
655 1.1 drochner
656 1.29 simonb static paddr_t
657 1.1 drochner vga_mmap(v, offset, prot)
658 1.1 drochner void *v;
659 1.1 drochner off_t offset;
660 1.1 drochner int prot;
661 1.1 drochner {
662 1.1 drochner
663 1.28 soda struct vga_config *vc = v;
664 1.28 soda
665 1.28 soda if (vc->vc_mmap != NULL)
666 1.28 soda return (*vc->vc_mmap)(v, offset, prot);
667 1.32 thorpej
668 1.1 drochner return -1;
669 1.1 drochner }
670 1.1 drochner
671 1.1 drochner int
672 1.3 drochner vga_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
673 1.1 drochner void *v;
674 1.1 drochner const struct wsscreen_descr *type;
675 1.1 drochner void **cookiep;
676 1.1 drochner int *curxp, *curyp;
677 1.3 drochner long *defattrp;
678 1.1 drochner {
679 1.1 drochner struct vga_config *vc = v;
680 1.1 drochner struct vgascreen *scr;
681 1.1 drochner
682 1.1 drochner if (vc->nscreens == 1) {
683 1.1 drochner /*
684 1.1 drochner * When allocating the second screen, get backing store
685 1.1 drochner * for the first one too.
686 1.1 drochner * XXX We could be more clever and use video RAM.
687 1.1 drochner */
688 1.4 drochner vc->screens.lh_first->pcs.mem =
689 1.1 drochner malloc(type->ncols * type->nrows * 2, M_DEVBUF, M_WAITOK);
690 1.1 drochner }
691 1.1 drochner
692 1.1 drochner scr = malloc(sizeof(struct vgascreen), M_DEVBUF, M_WAITOK);
693 1.4 drochner vga_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
694 1.1 drochner
695 1.4 drochner if (vc->nscreens == 1) {
696 1.4 drochner scr->pcs.active = 1;
697 1.1 drochner vc->active = scr;
698 1.11 drochner vc->currenttype = type;
699 1.4 drochner } else {
700 1.4 drochner scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
701 1.4 drochner M_DEVBUF, M_WAITOK);
702 1.4 drochner pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
703 1.1 drochner }
704 1.1 drochner
705 1.1 drochner *cookiep = scr;
706 1.4 drochner *curxp = scr->pcs.vc_ccol;
707 1.4 drochner *curyp = scr->pcs.vc_crow;
708 1.1 drochner
709 1.1 drochner return (0);
710 1.1 drochner }
711 1.1 drochner
712 1.1 drochner void
713 1.1 drochner vga_free_screen(v, cookie)
714 1.1 drochner void *v;
715 1.1 drochner void *cookie;
716 1.1 drochner {
717 1.1 drochner struct vgascreen *vs = cookie;
718 1.11 drochner struct vga_config *vc = vs->cfg;
719 1.1 drochner
720 1.1 drochner LIST_REMOVE(vs, next);
721 1.1 drochner if (vs != &vga_console_screen)
722 1.1 drochner free(vs, M_DEVBUF);
723 1.1 drochner else
724 1.1 drochner panic("vga_free_screen: console");
725 1.11 drochner
726 1.11 drochner if (vc->active == vs)
727 1.11 drochner vc->active = 0;
728 1.1 drochner }
729 1.1 drochner
730 1.12 drochner static void
731 1.12 drochner vga_setfont(vc, scr)
732 1.12 drochner struct vga_config *vc;
733 1.12 drochner struct vgascreen *scr;
734 1.12 drochner {
735 1.12 drochner int fontslot1, fontslot2;
736 1.12 drochner
737 1.12 drochner fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
738 1.12 drochner fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
739 1.12 drochner if (vc->currentfontset1 != fontslot1 ||
740 1.12 drochner vc->currentfontset2 != fontslot2) {
741 1.12 drochner vga_setfontset(&vc->hdl, fontslot1, fontslot2);
742 1.12 drochner vc->currentfontset1 = fontslot1;
743 1.12 drochner vc->currentfontset2 = fontslot2;
744 1.12 drochner }
745 1.12 drochner }
746 1.12 drochner
747 1.22 drochner int
748 1.22 drochner vga_show_screen(v, cookie, waitok, cb, cbarg)
749 1.1 drochner void *v;
750 1.1 drochner void *cookie;
751 1.22 drochner int waitok;
752 1.22 drochner void (*cb) __P((void *, int, int));
753 1.22 drochner void *cbarg;
754 1.1 drochner {
755 1.4 drochner struct vgascreen *scr = cookie, *oldscr;
756 1.1 drochner struct vga_config *vc = scr->cfg;
757 1.22 drochner
758 1.22 drochner oldscr = vc->active; /* can be NULL! */
759 1.22 drochner if (scr == oldscr) {
760 1.22 drochner return (0);
761 1.22 drochner }
762 1.22 drochner
763 1.22 drochner vc->wantedscreen = cookie;
764 1.22 drochner vc->switchcb = cb;
765 1.22 drochner vc->switchcbarg = cbarg;
766 1.22 drochner if (cb) {
767 1.26 thorpej callout_reset(&vc->vc_switch_callout, 0,
768 1.26 thorpej (void(*)(void *))vga_doswitch, vc);
769 1.22 drochner return (EAGAIN);
770 1.22 drochner }
771 1.22 drochner
772 1.22 drochner vga_doswitch(vc);
773 1.22 drochner return (0);
774 1.22 drochner }
775 1.22 drochner
776 1.22 drochner void
777 1.22 drochner vga_doswitch(vc)
778 1.22 drochner struct vga_config *vc;
779 1.22 drochner {
780 1.22 drochner struct vgascreen *scr, *oldscr;
781 1.1 drochner struct vga_handle *vh = &vc->hdl;
782 1.22 drochner const struct wsscreen_descr *type;
783 1.1 drochner
784 1.22 drochner scr = vc->wantedscreen;
785 1.22 drochner if (!scr) {
786 1.22 drochner printf("vga_doswitch: disappeared\n");
787 1.22 drochner (*vc->switchcb)(vc->switchcbarg, EIO, 0);
788 1.22 drochner return;
789 1.22 drochner }
790 1.22 drochner type = scr->pcs.type;
791 1.11 drochner oldscr = vc->active; /* can be NULL! */
792 1.4 drochner #ifdef DIAGNOSTIC
793 1.11 drochner if (oldscr) {
794 1.11 drochner if (!oldscr->pcs.active)
795 1.11 drochner panic("vga_show_screen: not active");
796 1.11 drochner if (oldscr->pcs.type != vc->currenttype)
797 1.11 drochner panic("vga_show_screen: bad type");
798 1.11 drochner }
799 1.4 drochner #endif
800 1.4 drochner if (scr == oldscr) {
801 1.1 drochner return;
802 1.4 drochner }
803 1.4 drochner #ifdef DIAGNOSTIC
804 1.4 drochner if (scr->pcs.active)
805 1.4 drochner panic("vga_show_screen: active");
806 1.4 drochner #endif
807 1.4 drochner
808 1.11 drochner if (oldscr) {
809 1.11 drochner const struct wsscreen_descr *oldtype = oldscr->pcs.type;
810 1.1 drochner
811 1.11 drochner oldscr->pcs.active = 0;
812 1.11 drochner bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
813 1.11 drochner oldscr->pcs.dispoffset, oldscr->pcs.mem,
814 1.11 drochner oldtype->ncols * oldtype->nrows);
815 1.11 drochner }
816 1.1 drochner
817 1.11 drochner if (vc->currenttype != type) {
818 1.4 drochner vga_setscreentype(vh, type);
819 1.11 drochner vc->currenttype = type;
820 1.11 drochner }
821 1.12 drochner
822 1.12 drochner vga_setfont(vc, scr);
823 1.11 drochner /* XXX swich colours! */
824 1.1 drochner
825 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
826 1.11 drochner if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
827 1.8 drochner vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
828 1.8 drochner vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
829 1.8 drochner }
830 1.8 drochner
831 1.11 drochner bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
832 1.11 drochner scr->pcs.dispoffset, scr->pcs.mem,
833 1.11 drochner type->ncols * type->nrows);
834 1.11 drochner scr->pcs.active = 1;
835 1.1 drochner
836 1.4 drochner vc->active = scr;
837 1.1 drochner
838 1.4 drochner pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
839 1.4 drochner scr->pcs.vc_crow, scr->pcs.vc_ccol);
840 1.22 drochner
841 1.22 drochner vc->wantedscreen = 0;
842 1.22 drochner if (vc->switchcb)
843 1.22 drochner (*vc->switchcb)(vc->switchcbarg, 0, 0);
844 1.1 drochner }
845 1.1 drochner
846 1.1 drochner static int
847 1.12 drochner vga_load_font(v, cookie, data)
848 1.1 drochner void *v;
849 1.1 drochner void *cookie;
850 1.12 drochner struct wsdisplay_font *data;
851 1.1 drochner {
852 1.12 drochner struct vga_config *vc = v;
853 1.1 drochner struct vgascreen *scr = cookie;
854 1.12 drochner char *name2;
855 1.12 drochner int res, slot;
856 1.12 drochner struct vgafont *f;
857 1.12 drochner
858 1.12 drochner if (scr) {
859 1.12 drochner name2 = strchr(data->name, ',');
860 1.12 drochner if (name2)
861 1.12 drochner *name2++ = '\0';
862 1.12 drochner res = vga_selectfont(vc, scr, data->name, name2);
863 1.12 drochner if (!res)
864 1.12 drochner vga_setfont(vc, scr);
865 1.12 drochner return (res);
866 1.12 drochner }
867 1.1 drochner
868 1.12 drochner if (data->fontwidth != 8 || data->stride != 1)
869 1.1 drochner return (EINVAL); /* XXX 1 byte per line */
870 1.12 drochner if (data->firstchar != 0 || data->numchars != 256)
871 1.12 drochner return (EINVAL);
872 1.16 drochner #ifndef WSCONS_SUPPORT_PCVTFONTS
873 1.16 drochner if (data->encoding == WSDISPLAY_FONTENC_PCVT) {
874 1.16 drochner printf("vga: pcvt font support not built in, see vga(4)\n");
875 1.16 drochner return (EINVAL);
876 1.16 drochner }
877 1.16 drochner #endif
878 1.12 drochner
879 1.12 drochner for (slot = 0; slot < 8; slot++)
880 1.12 drochner if (!vc->vc_fonts[slot])
881 1.12 drochner break;
882 1.12 drochner if (slot == 8)
883 1.12 drochner return (ENOSPC);
884 1.12 drochner
885 1.12 drochner f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK);
886 1.12 drochner strncpy(f->name, data->name, sizeof(f->name));
887 1.12 drochner f->height = data->fontheight;
888 1.12 drochner f->encoding = data->encoding;
889 1.12 drochner #ifdef notyet
890 1.12 drochner f->firstchar = data->firstchar;
891 1.12 drochner f->numchars = data->numchars;
892 1.12 drochner #endif
893 1.12 drochner #ifdef VGAFONTDEBUG
894 1.12 drochner printf("vga: load %s (8x%d, enc %d) font to slot %d\n", f->name,
895 1.12 drochner f->height, f->encoding, slot);
896 1.12 drochner #endif
897 1.12 drochner vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data);
898 1.12 drochner f->slot = slot;
899 1.12 drochner vc->vc_fonts[slot] = f;
900 1.1 drochner
901 1.1 drochner return (0);
902 1.1 drochner }
903 1.1 drochner
904 1.3 drochner static int
905 1.3 drochner vga_alloc_attr(id, fg, bg, flags, attrp)
906 1.3 drochner void *id;
907 1.3 drochner int fg, bg;
908 1.3 drochner int flags;
909 1.3 drochner long *attrp;
910 1.3 drochner {
911 1.3 drochner struct vgascreen *scr = id;
912 1.3 drochner struct vga_config *vc = scr->cfg;
913 1.3 drochner
914 1.4 drochner if (vc->hdl.vh_mono) {
915 1.3 drochner if (flags & WSATTR_WSCOLORS)
916 1.3 drochner return (EINVAL);
917 1.3 drochner if (flags & WSATTR_REVERSE)
918 1.3 drochner *attrp = 0x70;
919 1.3 drochner else
920 1.3 drochner *attrp = 0x07;
921 1.3 drochner if (flags & WSATTR_UNDERLINE)
922 1.3 drochner *attrp |= FG_UNDERLINE;
923 1.3 drochner if (flags & WSATTR_HILIT)
924 1.3 drochner *attrp |= FG_INTENSE;
925 1.3 drochner } else {
926 1.3 drochner if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
927 1.3 drochner return (EINVAL);
928 1.3 drochner if (flags & WSATTR_WSCOLORS)
929 1.3 drochner *attrp = fgansitopc[fg] | bgansitopc[bg];
930 1.3 drochner else
931 1.3 drochner *attrp = 7;
932 1.3 drochner if (flags & WSATTR_HILIT)
933 1.3 drochner *attrp += 8;
934 1.3 drochner }
935 1.3 drochner if (flags & WSATTR_BLINK)
936 1.3 drochner *attrp |= FG_BLINK;
937 1.3 drochner return (0);
938 1.8 drochner }
939 1.8 drochner
940 1.8 drochner void
941 1.8 drochner vga_copyrows(id, srcrow, dstrow, nrows)
942 1.8 drochner void *id;
943 1.8 drochner int srcrow, dstrow, nrows;
944 1.8 drochner {
945 1.8 drochner struct vgascreen *scr = id;
946 1.8 drochner bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
947 1.8 drochner bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
948 1.8 drochner int ncols = scr->pcs.type->ncols;
949 1.8 drochner bus_size_t srcoff, dstoff;
950 1.8 drochner
951 1.8 drochner srcoff = srcrow * ncols + 0;
952 1.8 drochner dstoff = dstrow * ncols + 0;
953 1.8 drochner
954 1.8 drochner if (scr->pcs.active) {
955 1.8 drochner if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
956 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
957 1.20 ad int cursoron = scr->pcs.cursoron;
958 1.20 ad
959 1.21 mycroft if (cursoron)
960 1.21 mycroft pcdisplay_cursor(&scr->pcs, 0,
961 1.21 mycroft scr->pcs.vc_crow, scr->pcs.vc_ccol);
962 1.18 ad #endif
963 1.8 drochner /* scroll up whole screen */
964 1.8 drochner if ((scr->pcs.dispoffset + srcrow * ncols * 2)
965 1.8 drochner <= scr->maxdispoffset) {
966 1.8 drochner scr->pcs.dispoffset += srcrow * ncols * 2;
967 1.8 drochner } else {
968 1.8 drochner bus_space_copy_region_2(memt, memh,
969 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
970 1.8 drochner memh, scr->mindispoffset,
971 1.8 drochner nrows * ncols);
972 1.8 drochner scr->pcs.dispoffset = scr->mindispoffset;
973 1.8 drochner }
974 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrh,
975 1.8 drochner scr->pcs.dispoffset >> 9);
976 1.8 drochner vga_6845_write(&scr->cfg->hdl, startadrl,
977 1.8 drochner scr->pcs.dispoffset >> 1);
978 1.18 ad #ifdef PCDISPLAY_SOFTCURSOR
979 1.21 mycroft if (cursoron)
980 1.21 mycroft pcdisplay_cursor(&scr->pcs, 1,
981 1.21 mycroft scr->pcs.vc_crow, scr->pcs.vc_ccol);
982 1.18 ad #endif
983 1.8 drochner } else {
984 1.8 drochner bus_space_copy_region_2(memt, memh,
985 1.8 drochner scr->pcs.dispoffset + srcoff * 2,
986 1.8 drochner memh, scr->pcs.dispoffset + dstoff * 2,
987 1.8 drochner nrows * ncols);
988 1.8 drochner }
989 1.8 drochner } else
990 1.8 drochner bcopy(&scr->pcs.mem[srcoff], &scr->pcs.mem[dstoff],
991 1.8 drochner nrows * ncols * 2);
992 1.12 drochner }
993 1.12 drochner
994 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
995 1.12 drochner
996 1.12 drochner #define NOTYET 0xffff
997 1.12 drochner static u_int16_t pcvt_unichars[0xa0] = {
998 1.14 drochner /* 0 */ _e006U,
999 1.14 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1000 1.12 drochner NOTYET,
1001 1.12 drochner 0x2409, /* SYMBOL FOR HORIZONTAL TABULATION */
1002 1.12 drochner 0x240a, /* SYMBOL FOR LINE FEED */
1003 1.12 drochner 0x240b, /* SYMBOL FOR VERTICAL TABULATION */
1004 1.12 drochner 0x240c, /* SYMBOL FOR FORM FEED */
1005 1.12 drochner 0x240d, /* SYMBOL FOR CARRIAGE RETURN */
1006 1.12 drochner NOTYET, NOTYET,
1007 1.14 drochner /* 1 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1008 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1009 1.12 drochner /* 2 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1010 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1011 1.14 drochner /* 3 */ NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1012 1.12 drochner NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET, NOTYET,
1013 1.12 drochner /* 4 */ 0x03c1, /* GREEK SMALL LETTER RHO */
1014 1.12 drochner 0x03c8, /* GREEK SMALL LETTER PSI */
1015 1.12 drochner 0x2202, /* PARTIAL DIFFERENTIAL */
1016 1.12 drochner 0x03bb, /* GREEK SMALL LETTER LAMDA */
1017 1.12 drochner 0x03b9, /* GREEK SMALL LETTER IOTA */
1018 1.12 drochner 0x03b7, /* GREEK SMALL LETTER ETA */
1019 1.12 drochner 0x03b5, /* GREEK SMALL LETTER EPSILON */
1020 1.12 drochner 0x03c7, /* GREEK SMALL LETTER CHI */
1021 1.12 drochner 0x2228, /* LOGICAL OR */
1022 1.12 drochner 0x2227, /* LOGICAL AND */
1023 1.12 drochner 0x222a, /* UNION */
1024 1.12 drochner 0x2283, /* SUPERSET OF */
1025 1.12 drochner 0x2282, /* SUBSET OF */
1026 1.12 drochner 0x03a5, /* GREEK CAPITAL LETTER UPSILON */
1027 1.12 drochner 0x039e, /* GREEK CAPITAL LETTER XI */
1028 1.12 drochner 0x03a8, /* GREEK CAPITAL LETTER PSI */
1029 1.14 drochner /* 5 */ 0x03a0, /* GREEK CAPITAL LETTER PI */
1030 1.12 drochner 0x21d2, /* RIGHTWARDS DOUBLE ARROW */
1031 1.12 drochner 0x21d4, /* LEFT RIGHT DOUBLE ARROW */
1032 1.12 drochner 0x039b, /* GREEK CAPITAL LETTER LAMDA */
1033 1.12 drochner 0x0398, /* GREEK CAPITAL LETTER THETA */
1034 1.12 drochner 0x2243, /* ASYMPTOTICALLY EQUAL TO */
1035 1.12 drochner 0x2207, /* NABLA */
1036 1.12 drochner 0x2206, /* INCREMENT */
1037 1.12 drochner 0x221d, /* PROPORTIONAL TO */
1038 1.12 drochner 0x2234, /* THEREFORE */
1039 1.12 drochner 0x222b, /* INTEGRAL */
1040 1.12 drochner 0x2215, /* DIVISION SLASH */
1041 1.12 drochner 0x2216, /* SET MINUS */
1042 1.14 drochner _e00eU,
1043 1.14 drochner _e00dU,
1044 1.14 drochner _e00bU,
1045 1.14 drochner /* 6 */ _e00cU,
1046 1.14 drochner _e007U,
1047 1.14 drochner _e008U,
1048 1.14 drochner _e009U,
1049 1.14 drochner _e00aU,
1050 1.12 drochner 0x221a, /* SQUARE ROOT */
1051 1.12 drochner 0x03c9, /* GREEK SMALL LETTER OMEGA */
1052 1.12 drochner 0x00a5, /* YEN SIGN */
1053 1.12 drochner 0x03be, /* GREEK SMALL LETTER XI */
1054 1.12 drochner 0x00fd, /* LATIN SMALL LETTER Y WITH ACUTE */
1055 1.12 drochner 0x00fe, /* LATIN SMALL LETTER THORN */
1056 1.12 drochner 0x00f0, /* LATIN SMALL LETTER ETH */
1057 1.12 drochner 0x00de, /* LATIN CAPITAL LETTER THORN */
1058 1.12 drochner 0x00dd, /* LATIN CAPITAL LETTER Y WITH ACUTE */
1059 1.12 drochner 0x00d7, /* MULTIPLICATION SIGN */
1060 1.12 drochner 0x00d0, /* LATIN CAPITAL LETTER ETH */
1061 1.14 drochner /* 7 */ 0x00be, /* VULGAR FRACTION THREE QUARTERS */
1062 1.12 drochner 0x00b8, /* CEDILLA */
1063 1.12 drochner 0x00b4, /* ACUTE ACCENT */
1064 1.12 drochner 0x00af, /* MACRON */
1065 1.12 drochner 0x00ae, /* REGISTERED SIGN */
1066 1.12 drochner 0x00ad, /* SOFT HYPHEN */
1067 1.12 drochner 0x00ac, /* NOT SIGN */
1068 1.12 drochner 0x00a8, /* DIAERESIS */
1069 1.12 drochner 0x2260, /* NOT EQUAL TO */
1070 1.14 drochner _e005U,
1071 1.14 drochner _e004U,
1072 1.14 drochner _e003U,
1073 1.14 drochner _e002U,
1074 1.14 drochner _e001U,
1075 1.12 drochner 0x03c5, /* GREEK SMALL LETTER UPSILON */
1076 1.12 drochner 0x00f8, /* LATIN SMALL LETTER O WITH STROKE */
1077 1.12 drochner /* 8 */ 0x0153, /* LATIN SMALL LIGATURE OE */
1078 1.12 drochner 0x00f5, /* LATIN SMALL LETTER O WITH TILDE !!!doc bug */
1079 1.12 drochner 0x00e3, /* LATIN SMALL LETTER A WITH TILDE */
1080 1.12 drochner 0x0178, /* LATIN CAPITAL LETTER Y WITH DIAERESIS */
1081 1.12 drochner 0x00db, /* LATIN CAPITAL LETTER U WITH CIRCUMFLEX */
1082 1.12 drochner 0x00da, /* LATIN CAPITAL LETTER U WITH ACUTE */
1083 1.12 drochner 0x00d9, /* LATIN CAPITAL LETTER U WITH GRAVE */
1084 1.12 drochner 0x00d8, /* LATIN CAPITAL LETTER O WITH STROKE */
1085 1.12 drochner 0x0152, /* LATIN CAPITAL LIGATURE OE */
1086 1.12 drochner 0x00d5, /* LATIN CAPITAL LETTER O WITH TILDE */
1087 1.12 drochner 0x00d4, /* LATIN CAPITAL LETTER O WITH CIRCUMFLEX */
1088 1.12 drochner 0x00d3, /* LATIN CAPITAL LETTER O WITH ACUTE */
1089 1.12 drochner 0x00d2, /* LATIN CAPITAL LETTER O WITH GRAVE */
1090 1.12 drochner 0x00cf, /* LATIN CAPITAL LETTER I WITH DIAERESIS */
1091 1.12 drochner 0x00ce, /* LATIN CAPITAL LETTER I WITH CIRCUMFLEX */
1092 1.12 drochner 0x00cd, /* LATIN CAPITAL LETTER I WITH ACUTE */
1093 1.14 drochner /* 9 */ 0x00cc, /* LATIN CAPITAL LETTER I WITH GRAVE */
1094 1.12 drochner 0x00cb, /* LATIN CAPITAL LETTER E WITH DIAERESIS */
1095 1.12 drochner 0x00ca, /* LATIN CAPITAL LETTER E WITH CIRCUMFLEX */
1096 1.12 drochner 0x00c8, /* LATIN CAPITAL LETTER E WITH GRAVE */
1097 1.12 drochner 0x00c3, /* LATIN CAPITAL LETTER A WITH TILDE */
1098 1.12 drochner 0x00c2, /* LATIN CAPITAL LETTER A WITH CIRCUMFLEX */
1099 1.12 drochner 0x00c1, /* LATIN CAPITAL LETTER A WITH ACUTE */
1100 1.12 drochner 0x00c0, /* LATIN CAPITAL LETTER A WITH GRAVE */
1101 1.12 drochner 0x00b9, /* SUPERSCRIPT ONE */
1102 1.12 drochner 0x00b7, /* MIDDLE DOT */
1103 1.12 drochner 0x03b6, /* GREEK SMALL LETTER ZETA */
1104 1.12 drochner 0x00b3, /* SUPERSCRIPT THREE */
1105 1.12 drochner 0x00a9, /* COPYRIGHT SIGN */
1106 1.12 drochner 0x00a4, /* CURRENCY SIGN */
1107 1.12 drochner 0x03ba, /* GREEK SMALL LETTER KAPPA */
1108 1.14 drochner _e000U
1109 1.12 drochner };
1110 1.12 drochner
1111 1.13 drochner static int vga_pcvt_mapchar __P((int, unsigned int *));
1112 1.12 drochner
1113 1.12 drochner static int
1114 1.13 drochner vga_pcvt_mapchar(uni, index)
1115 1.12 drochner int uni;
1116 1.13 drochner unsigned int *index;
1117 1.12 drochner {
1118 1.12 drochner int i;
1119 1.12 drochner
1120 1.12 drochner for (i = 0; i < 0xa0; i++) /* 0xa0..0xff are reserved */
1121 1.13 drochner if (uni == pcvt_unichars[i]) {
1122 1.13 drochner *index = i;
1123 1.13 drochner return (5);
1124 1.13 drochner }
1125 1.13 drochner *index = 0x99; /* middle dot */
1126 1.13 drochner return (0);
1127 1.12 drochner }
1128 1.12 drochner
1129 1.12 drochner #endif /* WSCONS_SUPPORT_PCVTFONTS */
1130 1.12 drochner
1131 1.34 drochner #ifdef WSCONS_SUPPORT_ISO7FONTS
1132 1.34 drochner
1133 1.34 drochner static int
1134 1.34 drochner vga_iso7_mapchar(int uni, unsigned int *index)
1135 1.34 drochner {
1136 1.34 drochner
1137 1.34 drochner /*
1138 1.34 drochner * U+0384 (GREEK TONOS) to
1139 1.34 drochner * U+03ce (GREEK SMALL LETTER OMEGA WITH TONOS)
1140 1.34 drochner * map directly to the iso-9 font
1141 1.34 drochner */
1142 1.34 drochner if (uni >= 0x0384 && uni <= 0x03ce) {
1143 1.34 drochner /* U+0384 is at offset 0xb4 in the font */
1144 1.34 drochner *index = uni - 0x0384 + 0xb4;
1145 1.34 drochner return (5);
1146 1.34 drochner }
1147 1.34 drochner
1148 1.34 drochner /* XXX more chars in the iso-9 font */
1149 1.34 drochner
1150 1.34 drochner *index = 0xa4; /* shaded rectangle */
1151 1.34 drochner return (0);
1152 1.34 drochner }
1153 1.34 drochner
1154 1.34 drochner #endif /* WSCONS_SUPPORT_ISO7FONTS */
1155 1.34 drochner
1156 1.13 drochner static int _vga_mapchar __P((void *, struct vgafont *, int, unsigned int *));
1157 1.12 drochner
1158 1.12 drochner static int
1159 1.13 drochner _vga_mapchar(id, font, uni, index)
1160 1.12 drochner void *id;
1161 1.12 drochner struct vgafont *font;
1162 1.12 drochner int uni;
1163 1.13 drochner unsigned int *index;
1164 1.12 drochner {
1165 1.12 drochner
1166 1.12 drochner switch (font->encoding) {
1167 1.12 drochner case WSDISPLAY_FONTENC_ISO:
1168 1.13 drochner if (uni < 256) {
1169 1.13 drochner *index = uni;
1170 1.13 drochner return (5);
1171 1.13 drochner } else {
1172 1.13 drochner *index = ' ';
1173 1.13 drochner return (0);
1174 1.13 drochner }
1175 1.12 drochner break;
1176 1.12 drochner case WSDISPLAY_FONTENC_IBM:
1177 1.13 drochner return (pcdisplay_mapchar(id, uni, index));
1178 1.12 drochner #ifdef WSCONS_SUPPORT_PCVTFONTS
1179 1.12 drochner case WSDISPLAY_FONTENC_PCVT:
1180 1.13 drochner return (vga_pcvt_mapchar(uni, index));
1181 1.34 drochner #endif
1182 1.34 drochner #ifdef WSCONS_SUPPORT_ISO7FONTS
1183 1.34 drochner case WSDISPLAY_FONTENC_ISO7:
1184 1.34 drochner return (vga_iso7_mapchar(uni, index));
1185 1.12 drochner #endif
1186 1.13 drochner default:
1187 1.16 drochner #ifdef VGAFONTDEBUG
1188 1.13 drochner printf("_vga_mapchar: encoding=%d\n", font->encoding);
1189 1.16 drochner #endif
1190 1.13 drochner *index = ' ';
1191 1.13 drochner return (0);
1192 1.12 drochner }
1193 1.12 drochner }
1194 1.12 drochner
1195 1.13 drochner static int
1196 1.13 drochner vga_mapchar(id, uni, index)
1197 1.12 drochner void *id;
1198 1.12 drochner int uni;
1199 1.13 drochner unsigned int *index;
1200 1.12 drochner {
1201 1.12 drochner struct vgascreen *scr = id;
1202 1.13 drochner unsigned int idx1, idx2;
1203 1.13 drochner int res1, res2;
1204 1.12 drochner
1205 1.13 drochner res1 = 0;
1206 1.13 drochner idx1 = ' '; /* space */
1207 1.13 drochner if (scr->fontset1)
1208 1.13 drochner res1 = _vga_mapchar(id, scr->fontset1, uni, &idx1);
1209 1.13 drochner res2 = -1;
1210 1.12 drochner if (scr->fontset2) {
1211 1.12 drochner KASSERT(VGA_SCREEN_CANTWOFONTS(scr->pcs.type));
1212 1.13 drochner res2 = _vga_mapchar(id, scr->fontset2, uni, &idx2);
1213 1.12 drochner }
1214 1.13 drochner if (res2 > res1) {
1215 1.14 drochner *index = idx2 | 0x0800; /* attribute bit 3 */
1216 1.14 drochner return (res2);
1217 1.13 drochner }
1218 1.13 drochner *index = idx1;
1219 1.13 drochner return (res1);
1220 1.1 drochner }
1221