2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2003 Jake Burkholder.
5 * Copyright (c) 2005 - 2006 Marius Strobl <marius@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
37 #include <sys/consio.h>
38 #include <sys/eventhandler.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/resource.h>
44 #include <dev/ofw/ofw_bus.h>
45 #include <dev/ofw/openfirm.h>
47 #include <machine/bus.h>
48 #include <machine/bus_private.h>
49 #include <machine/ofw_machdep.h>
50 #include <machine/resource.h>
51 #include <machine/sc_machdep.h>
55 #include <dev/fb/fbreg.h>
56 #include <dev/fb/creatorreg.h>
57 #include <dev/fb/gfb.h>
58 #include <dev/syscons/syscons.h>
60 #define CREATOR_DRIVER_NAME "creator"
62 struct creator_softc {
63 video_adapter_t sc_va; /* XXX must be first */
69 struct resource *sc_reg[FFB_NREG];
70 bus_space_tag_t sc_bt[FFB_NREG];
71 bus_space_handle_t sc_bh[FFB_NREG];
80 const u_char *sc_font;
90 #define CREATOR_AFB (1 << 0)
91 #define CREATOR_CONSOLE (1 << 1)
92 #define CREATOR_CUREN (1 << 2)
93 #define CREATOR_CURINV (1 << 3)
94 #define CREATOR_PAC1 (1 << 4)
97 #define FFB_READ(sc, reg, off) \
98 bus_space_read_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off))
99 #define FFB_WRITE(sc, reg, off, val) \
100 bus_space_write_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off), (val))
102 #define C(r, g, b) ((b << 16) | (g << 8) | (r))
103 static const uint32_t creator_cmap[] = {
104 C(0x00, 0x00, 0x00), /* black */
105 C(0x00, 0x00, 0xff), /* blue */
106 C(0x00, 0xff, 0x00), /* green */
107 C(0x00, 0xc0, 0xc0), /* cyan */
108 C(0xff, 0x00, 0x00), /* red */
109 C(0xc0, 0x00, 0xc0), /* magenta */
110 C(0xc0, 0xc0, 0x00), /* brown */
111 C(0xc0, 0xc0, 0xc0), /* light grey */
112 C(0x80, 0x80, 0x80), /* dark grey */
113 C(0x80, 0x80, 0xff), /* light blue */
114 C(0x80, 0xff, 0x80), /* light green */
115 C(0x80, 0xff, 0xff), /* light cyan */
116 C(0xff, 0x80, 0x80), /* light red */
117 C(0xff, 0x80, 0xff), /* light magenta */
118 C(0xff, 0xff, 0x80), /* yellow */
119 C(0xff, 0xff, 0xff), /* white */
123 static const struct {
127 } creator_fb_map[] = {
128 { FFB_VIRT_SFB8R, FFB_PHYS_SFB8R, FFB_SIZE_SFB8R },
129 { FFB_VIRT_SFB8G, FFB_PHYS_SFB8G, FFB_SIZE_SFB8G },
130 { FFB_VIRT_SFB8B, FFB_PHYS_SFB8B, FFB_SIZE_SFB8B },
131 { FFB_VIRT_SFB8X, FFB_PHYS_SFB8X, FFB_SIZE_SFB8X },
132 { FFB_VIRT_SFB32, FFB_PHYS_SFB32, FFB_SIZE_SFB32 },
133 { FFB_VIRT_SFB64, FFB_PHYS_SFB64, FFB_SIZE_SFB64 },
134 { FFB_VIRT_FBC, FFB_PHYS_FBC, FFB_SIZE_FBC },
135 { FFB_VIRT_FBC_BM, FFB_PHYS_FBC_BM, FFB_SIZE_FBC_BM },
136 { FFB_VIRT_DFB8R, FFB_PHYS_DFB8R, FFB_SIZE_DFB8R },
137 { FFB_VIRT_DFB8G, FFB_PHYS_DFB8G, FFB_SIZE_DFB8G },
138 { FFB_VIRT_DFB8B, FFB_PHYS_DFB8B, FFB_SIZE_DFB8B },
139 { FFB_VIRT_DFB8X, FFB_PHYS_DFB8X, FFB_SIZE_DFB8X },
140 { FFB_VIRT_DFB24, FFB_PHYS_DFB24, FFB_SIZE_DFB24 },
141 { FFB_VIRT_DFB32, FFB_PHYS_DFB32, FFB_SIZE_DFB32 },
142 { FFB_VIRT_DFB422A, FFB_PHYS_DFB422A, FFB_SIZE_DFB422A },
143 { FFB_VIRT_DFB422AD, FFB_PHYS_DFB422AD, FFB_SIZE_DFB422AD },
144 { FFB_VIRT_DFB24B, FFB_PHYS_DFB24B, FFB_SIZE_DFB24B },
145 { FFB_VIRT_DFB422B, FFB_PHYS_DFB422B, FFB_SIZE_DFB422B },
146 { FFB_VIRT_DFB422BD, FFB_PHYS_DFB422BD, FFB_SIZE_DFB422BD },
147 { FFB_VIRT_SFB16Z, FFB_PHYS_SFB16Z, FFB_SIZE_SFB16Z },
148 { FFB_VIRT_SFB8Z, FFB_PHYS_SFB8Z, FFB_SIZE_SFB8Z },
149 { FFB_VIRT_SFB422, FFB_PHYS_SFB422, FFB_SIZE_SFB422 },
150 { FFB_VIRT_SFB422D, FFB_PHYS_SFB422D, FFB_SIZE_SFB422D },
151 { FFB_VIRT_FBC_KREG, FFB_PHYS_FBC_KREG, FFB_SIZE_FBC_KREG },
152 { FFB_VIRT_DAC, FFB_PHYS_DAC, FFB_SIZE_DAC },
153 { FFB_VIRT_PROM, FFB_PHYS_PROM, FFB_SIZE_PROM },
154 { FFB_VIRT_EXP, FFB_PHYS_EXP, FFB_SIZE_EXP },
157 #define CREATOR_FB_MAP_SIZE nitems(creator_fb_map)
159 extern const struct gfb_font gallant12x22;
161 static struct creator_softc creator_softc;
162 static struct bus_space_tag creator_bst_store[FFB_FBC];
164 static device_probe_t creator_bus_probe;
165 static device_attach_t creator_bus_attach;
167 static device_method_t creator_bus_methods[] = {
168 DEVMETHOD(device_probe, creator_bus_probe),
169 DEVMETHOD(device_attach, creator_bus_attach),
174 static devclass_t creator_devclass;
176 DEFINE_CLASS_0(creator, creator_bus_driver, creator_bus_methods,
177 sizeof(struct creator_softc));
178 DRIVER_MODULE(creator, nexus, creator_bus_driver, creator_devclass, 0, 0);
179 DRIVER_MODULE(creator, upa, creator_bus_driver, creator_devclass, 0, 0);
181 static d_open_t creator_fb_open;
182 static d_close_t creator_fb_close;
183 static d_ioctl_t creator_fb_ioctl;
184 static d_mmap_t creator_fb_mmap;
186 static struct cdevsw creator_fb_devsw = {
187 .d_version = D_VERSION,
188 .d_flags = D_NEEDGIANT,
189 .d_open = creator_fb_open,
190 .d_close = creator_fb_close,
191 .d_ioctl = creator_fb_ioctl,
192 .d_mmap = creator_fb_mmap,
196 static void creator_cursor_enable(struct creator_softc *sc, int onoff);
197 static void creator_cursor_install(struct creator_softc *sc);
198 static void creator_shutdown(void *xsc);
200 static int creator_configure(int flags);
202 static vi_probe_t creator_probe;
203 static vi_init_t creator_init;
204 static vi_get_info_t creator_get_info;
205 static vi_query_mode_t creator_query_mode;
206 static vi_set_mode_t creator_set_mode;
207 static vi_save_font_t creator_save_font;
208 static vi_load_font_t creator_load_font;
209 static vi_show_font_t creator_show_font;
210 static vi_save_palette_t creator_save_palette;
211 static vi_load_palette_t creator_load_palette;
212 static vi_set_border_t creator_set_border;
213 static vi_save_state_t creator_save_state;
214 static vi_load_state_t creator_load_state;
215 static vi_set_win_org_t creator_set_win_org;
216 static vi_read_hw_cursor_t creator_read_hw_cursor;
217 static vi_set_hw_cursor_t creator_set_hw_cursor;
218 static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape;
219 static vi_blank_display_t creator_blank_display;
220 static vi_mmap_t creator_mmap;
221 static vi_ioctl_t creator_ioctl;
222 static vi_clear_t creator_clear;
223 static vi_fill_rect_t creator_fill_rect;
224 static vi_bitblt_t creator_bitblt;
225 static vi_diag_t creator_diag;
226 static vi_save_cursor_palette_t creator_save_cursor_palette;
227 static vi_load_cursor_palette_t creator_load_cursor_palette;
228 static vi_copy_t creator_copy;
229 static vi_putp_t creator_putp;
230 static vi_putc_t creator_putc;
231 static vi_puts_t creator_puts;
232 static vi_putm_t creator_putm;
234 static video_switch_t creatorvidsw = {
235 .probe = creator_probe,
236 .init = creator_init,
237 .get_info = creator_get_info,
238 .query_mode = creator_query_mode,
239 .set_mode = creator_set_mode,
240 .save_font = creator_save_font,
241 .load_font = creator_load_font,
242 .show_font = creator_show_font,
243 .save_palette = creator_save_palette,
244 .load_palette = creator_load_palette,
245 .set_border = creator_set_border,
246 .save_state = creator_save_state,
247 .load_state = creator_load_state,
248 .set_win_org = creator_set_win_org,
249 .read_hw_cursor = creator_read_hw_cursor,
250 .set_hw_cursor = creator_set_hw_cursor,
251 .set_hw_cursor_shape = creator_set_hw_cursor_shape,
252 .blank_display = creator_blank_display,
253 .mmap = creator_mmap,
254 .ioctl = creator_ioctl,
255 .clear = creator_clear,
256 .fill_rect = creator_fill_rect,
257 .bitblt = creator_bitblt,
258 .diag = creator_diag,
259 .save_cursor_palette = creator_save_cursor_palette,
260 .load_cursor_palette = creator_load_cursor_palette,
261 .copy = creator_copy,
262 .putp = creator_putp,
263 .putc = creator_putc,
264 .puts = creator_puts,
268 VIDEO_DRIVER(creator, creatorvidsw, creator_configure);
270 extern sc_rndr_sw_t txtrndrsw;
271 RENDERER(creator, 0, txtrndrsw, gfb_set);
273 RENDERER_MODULE(creator, gfb_set);
275 static const u_char creator_mouse_pointer[64][8] __aligned(8) = {
276 { 0x00, 0x00, }, /* ............ */
277 { 0x80, 0x00, }, /* *........... */
278 { 0xc0, 0x00, }, /* **.......... */
279 { 0xe0, 0x00, }, /* ***......... */
280 { 0xf0, 0x00, }, /* ****........ */
281 { 0xf8, 0x00, }, /* *****....... */
282 { 0xfc, 0x00, }, /* ******...... */
283 { 0xfe, 0x00, }, /* *******..... */
284 { 0xff, 0x00, }, /* ********.... */
285 { 0xff, 0x80, }, /* *********... */
286 { 0xfc, 0xc0, }, /* ******..**.. */
287 { 0xdc, 0x00, }, /* **.***...... */
288 { 0x8e, 0x00, }, /* *...***..... */
289 { 0x0e, 0x00, }, /* ....***..... */
290 { 0x07, 0x00, }, /* .....***.... */
291 { 0x04, 0x00, }, /* .....*...... */
292 { 0x00, 0x00, }, /* ............ */
293 { 0x00, 0x00, }, /* ............ */
294 { 0x00, 0x00, }, /* ............ */
295 { 0x00, 0x00, }, /* ............ */
296 { 0x00, 0x00, }, /* ............ */
297 { 0x00, 0x00, }, /* ............ */
300 static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n);
301 static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc);
302 static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw);
303 static inline void creator_ras_setbg(struct creator_softc *sc, int bg);
304 static inline void creator_ras_setfg(struct creator_softc *sc, int fg);
305 static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask);
306 static inline void creator_ras_wait(struct creator_softc *sc);
309 creator_ras_wait(struct creator_softc *sc)
315 ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR);
316 if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0)
318 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
320 FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r);
325 creator_ras_fifo_wait(struct creator_softc *sc, int n)
329 cache = sc->sc_fifo_cache;
331 cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) &
332 FBC_UCSR_FIFO_MASK) - 8;
333 sc->sc_fifo_cache = cache - n;
337 creator_ras_setfontinc(struct creator_softc *sc, int fontinc)
340 if (fontinc == sc->sc_fontinc_cache)
342 sc->sc_fontinc_cache = fontinc;
343 creator_ras_fifo_wait(sc, 1);
344 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc);
345 creator_ras_wait(sc);
349 creator_ras_setfontw(struct creator_softc *sc, int fontw)
352 if (fontw == sc->sc_fontw_cache)
354 sc->sc_fontw_cache = fontw;
355 creator_ras_fifo_wait(sc, 1);
356 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw);
357 creator_ras_wait(sc);
361 creator_ras_setbg(struct creator_softc *sc, int bg)
364 if (bg == sc->sc_bg_cache)
366 sc->sc_bg_cache = bg;
367 creator_ras_fifo_wait(sc, 1);
368 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg);
369 creator_ras_wait(sc);
373 creator_ras_setfg(struct creator_softc *sc, int fg)
376 if (fg == sc->sc_fg_cache)
378 sc->sc_fg_cache = fg;
379 creator_ras_fifo_wait(sc, 1);
380 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg);
381 creator_ras_wait(sc);
385 creator_ras_setpmask(struct creator_softc *sc, int pmask)
388 if (pmask == sc->sc_pmask_cache)
390 sc->sc_pmask_cache = pmask;
391 creator_ras_fifo_wait(sc, 1);
392 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask);
393 creator_ras_wait(sc);
397 * video driver interface
400 creator_configure(int flags)
402 struct creator_softc *sc;
407 char buf[sizeof("SUNW,ffb")];
412 * For the high-level console probing return the number of
413 * registered adapters.
415 if (!(flags & VIO_PROBE_ONLY)) {
416 for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++)
421 /* Low-level console probing and initialization. */
424 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
427 if ((chosen = OF_finddevice("/chosen")) == -1)
429 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
431 if ((output = OF_instance_to_package(stdout)) == -1)
433 if (OF_getprop(output, "name", buf, sizeof(buf)) == -1)
435 if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) {
436 sc->sc_flags = CREATOR_CONSOLE;
437 if (strcmp(buf, "SUNW,afb") == 0)
438 sc->sc_flags |= CREATOR_AFB;
439 sc->sc_node = output;
443 for (i = FFB_DAC; i <= FFB_FBC; i++) {
444 if (OF_decode_addr(output, i, &space, &addr) != 0)
446 sc->sc_bt[i] = &creator_bst_store[i - FFB_DAC];
447 sc->sc_bh[i] = sparc64_fake_bustag(space, addr, sc->sc_bt[i]);
450 if (creator_init(0, &sc->sc_va, 0) < 0)
454 /* Return number of found adapters. */
459 creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
466 creator_init(int unit, video_adapter_t *adp, int flags)
468 struct creator_softc *sc;
471 char buf[sizeof("screen-#columns")];
473 sc = (struct creator_softc *)adp;
476 vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit);
478 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
479 sizeof(sc->sc_height)) == -1)
481 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
482 sizeof(sc->sc_width)) == -1)
484 if ((options = OF_finddevice("/options")) == -1)
486 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
488 vi->vi_height = strtol(buf, NULL, 10);
489 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
491 vi->vi_width = strtol(buf, NULL, 10);
492 vi->vi_cwidth = gallant12x22.width;
493 vi->vi_cheight = gallant12x22.height;
494 vi->vi_flags = V_INFO_COLOR;
495 vi->vi_mem_model = V_INFO_MM_OTHER;
497 sc->sc_font = gallant12x22.data;
498 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
499 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
501 creator_set_mode(adp, 0);
503 if (!(sc->sc_flags & CREATOR_AFB)) {
504 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID);
505 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
506 FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) {
507 sc->sc_flags |= CREATOR_PAC1;
508 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL);
509 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
510 FFB_DAC_UCTRL_MANREV) >> 8) <= 2)
511 sc->sc_flags |= CREATOR_CURINV;
515 creator_blank_display(adp, V_DISPLAY_ON);
519 * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode()
520 * (which will invalidate our caches and restore our settings) is
521 * called when the X server shuts down. Otherwise screen corruption
522 * happens most of the time.
524 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER |
526 if (vid_register(adp) < 0)
528 adp->va_flags |= V_ADP_REGISTERED;
534 creator_get_info(video_adapter_t *adp, int mode, video_info_t *info)
537 bcopy(&adp->va_info, info, sizeof(*info));
542 creator_query_mode(video_adapter_t *adp, video_info_t *info)
549 creator_set_mode(video_adapter_t *adp, int mode)
551 struct creator_softc *sc;
553 sc = (struct creator_softc *)adp;
554 sc->sc_bg_cache = -1;
555 sc->sc_fg_cache = -1;
556 sc->sc_fontinc_cache = -1;
557 sc->sc_fontw_cache = -1;
558 sc->sc_pmask_cache = -1;
560 creator_ras_wait(sc);
561 sc->sc_fifo_cache = 0;
562 creator_ras_fifo_wait(sc, 2);
563 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS |
564 FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
565 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A |
566 FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
571 creator_save_font(video_adapter_t *adp, int page, int size, int width,
572 u_char *data, int c, int count)
579 creator_load_font(video_adapter_t *adp, int page, int size, int width,
580 u_char *data, int c, int count)
587 creator_show_font(video_adapter_t *adp, int page)
594 creator_save_palette(video_adapter_t *adp, u_char *palette)
601 creator_load_palette(video_adapter_t *adp, u_char *palette)
608 creator_set_border(video_adapter_t *adp, int border)
610 struct creator_softc *sc;
612 sc = (struct creator_softc *)adp;
613 creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
614 creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
615 sc->sc_width, sc->sc_ymargin);
616 creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
617 creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
618 sc->sc_xmargin, sc->sc_height);
623 creator_save_state(video_adapter_t *adp, void *p, size_t size)
630 creator_load_state(video_adapter_t *adp, void *p)
637 creator_set_win_org(video_adapter_t *adp, off_t offset)
644 creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
653 creator_set_hw_cursor(video_adapter_t *adp, int col, int row)
660 creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
661 int celsize, int blink)
668 creator_blank_display(video_adapter_t *adp, int mode)
670 struct creator_softc *sc;
674 sc = (struct creator_softc *)adp;
675 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
676 v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
679 v |= FFB_DAC_CFG_TGEN_VIDE;
681 case V_DISPLAY_BLANK:
682 case V_DISPLAY_STAND_BY:
683 case V_DISPLAY_SUSPEND:
684 v &= ~FFB_DAC_CFG_TGEN_VIDE;
687 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
688 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v);
689 for (i = 0; i < 10; i++) {
690 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
691 (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
697 creator_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
698 int prot, vm_memattr_t *memattr)
705 creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
707 struct creator_softc *sc;
708 struct fbcursor *fbc;
711 sc = (struct creator_softc *)adp;
714 fb = (struct fbtype *)data;
715 fb->fb_type = FBTYPE_CREATOR;
716 fb->fb_height = sc->sc_height;
717 fb->fb_width = sc->sc_width;
718 fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0;
721 fbc = (struct fbcursor *)data;
722 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
723 creator_cursor_enable(sc, 0);
724 sc->sc_flags &= ~CREATOR_CUREN;
730 return (fb_commonioctl(adp, cmd, data));
736 creator_clear(video_adapter_t *adp)
738 struct creator_softc *sc;
740 sc = (struct creator_softc *)adp;
741 creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
747 creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
749 struct creator_softc *sc;
751 sc = (struct creator_softc *)adp;
752 creator_ras_setpmask(sc, 0xffffffff);
753 creator_ras_fifo_wait(sc, 2);
754 FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW);
755 FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
756 creator_ras_setfg(sc, creator_cmap[val & 0xf]);
758 * Note that at least the Elite3D cards are sensitive to the order
759 * of operations here.
761 creator_ras_fifo_wait(sc, 4);
762 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y);
763 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x);
764 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy);
765 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx);
766 creator_ras_wait(sc);
771 creator_bitblt(video_adapter_t *adp, ...)
778 creator_diag(video_adapter_t *adp, int level)
782 fb_dump_adp_info(adp->va_name, adp, level);
783 creator_get_info(adp, 0, &info);
784 fb_dump_mode_info(adp->va_name, adp, &info, level);
789 creator_save_cursor_palette(video_adapter_t *adp, u_char *palette)
796 creator_load_cursor_palette(video_adapter_t *adp, u_char *palette)
803 creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
810 creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a,
811 int size, int bpp, int bit_ltor, int byte_ltor)
818 creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a)
820 struct creator_softc *sc;
826 sc = (struct creator_softc *)adp;
827 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
828 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
829 p = (const uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight);
830 creator_ras_setfg(sc, creator_cmap[a & 0xf]);
831 creator_ras_setbg(sc, creator_cmap[(a >> 4) & 0xf]);
832 creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight);
833 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY,
834 ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin));
835 creator_ras_setfontw(sc, adp->va_info.vi_cwidth);
836 creator_ras_setfontinc(sc, 0x10000);
837 for (i = 0; i < adp->va_info.vi_cheight; i++) {
838 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16);
844 creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
848 for (i = 0; i < len; i++) {
849 vidd_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
856 creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
857 u_int32_t pixel_mask, int size, int width)
859 struct creator_softc *sc;
861 sc = (struct creator_softc *)adp;
862 if (!(sc->sc_flags & CREATOR_CUREN)) {
863 creator_cursor_install(sc);
864 creator_cursor_enable(sc, 1);
865 sc->sc_flags |= CREATOR_CUREN;
867 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS);
868 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
869 ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin));
877 creator_bus_probe(device_t dev)
883 name = ofw_bus_get_name(dev);
884 node = ofw_bus_get_node(dev);
885 if (strcmp(name, "SUNW,ffb") == 0) {
886 if (OF_getprop(node, "board_type", &type, sizeof(type)) == -1)
890 device_set_desc(dev, "Creator");
893 device_set_desc(dev, "Creator3D");
898 } else if (strcmp(name, "SUNW,afb") == 0)
899 device_set_desc(dev, "Elite3D");
902 return (BUS_PROBE_DEFAULT);
906 creator_bus_attach(device_t dev)
908 struct creator_softc *sc;
909 video_adapter_t *adp;
917 node = ofw_bus_get_node(dev);
918 if ((sc = (struct creator_softc *)vid_get_adapter(vid_find_adapter(
919 CREATOR_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
920 device_printf(dev, "console\n");
921 device_set_softc(dev, sc);
923 sc = device_get_softc(dev);
929 * Allocate resources regardless of whether we are the console
930 * and already obtained the bus tags and handles for the FFB_DAC
931 * and FFB_FBC register banks in creator_configure() or not so
932 * the resources are marked as taken in the respective RMAN.
933 * The supported cards use either 15 (Creator, Elite3D?) or 24
934 * (Creator3D?) register banks. We make sure that we can also
935 * allocate the resources for at least the FFB_DAC and FFB_FBC
936 * banks here. We try but don't actually care whether we can
937 * allocate more than these two resources and just limit the
938 * range accessible via creator_fb_mmap() accordingly.
940 for (i = 0; i < FFB_NREG; i++) {
942 sc->sc_reg[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
944 if (sc->sc_reg[i] == NULL) {
947 "cannot allocate resources\n");
953 sc->sc_bt[i] = rman_get_bustag(sc->sc_reg[i]);
954 sc->sc_bh[i] = rman_get_bushandle(sc->sc_reg[i]);
957 * The XFree86/X.Org sunffb(4) expects to be able to access the
958 * memory spanned by the first and the last resource as one chunk
959 * via creator_fb_mmap(), using offsets from the first resource,
960 * even though the backing resources are actually non-continuous.
961 * So make sure that the memory we provide is at least backed by
962 * increasing resources.
964 for (i = 1; i < FFB_NREG && sc->sc_reg[i] != NULL &&
965 rman_get_start(sc->sc_reg[i]) > rman_get_start(sc->sc_reg[i - 1]);
968 sc->sc_reg_size = rman_get_end(sc->sc_reg[i - 1]) -
969 rman_get_start(sc->sc_reg[0]) + 1;
971 if (!(sc->sc_flags & CREATOR_CONSOLE)) {
972 if ((sw = vid_get_switch(CREATOR_DRIVER_NAME)) == NULL) {
973 device_printf(dev, "cannot get video switch\n");
978 * During device configuration we don't necessarily probe
979 * the adapter which is the console first so we can't use
980 * the device unit number for the video adapter unit. The
981 * worst case would be that we use the video adapter unit
982 * 0 twice. As it doesn't really matter which unit number
983 * the corresponding video adapter has just use the next
986 for (i = 0; i < devclass_get_maxunit(creator_devclass); i++)
987 if (vid_find_adapter(CREATOR_DRIVER_NAME, i) < 0)
989 if (strcmp(ofw_bus_get_name(dev), "SUNW,afb") == 0)
990 sc->sc_flags |= CREATOR_AFB;
991 if ((error = sw->init(i, adp, 0)) != 0) {
992 device_printf(dev, "cannot initialize adapter\n");
998 if (sc->sc_flags & CREATOR_PAC1)
1000 "BT9068/PAC1 RAMDAC (%s cursor control)\n",
1001 sc->sc_flags & CREATOR_CURINV ? "inverted" :
1004 device_printf(dev, "BT498/PAC2 RAMDAC\n");
1006 device_printf(dev, "resolution %dx%d\n", sc->sc_width, sc->sc_height);
1008 unit = device_get_unit(dev);
1009 sc->sc_si = make_dev(&creator_fb_devsw, unit, UID_ROOT, GID_WHEEL,
1010 0600, "fb%d", unit);
1011 sc->sc_si->si_drv1 = sc;
1013 EVENTHANDLER_REGISTER(shutdown_final, creator_shutdown, sc,
1014 SHUTDOWN_PRI_DEFAULT);
1019 for (i = 0; i < FFB_NREG && sc->sc_reg[i] != NULL; i++)
1020 bus_release_resource(dev, SYS_RES_MEMORY,
1021 rman_get_rid(sc->sc_reg[i]), sc->sc_reg[i]);
1029 creator_fb_open(struct cdev *dev, int flags, int mode, struct thread *td)
1036 creator_fb_close(struct cdev *dev, int flags, int mode, struct thread *td)
1043 creator_fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
1046 struct creator_softc *sc;
1049 return (creator_ioctl(&sc->sc_va, cmd, data));
1053 creator_fb_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
1054 int prot, vm_memattr_t *memattr)
1056 struct creator_softc *sc;
1060 * NB: This is a special implementation based on the /dev/fb
1061 * requirements of the XFree86/X.Org sunffb(4).
1064 for (i = 0; i < CREATOR_FB_MAP_SIZE; i++) {
1065 if (offset >= creator_fb_map[i].virt &&
1066 offset < creator_fb_map[i].virt + creator_fb_map[i].size) {
1067 offset += creator_fb_map[i].phys -
1068 creator_fb_map[i].virt;
1069 if (offset >= sc->sc_reg_size)
1071 *paddr = sc->sc_bh[0] + offset;
1079 * internal functions
1082 creator_cursor_enable(struct creator_softc *sc, int onoff)
1086 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_CTRL);
1087 if (sc->sc_flags & CREATOR_CURINV)
1088 v = onoff ? FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1 : 0;
1090 v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1;
1091 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v);
1095 creator_cursor_install(struct creator_softc *sc)
1099 creator_cursor_enable(sc, 0);
1100 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_COLOR1);
1101 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0xffffff);
1102 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, 0x0);
1103 for (i = 0; i < 2; i++) {
1104 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2,
1105 i ? FFB_DAC_CUR_BITMAP_P0 : FFB_DAC_CUR_BITMAP_P1);
1106 for (j = 0; j < 64; j++) {
1107 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
1108 *(const uint32_t *)(&creator_mouse_pointer[j][0]));
1109 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
1110 *(const uint32_t *)(&creator_mouse_pointer[j][4]));
1116 creator_shutdown(void *xsc)
1118 struct creator_softc *sc = xsc;
1120 creator_cursor_enable(sc, 0);
1122 * In case this is the console set the cursor of the stdout
1123 * instance to the start of the last line so OFW output ends
1124 * up beneath what FreeBSD left on the screen.
1126 if (sc->sc_flags & CREATOR_CONSOLE) {
1127 OF_interpret("stdout @ is my-self 0 to column#", 0);
1128 OF_interpret("stdout @ is my-self #lines 1 - to line#", 0);