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