wcfb.c revision 1.14.2.1 1 1.14.2.1 pgoyette /* $NetBSD: wcfb.c,v 1.14.2.1 2017/04/26 02:53:22 pgoyette Exp $ */
2 1.1 macallan
3 1.13 macallan /*
4 1.13 macallan * Copyright (c) 2007, 2008, 2009 Miodrag Vallat.
5 1.13 macallan * 2010 Michael Lorenz
6 1.1 macallan *
7 1.13 macallan * Permission to use, copy, modify, and distribute this software for any
8 1.13 macallan * purpose with or without fee is hereby granted, provided that the above
9 1.13 macallan * copyright notice and this permission notice appear in all copies.
10 1.1 macallan *
11 1.13 macallan * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 1.13 macallan * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.13 macallan * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 1.13 macallan * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.13 macallan * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.13 macallan * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 1.13 macallan * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.1 macallan */
19 1.1 macallan
20 1.13 macallan /* a driver for (some) 3DLabs Wildcat cards, based on OpenBSD's ifb driver */
21 1.13 macallan
22 1.1 macallan #include <sys/cdefs.h>
23 1.14.2.1 pgoyette __KERNEL_RCSID(0, "$NetBSD: wcfb.c,v 1.14.2.1 2017/04/26 02:53:22 pgoyette Exp $");
24 1.1 macallan
25 1.1 macallan #include <sys/param.h>
26 1.1 macallan #include <sys/systm.h>
27 1.1 macallan #include <sys/kernel.h>
28 1.1 macallan #include <sys/device.h>
29 1.1 macallan #include <sys/proc.h>
30 1.1 macallan #include <sys/mutex.h>
31 1.1 macallan #include <sys/ioctl.h>
32 1.1 macallan #include <sys/kernel.h>
33 1.1 macallan #include <sys/systm.h>
34 1.1 macallan #include <sys/kauth.h>
35 1.3 macallan #include <sys/kmem.h>
36 1.1 macallan
37 1.1 macallan #include <dev/pci/pcidevs.h>
38 1.1 macallan #include <dev/pci/pcireg.h>
39 1.1 macallan #include <dev/pci/pcivar.h>
40 1.1 macallan #include <dev/pci/pciio.h>
41 1.6 macallan #include <dev/pci/wcfbreg.h>
42 1.1 macallan
43 1.1 macallan #include <dev/wscons/wsdisplayvar.h>
44 1.1 macallan #include <dev/wscons/wsconsio.h>
45 1.1 macallan #include <dev/wsfont/wsfont.h>
46 1.1 macallan #include <dev/rasops/rasops.h>
47 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h>
48 1.8 cegger #include <dev/pci/wsdisplay_pci.h>
49 1.1 macallan
50 1.1 macallan #include "opt_wsfb.h"
51 1.5 macallan #include "opt_wsdisplay_compat.h"
52 1.1 macallan
53 1.1 macallan #ifdef WCFB_DEBUG
54 1.1 macallan # define DPRINTF printf
55 1.1 macallan #else
56 1.1 macallan # define DPRINTF while (0) printf
57 1.1 macallan #endif
58 1.1 macallan
59 1.1 macallan static int wcfb_match(device_t, cfdata_t, void *);
60 1.1 macallan static void wcfb_attach(device_t, device_t, void *);
61 1.1 macallan static int wcfb_ioctl(void *, void *, u_long, void *, int,
62 1.1 macallan struct lwp *);
63 1.1 macallan static paddr_t wcfb_mmap(void *, void *, off_t, int);
64 1.1 macallan
65 1.1 macallan struct wcfb_softc {
66 1.1 macallan device_t sc_dev;
67 1.1 macallan
68 1.1 macallan pci_chipset_tag_t sc_pc;
69 1.1 macallan pcitag_t sc_pcitag;
70 1.1 macallan
71 1.1 macallan bus_space_tag_t sc_memt;
72 1.1 macallan bus_space_tag_t sc_regt, sc_wtft;
73 1.1 macallan bus_space_tag_t sc_iot;
74 1.1 macallan
75 1.14.2.1 pgoyette bus_space_handle_t sc_fbh;
76 1.1 macallan bus_space_handle_t sc_regh;
77 1.14.2.1 pgoyette bus_addr_t sc_fb, sc_reg;
78 1.14.2.1 pgoyette bus_size_t sc_fbsize, sc_regsize;
79 1.1 macallan
80 1.1 macallan int sc_width, sc_height, sc_stride;
81 1.1 macallan int sc_locked;
82 1.3 macallan uint8_t *sc_fbaddr, *sc_fb0, *sc_fb1, *sc_shadow;
83 1.1 macallan struct vcons_screen sc_console_screen;
84 1.1 macallan struct wsscreen_descr sc_defaultscreen_descr;
85 1.1 macallan const struct wsscreen_descr *sc_screens[1];
86 1.1 macallan struct wsscreen_list sc_screenlist;
87 1.1 macallan struct vcons_data vd;
88 1.14.2.1 pgoyette int sc_mode, sc_dpms;
89 1.1 macallan u_char sc_cmap_red[256];
90 1.1 macallan u_char sc_cmap_green[256];
91 1.1 macallan u_char sc_cmap_blue[256];
92 1.14.2.1 pgoyette uint32_t sc_fb0off, sc_fb1off, sc_fb8size;
93 1.1 macallan
94 1.1 macallan void (*copycols)(void *, int, int, int, int);
95 1.1 macallan void (*erasecols)(void *, int, int, int, long);
96 1.1 macallan void (*copyrows)(void *, int, int, int);
97 1.1 macallan void (*eraserows)(void *, int, int, long);
98 1.1 macallan void (*putchar)(void *, int, int, u_int, long);
99 1.1 macallan void (*cursor)(void *, int, int, int);
100 1.12 macallan int sc_is_jfb;
101 1.1 macallan };
102 1.1 macallan
103 1.1 macallan static void wcfb_init_screen(void *, struct vcons_screen *, int, long *);
104 1.1 macallan
105 1.1 macallan CFATTACH_DECL_NEW(wcfb, sizeof(struct wcfb_softc),
106 1.1 macallan wcfb_match, wcfb_attach, NULL, NULL);
107 1.1 macallan
108 1.1 macallan struct wsdisplay_accessops wcfb_accessops = {
109 1.1 macallan wcfb_ioctl,
110 1.1 macallan wcfb_mmap,
111 1.1 macallan NULL, /* alloc_screen */
112 1.1 macallan NULL, /* free_screen */
113 1.1 macallan NULL, /* show_screen */
114 1.1 macallan NULL, /* load_font */
115 1.1 macallan NULL, /* pollc */
116 1.1 macallan NULL /* scroll */
117 1.1 macallan };
118 1.1 macallan
119 1.1 macallan static void wcfb_putchar(void *, int, int, u_int, long);
120 1.1 macallan static void wcfb_cursor(void *, int, int, int);
121 1.1 macallan static void wcfb_copycols(void *, int, int, int, int);
122 1.1 macallan static void wcfb_erasecols(void *, int, int, int, long);
123 1.1 macallan static void wcfb_copyrows(void *, int, int, int);
124 1.1 macallan static void wcfb_eraserows(void *, int, int, long);
125 1.1 macallan
126 1.12 macallan static void wcfb_acc_putchar(void *, int, int, u_int, long);
127 1.12 macallan static void wcfb_acc_cursor(void *, int, int, int);
128 1.12 macallan static void wcfb_acc_copycols(void *, int, int, int, int);
129 1.12 macallan static void wcfb_acc_erasecols(void *, int, int, int, long);
130 1.12 macallan static void wcfb_acc_copyrows(void *, int, int, int);
131 1.12 macallan static void wcfb_acc_eraserows(void *, int, int, long);
132 1.12 macallan
133 1.1 macallan static void wcfb_putpalreg(struct wcfb_softc *, int, int, int, int);
134 1.1 macallan
135 1.12 macallan static void wcfb_bitblt(struct wcfb_softc *, int, int, int, int, int,
136 1.12 macallan int, uint32_t);
137 1.12 macallan static void wcfb_rectfill(struct wcfb_softc *, int, int, int, int, int);
138 1.14 msaitoh static void wcfb_rop_common(struct wcfb_softc *, bus_addr_t, int, int, int,
139 1.12 macallan int, int, int, uint32_t, int32_t);
140 1.14 msaitoh static void wcfb_rop_jfb(struct wcfb_softc *, int, int, int, int, int, int,
141 1.12 macallan uint32_t, int32_t);
142 1.12 macallan static int wcfb_rop_wait(struct wcfb_softc *);
143 1.12 macallan
144 1.1 macallan static int
145 1.1 macallan wcfb_match(device_t parent, cfdata_t match, void *aux)
146 1.1 macallan {
147 1.1 macallan struct pci_attach_args *pa = aux;
148 1.1 macallan
149 1.1 macallan if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DLABS &&
150 1.1 macallan PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_3DLABS_WILDCAT5110)
151 1.1 macallan return 100;
152 1.1 macallan
153 1.1 macallan return 0;
154 1.1 macallan }
155 1.1 macallan
156 1.1 macallan static void
157 1.1 macallan wcfb_attach(device_t parent, device_t self, void *aux)
158 1.1 macallan {
159 1.1 macallan struct wcfb_softc *sc = device_private(self);
160 1.1 macallan struct pci_attach_args *pa = aux;
161 1.1 macallan struct rasops_info *ri;
162 1.1 macallan prop_dictionary_t dict;
163 1.1 macallan struct wsemuldisplaydev_attach_args aa;
164 1.1 macallan int i, j;
165 1.6 macallan uint32_t reg;
166 1.1 macallan unsigned long defattr;
167 1.6 macallan bool is_console = 0;
168 1.12 macallan uint32_t sub;
169 1.1 macallan
170 1.1 macallan sc->sc_dev = self;
171 1.1 macallan sc->putchar = NULL;
172 1.10 drochner pci_aprint_devinfo(pa, NULL);
173 1.1 macallan
174 1.1 macallan dict = device_properties(self);
175 1.1 macallan prop_dictionary_get_bool(dict, "is_console", &is_console);
176 1.6 macallan #ifndef WCFB_DEBUG
177 1.6 macallan if (!is_console) return;
178 1.6 macallan #endif
179 1.1 macallan sc->sc_memt = pa->pa_memt;
180 1.14 msaitoh sc->sc_iot = pa->pa_iot;
181 1.1 macallan sc->sc_pc = pa->pa_pc;
182 1.1 macallan sc->sc_pcitag = pa->pa_tag;
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.14.2.1 pgoyette if (pci_mapreg_map(pa, 0x10, PCI_MAPREG_TYPE_MEM,
191 1.14.2.1 pgoyette BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
192 1.1 macallan &sc->sc_memt, &sc->sc_fbh, &sc->sc_fb, &sc->sc_fbsize)) {
193 1.1 macallan aprint_error("%s: failed to map framebuffer.\n",
194 1.1 macallan device_xname(sc->sc_dev));
195 1.1 macallan }
196 1.1 macallan
197 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sc->sc_memt, sc->sc_fbh);
198 1.14.2.1 pgoyette #ifdef DEBUG
199 1.14.2.1 pgoyette memset(sc->sc_fbaddr, 0, sc->sc_fbsize);
200 1.14.2.1 pgoyette #endif
201 1.6 macallan sc->sc_fb0off =
202 1.12 macallan bus_space_read_4(sc->sc_regt, sc->sc_regh,
203 1.12 macallan WC_FB8_ADDR0) - sc->sc_fb;
204 1.3 macallan sc->sc_fb0 = sc->sc_fbaddr + sc->sc_fb0off;
205 1.14 msaitoh sc->sc_fb1off =
206 1.12 macallan bus_space_read_4(sc->sc_regt, sc->sc_regh,
207 1.12 macallan WC_FB8_ADDR1) - sc->sc_fb;
208 1.6 macallan sc->sc_fb1 = sc->sc_fbaddr + sc->sc_fb1off;
209 1.14.2.1 pgoyette sc->sc_fb8size = 2 * (sc->sc_fb1off - sc->sc_fb0off);
210 1.6 macallan
211 1.12 macallan sub = pci_conf_read(sc->sc_pc, sc->sc_pcitag, PCI_SUBSYS_ID_REG);
212 1.14 msaitoh aprint_normal("subsys: %08x\n", sub);
213 1.12 macallan switch (sub) {
214 1.12 macallan case WC_XVR1200:
215 1.12 macallan sc->sc_is_jfb = 1;
216 1.12 macallan break;
217 1.12 macallan default:
218 1.12 macallan sc->sc_is_jfb = 0;
219 1.12 macallan }
220 1.12 macallan
221 1.6 macallan reg = bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_RESOLUTION);
222 1.6 macallan sc->sc_height = (reg >> 16) + 1;
223 1.12 macallan #ifdef WCFB_DEBUG
224 1.12 macallan sc->sc_height -= 200;
225 1.12 macallan #endif
226 1.6 macallan sc->sc_width = (reg & 0xffff) + 1;
227 1.6 macallan sc->sc_stride = 1 <<
228 1.6 macallan ((bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_CONFIG) &
229 1.6 macallan 0x00ff0000) >> 16);
230 1.14 msaitoh aprint_normal_dev(self, "%d x %d, %d\n",
231 1.1 macallan sc->sc_width, sc->sc_height, sc->sc_stride);
232 1.3 macallan
233 1.12 macallan if (sc->sc_is_jfb == 0) {
234 1.12 macallan sc->sc_shadow = kmem_alloc(sc->sc_stride * sc->sc_height,
235 1.12 macallan KM_SLEEP);
236 1.12 macallan if (sc->sc_shadow == NULL) {
237 1.14 msaitoh aprint_error_dev(self,
238 1.14 msaitoh "failed to allocate shadow buffer\n");
239 1.12 macallan return;
240 1.12 macallan }
241 1.3 macallan }
242 1.3 macallan
243 1.1 macallan for (i = 0x40; i < 0x100; i += 16) {
244 1.14 msaitoh aprint_normal("%04x:", i);
245 1.1 macallan for (j = 0; j < 16; j += 4) {
246 1.14 msaitoh aprint_normal(" %08x", bus_space_read_4(sc->sc_regt,
247 1.1 macallan sc->sc_regh, 0x8000 + i + j));
248 1.1 macallan }
249 1.14 msaitoh aprint_normal("\n");
250 1.1 macallan }
251 1.1 macallan
252 1.6 macallan /* make sure video output is on */
253 1.6 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_DPMS_STATE, WC_DPMS_ON);
254 1.14.2.1 pgoyette sc->sc_dpms = WSDISPLAYIO_VIDEO_ON;
255 1.6 macallan
256 1.14.2.1 pgoyette #if 0
257 1.14.2.1 pgoyette /* testing & debugging voodoo */
258 1.14.2.1 pgoyette memset(sc->sc_fb0, 0x01, 0x00100000);
259 1.14.2.1 pgoyette memset(sc->sc_fb1, 0x00, 0x00100000);
260 1.14.2.1 pgoyette wcfb_rop_wait(sc);
261 1.14.2.1 pgoyette wcfb_rop_jfb(sc, 0, 0, 0, 0, 600, 600, WC_ROP_SET, 0xffffffff);
262 1.14.2.1 pgoyette wcfb_rop_wait(sc);
263 1.14.2.1 pgoyette delay(4000000);
264 1.14.2.1 pgoyette bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR1,
265 1.14.2.1 pgoyette bus_space_read_4(sc->sc_regt, sc->sc_regh, WC_FB8_ADDR0));
266 1.14.2.1 pgoyette delay(8000000);
267 1.14.2.1 pgoyette #endif
268 1.1 macallan sc->sc_defaultscreen_descr = (struct wsscreen_descr){
269 1.1 macallan "default",
270 1.1 macallan 0, 0,
271 1.1 macallan NULL,
272 1.1 macallan 8, 16,
273 1.1 macallan WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
274 1.1 macallan NULL
275 1.1 macallan };
276 1.1 macallan sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
277 1.1 macallan sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
278 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
279 1.1 macallan sc->sc_locked = 0;
280 1.1 macallan
281 1.1 macallan vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
282 1.1 macallan &wcfb_accessops);
283 1.1 macallan sc->vd.init_screen = wcfb_init_screen;
284 1.1 macallan
285 1.1 macallan /* init engine here */
286 1.1 macallan #if 0
287 1.1 macallan wcfb_init(sc);
288 1.1 macallan #endif
289 1.1 macallan
290 1.1 macallan ri = &sc->sc_console_screen.scr_ri;
291 1.1 macallan
292 1.1 macallan j = 0;
293 1.1 macallan for (i = 0; i < 256; i++) {
294 1.1 macallan
295 1.1 macallan sc->sc_cmap_red[i] = rasops_cmap[j];
296 1.1 macallan sc->sc_cmap_green[i] = rasops_cmap[j + 1];
297 1.1 macallan sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
298 1.1 macallan wcfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
299 1.1 macallan rasops_cmap[j + 2]);
300 1.1 macallan j += 3;
301 1.1 macallan }
302 1.1 macallan
303 1.1 macallan if (is_console) {
304 1.1 macallan vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
305 1.1 macallan &defattr);
306 1.1 macallan sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
307 1.1 macallan
308 1.12 macallan if (sc->sc_is_jfb) {
309 1.12 macallan wcfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height,
310 1.12 macallan ri->ri_devcmap[(defattr >> 16) & 0xff]);
311 1.12 macallan } else {
312 1.12 macallan memset(sc->sc_fb0,
313 1.12 macallan ri->ri_devcmap[(defattr >> 16) & 0xff],
314 1.12 macallan sc->sc_stride * sc->sc_height);
315 1.12 macallan memset(sc->sc_fb1,
316 1.12 macallan ri->ri_devcmap[(defattr >> 16) & 0xff],
317 1.12 macallan sc->sc_stride * sc->sc_height);
318 1.12 macallan }
319 1.1 macallan sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
320 1.1 macallan sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
321 1.1 macallan sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
322 1.1 macallan sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
323 1.1 macallan wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
324 1.1 macallan defattr);
325 1.1 macallan vcons_replay_msgbuf(&sc->sc_console_screen);
326 1.1 macallan } else {
327 1.1 macallan /*
328 1.1 macallan * since we're not the console we can postpone the rest
329 1.1 macallan * until someone actually allocates a screen for us
330 1.1 macallan */
331 1.6 macallan memset(sc->sc_fb0, WS_DEFAULT_BG,
332 1.6 macallan sc->sc_stride * sc->sc_height);
333 1.6 macallan memset(sc->sc_fb1, WS_DEFAULT_BG,
334 1.6 macallan sc->sc_stride * sc->sc_height);
335 1.6 macallan return;
336 1.1 macallan }
337 1.1 macallan
338 1.1 macallan aa.console = is_console;
339 1.1 macallan aa.scrdata = &sc->sc_screenlist;
340 1.1 macallan aa.accessops = &wcfb_accessops;
341 1.1 macallan aa.accesscookie = &sc->vd;
342 1.1 macallan
343 1.1 macallan config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
344 1.1 macallan }
345 1.1 macallan
346 1.1 macallan static int
347 1.14.2.1 pgoyette wcfb_putcmap(struct wcfb_softc *sc, struct wsdisplay_cmap *cm)
348 1.14.2.1 pgoyette {
349 1.14.2.1 pgoyette u_char *r, *g, *b;
350 1.14.2.1 pgoyette u_int index = cm->index;
351 1.14.2.1 pgoyette u_int count = cm->count;
352 1.14.2.1 pgoyette int i, error;
353 1.14.2.1 pgoyette u_char rbuf[256], gbuf[256], bbuf[256];
354 1.14.2.1 pgoyette
355 1.14.2.1 pgoyette if (cm->index >= 256 || cm->count > 256 ||
356 1.14.2.1 pgoyette (cm->index + cm->count) > 256)
357 1.14.2.1 pgoyette return EINVAL;
358 1.14.2.1 pgoyette error = copyin(cm->red, &rbuf[index], count);
359 1.14.2.1 pgoyette if (error)
360 1.14.2.1 pgoyette return error;
361 1.14.2.1 pgoyette error = copyin(cm->green, &gbuf[index], count);
362 1.14.2.1 pgoyette if (error)
363 1.14.2.1 pgoyette return error;
364 1.14.2.1 pgoyette error = copyin(cm->blue, &bbuf[index], count);
365 1.14.2.1 pgoyette if (error)
366 1.14.2.1 pgoyette return error;
367 1.14.2.1 pgoyette
368 1.14.2.1 pgoyette memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
369 1.14.2.1 pgoyette memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
370 1.14.2.1 pgoyette memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
371 1.14.2.1 pgoyette
372 1.14.2.1 pgoyette r = &sc->sc_cmap_red[index];
373 1.14.2.1 pgoyette g = &sc->sc_cmap_green[index];
374 1.14.2.1 pgoyette b = &sc->sc_cmap_blue[index];
375 1.14.2.1 pgoyette
376 1.14.2.1 pgoyette for (i = 0; i < count; i++) {
377 1.14.2.1 pgoyette wcfb_putpalreg(sc, index, *r, *g, *b);
378 1.14.2.1 pgoyette index++;
379 1.14.2.1 pgoyette r++, g++, b++;
380 1.14.2.1 pgoyette }
381 1.14.2.1 pgoyette return 0;
382 1.14.2.1 pgoyette }
383 1.14.2.1 pgoyette
384 1.14.2.1 pgoyette static int
385 1.14.2.1 pgoyette wcfb_getcmap(struct wcfb_softc *sc, struct wsdisplay_cmap *cm)
386 1.14.2.1 pgoyette {
387 1.14.2.1 pgoyette u_int index = cm->index;
388 1.14.2.1 pgoyette u_int count = cm->count;
389 1.14.2.1 pgoyette int error;
390 1.14.2.1 pgoyette
391 1.14.2.1 pgoyette if (index >= 255 || count > 256 || index + count > 256)
392 1.14.2.1 pgoyette return EINVAL;
393 1.14.2.1 pgoyette
394 1.14.2.1 pgoyette error = copyout(&sc->sc_cmap_red[index], cm->red, count);
395 1.14.2.1 pgoyette if (error)
396 1.14.2.1 pgoyette return error;
397 1.14.2.1 pgoyette error = copyout(&sc->sc_cmap_green[index], cm->green, count);
398 1.14.2.1 pgoyette if (error)
399 1.14.2.1 pgoyette return error;
400 1.14.2.1 pgoyette error = copyout(&sc->sc_cmap_blue[index], cm->blue, count);
401 1.14.2.1 pgoyette if (error)
402 1.14.2.1 pgoyette return error;
403 1.14.2.1 pgoyette
404 1.14.2.1 pgoyette return 0;
405 1.14.2.1 pgoyette }
406 1.14.2.1 pgoyette
407 1.14.2.1 pgoyette static int
408 1.1 macallan wcfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
409 1.1 macallan struct lwp *l)
410 1.1 macallan {
411 1.14.2.1 pgoyette struct vcons_data *vd = v;
412 1.14.2.1 pgoyette struct wcfb_softc *sc = vd->cookie;
413 1.1 macallan
414 1.1 macallan switch (cmd) {
415 1.7 cegger case WSDISPLAYIO_GTYPE:
416 1.7 cegger *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
417 1.7 cegger return 0;
418 1.7 cegger
419 1.7 cegger /* PCI config read/write passthrough. */
420 1.7 cegger case PCI_IOC_CFGREAD:
421 1.7 cegger case PCI_IOC_CFGWRITE:
422 1.7 cegger return pci_devioctl(sc->sc_pc, sc->sc_pcitag,
423 1.7 cegger cmd, data, flag, l);
424 1.8 cegger
425 1.8 cegger case WSDISPLAYIO_GET_BUSID:
426 1.8 cegger return wsdisplayio_busid_pci(sc->sc_dev, sc->sc_pc,
427 1.8 cegger sc->sc_pcitag, data);
428 1.8 cegger
429 1.14.2.1 pgoyette case WSDISPLAYIO_SVIDEO: {
430 1.14.2.1 pgoyette int new_mode = *(int*)data;
431 1.14.2.1 pgoyette if (new_mode != sc->sc_dpms) {
432 1.14.2.1 pgoyette sc->sc_dpms = new_mode;
433 1.14.2.1 pgoyette bus_space_write_4(sc->sc_regt, sc->sc_regh,
434 1.14.2.1 pgoyette WC_DPMS_STATE,
435 1.14.2.1 pgoyette (new_mode == WSDISPLAYIO_VIDEO_ON) ?
436 1.14.2.1 pgoyette WC_DPMS_ON : WC_DPMS_STANDBY);
437 1.14.2.1 pgoyette }
438 1.7 cegger }
439 1.7 cegger return 0;
440 1.1 macallan
441 1.14.2.1 pgoyette case WSDISPLAYIO_GVIDEO:
442 1.14.2.1 pgoyette *(int*)data = sc->sc_dpms;
443 1.14.2.1 pgoyette return 0;
444 1.14.2.1 pgoyette
445 1.14.2.1 pgoyette case WSDISPLAYIO_GETCMAP:
446 1.14.2.1 pgoyette return wcfb_getcmap(sc,
447 1.14.2.1 pgoyette (struct wsdisplay_cmap *)data);
448 1.14.2.1 pgoyette
449 1.14.2.1 pgoyette case WSDISPLAYIO_PUTCMAP:
450 1.14.2.1 pgoyette return wcfb_putcmap(sc,
451 1.14.2.1 pgoyette (struct wsdisplay_cmap *)data);
452 1.14.2.1 pgoyette
453 1.14.2.1 pgoyette case WSDISPLAYIO_GET_FBINFO: {
454 1.14.2.1 pgoyette struct wsdisplayio_fbinfo *fbi = data;
455 1.14.2.1 pgoyette
456 1.14.2.1 pgoyette fbi->fbi_fbsize = sc->sc_fb8size;
457 1.14.2.1 pgoyette fbi->fbi_fboffset = 0;
458 1.14.2.1 pgoyette fbi->fbi_width = sc->sc_width;
459 1.14.2.1 pgoyette fbi->fbi_height = sc->sc_height;
460 1.14.2.1 pgoyette fbi->fbi_bitsperpixel = 8;
461 1.14.2.1 pgoyette fbi->fbi_stride = sc->sc_stride;
462 1.14.2.1 pgoyette fbi->fbi_pixeltype = WSFB_CI;
463 1.14.2.1 pgoyette fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = 256;
464 1.14.2.1 pgoyette fbi->fbi_flags = WSFB_VRAM_IS_SPLIT;
465 1.14.2.1 pgoyette return 0;
466 1.14.2.1 pgoyette }
467 1.14.2.1 pgoyette }
468 1.1 macallan return EPASSTHROUGH;
469 1.1 macallan }
470 1.1 macallan
471 1.1 macallan static paddr_t
472 1.1 macallan wcfb_mmap(void *v, void *vs, off_t offset, int prot)
473 1.1 macallan {
474 1.14.2.1 pgoyette struct vcons_data *vd = v;
475 1.14.2.1 pgoyette struct wcfb_softc *sc = vd->cookie;
476 1.1 macallan
477 1.14.2.1 pgoyette /* XXX in theory the order is not fixed... */
478 1.14.2.1 pgoyette
479 1.14.2.1 pgoyette if (offset < sc->sc_fb8size)
480 1.14.2.1 pgoyette return bus_space_mmap(sc->sc_memt, sc->sc_fb + sc->sc_fb0off,
481 1.14.2.1 pgoyette offset, prot,
482 1.14.2.1 pgoyette BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE);
483 1.1 macallan /*
484 1.1 macallan * restrict all other mappings to processes with superuser privileges
485 1.1 macallan * or the kernel itself
486 1.1 macallan */
487 1.14 msaitoh if (kauth_authorize_machdep(kauth_cred_get(),
488 1.12 macallan KAUTH_MACHDEP_UNMANAGEDMEM,
489 1.11 elad NULL, NULL, NULL, NULL) != 0) {
490 1.1 macallan aprint_normal_dev(sc->sc_dev, "mmap() rejected.\n");
491 1.1 macallan return -1;
492 1.1 macallan }
493 1.1 macallan
494 1.14.2.1 pgoyette /* may want to mmap() registers at some point */
495 1.1 macallan
496 1.1 macallan return -1;
497 1.1 macallan }
498 1.1 macallan
499 1.1 macallan static void
500 1.1 macallan wcfb_init_screen(void *cookie, struct vcons_screen *scr,
501 1.1 macallan int existing, long *defattr)
502 1.1 macallan {
503 1.1 macallan struct wcfb_softc *sc = cookie;
504 1.1 macallan struct rasops_info *ri = &scr->scr_ri;
505 1.1 macallan
506 1.1 macallan ri->ri_depth = 8;
507 1.1 macallan ri->ri_width = sc->sc_width;
508 1.1 macallan ri->ri_height = sc->sc_height;
509 1.1 macallan ri->ri_stride = sc->sc_stride;
510 1.1 macallan ri->ri_flg = RI_CENTER /*| RI_FULLCLEAR*/;
511 1.1 macallan
512 1.12 macallan if (sc->sc_is_jfb) {
513 1.12 macallan ri->ri_bits = sc->sc_fb0;
514 1.12 macallan } else {
515 1.12 macallan ri->ri_bits = sc->sc_shadow;
516 1.12 macallan }
517 1.1 macallan if (existing) {
518 1.1 macallan ri->ri_flg |= RI_CLEAR;
519 1.1 macallan }
520 1.1 macallan
521 1.9 macallan rasops_init(ri, 0, 0);
522 1.1 macallan ri->ri_caps = WSSCREEN_WSCOLORS;
523 1.1 macallan
524 1.1 macallan rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
525 1.1 macallan sc->sc_width / ri->ri_font->fontwidth);
526 1.1 macallan
527 1.1 macallan ri->ri_hw = scr;
528 1.1 macallan sc->putchar = ri->ri_ops.putchar;
529 1.1 macallan sc->copyrows = ri->ri_ops.copyrows;
530 1.1 macallan sc->eraserows = ri->ri_ops.eraserows;
531 1.1 macallan sc->copycols = ri->ri_ops.copycols;
532 1.1 macallan sc->erasecols = ri->ri_ops.erasecols;
533 1.1 macallan
534 1.12 macallan if (sc->sc_is_jfb) {
535 1.12 macallan ri->ri_ops.copyrows = wcfb_acc_copyrows;
536 1.12 macallan ri->ri_ops.copycols = wcfb_acc_copycols;
537 1.12 macallan ri->ri_ops.eraserows = wcfb_acc_eraserows;
538 1.12 macallan ri->ri_ops.erasecols = wcfb_acc_erasecols;
539 1.12 macallan ri->ri_ops.putchar = wcfb_acc_putchar;
540 1.12 macallan ri->ri_ops.cursor = wcfb_acc_cursor;
541 1.12 macallan } else {
542 1.12 macallan ri->ri_ops.copyrows = wcfb_copyrows;
543 1.12 macallan ri->ri_ops.copycols = wcfb_copycols;
544 1.12 macallan ri->ri_ops.eraserows = wcfb_eraserows;
545 1.12 macallan ri->ri_ops.erasecols = wcfb_erasecols;
546 1.12 macallan ri->ri_ops.putchar = wcfb_putchar;
547 1.12 macallan ri->ri_ops.cursor = wcfb_cursor;
548 1.12 macallan }
549 1.1 macallan }
550 1.1 macallan
551 1.1 macallan static void
552 1.1 macallan wcfb_putchar(void *cookie, int row, int col, u_int c, long attr)
553 1.1 macallan {
554 1.1 macallan struct rasops_info *ri = cookie;
555 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
556 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
557 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
558 1.3 macallan sc->sc_stride + ri->ri_xorigin + col * ri->ri_font->fontwidth;
559 1.3 macallan uint8_t *from, *to0, *to1;
560 1.3 macallan int i;
561 1.1 macallan
562 1.1 macallan sc->putchar(ri, row, col, c, attr);
563 1.3 macallan from = sc->sc_shadow + offset;
564 1.3 macallan to0 = sc->sc_fb0 + offset;
565 1.3 macallan to1 = sc->sc_fb1 + offset;
566 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
567 1.3 macallan memcpy(to0, from, ri->ri_font->fontwidth);
568 1.3 macallan memcpy(to1, from, ri->ri_font->fontwidth);
569 1.3 macallan to0 += sc->sc_stride;
570 1.3 macallan to1 += sc->sc_stride;
571 1.3 macallan from += sc->sc_stride;
572 1.3 macallan }
573 1.14 msaitoh }
574 1.1 macallan
575 1.1 macallan static void
576 1.1 macallan wcfb_putpalreg(struct wcfb_softc *sc, int i, int r, int g, int b)
577 1.1 macallan {
578 1.1 macallan uint32_t rgb;
579 1.1 macallan
580 1.6 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_INDEX, i);
581 1.1 macallan rgb = (b << 22) | (g << 12) | (r << 2);
582 1.6 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, WC_CMAP_DATA, rgb);
583 1.1 macallan }
584 1.1 macallan
585 1.1 macallan static void
586 1.1 macallan wcfb_cursor(void *cookie, int on, int row, int col)
587 1.1 macallan {
588 1.1 macallan struct rasops_info *ri = cookie;
589 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
590 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
591 1.4 macallan int coffset;
592 1.14 msaitoh
593 1.4 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
594 1.4 macallan
595 1.4 macallan if (ri->ri_flg & RI_CURSOR) {
596 1.4 macallan /* remove cursor */
597 1.4 macallan coffset = ri->ri_ccol + (ri->ri_crow * ri->ri_cols);
598 1.4 macallan #ifdef WSDISPLAY_SCROLLSUPPORT
599 1.4 macallan coffset += scr->scr_offset_to_zero;
600 1.4 macallan #endif
601 1.14 msaitoh wcfb_putchar(cookie, ri->ri_crow,
602 1.14 msaitoh ri->ri_ccol, scr->scr_chars[coffset],
603 1.4 macallan scr->scr_attrs[coffset]);
604 1.4 macallan ri->ri_flg &= ~RI_CURSOR;
605 1.4 macallan }
606 1.4 macallan ri->ri_crow = row;
607 1.4 macallan ri->ri_ccol = col;
608 1.4 macallan if (on) {
609 1.4 macallan long attr, revattr;
610 1.4 macallan coffset = col + (row * ri->ri_cols);
611 1.4 macallan #ifdef WSDISPLAY_SCROLLSUPPORT
612 1.4 macallan coffset += scr->scr_offset_to_zero;
613 1.1 macallan #endif
614 1.4 macallan attr = scr->scr_attrs[coffset];
615 1.4 macallan revattr = attr ^ 0xffff0000;
616 1.4 macallan
617 1.4 macallan wcfb_putchar(cookie, ri->ri_crow, ri->ri_ccol,
618 1.4 macallan scr->scr_chars[coffset], revattr);
619 1.4 macallan ri->ri_flg |= RI_CURSOR;
620 1.4 macallan }
621 1.4 macallan } else {
622 1.4 macallan ri->ri_crow = row;
623 1.4 macallan ri->ri_ccol = col;
624 1.4 macallan ri->ri_flg &= ~RI_CURSOR;
625 1.4 macallan }
626 1.1 macallan }
627 1.1 macallan
628 1.1 macallan static void
629 1.1 macallan wcfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
630 1.1 macallan {
631 1.1 macallan struct rasops_info *ri = cookie;
632 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
633 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
634 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
635 1.3 macallan sc->sc_stride + ri->ri_xorigin + dstcol * ri->ri_font->fontwidth;
636 1.3 macallan uint8_t *from, *to0, *to1;
637 1.3 macallan int i;
638 1.1 macallan
639 1.1 macallan sc->copycols(ri, row, srccol, dstcol, ncols);
640 1.3 macallan from = sc->sc_shadow + offset;
641 1.3 macallan to0 = sc->sc_fb0 + offset;
642 1.3 macallan to1 = sc->sc_fb1 + offset;
643 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
644 1.3 macallan memcpy(to0, from, ri->ri_font->fontwidth * ncols);
645 1.3 macallan memcpy(to1, from, ri->ri_font->fontwidth * ncols);
646 1.3 macallan to0 += sc->sc_stride;
647 1.3 macallan to1 += sc->sc_stride;
648 1.3 macallan from += sc->sc_stride;
649 1.3 macallan }
650 1.1 macallan }
651 1.1 macallan
652 1.1 macallan static void
653 1.3 macallan wcfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
654 1.1 macallan {
655 1.1 macallan struct rasops_info *ri = cookie;
656 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
657 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
658 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
659 1.3 macallan sc->sc_stride + ri->ri_xorigin + startcol * ri->ri_font->fontwidth;
660 1.3 macallan uint8_t *to0, *to1;
661 1.3 macallan int i;
662 1.3 macallan
663 1.3 macallan sc->erasecols(ri, row, startcol, ncols, fillattr);
664 1.3 macallan
665 1.3 macallan to0 = sc->sc_fb0 + offset;
666 1.3 macallan to1 = sc->sc_fb1 + offset;
667 1.3 macallan for (i = 0; i < ri->ri_font->fontheight; i++) {
668 1.3 macallan memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
669 1.3 macallan ri->ri_font->fontwidth * ncols);
670 1.3 macallan memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
671 1.3 macallan ri->ri_font->fontwidth * ncols);
672 1.3 macallan to0 += sc->sc_stride;
673 1.3 macallan to1 += sc->sc_stride;
674 1.3 macallan }
675 1.1 macallan }
676 1.1 macallan
677 1.1 macallan static void
678 1.3 macallan wcfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
679 1.1 macallan {
680 1.1 macallan struct rasops_info *ri = cookie;
681 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
682 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
683 1.3 macallan int offset = (ri->ri_yorigin + dstrow * ri->ri_font->fontheight) *
684 1.3 macallan sc->sc_stride + ri->ri_xorigin;
685 1.3 macallan uint8_t *from, *to0, *to1;
686 1.3 macallan int i;
687 1.3 macallan
688 1.3 macallan sc->copyrows(ri, srcrow, dstrow, nrows);
689 1.3 macallan
690 1.3 macallan from = sc->sc_shadow + offset;
691 1.3 macallan to0 = sc->sc_fb0 + offset;
692 1.3 macallan to1 = sc->sc_fb1 + offset;
693 1.3 macallan for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
694 1.3 macallan memcpy(to0, from, ri->ri_emuwidth);
695 1.3 macallan memcpy(to1, from, ri->ri_emuwidth);
696 1.3 macallan to0 += sc->sc_stride;
697 1.3 macallan to1 += sc->sc_stride;
698 1.3 macallan from += sc->sc_stride;
699 1.3 macallan }
700 1.1 macallan }
701 1.1 macallan
702 1.1 macallan static void
703 1.1 macallan wcfb_eraserows(void *cookie, int row, int nrows, long fillattr)
704 1.1 macallan {
705 1.1 macallan struct rasops_info *ri = cookie;
706 1.1 macallan struct vcons_screen *scr = ri->ri_hw;
707 1.1 macallan struct wcfb_softc *sc = scr->scr_cookie;
708 1.3 macallan int offset = (ri->ri_yorigin + row * ri->ri_font->fontheight) *
709 1.3 macallan sc->sc_stride + ri->ri_xorigin;
710 1.3 macallan uint8_t *to0, *to1;
711 1.3 macallan int i;
712 1.1 macallan
713 1.1 macallan sc->eraserows(ri, row, nrows, fillattr);
714 1.3 macallan
715 1.3 macallan to0 = sc->sc_fb0 + offset;
716 1.3 macallan to1 = sc->sc_fb1 + offset;
717 1.3 macallan for (i = 0; i < ri->ri_font->fontheight * nrows; i++) {
718 1.3 macallan memset(to0, ri->ri_devcmap[(fillattr >> 16) & 0xff],
719 1.3 macallan ri->ri_emuwidth);
720 1.3 macallan memset(to1, ri->ri_devcmap[(fillattr >> 16) & 0xff],
721 1.3 macallan ri->ri_emuwidth);
722 1.3 macallan to0 += sc->sc_stride;
723 1.3 macallan to1 += sc->sc_stride;
724 1.3 macallan }
725 1.1 macallan }
726 1.12 macallan
727 1.12 macallan static void
728 1.12 macallan wcfb_bitblt(struct wcfb_softc *sc, int sx, int sy, int dx, int dy, int w,
729 1.12 macallan int h, uint32_t rop)
730 1.12 macallan {
731 1.12 macallan wcfb_rop_wait(sc);
732 1.14.2.1 pgoyette wcfb_rop_jfb(sc, sx, sy, dx, dy, w, h, rop, 0x0f);
733 1.12 macallan }
734 1.12 macallan
735 1.12 macallan static void
736 1.12 macallan wcfb_rectfill(struct wcfb_softc *sc, int x, int y, int w, int h, int bg)
737 1.12 macallan {
738 1.12 macallan int32_t mask;
739 1.12 macallan
740 1.14.2.1 pgoyette /* clear everything just in case... */
741 1.14.2.1 pgoyette wcfb_rop_wait(sc);
742 1.14.2.1 pgoyette wcfb_rop_jfb(sc, x, y, x, y, w, h, WC_ROP_CLEAR, 0xffffffff);
743 1.14.2.1 pgoyette
744 1.12 macallan /* pixels to set... */
745 1.14.2.1 pgoyette mask = 0x0f & bg;
746 1.12 macallan if (mask != 0) {
747 1.12 macallan wcfb_rop_wait(sc);
748 1.12 macallan wcfb_rop_jfb(sc, x, y, x, y, w, h, WC_ROP_SET, mask);
749 1.12 macallan }
750 1.12 macallan
751 1.12 macallan }
752 1.12 macallan
753 1.12 macallan void
754 1.12 macallan wcfb_rop_common(struct wcfb_softc *sc, bus_addr_t reg, int sx, int sy,
755 1.12 macallan int dx, int dy, int w, int h, uint32_t rop, int32_t planemask)
756 1.12 macallan {
757 1.12 macallan int dir = 0;
758 1.12 macallan
759 1.12 macallan /*
760 1.12 macallan * Compute rop direction. This only really matters for
761 1.12 macallan * screen-to-screen copies.
762 1.12 macallan */
763 1.12 macallan if (sy < dy /* && sy + h > dy */) {
764 1.12 macallan sy += h - 1;
765 1.12 macallan dy += h;
766 1.12 macallan dir |= WC_BLT_DIR_BACKWARDS_Y;
767 1.12 macallan }
768 1.12 macallan if (sx < dx /* && sx + w > dx */) {
769 1.12 macallan sx += w - 1;
770 1.12 macallan dx += w;
771 1.12 macallan dir |= WC_BLT_DIR_BACKWARDS_X;
772 1.12 macallan }
773 1.12 macallan
774 1.12 macallan /* Which one of those below is your magic number for today? */
775 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x61000001);
776 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
777 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x6301c080);
778 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x80000000);
779 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, rop);
780 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, planemask);
781 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
782 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x64000303);
783 1.12 macallan /*
784 1.12 macallan * This value is a pixel offset within the destination area. It is
785 1.12 macallan * probably used to define complex polygon shapes, with the
786 1.12 macallan * last pixel in the list being back to (0,0).
787 1.12 macallan */
788 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(0, 0));
789 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0);
790 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x00030000);
791 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x2200010d);
792 1.12 macallan
793 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x33f01000 | dir);
794 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(dx, dy));
795 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(w, h));
796 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, WCFB_COORDS(sx, sy));
797 1.12 macallan }
798 1.12 macallan
799 1.12 macallan
800 1.12 macallan static void
801 1.12 macallan wcfb_rop_jfb(struct wcfb_softc *sc, int sx, int sy, int dx, int dy,
802 1.12 macallan int w, int h, uint32_t rop, int32_t planemask)
803 1.12 macallan {
804 1.12 macallan bus_addr_t reg = WC_JFB_ENGINE;
805 1.12 macallan uint32_t spr, splr;
806 1.12 macallan
807 1.12 macallan #if 0
808 1.12 macallan /*
809 1.12 macallan * Pick the current spr and splr values from the communication
810 1.12 macallan * area if possible.
811 1.12 macallan */
812 1.12 macallan if (sc->sc_comm != NULL) {
813 1.12 macallan spr = sc->sc_comm[IFB_SHARED_TERM8_SPR >> 2];
814 1.12 macallan splr = sc->sc_comm[IFB_SHARED_TERM8_SPLR >> 2];
815 1.14 msaitoh } else
816 1.12 macallan #endif
817 1.12 macallan {
818 1.12 macallan /* supposedly sane defaults */
819 1.12 macallan spr = 0x54ff0303;
820 1.12 macallan splr = 0x5c0000ff;
821 1.12 macallan }
822 1.12 macallan
823 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x00400016);
824 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5b000002);
825 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5a000000);
826 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, spr);
827 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, splr);
828 1.12 macallan
829 1.12 macallan wcfb_rop_common(sc, reg, sx, sy, dx, dy, w, h, rop, planemask);
830 1.12 macallan
831 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5a000001);
832 1.12 macallan bus_space_write_4(sc->sc_regt, sc->sc_regh, reg, 0x5b000001);
833 1.12 macallan }
834 1.12 macallan
835 1.12 macallan static int
836 1.12 macallan wcfb_rop_wait(struct wcfb_softc *sc)
837 1.12 macallan {
838 1.12 macallan int i;
839 1.12 macallan
840 1.12 macallan for (i = 1000000; i != 0; i--) {
841 1.12 macallan if (bus_space_read_4(sc->sc_regt, sc->sc_regh,
842 1.12 macallan WC_STATUS) & WC_STATUS_DONE)
843 1.12 macallan break;
844 1.12 macallan delay(1);
845 1.12 macallan }
846 1.12 macallan
847 1.12 macallan return i;
848 1.12 macallan }
849 1.12 macallan
850 1.12 macallan static void
851 1.12 macallan wcfb_acc_putchar(void *cookie, int row, int col, u_int c, long attr)
852 1.12 macallan {
853 1.12 macallan struct rasops_info *ri = cookie;
854 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
855 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
856 1.12 macallan struct wsdisplay_font *font = PICK_FONT(ri, c);
857 1.12 macallan int x, y, wi, he;
858 1.12 macallan uint32_t bg;
859 1.12 macallan
860 1.12 macallan wi = font->fontwidth;
861 1.12 macallan he = font->fontheight;
862 1.12 macallan x = ri->ri_xorigin + col * wi;
863 1.12 macallan y = ri->ri_yorigin + row * he;
864 1.12 macallan bg = ri->ri_devcmap[(attr >> 16) & 0xf];
865 1.12 macallan if (c == 0x20) {
866 1.12 macallan wcfb_rectfill(sc, x, y, wi, he, bg);
867 1.12 macallan return;
868 1.12 macallan }
869 1.12 macallan /* we wait until the blitter is idle... */
870 1.12 macallan wcfb_rop_wait(sc);
871 1.12 macallan /* ... draw the character into buffer 0 ... */
872 1.12 macallan sc->putchar(ri, row, col, c, attr);
873 1.12 macallan /* ... and then blit it into buffer 1 */
874 1.12 macallan wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_COPY);
875 1.14 msaitoh }
876 1.12 macallan
877 1.12 macallan static void
878 1.12 macallan wcfb_acc_cursor(void *cookie, int on, int row, int col)
879 1.12 macallan {
880 1.12 macallan struct rasops_info *ri = cookie;
881 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
882 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
883 1.12 macallan int x, y, wi, he;
884 1.14 msaitoh
885 1.12 macallan wi = ri->ri_font->fontwidth;
886 1.12 macallan he = ri->ri_font->fontheight;
887 1.14 msaitoh
888 1.12 macallan if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
889 1.12 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
890 1.12 macallan y = ri->ri_crow * he + ri->ri_yorigin;
891 1.12 macallan if (ri->ri_flg & RI_CURSOR) {
892 1.12 macallan wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_XOR);
893 1.12 macallan ri->ri_flg &= ~RI_CURSOR;
894 1.12 macallan }
895 1.12 macallan ri->ri_crow = row;
896 1.12 macallan ri->ri_ccol = col;
897 1.12 macallan if (on) {
898 1.12 macallan x = ri->ri_ccol * wi + ri->ri_xorigin;
899 1.12 macallan y = ri->ri_crow * he + ri->ri_yorigin;
900 1.12 macallan wcfb_bitblt(sc, x, y, x, y, wi, he, WC_ROP_XOR);
901 1.12 macallan ri->ri_flg |= RI_CURSOR;
902 1.12 macallan }
903 1.12 macallan } else {
904 1.12 macallan scr->scr_ri.ri_crow = row;
905 1.12 macallan scr->scr_ri.ri_ccol = col;
906 1.12 macallan scr->scr_ri.ri_flg &= ~RI_CURSOR;
907 1.12 macallan }
908 1.12 macallan
909 1.12 macallan }
910 1.12 macallan
911 1.12 macallan static void
912 1.12 macallan wcfb_acc_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
913 1.12 macallan {
914 1.12 macallan struct rasops_info *ri = cookie;
915 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
916 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
917 1.12 macallan int32_t xs, xd, y, width, height;
918 1.14 msaitoh
919 1.12 macallan if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
920 1.12 macallan xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
921 1.12 macallan xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
922 1.12 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
923 1.12 macallan width = ri->ri_font->fontwidth * ncols;
924 1.12 macallan height = ri->ri_font->fontheight;
925 1.12 macallan wcfb_bitblt(sc, xs, y, xd, y, width, height, WC_ROP_COPY);
926 1.12 macallan }
927 1.12 macallan }
928 1.12 macallan
929 1.12 macallan static void
930 1.12 macallan wcfb_acc_erasecols(void *cookie, int row, int startcol, int ncols,
931 1.12 macallan long fillattr)
932 1.12 macallan {
933 1.12 macallan struct rasops_info *ri = cookie;
934 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
935 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
936 1.12 macallan int32_t x, y, width, height, fg, bg, ul;
937 1.14 msaitoh
938 1.12 macallan if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
939 1.12 macallan x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
940 1.12 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
941 1.12 macallan width = ri->ri_font->fontwidth * ncols;
942 1.12 macallan height = ri->ri_font->fontheight;
943 1.12 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
944 1.12 macallan
945 1.12 macallan wcfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
946 1.12 macallan }
947 1.12 macallan }
948 1.12 macallan
949 1.12 macallan static void
950 1.12 macallan wcfb_acc_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
951 1.12 macallan {
952 1.12 macallan struct rasops_info *ri = cookie;
953 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
954 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
955 1.12 macallan int32_t x, ys, yd, width, height;
956 1.12 macallan
957 1.12 macallan if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
958 1.12 macallan x = ri->ri_xorigin;
959 1.12 macallan ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
960 1.12 macallan yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
961 1.12 macallan width = ri->ri_emuwidth;
962 1.12 macallan height = ri->ri_font->fontheight * nrows;
963 1.12 macallan wcfb_bitblt(sc, x, ys, x, yd, width, height, WC_ROP_COPY);
964 1.12 macallan }
965 1.12 macallan }
966 1.12 macallan
967 1.12 macallan static void
968 1.12 macallan wcfb_acc_eraserows(void *cookie, int row, int nrows, long fillattr)
969 1.12 macallan {
970 1.12 macallan struct rasops_info *ri = cookie;
971 1.12 macallan struct vcons_screen *scr = ri->ri_hw;
972 1.12 macallan struct wcfb_softc *sc = scr->scr_cookie;
973 1.12 macallan int32_t x, y, width, height, fg, bg, ul;
974 1.14 msaitoh
975 1.12 macallan if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) {
976 1.12 macallan x = ri->ri_xorigin;
977 1.12 macallan y = ri->ri_yorigin + ri->ri_font->fontheight * row;
978 1.12 macallan width = ri->ri_emuwidth;
979 1.12 macallan height = ri->ri_font->fontheight * nrows;
980 1.12 macallan rasops_unpack_attr(fillattr, &fg, &bg, &ul);
981 1.12 macallan
982 1.12 macallan wcfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]);
983 1.12 macallan }
984 1.12 macallan }
985