agten.c revision 1.6.4.2 1 1.6.4.2 yamt /* $NetBSD: agten.c,v 1.6.4.2 2007/09/03 14:38:26 yamt Exp $ */
2 1.6.4.2 yamt
3 1.6.4.2 yamt /*-
4 1.6.4.2 yamt * Copyright (c) 2007 Michael Lorenz
5 1.6.4.2 yamt * All rights reserved.
6 1.6.4.2 yamt *
7 1.6.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.6.4.2 yamt * modification, are permitted provided that the following conditions
9 1.6.4.2 yamt * are met:
10 1.6.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.6.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.6.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.6.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.6.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.6.4.2 yamt * 3. Neither the name of The NetBSD Foundation nor the names of its
16 1.6.4.2 yamt * contributors may be used to endorse or promote products derived
17 1.6.4.2 yamt * from this software without specific prior written permission.
18 1.6.4.2 yamt *
19 1.6.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.6.4.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.6.4.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.6.4.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.6.4.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.6.4.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.6.4.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.6.4.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.6.4.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.6.4.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.6.4.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.6.4.2 yamt */
31 1.6.4.2 yamt
32 1.6.4.2 yamt #include <sys/cdefs.h>
33 1.6.4.2 yamt __KERNEL_RCSID(0, "$NetBSD: agten.c,v 1.6.4.2 2007/09/03 14:38:26 yamt Exp $");
34 1.6.4.2 yamt
35 1.6.4.2 yamt /*
36 1.6.4.2 yamt * a driver for the Fujitsu AG-10e SBus framebuffer
37 1.6.4.2 yamt *
38 1.6.4.2 yamt * this thing is Frankenstein's Monster among graphics boards.
39 1.6.4.2 yamt * it contains three graphics chips:
40 1.6.4.2 yamt * a GLint - 24bit stuff, double-buffered
41 1.6.4.2 yamt * an Imagine 128 which provides an 8bit overlay
42 1.6.4.2 yamt * a Weitek P9100 which provides WIDs
43 1.6.4.2 yamt * so here we need to mess only with the P9100 and the I128 - for X we just
44 1.6.4.2 yamt * hide the overlay and let the Xserver mess with the GLint
45 1.6.4.2 yamt */
46 1.6.4.2 yamt
47 1.6.4.2 yamt #include <sys/param.h>
48 1.6.4.2 yamt #include <sys/systm.h>
49 1.6.4.2 yamt #include <sys/kernel.h>
50 1.6.4.2 yamt #include <sys/device.h>
51 1.6.4.2 yamt #include <sys/proc.h>
52 1.6.4.2 yamt #include <sys/mutex.h>
53 1.6.4.2 yamt #include <sys/ioctl.h>
54 1.6.4.2 yamt #include <sys/kernel.h>
55 1.6.4.2 yamt #include <sys/systm.h>
56 1.6.4.2 yamt #include <sys/conf.h>
57 1.6.4.2 yamt
58 1.6.4.2 yamt #include <dev/sun/fbio.h>
59 1.6.4.2 yamt #include <dev/sun/fbvar.h>
60 1.6.4.2 yamt #include <dev/sun/btreg.h>
61 1.6.4.2 yamt #include <dev/sun/btvar.h>
62 1.6.4.2 yamt
63 1.6.4.2 yamt #include <machine/bus.h>
64 1.6.4.2 yamt #include <machine/autoconf.h>
65 1.6.4.2 yamt
66 1.6.4.2 yamt #include <dev/sbus/sbusvar.h>
67 1.6.4.2 yamt
68 1.6.4.2 yamt #include <dev/wscons/wsconsio.h>
69 1.6.4.2 yamt #include <dev/wscons/wsdisplayvar.h>
70 1.6.4.2 yamt #include <dev/rasops/rasops.h>
71 1.6.4.2 yamt #include <dev/wsfont/wsfont.h>
72 1.6.4.2 yamt
73 1.6.4.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
74 1.6.4.2 yamt
75 1.6.4.2 yamt #include <dev/sbus/p9100reg.h>
76 1.6.4.2 yamt #include <dev/ic/ibm561reg.h>
77 1.6.4.2 yamt #include <dev/ic/i128reg.h>
78 1.6.4.2 yamt #include <dev/ic/i128var.h>
79 1.6.4.2 yamt
80 1.6.4.2 yamt #include "opt_agten.h"
81 1.6.4.2 yamt
82 1.6.4.2 yamt static int agten_match(struct device *, struct cfdata *, void *);
83 1.6.4.2 yamt static void agten_attach(struct device *, struct device *, void *);
84 1.6.4.2 yamt
85 1.6.4.2 yamt static int agten_ioctl(void *, void *, u_long, void *, int, struct lwp *);
86 1.6.4.2 yamt static paddr_t agten_mmap(void *, void *, off_t, int);
87 1.6.4.2 yamt static void agten_init_screen(void *, struct vcons_screen *, int, long *);
88 1.6.4.2 yamt
89 1.6.4.2 yamt struct agten_softc {
90 1.6.4.2 yamt struct device sc_dev; /* base device */
91 1.6.4.2 yamt struct sbusdev sc_sd; /* sbus device */
92 1.6.4.2 yamt struct fbdevice sc_fb; /* frame buffer device */
93 1.6.4.2 yamt
94 1.6.4.2 yamt struct vcons_screen sc_console_screen;
95 1.6.4.2 yamt struct wsscreen_descr sc_defaultscreen_descr;
96 1.6.4.2 yamt const struct wsscreen_descr *sc_screens[1];
97 1.6.4.2 yamt struct wsscreen_list sc_screenlist;
98 1.6.4.2 yamt
99 1.6.4.2 yamt bus_space_tag_t sc_bustag;
100 1.6.4.2 yamt
101 1.6.4.2 yamt bus_space_handle_t sc_i128_fbh;
102 1.6.4.2 yamt bus_size_t sc_i128_fbsz;
103 1.6.4.2 yamt bus_space_handle_t sc_i128_regh;
104 1.6.4.2 yamt bus_space_handle_t sc_p9100_regh;
105 1.6.4.2 yamt bus_addr_t sc_glint_fb;
106 1.6.4.2 yamt bus_addr_t sc_glint_regs;
107 1.6.4.2 yamt uint32_t sc_glint_fbsz;
108 1.6.4.2 yamt
109 1.6.4.2 yamt uint32_t sc_width;
110 1.6.4.2 yamt uint32_t sc_height; /* panel width / height */
111 1.6.4.2 yamt uint32_t sc_stride;
112 1.6.4.2 yamt uint32_t sc_depth;
113 1.6.4.2 yamt
114 1.6.4.2 yamt int sc_cursor_x;
115 1.6.4.2 yamt int sc_cursor_y;
116 1.6.4.2 yamt int sc_video; /* video output enabled */
117 1.6.4.2 yamt
118 1.6.4.2 yamt /* some /dev/fb* stuff */
119 1.6.4.2 yamt int sc_fb_is_open;
120 1.6.4.2 yamt
121 1.6.4.2 yamt union bt_cmap sc_cmap; /* Brooktree color map */
122 1.6.4.2 yamt
123 1.6.4.2 yamt int sc_mode;
124 1.6.4.2 yamt uint32_t sc_bg;
125 1.6.4.2 yamt struct vcons_data vd;
126 1.6.4.2 yamt };
127 1.6.4.2 yamt
128 1.6.4.2 yamt CFATTACH_DECL(agten, sizeof(struct agten_softc),
129 1.6.4.2 yamt agten_match, agten_attach, NULL, NULL);
130 1.6.4.2 yamt
131 1.6.4.2 yamt
132 1.6.4.2 yamt static int agten_putcmap(struct agten_softc *, struct wsdisplay_cmap *);
133 1.6.4.2 yamt static int agten_getcmap(struct agten_softc *, struct wsdisplay_cmap *);
134 1.6.4.2 yamt static int agten_putpalreg(struct agten_softc *, uint8_t, uint8_t,
135 1.6.4.2 yamt uint8_t, uint8_t);
136 1.6.4.2 yamt static void agten_init(struct agten_softc *);
137 1.6.4.2 yamt static void agten_gfx(struct agten_softc *);
138 1.6.4.2 yamt static void agten_set_video(struct agten_softc *, int);
139 1.6.4.2 yamt static int agten_get_video(struct agten_softc *);
140 1.6.4.2 yamt
141 1.6.4.2 yamt static void agten_copycols(void *, int, int, int, int);
142 1.6.4.2 yamt static void agten_erasecols(void *, int, int, int, long);
143 1.6.4.2 yamt static void agten_copyrows(void *, int, int, int);
144 1.6.4.2 yamt static void agten_eraserows(void *, int, int, long);
145 1.6.4.2 yamt
146 1.6.4.2 yamt static void agten_move_cursor(struct agten_softc *, int, int);
147 1.6.4.2 yamt static int agten_do_cursor(struct agten_softc *sc,
148 1.6.4.2 yamt struct wsdisplay_cursor *);
149 1.6.4.2 yamt static int agten_do_sun_cursor(struct agten_softc *sc,
150 1.6.4.2 yamt struct fbcursor *);
151 1.6.4.2 yamt
152 1.6.4.2 yamt static uint16_t util_interleave(uint8_t, uint8_t);
153 1.6.4.2 yamt static uint16_t util_interleave_lin(uint8_t, uint8_t);
154 1.6.4.2 yamt
155 1.6.4.2 yamt extern const u_char rasops_cmap[768];
156 1.6.4.2 yamt
157 1.6.4.2 yamt struct wsdisplay_accessops agten_accessops = {
158 1.6.4.2 yamt agten_ioctl,
159 1.6.4.2 yamt agten_mmap,
160 1.6.4.2 yamt NULL, /* alloc_screen */
161 1.6.4.2 yamt NULL, /* free_screen */
162 1.6.4.2 yamt NULL, /* show_screen */
163 1.6.4.2 yamt NULL, /* load_font */
164 1.6.4.2 yamt NULL, /* pollc */
165 1.6.4.2 yamt NULL /* scroll */
166 1.6.4.2 yamt };
167 1.6.4.2 yamt
168 1.6.4.2 yamt /* /dev/fb* stuff */
169 1.6.4.2 yamt extern struct cfdriver agten_cd;
170 1.6.4.2 yamt
171 1.6.4.2 yamt static int agten_fb_open(dev_t, int, int, struct lwp *);
172 1.6.4.2 yamt static int agten_fb_close(dev_t, int, int, struct lwp *);
173 1.6.4.2 yamt static int agten_fb_ioctl(dev_t, u_long, void *, int, struct lwp *);
174 1.6.4.2 yamt static paddr_t agten_fb_mmap(dev_t, off_t, int);
175 1.6.4.2 yamt static void agten_fb_unblank(struct device *);
176 1.6.4.2 yamt
177 1.6.4.2 yamt static struct fbdriver agtenfbdriver = {
178 1.6.4.2 yamt agten_fb_unblank, agten_fb_open, agten_fb_close, agten_fb_ioctl,
179 1.6.4.2 yamt nopoll, agten_fb_mmap, nokqfilter
180 1.6.4.2 yamt };
181 1.6.4.2 yamt
182 1.6.4.2 yamt static inline void
183 1.6.4.2 yamt agten_write_dac(struct agten_softc *sc, int reg, uint8_t val)
184 1.6.4.2 yamt {
185 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
186 1.6.4.2 yamt 0x200 + (reg << 2), (uint32_t)val << 16);
187 1.6.4.2 yamt }
188 1.6.4.2 yamt
189 1.6.4.2 yamt static inline void
190 1.6.4.2 yamt agten_write_idx(struct agten_softc *sc, int offset)
191 1.6.4.2 yamt {
192 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
193 1.6.4.2 yamt 0x200 + (IBM561_ADDR_LOW << 2), (offset & 0xff) << 16);
194 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
195 1.6.4.2 yamt 0x200 + (IBM561_ADDR_HIGH << 2), ((offset >> 8) & 0xff) << 16);
196 1.6.4.2 yamt }
197 1.6.4.2 yamt
198 1.6.4.2 yamt static inline void
199 1.6.4.2 yamt agten_write_dac_10(struct agten_softc *sc, int reg, uint16_t val)
200 1.6.4.2 yamt {
201 1.6.4.2 yamt agten_write_dac(sc, reg, (val >> 2) & 0xff);
202 1.6.4.2 yamt agten_write_dac(sc, reg, (val & 0x3) << 6);
203 1.6.4.2 yamt }
204 1.6.4.2 yamt
205 1.6.4.2 yamt static int
206 1.6.4.2 yamt agten_match(struct device *dev, struct cfdata *cf, void *aux)
207 1.6.4.2 yamt {
208 1.6.4.2 yamt struct sbus_attach_args *sa = aux;
209 1.6.4.2 yamt
210 1.6.4.2 yamt if (strcmp("PFU,aga", sa->sa_name) == 0)
211 1.6.4.2 yamt return 100;
212 1.6.4.2 yamt return 0;
213 1.6.4.2 yamt }
214 1.6.4.2 yamt
215 1.6.4.2 yamt static void
216 1.6.4.2 yamt agten_attach(struct device *parent, struct device *dev, void *aux)
217 1.6.4.2 yamt {
218 1.6.4.2 yamt struct agten_softc *sc = (struct agten_softc *)dev;
219 1.6.4.2 yamt struct sbus_attach_args *sa = aux;
220 1.6.4.2 yamt struct fbdevice *fb = &sc->sc_fb;
221 1.6.4.2 yamt struct wsemuldisplaydev_attach_args aa;
222 1.6.4.2 yamt struct rasops_info *ri;
223 1.6.4.2 yamt long defattr;
224 1.6.4.2 yamt uint32_t reg;
225 1.6.4.2 yamt int node = sa->sa_node;
226 1.6.4.2 yamt int console;
227 1.6.4.2 yamt
228 1.6.4.2 yamt sc->sc_defaultscreen_descr = (struct wsscreen_descr){
229 1.6.4.2 yamt "default",
230 1.6.4.2 yamt 0, 0,
231 1.6.4.2 yamt NULL,
232 1.6.4.2 yamt 8, 16,
233 1.6.4.2 yamt WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
234 1.6.4.2 yamt NULL
235 1.6.4.2 yamt };
236 1.6.4.2 yamt sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
237 1.6.4.2 yamt sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
238 1.6.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
239 1.6.4.2 yamt sc->sc_fb_is_open = 0;
240 1.6.4.2 yamt sc->sc_video = -1;
241 1.6.4.2 yamt sc->sc_bustag = sa->sa_bustag;
242 1.6.4.2 yamt #if 0
243 1.6.4.2 yamt sc->sc_shadowfb = malloc(sc->sc_fbsize, M_DEVBUF, M_WAITOK);
244 1.6.4.2 yamt
245 1.6.4.2 yamt dict = device_properties(&sc->sc_dev);
246 1.6.4.2 yamt
247 1.6.4.2 yamt prop_dictionary_get_bool(dict, "is_console", &console);
248 1.6.4.2 yamt #endif
249 1.6.4.2 yamt
250 1.6.4.2 yamt reg = prom_getpropint(node, "i128_fb_physaddr", -1);
251 1.6.4.2 yamt sc->sc_i128_fbsz = prom_getpropint(node, "i128_fb_size", -1);
252 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
253 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
254 1.6.4.2 yamt sc->sc_i128_fbsz, BUS_SPACE_MAP_LINEAR, &sc->sc_i128_fbh) != 0) {
255 1.6.4.2 yamt
256 1.6.4.2 yamt aprint_error("%s: unable to map the framebuffer\n",
257 1.6.4.2 yamt dev->dv_xname);
258 1.6.4.2 yamt return;
259 1.6.4.2 yamt }
260 1.6.4.2 yamt fb->fb_pixels = bus_space_vaddr(sc->sc_bustag, sc->sc_i128_fbh);
261 1.6.4.2 yamt
262 1.6.4.2 yamt reg = prom_getpropint(node, "i128_reg_physaddr", -1);
263 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
264 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
265 1.6.4.2 yamt 0x10000, 0, &sc->sc_i128_regh) != 0) {
266 1.6.4.2 yamt
267 1.6.4.2 yamt aprint_error("%s: unable to map I128 registers\n",
268 1.6.4.2 yamt dev->dv_xname);
269 1.6.4.2 yamt return;
270 1.6.4.2 yamt }
271 1.6.4.2 yamt
272 1.6.4.2 yamt reg = prom_getpropint(node, "p9100_reg_physaddr", -1);
273 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
274 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
275 1.6.4.2 yamt 0x8000, 0, &sc->sc_p9100_regh) != 0) {
276 1.6.4.2 yamt
277 1.6.4.2 yamt aprint_error("%s: unable to map P9100 registers\n",
278 1.6.4.2 yamt dev->dv_xname);
279 1.6.4.2 yamt return;
280 1.6.4.2 yamt }
281 1.6.4.2 yamt
282 1.6.4.2 yamt reg = prom_getpropint(node, "glint_fb0_physaddr", -1);
283 1.6.4.2 yamt sc->sc_glint_fb = sbus_bus_addr(sc->sc_bustag,
284 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
285 1.6.4.2 yamt sc->sc_glint_fbsz = prom_getpropint(node, "glint_fb0_size", -1);
286 1.6.4.2 yamt reg = prom_getpropint(node, "glint_reg_physaddr", -1);
287 1.6.4.2 yamt sc->sc_glint_regs = sbus_bus_addr(sc->sc_bustag,
288 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
289 1.6.4.2 yamt
290 1.6.4.2 yamt sbus_establish(&sc->sc_sd, &sc->sc_dev);
291 1.6.4.2 yamt #if 0
292 1.6.4.2 yamt bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
293 1.6.4.2 yamt agten_intr, sc);
294 1.6.4.2 yamt #endif
295 1.6.4.2 yamt
296 1.6.4.2 yamt sc->sc_width = prom_getpropint(node, "ffb_width", 800);
297 1.6.4.2 yamt sc->sc_height = prom_getpropint(node, "ffb_height", 600);
298 1.6.4.2 yamt sc->sc_depth = prom_getpropint(node, "ffb_depth", 8);
299 1.6.4.2 yamt sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
300 1.6.4.2 yamt
301 1.6.4.2 yamt agten_init(sc);
302 1.6.4.2 yamt
303 1.6.4.2 yamt console = fb_is_console(node);
304 1.6.4.2 yamt
305 1.6.4.2 yamt vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
306 1.6.4.2 yamt &agten_accessops);
307 1.6.4.2 yamt sc->vd.init_screen = agten_init_screen;
308 1.6.4.2 yamt
309 1.6.4.2 yamt ri = &sc->sc_console_screen.scr_ri;
310 1.6.4.2 yamt
311 1.6.4.2 yamt if (console) {
312 1.6.4.2 yamt vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
313 1.6.4.2 yamt &defattr);
314 1.6.4.2 yamt sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
315 1.6.4.2 yamt
316 1.6.4.2 yamt sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
317 1.6.4.2 yamt sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
318 1.6.4.2 yamt sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
319 1.6.4.2 yamt sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
320 1.6.4.2 yamt wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
321 1.6.4.2 yamt defattr);
322 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0,
323 1.6.4.2 yamt sc->sc_width, sc->sc_height,
324 1.6.4.2 yamt ri->ri_devcmap[(defattr >> 16) & 0xff]);
325 1.6.4.2 yamt } else {
326 1.6.4.2 yamt /*
327 1.6.4.2 yamt * since we're not the console we can postpone the rest
328 1.6.4.2 yamt * until someone actually allocates a screen for us
329 1.6.4.2 yamt */
330 1.6.4.2 yamt }
331 1.6.4.2 yamt
332 1.6.4.2 yamt /* Initialize the default color map. */
333 1.6.4.2 yamt
334 1.6.4.2 yamt aa.console = console;
335 1.6.4.2 yamt aa.scrdata = &sc->sc_screenlist;
336 1.6.4.2 yamt aa.accessops = &agten_accessops;
337 1.6.4.2 yamt aa.accesscookie = &sc->vd;
338 1.6.4.2 yamt
339 1.6.4.2 yamt config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
340 1.6.4.2 yamt
341 1.6.4.2 yamt fb->fb_driver = &agtenfbdriver;
342 1.6.4.2 yamt fb->fb_device = &sc->sc_dev;
343 1.6.4.2 yamt fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
344 1.6.4.2 yamt fb->fb_type.fb_type = FBTYPE_AG10E;
345 1.6.4.2 yamt fb->fb_type.fb_cmsize = 256; /* doesn't matter, we're always 24bit */
346 1.6.4.2 yamt fb->fb_type.fb_size = sc->sc_glint_fbsz;
347 1.6.4.2 yamt fb->fb_type.fb_width = sc->sc_width;
348 1.6.4.2 yamt fb->fb_type.fb_height = sc->sc_height;
349 1.6.4.2 yamt fb->fb_type.fb_depth = 32;
350 1.6.4.2 yamt fb->fb_linebytes = sc->sc_stride;
351 1.6.4.2 yamt fb_attach(fb, console);
352 1.6.4.2 yamt agten_set_video(sc, 1); /* make sure video's on */
353 1.6.4.2 yamt }
354 1.6.4.2 yamt
355 1.6.4.2 yamt static int
356 1.6.4.2 yamt agten_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
357 1.6.4.2 yamt struct lwp *l)
358 1.6.4.2 yamt {
359 1.6.4.2 yamt struct vcons_data *vd = v;
360 1.6.4.2 yamt struct agten_softc *sc = vd->cookie;
361 1.6.4.2 yamt struct wsdisplay_fbinfo *wdf;
362 1.6.4.2 yamt struct vcons_screen *ms = vd->active;
363 1.6.4.2 yamt
364 1.6.4.2 yamt switch (cmd) {
365 1.6.4.2 yamt
366 1.6.4.2 yamt case WSDISPLAYIO_GTYPE:
367 1.6.4.2 yamt *(u_int *)data = WSDISPLAY_TYPE_AG10;
368 1.6.4.2 yamt return 0;
369 1.6.4.2 yamt
370 1.6.4.2 yamt case WSDISPLAYIO_GINFO:
371 1.6.4.2 yamt if (ms == NULL)
372 1.6.4.2 yamt return ENODEV;
373 1.6.4.2 yamt wdf = (void *)data;
374 1.6.4.2 yamt wdf->height = ms->scr_ri.ri_height;
375 1.6.4.2 yamt wdf->width = ms->scr_ri.ri_width;
376 1.6.4.2 yamt wdf->depth = 32;
377 1.6.4.2 yamt wdf->cmsize = 256;
378 1.6.4.2 yamt return 0;
379 1.6.4.2 yamt
380 1.6.4.2 yamt case WSDISPLAYIO_GVIDEO:
381 1.6.4.2 yamt *(int *)data = sc->sc_video;
382 1.6.4.2 yamt return 0;
383 1.6.4.2 yamt
384 1.6.4.2 yamt case WSDISPLAYIO_SVIDEO:
385 1.6.4.2 yamt agten_set_video(sc, *(int *)data);
386 1.6.4.2 yamt return 0;
387 1.6.4.2 yamt
388 1.6.4.2 yamt case WSDISPLAYIO_GETCMAP:
389 1.6.4.2 yamt return agten_getcmap(sc,
390 1.6.4.2 yamt (struct wsdisplay_cmap *)data);
391 1.6.4.2 yamt
392 1.6.4.2 yamt case WSDISPLAYIO_PUTCMAP:
393 1.6.4.2 yamt return agten_putcmap(sc,
394 1.6.4.2 yamt (struct wsdisplay_cmap *)data);
395 1.6.4.2 yamt
396 1.6.4.2 yamt case WSDISPLAYIO_LINEBYTES:
397 1.6.4.2 yamt *(u_int *)data = sc->sc_stride << 2;
398 1.6.4.2 yamt return 0;
399 1.6.4.2 yamt
400 1.6.4.2 yamt case WSDISPLAYIO_SMODE:
401 1.6.4.2 yamt {
402 1.6.4.2 yamt int new_mode = *(int*)data;
403 1.6.4.2 yamt if (new_mode != sc->sc_mode) {
404 1.6.4.2 yamt sc->sc_mode = new_mode;
405 1.6.4.2 yamt if(new_mode == WSDISPLAYIO_MODE_EMUL) {
406 1.6.4.2 yamt agten_init(sc);
407 1.6.4.2 yamt vcons_redraw_screen(ms);
408 1.6.4.2 yamt } else {
409 1.6.4.2 yamt agten_gfx(sc);
410 1.6.4.2 yamt }
411 1.6.4.2 yamt }
412 1.6.4.2 yamt }
413 1.6.4.2 yamt return 0;
414 1.6.4.2 yamt
415 1.6.4.2 yamt case WSDISPLAYIO_GCURPOS:
416 1.6.4.2 yamt {
417 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
418 1.6.4.2 yamt
419 1.6.4.2 yamt cp->x = sc->sc_cursor_x;
420 1.6.4.2 yamt cp->y = sc->sc_cursor_y;
421 1.6.4.2 yamt }
422 1.6.4.2 yamt return 0;
423 1.6.4.2 yamt
424 1.6.4.2 yamt case WSDISPLAYIO_SCURPOS:
425 1.6.4.2 yamt {
426 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
427 1.6.4.2 yamt
428 1.6.4.2 yamt agten_move_cursor(sc, cp->x, cp->y);
429 1.6.4.2 yamt }
430 1.6.4.2 yamt return 0;
431 1.6.4.2 yamt
432 1.6.4.2 yamt case WSDISPLAYIO_GCURMAX:
433 1.6.4.2 yamt {
434 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
435 1.6.4.2 yamt
436 1.6.4.2 yamt cp->x = 64;
437 1.6.4.2 yamt cp->y = 64;
438 1.6.4.2 yamt }
439 1.6.4.2 yamt return 0;
440 1.6.4.2 yamt
441 1.6.4.2 yamt case WSDISPLAYIO_SCURSOR:
442 1.6.4.2 yamt {
443 1.6.4.2 yamt struct wsdisplay_cursor *cursor = (void *)data;
444 1.6.4.2 yamt
445 1.6.4.2 yamt return agten_do_cursor(sc, cursor);
446 1.6.4.2 yamt }
447 1.6.4.2 yamt }
448 1.6.4.2 yamt return EPASSTHROUGH;
449 1.6.4.2 yamt }
450 1.6.4.2 yamt
451 1.6.4.2 yamt static paddr_t
452 1.6.4.2 yamt agten_mmap(void *v, void *vs, off_t offset, int prot)
453 1.6.4.2 yamt {
454 1.6.4.2 yamt struct vcons_data *vd = v;
455 1.6.4.2 yamt struct agten_softc *sc = vd->cookie;
456 1.6.4.2 yamt
457 1.6.4.2 yamt if (offset < sc->sc_glint_fbsz)
458 1.6.4.2 yamt return bus_space_mmap(sc->sc_bustag, sc->sc_glint_fb, offset,
459 1.6.4.2 yamt prot, BUS_SPACE_MAP_LINEAR);
460 1.6.4.2 yamt return -1;
461 1.6.4.2 yamt }
462 1.6.4.2 yamt
463 1.6.4.2 yamt static void
464 1.6.4.2 yamt agten_init_screen(void *cookie, struct vcons_screen *scr,
465 1.6.4.2 yamt int existing, long *defattr)
466 1.6.4.2 yamt {
467 1.6.4.2 yamt struct agten_softc *sc = cookie;
468 1.6.4.2 yamt struct rasops_info *ri = &scr->scr_ri;
469 1.6.4.2 yamt
470 1.6.4.2 yamt ri->ri_depth = sc->sc_depth;
471 1.6.4.2 yamt ri->ri_width = sc->sc_width;
472 1.6.4.2 yamt ri->ri_height = sc->sc_height;
473 1.6.4.2 yamt ri->ri_stride = sc->sc_stride;
474 1.6.4.2 yamt ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
475 1.6.4.2 yamt
476 1.6.4.2 yamt ri->ri_bits = (char *)sc->sc_fb.fb_pixels;
477 1.6.4.2 yamt
478 1.6.4.2 yamt if (existing) {
479 1.6.4.2 yamt ri->ri_flg |= RI_CLEAR;
480 1.6.4.2 yamt }
481 1.6.4.2 yamt
482 1.6.4.2 yamt rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
483 1.6.4.2 yamt ri->ri_caps = WSSCREEN_WSCOLORS;
484 1.6.4.2 yamt
485 1.6.4.2 yamt rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
486 1.6.4.2 yamt sc->sc_width / ri->ri_font->fontwidth);
487 1.6.4.2 yamt
488 1.6.4.2 yamt ri->ri_hw = scr;
489 1.6.4.2 yamt ri->ri_ops.copyrows = agten_copyrows;
490 1.6.4.2 yamt ri->ri_ops.eraserows = agten_eraserows;
491 1.6.4.2 yamt ri->ri_ops.copycols = agten_copycols;
492 1.6.4.2 yamt ri->ri_ops.erasecols = agten_erasecols;
493 1.6.4.2 yamt
494 1.6.4.2 yamt }
495 1.6.4.2 yamt
496 1.6.4.2 yamt static int
497 1.6.4.2 yamt agten_putcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
498 1.6.4.2 yamt {
499 1.6.4.2 yamt u_int index = cm->index;
500 1.6.4.2 yamt u_int count = cm->count;
501 1.6.4.2 yamt int i, error;
502 1.6.4.2 yamt u_char rbuf[256], gbuf[256], bbuf[256];
503 1.6.4.2 yamt u_char *r, *g, *b;
504 1.6.4.2 yamt
505 1.6.4.2 yamt if (cm->index >= 256 || cm->count > 256 ||
506 1.6.4.2 yamt (cm->index + cm->count) > 256)
507 1.6.4.2 yamt return EINVAL;
508 1.6.4.2 yamt error = copyin(cm->red, &rbuf[index], count);
509 1.6.4.2 yamt if (error)
510 1.6.4.2 yamt return error;
511 1.6.4.2 yamt error = copyin(cm->green, &gbuf[index], count);
512 1.6.4.2 yamt if (error)
513 1.6.4.2 yamt return error;
514 1.6.4.2 yamt error = copyin(cm->blue, &bbuf[index], count);
515 1.6.4.2 yamt if (error)
516 1.6.4.2 yamt return error;
517 1.6.4.2 yamt
518 1.6.4.2 yamt r = &rbuf[index];
519 1.6.4.2 yamt g = &gbuf[index];
520 1.6.4.2 yamt b = &bbuf[index];
521 1.6.4.2 yamt
522 1.6.4.2 yamt for (i = 0; i < count; i++) {
523 1.6.4.2 yamt agten_putpalreg(sc, index, *r, *g, *b);
524 1.6.4.2 yamt index++;
525 1.6.4.2 yamt r++, g++, b++;
526 1.6.4.2 yamt }
527 1.6.4.2 yamt return 0;
528 1.6.4.2 yamt }
529 1.6.4.2 yamt
530 1.6.4.2 yamt static int
531 1.6.4.2 yamt agten_getcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
532 1.6.4.2 yamt {
533 1.6.4.2 yamt u_int index = cm->index;
534 1.6.4.2 yamt u_int count = cm->count;
535 1.6.4.2 yamt int error, i;
536 1.6.4.2 yamt uint8_t red[256], green[256], blue[256];
537 1.6.4.2 yamt
538 1.6.4.2 yamt if (index >= 255 || count > 256 || index + count > 256)
539 1.6.4.2 yamt return EINVAL;
540 1.6.4.2 yamt
541 1.6.4.2 yamt i = index;
542 1.6.4.2 yamt while (i < (index + count)) {
543 1.6.4.2 yamt red[i] = sc->sc_cmap.cm_map[i][0];
544 1.6.4.2 yamt green[i] = sc->sc_cmap.cm_map[i][1];
545 1.6.4.2 yamt blue[i] = sc->sc_cmap.cm_map[i][2];
546 1.6.4.2 yamt i++;
547 1.6.4.2 yamt }
548 1.6.4.2 yamt error = copyout(&red[index], cm->red, count);
549 1.6.4.2 yamt if (error)
550 1.6.4.2 yamt return error;
551 1.6.4.2 yamt error = copyout(&green[index], cm->green, count);
552 1.6.4.2 yamt if (error)
553 1.6.4.2 yamt return error;
554 1.6.4.2 yamt error = copyout(&blue[index], cm->blue, count);
555 1.6.4.2 yamt if (error)
556 1.6.4.2 yamt return error;
557 1.6.4.2 yamt
558 1.6.4.2 yamt return 0;
559 1.6.4.2 yamt }
560 1.6.4.2 yamt
561 1.6.4.2 yamt static int
562 1.6.4.2 yamt agten_putpalreg(struct agten_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
563 1.6.4.2 yamt uint8_t b)
564 1.6.4.2 yamt {
565 1.6.4.2 yamt
566 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][0] = r;
567 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][1] = g;
568 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][2] = b;
569 1.6.4.2 yamt agten_write_idx(sc, IBM561_CMAP_TABLE + idx);
570 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, r);
571 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, g);
572 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, b);
573 1.6.4.2 yamt return 0;
574 1.6.4.2 yamt }
575 1.6.4.2 yamt
576 1.6.4.2 yamt static void
577 1.6.4.2 yamt agten_init(struct agten_softc *sc)
578 1.6.4.2 yamt {
579 1.6.4.2 yamt int i, j;
580 1.6.4.2 yamt uint32_t src, srcw;
581 1.6.4.2 yamt volatile uint32_t junk;
582 1.6.4.2 yamt
583 1.6.4.2 yamt /* first we set up the colour map */
584 1.6.4.2 yamt j = 0;
585 1.6.4.2 yamt for (i = 0; i < 256; i++) {
586 1.6.4.2 yamt
587 1.6.4.2 yamt agten_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
588 1.6.4.2 yamt rasops_cmap[j + 2]);
589 1.6.4.2 yamt j += 3;
590 1.6.4.2 yamt }
591 1.6.4.2 yamt
592 1.6.4.2 yamt /* then we set up a linear LUT for 24bit colour */
593 1.6.4.2 yamt agten_write_idx(sc, IBM561_CMAP_TABLE + 256);
594 1.6.4.2 yamt for (i = 0; i < 256; i++) {
595 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
596 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
597 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
598 1.6.4.2 yamt }
599 1.6.4.2 yamt
600 1.6.4.2 yamt /* and the linear gamma maps */
601 1.6.4.2 yamt agten_write_idx(sc, IBM561_RED_GAMMA_TABLE);
602 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
603 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
604 1.6.4.2 yamt agten_write_idx(sc, IBM561_GREEN_GAMMA_TABLE);
605 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
606 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
607 1.6.4.2 yamt agten_write_idx(sc, IBM561_BLUE_GAMMA_TABLE);
608 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
609 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
610 1.6.4.2 yamt
611 1.6.4.2 yamt /* enable outouts, RGB mode */
612 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG3);
613 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, 0x41);
614 1.6.4.2 yamt
615 1.6.4.2 yamt /* MUX 4:1 basic, 8bit overlay, 8bit WIDs */
616 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG1);
617 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, 0x2c);
618 1.6.4.2 yamt
619 1.6.4.2 yamt /* use internal PLL, enable video output */
620 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG2);
621 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, CR2_ENABLE_CLC | CR2_PLL_REF_SELECT |
622 1.6.4.2 yamt CR2_PIXEL_CLOCK_SELECT | CR2_ENABLE_RGB_OUTPUT);
623 1.6.4.2 yamt
624 1.6.4.2 yamt /* now set up some window attributes */
625 1.6.4.2 yamt
626 1.6.4.2 yamt /*
627 1.6.4.2 yamt * direct colour, 24 bit, transparency off, LUT from 0x100
628 1.6.4.2 yamt * we need to use direct colour and a linear LUT because for some
629 1.6.4.2 yamt * reason true color mode gives messed up colours
630 1.6.4.2 yamt */
631 1.6.4.2 yamt agten_write_idx(sc, IBM561_FB_WINTYPE);
632 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x134);
633 1.6.4.2 yamt
634 1.6.4.2 yamt /* use gamma LUTs, no crosshair, 0 is transparent */
635 1.6.4.2 yamt agten_write_idx(sc, IBM561_AUXFB_WINTYPE);
636 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_FB_WAT, 0x0);
637 1.6.4.2 yamt
638 1.6.4.2 yamt /* overlay is 8 bit, opaque */
639 1.6.4.2 yamt agten_write_idx(sc, IBM561_OL_WINTYPE);
640 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x00);
641 1.6.4.2 yamt
642 1.6.4.2 yamt /* now we fill the WID fb with zeroes */
643 1.6.4.2 yamt src = 0;
644 1.6.4.2 yamt srcw = sc->sc_width << 16 | sc->sc_height;
645 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, FOREGROUND_COLOR,
646 1.6.4.2 yamt 0x0);
647 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, BACKGROUND_COLOR,
648 1.6.4.2 yamt 0x0);
649 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RASTER_OP, ROP_PAT);
650 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, COORD_INDEX, 0);
651 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, src);
652 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, srcw);
653 1.6.4.2 yamt junk = bus_space_read_4(sc->sc_bustag, sc->sc_p9100_regh, COMMAND_QUAD);
654 1.6.4.2 yamt
655 1.6.4.2 yamt /* initialize the cursor registers */
656 1.6.4.2 yamt
657 1.6.4.2 yamt /* initialize the Imagine 128 */
658 1.6.4.2 yamt i128_init(sc->sc_bustag, sc->sc_i128_regh, sc->sc_stride, 8);
659 1.6.4.2 yamt }
660 1.6.4.2 yamt
661 1.6.4.2 yamt static void
662 1.6.4.2 yamt agten_gfx(struct agten_softc *sc)
663 1.6.4.2 yamt {
664 1.6.4.2 yamt /* enable overlay transparency on colour 0x00 */
665 1.6.4.2 yamt agten_write_idx(sc, IBM561_OL_WINTYPE);
666 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x01);
667 1.6.4.2 yamt
668 1.6.4.2 yamt /* then blit the overlay full of 0x00 */
669 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0, sc->sc_width,
670 1.6.4.2 yamt sc->sc_height, 0);
671 1.6.4.2 yamt
672 1.6.4.2 yamt /* ... so we can see the 24bit framebuffer */
673 1.6.4.2 yamt }
674 1.6.4.2 yamt
675 1.6.4.2 yamt static void
676 1.6.4.2 yamt agten_set_video(struct agten_softc *sc, int flag)
677 1.6.4.2 yamt {
678 1.6.4.2 yamt uint8_t reg =
679 1.6.4.2 yamt CR2_ENABLE_CLC | CR2_PLL_REF_SELECT | CR2_PIXEL_CLOCK_SELECT;
680 1.6.4.2 yamt
681 1.6.4.2 yamt if (flag == sc->sc_video)
682 1.6.4.2 yamt return;
683 1.6.4.2 yamt
684 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG2);
685 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, flag ? reg | CR2_ENABLE_RGB_OUTPUT :
686 1.6.4.2 yamt reg);
687 1.6.4.2 yamt
688 1.6.4.2 yamt sc->sc_video = flag;
689 1.6.4.2 yamt }
690 1.6.4.2 yamt
691 1.6.4.2 yamt static int
692 1.6.4.2 yamt agten_get_video(struct agten_softc *sc)
693 1.6.4.2 yamt {
694 1.6.4.2 yamt
695 1.6.4.2 yamt return sc->sc_video;
696 1.6.4.2 yamt }
697 1.6.4.2 yamt
698 1.6.4.2 yamt static void
699 1.6.4.2 yamt agten_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
700 1.6.4.2 yamt {
701 1.6.4.2 yamt struct rasops_info *ri = cookie;
702 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
703 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
704 1.6.4.2 yamt int32_t xs, xd, y, width, height;
705 1.6.4.2 yamt
706 1.6.4.2 yamt xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
707 1.6.4.2 yamt xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
708 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
709 1.6.4.2 yamt width = ri->ri_font->fontwidth * ncols;
710 1.6.4.2 yamt height = ri->ri_font->fontheight;
711 1.6.4.2 yamt i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, xs, y, xd, y, width,
712 1.6.4.2 yamt height, CR_COPY);
713 1.6.4.2 yamt }
714 1.6.4.2 yamt
715 1.6.4.2 yamt static void
716 1.6.4.2 yamt agten_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
717 1.6.4.2 yamt {
718 1.6.4.2 yamt struct rasops_info *ri = cookie;
719 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
720 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
721 1.6.4.2 yamt int32_t x, y, width, height, bg;
722 1.6.4.2 yamt
723 1.6.4.2 yamt x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
724 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
725 1.6.4.2 yamt width = ri->ri_font->fontwidth * ncols;
726 1.6.4.2 yamt height = ri->ri_font->fontheight;
727 1.6.4.2 yamt bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
728 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
729 1.6.4.2 yamt }
730 1.6.4.2 yamt
731 1.6.4.2 yamt static void
732 1.6.4.2 yamt agten_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
733 1.6.4.2 yamt {
734 1.6.4.2 yamt struct rasops_info *ri = cookie;
735 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
736 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
737 1.6.4.2 yamt int32_t x, ys, yd, width, height;
738 1.6.4.2 yamt
739 1.6.4.2 yamt x = ri->ri_xorigin;
740 1.6.4.2 yamt ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
741 1.6.4.2 yamt yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
742 1.6.4.2 yamt width = ri->ri_emuwidth;
743 1.6.4.2 yamt height = ri->ri_font->fontheight * nrows;
744 1.6.4.2 yamt i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, x, ys, x, yd, width,
745 1.6.4.2 yamt height, CR_COPY);
746 1.6.4.2 yamt }
747 1.6.4.2 yamt
748 1.6.4.2 yamt static void
749 1.6.4.2 yamt agten_eraserows(void *cookie, int row, int nrows, long fillattr)
750 1.6.4.2 yamt {
751 1.6.4.2 yamt struct rasops_info *ri = cookie;
752 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
753 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
754 1.6.4.2 yamt int32_t x, y, width, height, bg;
755 1.6.4.2 yamt
756 1.6.4.2 yamt if ((row == 0) && (nrows == ri->ri_rows)) {
757 1.6.4.2 yamt x = y = 0;
758 1.6.4.2 yamt width = ri->ri_width;
759 1.6.4.2 yamt height = ri->ri_height;
760 1.6.4.2 yamt } else {
761 1.6.4.2 yamt x = ri->ri_xorigin;
762 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
763 1.6.4.2 yamt width = ri->ri_emuwidth;
764 1.6.4.2 yamt height = ri->ri_font->fontheight * nrows;
765 1.6.4.2 yamt }
766 1.6.4.2 yamt bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
767 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
768 1.6.4.2 yamt }
769 1.6.4.2 yamt
770 1.6.4.2 yamt static void
771 1.6.4.2 yamt agten_move_cursor(struct agten_softc *sc, int x, int y)
772 1.6.4.2 yamt {
773 1.6.4.2 yamt
774 1.6.4.2 yamt sc->sc_cursor_x = x;
775 1.6.4.2 yamt sc->sc_cursor_y = y;
776 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_X_REG);
777 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, x & 0xff);
778 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (x >> 8) & 0xff);
779 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, y & 0xff);
780 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (y >> 8) & 0xff);
781 1.6.4.2 yamt }
782 1.6.4.2 yamt
783 1.6.4.2 yamt static int
784 1.6.4.2 yamt agten_do_cursor(struct agten_softc *sc, struct wsdisplay_cursor *cur)
785 1.6.4.2 yamt {
786 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
787 1.6.4.2 yamt
788 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURS_CNTL_REG);
789 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->enable ?
790 1.6.4.2 yamt CURS_ENABLE : 0);
791 1.6.4.2 yamt }
792 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
793 1.6.4.2 yamt
794 1.6.4.2 yamt agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
795 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.x);
796 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.y);
797 1.6.4.2 yamt }
798 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
799 1.6.4.2 yamt
800 1.6.4.2 yamt agten_move_cursor(sc, cur->pos.x, cur->pos.y);
801 1.6.4.2 yamt }
802 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
803 1.6.4.2 yamt int i;
804 1.6.4.2 yamt
805 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
806 1.6.4.2 yamt for (i = 0; i < cur->cmap.count; i++) {
807 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
808 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
809 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
810 1.6.4.2 yamt }
811 1.6.4.2 yamt }
812 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
813 1.6.4.2 yamt int i;
814 1.6.4.2 yamt uint16_t tmp;
815 1.6.4.2 yamt
816 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_BITMAP);
817 1.6.4.2 yamt for (i = 0; i < 512; i++) {
818 1.6.4.2 yamt tmp = util_interleave(cur->mask[i], cur->image[i]);
819 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
820 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
821 1.6.4.2 yamt }
822 1.6.4.2 yamt }
823 1.6.4.2 yamt return 0;
824 1.6.4.2 yamt }
825 1.6.4.2 yamt
826 1.6.4.2 yamt static int
827 1.6.4.2 yamt agten_do_sun_cursor(struct agten_softc *sc, struct fbcursor *cur)
828 1.6.4.2 yamt {
829 1.6.4.2 yamt if (cur->set & FB_CUR_SETCUR) {
830 1.6.4.2 yamt
831 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURS_CNTL_REG);
832 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->enable ?
833 1.6.4.2 yamt CURS_ENABLE : 0);
834 1.6.4.2 yamt }
835 1.6.4.2 yamt if (cur->set & FB_CUR_SETHOT) {
836 1.6.4.2 yamt
837 1.6.4.2 yamt agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
838 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.x);
839 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.y);
840 1.6.4.2 yamt }
841 1.6.4.2 yamt if (cur->set & FB_CUR_SETPOS) {
842 1.6.4.2 yamt
843 1.6.4.2 yamt agten_move_cursor(sc, cur->pos.x, cur->pos.y);
844 1.6.4.2 yamt }
845 1.6.4.2 yamt if (cur->set & FB_CUR_SETCMAP) {
846 1.6.4.2 yamt int i;
847 1.6.4.2 yamt
848 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
849 1.6.4.2 yamt for (i = 0; i < cur->cmap.count; i++) {
850 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
851 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
852 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
853 1.6.4.2 yamt }
854 1.6.4.2 yamt }
855 1.6.4.2 yamt if (cur->set & FB_CUR_SETSHAPE) {
856 1.6.4.2 yamt int i;
857 1.6.4.2 yamt uint16_t tmp;
858 1.6.4.2 yamt
859 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_BITMAP);
860 1.6.4.2 yamt for (i = 0; i < 512; i++) {
861 1.6.4.2 yamt tmp = util_interleave_lin(cur->mask[i], cur->image[i]);
862 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
863 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
864 1.6.4.2 yamt }
865 1.6.4.2 yamt }
866 1.6.4.2 yamt return 0;
867 1.6.4.2 yamt }
868 1.6.4.2 yamt
869 1.6.4.2 yamt uint16_t
870 1.6.4.2 yamt util_interleave(uint8_t b1, uint8_t b2)
871 1.6.4.2 yamt {
872 1.6.4.2 yamt int i;
873 1.6.4.2 yamt uint16_t ret = 0;
874 1.6.4.2 yamt uint16_t mask = 0x8000;
875 1.6.4.2 yamt uint8_t mask8 = 0x01;
876 1.6.4.2 yamt
877 1.6.4.2 yamt for (i = 0; i < 8; i++) {
878 1.6.4.2 yamt if (b1 & mask8)
879 1.6.4.2 yamt ret |= mask;
880 1.6.4.2 yamt mask = mask >> 1;
881 1.6.4.2 yamt if (b2 & mask8)
882 1.6.4.2 yamt ret |= mask;
883 1.6.4.2 yamt mask = mask >> 1;
884 1.6.4.2 yamt mask8 = mask8 << 1;
885 1.6.4.2 yamt }
886 1.6.4.2 yamt return ret;
887 1.6.4.2 yamt }
888 1.6.4.2 yamt
889 1.6.4.2 yamt uint16_t
890 1.6.4.2 yamt util_interleave_lin(uint8_t b1, uint8_t b2)
891 1.6.4.2 yamt {
892 1.6.4.2 yamt int i;
893 1.6.4.2 yamt uint16_t ret = 0;
894 1.6.4.2 yamt uint16_t mask = 0x8000;
895 1.6.4.2 yamt uint8_t mask8 = 0x80;
896 1.6.4.2 yamt
897 1.6.4.2 yamt for (i = 0; i < 8; i++) {
898 1.6.4.2 yamt if (b1 & mask8)
899 1.6.4.2 yamt ret |= mask;
900 1.6.4.2 yamt mask = mask >> 1;
901 1.6.4.2 yamt if (b2 & mask8)
902 1.6.4.2 yamt ret |= mask;
903 1.6.4.2 yamt mask = mask >> 1;
904 1.6.4.2 yamt mask8 = mask8 >> 1;
905 1.6.4.2 yamt }
906 1.6.4.2 yamt return ret;
907 1.6.4.2 yamt }
908 1.6.4.2 yamt
909 1.6.4.2 yamt /* and now the /dev/fb* stuff */
910 1.6.4.2 yamt static void
911 1.6.4.2 yamt agten_fb_unblank(struct device *dev)
912 1.6.4.2 yamt {
913 1.6.4.2 yamt struct agten_softc *sc = (void *)dev;
914 1.6.4.2 yamt
915 1.6.4.2 yamt agten_init(sc);
916 1.6.4.2 yamt agten_set_video(sc, 1);
917 1.6.4.2 yamt }
918 1.6.4.2 yamt
919 1.6.4.2 yamt static int
920 1.6.4.2 yamt agten_fb_open(dev_t dev, int flags, int mode, struct lwp *l)
921 1.6.4.2 yamt {
922 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
923 1.6.4.2 yamt int unit = minor(dev);
924 1.6.4.2 yamt
925 1.6.4.2 yamt if (unit >= agten_cd.cd_ndevs || agten_cd.cd_devs[unit] == NULL)
926 1.6.4.2 yamt return (ENXIO);
927 1.6.4.2 yamt if (sc->sc_fb_is_open)
928 1.6.4.2 yamt return 0;
929 1.6.4.2 yamt
930 1.6.4.2 yamt sc->sc_fb_is_open++;
931 1.6.4.2 yamt agten_gfx(sc);
932 1.6.4.2 yamt
933 1.6.4.2 yamt return (0);
934 1.6.4.2 yamt }
935 1.6.4.2 yamt
936 1.6.4.2 yamt static int
937 1.6.4.2 yamt agten_fb_close(dev_t dev, int flags, int mode, struct lwp *l)
938 1.6.4.2 yamt {
939 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
940 1.6.4.2 yamt
941 1.6.4.2 yamt sc->sc_fb_is_open--;
942 1.6.4.2 yamt if (sc->sc_fb_is_open < 0)
943 1.6.4.2 yamt sc->sc_fb_is_open = 0;
944 1.6.4.2 yamt
945 1.6.4.2 yamt if (sc->sc_fb_is_open == 0) {
946 1.6.4.2 yamt agten_init(sc);
947 1.6.4.2 yamt vcons_redraw_screen(sc->vd.active);
948 1.6.4.2 yamt }
949 1.6.4.2 yamt
950 1.6.4.2 yamt return (0);
951 1.6.4.2 yamt }
952 1.6.4.2 yamt
953 1.6.4.2 yamt static int
954 1.6.4.2 yamt agten_fb_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
955 1.6.4.2 yamt {
956 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
957 1.6.4.2 yamt struct fbgattr *fba;
958 1.6.4.2 yamt int error;
959 1.6.4.2 yamt
960 1.6.4.2 yamt switch (cmd) {
961 1.6.4.2 yamt
962 1.6.4.2 yamt case FBIOGTYPE:
963 1.6.4.2 yamt *(struct fbtype *)data = sc->sc_fb.fb_type;
964 1.6.4.2 yamt break;
965 1.6.4.2 yamt
966 1.6.4.2 yamt case FBIOGATTR:
967 1.6.4.2 yamt fba = (struct fbgattr *)data;
968 1.6.4.2 yamt fba->real_type = sc->sc_fb.fb_type.fb_type;
969 1.6.4.2 yamt fba->owner = 0; /* XXX ??? */
970 1.6.4.2 yamt fba->fbtype = sc->sc_fb.fb_type;
971 1.6.4.2 yamt fba->sattr.flags = 0;
972 1.6.4.2 yamt fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
973 1.6.4.2 yamt fba->sattr.dev_specific[0] = -1;
974 1.6.4.2 yamt fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
975 1.6.4.2 yamt fba->emu_types[1] = -1;
976 1.6.4.2 yamt break;
977 1.6.4.2 yamt
978 1.6.4.2 yamt case FBIOGETCMAP:
979 1.6.4.2 yamt #define p ((struct fbcmap *)data)
980 1.6.4.2 yamt return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
981 1.6.4.2 yamt
982 1.6.4.2 yamt case FBIOPUTCMAP:
983 1.6.4.2 yamt /* copy to software map */
984 1.6.4.2 yamt error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
985 1.6.4.2 yamt if (error)
986 1.6.4.2 yamt return (error);
987 1.6.4.2 yamt /* now blast them into the chip */
988 1.6.4.2 yamt /* don't bother - we're 24bit */
989 1.6.4.2 yamt #undef p
990 1.6.4.2 yamt break;
991 1.6.4.2 yamt
992 1.6.4.2 yamt case FBIOGVIDEO:
993 1.6.4.2 yamt *(int *)data = agten_get_video(sc);
994 1.6.4.2 yamt break;
995 1.6.4.2 yamt
996 1.6.4.2 yamt case FBIOSVIDEO:
997 1.6.4.2 yamt agten_set_video(sc, *(int *)data);
998 1.6.4.2 yamt break;
999 1.6.4.2 yamt
1000 1.6.4.2 yamt /* these are for both FBIOSCURSOR and FBIOGCURSOR */
1001 1.6.4.2 yamt #define p ((struct fbcursor *)data)
1002 1.6.4.2 yamt #define pc (&sc->sc_cursor)
1003 1.6.4.2 yamt
1004 1.6.4.2 yamt case FBIOGCURSOR:
1005 1.6.4.2 yamt /* does anyone use this ioctl?! */
1006 1.6.4.2 yamt p->set = FB_CUR_SETALL; /* close enough, anyway */
1007 1.6.4.2 yamt p->enable = 1;
1008 1.6.4.2 yamt p->pos.x = sc->sc_cursor_x;
1009 1.6.4.2 yamt p->pos.y = sc->sc_cursor_y;
1010 1.6.4.2 yamt p->size.x = 64;
1011 1.6.4.2 yamt p->size.y = 64;
1012 1.6.4.2 yamt break;
1013 1.6.4.2 yamt
1014 1.6.4.2 yamt case FBIOSCURSOR:
1015 1.6.4.2 yamt agten_do_sun_cursor(sc, p);
1016 1.6.4.2 yamt break;
1017 1.6.4.2 yamt
1018 1.6.4.2 yamt #undef p
1019 1.6.4.2 yamt #undef cc
1020 1.6.4.2 yamt
1021 1.6.4.2 yamt case FBIOGCURPOS:
1022 1.6.4.2 yamt {
1023 1.6.4.2 yamt struct fbcurpos *cp = (struct fbcurpos *)data;
1024 1.6.4.2 yamt cp->x = sc->sc_cursor_x;
1025 1.6.4.2 yamt cp->y = sc->sc_cursor_y;
1026 1.6.4.2 yamt }
1027 1.6.4.2 yamt break;
1028 1.6.4.2 yamt
1029 1.6.4.2 yamt case FBIOSCURPOS:
1030 1.6.4.2 yamt {
1031 1.6.4.2 yamt struct fbcurpos *cp = (struct fbcurpos *)data;
1032 1.6.4.2 yamt agten_move_cursor(sc, cp->x, cp->y);
1033 1.6.4.2 yamt }
1034 1.6.4.2 yamt break;
1035 1.6.4.2 yamt
1036 1.6.4.2 yamt case FBIOGCURMAX:
1037 1.6.4.2 yamt /* max cursor size is 64x64 */
1038 1.6.4.2 yamt ((struct fbcurpos *)data)->x = 64;
1039 1.6.4.2 yamt ((struct fbcurpos *)data)->y = 64;
1040 1.6.4.2 yamt break;
1041 1.6.4.2 yamt
1042 1.6.4.2 yamt default:
1043 1.6.4.2 yamt return (ENOTTY);
1044 1.6.4.2 yamt }
1045 1.6.4.2 yamt return (0);
1046 1.6.4.2 yamt }
1047 1.6.4.2 yamt
1048 1.6.4.2 yamt static paddr_t
1049 1.6.4.2 yamt agten_fb_mmap(dev_t dev, off_t off, int prot)
1050 1.6.4.2 yamt {
1051 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
1052 1.6.4.2 yamt
1053 1.6.4.2 yamt /*
1054 1.6.4.2 yamt * mappings are subject to change
1055 1.6.4.2 yamt * for now we put the framebuffer at offset 0 and the GLint registers
1056 1.6.4.2 yamt * right after that. We may want to expose more register ranges and
1057 1.6.4.2 yamt * probably will want to map the 2nd framebuffer as well
1058 1.6.4.2 yamt */
1059 1.6.4.2 yamt
1060 1.6.4.2 yamt if (off < 0)
1061 1.6.4.2 yamt return EINVAL;
1062 1.6.4.2 yamt
1063 1.6.4.2 yamt if (off >= sc->sc_glint_fbsz + 0x10000)
1064 1.6.4.2 yamt return EINVAL;
1065 1.6.4.2 yamt
1066 1.6.4.2 yamt if (off < sc->sc_glint_fbsz) {
1067 1.6.4.2 yamt return (bus_space_mmap(sc->sc_bustag,
1068 1.6.4.2 yamt sc->sc_glint_fb,
1069 1.6.4.2 yamt off,
1070 1.6.4.2 yamt prot,
1071 1.6.4.2 yamt BUS_SPACE_MAP_LINEAR));
1072 1.6.4.2 yamt }
1073 1.6.4.2 yamt
1074 1.6.4.2 yamt off -= sc->sc_glint_fbsz;
1075 1.6.4.2 yamt if (off < 0x10000) {
1076 1.6.4.2 yamt return (bus_space_mmap(sc->sc_bustag,
1077 1.6.4.2 yamt sc->sc_glint_regs,
1078 1.6.4.2 yamt off,
1079 1.6.4.2 yamt prot,
1080 1.6.4.2 yamt BUS_SPACE_MAP_LINEAR));
1081 1.6.4.2 yamt }
1082 1.6.4.2 yamt return EINVAL;
1083 1.6.4.2 yamt }
1084