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