2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2005 - 2006 Marius Strobl <marius@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
35 #include <sys/consio.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/resource.h>
41 #include <dev/ofw/ofw_bus.h>
42 #include <dev/ofw/openfirm.h>
44 #include <machine/bus.h>
45 #include <machine/bus_private.h>
46 #include <machine/ofw_machdep.h>
47 #include <machine/resource.h>
48 #include <machine/sc_machdep.h>
52 #include <dev/fb/fbreg.h>
53 #include <dev/fb/creatorreg.h>
54 #include <dev/fb/gfb.h>
55 #include <dev/syscons/syscons.h>
57 #define CREATOR_DRIVER_NAME "creator"
59 struct creator_softc {
60 video_adapter_t sc_va; /* XXX must be first */
66 struct resource *sc_reg[FFB_NREG];
67 bus_space_tag_t sc_bt[FFB_NREG];
68 bus_space_handle_t sc_bh[FFB_NREG];
77 const u_char *sc_font;
87 #define CREATOR_AFB (1 << 0)
88 #define CREATOR_CONSOLE (1 << 1)
89 #define CREATOR_CUREN (1 << 2)
90 #define CREATOR_CURINV (1 << 3)
91 #define CREATOR_PAC1 (1 << 4)
94 #define FFB_READ(sc, reg, off) \
95 bus_space_read_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off))
96 #define FFB_WRITE(sc, reg, off, val) \
97 bus_space_write_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off), (val))
99 #define C(r, g, b) ((b << 16) | (g << 8) | (r))
100 static const uint32_t const creator_cmap[] = {
101 C(0x00, 0x00, 0x00), /* black */
102 C(0x00, 0x00, 0xff), /* blue */
103 C(0x00, 0xff, 0x00), /* green */
104 C(0x00, 0xc0, 0xc0), /* cyan */
105 C(0xff, 0x00, 0x00), /* red */
106 C(0xc0, 0x00, 0xc0), /* magenta */
107 C(0xc0, 0xc0, 0x00), /* brown */
108 C(0xc0, 0xc0, 0xc0), /* light grey */
109 C(0x80, 0x80, 0x80), /* dark grey */
110 C(0x80, 0x80, 0xff), /* light blue */
111 C(0x80, 0xff, 0x80), /* light green */
112 C(0x80, 0xff, 0xff), /* light cyan */
113 C(0xff, 0x80, 0x80), /* light red */
114 C(0xff, 0x80, 0xff), /* light magenta */
115 C(0xff, 0xff, 0x80), /* yellow */
116 C(0xff, 0xff, 0xff), /* white */
120 static const struct {
124 } const creator_fb_map[] = {
125 { FFB_VIRT_SFB8R, FFB_PHYS_SFB8R, FFB_SIZE_SFB8R },
126 { FFB_VIRT_SFB8G, FFB_PHYS_SFB8G, FFB_SIZE_SFB8G },
127 { FFB_VIRT_SFB8B, FFB_PHYS_SFB8B, FFB_SIZE_SFB8B },
128 { FFB_VIRT_SFB8X, FFB_PHYS_SFB8X, FFB_SIZE_SFB8X },
129 { FFB_VIRT_SFB32, FFB_PHYS_SFB32, FFB_SIZE_SFB32 },
130 { FFB_VIRT_SFB64, FFB_PHYS_SFB64, FFB_SIZE_SFB64 },
131 { FFB_VIRT_FBC, FFB_PHYS_FBC, FFB_SIZE_FBC },
132 { FFB_VIRT_FBC_BM, FFB_PHYS_FBC_BM, FFB_SIZE_FBC_BM },
133 { FFB_VIRT_DFB8R, FFB_PHYS_DFB8R, FFB_SIZE_DFB8R },
134 { FFB_VIRT_DFB8G, FFB_PHYS_DFB8G, FFB_SIZE_DFB8G },
135 { FFB_VIRT_DFB8B, FFB_PHYS_DFB8B, FFB_SIZE_DFB8B },
136 { FFB_VIRT_DFB8X, FFB_PHYS_DFB8X, FFB_SIZE_DFB8X },
137 { FFB_VIRT_DFB24, FFB_PHYS_DFB24, FFB_SIZE_DFB24 },
138 { FFB_VIRT_DFB32, FFB_PHYS_DFB32, FFB_SIZE_DFB32 },
139 { FFB_VIRT_DFB422A, FFB_PHYS_DFB422A, FFB_SIZE_DFB422A },
140 { FFB_VIRT_DFB422AD, FFB_PHYS_DFB422AD, FFB_SIZE_DFB422AD },
141 { FFB_VIRT_DFB24B, FFB_PHYS_DFB24B, FFB_SIZE_DFB24B },
142 { FFB_VIRT_DFB422B, FFB_PHYS_DFB422B, FFB_SIZE_DFB422B },
143 { FFB_VIRT_DFB422BD, FFB_PHYS_DFB422BD, FFB_SIZE_DFB422BD },
144 { FFB_VIRT_SFB16Z, FFB_PHYS_SFB16Z, FFB_SIZE_SFB16Z },
145 { FFB_VIRT_SFB8Z, FFB_PHYS_SFB8Z, FFB_SIZE_SFB8Z },
146 { FFB_VIRT_SFB422, FFB_PHYS_SFB422, FFB_SIZE_SFB422 },
147 { FFB_VIRT_SFB422D, FFB_PHYS_SFB422D, FFB_SIZE_SFB422D },
148 { FFB_VIRT_FBC_KREG, FFB_PHYS_FBC_KREG, FFB_SIZE_FBC_KREG },
149 { FFB_VIRT_DAC, FFB_PHYS_DAC, FFB_SIZE_DAC },
150 { FFB_VIRT_PROM, FFB_PHYS_PROM, FFB_SIZE_PROM },
151 { FFB_VIRT_EXP, FFB_PHYS_EXP, FFB_SIZE_EXP },
154 #define CREATOR_FB_MAP_SIZE \
155 (sizeof(creator_fb_map) / sizeof(creator_fb_map[0]))
157 extern const struct gfb_font gallant12x22;
159 static struct creator_softc creator_softc;
160 static struct bus_space_tag creator_bst_store[FFB_FBC];
162 static device_probe_t creator_bus_probe;
163 static device_attach_t creator_bus_attach;
165 static device_method_t creator_bus_methods[] = {
166 DEVMETHOD(device_probe, creator_bus_probe),
167 DEVMETHOD(device_attach, creator_bus_attach),
172 static devclass_t creator_devclass;
174 DEFINE_CLASS_0(creator, creator_bus_driver, creator_bus_methods,
175 sizeof(struct creator_softc));
176 DRIVER_MODULE(creator, nexus, creator_bus_driver, creator_devclass, 0, 0);
177 DRIVER_MODULE(creator, upa, creator_bus_driver, creator_devclass, 0, 0);
179 static d_open_t creator_fb_open;
180 static d_close_t creator_fb_close;
181 static d_ioctl_t creator_fb_ioctl;
182 static d_mmap_t creator_fb_mmap;
184 static struct cdevsw creator_fb_devsw = {
185 .d_version = D_VERSION,
186 .d_flags = D_NEEDGIANT,
187 .d_open = creator_fb_open,
188 .d_close = creator_fb_close,
189 .d_ioctl = creator_fb_ioctl,
190 .d_mmap = creator_fb_mmap,
194 static void creator_cursor_enable(struct creator_softc *sc, int onoff);
195 static void creator_cursor_install(struct creator_softc *sc);
196 static void creator_shutdown(void *xsc);
198 static int creator_configure(int flags);
200 static vi_probe_t creator_probe;
201 static vi_init_t creator_init;
202 static vi_get_info_t creator_get_info;
203 static vi_query_mode_t creator_query_mode;
204 static vi_set_mode_t creator_set_mode;
205 static vi_save_font_t creator_save_font;
206 static vi_load_font_t creator_load_font;
207 static vi_show_font_t creator_show_font;
208 static vi_save_palette_t creator_save_palette;
209 static vi_load_palette_t creator_load_palette;
210 static vi_set_border_t creator_set_border;
211 static vi_save_state_t creator_save_state;
212 static vi_load_state_t creator_load_state;
213 static vi_set_win_org_t creator_set_win_org;
214 static vi_read_hw_cursor_t creator_read_hw_cursor;
215 static vi_set_hw_cursor_t creator_set_hw_cursor;
216 static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape;
217 static vi_blank_display_t creator_blank_display;
218 static vi_mmap_t creator_mmap;
219 static vi_ioctl_t creator_ioctl;
220 static vi_clear_t creator_clear;
221 static vi_fill_rect_t creator_fill_rect;
222 static vi_bitblt_t creator_bitblt;
223 static vi_diag_t creator_diag;
224 static vi_save_cursor_palette_t creator_save_cursor_palette;
225 static vi_load_cursor_palette_t creator_load_cursor_palette;
226 static vi_copy_t creator_copy;
227 static vi_putp_t creator_putp;
228 static vi_putc_t creator_putc;
229 static vi_puts_t creator_puts;
230 static vi_putm_t creator_putm;
232 static video_switch_t creatorvidsw = {
233 .probe = creator_probe,
234 .init = creator_init,
235 .get_info = creator_get_info,
236 .query_mode = creator_query_mode,
237 .set_mode = creator_set_mode,
238 .save_font = creator_save_font,
239 .load_font = creator_load_font,
240 .show_font = creator_show_font,
241 .save_palette = creator_save_palette,
242 .load_palette = creator_load_palette,
243 .set_border = creator_set_border,
244 .save_state = creator_save_state,
245 .load_state = creator_load_state,
246 .set_win_org = creator_set_win_org,
247 .read_hw_cursor = creator_read_hw_cursor,
248 .set_hw_cursor = creator_set_hw_cursor,
249 .set_hw_cursor_shape = creator_set_hw_cursor_shape,
250 .blank_display = creator_blank_display,
251 .mmap = creator_mmap,
252 .ioctl = creator_ioctl,
253 .clear = creator_clear,
254 .fill_rect = creator_fill_rect,
255 .bitblt = creator_bitblt,
256 .diag = creator_diag,
257 .save_cursor_palette = creator_save_cursor_palette,
258 .load_cursor_palette = creator_load_cursor_palette,
259 .copy = creator_copy,
260 .putp = creator_putp,
261 .putc = creator_putc,
262 .puts = creator_puts,
266 VIDEO_DRIVER(creator, creatorvidsw, creator_configure);
268 extern sc_rndr_sw_t txtrndrsw;
269 RENDERER(creator, 0, txtrndrsw, gfb_set);
271 RENDERER_MODULE(creator, gfb_set);
273 static const u_char const creator_mouse_pointer[64][8] __aligned(8) = {
274 { 0x00, 0x00, }, /* ............ */
275 { 0x80, 0x00, }, /* *........... */
276 { 0xc0, 0x00, }, /* **.......... */
277 { 0xe0, 0x00, }, /* ***......... */
278 { 0xf0, 0x00, }, /* ****........ */
279 { 0xf8, 0x00, }, /* *****....... */
280 { 0xfc, 0x00, }, /* ******...... */
281 { 0xfe, 0x00, }, /* *******..... */
282 { 0xff, 0x00, }, /* ********.... */
283 { 0xff, 0x80, }, /* *********... */
284 { 0xfc, 0xc0, }, /* ******..**.. */
285 { 0xdc, 0x00, }, /* **.***...... */
286 { 0x8e, 0x00, }, /* *...***..... */
287 { 0x0e, 0x00, }, /* ....***..... */
288 { 0x07, 0x00, }, /* .....***.... */
289 { 0x04, 0x00, }, /* .....*...... */
290 { 0x00, 0x00, }, /* ............ */
291 { 0x00, 0x00, }, /* ............ */
292 { 0x00, 0x00, }, /* ............ */
293 { 0x00, 0x00, }, /* ............ */
294 { 0x00, 0x00, }, /* ............ */
295 { 0x00, 0x00, }, /* ............ */
298 static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n);
299 static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc);
300 static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw);
301 static inline void creator_ras_setbg(struct creator_softc *sc, int bg);
302 static inline void creator_ras_setfg(struct creator_softc *sc, int fg);
303 static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask);
304 static inline void creator_ras_wait(struct creator_softc *sc);
307 creator_ras_wait(struct creator_softc *sc)
313 ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR);
314 if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0)
316 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
318 FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r);
323 creator_ras_fifo_wait(struct creator_softc *sc, int n)
327 cache = sc->sc_fifo_cache;
329 cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) &
330 FBC_UCSR_FIFO_MASK) - 8;
331 sc->sc_fifo_cache = cache - n;
335 creator_ras_setfontinc(struct creator_softc *sc, int fontinc)
338 if (fontinc == sc->sc_fontinc_cache)
340 sc->sc_fontinc_cache = fontinc;
341 creator_ras_fifo_wait(sc, 1);
342 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc);
343 creator_ras_wait(sc);
347 creator_ras_setfontw(struct creator_softc *sc, int fontw)
350 if (fontw == sc->sc_fontw_cache)
352 sc->sc_fontw_cache = fontw;
353 creator_ras_fifo_wait(sc, 1);
354 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw);
355 creator_ras_wait(sc);
359 creator_ras_setbg(struct creator_softc *sc, int bg)
362 if (bg == sc->sc_bg_cache)
364 sc->sc_bg_cache = bg;
365 creator_ras_fifo_wait(sc, 1);
366 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg);
367 creator_ras_wait(sc);
371 creator_ras_setfg(struct creator_softc *sc, int fg)
374 if (fg == sc->sc_fg_cache)
376 sc->sc_fg_cache = fg;
377 creator_ras_fifo_wait(sc, 1);
378 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg);
379 creator_ras_wait(sc);
383 creator_ras_setpmask(struct creator_softc *sc, int pmask)
386 if (pmask == sc->sc_pmask_cache)
388 sc->sc_pmask_cache = pmask;
389 creator_ras_fifo_wait(sc, 1);
390 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask);
391 creator_ras_wait(sc);
395 * video driver interface
398 creator_configure(int flags)
400 struct creator_softc *sc;
405 char buf[sizeof("SUNW,ffb")];
410 * For the high-level console probing return the number of
411 * registered adapters.
413 if (!(flags & VIO_PROBE_ONLY)) {
414 for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++)
419 /* Low-level console probing and initialization. */
422 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
425 if ((chosen = OF_finddevice("/chosen")) == -1)
427 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
429 if ((output = OF_instance_to_package(stdout)) == -1)
431 if (OF_getprop(output, "name", buf, sizeof(buf)) == -1)
433 if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) {
434 sc->sc_flags = CREATOR_CONSOLE;
435 if (strcmp(buf, "SUNW,afb") == 0)
436 sc->sc_flags |= CREATOR_AFB;
437 sc->sc_node = output;
441 for (i = FFB_DAC; i <= FFB_FBC; i++) {
442 if (OF_decode_addr(output, i, &space, &addr) != 0)
444 sc->sc_bt[i] = &creator_bst_store[i - FFB_DAC];
445 sc->sc_bh[i] = sparc64_fake_bustag(space, addr, sc->sc_bt[i]);
448 if (creator_init(0, &sc->sc_va, 0) < 0)
452 /* Return number of found adapters. */
457 creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
464 creator_init(int unit, video_adapter_t *adp, int flags)
466 struct creator_softc *sc;
469 char buf[sizeof("screen-#columns")];
471 sc = (struct creator_softc *)adp;
474 vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit);
476 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
477 sizeof(sc->sc_height)) == -1)
479 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
480 sizeof(sc->sc_width)) == -1)
482 if ((options = OF_finddevice("/options")) == -1)
484 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
486 vi->vi_height = strtol(buf, NULL, 10);
487 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
489 vi->vi_width = strtol(buf, NULL, 10);
490 vi->vi_cwidth = gallant12x22.width;
491 vi->vi_cheight = gallant12x22.height;
492 vi->vi_flags = V_INFO_COLOR;
493 vi->vi_mem_model = V_INFO_MM_OTHER;
495 sc->sc_font = gallant12x22.data;
496 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
497 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
499 creator_set_mode(adp, 0);
501 if (!(sc->sc_flags & CREATOR_AFB)) {
502 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID);
503 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
504 FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) {
505 sc->sc_flags |= CREATOR_PAC1;
506 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL);
507 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
508 FFB_DAC_UCTRL_MANREV) >> 8) <= 2)
509 sc->sc_flags |= CREATOR_CURINV;
513 creator_blank_display(adp, V_DISPLAY_ON);
517 * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode()
518 * (which will invalidate our caches and restore our settings) is
519 * called when the X server shuts down. Otherwise screen corruption
520 * happens most of the time.
522 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER |
524 if (vid_register(adp) < 0)
526 adp->va_flags |= V_ADP_REGISTERED;
532 creator_get_info(video_adapter_t *adp, int mode, video_info_t *info)
535 bcopy(&adp->va_info, info, sizeof(*info));
540 creator_query_mode(video_adapter_t *adp, video_info_t *info)
547 creator_set_mode(video_adapter_t *adp, int mode)
549 struct creator_softc *sc;
551 sc = (struct creator_softc *)adp;
552 sc->sc_bg_cache = -1;
553 sc->sc_fg_cache = -1;
554 sc->sc_fontinc_cache = -1;
555 sc->sc_fontw_cache = -1;
556 sc->sc_pmask_cache = -1;
558 creator_ras_wait(sc);
559 sc->sc_fifo_cache = 0;
560 creator_ras_fifo_wait(sc, 2);
561 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS |
562 FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
563 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A |
564 FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
569 creator_save_font(video_adapter_t *adp, int page, int size, int width,
570 u_char *data, int c, int count)
577 creator_load_font(video_adapter_t *adp, int page, int size, int width,
578 u_char *data, int c, int count)
585 creator_show_font(video_adapter_t *adp, int page)
592 creator_save_palette(video_adapter_t *adp, u_char *palette)
599 creator_load_palette(video_adapter_t *adp, u_char *palette)
606 creator_set_border(video_adapter_t *adp, int border)
608 struct creator_softc *sc;
610 sc = (struct creator_softc *)adp;
611 creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
612 creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
613 sc->sc_width, sc->sc_ymargin);
614 creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
615 creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
616 sc->sc_xmargin, sc->sc_height);
621 creator_save_state(video_adapter_t *adp, void *p, size_t size)
628 creator_load_state(video_adapter_t *adp, void *p)
635 creator_set_win_org(video_adapter_t *adp, off_t offset)
642 creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
651 creator_set_hw_cursor(video_adapter_t *adp, int col, int row)
658 creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
659 int celsize, int blink)
666 creator_blank_display(video_adapter_t *adp, int mode)
668 struct creator_softc *sc;
672 sc = (struct creator_softc *)adp;
673 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
674 v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
677 v |= FFB_DAC_CFG_TGEN_VIDE;
679 case V_DISPLAY_BLANK:
680 case V_DISPLAY_STAND_BY:
681 case V_DISPLAY_SUSPEND:
682 v &= ~FFB_DAC_CFG_TGEN_VIDE;
685 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
686 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v);
687 for (i = 0; i < 10; i++) {
688 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
689 (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
695 creator_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
703 creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
705 struct creator_softc *sc;
706 struct fbcursor *fbc;
709 sc = (struct creator_softc *)adp;
712 fb = (struct fbtype *)data;
713 fb->fb_type = FBTYPE_CREATOR;
714 fb->fb_height = sc->sc_height;
715 fb->fb_width = sc->sc_width;
716 fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0;
719 fbc = (struct fbcursor *)data;
720 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
721 creator_cursor_enable(sc, 0);
722 sc->sc_flags &= ~CREATOR_CUREN;
728 return (fb_commonioctl(adp, cmd, data));
734 creator_clear(video_adapter_t *adp)
736 struct creator_softc *sc;
738 sc = (struct creator_softc *)adp;
739 creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
745 creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
747 struct creator_softc *sc;
749 sc = (struct creator_softc *)adp;
750 creator_ras_setpmask(sc, 0xffffffff);
751 creator_ras_fifo_wait(sc, 2);
752 FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW);
753 FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
754 creator_ras_setfg(sc, creator_cmap[val & 0xf]);
756 * Note that at least the Elite3D cards are sensitive to the order
757 * of operations here.
759 creator_ras_fifo_wait(sc, 4);
760 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y);
761 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x);
762 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy);
763 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx);
764 creator_ras_wait(sc);
769 creator_bitblt(video_adapter_t *adp, ...)
776 creator_diag(video_adapter_t *adp, int level)
780 fb_dump_adp_info(adp->va_name, adp, level);
781 creator_get_info(adp, 0, &info);
782 fb_dump_mode_info(adp->va_name, adp, &info, level);
787 creator_save_cursor_palette(video_adapter_t *adp, u_char *palette)
794 creator_load_cursor_palette(video_adapter_t *adp, u_char *palette)
801 creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
808 creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a,
809 int size, int bpp, int bit_ltor, int byte_ltor)
816 creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a)
818 struct creator_softc *sc;
824 sc = (struct creator_softc *)adp;
825 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
826 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
827 p = (const uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight);
828 creator_ras_setfg(sc, creator_cmap[a & 0xf]);
829 creator_ras_setbg(sc, creator_cmap[(a >> 4) & 0xf]);
830 creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight);
831 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY,
832 ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin));
833 creator_ras_setfontw(sc, adp->va_info.vi_cwidth);
834 creator_ras_setfontinc(sc, 0x10000);
835 for (i = 0; i < adp->va_info.vi_cheight; i++) {
836 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16);
842 creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
846 for (i = 0; i < len; i++) {
847 vidd_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
854 creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
855 u_int32_t pixel_mask, int size, int width)
857 struct creator_softc *sc;
859 sc = (struct creator_softc *)adp;
860 if (!(sc->sc_flags & CREATOR_CUREN)) {
861 creator_cursor_install(sc);
862 creator_cursor_enable(sc, 1);
863 sc->sc_flags |= CREATOR_CUREN;
865 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS);
866 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
867 ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin));
875 creator_bus_probe(device_t dev)
881 name = ofw_bus_get_name(dev);
882 node = ofw_bus_get_node(dev);
883 if (strcmp(name, "SUNW,ffb") == 0) {
884 if (OF_getprop(node, "board_type", &type, sizeof(type)) == -1)
888 device_set_desc(dev, "Creator");
891 device_set_desc(dev, "Creator3D");
896 } else if (strcmp(name, "SUNW,afb") == 0)
897 device_set_desc(dev, "Elite3D");
900 return (BUS_PROBE_DEFAULT);
904 creator_bus_attach(device_t dev)
906 struct creator_softc *sc;
907 video_adapter_t *adp;
915 node = ofw_bus_get_node(dev);
916 if ((sc = (struct creator_softc *)vid_get_adapter(vid_find_adapter(
917 CREATOR_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
918 device_printf(dev, "console\n");
919 device_set_softc(dev, sc);
921 sc = device_get_softc(dev);
927 * Allocate resources regardless of whether we are the console
928 * and already obtained the bus tags and handles for the FFB_DAC
929 * and FFB_FBC register banks in creator_configure() or not so
930 * the resources are marked as taken in the respective RMAN.
931 * The supported cards use either 15 (Creator, Elite3D?) or 24
932 * (Creator3D?) register banks. We make sure that we can also
933 * allocate the resources for at least the FFB_DAC and FFB_FBC
934 * banks here. We try but don't actually care whether we can
935 * allocate more than these two resources and just limit the
936 * range accessible via creator_fb_mmap() accordingly.
938 for (i = 0; i < FFB_NREG; i++) {
940 sc->sc_reg[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
942 if (sc->sc_reg[i] == NULL) {
945 "cannot allocate resources\n");
951 sc->sc_bt[i] = rman_get_bustag(sc->sc_reg[i]);
952 sc->sc_bh[i] = rman_get_bushandle(sc->sc_reg[i]);
955 * The XFree86/X.Org sunffb(4) expects to be able to access the
956 * memory spanned by the first and the last resource as one chunk
957 * via creator_fb_mmap(), using offsets from the first resource,
958 * even though the backing resources are actually non-continuous.
959 * So make sure that the memory we provide is at least backed by
960 * increasing resources.
962 for (i = 1; i < FFB_NREG && sc->sc_reg[i] != NULL &&
963 rman_get_start(sc->sc_reg[i]) > rman_get_start(sc->sc_reg[i - 1]);
966 sc->sc_reg_size = rman_get_end(sc->sc_reg[i - 1]) -
967 rman_get_start(sc->sc_reg[0]) + 1;
969 if (!(sc->sc_flags & CREATOR_CONSOLE)) {
970 if ((sw = vid_get_switch(CREATOR_DRIVER_NAME)) == NULL) {
971 device_printf(dev, "cannot get video switch\n");
976 * During device configuration we don't necessarily probe
977 * the adapter which is the console first so we can't use
978 * the device unit number for the video adapter unit. The
979 * worst case would be that we use the video adapter unit
980 * 0 twice. As it doesn't really matter which unit number
981 * the corresponding video adapter has just use the next
984 for (i = 0; i < devclass_get_maxunit(creator_devclass); i++)
985 if (vid_find_adapter(CREATOR_DRIVER_NAME, i) < 0)
987 if (strcmp(ofw_bus_get_name(dev), "SUNW,afb") == 0)
988 sc->sc_flags |= CREATOR_AFB;
989 if ((error = sw->init(i, adp, 0)) != 0) {
990 device_printf(dev, "cannot initialize adapter\n");
996 if (sc->sc_flags & CREATOR_PAC1)
998 "BT9068/PAC1 RAMDAC (%s cursor control)\n",
999 sc->sc_flags & CREATOR_CURINV ? "inverted" :
1002 device_printf(dev, "BT498/PAC2 RAMDAC\n");
1004 device_printf(dev, "resolution %dx%d\n", sc->sc_width, sc->sc_height);
1006 unit = device_get_unit(dev);
1007 sc->sc_si = make_dev(&creator_fb_devsw, unit, UID_ROOT, GID_WHEEL,
1008 0600, "fb%d", unit);
1009 sc->sc_si->si_drv1 = sc;
1011 EVENTHANDLER_REGISTER(shutdown_final, creator_shutdown, sc,
1012 SHUTDOWN_PRI_DEFAULT);
1017 for (i = 0; i < FFB_NREG && sc->sc_reg[i] != NULL; i++)
1018 bus_release_resource(dev, SYS_RES_MEMORY,
1019 rman_get_rid(sc->sc_reg[i]), sc->sc_reg[i]);
1027 creator_fb_open(struct cdev *dev, int flags, int mode, struct thread *td)
1034 creator_fb_close(struct cdev *dev, int flags, int mode, struct thread *td)
1041 creator_fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
1044 struct creator_softc *sc;
1047 return (creator_ioctl(&sc->sc_va, cmd, data));
1051 creator_fb_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
1054 struct creator_softc *sc;
1058 * NB: This is a special implementation based on the /dev/fb
1059 * requirements of the XFree86/X.Org sunffb(4).
1062 for (i = 0; i < CREATOR_FB_MAP_SIZE; i++) {
1063 if (offset >= creator_fb_map[i].virt &&
1064 offset < creator_fb_map[i].virt + creator_fb_map[i].size) {
1065 offset += creator_fb_map[i].phys -
1066 creator_fb_map[i].virt;
1067 if (offset >= sc->sc_reg_size)
1069 *paddr = sc->sc_bh[0] + offset;
1077 * internal functions
1080 creator_cursor_enable(struct creator_softc *sc, int onoff)
1084 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_CTRL);
1085 if (sc->sc_flags & CREATOR_CURINV)
1086 v = onoff ? FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1 : 0;
1088 v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1;
1089 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v);
1093 creator_cursor_install(struct creator_softc *sc)
1097 creator_cursor_enable(sc, 0);
1098 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_COLOR1);
1099 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0xffffff);
1100 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0x0);
1101 for (i = 0; i < 2; i++) {
1102 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2,
1103 i ? FFB_DAC_CUR_BITMAP_P0 : FFB_DAC_CUR_BITMAP_P1);
1104 for (j = 0; j < 64; j++) {
1105 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
1106 *(const uint32_t *)(&creator_mouse_pointer[j][0]));
1107 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
1108 *(const uint32_t *)(&creator_mouse_pointer[j][4]));
1114 creator_shutdown(void *xsc)
1116 struct creator_softc *sc = xsc;
1118 creator_cursor_enable(sc, 0);
1120 * In case this is the console set the cursor of the stdout
1121 * instance to the start of the last line so OFW output ends
1122 * up beneath what FreeBSD left on the screen.
1124 if (sc->sc_flags & CREATOR_CONSOLE) {
1125 OF_interpret("stdout @ is my-self 0 to column#", 0);
1126 OF_interpret("stdout @ is my-self #lines 1 - to line#", 0);