ffb.c revision 1.12 1 1.12 mhitch /* $NetBSD: ffb.c,v 1.12 2005/05/13 06:33:32 mhitch Exp $ */
2 1.1 petrov /* $OpenBSD: creator.c,v 1.20 2002/07/30 19:48:15 jason Exp $ */
3 1.1 petrov
4 1.1 petrov /*
5 1.1 petrov * Copyright (c) 2002 Jason L. Wright (jason (at) thought.net)
6 1.1 petrov * All rights reserved.
7 1.1 petrov *
8 1.1 petrov * Redistribution and use in source and binary forms, with or without
9 1.1 petrov * modification, are permitted provided that the following conditions
10 1.1 petrov * are met:
11 1.1 petrov * 1. Redistributions of source code must retain the above copyright
12 1.1 petrov * notice, this list of conditions and the following disclaimer.
13 1.1 petrov * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 petrov * notice, this list of conditions and the following disclaimer in the
15 1.1 petrov * documentation and/or other materials provided with the distribution.
16 1.1 petrov * 3. All advertising materials mentioning features or use of this software
17 1.1 petrov * must display the following acknowledgement:
18 1.1 petrov * This product includes software developed by Jason L. Wright
19 1.1 petrov * 4. The name of the author may not be used to endorse or promote products
20 1.1 petrov * derived from this software without specific prior written permission.
21 1.1 petrov *
22 1.1 petrov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 petrov * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 1.1 petrov * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 1.1 petrov * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 1.1 petrov * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 1.1 petrov * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1 petrov * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 petrov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 1.1 petrov * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 1.1 petrov * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 petrov * POSSIBILITY OF SUCH DAMAGE.
33 1.1 petrov */
34 1.3 lukem
35 1.3 lukem #include <sys/cdefs.h>
36 1.12 mhitch __KERNEL_RCSID(0, "$NetBSD: ffb.c,v 1.12 2005/05/13 06:33:32 mhitch Exp $");
37 1.1 petrov
38 1.1 petrov #include <sys/types.h>
39 1.1 petrov #include <sys/param.h>
40 1.1 petrov #include <sys/systm.h>
41 1.1 petrov #include <sys/kernel.h>
42 1.1 petrov #include <sys/device.h>
43 1.1 petrov #include <sys/conf.h>
44 1.1 petrov
45 1.1 petrov #include <machine/bus.h>
46 1.1 petrov #include <machine/autoconf.h>
47 1.1 petrov #include <machine/openfirm.h>
48 1.11 martin #include <machine/vmparam.h>
49 1.1 petrov
50 1.1 petrov #include <dev/wscons/wsconsio.h>
51 1.11 martin #include <dev/sun/fbio.h>
52 1.11 martin #include <dev/sun/fbvar.h>
53 1.1 petrov
54 1.1 petrov #include <sparc64/dev/ffbreg.h>
55 1.1 petrov #include <sparc64/dev/ffbvar.h>
56 1.1 petrov
57 1.11 martin extern struct cfdriver ffb_cd;
58 1.11 martin
59 1.1 petrov struct wsscreen_descr ffb_stdscreen = {
60 1.6 heas "sunffb",
61 1.1 petrov 0, 0, /* will be filled in -- XXX shouldn't, it's global. */
62 1.1 petrov 0,
63 1.1 petrov 0, 0,
64 1.1 petrov WSSCREEN_REVERSE | WSSCREEN_WSCOLORS
65 1.1 petrov };
66 1.1 petrov
67 1.1 petrov const struct wsscreen_descr *ffb_scrlist[] = {
68 1.1 petrov &ffb_stdscreen,
69 1.1 petrov /* XXX other formats? */
70 1.1 petrov };
71 1.1 petrov
72 1.1 petrov struct wsscreen_list ffb_screenlist = {
73 1.1 petrov sizeof(ffb_scrlist) / sizeof(struct wsscreen_descr *),
74 1.1 petrov ffb_scrlist
75 1.1 petrov };
76 1.1 petrov
77 1.1 petrov int ffb_ioctl(void *, u_long, caddr_t, int, struct proc *);
78 1.1 petrov int ffb_alloc_screen(void *, const struct wsscreen_descr *, void **,
79 1.1 petrov int *, int *, long *);
80 1.7 heas static int ffb_blank(struct ffb_softc *, u_long, u_int *);
81 1.1 petrov void ffb_free_screen(void *, void *);
82 1.1 petrov int ffb_show_screen(void *, void *, int, void (*cb)(void *, int, int),
83 1.1 petrov void *);
84 1.1 petrov paddr_t ffb_mmap(void *, off_t, int);
85 1.1 petrov void ffb_ras_fifo_wait(struct ffb_softc *, int);
86 1.1 petrov void ffb_ras_wait(struct ffb_softc *);
87 1.1 petrov void ffb_ras_init(struct ffb_softc *);
88 1.1 petrov void ffb_ras_copyrows(void *, int, int, int);
89 1.1 petrov void ffb_ras_erasecols(void *, int, int, int, long int);
90 1.1 petrov void ffb_ras_eraserows(void *, int, int, long int);
91 1.1 petrov void ffb_ras_do_cursor(struct rasops_info *);
92 1.1 petrov void ffb_ras_fill(struct ffb_softc *);
93 1.1 petrov void ffb_ras_setfg(struct ffb_softc *, int32_t);
94 1.1 petrov
95 1.11 martin /* frame buffer generic driver */
96 1.11 martin static void ffbfb_unblank(struct device*);
97 1.11 martin dev_type_open(ffbfb_open);
98 1.11 martin dev_type_close(ffbfb_close);
99 1.11 martin dev_type_ioctl(ffbfb_ioctl);
100 1.11 martin dev_type_mmap(ffbfb_mmap);
101 1.11 martin static struct fbdriver ffb_fbdriver = {
102 1.11 martin ffbfb_unblank, ffbfb_open, ffbfb_close, ffbfb_ioctl, nopoll,
103 1.11 martin ffbfb_mmap, nokqfilter
104 1.11 martin };
105 1.11 martin
106 1.1 petrov struct wsdisplay_accessops ffb_accessops = {
107 1.1 petrov ffb_ioctl,
108 1.1 petrov ffb_mmap,
109 1.1 petrov ffb_alloc_screen,
110 1.1 petrov ffb_free_screen,
111 1.1 petrov ffb_show_screen,
112 1.1 petrov NULL, /* load font */
113 1.8 heas NULL, /* pollc */
114 1.8 heas NULL, /* getwschar */
115 1.8 heas NULL, /* putwschar */
116 1.8 heas NULL, /* scroll */
117 1.1 petrov };
118 1.1 petrov
119 1.1 petrov void
120 1.1 petrov ffb_attach(struct ffb_softc *sc)
121 1.1 petrov {
122 1.1 petrov struct wsemuldisplaydev_attach_args waa;
123 1.1 petrov char *model;
124 1.1 petrov int btype;
125 1.4 pk int maxrow, maxcol;
126 1.7 heas u_int blank = WSDISPLAYIO_VIDEO_ON;
127 1.4 pk char buf[6+1];
128 1.1 petrov
129 1.1 petrov printf(":");
130 1.1 petrov
131 1.1 petrov if (sc->sc_type == FFB_CREATOR) {
132 1.5 pk btype = prom_getpropint(sc->sc_node, "board_type", 0);
133 1.1 petrov if ((btype & 7) == 3)
134 1.1 petrov printf(" Creator3D");
135 1.1 petrov else
136 1.1 petrov printf(" Creator");
137 1.1 petrov } else
138 1.1 petrov printf(" Elite3D");
139 1.1 petrov
140 1.5 pk model = prom_getpropstring(sc->sc_node, "model");
141 1.1 petrov if (model == NULL || strlen(model) == 0)
142 1.1 petrov model = "unknown";
143 1.1 petrov
144 1.1 petrov sc->sc_depth = 24;
145 1.1 petrov sc->sc_linebytes = 8192;
146 1.5 pk sc->sc_height = prom_getpropint(sc->sc_node, "height", 0);
147 1.5 pk sc->sc_width = prom_getpropint(sc->sc_node, "width", 0);
148 1.1 petrov
149 1.11 martin sc->sc_fb.fb_rinfo.ri_depth = 32;
150 1.11 martin sc->sc_fb.fb_rinfo.ri_stride = sc->sc_linebytes;
151 1.11 martin sc->sc_fb.fb_rinfo.ri_flg = RI_CENTER;
152 1.11 martin sc->sc_fb.fb_rinfo.ri_bits = (void *)bus_space_vaddr(sc->sc_bt,
153 1.1 petrov sc->sc_pixel_h);
154 1.1 petrov
155 1.11 martin sc->sc_fb.fb_rinfo.ri_width = sc->sc_width;
156 1.11 martin sc->sc_fb.fb_rinfo.ri_height = sc->sc_height;
157 1.11 martin sc->sc_fb.fb_rinfo.ri_hw = sc;
158 1.1 petrov
159 1.4 pk maxcol = (prom_getoption("screen-#columns", buf, sizeof buf) == 0)
160 1.4 pk ? strtoul(buf, NULL, 10)
161 1.4 pk : 80;
162 1.4 pk
163 1.4 pk maxrow = (prom_getoption("screen-#rows", buf, sizeof buf) != 0)
164 1.4 pk ? strtoul(buf, NULL, 10)
165 1.4 pk : 34;
166 1.4 pk
167 1.11 martin rasops_init(&sc->sc_fb.fb_rinfo, maxrow, maxcol);
168 1.1 petrov
169 1.1 petrov if ((sc->sc_dv.dv_cfdata->cf_flags & FFB_CFFLAG_NOACCEL) == 0) {
170 1.11 martin sc->sc_fb.fb_rinfo.ri_hw = sc;
171 1.11 martin sc->sc_fb.fb_rinfo.ri_ops.eraserows = ffb_ras_eraserows;
172 1.11 martin sc->sc_fb.fb_rinfo.ri_ops.erasecols = ffb_ras_erasecols;
173 1.11 martin sc->sc_fb.fb_rinfo.ri_ops.copyrows = ffb_ras_copyrows;
174 1.1 petrov ffb_ras_init(sc);
175 1.1 petrov }
176 1.1 petrov
177 1.11 martin ffb_stdscreen.nrows = sc->sc_fb.fb_rinfo.ri_rows;
178 1.11 martin ffb_stdscreen.ncols = sc->sc_fb.fb_rinfo.ri_cols;
179 1.11 martin ffb_stdscreen.textops = &sc->sc_fb.fb_rinfo.ri_ops;
180 1.1 petrov
181 1.8 heas /* collect DAC version, as Elite3D cursor enable bit is reversed */
182 1.8 heas DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GVERS);
183 1.8 heas sc->sc_dacrev = DAC_READ(sc, FFB_DAC_VALUE) >> 28;
184 1.8 heas
185 1.8 heas if (sc->sc_type == FFB_AFB)
186 1.8 heas sc->sc_dacrev = 10;
187 1.8 heas printf(", model %s, dac %u\n", model, sc->sc_dacrev);
188 1.8 heas
189 1.7 heas ffb_blank(sc, WSDISPLAYIO_SVIDEO, &blank);
190 1.7 heas
191 1.11 martin sc->sc_fb.fb_driver = &ffb_fbdriver;
192 1.11 martin sc->sc_fb.fb_type.fb_cmsize = 0;
193 1.11 martin sc->sc_fb.fb_type.fb_size = maxrow * sc->sc_linebytes;
194 1.11 martin sc->sc_fb.fb_type.fb_type = FBTYPE_CREATOR;
195 1.12 mhitch sc->sc_fb.fb_type.fb_width = sc->sc_width;
196 1.12 mhitch sc->sc_fb.fb_type.fb_depth = sc->sc_depth;
197 1.12 mhitch sc->sc_fb.fb_type.fb_height = sc->sc_height;
198 1.11 martin sc->sc_fb.fb_device = &sc->sc_dv;
199 1.11 martin fb_attach(&sc->sc_fb, sc->sc_console);
200 1.11 martin
201 1.1 petrov if (sc->sc_console) {
202 1.1 petrov int *ccolp, *crowp;
203 1.1 petrov long defattr;
204 1.1 petrov
205 1.1 petrov if (romgetcursoraddr(&crowp, &ccolp))
206 1.1 petrov ccolp = crowp = NULL;
207 1.1 petrov if (ccolp != NULL)
208 1.11 martin sc->sc_fb.fb_rinfo.ri_ccol = *ccolp;
209 1.1 petrov if (crowp != NULL)
210 1.11 martin sc->sc_fb.fb_rinfo.ri_crow = *crowp;
211 1.1 petrov
212 1.11 martin sc->sc_fb.fb_rinfo.ri_ops.allocattr(&sc->sc_fb.fb_rinfo,
213 1.1 petrov 0, 0, 0, &defattr);
214 1.1 petrov
215 1.11 martin wsdisplay_cnattach(&ffb_stdscreen, &sc->sc_fb.fb_rinfo,
216 1.11 martin sc->sc_fb.fb_rinfo.ri_ccol, sc->sc_fb.fb_rinfo.ri_crow, defattr);
217 1.1 petrov }
218 1.1 petrov
219 1.1 petrov waa.console = sc->sc_console;
220 1.1 petrov waa.scrdata = &ffb_screenlist;
221 1.1 petrov waa.accessops = &ffb_accessops;
222 1.1 petrov waa.accesscookie = sc;
223 1.1 petrov config_found(&sc->sc_dv, &waa, wsemuldisplaydevprint);
224 1.1 petrov }
225 1.1 petrov
226 1.1 petrov int
227 1.10 martin ffb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
228 1.1 petrov {
229 1.1 petrov struct ffb_softc *sc = v;
230 1.1 petrov struct wsdisplay_fbinfo *wdf;
231 1.1 petrov
232 1.2 petrov #ifdef FFBDEBUG
233 1.1 petrov printf("ffb_ioctl: %s cmd _IO%s%s('%c', %lu)\n",
234 1.1 petrov sc->sc_dv.dv_xname,
235 1.1 petrov (cmd & IOC_IN) ? "W" : "", (cmd & IOC_OUT) ? "R" : "",
236 1.1 petrov (char)IOCGROUP(cmd), cmd & 0xff);
237 1.2 petrov #endif
238 1.1 petrov
239 1.1 petrov switch (cmd) {
240 1.11 martin case FBIOGTYPE:
241 1.11 martin *(struct fbtype *)data = sc->sc_fb.fb_type;
242 1.11 martin break;
243 1.11 martin case FBIOGATTR:
244 1.11 martin #define fba ((struct fbgattr *)data)
245 1.11 martin fba->real_type = sc->sc_fb.fb_type.fb_type;
246 1.11 martin fba->owner = 0; /* XXX ??? */
247 1.11 martin fba->fbtype = sc->sc_fb.fb_type;
248 1.11 martin fba->sattr.flags = 0;
249 1.11 martin fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
250 1.11 martin fba->sattr.dev_specific[0] = -1;
251 1.11 martin fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
252 1.11 martin fba->emu_types[1] = -1;
253 1.11 martin #undef fba
254 1.11 martin break;
255 1.11 martin
256 1.11 martin case FBIOGETCMAP:
257 1.11 martin case FBIOPUTCMAP:
258 1.11 martin return EIO;
259 1.11 martin
260 1.11 martin case FBIOGVIDEO:
261 1.11 martin case FBIOSVIDEO:
262 1.11 martin return ffb_blank(sc, cmd == FBIOGVIDEO?
263 1.11 martin WSDISPLAYIO_GVIDEO : WSDISPLAYIO_SVIDEO,
264 1.11 martin (u_int *)data);
265 1.11 martin break;
266 1.11 martin case FBIOGCURSOR:
267 1.11 martin printf("%s: FBIOGCURSOR not implemented\n", sc->sc_dv.dv_xname);
268 1.11 martin return EIO;
269 1.11 martin case FBIOSCURSOR:
270 1.11 martin printf("%s: FBIOSCURSOR not implemented\n", sc->sc_dv.dv_xname);
271 1.11 martin return EIO;
272 1.11 martin case FBIOGCURPOS:
273 1.11 martin printf("%s: FBIOGCURPOS not implemented\n", sc->sc_dv.dv_xname);
274 1.11 martin return EIO;
275 1.11 martin case FBIOSCURPOS:
276 1.11 martin printf("%s: FBIOSCURPOS not implemented\n", sc->sc_dv.dv_xname);
277 1.11 martin return EIO;
278 1.11 martin case FBIOGCURMAX:
279 1.11 martin printf("%s: FBIOGCURMAX not implemented\n", sc->sc_dv.dv_xname);
280 1.11 martin return EIO;
281 1.11 martin
282 1.1 petrov case WSDISPLAYIO_GTYPE:
283 1.6 heas *(u_int *)data = WSDISPLAY_TYPE_SUNFFB;
284 1.1 petrov break;
285 1.1 petrov case WSDISPLAYIO_SMODE:
286 1.1 petrov sc->sc_mode = *(u_int *)data;
287 1.1 petrov break;
288 1.1 petrov case WSDISPLAYIO_GINFO:
289 1.1 petrov wdf = (void *)data;
290 1.1 petrov wdf->height = sc->sc_height;
291 1.1 petrov wdf->width = sc->sc_width;
292 1.1 petrov wdf->depth = 32;
293 1.1 petrov wdf->cmsize = 256; /* XXX */
294 1.1 petrov break;
295 1.1 petrov #ifdef WSDISPLAYIO_LINEBYTES
296 1.1 petrov case WSDISPLAYIO_LINEBYTES:
297 1.1 petrov *(u_int *)data = sc->sc_linebytes;
298 1.1 petrov break;
299 1.1 petrov #endif
300 1.1 petrov case WSDISPLAYIO_GETCMAP:
301 1.1 petrov break;/* XXX */
302 1.1 petrov
303 1.1 petrov case WSDISPLAYIO_PUTCMAP:
304 1.1 petrov break;/* XXX */
305 1.1 petrov
306 1.1 petrov case WSDISPLAYIO_SVIDEO:
307 1.1 petrov case WSDISPLAYIO_GVIDEO:
308 1.7 heas return(ffb_blank(sc, cmd, (u_int *)data));
309 1.7 heas break;
310 1.1 petrov case WSDISPLAYIO_GCURPOS:
311 1.1 petrov case WSDISPLAYIO_SCURPOS:
312 1.1 petrov case WSDISPLAYIO_GCURMAX:
313 1.1 petrov case WSDISPLAYIO_GCURSOR:
314 1.1 petrov case WSDISPLAYIO_SCURSOR:
315 1.9 martin return EIO; /* not supported yet */
316 1.1 petrov default:
317 1.9 martin return EPASSTHROUGH;
318 1.1 petrov }
319 1.1 petrov
320 1.1 petrov return (0);
321 1.1 petrov }
322 1.1 petrov
323 1.1 petrov int
324 1.10 martin ffb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
325 1.10 martin int *curxp, int *curyp, long *attrp)
326 1.1 petrov {
327 1.1 petrov struct ffb_softc *sc = v;
328 1.1 petrov
329 1.1 petrov if (sc->sc_nscreens > 0)
330 1.1 petrov return (ENOMEM);
331 1.1 petrov
332 1.11 martin *cookiep = &sc->sc_fb.fb_rinfo;
333 1.1 petrov *curyp = 0;
334 1.1 petrov *curxp = 0;
335 1.1 petrov
336 1.11 martin sc->sc_fb.fb_rinfo.ri_ops.allocattr(&sc->sc_fb.fb_rinfo, 0, 0, 0, attrp);
337 1.1 petrov
338 1.1 petrov sc->sc_nscreens++;
339 1.1 petrov return (0);
340 1.1 petrov }
341 1.1 petrov
342 1.7 heas /* blank/unblank the screen */
343 1.7 heas static int
344 1.7 heas ffb_blank(struct ffb_softc *sc, u_long cmd, u_int *data)
345 1.7 heas {
346 1.7 heas u_int val;
347 1.7 heas
348 1.7 heas DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
349 1.7 heas val = DAC_READ(sc, FFB_DAC_VALUE);
350 1.7 heas
351 1.7 heas switch (cmd) {
352 1.7 heas case WSDISPLAYIO_GVIDEO:
353 1.7 heas *data = val & 1;
354 1.7 heas return(0);
355 1.7 heas break;
356 1.7 heas case WSDISPLAYIO_SVIDEO:
357 1.7 heas if (*data == WSDISPLAYIO_VIDEO_OFF)
358 1.7 heas val &= ~1;
359 1.7 heas else if (*data == WSDISPLAYIO_VIDEO_ON)
360 1.7 heas val |= 1;
361 1.7 heas else
362 1.7 heas return(EINVAL);
363 1.7 heas break;
364 1.7 heas default:
365 1.7 heas return(EINVAL);
366 1.7 heas }
367 1.7 heas
368 1.7 heas DAC_WRITE(sc, FFB_DAC_TYPE, FFB_DAC_GSBLANK);
369 1.7 heas DAC_WRITE(sc, FFB_DAC_VALUE, val);
370 1.7 heas
371 1.7 heas return(0);
372 1.7 heas }
373 1.7 heas
374 1.1 petrov void
375 1.10 martin ffb_free_screen(void *v, void *cookie)
376 1.1 petrov {
377 1.1 petrov struct ffb_softc *sc = v;
378 1.1 petrov
379 1.1 petrov sc->sc_nscreens--;
380 1.1 petrov }
381 1.1 petrov
382 1.1 petrov int
383 1.10 martin ffb_show_screen(void *v, void *cookie, int waitok,
384 1.10 martin void (*cb)(void *, int, int), void *cbarg)
385 1.1 petrov {
386 1.1 petrov return (0);
387 1.1 petrov }
388 1.1 petrov
389 1.1 petrov paddr_t
390 1.10 martin ffb_mmap(void *vsc, off_t off, int prot)
391 1.1 petrov {
392 1.1 petrov struct ffb_softc *sc = vsc;
393 1.1 petrov int i;
394 1.1 petrov
395 1.1 petrov switch (sc->sc_mode) {
396 1.1 petrov case WSDISPLAYIO_MODE_MAPPED:
397 1.1 petrov for (i = 0; i < sc->sc_nreg; i++) {
398 1.1 petrov /* Before this set? */
399 1.1 petrov if (off < sc->sc_addrs[i])
400 1.1 petrov continue;
401 1.1 petrov /* After this set? */
402 1.1 petrov if (off >= (sc->sc_addrs[i] + sc->sc_sizes[i]))
403 1.1 petrov continue;
404 1.1 petrov
405 1.1 petrov return (bus_space_mmap(sc->sc_bt, sc->sc_addrs[i],
406 1.1 petrov off - sc->sc_addrs[i], prot, BUS_SPACE_MAP_LINEAR));
407 1.1 petrov }
408 1.1 petrov break;
409 1.1 petrov #ifdef WSDISPLAYIO_MODE_DUMBFB
410 1.1 petrov case WSDISPLAYIO_MODE_DUMBFB:
411 1.1 petrov if (sc->sc_nreg < FFB_REG_DFB24)
412 1.1 petrov break;
413 1.1 petrov if (off >= 0 && off < sc->sc_sizes[FFB_REG_DFB24])
414 1.1 petrov return (bus_space_mmap(sc->sc_bt,
415 1.1 petrov sc->sc_addrs[FFB_REG_DFB24], off, prot,
416 1.1 petrov BUS_SPACE_MAP_LINEAR));
417 1.1 petrov break;
418 1.1 petrov #endif
419 1.1 petrov }
420 1.1 petrov
421 1.1 petrov return (-1);
422 1.1 petrov }
423 1.1 petrov
424 1.1 petrov void
425 1.10 martin ffb_ras_fifo_wait(struct ffb_softc *sc, int n)
426 1.1 petrov {
427 1.1 petrov int32_t cache = sc->sc_fifo_cache;
428 1.1 petrov
429 1.1 petrov if (cache < n) {
430 1.1 petrov do {
431 1.1 petrov cache = FBC_READ(sc, FFB_FBC_UCSR);
432 1.1 petrov cache = (cache & FBC_UCSR_FIFO_MASK) - 8;
433 1.1 petrov } while (cache < n);
434 1.1 petrov }
435 1.1 petrov sc->sc_fifo_cache = cache - n;
436 1.1 petrov }
437 1.1 petrov
438 1.1 petrov void
439 1.10 martin ffb_ras_wait(struct ffb_softc *sc)
440 1.1 petrov {
441 1.1 petrov u_int32_t ucsr, r;
442 1.1 petrov
443 1.1 petrov while (1) {
444 1.1 petrov ucsr = FBC_READ(sc, FFB_FBC_UCSR);
445 1.1 petrov if ((ucsr & (FBC_UCSR_FB_BUSY|FBC_UCSR_RP_BUSY)) == 0)
446 1.1 petrov break;
447 1.1 petrov r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
448 1.1 petrov if (r != 0)
449 1.1 petrov FBC_WRITE(sc, FFB_FBC_UCSR, r);
450 1.1 petrov }
451 1.1 petrov }
452 1.1 petrov
453 1.1 petrov void
454 1.10 martin ffb_ras_init(struct ffb_softc *sc)
455 1.1 petrov {
456 1.1 petrov ffb_ras_fifo_wait(sc, 7);
457 1.1 petrov FBC_WRITE(sc, FFB_FBC_PPC,
458 1.1 petrov FBC_PPC_VCE_DIS | FBC_PPC_TBE_OPAQUE |
459 1.1 petrov FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
460 1.1 petrov FBC_WRITE(sc, FFB_FBC_FBC,
461 1.1 petrov FFB_FBC_WB_A | FFB_FBC_RB_A | FFB_FBC_SB_BOTH |
462 1.1 petrov FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
463 1.1 petrov FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
464 1.1 petrov FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
465 1.1 petrov FBC_WRITE(sc, FFB_FBC_PMASK, 0xffffffff);
466 1.1 petrov FBC_WRITE(sc, FFB_FBC_FONTINC, 0x10000);
467 1.1 petrov sc->sc_fg_cache = 0;
468 1.1 petrov FBC_WRITE(sc, FFB_FBC_FG, sc->sc_fg_cache);
469 1.1 petrov ffb_ras_wait(sc);
470 1.1 petrov }
471 1.1 petrov
472 1.1 petrov void
473 1.10 martin ffb_ras_eraserows(void *cookie, int row, int n, long attr)
474 1.1 petrov {
475 1.1 petrov struct rasops_info *ri = cookie;
476 1.1 petrov struct ffb_softc *sc = ri->ri_hw;
477 1.1 petrov
478 1.1 petrov if (row < 0) {
479 1.1 petrov n += row;
480 1.1 petrov row = 0;
481 1.1 petrov }
482 1.1 petrov if (row + n > ri->ri_rows)
483 1.1 petrov n = ri->ri_rows - row;
484 1.1 petrov if (n <= 0)
485 1.1 petrov return;
486 1.1 petrov
487 1.1 petrov ffb_ras_fill(sc);
488 1.1 petrov ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
489 1.1 petrov ffb_ras_fifo_wait(sc, 4);
490 1.1 petrov if ((n == ri->ri_rows) && (ri->ri_flg & RI_FULLCLEAR)) {
491 1.1 petrov FBC_WRITE(sc, FFB_FBC_BY, 0);
492 1.1 petrov FBC_WRITE(sc, FFB_FBC_BX, 0);
493 1.1 petrov FBC_WRITE(sc, FFB_FBC_BH, ri->ri_height);
494 1.1 petrov FBC_WRITE(sc, FFB_FBC_BW, ri->ri_width);
495 1.1 petrov } else {
496 1.1 petrov row *= ri->ri_font->fontheight;
497 1.1 petrov FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
498 1.1 petrov FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
499 1.1 petrov FBC_WRITE(sc, FFB_FBC_BH, n * ri->ri_font->fontheight);
500 1.1 petrov FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
501 1.1 petrov }
502 1.1 petrov ffb_ras_wait(sc);
503 1.1 petrov }
504 1.1 petrov
505 1.1 petrov void
506 1.10 martin ffb_ras_erasecols(void *cookie, int row, int col, int n, long attr)
507 1.1 petrov {
508 1.1 petrov struct rasops_info *ri = cookie;
509 1.1 petrov struct ffb_softc *sc = ri->ri_hw;
510 1.1 petrov
511 1.1 petrov if ((row < 0) || (row >= ri->ri_rows))
512 1.1 petrov return;
513 1.1 petrov if (col < 0) {
514 1.1 petrov n += col;
515 1.1 petrov col = 0;
516 1.1 petrov }
517 1.1 petrov if (col + n > ri->ri_cols)
518 1.1 petrov n = ri->ri_cols - col;
519 1.1 petrov if (n <= 0)
520 1.1 petrov return;
521 1.1 petrov n *= ri->ri_font->fontwidth;
522 1.1 petrov col *= ri->ri_font->fontwidth;
523 1.1 petrov row *= ri->ri_font->fontheight;
524 1.1 petrov
525 1.1 petrov ffb_ras_fill(sc);
526 1.1 petrov ffb_ras_setfg(sc, ri->ri_devcmap[(attr >> 16) & 0xf]);
527 1.1 petrov ffb_ras_fifo_wait(sc, 4);
528 1.1 petrov FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + row);
529 1.1 petrov FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin + col);
530 1.1 petrov FBC_WRITE(sc, FFB_FBC_BH, ri->ri_font->fontheight);
531 1.1 petrov FBC_WRITE(sc, FFB_FBC_BW, n - 1);
532 1.1 petrov ffb_ras_wait(sc);
533 1.1 petrov }
534 1.1 petrov
535 1.1 petrov void
536 1.10 martin ffb_ras_fill(struct ffb_softc *sc)
537 1.1 petrov {
538 1.1 petrov ffb_ras_fifo_wait(sc, 2);
539 1.1 petrov FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_NEW);
540 1.1 petrov FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
541 1.1 petrov ffb_ras_wait(sc);
542 1.1 petrov }
543 1.1 petrov
544 1.1 petrov void
545 1.10 martin ffb_ras_copyrows(void *cookie, int src, int dst, int n)
546 1.1 petrov {
547 1.1 petrov struct rasops_info *ri = cookie;
548 1.1 petrov struct ffb_softc *sc = ri->ri_hw;
549 1.1 petrov
550 1.1 petrov if (dst == src)
551 1.1 petrov return;
552 1.1 petrov if (src < 0) {
553 1.1 petrov n += src;
554 1.1 petrov src = 0;
555 1.1 petrov }
556 1.1 petrov if ((src + n) > ri->ri_rows)
557 1.1 petrov n = ri->ri_rows - src;
558 1.1 petrov if (dst < 0) {
559 1.1 petrov n += dst;
560 1.1 petrov dst = 0;
561 1.1 petrov }
562 1.1 petrov if ((dst + n) > ri->ri_rows)
563 1.1 petrov n = ri->ri_rows - dst;
564 1.1 petrov if (n <= 0)
565 1.1 petrov return;
566 1.1 petrov n *= ri->ri_font->fontheight;
567 1.1 petrov src *= ri->ri_font->fontheight;
568 1.1 petrov dst *= ri->ri_font->fontheight;
569 1.1 petrov
570 1.1 petrov ffb_ras_fifo_wait(sc, 8);
571 1.1 petrov FBC_WRITE(sc, FFB_FBC_ROP, FBC_ROP_OLD | (FBC_ROP_OLD << 8));
572 1.1 petrov FBC_WRITE(sc, FFB_FBC_DRAWOP, FBC_DRAWOP_VSCROLL);
573 1.1 petrov FBC_WRITE(sc, FFB_FBC_BY, ri->ri_yorigin + src);
574 1.1 petrov FBC_WRITE(sc, FFB_FBC_BX, ri->ri_xorigin);
575 1.1 petrov FBC_WRITE(sc, FFB_FBC_DY, ri->ri_yorigin + dst);
576 1.1 petrov FBC_WRITE(sc, FFB_FBC_DX, ri->ri_xorigin);
577 1.1 petrov FBC_WRITE(sc, FFB_FBC_BH, n);
578 1.1 petrov FBC_WRITE(sc, FFB_FBC_BW, ri->ri_emuwidth);
579 1.1 petrov ffb_ras_wait(sc);
580 1.1 petrov }
581 1.1 petrov
582 1.1 petrov void
583 1.10 martin ffb_ras_setfg(struct ffb_softc *sc, int32_t fg)
584 1.1 petrov {
585 1.1 petrov ffb_ras_fifo_wait(sc, 1);
586 1.1 petrov if (fg == sc->sc_fg_cache)
587 1.1 petrov return;
588 1.1 petrov sc->sc_fg_cache = fg;
589 1.1 petrov FBC_WRITE(sc, FFB_FBC_FG, fg);
590 1.1 petrov ffb_ras_wait(sc);
591 1.1 petrov }
592 1.11 martin
593 1.11 martin /* frame buffer generic driver support functions */
594 1.11 martin static void
595 1.11 martin ffbfb_unblank(struct device *dev)
596 1.11 martin {
597 1.11 martin /* u_int on = 1; */
598 1.11 martin
599 1.11 martin if (dev && dev->dv_xname)
600 1.11 martin printf("%s: ffbfb_unblank\n", dev->dv_xname);
601 1.11 martin else
602 1.11 martin printf("ffbfb_unblank(%p)n", dev);
603 1.11 martin /* ffb_blank((struct ffb_softc*)dev, WSDISPLAYIO_SVIDEO, &on); */
604 1.11 martin }
605 1.11 martin
606 1.11 martin int
607 1.11 martin ffbfb_open(dev_t dev, int flags, int mode, struct proc *p)
608 1.11 martin {
609 1.11 martin int unit = minor(dev);
610 1.11 martin
611 1.11 martin if (unit >= ffb_cd.cd_ndevs || ffb_cd.cd_devs[unit] == NULL)
612 1.11 martin return ENXIO;
613 1.11 martin
614 1.11 martin return 0;
615 1.11 martin }
616 1.11 martin
617 1.11 martin int
618 1.11 martin ffbfb_close(dev_t dev, int flags, int mode, struct proc *p)
619 1.11 martin {
620 1.11 martin return 0;
621 1.11 martin }
622 1.11 martin
623 1.11 martin int
624 1.11 martin ffbfb_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
625 1.11 martin {
626 1.11 martin struct ffb_softc *sc = ffb_cd.cd_devs[minor(dev)];
627 1.11 martin
628 1.11 martin return ffb_ioctl(sc, cmd, data, flags, p);
629 1.11 martin }
630 1.11 martin
631 1.11 martin paddr_t
632 1.11 martin ffbfb_mmap(dev_t dev, off_t off, int prot)
633 1.11 martin {
634 1.11 martin struct ffb_softc *sc = ffb_cd.cd_devs[minor(dev)];
635 1.11 martin int i, reg;
636 1.11 martin off_t o;
637 1.11 martin
638 1.11 martin /*
639 1.11 martin * off is a magic cookie (see xfree86/drivers/sunffb/ffb.h),
640 1.11 martin * which we map to an index into the "reg" property, and use
641 1.11 martin * our copy of the firmware data as arguments for the real
642 1.11 martin * mapping.
643 1.11 martin */
644 1.11 martin static struct { unsigned long voff; int reg; } map[] = {
645 1.11 martin { 0x00000000, FFB_REG_SFB8R },
646 1.11 martin { 0x00400000, FFB_REG_SFB8G },
647 1.11 martin { 0x00800000, FFB_REG_SFB8B },
648 1.11 martin { 0x00c00000, FFB_REG_SFB8X },
649 1.11 martin { 0x01000000, FFB_REG_SFB32 },
650 1.11 martin { 0x02000000, FFB_REG_SFB64 },
651 1.11 martin { 0x04000000, FFB_REG_FBC },
652 1.11 martin { 0x04004000, FFB_REG_DFB8R },
653 1.11 martin { 0x04404000, FFB_REG_DFB8G },
654 1.11 martin { 0x04804000, FFB_REG_DFB8B },
655 1.11 martin { 0x04c04000, FFB_REG_DFB8X },
656 1.11 martin { 0x05004000, FFB_REG_DFB24 },
657 1.11 martin { 0x06004000, FFB_REG_DFB32 },
658 1.11 martin { 0x07004000, FFB_REG_DFB422A },
659 1.11 martin { 0x0bc06000, FFB_REG_DAC },
660 1.11 martin { 0x0bc08000, FFB_REG_PROM },
661 1.11 martin };
662 1.11 martin
663 1.11 martin /* special value "FFB_EXP_VOFF" - not backed by any "reg" entry */
664 1.11 martin if (off == 0x0bc18000)
665 1.11 martin return bus_space_mmap(sc->sc_bt, sc->sc_addrs[FFB_REG_PROM],
666 1.11 martin 0x00200000, prot, BUS_SPACE_MAP_LINEAR);
667 1.11 martin
668 1.11 martin #define NELEMS(arr) (sizeof(arr)/sizeof((arr)[0]))
669 1.11 martin
670 1.11 martin /* the map is ordered by voff */
671 1.11 martin for (i = 0; i < NELEMS(map); i++) {
672 1.11 martin if (map[i].voff > off)
673 1.11 martin break; /* beyound */
674 1.11 martin reg = map[i].reg;
675 1.11 martin if (map[i].voff + sc->sc_sizes[reg] < off)
676 1.11 martin continue; /* not there yet */
677 1.11 martin if (off > map[i].voff + sc->sc_sizes[reg])
678 1.11 martin break; /* out of range */
679 1.11 martin o = off - map[i].voff;
680 1.11 martin return bus_space_mmap(sc->sc_bt, sc->sc_addrs[reg], o, prot,
681 1.11 martin BUS_SPACE_MAP_LINEAR);
682 1.11 martin }
683 1.11 martin
684 1.11 martin return -1;
685 1.11 martin }
686