1 /* $OpenBSD: vgavar.h,v 1.13 2015/07/26 03:17:07 miod Exp $ */ 2 /* $NetBSD: vgavar.h,v 1.4 2000/06/17 07:11:50 soda Exp $ */ 3 4 /* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31 #include <sys/timeout.h> 32 33 struct vga_handle { 34 struct pcdisplay_handle vh_ph; 35 bus_space_handle_t vh_ioh_vga, vh_allmemh; 36 int vh_mono; 37 }; 38 #define vh_iot vh_ph.ph_iot 39 #define vh_memt vh_ph.ph_memt 40 #define vh_ioh_6845 vh_ph.ph_ioh_6845 41 #define vh_memh vh_ph.ph_memh 42 43 struct vgascreen { 44 struct pcdisplayscreen pcs; 45 LIST_ENTRY(vgascreen) next; 46 47 /* videostate */ 48 struct vga_config *cfg; 49 /* font data */ 50 struct vgafont *fontset1, *fontset2; 51 52 int mindispoffset, maxdispoffset; 53 int vga_rollover; 54 }; 55 56 struct vga_config { 57 struct vga_handle hdl; 58 59 struct device *vc_softc; 60 int vc_type; 61 int nscreens; 62 LIST_HEAD(, vgascreen) screens; 63 struct vgascreen *active; /* current display */ 64 const struct wsscreen_descr *currenttype; 65 int currentfontset1, currentfontset2; 66 67 #define VGA_MAXFONT 8 68 struct vgafont *vc_fonts[VGA_MAXFONT]; 69 uint8_t vc_palette[256 * 3]; 70 71 struct vgascreen *wantedscreen; 72 void (*switchcb)(void *, int, int); 73 void *switchcbarg; 74 75 paddr_t (*vc_mmap)(void *, off_t, int); 76 77 struct timeout vc_switch_timeout; 78 79 #ifdef __alpha__ 80 /* placeholder for a custom wsscreen_descr for odd resolutions */ 81 struct wsscreen_descr custom_scr; 82 struct wsscreen_descr *custom_scrlist[1]; 83 struct wsscreen_list custom_list; 84 #endif 85 }; 86 87 static inline u_int8_t _vga_attr_read(struct vga_handle *, int); 88 static inline void _vga_attr_write(struct vga_handle *, int, u_int8_t); 89 static inline u_int8_t _vga_ts_read(struct vga_handle *, int); 90 static inline void _vga_ts_write(struct vga_handle *, int, u_int8_t); 91 static inline u_int8_t _vga_gdc_read(struct vga_handle *, int); 92 static inline void _vga_gdc_write(struct vga_handle *, int, u_int8_t); 93 94 #define vga_raw_read(vh, reg) \ 95 bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, reg) 96 #define vga_raw_write(vh, reg, value) \ 97 bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga, reg, value) 98 99 #define vga_enable(vh) \ 100 vga_raw_write(vh, 0, 0x20); 101 102 static inline u_int8_t 103 _vga_attr_read(struct vga_handle *vh, int reg) 104 { 105 u_int8_t res; 106 107 /* reset state */ 108 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10); 109 110 vga_raw_write(vh, VGA_ATC_INDEX, reg); 111 res = vga_raw_read(vh, VGA_ATC_DATAR); 112 113 /* reset state XXX unneeded? */ 114 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10); 115 116 vga_enable(vh); 117 118 return (res); 119 } 120 121 static inline void 122 _vga_attr_write(struct vga_handle *vh, int reg, u_int8_t val) 123 { 124 /* reset state */ 125 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10); 126 127 vga_raw_write(vh, VGA_ATC_INDEX, reg); 128 vga_raw_write(vh, VGA_ATC_DATAW, val); 129 130 /* reset state XXX unneeded? */ 131 (void) bus_space_read_1(vh->vh_iot, vh->vh_ioh_6845, 10); 132 133 vga_enable(vh); 134 } 135 136 static inline u_int8_t 137 _vga_ts_read(struct vga_handle *vh, int reg) 138 { 139 vga_raw_write(vh, VGA_TS_INDEX, reg); 140 return (vga_raw_read(vh, VGA_TS_DATA)); 141 } 142 143 static inline void 144 _vga_ts_write(struct vga_handle *vh, int reg, u_int8_t val) 145 { 146 vga_raw_write(vh, VGA_TS_INDEX, reg); 147 vga_raw_write(vh, VGA_TS_DATA, val); 148 } 149 150 static inline u_int8_t 151 _vga_gdc_read(struct vga_handle *vh, int reg) 152 { 153 vga_raw_write(vh, VGA_GDC_INDEX, reg); 154 return (vga_raw_read(vh, VGA_GDC_DATA)); 155 } 156 157 static inline void 158 _vga_gdc_write(struct vga_handle *vh, int reg, u_int8_t val) 159 { 160 vga_raw_write(vh, VGA_GDC_INDEX, reg); 161 vga_raw_write(vh, VGA_GDC_DATA, val); 162 } 163 164 #define vga_attr_read(vh, reg) \ 165 _vga_attr_read(vh, offsetof(struct reg_vgaattr, reg)) 166 #define vga_attr_write(vh, reg, val) \ 167 _vga_attr_write(vh, offsetof(struct reg_vgaattr, reg), val) 168 #define vga_ts_read(vh, reg) \ 169 _vga_ts_read(vh, offsetof(struct reg_vgats, reg)) 170 #define vga_ts_write(vh, reg, val) \ 171 _vga_ts_write(vh, offsetof(struct reg_vgats, reg), val) 172 #define vga_gdc_read(vh, reg) \ 173 _vga_gdc_read(vh, offsetof(struct reg_vgagdc, reg)) 174 #define vga_gdc_write(vh, reg, val) \ 175 _vga_gdc_write(vh, offsetof(struct reg_vgagdc, reg), val) 176 177 #define vga_6845_read(vh, reg) \ 178 pcdisplay_6845_read(&(vh)->vh_ph, reg) 179 #define vga_6845_write(vh, reg, val) \ 180 pcdisplay_6845_write(&(vh)->vh_ph, reg, val) 181 182 int vga_common_probe(bus_space_tag_t, bus_space_tag_t); 183 struct vga_config * 184 vga_common_attach(struct device *, bus_space_tag_t, bus_space_tag_t, 185 int); 186 struct vga_config * 187 vga_extended_attach(struct device *, bus_space_tag_t, bus_space_tag_t, 188 int, paddr_t (*)(void *, off_t, int)); 189 int vga_is_console(bus_space_tag_t, int); 190 int vga_cnattach(bus_space_tag_t, bus_space_tag_t, int, int); 191 192 struct wsscreen_descr; 193 void vga_loadchars(struct vga_handle *, int, int, int, int, char *); 194 void vga_restore_fonts(struct vga_config *); 195 void vga_restore_palette(struct vga_config *); 196 void vga_save_palette(struct vga_config *); 197 void vga_setfontset(struct vga_handle *, int, int); 198 void vga_setscreentype(struct vga_handle *, const struct wsscreen_descr *); 199 #if NVGA_PCI > 0 200 int vga_pci_ioctl(void *, u_long, caddr_t, int, struct proc *); 201 #endif 202