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