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