Home | History | Annotate | Line # | Download | only in isa
ega.c revision 1.5.6.4
      1  1.5.6.4  jdolecek /* $NetBSD: ega.c,v 1.5.6.4 2002/09/06 08:44:47 jdolecek Exp $ */
      2      1.1  drochner 
      3      1.1  drochner /*
      4      1.1  drochner  * Copyright (c) 1999
      5      1.1  drochner  *	Matthias Drochner.  All rights reserved.
      6      1.1  drochner  *
      7      1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8      1.1  drochner  * modification, are permitted provided that the following conditions
      9      1.1  drochner  * are met:
     10      1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11      1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     12      1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14      1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15      1.1  drochner  * 3. All advertising materials mentioning features or use of this software
     16      1.1  drochner  *    must display the following acknowledgement:
     17      1.1  drochner  *	This product includes software developed for the NetBSD Project
     18      1.1  drochner  *	by Matthias Drochner.
     19      1.1  drochner  * 4. The name of the author may not be used to endorse or promote products
     20      1.1  drochner  *    derived from this software without specific prior written permission.
     21      1.1  drochner  *
     22      1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23      1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24      1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25      1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26      1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27      1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28      1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29      1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30      1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31      1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32      1.1  drochner  *
     33      1.1  drochner  */
     34      1.1  drochner 
     35  1.5.6.2   thorpej #include <sys/cdefs.h>
     36  1.5.6.4  jdolecek __KERNEL_RCSID(0, "$NetBSD: ega.c,v 1.5.6.4 2002/09/06 08:44:47 jdolecek Exp $");
     37  1.5.6.2   thorpej 
     38      1.1  drochner #include <sys/param.h>
     39      1.1  drochner #include <sys/systm.h>
     40      1.4   thorpej #include <sys/callout.h>
     41      1.1  drochner #include <sys/kernel.h>
     42      1.1  drochner #include <sys/device.h>
     43      1.1  drochner #include <sys/malloc.h>
     44      1.1  drochner #include <machine/bus.h>
     45      1.1  drochner 
     46      1.1  drochner #include <dev/isa/isavar.h>
     47      1.1  drochner 
     48      1.1  drochner #include <dev/ic/mc6845reg.h>
     49      1.1  drochner #include <dev/ic/pcdisplayvar.h>
     50      1.1  drochner #include <dev/ic/vgareg.h>
     51      1.1  drochner #include <dev/ic/vgavar.h>
     52      1.1  drochner #include <dev/isa/egavar.h>
     53      1.1  drochner 
     54      1.1  drochner #include <dev/ic/pcdisplay.h>
     55      1.1  drochner 
     56      1.1  drochner #include <dev/wscons/wsconsio.h>
     57      1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     58      1.1  drochner 
     59      1.1  drochner static struct egafont {
     60      1.1  drochner 	char name[16];
     61      1.1  drochner 	int height;
     62      1.1  drochner 	int encoding;
     63      1.1  drochner 	int slot;
     64      1.1  drochner } ega_builtinfont = {
     65      1.1  drochner 	"builtin",
     66      1.1  drochner 	14,
     67      1.1  drochner 	WSDISPLAY_FONTENC_IBM,
     68      1.1  drochner 	0
     69      1.1  drochner };
     70      1.1  drochner 
     71      1.1  drochner struct egascreen {
     72      1.1  drochner 	struct pcdisplayscreen pcs;
     73      1.1  drochner 	LIST_ENTRY(egascreen) next;
     74      1.1  drochner 	struct ega_config *cfg;
     75      1.1  drochner 	struct egafont *fontset1, *fontset2;
     76      1.1  drochner 
     77      1.1  drochner 	int mindispoffset, maxdispoffset;
     78      1.1  drochner };
     79      1.1  drochner 
     80      1.1  drochner struct ega_config {
     81      1.1  drochner 	struct vga_handle hdl;
     82      1.1  drochner 
     83      1.1  drochner 	int nscreens;
     84      1.1  drochner 	LIST_HEAD(, egascreen) screens;
     85      1.1  drochner 	struct egascreen *active; /* current display */
     86      1.1  drochner 	const struct wsscreen_descr *currenttype;
     87      1.1  drochner 	int currentfontset1, currentfontset2;
     88      1.1  drochner 
     89      1.1  drochner 	struct egafont *vc_fonts[4];
     90      1.1  drochner 
     91      1.1  drochner 	struct egascreen *wantedscreen;
     92  1.5.6.4  jdolecek 	void (*switchcb)(void *, int, int);
     93      1.1  drochner 	void *switchcbarg;
     94      1.4   thorpej 
     95      1.4   thorpej 	struct callout switch_callout;
     96      1.1  drochner };
     97      1.1  drochner 
     98      1.1  drochner struct ega_softc {
     99      1.1  drochner 	struct device sc_dev;
    100      1.1  drochner 	struct ega_config *sc_dc;
    101      1.1  drochner 	int nscreens;
    102      1.1  drochner };
    103      1.1  drochner 
    104      1.1  drochner static int egaconsole, ega_console_attached;
    105      1.1  drochner static struct egascreen ega_console_screen;
    106      1.1  drochner static struct ega_config ega_console_dc;
    107      1.1  drochner 
    108  1.5.6.4  jdolecek int	ega_match(struct device *, struct cfdata *, void *);
    109  1.5.6.4  jdolecek void	ega_attach(struct device *, struct device *, void *);
    110      1.1  drochner 
    111  1.5.6.4  jdolecek static int ega_is_console(bus_space_tag_t);
    112  1.5.6.4  jdolecek static int ega_probe_col(bus_space_tag_t, bus_space_tag_t);
    113  1.5.6.4  jdolecek static int ega_probe_mono(bus_space_tag_t, bus_space_tag_t);
    114  1.5.6.4  jdolecek int ega_selectfont(struct ega_config *, struct egascreen *, char *, char *);
    115  1.5.6.4  jdolecek void ega_init_screen(struct ega_config *, struct egascreen *,
    116  1.5.6.4  jdolecek 		     const struct wsscreen_descr *, int, long *);
    117  1.5.6.4  jdolecek static void ega_init(struct ega_config *, bus_space_tag_t, bus_space_tag_t,
    118  1.5.6.4  jdolecek 		     int);
    119  1.5.6.4  jdolecek static void ega_setfont(struct ega_config *, struct egascreen *);
    120  1.5.6.4  jdolecek static int ega_allocattr(void *, int, int, int, long *);
    121  1.5.6.4  jdolecek void ega_copyrows(void *, int, int, int);
    122      1.1  drochner 
    123      1.1  drochner struct cfattach ega_ca = {
    124      1.1  drochner 	sizeof(struct ega_softc), ega_match, ega_attach,
    125      1.1  drochner };
    126      1.1  drochner 
    127      1.1  drochner const struct wsdisplay_emulops ega_emulops = {
    128      1.1  drochner 	pcdisplay_cursor,
    129      1.1  drochner 	pcdisplay_mapchar,
    130      1.1  drochner 	pcdisplay_putchar,
    131      1.1  drochner 	pcdisplay_copycols,
    132      1.1  drochner 	pcdisplay_erasecols,
    133      1.1  drochner 	ega_copyrows,
    134      1.1  drochner 	pcdisplay_eraserows,
    135  1.5.6.4  jdolecek 	ega_allocattr
    136      1.1  drochner };
    137      1.1  drochner 
    138      1.1  drochner /*
    139      1.1  drochner  * translate WS(=ANSI) color codes to standard pc ones
    140      1.1  drochner  */
    141      1.1  drochner static unsigned char fgansitopc[] = {
    142      1.1  drochner 	FG_BLACK, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
    143      1.1  drochner 	FG_MAGENTA, FG_CYAN, FG_LIGHTGREY
    144      1.1  drochner }, bgansitopc[] = {
    145      1.1  drochner 	BG_BLACK, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
    146      1.1  drochner 	BG_MAGENTA, BG_CYAN, BG_LIGHTGREY
    147      1.1  drochner };
    148      1.1  drochner 
    149      1.1  drochner const struct wsscreen_descr ega_stdscreen = {
    150      1.1  drochner 	"80x25", 80, 25,
    151      1.1  drochner 	&ega_emulops,
    152      1.1  drochner 	8, 14,
    153      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
    154      1.1  drochner }, ega_stdscreen_mono = {
    155      1.1  drochner 	"80x25", 80, 25,
    156      1.1  drochner 	&ega_emulops,
    157      1.1  drochner 	8, 14,
    158      1.1  drochner 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
    159      1.1  drochner }, ega_stdscreen_bf = {
    160      1.1  drochner 	"80x25bf", 80, 25,
    161      1.1  drochner 	&ega_emulops,
    162      1.1  drochner 	8, 14,
    163      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
    164      1.1  drochner }, ega_35lscreen = {
    165      1.1  drochner 	"80x35", 80, 35,
    166      1.1  drochner 	&ega_emulops,
    167      1.1  drochner 	8, 10,
    168      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
    169      1.1  drochner }, ega_35lscreen_mono = {
    170      1.1  drochner 	"80x35", 80, 35,
    171      1.1  drochner 	&ega_emulops,
    172      1.1  drochner 	8, 10,
    173      1.1  drochner 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
    174      1.1  drochner }, ega_35lscreen_bf = {
    175      1.1  drochner 	"80x35bf", 80, 35,
    176      1.1  drochner 	&ega_emulops,
    177      1.1  drochner 	8, 10,
    178      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
    179      1.1  drochner }, ega_43lscreen = {
    180      1.1  drochner 	"80x43", 80, 43,
    181      1.1  drochner 	&ega_emulops,
    182      1.1  drochner 	8, 8,
    183      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_BLINK
    184      1.1  drochner }, ega_43lscreen_mono = {
    185      1.1  drochner 	"80x43", 80, 43,
    186      1.1  drochner 	&ega_emulops,
    187      1.1  drochner 	8, 8,
    188      1.1  drochner 	WSSCREEN_HILIT | WSSCREEN_UNDERLINE | WSSCREEN_BLINK | WSSCREEN_REVERSE
    189      1.1  drochner }, ega_43lscreen_bf = {
    190      1.1  drochner 	"80x43bf", 80, 43,
    191      1.1  drochner 	&ega_emulops,
    192      1.1  drochner 	8, 8,
    193      1.1  drochner 	WSSCREEN_WSCOLORS | WSSCREEN_BLINK
    194      1.1  drochner };
    195      1.1  drochner 
    196      1.1  drochner #define VGA_SCREEN_CANTWOFONTS(type) (!((type)->capabilities & WSSCREEN_HILIT))
    197      1.1  drochner 
    198      1.1  drochner const struct wsscreen_descr *_ega_scrlist[] = {
    199      1.1  drochner 	&ega_stdscreen,
    200      1.1  drochner 	&ega_stdscreen_bf,
    201      1.1  drochner 	&ega_35lscreen,
    202      1.1  drochner 	&ega_35lscreen_bf,
    203      1.1  drochner 	&ega_43lscreen,
    204      1.1  drochner 	&ega_43lscreen_bf,
    205      1.1  drochner }, *_ega_scrlist_mono[] = {
    206      1.1  drochner 	&ega_stdscreen_mono,
    207      1.1  drochner 	&ega_35lscreen_mono,
    208      1.1  drochner 	&ega_43lscreen_mono,
    209      1.1  drochner };
    210      1.1  drochner 
    211      1.1  drochner 
    212      1.1  drochner const struct wsscreen_list ega_screenlist = {
    213      1.1  drochner 	sizeof(_ega_scrlist) / sizeof(struct wsscreen_descr *),
    214      1.1  drochner 	_ega_scrlist
    215      1.1  drochner }, ega_screenlist_mono = {
    216      1.1  drochner 	sizeof(_ega_scrlist_mono) / sizeof(struct wsscreen_descr *),
    217      1.1  drochner 	_ega_scrlist_mono
    218      1.1  drochner };
    219      1.1  drochner 
    220  1.5.6.4  jdolecek static int ega_ioctl(void *, u_long, caddr_t, int, struct proc *);
    221  1.5.6.4  jdolecek static paddr_t ega_mmap(void *, off_t, int);
    222  1.5.6.4  jdolecek static int ega_alloc_screen(void *, const struct wsscreen_descr *,
    223  1.5.6.4  jdolecek 			    void **, int *, int *, long *);
    224  1.5.6.4  jdolecek static void ega_free_screen(void *, void *);
    225  1.5.6.4  jdolecek static int ega_show_screen(void *, void *, int,
    226  1.5.6.4  jdolecek 			   void (*) (void *, int, int), void *);
    227  1.5.6.4  jdolecek static int ega_load_font(void *, void *, struct wsdisplay_font *);
    228      1.1  drochner 
    229  1.5.6.4  jdolecek void ega_doswitch(struct ega_config *);
    230      1.1  drochner 
    231      1.1  drochner const struct wsdisplay_accessops ega_accessops = {
    232      1.1  drochner 	ega_ioctl,
    233      1.1  drochner 	ega_mmap,
    234      1.1  drochner 	ega_alloc_screen,
    235      1.1  drochner 	ega_free_screen,
    236      1.1  drochner 	ega_show_screen,
    237      1.1  drochner 	ega_load_font
    238      1.1  drochner };
    239      1.1  drochner 
    240      1.1  drochner static int
    241      1.1  drochner ega_probe_col(iot, memt)
    242      1.1  drochner 	bus_space_tag_t iot, memt;
    243      1.1  drochner {
    244      1.1  drochner 	bus_space_handle_t memh, ioh_6845;
    245      1.1  drochner 	u_int16_t oldval, val;
    246      1.1  drochner 
    247      1.1  drochner 	if (bus_space_map(memt, 0xb8000, 0x8000, 0, &memh))
    248      1.1  drochner 		return (0);
    249      1.1  drochner 	oldval = bus_space_read_2(memt, memh, 0);
    250      1.1  drochner 	bus_space_write_2(memt, memh, 0, 0xa55a);
    251      1.1  drochner 	val = bus_space_read_2(memt, memh, 0);
    252      1.1  drochner 	bus_space_write_2(memt, memh, 0, oldval);
    253      1.1  drochner 	bus_space_unmap(memt, memh, 0x8000);
    254      1.1  drochner 	if (val != 0xa55a)
    255      1.1  drochner 		return (0);
    256      1.1  drochner 
    257      1.1  drochner 	if (bus_space_map(iot, 0x3d0, 0x10, 0, &ioh_6845))
    258      1.1  drochner 		return (0);
    259      1.1  drochner 	bus_space_unmap(iot, ioh_6845, 0x10);
    260      1.1  drochner 
    261      1.1  drochner 	return (1);
    262      1.1  drochner }
    263      1.1  drochner 
    264      1.1  drochner static int
    265      1.1  drochner ega_probe_mono(iot, memt)
    266      1.1  drochner 	bus_space_tag_t iot, memt;
    267      1.1  drochner {
    268      1.1  drochner 	bus_space_handle_t memh, ioh_6845;
    269      1.1  drochner 	u_int16_t oldval, val;
    270      1.1  drochner 
    271      1.1  drochner 	if (bus_space_map(memt, 0xb0000, 0x8000, 0, &memh))
    272      1.1  drochner 		return (0);
    273      1.1  drochner 	oldval = bus_space_read_2(memt, memh, 0);
    274      1.1  drochner 	bus_space_write_2(memt, memh, 0, 0xa55a);
    275      1.1  drochner 	val = bus_space_read_2(memt, memh, 0);
    276      1.1  drochner 	bus_space_write_2(memt, memh, 0, oldval);
    277      1.1  drochner 	bus_space_unmap(memt, memh, 0x8000);
    278      1.1  drochner 	if (val != 0xa55a)
    279      1.1  drochner 		return (0);
    280      1.1  drochner 
    281      1.1  drochner 	if (bus_space_map(iot, 0x3b0, 0x10, 0, &ioh_6845))
    282      1.1  drochner 		return (0);
    283      1.1  drochner 	bus_space_unmap(iot, ioh_6845, 0x10);
    284      1.1  drochner 
    285      1.1  drochner 	return (1);
    286      1.1  drochner }
    287      1.1  drochner /*
    288      1.1  drochner  * We want at least ASCII 32..127 be present in the
    289      1.1  drochner  * first font slot.
    290      1.1  drochner  */
    291      1.1  drochner #define vga_valid_primary_font(f) \
    292      1.1  drochner 	(f->encoding == WSDISPLAY_FONTENC_IBM || \
    293      1.1  drochner 	f->encoding == WSDISPLAY_FONTENC_ISO)
    294      1.1  drochner 
    295      1.1  drochner int
    296      1.1  drochner ega_selectfont(vc, scr, name1, name2)
    297      1.1  drochner 	struct ega_config *vc;
    298      1.1  drochner 	struct egascreen *scr;
    299      1.1  drochner 	char *name1, *name2; /* NULL: take first found */
    300      1.1  drochner {
    301      1.1  drochner 	const struct wsscreen_descr *type = scr->pcs.type;
    302      1.1  drochner 	struct egafont *f1, *f2;
    303      1.1  drochner 	int i;
    304      1.1  drochner 
    305      1.1  drochner 	f1 = f2 = 0;
    306      1.1  drochner 
    307      1.1  drochner 	for (i = 0; i < 4; i++) {
    308      1.1  drochner 		struct egafont *f = vc->vc_fonts[i];
    309      1.1  drochner 		if (!f || f->height != type->fontheight)
    310      1.1  drochner 			continue;
    311      1.1  drochner 		if (!f1 &&
    312      1.1  drochner 		    vga_valid_primary_font(f) &&
    313      1.1  drochner 		    (!name1 || !strcmp(name1, f->name))) {
    314      1.1  drochner 			f1 = f;
    315      1.1  drochner 			continue;
    316      1.1  drochner 		}
    317      1.1  drochner 		if (!f2 &&
    318      1.1  drochner 		    VGA_SCREEN_CANTWOFONTS(type) &&
    319      1.1  drochner 		    (!name2 || !strcmp(name2, f->name))) {
    320      1.1  drochner 			f2 = f;
    321      1.1  drochner 			continue;
    322      1.1  drochner 		}
    323      1.1  drochner 	}
    324      1.1  drochner 
    325      1.1  drochner 	/*
    326      1.1  drochner 	 * The request fails if no primary font was found,
    327      1.1  drochner 	 * or if a second font was requested but not found.
    328      1.1  drochner 	 */
    329      1.1  drochner 	if (f1 && (!name2 || f2)) {
    330      1.1  drochner #ifdef EGAFONTDEBUG
    331      1.1  drochner 		if (scr != &ega_console_screen || ega_console_attached) {
    332      1.1  drochner 			printf("ega (%s): font1=%s (slot %d)", type->name,
    333      1.1  drochner 			       f1->name, f1->slot);
    334      1.1  drochner 			if (f2)
    335      1.1  drochner 				printf(", font2=%s (slot %d)",
    336      1.1  drochner 				       f2->name, f2->slot);
    337      1.1  drochner 			printf("\n");
    338      1.1  drochner 		}
    339      1.1  drochner #endif
    340      1.1  drochner 		scr->fontset1 = f1;
    341      1.1  drochner 		scr->fontset2 = f2;
    342      1.1  drochner 		return (0);
    343      1.1  drochner 	}
    344      1.1  drochner 	return (ENXIO);
    345      1.1  drochner }
    346      1.1  drochner 
    347      1.1  drochner void
    348      1.1  drochner ega_init_screen(vc, scr, type, existing, attrp)
    349      1.1  drochner 	struct ega_config *vc;
    350      1.1  drochner 	struct egascreen *scr;
    351      1.1  drochner 	const struct wsscreen_descr *type;
    352      1.1  drochner 	int existing;
    353      1.1  drochner 	long *attrp;
    354      1.1  drochner {
    355      1.1  drochner 	int cpos;
    356      1.1  drochner 	int res;
    357      1.1  drochner 
    358      1.1  drochner 	scr->cfg = vc;
    359      1.1  drochner 	scr->pcs.hdl = (struct pcdisplay_handle *)&vc->hdl;
    360      1.1  drochner 	scr->pcs.type = type;
    361      1.1  drochner 	scr->pcs.active = 0;
    362      1.1  drochner 	scr->mindispoffset = 0;
    363      1.1  drochner 	scr->maxdispoffset = 0x8000 - type->nrows * type->ncols * 2;
    364      1.1  drochner 
    365      1.1  drochner 	if (existing) {
    366      1.1  drochner 		cpos = vga_6845_read(&vc->hdl, cursorh) << 8;
    367      1.1  drochner 		cpos |= vga_6845_read(&vc->hdl, cursorl);
    368      1.1  drochner 
    369      1.1  drochner 		/* make sure we have a valid cursor position */
    370      1.1  drochner 		if (cpos < 0 || cpos >= type->nrows * type->ncols)
    371      1.1  drochner 			cpos = 0;
    372      1.1  drochner 
    373      1.1  drochner 		scr->pcs.dispoffset = vga_6845_read(&vc->hdl, startadrh) << 9;
    374      1.1  drochner 		scr->pcs.dispoffset |= vga_6845_read(&vc->hdl, startadrl) << 1;
    375      1.1  drochner 
    376      1.1  drochner 		/* make sure we have a valid memory offset */
    377      1.1  drochner 		if (scr->pcs.dispoffset < scr->mindispoffset ||
    378      1.1  drochner 		    scr->pcs.dispoffset > scr->maxdispoffset)
    379      1.1  drochner 			scr->pcs.dispoffset = scr->mindispoffset;
    380      1.1  drochner 	} else {
    381      1.1  drochner 		cpos = 0;
    382      1.1  drochner 		scr->pcs.dispoffset = scr->mindispoffset;
    383      1.1  drochner 	}
    384      1.1  drochner 
    385  1.5.6.4  jdolecek 	scr->pcs.cursorrow = cpos / type->ncols;
    386  1.5.6.4  jdolecek 	scr->pcs.cursorcol = cpos % type->ncols;
    387      1.3        ad 	pcdisplay_cursor_init(&scr->pcs, existing);
    388      1.1  drochner 
    389  1.5.6.4  jdolecek 	res = ega_allocattr(scr, 0, 0, 0, attrp);
    390      1.1  drochner #ifdef DIAGNOSTIC
    391      1.1  drochner 	if (res)
    392      1.1  drochner 		panic("ega_init_screen: attribute botch");
    393      1.1  drochner #endif
    394      1.1  drochner 
    395      1.1  drochner 	scr->pcs.mem = NULL;
    396      1.1  drochner 
    397      1.1  drochner 	scr->fontset1 = scr->fontset2 = 0;
    398      1.1  drochner 	if (ega_selectfont(vc, scr, 0, 0)) {
    399      1.1  drochner 		if (scr == &ega_console_screen)
    400      1.1  drochner 			panic("ega_init_screen: no font");
    401      1.1  drochner 		else
    402      1.1  drochner 			printf("ega_init_screen: no font\n");
    403      1.1  drochner 	}
    404      1.1  drochner 
    405      1.1  drochner 	vc->nscreens++;
    406      1.1  drochner 	LIST_INSERT_HEAD(&vc->screens, scr, next);
    407      1.1  drochner }
    408      1.1  drochner 
    409      1.1  drochner static void
    410      1.1  drochner ega_init(vc, iot, memt, mono)
    411      1.1  drochner 	struct ega_config *vc;
    412      1.1  drochner 	bus_space_tag_t iot, memt;
    413      1.1  drochner 	int mono;
    414      1.1  drochner {
    415      1.1  drochner 	struct vga_handle *vh = &vc->hdl;
    416      1.1  drochner 	int i;
    417      1.1  drochner 
    418      1.1  drochner         vh->vh_iot = iot;
    419      1.1  drochner         vh->vh_memt = memt;
    420      1.1  drochner 	vh->vh_mono = mono;
    421      1.1  drochner 
    422      1.1  drochner         if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
    423      1.1  drochner                 panic("ega_common_setup: couldn't map ega io");
    424      1.1  drochner 
    425      1.1  drochner 	if (bus_space_map(vh->vh_iot, (vh->vh_mono ? 0x3b0 : 0x3d0), 0x10, 0,
    426      1.1  drochner 			  &vh->vh_ioh_6845))
    427      1.1  drochner                 panic("ega_common_setup: couldn't map 6845 io");
    428      1.1  drochner 
    429      1.1  drochner         if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
    430      1.1  drochner                 panic("ega_common_setup: couldn't map memory");
    431      1.1  drochner 
    432      1.1  drochner         if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
    433      1.1  drochner 				(vh->vh_mono ? 0x10000 : 0x18000), 0x8000,
    434      1.1  drochner 				&vh->vh_memh))
    435      1.1  drochner                 panic("ega_common_setup: mem subrange failed");
    436      1.1  drochner 
    437      1.1  drochner 	vc->nscreens = 0;
    438      1.1  drochner 	LIST_INIT(&vc->screens);
    439      1.1  drochner 	vc->active = NULL;
    440      1.1  drochner 	vc->currenttype = vh->vh_mono ? &ega_stdscreen_mono : &ega_stdscreen;
    441      1.4   thorpej 	callout_init(&vc->switch_callout);
    442      1.1  drochner 
    443      1.1  drochner 	vc->vc_fonts[0] = &ega_builtinfont;
    444      1.1  drochner 	for (i = 1; i < 4; i++)
    445      1.1  drochner 		vc->vc_fonts[i] = 0;
    446      1.1  drochner 
    447      1.1  drochner 	vc->currentfontset1 = vc->currentfontset2 = 0;
    448      1.1  drochner }
    449      1.1  drochner 
    450      1.1  drochner int
    451      1.1  drochner ega_match(parent, match, aux)
    452      1.1  drochner 	struct device *parent;
    453      1.1  drochner 	struct cfdata *match;
    454      1.1  drochner 	void *aux;
    455      1.1  drochner {
    456      1.1  drochner 	struct isa_attach_args *ia = aux;
    457      1.1  drochner 	int mono;
    458      1.1  drochner 
    459  1.5.6.2   thorpej 	if (ia->ia_nio < 1)
    460  1.5.6.2   thorpej 		return (0);
    461  1.5.6.2   thorpej 
    462  1.5.6.2   thorpej 	if (ia->ia_iomem < 1)
    463  1.5.6.2   thorpej 		return (0);
    464  1.5.6.2   thorpej 
    465  1.5.6.2   thorpej 	if (ia->ia_nirq < 1)
    466  1.5.6.2   thorpej 		return (0);
    467  1.5.6.2   thorpej 
    468  1.5.6.2   thorpej 	if (ia->ia_ndrq < 1)
    469  1.5.6.2   thorpej 		return (0);
    470  1.5.6.2   thorpej 
    471  1.5.6.2   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    472  1.5.6.2   thorpej 		return (0);
    473  1.5.6.2   thorpej 
    474      1.1  drochner 	/* If values are hardwired to something that they can't be, punt. */
    475  1.5.6.2   thorpej 	if ((ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT &&
    476  1.5.6.2   thorpej 	     ia->ia_io[0].ir_addr != 0x3d0 &&
    477  1.5.6.2   thorpej 	     ia->ia_io[0].ir_addr != 0x3b0) ||
    478  1.5.6.2   thorpej 	    /* ia->ia_io[0].ir_size != 0 || XXX isa.c */
    479  1.5.6.2   thorpej 	    (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT &&
    480  1.5.6.2   thorpej 	     ia->ia_iomem[0].ir_addr != 0xb8000 &&
    481  1.5.6.2   thorpej 	     ia->ia_iomem[0].ir_addr != 0xb0000) ||
    482  1.5.6.2   thorpej 	    (ia->ia_iomem[0].ir_size != 0 &&
    483  1.5.6.2   thorpej 	     ia->ia_iomem[0].ir_size != 0x8000) ||
    484  1.5.6.2   thorpej 	    ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT ||
    485  1.5.6.2   thorpej 	    ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT)
    486      1.1  drochner 		return (0);
    487      1.1  drochner 
    488      1.1  drochner 	if (ega_is_console(ia->ia_iot))
    489      1.1  drochner 		mono = ega_console_dc.hdl.vh_mono;
    490  1.5.6.2   thorpej 	else if (ia->ia_io[0].ir_addr != 0x3b0 &&
    491  1.5.6.2   thorpej 	    ia->ia_iomem[0].ir_addr != 0xb0000 &&
    492      1.1  drochner 		 ega_probe_col(ia->ia_iot, ia->ia_memt))
    493      1.1  drochner 		mono = 0;
    494  1.5.6.2   thorpej 	else if (ia->ia_io[0].ir_addr != 0x3d0 &&
    495  1.5.6.2   thorpej 	    ia->ia_iomem[0].ir_addr != 0xb8000 &&
    496      1.1  drochner 		ega_probe_mono(ia->ia_iot, ia->ia_memt))
    497      1.1  drochner 		mono = 1;
    498      1.1  drochner 	else
    499      1.1  drochner 		return (0);
    500      1.1  drochner 
    501  1.5.6.2   thorpej 	ia->ia_io[0].ir_addr = mono ? 0x3b0 : 0x3d0;
    502  1.5.6.2   thorpej 	ia->ia_io[0].ir_size = 0x10;
    503  1.5.6.2   thorpej 	ia->ia_iomem[0].ir_addr = mono ? 0xb0000 : 0xb8000;
    504  1.5.6.2   thorpej 	ia->ia_iomem[0].ir_size = 0x8000;
    505      1.1  drochner 	return (2); /* beat pcdisplay */
    506      1.1  drochner }
    507      1.1  drochner 
    508      1.1  drochner void
    509      1.1  drochner ega_attach(parent, self, aux)
    510      1.1  drochner 	struct device *parent, *self;
    511      1.1  drochner 	void *aux;
    512      1.1  drochner {
    513      1.1  drochner 	struct isa_attach_args *ia = aux;
    514      1.1  drochner 	struct ega_softc *sc = (struct ega_softc *)self;
    515      1.1  drochner 	int console;
    516      1.1  drochner 	struct ega_config *dc;
    517      1.1  drochner 	struct wsemuldisplaydev_attach_args aa;
    518      1.1  drochner 
    519      1.1  drochner 	printf("\n");
    520      1.1  drochner 
    521      1.1  drochner 	console = ega_is_console(ia->ia_iot);
    522      1.1  drochner 
    523      1.1  drochner 	if (console) {
    524      1.1  drochner 		dc = &ega_console_dc;
    525      1.1  drochner 		sc->nscreens = 1;
    526      1.1  drochner 		ega_console_attached = 1;
    527      1.1  drochner 	} else {
    528      1.1  drochner 		dc = malloc(sizeof(struct ega_config),
    529      1.1  drochner 			    M_DEVBUF, M_WAITOK);
    530  1.5.6.2   thorpej 		if (ia->ia_io[0].ir_addr != 0x3b0 &&
    531  1.5.6.2   thorpej 		    ia->ia_iomem[0].ir_addr != 0xb0000 &&
    532      1.1  drochner 		    ega_probe_col(ia->ia_iot, ia->ia_memt))
    533      1.1  drochner 			ega_init(dc, ia->ia_iot, ia->ia_memt, 0);
    534  1.5.6.2   thorpej 		else if (ia->ia_io[0].ir_addr != 0x3d0 &&
    535  1.5.6.2   thorpej 		    ia->ia_iomem[0].ir_addr != 0xb8000 &&
    536      1.1  drochner 			 ega_probe_mono(ia->ia_iot, ia->ia_memt))
    537      1.1  drochner 			ega_init(dc, ia->ia_iot, ia->ia_memt, 1);
    538      1.1  drochner 		else
    539      1.1  drochner 			panic("ega_attach: display disappeared");
    540      1.1  drochner 	}
    541      1.1  drochner 	sc->sc_dc = dc;
    542      1.1  drochner 
    543      1.1  drochner 	aa.console = console;
    544      1.1  drochner 	aa.scrdata = &ega_screenlist;
    545      1.1  drochner 	aa.accessops = &ega_accessops;
    546      1.1  drochner 	aa.accesscookie = dc;
    547      1.1  drochner 
    548      1.1  drochner         config_found(self, &aa, wsemuldisplaydevprint);
    549      1.1  drochner }
    550      1.1  drochner 
    551      1.1  drochner 
    552      1.1  drochner int
    553      1.1  drochner ega_cnattach(iot, memt)
    554      1.1  drochner 	bus_space_tag_t iot, memt;
    555      1.1  drochner {
    556      1.1  drochner 	int mono;
    557      1.1  drochner 	long defattr;
    558      1.1  drochner 	const struct wsscreen_descr *scr;
    559      1.1  drochner 
    560      1.1  drochner 	if (ega_probe_col(iot, memt))
    561      1.1  drochner 		mono = 0;
    562      1.1  drochner 	else if (ega_probe_mono(iot, memt))
    563      1.1  drochner 		mono = 1;
    564      1.1  drochner 	else
    565      1.1  drochner 		return (ENXIO);
    566      1.1  drochner 
    567      1.1  drochner 	ega_init(&ega_console_dc, iot, memt, mono);
    568      1.1  drochner 	scr = ega_console_dc.currenttype;
    569      1.1  drochner 	ega_init_screen(&ega_console_dc, &ega_console_screen, scr, 1, &defattr);
    570      1.1  drochner 
    571      1.1  drochner 	ega_console_screen.pcs.active = 1;
    572      1.1  drochner 	ega_console_dc.active = &ega_console_screen;
    573      1.1  drochner 
    574      1.1  drochner 	wsdisplay_cnattach(scr, &ega_console_screen,
    575  1.5.6.4  jdolecek 			   ega_console_screen.pcs.cursorcol,
    576  1.5.6.4  jdolecek 			   ega_console_screen.pcs.cursorrow,
    577      1.1  drochner 			   defattr);
    578      1.1  drochner 
    579      1.1  drochner 	egaconsole = 1;
    580      1.1  drochner 	return (0);
    581      1.1  drochner }
    582      1.1  drochner 
    583      1.1  drochner static int
    584      1.1  drochner ega_is_console(iot)
    585      1.1  drochner 	bus_space_tag_t iot;
    586      1.1  drochner {
    587      1.1  drochner 	if (egaconsole &&
    588      1.1  drochner 	    !ega_console_attached &&
    589      1.1  drochner 	    iot == ega_console_dc.hdl.vh_iot)
    590      1.1  drochner 		return (1);
    591      1.1  drochner 	return (0);
    592      1.1  drochner }
    593      1.1  drochner 
    594      1.1  drochner static int
    595      1.1  drochner ega_ioctl(v, cmd, data, flag, p)
    596      1.1  drochner 	void *v;
    597      1.1  drochner 	u_long cmd;
    598      1.1  drochner 	caddr_t data;
    599      1.1  drochner 	int flag;
    600      1.1  drochner 	struct proc *p;
    601      1.1  drochner {
    602      1.1  drochner 	/*
    603      1.1  drochner 	 * XXX "do something!"
    604      1.1  drochner 	 */
    605  1.5.6.3  jdolecek 	return (EPASSTHROUGH);
    606      1.1  drochner }
    607      1.1  drochner 
    608      1.5    simonb static paddr_t
    609      1.1  drochner ega_mmap(v, offset, prot)
    610      1.1  drochner 	void *v;
    611      1.1  drochner 	off_t offset;
    612      1.1  drochner 	int prot;
    613      1.1  drochner {
    614      1.1  drochner 	return (-1);
    615      1.1  drochner }
    616      1.1  drochner 
    617      1.1  drochner static int
    618      1.1  drochner ega_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
    619      1.1  drochner 	void *v;
    620      1.1  drochner 	const struct wsscreen_descr *type;
    621      1.1  drochner 	void **cookiep;
    622      1.1  drochner 	int *curxp, *curyp;
    623      1.1  drochner 	long *defattrp;
    624      1.1  drochner {
    625      1.1  drochner 	struct ega_config *vc = v;
    626      1.1  drochner 	struct egascreen *scr;
    627      1.1  drochner 
    628      1.1  drochner 	if (vc->nscreens == 1) {
    629      1.1  drochner 		/*
    630      1.1  drochner 		 * When allocating the second screen, get backing store
    631      1.1  drochner 		 * for the first one too.
    632      1.1  drochner 		 * XXX We could be more clever and use video RAM.
    633      1.1  drochner 		 */
    634      1.1  drochner 		vc->screens.lh_first->pcs.mem =
    635      1.1  drochner 		  malloc(type->ncols * type->nrows * 2, M_DEVBUF, M_WAITOK);
    636      1.1  drochner 	}
    637      1.1  drochner 
    638      1.1  drochner 	scr = malloc(sizeof(struct egascreen), M_DEVBUF, M_WAITOK);
    639      1.1  drochner 	ega_init_screen(vc, scr, type, vc->nscreens == 0, defattrp);
    640      1.1  drochner 
    641      1.1  drochner 	if (vc->nscreens == 1) {
    642      1.1  drochner 		scr->pcs.active = 1;
    643      1.1  drochner 		vc->active = scr;
    644      1.1  drochner 		vc->currenttype = type;
    645      1.1  drochner 	} else {
    646      1.1  drochner 		scr->pcs.mem = malloc(type->ncols * type->nrows * 2,
    647      1.1  drochner 				      M_DEVBUF, M_WAITOK);
    648      1.1  drochner 		pcdisplay_eraserows(&scr->pcs, 0, type->nrows, *defattrp);
    649      1.1  drochner 	}
    650      1.1  drochner 
    651      1.1  drochner 	*cookiep = scr;
    652  1.5.6.4  jdolecek 	*curxp = scr->pcs.cursorcol;
    653  1.5.6.4  jdolecek 	*curyp = scr->pcs.cursorrow;
    654      1.1  drochner 	return (0);
    655      1.1  drochner }
    656      1.1  drochner 
    657      1.1  drochner static void
    658      1.1  drochner ega_free_screen(v, cookie)
    659      1.1  drochner 	void *v;
    660      1.1  drochner 	void *cookie;
    661      1.1  drochner {
    662      1.1  drochner 	struct egascreen *vs = cookie;
    663      1.1  drochner 	struct ega_config *vc = vs->cfg;
    664      1.1  drochner 
    665      1.1  drochner 	LIST_REMOVE(vs, next);
    666      1.1  drochner 	if (vs != &ega_console_screen)
    667      1.1  drochner 		free(vs, M_DEVBUF);
    668      1.1  drochner 	else
    669      1.1  drochner 		panic("ega_free_screen: console");
    670      1.1  drochner 
    671      1.1  drochner 	if (vc->active == vs)
    672      1.1  drochner 		vc->active = 0;
    673      1.1  drochner }
    674      1.1  drochner 
    675      1.1  drochner static void
    676      1.1  drochner ega_setfont(vc, scr)
    677      1.1  drochner 	struct ega_config *vc;
    678      1.1  drochner 	struct egascreen *scr;
    679      1.1  drochner {
    680      1.1  drochner 	int fontslot1, fontslot2;
    681      1.1  drochner 
    682      1.1  drochner 	fontslot1 = (scr->fontset1 ? scr->fontset1->slot : 0);
    683      1.1  drochner 	fontslot2 = (scr->fontset2 ? scr->fontset2->slot : fontslot1);
    684      1.1  drochner 	if (vc->currentfontset1 != fontslot1 ||
    685      1.1  drochner 	    vc->currentfontset2 != fontslot2) {
    686      1.1  drochner 		vga_setfontset(&vc->hdl, 2 * fontslot1, 2 * fontslot2);
    687      1.1  drochner 		vc->currentfontset1 = fontslot1;
    688      1.1  drochner 		vc->currentfontset2 = fontslot2;
    689      1.1  drochner 	}
    690      1.1  drochner }
    691      1.1  drochner 
    692      1.1  drochner static int
    693      1.1  drochner ega_show_screen(v, cookie, waitok, cb, cbarg)
    694      1.1  drochner 	void *v;
    695      1.1  drochner 	void *cookie;
    696      1.1  drochner 	int waitok;
    697  1.5.6.4  jdolecek 	void (*cb)(void *, int, int);
    698      1.1  drochner 	void *cbarg;
    699      1.1  drochner {
    700      1.1  drochner 	struct egascreen *scr = cookie, *oldscr;
    701      1.1  drochner 	struct ega_config *vc = scr->cfg;
    702      1.1  drochner 
    703      1.1  drochner 	oldscr = vc->active; /* can be NULL! */
    704      1.1  drochner 	if (scr == oldscr) {
    705      1.1  drochner 		return (0);
    706      1.1  drochner 	}
    707      1.1  drochner 
    708      1.1  drochner 	vc->wantedscreen = cookie;
    709      1.1  drochner 	vc->switchcb = cb;
    710      1.1  drochner 	vc->switchcbarg = cbarg;
    711      1.1  drochner 	if (cb) {
    712      1.4   thorpej 		callout_reset(&vc->switch_callout, 0,
    713      1.4   thorpej 		    (void(*)(void *))ega_doswitch);
    714      1.1  drochner 		return (EAGAIN);
    715      1.1  drochner 	}
    716      1.1  drochner 
    717      1.1  drochner 	ega_doswitch(vc);
    718      1.1  drochner 	return (0);
    719      1.1  drochner }
    720      1.1  drochner 
    721      1.1  drochner void
    722      1.1  drochner ega_doswitch(vc)
    723      1.1  drochner 	struct ega_config *vc;
    724      1.1  drochner {
    725      1.1  drochner 	struct egascreen *scr, *oldscr;
    726      1.1  drochner 	struct vga_handle *vh = &vc->hdl;
    727      1.1  drochner 	const struct wsscreen_descr *type;
    728      1.1  drochner 
    729      1.1  drochner 	scr = vc->wantedscreen;
    730      1.1  drochner 	if (!scr) {
    731      1.1  drochner 		printf("ega_doswitch: disappeared\n");
    732      1.1  drochner 		(*vc->switchcb)(vc->switchcbarg, EIO, 0);
    733      1.1  drochner 		return;
    734      1.1  drochner 	}
    735      1.1  drochner 	type = scr->pcs.type;
    736      1.1  drochner 	oldscr = vc->active; /* can be NULL! */
    737      1.1  drochner #ifdef DIAGNOSTIC
    738      1.1  drochner 	if (oldscr) {
    739      1.1  drochner 		if (!oldscr->pcs.active)
    740      1.1  drochner 			panic("ega_show_screen: not active");
    741      1.1  drochner 		if (oldscr->pcs.type != vc->currenttype)
    742      1.1  drochner 			panic("ega_show_screen: bad type");
    743      1.1  drochner 	}
    744      1.1  drochner #endif
    745      1.1  drochner 	if (scr == oldscr) {
    746      1.1  drochner 		return;
    747      1.1  drochner 	}
    748      1.1  drochner #ifdef DIAGNOSTIC
    749      1.1  drochner 	if (scr->pcs.active)
    750      1.1  drochner 		panic("ega_show_screen: active");
    751      1.1  drochner #endif
    752      1.1  drochner 
    753      1.1  drochner 	if (oldscr) {
    754      1.1  drochner 		const struct wsscreen_descr *oldtype = oldscr->pcs.type;
    755      1.1  drochner 
    756      1.1  drochner 		oldscr->pcs.active = 0;
    757      1.1  drochner 		bus_space_read_region_2(vh->vh_memt, vh->vh_memh,
    758      1.1  drochner 					oldscr->pcs.dispoffset, oldscr->pcs.mem,
    759      1.1  drochner 					oldtype->ncols * oldtype->nrows);
    760      1.1  drochner 	}
    761      1.1  drochner 
    762      1.1  drochner 	if (vc->currenttype != type) {
    763      1.1  drochner 		vga_setscreentype(vh, type);
    764      1.1  drochner 		vc->currenttype = type;
    765      1.1  drochner 	}
    766      1.1  drochner 
    767      1.1  drochner 	ega_setfont(vc, scr);
    768      1.1  drochner 	/* XXX swich colours! */
    769      1.1  drochner 
    770      1.1  drochner 	scr->pcs.dispoffset = scr->mindispoffset;
    771      1.1  drochner 	if (!oldscr || (scr->pcs.dispoffset != oldscr->pcs.dispoffset)) {
    772      1.1  drochner 		vga_6845_write(vh, startadrh, scr->pcs.dispoffset >> 9);
    773      1.1  drochner 		vga_6845_write(vh, startadrl, scr->pcs.dispoffset >> 1);
    774      1.1  drochner 	}
    775      1.1  drochner 
    776      1.1  drochner 	bus_space_write_region_2(vh->vh_memt, vh->vh_memh,
    777      1.1  drochner 				scr->pcs.dispoffset, scr->pcs.mem,
    778      1.1  drochner 				type->ncols * type->nrows);
    779      1.1  drochner 	scr->pcs.active = 1;
    780      1.1  drochner 
    781      1.1  drochner 	vc->active = scr;
    782      1.1  drochner 
    783      1.1  drochner 	pcdisplay_cursor(&scr->pcs, scr->pcs.cursoron,
    784  1.5.6.4  jdolecek 			 scr->pcs.cursorrow, scr->pcs.cursorcol);
    785      1.1  drochner 
    786      1.1  drochner 	vc->wantedscreen = 0;
    787      1.1  drochner 	if (vc->switchcb)
    788      1.1  drochner 		(*vc->switchcb)(vc->switchcbarg, 0, 0);
    789      1.1  drochner }
    790      1.1  drochner 
    791      1.1  drochner static int
    792      1.1  drochner ega_load_font(v, cookie, data)
    793      1.1  drochner 	void *v;
    794      1.1  drochner 	void *cookie;
    795      1.1  drochner 	struct wsdisplay_font *data;
    796      1.1  drochner {
    797      1.1  drochner 	struct ega_config *vc = v;
    798      1.1  drochner 	struct egascreen *scr = cookie;
    799      1.1  drochner 	char *name2;
    800      1.1  drochner 	int res, slot;
    801      1.1  drochner 	struct egafont *f;
    802      1.1  drochner 
    803      1.1  drochner 	if (scr) {
    804      1.1  drochner 		name2 = strchr(data->name, ',');
    805      1.1  drochner 		if (name2)
    806      1.1  drochner 			*name2++ = '\0';
    807      1.1  drochner 		res = ega_selectfont(vc, scr, data->name, name2);
    808      1.1  drochner 		if (!res)
    809      1.1  drochner 			ega_setfont(vc, scr);
    810      1.1  drochner 		return (res);
    811      1.1  drochner 	}
    812      1.1  drochner 
    813      1.1  drochner 	if (data->fontwidth != 8 || data->stride != 1)
    814      1.1  drochner 		return (EINVAL); /* XXX 1 byte per line */
    815      1.1  drochner 	if (data->firstchar != 0 || data->numchars != 256)
    816      1.1  drochner 		return (EINVAL);
    817      1.1  drochner #ifndef WSCONS_SUPPORT_PCVTFONTS
    818      1.1  drochner 	if (data->encoding == WSDISPLAY_FONTENC_PCVT) {
    819      1.1  drochner 		printf("vga: pcvt font support not built in, see vga(4)\n");
    820      1.1  drochner 		return (EINVAL);
    821      1.1  drochner 	}
    822      1.1  drochner #endif
    823      1.1  drochner 
    824      1.1  drochner 	for (slot = 0; slot < 4; slot++)
    825      1.1  drochner 		if (!vc->vc_fonts[slot])
    826      1.1  drochner 			break;
    827      1.1  drochner 	if (slot == 4)
    828      1.1  drochner 		return (ENOSPC);
    829      1.1  drochner 
    830      1.1  drochner 	f = malloc(sizeof(struct egafont), M_DEVBUF, M_WAITOK);
    831      1.1  drochner 	strncpy(f->name, data->name, sizeof(f->name));
    832      1.1  drochner 	f->height = data->fontheight;
    833      1.1  drochner 	f->encoding = data->encoding;
    834      1.1  drochner #ifdef notyet
    835      1.1  drochner 	f->firstchar = data->firstchar;
    836      1.1  drochner 	f->numchars = data->numchars;
    837      1.1  drochner #endif
    838      1.1  drochner #ifdef EGAFONTDEBUG
    839      1.1  drochner 	printf("ega: load %s (8x%d, enc %d) font to slot %d\n", f->name,
    840      1.1  drochner 	       f->height, f->encoding, slot);
    841      1.1  drochner #endif
    842      1.1  drochner 	vga_loadchars(&vc->hdl, 2 * slot, 0, 256, f->height, data->data);
    843      1.1  drochner 	f->slot = slot;
    844      1.1  drochner 	vc->vc_fonts[slot] = f;
    845      1.1  drochner 
    846      1.1  drochner 	return (0);
    847      1.1  drochner }
    848      1.1  drochner 
    849      1.1  drochner static int
    850  1.5.6.4  jdolecek ega_allocattr(id, fg, bg, flags, attrp)
    851      1.1  drochner 	void *id;
    852      1.1  drochner 	int fg, bg;
    853      1.1  drochner 	int flags;
    854      1.1  drochner 	long *attrp;
    855      1.1  drochner {
    856      1.1  drochner 	struct egascreen *scr = id;
    857      1.1  drochner 	struct ega_config *vc = scr->cfg;
    858      1.1  drochner 
    859      1.1  drochner 	if (vc->hdl.vh_mono) {
    860      1.1  drochner 		if (flags & WSATTR_WSCOLORS)
    861      1.1  drochner 			return (EINVAL);
    862      1.1  drochner 		if (flags & WSATTR_REVERSE)
    863      1.1  drochner 			*attrp = 0x70;
    864      1.1  drochner 		else
    865      1.1  drochner 			*attrp = 0x07;
    866      1.1  drochner 		if (flags & WSATTR_UNDERLINE)
    867      1.1  drochner 			*attrp |= FG_UNDERLINE;
    868      1.1  drochner 		if (flags & WSATTR_HILIT)
    869      1.1  drochner 			*attrp |= FG_INTENSE;
    870      1.1  drochner 	} else {
    871      1.1  drochner 		if (flags & (WSATTR_UNDERLINE | WSATTR_REVERSE))
    872      1.1  drochner 			return (EINVAL);
    873      1.1  drochner 		if (flags & WSATTR_WSCOLORS)
    874      1.1  drochner 			*attrp = fgansitopc[fg] | bgansitopc[bg];
    875      1.1  drochner 		else
    876      1.1  drochner 			*attrp = 7;
    877      1.1  drochner 		if (flags & WSATTR_HILIT)
    878      1.1  drochner 			*attrp += 8;
    879      1.1  drochner 	}
    880      1.1  drochner 	if (flags & WSATTR_BLINK)
    881      1.1  drochner 		*attrp |= FG_BLINK;
    882      1.1  drochner 	return (0);
    883      1.1  drochner }
    884      1.1  drochner 
    885      1.1  drochner void
    886      1.1  drochner ega_copyrows(id, srcrow, dstrow, nrows)
    887      1.1  drochner 	void *id;
    888      1.1  drochner 	int srcrow, dstrow, nrows;
    889      1.1  drochner {
    890      1.1  drochner 	struct egascreen *scr = id;
    891      1.1  drochner 	bus_space_tag_t memt = scr->pcs.hdl->ph_memt;
    892      1.1  drochner 	bus_space_handle_t memh = scr->pcs.hdl->ph_memh;
    893      1.1  drochner 	int ncols = scr->pcs.type->ncols;
    894      1.1  drochner 	bus_size_t srcoff, dstoff;
    895      1.1  drochner 
    896      1.1  drochner 	srcoff = srcrow * ncols + 0;
    897      1.1  drochner 	dstoff = dstrow * ncols + 0;
    898      1.1  drochner 
    899      1.1  drochner 	if (scr->pcs.active) {
    900      1.1  drochner 		if (dstrow == 0 && (srcrow + nrows == scr->pcs.type->nrows)) {
    901      1.1  drochner #ifdef PCDISPLAY_SOFTCURSOR
    902      1.1  drochner 			int cursoron = scr->pcs.cursoron;
    903      1.1  drochner 
    904      1.1  drochner 			if (cursoron)
    905      1.1  drochner 				pcdisplay_cursor(&scr->pcs, 0,
    906  1.5.6.4  jdolecek 				    scr->pcs.cursorrow, scr->pcs.cursorcol);
    907      1.1  drochner #endif
    908      1.1  drochner 			/* scroll up whole screen */
    909      1.1  drochner 			if ((scr->pcs.dispoffset + srcrow * ncols * 2)
    910      1.1  drochner 			    <= scr->maxdispoffset) {
    911      1.1  drochner 				scr->pcs.dispoffset += srcrow * ncols * 2;
    912      1.1  drochner 			} else {
    913      1.1  drochner 				bus_space_copy_region_2(memt, memh,
    914      1.1  drochner 					scr->pcs.dispoffset + srcoff * 2,
    915      1.1  drochner 					memh, scr->mindispoffset,
    916      1.1  drochner 					nrows * ncols);
    917      1.1  drochner 				scr->pcs.dispoffset = scr->mindispoffset;
    918      1.1  drochner 			}
    919      1.1  drochner 			vga_6845_write(&scr->cfg->hdl, startadrh,
    920      1.1  drochner 				       scr->pcs.dispoffset >> 9);
    921      1.1  drochner 			vga_6845_write(&scr->cfg->hdl, startadrl,
    922      1.1  drochner 				       scr->pcs.dispoffset >> 1);
    923      1.1  drochner #ifdef PCDISPLAY_SOFTCURSOR
    924      1.1  drochner 			if (cursoron)
    925      1.1  drochner 				pcdisplay_cursor(&scr->pcs, 1,
    926  1.5.6.4  jdolecek 				    scr->pcs.cursorrow, scr->pcs.cursorcol);
    927      1.1  drochner #endif
    928      1.1  drochner 		} else {
    929      1.1  drochner 			bus_space_copy_region_2(memt, memh,
    930      1.1  drochner 					scr->pcs.dispoffset + srcoff * 2,
    931      1.1  drochner 					memh, scr->pcs.dispoffset + dstoff * 2,
    932      1.1  drochner 					nrows * ncols);
    933      1.1  drochner 		}
    934      1.1  drochner 	} else
    935  1.5.6.1     lukem 		memcpy(&scr->pcs.mem[dstoff], &scr->pcs.mem[srcoff],
    936      1.1  drochner 		      nrows * ncols * 2);
    937      1.1  drochner }
    938