pci_vga.c revision 1.5 1 /* $NetBSD: pci_vga.c,v 1.5 2001/05/28 08:30:03 leo Exp $ */
2
3 /*
4 * Copyright (c) 1999 Leo Weppelman. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Leo Weppelman.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include <sys/param.h>
32 #include <sys/queue.h>
33 #include <sys/systm.h>
34 #include <dev/pci/pcireg.h>
35 #include <dev/pci/pcivar.h>
36 #include <dev/pci/pcidevs.h>
37 #include <atari/pci/pci_vga.h>
38 #include <atari/dev/grf_etreg.h>
39 #include <atari/include/iomap.h>
40
41 #include <atari/dev/font.h>
42
43 #if NVGA_PCI > 0
44 #include <dev/cons.h>
45 #include <dev/ic/mc6845reg.h>
46 #include <dev/ic/pcdisplayvar.h>
47 #include <dev/ic/vgareg.h>
48 #include <dev/ic/vgavar.h>
49 #endif
50
51 static void loadfont(volatile u_char *, u_char *fb);
52
53 /* XXX: Shouldn't these be in font.h???? */
54 extern font_info font_info_8x8;
55 extern font_info font_info_8x16;
56
57 /* Console colors */
58 static u_char conscolors[3][3] = { /* background, foreground, hilite */
59 {0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f, 0x3f, 0x3f}
60 };
61
62 static bus_space_tag_t vga_iot, vga_memt;
63 static int tags_valid = 0;
64
65 #define VGA_REG_SIZE (8*1024)
66 #define VGA_FB_SIZE (32*1024)
67
68 /*
69 * Go look for a VGA card on the PCI-bus. This search is a
70 * stripped down version of the PCI-probe. It only looks on
71 * bus0 for VGA cards. The first card found is used.
72 */
73 int
74 check_for_vga(iot, memt)
75 bus_space_tag_t iot, memt;
76 {
77 pci_chipset_tag_t pc = NULL; /* XXX */
78 bus_space_handle_t ioh_regs, memh_fb;
79 pcitag_t tag;
80 int device, found, id, maxndevs, i, j;
81 int class, got_ioh, got_memh, rv;
82 volatile u_char *regs;
83 u_char *fb;
84 char *nbd = "NetBSD/Atari";
85
86 found = 0;
87 tag = 0;
88 id = 0;
89 rv = 0;
90 got_ioh = 0;
91 got_memh = 0;
92 maxndevs = pci_bus_maxdevs(pc, 0);
93
94 /*
95 * Map 8Kb of registers and 32Kb frame buffer.
96 * XXX: The way the registers are mapped here is plain wrong.
97 * We should try to pin-point the region down to 3[bcd]0 (see
98 * .../dev/ic/vga.c).
99 */
100 if (bus_space_map(iot, 0, VGA_REG_SIZE, 0, &ioh_regs))
101 return 0;
102 got_ioh = 1;
103
104 if (bus_space_map(memt, 0xa0000, VGA_FB_SIZE, 0, &memh_fb))
105 goto bad;
106 got_memh = 1;
107 regs = bus_space_vaddr(iot, ioh_regs);
108 fb = bus_space_vaddr(memt, memh_fb);
109
110 for (device = 0; !found && (device < maxndevs); device++) {
111
112 tag = pci_make_tag(pc, 0, device, 0);
113 id = pci_conf_read(pc, tag, PCI_ID_REG);
114 if (id == 0 || id == 0xffffffff)
115 continue;
116
117 /*
118 * Check if we have some display device here...
119 */
120 class = pci_conf_read(pc, tag, PCI_CLASS_REG);
121 i = 0;
122 if (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&
123 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)
124 i = 1;
125 if (PCI_CLASS(class) == PCI_CLASS_DISPLAY &&
126 PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA)
127 i = 1;
128 if (i == 0)
129 continue;
130
131 #if _MILANHW_
132 /* Don't need to be more specific */
133 milan_vga_init(pc, tag, id, regs, fb);
134 found = 1;
135 #else
136 switch (id = PCI_PRODUCT(id)) {
137
138 /*
139 * XXX Make the inclusion of the cases dependend
140 * on config options!
141 */
142 case PCI_PRODUCT_TSENG_ET6000:
143 case PCI_PRODUCT_TSENG_ET4000_W32P_A:
144 case PCI_PRODUCT_TSENG_ET4000_W32P_B:
145 case PCI_PRODUCT_TSENG_ET4000_W32P_C:
146 case PCI_PRODUCT_TSENG_ET4000_W32P_D:
147 tseng_init(pc, tag, id, regs, fb);
148 found = 1;
149 break;
150 default:
151 break;
152 }
153 #endif /* _MILANHW_ */
154 }
155 if (!found)
156 goto bad;
157
158 /*
159 * Assume the device is in CGA mode. Wscons expects this too...
160 */
161 bus_space_unmap(memt, memh_fb, VGA_FB_SIZE);
162 if (bus_space_map(memt, 0xb8000, VGA_FB_SIZE, 0, &memh_fb)) {
163 got_memh = 0;
164 goto bad;
165 }
166 fb = bus_space_vaddr(memt, memh_fb);
167
168 /*
169 * Generic parts of the initialization...
170 */
171
172 /* B&W colors */
173 vgaw(regs, VDAC_ADDRESS_W, 0);
174 for (i = 0; i < 256; i++) {
175 j = (i & 1) ? ((i > 7) ? 2 : 1) : 0;
176 vgaw(regs, VDAC_DATA, conscolors[j][0]);
177 vgaw(regs, VDAC_DATA, conscolors[j][1]);
178 vgaw(regs, VDAC_DATA, conscolors[j][2]);
179 }
180
181 loadfont(regs, fb);
182
183 /*
184 * Clear the screen and print a message. The latter
185 * is of diagnostic/debug use only.
186 */
187 for (i = 50 * 80; i >= 0; i -= 2) {
188 fb[i] = 0x20; fb[i+1] = 0x07;
189 }
190 for (i = 56; *nbd; i += 2)
191 fb[i] = *nbd++;
192
193 rv = 1;
194 vga_iot = iot;
195 vga_memt = memt;
196 rv = tags_valid = 1;
197
198 bad:
199 if (got_memh)
200 bus_space_unmap(memt, memh_fb, VGA_FB_SIZE);
201 if (got_ioh)
202 bus_space_unmap(iot, ioh_regs, VGA_REG_SIZE);
203 return (rv);
204 }
205
206 #if NVGA_PCI > 0
207 void vgacnprobe(struct consdev *);
208 void vgacninit(struct consdev *);
209
210 void
211 vgacnprobe(cp)
212 struct consdev *cp;
213 {
214 if (tags_valid)
215 cp->cn_pri = CN_NORMAL;
216 }
217
218 void
219 vgacninit(cp)
220 struct consdev *cp;
221 {
222 if (tags_valid) {
223 /* XXX: Are those arguments correct? Leo */
224 vga_cnattach(vga_iot, vga_memt, 8, 0);
225 }
226 }
227 #endif /* NVGA_PCI */
228
229 /*
230 * Generic VGA. Load the configured kernel font into the videomemory and
231 * place the card into textmode.
232 */
233 static void
234 loadfont(ba, fb)
235 volatile u_char *ba; /* Register area KVA */
236 u_char *fb; /* Frame buffer KVA */
237 {
238 font_info *fd;
239 u_char *c, *f, tmp;
240 u_short z, y;
241
242 #if defined(KFONT_8X8)
243 fd = &font_info_8x8;
244 #else
245 fd = &font_info_8x16;
246 #endif
247
248 WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
249 WSeq(ba, SEQ_ID_MAP_MASK, 0x04);
250 WSeq(ba, SEQ_ID_MEMORY_MODE, 0x06);
251 WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
252 WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
253 WGfx(ba, GCT_ID_MISC, 0x0c);
254
255 /*
256 * load text font into beginning of display memory. Each
257 * character cell is 32 bytes long (enough for 4 planes)
258 */
259 for (z = 0, c = fb; z < 256 * 32; z++)
260 *c++ = 0;
261
262 c = (unsigned char *) (fb) + (32 * fd->font_lo);
263 f = fd->font_p;
264 z = fd->font_lo;
265 for (; z <= fd->font_hi; z++, c += (32 - fd->height))
266 for (y = 0; y < fd->height; y++) {
267 *c++ = *f++;
268 }
269
270 /*
271 * Odd/Even addressing
272 */
273 WSeq(ba, SEQ_ID_MAP_MASK, 0x03);
274 WSeq(ba, SEQ_ID_MEMORY_MODE, 0x03);
275 WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
276 WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x10);
277 WGfx(ba, GCT_ID_MISC, 0x0e);
278
279 /*
280 * Font height + underline location
281 */
282 tmp = RCrt(ba, CRT_ID_MAX_ROW_ADDRESS) & 0xe0;
283 WCrt(ba, CRT_ID_MAX_ROW_ADDRESS, tmp | (fd->height - 1));
284 tmp = RCrt(ba, CRT_ID_UNDERLINE_LOC) & 0xe0;
285 WCrt(ba, CRT_ID_UNDERLINE_LOC, tmp | (fd->height - 1));
286
287 /*
288 * Cursor setup
289 */
290 WCrt(ba, CRT_ID_CURSOR_START , 0x00);
291 WCrt(ba, CRT_ID_CURSOR_END , fd->height - 1);
292 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
293 WCrt(ba, CRT_ID_CURSOR_LOC_LOW , 0x00);
294
295 /*
296 * Enter text mode
297 */
298 WCrt(ba, CRT_ID_MODE_CONTROL , 0xa3);
299 WAttr(ba, ACT_ID_ATTR_MODE_CNTL | 0x20, 0x0a);
300 }
301