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