FreeBSD/Linux Kernel Cross Reference
sys/dev/fb/creator.c
1 /*-
2 * Copyright (c) 2003 Jake Burkholder.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: releng/6.0/sys/dev/fb/creator.c 150981 2005-10-05 21:48:03Z marius $");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/consio.h>
34 #include <sys/fbio.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37
38 #include <machine/bus.h>
39 #include <machine/ofw_upa.h>
40 #include <machine/sc_machdep.h>
41
42 #include <dev/fb/fbreg.h>
43 #include <dev/fb/gallant12x22.h>
44 #include <dev/syscons/syscons.h>
45
46 #include <dev/ofw/openfirm.h>
47
48 #include <sparc64/creator/creator.h>
49
50 static int creator_configure(int flags);
51
52 static vi_probe_t creator_probe;
53 static vi_init_t creator_init;
54 static vi_get_info_t creator_get_info;
55 static vi_query_mode_t creator_query_mode;
56 static vi_set_mode_t creator_set_mode;
57 static vi_save_font_t creator_save_font;
58 static vi_load_font_t creator_load_font;
59 static vi_show_font_t creator_show_font;
60 static vi_save_palette_t creator_save_palette;
61 static vi_load_palette_t creator_load_palette;
62 static vi_set_border_t creator_set_border;
63 static vi_save_state_t creator_save_state;
64 static vi_load_state_t creator_load_state;
65 static vi_set_win_org_t creator_set_win_org;
66 static vi_read_hw_cursor_t creator_read_hw_cursor;
67 static vi_set_hw_cursor_t creator_set_hw_cursor;
68 static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape;
69 static vi_blank_display_t creator_blank_display;
70 static vi_mmap_t creator_mmap;
71 static vi_ioctl_t creator_ioctl;
72 static vi_clear_t creator_clear;
73 static vi_fill_rect_t creator_fill_rect;
74 static vi_bitblt_t creator_bitblt;
75 static vi_diag_t creator_diag;
76 static vi_save_cursor_palette_t creator_save_cursor_palette;
77 static vi_load_cursor_palette_t creator_load_cursor_palette;
78 static vi_copy_t creator_copy;
79 static vi_putp_t creator_putp;
80 static vi_putc_t creator_putc;
81 static vi_puts_t creator_puts;
82 static vi_putm_t creator_putm;
83
84 static void creator_cursor_enable(struct creator_softc *sc, int onoff);
85 static void creator_cursor_install(struct creator_softc *sc);
86
87 static video_switch_t creatorvidsw = {
88 .probe = creator_probe,
89 .init = creator_init,
90 .get_info = creator_get_info,
91 .query_mode = creator_query_mode,
92 .set_mode = creator_set_mode,
93 .save_font = creator_save_font,
94 .load_font = creator_load_font,
95 .show_font = creator_show_font,
96 .save_palette = creator_save_palette,
97 .load_palette = creator_load_palette,
98 .set_border = creator_set_border,
99 .save_state = creator_save_state,
100 .load_state = creator_load_state,
101 .set_win_org = creator_set_win_org,
102 .read_hw_cursor = creator_read_hw_cursor,
103 .set_hw_cursor = creator_set_hw_cursor,
104 .set_hw_cursor_shape = creator_set_hw_cursor_shape,
105 .blank_display = creator_blank_display,
106 .mmap = creator_mmap,
107 .ioctl = creator_ioctl,
108 .clear = creator_clear,
109 .fill_rect = creator_fill_rect,
110 .bitblt = creator_bitblt,
111 NULL, /* XXX brain damage */
112 NULL, /* XXX brain damage */
113 .diag = creator_diag,
114 .save_cursor_palette = creator_save_cursor_palette,
115 .load_cursor_palette = creator_load_cursor_palette,
116 .copy = creator_copy,
117 .putp = creator_putp,
118 .putc = creator_putc,
119 .puts = creator_puts,
120 .putm = creator_putm
121 };
122
123 VIDEO_DRIVER(creator, creatorvidsw, creator_configure);
124
125 extern sc_rndr_sw_t txtrndrsw;
126 RENDERER(creator, 0, txtrndrsw, gfb_set);
127
128 RENDERER_MODULE(creator, gfb_set);
129
130 extern struct bus_space_tag nexus_bustag;
131
132 #define C(r, g, b) ((b << 16) | (g << 8) | (r))
133 static const int cmap[] = {
134 C(0x00, 0x00, 0x00), /* black */
135 C(0x00, 0x00, 0xff), /* blue */
136 C(0x00, 0xff, 0x00), /* green */
137 C(0x00, 0xc0, 0xc0), /* cyan */
138 C(0xff, 0x00, 0x00), /* red */
139 C(0xc0, 0x00, 0xc0), /* magenta */
140 C(0xc0, 0xc0, 0x00), /* brown */
141 C(0xc0, 0xc0, 0xc0), /* light grey */
142 C(0x80, 0x80, 0x80), /* dark grey */
143 C(0x80, 0x80, 0xff), /* light blue */
144 C(0x80, 0xff, 0x80), /* light green */
145 C(0x80, 0xff, 0xff), /* light cyan */
146 C(0xff, 0x80, 0x80), /* light red */
147 C(0xff, 0x80, 0xff), /* light magenta */
148 C(0xff, 0xff, 0x80), /* yellow */
149 C(0xff, 0xff, 0xff), /* white */
150 };
151
152 static const u_char creator_mouse_pointer[64][8] __aligned(8) = {
153 { 0x00, 0x00, }, /* ............ */
154 { 0x80, 0x00, }, /* *........... */
155 { 0xc0, 0x00, }, /* **.......... */
156 { 0xe0, 0x00, }, /* ***......... */
157 { 0xf0, 0x00, }, /* ****........ */
158 { 0xf8, 0x00, }, /* *****....... */
159 { 0xfc, 0x00, }, /* ******...... */
160 { 0xfe, 0x00, }, /* *******..... */
161 { 0xff, 0x00, }, /* ********.... */
162 { 0xff, 0x80, }, /* *********... */
163 { 0xfc, 0xc0, }, /* ******..**.. */
164 { 0xdc, 0x00, }, /* **.***...... */
165 { 0x8e, 0x00, }, /* *...***..... */
166 { 0x0e, 0x00, }, /* ....***..... */
167 { 0x07, 0x00, }, /* .....***.... */
168 { 0x04, 0x00, }, /* .....*...... */
169 { 0x00, 0x00, }, /* ............ */
170 { 0x00, 0x00, }, /* ............ */
171 { 0x00, 0x00, }, /* ............ */
172 { 0x00, 0x00, }, /* ............ */
173 { 0x00, 0x00, }, /* ............ */
174 { 0x00, 0x00, }, /* ............ */
175 };
176
177 static struct creator_softc creator_softc;
178
179 static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n);
180 static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc);
181 static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw);
182 static inline void creator_ras_setbg(struct creator_softc *sc, int bg);
183 static inline void creator_ras_setfg(struct creator_softc *sc, int fg);
184 static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask);
185 static inline void creator_ras_wait(struct creator_softc *sc);
186
187 static inline void
188 creator_ras_wait(struct creator_softc *sc)
189 {
190 int ucsr;
191 int r;
192
193 for (;;) {
194 ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR);
195 if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0)
196 break;
197 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
198 if (r != 0)
199 FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r);
200 }
201 }
202
203 static inline void
204 creator_ras_fifo_wait(struct creator_softc *sc, int n)
205 {
206 int cache;
207
208 cache = sc->sc_fifo_cache;
209 while (cache < n)
210 cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) &
211 FBC_UCSR_FIFO_MASK) - 8;
212 sc->sc_fifo_cache = cache - n;
213 }
214
215 static inline void
216 creator_ras_setfontinc(struct creator_softc *sc, int fontinc)
217 {
218
219 if (fontinc == sc->sc_fontinc_cache)
220 return;
221 sc->sc_fontinc_cache = fontinc;
222 creator_ras_fifo_wait(sc, 1);
223 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc);
224 creator_ras_wait(sc);
225 }
226
227 static inline void
228 creator_ras_setfontw(struct creator_softc *sc, int fontw)
229 {
230
231 if (fontw == sc->sc_fontw_cache)
232 return;
233 sc->sc_fontw_cache = fontw;
234 creator_ras_fifo_wait(sc, 1);
235 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw);
236 creator_ras_wait(sc);
237 }
238
239 static inline void
240 creator_ras_setbg(struct creator_softc *sc, int bg)
241 {
242
243 if (bg == sc->sc_bg_cache)
244 return;
245 sc->sc_bg_cache = bg;
246 creator_ras_fifo_wait(sc, 1);
247 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg);
248 creator_ras_wait(sc);
249 }
250
251 static inline void
252 creator_ras_setfg(struct creator_softc *sc, int fg)
253 {
254
255 if (fg == sc->sc_fg_cache)
256 return;
257 sc->sc_fg_cache = fg;
258 creator_ras_fifo_wait(sc, 1);
259 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg);
260 creator_ras_wait(sc);
261 }
262
263 static inline void
264 creator_ras_setpmask(struct creator_softc *sc, int pmask)
265 {
266
267 if (pmask == sc->sc_pmask_cache)
268 return;
269 sc->sc_pmask_cache = pmask;
270 creator_ras_fifo_wait(sc, 1);
271 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask);
272 creator_ras_wait(sc);
273 }
274
275 static int
276 creator_configure(int flags)
277 {
278 struct upa_regs reg[FFB_NREG];
279 struct creator_softc *sc;
280 phandle_t chosen;
281 phandle_t output;
282 ihandle_t stdout;
283 char buf[32];
284 int i;
285
286 /*
287 * For the high-level console probing return the number of
288 * registered adapters.
289 */
290 if (!(flags & VIO_PROBE_ONLY)) {
291 for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++)
292 ;
293 return (i);
294 }
295
296 /* Low-level console probing and initialization. */
297
298 sc = &creator_softc;
299 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
300 goto found;
301
302 if ((chosen = OF_finddevice("/chosen")) == -1)
303 return (0);
304 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
305 return (0);
306 if ((output = OF_instance_to_package(stdout)) == -1)
307 return (0);
308 if (OF_getprop(output, "name", buf, sizeof(buf)) == -1)
309 return (0);
310 if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) {
311 sc->sc_flags = CREATOR_CONSOLE;
312 if (strcmp(buf, "SUNW,afb") == 0)
313 sc->sc_flags |= CREATOR_AFB;
314 sc->sc_node = output;
315 } else
316 return (0);
317
318 if (OF_getprop(output, "reg", reg, sizeof(reg)) == -1)
319 return (0);
320 for (i = 0; i < FFB_NREG; i++) {
321 sc->sc_bt[i] = &nexus_bustag;
322 sc->sc_bh[i] = UPA_REG_PHYS(reg + i);
323 }
324
325 if (creator_init(0, &sc->sc_va, 0) < 0)
326 return (0);
327
328 found:
329 /* Return number of found adapters. */
330 return (1);
331 }
332
333 static int
334 creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
335 {
336
337 return (0);
338 }
339
340 static int
341 creator_init(int unit, video_adapter_t *adp, int flags)
342 {
343 struct creator_softc *sc;
344 phandle_t options;
345 video_info_t *vi;
346 char buf[32];
347
348 sc = (struct creator_softc *)adp;
349 vi = &adp->va_info;
350
351 vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit);
352
353 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
354 sizeof(sc->sc_height)) == -1)
355 return (ENXIO);
356 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
357 sizeof(sc->sc_width)) == -1)
358 return (ENXIO);
359 if ((options = OF_finddevice("/options")) == -1)
360 return (ENXIO);
361 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
362 return (ENXIO);
363 vi->vi_height = strtol(buf, NULL, 10);
364 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
365 return (ENXIO);
366 vi->vi_width = strtol(buf, NULL, 10);
367 vi->vi_cwidth = 12;
368 vi->vi_cheight = 22;
369 vi->vi_flags = V_INFO_COLOR;
370 vi->vi_mem_model = V_INFO_MM_OTHER;
371
372 sc->sc_font = gallant12x22_data;
373 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
374 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
375
376 creator_set_mode(adp, 0);
377
378 if (!(sc->sc_flags & CREATOR_AFB)) {
379 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID);
380 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
381 FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) {
382 sc->sc_flags |= CREATOR_PAC1;
383 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL);
384 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
385 FFB_DAC_UCTRL_MANREV) >> 8) <= 2)
386 sc->sc_flags |= CREATOR_CURINV;
387 }
388 }
389
390 creator_blank_display(adp, V_DISPLAY_ON);
391 creator_clear(adp);
392
393 /*
394 * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode()
395 * (which will invalidate our caches and restore our settings) is
396 * called when the X server shuts down. Otherwise screen corruption
397 * happens most of the time.
398 */
399 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER |
400 V_ADP_INITIALIZED;
401 if (vid_register(adp) < 0)
402 return (ENXIO);
403 adp->va_flags |= V_ADP_REGISTERED;
404
405 return (0);
406 }
407
408 static int
409 creator_get_info(video_adapter_t *adp, int mode, video_info_t *info)
410 {
411
412 bcopy(&adp->va_info, info, sizeof(*info));
413 return (0);
414 }
415
416 static int
417 creator_query_mode(video_adapter_t *adp, video_info_t *info)
418 {
419
420 return (ENODEV);
421 }
422
423 static int
424 creator_set_mode(video_adapter_t *adp, int mode)
425 {
426 struct creator_softc *sc;
427
428 sc = (struct creator_softc *)adp;
429 sc->sc_bg_cache = -1;
430 sc->sc_fg_cache = -1;
431 sc->sc_fontinc_cache = -1;
432 sc->sc_fontw_cache = -1;
433 sc->sc_pmask_cache = -1;
434
435 creator_ras_wait(sc);
436 sc->sc_fifo_cache = 0;
437 creator_ras_fifo_wait(sc, 2);
438 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS |
439 FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
440 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A |
441 FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
442 return (0);
443 }
444
445 static int
446 creator_save_font(video_adapter_t *adp, int page, int size, int width,
447 u_char *data, int c, int count)
448 {
449
450 return (ENODEV);
451 }
452
453 static int
454 creator_load_font(video_adapter_t *adp, int page, int size, int width,
455 u_char *data, int c, int count)
456 {
457
458 return (ENODEV);
459 }
460
461 static int
462 creator_show_font(video_adapter_t *adp, int page)
463 {
464
465 return (ENODEV);
466 }
467
468 static int
469 creator_save_palette(video_adapter_t *adp, u_char *palette)
470 {
471
472 return (ENODEV);
473 }
474
475 static int
476 creator_load_palette(video_adapter_t *adp, u_char *palette)
477 {
478
479 return (ENODEV);
480 }
481
482 static int
483 creator_set_border(video_adapter_t *adp, int border)
484 {
485 struct creator_softc *sc;
486
487 sc = (struct creator_softc *)adp;
488 creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
489 creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
490 sc->sc_width, sc->sc_ymargin);
491 creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
492 creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
493 sc->sc_xmargin, sc->sc_height);
494 return (0);
495 }
496
497 static int
498 creator_save_state(video_adapter_t *adp, void *p, size_t size)
499 {
500
501 return (ENODEV);
502 }
503
504 static int
505 creator_load_state(video_adapter_t *adp, void *p)
506 {
507
508 return (ENODEV);
509 }
510
511 static int
512 creator_set_win_org(video_adapter_t *adp, off_t offset)
513 {
514
515 return (ENODEV);
516 }
517
518 static int
519 creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
520 {
521
522 *col = 0;
523 *row = 0;
524 return (0);
525 }
526
527 static int
528 creator_set_hw_cursor(video_adapter_t *adp, int col, int row)
529 {
530
531 return (ENODEV);
532 }
533
534 static int
535 creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
536 int celsize, int blink)
537 {
538
539 return (ENODEV);
540 }
541
542 static int
543 creator_blank_display(video_adapter_t *adp, int mode)
544 {
545 struct creator_softc *sc;
546 uint32_t v;
547 int i;
548
549 sc = (struct creator_softc *)adp;
550 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
551 v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
552 switch (mode) {
553 case V_DISPLAY_ON:
554 v &= ~(FFB_DAC_CFG_TGEN_VSD | FFB_DAC_CFG_TGEN_HSD);
555 v |= FFB_DAC_CFG_TGEN_VIDE;
556 break;
557 case V_DISPLAY_BLANK:
558 v |= (FFB_DAC_CFG_TGEN_VSD | FFB_DAC_CFG_TGEN_HSD);
559 v &= ~FFB_DAC_CFG_TGEN_VIDE;
560 break;
561 case V_DISPLAY_STAND_BY:
562 v &= ~FFB_DAC_CFG_TGEN_VSD;
563 v &= ~FFB_DAC_CFG_TGEN_VIDE;
564 break;
565 case V_DISPLAY_SUSPEND:
566 v |= FFB_DAC_CFG_TGEN_VSD;
567 v &= ~FFB_DAC_CFG_TGEN_HSD;
568 v &= ~FFB_DAC_CFG_TGEN_VIDE;
569 break;
570 }
571 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
572 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v);
573 for (i = 0; i < 10; i++) {
574 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
575 (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
576 }
577 return (0);
578 }
579
580 static int
581 creator_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
582 int prot)
583 {
584
585 return (EINVAL);
586 }
587
588 static int
589 creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
590 {
591 struct creator_softc *sc;
592 struct fbcursor *fbc;
593 struct fbtype *fb;
594
595 sc = (struct creator_softc *)adp;
596 switch (cmd) {
597 case FBIOGTYPE:
598 fb = (struct fbtype *)data;
599 fb->fb_type = FBTYPE_CREATOR;
600 fb->fb_height = sc->sc_height;
601 fb->fb_width = sc->sc_width;
602 fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0;
603 break;
604 case FBIOSCURSOR:
605 fbc = (struct fbcursor *)data;
606 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
607 creator_cursor_enable(sc, 0);
608 sc->sc_flags &= ~CREATOR_CUREN;
609 } else
610 return (ENODEV);
611 break;
612 break;
613 default:
614 return (fb_commonioctl(adp, cmd, data));
615 }
616 return (0);
617 }
618
619 static int
620 creator_clear(video_adapter_t *adp)
621 {
622 struct creator_softc *sc;
623
624 sc = (struct creator_softc *)adp;
625 creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
626 sc->sc_height);
627 return (0);
628 }
629
630 static int
631 creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
632 {
633 struct creator_softc *sc;
634
635 sc = (struct creator_softc *)adp;
636 creator_ras_setpmask(sc, 0xffffffff);
637 creator_ras_fifo_wait(sc, 2);
638 FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW);
639 FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
640 creator_ras_setfg(sc, cmap[val & 0xf]);
641 /*
642 * Note that at least the Elite3D cards are sensitive to the order
643 * of operations here.
644 */
645 creator_ras_fifo_wait(sc, 4);
646 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y);
647 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x);
648 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy);
649 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx);
650 creator_ras_wait(sc);
651 return (0);
652 }
653
654 static int
655 creator_bitblt(video_adapter_t *adp, ...)
656 {
657
658 return (ENODEV);
659 }
660
661 static int
662 creator_diag(video_adapter_t *adp, int level)
663 {
664 video_info_t info;
665
666 fb_dump_adp_info(adp->va_name, adp, level);
667 creator_get_info(adp, 0, &info);
668 fb_dump_mode_info(adp->va_name, adp, &info, level);
669 return (0);
670 }
671
672 static int
673 creator_save_cursor_palette(video_adapter_t *adp, u_char *palette)
674 {
675
676 return (ENODEV);
677 }
678
679 static int
680 creator_load_cursor_palette(video_adapter_t *adp, u_char *palette)
681 {
682
683 return (ENODEV);
684 }
685
686 static int
687 creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
688 {
689
690 return (ENODEV);
691 }
692
693 static int
694 creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a,
695 int size, int bpp, int bit_ltor, int byte_ltor)
696 {
697
698 return (ENODEV);
699 }
700
701 static int
702 creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a)
703 {
704 struct creator_softc *sc;
705 uint16_t *p;
706 int row;
707 int col;
708 int i;
709
710 sc = (struct creator_softc *)adp;
711 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
712 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
713 p = (uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight);
714 creator_ras_setfg(sc, cmap[a & 0xf]);
715 creator_ras_setbg(sc, cmap[(a >> 4) & 0xf]);
716 creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight);
717 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY,
718 ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin));
719 creator_ras_setfontw(sc, adp->va_info.vi_cwidth);
720 creator_ras_setfontinc(sc, 0x10000);
721 for (i = 0; i < adp->va_info.vi_cheight; i++) {
722 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16);
723 }
724 return (0);
725 }
726
727 static int
728 creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
729 {
730 int i;
731
732 for (i = 0; i < len; i++) {
733 (*vidsw[adp->va_index]->putc)(adp, off + i, s[i] & 0xff,
734 (s[i] & 0xff00) >> 8);
735 }
736 return (0);
737 }
738
739 static int
740 creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
741 u_int32_t pixel_mask, int size, int width)
742 {
743 struct creator_softc *sc;
744
745 sc = (struct creator_softc *)adp;
746 if (!(sc->sc_flags & CREATOR_CUREN)) {
747 creator_cursor_install(sc);
748 creator_cursor_enable(sc, 1);
749 sc->sc_flags |= CREATOR_CUREN;
750 }
751 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS);
752 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
753 ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin));
754 return (0);
755 }
756
757 static void
758 creator_cursor_enable(struct creator_softc *sc, int onoff)
759 {
760 int v;
761
762 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_CTRL);
763 if (sc->sc_flags & CREATOR_CURINV)
764 v = onoff ? FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1 : 0;
765 else
766 v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1;
767 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v);
768 }
769
770 static void
771 creator_cursor_install(struct creator_softc *sc)
772 {
773 int i, j;
774
775 creator_cursor_enable(sc, 0);
776 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_COLOR1);
777 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0xffffff);
778 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0x0);
779 for (i = 0; i < 2; i++) {
780 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2,
781 i ? FFB_DAC_CUR_BITMAP_P0 : FFB_DAC_CUR_BITMAP_P1);
782 for (j = 0; j < 64; j++) {
783 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
784 *(const uint32_t *)(&creator_mouse_pointer[j][0]));
785 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
786 *(const uint32_t *)(&creator_mouse_pointer[j][4]));
787 }
788 }
789 }
Cache object: 6ec2c5dd1625784ae993a108cfd7163d
|