vidcvideo.c revision 1.5 1 1.5 atatat /* $NetBSD: vidcvideo.c,v 1.5 2002/03/17 19:40:33 atatat Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 2001 Reinoud Zandijk
5 1.1 reinoud * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved.
6 1.1 reinoud *
7 1.1 reinoud * Redistribution and use in source and binary forms, with or without
8 1.1 reinoud * modification, are permitted provided that the following conditions
9 1.1 reinoud * are met:
10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
11 1.1 reinoud * notice, this list of conditions and the following disclaimer.
12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
14 1.1 reinoud * documentation and/or other materials provided with the distribution.
15 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
16 1.1 reinoud * must display the following acknowledgement:
17 1.1 reinoud * This product includes software developed by Tohru Nishimura
18 1.1 reinoud * and Reinoud Zandijk for the NetBSD Project.
19 1.1 reinoud * 4. The name of the author may not be used to endorse or promote products
20 1.1 reinoud * derived from this software without specific prior written permission
21 1.1 reinoud *
22 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 reinoud *
33 1.1 reinoud * Created vidcvideo.c from /dev/tc/cfb.c to fit the Acorn/ARM VIDC1 and VIDC20 chips
34 1.1 reinoud *
35 1.1 reinoud */
36 1.1 reinoud
37 1.1 reinoud #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
38 1.1 reinoud
39 1.5 atatat __KERNEL_RCSID(0, "$NetBSD: vidcvideo.c,v 1.5 2002/03/17 19:40:33 atatat Exp $");
40 1.1 reinoud
41 1.1 reinoud #include <sys/param.h>
42 1.1 reinoud #include <sys/systm.h>
43 1.1 reinoud #include <sys/kernel.h>
44 1.1 reinoud #include <sys/device.h>
45 1.1 reinoud #include <sys/malloc.h>
46 1.1 reinoud #include <sys/buf.h>
47 1.1 reinoud #include <sys/ioctl.h>
48 1.1 reinoud
49 1.1 reinoud #include <arm/mainbus/mainbus.h>
50 1.1 reinoud #include <machine/bus.h>
51 1.1 reinoud #include <machine/intr.h>
52 1.1 reinoud
53 1.1 reinoud #include <dev/wscons/wsconsio.h>
54 1.1 reinoud #include <dev/wscons/wsdisplayvar.h>
55 1.1 reinoud
56 1.1 reinoud #include <dev/rasops/rasops.h>
57 1.1 reinoud #include <dev/wsfont/wsfont.h>
58 1.1 reinoud
59 1.1 reinoud #include <uvm/uvm_extern.h>
60 1.1 reinoud #include <arm/arm32/pmap.h>
61 1.2 thorpej #include <machine/intr.h>
62 1.1 reinoud
63 1.1 reinoud /* for vidc_mode ... needs to be MI indepenent one day */
64 1.1 reinoud #include <arm/iomd/vidc.h>
65 1.1 reinoud #include <arm/iomd/vidc20config.h>
66 1.1 reinoud #include <machine/bootconfig.h>
67 1.1 reinoud extern videomemory_t videomemory;
68 1.1 reinoud
69 1.1 reinoud #define machine_btop(x) arm_byte_to_page(x)
70 1.1 reinoud #define MACHINE_KSEG0_TO_PHYS(x) vtophys(x)
71 1.1 reinoud
72 1.1 reinoud /* FOR DEBUG */
73 1.1 reinoud extern videomemory_t videomemory;
74 1.1 reinoud
75 1.1 reinoud struct fb_devconfig {
76 1.1 reinoud vaddr_t dc_vaddr; /* memory space virtual base address */
77 1.1 reinoud paddr_t dc_paddr; /* memory space physical base address */
78 1.1 reinoud vsize_t dc_size; /* size of slot memory */
79 1.1 reinoud int dc_wid; /* width of frame buffer */
80 1.1 reinoud int dc_ht; /* height of frame buffer */
81 1.1 reinoud int dc_log2_depth; /* log2 of bits per pixel */
82 1.1 reinoud int dc_depth; /* depth, bits per pixel */
83 1.1 reinoud int dc_rowbytes; /* bytes in a FB scan line */
84 1.1 reinoud vaddr_t dc_videobase; /* base of flat frame buffer */
85 1.1 reinoud int dc_blanked; /* currently has video disabled */
86 1.1 reinoud void *dc_hwscroll_cookie; /* cookie for hardware scroll */
87 1.1 reinoud
88 1.1 reinoud struct vidc_mode mode_info;
89 1.1 reinoud struct rasops_info rinfo;
90 1.1 reinoud };
91 1.1 reinoud
92 1.1 reinoud
93 1.1 reinoud struct hwcmap256 {
94 1.1 reinoud #define CMAP_SIZE 256 /* 256 R/G/B entries */
95 1.1 reinoud u_int8_t r[CMAP_SIZE];
96 1.1 reinoud u_int8_t g[CMAP_SIZE];
97 1.1 reinoud u_int8_t b[CMAP_SIZE];
98 1.1 reinoud };
99 1.1 reinoud
100 1.1 reinoud
101 1.1 reinoud /* XXX for CURSOR_MAX_WIDTH = 32 */
102 1.1 reinoud struct hwcursor32 {
103 1.1 reinoud struct wsdisplay_curpos cc_pos;
104 1.1 reinoud struct wsdisplay_curpos cc_hot;
105 1.1 reinoud struct wsdisplay_curpos cc_size;
106 1.1 reinoud struct wsdisplay_curpos cc_magic;
107 1.1 reinoud u_int8_t cc_color[6]; /* how many? */
108 1.1 reinoud u_int32_t cc_image[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
109 1.1 reinoud u_int32_t cc_mask[(CURSOR_MAX_WIDTH/4) * CURSOR_MAX_HEIGHT];
110 1.1 reinoud };
111 1.1 reinoud
112 1.1 reinoud
113 1.1 reinoud struct vidcvideo_softc {
114 1.1 reinoud struct device sc_dev;
115 1.1 reinoud struct fb_devconfig *sc_dc; /* device configuration */
116 1.1 reinoud struct hwcmap256 sc_cmap; /* software copy of colormap */
117 1.1 reinoud struct hwcursor32 sc_cursor; /* software copy of cursor */
118 1.1 reinoud int sc_curenb; /* cursor sprite enabled */
119 1.1 reinoud int sc_changed; /* need update of hardware */
120 1.1 reinoud #define WSDISPLAY_CMAP_DOLUT 0x20
121 1.1 reinoud #define WSDISPLAY_VIDEO_ONOFF 0x40
122 1.1 reinoud int nscreens;
123 1.1 reinoud };
124 1.1 reinoud
125 1.1 reinoud
126 1.1 reinoud /* XXX has to go XXX */
127 1.1 reinoud #define CX_MAGIC_X 220
128 1.1 reinoud #define CX_MAGIC_Y 35
129 1.1 reinoud #define CX_FB_OFFSET 0x000000
130 1.1 reinoud #define CX_FB_SIZE 0x100000
131 1.1 reinoud #define CX_BT459_OFFSET 0x200000
132 1.1 reinoud #define CX_OFFSET_IREQ 0x300000 /* Interrupt req. control */
133 1.1 reinoud /* XXX till here XXX */
134 1.1 reinoud
135 1.1 reinoud
136 1.1 reinoud /* Function prototypes for glue */
137 1.1 reinoud static int vidcvideo_match __P((struct device *, struct cfdata *, void *));
138 1.1 reinoud static void vidcvideo_attach __P((struct device *, struct device *, void *));
139 1.1 reinoud
140 1.1 reinoud
141 1.1 reinoud /* config glue */
142 1.1 reinoud const struct cfattach vidcvideo_ca = {
143 1.1 reinoud sizeof(struct vidcvideo_softc), vidcvideo_match, vidcvideo_attach,
144 1.1 reinoud };
145 1.1 reinoud
146 1.1 reinoud
147 1.1 reinoud static struct fb_devconfig vidcvideo_console_dc;
148 1.1 reinoud static int vidcvideo_is_console;
149 1.1 reinoud
150 1.1 reinoud
151 1.1 reinoud static struct wsscreen_descr vidcvideo_stdscreen = {
152 1.1 reinoud "std", 0, 0,
153 1.1 reinoud 0, /* textops */
154 1.1 reinoud 0, 0,
155 1.1 reinoud WSSCREEN_REVERSE
156 1.1 reinoud };
157 1.1 reinoud
158 1.1 reinoud static const struct wsscreen_descr *_vidcvideo_scrlist[] = {
159 1.1 reinoud &vidcvideo_stdscreen,
160 1.1 reinoud };
161 1.1 reinoud
162 1.1 reinoud static const struct wsscreen_list vidcvideo_screenlist = {
163 1.1 reinoud sizeof(_vidcvideo_scrlist) / sizeof(struct wsscreen_descr *), _vidcvideo_scrlist
164 1.1 reinoud };
165 1.1 reinoud
166 1.1 reinoud static int vidcvideoioctl __P((void *, u_long, caddr_t, int, struct proc *));
167 1.1 reinoud static paddr_t vidcvideommap __P((void *, off_t, int));
168 1.1 reinoud
169 1.1 reinoud static int vidcvideo_alloc_screen __P((void *, const struct wsscreen_descr *,
170 1.1 reinoud void **, int *, int *, long *));
171 1.1 reinoud static void vidcvideo_free_screen __P((void *, void *));
172 1.1 reinoud static int vidcvideo_show_screen __P((void *, void *, int,
173 1.1 reinoud void (*) (void *, int, int), void *));
174 1.1 reinoud
175 1.1 reinoud static const struct wsdisplay_accessops vidcvideo_accessops = {
176 1.1 reinoud vidcvideoioctl,
177 1.1 reinoud vidcvideommap,
178 1.1 reinoud vidcvideo_alloc_screen,
179 1.1 reinoud vidcvideo_free_screen,
180 1.1 reinoud vidcvideo_show_screen,
181 1.1 reinoud 0 /* load_font */
182 1.1 reinoud };
183 1.1 reinoud
184 1.1 reinoud /* Function prototypes */
185 1.1 reinoud int vidcvideo_cnattach __P((vaddr_t));
186 1.1 reinoud static void vidcvideo_colourmap_and_cursor_init __P((struct fb_devconfig *));
187 1.1 reinoud
188 1.1 reinoud static int get_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
189 1.1 reinoud static int set_cmap __P((struct vidcvideo_softc *, struct wsdisplay_cmap *));
190 1.1 reinoud static int set_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
191 1.1 reinoud static int get_cursor __P((struct vidcvideo_softc *, struct wsdisplay_cursor *));
192 1.1 reinoud static void set_curpos __P((struct vidcvideo_softc *, struct wsdisplay_curpos *));
193 1.1 reinoud static void vidcvideo_getdevconfig __P((vaddr_t, struct fb_devconfig *));
194 1.1 reinoud
195 1.1 reinoud static int vidcvideointr __P((void *));
196 1.3 bjh21 static void vidcvideo_config_wscons __P((struct fb_devconfig *));
197 1.1 reinoud
198 1.1 reinoud /* Acceleration function prototypes */
199 1.1 reinoud static void vv_copyrows __P((void *, int, int, int));
200 1.1 reinoud static void vv_eraserows __P((void *, int, int, long));
201 1.1 reinoud
202 1.1 reinoud
203 1.1 reinoud static int
204 1.1 reinoud vidcvideo_match(parent, match, aux)
205 1.1 reinoud struct device *parent;
206 1.1 reinoud struct cfdata *match;
207 1.1 reinoud void *aux;
208 1.1 reinoud {
209 1.1 reinoud /* Can't probe AFAIK ; how ? */
210 1.1 reinoud return (1);
211 1.1 reinoud }
212 1.1 reinoud
213 1.1 reinoud
214 1.1 reinoud static void
215 1.1 reinoud vidcvideo_getdevconfig(dense_addr, dc)
216 1.1 reinoud vaddr_t dense_addr;
217 1.1 reinoud struct fb_devconfig *dc;
218 1.1 reinoud {
219 1.1 reinoud dc->dc_vaddr = dense_addr;
220 1.1 reinoud dc->dc_paddr = MACHINE_KSEG0_TO_PHYS(dc->dc_vaddr);
221 1.1 reinoud
222 1.1 reinoud vidcvideo_getmode(&dc->mode_info);
223 1.1 reinoud
224 1.1 reinoud dc->dc_wid = dc->mode_info.hder;
225 1.1 reinoud dc->dc_ht = dc->mode_info.vder;
226 1.1 reinoud dc->dc_log2_depth = dc->mode_info.log2_bpp;
227 1.1 reinoud dc->dc_depth = 1 << dc->dc_log2_depth;
228 1.1 reinoud dc->dc_videobase = dc->dc_vaddr;
229 1.1 reinoud dc->dc_blanked = 0;
230 1.1 reinoud
231 1.1 reinoud /* this should/could be done somewhat more elegant! */
232 1.1 reinoud switch (dc->dc_depth) {
233 1.1 reinoud case 1:
234 1.1 reinoud dc->dc_rowbytes = dc->dc_wid / 8;
235 1.1 reinoud break;
236 1.1 reinoud case 2:
237 1.1 reinoud dc->dc_rowbytes = dc->dc_wid / 4;
238 1.1 reinoud break;
239 1.1 reinoud case 4:
240 1.1 reinoud dc->dc_rowbytes = dc->dc_wid / 2;
241 1.1 reinoud break;
242 1.1 reinoud case 8:
243 1.1 reinoud dc->dc_rowbytes = dc->dc_wid;
244 1.1 reinoud break;
245 1.1 reinoud case 16:
246 1.1 reinoud dc->dc_rowbytes = dc->dc_wid * 2;
247 1.1 reinoud break;
248 1.1 reinoud case 32:
249 1.1 reinoud dc->dc_rowbytes = dc->dc_wid * 4;
250 1.1 reinoud break;
251 1.1 reinoud default:
252 1.1 reinoud printf("Unknown colour depth %d ... what to do ?", dc->dc_depth);
253 1.1 reinoud break;
254 1.1 reinoud };
255 1.1 reinoud
256 1.1 reinoud /* euhm... correct ? i.e. not complete VIDC memory */
257 1.1 reinoud dc->dc_size = dc->mode_info.vder * dc->dc_rowbytes;
258 1.1 reinoud
259 1.1 reinoud /* initialize colormap and cursor resource */
260 1.1 reinoud vidcvideo_colourmap_and_cursor_init(dc);
261 1.1 reinoud
262 1.1 reinoud dc->rinfo.ri_flg = 0; /* RI_CENTER; */
263 1.1 reinoud dc->rinfo.ri_depth = dc->dc_depth;
264 1.1 reinoud dc->rinfo.ri_bits = (void *) dc->dc_videobase;
265 1.1 reinoud dc->rinfo.ri_width = dc->dc_wid;
266 1.1 reinoud dc->rinfo.ri_height = dc->dc_ht;
267 1.1 reinoud dc->rinfo.ri_stride = dc->dc_rowbytes;
268 1.1 reinoud dc->rinfo.ri_hw = NULL;
269 1.1 reinoud }
270 1.1 reinoud
271 1.1 reinoud
272 1.1 reinoud static void
273 1.1 reinoud vidcvideo_config_wscons(dc)
274 1.1 reinoud struct fb_devconfig *dc;
275 1.1 reinoud {
276 1.4 ad int i, cookie, font_not_locked;
277 1.1 reinoud
278 1.1 reinoud /* clear the screen ; why not a memset ? - it was this way so keep it for now */
279 1.1 reinoud for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
280 1.1 reinoud *(u_int32_t *)(dc->dc_videobase + i) = 0x0;
281 1.1 reinoud
282 1.1 reinoud wsfont_init();
283 1.1 reinoud
284 1.1 reinoud /* prefer 8 pixel wide font */
285 1.4 ad cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
286 1.4 ad WSDISPLAY_FONTORDER_L2R);
287 1.4 ad if (cookie <= 0)
288 1.4 ad cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_L2R,
289 1.4 ad WSDISPLAY_FONTORDER_L2R);
290 1.1 reinoud
291 1.1 reinoud if (cookie < 0) {
292 1.1 reinoud /* Can I even print here ? */
293 1.1 reinoud printf("Font table empty! exiting\n");
294 1.1 reinoud return;
295 1.1 reinoud };
296 1.1 reinoud
297 1.4 ad font_not_locked = wsfont_lock(cookie, &dc->rinfo.ri_font);
298 1.1 reinoud
299 1.1 reinoud dc->rinfo.ri_wsfcookie = cookie;
300 1.1 reinoud
301 1.1 reinoud rasops_init(&dc->rinfo,
302 1.1 reinoud dc->rinfo.ri_height / dc->rinfo.ri_font->fontheight,
303 1.1 reinoud dc->rinfo.ri_width / dc->rinfo.ri_font->fontwidth
304 1.1 reinoud );
305 1.1 reinoud
306 1.1 reinoud /* XXX add our accelerated functions */
307 1.1 reinoud dc->rinfo.ri_ops.eraserows = vv_eraserows;
308 1.1 reinoud dc->rinfo.ri_ops.copyrows = vv_copyrows;
309 1.1 reinoud
310 1.1 reinoud /* XXX shouldn't be global */
311 1.1 reinoud vidcvideo_stdscreen.nrows = dc->rinfo.ri_rows;
312 1.1 reinoud vidcvideo_stdscreen.ncols = dc->rinfo.ri_cols;
313 1.1 reinoud vidcvideo_stdscreen.textops = &dc->rinfo.ri_ops;
314 1.1 reinoud vidcvideo_stdscreen.capabilities = dc->rinfo.ri_caps;
315 1.1 reinoud
316 1.4 ad if (font_not_locked) {
317 1.1 reinoud printf(" warning ... couldn't lock font! ");
318 1.1 reinoud };
319 1.1 reinoud }
320 1.1 reinoud
321 1.1 reinoud
322 1.1 reinoud static void
323 1.1 reinoud vidcvideo_attach(parent, self, aux)
324 1.1 reinoud struct device *parent, *self;
325 1.1 reinoud void *aux;
326 1.1 reinoud {
327 1.1 reinoud struct vidcvideo_softc *sc = (struct vidcvideo_softc *)self;
328 1.1 reinoud struct wsemuldisplaydev_attach_args waa;
329 1.1 reinoud struct hwcmap256 *cm;
330 1.1 reinoud const u_int8_t *p;
331 1.1 reinoud int index;
332 1.1 reinoud
333 1.1 reinoud vidcvideo_init();
334 1.1 reinoud if (sc->nscreens == 0) {
335 1.1 reinoud if (vidcvideo_is_console) {
336 1.1 reinoud sc->sc_dc = &vidcvideo_console_dc;
337 1.1 reinoud } else {
338 1.1 reinoud printf(" : non console vidcvideo fb ... can't cope with this\n");
339 1.1 reinoud return;
340 1.1 reinoud /*
341 1.1 reinoud * sc->sc_dc = (struct fb_devconfig *)
342 1.1 reinoud * malloc(sizeof(struct fb_devconfig), M_DEVBUF, M_WAITOK);
343 1.1 reinoud * vidcvideo_getdevconfig(videomemory.vidm_vbase, sc->sc_dc);
344 1.1 reinoud */
345 1.1 reinoud };
346 1.1 reinoud sc->nscreens = 1;
347 1.1 reinoud } else {
348 1.1 reinoud printf(": allready attached ... can't cope with this\n");
349 1.1 reinoud return;
350 1.1 reinoud };
351 1.1 reinoud
352 1.1 reinoud vidcvideo_printdetails();
353 1.1 reinoud printf(": using %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
354 1.1 reinoud sc->sc_dc->dc_depth);
355 1.1 reinoud
356 1.1 reinoud /* initialise rasops */
357 1.1 reinoud cm = &sc->sc_cmap;
358 1.1 reinoud p = rasops_cmap;
359 1.1 reinoud for (index = 0; index < CMAP_SIZE; index++, p += 3) {
360 1.1 reinoud cm->r[index] = p[0];
361 1.1 reinoud cm->g[index] = p[1];
362 1.1 reinoud cm->b[index] = p[2];
363 1.1 reinoud }
364 1.1 reinoud
365 1.1 reinoud /* what does these do ? */
366 1.1 reinoud sc->sc_cursor.cc_magic.x = CX_MAGIC_X;
367 1.1 reinoud sc->sc_cursor.cc_magic.y = CX_MAGIC_Y;
368 1.1 reinoud
369 1.1 reinoud /* set up interrupt flags */
370 1.1 reinoud sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
371 1.1 reinoud
372 1.1 reinoud /* set up a link in the rasops structure to our softc for acceleration stuff */
373 1.1 reinoud sc->sc_dc->rinfo.ri_hw = sc;
374 1.1 reinoud
375 1.1 reinoud /* Establish an interrupt handler, and clear any pending interrupts */
376 1.1 reinoud intr_claim(IRQ_FLYBACK, IPL_TTY, "vblank", vidcvideointr, sc);
377 1.1 reinoud
378 1.1 reinoud waa.console = (vidcvideo_is_console ? 1 : 0);
379 1.1 reinoud waa.scrdata = &vidcvideo_screenlist;
380 1.1 reinoud waa.accessops = &vidcvideo_accessops;
381 1.1 reinoud waa.accesscookie = sc;
382 1.1 reinoud
383 1.1 reinoud config_found(self, &waa, wsemuldisplaydevprint);
384 1.1 reinoud }
385 1.1 reinoud
386 1.1 reinoud
387 1.1 reinoud static int
388 1.1 reinoud vidcvideoioctl(v, cmd, data, flag, p)
389 1.1 reinoud void *v;
390 1.1 reinoud u_long cmd;
391 1.1 reinoud caddr_t data;
392 1.1 reinoud int flag;
393 1.1 reinoud struct proc *p;
394 1.1 reinoud {
395 1.1 reinoud struct vidcvideo_softc *sc = v;
396 1.1 reinoud struct fb_devconfig *dc = sc->sc_dc;
397 1.1 reinoud int state;
398 1.1 reinoud
399 1.1 reinoud switch (cmd) {
400 1.1 reinoud case WSDISPLAYIO_GTYPE:
401 1.1 reinoud *(u_int *)data = WSDISPLAY_TYPE_VIDC;
402 1.1 reinoud return (0);
403 1.1 reinoud
404 1.1 reinoud case WSDISPLAYIO_GINFO:
405 1.1 reinoud #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
406 1.1 reinoud wsd_fbip->height = sc->sc_dc->dc_ht;
407 1.1 reinoud wsd_fbip->width = sc->sc_dc->dc_wid;
408 1.1 reinoud wsd_fbip->depth = sc->sc_dc->dc_depth;
409 1.1 reinoud wsd_fbip->cmsize = CMAP_SIZE;
410 1.1 reinoud #undef fbt
411 1.1 reinoud return (0);
412 1.1 reinoud
413 1.1 reinoud case WSDISPLAYIO_GETCMAP:
414 1.1 reinoud return get_cmap(sc, (struct wsdisplay_cmap *)data);
415 1.1 reinoud
416 1.1 reinoud case WSDISPLAYIO_PUTCMAP:
417 1.1 reinoud return set_cmap(sc, (struct wsdisplay_cmap *)data);
418 1.1 reinoud
419 1.1 reinoud case WSDISPLAYIO_SVIDEO:
420 1.1 reinoud state = *(int *)data;
421 1.1 reinoud dc->dc_blanked = (state == WSDISPLAYIO_VIDEO_OFF);
422 1.1 reinoud sc->sc_changed |= WSDISPLAY_VIDEO_ONOFF;
423 1.1 reinoud /* done on video blank */
424 1.1 reinoud return (0);
425 1.1 reinoud
426 1.1 reinoud case WSDISPLAYIO_GVIDEO:
427 1.1 reinoud *(u_int *)data = dc->dc_blanked ?
428 1.1 reinoud WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
429 1.1 reinoud return (0);
430 1.1 reinoud
431 1.1 reinoud case WSDISPLAYIO_GCURPOS:
432 1.1 reinoud *(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
433 1.1 reinoud return (0);
434 1.1 reinoud
435 1.1 reinoud case WSDISPLAYIO_SCURPOS:
436 1.1 reinoud set_curpos(sc, (struct wsdisplay_curpos *)data);
437 1.1 reinoud sc->sc_changed |= WSDISPLAY_CURSOR_DOPOS;
438 1.1 reinoud return (0);
439 1.1 reinoud
440 1.1 reinoud case WSDISPLAYIO_GCURMAX:
441 1.1 reinoud ((struct wsdisplay_curpos *)data)->x = CURSOR_MAX_WIDTH;
442 1.1 reinoud ((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_HEIGHT;
443 1.1 reinoud return (0);
444 1.1 reinoud
445 1.1 reinoud case WSDISPLAYIO_GCURSOR:
446 1.1 reinoud return get_cursor(sc, (struct wsdisplay_cursor *)data);
447 1.1 reinoud
448 1.1 reinoud case WSDISPLAYIO_SCURSOR:
449 1.1 reinoud return set_cursor(sc, (struct wsdisplay_cursor *)data);
450 1.1 reinoud
451 1.1 reinoud case WSDISPLAYIO_SMODE:
452 1.1 reinoud state = *(int *)data;
453 1.1 reinoud if (state == WSDISPLAYIO_MODE_MAPPED) {
454 1.1 reinoud dc->dc_hwscroll_cookie = vidcvideo_hwscroll_reset();
455 1.1 reinoud };
456 1.1 reinoud if (state == WSDISPLAYIO_MODE_EMUL) {
457 1.1 reinoud vidcvideo_hwscroll_back(dc->dc_hwscroll_cookie);
458 1.1 reinoud };
459 1.1 reinoud vidcvideo_progr_scroll();
460 1.1 reinoud return (0);
461 1.1 reinoud }
462 1.5 atatat return EPASSTHROUGH;
463 1.1 reinoud }
464 1.1 reinoud
465 1.1 reinoud
466 1.1 reinoud paddr_t
467 1.1 reinoud vidcvideommap(v, offset, prot)
468 1.1 reinoud void *v;
469 1.1 reinoud off_t offset;
470 1.1 reinoud int prot;
471 1.1 reinoud {
472 1.1 reinoud struct vidcvideo_softc *sc = v;
473 1.1 reinoud
474 1.1 reinoud if (offset >= sc->sc_dc->dc_size || offset < 0)
475 1.1 reinoud return (-1);
476 1.1 reinoud return machine_btop(sc->sc_dc->dc_paddr + offset);
477 1.1 reinoud }
478 1.1 reinoud
479 1.1 reinoud
480 1.1 reinoud static int
481 1.1 reinoud vidcvideo_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
482 1.1 reinoud void *v;
483 1.1 reinoud const struct wsscreen_descr *type;
484 1.1 reinoud void **cookiep;
485 1.1 reinoud int *curxp, *curyp;
486 1.1 reinoud long *attrp;
487 1.1 reinoud {
488 1.1 reinoud struct vidcvideo_softc *sc = v;
489 1.1 reinoud long defattr;
490 1.1 reinoud
491 1.1 reinoud if (sc->nscreens > 0)
492 1.1 reinoud return (ENOMEM);
493 1.1 reinoud
494 1.1 reinoud *cookiep = &sc->sc_dc->rinfo; /* one and only for now */
495 1.1 reinoud *curxp = 0;
496 1.1 reinoud *curyp = 0;
497 1.1 reinoud (*sc->sc_dc->rinfo.ri_ops.alloc_attr)(&sc->sc_dc->rinfo, 0, 0, 0, &defattr);
498 1.1 reinoud *attrp = defattr;
499 1.1 reinoud sc->nscreens++;
500 1.1 reinoud return (0);
501 1.1 reinoud }
502 1.1 reinoud
503 1.1 reinoud
504 1.1 reinoud static void
505 1.1 reinoud vidcvideo_free_screen(v, cookie)
506 1.1 reinoud void *v;
507 1.1 reinoud void *cookie;
508 1.1 reinoud {
509 1.1 reinoud struct vidcvideo_softc *sc = v;
510 1.1 reinoud
511 1.1 reinoud if (sc->sc_dc == &vidcvideo_console_dc)
512 1.1 reinoud panic("vidcvideo_free_screen: console");
513 1.1 reinoud
514 1.1 reinoud sc->nscreens--;
515 1.1 reinoud }
516 1.1 reinoud
517 1.1 reinoud
518 1.1 reinoud static int
519 1.1 reinoud vidcvideo_show_screen(v, cookie, waitok, cb, cbarg)
520 1.1 reinoud void *v;
521 1.1 reinoud void *cookie;
522 1.1 reinoud int waitok;
523 1.1 reinoud void (*cb) __P((void *, int, int));
524 1.1 reinoud void *cbarg;
525 1.1 reinoud {
526 1.1 reinoud
527 1.1 reinoud return (0);
528 1.1 reinoud }
529 1.1 reinoud
530 1.1 reinoud
531 1.1 reinoud /* EXPORT */ int
532 1.1 reinoud vidcvideo_cnattach(addr)
533 1.1 reinoud vaddr_t addr;
534 1.1 reinoud {
535 1.1 reinoud struct fb_devconfig *dcp = &vidcvideo_console_dc;
536 1.1 reinoud long defattr;
537 1.1 reinoud
538 1.1 reinoud vidcvideo_init();
539 1.1 reinoud vidcvideo_getdevconfig(addr, dcp);
540 1.1 reinoud vidcvideo_config_wscons(dcp);
541 1.1 reinoud (*dcp->rinfo.ri_ops.alloc_attr)(&dcp->rinfo, 0, 0, 0, &defattr);
542 1.1 reinoud wsdisplay_cnattach(&vidcvideo_stdscreen, &dcp->rinfo, 0, 0, defattr);
543 1.1 reinoud
544 1.1 reinoud vidcvideo_is_console = 1;
545 1.1 reinoud return(0);
546 1.1 reinoud }
547 1.1 reinoud
548 1.1 reinoud
549 1.1 reinoud static int
550 1.1 reinoud vidcvideointr(arg)
551 1.1 reinoud void *arg;
552 1.1 reinoud {
553 1.1 reinoud struct vidcvideo_softc *sc = arg;
554 1.1 reinoud int v;
555 1.1 reinoud
556 1.1 reinoud v = sc->sc_changed;
557 1.1 reinoud if (v == 0)
558 1.1 reinoud return (1);
559 1.1 reinoud
560 1.1 reinoud if (v & WSDISPLAY_CMAP_DOLUT) {
561 1.1 reinoud struct hwcmap256 *cm = &sc->sc_cmap;
562 1.1 reinoud int index;
563 1.1 reinoud
564 1.1 reinoud if (sc->sc_dc->dc_depth == 4) {
565 1.1 reinoud /* palette for 4 bpp is different from 8bpp */
566 1.1 reinoud vidcvideo_write(VIDC_PALREG, 0x00000000);
567 1.1 reinoud for (index=0; index < 1<<sc->sc_dc->dc_depth; index++)
568 1.1 reinoud vidcvideo_write(VIDC_PALETTE,
569 1.1 reinoud VIDC_COL(cm->r[index],
570 1.1 reinoud cm->g[index],
571 1.1 reinoud cm->b[index]));
572 1.1 reinoud ;
573 1.1 reinoud };
574 1.1 reinoud
575 1.1 reinoud if (sc->sc_dc->dc_depth == 8) {
576 1.1 reinoud /* XXX dunno what to do in less than 8bpp */
577 1.1 reinoud /* palettes only make sense in 8bpp and less modes on VIDC */
578 1.1 reinoud vidcvideo_write(VIDC_PALREG, 0x00000000);
579 1.1 reinoud for (index = 0; index < CMAP_SIZE; index++) {
580 1.1 reinoud vidcvideo_write(VIDC_PALETTE,
581 1.1 reinoud VIDC_COL(cm->r[index], cm->g[index], cm->b[index])
582 1.1 reinoud );
583 1.1 reinoud };
584 1.1 reinoud };
585 1.1 reinoud }
586 1.1 reinoud
587 1.1 reinoud if (v & WSDISPLAY_VIDEO_ONOFF) {
588 1.1 reinoud vidcvideo_blank(sc->sc_dc->dc_blanked);
589 1.1 reinoud };
590 1.1 reinoud
591 1.1 reinoud if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
592 1.1 reinoud int x, y;
593 1.1 reinoud x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
594 1.1 reinoud y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
595 1.1 reinoud
596 1.1 reinoud vidcvideo_updatecursor(x, y);
597 1.1 reinoud };
598 1.1 reinoud
599 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCUR) {
600 1.1 reinoud vidcvideo_enablecursor(sc->sc_curenb);
601 1.1 reinoud };
602 1.1 reinoud
603 1.1 reinoud
604 1.1 reinoud #if 0 /* XXX snip XXX */
605 1.1 reinoud /* XXX kept here as an archive for now XXX */
606 1.1 reinoud
607 1.1 reinoud vdac = vidcvideobase + CX_BT459_OFFSET;
608 1.1 reinoud v = sc->sc_changed;
609 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCUR) {
610 1.1 reinoud SELECT(vdac, BT459_IREG_CCR);
611 1.1 reinoud REG(vdac, bt_reg) = (sc->sc_curenb) ? 0xc0 : 0x00;
612 1.1 reinoud }
613 1.1 reinoud if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOHOT)) {
614 1.1 reinoud int x, y;
615 1.1 reinoud
616 1.1 reinoud x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
617 1.1 reinoud y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
618 1.1 reinoud
619 1.1 reinoud x += sc->sc_cursor.cc_magic.x;
620 1.1 reinoud y += sc->sc_cursor.cc_magic.y;
621 1.1 reinoud
622 1.1 reinoud SELECT(vdac, BT459_IREG_CURSOR_X_LOW);
623 1.1 reinoud REG(vdac, bt_reg) = x; tc_wmb();
624 1.1 reinoud REG(vdac, bt_reg) = x >> 8; tc_wmb();
625 1.1 reinoud REG(vdac, bt_reg) = y; tc_wmb();
626 1.1 reinoud REG(vdac, bt_reg) = y >> 8; tc_wmb();
627 1.1 reinoud }
628 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCMAP) {
629 1.1 reinoud u_int8_t *cp = sc->sc_cursor.cc_color;
630 1.1 reinoud
631 1.1 reinoud SELECT(vdac, BT459_IREG_CCOLOR_2);
632 1.1 reinoud REG(vdac, bt_reg) = cp[1]; tc_wmb();
633 1.1 reinoud REG(vdac, bt_reg) = cp[3]; tc_wmb();
634 1.1 reinoud REG(vdac, bt_reg) = cp[5]; tc_wmb();
635 1.1 reinoud
636 1.1 reinoud REG(vdac, bt_reg) = cp[0]; tc_wmb();
637 1.1 reinoud REG(vdac, bt_reg) = cp[2]; tc_wmb();
638 1.1 reinoud REG(vdac, bt_reg) = cp[4]; tc_wmb();
639 1.1 reinoud }
640 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOSHAPE) {
641 1.1 reinoud u_int8_t *ip, *mp, img, msk;
642 1.1 reinoud u_int8_t u;
643 1.1 reinoud int bcnt;
644 1.1 reinoud
645 1.1 reinoud ip = (u_int8_t *)sc->sc_cursor.cc_image;
646 1.1 reinoud mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_HEIGHT);
647 1.1 reinoud
648 1.1 reinoud bcnt = 0;
649 1.1 reinoud SELECT(vdac, BT459_IREG_CRAM_BASE+0);
650 1.1 reinoud /* 64 pixel scan line is consisted with 16 byte cursor ram */
651 1.1 reinoud while (bcnt < sc->sc_cursor.cc_size.y * 16) {
652 1.1 reinoud /* pad right half 32 pixel when smaller than 33 */
653 1.1 reinoud if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
654 1.1 reinoud REG(vdac, bt_reg) = 0; tc_wmb();
655 1.1 reinoud REG(vdac, bt_reg) = 0; tc_wmb();
656 1.1 reinoud }
657 1.1 reinoud else {
658 1.1 reinoud img = *ip++;
659 1.1 reinoud msk = *mp++;
660 1.1 reinoud img &= msk; /* cookie off image */
661 1.1 reinoud u = (msk & 0x0f) << 4 | (img & 0x0f);
662 1.1 reinoud REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
663 1.1 reinoud u = (msk & 0xf0) | (img & 0xf0) >> 4;
664 1.1 reinoud REG(vdac, bt_reg) = shuffle[u]; tc_wmb();
665 1.1 reinoud }
666 1.1 reinoud bcnt += 2;
667 1.1 reinoud }
668 1.1 reinoud /* pad unoccupied scan lines */
669 1.1 reinoud while (bcnt < CURSOR_MAX_HEIGHT * 16) {
670 1.1 reinoud REG(vdac, bt_reg) = 0; tc_wmb();
671 1.1 reinoud REG(vdac, bt_reg) = 0; tc_wmb();
672 1.1 reinoud bcnt += 2;
673 1.1 reinoud }
674 1.1 reinoud }
675 1.1 reinoud #endif /* XXX snip XXX */
676 1.1 reinoud
677 1.1 reinoud sc->sc_changed = 0;
678 1.1 reinoud return (1);
679 1.1 reinoud }
680 1.1 reinoud
681 1.1 reinoud
682 1.1 reinoud static u_char ri_col_data[6][6] = {
683 1.1 reinoud { 0, 0, 0, 0, 0, 0}, /* 1 bpp */
684 1.1 reinoud { 0, 0, 0, 0, 0, 0}, /* 2 bpp */
685 1.1 reinoud { 0, 0, 0, 0, 0, 0}, /* 4 bpp */
686 1.1 reinoud { 0, 0, 0, 0, 0, 0}, /* 8 bpp */
687 1.1 reinoud { 5, 5, 5, 0, 5, 10}, /* 16 bpp */
688 1.1 reinoud { 8, 8, 8, 0, 8, 16}, /* 32 bpp */
689 1.1 reinoud };
690 1.1 reinoud
691 1.1 reinoud static void
692 1.1 reinoud vidcvideo_colourmap_and_cursor_init(dc)
693 1.1 reinoud struct fb_devconfig *dc;
694 1.1 reinoud {
695 1.1 reinoud struct rasops_info *ri = &dc->rinfo;
696 1.1 reinoud u_char *rgbdat;
697 1.1 reinoud
698 1.1 reinoud /* Whatever we do later... just make sure we have a
699 1.1 reinoud * sane palette to start with
700 1.1 reinoud */
701 1.1 reinoud vidcvideo_stdpalette();
702 1.1 reinoud
703 1.1 reinoud /* set up rgb bit pattern values for rasops_init */
704 1.1 reinoud rgbdat = ri_col_data[dc->dc_log2_depth];
705 1.1 reinoud ri->ri_rnum = rgbdat[0];
706 1.1 reinoud ri->ri_gnum = rgbdat[1];
707 1.1 reinoud ri->ri_bnum = rgbdat[2];
708 1.1 reinoud ri->ri_rpos = rgbdat[3];
709 1.1 reinoud ri->ri_gpos = rgbdat[4];
710 1.1 reinoud ri->ri_bpos = rgbdat[5];
711 1.1 reinoud
712 1.1 reinoud }
713 1.1 reinoud
714 1.1 reinoud
715 1.1 reinoud static int
716 1.1 reinoud get_cmap(sc, p)
717 1.1 reinoud struct vidcvideo_softc *sc;
718 1.1 reinoud struct wsdisplay_cmap *p;
719 1.1 reinoud {
720 1.1 reinoud u_int index = p->index, count = p->count;
721 1.1 reinoud
722 1.1 reinoud if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
723 1.1 reinoud return (EINVAL);
724 1.1 reinoud
725 1.1 reinoud if (!uvm_useracc(p->red, count, B_WRITE) ||
726 1.1 reinoud !uvm_useracc(p->green, count, B_WRITE) ||
727 1.1 reinoud !uvm_useracc(p->blue, count, B_WRITE))
728 1.1 reinoud return (EFAULT);
729 1.1 reinoud
730 1.1 reinoud copyout(&sc->sc_cmap.r[index], p->red, count);
731 1.1 reinoud copyout(&sc->sc_cmap.g[index], p->green, count);
732 1.1 reinoud copyout(&sc->sc_cmap.b[index], p->blue, count);
733 1.1 reinoud
734 1.1 reinoud return (0);
735 1.1 reinoud }
736 1.1 reinoud
737 1.1 reinoud
738 1.1 reinoud static int
739 1.1 reinoud set_cmap(sc, p)
740 1.1 reinoud struct vidcvideo_softc *sc;
741 1.1 reinoud struct wsdisplay_cmap *p;
742 1.1 reinoud {
743 1.1 reinoud u_int index = p->index, count = p->count;
744 1.1 reinoud
745 1.1 reinoud if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
746 1.1 reinoud return (EINVAL);
747 1.1 reinoud
748 1.1 reinoud if (!uvm_useracc(p->red, count, B_READ) ||
749 1.1 reinoud !uvm_useracc(p->green, count, B_READ) ||
750 1.1 reinoud !uvm_useracc(p->blue, count, B_READ))
751 1.1 reinoud return (EFAULT);
752 1.1 reinoud
753 1.1 reinoud copyin(p->red, &sc->sc_cmap.r[index], count);
754 1.1 reinoud copyin(p->green, &sc->sc_cmap.g[index], count);
755 1.1 reinoud copyin(p->blue, &sc->sc_cmap.b[index], count);
756 1.1 reinoud sc->sc_changed |= WSDISPLAY_CMAP_DOLUT;
757 1.1 reinoud return (0);
758 1.1 reinoud }
759 1.1 reinoud
760 1.1 reinoud
761 1.1 reinoud static int
762 1.1 reinoud set_cursor(sc, p)
763 1.1 reinoud struct vidcvideo_softc *sc;
764 1.1 reinoud struct wsdisplay_cursor *p;
765 1.1 reinoud {
766 1.1 reinoud #define cc (&sc->sc_cursor)
767 1.1 reinoud u_int v, index, count, icount;
768 1.1 reinoud
769 1.1 reinoud v = p->which;
770 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCMAP) {
771 1.1 reinoud index = p->cmap.index;
772 1.1 reinoud count = p->cmap.count;
773 1.1 reinoud if (index >= CURSOR_MAX_COLOURS || (index + count) > CURSOR_MAX_COLOURS)
774 1.1 reinoud return (EINVAL);
775 1.1 reinoud if (!uvm_useracc(p->cmap.red, count, B_READ) ||
776 1.1 reinoud !uvm_useracc(p->cmap.green, count, B_READ) ||
777 1.1 reinoud !uvm_useracc(p->cmap.blue, count, B_READ))
778 1.1 reinoud return (EFAULT);
779 1.1 reinoud }
780 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOSHAPE) {
781 1.1 reinoud if (p->size.x > CURSOR_MAX_WIDTH || p->size.y > CURSOR_MAX_HEIGHT)
782 1.1 reinoud return (EINVAL);
783 1.1 reinoud icount = sizeof(u_int32_t) * p->size.y;
784 1.1 reinoud if (!uvm_useracc(p->image, icount, B_READ) ||
785 1.1 reinoud !uvm_useracc(p->mask, icount, B_READ))
786 1.1 reinoud return (EFAULT);
787 1.1 reinoud }
788 1.1 reinoud
789 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCUR)
790 1.1 reinoud sc->sc_curenb = p->enable;
791 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOPOS)
792 1.1 reinoud set_curpos(sc, &p->pos);
793 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOHOT)
794 1.1 reinoud cc->cc_hot = p->hot;
795 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOCMAP) {
796 1.1 reinoud copyin(p->cmap.red, &cc->cc_color[index], count);
797 1.1 reinoud copyin(p->cmap.green, &cc->cc_color[index + 2], count);
798 1.1 reinoud copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
799 1.1 reinoud }
800 1.1 reinoud if (v & WSDISPLAY_CURSOR_DOSHAPE) {
801 1.1 reinoud cc->cc_size = p->size;
802 1.1 reinoud memset(cc->cc_image, 0, sizeof cc->cc_image);
803 1.1 reinoud memset(cc->cc_mask, 0, sizeof cc->cc_mask);
804 1.1 reinoud copyin(p->image, cc->cc_image, icount);
805 1.1 reinoud copyin(p->mask, cc->cc_mask, icount);
806 1.1 reinoud }
807 1.1 reinoud sc->sc_changed |= v;
808 1.1 reinoud
809 1.1 reinoud return (0);
810 1.1 reinoud #undef cc
811 1.1 reinoud }
812 1.1 reinoud
813 1.1 reinoud
814 1.1 reinoud static int
815 1.1 reinoud get_cursor(sc, p)
816 1.1 reinoud struct vidcvideo_softc *sc;
817 1.1 reinoud struct wsdisplay_cursor *p;
818 1.1 reinoud {
819 1.5 atatat return (EPASSTHROUGH); /* XXX */
820 1.1 reinoud }
821 1.1 reinoud
822 1.1 reinoud
823 1.1 reinoud static void
824 1.1 reinoud set_curpos(sc, curpos)
825 1.1 reinoud struct vidcvideo_softc *sc;
826 1.1 reinoud struct wsdisplay_curpos *curpos;
827 1.1 reinoud {
828 1.1 reinoud struct fb_devconfig *dc = sc->sc_dc;
829 1.1 reinoud int x = curpos->x, y = curpos->y;
830 1.1 reinoud
831 1.1 reinoud if (y < 0)
832 1.1 reinoud y = 0;
833 1.1 reinoud else if (y > dc->dc_ht)
834 1.1 reinoud y = dc->dc_ht;
835 1.1 reinoud if (x < 0)
836 1.1 reinoud x = 0;
837 1.1 reinoud else if (x > dc->dc_wid)
838 1.1 reinoud x = dc->dc_wid;
839 1.1 reinoud sc->sc_cursor.cc_pos.x = x;
840 1.1 reinoud sc->sc_cursor.cc_pos.y = y;
841 1.1 reinoud }
842 1.1 reinoud
843 1.1 reinoud
844 1.1 reinoud static void vv_copyrows(id, srcrow, dstrow, nrows)
845 1.1 reinoud void *id;
846 1.1 reinoud int srcrow, dstrow, nrows;
847 1.1 reinoud {
848 1.1 reinoud struct rasops_info *ri = id;
849 1.1 reinoud int height, offset, size;
850 1.1 reinoud int scrollup, scrolldown;
851 1.1 reinoud unsigned char *src, *dst;
852 1.1 reinoud
853 1.1 reinoud /* All movements are done in multiples of character heigths */
854 1.1 reinoud height = ri->ri_font->fontheight * nrows;
855 1.1 reinoud offset = (srcrow - dstrow) * ri->ri_yscale;
856 1.1 reinoud size = height * ri->ri_stride;
857 1.1 reinoud
858 1.1 reinoud /* check if we are full screen scrolling */
859 1.1 reinoud scrollup = (srcrow + nrows >= ri->ri_rows);
860 1.1 reinoud scrolldown = (dstrow + nrows >= ri->ri_rows);
861 1.1 reinoud
862 1.1 reinoud if ((scrollup || scrolldown) && (videomemory.vidm_type == VIDEOMEM_TYPE_VRAM)) {
863 1.1 reinoud ri->ri_bits = vidcvideo_hwscroll(offset);
864 1.1 reinoud vidcvideo_progr_scroll(); /* sadistic ; shouldnt this be on vsync? */
865 1.1 reinoud
866 1.1 reinoud /* wipe out remains of the screen if nessisary */
867 1.1 reinoud if (ri->ri_emuheight != ri->ri_height) vv_eraserows(id, ri->ri_rows, 1, NULL);
868 1.1 reinoud return;
869 1.1 reinoud };
870 1.1 reinoud
871 1.1 reinoud /* Else we just copy the area : we're braindead for now
872 1.1 reinoud * Note: we can't use hardware scrolling when the softc isnt known yet...
873 1.1 reinoud * if its not known we dont have interrupts and we can't change the display
874 1.1 reinoud * address reliable other than in a Vsync
875 1.1 reinoud */
876 1.1 reinoud
877 1.1 reinoud src = ri->ri_bits + srcrow * ri->ri_font->fontheight * ri->ri_stride;
878 1.1 reinoud dst = ri->ri_bits + dstrow * ri->ri_font->fontheight * ri->ri_stride;
879 1.1 reinoud
880 1.1 reinoud bcopy(src, dst, size);
881 1.1 reinoud }
882 1.1 reinoud
883 1.1 reinoud
884 1.1 reinoud static void vv_eraserows(id, startrow, nrows, attr)
885 1.1 reinoud void *id;
886 1.1 reinoud int startrow, nrows;
887 1.1 reinoud long attr;
888 1.1 reinoud {
889 1.1 reinoud struct rasops_info *ri = id;
890 1.1 reinoud int height;
891 1.1 reinoud unsigned char *src;
892 1.1 reinoud
893 1.1 reinoud /* we're braindead for now */
894 1.1 reinoud height = ri->ri_font->fontheight * nrows * ri->ri_stride;
895 1.1 reinoud
896 1.1 reinoud src = ri->ri_bits + startrow * ri->ri_font->fontheight * ri->ri_stride;
897 1.1 reinoud
898 1.1 reinoud bzero(src, height);
899 1.1 reinoud }
900 1.1 reinoud
901