Home | History | Annotate | Line # | Download | only in ic
vgavar.h revision 1.11
      1  1.11  drochner /* $NetBSD: vgavar.h,v 1.11 2002/06/25 21:07:42 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.7   thorpej #include <sys/callout.h>
     31   1.7   thorpej 
     32   1.1  drochner struct vga_handle {
     33   1.2  drochner 	struct pcdisplay_handle vh_ph;
     34   1.2  drochner 	bus_space_handle_t vh_ioh_vga, vh_allmemh;
     35   1.2  drochner 	int vh_mono;
     36   1.1  drochner };
     37   1.8  junyoung #define vh_iot 		vh_ph.ph_iot
     38   1.8  junyoung #define vh_memt 	vh_ph.ph_memt
     39   1.8  junyoung #define vh_ioh_6845 	vh_ph.ph_ioh_6845
     40   1.8  junyoung #define vh_memh 	vh_ph.ph_memh
     41   1.1  drochner 
     42   1.7   thorpej struct vga_funcs {
     43   1.7   thorpej 	int (*vf_ioctl)(void *, u_long, caddr_t, int, struct proc *);
     44   1.7   thorpej 	paddr_t (*vf_mmap)(void *, off_t, int);
     45   1.7   thorpej };
     46   1.7   thorpej 
     47   1.7   thorpej struct vga_config {
     48   1.7   thorpej 	struct vga_handle hdl;
     49   1.7   thorpej 	struct vga_softc *softc;
     50   1.7   thorpej 
     51   1.7   thorpej 	int nscreens;
     52   1.7   thorpej 	LIST_HEAD(, vgascreen) screens;
     53   1.7   thorpej 	struct vgascreen *active; /* current display */
     54   1.7   thorpej 	const struct wsscreen_descr *currenttype;
     55   1.7   thorpej 	int currentfontset1, currentfontset2;
     56   1.7   thorpej 
     57   1.7   thorpej 	int vc_biosmapped;
     58   1.7   thorpej 	bus_space_tag_t vc_biostag;
     59   1.7   thorpej 	bus_space_handle_t vc_bioshdl;
     60   1.7   thorpej 
     61  1.11  drochner 	int vc_nfontslots;
     62   1.7   thorpej 	struct egavga_font *vc_fonts[8]; /* currently loaded */
     63   1.7   thorpej 	TAILQ_HEAD(, egavga_font) vc_fontlist; /* LRU queue */
     64   1.7   thorpej 
     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.7   thorpej 	int vc_type;
     70   1.7   thorpej 	const struct vga_funcs *vc_funcs;
     71   1.7   thorpej 
     72   1.7   thorpej 	struct callout vc_switch_callout;
     73   1.7   thorpej };
     74   1.7   thorpej 
     75   1.7   thorpej struct vga_softc {
     76   1.7   thorpej 	struct device sc_dev;
     77   1.7   thorpej 	struct vga_config *sc_vc;
     78   1.7   thorpej };
     79   1.7   thorpej 
     80   1.8  junyoung static inline u_int8_t 	_vga_attr_read(struct vga_handle *, int);
     81   1.8  junyoung static inline void 	_vga_attr_write(struct vga_handle *, int, u_int8_t);
     82   1.8  junyoung static inline u_int8_t 	_vga_ts_read(struct vga_handle *, int);
     83   1.8  junyoung static inline void 	_vga_ts_write(struct vga_handle *, int, u_int8_t);
     84   1.8  junyoung static inline u_int8_t 	_vga_gdc_read(struct vga_handle *, int);
     85   1.8  junyoung static inline void 	_vga_gdc_write(struct vga_handle *, int, u_int8_t);
     86  1.10  junyoung static inline u_int8_t 	_vga_crtc_read(struct vga_handle *, int);
     87  1.10  junyoung static inline void 	_vga_crtc_write(struct vga_handle *, int, u_int8_t);
     88   1.8  junyoung 
     89   1.9  junyoung static inline u_int8_t
     90   1.9  junyoung _vga_attr_read(struct vga_handle *vh, int reg)
     91   1.1  drochner {
     92   1.1  drochner 	u_int8_t res;
     93   1.1  drochner 
     94   1.1  drochner 	/* reset state */
     95   1.1  drochner 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
     96   1.1  drochner 
     97   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
     98   1.1  drochner 	res = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAR);
     99   1.1  drochner 
    100   1.1  drochner 	/* reset state XXX unneeded? */
    101   1.1  drochner 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    102   1.1  drochner 
    103   1.1  drochner 	/* enable */
    104   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
    105   1.1  drochner 
    106   1.1  drochner 	return (res);
    107   1.1  drochner }
    108   1.1  drochner 
    109   1.9  junyoung static inline void
    110   1.9  junyoung _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val)
    111   1.1  drochner {
    112   1.1  drochner 	/* reset state */
    113   1.1  drochner 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    114   1.1  drochner 
    115   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_INDEX, reg);
    116   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_ATC_DATAW, val);
    117   1.1  drochner 
    118   1.1  drochner 	/* reset state XXX unneeded? */
    119   1.1  drochner 	(void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10);
    120   1.1  drochner 
    121   1.1  drochner 	/* enable */
    122   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, 0, 0x20);
    123   1.1  drochner }
    124   1.1  drochner 
    125   1.9  junyoung static inline u_int8_t
    126   1.9  junyoung _vga_ts_read(struct vga_handle *vh, int reg)
    127   1.1  drochner {
    128   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
    129   1.1  drochner 	return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA));
    130   1.1  drochner }
    131   1.1  drochner 
    132   1.9  junyoung static inline void
    133   1.9  junyoung _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val)
    134   1.1  drochner {
    135   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_INDEX, reg);
    136   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_TS_DATA, val);
    137   1.1  drochner }
    138   1.1  drochner 
    139   1.9  junyoung static inline u_int8_t
    140   1.9  junyoung _vga_gdc_read(struct vga_handle *vh, int reg)
    141   1.1  drochner {
    142   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
    143   1.1  drochner 	return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA));
    144   1.1  drochner }
    145   1.1  drochner 
    146   1.9  junyoung static inline void
    147   1.9  junyoung _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val)
    148   1.1  drochner {
    149   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_INDEX, reg);
    150   1.1  drochner 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_GDC_DATA, val);
    151  1.10  junyoung }
    152  1.10  junyoung 
    153  1.10  junyoung static inline u_int8_t
    154  1.10  junyoung _vga_crtc_read(struct vga_handle *vh, int reg)
    155  1.10  junyoung {
    156  1.10  junyoung 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
    157  1.10  junyoung 	return (bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA));
    158  1.10  junyoung }
    159  1.10  junyoung 
    160  1.10  junyoung static inline void
    161  1.10  junyoung _vga_crtc_write(struct vga_handle *vh, int reg, u_int8_t val)
    162  1.10  junyoung {
    163  1.10  junyoung 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_INDEX, reg);
    164  1.10  junyoung 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, VGA_CRTC_DATA, val);
    165   1.1  drochner }
    166   1.1  drochner 
    167   1.1  drochner #define vga_attr_read(vh, reg) \
    168   1.1  drochner 	_vga_attr_read(vh, offsetof(struct reg_vgaattr, reg))
    169   1.1  drochner #define vga_attr_write(vh, reg, val) \
    170   1.1  drochner 	_vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val)
    171   1.1  drochner #define vga_ts_read(vh, reg) \
    172   1.1  drochner 	_vga_ts_read(vh, offsetof(struct reg_vgats, reg))
    173   1.1  drochner #define vga_ts_write(vh, reg, val) \
    174   1.1  drochner 	_vga_ts_write(vh, offsetof(struct reg_vgats, reg), val)
    175   1.1  drochner #define vga_gdc_read(vh, reg) \
    176   1.1  drochner 	_vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg))
    177   1.1  drochner #define vga_gdc_write(vh, reg, val) \
    178   1.1  drochner 	_vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val)
    179   1.1  drochner 
    180   1.2  drochner #define vga_6845_read(vh, reg) \
    181   1.2  drochner 	pcdisplay_6845_read(&(vh)->vh_ph, reg)
    182   1.2  drochner #define vga_6845_write(vh, reg, val) \
    183   1.2  drochner 	pcdisplay_6845_write(&(vh)->vh_ph, reg, val)
    184   1.1  drochner 
    185   1.8  junyoung int	vga_common_probe(bus_space_tag_t, bus_space_tag_t);
    186   1.8  junyoung void	vga_common_attach(struct vga_softc *, bus_space_tag_t,
    187  1.11  drochner 			  bus_space_tag_t, int, int,
    188  1.11  drochner 			  const struct vga_funcs *);
    189  1.11  drochner #define VGA_QUIRK_ONEFONT	0x01
    190  1.11  drochner #define VGA_QUIRK_NOFASTSCROLL	0x02
    191   1.8  junyoung int	vga_is_console(bus_space_tag_t, int);
    192   1.1  drochner 
    193   1.8  junyoung int	vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int);
    194   1.1  drochner 
    195   1.1  drochner struct wsscreen_descr;
    196   1.8  junyoung void 	vga_loadchars(struct vga_handle *, int, int, int, int, char *);
    197   1.8  junyoung void 	vga_setfontset(struct vga_handle *, int, int);
    198   1.8  junyoung void 	vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *);
    199