Deleted Added
full compact
creator.c (167308) creator.c (170840)
1/*-
2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2005 - 2006 Marius Strobl <marius@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Jake Burkholder.
3 * Copyright (c) 2005 - 2006 Marius Strobl <marius@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/dev/fb/creator.c 167308 2007-03-07 21:13:51Z marius $");
29__FBSDID("$FreeBSD: head/sys/dev/fb/creator.c 170840 2007-06-16 21:48:50Z marius $");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34#include <sys/conf.h>
35#include <sys/consio.h>
36#include <sys/fbio.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/resource.h>
40
41#include <dev/ofw/ofw_bus.h>
42#include <dev/ofw/openfirm.h>
43
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>
49
50#include <sys/rman.h>
51
52#include <dev/fb/fbreg.h>
53#include <dev/fb/creatorreg.h>
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34#include <sys/conf.h>
35#include <sys/consio.h>
36#include <sys/fbio.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/resource.h>
40
41#include <dev/ofw/ofw_bus.h>
42#include <dev/ofw/openfirm.h>
43
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>
49
50#include <sys/rman.h>
51
52#include <dev/fb/fbreg.h>
53#include <dev/fb/creatorreg.h>
54#include <dev/fb/gallant12x22.h>
54#include <dev/fb/gfb.h>
55#include <dev/syscons/syscons.h>
56
57#define CREATOR_DRIVER_NAME "creator"
58
59struct creator_softc {
60 video_adapter_t sc_va; /* XXX must be first */
61
62 phandle_t sc_node;
63
64 struct cdev *sc_si;
65
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];
69
70 int sc_height;
71 int sc_width;
72
73 int sc_xmargin;
74 int sc_ymargin;
75
55#include <dev/syscons/syscons.h>
56
57#define CREATOR_DRIVER_NAME "creator"
58
59struct creator_softc {
60 video_adapter_t sc_va; /* XXX must be first */
61
62 phandle_t sc_node;
63
64 struct cdev *sc_si;
65
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];
69
70 int sc_height;
71 int sc_width;
72
73 int sc_xmargin;
74 int sc_ymargin;
75
76 u_char *sc_font;
76 const u_char *sc_font;
77
78 int sc_bg_cache;
79 int sc_fg_cache;
80 int sc_fifo_cache;
81 int sc_fontinc_cache;
82 int sc_fontw_cache;
83 int sc_pmask_cache;
84
85 int sc_flags;
86#define CREATOR_AFB (1 << 0)
87#define CREATOR_CONSOLE (1 << 1)
88#define CREATOR_CUREN (1 << 2)
89#define CREATOR_CURINV (1 << 3)
90#define CREATOR_PAC1 (1 << 4)
91};
92
93#define FFB_READ(sc, reg, off) \
94 bus_space_read_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off))
95#define FFB_WRITE(sc, reg, off, val) \
96 bus_space_write_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off), (val))
97
98#define C(r, g, b) ((b << 16) | (g << 8) | (r))
99static const uint32_t creator_cmap[] = {
100 C(0x00, 0x00, 0x00), /* black */
101 C(0x00, 0x00, 0xff), /* blue */
102 C(0x00, 0xff, 0x00), /* green */
103 C(0x00, 0xc0, 0xc0), /* cyan */
104 C(0xff, 0x00, 0x00), /* red */
105 C(0xc0, 0x00, 0xc0), /* magenta */
106 C(0xc0, 0xc0, 0x00), /* brown */
107 C(0xc0, 0xc0, 0xc0), /* light grey */
108 C(0x80, 0x80, 0x80), /* dark grey */
109 C(0x80, 0x80, 0xff), /* light blue */
110 C(0x80, 0xff, 0x80), /* light green */
111 C(0x80, 0xff, 0xff), /* light cyan */
112 C(0xff, 0x80, 0x80), /* light red */
113 C(0xff, 0x80, 0xff), /* light magenta */
114 C(0xff, 0xff, 0x80), /* yellow */
115 C(0xff, 0xff, 0xff), /* white */
116};
117#undef C
118
119static const struct {
120 vm_offset_t virt;
121 vm_paddr_t phys;
122 vm_size_t size;
123} creator_fb_map[] = {
124 { FFB_VIRT_SFB8R, FFB_PHYS_SFB8R, FFB_SIZE_SFB8R },
125 { FFB_VIRT_SFB8G, FFB_PHYS_SFB8G, FFB_SIZE_SFB8G },
126 { FFB_VIRT_SFB8B, FFB_PHYS_SFB8B, FFB_SIZE_SFB8B },
127 { FFB_VIRT_SFB8X, FFB_PHYS_SFB8X, FFB_SIZE_SFB8X },
128 { FFB_VIRT_SFB32, FFB_PHYS_SFB32, FFB_SIZE_SFB32 },
129 { FFB_VIRT_SFB64, FFB_PHYS_SFB64, FFB_SIZE_SFB64 },
130 { FFB_VIRT_FBC, FFB_PHYS_FBC, FFB_SIZE_FBC },
131 { FFB_VIRT_FBC_BM, FFB_PHYS_FBC_BM, FFB_SIZE_FBC_BM },
132 { FFB_VIRT_DFB8R, FFB_PHYS_DFB8R, FFB_SIZE_DFB8R },
133 { FFB_VIRT_DFB8G, FFB_PHYS_DFB8G, FFB_SIZE_DFB8G },
134 { FFB_VIRT_DFB8B, FFB_PHYS_DFB8B, FFB_SIZE_DFB8B },
135 { FFB_VIRT_DFB8X, FFB_PHYS_DFB8X, FFB_SIZE_DFB8X },
136 { FFB_VIRT_DFB24, FFB_PHYS_DFB24, FFB_SIZE_DFB24 },
137 { FFB_VIRT_DFB32, FFB_PHYS_DFB32, FFB_SIZE_DFB32 },
138 { FFB_VIRT_DFB422A, FFB_PHYS_DFB422A, FFB_SIZE_DFB422A },
139 { FFB_VIRT_DFB422AD, FFB_PHYS_DFB422AD, FFB_SIZE_DFB422AD },
140 { FFB_VIRT_DFB24B, FFB_PHYS_DFB24B, FFB_SIZE_DFB24B },
141 { FFB_VIRT_DFB422B, FFB_PHYS_DFB422B, FFB_SIZE_DFB422B },
142 { FFB_VIRT_DFB422BD, FFB_PHYS_DFB422BD, FFB_SIZE_DFB422BD },
143 { FFB_VIRT_SFB16Z, FFB_PHYS_SFB16Z, FFB_SIZE_SFB16Z },
144 { FFB_VIRT_SFB8Z, FFB_PHYS_SFB8Z, FFB_SIZE_SFB8Z },
145 { FFB_VIRT_SFB422, FFB_PHYS_SFB422, FFB_SIZE_SFB422 },
146 { FFB_VIRT_SFB422D, FFB_PHYS_SFB422D, FFB_SIZE_SFB422D },
147 { FFB_VIRT_FBC_KREG, FFB_PHYS_FBC_KREG, FFB_SIZE_FBC_KREG },
148 { FFB_VIRT_DAC, FFB_PHYS_DAC, FFB_SIZE_DAC },
149 { FFB_VIRT_PROM, FFB_PHYS_PROM, FFB_SIZE_PROM },
150 { FFB_VIRT_EXP, FFB_PHYS_EXP, FFB_SIZE_EXP },
151};
152
153#define CREATOR_FB_MAP_SIZE \
154 (sizeof(creator_fb_map) / sizeof(creator_fb_map[0]))
155
77
78 int sc_bg_cache;
79 int sc_fg_cache;
80 int sc_fifo_cache;
81 int sc_fontinc_cache;
82 int sc_fontw_cache;
83 int sc_pmask_cache;
84
85 int sc_flags;
86#define CREATOR_AFB (1 << 0)
87#define CREATOR_CONSOLE (1 << 1)
88#define CREATOR_CUREN (1 << 2)
89#define CREATOR_CURINV (1 << 3)
90#define CREATOR_PAC1 (1 << 4)
91};
92
93#define FFB_READ(sc, reg, off) \
94 bus_space_read_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off))
95#define FFB_WRITE(sc, reg, off, val) \
96 bus_space_write_4((sc)->sc_bt[(reg)], (sc)->sc_bh[(reg)], (off), (val))
97
98#define C(r, g, b) ((b << 16) | (g << 8) | (r))
99static const uint32_t creator_cmap[] = {
100 C(0x00, 0x00, 0x00), /* black */
101 C(0x00, 0x00, 0xff), /* blue */
102 C(0x00, 0xff, 0x00), /* green */
103 C(0x00, 0xc0, 0xc0), /* cyan */
104 C(0xff, 0x00, 0x00), /* red */
105 C(0xc0, 0x00, 0xc0), /* magenta */
106 C(0xc0, 0xc0, 0x00), /* brown */
107 C(0xc0, 0xc0, 0xc0), /* light grey */
108 C(0x80, 0x80, 0x80), /* dark grey */
109 C(0x80, 0x80, 0xff), /* light blue */
110 C(0x80, 0xff, 0x80), /* light green */
111 C(0x80, 0xff, 0xff), /* light cyan */
112 C(0xff, 0x80, 0x80), /* light red */
113 C(0xff, 0x80, 0xff), /* light magenta */
114 C(0xff, 0xff, 0x80), /* yellow */
115 C(0xff, 0xff, 0xff), /* white */
116};
117#undef C
118
119static const struct {
120 vm_offset_t virt;
121 vm_paddr_t phys;
122 vm_size_t size;
123} creator_fb_map[] = {
124 { FFB_VIRT_SFB8R, FFB_PHYS_SFB8R, FFB_SIZE_SFB8R },
125 { FFB_VIRT_SFB8G, FFB_PHYS_SFB8G, FFB_SIZE_SFB8G },
126 { FFB_VIRT_SFB8B, FFB_PHYS_SFB8B, FFB_SIZE_SFB8B },
127 { FFB_VIRT_SFB8X, FFB_PHYS_SFB8X, FFB_SIZE_SFB8X },
128 { FFB_VIRT_SFB32, FFB_PHYS_SFB32, FFB_SIZE_SFB32 },
129 { FFB_VIRT_SFB64, FFB_PHYS_SFB64, FFB_SIZE_SFB64 },
130 { FFB_VIRT_FBC, FFB_PHYS_FBC, FFB_SIZE_FBC },
131 { FFB_VIRT_FBC_BM, FFB_PHYS_FBC_BM, FFB_SIZE_FBC_BM },
132 { FFB_VIRT_DFB8R, FFB_PHYS_DFB8R, FFB_SIZE_DFB8R },
133 { FFB_VIRT_DFB8G, FFB_PHYS_DFB8G, FFB_SIZE_DFB8G },
134 { FFB_VIRT_DFB8B, FFB_PHYS_DFB8B, FFB_SIZE_DFB8B },
135 { FFB_VIRT_DFB8X, FFB_PHYS_DFB8X, FFB_SIZE_DFB8X },
136 { FFB_VIRT_DFB24, FFB_PHYS_DFB24, FFB_SIZE_DFB24 },
137 { FFB_VIRT_DFB32, FFB_PHYS_DFB32, FFB_SIZE_DFB32 },
138 { FFB_VIRT_DFB422A, FFB_PHYS_DFB422A, FFB_SIZE_DFB422A },
139 { FFB_VIRT_DFB422AD, FFB_PHYS_DFB422AD, FFB_SIZE_DFB422AD },
140 { FFB_VIRT_DFB24B, FFB_PHYS_DFB24B, FFB_SIZE_DFB24B },
141 { FFB_VIRT_DFB422B, FFB_PHYS_DFB422B, FFB_SIZE_DFB422B },
142 { FFB_VIRT_DFB422BD, FFB_PHYS_DFB422BD, FFB_SIZE_DFB422BD },
143 { FFB_VIRT_SFB16Z, FFB_PHYS_SFB16Z, FFB_SIZE_SFB16Z },
144 { FFB_VIRT_SFB8Z, FFB_PHYS_SFB8Z, FFB_SIZE_SFB8Z },
145 { FFB_VIRT_SFB422, FFB_PHYS_SFB422, FFB_SIZE_SFB422 },
146 { FFB_VIRT_SFB422D, FFB_PHYS_SFB422D, FFB_SIZE_SFB422D },
147 { FFB_VIRT_FBC_KREG, FFB_PHYS_FBC_KREG, FFB_SIZE_FBC_KREG },
148 { FFB_VIRT_DAC, FFB_PHYS_DAC, FFB_SIZE_DAC },
149 { FFB_VIRT_PROM, FFB_PHYS_PROM, FFB_SIZE_PROM },
150 { FFB_VIRT_EXP, FFB_PHYS_EXP, FFB_SIZE_EXP },
151};
152
153#define CREATOR_FB_MAP_SIZE \
154 (sizeof(creator_fb_map) / sizeof(creator_fb_map[0]))
155
156extern const struct gfb_font gallant12x22;
157
156static struct creator_softc creator_softc;
157static struct bus_space_tag creator_bst_store[FFB_FBC];
158
159static device_probe_t creator_bus_probe;
160static device_attach_t creator_bus_attach;
161
162static device_method_t creator_bus_methods[] = {
163 DEVMETHOD(device_probe, creator_bus_probe),
164 DEVMETHOD(device_attach, creator_bus_attach),
165
166 { 0, 0 }
167};
168
169static devclass_t creator_devclass;
170
171DEFINE_CLASS_0(creator, creator_bus_driver, creator_bus_methods,
172 sizeof(struct creator_softc));
173DRIVER_MODULE(creator, nexus, creator_bus_driver, creator_devclass, 0, 0);
174DRIVER_MODULE(creator, upa, creator_bus_driver, creator_devclass, 0, 0);
175
176static d_open_t creator_fb_open;
177static d_close_t creator_fb_close;
178static d_ioctl_t creator_fb_ioctl;
179static d_mmap_t creator_fb_mmap;
180
181static struct cdevsw creator_fb_devsw = {
182 .d_version = D_VERSION,
183 .d_flags = D_NEEDGIANT,
184 .d_open = creator_fb_open,
185 .d_close = creator_fb_close,
186 .d_ioctl = creator_fb_ioctl,
187 .d_mmap = creator_fb_mmap,
188 .d_name = "fb",
189};
190
191static void creator_cursor_enable(struct creator_softc *sc, int onoff);
192static void creator_cursor_install(struct creator_softc *sc);
193static void creator_shutdown(void *xsc);
194
195static int creator_configure(int flags);
196
197static vi_probe_t creator_probe;
198static vi_init_t creator_init;
199static vi_get_info_t creator_get_info;
200static vi_query_mode_t creator_query_mode;
201static vi_set_mode_t creator_set_mode;
202static vi_save_font_t creator_save_font;
203static vi_load_font_t creator_load_font;
204static vi_show_font_t creator_show_font;
205static vi_save_palette_t creator_save_palette;
206static vi_load_palette_t creator_load_palette;
207static vi_set_border_t creator_set_border;
208static vi_save_state_t creator_save_state;
209static vi_load_state_t creator_load_state;
210static vi_set_win_org_t creator_set_win_org;
211static vi_read_hw_cursor_t creator_read_hw_cursor;
212static vi_set_hw_cursor_t creator_set_hw_cursor;
213static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape;
214static vi_blank_display_t creator_blank_display;
215static vi_mmap_t creator_mmap;
216static vi_ioctl_t creator_ioctl;
217static vi_clear_t creator_clear;
218static vi_fill_rect_t creator_fill_rect;
219static vi_bitblt_t creator_bitblt;
220static vi_diag_t creator_diag;
221static vi_save_cursor_palette_t creator_save_cursor_palette;
222static vi_load_cursor_palette_t creator_load_cursor_palette;
223static vi_copy_t creator_copy;
224static vi_putp_t creator_putp;
225static vi_putc_t creator_putc;
226static vi_puts_t creator_puts;
227static vi_putm_t creator_putm;
228
229static video_switch_t creatorvidsw = {
230 .probe = creator_probe,
231 .init = creator_init,
232 .get_info = creator_get_info,
233 .query_mode = creator_query_mode,
234 .set_mode = creator_set_mode,
235 .save_font = creator_save_font,
236 .load_font = creator_load_font,
237 .show_font = creator_show_font,
238 .save_palette = creator_save_palette,
239 .load_palette = creator_load_palette,
240 .set_border = creator_set_border,
241 .save_state = creator_save_state,
242 .load_state = creator_load_state,
243 .set_win_org = creator_set_win_org,
244 .read_hw_cursor = creator_read_hw_cursor,
245 .set_hw_cursor = creator_set_hw_cursor,
246 .set_hw_cursor_shape = creator_set_hw_cursor_shape,
247 .blank_display = creator_blank_display,
248 .mmap = creator_mmap,
249 .ioctl = creator_ioctl,
250 .clear = creator_clear,
251 .fill_rect = creator_fill_rect,
252 .bitblt = creator_bitblt,
253 NULL, /* XXX brain damage */
254 NULL, /* XXX brain damage */
255 .diag = creator_diag,
256 .save_cursor_palette = creator_save_cursor_palette,
257 .load_cursor_palette = creator_load_cursor_palette,
258 .copy = creator_copy,
259 .putp = creator_putp,
260 .putc = creator_putc,
261 .puts = creator_puts,
262 .putm = creator_putm
263};
264
265VIDEO_DRIVER(creator, creatorvidsw, creator_configure);
266
267extern sc_rndr_sw_t txtrndrsw;
268RENDERER(creator, 0, txtrndrsw, gfb_set);
269
270RENDERER_MODULE(creator, gfb_set);
271
272static const u_char creator_mouse_pointer[64][8] __aligned(8) = {
273 { 0x00, 0x00, }, /* ............ */
274 { 0x80, 0x00, }, /* *........... */
275 { 0xc0, 0x00, }, /* **.......... */
276 { 0xe0, 0x00, }, /* ***......... */
277 { 0xf0, 0x00, }, /* ****........ */
278 { 0xf8, 0x00, }, /* *****....... */
279 { 0xfc, 0x00, }, /* ******...... */
280 { 0xfe, 0x00, }, /* *******..... */
281 { 0xff, 0x00, }, /* ********.... */
282 { 0xff, 0x80, }, /* *********... */
283 { 0xfc, 0xc0, }, /* ******..**.. */
284 { 0xdc, 0x00, }, /* **.***...... */
285 { 0x8e, 0x00, }, /* *...***..... */
286 { 0x0e, 0x00, }, /* ....***..... */
287 { 0x07, 0x00, }, /* .....***.... */
288 { 0x04, 0x00, }, /* .....*...... */
289 { 0x00, 0x00, }, /* ............ */
290 { 0x00, 0x00, }, /* ............ */
291 { 0x00, 0x00, }, /* ............ */
292 { 0x00, 0x00, }, /* ............ */
293 { 0x00, 0x00, }, /* ............ */
294 { 0x00, 0x00, }, /* ............ */
295};
296
297static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n);
298static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc);
299static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw);
300static inline void creator_ras_setbg(struct creator_softc *sc, int bg);
301static inline void creator_ras_setfg(struct creator_softc *sc, int fg);
302static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask);
303static inline void creator_ras_wait(struct creator_softc *sc);
304
305static inline void
306creator_ras_wait(struct creator_softc *sc)
307{
308 int ucsr;
309 int r;
310
311 for (;;) {
312 ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR);
313 if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0)
314 break;
315 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
316 if (r != 0)
317 FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r);
318 }
319}
320
321static inline void
322creator_ras_fifo_wait(struct creator_softc *sc, int n)
323{
324 int cache;
325
326 cache = sc->sc_fifo_cache;
327 while (cache < n)
328 cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) &
329 FBC_UCSR_FIFO_MASK) - 8;
330 sc->sc_fifo_cache = cache - n;
331}
332
333static inline void
334creator_ras_setfontinc(struct creator_softc *sc, int fontinc)
335{
336
337 if (fontinc == sc->sc_fontinc_cache)
338 return;
339 sc->sc_fontinc_cache = fontinc;
340 creator_ras_fifo_wait(sc, 1);
341 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc);
342 creator_ras_wait(sc);
343}
344
345static inline void
346creator_ras_setfontw(struct creator_softc *sc, int fontw)
347{
348
349 if (fontw == sc->sc_fontw_cache)
350 return;
351 sc->sc_fontw_cache = fontw;
352 creator_ras_fifo_wait(sc, 1);
353 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw);
354 creator_ras_wait(sc);
355}
356
357static inline void
358creator_ras_setbg(struct creator_softc *sc, int bg)
359{
360
361 if (bg == sc->sc_bg_cache)
362 return;
363 sc->sc_bg_cache = bg;
364 creator_ras_fifo_wait(sc, 1);
365 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg);
366 creator_ras_wait(sc);
367}
368
369static inline void
370creator_ras_setfg(struct creator_softc *sc, int fg)
371{
372
373 if (fg == sc->sc_fg_cache)
374 return;
375 sc->sc_fg_cache = fg;
376 creator_ras_fifo_wait(sc, 1);
377 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg);
378 creator_ras_wait(sc);
379}
380
381static inline void
382creator_ras_setpmask(struct creator_softc *sc, int pmask)
383{
384
385 if (pmask == sc->sc_pmask_cache)
386 return;
387 sc->sc_pmask_cache = pmask;
388 creator_ras_fifo_wait(sc, 1);
389 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask);
390 creator_ras_wait(sc);
391}
392
393/*
394 * video driver interface
395 */
396static int
397creator_configure(int flags)
398{
399 struct creator_softc *sc;
400 phandle_t chosen;
401 phandle_t output;
402 ihandle_t stdout;
403 bus_addr_t addr;
404 char buf[sizeof("SUNW,ffb")];
405 int i;
406 int space;
407
408 /*
409 * For the high-level console probing return the number of
410 * registered adapters.
411 */
412 if (!(flags & VIO_PROBE_ONLY)) {
413 for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++)
414 ;
415 return (i);
416 }
417
418 /* Low-level console probing and initialization. */
419
420 sc = &creator_softc;
421 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
422 goto found;
423
424 if ((chosen = OF_finddevice("/chosen")) == -1)
425 return (0);
426 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
427 return (0);
428 if ((output = OF_instance_to_package(stdout)) == -1)
429 return (0);
430 if (OF_getprop(output, "name", buf, sizeof(buf)) == -1)
431 return (0);
432 if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) {
433 sc->sc_flags = CREATOR_CONSOLE;
434 if (strcmp(buf, "SUNW,afb") == 0)
435 sc->sc_flags |= CREATOR_AFB;
436 sc->sc_node = output;
437 } else
438 return (0);
439
440 for (i = FFB_DAC; i <= FFB_FBC; i++) {
441 if (OF_decode_addr(output, i, &space, &addr) != 0)
442 return (0);
443 sc->sc_bt[i] = &creator_bst_store[i - FFB_DAC];
444 sc->sc_bh[i] = sparc64_fake_bustag(space, addr, sc->sc_bt[i]);
445 }
446
447 if (creator_init(0, &sc->sc_va, 0) < 0)
448 return (0);
449
450 found:
451 /* Return number of found adapters. */
452 return (1);
453}
454
455static int
456creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
457{
458
459 return (0);
460}
461
462static int
463creator_init(int unit, video_adapter_t *adp, int flags)
464{
465 struct creator_softc *sc;
466 phandle_t options;
467 video_info_t *vi;
468 char buf[sizeof("screen-#columns")];
469
470 sc = (struct creator_softc *)adp;
471 vi = &adp->va_info;
472
473 vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit);
474
475 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
476 sizeof(sc->sc_height)) == -1)
477 return (ENXIO);
478 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
479 sizeof(sc->sc_width)) == -1)
480 return (ENXIO);
481 if ((options = OF_finddevice("/options")) == -1)
482 return (ENXIO);
483 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
484 return (ENXIO);
485 vi->vi_height = strtol(buf, NULL, 10);
486 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
487 return (ENXIO);
488 vi->vi_width = strtol(buf, NULL, 10);
158static struct creator_softc creator_softc;
159static struct bus_space_tag creator_bst_store[FFB_FBC];
160
161static device_probe_t creator_bus_probe;
162static device_attach_t creator_bus_attach;
163
164static device_method_t creator_bus_methods[] = {
165 DEVMETHOD(device_probe, creator_bus_probe),
166 DEVMETHOD(device_attach, creator_bus_attach),
167
168 { 0, 0 }
169};
170
171static devclass_t creator_devclass;
172
173DEFINE_CLASS_0(creator, creator_bus_driver, creator_bus_methods,
174 sizeof(struct creator_softc));
175DRIVER_MODULE(creator, nexus, creator_bus_driver, creator_devclass, 0, 0);
176DRIVER_MODULE(creator, upa, creator_bus_driver, creator_devclass, 0, 0);
177
178static d_open_t creator_fb_open;
179static d_close_t creator_fb_close;
180static d_ioctl_t creator_fb_ioctl;
181static d_mmap_t creator_fb_mmap;
182
183static struct cdevsw creator_fb_devsw = {
184 .d_version = D_VERSION,
185 .d_flags = D_NEEDGIANT,
186 .d_open = creator_fb_open,
187 .d_close = creator_fb_close,
188 .d_ioctl = creator_fb_ioctl,
189 .d_mmap = creator_fb_mmap,
190 .d_name = "fb",
191};
192
193static void creator_cursor_enable(struct creator_softc *sc, int onoff);
194static void creator_cursor_install(struct creator_softc *sc);
195static void creator_shutdown(void *xsc);
196
197static int creator_configure(int flags);
198
199static vi_probe_t creator_probe;
200static vi_init_t creator_init;
201static vi_get_info_t creator_get_info;
202static vi_query_mode_t creator_query_mode;
203static vi_set_mode_t creator_set_mode;
204static vi_save_font_t creator_save_font;
205static vi_load_font_t creator_load_font;
206static vi_show_font_t creator_show_font;
207static vi_save_palette_t creator_save_palette;
208static vi_load_palette_t creator_load_palette;
209static vi_set_border_t creator_set_border;
210static vi_save_state_t creator_save_state;
211static vi_load_state_t creator_load_state;
212static vi_set_win_org_t creator_set_win_org;
213static vi_read_hw_cursor_t creator_read_hw_cursor;
214static vi_set_hw_cursor_t creator_set_hw_cursor;
215static vi_set_hw_cursor_shape_t creator_set_hw_cursor_shape;
216static vi_blank_display_t creator_blank_display;
217static vi_mmap_t creator_mmap;
218static vi_ioctl_t creator_ioctl;
219static vi_clear_t creator_clear;
220static vi_fill_rect_t creator_fill_rect;
221static vi_bitblt_t creator_bitblt;
222static vi_diag_t creator_diag;
223static vi_save_cursor_palette_t creator_save_cursor_palette;
224static vi_load_cursor_palette_t creator_load_cursor_palette;
225static vi_copy_t creator_copy;
226static vi_putp_t creator_putp;
227static vi_putc_t creator_putc;
228static vi_puts_t creator_puts;
229static vi_putm_t creator_putm;
230
231static video_switch_t creatorvidsw = {
232 .probe = creator_probe,
233 .init = creator_init,
234 .get_info = creator_get_info,
235 .query_mode = creator_query_mode,
236 .set_mode = creator_set_mode,
237 .save_font = creator_save_font,
238 .load_font = creator_load_font,
239 .show_font = creator_show_font,
240 .save_palette = creator_save_palette,
241 .load_palette = creator_load_palette,
242 .set_border = creator_set_border,
243 .save_state = creator_save_state,
244 .load_state = creator_load_state,
245 .set_win_org = creator_set_win_org,
246 .read_hw_cursor = creator_read_hw_cursor,
247 .set_hw_cursor = creator_set_hw_cursor,
248 .set_hw_cursor_shape = creator_set_hw_cursor_shape,
249 .blank_display = creator_blank_display,
250 .mmap = creator_mmap,
251 .ioctl = creator_ioctl,
252 .clear = creator_clear,
253 .fill_rect = creator_fill_rect,
254 .bitblt = creator_bitblt,
255 NULL, /* XXX brain damage */
256 NULL, /* XXX brain damage */
257 .diag = creator_diag,
258 .save_cursor_palette = creator_save_cursor_palette,
259 .load_cursor_palette = creator_load_cursor_palette,
260 .copy = creator_copy,
261 .putp = creator_putp,
262 .putc = creator_putc,
263 .puts = creator_puts,
264 .putm = creator_putm
265};
266
267VIDEO_DRIVER(creator, creatorvidsw, creator_configure);
268
269extern sc_rndr_sw_t txtrndrsw;
270RENDERER(creator, 0, txtrndrsw, gfb_set);
271
272RENDERER_MODULE(creator, gfb_set);
273
274static const u_char creator_mouse_pointer[64][8] __aligned(8) = {
275 { 0x00, 0x00, }, /* ............ */
276 { 0x80, 0x00, }, /* *........... */
277 { 0xc0, 0x00, }, /* **.......... */
278 { 0xe0, 0x00, }, /* ***......... */
279 { 0xf0, 0x00, }, /* ****........ */
280 { 0xf8, 0x00, }, /* *****....... */
281 { 0xfc, 0x00, }, /* ******...... */
282 { 0xfe, 0x00, }, /* *******..... */
283 { 0xff, 0x00, }, /* ********.... */
284 { 0xff, 0x80, }, /* *********... */
285 { 0xfc, 0xc0, }, /* ******..**.. */
286 { 0xdc, 0x00, }, /* **.***...... */
287 { 0x8e, 0x00, }, /* *...***..... */
288 { 0x0e, 0x00, }, /* ....***..... */
289 { 0x07, 0x00, }, /* .....***.... */
290 { 0x04, 0x00, }, /* .....*...... */
291 { 0x00, 0x00, }, /* ............ */
292 { 0x00, 0x00, }, /* ............ */
293 { 0x00, 0x00, }, /* ............ */
294 { 0x00, 0x00, }, /* ............ */
295 { 0x00, 0x00, }, /* ............ */
296 { 0x00, 0x00, }, /* ............ */
297};
298
299static inline void creator_ras_fifo_wait(struct creator_softc *sc, int n);
300static inline void creator_ras_setfontinc(struct creator_softc *sc, int fontinc);
301static inline void creator_ras_setfontw(struct creator_softc *sc, int fontw);
302static inline void creator_ras_setbg(struct creator_softc *sc, int bg);
303static inline void creator_ras_setfg(struct creator_softc *sc, int fg);
304static inline void creator_ras_setpmask(struct creator_softc *sc, int pmask);
305static inline void creator_ras_wait(struct creator_softc *sc);
306
307static inline void
308creator_ras_wait(struct creator_softc *sc)
309{
310 int ucsr;
311 int r;
312
313 for (;;) {
314 ucsr = FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR);
315 if ((ucsr & (FBC_UCSR_FB_BUSY | FBC_UCSR_RP_BUSY)) == 0)
316 break;
317 r = ucsr & (FBC_UCSR_READ_ERR | FBC_UCSR_FIFO_OVFL);
318 if (r != 0)
319 FFB_WRITE(sc, FFB_FBC, FFB_FBC_UCSR, r);
320 }
321}
322
323static inline void
324creator_ras_fifo_wait(struct creator_softc *sc, int n)
325{
326 int cache;
327
328 cache = sc->sc_fifo_cache;
329 while (cache < n)
330 cache = (FFB_READ(sc, FFB_FBC, FFB_FBC_UCSR) &
331 FBC_UCSR_FIFO_MASK) - 8;
332 sc->sc_fifo_cache = cache - n;
333}
334
335static inline void
336creator_ras_setfontinc(struct creator_softc *sc, int fontinc)
337{
338
339 if (fontinc == sc->sc_fontinc_cache)
340 return;
341 sc->sc_fontinc_cache = fontinc;
342 creator_ras_fifo_wait(sc, 1);
343 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTINC, fontinc);
344 creator_ras_wait(sc);
345}
346
347static inline void
348creator_ras_setfontw(struct creator_softc *sc, int fontw)
349{
350
351 if (fontw == sc->sc_fontw_cache)
352 return;
353 sc->sc_fontw_cache = fontw;
354 creator_ras_fifo_wait(sc, 1);
355 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTW, fontw);
356 creator_ras_wait(sc);
357}
358
359static inline void
360creator_ras_setbg(struct creator_softc *sc, int bg)
361{
362
363 if (bg == sc->sc_bg_cache)
364 return;
365 sc->sc_bg_cache = bg;
366 creator_ras_fifo_wait(sc, 1);
367 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BG, bg);
368 creator_ras_wait(sc);
369}
370
371static inline void
372creator_ras_setfg(struct creator_softc *sc, int fg)
373{
374
375 if (fg == sc->sc_fg_cache)
376 return;
377 sc->sc_fg_cache = fg;
378 creator_ras_fifo_wait(sc, 1);
379 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FG, fg);
380 creator_ras_wait(sc);
381}
382
383static inline void
384creator_ras_setpmask(struct creator_softc *sc, int pmask)
385{
386
387 if (pmask == sc->sc_pmask_cache)
388 return;
389 sc->sc_pmask_cache = pmask;
390 creator_ras_fifo_wait(sc, 1);
391 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PMASK, pmask);
392 creator_ras_wait(sc);
393}
394
395/*
396 * video driver interface
397 */
398static int
399creator_configure(int flags)
400{
401 struct creator_softc *sc;
402 phandle_t chosen;
403 phandle_t output;
404 ihandle_t stdout;
405 bus_addr_t addr;
406 char buf[sizeof("SUNW,ffb")];
407 int i;
408 int space;
409
410 /*
411 * For the high-level console probing return the number of
412 * registered adapters.
413 */
414 if (!(flags & VIO_PROBE_ONLY)) {
415 for (i = 0; vid_find_adapter(CREATOR_DRIVER_NAME, i) >= 0; i++)
416 ;
417 return (i);
418 }
419
420 /* Low-level console probing and initialization. */
421
422 sc = &creator_softc;
423 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
424 goto found;
425
426 if ((chosen = OF_finddevice("/chosen")) == -1)
427 return (0);
428 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
429 return (0);
430 if ((output = OF_instance_to_package(stdout)) == -1)
431 return (0);
432 if (OF_getprop(output, "name", buf, sizeof(buf)) == -1)
433 return (0);
434 if (strcmp(buf, "SUNW,ffb") == 0 || strcmp(buf, "SUNW,afb") == 0) {
435 sc->sc_flags = CREATOR_CONSOLE;
436 if (strcmp(buf, "SUNW,afb") == 0)
437 sc->sc_flags |= CREATOR_AFB;
438 sc->sc_node = output;
439 } else
440 return (0);
441
442 for (i = FFB_DAC; i <= FFB_FBC; i++) {
443 if (OF_decode_addr(output, i, &space, &addr) != 0)
444 return (0);
445 sc->sc_bt[i] = &creator_bst_store[i - FFB_DAC];
446 sc->sc_bh[i] = sparc64_fake_bustag(space, addr, sc->sc_bt[i]);
447 }
448
449 if (creator_init(0, &sc->sc_va, 0) < 0)
450 return (0);
451
452 found:
453 /* Return number of found adapters. */
454 return (1);
455}
456
457static int
458creator_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
459{
460
461 return (0);
462}
463
464static int
465creator_init(int unit, video_adapter_t *adp, int flags)
466{
467 struct creator_softc *sc;
468 phandle_t options;
469 video_info_t *vi;
470 char buf[sizeof("screen-#columns")];
471
472 sc = (struct creator_softc *)adp;
473 vi = &adp->va_info;
474
475 vid_init_struct(adp, CREATOR_DRIVER_NAME, -1, unit);
476
477 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
478 sizeof(sc->sc_height)) == -1)
479 return (ENXIO);
480 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
481 sizeof(sc->sc_width)) == -1)
482 return (ENXIO);
483 if ((options = OF_finddevice("/options")) == -1)
484 return (ENXIO);
485 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
486 return (ENXIO);
487 vi->vi_height = strtol(buf, NULL, 10);
488 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
489 return (ENXIO);
490 vi->vi_width = strtol(buf, NULL, 10);
489 vi->vi_cwidth = 12;
490 vi->vi_cheight = 22;
491 vi->vi_cwidth = gallant12x22.width;
492 vi->vi_cheight = gallant12x22.height;
491 vi->vi_flags = V_INFO_COLOR;
492 vi->vi_mem_model = V_INFO_MM_OTHER;
493
493 vi->vi_flags = V_INFO_COLOR;
494 vi->vi_mem_model = V_INFO_MM_OTHER;
495
494 sc->sc_font = gallant12x22_data;
496 sc->sc_font = gallant12x22.data;
495 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
496 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
497
498 creator_set_mode(adp, 0);
499
500 if (!(sc->sc_flags & CREATOR_AFB)) {
501 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID);
502 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
503 FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) {
504 sc->sc_flags |= CREATOR_PAC1;
505 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL);
506 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
507 FFB_DAC_UCTRL_MANREV) >> 8) <= 2)
508 sc->sc_flags |= CREATOR_CURINV;
509 }
510 }
511
512 creator_blank_display(adp, V_DISPLAY_ON);
513 creator_clear(adp);
514
515 /*
516 * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode()
517 * (which will invalidate our caches and restore our settings) is
518 * called when the X server shuts down. Otherwise screen corruption
519 * happens most of the time.
520 */
521 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER |
522 V_ADP_INITIALIZED;
523 if (vid_register(adp) < 0)
524 return (ENXIO);
525 adp->va_flags |= V_ADP_REGISTERED;
526
527 return (0);
528}
529
530static int
531creator_get_info(video_adapter_t *adp, int mode, video_info_t *info)
532{
533
534 bcopy(&adp->va_info, info, sizeof(*info));
535 return (0);
536}
537
538static int
539creator_query_mode(video_adapter_t *adp, video_info_t *info)
540{
541
542 return (ENODEV);
543}
544
545static int
546creator_set_mode(video_adapter_t *adp, int mode)
547{
548 struct creator_softc *sc;
549
550 sc = (struct creator_softc *)adp;
551 sc->sc_bg_cache = -1;
552 sc->sc_fg_cache = -1;
553 sc->sc_fontinc_cache = -1;
554 sc->sc_fontw_cache = -1;
555 sc->sc_pmask_cache = -1;
556
557 creator_ras_wait(sc);
558 sc->sc_fifo_cache = 0;
559 creator_ras_fifo_wait(sc, 2);
560 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS |
561 FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
562 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A |
563 FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
564 return (0);
565}
566
567static int
568creator_save_font(video_adapter_t *adp, int page, int size, int width,
569 u_char *data, int c, int count)
570{
571
572 return (ENODEV);
573}
574
575static int
576creator_load_font(video_adapter_t *adp, int page, int size, int width,
577 u_char *data, int c, int count)
578{
579
580 return (ENODEV);
581}
582
583static int
584creator_show_font(video_adapter_t *adp, int page)
585{
586
587 return (ENODEV);
588}
589
590static int
591creator_save_palette(video_adapter_t *adp, u_char *palette)
592{
593
594 return (ENODEV);
595}
596
597static int
598creator_load_palette(video_adapter_t *adp, u_char *palette)
599{
600
601 return (ENODEV);
602}
603
604static int
605creator_set_border(video_adapter_t *adp, int border)
606{
607 struct creator_softc *sc;
608
609 sc = (struct creator_softc *)adp;
610 creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
611 creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
612 sc->sc_width, sc->sc_ymargin);
613 creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
614 creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
615 sc->sc_xmargin, sc->sc_height);
616 return (0);
617}
618
619static int
620creator_save_state(video_adapter_t *adp, void *p, size_t size)
621{
622
623 return (ENODEV);
624}
625
626static int
627creator_load_state(video_adapter_t *adp, void *p)
628{
629
630 return (ENODEV);
631}
632
633static int
634creator_set_win_org(video_adapter_t *adp, off_t offset)
635{
636
637 return (ENODEV);
638}
639
640static int
641creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
642{
643
644 *col = 0;
645 *row = 0;
646 return (0);
647}
648
649static int
650creator_set_hw_cursor(video_adapter_t *adp, int col, int row)
651{
652
653 return (ENODEV);
654}
655
656static int
657creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
658 int celsize, int blink)
659{
660
661 return (ENODEV);
662}
663
664static int
665creator_blank_display(video_adapter_t *adp, int mode)
666{
667 struct creator_softc *sc;
668 uint32_t v;
669 int i;
670
671 sc = (struct creator_softc *)adp;
672 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
673 v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
674 switch (mode) {
675 case V_DISPLAY_ON:
676 v |= FFB_DAC_CFG_TGEN_VIDE;
677 break;
678 case V_DISPLAY_BLANK:
679 case V_DISPLAY_STAND_BY:
680 case V_DISPLAY_SUSPEND:
681 v &= ~FFB_DAC_CFG_TGEN_VIDE;
682 break;
683 }
684 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
685 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v);
686 for (i = 0; i < 10; i++) {
687 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
688 (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
689 }
690 return (0);
691}
692
693static int
694creator_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
695 int prot)
696{
697
698 return (EINVAL);
699}
700
701static int
702creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
703{
704 struct creator_softc *sc;
705 struct fbcursor *fbc;
706 struct fbtype *fb;
707
708 sc = (struct creator_softc *)adp;
709 switch (cmd) {
710 case FBIOGTYPE:
711 fb = (struct fbtype *)data;
712 fb->fb_type = FBTYPE_CREATOR;
713 fb->fb_height = sc->sc_height;
714 fb->fb_width = sc->sc_width;
715 fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0;
716 break;
717 case FBIOSCURSOR:
718 fbc = (struct fbcursor *)data;
719 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
720 creator_cursor_enable(sc, 0);
721 sc->sc_flags &= ~CREATOR_CUREN;
722 } else
723 return (ENODEV);
724 break;
725 break;
726 default:
727 return (fb_commonioctl(adp, cmd, data));
728 }
729 return (0);
730}
731
732static int
733creator_clear(video_adapter_t *adp)
734{
735 struct creator_softc *sc;
736
737 sc = (struct creator_softc *)adp;
738 creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
739 sc->sc_height);
740 return (0);
741}
742
743static int
744creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
745{
746 struct creator_softc *sc;
747
748 sc = (struct creator_softc *)adp;
749 creator_ras_setpmask(sc, 0xffffffff);
750 creator_ras_fifo_wait(sc, 2);
751 FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW);
752 FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
753 creator_ras_setfg(sc, creator_cmap[val & 0xf]);
754 /*
755 * Note that at least the Elite3D cards are sensitive to the order
756 * of operations here.
757 */
758 creator_ras_fifo_wait(sc, 4);
759 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y);
760 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x);
761 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy);
762 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx);
763 creator_ras_wait(sc);
764 return (0);
765}
766
767static int
768creator_bitblt(video_adapter_t *adp, ...)
769{
770
771 return (ENODEV);
772}
773
774static int
775creator_diag(video_adapter_t *adp, int level)
776{
777 video_info_t info;
778
779 fb_dump_adp_info(adp->va_name, adp, level);
780 creator_get_info(adp, 0, &info);
781 fb_dump_mode_info(adp->va_name, adp, &info, level);
782 return (0);
783}
784
785static int
786creator_save_cursor_palette(video_adapter_t *adp, u_char *palette)
787{
788
789 return (ENODEV);
790}
791
792static int
793creator_load_cursor_palette(video_adapter_t *adp, u_char *palette)
794{
795
796 return (ENODEV);
797}
798
799static int
800creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
801{
802
803 return (ENODEV);
804}
805
806static int
807creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a,
808 int size, int bpp, int bit_ltor, int byte_ltor)
809{
810
811 return (ENODEV);
812}
813
814static int
815creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a)
816{
817 struct creator_softc *sc;
497 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
498 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
499
500 creator_set_mode(adp, 0);
501
502 if (!(sc->sc_flags & CREATOR_AFB)) {
503 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_DID);
504 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
505 FFB_DAC_CFG_DID_PNUM) >> 12) != 0x236e) {
506 sc->sc_flags |= CREATOR_PAC1;
507 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_UCTRL);
508 if (((FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE) &
509 FFB_DAC_UCTRL_MANREV) >> 8) <= 2)
510 sc->sc_flags |= CREATOR_CURINV;
511 }
512 }
513
514 creator_blank_display(adp, V_DISPLAY_ON);
515 creator_clear(adp);
516
517 /*
518 * Setting V_ADP_MODECHANGE serves as hack so creator_set_mode()
519 * (which will invalidate our caches and restore our settings) is
520 * called when the X server shuts down. Otherwise screen corruption
521 * happens most of the time.
522 */
523 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_BORDER |
524 V_ADP_INITIALIZED;
525 if (vid_register(adp) < 0)
526 return (ENXIO);
527 adp->va_flags |= V_ADP_REGISTERED;
528
529 return (0);
530}
531
532static int
533creator_get_info(video_adapter_t *adp, int mode, video_info_t *info)
534{
535
536 bcopy(&adp->va_info, info, sizeof(*info));
537 return (0);
538}
539
540static int
541creator_query_mode(video_adapter_t *adp, video_info_t *info)
542{
543
544 return (ENODEV);
545}
546
547static int
548creator_set_mode(video_adapter_t *adp, int mode)
549{
550 struct creator_softc *sc;
551
552 sc = (struct creator_softc *)adp;
553 sc->sc_bg_cache = -1;
554 sc->sc_fg_cache = -1;
555 sc->sc_fontinc_cache = -1;
556 sc->sc_fontw_cache = -1;
557 sc->sc_pmask_cache = -1;
558
559 creator_ras_wait(sc);
560 sc->sc_fifo_cache = 0;
561 creator_ras_fifo_wait(sc, 2);
562 FFB_WRITE(sc, FFB_FBC, FFB_FBC_PPC, FBC_PPC_VCE_DIS |
563 FBC_PPC_TBE_OPAQUE | FBC_PPC_APE_DIS | FBC_PPC_CS_CONST);
564 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FBC, FFB_FBC_WB_A | FFB_FBC_RB_A |
565 FFB_FBC_SB_BOTH | FFB_FBC_XE_OFF | FFB_FBC_RGBE_MASK);
566 return (0);
567}
568
569static int
570creator_save_font(video_adapter_t *adp, int page, int size, int width,
571 u_char *data, int c, int count)
572{
573
574 return (ENODEV);
575}
576
577static int
578creator_load_font(video_adapter_t *adp, int page, int size, int width,
579 u_char *data, int c, int count)
580{
581
582 return (ENODEV);
583}
584
585static int
586creator_show_font(video_adapter_t *adp, int page)
587{
588
589 return (ENODEV);
590}
591
592static int
593creator_save_palette(video_adapter_t *adp, u_char *palette)
594{
595
596 return (ENODEV);
597}
598
599static int
600creator_load_palette(video_adapter_t *adp, u_char *palette)
601{
602
603 return (ENODEV);
604}
605
606static int
607creator_set_border(video_adapter_t *adp, int border)
608{
609 struct creator_softc *sc;
610
611 sc = (struct creator_softc *)adp;
612 creator_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
613 creator_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
614 sc->sc_width, sc->sc_ymargin);
615 creator_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
616 creator_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
617 sc->sc_xmargin, sc->sc_height);
618 return (0);
619}
620
621static int
622creator_save_state(video_adapter_t *adp, void *p, size_t size)
623{
624
625 return (ENODEV);
626}
627
628static int
629creator_load_state(video_adapter_t *adp, void *p)
630{
631
632 return (ENODEV);
633}
634
635static int
636creator_set_win_org(video_adapter_t *adp, off_t offset)
637{
638
639 return (ENODEV);
640}
641
642static int
643creator_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
644{
645
646 *col = 0;
647 *row = 0;
648 return (0);
649}
650
651static int
652creator_set_hw_cursor(video_adapter_t *adp, int col, int row)
653{
654
655 return (ENODEV);
656}
657
658static int
659creator_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
660 int celsize, int blink)
661{
662
663 return (ENODEV);
664}
665
666static int
667creator_blank_display(video_adapter_t *adp, int mode)
668{
669 struct creator_softc *sc;
670 uint32_t v;
671 int i;
672
673 sc = (struct creator_softc *)adp;
674 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
675 v = FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
676 switch (mode) {
677 case V_DISPLAY_ON:
678 v |= FFB_DAC_CFG_TGEN_VIDE;
679 break;
680 case V_DISPLAY_BLANK:
681 case V_DISPLAY_STAND_BY:
682 case V_DISPLAY_SUSPEND:
683 v &= ~FFB_DAC_CFG_TGEN_VIDE;
684 break;
685 }
686 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
687 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE, v);
688 for (i = 0; i < 10; i++) {
689 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE, FFB_DAC_CFG_TGEN);
690 (void)FFB_READ(sc, FFB_DAC, FFB_DAC_VALUE);
691 }
692 return (0);
693}
694
695static int
696creator_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
697 int prot)
698{
699
700 return (EINVAL);
701}
702
703static int
704creator_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
705{
706 struct creator_softc *sc;
707 struct fbcursor *fbc;
708 struct fbtype *fb;
709
710 sc = (struct creator_softc *)adp;
711 switch (cmd) {
712 case FBIOGTYPE:
713 fb = (struct fbtype *)data;
714 fb->fb_type = FBTYPE_CREATOR;
715 fb->fb_height = sc->sc_height;
716 fb->fb_width = sc->sc_width;
717 fb->fb_depth = fb->fb_cmsize = fb->fb_size = 0;
718 break;
719 case FBIOSCURSOR:
720 fbc = (struct fbcursor *)data;
721 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
722 creator_cursor_enable(sc, 0);
723 sc->sc_flags &= ~CREATOR_CUREN;
724 } else
725 return (ENODEV);
726 break;
727 break;
728 default:
729 return (fb_commonioctl(adp, cmd, data));
730 }
731 return (0);
732}
733
734static int
735creator_clear(video_adapter_t *adp)
736{
737 struct creator_softc *sc;
738
739 sc = (struct creator_softc *)adp;
740 creator_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
741 sc->sc_height);
742 return (0);
743}
744
745static int
746creator_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
747{
748 struct creator_softc *sc;
749
750 sc = (struct creator_softc *)adp;
751 creator_ras_setpmask(sc, 0xffffffff);
752 creator_ras_fifo_wait(sc, 2);
753 FFB_WRITE(sc, FFB_FBC, FFB_FBC_ROP, FBC_ROP_NEW);
754 FFB_WRITE(sc, FFB_FBC, FFB_FBC_DRAWOP, FBC_DRAWOP_RECTANGLE);
755 creator_ras_setfg(sc, creator_cmap[val & 0xf]);
756 /*
757 * Note that at least the Elite3D cards are sensitive to the order
758 * of operations here.
759 */
760 creator_ras_fifo_wait(sc, 4);
761 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BY, y);
762 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BX, x);
763 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BH, cy);
764 FFB_WRITE(sc, FFB_FBC, FFB_FBC_BW, cx);
765 creator_ras_wait(sc);
766 return (0);
767}
768
769static int
770creator_bitblt(video_adapter_t *adp, ...)
771{
772
773 return (ENODEV);
774}
775
776static int
777creator_diag(video_adapter_t *adp, int level)
778{
779 video_info_t info;
780
781 fb_dump_adp_info(adp->va_name, adp, level);
782 creator_get_info(adp, 0, &info);
783 fb_dump_mode_info(adp->va_name, adp, &info, level);
784 return (0);
785}
786
787static int
788creator_save_cursor_palette(video_adapter_t *adp, u_char *palette)
789{
790
791 return (ENODEV);
792}
793
794static int
795creator_load_cursor_palette(video_adapter_t *adp, u_char *palette)
796{
797
798 return (ENODEV);
799}
800
801static int
802creator_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
803{
804
805 return (ENODEV);
806}
807
808static int
809creator_putp(video_adapter_t *adp, vm_offset_t off, u_int32_t p, u_int32_t a,
810 int size, int bpp, int bit_ltor, int byte_ltor)
811{
812
813 return (ENODEV);
814}
815
816static int
817creator_putc(video_adapter_t *adp, vm_offset_t off, u_int8_t c, u_int8_t a)
818{
819 struct creator_softc *sc;
818 uint16_t *p;
820 const uint16_t *p;
819 int row;
820 int col;
821 int i;
822
823 sc = (struct creator_softc *)adp;
824 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
825 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
821 int row;
822 int col;
823 int i;
824
825 sc = (struct creator_softc *)adp;
826 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
827 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
826 p = (uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight);
828 p = (const uint16_t *)sc->sc_font + (c * adp->va_info.vi_cheight);
827 creator_ras_setfg(sc, creator_cmap[a & 0xf]);
828 creator_ras_setbg(sc, creator_cmap[(a >> 4) & 0xf]);
829 creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight);
830 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY,
831 ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin));
832 creator_ras_setfontw(sc, adp->va_info.vi_cwidth);
833 creator_ras_setfontinc(sc, 0x10000);
834 for (i = 0; i < adp->va_info.vi_cheight; i++) {
835 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16);
836 }
837 return (0);
838}
839
840static int
841creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
842{
843 int i;
844
845 for (i = 0; i < len; i++) {
846 (*vidsw[adp->va_index]->putc)(adp, off + i, s[i] & 0xff,
847 (s[i] & 0xff00) >> 8);
848 }
849 return (0);
850}
851
852static int
853creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
854 u_int32_t pixel_mask, int size, int width)
855{
856 struct creator_softc *sc;
857
858 sc = (struct creator_softc *)adp;
859 if (!(sc->sc_flags & CREATOR_CUREN)) {
860 creator_cursor_install(sc);
861 creator_cursor_enable(sc, 1);
862 sc->sc_flags |= CREATOR_CUREN;
863 }
864 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS);
865 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
866 ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin));
867 return (0);
868}
869
870/*
871 * bus interface
872 */
873static int
874creator_bus_probe(device_t dev)
875{
876 const char *name;
877 phandle_t node;
878 int type;
879
880 name = ofw_bus_get_name(dev);
881 node = ofw_bus_get_node(dev);
882 if (strcmp(name, "SUNW,ffb") == 0) {
883 if (OF_getprop(node, "board_type", &type, sizeof(type)) == -1)
884 return (ENXIO);
885 switch (type & 7) {
886 case 0x0:
887 device_set_desc(dev, "Creator");
888 break;
889 case 0x3:
890 device_set_desc(dev, "Creator3D");
891 break;
892 default:
893 return (ENXIO);
894 }
895 } else if (strcmp(name, "SUNW,afb") == 0)
896 device_set_desc(dev, "Elite3D");
897 else
898 return (ENXIO);
899 return (BUS_PROBE_DEFAULT);
900}
901
902static int
903creator_bus_attach(device_t dev)
904{
905 struct creator_softc *sc;
906 video_adapter_t *adp;
907 video_switch_t *sw;
908 phandle_t node;
909 int error;
910 int rid;
911 int unit;
912 int i;
913
914 node = ofw_bus_get_node(dev);
915 if ((sc = (struct creator_softc *)vid_get_adapter(vid_find_adapter(
916 CREATOR_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
917 device_printf(dev, "console\n");
918 device_set_softc(dev, sc);
919 } else {
920 sc = device_get_softc(dev);
921 sc->sc_node = node;
922 }
923 adp = &sc->sc_va;
924
925 /*
926 * Allocate resources regardless of whether we are the console
927 * and already obtained the bus tags and handles for the FFB_DAC
928 * and FFB_FBC register banks in creator_configure() or not so
929 * the resources are marked as taken in the respective RMAN.
930 * The supported cards use either 15 (Creator, Elite3D?) or 24
931 * (Creator3D?) register banks. We make sure that we can also
932 * allocate the resources for at least the FFB_DAC and FFB_FBC
933 * banks here. We try but don't actually care whether we can
934 * allocate more than these two resources and just limit the
935 * range accessible via creator_fb_mmap() accordingly.
936 */
937 for (i = 0; i < FFB_NREG; i++) {
938 rid = i;
939 sc->sc_reg[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
940 &rid, RF_ACTIVE);
941 if (sc->sc_reg[i] == NULL) {
942 if (i <= FFB_FBC) {
943 device_printf(dev,
944 "cannot allocate resources\n");
945 error = ENXIO;
946 goto fail;
947 }
948 break;
949 }
950 sc->sc_bt[i] = rman_get_bustag(sc->sc_reg[i]);
951 sc->sc_bh[i] = rman_get_bushandle(sc->sc_reg[i]);
952 }
953 /*
954 * The XFree86/Xorg sunffb(4) expects to be able to access the
955 * memory spanned by the first and the last resource as one chunk
956 * via creator_fb_mmap(), using offsets from the first resource,
957 * even though the backing resources are actually non-continuous.
958 * So make sure that the memory we provide is at least backed by
959 * increasing resources.
960 */
961 adp->va_mem_base = rman_get_start(sc->sc_reg[0]);
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]);
964 i++)
965 ;
966 adp->va_mem_size = rman_get_end(sc->sc_reg[i - 1]) -
967 adp->va_mem_base + 1;
968
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");
972 error = ENODEV;
973 goto fail;
974 }
975 /*
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
982 * unused one.
983 */
984 for (i = 0; i < devclass_get_maxunit(creator_devclass); i++)
985 if (vid_find_adapter(CREATOR_DRIVER_NAME, i) < 0)
986 break;
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");
991 goto fail;
992 }
993 }
994
995 if (bootverbose) {
996 if (sc->sc_flags & CREATOR_PAC1)
997 device_printf(dev,
998 "BT9068/PAC1 RAMDAC (%s cursor control)\n",
999 sc->sc_flags & CREATOR_CURINV ? "inverted" :
1000 "normal");
1001 else
1002 device_printf(dev, "BT498/PAC2 RAMDAC\n");
1003 }
1004 device_printf(dev, "resolution %dx%d\n", sc->sc_width, sc->sc_height);
1005
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;
1010
1011 EVENTHANDLER_REGISTER(shutdown_final, creator_shutdown, sc,
1012 SHUTDOWN_PRI_DEFAULT);
1013
1014 return (0);
1015
1016 fail:
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]);
1020 return (error);
1021}
1022
1023/*
1024 * /dev/fb interface
1025 */
1026static int
1027creator_fb_open(struct cdev *dev, int flags, int mode, struct thread *td)
1028{
1029
1030 return (0);
1031}
1032
1033static int
1034creator_fb_close(struct cdev *dev, int flags, int mode, struct thread *td)
1035{
1036
1037 return (0);
1038}
1039
1040static int
1041creator_fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
1042 struct thread *td)
1043{
1044 struct creator_softc *sc;
1045
1046 sc = dev->si_drv1;
1047 return (creator_ioctl(&sc->sc_va, cmd, data));
1048}
1049
1050static int
1051creator_fb_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
1052 int prot)
1053{
1054 struct creator_softc *sc;
1055 int i;
1056
1057 /*
1058 * NB: This is a special implementation based on the /dev/fb
1059 * requirements of the XFree86/Xorg sunffb(4).
1060 */
1061 sc = dev->si_drv1;
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_va.va_mem_size)
1068 return (EINVAL);
1069 *paddr = sc->sc_bh[0] + offset;
1070 return (0);
1071 }
1072 }
1073 return (EINVAL);
1074}
1075
1076/*
1077 * internal functions
1078 */
1079static void
1080creator_cursor_enable(struct creator_softc *sc, int onoff)
1081{
1082 int v;
1083
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;
1087 else
1088 v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1;
1089 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v);
1090}
1091
1092static void
1093creator_cursor_install(struct creator_softc *sc)
1094{
1095 int i, j;
1096
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]));
1109 }
1110 }
1111}
1112
1113static void
1114creator_shutdown(void *xsc)
1115{
1116 struct creator_softc *sc = xsc;
1117
1118 creator_cursor_enable(sc, 0);
1119 /*
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.
1123 */
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);
1127 }
1128}
829 creator_ras_setfg(sc, creator_cmap[a & 0xf]);
830 creator_ras_setbg(sc, creator_cmap[(a >> 4) & 0xf]);
831 creator_ras_fifo_wait(sc, 1 + adp->va_info.vi_cheight);
832 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONTXY,
833 ((row + sc->sc_ymargin) << 16) | (col + sc->sc_xmargin));
834 creator_ras_setfontw(sc, adp->va_info.vi_cwidth);
835 creator_ras_setfontinc(sc, 0x10000);
836 for (i = 0; i < adp->va_info.vi_cheight; i++) {
837 FFB_WRITE(sc, FFB_FBC, FFB_FBC_FONT, *p++ << 16);
838 }
839 return (0);
840}
841
842static int
843creator_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
844{
845 int i;
846
847 for (i = 0; i < len; i++) {
848 (*vidsw[adp->va_index]->putc)(adp, off + i, s[i] & 0xff,
849 (s[i] & 0xff00) >> 8);
850 }
851 return (0);
852}
853
854static int
855creator_putm(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
856 u_int32_t pixel_mask, int size, int width)
857{
858 struct creator_softc *sc;
859
860 sc = (struct creator_softc *)adp;
861 if (!(sc->sc_flags & CREATOR_CUREN)) {
862 creator_cursor_install(sc);
863 creator_cursor_enable(sc, 1);
864 sc->sc_flags |= CREATOR_CUREN;
865 }
866 FFB_WRITE(sc, FFB_DAC, FFB_DAC_TYPE2, FFB_DAC_CUR_POS);
867 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2,
868 ((y + sc->sc_ymargin) << 16) | (x + sc->sc_xmargin));
869 return (0);
870}
871
872/*
873 * bus interface
874 */
875static int
876creator_bus_probe(device_t dev)
877{
878 const char *name;
879 phandle_t node;
880 int type;
881
882 name = ofw_bus_get_name(dev);
883 node = ofw_bus_get_node(dev);
884 if (strcmp(name, "SUNW,ffb") == 0) {
885 if (OF_getprop(node, "board_type", &type, sizeof(type)) == -1)
886 return (ENXIO);
887 switch (type & 7) {
888 case 0x0:
889 device_set_desc(dev, "Creator");
890 break;
891 case 0x3:
892 device_set_desc(dev, "Creator3D");
893 break;
894 default:
895 return (ENXIO);
896 }
897 } else if (strcmp(name, "SUNW,afb") == 0)
898 device_set_desc(dev, "Elite3D");
899 else
900 return (ENXIO);
901 return (BUS_PROBE_DEFAULT);
902}
903
904static int
905creator_bus_attach(device_t dev)
906{
907 struct creator_softc *sc;
908 video_adapter_t *adp;
909 video_switch_t *sw;
910 phandle_t node;
911 int error;
912 int rid;
913 int unit;
914 int i;
915
916 node = ofw_bus_get_node(dev);
917 if ((sc = (struct creator_softc *)vid_get_adapter(vid_find_adapter(
918 CREATOR_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
919 device_printf(dev, "console\n");
920 device_set_softc(dev, sc);
921 } else {
922 sc = device_get_softc(dev);
923 sc->sc_node = node;
924 }
925 adp = &sc->sc_va;
926
927 /*
928 * Allocate resources regardless of whether we are the console
929 * and already obtained the bus tags and handles for the FFB_DAC
930 * and FFB_FBC register banks in creator_configure() or not so
931 * the resources are marked as taken in the respective RMAN.
932 * The supported cards use either 15 (Creator, Elite3D?) or 24
933 * (Creator3D?) register banks. We make sure that we can also
934 * allocate the resources for at least the FFB_DAC and FFB_FBC
935 * banks here. We try but don't actually care whether we can
936 * allocate more than these two resources and just limit the
937 * range accessible via creator_fb_mmap() accordingly.
938 */
939 for (i = 0; i < FFB_NREG; i++) {
940 rid = i;
941 sc->sc_reg[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
942 &rid, RF_ACTIVE);
943 if (sc->sc_reg[i] == NULL) {
944 if (i <= FFB_FBC) {
945 device_printf(dev,
946 "cannot allocate resources\n");
947 error = ENXIO;
948 goto fail;
949 }
950 break;
951 }
952 sc->sc_bt[i] = rman_get_bustag(sc->sc_reg[i]);
953 sc->sc_bh[i] = rman_get_bushandle(sc->sc_reg[i]);
954 }
955 /*
956 * The XFree86/Xorg sunffb(4) expects to be able to access the
957 * memory spanned by the first and the last resource as one chunk
958 * via creator_fb_mmap(), using offsets from the first resource,
959 * even though the backing resources are actually non-continuous.
960 * So make sure that the memory we provide is at least backed by
961 * increasing resources.
962 */
963 adp->va_mem_base = rman_get_start(sc->sc_reg[0]);
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]);
966 i++)
967 ;
968 adp->va_mem_size = rman_get_end(sc->sc_reg[i - 1]) -
969 adp->va_mem_base + 1;
970
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");
974 error = ENODEV;
975 goto fail;
976 }
977 /*
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
984 * unused one.
985 */
986 for (i = 0; i < devclass_get_maxunit(creator_devclass); i++)
987 if (vid_find_adapter(CREATOR_DRIVER_NAME, i) < 0)
988 break;
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");
993 goto fail;
994 }
995 }
996
997 if (bootverbose) {
998 if (sc->sc_flags & CREATOR_PAC1)
999 device_printf(dev,
1000 "BT9068/PAC1 RAMDAC (%s cursor control)\n",
1001 sc->sc_flags & CREATOR_CURINV ? "inverted" :
1002 "normal");
1003 else
1004 device_printf(dev, "BT498/PAC2 RAMDAC\n");
1005 }
1006 device_printf(dev, "resolution %dx%d\n", sc->sc_width, sc->sc_height);
1007
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;
1012
1013 EVENTHANDLER_REGISTER(shutdown_final, creator_shutdown, sc,
1014 SHUTDOWN_PRI_DEFAULT);
1015
1016 return (0);
1017
1018 fail:
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]);
1022 return (error);
1023}
1024
1025/*
1026 * /dev/fb interface
1027 */
1028static int
1029creator_fb_open(struct cdev *dev, int flags, int mode, struct thread *td)
1030{
1031
1032 return (0);
1033}
1034
1035static int
1036creator_fb_close(struct cdev *dev, int flags, int mode, struct thread *td)
1037{
1038
1039 return (0);
1040}
1041
1042static int
1043creator_fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flags,
1044 struct thread *td)
1045{
1046 struct creator_softc *sc;
1047
1048 sc = dev->si_drv1;
1049 return (creator_ioctl(&sc->sc_va, cmd, data));
1050}
1051
1052static int
1053creator_fb_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr,
1054 int prot)
1055{
1056 struct creator_softc *sc;
1057 int i;
1058
1059 /*
1060 * NB: This is a special implementation based on the /dev/fb
1061 * requirements of the XFree86/Xorg sunffb(4).
1062 */
1063 sc = dev->si_drv1;
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_va.va_mem_size)
1070 return (EINVAL);
1071 *paddr = sc->sc_bh[0] + offset;
1072 return (0);
1073 }
1074 }
1075 return (EINVAL);
1076}
1077
1078/*
1079 * internal functions
1080 */
1081static void
1082creator_cursor_enable(struct creator_softc *sc, int onoff)
1083{
1084 int v;
1085
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;
1089 else
1090 v = onoff ? 0 : FFB_DAC_CUR_CTRL_P0 | FFB_DAC_CUR_CTRL_P1;
1091 FFB_WRITE(sc, FFB_DAC, FFB_DAC_VALUE2, v);
1092}
1093
1094static void
1095creator_cursor_install(struct creator_softc *sc)
1096{
1097 int i, j;
1098
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]));
1111 }
1112 }
1113}
1114
1115static void
1116creator_shutdown(void *xsc)
1117{
1118 struct creator_softc *sc = xsc;
1119
1120 creator_cursor_enable(sc, 0);
1121 /*
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.
1125 */
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);
1129 }
1130}