wcfb.c revision 1.4 1 1.4 macallan /* $NetBSD: wcfb.c,v 1.4 2010/03/09 23:17:12 macallan Exp $ */
2 1.1 macallan
3 1.1 macallan /*-
4 1.2 macallan * Copyright (c) 2010 Michael Lorenz
5 1.1 macallan * All rights reserved.
6 1.1 macallan *
7 1.1 macallan * Redistribution and use in source and binary forms, with or without
8 1.1 macallan * modification, are permitted provided that the following conditions
9 1.1 macallan * are met:
10 1.1 macallan * 1. Redistributions of source code must retain the above copyright
11 1.1 macallan * notice, this list of conditions and the following disclaimer.
12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 macallan * notice, this list of conditions and the following disclaimer in the
14 1.1 macallan * documentation and/or other materials provided with the distribution.
15 1.1 macallan *
16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE.
27 1.1 macallan */
28 1.1 macallan
29 1.1 macallan #include <sys/cdefs.h>
30 1.4 macallan __KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.4 2010/03/09 23:17:12 macallan Exp $");
31 1.1 macallan
32 1.1 macallan #include <sys/param.h>
33 1.1 macallan #include <sys/systm.h>
34 1.1 macallan #include <sys/kernel.h>
35 1.1 macallan #include <sys/device.h>
36 1.1 macallan #include <sys/proc.h>
37 1.1 macallan #include <sys/mutex.h>
38 1.1 macallan #include <sys/ioctl.h>
39 1.1 macallan #include <sys/kernel.h>
40 1.1 macallan #include <sys/systm.h>
41 1.1 macallan #include <sys/kauth.h>
42 1.3 macallan #include <sys/kmem.h>
43 1.1 macallan
44 1.1 macallan #include <dev/pci/pcidevs.h>
45 1.1 macallan #include <dev/pci/pcireg.h>
46 1.1 macallan #include <dev/pci/pcivar.h>
47 1.1 macallan #include <dev/pci/pciio.h>
48 1.1 macallan
49 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
50 1.1 macallan #include <dev/wscons/wsconsio.h>
51 1.1 macallan #include <dev/wsfont/wsfont.h>
52 1.1 macallan #include <dev/rasops/rasops.h>
53 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
54 1.1 macallan
55 1.1 macallan #include "opt_wsfb.h"
56 1.1 macallan #include "opt_wcfb.h"
57 1.1 macallan
58 1.1 macallan #ifdef WCFB_DEBUG
59 1.1 macallan # define DPRINTF printf
60 1.1 macallan #else
61 1.1 macallan # define DPRINTF while (0) printf
62 1.1 macallan #endif
63 1.1 macallan
64 1.1 macallan static int wcfb_match(device_t, cfdata_t, void *);
65 1.1 macallan static void wcfb_attach(device_t, device_t, void *);
66 1.1 macallan static int wcfb_ioctl(void *, void *, u_long, void *, int,
67 1.1 macallan struct lwp *);
68 1.1 macallan static paddr_t wcfb_mmap(void *, void *, off_t, int);
69 1.1 macallan
70 1.1 macallan struct wcfb_softc {
71 1.1 macallan device_t sc_dev;
72 1.1 macallan
73 1.1 macallan pci_chipset_tag_t sc_pc;
74 1.1 macallan pcitag_t sc_pcitag;
75 1.1 macallan
76 1.1 macallan bus_space_tag_t sc_memt;
77 1.1 macallan bus_space_tag_t sc_regt, sc_wtft;
78 1.1 macallan bus_space_tag_t sc_iot;
79 1.1 macallan
80 1.1 macallan bus_space_handle_t sc_fbh, sc_wtfh;
81 1.1 macallan bus_space_handle_t sc_regh;
82 1.1 macallan bus_addr_t sc_fb, sc_reg, sc_wtf;
83 1.1 macallan bus_size_t sc_fbsize, sc_regsize, sc_wtfsize;
84 1.1 macallan
85 1.1 macallan int sc_width, sc_height, sc_stride;
86 1.1 macallan int sc_locked;
87 1.3 macallan uint8_t *sc_fbaddr, *sc_fb0, *sc_fb1, *sc_shadow;
88 1.1 macallan struct vcons_screen sc_console_screen;
89 1.1 macallan struct wsscreen_descr sc_defaultscreen_descr;
90 1.1 macallan const struct wsscreen_descr *sc_screens[1];
91 1.1 macallan struct wsscreen_list sc_screenlist;
92 1.1 macallan struct vcons_data vd;
93 1.1 macallan int sc_mode;
94 1.1 macallan u_char sc_cmap_red[256];
95 1.1 macallan u_char sc_cmap_green[256];
96 1.1 macallan u_char sc_cmap_blue[256];
97 1.1 macallan uint32_t sc_fb0off;
98 1.1 macallan
99 1.1 macallan void (*copycols)(void *, int, int, int, int);
100 1.1 macallan void (*erasecols)(void *, int, int, int, long);
101 1.1 macallan void (*copyrows)(void *, int, int, int);
102 1.1 macallan void (*eraserows)(void *, int, int, long);
103 1.1 macallan void (*putchar)(void *, int, int, u_int, long);
104 1.1 macallan void (*cursor)(void *, int, int, int);
105 1.1 macallan
106 1.1 macallan };
107 1.1 macallan
108 1.1 macallan static void wcfb_init_screen(void *, struct vcons_screen *, int, long *);
109 1.1 macallan
110 1.1 macallan CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
111 1.1 macallan wcfb_match, wcfb_attach, NULL, NULL);
112 1.1 macallan
113 1.1 macallan struct wsdisplay_accessops wcfb_accessops = {
114 1.1 macallan wcfb_ioctl,
115 1.1 macallan wcfb_mmap,
116 1.1 macallan NULL, /* alloc_screen */
117 1.1 macallan NULL, /* free_screen */
118 1.1 macallan NULL, /* show_screen */
119 1.1 macallan NULL, /* load_font */
120 1.1 macallan NULL, /* pollc */
121 1.1 macallan NULL /* scroll */
122 1.1 macallan };
123 1.1 macallan
124 1.1 macallan static void wcfb_putchar(void *, int, int, u_int, long);
125 1.1 macallan static void wcfb_cursor(void *, int, int, int);
126 1.1 macallan static void wcfb_copycols(void *, int, int, int, int);
127 1.1 macallan static void wcfb_erasecols(void *, int, int, int, long);
128 1.1 macallan static void wcfb_copyrows(void *, int, int, int);
129 1.1 macallan static void wcfb_eraserows(void *, int, int, long);
130 1.1 macallan
131 1.1 macallan static void wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
132 1.1 macallan
133 1.1 macallan static int
134 1.1 macallan wcfb_match(device_t parent, cfdata_t match, void *aux)
135 1.1 macallan {
136 1.1 macallan struct pci_attach_args *pa = aux;
137 1.1 macallan
138 1.1 macallan if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
139 1.1 macallan PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
140 1.1 macallan return 100;
141 1.1 macallan
142 1.1 macallan return 0;
143 1.1 macallan }
144 1.1 macallan
145 1.1 macallan static void
146 1.1 macallan wcfb_attach(device_t parent, device_t self, void *aux)
147 1.1 macallan {
148 1.1 macallan struct wcfb_softc *sc = device_private(self);
149 1.1 macallan struct pci_attach_args *pa = aux;
150 1.1 macallan struct rasops_info *ri;
151 1.1 macallan prop_dictionary_t dict;
152 1.1 macallan struct wsemuldisplaydev_attach_args aa;
153 1.1 macallan int i, j;
154 1.1 macallan unsigned long defattr;
155 1.1 macallan bool is_console;
156 1.1 macallan char devinfo[256];
157 1.1 macallan void *wtf;
158 1.1 macallan
159 1.1 macallan sc->sc_dev = self;
160 1.1 macallan sc->putchar = NULL;
161 1.1 macallan pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
162 1.1 macallan aprint_naive("\n");
163 1.1 macallan aprint_normal(": %s\n", devinfo);
164 1.1 macallan
165 1.1 macallan dict = device_properties(self);
166 1.1 macallan prop_dictionary_get_bool(dict, "is_console", &is_console);
167 1.2 macallan if(!is_console) return;
168 1.1 macallan
169 1.1 macallan sc->sc_memt = pa->pa_memt;
170 1.1 macallan sc->sc_iot = pa->pa_iot;
171 1.1 macallan sc->sc_pc = pa->pa_pc;
172 1.1 macallan sc->sc_pcitag = pa->pa_tag;
173 1.1 macallan
174 1.1 macallan /* fill in parameters from properties */
175 1.1 macallan if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
176 1.1 macallan aprint_error("%s: no width property\n", device_xname(self));
177 1.1 macallan return;
178 1.1 macallan }
179 1.1 macallan if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
180 1.1 macallan aprint_error("%s: no height property\n", device_xname(self));
181 1.1 macallan return;
182 1.1 macallan }
183 1.1 macallan
184 1.1 macallan if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
185 1.1 macallan &sc->sc_regt, &sc->sc_regh, &sc->sc_reg, &sc->sc_regsize)) {
186 1.1 macallan aprint_error("%s: failed to map registers.\n",
187 1.1 macallan device_xname(sc->sc_dev));
188 1.1 macallan }
189 1.1 macallan
190 1.1 macallan if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
191 1.1 macallan &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
192 1.1 macallan aprint_error("%s: failed to map framebuffer.\n",
193 1.1 macallan device_xname(sc->sc_dev));
194 1.1 macallan }
195 1.1 macallan
196 1.1 macallan if (pci_mapreg_map(pa, 0x18, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR,
197 1.1 macallan &sc->sc_wtft, &sc->sc_wtfh, &sc->sc_wtf, &sc->sc_wtfsize)) {
198 1.1 macallan aprint_error("%s: failed to map wtf.\n",
199 1.1 macallan device_xname(sc->sc_dev));
200 1.1 macallan }
201 1.1 macallan wtf = bus_space_vaddr(sc->sc_wtft, sc->sc_wtfh);
202 1.1 macallan memset(wtf, 0, 0x100000);
203 1.1 macallan
204 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
205 1.1 macallan
206 1.1 macallan sc->sc_fb0off = bus_space_read_4(sc->sc_regt, sc->sc_regh, 0x8080) -
207 1.1 macallan sc->sc_fb;
208 1.3 macallan sc->sc_fb0 = sc->sc_fbaddr + sc->sc_fb0off;
209 1.3 macallan sc->sc_fb1 = sc->sc_fb0 + 0x200000;
210 1.3 macallan
211 1.1 macallan sc->sc_stride = 1 <<
212 1.1 macallan ((bus_space_read_4(sc->sc_regt, sc->sc_regh, 0x8074) & 0x00ff0000) >> 16);
213 1.1 macallan printf("%s: %d x %d, %d\n", device_xname(sc->sc_dev),
214 1.1 macallan sc->sc_width, sc->sc_height, sc->sc_stride);
215 1.3 macallan
216 1.3 macallan sc->sc_shadow = kmem_alloc(sc->sc_stride * sc->sc_height, KM_SLEEP);
217 1.3 macallan if (sc->sc_shadow == NULL) {
218 1.3 macallan printf("%s: failed to allocate shadow buffer\n",
219 1.3 macallan device_xname(self));
220 1.3 macallan return;
221 1.3 macallan }
222 1.3 macallan
223 1.1 macallan for (i = 0x40; i < 0x100; i += 16) {
224 1.1 macallan printf("%04x:", i);
225 1.1 macallan for (j = 0; j < 16; j += 4) {
226 1.1 macallan printf(" %08x", bus_space_read_4(sc->sc_regt,
227 1.1 macallan sc->sc_regh, 0x8000 + i + j));
228 1.1 macallan }
229 1.1 macallan printf("\n");
230 1.1 macallan }
231 1.1 macallan
232 1.1 macallan sc->sc_defaultscreen_descr = (struct wsscreen_descr){
233 1.1 macallan "default",
234 1.1 macallan 0, 0,
235 1.1 macallan NULL,
236 1.1 macallan 8, 16,
237 1.1 macallan WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
238 1.1 macallan NULL
239 1.1 macallan };
240 1.1 macallan sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
241 1.1 macallan sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
242 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
243 1.1 macallan sc->sc_locked = 0;
244 1.1 macallan
245 1.1 macallan vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
246 1.1 macallan &wcfb_accessops);
247 1.1 macallan sc->vd.init_screen = wcfb_init_screen;
248 1.1 macallan
249 1.1 macallan /* init engine here */
250 1.1 macallan #if 0
251 1.1 macallan wcfb_init(sc);
252 1.1 macallan #endif
253 1.1 macallan
254 1.1 macallan ri = &sc->sc_console_screen.scr_ri;
255 1.1 macallan
256 1.1 macallan j = 0;
257 1.1 macallan for (i = 0; i < 256; i++) {
258 1.1 macallan
259 1.1 macallan sc->sc_cmap_red[i] = rasops_cmap[j];
260 1.1 macallan sc->sc_cmap_green[i] = rasops_cmap[j + 1];
261 1.1 macallan sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
262 1.1 macallan wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
263 1.1 macallan rasops_cmap[j + 2]);
264 1.1 macallan j += 3;
265 1.1 macallan }
266 1.1 macallan wcfb_putpalreg(sc, 0, 0, 0, 0);
267 1.1 macallan wcfb_putpalreg(sc, 15, 0xff, 0xff, 0xff);
268 1.1 macallan
269 1.1 macallan if (is_console) {
270 1.1 macallan vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
271 1.1 macallan &defattr);
272 1.1 macallan sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
273 1.1 macallan
274 1.1 macallan #if 0
275 1.1 macallan wcfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
276 1.1 macallan ri->ri_devcmap[(defattr >> 16) & 0xff]);
277 1.1 macallan #else
278 1.1 macallan /*memset(sc->sc_fbaddr + sc->sc_fb0off, 0, 0x400000);*/
279 1.1 macallan #endif
280 1.1 macallan sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
281 1.1 macallan sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
282 1.1 macallan sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
283 1.1 macallan sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
284 1.1 macallan wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
285 1.1 macallan defattr);
286 1.1 macallan vcons_replay_msgbuf(&sc->sc_console_screen);
287 1.1 macallan } else {
288 1.1 macallan /*
289 1.1 macallan * since we're not the console we can postpone the rest
290 1.1 macallan * until someone actually allocates a screen for us
291 1.1 macallan */
292 1.1 macallan (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
293 1.1 macallan }
294 1.1 macallan
295 1.1 macallan aa.console = is_console;
296 1.1 macallan aa.scrdata = &sc->sc_screenlist;
297 1.1 macallan aa.accessops = &wcfb_accessops;
298 1.1 macallan aa.accesscookie = &sc->vd;
299 1.1 macallan
300 1.1 macallan config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
301 1.1 macallan }
302 1.1 macallan
303 1.1 macallan static int
304 1.1 macallan wcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
305 1.1 macallan struct lwp *l)
306 1.1 macallan {
307 1.1 macallan struct wcfb_softc *sc = v;
308 1.1 macallan
309 1.1 macallan switch (cmd) {
310 1.1 macallan case WSDISPLAYIO_GTYPE:
311 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
312 1.1 macallan return 0;
313 1.1 macallan
314 1.1 macallan /* PCI config read/write passthrough. */
315 1.1 macallan case PCI_IOC_CFGREAD:
316 1.1 macallan case PCI_IOC_CFGWRITE:
317 1.1 macallan return (pci_devioctl(sc->sc_pc, sc->sc_pcitag,
318 1.1 macallan cmd, data, flag, l));
319 1.1 macallan case WSDISPLAYIO_SMODE:
320 1.1 macallan {
321 1.1 macallan /*int new_mode = *(int*)data, i;*/
322 1.1 macallan }
323 1.1 macallan return 0;
324 1.1 macallan }
325 1.1 macallan
326 1.1 macallan return EPASSTHROUGH;
327 1.1 macallan }
328 1.1 macallan
329 1.1 macallan static paddr_t
330 1.1 macallan wcfb_mmap(void *v, void *vs, off_t offset, int prot)
331 1.1 macallan {
332 1.1 macallan struct wcfb_softc *sc = v;
333 1.1 macallan
334 1.1 macallan /* no point in allowing a wsfb map if we can't provide one */
335 1.1 macallan /*
336 1.1 macallan * restrict all other mappings to processes with superuser privileges
337 1.1 macallan * or the kernel itself
338 1.1 macallan */
339 1.1 macallan if (kauth_authorize_generic(kauth_cred_get(), KAUTH_GENERIC_ISSUSER,
340 1.1 macallan NULL) != 0) {
341 1.1 macallan aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
342 1.1 macallan return -1;
343 1.1 macallan }
344 1.1 macallan
345 1.1 macallan #ifdef WSFB_FAKE_VGA_FB
346 1.1 macallan if ((offset >= 0xa0000) && (offset < 0xbffff)) {
347 1.1 macallan
348 1.1 macallan return bus_space_mmap(sc->sc_memt, sc->sc_gen.sc_fboffset,
349 1.1 macallan offset - 0xa0000, prot, BUS_SPACE_MAP_LINEAR);
350 1.1 macallan }
351 1.1 macallan #endif
352 1.1 macallan
353 1.1 macallan /*
354 1.1 macallan * XXX this should be generalized, let's just
355 1.1 macallan * #define PCI_IOAREA_PADDR
356 1.1 macallan * #define PCI_IOAREA_OFFSET
357 1.1 macallan * #define PCI_IOAREA_SIZE
358 1.1 macallan * somewhere in a MD header and compile this code only if all are
359 1.1 macallan * present
360 1.1 macallan */
361 1.2 macallan /*
362 1.2 macallan * PCI_IOAREA_PADDR is useless, that's what the IO tag is for
363 1.2 macallan * the address isn't guaranteed to be the same on each host bridge
364 1.2 macallan * either, never mind the fact that it would be a bus address
365 1.2 macallan */
366 1.1 macallan #ifdef PCI_MAGIC_IO_RANGE
367 1.1 macallan /* allow to map our IO space */
368 1.1 macallan if ((offset >= PCI_MAGIC_IO_RANGE) &&
369 1.1 macallan (offset < PCI_MAGIC_IO_RANGE + 0x10000)) {
370 1.1 macallan return bus_space_mmap(sc->sc_iot, offset - PCI_MAGIC_IO_RANGE,
371 1.1 macallan 0, prot, BUS_SPACE_MAP_LINEAR);
372 1.1 macallan }
373 1.1 macallan #endif
374 1.1 macallan return -1;
375 1.1 macallan }
376 1.1 macallan
377 1.1 macallan static void
378 1.1 macallan wcfb_init_screen(void *cookie, struct vcons_screen *scr,
379 1.1 macallan int existing, long *defattr)
380 1.1 macallan {
381 1.1 macallan struct wcfb_softc *sc = cookie;
382 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
383 1.1 macallan
384 1.1 macallan ri->ri_depth = 8;
385 1.1 macallan ri->ri_width = sc->sc_width;
386 1.1 macallan ri->ri_height = sc->sc_height;
387 1.1 macallan ri->ri_stride = sc->sc_stride;
388 1.1 macallan ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
389 1.1 macallan
390 1.3 macallan ri->ri_bits = sc->sc_shadow;
391 1.1 macallan
392 1.1 macallan if (existing) {
393 1.1 macallan ri->ri_flg |= RI_CLEAR;
394 1.1 macallan }
395 1.1 macallan
396 1.1 macallan rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
397 1.1 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
398 1.1 macallan
399 1.1 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
400 1.1 macallan sc->sc_width / ri->ri_font->fontwidth);
401 1.1 macallan
402 1.1 macallan ri->ri_hw = scr;
403 1.1 macallan sc->putchar = ri->ri_ops.putchar;
404 1.1 macallan sc->copyrows = ri->ri_ops.copyrows;
405 1.1 macallan sc->eraserows = ri->ri_ops.eraserows;
406 1.1 macallan sc->copycols = ri->ri_ops.copycols;
407 1.1 macallan sc->erasecols = ri->ri_ops.erasecols;
408 1.1 macallan
409 1.1 macallan ri->ri_ops.copyrows = wcfb_copyrows;
410 1.1 macallan ri->ri_ops.copycols = wcfb_copycols;
411 1.1 macallan ri->ri_ops.eraserows = wcfb_eraserows;
412 1.1 macallan ri->ri_ops.erasecols = wcfb_erasecols;
413 1.1 macallan ri->ri_ops.putchar = wcfb_putchar;
414 1.1 macallan ri->ri_ops.cursor = wcfb_cursor;
415 1.1 macallan }
416 1.1 macallan
417 1.1 macallan static void
418 1.1 macallan wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
419 1.1 macallan {
420 1.1 macallan struct rasops_info *ri = cookie;
421 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
422 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
423 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
424 1.3 macallan sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
425 1.3 macallan uint8_t *from, *to0, *to1;
426 1.3 macallan int i;
427 1.1 macallan
428 1.1 macallan sc->putchar(ri, row, col, c, attr);
429 1.3 macallan from = sc->sc_shadow + offset;
430 1.3 macallan to0 = sc->sc_fb0 + offset;
431 1.3 macallan to1 = sc->sc_fb1 + offset;
432 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
433 1.3 macallan memcpy(to0, from, ri->ri_font->fontwidth);
434 1.3 macallan memcpy(to1, from, ri->ri_font->fontwidth);
435 1.3 macallan to0 += sc->sc_stride;
436 1.3 macallan to1 += sc->sc_stride;
437 1.3 macallan from += sc->sc_stride;
438 1.3 macallan }
439 1.1 macallan }
440 1.1 macallan
441 1.1 macallan static void
442 1.1 macallan wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
443 1.1 macallan {
444 1.1 macallan uint32_t rgb;
445 1.1 macallan
446 1.1 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, 0x80bc, i);
447 1.1 macallan rgb = (b << 22) | (g << 12) | (r << 2);
448 1.1 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, 0x80c0, rgb);
449 1.1 macallan }
450 1.1 macallan
451 1.1 macallan static void
452 1.1 macallan wcfb_cursor(void *cookie, int on, int row, int col)
453 1.1 macallan {
454 1.1 macallan struct rasops_info *ri = cookie;
455 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
456 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
457 1.4 macallan int coffset;
458 1.4 macallan
459 1.4 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
460 1.4 macallan
461 1.4 macallan if (ri->ri_flg & RI_CURSOR) {
462 1.4 macallan /* remove cursor */
463 1.4 macallan coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
464 1.4 macallan #ifdef WSDISPLAY_SCROLLSUPPORT
465 1.4 macallan coffset += scr->scr_offset_to_zero;
466 1.4 macallan #endif
467 1.4 macallan wcfb_putchar(cookie, ri->ri_crow,
468 1.4 macallan ri->ri_ccol, scr->scr_chars[coffset],
469 1.4 macallan scr->scr_attrs[coffset]);
470 1.4 macallan ri->ri_flg &= ~RI_CURSOR;
471 1.4 macallan }
472 1.4 macallan ri->ri_crow = row;
473 1.4 macallan ri->ri_ccol = col;
474 1.4 macallan if (on) {
475 1.4 macallan long attr, revattr;
476 1.4 macallan coffset = col + (row * ri->ri_cols);
477 1.4 macallan #ifdef WSDISPLAY_SCROLLSUPPORT
478 1.4 macallan coffset += scr->scr_offset_to_zero;
479 1.1 macallan #endif
480 1.4 macallan attr = scr->scr_attrs[coffset];
481 1.4 macallan revattr = attr ^ 0xffff0000;
482 1.4 macallan
483 1.4 macallan wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
484 1.4 macallan scr->scr_chars[coffset], revattr);
485 1.4 macallan ri->ri_flg |= RI_CURSOR;
486 1.4 macallan }
487 1.4 macallan } else {
488 1.4 macallan ri->ri_crow = row;
489 1.4 macallan ri->ri_ccol = col;
490 1.4 macallan ri->ri_flg &= ~RI_CURSOR;
491 1.4 macallan }
492 1.1 macallan }
493 1.1 macallan
494 1.1 macallan static void
495 1.1 macallan wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
496 1.1 macallan {
497 1.1 macallan struct rasops_info *ri = cookie;
498 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
499 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
500 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
501 1.3 macallan sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
502 1.3 macallan uint8_t *from, *to0, *to1;
503 1.3 macallan int i;
504 1.1 macallan
505 1.1 macallan sc->copycols(ri, row, srccol, dstcol, ncols);
506 1.3 macallan from = sc->sc_shadow + offset;
507 1.3 macallan to0 = sc->sc_fb0 + offset;
508 1.3 macallan to1 = sc->sc_fb1 + offset;
509 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
510 1.3 macallan memcpy(to0, from, ri->ri_font->fontwidth * ncols);
511 1.3 macallan memcpy(to1, from, ri->ri_font->fontwidth * ncols);
512 1.3 macallan to0 += sc->sc_stride;
513 1.3 macallan to1 += sc->sc_stride;
514 1.3 macallan from += sc->sc_stride;
515 1.3 macallan }
516 1.1 macallan }
517 1.1 macallan
518 1.1 macallan static void
519 1.3 macallan wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
520 1.1 macallan {
521 1.1 macallan struct rasops_info *ri = cookie;
522 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
523 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
524 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
525 1.3 macallan sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
526 1.3 macallan uint8_t *to0, *to1;
527 1.3 macallan int i;
528 1.3 macallan
529 1.3 macallan sc->erasecols(ri, row, startcol, ncols, fillattr);
530 1.3 macallan
531 1.3 macallan to0 = sc->sc_fb0 + offset;
532 1.3 macallan to1 = sc->sc_fb1 + offset;
533 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
534 1.3 macallan memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
535 1.3 macallan ri->ri_font->fontwidth * ncols);
536 1.3 macallan memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
537 1.3 macallan ri->ri_font->fontwidth * ncols);
538 1.3 macallan to0 += sc->sc_stride;
539 1.3 macallan to1 += sc->sc_stride;
540 1.3 macallan }
541 1.1 macallan }
542 1.1 macallan
543 1.1 macallan static void
544 1.3 macallan wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
545 1.1 macallan {
546 1.1 macallan struct rasops_info *ri = cookie;
547 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
548 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
549 1.3 macallan int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
550 1.3 macallan sc->sc_stride + ri->ri_xorigin;
551 1.3 macallan uint8_t *from, *to0, *to1;
552 1.3 macallan int i;
553 1.3 macallan
554 1.3 macallan sc->copyrows(ri, srcrow, dstrow, nrows);
555 1.3 macallan
556 1.3 macallan from = sc->sc_shadow + offset;
557 1.3 macallan to0 = sc->sc_fb0 + offset;
558 1.3 macallan to1 = sc->sc_fb1 + offset;
559 1.3 macallan for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
560 1.3 macallan memcpy(to0, from, ri->ri_emuwidth);
561 1.3 macallan memcpy(to1, from, ri->ri_emuwidth);
562 1.3 macallan to0 += sc->sc_stride;
563 1.3 macallan to1 += sc->sc_stride;
564 1.3 macallan from += sc->sc_stride;
565 1.3 macallan }
566 1.1 macallan }
567 1.1 macallan
568 1.1 macallan static void
569 1.1 macallan wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
570 1.1 macallan {
571 1.1 macallan struct rasops_info *ri = cookie;
572 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
573 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
574 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
575 1.3 macallan sc->sc_stride + ri->ri_xorigin;
576 1.3 macallan uint8_t *to0, *to1;
577 1.3 macallan int i;
578 1.1 macallan
579 1.1 macallan sc->eraserows(ri, row, nrows, fillattr);
580 1.3 macallan
581 1.3 macallan to0 = sc->sc_fb0 + offset;
582 1.3 macallan to1 = sc->sc_fb1 + offset;
583 1.3 macallan for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
584 1.3 macallan memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
585 1.3 macallan ri->ri_emuwidth);
586 1.3 macallan memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
587 1.3 macallan ri->ri_emuwidth);
588 1.3 macallan to0 += sc->sc_stride;
589 1.3 macallan to1 += sc->sc_stride;
590 1.3 macallan }
591 1.1 macallan }
592