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