voodoofb.c revision 1.4.2.2 1 1.4.2.2 elad /* $NetBSD: voodoofb.c,v 1.4.2.2 2006/04/19 03:25:38 elad Exp $ */
2 1.4.2.2 elad
3 1.4.2.2 elad /*
4 1.4.2.2 elad * Copyright (c) 2005, 2006 Michael Lorenz
5 1.4.2.2 elad * All rights reserved.
6 1.4.2.2 elad *
7 1.4.2.2 elad * Redistribution and use in source and binary forms, with or without
8 1.4.2.2 elad * modification, are permitted provided that the following conditions
9 1.4.2.2 elad * are met:
10 1.4.2.2 elad * 1. Redistributions of source code must retain the above copyright
11 1.4.2.2 elad * notice, this list of conditions and the following disclaimer.
12 1.4.2.2 elad * 2. Redistributions in binary form must reproduce the above copyright
13 1.4.2.2 elad * notice, this list of conditions and the following disclaimer in the
14 1.4.2.2 elad * documentation and/or other materials provided with the distribution.
15 1.4.2.2 elad * 3. The name of the author may not be used to endorse or promote products
16 1.4.2.2 elad * derived from this software without specific prior written permission.
17 1.4.2.2 elad *
18 1.4.2.2 elad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.4.2.2 elad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.4.2.2 elad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.4.2.2 elad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.4.2.2 elad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.4.2.2 elad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.4.2.2 elad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.4.2.2 elad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.4.2.2 elad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.4.2.2 elad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.4.2.2 elad */
29 1.4.2.2 elad
30 1.4.2.2 elad /*
31 1.4.2.2 elad * A console driver for 3Dfx Voodoo3 graphics boards
32 1.4.2.2 elad * Thanks to Andreas Drewke (andreas_dr (at) gmx.de) for his Voodoo3 driver for BeOS
33 1.4.2.2 elad * which I used as reference / documentation
34 1.4.2.2 elad */
35 1.4.2.2 elad
36 1.4.2.2 elad #include <sys/cdefs.h>
37 1.4.2.2 elad __KERNEL_RCSID(0, "$NetBSD: voodoofb.c,v 1.4.2.2 2006/04/19 03:25:38 elad Exp $");
38 1.4.2.2 elad
39 1.4.2.2 elad #include <sys/param.h>
40 1.4.2.2 elad #include <sys/systm.h>
41 1.4.2.2 elad #include <sys/kernel.h>
42 1.4.2.2 elad #include <sys/device.h>
43 1.4.2.2 elad #include <sys/malloc.h>
44 1.4.2.2 elad #include <sys/callout.h>
45 1.4.2.2 elad
46 1.4.2.2 elad #include <uvm/uvm_extern.h>
47 1.4.2.2 elad
48 1.4.2.2 elad #if defined(macppc) || defined (sparc64) || defined(ofppc)
49 1.4.2.2 elad #define HAVE_OPENFIRMWARE
50 1.4.2.2 elad #endif
51 1.4.2.2 elad
52 1.4.2.2 elad #ifdef HAVE_OPENFIRMWARE
53 1.4.2.2 elad #include <dev/ofw/openfirm.h>
54 1.4.2.2 elad #include <dev/ofw/ofw_pci.h>
55 1.4.2.2 elad #endif
56 1.4.2.2 elad
57 1.4.2.2 elad #include <dev/videomode/videomode.h>
58 1.4.2.2 elad
59 1.4.2.2 elad #include <dev/pci/pcivar.h>
60 1.4.2.2 elad #include <dev/pci/pcireg.h>
61 1.4.2.2 elad #include <dev/pci/pcidevs.h>
62 1.4.2.2 elad #include <dev/pci/pciio.h>
63 1.4.2.2 elad #include <dev/pci/voodoofbreg.h>
64 1.4.2.2 elad
65 1.4.2.2 elad #include <dev/wscons/wsdisplayvar.h>
66 1.4.2.2 elad #include <dev/wscons/wsconsio.h>
67 1.4.2.2 elad #include <dev/wsfont/wsfont.h>
68 1.4.2.2 elad #include <dev/rasops/rasops.h>
69 1.4.2.2 elad #include <dev/wscons/wsdisplay_vconsvar.h>
70 1.4.2.2 elad
71 1.4.2.2 elad #include "opt_wsemul.h"
72 1.4.2.2 elad
73 1.4.2.2 elad struct voodoofb_softc {
74 1.4.2.2 elad struct device sc_dev;
75 1.4.2.2 elad pci_chipset_tag_t sc_pc;
76 1.4.2.2 elad pcitag_t sc_pcitag;
77 1.4.2.2 elad
78 1.4.2.2 elad bus_space_tag_t sc_memt;
79 1.4.2.2 elad bus_space_tag_t sc_iot;
80 1.4.2.2 elad bus_space_handle_t sc_memh;
81 1.4.2.2 elad
82 1.4.2.2 elad bus_space_tag_t sc_regt;
83 1.4.2.2 elad bus_space_tag_t sc_fbt;
84 1.4.2.2 elad bus_space_tag_t sc_ioregt;
85 1.4.2.2 elad bus_space_handle_t sc_regh;
86 1.4.2.2 elad bus_space_handle_t sc_fbh;
87 1.4.2.2 elad bus_space_handle_t sc_ioregh;
88 1.4.2.2 elad bus_addr_t sc_regs, sc_fb, sc_ioreg;
89 1.4.2.2 elad bus_size_t sc_regsize, sc_fbsize, sc_ioregsize;
90 1.4.2.2 elad
91 1.4.2.2 elad void *sc_ih;
92 1.4.2.2 elad
93 1.4.2.2 elad size_t memsize;
94 1.4.2.2 elad int memtype;
95 1.4.2.2 elad
96 1.4.2.2 elad int bits_per_pixel;
97 1.4.2.2 elad int width, height, linebytes;
98 1.4.2.2 elad
99 1.4.2.2 elad int sc_mode;
100 1.4.2.2 elad uint32_t sc_bg;
101 1.4.2.2 elad
102 1.4.2.2 elad u_char sc_cmap_red[256];
103 1.4.2.2 elad u_char sc_cmap_green[256];
104 1.4.2.2 elad u_char sc_cmap_blue[256];
105 1.4.2.2 elad int sc_dacw;
106 1.4.2.2 elad
107 1.4.2.2 elad struct vcons_data vd;
108 1.4.2.2 elad };
109 1.4.2.2 elad
110 1.4.2.2 elad struct voodoo_regs {
111 1.4.2.2 elad uint8_t vr_crtc[31];
112 1.4.2.2 elad uint8_t vr_graph[9];
113 1.4.2.2 elad uint8_t vr_attr[21];
114 1.4.2.2 elad uint8_t vr_seq[5];
115 1.4.2.2 elad };
116 1.4.2.2 elad
117 1.4.2.2 elad static struct vcons_screen voodoofb_console_screen;
118 1.4.2.2 elad
119 1.4.2.2 elad extern const u_char rasops_cmap[768];
120 1.4.2.2 elad
121 1.4.2.2 elad static int voodoofb_match(struct device *, struct cfdata *, void *);
122 1.4.2.2 elad static void voodoofb_attach(struct device *, struct device *, void *);
123 1.4.2.2 elad
124 1.4.2.2 elad CFATTACH_DECL(voodoofb, sizeof(struct voodoofb_softc), voodoofb_match,
125 1.4.2.2 elad voodoofb_attach, NULL, NULL);
126 1.4.2.2 elad
127 1.4.2.2 elad static int voodoofb_is_console(struct pci_attach_args *);
128 1.4.2.2 elad static void voodoofb_init(struct voodoofb_softc *);
129 1.4.2.2 elad
130 1.4.2.2 elad static void voodoofb_cursor(void *, int, int, int);
131 1.4.2.2 elad static void voodoofb_putchar(void *, int, int, u_int, long);
132 1.4.2.2 elad static void voodoofb_copycols(void *, int, int, int, int);
133 1.4.2.2 elad static void voodoofb_erasecols(void *, int, int, int, long);
134 1.4.2.2 elad static void voodoofb_copyrows(void *, int, int, int);
135 1.4.2.2 elad static void voodoofb_eraserows(void *, int, int, long);
136 1.4.2.2 elad
137 1.4.2.2 elad #if 0
138 1.4.2.2 elad static int voodoofb_allocattr(void *, int, int, int, long *);
139 1.4.2.2 elad static void voodoofb_scroll(void *, void *, int);
140 1.4.2.2 elad static int voodoofb_load_font(void *, void *, struct wsdisplay_font *);
141 1.4.2.2 elad #endif
142 1.4.2.2 elad
143 1.4.2.2 elad static int voodoofb_putcmap(struct voodoofb_softc *,
144 1.4.2.2 elad struct wsdisplay_cmap *);
145 1.4.2.2 elad static int voodoofb_getcmap(struct voodoofb_softc *,
146 1.4.2.2 elad struct wsdisplay_cmap *);
147 1.4.2.2 elad static int voodoofb_putpalreg(struct voodoofb_softc *, uint8_t, uint8_t,
148 1.4.2.2 elad uint8_t, uint8_t);
149 1.4.2.2 elad static void voodoofb_bitblt(struct voodoofb_softc *, int, int, int, int,
150 1.4.2.2 elad int, int);
151 1.4.2.2 elad static void voodoofb_rectfill(struct voodoofb_softc *, int, int, int, int,
152 1.4.2.2 elad int);
153 1.4.2.2 elad static void voodoofb_rectinvert(struct voodoofb_softc *, int, int, int,
154 1.4.2.2 elad int);
155 1.4.2.2 elad static void voodoofb_setup_mono(struct voodoofb_softc *, int, int, int,
156 1.4.2.2 elad int, uint32_t, uint32_t);
157 1.4.2.2 elad static void voodoofb_feed_line(struct voodoofb_softc *, int, uint8_t *);
158 1.4.2.2 elad
159 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
160 1.4.2.2 elad static void voodoofb_showpal(struct voodoofb_softc *);
161 1.4.2.2 elad #endif
162 1.4.2.2 elad
163 1.4.2.2 elad static void voodoofb_wait_idle(struct voodoofb_softc *);
164 1.4.2.2 elad
165 1.4.2.2 elad static int voodoofb_intr(void *);
166 1.4.2.2 elad
167 1.4.2.2 elad static void voodoofb_set_videomode(struct voodoofb_softc *,
168 1.4.2.2 elad const struct videomode *);
169 1.4.2.2 elad
170 1.4.2.2 elad struct wsscreen_descr voodoofb_defaultscreen = {
171 1.4.2.2 elad "default",
172 1.4.2.2 elad 0, 0,
173 1.4.2.2 elad NULL,
174 1.4.2.2 elad 8, 16,
175 1.4.2.2 elad WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
176 1.4.2.2 elad };
177 1.4.2.2 elad
178 1.4.2.2 elad const struct wsscreen_descr *_voodoofb_scrlist[] = {
179 1.4.2.2 elad &voodoofb_defaultscreen,
180 1.4.2.2 elad /* XXX other formats, graphics screen? */
181 1.4.2.2 elad };
182 1.4.2.2 elad
183 1.4.2.2 elad struct wsscreen_list voodoofb_screenlist = {
184 1.4.2.2 elad sizeof(_voodoofb_scrlist) / sizeof(struct wsscreen_descr *), _voodoofb_scrlist
185 1.4.2.2 elad };
186 1.4.2.2 elad
187 1.4.2.2 elad static int voodoofb_ioctl(void *, void *, u_long, caddr_t, int,
188 1.4.2.2 elad struct lwp *);
189 1.4.2.2 elad static paddr_t voodoofb_mmap(void *, void *, off_t, int);
190 1.4.2.2 elad
191 1.4.2.2 elad static void voodoofb_clearscreen(struct voodoofb_softc *);
192 1.4.2.2 elad static void voodoofb_init_screen(void *, struct vcons_screen *, int,
193 1.4.2.2 elad long *);
194 1.4.2.2 elad
195 1.4.2.2 elad
196 1.4.2.2 elad struct wsdisplay_accessops voodoofb_accessops = {
197 1.4.2.2 elad voodoofb_ioctl,
198 1.4.2.2 elad voodoofb_mmap,
199 1.4.2.2 elad NULL, /* load_font */
200 1.4.2.2 elad NULL, /* polls */
201 1.4.2.2 elad NULL, /* scroll */
202 1.4.2.2 elad };
203 1.4.2.2 elad
204 1.4.2.2 elad /*
205 1.4.2.2 elad * Inline functions for getting access to register aperture.
206 1.4.2.2 elad */
207 1.4.2.2 elad static inline void
208 1.4.2.2 elad voodoo3_write32(struct voodoofb_softc *sc, uint32_t reg, uint32_t val)
209 1.4.2.2 elad {
210 1.4.2.2 elad bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, val);
211 1.4.2.2 elad }
212 1.4.2.2 elad
213 1.4.2.2 elad static inline uint32_t
214 1.4.2.2 elad voodoo3_read32(struct voodoofb_softc *sc, uint32_t reg)
215 1.4.2.2 elad {
216 1.4.2.2 elad return bus_space_read_4(sc->sc_regt, sc->sc_regh, reg);
217 1.4.2.2 elad }
218 1.4.2.2 elad
219 1.4.2.2 elad static inline void
220 1.4.2.2 elad voodoo3_write_crtc(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
221 1.4.2.2 elad {
222 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, CRTC_INDEX - 0x300, reg);
223 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, CRTC_DATA - 0x300, val);
224 1.4.2.2 elad }
225 1.4.2.2 elad
226 1.4.2.2 elad static inline void
227 1.4.2.2 elad voodoo3_write_seq(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
228 1.4.2.2 elad {
229 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, SEQ_INDEX - 0x300, reg);
230 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, SEQ_DATA - 0x300, val);
231 1.4.2.2 elad }
232 1.4.2.2 elad
233 1.4.2.2 elad static inline void
234 1.4.2.2 elad voodoo3_write_gra(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
235 1.4.2.2 elad {
236 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, GRA_INDEX - 0x300, reg);
237 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, GRA_DATA - 0x300, val);
238 1.4.2.2 elad }
239 1.4.2.2 elad
240 1.4.2.2 elad static inline void
241 1.4.2.2 elad voodoo3_write_attr(struct voodoofb_softc *sc, uint8_t reg, uint8_t val)
242 1.4.2.2 elad {
243 1.4.2.2 elad volatile uint8_t junk;
244 1.4.2.2 elad uint8_t index;
245 1.4.2.2 elad
246 1.4.2.2 elad junk = bus_space_read_1(sc->sc_ioregt, sc->sc_ioregh, IS1_R - 0x300);
247 1.4.2.2 elad index = bus_space_read_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300);
248 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, reg);
249 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, val);
250 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, ATT_IW - 0x300, index);
251 1.4.2.2 elad }
252 1.4.2.2 elad
253 1.4.2.2 elad static inline void
254 1.4.2.2 elad vga_outb(struct voodoofb_softc *sc, uint32_t reg, uint8_t val)
255 1.4.2.2 elad {
256 1.4.2.2 elad bus_space_write_1(sc->sc_ioregt, sc->sc_ioregh, reg - 0x300, val);
257 1.4.2.2 elad }
258 1.4.2.2 elad
259 1.4.2.2 elad /* wait until there's room for len bytes in the FIFO */
260 1.4.2.2 elad static inline void
261 1.4.2.2 elad voodoo3_make_room(struct voodoofb_softc *sc, int len)
262 1.4.2.2 elad {
263 1.4.2.2 elad while ((voodoo3_read32(sc, STATUS) & 0x1f) < len);
264 1.4.2.2 elad }
265 1.4.2.2 elad
266 1.4.2.2 elad static void
267 1.4.2.2 elad voodoofb_wait_idle(struct voodoofb_softc *sc)
268 1.4.2.2 elad {
269 1.4.2.2 elad int i = 0;
270 1.4.2.2 elad
271 1.4.2.2 elad voodoo3_make_room(sc, 1);
272 1.4.2.2 elad voodoo3_write32(sc, COMMAND_3D, COMMAND_3D_NOP);
273 1.4.2.2 elad
274 1.4.2.2 elad while (1) {
275 1.4.2.2 elad i = (voodoo3_read32(sc, STATUS) & STATUS_BUSY) ? 0 : i + 1;
276 1.4.2.2 elad if(i == 3) break;
277 1.4.2.2 elad }
278 1.4.2.2 elad }
279 1.4.2.2 elad
280 1.4.2.2 elad static int
281 1.4.2.2 elad voodoofb_match(struct device *parent, struct cfdata *match, void *aux)
282 1.4.2.2 elad {
283 1.4.2.2 elad struct pci_attach_args *pa = (struct pci_attach_args *)aux;
284 1.4.2.2 elad
285 1.4.2.2 elad if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
286 1.4.2.2 elad PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
287 1.4.2.2 elad return 0;
288 1.4.2.2 elad if ((PCI_VENDOR(pa->pa_id)==PCI_VENDOR_3DFX) &&
289 1.4.2.2 elad (PCI_PRODUCT(pa->pa_id)>=PCI_PRODUCT_3DFX_VOODOO3))
290 1.4.2.2 elad return 100;
291 1.4.2.2 elad return 0;
292 1.4.2.2 elad }
293 1.4.2.2 elad
294 1.4.2.2 elad static void
295 1.4.2.2 elad voodoofb_attach(struct device *parent, struct device *self, void *aux)
296 1.4.2.2 elad {
297 1.4.2.2 elad struct voodoofb_softc *sc = (void *)self;
298 1.4.2.2 elad struct pci_attach_args *pa = aux;
299 1.4.2.2 elad char devinfo[256];
300 1.4.2.2 elad struct wsemuldisplaydev_attach_args aa;
301 1.4.2.2 elad struct rasops_info *ri;
302 1.4.2.2 elad pci_intr_handle_t ih;
303 1.4.2.2 elad ulong defattr;
304 1.4.2.2 elad const char *intrstr;
305 1.4.2.2 elad int console, width, height, node, i, j;
306 1.4.2.2 elad #ifdef HAVE_OPENFIRMWARE
307 1.4.2.2 elad int linebytes, depth;
308 1.4.2.2 elad #endif
309 1.4.2.2 elad uint32_t bg, fg, ul;
310 1.4.2.2 elad
311 1.4.2.2 elad sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
312 1.4.2.2 elad node = pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
313 1.4.2.2 elad sc->sc_pc = pa->pa_pc;
314 1.4.2.2 elad sc->sc_pcitag = pa->pa_tag;
315 1.4.2.2 elad sc->sc_dacw = -1;
316 1.4.2.2 elad pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
317 1.4.2.2 elad printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
318 1.4.2.2 elad
319 1.4.2.2 elad sc->sc_memt = pa->pa_memt;
320 1.4.2.2 elad sc->sc_iot = pa->pa_iot;
321 1.4.2.2 elad
322 1.4.2.2 elad /* the framebuffer */
323 1.4.2.2 elad if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM,
324 1.4.2.2 elad BUS_SPACE_MAP_CACHEABLE | BUS_SPACE_MAP_PREFETCHABLE |
325 1.4.2.2 elad BUS_SPACE_MAP_LINEAR,
326 1.4.2.2 elad &sc->sc_fbt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
327 1.4.2.2 elad printf("%s: failed to map the frame buffer.\n",
328 1.4.2.2 elad sc->sc_dev.dv_xname);
329 1.4.2.2 elad }
330 1.4.2.2 elad
331 1.4.2.2 elad /* memory-mapped registers */
332 1.4.2.2 elad if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, 0,
333 1.4.2.2 elad &sc->sc_regt, &sc->sc_regh, &sc->sc_regs, &sc->sc_regsize)) {
334 1.4.2.2 elad printf("%s: failed to map memory-mapped registers.\n",
335 1.4.2.2 elad sc->sc_dev.dv_xname);
336 1.4.2.2 elad }
337 1.4.2.2 elad
338 1.4.2.2 elad /* IO-mapped registers */
339 1.4.2.2 elad if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_IO, 0,
340 1.4.2.2 elad &sc->sc_ioregt, &sc->sc_ioregh, &sc->sc_ioreg,
341 1.4.2.2 elad &sc->sc_ioregsize)) {
342 1.4.2.2 elad printf("%s: failed to map IO-mapped registers.\n",
343 1.4.2.2 elad sc->sc_dev.dv_xname);
344 1.4.2.2 elad }
345 1.4.2.2 elad voodoofb_init(sc);
346 1.4.2.2 elad
347 1.4.2.2 elad /* we should read these from the chip instead of depending on OF */
348 1.4.2.2 elad width = height = -1;
349 1.4.2.2 elad
350 1.4.2.2 elad #ifdef HAVE_OPENFIRMWARE
351 1.4.2.2 elad if (OF_getprop(node, "width", &width, 4) != 4)
352 1.4.2.2 elad OF_interpret("screen-width", 1, &width);
353 1.4.2.2 elad if (OF_getprop(node, "height", &height, 4) != 4)
354 1.4.2.2 elad OF_interpret("screen-height", 1, &height);
355 1.4.2.2 elad if (OF_getprop(node, "linebytes", &linebytes, 4) != 4)
356 1.4.2.2 elad linebytes = width; /* XXX */
357 1.4.2.2 elad if (OF_getprop(node, "depth", &depth, 4) != 4)
358 1.4.2.2 elad depth = 8; /* XXX */
359 1.4.2.2 elad
360 1.4.2.2 elad if (width == -1 || height == -1)
361 1.4.2.2 elad return;
362 1.4.2.2 elad
363 1.4.2.2 elad sc->width = width;
364 1.4.2.2 elad sc->height = height;
365 1.4.2.2 elad sc->bits_per_pixel = depth;
366 1.4.2.2 elad sc->linebytes = linebytes;
367 1.4.2.2 elad printf("%s: initial resolution %dx%d, %d bit\n", sc->sc_dev.dv_xname,
368 1.4.2.2 elad sc->width, sc->height, sc->bits_per_pixel);
369 1.4.2.2 elad #endif
370 1.4.2.2 elad
371 1.4.2.2 elad /* XXX this should at least be configurable via kernel config */
372 1.4.2.2 elad voodoofb_set_videomode(sc, &videomode_list[16]);
373 1.4.2.2 elad
374 1.4.2.2 elad vcons_init(&sc->vd, sc, &voodoofb_defaultscreen, &voodoofb_accessops);
375 1.4.2.2 elad sc->vd.init_screen = voodoofb_init_screen;
376 1.4.2.2 elad
377 1.4.2.2 elad console = voodoofb_is_console(pa);
378 1.4.2.2 elad
379 1.4.2.2 elad ri = &voodoofb_console_screen.scr_ri;
380 1.4.2.2 elad if (console) {
381 1.4.2.2 elad vcons_init_screen(&sc->vd, &voodoofb_console_screen, 1,
382 1.4.2.2 elad &defattr);
383 1.4.2.2 elad voodoofb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
384 1.4.2.2 elad
385 1.4.2.2 elad voodoofb_defaultscreen.textops = &ri->ri_ops;
386 1.4.2.2 elad voodoofb_defaultscreen.capabilities = ri->ri_caps;
387 1.4.2.2 elad voodoofb_defaultscreen.nrows = ri->ri_rows;
388 1.4.2.2 elad voodoofb_defaultscreen.ncols = ri->ri_cols;
389 1.4.2.2 elad wsdisplay_cnattach(&voodoofb_defaultscreen, ri, 0, 0, defattr);
390 1.4.2.2 elad } else {
391 1.4.2.2 elad /*
392 1.4.2.2 elad * since we're not the console we can postpone the rest
393 1.4.2.2 elad * until someone actually allocates a screen for us
394 1.4.2.2 elad */
395 1.4.2.2 elad voodoofb_set_videomode(sc, &videomode_list[0]);
396 1.4.2.2 elad }
397 1.4.2.2 elad
398 1.4.2.2 elad printf("%s: %d MB aperture at 0x%08x, %d MB registers at 0x%08x\n",
399 1.4.2.2 elad sc->sc_dev.dv_xname, (u_int)(sc->sc_fbsize >> 20),
400 1.4.2.2 elad (u_int)sc->sc_fb, (u_int)(sc->sc_regsize >> 20),
401 1.4.2.2 elad (u_int)sc->sc_regs);
402 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
403 1.4.2.2 elad printf("fb: %08lx\n", (ulong)ri->ri_bits);
404 1.4.2.2 elad #endif
405 1.4.2.2 elad
406 1.4.2.2 elad j = 0;
407 1.4.2.2 elad for (i = 0; i < 256; i++) {
408 1.4.2.2 elad voodoofb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
409 1.4.2.2 elad rasops_cmap[j + 2]);
410 1.4.2.2 elad j += 3;
411 1.4.2.2 elad }
412 1.4.2.2 elad
413 1.4.2.2 elad /* Interrupt. We don't use it for anything yet */
414 1.4.2.2 elad if (pci_intr_map(pa, &ih)) {
415 1.4.2.2 elad printf("%s: failed to map interrupt\n", sc->sc_dev.dv_xname);
416 1.4.2.2 elad return;
417 1.4.2.2 elad }
418 1.4.2.2 elad
419 1.4.2.2 elad intrstr = pci_intr_string(sc->sc_pc, ih);
420 1.4.2.2 elad sc->sc_ih = pci_intr_establish(sc->sc_pc, ih, IPL_NET, voodoofb_intr,
421 1.4.2.2 elad sc);
422 1.4.2.2 elad if (sc->sc_ih == NULL) {
423 1.4.2.2 elad printf("%s: failed to establish interrupt",
424 1.4.2.2 elad sc->sc_dev.dv_xname);
425 1.4.2.2 elad if (intrstr != NULL)
426 1.4.2.2 elad printf(" at %s", intrstr);
427 1.4.2.2 elad printf("\n");
428 1.4.2.2 elad return;
429 1.4.2.2 elad }
430 1.4.2.2 elad printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
431 1.4.2.2 elad
432 1.4.2.2 elad rasops_unpack_attr(defattr, &fg, &bg, &ul);
433 1.4.2.2 elad sc->sc_bg = ri->ri_devcmap[bg];
434 1.4.2.2 elad voodoofb_clearscreen(sc);
435 1.4.2.2 elad
436 1.4.2.2 elad aa.console = console;
437 1.4.2.2 elad aa.scrdata = &voodoofb_screenlist;
438 1.4.2.2 elad aa.accessops = &voodoofb_accessops;
439 1.4.2.2 elad aa.accesscookie = &sc->vd;
440 1.4.2.2 elad
441 1.4.2.2 elad config_found(self, &aa, wsemuldisplaydevprint);
442 1.4.2.2 elad }
443 1.4.2.2 elad
444 1.4.2.2 elad static int
445 1.4.2.2 elad voodoofb_putpalreg(struct voodoofb_softc *sc, uint8_t index, uint8_t r,
446 1.4.2.2 elad uint8_t g, uint8_t b)
447 1.4.2.2 elad {
448 1.4.2.2 elad uint32_t color;
449 1.4.2.2 elad
450 1.4.2.2 elad sc->sc_cmap_red[index] = r;
451 1.4.2.2 elad sc->sc_cmap_green[index] = g;
452 1.4.2.2 elad sc->sc_cmap_blue[index] = b;
453 1.4.2.2 elad
454 1.4.2.2 elad color = (r << 16) | (g << 8) | b;
455 1.4.2.2 elad voodoo3_make_room(sc, 2);
456 1.4.2.2 elad voodoo3_write32(sc, DACADDR, index);
457 1.4.2.2 elad voodoo3_write32(sc, DACDATA, color);
458 1.4.2.2 elad
459 1.4.2.2 elad return 0;
460 1.4.2.2 elad }
461 1.4.2.2 elad
462 1.4.2.2 elad static int
463 1.4.2.2 elad voodoofb_putcmap(struct voodoofb_softc *sc, struct wsdisplay_cmap *cm)
464 1.4.2.2 elad {
465 1.4.2.2 elad u_char *r, *g, *b;
466 1.4.2.2 elad u_int index = cm->index;
467 1.4.2.2 elad u_int count = cm->count;
468 1.4.2.2 elad int i, error;
469 1.4.2.2 elad u_char rbuf[256], gbuf[256], bbuf[256];
470 1.4.2.2 elad
471 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
472 1.4.2.2 elad printf("putcmap: %d %d\n",index, count);
473 1.4.2.2 elad #endif
474 1.4.2.2 elad if (cm->index >= 256 || cm->count > 256 ||
475 1.4.2.2 elad (cm->index + cm->count) > 256)
476 1.4.2.2 elad return EINVAL;
477 1.4.2.2 elad error = copyin(cm->red, &rbuf[index], count);
478 1.4.2.2 elad if (error)
479 1.4.2.2 elad return error;
480 1.4.2.2 elad error = copyin(cm->green, &gbuf[index], count);
481 1.4.2.2 elad if (error)
482 1.4.2.2 elad return error;
483 1.4.2.2 elad error = copyin(cm->blue, &bbuf[index], count);
484 1.4.2.2 elad if (error)
485 1.4.2.2 elad return error;
486 1.4.2.2 elad
487 1.4.2.2 elad memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
488 1.4.2.2 elad memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
489 1.4.2.2 elad memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
490 1.4.2.2 elad
491 1.4.2.2 elad r = &sc->sc_cmap_red[index];
492 1.4.2.2 elad g = &sc->sc_cmap_green[index];
493 1.4.2.2 elad b = &sc->sc_cmap_blue[index];
494 1.4.2.2 elad
495 1.4.2.2 elad for (i = 0; i < count; i++) {
496 1.4.2.2 elad voodoofb_putpalreg(sc, index, *r, *g, *b);
497 1.4.2.2 elad index++;
498 1.4.2.2 elad r++, g++, b++;
499 1.4.2.2 elad }
500 1.4.2.2 elad return 0;
501 1.4.2.2 elad }
502 1.4.2.2 elad
503 1.4.2.2 elad static int
504 1.4.2.2 elad voodoofb_getcmap(struct voodoofb_softc *sc, struct wsdisplay_cmap *cm)
505 1.4.2.2 elad {
506 1.4.2.2 elad u_int index = cm->index;
507 1.4.2.2 elad u_int count = cm->count;
508 1.4.2.2 elad int error;
509 1.4.2.2 elad
510 1.4.2.2 elad if (index >= 255 || count > 256 || index + count > 256)
511 1.4.2.2 elad return EINVAL;
512 1.4.2.2 elad
513 1.4.2.2 elad error = copyout(&sc->sc_cmap_red[index], cm->red, count);
514 1.4.2.2 elad if (error)
515 1.4.2.2 elad return error;
516 1.4.2.2 elad error = copyout(&sc->sc_cmap_green[index], cm->green, count);
517 1.4.2.2 elad if (error)
518 1.4.2.2 elad return error;
519 1.4.2.2 elad error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
520 1.4.2.2 elad if (error)
521 1.4.2.2 elad return error;
522 1.4.2.2 elad
523 1.4.2.2 elad return 0;
524 1.4.2.2 elad }
525 1.4.2.2 elad
526 1.4.2.2 elad static int
527 1.4.2.2 elad voodoofb_is_console(struct pci_attach_args *pa)
528 1.4.2.2 elad {
529 1.4.2.2 elad
530 1.4.2.2 elad #ifdef HAVE_OPENFIRMWARE
531 1.4.2.2 elad /* check if we're the /chosen console device */
532 1.4.2.2 elad int chosen, stdout, node, us;
533 1.4.2.2 elad
534 1.4.2.2 elad us=pcidev_to_ofdev(pa->pa_pc, pa->pa_tag);
535 1.4.2.2 elad chosen = OF_finddevice("/chosen");
536 1.4.2.2 elad OF_getprop(chosen, "stdout", &stdout, 4);
537 1.4.2.2 elad node = OF_instance_to_package(stdout);
538 1.4.2.2 elad return(us == node);
539 1.4.2.2 elad #else
540 1.4.2.2 elad /* XXX how do we know we're console on i386? */
541 1.4.2.2 elad return 1;
542 1.4.2.2 elad #endif
543 1.4.2.2 elad }
544 1.4.2.2 elad
545 1.4.2.2 elad static void
546 1.4.2.2 elad voodoofb_clearscreen(struct voodoofb_softc *sc)
547 1.4.2.2 elad {
548 1.4.2.2 elad voodoofb_rectfill(sc, 0, 0, sc->width, sc->height, sc->sc_bg);
549 1.4.2.2 elad }
550 1.4.2.2 elad
551 1.4.2.2 elad /*
552 1.4.2.2 elad * wsdisplay_emulops
553 1.4.2.2 elad */
554 1.4.2.2 elad
555 1.4.2.2 elad static void
556 1.4.2.2 elad voodoofb_cursor(void *cookie, int on, int row, int col)
557 1.4.2.2 elad {
558 1.4.2.2 elad struct rasops_info *ri = cookie;
559 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
560 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
561 1.4.2.2 elad int x, y, wi, he;
562 1.4.2.2 elad
563 1.4.2.2 elad wi = ri->ri_font->fontwidth;
564 1.4.2.2 elad he = ri->ri_font->fontheight;
565 1.4.2.2 elad
566 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
567 1.4.2.2 elad x = ri->ri_ccol * wi + ri->ri_xorigin;
568 1.4.2.2 elad y = ri->ri_crow * he + ri->ri_yorigin;
569 1.4.2.2 elad if (ri->ri_flg & RI_CURSOR) {
570 1.4.2.2 elad voodoofb_rectinvert(sc, x, y, wi, he);
571 1.4.2.2 elad ri->ri_flg &= ~RI_CURSOR;
572 1.4.2.2 elad }
573 1.4.2.2 elad ri->ri_crow = row;
574 1.4.2.2 elad ri->ri_ccol = col;
575 1.4.2.2 elad if (on)
576 1.4.2.2 elad {
577 1.4.2.2 elad x = ri->ri_ccol * wi + ri->ri_xorigin;
578 1.4.2.2 elad y = ri->ri_crow * he + ri->ri_yorigin;
579 1.4.2.2 elad voodoofb_rectinvert(sc, x, y, wi, he);
580 1.4.2.2 elad ri->ri_flg |= RI_CURSOR;
581 1.4.2.2 elad }
582 1.4.2.2 elad } else {
583 1.4.2.2 elad ri->ri_flg &= ~RI_CURSOR;
584 1.4.2.2 elad ri->ri_crow = row;
585 1.4.2.2 elad ri->ri_ccol = col;
586 1.4.2.2 elad }
587 1.4.2.2 elad }
588 1.4.2.2 elad
589 1.4.2.2 elad #if 0
590 1.4.2.2 elad int
591 1.4.2.2 elad voodoofb_mapchar(void *cookie, int uni, u_int *index)
592 1.4.2.2 elad {
593 1.4.2.2 elad return 0;
594 1.4.2.2 elad }
595 1.4.2.2 elad #endif
596 1.4.2.2 elad
597 1.4.2.2 elad static void
598 1.4.2.2 elad voodoofb_putchar(void *cookie, int row, int col, u_int c, long attr)
599 1.4.2.2 elad {
600 1.4.2.2 elad struct rasops_info *ri = cookie;
601 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
602 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
603 1.4.2.2 elad
604 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
605 1.4.2.2 elad uint8_t *data;
606 1.4.2.2 elad int fg, bg, uc, i;
607 1.4.2.2 elad int x, y, wi, he;
608 1.4.2.2 elad
609 1.4.2.2 elad wi = ri->ri_font->fontwidth;
610 1.4.2.2 elad he = ri->ri_font->fontheight;
611 1.4.2.2 elad
612 1.4.2.2 elad if (!CHAR_IN_FONT(c, ri->ri_font))
613 1.4.2.2 elad return;
614 1.4.2.2 elad bg = (u_char)ri->ri_devcmap[(attr >> 16) & 0xf];
615 1.4.2.2 elad fg = (u_char)ri->ri_devcmap[(attr >> 24) & 0xf];
616 1.4.2.2 elad x = ri->ri_xorigin + col * wi;
617 1.4.2.2 elad y = ri->ri_yorigin + row * he;
618 1.4.2.2 elad if (c == 0x20) {
619 1.4.2.2 elad voodoofb_rectfill(sc, x, y, wi, he, bg);
620 1.4.2.2 elad } else {
621 1.4.2.2 elad uc = c-ri->ri_font->firstchar;
622 1.4.2.2 elad data = (uint8_t *)ri->ri_font->data + uc *
623 1.4.2.2 elad ri->ri_fontscale;
624 1.4.2.2 elad voodoofb_setup_mono(sc, x, y, wi, he, fg, bg);
625 1.4.2.2 elad for (i = 0; i < he; i++) {
626 1.4.2.2 elad voodoofb_feed_line(sc,
627 1.4.2.2 elad ri->ri_font->stride, data);
628 1.4.2.2 elad data += ri->ri_font->stride;
629 1.4.2.2 elad }
630 1.4.2.2 elad }
631 1.4.2.2 elad }
632 1.4.2.2 elad }
633 1.4.2.2 elad
634 1.4.2.2 elad static void
635 1.4.2.2 elad voodoofb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
636 1.4.2.2 elad {
637 1.4.2.2 elad struct rasops_info *ri = cookie;
638 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
639 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
640 1.4.2.2 elad int32_t xs, xd, y, width, height;
641 1.4.2.2 elad
642 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
643 1.4.2.2 elad xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
644 1.4.2.2 elad xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
645 1.4.2.2 elad y = ri->ri_yorigin + ri->ri_font->fontheight * row;
646 1.4.2.2 elad width = ri->ri_font->fontwidth * ncols;
647 1.4.2.2 elad height = ri->ri_font->fontheight;
648 1.4.2.2 elad voodoofb_bitblt(sc, xs, y, xd, y, width, height);
649 1.4.2.2 elad }
650 1.4.2.2 elad }
651 1.4.2.2 elad
652 1.4.2.2 elad static void
653 1.4.2.2 elad voodoofb_erasecols(void *cookie, int row, int startcol, int ncols,
654 1.4.2.2 elad long fillattr)
655 1.4.2.2 elad {
656 1.4.2.2 elad struct rasops_info *ri = cookie;
657 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
658 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
659 1.4.2.2 elad int32_t x, y, width, height, fg, bg, ul;
660 1.4.2.2 elad
661 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
662 1.4.2.2 elad x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
663 1.4.2.2 elad y = ri->ri_yorigin + ri->ri_font->fontheight * row;
664 1.4.2.2 elad width = ri->ri_font->fontwidth * ncols;
665 1.4.2.2 elad height = ri->ri_font->fontheight;
666 1.4.2.2 elad rasops_unpack_attr(fillattr, &fg, &bg, &ul);
667 1.4.2.2 elad
668 1.4.2.2 elad voodoofb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
669 1.4.2.2 elad }
670 1.4.2.2 elad }
671 1.4.2.2 elad
672 1.4.2.2 elad static void
673 1.4.2.2 elad voodoofb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
674 1.4.2.2 elad {
675 1.4.2.2 elad struct rasops_info *ri = cookie;
676 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
677 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
678 1.4.2.2 elad int32_t x, ys, yd, width, height;
679 1.4.2.2 elad
680 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
681 1.4.2.2 elad x = ri->ri_xorigin;
682 1.4.2.2 elad ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
683 1.4.2.2 elad yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
684 1.4.2.2 elad width = ri->ri_emuwidth;
685 1.4.2.2 elad height = ri->ri_font->fontheight * nrows;
686 1.4.2.2 elad voodoofb_bitblt(sc, x, ys, x, yd, width, height);
687 1.4.2.2 elad }
688 1.4.2.2 elad }
689 1.4.2.2 elad
690 1.4.2.2 elad static void
691 1.4.2.2 elad voodoofb_eraserows(void *cookie, int row, int nrows, long fillattr)
692 1.4.2.2 elad {
693 1.4.2.2 elad struct rasops_info *ri = cookie;
694 1.4.2.2 elad struct vcons_screen *scr = ri->ri_hw;
695 1.4.2.2 elad struct voodoofb_softc *sc = scr->scr_cookie;
696 1.4.2.2 elad int32_t x, y, width, height, fg, bg, ul;
697 1.4.2.2 elad
698 1.4.2.2 elad if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
699 1.4.2.2 elad rasops_unpack_attr(fillattr, &fg, &bg, &ul);
700 1.4.2.2 elad if ((row == 0) && (nrows == ri->ri_rows)) {
701 1.4.2.2 elad /* clear the whole screen */
702 1.4.2.2 elad voodoofb_rectfill(sc, 0, 0, ri->ri_width,
703 1.4.2.2 elad ri->ri_height, ri->ri_devcmap[bg]);
704 1.4.2.2 elad } else {
705 1.4.2.2 elad x = ri->ri_xorigin;
706 1.4.2.2 elad y = ri->ri_yorigin + ri->ri_font->fontheight * row;
707 1.4.2.2 elad width = ri->ri_emuwidth;
708 1.4.2.2 elad height = ri->ri_font->fontheight * nrows;
709 1.4.2.2 elad voodoofb_rectfill(sc, x, y, width, height,
710 1.4.2.2 elad ri->ri_devcmap[bg]);
711 1.4.2.2 elad }
712 1.4.2.2 elad }
713 1.4.2.2 elad }
714 1.4.2.2 elad
715 1.4.2.2 elad static void
716 1.4.2.2 elad voodoofb_bitblt(struct voodoofb_softc *sc, int xs, int ys, int xd, int yd, int width, int height)
717 1.4.2.2 elad {
718 1.4.2.2 elad uint32_t fmt, blitcmd;
719 1.4.2.2 elad
720 1.4.2.2 elad fmt = sc->linebytes | ((sc->bits_per_pixel +
721 1.4.2.2 elad ((sc->bits_per_pixel == 8) ? 0 : 8)) << 13);
722 1.4.2.2 elad blitcmd = COMMAND_2D_S2S_BITBLT | (ROP_COPY << 24);
723 1.4.2.2 elad
724 1.4.2.2 elad if (xs <= xd) {
725 1.4.2.2 elad blitcmd |= BIT(14);
726 1.4.2.2 elad xs += (width - 1);
727 1.4.2.2 elad xd += (width - 1);
728 1.4.2.2 elad }
729 1.4.2.2 elad if (ys <= yd) {
730 1.4.2.2 elad blitcmd |= BIT(15);
731 1.4.2.2 elad ys += (height - 1);
732 1.4.2.2 elad yd += (height - 1);
733 1.4.2.2 elad }
734 1.4.2.2 elad voodoo3_make_room(sc, 6);
735 1.4.2.2 elad
736 1.4.2.2 elad voodoo3_write32(sc, SRCFORMAT, fmt);
737 1.4.2.2 elad voodoo3_write32(sc, DSTFORMAT, fmt);
738 1.4.2.2 elad voodoo3_write32(sc, DSTSIZE, width | (height << 16));
739 1.4.2.2 elad voodoo3_write32(sc, DSTXY, xd | (yd << 16));
740 1.4.2.2 elad voodoo3_write32(sc, SRCXY, xs | (ys << 16));
741 1.4.2.2 elad voodoo3_write32(sc, COMMAND_2D, blitcmd | SST_2D_GO);
742 1.4.2.2 elad }
743 1.4.2.2 elad
744 1.4.2.2 elad static void
745 1.4.2.2 elad voodoofb_rectfill(struct voodoofb_softc *sc, int x, int y, int width,
746 1.4.2.2 elad int height, int colour)
747 1.4.2.2 elad {
748 1.4.2.2 elad uint32_t fmt, col;
749 1.4.2.2 elad
750 1.4.2.2 elad col = (colour << 24) | (colour << 16) | (colour << 8) | colour;
751 1.4.2.2 elad fmt = sc->linebytes | ((sc->bits_per_pixel +
752 1.4.2.2 elad ((sc->bits_per_pixel == 8) ? 0 : 8)) << 13);
753 1.4.2.2 elad
754 1.4.2.2 elad voodoo3_make_room(sc, 6);
755 1.4.2.2 elad voodoo3_write32(sc, DSTFORMAT, fmt);
756 1.4.2.2 elad voodoo3_write32(sc, COLORFORE, colour);
757 1.4.2.2 elad voodoo3_write32(sc, COLORBACK, colour);
758 1.4.2.2 elad voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_FILLRECT | (ROP_COPY << 24));
759 1.4.2.2 elad voodoo3_write32(sc, DSTSIZE, width | (height << 16));
760 1.4.2.2 elad voodoo3_write32(sc, LAUNCH_2D, x | (y << 16));
761 1.4.2.2 elad }
762 1.4.2.2 elad
763 1.4.2.2 elad static void
764 1.4.2.2 elad voodoofb_rectinvert(struct voodoofb_softc *sc, int x, int y, int width,
765 1.4.2.2 elad int height)
766 1.4.2.2 elad {
767 1.4.2.2 elad uint32_t fmt;
768 1.4.2.2 elad
769 1.4.2.2 elad fmt = sc->linebytes | ((sc->bits_per_pixel +
770 1.4.2.2 elad ((sc->bits_per_pixel == 8) ? 0 : 8)) << 13);
771 1.4.2.2 elad
772 1.4.2.2 elad voodoo3_make_room(sc, 6);
773 1.4.2.2 elad voodoo3_write32(sc, DSTFORMAT, fmt);
774 1.4.2.2 elad voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_FILLRECT |
775 1.4.2.2 elad (ROP_INVERT << 24));
776 1.4.2.2 elad voodoo3_write32(sc, DSTSIZE, width | (height << 16));
777 1.4.2.2 elad voodoo3_write32(sc, DSTXY, x | (y << 16));
778 1.4.2.2 elad voodoo3_write32(sc, LAUNCH_2D, x | (y << 16));
779 1.4.2.2 elad }
780 1.4.2.2 elad
781 1.4.2.2 elad static void
782 1.4.2.2 elad voodoofb_setup_mono(struct voodoofb_softc *sc, int xd, int yd, int width, int height, uint32_t fg,
783 1.4.2.2 elad uint32_t bg)
784 1.4.2.2 elad {
785 1.4.2.2 elad uint32_t dfmt, sfmt = sc->linebytes;
786 1.4.2.2 elad
787 1.4.2.2 elad dfmt = sc->linebytes | ((sc->bits_per_pixel +
788 1.4.2.2 elad ((sc->bits_per_pixel == 8) ? 0 : 8)) << 13);
789 1.4.2.2 elad
790 1.4.2.2 elad voodoo3_make_room(sc, 9);
791 1.4.2.2 elad voodoo3_write32(sc, SRCFORMAT, sfmt);
792 1.4.2.2 elad voodoo3_write32(sc, DSTFORMAT, dfmt);
793 1.4.2.2 elad voodoo3_write32(sc, COLORFORE, fg);
794 1.4.2.2 elad voodoo3_write32(sc, COLORBACK, bg);
795 1.4.2.2 elad voodoo3_write32(sc, DSTSIZE, width | (height << 16));
796 1.4.2.2 elad voodoo3_write32(sc, DSTXY, xd | (yd << 16));
797 1.4.2.2 elad voodoo3_write32(sc, SRCXY, 0);
798 1.4.2.2 elad voodoo3_write32(sc, COMMAND_2D, COMMAND_2D_H2S_BITBLT |
799 1.4.2.2 elad (ROP_COPY << 24) | SST_2D_GO);
800 1.4.2.2 elad
801 1.4.2.2 elad /* now feed the data into the chip */
802 1.4.2.2 elad }
803 1.4.2.2 elad
804 1.4.2.2 elad static void
805 1.4.2.2 elad voodoofb_feed_line(struct voodoofb_softc *sc, int count, uint8_t *data)
806 1.4.2.2 elad {
807 1.4.2.2 elad int i;
808 1.4.2.2 elad uint32_t latch = 0, bork;
809 1.4.2.2 elad int shift = 0;
810 1.4.2.2 elad
811 1.4.2.2 elad voodoo3_make_room(sc, count);
812 1.4.2.2 elad for (i = 0; i < count; i++) {
813 1.4.2.2 elad bork = data[i];
814 1.4.2.2 elad latch |= (bork << shift);
815 1.4.2.2 elad if (shift == 24) {
816 1.4.2.2 elad voodoo3_write32(sc, LAUNCH_2D, latch);
817 1.4.2.2 elad latch = 0;
818 1.4.2.2 elad shift = 0;
819 1.4.2.2 elad } else
820 1.4.2.2 elad shift += 8;
821 1.4.2.2 elad }
822 1.4.2.2 elad if (shift != 24)
823 1.4.2.2 elad voodoo3_write32(sc, LAUNCH_2D, latch);
824 1.4.2.2 elad }
825 1.4.2.2 elad
826 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
827 1.4.2.2 elad static void
828 1.4.2.2 elad voodoofb_showpal(struct voodoofb_softc *sc)
829 1.4.2.2 elad {
830 1.4.2.2 elad int i, x = 0;
831 1.4.2.2 elad
832 1.4.2.2 elad for (i = 0; i < 16; i++) {
833 1.4.2.2 elad voodoofb_rectfill(sc, x, 0, 64, 64, i);
834 1.4.2.2 elad x += 64;
835 1.4.2.2 elad }
836 1.4.2.2 elad }
837 1.4.2.2 elad #endif
838 1.4.2.2 elad
839 1.4.2.2 elad #if 0
840 1.4.2.2 elad static int
841 1.4.2.2 elad voodoofb_allocattr(void *cookie, int fg, int bg, int flags, long *attrp)
842 1.4.2.2 elad {
843 1.4.2.2 elad
844 1.4.2.2 elad return 0;
845 1.4.2.2 elad }
846 1.4.2.2 elad #endif
847 1.4.2.2 elad
848 1.4.2.2 elad /*
849 1.4.2.2 elad * wsdisplay_accessops
850 1.4.2.2 elad */
851 1.4.2.2 elad
852 1.4.2.2 elad static int
853 1.4.2.2 elad voodoofb_ioctl(void *v, void *vs, u_long cmd, caddr_t data, int flag,
854 1.4.2.2 elad struct lwp *l)
855 1.4.2.2 elad {
856 1.4.2.2 elad struct vcons_data *vd = v;
857 1.4.2.2 elad struct voodoofb_softc *sc = vd->cookie;
858 1.4.2.2 elad struct wsdisplay_fbinfo *wdf;
859 1.4.2.2 elad struct vcons_screen *ms = vd->active;
860 1.4.2.2 elad
861 1.4.2.2 elad switch (cmd) {
862 1.4.2.2 elad case WSDISPLAYIO_GTYPE:
863 1.4.2.2 elad *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
864 1.4.2.2 elad return 0;
865 1.4.2.2 elad
866 1.4.2.2 elad case WSDISPLAYIO_GINFO:
867 1.4.2.2 elad wdf = (void *)data;
868 1.4.2.2 elad wdf->height = ms->scr_ri.ri_height;
869 1.4.2.2 elad wdf->width = ms->scr_ri.ri_width;
870 1.4.2.2 elad wdf->depth = ms->scr_ri.ri_depth;
871 1.4.2.2 elad wdf->cmsize = 256;
872 1.4.2.2 elad return 0;
873 1.4.2.2 elad
874 1.4.2.2 elad case WSDISPLAYIO_GETCMAP:
875 1.4.2.2 elad return voodoofb_getcmap(sc,
876 1.4.2.2 elad (struct wsdisplay_cmap *)data);
877 1.4.2.2 elad
878 1.4.2.2 elad case WSDISPLAYIO_PUTCMAP:
879 1.4.2.2 elad return voodoofb_putcmap(sc,
880 1.4.2.2 elad (struct wsdisplay_cmap *)data);
881 1.4.2.2 elad
882 1.4.2.2 elad /* PCI config read/write passthrough. */
883 1.4.2.2 elad case PCI_IOC_CFGREAD:
884 1.4.2.2 elad case PCI_IOC_CFGWRITE:
885 1.4.2.2 elad return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
886 1.4.2.2 elad cmd, data, flag, l));
887 1.4.2.2 elad
888 1.4.2.2 elad case WSDISPLAYIO_SMODE:
889 1.4.2.2 elad {
890 1.4.2.2 elad int new_mode = *(int*)data;
891 1.4.2.2 elad if (new_mode != sc->sc_mode)
892 1.4.2.2 elad {
893 1.4.2.2 elad sc->sc_mode = new_mode;
894 1.4.2.2 elad if(new_mode == WSDISPLAYIO_MODE_EMUL)
895 1.4.2.2 elad {
896 1.4.2.2 elad int i;
897 1.4.2.2 elad
898 1.4.2.2 elad /* restore the palette */
899 1.4.2.2 elad for (i = 0; i < 256; i++) {
900 1.4.2.2 elad voodoofb_putpalreg(sc,
901 1.4.2.2 elad i,
902 1.4.2.2 elad sc->sc_cmap_red[i],
903 1.4.2.2 elad sc->sc_cmap_green[i],
904 1.4.2.2 elad sc->sc_cmap_blue[i]);
905 1.4.2.2 elad }
906 1.4.2.2 elad vcons_redraw_screen(ms);
907 1.4.2.2 elad }
908 1.4.2.2 elad }
909 1.4.2.2 elad }
910 1.4.2.2 elad }
911 1.4.2.2 elad return EPASSTHROUGH;
912 1.4.2.2 elad }
913 1.4.2.2 elad
914 1.4.2.2 elad static paddr_t
915 1.4.2.2 elad voodoofb_mmap(void *v, void *vs, off_t offset, int prot)
916 1.4.2.2 elad {
917 1.4.2.2 elad struct vcons_data *vd = v;
918 1.4.2.2 elad struct voodoofb_softc *sc = vd->cookie;
919 1.4.2.2 elad paddr_t pa;
920 1.4.2.2 elad
921 1.4.2.2 elad /* 'regular' framebuffer mmap()ing */
922 1.4.2.2 elad if (offset < sc->sc_fbsize) {
923 1.4.2.2 elad pa = bus_space_mmap(sc->sc_fbt, offset, 0, prot,
924 1.4.2.2 elad BUS_SPACE_MAP_LINEAR);
925 1.4.2.2 elad return pa;
926 1.4.2.2 elad }
927 1.4.2.2 elad
928 1.4.2.2 elad if ((offset >= sc->sc_fb) && (offset < (sc->sc_fb + sc->sc_fbsize))) {
929 1.4.2.2 elad pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
930 1.4.2.2 elad BUS_SPACE_MAP_LINEAR);
931 1.4.2.2 elad return pa;
932 1.4.2.2 elad }
933 1.4.2.2 elad
934 1.4.2.2 elad if ((offset >= sc->sc_regs) && (offset < (sc->sc_regs +
935 1.4.2.2 elad sc->sc_regsize))) {
936 1.4.2.2 elad pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
937 1.4.2.2 elad BUS_SPACE_MAP_LINEAR);
938 1.4.2.2 elad return pa;
939 1.4.2.2 elad }
940 1.4.2.2 elad
941 1.4.2.2 elad /* allow mapping of IO space */
942 1.4.2.2 elad if ((offset >= 0xf2000000) && (offset < 0xf2800000)) {
943 1.4.2.2 elad pa = bus_space_mmap(sc->sc_iot, offset-0xf2000000, 0, prot,
944 1.4.2.2 elad BUS_SPACE_MAP_LINEAR);
945 1.4.2.2 elad return pa;
946 1.4.2.2 elad }
947 1.4.2.2 elad #ifdef OFB_ALLOW_OTHERS
948 1.4.2.2 elad if (offset >= 0x80000000) {
949 1.4.2.2 elad pa = bus_space_mmap(sc->sc_memt, offset, 0, prot,
950 1.4.2.2 elad BUS_SPACE_MAP_LINEAR);
951 1.4.2.2 elad return pa;
952 1.4.2.2 elad }
953 1.4.2.2 elad #endif
954 1.4.2.2 elad return -1;
955 1.4.2.2 elad }
956 1.4.2.2 elad
957 1.4.2.2 elad static void
958 1.4.2.2 elad voodoofb_init_screen(void *cookie, struct vcons_screen *scr,
959 1.4.2.2 elad int existing, long *defattr)
960 1.4.2.2 elad {
961 1.4.2.2 elad struct voodoofb_softc *sc = cookie;
962 1.4.2.2 elad struct rasops_info *ri = &scr->scr_ri;
963 1.4.2.2 elad
964 1.4.2.2 elad ri->ri_depth = sc->bits_per_pixel;
965 1.4.2.2 elad ri->ri_width = sc->width;
966 1.4.2.2 elad ri->ri_height = sc->height;
967 1.4.2.2 elad ri->ri_stride = sc->width;
968 1.4.2.2 elad ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
969 1.4.2.2 elad
970 1.4.2.2 elad ri->ri_bits = bus_space_vaddr(sc->sc_fbt, sc->sc_fbh);
971 1.4.2.2 elad
972 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
973 1.4.2.2 elad printf("addr: %08lx\n", (ulong)ri->ri_bits);
974 1.4.2.2 elad #endif
975 1.4.2.2 elad if (existing) {
976 1.4.2.2 elad ri->ri_flg |= RI_CLEAR;
977 1.4.2.2 elad }
978 1.4.2.2 elad
979 1.4.2.2 elad rasops_init(ri, sc->height/8, sc->width/8);
980 1.4.2.2 elad ri->ri_caps = WSSCREEN_WSCOLORS;
981 1.4.2.2 elad
982 1.4.2.2 elad rasops_reconfig(ri, sc->height / ri->ri_font->fontheight,
983 1.4.2.2 elad sc->width / ri->ri_font->fontwidth);
984 1.4.2.2 elad
985 1.4.2.2 elad ri->ri_hw = scr;
986 1.4.2.2 elad ri->ri_ops.copyrows = voodoofb_copyrows;
987 1.4.2.2 elad ri->ri_ops.copycols = voodoofb_copycols;
988 1.4.2.2 elad ri->ri_ops.eraserows = voodoofb_eraserows;
989 1.4.2.2 elad ri->ri_ops.erasecols = voodoofb_erasecols;
990 1.4.2.2 elad ri->ri_ops.cursor = voodoofb_cursor;
991 1.4.2.2 elad ri->ri_ops.putchar = voodoofb_putchar;
992 1.4.2.2 elad }
993 1.4.2.2 elad
994 1.4.2.2 elad #if 0
995 1.4.2.2 elad int
996 1.4.2.2 elad voodoofb_load_font(void *v, void *cookie, struct wsdisplay_font *data)
997 1.4.2.2 elad {
998 1.4.2.2 elad
999 1.4.2.2 elad return 0;
1000 1.4.2.2 elad }
1001 1.4.2.2 elad #endif
1002 1.4.2.2 elad
1003 1.4.2.2 elad static int
1004 1.4.2.2 elad voodoofb_intr(void *arg)
1005 1.4.2.2 elad {
1006 1.4.2.2 elad struct voodoofb_softc *sc = arg;
1007 1.4.2.2 elad
1008 1.4.2.2 elad voodoo3_write32(sc, V3_STATUS, 0); /* clear interrupts */
1009 1.4.2.2 elad return 1;
1010 1.4.2.2 elad }
1011 1.4.2.2 elad
1012 1.4.2.2 elad /* video mode stuff */
1013 1.4.2.2 elad
1014 1.4.2.2 elad #define REFFREQ 14318 /* .18 */
1015 1.4.2.2 elad
1016 1.4.2.2 elad #define ABS(a) ((a < 0) ? -a : a)
1017 1.4.2.2 elad
1018 1.4.2.2 elad static int
1019 1.4.2.2 elad voodoofb_calc_pll(int freq, int *f_out, int isBanshee)
1020 1.4.2.2 elad {
1021 1.4.2.2 elad int m, n, k, best_m, best_n, best_k, f_cur, best_error;
1022 1.4.2.2 elad int minm, maxm;
1023 1.4.2.2 elad
1024 1.4.2.2 elad best_error = freq;
1025 1.4.2.2 elad best_n = best_m = best_k = 0;
1026 1.4.2.2 elad
1027 1.4.2.2 elad if (isBanshee) {
1028 1.4.2.2 elad minm = 24;
1029 1.4.2.2 elad maxm = 24;
1030 1.4.2.2 elad } else {
1031 1.4.2.2 elad minm = 1;
1032 1.4.2.2 elad maxm = 57;
1033 1.4.2.2 elad /* This used to be 64, alas it seems the last 8 (funny that ?)
1034 1.4.2.2 elad * values cause jittering at lower resolutions. I've not done
1035 1.4.2.2 elad * any calculations to what the adjustment affects clock ranges,
1036 1.4.2.2 elad * but I can still run at 1600x1200@75Hz */
1037 1.4.2.2 elad }
1038 1.4.2.2 elad for (n = 1; n < 256; n++) {
1039 1.4.2.2 elad f_cur = REFFREQ * (n + 2);
1040 1.4.2.2 elad if (f_cur < freq) {
1041 1.4.2.2 elad f_cur = f_cur / 3;
1042 1.4.2.2 elad if (freq - f_cur < best_error) {
1043 1.4.2.2 elad best_error = freq - f_cur;
1044 1.4.2.2 elad best_n = n;
1045 1.4.2.2 elad best_m = 1;
1046 1.4.2.2 elad best_k = 0;
1047 1.4.2.2 elad continue;
1048 1.4.2.2 elad }
1049 1.4.2.2 elad }
1050 1.4.2.2 elad for (m = minm; m < maxm; m++) {
1051 1.4.2.2 elad for (k = 0; k < 4; k++) {
1052 1.4.2.2 elad f_cur = REFFREQ * (n + 2) / (m + 2) / (1 << k);
1053 1.4.2.2 elad if (ABS(f_cur - freq) < best_error) {
1054 1.4.2.2 elad best_error = ABS(f_cur - freq);
1055 1.4.2.2 elad best_n = n;
1056 1.4.2.2 elad best_m = m;
1057 1.4.2.2 elad best_k = k;
1058 1.4.2.2 elad }
1059 1.4.2.2 elad }
1060 1.4.2.2 elad }
1061 1.4.2.2 elad }
1062 1.4.2.2 elad n = best_n;
1063 1.4.2.2 elad m = best_m;
1064 1.4.2.2 elad k = best_k;
1065 1.4.2.2 elad *f_out = REFFREQ * (n + 2) / (m + 2) / (1 << k);
1066 1.4.2.2 elad return ( n << 8) | (m << 2) | k;
1067 1.4.2.2 elad }
1068 1.4.2.2 elad
1069 1.4.2.2 elad static void
1070 1.4.2.2 elad voodoofb_setup_monitor(struct voodoofb_softc *sc, const struct videomode *vm)
1071 1.4.2.2 elad {
1072 1.4.2.2 elad struct voodoo_regs mod;
1073 1.4.2.2 elad struct voodoo_regs *mode;
1074 1.4.2.2 elad uint32_t horizontal_display_end, horizontal_sync_start,
1075 1.4.2.2 elad horizontal_sync_end, horizontal_total,
1076 1.4.2.2 elad horizontal_blanking_start, horizontal_blanking_end;
1077 1.4.2.2 elad
1078 1.4.2.2 elad uint32_t vertical_display_enable_end, vertical_sync_start,
1079 1.4.2.2 elad vertical_sync_end, vertical_total, vertical_blanking_start,
1080 1.4.2.2 elad vertical_blanking_end;
1081 1.4.2.2 elad
1082 1.4.2.2 elad uint32_t wd; // CRTC offset
1083 1.4.2.2 elad
1084 1.4.2.2 elad int i;
1085 1.4.2.2 elad
1086 1.4.2.2 elad uint8_t misc;
1087 1.4.2.2 elad
1088 1.4.2.2 elad memset(&mod, 0, sizeof(mode));
1089 1.4.2.2 elad
1090 1.4.2.2 elad mode = &mod;
1091 1.4.2.2 elad
1092 1.4.2.2 elad wd = (vm->hdisplay >> 3) - 1;
1093 1.4.2.2 elad horizontal_display_end = (vm->hdisplay >> 3) - 1;
1094 1.4.2.2 elad horizontal_sync_start = (vm->hsync_start >> 3) - 1;
1095 1.4.2.2 elad horizontal_sync_end = (vm->hsync_end >> 3) - 1;
1096 1.4.2.2 elad horizontal_total = (vm->htotal >> 3) - 1;
1097 1.4.2.2 elad horizontal_blanking_start = horizontal_display_end;
1098 1.4.2.2 elad horizontal_blanking_end = horizontal_total;
1099 1.4.2.2 elad
1100 1.4.2.2 elad vertical_display_enable_end = vm->vdisplay - 1;
1101 1.4.2.2 elad vertical_sync_start = vm->vsync_start; // - 1;
1102 1.4.2.2 elad vertical_sync_end = vm->vsync_end; // - 1;
1103 1.4.2.2 elad vertical_total = vm->vtotal - 2;
1104 1.4.2.2 elad vertical_blanking_start = vertical_display_enable_end;
1105 1.4.2.2 elad vertical_blanking_end = vertical_total;
1106 1.4.2.2 elad
1107 1.4.2.2 elad misc = 0x0f |
1108 1.4.2.2 elad (vm->hdisplay < 400 ? 0xa0 :
1109 1.4.2.2 elad vm->hdisplay < 480 ? 0x60 :
1110 1.4.2.2 elad vm->hdisplay < 768 ? 0xe0 : 0x20);
1111 1.4.2.2 elad
1112 1.4.2.2 elad mode->vr_seq[0] = 3;
1113 1.4.2.2 elad mode->vr_seq[1] = 1;
1114 1.4.2.2 elad mode->vr_seq[2] = 8;
1115 1.4.2.2 elad mode->vr_seq[3] = 0;
1116 1.4.2.2 elad mode->vr_seq[4] = 6;
1117 1.4.2.2 elad
1118 1.4.2.2 elad /* crtc regs start */
1119 1.4.2.2 elad mode->vr_crtc[0] = horizontal_total - 4;
1120 1.4.2.2 elad mode->vr_crtc[1] = horizontal_display_end;
1121 1.4.2.2 elad mode->vr_crtc[2] = horizontal_blanking_start;
1122 1.4.2.2 elad mode->vr_crtc[3] = 0x80 | (horizontal_blanking_end & 0x1f);
1123 1.4.2.2 elad mode->vr_crtc[4] = horizontal_sync_start;
1124 1.4.2.2 elad
1125 1.4.2.2 elad mode->vr_crtc[5] = ((horizontal_blanking_end & 0x20) << 2) |
1126 1.4.2.2 elad (horizontal_sync_end & 0x1f);
1127 1.4.2.2 elad mode->vr_crtc[6] = vertical_total;
1128 1.4.2.2 elad mode->vr_crtc[7] = ((vertical_sync_start & 0x200) >> 2) |
1129 1.4.2.2 elad ((vertical_display_enable_end & 0x200) >> 3) |
1130 1.4.2.2 elad ((vertical_total & 0x200) >> 4) |
1131 1.4.2.2 elad 0x10 |
1132 1.4.2.2 elad ((vertical_blanking_start & 0x100) >> 5) |
1133 1.4.2.2 elad ((vertical_sync_start & 0x100) >> 6) |
1134 1.4.2.2 elad ((vertical_display_enable_end & 0x100) >> 7) |
1135 1.4.2.2 elad ((vertical_total & 0x100) >> 8);
1136 1.4.2.2 elad
1137 1.4.2.2 elad mode->vr_crtc[8] = 0;
1138 1.4.2.2 elad mode->vr_crtc[9] = 0x40 |
1139 1.4.2.2 elad ((vertical_blanking_start & 0x200) >> 4);
1140 1.4.2.2 elad
1141 1.4.2.2 elad mode->vr_crtc[10] = 0;
1142 1.4.2.2 elad mode->vr_crtc[11] = 0;
1143 1.4.2.2 elad mode->vr_crtc[12] = 0;
1144 1.4.2.2 elad mode->vr_crtc[13] = 0;
1145 1.4.2.2 elad mode->vr_crtc[14] = 0;
1146 1.4.2.2 elad mode->vr_crtc[15] = 0;
1147 1.4.2.2 elad
1148 1.4.2.2 elad mode->vr_crtc[16] = vertical_sync_start;
1149 1.4.2.2 elad mode->vr_crtc[17] = (vertical_sync_end & 0x0f) | 0x20;
1150 1.4.2.2 elad mode->vr_crtc[18] = vertical_display_enable_end;
1151 1.4.2.2 elad mode->vr_crtc[19] = wd; // CRTC offset
1152 1.4.2.2 elad mode->vr_crtc[20] = 0;
1153 1.4.2.2 elad mode->vr_crtc[21] = vertical_blanking_start;
1154 1.4.2.2 elad mode->vr_crtc[22] = vertical_blanking_end + 1;
1155 1.4.2.2 elad mode->vr_crtc[23] = 128;
1156 1.4.2.2 elad mode->vr_crtc[24] = 255;
1157 1.4.2.2 elad
1158 1.4.2.2 elad /* attr regs start */
1159 1.4.2.2 elad mode->vr_attr[0] = 0;
1160 1.4.2.2 elad mode->vr_attr[1] = 0;
1161 1.4.2.2 elad mode->vr_attr[2] = 0;
1162 1.4.2.2 elad mode->vr_attr[3] = 0;
1163 1.4.2.2 elad mode->vr_attr[4] = 0;
1164 1.4.2.2 elad mode->vr_attr[5] = 0;
1165 1.4.2.2 elad mode->vr_attr[6] = 0;
1166 1.4.2.2 elad mode->vr_attr[7] = 0;
1167 1.4.2.2 elad mode->vr_attr[8] = 0;
1168 1.4.2.2 elad mode->vr_attr[9] = 0;
1169 1.4.2.2 elad mode->vr_attr[10] = 0;
1170 1.4.2.2 elad mode->vr_attr[11] = 0;
1171 1.4.2.2 elad mode->vr_attr[12] = 0;
1172 1.4.2.2 elad mode->vr_attr[13] = 0;
1173 1.4.2.2 elad mode->vr_attr[14] = 0;
1174 1.4.2.2 elad mode->vr_attr[15] = 0;
1175 1.4.2.2 elad mode->vr_attr[16] = 1;
1176 1.4.2.2 elad mode->vr_attr[17] = 0;
1177 1.4.2.2 elad mode->vr_attr[18] = 15;
1178 1.4.2.2 elad mode->vr_attr[19] = 0;
1179 1.4.2.2 elad /* attr regs end */
1180 1.4.2.2 elad
1181 1.4.2.2 elad /* graph regs start */
1182 1.4.2.2 elad mode->vr_graph[0] = 159;
1183 1.4.2.2 elad mode->vr_graph[1] = 127;
1184 1.4.2.2 elad mode->vr_graph[2] = 127;
1185 1.4.2.2 elad mode->vr_graph[3] = 131;
1186 1.4.2.2 elad mode->vr_graph[4] = 130;
1187 1.4.2.2 elad mode->vr_graph[5] = 142;
1188 1.4.2.2 elad mode->vr_graph[6] = 30;
1189 1.4.2.2 elad mode->vr_graph[7] = 245;
1190 1.4.2.2 elad mode->vr_graph[8] = 0;
1191 1.4.2.2 elad
1192 1.4.2.2 elad vga_outb(sc, MISC_W, misc | 0x01);
1193 1.4.2.2 elad
1194 1.4.2.2 elad for(i = 0; i < 5; i++)
1195 1.4.2.2 elad voodoo3_write_seq(sc, i, mode->vr_seq[i]);
1196 1.4.2.2 elad for (i = 0; i < 0x19; i ++)
1197 1.4.2.2 elad voodoo3_write_crtc(sc, i, mode->vr_crtc[i]);
1198 1.4.2.2 elad for (i = 0; i < 0x14; i ++)
1199 1.4.2.2 elad voodoo3_write_attr(sc, i, mode->vr_attr[i]);
1200 1.4.2.2 elad for (i = 0; i < 0x09; i ++)
1201 1.4.2.2 elad voodoo3_write_gra(sc, i, mode->vr_graph[i]);
1202 1.4.2.2 elad }
1203 1.4.2.2 elad
1204 1.4.2.2 elad static void
1205 1.4.2.2 elad voodoofb_set_videomode(struct voodoofb_softc *sc,
1206 1.4.2.2 elad const struct videomode *vm)
1207 1.4.2.2 elad {
1208 1.4.2.2 elad uint32_t miscinit0 = 0;
1209 1.4.2.2 elad int vidpll, fout;
1210 1.4.2.2 elad uint32_t vp, vidproc = VIDPROCDEFAULT;
1211 1.4.2.2 elad uint32_t bpp = 1; /* for now */
1212 1.4.2.2 elad uint32_t bytes_per_row = vm->hdisplay * bpp;
1213 1.4.2.2 elad
1214 1.4.2.2 elad sc->bits_per_pixel = bpp << 3;
1215 1.4.2.2 elad sc->width = vm->hdisplay;
1216 1.4.2.2 elad sc->height = vm->vdisplay;
1217 1.4.2.2 elad sc->linebytes = bytes_per_row;
1218 1.4.2.2 elad
1219 1.4.2.2 elad voodoofb_setup_monitor(sc, vm);
1220 1.4.2.2 elad vp = voodoo3_read32(sc, VIDPROCCFG);
1221 1.4.2.2 elad
1222 1.4.2.2 elad vidproc &= ~(0x1c0000); /* clear bits 18 to 20, bpp in vidproccfg */
1223 1.4.2.2 elad /* enable bits 18 to 20 to the required bpp */
1224 1.4.2.2 elad vidproc |= ((bpp - 1) << VIDCFG_PIXFMT_SHIFT);
1225 1.4.2.2 elad
1226 1.4.2.2 elad vidpll = voodoofb_calc_pll(vm->dot_clock, &fout, 0);
1227 1.4.2.2 elad
1228 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
1229 1.4.2.2 elad printf("old vidproc: %08x\n", vp);
1230 1.4.2.2 elad printf("pll: %08x %d\n", vidpll, fout);
1231 1.4.2.2 elad #endif
1232 1.4.2.2 elad /* bit 10 of vidproccfg, is enabled or disabled as needed */
1233 1.4.2.2 elad switch (bpp) {
1234 1.4.2.2 elad case 1:
1235 1.4.2.2 elad /*
1236 1.4.2.2 elad * bit 10 off for palettized modes only, off means
1237 1.4.2.2 elad * palette is used
1238 1.4.2.2 elad */
1239 1.4.2.2 elad vidproc &= ~(1 << 10);
1240 1.4.2.2 elad break;
1241 1.4.2.2 elad #if 0
1242 1.4.2.2 elad case 2:
1243 1.4.2.2 elad #if __POWERPC__
1244 1.4.2.2 elad miscinit0 = 0xc0000000;
1245 1.4.2.2 elad #endif
1246 1.4.2.2 elad /* bypass palette for 16bit modes */
1247 1.4.2.2 elad vidproc |= (1 << 10);
1248 1.4.2.2 elad break;
1249 1.4.2.2 elad case 4:
1250 1.4.2.2 elad #if __POWERPC__
1251 1.4.2.2 elad miscinit0 = 0x40000000;
1252 1.4.2.2 elad #endif
1253 1.4.2.2 elad vidproc |= (1 << 10); /* Same for 32bit modes */
1254 1.4.2.2 elad break;
1255 1.4.2.2 elad #endif
1256 1.4.2.2 elad default:
1257 1.4.2.2 elad printf("We support only 8 bit for now\n");
1258 1.4.2.2 elad return;
1259 1.4.2.2 elad }
1260 1.4.2.2 elad
1261 1.4.2.2 elad voodoofb_wait_idle(sc);
1262 1.4.2.2 elad
1263 1.4.2.2 elad voodoo3_write32(sc, MISCINIT1, voodoo3_read32(sc, MISCINIT1) | 0x01);
1264 1.4.2.2 elad
1265 1.4.2.2 elad voodoo3_make_room(sc, 4);
1266 1.4.2.2 elad voodoo3_write32(sc, VGAINIT0, 4928);
1267 1.4.2.2 elad voodoo3_write32(sc, DACMODE, 0);
1268 1.4.2.2 elad voodoo3_write32(sc, VIDDESKSTRIDE, bytes_per_row);
1269 1.4.2.2 elad voodoo3_write32(sc, PLLCTRL0, vidpll);
1270 1.4.2.2 elad
1271 1.4.2.2 elad voodoo3_make_room(sc, 5);
1272 1.4.2.2 elad voodoo3_write32(sc, VIDSCREENSIZE, sc->width | (sc->height << 12));
1273 1.4.2.2 elad voodoo3_write32(sc, VIDDESKSTART, 1024);
1274 1.4.2.2 elad
1275 1.4.2.2 elad vidproc &= ~VIDCFG_HWCURSOR_ENABLE;
1276 1.4.2.2 elad voodoo3_write32(sc, VIDPROCCFG, vidproc);
1277 1.4.2.2 elad
1278 1.4.2.2 elad voodoo3_write32(sc, VGAINIT1, 0);
1279 1.4.2.2 elad voodoo3_write32(sc, MISCINIT0, miscinit0);
1280 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
1281 1.4.2.2 elad printf("vidproc: %08x\n", vidproc);
1282 1.4.2.2 elad #endif
1283 1.4.2.2 elad voodoo3_make_room(sc, 8);
1284 1.4.2.2 elad voodoo3_write32(sc, SRCBASE, 0);
1285 1.4.2.2 elad voodoo3_write32(sc, DSTBASE, 0);
1286 1.4.2.2 elad voodoo3_write32(sc, COMMANDEXTRA_2D, 0);
1287 1.4.2.2 elad voodoo3_write32(sc, CLIP0MIN, 0);
1288 1.4.2.2 elad voodoo3_write32(sc, CLIP0MAX, 0x0fff0fff);
1289 1.4.2.2 elad voodoo3_write32(sc, CLIP1MIN, 0);
1290 1.4.2.2 elad voodoo3_write32(sc, CLIP1MAX, 0x0fff0fff);
1291 1.4.2.2 elad voodoo3_write32(sc, SRCXY, 0);
1292 1.4.2.2 elad voodoofb_wait_idle(sc);
1293 1.4.2.2 elad printf("%s: switched to %dx%d, %d bit\n", sc->sc_dev.dv_xname,
1294 1.4.2.2 elad sc->width, sc->height, sc->bits_per_pixel);
1295 1.4.2.2 elad }
1296 1.4.2.2 elad
1297 1.4.2.2 elad static void
1298 1.4.2.2 elad voodoofb_init(struct voodoofb_softc *sc)
1299 1.4.2.2 elad {
1300 1.4.2.2 elad /* XXX */
1301 1.4.2.2 elad uint32_t vgainit0 = 0;
1302 1.4.2.2 elad uint32_t vidcfg = 0;
1303 1.4.2.2 elad
1304 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
1305 1.4.2.2 elad printf("initializing engine...");
1306 1.4.2.2 elad #endif
1307 1.4.2.2 elad vgainit0 = voodoo3_read32(sc, VGAINIT0);
1308 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
1309 1.4.2.2 elad printf("vga: %08x", vgainit0);
1310 1.4.2.2 elad #endif
1311 1.4.2.2 elad vgainit0 |=
1312 1.4.2.2 elad VGAINIT0_8BIT_DAC |
1313 1.4.2.2 elad VGAINIT0_EXT_ENABLE |
1314 1.4.2.2 elad VGAINIT0_WAKEUP_3C3 |
1315 1.4.2.2 elad VGAINIT0_ALT_READBACK |
1316 1.4.2.2 elad VGAINIT0_EXTSHIFTOUT;
1317 1.4.2.2 elad
1318 1.4.2.2 elad vidcfg = voodoo3_read32(sc, VIDPROCCFG);
1319 1.4.2.2 elad #ifdef VOODOOFB_DEBUG
1320 1.4.2.2 elad printf(" vidcfg: %08x\n", vidcfg);
1321 1.4.2.2 elad #endif
1322 1.4.2.2 elad vidcfg |=
1323 1.4.2.2 elad VIDCFG_VIDPROC_ENABLE |
1324 1.4.2.2 elad VIDCFG_DESK_ENABLE;
1325 1.4.2.2 elad vidcfg &= ~VIDCFG_HWCURSOR_ENABLE;
1326 1.4.2.2 elad
1327 1.4.2.2 elad voodoo3_make_room(sc, 2);
1328 1.4.2.2 elad
1329 1.4.2.2 elad voodoo3_write32(sc, VGAINIT0, vgainit0);
1330 1.4.2.2 elad voodoo3_write32(sc, VIDPROCCFG, vidcfg);
1331 1.4.2.2 elad
1332 1.4.2.2 elad voodoo3_make_room(sc, 8);
1333 1.4.2.2 elad voodoo3_write32(sc, SRCBASE, 0);
1334 1.4.2.2 elad voodoo3_write32(sc, DSTBASE, 0);
1335 1.4.2.2 elad voodoo3_write32(sc, COMMANDEXTRA_2D, 0);
1336 1.4.2.2 elad voodoo3_write32(sc, CLIP0MIN, 0);
1337 1.4.2.2 elad voodoo3_write32(sc, CLIP0MAX, 0x1fff1fff);
1338 1.4.2.2 elad voodoo3_write32(sc, CLIP1MIN, 0);
1339 1.4.2.2 elad voodoo3_write32(sc, CLIP1MAX, 0x1fff1fff);
1340 1.4.2.2 elad voodoo3_write32(sc, SRCXY, 0);
1341 1.4.2.2 elad
1342 1.4.2.2 elad voodoofb_wait_idle(sc);
1343 1.4.2.2 elad }
1344