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