Home | History | Annotate | Line # | Download | only in ic
vgavar.h revision 1.7
      1 /* $NetBSD: vgavar.h,v 1.7 2001/09/14 01:10:11 thorpej Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/callout.h>
     31 
     32 struct vga_handle {
     33 	struct pcdisplay_handle vh_ph;
     34 	bus_space_handle_t vh_ioh_vga, vh_allmemh;
     35 	int vh_mono;
     36 };
     37 #define vh_iot vh_ph.ph_iot
     38 #define vh_memt vh_ph.ph_memt
     39 #define vh_ioh_6845 vh_ph.ph_ioh_6845
     40 #define vh_memh vh_ph.ph_memh
     41 
     42 struct vga_funcs {
     43 	int (*vf_ioctl)(void *, u_long, caddr_t, int, struct proc *);
     44 	paddr_t (*vf_mmap)(void *, off_t, int);
     45 };
     46 
     47 struct vga_config {
     48 	struct vga_handle hdl;
     49 	struct vga_softc *softc;
     50 
     51 	int nscreens;
     52 	LIST_HEAD(, vgascreen) screens;
     53 	struct vgascreen *active; /* current display */
     54 	const struct wsscreen_descr *currenttype;
     55 	int currentfontset1, currentfontset2;
     56 
     57 	int vc_biosmapped;
     58 	bus_space_tag_t vc_biostag;
     59 	bus_space_handle_t vc_bioshdl;
     60 
     61 	struct egavga_font *vc_fonts[8]; /* currently loaded */
     62 	TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
     63 
     64 	struct vgascreen *wantedscreen;
     65 	void (*switchcb) __P((void *, int, int));
     66 	void *switchcbarg;
     67 
     68 	int vc_type;
     69 	const struct vga_funcs *vc_funcs;
     70 
     71 	struct callout vc_switch_callout;
     72 };
     73 
     74 struct vga_softc {
     75 	struct device sc_dev;
     76 	struct vga_config *sc_vc;
     77 };
     78 
     79 static inline u_int8_t _vga_attr_read __P((struct vga_handle *, int));
     80 static inline void _vga_attr_write __P((struct vga_handle *, int, u_int8_t));
     81 static inline u_int8_t _vga_ts_read __P((struct vga_handle *, int));
     82 static inline void _vga_ts_write __P((struct vga_handle *, int, u_int8_t));
     83 static inline u_int8_t _vga_gdc_read __P((struct vga_handle *, int));
     84 static inline void _vga_gdc_write __P((struct vga_handle *, int, u_int8_t));
     85 
     86 static inline u_int8_t _vga_attr_read(vh, reg)
     87 	struct vga_handle *vh;
     88 	int reg;
     89 {
     90 	u_int8_t res;
     91 
     92 	/* reset state */
     93 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
     94 
     95 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
     96 	res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
     97 
     98 	/* reset state XXX unneeded? */
     99 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    100 
    101 	/* enable */
    102 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
    103 
    104 	return (res);
    105 }
    106 
    107 static inline void _vga_attr_write(vh, reg, val)
    108 	struct vga_handle *vh;
    109 	int reg;
    110 	u_int8_t val;
    111 {
    112 	/* reset state */
    113 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    114 
    115 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
    116 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
    117 
    118 	/* reset state XXX unneeded? */
    119 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    120 
    121 	/* enable */
    122 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
    123 }
    124 
    125 static inline u_int8_t _vga_ts_read(vh, reg)
    126 	struct vga_handle *vh;
    127 	int reg;
    128 {
    129 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
    130 	return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
    131 }
    132 
    133 static inline void _vga_ts_write(vh, reg, val)
    134 	struct vga_handle *vh;
    135 	int reg;
    136 	u_int8_t val;
    137 {
    138 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
    139 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
    140 }
    141 
    142 static inline u_int8_t _vga_gdc_read(vh, reg)
    143 	struct vga_handle *vh;
    144 	int reg;
    145 {
    146 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
    147 	return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
    148 }
    149 
    150 static inline void _vga_gdc_write(vh, reg, val)
    151 	struct vga_handle *vh;
    152 	int reg;
    153 	u_int8_t val;
    154 {
    155 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
    156 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
    157 }
    158 
    159 #define vga_attr_read(vh, reg) \
    160 	_vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
    161 #define vga_attr_write(vh, reg, val) \
    162 	_vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
    163 #define vga_ts_read(vh, reg) \
    164 	_vga_ts_read(vh, offsetof(struct reg_vgats, reg))
    165 #define vga_ts_write(vh, reg, val) \
    166 	_vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
    167 #define vga_gdc_read(vh, reg) \
    168 	_vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
    169 #define vga_gdc_write(vh, reg, val) \
    170 	_vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
    171 
    172 #define vga_6845_read(vh, reg) \
    173 	pcdisplay_6845_read(&(vh)->vh_ph, reg)
    174 #define vga_6845_write(vh, reg, val) \
    175 	pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
    176 
    177 int	vga_common_probe __P((bus_space_tag_t, bus_space_tag_t));
    178 void	vga_common_attach __P((struct vga_softc *, bus_space_tag_t,
    179 			       bus_space_tag_t, int,
    180 			       const struct vga_funcs *));
    181 int	vga_is_console __P((bus_space_tag_t, int));
    182 
    183 int	vga_cnattach __P((bus_space_tag_t, bus_space_tag_t, int, int));
    184 
    185 struct wsscreen_descr;
    186 void vga_loadchars __P((struct vga_handle *, int, int, int, int, char *));
    187 void vga_setfontset __P((struct vga_handle *, int, int));
    188 void vga_setscreentype __P((struct vga_handle *,
    189 			    const struct wsscreen_descr *));
    190